Download packages/app/src/utils/diffs.ts from SaylorTwift/opencode: direct link, hf CLI and curl.
- Browser
- Download file 1.94 kB
-
https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/app/src/utils/diffs.ts
- Command line
-
hf download hf://SaylorTwift/opencode/packages/app/src/utils/diffs.ts
-
curl -L -o diffs.ts https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/app/src/utils/diffs.ts
1.94 kB
| import type { SnapshotFileDiff, VcsFileDiff } from "@opencode-ai/sdk/v2" | |
| import type { FileDiffInfo } from "@opencode-ai/client/promise" | |
| import type { Message } from "@opencode-ai/sdk/v2/client" | |
| type Diff = FileDiffInfo | SnapshotFileDiff | VcsFileDiff | |
| function diff(value: unknown): value is Diff { | |
| if (!value || typeof value !== "object" || Array.isArray(value)) return false | |
| if (!("file" in value) || typeof value.file !== "string") return false | |
| if (!("patch" in value) || typeof value.patch !== "string") return false | |
| if (!("additions" in value) || typeof value.additions !== "number") return false | |
| if (!("deletions" in value) || typeof value.deletions !== "number") return false | |
| if (!("status" in value) || value.status === undefined) return true | |
| return value.status === "added" || value.status === "deleted" || value.status === "modified" | |
| } | |
| function object(value: unknown): value is Record<string, unknown> { | |
| return !!value && typeof value === "object" && !Array.isArray(value) | |
| } | |
| export function diffs(value: unknown): Diff[] { | |
| if (Array.isArray(value) && value.every(diff)) return value | |
| if (Array.isArray(value)) return value.filter(diff) | |
| if (diff(value)) return [value] | |
| if (!object(value)) return [] | |
| return Object.values(value).filter(diff) | |
| } | |
| export function message(value: Message): Message { | |
| if (value.role !== "user") return value | |
| const raw = value.summary as unknown | |
| if (raw === undefined) return value | |
| if (!object(raw)) return { ...value, summary: undefined } | |
| const title = typeof raw.title === "string" ? raw.title : undefined | |
| const body = typeof raw.body === "string" ? raw.body : undefined | |
| const next = diffs(raw.diffs) | |
| if (title === raw.title && body === raw.body && next === raw.diffs) return value | |
| return { | |
| ...value, | |
| summary: { | |
| ...(title === undefined ? {} : { title }), | |
| ...(body === undefined ? {} : { body }), | |
| diffs: next, | |
| }, | |
| } | |
| } | |