Drop small session Zod statics (#26921)
This commit is contained in:
@@ -4,8 +4,6 @@ import { Snapshot } from "../snapshot"
|
|||||||
import { Storage } from "@/storage/storage"
|
import { Storage } from "@/storage/storage"
|
||||||
import { SyncEvent } from "../sync"
|
import { SyncEvent } from "../sync"
|
||||||
import * as Log from "@opencode-ai/core/util/log"
|
import * as Log from "@opencode-ai/core/util/log"
|
||||||
import { zod } from "@opencode-ai/core/effect-zod"
|
|
||||||
import { withStatics } from "@opencode-ai/core/schema"
|
|
||||||
import * as Session from "./session"
|
import * as Session from "./session"
|
||||||
import { MessageV2 } from "./message-v2"
|
import { MessageV2 } from "./message-v2"
|
||||||
import { SessionID, MessageID, PartID } from "./schema"
|
import { SessionID, MessageID, PartID } from "./schema"
|
||||||
@@ -18,7 +16,7 @@ export const RevertInput = Schema.Struct({
|
|||||||
sessionID: SessionID,
|
sessionID: SessionID,
|
||||||
messageID: MessageID,
|
messageID: MessageID,
|
||||||
partID: Schema.optional(PartID),
|
partID: Schema.optional(PartID),
|
||||||
}).pipe(withStatics((s) => ({ zod: zod(s) })))
|
})
|
||||||
export type RevertInput = Schema.Schema.Type<typeof RevertInput>
|
export type RevertInput = Schema.Schema.Type<typeof RevertInput>
|
||||||
|
|
||||||
export interface Interface {
|
export interface Interface {
|
||||||
|
|||||||
@@ -2,10 +2,8 @@ import { BusEvent } from "@/bus/bus-event"
|
|||||||
import { Bus } from "@/bus"
|
import { Bus } from "@/bus"
|
||||||
import { InstanceState } from "@/effect/instance-state"
|
import { InstanceState } from "@/effect/instance-state"
|
||||||
import { SessionID } from "./schema"
|
import { SessionID } from "./schema"
|
||||||
import { zod } from "@opencode-ai/core/effect-zod"
|
import { NonNegativeInt } from "@opencode-ai/core/schema"
|
||||||
import { NonNegativeInt, withStatics } from "@opencode-ai/core/schema"
|
|
||||||
import { Effect, Layer, Context, Schema } from "effect"
|
import { Effect, Layer, Context, Schema } from "effect"
|
||||||
import z from "zod"
|
|
||||||
|
|
||||||
export const Info = Schema.Union([
|
export const Info = Schema.Union([
|
||||||
Schema.Struct({
|
Schema.Struct({
|
||||||
@@ -30,9 +28,7 @@ export const Info = Schema.Union([
|
|||||||
Schema.Struct({
|
Schema.Struct({
|
||||||
type: Schema.Literal("busy"),
|
type: Schema.Literal("busy"),
|
||||||
}),
|
}),
|
||||||
])
|
]).annotate({ identifier: "SessionStatus" })
|
||||||
.annotate({ identifier: "SessionStatus" })
|
|
||||||
.pipe(withStatics((s) => ({ zod: zod(s) })))
|
|
||||||
export type Info = Schema.Schema.Type<typeof Info>
|
export type Info = Schema.Schema.Type<typeof Info>
|
||||||
|
|
||||||
export const Event = {
|
export const Event = {
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
import { BusEvent } from "@/bus/bus-event"
|
import { BusEvent } from "@/bus/bus-event"
|
||||||
import { Bus } from "@/bus"
|
import { Bus } from "@/bus"
|
||||||
import { SessionID } from "./schema"
|
import { SessionID } from "./schema"
|
||||||
import { zod } from "@opencode-ai/core/effect-zod"
|
|
||||||
import { withStatics } from "@opencode-ai/core/schema"
|
|
||||||
import { Effect, Layer, Context, Schema } from "effect"
|
import { Effect, Layer, Context, Schema } from "effect"
|
||||||
import z from "zod"
|
|
||||||
import { Database } from "@/storage/db"
|
import { Database } from "@/storage/db"
|
||||||
import { eq } from "drizzle-orm"
|
import { eq } from "drizzle-orm"
|
||||||
import { asc } from "drizzle-orm"
|
import { asc } from "drizzle-orm"
|
||||||
@@ -16,9 +13,7 @@ export const Info = Schema.Struct({
|
|||||||
description: "Current status of the task: pending, in_progress, completed, cancelled",
|
description: "Current status of the task: pending, in_progress, completed, cancelled",
|
||||||
}),
|
}),
|
||||||
priority: Schema.String.annotate({ description: "Priority level of the task: high, medium, low" }),
|
priority: Schema.String.annotate({ description: "Priority level of the task: high, medium, low" }),
|
||||||
})
|
}).annotate({ identifier: "Todo" })
|
||||||
.annotate({ identifier: "Todo" })
|
|
||||||
.pipe(withStatics((s) => ({ zod: zod(s) })))
|
|
||||||
export type Info = Schema.Schema.Type<typeof Info>
|
export type Info = Schema.Schema.Type<typeof Info>
|
||||||
|
|
||||||
export const Event = {
|
export const Event = {
|
||||||
|
|||||||
@@ -221,14 +221,11 @@ describe("SessionRevert.RevertInput", () => {
|
|||||||
test("messageID is required, partID is optional", () => {
|
test("messageID is required, partID is optional", () => {
|
||||||
const withPart = { sessionID, messageID, partID }
|
const withPart = { sessionID, messageID, partID }
|
||||||
expect(decode(withPart)).toEqual(withPart)
|
expect(decode(withPart)).toEqual(withPart)
|
||||||
expect(SessionRevert.RevertInput.zod.parse(withPart)).toEqual(withPart)
|
|
||||||
|
|
||||||
const noPart = { sessionID, messageID }
|
const noPart = { sessionID, messageID }
|
||||||
expect(decode(noPart)).toEqual(noPart)
|
expect(decode(noPart)).toEqual(noPart)
|
||||||
expect(SessionRevert.RevertInput.zod.parse(noPart)).toEqual(noPart)
|
|
||||||
|
|
||||||
expect(() => decode({ sessionID })).toThrow()
|
expect(() => decode({ sessionID })).toThrow()
|
||||||
expect(() => SessionRevert.RevertInput.zod.parse({ sessionID })).toThrow()
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -247,7 +244,6 @@ describe("SessionStatus.Info", () => {
|
|||||||
test("idle / busy discriminators", () => {
|
test("idle / busy discriminators", () => {
|
||||||
expect(decode({ type: "idle" })).toEqual({ type: "idle" })
|
expect(decode({ type: "idle" })).toEqual({ type: "idle" })
|
||||||
expect(decode({ type: "busy" })).toEqual({ type: "busy" })
|
expect(decode({ type: "busy" })).toEqual({ type: "busy" })
|
||||||
expect(SessionStatus.Info.zod.parse({ type: "idle" })).toEqual({ type: "idle" })
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test("retry carries attempt/message/action/next", () => {
|
test("retry carries attempt/message/action/next", () => {
|
||||||
@@ -266,12 +262,10 @@ describe("SessionStatus.Info", () => {
|
|||||||
next: 500,
|
next: 500,
|
||||||
}
|
}
|
||||||
expect(decode(input)).toEqual(input)
|
expect(decode(input)).toEqual(input)
|
||||||
expect(SessionStatus.Info.zod.parse(input)).toEqual(input)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test("rejects unknown type", () => {
|
test("rejects unknown type", () => {
|
||||||
expect(() => decode({ type: "bogus" })).toThrow()
|
expect(() => decode({ type: "bogus" })).toThrow()
|
||||||
expect(() => SessionStatus.Info.zod.parse({ type: "bogus" })).toThrow()
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -281,7 +275,6 @@ describe("Todo.Info", () => {
|
|||||||
test("three-field round-trip", () => {
|
test("three-field round-trip", () => {
|
||||||
const input = { content: "do a thing", status: "pending", priority: "high" }
|
const input = { content: "do a thing", status: "pending", priority: "high" }
|
||||||
expect(decode(input)).toEqual(input)
|
expect(decode(input)).toEqual(input)
|
||||||
expect(Todo.Info.zod.parse(input)).toEqual(input)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user