Skip to content

Commit 9847e35

Browse files
committed
feat: add client tool abort signal
1 parent 7b514f3 commit 9847e35

11 files changed

Lines changed: 530 additions & 22 deletions

File tree

apps/website/content/docs/chat/api/api-docs.json

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6305,7 +6305,7 @@
63056305
},
63066306
{
63076307
"name": "handler",
6308-
"type": "(args: any) => unknown",
6308+
"type": "(args: any, context: FunctionToolHandlerContext) => unknown",
63096309
"description": "",
63106310
"optional": false
63116311
},
@@ -6976,7 +6976,7 @@
69766976
},
69776977
{
69786978
"name": "handler",
6979-
"type": "(args: StandardSchemaInferOutput<S>) => R | Promise<R>",
6979+
"type": "(args: StandardSchemaInferOutput<S>, context: FunctionToolHandlerContext) => R | Promise<R>",
69806980
"description": "",
69816981
"optional": false
69826982
},
@@ -6995,6 +6995,20 @@
69956995
],
69966996
"examples": []
69976997
},
6998+
{
6999+
"name": "FunctionToolHandlerContext",
7000+
"kind": "interface",
7001+
"description": "Runtime context passed to browser-executed function tool handlers.",
7002+
"properties": [
7003+
{
7004+
"name": "signal",
7005+
"type": "AbortSignal",
7006+
"description": "Aborts when the client tool execution should stop without resolving.",
7007+
"optional": false
7008+
}
7009+
],
7010+
"examples": []
7011+
},
69987012
{
69997013
"name": "Message",
70007014
"kind": "interface",
@@ -8144,7 +8158,7 @@
81448158
"name": "action",
81458159
"kind": "function",
81468160
"description": "Declare an async function tool the model can call; its resolved return value\nbecomes the tool result shipped back to the model.",
8147-
"signature": "action(description: string, schema: S, handler: (args: StandardSchemaInferOutput<S>) => R | Promise<R>): FunctionToolDef<S, R>",
8161+
"signature": "action(description: string, schema: S, handler: (args: StandardSchemaInferOutput<S>, context: FunctionToolHandlerContext) => R | Promise<R>): FunctionToolDef<S, R>",
81488162
"params": [
81498163
{
81508164
"name": "description",
@@ -8160,8 +8174,8 @@
81608174
},
81618175
{
81628176
"name": "handler",
8163-
"type": "(args: StandardSchemaInferOutput<S>) => R | Promise<R>",
8164-
"description": "Runs in the browser when the model calls the tool; its return\n type `R` is carried on the resulting FunctionToolDef.",
8177+
"type": "(args: StandardSchemaInferOutput<S>, context: FunctionToolHandlerContext) => R | Promise<R>",
8178+
"description": "Runs in the browser when the model calls the tool. The second\n argument carries an `AbortSignal`; its return type `R` is carried on the\n resulting FunctionToolDef.",
81658179
"optional": false
81668180
}
81678181
],
@@ -8500,7 +8514,7 @@
85008514
"name": "executeFunctionTool",
85018515
"kind": "function",
85028516
"description": "Validate args, run the handler, and normalize the outcome to a ClientToolResult.",
8503-
"signature": "executeFunctionTool(def: AnyFunctionToolDef, rawArgs: unknown): Promise<ClientToolResult>",
8517+
"signature": "executeFunctionTool(def: AnyFunctionToolDef, rawArgs: unknown, context: FunctionToolHandlerContext): Promise<ClientToolResult>",
85048518
"params": [
85058519
{
85068520
"name": "def",
@@ -8513,6 +8527,12 @@
85138527
"type": "unknown",
85148528
"description": "",
85158529
"optional": false
8530+
},
8531+
{
8532+
"name": "context",
8533+
"type": "FunctionToolHandlerContext",
8534+
"description": "",
8535+
"optional": true
85168536
}
85178537
],
85188538
"returns": {

0 commit comments

Comments
 (0)