assistant-stream 0.1.5 → 0.1.7
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/dist/ai-sdk/index.d.ts +5 -0
- package/dist/ai-sdk/index.d.ts.map +1 -0
- package/dist/ai-sdk/index.js +199 -0
- package/dist/ai-sdk/index.js.map +1 -0
- package/dist/ai-sdk/index.mjs +173 -0
- package/dist/ai-sdk/index.mjs.map +1 -0
- package/dist/ai-sdk/language-model.d.ts +6 -0
- package/dist/ai-sdk/language-model.d.ts.map +1 -0
- package/dist/ai-sdk/language-model.js +131 -0
- package/dist/ai-sdk/language-model.js.map +1 -0
- package/dist/ai-sdk/language-model.mjs +106 -0
- package/dist/ai-sdk/language-model.mjs.map +1 -0
- package/dist/ai-sdk.d.ts +3 -24
- package/dist/ai-sdk.d.ts.map +1 -0
- package/dist/ai-sdk.js +5 -782
- package/dist/ai-sdk.js.map +1 -1
- package/dist/ai-sdk.mjs +4 -276
- package/dist/ai-sdk.mjs.map +1 -1
- package/dist/core/AssistantStream.d.ts +12 -0
- package/dist/core/AssistantStream.d.ts.map +1 -0
- package/dist/core/AssistantStream.js +46 -0
- package/dist/core/AssistantStream.js.map +1 -0
- package/dist/core/AssistantStream.mjs +21 -0
- package/dist/core/AssistantStream.mjs.map +1 -0
- package/dist/core/AssistantStreamChunk.d.ts +64 -0
- package/dist/core/AssistantStreamChunk.d.ts.map +1 -0
- package/dist/core/AssistantStreamChunk.js +19 -0
- package/dist/core/AssistantStreamChunk.js.map +1 -0
- package/dist/core/AssistantStreamChunk.mjs +1 -0
- package/dist/core/AssistantStreamChunk.mjs.map +1 -0
- package/dist/core/accumulators/AssistantMessageStream.d.ts +13 -0
- package/dist/core/accumulators/AssistantMessageStream.d.ts.map +1 -0
- package/dist/core/accumulators/AssistantMessageStream.js +79 -0
- package/dist/core/accumulators/AssistantMessageStream.js.map +1 -0
- package/dist/core/accumulators/AssistantMessageStream.mjs +54 -0
- package/dist/core/accumulators/AssistantMessageStream.mjs.map +1 -0
- package/dist/core/accumulators/assistant-message-accumulator.d.ts +8 -0
- package/dist/core/accumulators/assistant-message-accumulator.d.ts.map +1 -0
- package/dist/core/accumulators/assistant-message-accumulator.js +334 -0
- package/dist/core/accumulators/assistant-message-accumulator.js.map +1 -0
- package/dist/core/accumulators/assistant-message-accumulator.mjs +309 -0
- package/dist/core/accumulators/assistant-message-accumulator.mjs.map +1 -0
- package/dist/core/index.d.ts +11 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +55 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/index.mjs +26 -0
- package/dist/core/index.mjs.map +1 -0
- package/dist/core/modules/assistant-stream.d.ts +31 -0
- package/dist/core/modules/assistant-stream.d.ts.map +1 -0
- package/dist/core/modules/assistant-stream.js +224 -0
- package/dist/core/modules/assistant-stream.js.map +1 -0
- package/dist/core/modules/assistant-stream.mjs +202 -0
- package/dist/core/modules/assistant-stream.mjs.map +1 -0
- package/dist/core/modules/text.d.ts +9 -0
- package/dist/core/modules/text.d.ts.map +1 -0
- package/dist/core/modules/text.js +78 -0
- package/dist/core/modules/text.js.map +1 -0
- package/dist/core/modules/text.mjs +52 -0
- package/dist/core/modules/text.mjs.map +1 -0
- package/dist/core/modules/tool-call.d.ts +13 -0
- package/dist/core/modules/tool-call.d.ts.map +1 -0
- package/dist/core/modules/tool-call.js +110 -0
- package/dist/core/modules/tool-call.js.map +1 -0
- package/dist/core/modules/tool-call.mjs +84 -0
- package/dist/core/modules/tool-call.mjs.map +1 -0
- package/dist/core/serialization/PlainText.d.ts +11 -0
- package/dist/core/serialization/PlainText.d.ts.map +1 -0
- package/dist/core/serialization/PlainText.js +70 -0
- package/dist/core/serialization/PlainText.js.map +1 -0
- package/dist/core/serialization/PlainText.mjs +44 -0
- package/dist/core/serialization/PlainText.mjs.map +1 -0
- package/dist/core/serialization/data-stream/DataStream.d.ts +11 -0
- package/dist/core/serialization/data-stream/DataStream.d.ts.map +1 -0
- package/dist/core/serialization/data-stream/DataStream.js +332 -0
- package/dist/core/serialization/data-stream/DataStream.js.map +1 -0
- package/dist/core/serialization/data-stream/DataStream.mjs +311 -0
- package/dist/core/serialization/data-stream/DataStream.mjs.map +1 -0
- package/dist/core/serialization/data-stream/chunk-types.d.ts +86 -0
- package/dist/core/serialization/data-stream/chunk-types.d.ts.map +1 -0
- package/dist/core/serialization/data-stream/chunk-types.js +49 -0
- package/dist/core/serialization/data-stream/chunk-types.js.map +1 -0
- package/dist/core/serialization/data-stream/chunk-types.mjs +24 -0
- package/dist/core/serialization/data-stream/chunk-types.mjs.map +1 -0
- package/dist/core/serialization/data-stream/serialization.d.ts +8 -0
- package/dist/core/serialization/data-stream/serialization.d.ts.map +1 -0
- package/dist/core/serialization/data-stream/serialization.js +56 -0
- package/dist/core/serialization/data-stream/serialization.js.map +1 -0
- package/dist/core/serialization/data-stream/serialization.mjs +30 -0
- package/dist/core/serialization/data-stream/serialization.mjs.map +1 -0
- package/dist/core/tool/ToolCallReader.d.ts +33 -0
- package/dist/core/tool/ToolCallReader.d.ts.map +1 -0
- package/dist/core/tool/ToolCallReader.js +339 -0
- package/dist/core/tool/ToolCallReader.js.map +1 -0
- package/dist/core/tool/ToolCallReader.mjs +315 -0
- package/dist/core/tool/ToolCallReader.mjs.map +1 -0
- package/dist/core/tool/ToolExecutionStream.d.ts +24 -0
- package/dist/core/tool/ToolExecutionStream.d.ts.map +1 -0
- package/dist/core/tool/ToolExecutionStream.js +165 -0
- package/dist/core/tool/ToolExecutionStream.js.map +1 -0
- package/dist/core/tool/ToolExecutionStream.mjs +132 -0
- package/dist/core/tool/ToolExecutionStream.mjs.map +1 -0
- package/dist/core/tool/ToolResponse.d.ts +17 -0
- package/dist/core/tool/ToolResponse.d.ts.map +1 -0
- package/dist/core/tool/ToolResponse.js +47 -0
- package/dist/core/tool/ToolResponse.js.map +1 -0
- package/dist/core/tool/ToolResponse.mjs +22 -0
- package/dist/core/tool/ToolResponse.mjs.map +1 -0
- package/dist/core/tool/index.d.ts +6 -0
- package/dist/core/tool/index.d.ts.map +1 -0
- package/dist/core/tool/index.js +39 -0
- package/dist/core/tool/index.js.map +1 -0
- package/dist/core/tool/index.mjs +14 -0
- package/dist/core/tool/index.mjs.map +1 -0
- package/dist/core/tool/tool-types.d.ts +76 -0
- package/dist/core/tool/tool-types.d.ts.map +1 -0
- package/dist/core/tool/tool-types.js +19 -0
- package/dist/core/tool/tool-types.js.map +1 -0
- package/dist/core/tool/tool-types.mjs +1 -0
- package/dist/core/tool/tool-types.mjs.map +1 -0
- package/dist/core/tool/toolResultStream.d.ts +6 -0
- package/dist/core/tool/toolResultStream.d.ts.map +1 -0
- package/dist/core/tool/toolResultStream.js +104 -0
- package/dist/core/tool/toolResultStream.js.map +1 -0
- package/dist/core/tool/toolResultStream.mjs +78 -0
- package/dist/core/tool/toolResultStream.mjs.map +1 -0
- package/dist/core/tool/type-path-utils.d.ts +23 -0
- package/dist/core/tool/type-path-utils.d.ts.map +1 -0
- package/dist/core/tool/type-path-utils.js +19 -0
- package/dist/core/tool/type-path-utils.js.map +1 -0
- package/dist/core/tool/type-path-utils.mjs +1 -0
- package/dist/core/tool/type-path-utils.mjs.map +1 -0
- package/dist/core/utils/Counter.d.ts +5 -0
- package/dist/core/utils/Counter.d.ts.map +1 -0
- package/dist/core/utils/Counter.js +36 -0
- package/dist/core/utils/Counter.js.map +1 -0
- package/dist/core/utils/Counter.mjs +11 -0
- package/dist/core/utils/Counter.mjs.map +1 -0
- package/dist/core/utils/generateId.d.ts +2 -0
- package/dist/core/utils/generateId.d.ts.map +1 -0
- package/dist/core/utils/generateId.js +35 -0
- package/dist/core/utils/generateId.js.map +1 -0
- package/dist/core/utils/generateId.mjs +10 -0
- package/dist/core/utils/generateId.mjs.map +1 -0
- package/dist/core/utils/stream/AssistantMetaTransformStream.d.ts +20 -0
- package/dist/core/utils/stream/AssistantMetaTransformStream.d.ts.map +1 -0
- package/dist/core/utils/stream/AssistantMetaTransformStream.js +69 -0
- package/dist/core/utils/stream/AssistantMetaTransformStream.js.map +1 -0
- package/dist/core/utils/stream/AssistantMetaTransformStream.mjs +44 -0
- package/dist/core/utils/stream/AssistantMetaTransformStream.mjs.map +1 -0
- package/dist/core/utils/stream/AssistantTransformStream.d.ts +15 -0
- package/dist/core/utils/stream/AssistantTransformStream.d.ts.map +1 -0
- package/dist/core/utils/stream/AssistantTransformStream.js +69 -0
- package/dist/core/utils/stream/AssistantTransformStream.js.map +1 -0
- package/dist/core/utils/stream/AssistantTransformStream.mjs +46 -0
- package/dist/core/utils/stream/AssistantTransformStream.mjs.map +1 -0
- package/dist/core/utils/stream/LineDecoderStream.d.ts +5 -0
- package/dist/core/utils/stream/LineDecoderStream.d.ts.map +1 -0
- package/dist/core/utils/stream/LineDecoderStream.js +52 -0
- package/dist/core/utils/stream/LineDecoderStream.js.map +1 -0
- package/dist/core/utils/stream/LineDecoderStream.mjs +27 -0
- package/dist/core/utils/stream/LineDecoderStream.mjs.map +1 -0
- package/dist/core/utils/stream/PipeableTransformStream.d.ts +4 -0
- package/dist/core/utils/stream/PipeableTransformStream.d.ts.map +1 -0
- package/dist/core/utils/stream/PipeableTransformStream.js +40 -0
- package/dist/core/utils/stream/PipeableTransformStream.js.map +1 -0
- package/dist/core/utils/stream/PipeableTransformStream.mjs +15 -0
- package/dist/core/utils/stream/PipeableTransformStream.mjs.map +1 -0
- package/dist/core/utils/stream/UnderlyingReadable.d.ts +6 -0
- package/dist/core/utils/stream/UnderlyingReadable.d.ts.map +1 -0
- package/dist/core/utils/stream/UnderlyingReadable.js +19 -0
- package/dist/core/utils/stream/UnderlyingReadable.js.map +1 -0
- package/dist/core/utils/stream/UnderlyingReadable.mjs +1 -0
- package/dist/core/utils/stream/UnderlyingReadable.mjs.map +1 -0
- package/dist/core/utils/stream/merge.d.ts +9 -0
- package/dist/core/utils/stream/merge.d.ts.map +1 -0
- package/dist/core/utils/stream/merge.js +110 -0
- package/dist/core/utils/stream/merge.js.map +1 -0
- package/dist/core/utils/stream/merge.mjs +85 -0
- package/dist/core/utils/stream/merge.mjs.map +1 -0
- package/dist/core/utils/stream/path-utils.d.ts +12 -0
- package/dist/core/utils/stream/path-utils.d.ts.map +1 -0
- package/dist/core/utils/stream/path-utils.js +88 -0
- package/dist/core/utils/stream/path-utils.js.map +1 -0
- package/dist/core/utils/stream/path-utils.mjs +61 -0
- package/dist/core/utils/stream/path-utils.mjs.map +1 -0
- package/dist/core/utils/types.d.ts +102 -0
- package/dist/core/utils/types.d.ts.map +1 -0
- package/dist/core/utils/types.js +19 -0
- package/dist/core/utils/types.js.map +1 -0
- package/dist/core/utils/types.mjs +1 -0
- package/dist/core/utils/types.mjs.map +1 -0
- package/dist/core/utils/withPromiseOrValue.d.ts +2 -0
- package/dist/core/utils/withPromiseOrValue.d.ts.map +1 -0
- package/dist/core/utils/withPromiseOrValue.js +42 -0
- package/dist/core/utils/withPromiseOrValue.js.map +1 -0
- package/dist/core/utils/withPromiseOrValue.mjs +17 -0
- package/dist/core/utils/withPromiseOrValue.mjs.map +1 -0
- package/dist/index.d.ts +2 -153
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -2318
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -957
- package/dist/index.mjs.map +1 -1
- package/dist/utils/AsyncIterableStream.d.ts +3 -0
- package/dist/utils/AsyncIterableStream.d.ts.map +1 -0
- package/dist/utils/AsyncIterableStream.js +46 -0
- package/dist/utils/AsyncIterableStream.js.map +1 -0
- package/dist/utils/AsyncIterableStream.mjs +21 -0
- package/dist/utils/AsyncIterableStream.mjs.map +1 -0
- package/dist/utils/json/fix-json.d.ts +2 -0
- package/dist/utils/json/fix-json.d.ts.map +1 -0
- package/dist/{chunk-PQLDKUPN.mjs → utils/json/fix-json.js} +28 -66
- package/dist/utils/json/fix-json.js.map +1 -0
- package/dist/utils/json/fix-json.mjs +362 -0
- package/dist/utils/json/fix-json.mjs.map +1 -0
- package/dist/utils/json/is-json.d.ts +5 -0
- package/dist/utils/json/is-json.d.ts.map +1 -0
- package/dist/utils/json/is-json.js +56 -0
- package/dist/utils/json/is-json.js.map +1 -0
- package/dist/utils/json/is-json.mjs +29 -0
- package/dist/utils/json/is-json.mjs.map +1 -0
- package/dist/utils/json/json-value.d.ts +6 -0
- package/dist/utils/json/json-value.d.ts.map +1 -0
- package/dist/utils/json/json-value.js +19 -0
- package/dist/utils/json/json-value.js.map +1 -0
- package/dist/utils/json/json-value.mjs +1 -0
- package/dist/utils/json/json-value.mjs.map +1 -0
- package/dist/utils/json/parse-partial-json-object.d.ts +14 -0
- package/dist/utils/json/parse-partial-json-object.d.ts.map +1 -0
- package/dist/utils/json/parse-partial-json-object.js +102 -0
- package/dist/utils/json/parse-partial-json-object.js.map +1 -0
- package/dist/utils/json/parse-partial-json-object.mjs +65 -0
- package/dist/utils/json/parse-partial-json-object.mjs.map +1 -0
- package/dist/utils/json/parse-partial-json-object.test.d.ts +2 -0
- package/dist/utils/json/parse-partial-json-object.test.d.ts.map +1 -0
- package/dist/utils/promiseWithResolvers.d.ts +6 -0
- package/dist/utils/promiseWithResolvers.d.ts.map +1 -0
- package/dist/utils/promiseWithResolvers.js +40 -0
- package/dist/utils/promiseWithResolvers.js.map +1 -0
- package/dist/utils/promiseWithResolvers.mjs +15 -0
- package/dist/utils/promiseWithResolvers.mjs.map +1 -0
- package/dist/utils.d.ts +4 -16
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +5 -451
- package/dist/utils.js.map +1 -1
- package/dist/utils.mjs +7 -21
- package/dist/utils.mjs.map +1 -1
- package/package.json +2 -1
- package/dist/AsyncIterableStream-C3C8ZoXv.d.mts +0 -4
- package/dist/AsyncIterableStream-C3C8ZoXv.d.ts +0 -4
- package/dist/ai-sdk.d.mts +0 -24
- package/dist/assistant-stream-ISFjQ0mQ.d.mts +0 -225
- package/dist/assistant-stream-kAoIMgvk.d.ts +0 -225
- package/dist/chunk-EDE6WQ2R.mjs +0 -943
- package/dist/chunk-EDE6WQ2R.mjs.map +0 -1
- package/dist/chunk-PQLDKUPN.mjs.map +0 -1
- package/dist/index.d.mts +0 -153
- package/dist/json-value-Ch5eKkQ_.d.mts +0 -7
- package/dist/json-value-Ch5eKkQ_.d.ts +0 -7
- package/dist/utils.d.mts +0 -16
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { JSONSchema7 } from "json-schema";
|
|
2
|
+
import { TypeAtPath, TypePath } from "./type-path-utils";
|
|
3
|
+
import { DeepPartial } from "ai";
|
|
4
|
+
import { AsyncIterableStream } from "../../utils";
|
|
5
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
6
|
+
import { ToolResponse } from "./ToolResponse";
|
|
7
|
+
/**
|
|
8
|
+
* Interface for reading tool call arguments from a stream, which are
|
|
9
|
+
* generated by a language learning model (LLM). Provides methods to
|
|
10
|
+
* retrieve specific values, partial streams, or complete items from
|
|
11
|
+
* an array, based on a specified path.
|
|
12
|
+
*
|
|
13
|
+
* @template TArgs The type of arguments being read.
|
|
14
|
+
*/
|
|
15
|
+
export interface ToolCallArgsReader<TArgs> {
|
|
16
|
+
/**
|
|
17
|
+
* Returns a promise that will resolve to the value at the given path,
|
|
18
|
+
* as soon as that path is generated by the LLM.
|
|
19
|
+
*
|
|
20
|
+
* @param fieldPath An array of object keys or array indices.
|
|
21
|
+
*/
|
|
22
|
+
get<PathT extends TypePath<TArgs>>(...fieldPath: PathT): Promise<TypeAtPath<TArgs, PathT>>;
|
|
23
|
+
/**
|
|
24
|
+
* Returns a stream that will emit partial values at the given path,
|
|
25
|
+
* as they are generated by the LLM.
|
|
26
|
+
*
|
|
27
|
+
* @param fieldPath An array of object keys or array indices.
|
|
28
|
+
*/
|
|
29
|
+
streamValues<PathT extends TypePath<TArgs>>(...fieldPath: PathT): AsyncIterableStream<DeepPartial<TypeAtPath<TArgs, PathT>>>;
|
|
30
|
+
/**
|
|
31
|
+
* Returns a stream that will emit partial text at the given path,
|
|
32
|
+
* as they are generated by the LLM.
|
|
33
|
+
*
|
|
34
|
+
* @param fieldPath An array of object keys or array indices.
|
|
35
|
+
*/
|
|
36
|
+
streamText<PathT extends TypePath<TArgs>>(...fieldPath: PathT): TypeAtPath<TArgs, PathT> extends string & infer U ? AsyncIterableStream<U> : never;
|
|
37
|
+
/**
|
|
38
|
+
* Returns a stream that will emit complete items in the array
|
|
39
|
+
* at the given path, as they are generated by the LLM.
|
|
40
|
+
*
|
|
41
|
+
* @param fieldPath An array of object keys or array indices.
|
|
42
|
+
*/
|
|
43
|
+
forEach<PathT extends TypePath<TArgs>>(...fieldPath: PathT): TypeAtPath<TArgs, PathT> extends Array<infer U> ? AsyncIterableStream<U> : never;
|
|
44
|
+
}
|
|
45
|
+
export interface ToolCallResponseReader<TResult> {
|
|
46
|
+
get: () => Promise<ToolResponse<TResult>>;
|
|
47
|
+
}
|
|
48
|
+
export interface ToolCallReader<TArgs, TResult> {
|
|
49
|
+
args: ToolCallArgsReader<TArgs>;
|
|
50
|
+
response: ToolCallResponseReader<TResult>;
|
|
51
|
+
/**
|
|
52
|
+
* @deprecated Deprecated. Use `response.get().result` instead.
|
|
53
|
+
*/
|
|
54
|
+
result: {
|
|
55
|
+
get: () => Promise<TResult>;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
type ToolExecutionContext = {
|
|
59
|
+
toolCallId: string;
|
|
60
|
+
abortSignal: AbortSignal;
|
|
61
|
+
};
|
|
62
|
+
export type ToolExecuteFunction<TArgs, TResult> = (args: TArgs, context: ToolExecutionContext) => TResult | Promise<TResult>;
|
|
63
|
+
export type ToolStreamCallFunction<TArgs, TResult> = (reader: ToolCallReader<TArgs, TResult>, context: ToolExecutionContext) => void;
|
|
64
|
+
type OnSchemaValidationErrorFunction<TResult> = ToolExecuteFunction<unknown, TResult>;
|
|
65
|
+
export type Tool<TArgs = unknown, TResult = unknown> = {
|
|
66
|
+
description?: string | undefined;
|
|
67
|
+
parameters: StandardSchemaV1<TArgs> | JSONSchema7;
|
|
68
|
+
execute?: ToolExecuteFunction<TArgs, TResult>;
|
|
69
|
+
/**
|
|
70
|
+
* @deprecated Experimental, API may change.
|
|
71
|
+
*/
|
|
72
|
+
streamCall?: ToolStreamCallFunction<TArgs, TResult>;
|
|
73
|
+
experimental_onSchemaValidationError?: OnSchemaValidationErrorFunction<TResult>;
|
|
74
|
+
};
|
|
75
|
+
export {};
|
|
76
|
+
//# sourceMappingURL=tool-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-types.d.ts","sourceRoot":"","sources":["../../../src/core/tool/tool-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAkB,CAAC,KAAK;IACvC;;;;;OAKG;IACH,GAAG,CAAC,KAAK,SAAS,QAAQ,CAAC,KAAK,CAAC,EAC/B,GAAG,SAAS,EAAE,KAAK,GAClB,OAAO,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IAErC;;;;;OAKG;IACH,YAAY,CAAC,KAAK,SAAS,QAAQ,CAAC,KAAK,CAAC,EACxC,GAAG,SAAS,EAAE,KAAK,GAClB,mBAAmB,CAAC,WAAW,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IAE9D;;;;;OAKG;IACH,UAAU,CAAC,KAAK,SAAS,QAAQ,CAAC,KAAK,CAAC,EACtC,GAAG,SAAS,EAAE,KAAK,GAClB,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,GAChD,mBAAmB,CAAC,CAAC,CAAC,GACtB,KAAK,CAAC;IAEV;;;;;OAKG;IACH,OAAO,CAAC,KAAK,SAAS,QAAQ,CAAC,KAAK,CAAC,EACnC,GAAG,SAAS,EAAE,KAAK,GAClB,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,CAAC,GAC9C,mBAAmB,CAAC,CAAC,CAAC,GACtB,KAAK,CAAC;CACX;AAED,MAAM,WAAW,sBAAsB,CAAC,OAAO;IAC7C,GAAG,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,cAAc,CAAC,KAAK,EAAE,OAAO;IAC5C,IAAI,EAAE,kBAAkB,CAAC,KAAK,CAAC,CAAC;IAChC,QAAQ,EAAE,sBAAsB,CAAC,OAAO,CAAC,CAAC;IAE1C;;OAEG;IACH,MAAM,EAAE;QACN,GAAG,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;KAC7B,CAAC;CACH;AAED,KAAK,oBAAoB,GAAG;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,WAAW,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,mBAAmB,CAAC,KAAK,EAAE,OAAO,IAAI,CAChD,IAAI,EAAE,KAAK,EACX,OAAO,EAAE,oBAAoB,KAC1B,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAEhC,MAAM,MAAM,sBAAsB,CAAC,KAAK,EAAE,OAAO,IAAI,CACnD,MAAM,EAAE,cAAc,CAAC,KAAK,EAAE,OAAO,CAAC,EACtC,OAAO,EAAE,oBAAoB,KAC1B,IAAI,CAAC;AAEV,KAAK,+BAA+B,CAAC,OAAO,IAAI,mBAAmB,CACjE,OAAO,EACP,OAAO,CACR,CAAC;AAEF,MAAM,MAAM,IAAI,CAAC,KAAK,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI;IACrD,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,UAAU,EAAE,gBAAgB,CAAC,KAAK,CAAC,GAAG,WAAW,CAAC;IAClD,OAAO,CAAC,EAAE,mBAAmB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC9C;;OAEG;IACH,UAAU,CAAC,EAAE,sBAAsB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACpD,oCAAoC,CAAC,EAAE,+BAA+B,CAAC,OAAO,CAAC,CAAC;CACjF,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/core/tool/tool-types.ts
|
|
17
|
+
var tool_types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(tool_types_exports);
|
|
19
|
+
//# sourceMappingURL=tool-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/tool/tool-types.ts"],"sourcesContent":["import { JSONSchema7 } from \"json-schema\";\nimport { TypeAtPath, TypePath } from \"./type-path-utils\";\nimport { DeepPartial } from \"ai\";\nimport { AsyncIterableStream } from \"../../utils\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport { ToolResponse } from \"./ToolResponse\";\n\n/**\n * Interface for reading tool call arguments from a stream, which are\n * generated by a language learning model (LLM). Provides methods to\n * retrieve specific values, partial streams, or complete items from\n * an array, based on a specified path.\n *\n * @template TArgs The type of arguments being read.\n */\nexport interface ToolCallArgsReader<TArgs> {\n /**\n * Returns a promise that will resolve to the value at the given path,\n * as soon as that path is generated by the LLM.\n *\n * @param fieldPath An array of object keys or array indices.\n */\n get<PathT extends TypePath<TArgs>>(\n ...fieldPath: PathT\n ): Promise<TypeAtPath<TArgs, PathT>>;\n\n /**\n * Returns a stream that will emit partial values at the given path,\n * as they are generated by the LLM.\n *\n * @param fieldPath An array of object keys or array indices.\n */\n streamValues<PathT extends TypePath<TArgs>>(\n ...fieldPath: PathT\n ): AsyncIterableStream<DeepPartial<TypeAtPath<TArgs, PathT>>>;\n\n /**\n * Returns a stream that will emit partial text at the given path,\n * as they are generated by the LLM.\n *\n * @param fieldPath An array of object keys or array indices.\n */\n streamText<PathT extends TypePath<TArgs>>(\n ...fieldPath: PathT\n ): TypeAtPath<TArgs, PathT> extends string & infer U\n ? AsyncIterableStream<U>\n : never;\n\n /**\n * Returns a stream that will emit complete items in the array\n * at the given path, as they are generated by the LLM.\n *\n * @param fieldPath An array of object keys or array indices.\n */\n forEach<PathT extends TypePath<TArgs>>(\n ...fieldPath: PathT\n ): TypeAtPath<TArgs, PathT> extends Array<infer U>\n ? AsyncIterableStream<U>\n : never;\n}\n\nexport interface ToolCallResponseReader<TResult> {\n get: () => Promise<ToolResponse<TResult>>;\n}\n\nexport interface ToolCallReader<TArgs, TResult> {\n args: ToolCallArgsReader<TArgs>;\n response: ToolCallResponseReader<TResult>;\n\n /**\n * @deprecated Deprecated. Use `response.get().result` instead.\n */\n result: {\n get: () => Promise<TResult>;\n };\n}\n\ntype ToolExecutionContext = {\n toolCallId: string;\n abortSignal: AbortSignal;\n};\n\nexport type ToolExecuteFunction<TArgs, TResult> = (\n args: TArgs,\n context: ToolExecutionContext,\n) => TResult | Promise<TResult>;\n\nexport type ToolStreamCallFunction<TArgs, TResult> = (\n reader: ToolCallReader<TArgs, TResult>,\n context: ToolExecutionContext,\n) => void;\n\ntype OnSchemaValidationErrorFunction<TResult> = ToolExecuteFunction<\n unknown,\n TResult\n>;\n\nexport type Tool<TArgs = unknown, TResult = unknown> = {\n description?: string | undefined;\n parameters: StandardSchemaV1<TArgs> | JSONSchema7;\n execute?: ToolExecuteFunction<TArgs, TResult>;\n /**\n * @deprecated Experimental, API may change.\n */\n streamCall?: ToolStreamCallFunction<TArgs, TResult>;\n experimental_onSchemaValidationError?: OnSchemaValidationErrorFunction<TResult>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=tool-types.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Tool } from "./tool-types";
|
|
2
|
+
import { ToolExecutionStream } from "./ToolExecutionStream";
|
|
3
|
+
import { AssistantMessage } from "../utils/types";
|
|
4
|
+
export declare function unstable_runPendingTools(message: AssistantMessage, tools: Record<string, Tool<any, any>> | undefined, abortSignal: AbortSignal): Promise<AssistantMessage>;
|
|
5
|
+
export declare function toolResultStream(tools: Record<string, Tool<any, any>> | undefined, abortSignal: AbortSignal): ToolExecutionStream;
|
|
6
|
+
//# sourceMappingURL=toolResultStream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolResultStream.d.ts","sourceRoot":"","sources":["../../../src/core/tool/toolResultStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAuC,MAAM,cAAc,CAAC;AAGzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAuElD,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,gBAAgB,EACzB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,GAAG,SAAS,EACjD,WAAW,EAAE,WAAW,6BA6BzB;AAED,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,GAAG,SAAS,EACjD,WAAW,EAAE,WAAW,uBAOzB"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/core/tool/toolResultStream.ts
|
|
21
|
+
var toolResultStream_exports = {};
|
|
22
|
+
__export(toolResultStream_exports, {
|
|
23
|
+
toolResultStream: () => toolResultStream,
|
|
24
|
+
unstable_runPendingTools: () => unstable_runPendingTools
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(toolResultStream_exports);
|
|
27
|
+
var import_ToolResponse = require("./ToolResponse.js");
|
|
28
|
+
var import_ToolExecutionStream = require("./ToolExecutionStream.js");
|
|
29
|
+
var isStandardSchemaV1 = (schema) => {
|
|
30
|
+
return typeof schema === "object" && schema !== null && "~standard" in schema && schema["~standard"].version === 1;
|
|
31
|
+
};
|
|
32
|
+
function getToolResponse(tools, abortSignal, toolCall) {
|
|
33
|
+
const tool = tools?.[toolCall.toolName];
|
|
34
|
+
if (!tool || !tool.execute) return void 0;
|
|
35
|
+
const getResult = async (toolExecute) => {
|
|
36
|
+
let executeFn = toolExecute;
|
|
37
|
+
if (isStandardSchemaV1(tool.parameters)) {
|
|
38
|
+
let result2 = tool.parameters["~standard"].validate(toolCall.args);
|
|
39
|
+
if (result2 instanceof Promise) result2 = await result2;
|
|
40
|
+
if (result2.issues) {
|
|
41
|
+
executeFn = tool.experimental_onSchemaValidationError ?? (() => {
|
|
42
|
+
throw new Error(
|
|
43
|
+
`Function parameter validation failed. ${JSON.stringify(result2.issues)}`
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const result = await executeFn(toolCall.args, {
|
|
49
|
+
toolCallId: toolCall.toolCallId,
|
|
50
|
+
abortSignal
|
|
51
|
+
});
|
|
52
|
+
if (result instanceof import_ToolResponse.ToolResponse) return result;
|
|
53
|
+
return new import_ToolResponse.ToolResponse({
|
|
54
|
+
result: result === void 0 ? "<no result>" : result
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
return getResult(tool.execute);
|
|
58
|
+
}
|
|
59
|
+
function getToolStreamResponse(tools, abortSignal, reader, context) {
|
|
60
|
+
tools?.[context.toolName]?.streamCall?.(reader, {
|
|
61
|
+
toolCallId: context.toolCallId,
|
|
62
|
+
abortSignal
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
async function unstable_runPendingTools(message, tools, abortSignal) {
|
|
66
|
+
for (const part of message.parts) {
|
|
67
|
+
if (part.type === "tool-call") {
|
|
68
|
+
const promiseOrUndefined = getToolResponse(tools, abortSignal, part);
|
|
69
|
+
if (promiseOrUndefined) {
|
|
70
|
+
const result = await promiseOrUndefined;
|
|
71
|
+
const updatedParts = message.parts.map((p) => {
|
|
72
|
+
if (p.type === "tool-call" && p.toolCallId === part.toolCallId) {
|
|
73
|
+
return {
|
|
74
|
+
...p,
|
|
75
|
+
state: "result",
|
|
76
|
+
artifact: result.artifact,
|
|
77
|
+
result: result.result,
|
|
78
|
+
isError: result.isError
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return p;
|
|
82
|
+
});
|
|
83
|
+
message = {
|
|
84
|
+
...message,
|
|
85
|
+
parts: updatedParts,
|
|
86
|
+
content: updatedParts
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return message;
|
|
92
|
+
}
|
|
93
|
+
function toolResultStream(tools, abortSignal) {
|
|
94
|
+
return new import_ToolExecutionStream.ToolExecutionStream({
|
|
95
|
+
execute: (toolCall) => getToolResponse(tools, abortSignal, toolCall),
|
|
96
|
+
streamCall: ({ reader, ...context }) => getToolStreamResponse(tools, abortSignal, reader, context)
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
100
|
+
0 && (module.exports = {
|
|
101
|
+
toolResultStream,
|
|
102
|
+
unstable_runPendingTools
|
|
103
|
+
});
|
|
104
|
+
//# sourceMappingURL=toolResultStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/tool/toolResultStream.ts"],"sourcesContent":["import { Tool, ToolCallReader, ToolExecuteFunction } from \"./tool-types\";\nimport { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport { ToolResponse } from \"./ToolResponse\";\nimport { ToolExecutionStream } from \"./ToolExecutionStream\";\nimport { AssistantMessage } from \"../utils/types\";\n\nconst isStandardSchemaV1 = (\n schema: unknown,\n): schema is StandardSchemaV1<unknown> => {\n return (\n typeof schema === \"object\" &&\n schema !== null &&\n \"~standard\" in schema &&\n (schema as StandardSchemaV1<unknown>)[\"~standard\"].version === 1\n );\n};\n\nfunction getToolResponse(\n tools: Record<string, Tool<any, any>> | undefined,\n abortSignal: AbortSignal,\n toolCall: {\n toolCallId: string;\n toolName: string;\n args: unknown;\n },\n) {\n const tool = tools?.[toolCall.toolName];\n if (!tool || !tool.execute) return undefined;\n\n const getResult = async (toolExecute: ToolExecuteFunction<any, any>) => {\n let executeFn = toolExecute;\n\n if (isStandardSchemaV1(tool.parameters)) {\n let result = tool.parameters[\"~standard\"].validate(toolCall.args);\n if (result instanceof Promise) result = await result;\n\n if (result.issues) {\n executeFn =\n tool.experimental_onSchemaValidationError ??\n (() => {\n throw new Error(\n `Function parameter validation failed. ${JSON.stringify(result.issues)}`,\n );\n });\n }\n }\n\n const result = await executeFn(toolCall.args, {\n toolCallId: toolCall.toolCallId,\n abortSignal,\n });\n if (result instanceof ToolResponse) return result;\n return new ToolResponse({\n result: result === undefined ? \"<no result>\" : result,\n });\n };\n\n return getResult(tool.execute);\n}\n\nfunction getToolStreamResponse<TArgs, TResult>(\n tools: Record<string, Tool<any, any>> | undefined,\n abortSignal: AbortSignal,\n reader: ToolCallReader<TArgs, TResult>,\n context: {\n toolCallId: string;\n toolName: string;\n },\n) {\n tools?.[context.toolName]?.streamCall?.(reader, {\n toolCallId: context.toolCallId,\n abortSignal,\n });\n}\n\nexport async function unstable_runPendingTools(\n message: AssistantMessage,\n tools: Record<string, Tool<any, any>> | undefined,\n abortSignal: AbortSignal,\n) {\n // TODO parallel tool calling\n for (const part of message.parts) {\n if (part.type === \"tool-call\") {\n const promiseOrUndefined = getToolResponse(tools, abortSignal, part);\n if (promiseOrUndefined) {\n const result = await promiseOrUndefined;\n const updatedParts = message.parts.map((p) => {\n if (p.type === \"tool-call\" && p.toolCallId === part.toolCallId) {\n return {\n ...p,\n state: \"result\" as const,\n artifact: result.artifact,\n result: result.result,\n isError: result.isError,\n };\n }\n return p;\n });\n message = {\n ...message,\n parts: updatedParts,\n content: updatedParts,\n };\n }\n }\n }\n return message;\n}\n\nexport function toolResultStream(\n tools: Record<string, Tool<any, any>> | undefined,\n abortSignal: AbortSignal,\n) {\n return new ToolExecutionStream({\n execute: (toolCall) => getToolResponse(tools, abortSignal, toolCall),\n streamCall: ({ reader, ...context }) =>\n getToolStreamResponse(tools, abortSignal, reader, context),\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,0BAA6B;AAC7B,iCAAoC;AAGpC,IAAM,qBAAqB,CACzB,WACwC;AACxC,SACE,OAAO,WAAW,YAClB,WAAW,QACX,eAAe,UACd,OAAqC,WAAW,EAAE,YAAY;AAEnE;AAEA,SAAS,gBACP,OACA,aACA,UAKA;AACA,QAAM,OAAO,QAAQ,SAAS,QAAQ;AACtC,MAAI,CAAC,QAAQ,CAAC,KAAK,QAAS,QAAO;AAEnC,QAAM,YAAY,OAAO,gBAA+C;AACtE,QAAI,YAAY;AAEhB,QAAI,mBAAmB,KAAK,UAAU,GAAG;AACvC,UAAIA,UAAS,KAAK,WAAW,WAAW,EAAE,SAAS,SAAS,IAAI;AAChE,UAAIA,mBAAkB,QAAS,CAAAA,UAAS,MAAMA;AAE9C,UAAIA,QAAO,QAAQ;AACjB,oBACE,KAAK,yCACJ,MAAM;AACL,gBAAM,IAAI;AAAA,YACR,yCAAyC,KAAK,UAAUA,QAAO,MAAM,CAAC;AAAA,UACxE;AAAA,QACF;AAAA,MACJ;AAAA,IACF;AAEA,UAAM,SAAS,MAAM,UAAU,SAAS,MAAM;AAAA,MAC5C,YAAY,SAAS;AAAA,MACrB;AAAA,IACF,CAAC;AACD,QAAI,kBAAkB,iCAAc,QAAO;AAC3C,WAAO,IAAI,iCAAa;AAAA,MACtB,QAAQ,WAAW,SAAY,gBAAgB;AAAA,IACjD,CAAC;AAAA,EACH;AAEA,SAAO,UAAU,KAAK,OAAO;AAC/B;AAEA,SAAS,sBACP,OACA,aACA,QACA,SAIA;AACA,UAAQ,QAAQ,QAAQ,GAAG,aAAa,QAAQ;AAAA,IAC9C,YAAY,QAAQ;AAAA,IACpB;AAAA,EACF,CAAC;AACH;AAEA,eAAsB,yBACpB,SACA,OACA,aACA;AAEA,aAAW,QAAQ,QAAQ,OAAO;AAChC,QAAI,KAAK,SAAS,aAAa;AAC7B,YAAM,qBAAqB,gBAAgB,OAAO,aAAa,IAAI;AACnE,UAAI,oBAAoB;AACtB,cAAM,SAAS,MAAM;AACrB,cAAM,eAAe,QAAQ,MAAM,IAAI,CAAC,MAAM;AAC5C,cAAI,EAAE,SAAS,eAAe,EAAE,eAAe,KAAK,YAAY;AAC9D,mBAAO;AAAA,cACL,GAAG;AAAA,cACH,OAAO;AAAA,cACP,UAAU,OAAO;AAAA,cACjB,QAAQ,OAAO;AAAA,cACf,SAAS,OAAO;AAAA,YAClB;AAAA,UACF;AACA,iBAAO;AAAA,QACT,CAAC;AACD,kBAAU;AAAA,UACR,GAAG;AAAA,UACH,OAAO;AAAA,UACP,SAAS;AAAA,QACX;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEO,SAAS,iBACd,OACA,aACA;AACA,SAAO,IAAI,+CAAoB;AAAA,IAC7B,SAAS,CAAC,aAAa,gBAAgB,OAAO,aAAa,QAAQ;AAAA,IACnE,YAAY,CAAC,EAAE,QAAQ,GAAG,QAAQ,MAChC,sBAAsB,OAAO,aAAa,QAAQ,OAAO;AAAA,EAC7D,CAAC;AACH;","names":["result"]}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// src/core/tool/toolResultStream.ts
|
|
2
|
+
import { ToolResponse } from "./ToolResponse.mjs";
|
|
3
|
+
import { ToolExecutionStream } from "./ToolExecutionStream.mjs";
|
|
4
|
+
var isStandardSchemaV1 = (schema) => {
|
|
5
|
+
return typeof schema === "object" && schema !== null && "~standard" in schema && schema["~standard"].version === 1;
|
|
6
|
+
};
|
|
7
|
+
function getToolResponse(tools, abortSignal, toolCall) {
|
|
8
|
+
const tool = tools?.[toolCall.toolName];
|
|
9
|
+
if (!tool || !tool.execute) return void 0;
|
|
10
|
+
const getResult = async (toolExecute) => {
|
|
11
|
+
let executeFn = toolExecute;
|
|
12
|
+
if (isStandardSchemaV1(tool.parameters)) {
|
|
13
|
+
let result2 = tool.parameters["~standard"].validate(toolCall.args);
|
|
14
|
+
if (result2 instanceof Promise) result2 = await result2;
|
|
15
|
+
if (result2.issues) {
|
|
16
|
+
executeFn = tool.experimental_onSchemaValidationError ?? (() => {
|
|
17
|
+
throw new Error(
|
|
18
|
+
`Function parameter validation failed. ${JSON.stringify(result2.issues)}`
|
|
19
|
+
);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const result = await executeFn(toolCall.args, {
|
|
24
|
+
toolCallId: toolCall.toolCallId,
|
|
25
|
+
abortSignal
|
|
26
|
+
});
|
|
27
|
+
if (result instanceof ToolResponse) return result;
|
|
28
|
+
return new ToolResponse({
|
|
29
|
+
result: result === void 0 ? "<no result>" : result
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
return getResult(tool.execute);
|
|
33
|
+
}
|
|
34
|
+
function getToolStreamResponse(tools, abortSignal, reader, context) {
|
|
35
|
+
tools?.[context.toolName]?.streamCall?.(reader, {
|
|
36
|
+
toolCallId: context.toolCallId,
|
|
37
|
+
abortSignal
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
async function unstable_runPendingTools(message, tools, abortSignal) {
|
|
41
|
+
for (const part of message.parts) {
|
|
42
|
+
if (part.type === "tool-call") {
|
|
43
|
+
const promiseOrUndefined = getToolResponse(tools, abortSignal, part);
|
|
44
|
+
if (promiseOrUndefined) {
|
|
45
|
+
const result = await promiseOrUndefined;
|
|
46
|
+
const updatedParts = message.parts.map((p) => {
|
|
47
|
+
if (p.type === "tool-call" && p.toolCallId === part.toolCallId) {
|
|
48
|
+
return {
|
|
49
|
+
...p,
|
|
50
|
+
state: "result",
|
|
51
|
+
artifact: result.artifact,
|
|
52
|
+
result: result.result,
|
|
53
|
+
isError: result.isError
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return p;
|
|
57
|
+
});
|
|
58
|
+
message = {
|
|
59
|
+
...message,
|
|
60
|
+
parts: updatedParts,
|
|
61
|
+
content: updatedParts
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return message;
|
|
67
|
+
}
|
|
68
|
+
function toolResultStream(tools, abortSignal) {
|
|
69
|
+
return new ToolExecutionStream({
|
|
70
|
+
execute: (toolCall) => getToolResponse(tools, abortSignal, toolCall),
|
|
71
|
+
streamCall: ({ reader, ...context }) => getToolStreamResponse(tools, abortSignal, reader, context)
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
export {
|
|
75
|
+
toolResultStream,
|
|
76
|
+
unstable_runPendingTools
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=toolResultStream.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/tool/toolResultStream.ts"],"sourcesContent":["import { Tool, ToolCallReader, ToolExecuteFunction } from \"./tool-types\";\nimport { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport { ToolResponse } from \"./ToolResponse\";\nimport { ToolExecutionStream } from \"./ToolExecutionStream\";\nimport { AssistantMessage } from \"../utils/types\";\n\nconst isStandardSchemaV1 = (\n schema: unknown,\n): schema is StandardSchemaV1<unknown> => {\n return (\n typeof schema === \"object\" &&\n schema !== null &&\n \"~standard\" in schema &&\n (schema as StandardSchemaV1<unknown>)[\"~standard\"].version === 1\n );\n};\n\nfunction getToolResponse(\n tools: Record<string, Tool<any, any>> | undefined,\n abortSignal: AbortSignal,\n toolCall: {\n toolCallId: string;\n toolName: string;\n args: unknown;\n },\n) {\n const tool = tools?.[toolCall.toolName];\n if (!tool || !tool.execute) return undefined;\n\n const getResult = async (toolExecute: ToolExecuteFunction<any, any>) => {\n let executeFn = toolExecute;\n\n if (isStandardSchemaV1(tool.parameters)) {\n let result = tool.parameters[\"~standard\"].validate(toolCall.args);\n if (result instanceof Promise) result = await result;\n\n if (result.issues) {\n executeFn =\n tool.experimental_onSchemaValidationError ??\n (() => {\n throw new Error(\n `Function parameter validation failed. ${JSON.stringify(result.issues)}`,\n );\n });\n }\n }\n\n const result = await executeFn(toolCall.args, {\n toolCallId: toolCall.toolCallId,\n abortSignal,\n });\n if (result instanceof ToolResponse) return result;\n return new ToolResponse({\n result: result === undefined ? \"<no result>\" : result,\n });\n };\n\n return getResult(tool.execute);\n}\n\nfunction getToolStreamResponse<TArgs, TResult>(\n tools: Record<string, Tool<any, any>> | undefined,\n abortSignal: AbortSignal,\n reader: ToolCallReader<TArgs, TResult>,\n context: {\n toolCallId: string;\n toolName: string;\n },\n) {\n tools?.[context.toolName]?.streamCall?.(reader, {\n toolCallId: context.toolCallId,\n abortSignal,\n });\n}\n\nexport async function unstable_runPendingTools(\n message: AssistantMessage,\n tools: Record<string, Tool<any, any>> | undefined,\n abortSignal: AbortSignal,\n) {\n // TODO parallel tool calling\n for (const part of message.parts) {\n if (part.type === \"tool-call\") {\n const promiseOrUndefined = getToolResponse(tools, abortSignal, part);\n if (promiseOrUndefined) {\n const result = await promiseOrUndefined;\n const updatedParts = message.parts.map((p) => {\n if (p.type === \"tool-call\" && p.toolCallId === part.toolCallId) {\n return {\n ...p,\n state: \"result\" as const,\n artifact: result.artifact,\n result: result.result,\n isError: result.isError,\n };\n }\n return p;\n });\n message = {\n ...message,\n parts: updatedParts,\n content: updatedParts,\n };\n }\n }\n }\n return message;\n}\n\nexport function toolResultStream(\n tools: Record<string, Tool<any, any>> | undefined,\n abortSignal: AbortSignal,\n) {\n return new ToolExecutionStream({\n execute: (toolCall) => getToolResponse(tools, abortSignal, toolCall),\n streamCall: ({ reader, ...context }) =>\n getToolStreamResponse(tools, abortSignal, reader, context),\n });\n}\n"],"mappings":";AAEA,SAAS,oBAAoB;AAC7B,SAAS,2BAA2B;AAGpC,IAAM,qBAAqB,CACzB,WACwC;AACxC,SACE,OAAO,WAAW,YAClB,WAAW,QACX,eAAe,UACd,OAAqC,WAAW,EAAE,YAAY;AAEnE;AAEA,SAAS,gBACP,OACA,aACA,UAKA;AACA,QAAM,OAAO,QAAQ,SAAS,QAAQ;AACtC,MAAI,CAAC,QAAQ,CAAC,KAAK,QAAS,QAAO;AAEnC,QAAM,YAAY,OAAO,gBAA+C;AACtE,QAAI,YAAY;AAEhB,QAAI,mBAAmB,KAAK,UAAU,GAAG;AACvC,UAAIA,UAAS,KAAK,WAAW,WAAW,EAAE,SAAS,SAAS,IAAI;AAChE,UAAIA,mBAAkB,QAAS,CAAAA,UAAS,MAAMA;AAE9C,UAAIA,QAAO,QAAQ;AACjB,oBACE,KAAK,yCACJ,MAAM;AACL,gBAAM,IAAI;AAAA,YACR,yCAAyC,KAAK,UAAUA,QAAO,MAAM,CAAC;AAAA,UACxE;AAAA,QACF;AAAA,MACJ;AAAA,IACF;AAEA,UAAM,SAAS,MAAM,UAAU,SAAS,MAAM;AAAA,MAC5C,YAAY,SAAS;AAAA,MACrB;AAAA,IACF,CAAC;AACD,QAAI,kBAAkB,aAAc,QAAO;AAC3C,WAAO,IAAI,aAAa;AAAA,MACtB,QAAQ,WAAW,SAAY,gBAAgB;AAAA,IACjD,CAAC;AAAA,EACH;AAEA,SAAO,UAAU,KAAK,OAAO;AAC/B;AAEA,SAAS,sBACP,OACA,aACA,QACA,SAIA;AACA,UAAQ,QAAQ,QAAQ,GAAG,aAAa,QAAQ;AAAA,IAC9C,YAAY,QAAQ;AAAA,IACpB;AAAA,EACF,CAAC;AACH;AAEA,eAAsB,yBACpB,SACA,OACA,aACA;AAEA,aAAW,QAAQ,QAAQ,OAAO;AAChC,QAAI,KAAK,SAAS,aAAa;AAC7B,YAAM,qBAAqB,gBAAgB,OAAO,aAAa,IAAI;AACnE,UAAI,oBAAoB;AACtB,cAAM,SAAS,MAAM;AACrB,cAAM,eAAe,QAAQ,MAAM,IAAI,CAAC,MAAM;AAC5C,cAAI,EAAE,SAAS,eAAe,EAAE,eAAe,KAAK,YAAY;AAC9D,mBAAO;AAAA,cACL,GAAG;AAAA,cACH,OAAO;AAAA,cACP,UAAU,OAAO;AAAA,cACjB,QAAQ,OAAO;AAAA,cACf,SAAS,OAAO;AAAA,YAClB;AAAA,UACF;AACA,iBAAO;AAAA,QACT,CAAC;AACD,kBAAU;AAAA,UACR,GAAG;AAAA,UACH,OAAO;AAAA,UACP,SAAS;AAAA,QACX;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEO,SAAS,iBACd,OACA,aACA;AACA,SAAO,IAAI,oBAAoB;AAAA,IAC7B,SAAS,CAAC,aAAa,gBAAgB,OAAO,aAAa,QAAQ;AAAA,IACnE,YAAY,CAAC,EAAE,QAAQ,GAAG,QAAQ,MAChC,sBAAsB,OAAO,aAAa,QAAQ,OAAO;AAAA,EAC7D,CAAC;AACH;","names":["result"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type AsNumber<K> = K extends `${infer N extends number}` ? N | K : never;
|
|
2
|
+
type TupleIndex<T extends readonly any[]> = Exclude<keyof T, keyof any[]>;
|
|
3
|
+
type ObjectKey<T> = keyof T & (string | number);
|
|
4
|
+
export type TypePath<T> = [] | (0 extends 1 & T ? any[] : T extends object ? T extends readonly any[] ? number extends T["length"] ? {
|
|
5
|
+
[K in TupleIndex<T>]: [AsNumber<K>, ...TypePath<T[K]>];
|
|
6
|
+
}[TupleIndex<T>] : [
|
|
7
|
+
number,
|
|
8
|
+
...TypePath<T[number]>
|
|
9
|
+
] : {
|
|
10
|
+
[K in ObjectKey<T>]: [K, ...TypePath<T[K]>];
|
|
11
|
+
}[ObjectKey<T>] : [
|
|
12
|
+
]);
|
|
13
|
+
export type TypeAtPath<T, P extends readonly any[]> = P extends [
|
|
14
|
+
infer Head,
|
|
15
|
+
...infer Rest
|
|
16
|
+
] ? Head extends keyof T ? TypeAtPath<T[Head], Rest> : never : T;
|
|
17
|
+
export type DeepPartial<T> = T extends readonly any[] ? readonly DeepPartial<T[number]>[] : T extends {
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
} ? {
|
|
20
|
+
readonly [K in keyof T]?: DeepPartial<T[K]>;
|
|
21
|
+
} : T;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=type-path-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-path-utils.d.ts","sourceRoot":"","sources":["../../../src/core/tool/type-path-utils.ts"],"names":[],"mappings":"AAAA,KAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AACzE,KAAK,UAAU,CAAC,CAAC,SAAS,SAAS,GAAG,EAAE,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,EAAE,CAAC,CAAC;AAC1E,KAAK,SAAS,CAAC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;AAEhD,MAAM,MAAM,QAAQ,CAAC,CAAC,IAClB,EAAE,GACF,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GACZ,GAAG,EAAE,GACL,CAAC,SAAS,MAAM,GACd,CAAC,SAAS,SAAS,GAAG,EAAE,GACtB,MAAM,SAAS,CAAC,CAAC,QAAQ,CAAC,GAExB;KACG,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACvD,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAEhB;IAAC,MAAM;IAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;CAAC,GAElC;KAAG,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAE/D;CAAE,CAAC,CAAC;AAEd,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,SAAS,SAAS,GAAG,EAAE,IAAI,CAAC,SAAS;IAC9D,MAAM,IAAI;IACV,GAAG,MAAM,IAAI;CACd,GACG,IAAI,SAAS,MAAM,CAAC,GAClB,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,GACzB,KAAK,GACP,CAAC,CAAC;AAEN,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,GAAG,EAAE,GACjD,SAAS,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,GACjC,CAAC,SAAS;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,GAC9B;IAAE,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,GAC/C,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/core/tool/type-path-utils.ts
|
|
17
|
+
var type_path_utils_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(type_path_utils_exports);
|
|
19
|
+
//# sourceMappingURL=type-path-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/tool/type-path-utils.ts"],"sourcesContent":["type AsNumber<K> = K extends `${infer N extends number}` ? N | K : never;\ntype TupleIndex<T extends readonly any[]> = Exclude<keyof T, keyof any[]>;\ntype ObjectKey<T> = keyof T & (string | number);\n\nexport type TypePath<T> =\n | []\n | (0 extends 1 & T // IsAny\n ? any[]\n : T extends object // IsObjectOrArrayOrTuple\n ? T extends readonly any[] // IsArrayOrTuple\n ? number extends T[\"length\"] // IsTuple\n ? // Tuple: make union of [index, ...TypePath<element>]\n {\n [K in TupleIndex<T>]: [AsNumber<K>, ...TypePath<T[K]>];\n }[TupleIndex<T>]\n : // Array: use number index\n [number, ...TypePath<T[number]>]\n : // Object: make union of [key, ...TypePath<value>]\n { [K in ObjectKey<T>]: [K, ...TypePath<T[K]>] }[ObjectKey<T>]\n : // Base case: primitive values have no path\n []);\n\nexport type TypeAtPath<T, P extends readonly any[]> = P extends [\n infer Head,\n ...infer Rest,\n]\n ? Head extends keyof T\n ? TypeAtPath<T[Head], Rest>\n : never\n : T;\n\nexport type DeepPartial<T> = T extends readonly any[]\n ? readonly DeepPartial<T[number]>[]\n : T extends { [key: string]: any }\n ? { readonly [K in keyof T]?: DeepPartial<T[K]> }\n : T;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=type-path-utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Counter.d.ts","sourceRoot":"","sources":["../../../src/core/utils/Counter.ts"],"names":[],"mappings":"AAAA,qBAAa,OAAO;IACX,KAAK,SAAM;IAElB,EAAE;CAGH"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/core/utils/Counter.ts
|
|
21
|
+
var Counter_exports = {};
|
|
22
|
+
__export(Counter_exports, {
|
|
23
|
+
Counter: () => Counter
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(Counter_exports);
|
|
26
|
+
var Counter = class {
|
|
27
|
+
value = -1;
|
|
28
|
+
up() {
|
|
29
|
+
return ++this.value;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
Counter
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=Counter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/utils/Counter.ts"],"sourcesContent":["export class Counter {\n public value = -1;\n\n up() {\n return ++this.value;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,IAAM,UAAN,MAAc;AAAA,EACZ,QAAQ;AAAA,EAEf,KAAK;AACH,WAAO,EAAE,KAAK;AAAA,EAChB;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/utils/Counter.ts"],"sourcesContent":["export class Counter {\n public value = -1;\n\n up() {\n return ++this.value;\n }\n}\n"],"mappings":";AAAO,IAAM,UAAN,MAAc;AAAA,EACZ,QAAQ;AAAA,EAEf,KAAK;AACH,WAAO,EAAE,KAAK;AAAA,EAChB;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateId.d.ts","sourceRoot":"","sources":["../../../src/core/utils/generateId.tsx"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,2BAGtB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/core/utils/generateId.tsx
|
|
21
|
+
var generateId_exports = {};
|
|
22
|
+
__export(generateId_exports, {
|
|
23
|
+
generateId: () => generateId
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(generateId_exports);
|
|
26
|
+
var import_non_secure = require("nanoid/non-secure");
|
|
27
|
+
var generateId = (0, import_non_secure.customAlphabet)(
|
|
28
|
+
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
29
|
+
7
|
|
30
|
+
);
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
generateId
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=generateId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/utils/generateId.tsx"],"sourcesContent":["import { customAlphabet } from \"nanoid/non-secure\";\n\nexport const generateId = customAlphabet(\n \"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\",\n 7,\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA+B;AAExB,IAAM,iBAAa;AAAA,EACxB;AAAA,EACA;AACF;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/core/utils/generateId.tsx
|
|
2
|
+
import { customAlphabet } from "nanoid/non-secure";
|
|
3
|
+
var generateId = customAlphabet(
|
|
4
|
+
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
5
|
+
7
|
|
6
|
+
);
|
|
7
|
+
export {
|
|
8
|
+
generateId
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=generateId.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/utils/generateId.tsx"],"sourcesContent":["import { customAlphabet } from \"nanoid/non-secure\";\n\nexport const generateId = customAlphabet(\n \"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\",\n 7,\n);\n"],"mappings":";AAAA,SAAS,sBAAsB;AAExB,IAAM,aAAa;AAAA,EACxB;AAAA,EACA;AACF;","names":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AssistantStreamChunk, PartInit } from "../../AssistantStreamChunk";
|
|
2
|
+
/**
|
|
3
|
+
* For chunk types that are associated with a part,
|
|
4
|
+
* we require a non‑nullable meta field.
|
|
5
|
+
*/
|
|
6
|
+
export type AssistantMetaStreamChunk = (AssistantStreamChunk & {
|
|
7
|
+
type: "text-delta" | "part-finish";
|
|
8
|
+
meta: PartInit;
|
|
9
|
+
}) | (AssistantStreamChunk & {
|
|
10
|
+
type: "result" | "tool-call-args-text-finish";
|
|
11
|
+
meta: PartInit & {
|
|
12
|
+
type: "tool-call";
|
|
13
|
+
};
|
|
14
|
+
}) | (AssistantStreamChunk & {
|
|
15
|
+
type: Exclude<AssistantStreamChunk["type"], "text-delta" | "result" | "tool-call-args-text-finish" | "part-finish">;
|
|
16
|
+
});
|
|
17
|
+
export declare class AssistantMetaTransformStream extends TransformStream<AssistantStreamChunk, AssistantMetaStreamChunk> {
|
|
18
|
+
constructor();
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=AssistantMetaTransformStream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AssistantMetaTransformStream.d.ts","sourceRoot":"","sources":["../../../../src/core/utils/stream/AssistantMetaTransformStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAE5E;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAChC,CAAC,oBAAoB,GAAG;IACtB,IAAI,EAAE,YAAY,GAAG,aAAa,CAAC;IACnC,IAAI,EAAE,QAAQ,CAAC;CAChB,CAAC,GACF,CAAC,oBAAoB,GAAG;IACtB,IAAI,EAAE,QAAQ,GAAG,4BAA4B,CAAC;IAC9C,IAAI,EAAE,QAAQ,GAAG;QAAE,IAAI,EAAE,WAAW,CAAA;KAAE,CAAC;CACxC,CAAC,GACF,CAAC,oBAAoB,GAAG;IACtB,IAAI,EAAE,OAAO,CACX,oBAAoB,CAAC,MAAM,CAAC,EAC5B,YAAY,GAAG,QAAQ,GAAG,4BAA4B,GAAG,aAAa,CACvE,CAAC;CACH,CAAC,CAAC;AACP,qBAAa,4BAA6B,SAAQ,eAAe,CAC/D,oBAAoB,EACpB,wBAAwB,CACzB;;CAiDA"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/core/utils/stream/AssistantMetaTransformStream.ts
|
|
21
|
+
var AssistantMetaTransformStream_exports = {};
|
|
22
|
+
__export(AssistantMetaTransformStream_exports, {
|
|
23
|
+
AssistantMetaTransformStream: () => AssistantMetaTransformStream
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(AssistantMetaTransformStream_exports);
|
|
26
|
+
var AssistantMetaTransformStream = class extends TransformStream {
|
|
27
|
+
constructor() {
|
|
28
|
+
const parts = [];
|
|
29
|
+
super({
|
|
30
|
+
transform(chunk, controller) {
|
|
31
|
+
if (chunk.type === "part-start") {
|
|
32
|
+
if (chunk.path.length !== 0) {
|
|
33
|
+
controller.error(new Error("Nested parts are not supported"));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
parts.push(chunk.part);
|
|
37
|
+
controller.enqueue(chunk);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (chunk.type === "text-delta" || chunk.type === "result" || chunk.type === "part-finish" || chunk.type === "tool-call-args-text-finish") {
|
|
41
|
+
if (chunk.path.length !== 1) {
|
|
42
|
+
controller.error(
|
|
43
|
+
new Error(`${chunk.type} chunks must have a path of length 1`)
|
|
44
|
+
);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const idx = chunk.path[0];
|
|
48
|
+
if (idx < 0 || idx >= parts.length) {
|
|
49
|
+
controller.error(new Error(`Invalid path index: ${idx}`));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const part = parts[idx];
|
|
53
|
+
controller.enqueue({
|
|
54
|
+
...chunk,
|
|
55
|
+
meta: part
|
|
56
|
+
// TODO
|
|
57
|
+
});
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
controller.enqueue(chunk);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
AssistantMetaTransformStream
|
|
68
|
+
});
|
|
69
|
+
//# sourceMappingURL=AssistantMetaTransformStream.js.map
|