refactor(tools): unify tool APIs and result handling (#38367)

This commit is contained in:
Kit Langton 2026-07-23 17:13:31 -04:00 committed by GitHub
commit 79c1544072
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
133 changed files with 3602 additions and 2770 deletions

View file

@ -409,40 +409,49 @@ export namespace Tool {
})
export type Called = typeof Called.Type
/** Live replacement snapshot for a running tool. */
/** Live replacement metadata for a running tool. */
export const Progress = Event.ephemeral({
type: "session.tool.progress",
schema: {
...ToolBase,
structured: Schema.Record(Schema.String, Schema.Unknown),
content: Schema.Array(ToolContent),
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",
...options,
durable: {
aggregate: "sessionID",
version: 2,
},
schema: {
...ToolBase,
structured: Schema.Record(Schema.String, Schema.Unknown),
content: Schema.Array(ToolContent),
result: Schema.Unknown.pipe(optional),
content: Schema.NonEmptyArray(ToolContent),
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",
...options,
durable: {
aggregate: "sessionID",
version: 2,
},
schema: {
...ToolBase,
error: SessionError.Error,
content: Schema.NonEmptyArray(ToolContent).pipe(optional),
metadata: Schema.Record(Schema.String, Schema.Unknown).pipe(optional),
result: Schema.Unknown.pipe(optional),
metadata: Schema.Record(Schema.String, Schema.Json).pipe(optional),
executed: Schema.Boolean,
resultState: SessionMessage.ProviderState.pipe(optional),
},

View file

@ -110,27 +110,24 @@ export interface ToolStateRunning extends Schema.Schema.Type<typeof ToolStateRun
export const ToolStateRunning = Schema.Struct({
status: Schema.tag("running"),
input: Schema.Record(Schema.String, Schema.Unknown),
structured: Schema.Record(Schema.String, Schema.Unknown),
content: ToolContent.pipe(Schema.Array),
metadata: Schema.Record(Schema.String, Schema.Json),
}).annotate({ identifier: "Session.Message.ToolState.Running" })
export interface ToolStateCompleted extends Schema.Schema.Type<typeof ToolStateCompleted> {}
export const ToolStateCompleted = Schema.Struct({
status: Schema.tag("completed"),
input: Schema.Record(Schema.String, Schema.Unknown),
content: ToolContent.pipe(Schema.Array),
structured: Schema.Record(Schema.String, Schema.Unknown),
result: Schema.Unknown.pipe(optional),
content: Schema.NonEmptyArray(ToolContent),
metadata: Schema.Record(Schema.String, Schema.Json).pipe(optional),
}).annotate({ identifier: "Session.Message.ToolState.Completed" })
export interface ToolStateError extends Schema.Schema.Type<typeof ToolStateError> {}
export const ToolStateError = Schema.Struct({
status: Schema.tag("error"),
input: Schema.Record(Schema.String, Schema.Unknown),
content: ToolContent.pipe(Schema.Array),
structured: Schema.Record(Schema.String, Schema.Unknown),
error: SessionError.Error,
result: Schema.Unknown.pipe(optional),
content: Schema.NonEmptyArray(ToolContent).pipe(optional),
metadata: Schema.Record(Schema.String, Schema.Json).pipe(optional),
}).annotate({ identifier: "Session.Message.ToolState.Error" })
export const ToolState = Schema.Union([ToolStateStreaming, ToolStateRunning, ToolStateCompleted, ToolStateError]).pipe(