assistant-stream 0.3.16 → 0.3.18

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.
Files changed (38) hide show
  1. package/dist/core/accumulators/AssistantMessageStream.d.ts.map +1 -1
  2. package/dist/core/accumulators/TimingTracker.d.ts.map +1 -1
  3. package/dist/core/modules/assistant-stream.d.ts.map +1 -1
  4. package/dist/core/modules/assistant-stream.js +6 -4
  5. package/dist/core/modules/assistant-stream.js.map +1 -1
  6. package/dist/core/object/ObjectStreamAccumulator.d.ts.map +1 -1
  7. package/dist/core/object/ObjectStreamResponse.js.map +1 -1
  8. package/dist/core/serialization/data-stream/DataStream.js.map +1 -1
  9. package/dist/core/serialization/ui-message-stream/UIMessageStream.js.map +1 -1
  10. package/dist/core/tool/ToolCallReader.d.ts +1 -1
  11. package/dist/core/tool/ToolCallReader.d.ts.map +1 -1
  12. package/dist/core/tool/ToolCallReader.js.map +1 -1
  13. package/dist/core/tool/ToolResponse.d.ts.map +1 -1
  14. package/dist/core/tool/ToolResponse.js.map +1 -1
  15. package/dist/core/tool/schema-utils.d.ts +7 -1
  16. package/dist/core/tool/schema-utils.d.ts.map +1 -1
  17. package/dist/core/tool/schema-utils.js +8 -2
  18. package/dist/core/tool/schema-utils.js.map +1 -1
  19. package/dist/core/tool/tool-types.d.ts +68 -3
  20. package/dist/core/tool/tool-types.d.ts.map +1 -1
  21. package/dist/core/utils/Counter.d.ts.map +1 -1
  22. package/dist/core/utils/withPromiseOrValue.d.ts.map +1 -1
  23. package/dist/index.d.ts +2 -2
  24. package/dist/node_modules/.pnpm/@types_json-schema@7.0.15/node_modules/@types/json-schema/index.d.ts.map +1 -1
  25. package/dist/utils/AsyncIterableStream.d.ts.map +1 -1
  26. package/package.json +4 -4
  27. package/src/core/modules/assistant-stream.test.ts +104 -0
  28. package/src/core/modules/assistant-stream.ts +13 -4
  29. package/src/core/object/ObjectStreamResponse.ts +4 -4
  30. package/src/core/serialization/data-stream/DataStream.ts +0 -1
  31. package/src/core/serialization/ui-message-stream/UIMessageStream.ts +0 -1
  32. package/src/core/tool/ToolCallReader.ts +8 -9
  33. package/src/core/tool/ToolResponse.ts +1 -0
  34. package/src/core/tool/schema-utils.test.ts +56 -0
  35. package/src/core/tool/schema-utils.ts +11 -1
  36. package/src/core/tool/tool-types.ts +89 -1
  37. package/src/index.ts +2 -1
  38. package/src/resumable/index.ts +1 -4
@@ -98,7 +98,7 @@ export interface ToolCallArgsReader<TArgs extends Record<string, unknown>> {
98
98
  */
99
99
  streamText<PathT extends TypePath<TArgs>>(
100
100
  ...fieldPath: PathT
101
- ): TypeAtPath<TArgs, PathT> extends string & infer U
101
+ ): TypeAtPath<TArgs, PathT> extends string & (infer U)
102
102
  ? AsyncIterableStream<U>
103
103
  : never;
104
104
 
@@ -168,6 +168,35 @@ type OnSchemaValidationErrorFunction<TResult> = ToolExecuteFunction<
168
168
  TResult
169
169
  >;
170
170
 
171
+ /**
172
+ * Per-provider metadata forwarded into the wire request body verbatim.
173
+ * assistant-ui does not interpret these values; downstream adapters (AI SDK,
174
+ * custom routes) pass them to the model provider as-is.
175
+ *
176
+ * The outer key is the provider name (`anthropic`, `openai`, ...); the inner
177
+ * object is whatever shape that provider's SDK expects under
178
+ * `tool.providerOptions[providerName]`. Use this to enable provider-specific
179
+ * tool behaviors such as Anthropic's `defer_loading`
180
+ * (`{ anthropic: { deferLoading: true } }`) without adding provider-aware
181
+ * code in assistant-ui.
182
+ */
183
+ export type ProviderOptions = Record<string, Record<string, unknown>>;
184
+
185
+ /**
186
+ * Controls how a tool call's UI is presented relative to the assistant's
187
+ * chain-of-thought trace.
188
+ *
189
+ * - `"inline"` — the tool call is part of the reasoning trace and is folded
190
+ * into the chain-of-thought grouping alongside other routine tool calls.
191
+ * - `"standalone"` — the tool call is surfaced on its own, outside the
192
+ * chain-of-thought grouping (e.g. a human-in-the-loop prompt, a generative
193
+ * UI surface, or an important action UI worth showing prominently).
194
+ *
195
+ * This is a client-side presentation hint only; it does not affect how the
196
+ * tool is exposed to or executed by the model.
197
+ */
198
+ type ToolDisplay = "standalone" | "inline";
199
+
171
200
  type ToolBase<
172
201
  TArgs extends Record<string, unknown> = Record<string, unknown>,
173
202
  TResult = unknown,
@@ -176,6 +205,17 @@ type ToolBase<
176
205
  * @deprecated Experimental, API may change.
177
206
  */
178
207
  streamCall?: ToolStreamCallFunction<TArgs, TResult>;
208
+
209
+ /**
210
+ * How this tool's UI is presented relative to the chain-of-thought trace.
211
+ *
212
+ * Defaults to `"inline"` (folded into the chain-of-thought grouping).
213
+ * Set `"standalone"` to surface the tool call on its own. `human` tools are
214
+ * always `"standalone"` and cannot opt out.
215
+ *
216
+ * @see ToolDisplay
217
+ */
218
+ display?: ToolDisplay;
179
219
  };
180
220
 
181
221
  type BackendTool<
@@ -191,6 +231,35 @@ type BackendTool<
191
231
  execute?: undefined;
192
232
  toModelOutput?: undefined;
193
233
  experimental_onSchemaValidationError?: undefined;
234
+ providerOptions?: undefined;
235
+ };
236
+
237
+ /**
238
+ * Backend tool as *authored* (a {@link ToolDeclaration}), before the build
239
+ * splits it: it may declare a `description`, `parameters`, and a server-side
240
+ * `execute`. The canonical {@link BackendTool} keeps these `undefined` because,
241
+ * once split, the client never sees them and the server consumes them through a
242
+ * server adapter rather than the shared {@link Tool} shape.
243
+ */
244
+ type BackendToolDeclaration<
245
+ TArgs extends Record<string, unknown> = Record<string, unknown>,
246
+ TResult = unknown,
247
+ > = ToolBase<TArgs, TResult> & {
248
+ type: "backend";
249
+
250
+ /** Natural-language description shown to the model when selecting tools. */
251
+ description?: string | undefined;
252
+ /** Schema for the arguments the model must provide when calling the tool. */
253
+ parameters?: StandardSchemaV1<TArgs> | JSONSchema7 | undefined;
254
+ /** Prevents the tool from being exposed to the model while true. */
255
+ disabled?: boolean;
256
+ /** Executes the tool on the server after the model provides valid arguments. */
257
+ execute?: ToolExecuteFunction<TArgs, TResult>;
258
+ /** Converts the execution result into model-visible output. */
259
+ toModelOutput?: ToolModelOutputFunction<TArgs, TResult>;
260
+ /** Handles invalid tool arguments when schema validation fails. */
261
+ experimental_onSchemaValidationError?: OnSchemaValidationErrorFunction<TResult>;
262
+ providerOptions?: ProviderOptions;
194
263
  };
195
264
 
196
265
  type FrontendTool<
@@ -212,6 +281,7 @@ type FrontendTool<
212
281
  toModelOutput?: ToolModelOutputFunction<TArgs, TResult>;
213
282
  /** Handles invalid tool arguments when schema validation fails. */
214
283
  experimental_onSchemaValidationError?: OnSchemaValidationErrorFunction<TResult>;
284
+ providerOptions?: ProviderOptions;
215
285
  };
216
286
 
217
287
  type HumanTool<
@@ -227,9 +297,12 @@ type HumanTool<
227
297
  parameters: StandardSchemaV1<TArgs> | JSONSchema7;
228
298
  /** Prevents the tool from being exposed to the model while true. */
229
299
  disabled?: boolean;
300
+ /** Human tools are always surfaced standalone and cannot opt out. */
301
+ display?: "standalone";
230
302
  execute?: undefined;
231
303
  toModelOutput?: undefined;
232
304
  experimental_onSchemaValidationError?: undefined;
305
+ providerOptions?: ProviderOptions;
233
306
  };
234
307
 
235
308
  /**
@@ -282,6 +355,21 @@ export type Tool<
282
355
  | HumanTool<TArgs, TResult>
283
356
  | ToolWithoutType<TArgs, TResult>;
284
357
 
358
+ /**
359
+ * A tool as *authored* — the permissive counterpart to {@link Tool}. Unlike
360
+ * {@link Tool}, a `backend` entry may declare `description`, `parameters`, and a
361
+ * server-side `execute`. Use this for the input of authoring helpers (e.g.
362
+ * `defineToolkit`); the canonical {@link Tool} is the output.
363
+ */
364
+ export type ToolDeclaration<
365
+ TArgs extends Record<string, unknown> = Record<string, unknown>,
366
+ TResult = unknown,
367
+ > =
368
+ | FrontendTool<TArgs, TResult>
369
+ | BackendToolDeclaration<TArgs, TResult>
370
+ | HumanTool<TArgs, TResult>
371
+ | ToolWithoutType<TArgs, TResult>;
372
+
285
373
  /**
286
374
  * @deprecated Use {@link Tool} with an explicit `type` field instead.
287
375
  */
package/src/index.ts CHANGED
@@ -37,12 +37,13 @@ export type {
37
37
 
38
38
  export type {
39
39
  Tool,
40
+ ToolDeclaration,
40
41
  ToolModelContentPart,
41
42
  ToolModelOutputFunction,
42
43
  } from "./core/tool/tool-types";
43
44
  export { ToolResponse, type ToolResponseLike } from "./core/tool/ToolResponse";
44
45
  export { ToolExecutionStream } from "./core/tool/ToolExecutionStream";
45
- export type { ToolCallReader } from "./core/tool/tool-types";
46
+ export type { ProviderOptions, ToolCallReader } from "./core/tool/tool-types";
46
47
  export {
47
48
  toolResultStream as unstable_toolResultStream,
48
49
  unstable_runPendingTools,
@@ -6,10 +6,7 @@ export type {
6
6
  ResumableStreamAcquireOptions,
7
7
  } from "./types";
8
8
 
9
- export {
10
- ResumableStreamError,
11
- type ResumableStreamErrorCode,
12
- } from "./errors";
9
+ export { ResumableStreamError, type ResumableStreamErrorCode } from "./errors";
13
10
 
14
11
  export {
15
12
  createResumableStreamContext,