| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662 |
- export * as SessionEvent from "./session-event.js"
- import { Schema } from "effect"
- import { optional } from "./schema.js"
- import { Event } from "./event.js"
- import { FinishReason } from "./llm.js"
- import { Content } from "./tool.js"
- import { Model } from "./model.js"
- import { NonNegativeInt, PositiveInt, RelativePath } from "./schema.js"
- import { FileAttachment } from "./prompt.js"
- import { SessionID } from "./session-id.js"
- import { Location } from "./location.js"
- import { SessionMessage } from "./session-message.js"
- import { Revert } from "./session-revert.js"
- import { Shell as ShellSchema } from "./shell.js"
- import { SessionError } from "./session-error.js"
- import { Instruction } from "./instruction.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"
- import { SessionPending } from "./session-pending.js"
- import { Project } from "./project.js"
- import { SessionFork } from "./session-fork.js"
- export { FileAttachment }
- export const Source = Schema.Struct({
- start: NonNegativeInt,
- end: NonNegativeInt,
- text: Schema.String,
- }).annotate({
- identifier: "Session.Event.Source",
- })
- export interface Source extends Schema.Schema.Type<typeof Source> {}
- const Base = {
- sessionID: SessionID,
- }
- const options = {
- durable: {
- aggregate: "sessionID",
- version: 1,
- },
- } as const
- export const Created = Event.durable({
- type: "session.created",
- ...options,
- schema: {
- ...Base,
- projectID: Project.ID,
- location: Location.Ref,
- subpath: RelativePath.pipe(optional),
- parentID: SessionID.pipe(optional),
- slug: Schema.String,
- title: Schema.String.pipe(optional),
- agent: Agent.ID.pipe(optional),
- model: Model.Ref.pipe(optional),
- version: Schema.String,
- },
- })
- export type Created = typeof Created.Type
- export const AgentSelected = Event.durable({
- type: "session.agent.selected",
- ...options,
- schema: {
- ...Base,
- agent: Agent.ID,
- },
- })
- export type AgentSelected = typeof AgentSelected.Type
- export const ModelSelected = Event.durable({
- type: "session.model.selected",
- ...options,
- schema: {
- ...Base,
- model: Model.Ref,
- },
- })
- export type ModelSelected = typeof ModelSelected.Type
- export const Moved = Event.durable({
- type: "session.moved",
- ...options,
- schema: {
- ...Base,
- location: Location.Ref,
- projectID: Project.ID.pipe(optional),
- subpath: RelativePath.pipe(optional),
- },
- })
- export type Moved = typeof Moved.Type
- export const Renamed = Event.durable({
- type: "session.renamed",
- ...options,
- schema: {
- ...Base,
- title: Schema.String,
- },
- })
- export type Renamed = typeof Renamed.Type
- export const UsageRecorded = Event.durable({
- type: "session.usage.recorded",
- ...options,
- schema: {
- ...Base,
- source: Schema.Literals(["title", "compaction"]),
- cost: Money.USD,
- tokens: TokenUsage.Info,
- },
- })
- export type UsageRecorded = typeof UsageRecorded.Type
- export const UsageUpdated = Event.ephemeral({
- type: "session.usage.updated",
- schema: {
- ...Base,
- cost: Money.USD,
- tokens: TokenUsage.Info,
- },
- })
- export type UsageUpdated = typeof UsageUpdated.Type
- export const Deleted = Event.durable({
- type: "session.deleted",
- durable: {
- aggregate: "sessionID",
- version: 2,
- },
- schema: Base,
- })
- export type Deleted = typeof Deleted.Type
- export const Forked = Event.durable({
- type: "session.forked",
- durable: {
- aggregate: "sessionID",
- version: 2,
- },
- schema: {
- ...Base,
- parentID: SessionID,
- boundary: SessionFork.Boundary,
- instructions: Instruction.Values.pipe(optional),
- },
- })
- export type Forked = typeof Forked.Type
- const InputRef = {
- ...Base,
- inputID: SessionMessage.ID,
- }
- export const InputPromoted = Event.durable({
- type: "session.input.promoted",
- ...options,
- schema: InputRef,
- })
- export type InputPromoted = typeof InputPromoted.Type
- export const InputAdmitted = Event.durable({
- type: "session.input.admitted",
- ...options,
- schema: {
- ...InputRef,
- input: SessionPending.Message,
- },
- })
- export type InputAdmitted = typeof InputAdmitted.Type
- export const InputCancelled = Event.durable({
- type: "session.input.cancelled",
- ...options,
- schema: InputRef,
- })
- export type InputCancelled = typeof InputCancelled.Type
- export const InputSteered = Event.durable({
- type: "session.input.steered",
- ...options,
- schema: InputRef,
- })
- export type InputSteered = typeof InputSteered.Type
- export const InputQueued = Event.durable({
- type: "session.input.queued",
- ...options,
- schema: InputRef,
- })
- export type InputQueued = typeof InputQueued.Type
- export namespace Execution {
- export const Started = Event.durable({ type: "session.execution.started", ...options, schema: Base })
- export type Started = typeof Started.Type
- export const Succeeded = Event.durable({ type: "session.execution.succeeded", ...options, schema: Base })
- export type Succeeded = typeof Succeeded.Type
- export const Failed = Event.durable({
- type: "session.execution.failed",
- ...options,
- schema: { ...Base, error: SessionError.Error },
- })
- export type Failed = typeof Failed.Type
- export const Interrupted = Event.durable({
- type: "session.execution.interrupted",
- ...options,
- schema: { ...Base, reason: Schema.Literals(["user", "shutdown", "superseded"]) },
- })
- export type Interrupted = typeof Interrupted.Type
- }
- export const InstructionsUpdated = Event.durable({
- type: "session.instructions.updated",
- durable: {
- aggregate: "sessionID",
- version: 2,
- },
- schema: {
- ...Base,
- delta: Instruction.Delta,
- /**
- * The rendered chronological update shown to the model, frozen at emit time.
- * Absent for the initial baseline observation and for deltas that render empty.
- */
- text: Schema.String.pipe(optional),
- },
- })
- export type InstructionsUpdated = typeof InstructionsUpdated.Type
- export const Synthetic = Event.durable({
- type: "session.synthetic",
- ...options,
- schema: {
- ...Base,
- text: Schema.String,
- description: Schema.String.pipe(optional),
- metadata: Schema.Record(Schema.String, Schema.Unknown).pipe(optional),
- },
- })
- export type Synthetic = typeof Synthetic.Type
- export namespace Skill {
- export const Activated = Event.durable({
- type: "session.skill.activated",
- ...options,
- schema: {
- ...Base,
- id: SkillSchema.ID,
- name: SkillSchema.Name,
- text: Schema.String,
- },
- })
- export type Activated = typeof Activated.Type
- }
- export namespace Shell {
- export const Started = Event.durable({
- type: "session.shell.started",
- ...options,
- schema: {
- ...Base,
- shell: ShellSchema.Info,
- },
- })
- export type Started = typeof Started.Type
- export const Ended = Event.durable({
- type: "session.shell.ended",
- ...options,
- schema: {
- ...Base,
- shell: ShellSchema.Info,
- output: ShellSchema.Output,
- },
- })
- export type Ended = typeof Ended.Type
- }
- export namespace Step {
- export const Started = Event.durable({
- type: "session.step.started",
- ...options,
- schema: {
- ...Base,
- assistantMessageID: SessionMessage.ID,
- agent: Agent.ID,
- model: Model.Ref,
- snapshot: Snapshot.ID.pipe(optional),
- },
- })
- export type Started = typeof Started.Type
- export const Ended = Event.durable({
- type: "session.step.ended",
- ...options,
- schema: {
- ...Base,
- assistantMessageID: SessionMessage.ID,
- finish: FinishReason,
- cost: Money.USD,
- tokens: TokenUsage.Info,
- snapshot: Snapshot.ID.pipe(optional),
- files: Schema.Array(RelativePath).pipe(optional),
- },
- })
- export type Ended = typeof Ended.Type
- export const Failed = Event.durable({
- type: "session.step.failed",
- ...options,
- schema: {
- ...Base,
- assistantMessageID: SessionMessage.ID,
- error: SessionError.Error,
- cost: Money.USD.pipe(optional),
- tokens: TokenUsage.Info.pipe(optional),
- snapshot: Snapshot.ID.pipe(optional),
- files: Schema.Array(RelativePath).pipe(optional),
- },
- })
- export type Failed = typeof Failed.Type
- }
- export namespace Text {
- export const Started = Event.durable({
- type: "session.text.started",
- ...options,
- schema: {
- ...Base,
- assistantMessageID: SessionMessage.ID,
- ordinal: NonNegativeInt,
- },
- })
- export type Started = typeof Started.Type
- // Stream fragments are live-only; Text.Ended is the replayable full-value boundary.
- export const Delta = Event.ephemeral({
- type: "session.text.delta",
- schema: {
- ...Base,
- assistantMessageID: SessionMessage.ID,
- ordinal: NonNegativeInt,
- delta: Schema.String,
- },
- })
- export type Delta = typeof Delta.Type
- export const Ended = Event.durable({
- type: "session.text.ended",
- ...options,
- schema: {
- ...Base,
- assistantMessageID: SessionMessage.ID,
- ordinal: NonNegativeInt,
- text: Schema.String,
- state: SessionMessage.ProviderState.pipe(optional),
- },
- })
- export type Ended = typeof Ended.Type
- }
- export namespace Reasoning {
- export const Started = Event.durable({
- type: "session.reasoning.started",
- ...options,
- schema: {
- ...Base,
- assistantMessageID: SessionMessage.ID,
- ordinal: NonNegativeInt,
- state: SessionMessage.ProviderState.pipe(optional),
- },
- })
- export type Started = typeof Started.Type
- // Stream fragments are live-only; Reasoning.Ended is the replayable full-value boundary.
- export const Delta = Event.ephemeral({
- type: "session.reasoning.delta",
- schema: {
- ...Base,
- assistantMessageID: SessionMessage.ID,
- ordinal: NonNegativeInt,
- delta: Schema.String,
- },
- })
- export type Delta = typeof Delta.Type
- export const Ended = Event.durable({
- type: "session.reasoning.ended",
- ...options,
- schema: {
- ...Base,
- assistantMessageID: SessionMessage.ID,
- ordinal: NonNegativeInt,
- text: Schema.String,
- state: SessionMessage.ProviderState.pipe(optional),
- },
- })
- export type Ended = typeof Ended.Type
- }
- export namespace Tool {
- const ToolBase = {
- ...Base,
- assistantMessageID: SessionMessage.ID,
- id: Schema.String,
- }
- export namespace Input {
- export const Started = Event.durable({
- type: "session.tool.input.started",
- ...options,
- schema: {
- ...ToolBase,
- name: Schema.String,
- },
- })
- export type Started = typeof Started.Type
- // Stream fragments are live-only; Input.Ended is the replayable raw-input boundary.
- export const Delta = Event.ephemeral({
- type: "session.tool.input.delta",
- schema: {
- ...ToolBase,
- delta: Schema.String,
- },
- })
- export type Delta = typeof Delta.Type
- export const Ended = Event.durable({
- type: "session.tool.input.ended",
- ...options,
- schema: {
- ...ToolBase,
- text: Schema.String,
- },
- })
- export type Ended = typeof Ended.Type
- }
- export const Called = Event.durable({
- type: "session.tool.called",
- ...options,
- schema: {
- ...ToolBase,
- input: Schema.Record(Schema.String, Schema.Unknown),
- executed: Schema.Boolean,
- state: SessionMessage.ProviderState.pipe(optional),
- },
- })
- export type Called = typeof Called.Type
- /** Live replacement metadata for a running tool. */
- export const Progress = Event.ephemeral({
- type: "session.tool.progress",
- schema: {
- ...ToolBase,
- metadata: Schema.Record(Schema.String, Schema.Json),
- },
- })
- export type Progress = typeof Progress.Type
- /** Canonical terminal success: one non-empty model representation plus optional UI metadata. */
- export const Success = Event.durable({
- type: "session.tool.success",
- durable: {
- aggregate: "sessionID",
- version: 2,
- },
- schema: {
- ...ToolBase,
- content: Schema.NonEmptyArray(Content),
- metadata: Schema.Record(Schema.String, Schema.Json).pipe(optional),
- executed: Schema.Boolean,
- resultState: SessionMessage.ProviderState.pipe(optional),
- },
- })
- export type Success = typeof Success.Type
- /**
- * Canonical terminal failure: one error plus the final bounded snapshot of
- * partial progress. The event is self-contained; projection never reaches
- * into ephemeral progress history.
- */
- export const Failed = Event.durable({
- type: "session.tool.failed",
- durable: {
- aggregate: "sessionID",
- version: 2,
- },
- schema: {
- ...ToolBase,
- error: SessionError.Error,
- content: Schema.NonEmptyArray(Content).pipe(optional),
- metadata: Schema.Record(Schema.String, Schema.Json).pipe(optional),
- executed: Schema.Boolean,
- resultState: SessionMessage.ProviderState.pipe(optional),
- },
- })
- export type Failed = typeof Failed.Type
- }
- export const RetryScheduled = Event.durable({
- type: "session.retry.scheduled",
- ...options,
- schema: {
- ...Base,
- assistantMessageID: SessionMessage.ID,
- attempt: PositiveInt,
- at: NonNegativeInt,
- error: SessionError.Error,
- },
- })
- export type RetryScheduled = typeof RetryScheduled.Type
- export namespace Compaction {
- export const Admitted = Event.durable({
- type: "session.compaction.admitted",
- ...options,
- schema: {
- ...Base,
- inputID: SessionMessage.ID,
- },
- })
- export type Admitted = typeof Admitted.Type
- export const Started = Event.durable({
- type: "session.compaction.started",
- ...options,
- schema: {
- ...Base,
- reason: Schema.Literals(["auto", "manual"]),
- recent: Schema.String,
- inputID: SessionMessage.ID.pipe(optional),
- },
- })
- export type Started = typeof Started.Type
- export const Delta = Event.ephemeral({
- type: "session.compaction.delta",
- schema: {
- ...Base,
- text: Schema.String,
- },
- })
- export type Delta = typeof Delta.Type
- export const Ended = Event.durable({
- type: "session.compaction.ended",
- ...options,
- schema: {
- ...Base,
- reason: Started.data.fields.reason,
- text: Schema.String,
- recent: Schema.String,
- },
- })
- export type Ended = typeof Ended.Type
- export const Failed = Event.durable({
- type: "session.compaction.failed",
- ...options,
- schema: {
- ...Base,
- reason: Started.data.fields.reason,
- error: SessionError.Error,
- inputID: SessionMessage.ID.pipe(optional),
- },
- })
- export type Failed = typeof Failed.Type
- }
- export namespace RevertEvent {
- export const Staged = Event.durable({
- type: "session.revert.staged",
- ...options,
- schema: { ...Base, revert: Revert },
- })
- export const Cleared = Event.durable({ type: "session.revert.cleared", ...options, schema: Base })
- export const Committed = Event.durable({
- type: "session.revert.committed",
- ...options,
- schema: { ...Base, to: SessionMessage.ID },
- })
- }
- export const Definitions = Event.inventory(
- Created,
- AgentSelected,
- ModelSelected,
- Moved,
- Renamed,
- UsageUpdated,
- Deleted,
- Forked,
- InputPromoted,
- InputAdmitted,
- InputCancelled,
- InputSteered,
- InputQueued,
- Execution.Started,
- Execution.Succeeded,
- Execution.Failed,
- Execution.Interrupted,
- InstructionsUpdated,
- Synthetic,
- Skill.Activated,
- Shell.Started,
- Shell.Ended,
- Step.Started,
- Step.Ended,
- Step.Failed,
- Text.Started,
- Text.Delta,
- Text.Ended,
- Reasoning.Started,
- Reasoning.Delta,
- Reasoning.Ended,
- Tool.Input.Started,
- Tool.Input.Delta,
- Tool.Input.Ended,
- Tool.Called,
- Tool.Progress,
- Tool.Success,
- Tool.Failed,
- RetryScheduled,
- Compaction.Admitted,
- Compaction.Started,
- Compaction.Delta,
- Compaction.Ended,
- Compaction.Failed,
- RevertEvent.Staged,
- RevertEvent.Cleared,
- RevertEvent.Committed,
- )
- // UsageRecorded is durable but internal: excluded from Definitions so it never reaches the public manifest.
- export const DurableDefinitions = Event.inventory(
- ...Definitions.filter((definition) => definition.durability === "durable"),
- UsageRecorded,
- )
- export const EphemeralDefinitions = Event.inventory(
- ...Definitions.filter((definition) => definition.durability === "ephemeral"),
- )
- export const Durable = Schema.Union(DurableDefinitions, { mode: "oneOf" })
- .pipe(Schema.toTaggedUnion("type"))
- .annotate({ identifier: "Session.Event.Durable" })
- export type DurableEvent = typeof Durable.Type
- export const All = Schema.Union([Durable, ...EphemeralDefinitions], { mode: "oneOf" }).pipe(
- Schema.toTaggedUnion("type"),
- )
- export type Event = typeof All.Type
- export type Type = Event["type"]
|