| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402 |
- import { Schema } from "effect"
- import { EventV2 } from "./event"
- import { ModelV2 } from "./model"
- import { NonNegativeInt } from "./schema"
- import { Session } from "./session"
- import { FileAttachment, Prompt } from "./session-prompt"
- import { ToolOutput } from "./tool-output"
- import { V2Schema } from "./v2-schema"
- export { FileAttachment }
- export const Source = Schema.Struct({
- start: NonNegativeInt,
- end: NonNegativeInt,
- text: Schema.String,
- }).annotate({
- identifier: "session.next.event.source",
- })
- export type Source = typeof Source.Type
- const Base = {
- timestamp: V2Schema.DateTimeUtcFromMillis,
- sessionID: Session.ID,
- }
- const options = {
- aggregate: "sessionID",
- version: 1,
- } as const
- export const UnknownError = Schema.Struct({
- type: Schema.Literal("unknown"),
- message: Schema.String,
- }).annotate({
- identifier: "Session.Error.Unknown",
- })
- export type UnknownError = typeof UnknownError.Type
- export const AgentSwitched = EventV2.define({
- type: "session.next.agent.switched",
- ...options,
- schema: {
- ...Base,
- agent: Schema.String,
- },
- })
- export type AgentSwitched = typeof AgentSwitched.Type
- export const ModelSwitched = EventV2.define({
- type: "session.next.model.switched",
- ...options,
- schema: {
- ...Base,
- model: ModelV2.Ref,
- },
- })
- export type ModelSwitched = typeof ModelSwitched.Type
- export const Prompted = EventV2.define({
- type: "session.next.prompted",
- ...options,
- schema: {
- ...Base,
- prompt: Prompt,
- },
- })
- export type Prompted = typeof Prompted.Type
- export const Synthetic = EventV2.define({
- type: "session.next.synthetic",
- ...options,
- schema: {
- ...Base,
- text: Schema.String,
- },
- })
- export type Synthetic = typeof Synthetic.Type
- export namespace Shell {
- export const Started = EventV2.define({
- type: "session.next.shell.started",
- ...options,
- schema: {
- ...Base,
- callID: Schema.String,
- command: Schema.String,
- },
- })
- export type Started = typeof Started.Type
- export const Ended = EventV2.define({
- type: "session.next.shell.ended",
- ...options,
- schema: {
- ...Base,
- callID: Schema.String,
- output: Schema.String,
- },
- })
- export type Ended = typeof Ended.Type
- }
- export namespace Step {
- export const Started = EventV2.define({
- type: "session.next.step.started",
- ...options,
- schema: {
- ...Base,
- agent: Schema.String,
- model: ModelV2.Ref,
- snapshot: Schema.String.pipe(Schema.optional),
- },
- })
- export type Started = typeof Started.Type
- export const Ended = EventV2.define({
- type: "session.next.step.ended",
- ...options,
- schema: {
- ...Base,
- finish: Schema.String,
- cost: Schema.Finite,
- tokens: Schema.Struct({
- input: Schema.Finite,
- output: Schema.Finite,
- reasoning: Schema.Finite,
- cache: Schema.Struct({
- read: Schema.Finite,
- write: Schema.Finite,
- }),
- }),
- snapshot: Schema.String.pipe(Schema.optional),
- },
- })
- export type Ended = typeof Ended.Type
- export const Failed = EventV2.define({
- type: "session.next.step.failed",
- ...options,
- schema: {
- ...Base,
- error: UnknownError,
- },
- })
- export type Failed = typeof Failed.Type
- }
- export namespace Text {
- export const Started = EventV2.define({
- type: "session.next.text.started",
- ...options,
- schema: {
- ...Base,
- },
- })
- export type Started = typeof Started.Type
- export const Delta = EventV2.define({
- type: "session.next.text.delta",
- ...options,
- schema: {
- ...Base,
- delta: Schema.String,
- },
- })
- export type Delta = typeof Delta.Type
- export const Ended = EventV2.define({
- type: "session.next.text.ended",
- ...options,
- schema: {
- ...Base,
- text: Schema.String,
- },
- })
- export type Ended = typeof Ended.Type
- }
- export namespace Reasoning {
- export const Started = EventV2.define({
- type: "session.next.reasoning.started",
- ...options,
- schema: {
- ...Base,
- reasoningID: Schema.String,
- },
- })
- export type Started = typeof Started.Type
- export const Delta = EventV2.define({
- type: "session.next.reasoning.delta",
- ...options,
- schema: {
- ...Base,
- reasoningID: Schema.String,
- delta: Schema.String,
- },
- })
- export type Delta = typeof Delta.Type
- export const Ended = EventV2.define({
- type: "session.next.reasoning.ended",
- ...options,
- schema: {
- ...Base,
- reasoningID: Schema.String,
- text: Schema.String,
- },
- })
- export type Ended = typeof Ended.Type
- }
- export namespace Tool {
- export namespace Input {
- export const Started = EventV2.define({
- type: "session.next.tool.input.started",
- ...options,
- schema: {
- ...Base,
- callID: Schema.String,
- name: Schema.String,
- },
- })
- export type Started = typeof Started.Type
- export const Delta = EventV2.define({
- type: "session.next.tool.input.delta",
- ...options,
- schema: {
- ...Base,
- callID: Schema.String,
- delta: Schema.String,
- },
- })
- export type Delta = typeof Delta.Type
- export const Ended = EventV2.define({
- type: "session.next.tool.input.ended",
- ...options,
- schema: {
- ...Base,
- callID: Schema.String,
- text: Schema.String,
- },
- })
- export type Ended = typeof Ended.Type
- }
- export const Called = EventV2.define({
- type: "session.next.tool.called",
- ...options,
- schema: {
- ...Base,
- callID: Schema.String,
- tool: Schema.String,
- input: Schema.Record(Schema.String, Schema.Unknown),
- provider: Schema.Struct({
- executed: Schema.Boolean,
- metadata: Schema.Record(Schema.String, Schema.Unknown).pipe(Schema.optional),
- }),
- },
- })
- export type Called = typeof Called.Type
- export const Progress = EventV2.define({
- type: "session.next.tool.progress",
- ...options,
- schema: {
- ...Base,
- callID: Schema.String,
- structured: ToolOutput.Structured,
- content: Schema.Array(ToolOutput.Content),
- },
- })
- export type Progress = typeof Progress.Type
- export const Success = EventV2.define({
- type: "session.next.tool.success",
- ...options,
- schema: {
- ...Base,
- callID: Schema.String,
- structured: ToolOutput.Structured,
- content: Schema.Array(ToolOutput.Content),
- provider: Schema.Struct({
- executed: Schema.Boolean,
- metadata: Schema.Record(Schema.String, Schema.Unknown).pipe(Schema.optional),
- }),
- },
- })
- export type Success = typeof Success.Type
- export const Failed = EventV2.define({
- type: "session.next.tool.failed",
- ...options,
- schema: {
- ...Base,
- callID: Schema.String,
- error: UnknownError,
- provider: Schema.Struct({
- executed: Schema.Boolean,
- metadata: Schema.Record(Schema.String, Schema.Unknown).pipe(Schema.optional),
- }),
- },
- })
- export type Failed = typeof Failed.Type
- }
- export const RetryError = Schema.Struct({
- message: Schema.String,
- statusCode: Schema.Finite.pipe(Schema.optional),
- isRetryable: Schema.Boolean,
- responseHeaders: Schema.Record(Schema.String, Schema.String).pipe(Schema.optional),
- responseBody: Schema.String.pipe(Schema.optional),
- metadata: Schema.Record(Schema.String, Schema.String).pipe(Schema.optional),
- }).annotate({
- identifier: "session.next.retry_error",
- })
- export type RetryError = typeof RetryError.Type
- export const Retried = EventV2.define({
- type: "session.next.retried",
- ...options,
- schema: {
- ...Base,
- attempt: Schema.Finite,
- error: RetryError,
- },
- })
- export type Retried = typeof Retried.Type
- export namespace Compaction {
- export const Started = EventV2.define({
- type: "session.next.compaction.started",
- ...options,
- schema: {
- ...Base,
- reason: Schema.Union([Schema.Literal("auto"), Schema.Literal("manual")]),
- },
- })
- export type Started = typeof Started.Type
- export const Delta = EventV2.define({
- type: "session.next.compaction.delta",
- ...options,
- schema: {
- ...Base,
- text: Schema.String,
- },
- })
- export type Delta = typeof Delta.Type
- export const Ended = EventV2.define({
- type: "session.next.compaction.ended",
- ...options,
- schema: {
- ...Base,
- text: Schema.String,
- include: Schema.String.pipe(Schema.optional),
- },
- })
- export type Ended = typeof Ended.Type
- }
- export const All = Schema.Union(
- [
- AgentSwitched,
- ModelSwitched,
- Prompted,
- Synthetic,
- Shell.Started,
- Shell.Ended,
- Step.Started,
- Step.Ended,
- Step.Failed,
- Text.Started,
- Text.Delta,
- Text.Ended,
- Tool.Input.Started,
- Tool.Input.Delta,
- Tool.Input.Ended,
- Tool.Called,
- Tool.Progress,
- Tool.Success,
- Tool.Failed,
- Reasoning.Started,
- Reasoning.Delta,
- Reasoning.Ended,
- Retried,
- Compaction.Started,
- Compaction.Delta,
- Compaction.Ended,
- ],
- {
- mode: "oneOf",
- },
- ).pipe(Schema.toTaggedUnion("type"))
- export type Event = typeof All.Type
- export type Type = Event["type"]
- export * as SessionEvent from "./session-event"
|