assistant-stream 0.3.19 → 0.3.21
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/core/accumulators/assistant-message-accumulator.js.map +1 -1
- package/dist/core/converters/toGenericMessages.js.map +1 -1
- package/dist/core/object/ObjectStreamResponse.js.map +1 -1
- package/dist/core/serialization/PlainText.js.map +1 -1
- package/dist/core/serialization/assistant-transport/AssistantTransport.js.map +1 -1
- package/dist/core/serialization/data-stream/DataStream.js.map +1 -1
- package/dist/core/serialization/ui-message-stream/UIMessageStream.js.map +1 -1
- package/dist/core/tool/ToolCallReader.d.ts +2 -0
- package/dist/core/tool/ToolCallReader.d.ts.map +1 -1
- package/dist/core/tool/ToolCallReader.js +60 -13
- package/dist/core/tool/ToolCallReader.js.map +1 -1
- package/dist/core/tool/ToolExecutionStream.js +3 -2
- package/dist/core/tool/ToolExecutionStream.js.map +1 -1
- package/dist/core/tool/schema-utils.d.ts +2 -0
- package/dist/core/tool/schema-utils.d.ts.map +1 -1
- package/dist/core/tool/schema-utils.js +5 -2
- package/dist/core/tool/schema-utils.js.map +1 -1
- package/dist/core/tool/tool-types.d.ts +44 -5
- package/dist/core/tool/tool-types.d.ts.map +1 -1
- package/dist/core/tool/toolResultStream.js.map +1 -1
- package/dist/core/utils/stream/AssistantTransformStream.js.map +1 -1
- package/dist/core/utils/stream/SSE.js.map +1 -1
- package/dist/core/utils/stream/merge.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/resumable/ResumableStreamContext.js.map +1 -1
- package/dist/resumable/createResumableAssistantStreamResponse.js.map +1 -1
- package/dist/resumable/stores/InMemoryResumableStreamStore.js.map +1 -1
- package/dist/resumable/stores/ioredis.js.map +1 -1
- package/dist/utils/json/fix-json.js.map +1 -1
- package/dist/utils/json/is-json.js.map +1 -1
- package/package.json +4 -4
- package/src/core/tool/ToolCallReader.test.ts +86 -0
- package/src/core/tool/ToolCallReader.ts +83 -29
- package/src/core/tool/ToolExecutionStream.ts +8 -2
- package/src/core/tool/schema-utils.test.ts +63 -0
- package/src/core/tool/schema-utils.ts +25 -3
- package/src/core/tool/tool-types.ts +73 -1
- package/src/index.ts +1 -0
|
@@ -15,6 +15,8 @@ export type ToToolsJSONSchemaOptions = {
|
|
|
15
15
|
/**
|
|
16
16
|
* Filter to determine which tools to include.
|
|
17
17
|
* Defaults to excluding disabled tools and backend tools.
|
|
18
|
+
*
|
|
19
|
+
* Tools with backend-default parameters are always excluded.
|
|
18
20
|
*/
|
|
19
21
|
filter?: (name: string, tool: Tool) => boolean;
|
|
20
22
|
};
|
|
@@ -130,7 +132,19 @@ export function toPartialJSONSchema(schema: JSONSchema7): JSONSchema7 {
|
|
|
130
132
|
}
|
|
131
133
|
|
|
132
134
|
function defaultToolFilter(_name: string, tool: Tool): boolean {
|
|
133
|
-
return
|
|
135
|
+
return (
|
|
136
|
+
!tool.disabled &&
|
|
137
|
+
tool.type !== "backend" &&
|
|
138
|
+
(tool.type !== "frontend" || tool.execute !== undefined)
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function toolHasUploadableParameters(
|
|
143
|
+
tool: Tool,
|
|
144
|
+
): tool is Tool & { parameters: NonNullable<Tool["parameters"]> } {
|
|
145
|
+
return (
|
|
146
|
+
tool.parameters !== undefined && !tool.unstable_backendDefault?.parameters
|
|
147
|
+
);
|
|
134
148
|
}
|
|
135
149
|
|
|
136
150
|
/**
|
|
@@ -152,13 +166,21 @@ export function toToolsJSONSchema(
|
|
|
152
166
|
|
|
153
167
|
return Object.fromEntries(
|
|
154
168
|
Object.entries(tools)
|
|
155
|
-
.filter(([name, tool]) => filter(name, tool)
|
|
169
|
+
.filter(([name, tool]) => filter(name, tool))
|
|
170
|
+
.filter(
|
|
171
|
+
(
|
|
172
|
+
entry,
|
|
173
|
+
): entry is [
|
|
174
|
+
string,
|
|
175
|
+
Tool & { parameters: NonNullable<Tool["parameters"]> },
|
|
176
|
+
] => toolHasUploadableParameters(entry[1]),
|
|
177
|
+
)
|
|
156
178
|
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
|
157
179
|
.map(([name, tool]) => [
|
|
158
180
|
name,
|
|
159
181
|
{
|
|
160
182
|
...(tool.description && { description: tool.description }),
|
|
161
|
-
parameters: toJSONSchema(tool.parameters
|
|
183
|
+
parameters: toJSONSchema(tool.parameters),
|
|
162
184
|
...(tool.providerOptions && {
|
|
163
185
|
providerOptions: tool.providerOptions,
|
|
164
186
|
}),
|
|
@@ -216,6 +216,16 @@ type ToolBase<
|
|
|
216
216
|
* @see ToolDisplay
|
|
217
217
|
*/
|
|
218
218
|
display?: ToolDisplay;
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* @internal Defaults already known by the backend for this tool. Client
|
|
222
|
+
* transports omit matching fields and only upload overrides.
|
|
223
|
+
*
|
|
224
|
+
* This is only meaningful for frontend and human tools.
|
|
225
|
+
*/
|
|
226
|
+
unstable_backendDefault?: {
|
|
227
|
+
parameters?: boolean;
|
|
228
|
+
};
|
|
219
229
|
};
|
|
220
230
|
|
|
221
231
|
type BackendTool<
|
|
@@ -276,7 +286,7 @@ type FrontendTool<
|
|
|
276
286
|
/** Prevents the tool from being exposed to the model while true. */
|
|
277
287
|
disabled?: boolean;
|
|
278
288
|
/** Executes the tool after the model provides valid arguments. */
|
|
279
|
-
execute
|
|
289
|
+
execute?: ToolExecuteFunction<TArgs, TResult>;
|
|
280
290
|
/** Converts the execution result into model-visible output. */
|
|
281
291
|
toModelOutput?: ToolModelOutputFunction<TArgs, TResult>;
|
|
282
292
|
/** Handles invalid tool arguments when schema validation fails. */
|
|
@@ -305,6 +315,63 @@ type HumanTool<
|
|
|
305
315
|
providerOptions?: ProviderOptions;
|
|
306
316
|
};
|
|
307
317
|
|
|
318
|
+
type ProviderTool<
|
|
319
|
+
TArgs extends Record<string, unknown> = Record<string, unknown>,
|
|
320
|
+
TResult = unknown,
|
|
321
|
+
> = ToolBase<TArgs, TResult> & {
|
|
322
|
+
/** Tool executed by the LLM provider rather than assistant-ui. */
|
|
323
|
+
type: "provider";
|
|
324
|
+
|
|
325
|
+
/** Provider-defined tool identifier, e.g. `openai.web_search_preview`. */
|
|
326
|
+
providerId: `${string}.${string}`;
|
|
327
|
+
/** Schema used by adapters for validation and type plumbing. */
|
|
328
|
+
parameters?: StandardSchemaV1<TArgs> | JSONSchema7 | undefined;
|
|
329
|
+
/** Provider-specific configuration for this tool. */
|
|
330
|
+
args: Record<string, unknown>;
|
|
331
|
+
/**
|
|
332
|
+
* Whether provider results may arrive after the originating response turn.
|
|
333
|
+
*/
|
|
334
|
+
supportsDeferredResults?: boolean;
|
|
335
|
+
|
|
336
|
+
description?: undefined;
|
|
337
|
+
disabled?: boolean;
|
|
338
|
+
execute?: undefined;
|
|
339
|
+
toModelOutput?: undefined;
|
|
340
|
+
experimental_onSchemaValidationError?: undefined;
|
|
341
|
+
providerOptions?: ProviderOptions;
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
export type McpServerConfig =
|
|
345
|
+
| {
|
|
346
|
+
/** Connect to an MCP server over Streamable HTTP or server-sent events. */
|
|
347
|
+
type: "http" | "sse";
|
|
348
|
+
url: string;
|
|
349
|
+
headers?: Record<string, string>;
|
|
350
|
+
redirect?: "follow" | "error";
|
|
351
|
+
}
|
|
352
|
+
| {
|
|
353
|
+
/** Start and connect to a local MCP server over stdio. */
|
|
354
|
+
type: "stdio";
|
|
355
|
+
command: string;
|
|
356
|
+
args?: readonly string[];
|
|
357
|
+
env?: Record<string, string>;
|
|
358
|
+
cwd?: string;
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
type McpTool = ToolBase<Record<string, unknown>, unknown> & {
|
|
362
|
+
/** Tools loaded from an MCP server by a server adapter. */
|
|
363
|
+
type: "mcp";
|
|
364
|
+
server: McpServerConfig;
|
|
365
|
+
|
|
366
|
+
description?: undefined;
|
|
367
|
+
parameters?: undefined;
|
|
368
|
+
disabled?: boolean;
|
|
369
|
+
execute?: undefined;
|
|
370
|
+
toModelOutput?: undefined;
|
|
371
|
+
experimental_onSchemaValidationError?: undefined;
|
|
372
|
+
providerOptions?: undefined;
|
|
373
|
+
};
|
|
374
|
+
|
|
308
375
|
/**
|
|
309
376
|
* Definition for a tool that can be exposed to the assistant model.
|
|
310
377
|
*
|
|
@@ -353,6 +420,8 @@ export type Tool<
|
|
|
353
420
|
| FrontendTool<TArgs, TResult>
|
|
354
421
|
| BackendTool<TArgs, TResult>
|
|
355
422
|
| HumanTool<TArgs, TResult>
|
|
423
|
+
| ProviderTool<TArgs, TResult>
|
|
424
|
+
| McpTool
|
|
356
425
|
| ToolWithoutType<TArgs, TResult>;
|
|
357
426
|
|
|
358
427
|
/**
|
|
@@ -368,6 +437,8 @@ export type ToolDeclaration<
|
|
|
368
437
|
| FrontendTool<TArgs, TResult>
|
|
369
438
|
| BackendToolDeclaration<TArgs, TResult>
|
|
370
439
|
| HumanTool<TArgs, TResult>
|
|
440
|
+
| ProviderTool<TArgs, TResult>
|
|
441
|
+
| McpTool
|
|
371
442
|
| ToolWithoutType<TArgs, TResult>;
|
|
372
443
|
|
|
373
444
|
/**
|
|
@@ -380,4 +451,5 @@ export type ToolWithoutType<
|
|
|
380
451
|
| Omit<FrontendTool<TArgs, TResult>, "type">
|
|
381
452
|
| Omit<BackendTool<TArgs, TResult>, "type">
|
|
382
453
|
| Omit<HumanTool<TArgs, TResult>, "type">
|
|
454
|
+
| Omit<ProviderTool<TArgs, TResult>, "type">
|
|
383
455
|
) & { type?: undefined };
|