fix(core): separate interruption from finish
This commit is contained in:
parent
db664db5f3
commit
fd229f7edf
12 changed files with 141 additions and 18 deletions
|
|
@ -165,7 +165,8 @@ export namespace Step {
|
|||
schema: {
|
||||
...Base,
|
||||
assistantMessageID: SessionMessage.ID,
|
||||
finish: SessionMessage.Finish,
|
||||
// Step.Ended v2 was originally persisted with an open string schema.
|
||||
finish: Schema.String,
|
||||
cost: Schema.Finite,
|
||||
tokens: Schema.Struct({
|
||||
input: Schema.Finite,
|
||||
|
|
|
|||
|
|
@ -28,10 +28,12 @@ export const Finish = Schema.Literals([
|
|||
"content-filter",
|
||||
"error",
|
||||
"unknown",
|
||||
"interrupted",
|
||||
])
|
||||
export type Finish = typeof Finish.Type
|
||||
|
||||
export const Settlement = Schema.Literals(["completed", "failed", "interrupted"])
|
||||
export type Settlement = typeof Settlement.Type
|
||||
|
||||
const Base = {
|
||||
id: ID,
|
||||
metadata: Schema.Record(Schema.String, Schema.Unknown).pipe(optional),
|
||||
|
|
@ -180,7 +182,9 @@ export const Assistant = Schema.Struct({
|
|||
end: Schema.String.pipe(optional),
|
||||
files: Schema.Array(RelativePath).pipe(optional),
|
||||
}).pipe(optional),
|
||||
finish: Finish.pipe(optional),
|
||||
// Projected histories predate the typed provider finish model and may contain arbitrary values.
|
||||
finish: Schema.String.pipe(optional),
|
||||
settlement: Settlement.pipe(optional),
|
||||
cost: Schema.Finite.pipe(optional),
|
||||
tokens: Schema.Struct({
|
||||
input: Schema.Finite,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { describe, expect, test } from "bun:test"
|
||||
import { Schema } from "effect"
|
||||
import { FileSystem, Integration, Permission, Project, Reference, Session, Workspace } from "../src"
|
||||
import { EventManifest } from "../src/event-manifest"
|
||||
import { IdeEvent } from "../src/ide-event"
|
||||
|
|
@ -53,4 +54,17 @@ describe("public event manifest", () => {
|
|||
expect(EventManifest.Durable.has("session.next.step.ended.1")).toBe(false)
|
||||
expect(EventManifest.Durable.get("session.next.step.ended.2")).toBe(SessionEvent.Step.Ended)
|
||||
})
|
||||
|
||||
test("decodes legacy Step.Ended v2 finish strings", () => {
|
||||
const event = Schema.decodeUnknownSync(SessionEvent.Step.Ended.data)({
|
||||
sessionID: "ses_legacy",
|
||||
timestamp: 0,
|
||||
assistantMessageID: "msg_legacy",
|
||||
finish: "legacy-provider-reason",
|
||||
cost: 0,
|
||||
tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
|
||||
})
|
||||
|
||||
expect(event.finish).toBe("legacy-provider-reason")
|
||||
})
|
||||
})
|
||||
|
|
|
|||
22
packages/schema/test/session-message.test.ts
Normal file
22
packages/schema/test/session-message.test.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import { expect, test } from "bun:test"
|
||||
import { Schema } from "effect"
|
||||
import { SessionMessage } from "../src/session-message"
|
||||
|
||||
test("does not model interruption as a provider finish reason", () => {
|
||||
expect(() => Schema.decodeUnknownSync(SessionMessage.Finish)("interrupted")).toThrow()
|
||||
expect(Schema.decodeUnknownSync(SessionMessage.Finish)("error")).toBe("error")
|
||||
})
|
||||
|
||||
test("decodes projected assistant histories with arbitrary finish strings", () => {
|
||||
const message = Schema.decodeUnknownSync(SessionMessage.Message)({
|
||||
id: "msg_legacy",
|
||||
type: "assistant",
|
||||
agent: "build",
|
||||
model: { id: "model", providerID: "provider" },
|
||||
content: [],
|
||||
finish: "legacy-provider-reason",
|
||||
time: { created: 0, completed: 1 },
|
||||
})
|
||||
|
||||
expect(message).toMatchObject({ type: "assistant", finish: "legacy-provider-reason" })
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue