mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
fix(plugin): keep fork history events wire-ready
This commit is contained in:
parent
aeacdceaea
commit
9494aeec92
9 changed files with 23 additions and 31 deletions
|
|
@ -518,7 +518,7 @@ export type SessionLogOutput =
|
|||
readonly sessionID: Session.ID
|
||||
readonly parentID: Session.ID
|
||||
readonly boundary: Session.ForkBoundary
|
||||
readonly messages?: ReadonlyArray<SessionMessage.Info> | undefined
|
||||
readonly messages?: ReadonlyArray<SessionMessage.InfoEncoded> | undefined
|
||||
readonly instructions?:
|
||||
| { readonly [x: string & Brand.Brand<"Instruction.Key">]: string & Brand.Brand<"Instruction.Hash"> }
|
||||
| undefined
|
||||
|
|
@ -715,7 +715,7 @@ export type SessionLogOutput =
|
|||
readonly assistantMessageID: SessionMessage.ID
|
||||
readonly finish: "stop" | "length" | "tool-calls" | "content-filter" | "error" | "unknown"
|
||||
readonly rawFinish?: string | undefined
|
||||
readonly providerState?: SessionMessage.ProviderState | undefined
|
||||
readonly providerState?: { readonly [x: string]: unknown } | undefined
|
||||
readonly cost: number & Brand.Brand<"Money.USD">
|
||||
readonly tokens: {
|
||||
readonly input: number
|
||||
|
|
@ -740,7 +740,7 @@ export type SessionLogOutput =
|
|||
readonly error: { readonly type: string; readonly message: string; readonly status?: number | undefined }
|
||||
readonly finish?: "content-filter" | undefined
|
||||
readonly rawFinish?: string | undefined
|
||||
readonly providerState?: SessionMessage.ProviderState | undefined
|
||||
readonly providerState?: { readonly [x: string]: unknown } | undefined
|
||||
readonly cost?: (number & Brand.Brand<"Money.USD">) | undefined
|
||||
readonly tokens?:
|
||||
| {
|
||||
|
|
@ -779,7 +779,7 @@ export type SessionLogOutput =
|
|||
readonly assistantMessageID: SessionMessage.ID
|
||||
readonly ordinal: number
|
||||
readonly text: string
|
||||
readonly state?: SessionMessage.ProviderState | undefined
|
||||
readonly state?: { readonly [x: string]: unknown } | undefined
|
||||
}
|
||||
}
|
||||
| {
|
||||
|
|
@ -793,7 +793,7 @@ export type SessionLogOutput =
|
|||
readonly sessionID: Session.ID
|
||||
readonly assistantMessageID: SessionMessage.ID
|
||||
readonly ordinal: number
|
||||
readonly state?: SessionMessage.ProviderState | undefined
|
||||
readonly state?: { readonly [x: string]: unknown } | undefined
|
||||
}
|
||||
}
|
||||
| {
|
||||
|
|
@ -808,7 +808,7 @@ export type SessionLogOutput =
|
|||
readonly assistantMessageID: SessionMessage.ID
|
||||
readonly ordinal: number
|
||||
readonly text: string
|
||||
readonly state?: SessionMessage.ProviderState | undefined
|
||||
readonly state?: { readonly [x: string]: unknown } | undefined
|
||||
}
|
||||
}
|
||||
| {
|
||||
|
|
@ -852,7 +852,7 @@ export type SessionLogOutput =
|
|||
readonly id: string
|
||||
readonly input: { readonly [x: string]: unknown }
|
||||
readonly executed: boolean
|
||||
readonly state?: SessionMessage.ProviderState | undefined
|
||||
readonly state?: { readonly [x: string]: unknown } | undefined
|
||||
}
|
||||
}
|
||||
| {
|
||||
|
|
@ -888,7 +888,7 @@ export type SessionLogOutput =
|
|||
]
|
||||
readonly metadata?: { readonly [x: string]: Schema.Json } | undefined
|
||||
readonly executed: boolean
|
||||
readonly resultState?: SessionMessage.ProviderState | undefined
|
||||
readonly resultState?: { readonly [x: string]: unknown } | undefined
|
||||
}
|
||||
}
|
||||
| {
|
||||
|
|
@ -927,7 +927,7 @@ export type SessionLogOutput =
|
|||
| undefined
|
||||
readonly metadata?: { readonly [x: string]: Schema.Json } | undefined
|
||||
readonly executed: boolean
|
||||
readonly resultState?: SessionMessage.ProviderState | undefined
|
||||
readonly resultState?: { readonly [x: string]: unknown } | undefined
|
||||
}
|
||||
}
|
||||
| {
|
||||
|
|
@ -970,7 +970,7 @@ export type SessionLogOutput =
|
|||
readonly sessionID: Session.ID
|
||||
readonly reason: "auto" | "manual"
|
||||
readonly model?: Model.Ref | undefined
|
||||
readonly providerState?: SessionMessage.ProviderState | undefined
|
||||
readonly providerState?: { readonly [x: string]: unknown } | undefined
|
||||
readonly providerContext?:
|
||||
| {
|
||||
readonly version: 1
|
||||
|
|
|
|||
|
|
@ -2300,7 +2300,7 @@ export type SessionMessageInfo =
|
|||
| SessionMessageAssistant
|
||||
| SessionMessageCompaction
|
||||
|
||||
export type SessionMessageInfo1 =
|
||||
export type SessionMessageInfoEncoded =
|
||||
| SessionMessageAgentSelected1
|
||||
| SessionMessageModelSelected1
|
||||
| SessionMessageLocationSwitched1
|
||||
|
|
@ -2355,7 +2355,7 @@ export type SessionForked = {
|
|||
sessionID: string
|
||||
parentID: string
|
||||
boundary: SessionForkBoundary
|
||||
messages?: Array<SessionMessageInfo1>
|
||||
messages?: Array<SessionMessageInfoEncoded>
|
||||
instructions?: { [x: string]: string }
|
||||
instructionEntries?: InstructionEntrySnapshot
|
||||
}
|
||||
|
|
|
|||
|
|
@ -354,7 +354,7 @@ const layer = Layer.effect(
|
|||
sessionID,
|
||||
parentID: parent.id,
|
||||
boundary: { ...input.boundary, messageID: boundary.id },
|
||||
messages,
|
||||
messages: messages === undefined ? undefined : Schema.encodeSync(Schema.Array(SessionMessage.Info))(messages),
|
||||
...inherited,
|
||||
})
|
||||
return yield* result.get(sessionID).pipe(Effect.orDie)
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ const projectFork = Effect.fn("SessionProjector.projectFork")(function* (
|
|||
.insert(SessionMessageTable)
|
||||
.values(
|
||||
event.data.messages.map((message, index) => {
|
||||
const { id: _, type, ...data } = Schema.encodeSync(SessionMessage.Info)(message)
|
||||
const { id: _, type, ...data } = message
|
||||
return {
|
||||
id: SessionMessage.ID.make(`${SessionMessage.ID.fromEvent(event.id)}_${index + 1}`),
|
||||
session_id: event.data.sessionID,
|
||||
|
|
|
|||
|
|
@ -590,6 +590,9 @@ describe("Session.create", () => {
|
|||
const original = yield* session.context(forked.id)
|
||||
expect(calls).toEqual([2])
|
||||
expect(original).toMatchObject([{ type: "synthetic", text: "Filtered note" }])
|
||||
const event = Array.from(yield* Stream.runCollect(logEvents(session, forked.id)))[0]
|
||||
if (event.type !== "session.forked") return yield* Effect.die(new Error("Fork event not found"))
|
||||
expect(typeof event.data.messages?.[0].time.created).toBe("number")
|
||||
expect((yield* session.context(parent.id))[1]).toMatchObject({ text: "Original note" })
|
||||
const recorded = yield* db.select().from(EventTable).where(eq(EventTable.aggregate_id, forked.id)).get()
|
||||
if (!recorded) return yield* Effect.die(new Error("Fork event not found"))
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ export const Forked = Event.durable({
|
|||
parentID: SessionID,
|
||||
boundary: SessionFork.Boundary,
|
||||
/** Frozen plugin-selected history. Omitted for ordinary boundary-based forks. */
|
||||
messages: Schema.Array(SessionMessage.Info).pipe(optional),
|
||||
messages: Schema.Array(SessionMessage.InfoEncoded).pipe(optional),
|
||||
instructions: Instruction.Values.pipe(optional),
|
||||
instructionEntries: InstructionEntry.Snapshot.pipe(optional),
|
||||
},
|
||||
|
|
|
|||
|
|
@ -296,3 +296,6 @@ export type Info =
|
|||
| Assistant
|
||||
| Compaction
|
||||
export type Type = Info["type"]
|
||||
|
||||
export const InfoEncoded = Schema.toEncoded(Info).annotate({ identifier: "Session.Message.Info.Encoded" })
|
||||
export type InfoEncoded = typeof InfoEncoded.Type
|
||||
|
|
|
|||
|
|
@ -1621,14 +1621,7 @@
|
|||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/SessionNotFoundErrorEncoded"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/SessionNotFoundErrorEncoded"
|
||||
}
|
||||
]
|
||||
"$ref": "#/components/schemas/SessionNotFoundErrorEncoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1621,14 +1621,7 @@
|
|||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/SessionNotFoundErrorEncoded"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/SessionNotFoundErrorEncoded"
|
||||
}
|
||||
]
|
||||
"$ref": "#/components/schemas/SessionNotFoundErrorEncoded"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue