assistant-stream 0.3.15 → 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 +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 +174 -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/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,25 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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;
|
|
11
11
|
} | {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
readonly mediaType: string;
|
|
21
|
-
/** Optional display filename for the file payload. */
|
|
22
|
-
readonly filename?: string;
|
|
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;
|
|
23
20
|
};
|
|
24
21
|
/**
|
|
25
22
|
* Converts a tool's runtime result into content that is sent back to the
|
|
@@ -46,13 +43,10 @@ export type ToolModelContentPart = {
|
|
|
46
43
|
* ];
|
|
47
44
|
* ```
|
|
48
45
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
input: TArgs;
|
|
54
|
-
/** Value returned by the tool's {@link ToolExecuteFunction}. */
|
|
55
|
-
output: TResult;
|
|
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;
|
|
56
50
|
}) => readonly ToolModelContentPart[] | Promise<readonly ToolModelContentPart[]>;
|
|
57
51
|
/**
|
|
58
52
|
* Interface for reading tool call arguments from a stream, which are
|
|
@@ -62,111 +56,97 @@ export type ToolModelOutputFunction<TArgs, TResult> = (options: {
|
|
|
62
56
|
*
|
|
63
57
|
* @template TArgs The type of arguments being read.
|
|
64
58
|
*/
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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;
|
|
94
88
|
}
|
|
95
|
-
|
|
96
|
-
|
|
89
|
+
interface ToolCallResponseReader<TResult> {
|
|
90
|
+
get: () => Promise<ToolResponse<TResult>>;
|
|
97
91
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
+
};
|
|
108
102
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
*/
|
|
118
|
-
human: (payload: unknown) => Promise<unknown>;
|
|
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>;
|
|
119
111
|
};
|
|
120
112
|
/**
|
|
121
113
|
* Function called when assistant-ui executes a frontend tool.
|
|
122
114
|
*/
|
|
123
|
-
|
|
124
|
-
|
|
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;
|
|
125
117
|
type OnSchemaValidationErrorFunction<TResult> = ToolExecuteFunction<unknown, TResult>;
|
|
126
118
|
type ToolBase<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
119
|
+
/**
|
|
120
|
+
* @deprecated Experimental, API may change.
|
|
121
|
+
*/
|
|
122
|
+
streamCall?: ToolStreamCallFunction<TArgs, TResult>;
|
|
131
123
|
};
|
|
132
124
|
type BackendTool<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = ToolBase<TArgs, TResult> & {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
experimental_onSchemaValidationError?: undefined;
|
|
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;
|
|
141
132
|
};
|
|
142
133
|
type FrontendTool<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = ToolBase<TArgs, TResult> & {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
disabled?: boolean;
|
|
151
|
-
/** Executes the tool after the model provides valid arguments. */
|
|
152
|
-
execute: ToolExecuteFunction<TArgs, TResult>;
|
|
153
|
-
/** Converts the execution result into model-visible output. */
|
|
154
|
-
toModelOutput?: ToolModelOutputFunction<TArgs, TResult>;
|
|
155
|
-
/** Handles invalid tool arguments when schema validation fails. */
|
|
156
|
-
experimental_onSchemaValidationError?: OnSchemaValidationErrorFunction<TResult>;
|
|
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>;
|
|
157
141
|
};
|
|
158
142
|
type HumanTool<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown> = ToolBase<TArgs, TResult> & {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
disabled?: boolean;
|
|
167
|
-
execute?: undefined;
|
|
168
|
-
toModelOutput?: undefined;
|
|
169
|
-
experimental_onSchemaValidationError?: undefined;
|
|
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;
|
|
170
150
|
};
|
|
171
151
|
/**
|
|
172
152
|
* Definition for a tool that can be exposed to the assistant model.
|
|
@@ -209,12 +189,13 @@ type HumanTool<TArgs extends Record<string, unknown> = Record<string, unknown>,
|
|
|
209
189
|
* };
|
|
210
190
|
* ```
|
|
211
191
|
*/
|
|
212
|
-
|
|
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>;
|
|
213
193
|
/**
|
|
214
194
|
* @deprecated Use {@link Tool} with an explicit `type` field instead.
|
|
215
195
|
*/
|
|
216
|
-
|
|
217
|
-
|
|
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;
|
|
218
198
|
};
|
|
219
|
-
|
|
199
|
+
//#endregion
|
|
200
|
+
export { Tool, ToolCallArgsReader, ToolCallReader, ToolCallResponseReader, ToolExecuteFunction, ToolExecutionContext, ToolModelContentPart, ToolModelOutputFunction, ToolStreamCallFunction, ToolWithoutType };
|
|
220
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,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oBAA0B,MAAA,yCAGtC,IAAA,CAAK,YAAA,CAAa,KAAA,EAAO,OAAA,aACzB,IAAA,CAAK,WAAA,CAAY,KAAA,EAAO,OAAA,aACxB,IAAA,CAAK,SAAA,CAAU,KAAA,EAAO,OAAA;EACpB,IAAA;AAAA"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Tool } from "./tool-types.js";
|
|
2
|
+
import { AssistantMessage } from "../utils/types.js";
|
|
2
3
|
import { ToolExecutionStream } from "./ToolExecutionStream.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
onExecutionEnd?: (toolCallId: string, toolName: string) => void;
|
|
4
|
+
|
|
5
|
+
//#region src/core/tool/toolResultStream.d.ts
|
|
6
|
+
declare function unstable_runPendingTools(message: AssistantMessage, tools: Record<string, Tool> | undefined, abortSignal: AbortSignal, human: (toolCallId: string, payload: unknown) => Promise<unknown>): Promise<AssistantMessage>;
|
|
7
|
+
type ToolResultStreamOptions = {
|
|
8
|
+
/** Called immediately before a frontend tool's `execute` function runs. */onExecutionStart?: (toolCallId: string, toolName: string) => void; /** Called after frontend tool execution finishes or fails. */
|
|
9
|
+
onExecutionEnd?: (toolCallId: string, toolName: string) => void;
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
12
|
* Transform stream that executes frontend tools and appends tool results.
|
|
@@ -21,5 +21,7 @@ export type ToolResultStreamOptions = {
|
|
|
21
21
|
* @param human Callback used to resolve human-tool requests from UI input.
|
|
22
22
|
* @param options Optional execution lifecycle callbacks.
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
declare function toolResultStream(tools: Record<string, Tool> | (() => Record<string, Tool> | undefined) | undefined, abortSignal: AbortSignal | (() => AbortSignal), human: (toolCallId: string, payload: unknown) => Promise<unknown>, options?: ToolResultStreamOptions): ToolExecutionStream;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { ToolResultStreamOptions, toolResultStream, unstable_runPendingTools };
|
|
25
27
|
//# sourceMappingURL=toolResultStream.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolResultStream.d.ts","
|
|
1
|
+
{"version":3,"file":"toolResultStream.d.ts","names":[],"sources":["../../../src/core/tool/toolResultStream.ts"],"mappings":";;;;;iBA6IsB,wBAAA,CACpB,OAAA,EAAS,gBAAA,EACT,KAAA,EAAO,MAAA,SAAe,IAAA,eACtB,WAAA,EAAa,WAAA,EACb,KAAA,GAAQ,UAAA,UAAoB,OAAA,cAAqB,OAAA,YAAgB,OAAA,CAAA,gBAAA;AAAA,KAsEvD,uBAAA;EA1EU,2EA4EpB,gBAAA,IAAoB,UAAA,UAAoB,QAAA;EAExC,cAAA,IAAkB,UAAA,UAAoB,QAAA;AAAA;;;;;;;;;;;;;;iBAgBxB,gBAAA,CACd,KAAA,EACI,MAAA,SAAe,IAAA,WACR,MAAA,SAAe,IAAA,4BAE1B,WAAA,EAAa,WAAA,UAAqB,WAAA,GAClC,KAAA,GAAQ,UAAA,UAAoB,OAAA,cAAqB,OAAA,WACjD,OAAA,GAAU,uBAAA,GAAuB,mBAAA"}
|