refactor(schema): declare event durability at definition level (#35172)
This commit is contained in:
parent
bd8d858bf7
commit
de476aa51b
53 changed files with 700 additions and 1165 deletions
|
|
@ -51,7 +51,7 @@ const stepSettlementOptions = {
|
|||
export const UnknownError = SessionMessage.UnknownError
|
||||
export type UnknownError = SessionMessage.UnknownError
|
||||
|
||||
export const AgentSwitched = Event.define({
|
||||
export const AgentSwitched = Event.durable({
|
||||
type: "session.next.agent.switched",
|
||||
...options,
|
||||
schema: {
|
||||
|
|
@ -62,7 +62,7 @@ export const AgentSwitched = Event.define({
|
|||
})
|
||||
export type AgentSwitched = typeof AgentSwitched.Type
|
||||
|
||||
export const ModelSwitched = Event.define({
|
||||
export const ModelSwitched = Event.durable({
|
||||
type: "session.next.model.switched",
|
||||
...options,
|
||||
schema: {
|
||||
|
|
@ -73,7 +73,7 @@ export const ModelSwitched = Event.define({
|
|||
})
|
||||
export type ModelSwitched = typeof ModelSwitched.Type
|
||||
|
||||
export const Moved = Event.define({
|
||||
export const Moved = Event.durable({
|
||||
type: "session.next.moved",
|
||||
...options,
|
||||
schema: {
|
||||
|
|
@ -84,7 +84,7 @@ export const Moved = Event.define({
|
|||
})
|
||||
export type Moved = typeof Moved.Type
|
||||
|
||||
export const Renamed = Event.define({
|
||||
export const Renamed = Event.durable({
|
||||
type: "session.next.renamed",
|
||||
...options,
|
||||
schema: {
|
||||
|
|
@ -94,7 +94,7 @@ export const Renamed = Event.define({
|
|||
})
|
||||
export type Renamed = typeof Renamed.Type
|
||||
|
||||
export const Forked = Event.define({
|
||||
export const Forked = Event.durable({
|
||||
type: "session.next.forked",
|
||||
...options,
|
||||
schema: {
|
||||
|
|
@ -105,21 +105,21 @@ export const Forked = Event.define({
|
|||
})
|
||||
export type Forked = typeof Forked.Type
|
||||
|
||||
export const Prompted = Event.define({
|
||||
export const Prompted = Event.durable({
|
||||
type: "session.next.prompted",
|
||||
...options,
|
||||
schema: PromptFields,
|
||||
})
|
||||
export type Prompted = typeof Prompted.Type
|
||||
|
||||
export const PromptAdmitted = Event.define({
|
||||
export const PromptAdmitted = Event.durable({
|
||||
type: "session.next.prompt.admitted",
|
||||
...options,
|
||||
schema: PromptFields,
|
||||
})
|
||||
export type PromptAdmitted = typeof PromptAdmitted.Type
|
||||
|
||||
export const ExecutionSettled = Event.define({
|
||||
export const ExecutionSettled = Event.ephemeral({
|
||||
type: "session.next.execution.settled",
|
||||
schema: {
|
||||
...Base,
|
||||
|
|
@ -129,7 +129,7 @@ export const ExecutionSettled = Event.define({
|
|||
})
|
||||
export type ExecutionSettled = typeof ExecutionSettled.Type
|
||||
|
||||
export const ContextUpdated = Event.define({
|
||||
export const ContextUpdated = Event.durable({
|
||||
type: "session.next.context.updated",
|
||||
...options,
|
||||
schema: {
|
||||
|
|
@ -140,7 +140,7 @@ export const ContextUpdated = Event.define({
|
|||
})
|
||||
export type ContextUpdated = typeof ContextUpdated.Type
|
||||
|
||||
export const Synthetic = Event.define({
|
||||
export const Synthetic = Event.durable({
|
||||
type: "session.next.synthetic",
|
||||
...options,
|
||||
schema: {
|
||||
|
|
@ -154,7 +154,7 @@ export const Synthetic = Event.define({
|
|||
export type Synthetic = typeof Synthetic.Type
|
||||
|
||||
export namespace Skill {
|
||||
export const Activated = Event.define({
|
||||
export const Activated = Event.durable({
|
||||
type: "session.next.skill.activated",
|
||||
...options,
|
||||
schema: {
|
||||
|
|
@ -168,7 +168,7 @@ export namespace Skill {
|
|||
}
|
||||
|
||||
export namespace Shell {
|
||||
export const Started = Event.define({
|
||||
export const Started = Event.durable({
|
||||
type: "session.next.shell.started",
|
||||
...options,
|
||||
schema: {
|
||||
|
|
@ -180,7 +180,7 @@ export namespace Shell {
|
|||
})
|
||||
export type Started = typeof Started.Type
|
||||
|
||||
export const Ended = Event.define({
|
||||
export const Ended = Event.durable({
|
||||
type: "session.next.shell.ended",
|
||||
...options,
|
||||
schema: {
|
||||
|
|
@ -193,7 +193,7 @@ export namespace Shell {
|
|||
}
|
||||
|
||||
export namespace Step {
|
||||
export const Started = Event.define({
|
||||
export const Started = Event.durable({
|
||||
type: "session.next.step.started",
|
||||
...options,
|
||||
schema: {
|
||||
|
|
@ -206,7 +206,7 @@ export namespace Step {
|
|||
})
|
||||
export type Started = typeof Started.Type
|
||||
|
||||
export const Ended = Event.define({
|
||||
export const Ended = Event.durable({
|
||||
type: "session.next.step.ended",
|
||||
...stepSettlementOptions,
|
||||
schema: {
|
||||
|
|
@ -229,7 +229,7 @@ export namespace Step {
|
|||
})
|
||||
export type Ended = typeof Ended.Type
|
||||
|
||||
export const Failed = Event.define({
|
||||
export const Failed = Event.durable({
|
||||
type: "session.next.step.failed",
|
||||
...stepSettlementOptions,
|
||||
schema: {
|
||||
|
|
@ -242,7 +242,7 @@ export namespace Step {
|
|||
}
|
||||
|
||||
export namespace Text {
|
||||
export const Started = Event.define({
|
||||
export const Started = Event.durable({
|
||||
type: "session.next.text.started",
|
||||
...options,
|
||||
schema: {
|
||||
|
|
@ -254,7 +254,7 @@ export namespace Text {
|
|||
export type Started = typeof Started.Type
|
||||
|
||||
// Stream fragments are live-only; Text.Ended is the replayable full-value boundary.
|
||||
export const Delta = Event.define({
|
||||
export const Delta = Event.ephemeral({
|
||||
type: "session.next.text.delta",
|
||||
schema: {
|
||||
...Base,
|
||||
|
|
@ -265,7 +265,7 @@ export namespace Text {
|
|||
})
|
||||
export type Delta = typeof Delta.Type
|
||||
|
||||
export const Ended = Event.define({
|
||||
export const Ended = Event.durable({
|
||||
type: "session.next.text.ended",
|
||||
...options,
|
||||
schema: {
|
||||
|
|
@ -279,7 +279,7 @@ export namespace Text {
|
|||
}
|
||||
|
||||
export namespace Reasoning {
|
||||
export const Started = Event.define({
|
||||
export const Started = Event.durable({
|
||||
type: "session.next.reasoning.started",
|
||||
...options,
|
||||
schema: {
|
||||
|
|
@ -292,7 +292,7 @@ export namespace Reasoning {
|
|||
export type Started = typeof Started.Type
|
||||
|
||||
// Stream fragments are live-only; Reasoning.Ended is the replayable full-value boundary.
|
||||
export const Delta = Event.define({
|
||||
export const Delta = Event.ephemeral({
|
||||
type: "session.next.reasoning.delta",
|
||||
schema: {
|
||||
...Base,
|
||||
|
|
@ -303,7 +303,7 @@ export namespace Reasoning {
|
|||
})
|
||||
export type Delta = typeof Delta.Type
|
||||
|
||||
export const Ended = Event.define({
|
||||
export const Ended = Event.durable({
|
||||
type: "session.next.reasoning.ended",
|
||||
...options,
|
||||
schema: {
|
||||
|
|
@ -325,7 +325,7 @@ export namespace Tool {
|
|||
}
|
||||
|
||||
export namespace Input {
|
||||
export const Started = Event.define({
|
||||
export const Started = Event.durable({
|
||||
type: "session.next.tool.input.started",
|
||||
...options,
|
||||
schema: {
|
||||
|
|
@ -336,7 +336,7 @@ export namespace Tool {
|
|||
export type Started = typeof Started.Type
|
||||
|
||||
// Stream fragments are live-only; Input.Ended is the replayable raw-input boundary.
|
||||
export const Delta = Event.define({
|
||||
export const Delta = Event.ephemeral({
|
||||
type: "session.next.tool.input.delta",
|
||||
schema: {
|
||||
...ToolBase,
|
||||
|
|
@ -345,7 +345,7 @@ export namespace Tool {
|
|||
})
|
||||
export type Delta = typeof Delta.Type
|
||||
|
||||
export const Ended = Event.define({
|
||||
export const Ended = Event.durable({
|
||||
type: "session.next.tool.input.ended",
|
||||
...options,
|
||||
schema: {
|
||||
|
|
@ -356,7 +356,7 @@ export namespace Tool {
|
|||
export type Ended = typeof Ended.Type
|
||||
}
|
||||
|
||||
export const Called = Event.define({
|
||||
export const Called = Event.durable({
|
||||
type: "session.next.tool.called",
|
||||
...options,
|
||||
schema: {
|
||||
|
|
@ -375,7 +375,7 @@ export namespace Tool {
|
|||
* Replayable bounded running-tool state. Tools should checkpoint semantic
|
||||
* transitions or at a bounded cadence, not persist every stdout/stderr chunk.
|
||||
*/
|
||||
export const Progress = Event.define({
|
||||
export const Progress = Event.durable({
|
||||
type: "session.next.tool.progress",
|
||||
...options,
|
||||
schema: {
|
||||
|
|
@ -386,7 +386,7 @@ export namespace Tool {
|
|||
})
|
||||
export type Progress = typeof Progress.Type
|
||||
|
||||
export const Success = Event.define({
|
||||
export const Success = Event.durable({
|
||||
type: "session.next.tool.success",
|
||||
...options,
|
||||
schema: {
|
||||
|
|
@ -403,7 +403,7 @@ export namespace Tool {
|
|||
})
|
||||
export type Success = typeof Success.Type
|
||||
|
||||
export const Failed = Event.define({
|
||||
export const Failed = Event.durable({
|
||||
type: "session.next.tool.failed",
|
||||
...options,
|
||||
schema: {
|
||||
|
|
@ -431,7 +431,7 @@ export const RetryError = Schema.Struct({
|
|||
})
|
||||
export interface RetryError extends Schema.Schema.Type<typeof RetryError> {}
|
||||
|
||||
export const Retried = Event.define({
|
||||
export const Retried = Event.durable({
|
||||
type: "session.next.retried",
|
||||
...options,
|
||||
schema: {
|
||||
|
|
@ -443,7 +443,7 @@ export const Retried = Event.define({
|
|||
export type Retried = typeof Retried.Type
|
||||
|
||||
export namespace Compaction {
|
||||
export const Started = Event.define({
|
||||
export const Started = Event.durable({
|
||||
type: "session.next.compaction.started",
|
||||
...options,
|
||||
schema: {
|
||||
|
|
@ -454,7 +454,7 @@ export namespace Compaction {
|
|||
})
|
||||
export type Started = typeof Started.Type
|
||||
|
||||
export const Delta = Event.define({
|
||||
export const Delta = Event.ephemeral({
|
||||
type: "session.next.compaction.delta",
|
||||
schema: {
|
||||
...Base,
|
||||
|
|
@ -464,7 +464,7 @@ export namespace Compaction {
|
|||
})
|
||||
export type Delta = typeof Delta.Type
|
||||
|
||||
export const Ended = Event.define({
|
||||
export const Ended = Event.durable({
|
||||
type: "session.next.compaction.ended",
|
||||
...options,
|
||||
schema: {
|
||||
|
|
@ -479,53 +479,19 @@ export namespace Compaction {
|
|||
}
|
||||
|
||||
export namespace RevertEvent {
|
||||
export const Staged = Event.define({
|
||||
export const Staged = Event.durable({
|
||||
type: "session.next.revert.staged",
|
||||
...options,
|
||||
schema: { ...Base, revert: Revert.State },
|
||||
})
|
||||
export const Cleared = Event.define({ type: "session.next.revert.cleared", ...options, schema: Base })
|
||||
export const Committed = Event.define({
|
||||
export const Cleared = Event.durable({ type: "session.next.revert.cleared", ...options, schema: Base })
|
||||
export const Committed = Event.durable({
|
||||
type: "session.next.revert.committed",
|
||||
...options,
|
||||
schema: { ...Base, messageID: SessionMessage.ID },
|
||||
})
|
||||
}
|
||||
|
||||
export const DurableDefinitions = Event.inventory(
|
||||
AgentSwitched,
|
||||
ModelSwitched,
|
||||
Moved,
|
||||
Renamed,
|
||||
Forked,
|
||||
Prompted,
|
||||
PromptAdmitted,
|
||||
ContextUpdated,
|
||||
Synthetic,
|
||||
Skill.Activated,
|
||||
Shell.Started,
|
||||
Shell.Ended,
|
||||
Step.Started,
|
||||
Step.Ended,
|
||||
Step.Failed,
|
||||
Text.Started,
|
||||
Text.Ended,
|
||||
Tool.Input.Started,
|
||||
Tool.Input.Ended,
|
||||
Tool.Called,
|
||||
Tool.Progress,
|
||||
Tool.Success,
|
||||
Tool.Failed,
|
||||
Reasoning.Started,
|
||||
Reasoning.Ended,
|
||||
Retried,
|
||||
Compaction.Started,
|
||||
Compaction.Ended,
|
||||
RevertEvent.Staged,
|
||||
RevertEvent.Cleared,
|
||||
RevertEvent.Committed,
|
||||
)
|
||||
|
||||
export const Definitions = Event.inventory(
|
||||
AgentSwitched,
|
||||
ModelSwitched,
|
||||
|
|
@ -565,6 +531,10 @@ export const Definitions = Event.inventory(
|
|||
RevertEvent.Committed,
|
||||
)
|
||||
|
||||
export const DurableDefinitions = Event.inventory(
|
||||
...Definitions.filter((definition) => definition.durability === "durable"),
|
||||
)
|
||||
|
||||
export const Durable = Schema.Union(DurableDefinitions, { mode: "oneOf" })
|
||||
.pipe(Schema.toTaggedUnion("type"))
|
||||
.annotate({ identifier: "SessionDurableEvent" })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue