refactor(schema): apply session review decisions (#35793)
This commit is contained in:
parent
d27746e5b3
commit
ed6ad272ec
142 changed files with 4239 additions and 3174 deletions
|
|
@ -12,9 +12,14 @@ import { FileAttachment, Prompt } from "./prompt.js"
|
|||
import { SessionID } from "./session-id.js"
|
||||
import { Location } from "./location.js"
|
||||
import { SessionMessage } from "./session-message.js"
|
||||
import { Revert } from "./revert.js"
|
||||
import { Revert } from "./session-revert.js"
|
||||
import { Shell as ShellSchema } from "./shell.js"
|
||||
import { SessionError } from "./session-error.js"
|
||||
import { Agent } from "./agent.js"
|
||||
import { Skill as SkillSchema } from "./skill.js"
|
||||
import { Money } from "./money.js"
|
||||
import { Snapshot } from "./snapshot.js"
|
||||
import { TokenUsage } from "./token-usage.js"
|
||||
|
||||
export { FileAttachment }
|
||||
|
||||
|
|
@ -23,22 +28,13 @@ export const Source = Schema.Struct({
|
|||
end: NonNegativeInt,
|
||||
text: Schema.String,
|
||||
}).annotate({
|
||||
identifier: "session.event.source",
|
||||
identifier: "Session.Event.Source",
|
||||
})
|
||||
export interface Source extends Schema.Schema.Type<typeof Source> {}
|
||||
|
||||
const Base = {
|
||||
sessionID: SessionID,
|
||||
}
|
||||
const Tokens = Schema.Struct({
|
||||
input: Schema.Finite,
|
||||
output: Schema.Finite,
|
||||
reasoning: Schema.Finite,
|
||||
cache: Schema.Struct({
|
||||
read: Schema.Finite,
|
||||
write: Schema.Finite,
|
||||
}),
|
||||
})
|
||||
const PromptFields = {
|
||||
...Base,
|
||||
inputID: SessionMessage.ID,
|
||||
|
|
@ -57,7 +53,7 @@ export const AgentSelected = Event.durable({
|
|||
...options,
|
||||
schema: {
|
||||
...Base,
|
||||
agent: Schema.String,
|
||||
agent: Agent.ID,
|
||||
},
|
||||
})
|
||||
export type AgentSelected = typeof AgentSelected.Type
|
||||
|
|
@ -97,8 +93,8 @@ export const UsageUpdated = Event.ephemeral({
|
|||
type: "session.usage.updated",
|
||||
schema: {
|
||||
...Base,
|
||||
cost: Schema.Finite,
|
||||
tokens: Tokens,
|
||||
cost: Money.USD,
|
||||
tokens: TokenUsage.Info,
|
||||
},
|
||||
})
|
||||
export type UsageUpdated = typeof UsageUpdated.Type
|
||||
|
|
@ -191,7 +187,8 @@ export namespace Skill {
|
|||
...options,
|
||||
schema: {
|
||||
...Base,
|
||||
name: Schema.String,
|
||||
id: SkillSchema.ID,
|
||||
name: SkillSchema.Name,
|
||||
text: Schema.String,
|
||||
},
|
||||
})
|
||||
|
|
@ -228,9 +225,9 @@ export namespace Step {
|
|||
schema: {
|
||||
...Base,
|
||||
assistantMessageID: SessionMessage.ID,
|
||||
agent: Schema.String,
|
||||
agent: Agent.ID,
|
||||
model: Model.Ref,
|
||||
snapshot: Schema.String.pipe(optional),
|
||||
snapshot: Snapshot.ID.pipe(optional),
|
||||
},
|
||||
})
|
||||
export type Started = typeof Started.Type
|
||||
|
|
@ -242,9 +239,9 @@ export namespace Step {
|
|||
...Base,
|
||||
assistantMessageID: SessionMessage.ID,
|
||||
finish: FinishReason,
|
||||
cost: Schema.Finite,
|
||||
tokens: Tokens,
|
||||
snapshot: Schema.String.pipe(optional),
|
||||
cost: Money.USD,
|
||||
tokens: TokenUsage.Info,
|
||||
snapshot: Snapshot.ID.pipe(optional),
|
||||
files: Schema.Array(RelativePath).pipe(optional),
|
||||
},
|
||||
})
|
||||
|
|
@ -257,8 +254,8 @@ export namespace Step {
|
|||
...Base,
|
||||
assistantMessageID: SessionMessage.ID,
|
||||
error: SessionError.Error,
|
||||
cost: Schema.Finite.pipe(optional),
|
||||
tokens: Tokens.pipe(optional),
|
||||
cost: Money.USD.pipe(optional),
|
||||
tokens: TokenUsage.Info.pipe(optional),
|
||||
},
|
||||
})
|
||||
export type Failed = typeof Failed.Type
|
||||
|
|
@ -413,7 +410,6 @@ export namespace Tool {
|
|||
...ToolBase,
|
||||
structured: Schema.Record(Schema.String, Schema.Unknown),
|
||||
content: Schema.Array(ToolContent),
|
||||
outputPaths: Schema.Array(Schema.String).pipe(optional),
|
||||
result: Schema.Unknown.pipe(optional),
|
||||
executed: Schema.Boolean,
|
||||
resultState: SessionMessage.ProviderState.pipe(optional),
|
||||
|
|
@ -464,7 +460,9 @@ export namespace Compaction {
|
|||
...options,
|
||||
schema: {
|
||||
...Base,
|
||||
reason: Schema.Union([Schema.Literal("auto"), Schema.Literal("manual")]),
|
||||
reason: Schema.Literals(["auto", "manual"]),
|
||||
recent: Schema.String,
|
||||
inputID: SessionMessage.ID.pipe(optional),
|
||||
},
|
||||
})
|
||||
export type Started = typeof Started.Type
|
||||
|
|
@ -493,7 +491,12 @@ export namespace Compaction {
|
|||
export const Failed = Event.durable({
|
||||
type: "session.compaction.failed",
|
||||
...options,
|
||||
schema: Base,
|
||||
schema: {
|
||||
...Base,
|
||||
reason: Started.data.fields.reason,
|
||||
error: SessionError.Error,
|
||||
inputID: SessionMessage.ID.pipe(optional),
|
||||
},
|
||||
})
|
||||
export type Failed = typeof Failed.Type
|
||||
}
|
||||
|
|
@ -502,7 +505,7 @@ export namespace RevertEvent {
|
|||
export const Staged = Event.durable({
|
||||
type: "session.revert.staged",
|
||||
...options,
|
||||
schema: { ...Base, revert: Revert.State },
|
||||
schema: { ...Base, revert: Revert },
|
||||
})
|
||||
export const Cleared = Event.durable({ type: "session.revert.cleared", ...options, schema: Base })
|
||||
export const Committed = Event.durable({
|
||||
|
|
@ -564,7 +567,7 @@ export const DurableDefinitions = Event.inventory(
|
|||
|
||||
export const Durable = Schema.Union(DurableDefinitions, { mode: "oneOf" })
|
||||
.pipe(Schema.toTaggedUnion("type"))
|
||||
.annotate({ identifier: "SessionDurableEvent" })
|
||||
.annotate({ identifier: "Session.Event.Durable" })
|
||||
export type DurableEvent = typeof Durable.Type
|
||||
|
||||
export const All = Schema.Union(Definitions, { mode: "oneOf" }).pipe(Schema.toTaggedUnion("type"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue