Drop unused opencode Zod statics (#26935)

This commit is contained in:
Kit Langton
2026-05-11 17:14:18 -04:00
committed by GitHub
parent d3caac5270
commit fd65d29dcc
34 changed files with 161 additions and 389 deletions

View File

@@ -23,8 +23,7 @@ import type { SystemError } from "bun"
import type { Provider } from "@/provider/provider"
import { ModelID, ProviderID } from "@/provider/schema"
import { Effect, Schema, Types } from "effect"
import { zod } from "@opencode-ai/core/effect-zod"
import { NonNegativeInt, withStatics } from "@opencode-ai/core/schema"
import { NonNegativeInt } from "@opencode-ai/core/schema"
import { namedSchemaError } from "@/util/named-schema-error"
import * as EffectLogger from "@opencode-ai/core/effect/logger"
@@ -88,9 +87,7 @@ export const SnapshotPart = Schema.Struct({
...partBase,
type: Schema.Literal("snapshot"),
snapshot: Schema.String,
})
.annotate({ identifier: "SnapshotPart" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "SnapshotPart" })
export type SnapshotPart = Types.DeepMutable<Schema.Schema.Type<typeof SnapshotPart>>
export const PatchPart = Schema.Struct({
@@ -98,9 +95,7 @@ export const PatchPart = Schema.Struct({
type: Schema.Literal("patch"),
hash: Schema.String,
files: Schema.Array(Schema.String),
})
.annotate({ identifier: "PatchPart" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "PatchPart" })
export type PatchPart = Types.DeepMutable<Schema.Schema.Type<typeof PatchPart>>
export const TextPart = Schema.Struct({
@@ -116,9 +111,7 @@ export const TextPart = Schema.Struct({
}),
),
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Any)),
})
.annotate({ identifier: "TextPart" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "TextPart" })
export type TextPart = Types.DeepMutable<Schema.Schema.Type<typeof TextPart>>
export const ReasoningPart = Schema.Struct({
@@ -130,9 +123,7 @@ export const ReasoningPart = Schema.Struct({
start: NonNegativeInt,
end: Schema.optional(NonNegativeInt),
}),
})
.annotate({ identifier: "ReasoningPart" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "ReasoningPart" })
export type ReasoningPart = Types.DeepMutable<Schema.Schema.Type<typeof ReasoningPart>>
const filePartSourceBase = {
@@ -147,9 +138,7 @@ export const FileSource = Schema.Struct({
...filePartSourceBase,
type: Schema.Literal("file"),
path: Schema.String,
})
.annotate({ identifier: "FileSource" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "FileSource" })
export const SymbolSource = Schema.Struct({
...filePartSourceBase,
@@ -158,24 +147,19 @@ export const SymbolSource = Schema.Struct({
range: LSP.Range,
name: Schema.String,
kind: NonNegativeInt,
})
.annotate({ identifier: "SymbolSource" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "SymbolSource" })
export const ResourceSource = Schema.Struct({
...filePartSourceBase,
type: Schema.Literal("resource"),
clientName: Schema.String,
uri: Schema.String,
})
.annotate({ identifier: "ResourceSource" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "ResourceSource" })
const _FilePartSource = Schema.Union([FileSource, SymbolSource, ResourceSource]).annotate({
export const FilePartSource = Schema.Union([FileSource, SymbolSource, ResourceSource]).annotate({
discriminator: "type",
identifier: "FilePartSource",
})
export const FilePartSource = Object.assign(_FilePartSource, { zod: zod(_FilePartSource) })
export const FilePart = Schema.Struct({
...partBase,
@@ -183,10 +167,8 @@ export const FilePart = Schema.Struct({
mime: Schema.String,
filename: Schema.optional(Schema.String),
url: Schema.String,
source: Schema.optional(_FilePartSource),
})
.annotate({ identifier: "FilePart" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
source: Schema.optional(FilePartSource),
}).annotate({ identifier: "FilePart" })
export type FilePart = Types.DeepMutable<Schema.Schema.Type<typeof FilePart>>
export const AgentPart = Schema.Struct({
@@ -200,9 +182,7 @@ export const AgentPart = Schema.Struct({
end: NonNegativeInt,
}),
),
})
.annotate({ identifier: "AgentPart" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "AgentPart" })
export type AgentPart = Types.DeepMutable<Schema.Schema.Type<typeof AgentPart>>
export const CompactionPart = Schema.Struct({
@@ -211,9 +191,7 @@ export const CompactionPart = Schema.Struct({
auto: Schema.Boolean,
overflow: Schema.optional(Schema.Boolean),
tail_start_id: Schema.optional(MessageID),
})
.annotate({ identifier: "CompactionPart" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "CompactionPart" })
export type CompactionPart = Types.DeepMutable<Schema.Schema.Type<typeof CompactionPart>>
export const SubtaskPart = Schema.Struct({
@@ -229,9 +207,7 @@ export const SubtaskPart = Schema.Struct({
}),
),
command: Schema.optional(Schema.String),
})
.annotate({ identifier: "SubtaskPart" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "SubtaskPart" })
export type SubtaskPart = Types.DeepMutable<Schema.Schema.Type<typeof SubtaskPart>>
export const RetryPart = Schema.Struct({
@@ -242,9 +218,7 @@ export const RetryPart = Schema.Struct({
time: Schema.Struct({
created: NonNegativeInt,
}),
})
.annotate({ identifier: "RetryPart" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "RetryPart" })
export type RetryPart = Omit<Types.DeepMutable<Schema.Schema.Type<typeof RetryPart>>, "error"> & {
error: APIError
}
@@ -253,9 +227,7 @@ export const StepStartPart = Schema.Struct({
...partBase,
type: Schema.Literal("step-start"),
snapshot: Schema.optional(Schema.String),
})
.annotate({ identifier: "StepStartPart" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "StepStartPart" })
export type StepStartPart = Types.DeepMutable<Schema.Schema.Type<typeof StepStartPart>>
export const StepFinishPart = Schema.Struct({
@@ -274,18 +246,14 @@ export const StepFinishPart = Schema.Struct({
write: Schema.Finite,
}),
}),
})
.annotate({ identifier: "StepFinishPart" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "StepFinishPart" })
export type StepFinishPart = Types.DeepMutable<Schema.Schema.Type<typeof StepFinishPart>>
export const ToolStatePending = Schema.Struct({
status: Schema.Literal("pending"),
input: Schema.Record(Schema.String, Schema.Any),
raw: Schema.String,
})
.annotate({ identifier: "ToolStatePending" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "ToolStatePending" })
export type ToolStatePending = Types.DeepMutable<Schema.Schema.Type<typeof ToolStatePending>>
export const ToolStateRunning = Schema.Struct({
@@ -296,9 +264,7 @@ export const ToolStateRunning = Schema.Struct({
time: Schema.Struct({
start: NonNegativeInt,
}),
})
.annotate({ identifier: "ToolStateRunning" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "ToolStateRunning" })
export type ToolStateRunning = Types.DeepMutable<Schema.Schema.Type<typeof ToolStateRunning>>
export const ToolStateCompleted = Schema.Struct({
@@ -313,9 +279,7 @@ export const ToolStateCompleted = Schema.Struct({
compacted: Schema.optional(NonNegativeInt),
}),
attachments: Schema.optional(Schema.Array(FilePart)),
})
.annotate({ identifier: "ToolStateCompleted" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "ToolStateCompleted" })
export type ToolStateCompleted = Types.DeepMutable<Schema.Schema.Type<typeof ToolStateCompleted>>
function truncateToolOutput(text: string, maxChars?: number) {
@@ -333,22 +297,18 @@ export const ToolStateError = Schema.Struct({
start: NonNegativeInt,
end: NonNegativeInt,
}),
})
.annotate({ identifier: "ToolStateError" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "ToolStateError" })
export type ToolStateError = Types.DeepMutable<Schema.Schema.Type<typeof ToolStateError>>
const _ToolState = Schema.Union([ToolStatePending, ToolStateRunning, ToolStateCompleted, ToolStateError]).annotate({
export const ToolState = Schema.Union([
ToolStatePending,
ToolStateRunning,
ToolStateCompleted,
ToolStateError,
]).annotate({
discriminator: "status",
identifier: "ToolState",
})
// Cast the derived zod so downstream z.infer sees the same mutable shape that
// our exported TS types expose (the pre-migration Zod inferences were mutable).
export const ToolState = Object.assign(_ToolState, {
zod: zod(_ToolState) as unknown as z.ZodType<
ToolStatePending | ToolStateRunning | ToolStateCompleted | ToolStateError
>,
})
export type ToolState = ToolStatePending | ToolStateRunning | ToolStateCompleted | ToolStateError
export const ToolPart = Schema.Struct({
@@ -356,11 +316,9 @@ export const ToolPart = Schema.Struct({
type: Schema.Literal("tool"),
callID: Schema.String,
tool: Schema.String,
state: _ToolState,
state: ToolState,
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Any)),
})
.annotate({ identifier: "ToolPart" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "ToolPart" })
export type ToolPart = Omit<Types.DeepMutable<Schema.Schema.Type<typeof ToolPart>>, "state"> & {
state: ToolState
}
@@ -441,8 +399,7 @@ type AssistantError = Schema.Schema.Type<typeof AssistantErrorSchema>
// Consumers of `SessionPrompt.PromptInput.parts` send part drafts without the
// ambient IDs (`messageID`, `sessionID`) that live on stored parts, and may
// omit `id` to let the server allocate one. These Schema-Struct variants
// carry that shape, and `SessionPrompt.PromptInput` just references the
// derived `.zod` (no omit/partial gymnastics needed at the call site).
// carry that shape so prompt decoding can accept drafts without stored IDs.
export const TextPartInput = Schema.Struct({
id: Schema.optional(PartID),
@@ -457,9 +414,7 @@ export const TextPartInput = Schema.Struct({
}),
),
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Any)),
})
.annotate({ identifier: "TextPartInput" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "TextPartInput" })
export type TextPartInput = Types.DeepMutable<Schema.Schema.Type<typeof TextPartInput>>
export const FilePartInput = Schema.Struct({
@@ -468,10 +423,8 @@ export const FilePartInput = Schema.Struct({
mime: Schema.String,
filename: Schema.optional(Schema.String),
url: Schema.String,
source: Schema.optional(_FilePartSource),
})
.annotate({ identifier: "FilePartInput" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
source: Schema.optional(FilePartSource),
}).annotate({ identifier: "FilePartInput" })
export type FilePartInput = Types.DeepMutable<Schema.Schema.Type<typeof FilePartInput>>
export const AgentPartInput = Schema.Struct({
@@ -485,9 +438,7 @@ export const AgentPartInput = Schema.Struct({
end: NonNegativeInt,
}),
),
})
.annotate({ identifier: "AgentPartInput" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "AgentPartInput" })
export type AgentPartInput = Types.DeepMutable<Schema.Schema.Type<typeof AgentPartInput>>
export const SubtaskPartInput = Schema.Struct({
@@ -503,9 +454,7 @@ export const SubtaskPartInput = Schema.Struct({
}),
),
command: Schema.optional(Schema.String),
})
.annotate({ identifier: "SubtaskPartInput" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "SubtaskPartInput" })
export type SubtaskPartInput = Types.DeepMutable<Schema.Schema.Type<typeof SubtaskPartInput>>
export const Assistant = Schema.Struct({
@@ -613,7 +562,7 @@ export const Event = {
export const WithParts = Schema.Struct({
info: Info,
parts: Schema.Array(Part),
}).pipe(withStatics((s) => ({ zod: zod(s) })))
})
export type WithParts = {
info: Info
parts: Part[]

View File

@@ -1,8 +1,7 @@
import { Schema } from "effect"
import { SessionID } from "./schema"
import { ModelID, ProviderID } from "../provider/schema"
import { zod } from "@opencode-ai/core/effect-zod"
import { NonNegativeInt, withStatics } from "@opencode-ai/core/schema"
import { NonNegativeInt } from "@opencode-ai/core/schema"
import { namedSchemaError } from "@/util/named-schema-error"
export const OutputLengthError = namedSchemaError("MessageOutputLengthError", {})
@@ -37,9 +36,7 @@ export const ToolCall = Schema.Struct({
toolCallId: Schema.String,
toolName: Schema.String,
args: Schema.Unknown,
})
.annotate({ identifier: "ToolCall" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "ToolCall" })
export type ToolCall = Schema.Schema.Type<typeof ToolCall>
export const ToolPartialCall = Schema.Struct({
@@ -48,9 +45,7 @@ export const ToolPartialCall = Schema.Struct({
toolCallId: Schema.String,
toolName: Schema.String,
args: Schema.Unknown,
})
.annotate({ identifier: "ToolPartialCall" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "ToolPartialCall" })
export type ToolPartialCall = Schema.Schema.Type<typeof ToolPartialCall>
export const ToolResult = Schema.Struct({
@@ -60,39 +55,32 @@ export const ToolResult = Schema.Struct({
toolName: Schema.String,
args: Schema.Unknown,
result: Schema.String,
})
.annotate({ identifier: "ToolResult" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "ToolResult" })
export type ToolResult = Schema.Schema.Type<typeof ToolResult>
export const ToolInvocation = Schema.Union([ToolCall, ToolPartialCall, ToolResult])
.annotate({ identifier: "ToolInvocation", discriminator: "state" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
export const ToolInvocation = Schema.Union([ToolCall, ToolPartialCall, ToolResult]).annotate({
identifier: "ToolInvocation",
discriminator: "state",
})
export type ToolInvocation = Schema.Schema.Type<typeof ToolInvocation>
export const TextPart = Schema.Struct({
type: Schema.Literal("text"),
text: Schema.String,
})
.annotate({ identifier: "TextPart" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "TextPart" })
export type TextPart = Schema.Schema.Type<typeof TextPart>
export const ReasoningPart = Schema.Struct({
type: Schema.Literal("reasoning"),
text: Schema.String,
providerMetadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
})
.annotate({ identifier: "ReasoningPart" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "ReasoningPart" })
export type ReasoningPart = Schema.Schema.Type<typeof ReasoningPart>
export const ToolInvocationPart = Schema.Struct({
type: Schema.Literal("tool-invocation"),
toolInvocation: ToolInvocation,
})
.annotate({ identifier: "ToolInvocationPart" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "ToolInvocationPart" })
export type ToolInvocationPart = Schema.Schema.Type<typeof ToolInvocationPart>
export const SourceUrlPart = Schema.Struct({
@@ -101,9 +89,7 @@ export const SourceUrlPart = Schema.Struct({
url: Schema.String,
title: Schema.optional(Schema.String),
providerMetadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
})
.annotate({ identifier: "SourceUrlPart" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "SourceUrlPart" })
export type SourceUrlPart = Schema.Schema.Type<typeof SourceUrlPart>
export const FilePart = Schema.Struct({
@@ -111,16 +97,12 @@ export const FilePart = Schema.Struct({
mediaType: Schema.String,
filename: Schema.optional(Schema.String),
url: Schema.String,
})
.annotate({ identifier: "FilePart" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "FilePart" })
export type FilePart = Schema.Schema.Type<typeof FilePart>
export const StepStartPart = Schema.Struct({
type: Schema.Literal("step-start"),
})
.annotate({ identifier: "StepStartPart" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "StepStartPart" })
export type StepStartPart = Schema.Schema.Type<typeof StepStartPart>
export const MessagePart = Schema.Union([
@@ -130,9 +112,7 @@ export const MessagePart = Schema.Union([
SourceUrlPart,
FilePart,
StepStartPart,
])
.annotate({ identifier: "MessagePart", discriminator: "type" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
]).annotate({ identifier: "MessagePart", discriminator: "type" })
export type MessagePart = Schema.Schema.Type<typeof MessagePart>
export const Info = Schema.Struct({
@@ -184,9 +164,7 @@ export const Info = Schema.Struct({
),
snapshot: Schema.optional(Schema.String),
}).annotate({ identifier: "MessageMetadata" }),
})
.annotate({ identifier: "Message" })
.pipe(withStatics((s) => ({ zod: zod(s) })))
}).annotate({ identifier: "Message" })
export type Info = Schema.Schema.Type<typeof Info>
export * as Message from "./message"

View File

@@ -2,8 +2,6 @@ import { Effect, Layer, Context, Schema } from "effect"
import { Bus } from "@/bus"
import { Snapshot } from "@/snapshot"
import { Storage } from "@/storage/storage"
import { zod } from "@opencode-ai/core/effect-zod"
import { withStatics } from "@opencode-ai/core/schema"
import * as Session from "./session"
import { MessageV2 } from "./message-v2"
import { SessionID, MessageID } from "./schema"
@@ -160,7 +158,7 @@ export const defaultLayer = Layer.suspend(() =>
export const DiffInput = Schema.Struct({
sessionID: SessionID,
messageID: Schema.optional(MessageID),
}).pipe(withStatics((s) => ({ zod: zod(s) })))
})
export type DiffInput = Schema.Schema.Type<typeof DiffInput>
export * as SessionSummary from "./summary"