assistant-stream 0.3.14 → 0.3.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/dist/core/AssistantStream.d.ts +50 -9
- package/dist/core/AssistantStream.d.ts.map +1 -1
- package/dist/core/AssistantStream.js +39 -15
- package/dist/core/AssistantStream.js.map +1 -1
- package/dist/core/AssistantStreamChunk.d.ts +84 -61
- package/dist/core/AssistantStreamChunk.d.ts.map +1 -1
- package/dist/core/AssistantStreamChunk.js +0 -2
- package/dist/core/accumulators/AssistantMessageStream.d.ts +15 -11
- package/dist/core/accumulators/AssistantMessageStream.d.ts.map +1 -1
- package/dist/core/accumulators/AssistantMessageStream.js +52 -48
- package/dist/core/accumulators/AssistantMessageStream.js.map +1 -1
- package/dist/core/accumulators/TimingTracker.d.ts +15 -11
- package/dist/core/accumulators/TimingTracker.d.ts.map +1 -1
- package/dist/core/accumulators/TimingTracker.js +36 -43
- package/dist/core/accumulators/TimingTracker.js.map +1 -1
- package/dist/core/accumulators/assistant-message-accumulator.d.ts +21 -11
- package/dist/core/accumulators/assistant-message-accumulator.d.ts.map +1 -1
- package/dist/core/accumulators/assistant-message-accumulator.js +349 -390
- package/dist/core/accumulators/assistant-message-accumulator.js.map +1 -1
- package/dist/core/converters/toGenericMessages.d.ts +49 -47
- package/dist/core/converters/toGenericMessages.d.ts.map +1 -1
- package/dist/core/converters/toGenericMessages.js +122 -136
- package/dist/core/converters/toGenericMessages.js.map +1 -1
- package/dist/core/modules/assistant-stream.d.ts +92 -28
- package/dist/core/modules/assistant-stream.d.ts.map +1 -1
- package/dist/core/modules/assistant-stream.js +177 -162
- package/dist/core/modules/assistant-stream.js.map +1 -1
- package/dist/core/modules/text.d.ts +11 -7
- package/dist/core/modules/text.d.ts.map +1 -1
- package/dist/core/modules/text.js +45 -45
- package/dist/core/modules/text.js.map +1 -1
- package/dist/core/modules/tool-call.d.ts +15 -11
- package/dist/core/modules/tool-call.d.ts.map +1 -1
- package/dist/core/modules/tool-call.js +81 -96
- package/dist/core/modules/tool-call.js.map +1 -1
- package/dist/core/object/ObjectStreamAccumulator.d.ts +13 -9
- package/dist/core/object/ObjectStreamAccumulator.d.ts.map +1 -1
- package/dist/core/object/ObjectStreamAccumulator.js +44 -52
- package/dist/core/object/ObjectStreamAccumulator.js.map +1 -1
- package/dist/core/object/ObjectStreamResponse.d.ts +12 -8
- package/dist/core/object/ObjectStreamResponse.d.ts.map +1 -1
- package/dist/core/object/ObjectStreamResponse.js +52 -71
- package/dist/core/object/ObjectStreamResponse.js.map +1 -1
- package/dist/core/object/createObjectStream.d.ts +14 -8
- package/dist/core/object/createObjectStream.d.ts.map +1 -1
- package/dist/core/object/createObjectStream.js +50 -47
- package/dist/core/object/createObjectStream.js.map +1 -1
- package/dist/core/object/types.d.ts +14 -11
- package/dist/core/object/types.d.ts.map +1 -1
- package/dist/core/object/types.js +0 -2
- package/dist/core/serialization/PlainText.d.ts +11 -7
- package/dist/core/serialization/PlainText.d.ts.map +1 -1
- package/dist/core/serialization/PlainText.js +40 -48
- package/dist/core/serialization/PlainText.js.map +1 -1
- package/dist/core/serialization/assistant-transport/AssistantTransport.d.ts +11 -7
- package/dist/core/serialization/assistant-transport/AssistantTransport.d.ts.map +1 -1
- package/dist/core/serialization/assistant-transport/AssistantTransport.js +102 -117
- package/dist/core/serialization/assistant-transport/AssistantTransport.js.map +1 -1
- package/dist/core/serialization/data-stream/DataStream.d.ts +11 -7
- package/dist/core/serialization/data-stream/DataStream.d.ts.map +1 -1
- package/dist/core/serialization/data-stream/DataStream.js +320 -371
- package/dist/core/serialization/data-stream/DataStream.js.map +1 -1
- package/dist/core/serialization/data-stream/chunk-types.d.ts +101 -100
- package/dist/core/serialization/data-stream/chunk-types.d.ts.map +1 -1
- package/dist/core/serialization/data-stream/chunk-types.js +27 -23
- package/dist/core/serialization/data-stream/chunk-types.js.map +1 -1
- package/dist/core/serialization/data-stream/serialization.d.ts +9 -5
- package/dist/core/serialization/data-stream/serialization.d.ts.map +1 -1
- package/dist/core/serialization/data-stream/serialization.js +23 -24
- package/dist/core/serialization/data-stream/serialization.js.map +1 -1
- package/dist/core/serialization/ui-message-stream/UIMessageStream.d.ts +15 -12
- package/dist/core/serialization/ui-message-stream/UIMessageStream.d.ts.map +1 -1
- package/dist/core/serialization/ui-message-stream/UIMessageStream.js +205 -228
- package/dist/core/serialization/ui-message-stream/UIMessageStream.js.map +1 -1
- package/dist/core/serialization/ui-message-stream/chunk-types.d.ts +68 -65
- package/dist/core/serialization/ui-message-stream/chunk-types.d.ts.map +1 -1
- package/dist/core/serialization/ui-message-stream/chunk-types.js +0 -2
- package/dist/core/tool/ToolCallReader.d.ts +34 -30
- package/dist/core/tool/ToolCallReader.d.ts.map +1 -1
- package/dist/core/tool/ToolCallReader.js +264 -317
- package/dist/core/tool/ToolCallReader.js.map +1 -1
- package/dist/core/tool/ToolExecutionStream.d.ts +20 -17
- package/dist/core/tool/ToolExecutionStream.d.ts.map +1 -1
- package/dist/core/tool/ToolExecutionStream.js +123 -146
- package/dist/core/tool/ToolExecutionStream.js.map +1 -1
- package/dist/core/tool/ToolResponse.d.ts +60 -19
- package/dist/core/tool/ToolResponse.d.ts.map +1 -1
- package/dist/core/tool/ToolResponse.js +51 -34
- package/dist/core/tool/ToolResponse.js.map +1 -1
- package/dist/core/tool/schema-utils.d.ts +19 -15
- package/dist/core/tool/schema-utils.d.ts.map +1 -1
- package/dist/core/tool/schema-utils.js +50 -84
- package/dist/core/tool/schema-utils.js.map +1 -1
- package/dist/core/tool/tool-types.d.ts +173 -92
- package/dist/core/tool/tool-types.d.ts.map +1 -1
- package/dist/core/tool/tool-types.js +0 -2
- package/dist/core/tool/toolResultStream.d.ts +24 -7
- package/dist/core/tool/toolResultStream.d.ts.map +1 -1
- package/dist/core/tool/toolResultStream.js +128 -145
- package/dist/core/tool/toolResultStream.js.map +1 -1
- package/dist/core/tool/type-path-utils.d.ts +8 -19
- package/dist/core/tool/type-path-utils.d.ts.map +1 -1
- package/dist/core/tool/type-path-utils.js +0 -2
- package/dist/core/utils/Counter.d.ts +6 -3
- package/dist/core/utils/Counter.d.ts.map +1 -1
- package/dist/core/utils/Counter.js +10 -6
- package/dist/core/utils/Counter.js.map +1 -1
- package/dist/core/utils/generateId.d.ts +4 -1
- package/dist/core/utils/generateId.d.ts.map +1 -1
- package/dist/core/utils/generateId.js +5 -1
- package/dist/core/utils/generateId.js.map +1 -1
- package/dist/core/utils/stream/AssistantMetaTransformStream.d.ts +15 -11
- package/dist/core/utils/stream/AssistantMetaTransformStream.d.ts.map +1 -1
- package/dist/core/utils/stream/AssistantMetaTransformStream.js +38 -42
- package/dist/core/utils/stream/AssistantMetaTransformStream.js.map +1 -1
- package/dist/core/utils/stream/AssistantTransformStream.d.ts +11 -8
- package/dist/core/utils/stream/AssistantTransformStream.d.ts.map +1 -1
- package/dist/core/utils/stream/AssistantTransformStream.js +37 -35
- package/dist/core/utils/stream/AssistantTransformStream.js.map +1 -1
- package/dist/core/utils/stream/LineDecoderStream.d.ts +6 -3
- package/dist/core/utils/stream/LineDecoderStream.d.ts.map +1 -1
- package/dist/core/utils/stream/LineDecoderStream.js +23 -26
- package/dist/core/utils/stream/LineDecoderStream.js.map +1 -1
- package/dist/core/utils/stream/PipeableTransformStream.d.ts +5 -2
- package/dist/core/utils/stream/PipeableTransformStream.d.ts.map +1 -1
- package/dist/core/utils/stream/PipeableTransformStream.js +14 -10
- package/dist/core/utils/stream/PipeableTransformStream.js.map +1 -1
- package/dist/core/utils/stream/SSE.d.ts +10 -6
- package/dist/core/utils/stream/SSE.d.ts.map +1 -1
- package/dist/core/utils/stream/SSE.js +79 -91
- package/dist/core/utils/stream/SSE.js.map +1 -1
- package/dist/core/utils/stream/UnderlyingReadable.d.ts +7 -4
- package/dist/core/utils/stream/UnderlyingReadable.d.ts.map +1 -1
- package/dist/core/utils/stream/UnderlyingReadable.js +0 -2
- package/dist/core/utils/stream/merge.d.ts +11 -7
- package/dist/core/utils/stream/merge.d.ts.map +1 -1
- package/dist/core/utils/stream/merge.js +68 -170
- package/dist/core/utils/stream/merge.js.map +1 -1
- package/dist/core/utils/stream/path-utils.d.ts +11 -7
- package/dist/core/utils/stream/path-utils.d.ts.map +1 -1
- package/dist/core/utils/stream/path-utils.js +46 -52
- package/dist/core/utils/stream/path-utils.js.map +1 -1
- package/dist/core/utils/types.d.ts +109 -113
- package/dist/core/utils/types.d.ts.map +1 -1
- package/dist/core/utils/types.js +0 -2
- package/dist/core/utils/withPromiseOrValue.d.ts +4 -1
- package/dist/core/utils/withPromiseOrValue.d.ts.map +1 -1
- package/dist/core/utils/withPromiseOrValue.js +12 -15
- package/dist/core/utils/withPromiseOrValue.js.map +1 -1
- package/dist/index.d.ts +23 -24
- package/dist/index.js +16 -16
- package/dist/node_modules/.pnpm/@types_json-schema@7.0.15/node_modules/@types/json-schema/index.d.ts +141 -0
- package/dist/node_modules/.pnpm/@types_json-schema@7.0.15/node_modules/@types/json-schema/index.d.ts.map +1 -0
- package/dist/resumable/ResumableStreamContext.d.ts +28 -24
- package/dist/resumable/ResumableStreamContext.d.ts.map +1 -1
- package/dist/resumable/ResumableStreamContext.js +99 -114
- package/dist/resumable/ResumableStreamContext.js.map +1 -1
- package/dist/resumable/constants.d.ts +4 -1
- package/dist/resumable/constants.d.ts.map +1 -1
- package/dist/resumable/constants.js +5 -1
- package/dist/resumable/constants.js.map +1 -1
- package/dist/resumable/createResumableAssistantStreamResponse.d.ts +22 -21
- package/dist/resumable/createResumableAssistantStreamResponse.d.ts.map +1 -1
- package/dist/resumable/createResumableAssistantStreamResponse.js +25 -32
- package/dist/resumable/createResumableAssistantStreamResponse.js.map +1 -1
- package/dist/resumable/errors.d.ts +8 -5
- package/dist/resumable/errors.d.ts.map +1 -1
- package/dist/resumable/errors.js +14 -12
- package/dist/resumable/errors.js.map +1 -1
- package/dist/resumable/index.d.ts +7 -7
- package/dist/resumable/index.js +5 -5
- package/dist/resumable/stores/InMemoryResumableStreamStore.d.ts +14 -10
- package/dist/resumable/stores/InMemoryResumableStreamStore.d.ts.map +1 -1
- package/dist/resumable/stores/InMemoryResumableStreamStore.js +159 -193
- package/dist/resumable/stores/InMemoryResumableStreamStore.js.map +1 -1
- package/dist/resumable/stores/ioredis.d.ts +9 -5
- package/dist/resumable/stores/ioredis.d.ts.map +1 -1
- package/dist/resumable/stores/ioredis.js +70 -82
- package/dist/resumable/stores/ioredis.js.map +1 -1
- package/dist/resumable/stores/redis-impl.d.ts +51 -48
- package/dist/resumable/stores/redis-impl.d.ts.map +1 -1
- package/dist/resumable/stores/redis-impl.js +176 -176
- package/dist/resumable/stores/redis-impl.js.map +1 -1
- package/dist/resumable/stores/redis.d.ts +31 -28
- package/dist/resumable/stores/redis.d.ts.map +1 -1
- package/dist/resumable/stores/redis.js +87 -95
- package/dist/resumable/stores/redis.js.map +1 -1
- package/dist/resumable/types.d.ts +29 -26
- package/dist/resumable/types.d.ts.map +1 -1
- package/dist/resumable/types.js +0 -2
- package/dist/utils/AsyncIterableStream.d.ts +5 -2
- package/dist/utils/AsyncIterableStream.d.ts.map +1 -1
- package/dist/utils/AsyncIterableStream.js +17 -16
- package/dist/utils/AsyncIterableStream.js.map +1 -1
- package/dist/utils/json/fix-json.d.ts +4 -1
- package/dist/utils/json/fix-json.d.ts.map +1 -1
- package/dist/utils/json/fix-json.js +286 -380
- package/dist/utils/json/fix-json.js.map +1 -1
- package/dist/utils/json/is-json.d.ts +8 -4
- package/dist/utils/json/is-json.d.ts.map +1 -1
- package/dist/utils/json/is-json.js +13 -21
- package/dist/utils/json/is-json.js.map +1 -1
- package/dist/utils/json/json-value.d.ts +7 -4
- package/dist/utils/json/json-value.d.ts.map +1 -1
- package/dist/utils/json/json-value.js +0 -2
- package/dist/utils/json/parse-partial-json-object.d.ts +11 -8
- package/dist/utils/json/parse-partial-json-object.d.ts.map +1 -1
- package/dist/utils/json/parse-partial-json-object.js +50 -62
- package/dist/utils/json/parse-partial-json-object.js.map +1 -1
- package/dist/utils/promiseWithResolvers.d.ts +7 -4
- package/dist/utils/promiseWithResolvers.d.ts.map +1 -1
- package/dist/utils/promiseWithResolvers.js +17 -10
- package/dist/utils/promiseWithResolvers.js.map +1 -1
- package/dist/utils.d.ts +6 -6
- package/dist/utils.js +5 -5
- package/package.json +5 -4
- package/src/core/AssistantStream.ts +37 -0
- package/src/core/AssistantStreamChunk.ts +30 -0
- package/src/core/modules/assistant-stream.ts +68 -0
- package/src/core/tool/ToolResponse.ts +45 -1
- package/src/core/tool/tool-types.ts +102 -2
- package/src/core/tool/toolResultStream.ts +15 -0
- package/dist/core/AssistantStreamChunk.js.map +0 -1
- package/dist/core/object/types.js.map +0 -1
- package/dist/core/serialization/ui-message-stream/chunk-types.js.map +0 -1
- package/dist/core/tool/tool-types.js.map +0 -1
- package/dist/core/tool/type-path-utils.js.map +0 -1
- package/dist/core/utils/stream/UnderlyingReadable.js.map +0 -1
- package/dist/core/utils/types.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/resumable/index.d.ts.map +0 -1
- package/dist/resumable/index.js.map +0 -1
- package/dist/resumable/types.js.map +0 -1
- package/dist/utils/json/json-value.js.map +0 -1
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToolResponse.js","
|
|
1
|
+
{"version":3,"file":"ToolResponse.js","names":[],"sources":["../../../src/core/tool/ToolResponse.ts"],"sourcesContent":["import type { ReadonlyJSONValue } from \"../../utils/json/json-value\";\nimport type {\n ToolModelContentPart,\n ToolModelOutputFunction,\n} from \"./tool-types\";\n\nconst TOOL_RESPONSE_SYMBOL = Symbol.for(\"aui.tool-response\");\n\n/**\n * Shape accepted anywhere a {@link ToolResponse} can be returned.\n */\nexport type ToolResponseLike<TResult> = {\n /** UI-visible tool result value. */\n result: TResult;\n /**\n * Optional UI-only artifact associated with the result.\n *\n * Artifacts are useful for large or structured data that should be available\n * to renderers without necessarily being sent back to the model.\n */\n artifact?: ReadonlyJSONValue | undefined;\n /** Marks the tool result as an error result. */\n isError?: boolean | undefined;\n /**\n * Explicit model-visible content to send back after the tool call.\n *\n * When omitted, assistant-ui derives model output from `result` or a tool's\n * {@link ToolModelOutputFunction}.\n */\n modelContent?: readonly ToolModelContentPart[] | undefined;\n /** Optional provider-specific message payload associated with the tool result. */\n messages?: ReadonlyJSONValue | undefined;\n};\n\n/**\n * Tool result wrapper for separating UI-visible output from model-visible\n * output.\n *\n * Return `ToolResponse` from a tool when you need to attach an artifact, mark\n * the result as an error, or control the content sent back to the model.\n *\n * @example\n * ```ts\n * return new ToolResponse({\n * result: { title: \"Report ready\" },\n * artifact: { reportId },\n * modelContent: [{ type: \"text\", text: \"The report is ready.\" }],\n * });\n * ```\n */\nexport class ToolResponse<TResult> {\n get [TOOL_RESPONSE_SYMBOL]() {\n return true;\n }\n\n readonly artifact?: ReadonlyJSONValue;\n readonly result: TResult;\n readonly isError: boolean;\n readonly modelContent?: readonly ToolModelContentPart[];\n readonly messages?: ReadonlyJSONValue;\n\n constructor(options: ToolResponseLike<TResult>) {\n if (options.artifact !== undefined) {\n this.artifact = options.artifact;\n }\n this.result = options.result;\n this.isError = options.isError ?? false;\n if (options.modelContent !== undefined) {\n this.modelContent = options.modelContent;\n }\n if (options.messages !== undefined) {\n this.messages = options.messages;\n }\n }\n\n static [Symbol.hasInstance](\n obj: unknown,\n ): obj is ToolResponse<ReadonlyJSONValue> {\n return (\n typeof obj === \"object\" && obj !== null && TOOL_RESPONSE_SYMBOL in obj\n );\n }\n\n /**\n * Converts a plain tool return value into a {@link ToolResponse}.\n *\n * Existing `ToolResponse` instances are returned unchanged. `undefined`\n * becomes the string `\"<no result>\"` so downstream protocol chunks always\n * carry a concrete result.\n */\n static toResponse(result: any | ToolResponse<any>): ToolResponse<any> {\n if (result instanceof ToolResponse) {\n return result;\n }\n return new ToolResponse({\n result: result === undefined ? \"<no result>\" : result,\n });\n }\n}\n"],"mappings":";AAMA,MAAM,uBAAuB,OAAO,IAAI,mBAAmB;;;;;;;;;;;;;;;;;AA4C3D,IAAa,eAAb,MAAa,aAAsB;CACjC,KAAK,wBAAwB;EAC3B,OAAO;CACT;CAEA;CACA;CACA;CACA;CACA;CAEA,YAAY,SAAoC;EAC9C,IAAI,QAAQ,aAAa,KAAA,GACvB,KAAK,WAAW,QAAQ;EAE1B,KAAK,SAAS,QAAQ;EACtB,KAAK,UAAU,QAAQ,WAAW;EAClC,IAAI,QAAQ,iBAAiB,KAAA,GAC3B,KAAK,eAAe,QAAQ;EAE9B,IAAI,QAAQ,aAAa,KAAA,GACvB,KAAK,WAAW,QAAQ;CAE5B;CAEA,QAAQ,OAAO,aACb,KACwC;EACxC,OACE,OAAO,QAAQ,YAAY,QAAQ,QAAQ,wBAAwB;CAEvE;;;;;;;;CASA,OAAO,WAAW,QAAoD;EACpE,IAAI,kBAAkB,cACpB,OAAO;EAET,OAAO,IAAI,aAAa,EACtB,QAAQ,WAAW,KAAA,IAAY,gBAAgB,OACjD,CAAC;CACH;AACF"}
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { JSONSchema7 } from "../../node_modules/.pnpm/@types_json-schema@7.0.15/node_modules/@types/json-schema/index.js";
|
|
2
|
+
import { Tool } from "./tool-types.js";
|
|
3
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
4
|
+
|
|
5
|
+
//#region src/core/tool/schema-utils.d.ts
|
|
4
6
|
/**
|
|
5
7
|
* Type for a tool definition with JSON Schema parameters.
|
|
6
8
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
type ToolJSONSchema = {
|
|
10
|
+
description?: string;
|
|
11
|
+
parameters: JSONSchema7;
|
|
10
12
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
type ToToolsJSONSchemaOptions = {
|
|
14
|
+
/**
|
|
15
|
+
* Filter to determine which tools to include.
|
|
16
|
+
* Defaults to excluding disabled tools and backend tools.
|
|
17
|
+
*/
|
|
18
|
+
filter?: (name: string, tool: Tool) => boolean;
|
|
17
19
|
};
|
|
18
20
|
/**
|
|
19
21
|
* Converts a schema to JSONSchema7.
|
|
@@ -24,15 +26,17 @@ export type ToToolsJSONSchemaOptions = {
|
|
|
24
26
|
* - Objects with toJSON() method
|
|
25
27
|
* - Plain JSONSchema7 objects (must have a "type" property)
|
|
26
28
|
*/
|
|
27
|
-
|
|
29
|
+
declare function toJSONSchema(schema: StandardSchemaV1 | JSONSchema7): JSONSchema7;
|
|
28
30
|
/**
|
|
29
31
|
* Returns a copy of the JSON Schema with `required` removed recursively,
|
|
30
32
|
* making every property optional. Array item schemas are left unchanged.
|
|
31
33
|
*/
|
|
32
|
-
|
|
34
|
+
declare function toPartialJSONSchema(schema: JSONSchema7): JSONSchema7;
|
|
33
35
|
/**
|
|
34
36
|
* Converts a record of tools to a record of tool definitions with JSON Schema parameters.
|
|
35
37
|
* By default, filters out disabled tools and backend tools.
|
|
36
38
|
*/
|
|
37
|
-
|
|
39
|
+
declare function toToolsJSONSchema(tools: Record<string, Tool> | undefined, options?: ToToolsJSONSchemaOptions): Record<string, ToolJSONSchema>;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { ToToolsJSONSchemaOptions, ToolJSONSchema, toJSONSchema, toPartialJSONSchema, toToolsJSONSchema };
|
|
38
42
|
//# sourceMappingURL=schema-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-utils.d.ts","
|
|
1
|
+
{"version":3,"file":"schema-utils.d.ts","names":[],"sources":["../../../src/core/tool/schema-utils.ts"],"mappings":";;;;;;;AAOA;KAAY,cAAA;EACV,WAAA;EACA,UAAA,EAAY,WAAW;AAAA;AAAA,KAGb,wBAAA;EAHE;;AAAW;AAGzB;EAKE,MAAA,IAAU,IAAA,UAAc,IAAA,EAAM,IAAI;AAAA;;;;;;;AAAA;AA8CpC;;iBAAgB,YAAA,CACd,MAAA,EAAQ,gBAAA,GAAmB,WAAA,GAC1B,WAAA;;;;;iBA+Ca,mBAAA,CAAoB,MAAA,EAAQ,WAAA,GAAc,WAAW;;;;;iBA0BrD,iBAAA,CACd,KAAA,EAAO,MAAA,SAAe,IAAA,eACtB,OAAA,GAAS,wBAAA,GACR,MAAA,SAAe,cAAA"}
|
|
@@ -1,99 +1,65 @@
|
|
|
1
|
+
//#region src/core/tool/schema-utils.ts
|
|
1
2
|
function isStandardSchema(schema) {
|
|
2
|
-
|
|
3
|
-
schema !== null &&
|
|
4
|
-
"~standard" in schema &&
|
|
5
|
-
typeof schema["~standard"] === "object");
|
|
3
|
+
return typeof schema === "object" && schema !== null && "~standard" in schema && typeof schema["~standard"] === "object";
|
|
6
4
|
}
|
|
7
5
|
function hasToJSONSchemaMethod(schema) {
|
|
8
|
-
|
|
9
|
-
schema !== null &&
|
|
10
|
-
"toJSONSchema" in schema &&
|
|
11
|
-
typeof schema.toJSONSchema === "function");
|
|
6
|
+
return typeof schema === "object" && schema !== null && "toJSONSchema" in schema && typeof schema.toJSONSchema === "function";
|
|
12
7
|
}
|
|
13
8
|
function hasToJSONMethod(schema) {
|
|
14
|
-
|
|
15
|
-
schema !== null &&
|
|
16
|
-
"toJSON" in schema &&
|
|
17
|
-
typeof schema.toJSON === "function");
|
|
9
|
+
return typeof schema === "object" && schema !== null && "toJSON" in schema && typeof schema.toJSON === "function";
|
|
18
10
|
}
|
|
19
11
|
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
typeof jsonSchema.input === "function") {
|
|
40
|
-
return jsonSchema.input();
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
// toJSONSchema method on the schema itself
|
|
44
|
-
if (hasToJSONSchemaMethod(schema)) {
|
|
45
|
-
return schema.toJSONSchema();
|
|
46
|
-
}
|
|
47
|
-
// toJSON method on the schema
|
|
48
|
-
if (hasToJSONMethod(schema)) {
|
|
49
|
-
return schema.toJSON();
|
|
50
|
-
}
|
|
51
|
-
// If it's a Standard Schema that we couldn't convert, throw a helpful error
|
|
52
|
-
if (isStandardSchema(schema)) {
|
|
53
|
-
throw new Error("Could not convert schema to JSON Schema. " +
|
|
54
|
-
"The schema implements Standard Schema but does not support JSON Schema conversion. " +
|
|
55
|
-
"If you are using Zod, please upgrade to Zod v4 (npm install zod@latest). " +
|
|
56
|
-
"Alternatively, pass a plain JSON Schema object instead.");
|
|
57
|
-
}
|
|
58
|
-
// Already a plain JSONSchema7
|
|
59
|
-
return schema;
|
|
12
|
+
* Converts a schema to JSONSchema7.
|
|
13
|
+
* Supports:
|
|
14
|
+
* - StandardSchemaV1 with ~standard.toJSONSchema (e.g., Zod v4)
|
|
15
|
+
* - StandardSchemaV1 with ~standard.jsonSchema.input() (e.g., Zod v4)
|
|
16
|
+
* - Objects with toJSONSchema() method (e.g., Zod v4)
|
|
17
|
+
* - Objects with toJSON() method
|
|
18
|
+
* - Plain JSONSchema7 objects (must have a "type" property)
|
|
19
|
+
*/
|
|
20
|
+
function toJSONSchema(schema) {
|
|
21
|
+
if (isStandardSchema(schema)) {
|
|
22
|
+
const toJSONSchemaMethod = schema["~standard"].toJSONSchema;
|
|
23
|
+
if (typeof toJSONSchemaMethod === "function") return toJSONSchemaMethod();
|
|
24
|
+
const jsonSchema = schema["~standard"].jsonSchema;
|
|
25
|
+
if (typeof jsonSchema === "object" && jsonSchema !== null && typeof jsonSchema.input === "function") return jsonSchema.input();
|
|
26
|
+
}
|
|
27
|
+
if (hasToJSONSchemaMethod(schema)) return schema.toJSONSchema();
|
|
28
|
+
if (hasToJSONMethod(schema)) return schema.toJSON();
|
|
29
|
+
if (isStandardSchema(schema)) throw new Error("Could not convert schema to JSON Schema. The schema implements Standard Schema but does not support JSON Schema conversion. If you are using Zod, please upgrade to Zod v4 (npm install zod@latest). Alternatively, pass a plain JSON Schema object instead.");
|
|
30
|
+
return schema;
|
|
60
31
|
}
|
|
61
32
|
/**
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
return result;
|
|
33
|
+
* Returns a copy of the JSON Schema with `required` removed recursively,
|
|
34
|
+
* making every property optional. Array item schemas are left unchanged.
|
|
35
|
+
*/
|
|
36
|
+
function toPartialJSONSchema(schema) {
|
|
37
|
+
const { required: _, ...result } = schema;
|
|
38
|
+
if (result.properties) result.properties = Object.fromEntries(Object.entries(result.properties).map(([key, prop]) => {
|
|
39
|
+
if (typeof prop === "object" && prop !== null && !Array.isArray(prop)) {
|
|
40
|
+
const p = prop;
|
|
41
|
+
return [key, p.properties != null ? toPartialJSONSchema(p) : prop];
|
|
42
|
+
}
|
|
43
|
+
return [key, prop];
|
|
44
|
+
}));
|
|
45
|
+
return result;
|
|
77
46
|
}
|
|
78
47
|
function defaultToolFilter(_name, tool) {
|
|
79
|
-
|
|
48
|
+
return !tool.disabled && tool.type !== "backend";
|
|
80
49
|
}
|
|
81
50
|
/**
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
name,
|
|
93
|
-
{
|
|
94
|
-
...(tool.description && { description: tool.description }),
|
|
95
|
-
parameters: toJSONSchema(tool.parameters),
|
|
96
|
-
},
|
|
97
|
-
]));
|
|
51
|
+
* Converts a record of tools to a record of tool definitions with JSON Schema parameters.
|
|
52
|
+
* By default, filters out disabled tools and backend tools.
|
|
53
|
+
*/
|
|
54
|
+
function toToolsJSONSchema(tools, options = {}) {
|
|
55
|
+
if (!tools) return {};
|
|
56
|
+
const filter = options.filter ?? defaultToolFilter;
|
|
57
|
+
return Object.fromEntries(Object.entries(tools).filter(([name, tool]) => filter(name, tool) && tool.parameters).map(([name, tool]) => [name, {
|
|
58
|
+
...tool.description && { description: tool.description },
|
|
59
|
+
parameters: toJSONSchema(tool.parameters)
|
|
60
|
+
}]));
|
|
98
61
|
}
|
|
62
|
+
//#endregion
|
|
63
|
+
export { toJSONSchema, toPartialJSONSchema, toToolsJSONSchema };
|
|
64
|
+
|
|
99
65
|
//# sourceMappingURL=schema-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-utils.js","
|
|
1
|
+
{"version":3,"file":"schema-utils.js","names":[],"sources":["../../../src/core/tool/schema-utils.ts"],"sourcesContent":["import type { JSONSchema7 } from \"json-schema\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { Tool } from \"./tool-types\";\n\n/**\n * Type for a tool definition with JSON Schema parameters.\n */\nexport type ToolJSONSchema = {\n description?: string;\n parameters: JSONSchema7;\n};\n\nexport type ToToolsJSONSchemaOptions = {\n /**\n * Filter to determine which tools to include.\n * Defaults to excluding disabled tools and backend tools.\n */\n filter?: (name: string, tool: Tool) => boolean;\n};\n\nfunction isStandardSchema(schema: unknown): schema is StandardSchemaV1 & {\n \"~standard\": StandardSchemaV1[\"~standard\"] & {\n toJSONSchema?: () => unknown;\n jsonSchema?: { input?: () => unknown; output?: () => unknown };\n };\n} {\n return (\n typeof schema === \"object\" &&\n schema !== null &&\n \"~standard\" in schema &&\n typeof (schema as StandardSchemaV1)[\"~standard\"] === \"object\"\n );\n}\n\nfunction hasToJSONSchemaMethod(\n schema: unknown,\n): schema is { toJSONSchema: () => unknown } {\n return (\n typeof schema === \"object\" &&\n schema !== null &&\n \"toJSONSchema\" in schema &&\n typeof (schema as { toJSONSchema: unknown }).toJSONSchema === \"function\"\n );\n}\n\nfunction hasToJSONMethod(schema: unknown): schema is { toJSON: () => unknown } {\n return (\n typeof schema === \"object\" &&\n schema !== null &&\n \"toJSON\" in schema &&\n typeof (schema as { toJSON: unknown }).toJSON === \"function\"\n );\n}\n\n/**\n * Converts a schema to JSONSchema7.\n * Supports:\n * - StandardSchemaV1 with ~standard.toJSONSchema (e.g., Zod v4)\n * - StandardSchemaV1 with ~standard.jsonSchema.input() (e.g., Zod v4)\n * - Objects with toJSONSchema() method (e.g., Zod v4)\n * - Objects with toJSON() method\n * - Plain JSONSchema7 objects (must have a \"type\" property)\n */\nexport function toJSONSchema(\n schema: StandardSchemaV1 | JSONSchema7,\n): JSONSchema7 {\n // StandardSchemaV1 with ~standard.toJSONSchema (e.g., Zod v4)\n if (isStandardSchema(schema)) {\n const toJSONSchemaMethod = schema[\"~standard\"].toJSONSchema;\n if (typeof toJSONSchemaMethod === \"function\") {\n return toJSONSchemaMethod() as JSONSchema7;\n }\n\n // StandardSchemaV1 with ~standard.jsonSchema.input()\n const jsonSchema = schema[\"~standard\"].jsonSchema;\n if (\n typeof jsonSchema === \"object\" &&\n jsonSchema !== null &&\n typeof jsonSchema.input === \"function\"\n ) {\n return jsonSchema.input() as JSONSchema7;\n }\n }\n\n // toJSONSchema method on the schema itself\n if (hasToJSONSchemaMethod(schema)) {\n return schema.toJSONSchema() as JSONSchema7;\n }\n\n // toJSON method on the schema\n if (hasToJSONMethod(schema)) {\n return schema.toJSON() as JSONSchema7;\n }\n\n // If it's a Standard Schema that we couldn't convert, throw a helpful error\n if (isStandardSchema(schema)) {\n throw new Error(\n \"Could not convert schema to JSON Schema. \" +\n \"The schema implements Standard Schema but does not support JSON Schema conversion. \" +\n \"If you are using Zod, please upgrade to Zod v4 (npm install zod@latest). \" +\n \"Alternatively, pass a plain JSON Schema object instead.\",\n );\n }\n\n // Already a plain JSONSchema7\n return schema as JSONSchema7;\n}\n\n/**\n * Returns a copy of the JSON Schema with `required` removed recursively,\n * making every property optional. Array item schemas are left unchanged.\n */\nexport function toPartialJSONSchema(schema: JSONSchema7): JSONSchema7 {\n const { required: _, ...result } = schema;\n\n if (result.properties) {\n result.properties = Object.fromEntries(\n Object.entries(result.properties).map(([key, prop]) => {\n if (typeof prop === \"object\" && prop !== null && !Array.isArray(prop)) {\n const p = prop as JSONSchema7;\n return [key, p.properties != null ? toPartialJSONSchema(p) : prop];\n }\n return [key, prop];\n }),\n );\n }\n\n return result;\n}\n\nfunction defaultToolFilter(_name: string, tool: Tool): boolean {\n return !tool.disabled && tool.type !== \"backend\";\n}\n\n/**\n * Converts a record of tools to a record of tool definitions with JSON Schema parameters.\n * By default, filters out disabled tools and backend tools.\n */\nexport function toToolsJSONSchema(\n tools: Record<string, Tool> | undefined,\n options: ToToolsJSONSchemaOptions = {},\n): Record<string, ToolJSONSchema> {\n if (!tools) return {};\n\n const filter = options.filter ?? defaultToolFilter;\n\n return Object.fromEntries(\n Object.entries(tools)\n .filter(([name, tool]) => filter(name, tool) && tool.parameters)\n .map(([name, tool]) => [\n name,\n {\n ...(tool.description && { description: tool.description }),\n parameters: toJSONSchema(tool.parameters!),\n },\n ]),\n );\n}\n"],"mappings":";AAoBA,SAAS,iBAAiB,QAKxB;CACA,OACE,OAAO,WAAW,YAClB,WAAW,QACX,eAAe,UACf,OAAQ,OAA4B,iBAAiB;AAEzD;AAEA,SAAS,sBACP,QAC2C;CAC3C,OACE,OAAO,WAAW,YAClB,WAAW,QACX,kBAAkB,UAClB,OAAQ,OAAqC,iBAAiB;AAElE;AAEA,SAAS,gBAAgB,QAAsD;CAC7E,OACE,OAAO,WAAW,YAClB,WAAW,QACX,YAAY,UACZ,OAAQ,OAA+B,WAAW;AAEtD;;;;;;;;;;AAWA,SAAgB,aACd,QACa;CAEb,IAAI,iBAAiB,MAAM,GAAG;EAC5B,MAAM,qBAAqB,OAAO,aAAa;EAC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@@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { AsyncIterableStream } from "../../utils/AsyncIterableStream.js";
|
|
2
|
+
import { JSONSchema7 } from "../../node_modules/.pnpm/@types_json-schema@7.0.15/node_modules/@types/json-schema/index.js";
|
|
3
|
+
import { DeepPartial, TypeAtPath, TypePath } from "./type-path-utils.js";
|
|
4
|
+
import { ToolResponse } from "./ToolResponse.js";
|
|
5
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
6
|
+
|
|
7
|
+
//#region src/core/tool/tool-types.d.ts
|
|
8
|
+
type ToolModelContentPart = {
|
|
9
|
+
/** A text content part returned to the model after a tool call. */readonly type: "text"; /** Text that should be included in the model-visible tool result. */
|
|
10
|
+
readonly text: string;
|
|
9
11
|
} | {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
/** A file content part returned to the model after a tool call. */readonly type: "file";
|
|
13
|
+
/**
|
|
14
|
+
* File payload encoded as a provider-compatible string, commonly base64
|
|
15
|
+
* for binary data.
|
|
16
|
+
*/
|
|
17
|
+
readonly data: string; /** MIME type for the file payload. */
|
|
18
|
+
readonly mediaType: string; /** Optional display filename for the file payload. */
|
|
19
|
+
readonly filename?: string;
|
|
14
20
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Converts a tool's runtime result into content that is sent back to the
|
|
23
|
+
* model.
|
|
24
|
+
*
|
|
25
|
+
* Return this when the value shown in the UI or stored as the tool result
|
|
26
|
+
* should differ from the model-visible response. When omitted, the successful
|
|
27
|
+
* tool result is sent back to the model as-is. If a tool returns a
|
|
28
|
+
* `ToolResponse` with `modelContent`, that explicit content is used instead
|
|
29
|
+
* of calling this function.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const toModelOutput: ToolModelOutputFunction<
|
|
34
|
+
* { documentId: string },
|
|
35
|
+
* { summary: string; pdfBase64: string }
|
|
36
|
+
* > = ({ output }) => [
|
|
37
|
+
* { type: "text", text: output.summary },
|
|
38
|
+
* {
|
|
39
|
+
* type: "file",
|
|
40
|
+
* data: output.pdfBase64,
|
|
41
|
+
* mediaType: "application/pdf",
|
|
42
|
+
* },
|
|
43
|
+
* ];
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
type ToolModelOutputFunction<TArgs, TResult> = (options: {
|
|
47
|
+
/** Stable identifier for the tool call being converted. */toolCallId: string; /** Arguments supplied by the model for this tool call. */
|
|
48
|
+
input: TArgs; /** Value returned by the tool's {@link ToolExecuteFunction}. */
|
|
49
|
+
output: TResult;
|
|
19
50
|
}) => readonly ToolModelContentPart[] | Promise<readonly ToolModelContentPart[]>;
|
|
20
51
|
/**
|
|
21
52
|
* Interface for reading tool call arguments from a stream, which are
|
|
@@ -25,96 +56,146 @@ export type ToolModelOutputFunction<TArgs, TResult> = (options: {
|
|
|
25
56
|
*
|
|
26
57
|
* @template TArgs The type of arguments being read.
|
|
27
58
|
*/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
59
|
+
interface ToolCallArgsReader<TArgs extends Record<string, unknown>> {
|
|
60
|
+
/**
|
|
61
|
+
* Returns a promise that will resolve to the value at the given path,
|
|
62
|
+
* as soon as that path is generated by the LLM.
|
|
63
|
+
*
|
|
64
|
+
* @param fieldPath An array of object keys or array indices.
|
|
65
|
+
*/
|
|
66
|
+
get<PathT extends TypePath<TArgs>>(...fieldPath: PathT): Promise<TypeAtPath<TArgs, PathT>>;
|
|
67
|
+
/**
|
|
68
|
+
* Returns a stream that will emit partial values at the given path,
|
|
69
|
+
* as they are generated by the LLM.
|
|
70
|
+
*
|
|
71
|
+
* @param fieldPath An array of object keys or array indices.
|
|
72
|
+
*/
|
|
73
|
+
streamValues<PathT extends TypePath<TArgs>>(...fieldPath: PathT): AsyncIterableStream<DeepPartial<TypeAtPath<TArgs, PathT>>>;
|
|
74
|
+
/**
|
|
75
|
+
* Returns a stream that will emit partial text at the given path,
|
|
76
|
+
* as they are generated by the LLM.
|
|
77
|
+
*
|
|
78
|
+
* @param fieldPath An array of object keys or array indices.
|
|
79
|
+
*/
|
|
80
|
+
streamText<PathT extends TypePath<TArgs>>(...fieldPath: PathT): TypeAtPath<TArgs, PathT> extends string & infer U ? AsyncIterableStream<U> : never;
|
|
81
|
+
/**
|
|
82
|
+
* Returns a stream that will emit complete items in the array
|
|
83
|
+
* at the given path, as they are generated by the LLM.
|
|
84
|
+
*
|
|
85
|
+
* @param fieldPath An array of object keys or array indices.
|
|
86
|
+
*/
|
|
87
|
+
forEach<PathT extends TypePath<TArgs>>(...fieldPath: PathT): TypeAtPath<TArgs, PathT> extends Array<infer U> ? AsyncIterableStream<U> : never;
|
|
57
88
|
}
|
|
58
|
-
|
|
59
|
-
|
|
89
|
+
interface ToolCallResponseReader<TResult> {
|
|
90
|
+
get: () => Promise<ToolResponse<TResult>>;
|
|
60
91
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
92
|
+
interface ToolCallReader<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> {
|
|
93
|
+
args: ToolCallArgsReader<TArgs>;
|
|
94
|
+
response: ToolCallResponseReader<TResult>;
|
|
95
|
+
/**
|
|
96
|
+
* @deprecated Use {@link ToolCallReader.response} and read
|
|
97
|
+
* `response.get().result` instead.
|
|
98
|
+
*/
|
|
99
|
+
result: {
|
|
100
|
+
get: () => Promise<TResult>;
|
|
101
|
+
};
|
|
70
102
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
103
|
+
type ToolExecutionContext = {
|
|
104
|
+
/** Stable identifier for the tool call being executed. */toolCallId: string; /** Signal that is aborted when the current run is cancelled. */
|
|
105
|
+
abortSignal: AbortSignal;
|
|
106
|
+
/**
|
|
107
|
+
* From inside a frontend tool's execute function, request human input from
|
|
108
|
+
* the UI. Resolves with the payload the UI supplies.
|
|
109
|
+
*/
|
|
110
|
+
human: (payload: unknown) => Promise<unknown>;
|
|
75
111
|
};
|
|
76
|
-
|
|
77
|
-
|
|
112
|
+
/**
|
|
113
|
+
* Function called when assistant-ui executes a frontend tool.
|
|
114
|
+
*/
|
|
115
|
+
type ToolExecuteFunction<TArgs, TResult> = (args: TArgs, context: ToolExecutionContext) => TResult | Promise<TResult>;
|
|
116
|
+
type ToolStreamCallFunction<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = (reader: ToolCallReader<TArgs, TResult>, context: ToolExecutionContext) => void;
|
|
78
117
|
type OnSchemaValidationErrorFunction<TResult> = ToolExecuteFunction<unknown, TResult>;
|
|
79
118
|
type ToolBase<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
119
|
+
/**
|
|
120
|
+
* @deprecated Experimental, API may change.
|
|
121
|
+
*/
|
|
122
|
+
streamCall?: ToolStreamCallFunction<TArgs, TResult>;
|
|
84
123
|
};
|
|
85
124
|
type BackendTool<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = ToolBase<TArgs, TResult> & {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
125
|
+
/** Tool that is executed by the backend rather than in the browser. */type: "backend";
|
|
126
|
+
description?: undefined;
|
|
127
|
+
parameters?: undefined;
|
|
128
|
+
disabled?: undefined;
|
|
129
|
+
execute?: undefined;
|
|
130
|
+
toModelOutput?: undefined;
|
|
131
|
+
experimental_onSchemaValidationError?: undefined;
|
|
93
132
|
};
|
|
94
133
|
type FrontendTool<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = ToolBase<TArgs, TResult> & {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
134
|
+
/** Tool that is executed in the frontend runtime. */type: "frontend"; /** Natural-language description shown to the model when selecting tools. */
|
|
135
|
+
description?: string | undefined; /** Schema for the arguments the model must provide when calling the tool. */
|
|
136
|
+
parameters: StandardSchemaV1<TArgs> | JSONSchema7; /** Prevents the tool from being exposed to the model while true. */
|
|
137
|
+
disabled?: boolean; /** Executes the tool after the model provides valid arguments. */
|
|
138
|
+
execute: ToolExecuteFunction<TArgs, TResult>; /** Converts the execution result into model-visible output. */
|
|
139
|
+
toModelOutput?: ToolModelOutputFunction<TArgs, TResult>; /** Handles invalid tool arguments when schema validation fails. */
|
|
140
|
+
experimental_onSchemaValidationError?: OnSchemaValidationErrorFunction<TResult>;
|
|
102
141
|
};
|
|
103
142
|
type HumanTool<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = ToolBase<TArgs, TResult> & {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
143
|
+
/** Tool that pauses the run until a user or UI supplies a result. */type: "human"; /** Natural-language description shown to the model when selecting tools. */
|
|
144
|
+
description?: string | undefined; /** Schema for the arguments the model must provide when requesting input. */
|
|
145
|
+
parameters: StandardSchemaV1<TArgs> | JSONSchema7; /** Prevents the tool from being exposed to the model while true. */
|
|
146
|
+
disabled?: boolean;
|
|
147
|
+
execute?: undefined;
|
|
148
|
+
toModelOutput?: undefined;
|
|
149
|
+
experimental_onSchemaValidationError?: undefined;
|
|
111
150
|
};
|
|
112
|
-
export type Tool<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = FrontendTool<TArgs, TResult> | BackendTool<TArgs, TResult> | HumanTool<TArgs, TResult> | ToolWithoutType<TArgs, TResult>;
|
|
113
151
|
/**
|
|
114
|
-
*
|
|
152
|
+
* Definition for a tool that can be exposed to the assistant model.
|
|
153
|
+
*
|
|
154
|
+
* Use `type: "frontend"` for tools executed in the browser, `type: "backend"`
|
|
155
|
+
* for tools handled by your server, and `type: "human"` for flows that pause
|
|
156
|
+
* until the UI supplies a result.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts
|
|
160
|
+
* const frontendTool: Tool<{ city: string }, string> = {
|
|
161
|
+
* type: "frontend",
|
|
162
|
+
* description: "Get the weather for a city.",
|
|
163
|
+
* parameters: {
|
|
164
|
+
* type: "object",
|
|
165
|
+
* properties: { city: { type: "string" } },
|
|
166
|
+
* required: ["city"],
|
|
167
|
+
* },
|
|
168
|
+
* execute: async ({ city }) => `Sunny in ${city}`,
|
|
169
|
+
* };
|
|
170
|
+
* ```
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* const backendTool: Tool = {
|
|
175
|
+
* type: "backend",
|
|
176
|
+
* };
|
|
177
|
+
* ```
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* const humanTool: Tool<{ question: string }, string> = {
|
|
182
|
+
* type: "human",
|
|
183
|
+
* description: "Ask the user a follow-up question.",
|
|
184
|
+
* parameters: {
|
|
185
|
+
* type: "object",
|
|
186
|
+
* properties: { question: { type: "string" } },
|
|
187
|
+
* required: ["question"],
|
|
188
|
+
* },
|
|
189
|
+
* };
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
type Tool<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = FrontendTool<TArgs, TResult> | BackendTool<TArgs, TResult> | HumanTool<TArgs, TResult> | ToolWithoutType<TArgs, TResult>;
|
|
193
|
+
/**
|
|
194
|
+
* @deprecated Use {@link Tool} with an explicit `type` field instead.
|
|
115
195
|
*/
|
|
116
|
-
|
|
117
|
-
|
|
196
|
+
type ToolWithoutType<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = (Omit<FrontendTool<TArgs, TResult>, "type"> | Omit<BackendTool<TArgs, TResult>, "type"> | Omit<HumanTool<TArgs, TResult>, "type">) & {
|
|
197
|
+
type?: undefined;
|
|
118
198
|
};
|
|
119
|
-
|
|
199
|
+
//#endregion
|
|
200
|
+
export { Tool, ToolCallArgsReader, ToolCallReader, ToolCallResponseReader, ToolExecuteFunction, ToolExecutionContext, ToolModelContentPart, ToolModelOutputFunction, ToolStreamCallFunction, ToolWithoutType };
|
|
120
201
|
//# sourceMappingURL=tool-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-types.d.ts","
|
|
1
|
+
{"version":3,"file":"tool-types.d.ts","names":[],"sources":["../../../src/core/tool/tool-types.ts"],"mappings":";;;;;;;KAMY,oBAAA;8EAGG,IAAA,UAHH;EAAA,SAKG,IAAA;AAAA;EALiB,4EASjB,IAAA;EAJA;;;;EAAA,SASA,IAAA,UAIQ;EAAA,SAFR,SAAA,UA8BH;EAAA,SA5BG,QAAA;AAAA;;;;;;;;;;;;;;;;;;;;AAqC0B;AAUzC;;;;;KAnBY,uBAAA,oBAA2C,OAAA;EA2BrC,2DAzBhB,UAAA,UA0B6B;EAxB7B,KAAA,EAAO,KAAA,EAwBJ;EAtBH,MAAA,EAAQ,OAAA;AAAA,eAEG,oBAAA,KACT,OAAA,UAAiB,oBAAA;;;;;;;;;UAUJ,kBAAA,eAAiC,MAAA;EA6BlC;;;;;;E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