assistant-stream 0.3.15 → 0.3.17
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 +35 -31
- package/dist/core/AssistantStream.d.ts.map +1 -1
- package/dist/core/AssistantStream.js +39 -37
- package/dist/core/AssistantStream.js.map +1 -1
- package/dist/core/AssistantStreamChunk.d.ts +71 -78
- 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 +62 -66
- package/dist/core/modules/assistant-stream.d.ts.map +1 -1
- package/dist/core/modules/assistant-stream.js +176 -182
- 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 +41 -41
- package/dist/core/tool/ToolResponse.d.ts.map +1 -1
- package/dist/core/tool/ToolResponse.js +50 -56
- 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 +103 -122
- 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 +11 -9
- package/dist/core/tool/toolResultStream.d.ts.map +1 -1
- package/dist/core/tool/toolResultStream.js +127 -157
- 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 +3 -3
- package/src/core/modules/assistant-stream.test.ts +104 -0
- package/src/core/modules/assistant-stream.ts +13 -4
- 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,59 +1,53 @@
|
|
|
1
|
+
//#region src/core/tool/ToolResponse.ts
|
|
1
2
|
const TOOL_RESPONSE_SYMBOL = Symbol.for("aui.tool-response");
|
|
2
3
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
return result;
|
|
53
|
-
}
|
|
54
|
-
return new ToolResponse({
|
|
55
|
-
result: result === undefined ? "<no result>" : result,
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
}
|
|
4
|
+
* Tool result wrapper for separating UI-visible output from model-visible
|
|
5
|
+
* output.
|
|
6
|
+
*
|
|
7
|
+
* Return `ToolResponse` from a tool when you need to attach an artifact, mark
|
|
8
|
+
* the result as an error, or control the content sent back to the model.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* return new ToolResponse({
|
|
13
|
+
* result: { title: "Report ready" },
|
|
14
|
+
* artifact: { reportId },
|
|
15
|
+
* modelContent: [{ type: "text", text: "The report is ready." }],
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
var ToolResponse = class ToolResponse {
|
|
20
|
+
get [TOOL_RESPONSE_SYMBOL]() {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
artifact;
|
|
24
|
+
result;
|
|
25
|
+
isError;
|
|
26
|
+
modelContent;
|
|
27
|
+
messages;
|
|
28
|
+
constructor(options) {
|
|
29
|
+
if (options.artifact !== void 0) this.artifact = options.artifact;
|
|
30
|
+
this.result = options.result;
|
|
31
|
+
this.isError = options.isError ?? false;
|
|
32
|
+
if (options.modelContent !== void 0) this.modelContent = options.modelContent;
|
|
33
|
+
if (options.messages !== void 0) this.messages = options.messages;
|
|
34
|
+
}
|
|
35
|
+
static [Symbol.hasInstance](obj) {
|
|
36
|
+
return typeof obj === "object" && obj !== null && TOOL_RESPONSE_SYMBOL in obj;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Converts a plain tool return value into a {@link ToolResponse}.
|
|
40
|
+
*
|
|
41
|
+
* Existing `ToolResponse` instances are returned unchanged. `undefined`
|
|
42
|
+
* becomes the string `"<no result>"` so downstream protocol chunks always
|
|
43
|
+
* carry a concrete result.
|
|
44
|
+
*/
|
|
45
|
+
static toResponse(result) {
|
|
46
|
+
if (result instanceof ToolResponse) return result;
|
|
47
|
+
return new ToolResponse({ result: result === void 0 ? "<no result>" : result });
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
//#endregion
|
|
51
|
+
export { ToolResponse };
|
|
52
|
+
|
|
59
53
|
//# sourceMappingURL=ToolResponse.js.map
|
|
@@ -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/C,IAAI,OAAO,uBAAuB,YAChC,OAAO,mBAAmB;EAI5B,MAAM,aAAa,OAAO,aAAa;EACvC,IACE,OAAO,eAAe,YACtB,eAAe,QACf,OAAO,WAAW,UAAU,YAE5B,OAAO,WAAW,MAAM;CAE5B;CAGA,IAAI,sBAAsB,MAAM,GAC9B,OAAO,OAAO,aAAa;CAI7B,IAAI,gBAAgB,MAAM,GACxB,OAAO,OAAO,OAAO;CAIvB,IAAI,iBAAiB,MAAM,GACzB,MAAM,IAAI,MACR,8PAIF;CAIF,OAAO;AACT;;;;;AAMA,SAAgB,oBAAoB,QAAkC;CACpE,MAAM,EAAE,UAAU,GAAG,GAAG,WAAW;CAEnC,IAAI,OAAO,YACT,OAAO,aAAa,OAAO,YACzB,OAAO,QAAQ,OAAO,UAAU,EAAE,KAAK,CAAC,KAAK,UAAU;EACrD,IAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,CAAC,MAAM,QAAQ,IAAI,GAAG;GACrE,MAAM,IAAI;GACV,OAAO,CAAC,KAAK,EAAE,cAAc,OAAO,oBAAoB,CAAC,IAAI,IAAI;EACnE;EACA,OAAO,CAAC,KAAK,IAAI;CACnB,CAAC,CACH;CAGF,OAAO;AACT;AAEA,SAAS,kBAAkB,OAAe,MAAqB;CAC7D,OAAO,CAAC,KAAK,YAAY,KAAK,SAAS;AACzC;;;;;AAMA,SAAgB,kBACd,OACA,UAAoC,CAAC,GACL;CAChC,IAAI,CAAC,OAAO,OAAO,CAAC;CAEpB,MAAM,SAAS,QAAQ,UAAU;CAEjC,OAAO,OAAO,YACZ,OAAO,QAAQ,KAAK,EACjB,QAAQ,CAAC,MAAM,UAAU,OAAO,MAAM,IAAI,KAAK,KAAK,UAAU,EAC9D,KAAK,CAAC,MAAM,UAAU,CACrB,MACA;EACE,GAAI,KAAK,eAAe,EAAE,aAAa,KAAK,YAAY;EACxD,YAAY,aAAa,KAAK,UAAW;CAC3C,CACF,CAAC,CACL;AACF"}
|