assistant-stream 0.1.2 → 0.1.4

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/index.d.ts CHANGED
@@ -1,18 +1,10 @@
1
- import { a as AssistantStreamChunk, T as ToolResponse, R as ReadonlyJSONValue, c as AssistantMessage, d as AssistantStreamEncoder, A as AssistantStream } from './assistant-stream-54RSz6y3.js';
2
- export { e as createAssistantStream, f as createAssistantStreamResponse } from './assistant-stream-54RSz6y3.js';
3
-
4
- declare class PipeableTransformStream<I, O> extends TransformStream<I, O> {
5
- constructor(transform: (readable: ReadableStream<I>) => ReadableStream<O>);
6
- }
7
-
8
- type ToolCallback = (toolCall: {
9
- toolCallId: string;
10
- toolName: string;
11
- args: unknown;
12
- }) => Promise<ToolResponse<ReadonlyJSONValue>> | ToolResponse<ReadonlyJSONValue> | undefined;
13
- declare class ToolExecutionStream extends PipeableTransformStream<AssistantStreamChunk, AssistantStreamChunk> {
14
- constructor(toolCallback: ToolCallback);
15
- }
1
+ import { a as AssistantStreamChunk, c as AssistantMessage, d as AssistantStreamEncoder, A as AssistantStream, T as ToolResponse } from './assistant-stream-kAoIMgvk.js';
2
+ export { e as createAssistantStream, f as createAssistantStreamResponse } from './assistant-stream-kAoIMgvk.js';
3
+ import { JSONSchema7 } from 'json-schema';
4
+ import { DeepPartial } from 'ai';
5
+ import { A as AsyncIterableStream } from './AsyncIterableStream-C3C8ZoXv.js';
6
+ import { StandardSchemaV1 } from '@standard-schema/spec';
7
+ import { R as ReadonlyJSONValue } from './json-value-Ch5eKkQ_.js';
16
8
 
17
9
  declare class AssistantMessageAccumulator extends TransformStream<AssistantStreamChunk, AssistantMessage> {
18
10
  constructor({ initialMessage, }?: {
@@ -20,6 +12,10 @@ declare class AssistantMessageAccumulator extends TransformStream<AssistantStrea
20
12
  });
21
13
  }
22
14
 
15
+ declare class PipeableTransformStream<I, O> extends TransformStream<I, O> {
16
+ constructor(transform: (readable: ReadableStream<I>) => ReadableStream<O>);
17
+ }
18
+
23
19
  declare class DataStreamEncoder extends PipeableTransformStream<AssistantStreamChunk, Uint8Array> implements AssistantStreamEncoder {
24
20
  headers: Headers;
25
21
  constructor();
@@ -47,4 +43,105 @@ declare class AssistantMessageStream {
47
43
  tee(): [AssistantMessageStream, AssistantMessageStream];
48
44
  }
49
45
 
50
- export { AssistantMessage, AssistantMessageAccumulator, AssistantMessageStream, AssistantStream, AssistantStreamChunk, DataStreamDecoder, DataStreamEncoder, PlainTextDecoder, PlainTextEncoder, ToolExecutionStream, ToolResponse };
46
+ type AsNumber<K> = K extends `${infer N extends number}` ? N | K : never;
47
+ type TupleIndex<T extends readonly any[]> = Exclude<keyof T, keyof any[]>;
48
+ type ObjectKey<T> = keyof T & (string | number);
49
+ type TypePath<T> = [] | (0 extends 1 & T ? any[] : T extends object ? T extends readonly any[] ? number extends T["length"] ? {
50
+ [K in TupleIndex<T>]: [AsNumber<K>, ...TypePath<T[K]>];
51
+ }[TupleIndex<T>] : [
52
+ number,
53
+ ...TypePath<T[number]>
54
+ ] : {
55
+ [K in ObjectKey<T>]: [K, ...TypePath<T[K]>];
56
+ }[ObjectKey<T>] : [
57
+ ]);
58
+ type TypeAtPath<T, P extends readonly any[]> = P extends [
59
+ infer Head,
60
+ ...infer Rest
61
+ ] ? Head extends keyof T ? TypeAtPath<T[Head], Rest> : never : T;
62
+
63
+ /**
64
+ * Interface for reading tool call arguments from a stream, which are
65
+ * generated by a language learning model (LLM). Provides methods to
66
+ * retrieve specific values, partial streams, or complete items from
67
+ * an array, based on a specified path.
68
+ *
69
+ * @template TArgs The type of arguments being read.
70
+ */
71
+ interface ToolCallArgsReader<TArgs> {
72
+ /**
73
+ * Returns a promise that will resolve to the value at the given path,
74
+ * as soon as that path is generated by the LLM.
75
+ *
76
+ * @param fieldPath An array of object keys or array indices.
77
+ */
78
+ get<PathT extends TypePath<TArgs>>(...fieldPath: PathT): Promise<TypeAtPath<TArgs, PathT>>;
79
+ /**
80
+ * Returns a stream that will emit partial values at the given path,
81
+ * as they are generated by the LLM.
82
+ *
83
+ * @param fieldPath An array of object keys or array indices.
84
+ */
85
+ streamValues<PathT extends TypePath<TArgs>>(...fieldPath: PathT): AsyncIterableStream<DeepPartial<TypeAtPath<TArgs, PathT>>>;
86
+ /**
87
+ * Returns a stream that will emit partial text at the given path,
88
+ * as they are generated by the LLM.
89
+ *
90
+ * @param fieldPath An array of object keys or array indices.
91
+ */
92
+ streamText<PathT extends TypePath<TArgs>>(...fieldPath: PathT): TypeAtPath<TArgs, PathT> extends string & infer U ? AsyncIterableStream<U> : never;
93
+ /**
94
+ * Returns a stream that will emit complete items in the array
95
+ * at the given path, as they are generated by the LLM.
96
+ *
97
+ * @param fieldPath An array of object keys or array indices.
98
+ */
99
+ forEach<PathT extends TypePath<TArgs>>(...fieldPath: PathT): TypeAtPath<TArgs, PathT> extends Array<infer U> ? AsyncIterableStream<U> : never;
100
+ }
101
+ interface ToolCallResultReader<TResult> {
102
+ get: () => Promise<TResult>;
103
+ }
104
+ interface ToolCallReader<TArgs, TResult> {
105
+ args: ToolCallArgsReader<TArgs>;
106
+ result: ToolCallResultReader<TResult>;
107
+ }
108
+ type ToolExecutionContext = {
109
+ toolCallId: string;
110
+ abortSignal: AbortSignal;
111
+ };
112
+ type ToolExecuteFunction<TArgs, TResult> = (args: TArgs, context: ToolExecutionContext) => TResult | Promise<TResult>;
113
+ type ToolStreamCallFunction<TArgs, TResult> = (reader: ToolCallReader<TArgs, TResult>, context: ToolExecutionContext) => void;
114
+ type OnSchemaValidationErrorFunction<TResult> = ToolExecuteFunction<unknown, TResult>;
115
+ type Tool<TArgs = unknown, TResult = unknown> = {
116
+ description?: string | undefined;
117
+ parameters: StandardSchemaV1<TArgs> | JSONSchema7;
118
+ execute?: ToolExecuteFunction<TArgs, TResult>;
119
+ /**
120
+ * @deprecated Experimental, API may change.
121
+ */
122
+ streamCall?: ToolStreamCallFunction<TArgs, TResult>;
123
+ experimental_onSchemaValidationError?: OnSchemaValidationErrorFunction<TResult>;
124
+ };
125
+
126
+ type ToolCallback = (toolCall: {
127
+ toolCallId: string;
128
+ toolName: string;
129
+ args: unknown;
130
+ }) => Promise<ToolResponse<ReadonlyJSONValue>> | ToolResponse<ReadonlyJSONValue> | undefined;
131
+ type ToolStreamCallback = <TArgs, TResult>(toolCall: {
132
+ reader: ToolCallReader<TArgs, TResult>;
133
+ toolCallId: string;
134
+ toolName: string;
135
+ }) => void;
136
+ type ToolExecutionOptions = {
137
+ execute: ToolCallback;
138
+ streamCall: ToolStreamCallback;
139
+ };
140
+ declare class ToolExecutionStream extends PipeableTransformStream<AssistantStreamChunk, AssistantStreamChunk> {
141
+ constructor(options: ToolExecutionOptions);
142
+ }
143
+
144
+ declare function unstable_runPendingTools(message: AssistantMessage, tools: Record<string, Tool<any, any>> | undefined, abortSignal: AbortSignal): Promise<AssistantMessage>;
145
+ declare function toolResultStream(tools: Record<string, Tool<any, any>> | undefined, abortSignal: AbortSignal): ToolExecutionStream;
146
+
147
+ export { AssistantMessage, AssistantMessageAccumulator, AssistantMessageStream, AssistantStream, AssistantStreamChunk, DataStreamDecoder, DataStreamEncoder, PlainTextDecoder, PlainTextEncoder, type Tool, type ToolCallReader, ToolExecutionStream, ToolResponse, unstable_runPendingTools, toolResultStream as unstable_toolResultStream };