assistant-stream 0.1.4 → 0.1.6
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.mts +10 -4
- package/dist/index.d.ts +10 -4
- package/dist/index.js +33 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as AssistantStreamChunk, c as AssistantMessage, d as AssistantStreamEncoder, A as AssistantStream, T as ToolResponse } from './assistant-stream-ISFjQ0mQ.mjs';
|
|
2
|
-
export { e as createAssistantStream, f as createAssistantStreamResponse } from './assistant-stream-ISFjQ0mQ.mjs';
|
|
2
|
+
export { b as AssistantStreamController, e as createAssistantStream, f as createAssistantStreamResponse } from './assistant-stream-ISFjQ0mQ.mjs';
|
|
3
3
|
import { JSONSchema7 } from 'json-schema';
|
|
4
4
|
import { DeepPartial } from 'ai';
|
|
5
5
|
import { A as AsyncIterableStream } from './AsyncIterableStream-C3C8ZoXv.mjs';
|
|
@@ -98,12 +98,18 @@ interface ToolCallArgsReader<TArgs> {
|
|
|
98
98
|
*/
|
|
99
99
|
forEach<PathT extends TypePath<TArgs>>(...fieldPath: PathT): TypeAtPath<TArgs, PathT> extends Array<infer U> ? AsyncIterableStream<U> : never;
|
|
100
100
|
}
|
|
101
|
-
interface
|
|
102
|
-
get: () => Promise<TResult
|
|
101
|
+
interface ToolCallResponseReader<TResult> {
|
|
102
|
+
get: () => Promise<ToolResponse<TResult>>;
|
|
103
103
|
}
|
|
104
104
|
interface ToolCallReader<TArgs, TResult> {
|
|
105
105
|
args: ToolCallArgsReader<TArgs>;
|
|
106
|
-
|
|
106
|
+
response: ToolCallResponseReader<TResult>;
|
|
107
|
+
/**
|
|
108
|
+
* @deprecated Deprecated. Use `response.get().result` instead.
|
|
109
|
+
*/
|
|
110
|
+
result: {
|
|
111
|
+
get: () => Promise<TResult>;
|
|
112
|
+
};
|
|
107
113
|
}
|
|
108
114
|
type ToolExecutionContext = {
|
|
109
115
|
toolCallId: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
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';
|
|
2
|
+
export { b as AssistantStreamController, e as createAssistantStream, f as createAssistantStreamResponse } from './assistant-stream-kAoIMgvk.js';
|
|
3
3
|
import { JSONSchema7 } from 'json-schema';
|
|
4
4
|
import { DeepPartial } from 'ai';
|
|
5
5
|
import { A as AsyncIterableStream } from './AsyncIterableStream-C3C8ZoXv.js';
|
|
@@ -98,12 +98,18 @@ interface ToolCallArgsReader<TArgs> {
|
|
|
98
98
|
*/
|
|
99
99
|
forEach<PathT extends TypePath<TArgs>>(...fieldPath: PathT): TypeAtPath<TArgs, PathT> extends Array<infer U> ? AsyncIterableStream<U> : never;
|
|
100
100
|
}
|
|
101
|
-
interface
|
|
102
|
-
get: () => Promise<TResult
|
|
101
|
+
interface ToolCallResponseReader<TResult> {
|
|
102
|
+
get: () => Promise<ToolResponse<TResult>>;
|
|
103
103
|
}
|
|
104
104
|
interface ToolCallReader<TArgs, TResult> {
|
|
105
105
|
args: ToolCallArgsReader<TArgs>;
|
|
106
|
-
|
|
106
|
+
response: ToolCallResponseReader<TResult>;
|
|
107
|
+
/**
|
|
108
|
+
* @deprecated Deprecated. Use `response.get().result` instead.
|
|
109
|
+
*/
|
|
110
|
+
result: {
|
|
111
|
+
get: () => Promise<TResult>;
|
|
112
|
+
};
|
|
107
113
|
}
|
|
108
114
|
type ToolExecutionContext = {
|
|
109
115
|
toolCallId: string;
|
package/dist/index.js
CHANGED
|
@@ -2085,17 +2085,17 @@ var ToolCallArgsReaderImpl = class {
|
|
|
2085
2085
|
return stream;
|
|
2086
2086
|
}
|
|
2087
2087
|
};
|
|
2088
|
-
var
|
|
2089
|
-
constructor(
|
|
2090
|
-
this.
|
|
2088
|
+
var ToolCallResponseReaderImpl = class {
|
|
2089
|
+
constructor(promise) {
|
|
2090
|
+
this.promise = promise;
|
|
2091
2091
|
}
|
|
2092
2092
|
get() {
|
|
2093
|
-
return this.
|
|
2093
|
+
return this.promise;
|
|
2094
2094
|
}
|
|
2095
2095
|
};
|
|
2096
2096
|
var ToolCallReaderImpl = class {
|
|
2097
2097
|
args;
|
|
2098
|
-
|
|
2098
|
+
response;
|
|
2099
2099
|
writable;
|
|
2100
2100
|
resolve;
|
|
2101
2101
|
argsText = "";
|
|
@@ -2105,7 +2105,7 @@ var ToolCallReaderImpl = class {
|
|
|
2105
2105
|
this.args = new ToolCallArgsReaderImpl(stream.readable);
|
|
2106
2106
|
const { promise, resolve } = promiseWithResolvers();
|
|
2107
2107
|
this.resolve = resolve;
|
|
2108
|
-
this.
|
|
2108
|
+
this.response = new ToolCallResponseReaderImpl(promise);
|
|
2109
2109
|
}
|
|
2110
2110
|
async appendArgsTextDelta(text) {
|
|
2111
2111
|
const writer = this.writable.getWriter();
|
|
@@ -2118,9 +2118,15 @@ var ToolCallReaderImpl = class {
|
|
|
2118
2118
|
}
|
|
2119
2119
|
this.argsText += text;
|
|
2120
2120
|
}
|
|
2121
|
-
|
|
2121
|
+
setResponse(value) {
|
|
2122
2122
|
this.resolve(value);
|
|
2123
2123
|
}
|
|
2124
|
+
result = {
|
|
2125
|
+
get: async () => {
|
|
2126
|
+
const response = await this.response.get();
|
|
2127
|
+
return response.result;
|
|
2128
|
+
}
|
|
2129
|
+
};
|
|
2124
2130
|
};
|
|
2125
2131
|
|
|
2126
2132
|
// src/core/tool/ToolExecutionStream.ts
|
|
@@ -2160,20 +2166,22 @@ var ToolExecutionStream = class extends PipeableTransformStream {
|
|
|
2160
2166
|
case "tool-call-args-text-finish": {
|
|
2161
2167
|
if (chunk.meta.type !== "tool-call") break;
|
|
2162
2168
|
const { toolCallId, toolName } = chunk.meta;
|
|
2169
|
+
const streamController = toolCallControllers.get(toolCallId);
|
|
2170
|
+
if (!streamController)
|
|
2171
|
+
throw new Error("No controller found for tool call");
|
|
2163
2172
|
const promise = withPromiseOrValue(
|
|
2164
2173
|
() => {
|
|
2165
|
-
|
|
2166
|
-
if (!controller2) {
|
|
2174
|
+
if (!streamController.argsText) {
|
|
2167
2175
|
console.log(
|
|
2168
|
-
"Encountered tool call without
|
|
2176
|
+
"Encountered tool call without args, this should never happen"
|
|
2169
2177
|
);
|
|
2170
2178
|
throw new Error(
|
|
2171
|
-
"Encountered tool call without
|
|
2179
|
+
"Encountered tool call without args, this is unexpected."
|
|
2172
2180
|
);
|
|
2173
2181
|
}
|
|
2174
2182
|
let args;
|
|
2175
2183
|
try {
|
|
2176
|
-
args = import_secure_json_parse2.default.parse(
|
|
2184
|
+
args = import_secure_json_parse2.default.parse(streamController.argsText);
|
|
2177
2185
|
} catch (e) {
|
|
2178
2186
|
throw new Error(
|
|
2179
2187
|
`Function parameter parsing failed. ${JSON.stringify(e.message)}`
|
|
@@ -2187,21 +2195,29 @@ var ToolExecutionStream = class extends PipeableTransformStream {
|
|
|
2187
2195
|
},
|
|
2188
2196
|
(c) => {
|
|
2189
2197
|
if (c === void 0) return;
|
|
2190
|
-
|
|
2191
|
-
type: "result",
|
|
2192
|
-
path: chunk.path,
|
|
2198
|
+
const result = new ToolResponse({
|
|
2193
2199
|
artifact: c.artifact,
|
|
2194
2200
|
result: c.result,
|
|
2195
2201
|
isError: c.isError
|
|
2196
2202
|
});
|
|
2197
|
-
|
|
2198
|
-
(e) => {
|
|
2203
|
+
streamController.setResponse(result);
|
|
2199
2204
|
controller.enqueue({
|
|
2200
2205
|
type: "result",
|
|
2201
2206
|
path: chunk.path,
|
|
2207
|
+
...result
|
|
2208
|
+
});
|
|
2209
|
+
},
|
|
2210
|
+
(e) => {
|
|
2211
|
+
const result = new ToolResponse({
|
|
2202
2212
|
result: String(e),
|
|
2203
2213
|
isError: true
|
|
2204
2214
|
});
|
|
2215
|
+
streamController.setResponse(result);
|
|
2216
|
+
controller.enqueue({
|
|
2217
|
+
type: "result",
|
|
2218
|
+
path: chunk.path,
|
|
2219
|
+
...result
|
|
2220
|
+
});
|
|
2205
2221
|
}
|
|
2206
2222
|
);
|
|
2207
2223
|
if (promise) {
|