fix: restore desktop startup and align tool previews with SDK updates
Add reflect-metadata bootstrap so desktop sidecar no longer crashes on startup. Update SDK v1.4 compatibility for model variant and diff payload handling. Unify write/edit/apply patch expanded previews and hide write success output noise.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import type {
|
||||
Event,
|
||||
FileDiff,
|
||||
Message,
|
||||
Part,
|
||||
PermissionRequest,
|
||||
@@ -11,7 +10,7 @@ import type {
|
||||
Todo,
|
||||
} from "@opencode-ai/sdk/v2/client"
|
||||
import { Binary } from "./binary"
|
||||
import type { GlobalState, State } from "./types"
|
||||
import type { FileDiff, GlobalState, State } from "./types"
|
||||
import { dropSessionCaches } from "./session-cache"
|
||||
import { stripSessionDiffSnapshots } from "./sanitize"
|
||||
import { syncDebug } from "./debug"
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
// ---------------------------------------------------------------------------
|
||||
// Payload sanitization — strip oversized diff snapshot fields client-side.
|
||||
//
|
||||
// OpenCode session objects carry summary.diffs[].before/after with full file
|
||||
// contents. The UI never uses these fields but they waste browser memory and
|
||||
// OpenCode session/message snapshots may carry large full-content diff fields
|
||||
// (legacy before/after or from/to). The UI never uses these fields but they
|
||||
// waste browser memory and
|
||||
// can crash tabs for large sessions.
|
||||
//
|
||||
// Applied at two points:
|
||||
@@ -19,6 +20,8 @@ type DiffEntry = {
|
||||
deletions?: number
|
||||
before?: string
|
||||
after?: string
|
||||
from?: string
|
||||
to?: string
|
||||
}
|
||||
|
||||
type SessionSummary = {
|
||||
@@ -26,16 +29,24 @@ type SessionSummary = {
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
/** Strip before/after from summary.diffs on a session object */
|
||||
/** Strip oversized snapshot fields from summary.diffs on a session object */
|
||||
export function stripSessionDiffSnapshots(session: Session): Session {
|
||||
const summary = (session as { summary?: SessionSummary }).summary
|
||||
if (!summary?.diffs || !Array.isArray(summary.diffs)) return session
|
||||
|
||||
let changed = false
|
||||
const stripped = summary.diffs.map((d) => {
|
||||
if (d && (typeof d.before === "string" || typeof d.after === "string")) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { before: _before, after: _after, ...rest } = d
|
||||
if (d && (
|
||||
typeof d.before === "string"
|
||||
|| typeof d.after === "string"
|
||||
|| typeof d.from === "string"
|
||||
|| typeof d.to === "string"
|
||||
)) {
|
||||
const rest = { ...d }
|
||||
delete rest.before
|
||||
delete rest.after
|
||||
delete rest.from
|
||||
delete rest.to
|
||||
changed = true
|
||||
return rest
|
||||
}
|
||||
@@ -46,16 +57,24 @@ export function stripSessionDiffSnapshots(session: Session): Session {
|
||||
return { ...session, summary: { ...summary, diffs: stripped } } as Session
|
||||
}
|
||||
|
||||
/** Strip before/after from summary.diffs on a message object */
|
||||
/** Strip oversized snapshot fields from summary.diffs on a message object */
|
||||
export function stripMessageDiffSnapshots(message: Message): Message {
|
||||
const summary = (message as { summary?: SessionSummary }).summary
|
||||
if (!summary?.diffs || !Array.isArray(summary.diffs)) return message
|
||||
|
||||
let changed = false
|
||||
const stripped = summary.diffs.map((d) => {
|
||||
if (d && (typeof d.before === "string" || typeof d.after === "string")) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { before: _before, after: _after, ...rest } = d
|
||||
if (d && (
|
||||
typeof d.before === "string"
|
||||
|| typeof d.after === "string"
|
||||
|| typeof d.from === "string"
|
||||
|| typeof d.to === "string"
|
||||
)) {
|
||||
const rest = { ...d }
|
||||
delete rest.before
|
||||
delete rest.after
|
||||
delete rest.from
|
||||
delete rest.to
|
||||
changed = true
|
||||
return rest
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type {
|
||||
FileDiff,
|
||||
Message,
|
||||
Part,
|
||||
PermissionRequest,
|
||||
@@ -7,6 +6,7 @@ import type {
|
||||
SessionStatus,
|
||||
Todo,
|
||||
} from "@opencode-ai/sdk/v2/client"
|
||||
import type { FileDiff } from "./types"
|
||||
|
||||
type SessionCache = {
|
||||
session_status: Record<string, SessionStatus | undefined>
|
||||
|
||||
@@ -1099,7 +1099,7 @@ export const useSessionUIStore = create<SessionUIState>()((set, get) => ({
|
||||
const messages = getSyncMessages(sessionId, directory)
|
||||
for (let i = messages.length - 1; i >= 0; i -= 1) {
|
||||
const message = messages[i] as Message & {
|
||||
model?: { providerID?: string; modelID?: string }
|
||||
model?: { providerID?: string; modelID?: string; variant?: string }
|
||||
variant?: string
|
||||
mode?: string
|
||||
}
|
||||
@@ -1116,8 +1116,9 @@ export const useSessionUIStore = create<SessionUIState>()((set, get) => ({
|
||||
const agent = typeof message.agent === "string" && message.agent.trim().length > 0
|
||||
? message.agent
|
||||
: (typeof message.mode === "string" && message.mode.trim().length > 0 ? message.mode : undefined)
|
||||
const variant = typeof message.variant === "string" && message.variant.trim().length > 0
|
||||
? message.variant
|
||||
const variantCandidate = message.model?.variant ?? message.variant
|
||||
const variant = typeof variantCandidate === "string" && variantCandidate.trim().length > 0
|
||||
? variantCandidate
|
||||
: undefined
|
||||
|
||||
return { agent, providerID, modelID, variant }
|
||||
|
||||
@@ -2,7 +2,6 @@ import type {
|
||||
Agent,
|
||||
Command,
|
||||
Config,
|
||||
FileDiff,
|
||||
LspStatus,
|
||||
McpStatus,
|
||||
Message,
|
||||
@@ -19,6 +18,15 @@ import type {
|
||||
VcsInfo,
|
||||
} from "@opencode-ai/sdk/v2/client"
|
||||
|
||||
export type FileDiff = {
|
||||
file?: string
|
||||
status?: string
|
||||
additions?: number
|
||||
deletions?: number
|
||||
patch?: string
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
export type ProjectMeta = {
|
||||
name?: string
|
||||
icon?: {
|
||||
|
||||
Reference in New Issue
Block a user