@ai-sdk/provider-utils 5.0.0-beta.9 → 5.0.0-canary.32

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 (105) hide show
  1. package/CHANGELOG.md +184 -0
  2. package/dist/index.d.ts +1346 -878
  3. package/dist/index.js +813 -325
  4. package/dist/index.js.map +1 -1
  5. package/dist/test/index.d.ts +2 -1
  6. package/dist/test/index.js +18 -37
  7. package/dist/test/index.js.map +1 -1
  8. package/package.json +13 -11
  9. package/src/add-additional-properties-to-json-schema.ts +1 -1
  10. package/src/as-array.ts +12 -0
  11. package/src/convert-image-model-file-to-data-uri.ts +1 -1
  12. package/src/convert-inline-file-data-to-uint8-array.ts +30 -0
  13. package/src/create-tool-name-mapping.ts +1 -1
  14. package/src/detect-media-type.ts +312 -0
  15. package/src/filter-nullable.ts +11 -0
  16. package/src/get-error-message.ts +1 -15
  17. package/src/get-from-api.ts +2 -2
  18. package/src/has-required-key.ts +6 -0
  19. package/src/index.ts +39 -14
  20. package/src/inject-json-instruction.ts +1 -1
  21. package/src/is-buffer.ts +9 -0
  22. package/src/is-json-serializable.ts +29 -0
  23. package/src/is-provider-reference.ts +21 -0
  24. package/src/is-url-supported.ts +17 -2
  25. package/src/load-api-key.ts +1 -1
  26. package/src/load-setting.ts +1 -1
  27. package/src/map-reasoning-to-provider.ts +4 -1
  28. package/src/maybe-promise-like.ts +3 -0
  29. package/src/parse-json-event-stream.ts +3 -3
  30. package/src/parse-json.ts +3 -3
  31. package/src/parse-provider-options.ts +1 -1
  32. package/src/post-to-api.ts +4 -4
  33. package/src/{provider-tool-factory.ts → provider-defined-tool-factory.ts} +22 -29
  34. package/src/provider-executed-tool-factory.ts +69 -0
  35. package/src/resolve-full-media-type.ts +49 -0
  36. package/src/resolve-provider-reference.ts +26 -0
  37. package/src/resolve.ts +16 -1
  38. package/src/response-handler.ts +3 -3
  39. package/src/schema.ts +6 -3
  40. package/src/secure-json-parse.ts +1 -1
  41. package/src/serialize-model-options.ts +63 -0
  42. package/src/streaming-tool-call-tracker.ts +241 -0
  43. package/src/test/convert-response-stream-to-array.ts +1 -1
  44. package/src/test/is-node-version.ts +22 -1
  45. package/src/to-json-schema/zod3-to-json-schema/options.ts +3 -3
  46. package/src/to-json-schema/zod3-to-json-schema/parse-def.ts +3 -3
  47. package/src/to-json-schema/zod3-to-json-schema/parse-types.ts +22 -22
  48. package/src/to-json-schema/zod3-to-json-schema/parsers/array.ts +3 -3
  49. package/src/to-json-schema/zod3-to-json-schema/parsers/bigint.ts +1 -1
  50. package/src/to-json-schema/zod3-to-json-schema/parsers/branded.ts +2 -2
  51. package/src/to-json-schema/zod3-to-json-schema/parsers/catch.ts +2 -2
  52. package/src/to-json-schema/zod3-to-json-schema/parsers/date.ts +4 -4
  53. package/src/to-json-schema/zod3-to-json-schema/parsers/default.ts +3 -3
  54. package/src/to-json-schema/zod3-to-json-schema/parsers/effects.ts +3 -3
  55. package/src/to-json-schema/zod3-to-json-schema/parsers/enum.ts +1 -1
  56. package/src/to-json-schema/zod3-to-json-schema/parsers/intersection.ts +5 -5
  57. package/src/to-json-schema/zod3-to-json-schema/parsers/literal.ts +1 -1
  58. package/src/to-json-schema/zod3-to-json-schema/parsers/map.ts +4 -5
  59. package/src/to-json-schema/zod3-to-json-schema/parsers/native-enum.ts +1 -1
  60. package/src/to-json-schema/zod3-to-json-schema/parsers/never.ts +1 -2
  61. package/src/to-json-schema/zod3-to-json-schema/parsers/nullable.ts +4 -4
  62. package/src/to-json-schema/zod3-to-json-schema/parsers/number.ts +1 -1
  63. package/src/to-json-schema/zod3-to-json-schema/parsers/object.ts +3 -3
  64. package/src/to-json-schema/zod3-to-json-schema/parsers/optional.ts +3 -3
  65. package/src/to-json-schema/zod3-to-json-schema/parsers/pipeline.ts +4 -4
  66. package/src/to-json-schema/zod3-to-json-schema/parsers/promise.ts +3 -3
  67. package/src/to-json-schema/zod3-to-json-schema/parsers/readonly.ts +2 -2
  68. package/src/to-json-schema/zod3-to-json-schema/parsers/record.ts +9 -10
  69. package/src/to-json-schema/zod3-to-json-schema/parsers/set.ts +3 -3
  70. package/src/to-json-schema/zod3-to-json-schema/parsers/string.ts +2 -2
  71. package/src/to-json-schema/zod3-to-json-schema/parsers/tuple.ts +3 -3
  72. package/src/to-json-schema/zod3-to-json-schema/parsers/undefined.ts +1 -2
  73. package/src/to-json-schema/zod3-to-json-schema/parsers/union.ts +3 -3
  74. package/src/to-json-schema/zod3-to-json-schema/parsers/unknown.ts +1 -2
  75. package/src/to-json-schema/zod3-to-json-schema/refs.ts +3 -3
  76. package/src/to-json-schema/zod3-to-json-schema/select-parser.ts +2 -2
  77. package/src/to-json-schema/zod3-to-json-schema/zod3-to-json-schema.ts +3 -3
  78. package/src/types/assistant-model-message.ts +3 -3
  79. package/src/types/content-part.ts +138 -19
  80. package/src/types/executable-tool.ts +17 -0
  81. package/src/types/execute-tool.ts +23 -23
  82. package/src/types/file-data.ts +48 -0
  83. package/src/types/index.ts +19 -3
  84. package/src/types/infer-tool-context.ts +7 -2
  85. package/src/types/infer-tool-set-context.ts +7 -9
  86. package/src/types/model-message.ts +4 -4
  87. package/src/types/never-optional.ts +7 -0
  88. package/src/types/provider-options.ts +1 -1
  89. package/src/types/provider-reference.ts +10 -0
  90. package/src/types/sensitive-context.ts +9 -0
  91. package/src/types/system-model-message.ts +1 -1
  92. package/src/types/tool-approval-request.ts +7 -0
  93. package/src/types/tool-execute-function.ts +50 -0
  94. package/src/types/tool-model-message.ts +3 -3
  95. package/src/types/tool-needs-approval-function.ts +39 -0
  96. package/src/types/tool.ts +236 -223
  97. package/src/types/user-model-message.ts +2 -2
  98. package/src/validate-types.ts +5 -3
  99. package/dist/index.d.mts +0 -1578
  100. package/dist/index.mjs +0 -2817
  101. package/dist/index.mjs.map +0 -1
  102. package/dist/test/index.d.mts +0 -17
  103. package/dist/test/index.mjs +0 -77
  104. package/dist/test/index.mjs.map +0 -1
  105. package/src/types/union-to-intersection.ts +0 -17
@@ -1,4 +1,4 @@
1
- import { SharedV4ProviderOptions } from '@ai-sdk/provider';
1
+ import type { SharedV4ProviderOptions } from '@ai-sdk/provider';
2
2
 
3
3
  /**
4
4
  * Additional provider-specific options.
@@ -0,0 +1,10 @@
1
+ import type { SharedV4ProviderReference } from '@ai-sdk/provider';
2
+
3
+ /**
4
+ * A mapping of provider names to provider-specific file identifiers.
5
+ *
6
+ * Provider references allow files to be identified across different
7
+ * providers without re-uploading, by storing each provider's own
8
+ * identifier for the same logical file.
9
+ */
10
+ export type ProviderReference = SharedV4ProviderReference;
@@ -0,0 +1,9 @@
1
+ import type { Context } from './context';
2
+
3
+ /**
4
+ * Top-level context properties that contain sensitive data and should be
5
+ * excluded from telemetry.
6
+ */
7
+ export type SensitiveContext<CONTEXT extends Context | unknown | never> =
8
+ | { [KEY in keyof CONTEXT]?: boolean }
9
+ | undefined;
@@ -1,4 +1,4 @@
1
- import { ProviderOptions } from './provider-options';
1
+ import type { ProviderOptions } from './provider-options';
2
2
 
3
3
  /**
4
4
  * A system message. It can contain system information.
@@ -13,4 +13,11 @@ export type ToolApprovalRequest = {
13
13
  * ID of the tool call that the approval request is for.
14
14
  */
15
15
  toolCallId: string;
16
+
17
+ /**
18
+ * Flag indicating whether the tool was automatically approved or denied.
19
+ *
20
+ * @default false
21
+ */
22
+ isAutomatic?: boolean;
16
23
  };
@@ -0,0 +1,50 @@
1
+ import type { Context } from './context';
2
+ import type { ModelMessage } from './model-message';
3
+
4
+ /**
5
+ * Additional options that are sent into each tool execution.
6
+ */
7
+ export interface ToolExecutionOptions<
8
+ CONTEXT extends Context | unknown | never,
9
+ > {
10
+ /**
11
+ * The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
12
+ */
13
+ toolCallId: string;
14
+
15
+ /**
16
+ * Messages that were sent to the language model to initiate the response that contained the tool call.
17
+ * The messages **do not** include the system prompt nor the assistant response that contained the tool call.
18
+ */
19
+ messages: ModelMessage[];
20
+
21
+ /**
22
+ * An optional abort signal that indicates that the overall operation should be aborted.
23
+ */
24
+ abortSignal?: AbortSignal;
25
+
26
+ /**
27
+ * Tool context as defined by the tool's context schema.
28
+ * The tool context is specific to the tool and is passed to the tool execution.
29
+ *
30
+ * Treat the context object as immutable inside tools.
31
+ * Mutating the context object can lead to race conditions and unexpected results
32
+ * when tools are called in parallel.
33
+ *
34
+ * If you need to mutate the context, analyze the tool calls and results
35
+ * in `prepareStep` and update it there.
36
+ */
37
+ context: CONTEXT;
38
+ }
39
+
40
+ /**
41
+ * Function that executes the tool and returns either a single result or a stream of results.
42
+ */
43
+ export type ToolExecuteFunction<
44
+ INPUT,
45
+ OUTPUT,
46
+ CONTEXT extends Context | unknown | never,
47
+ > = (
48
+ input: INPUT,
49
+ options: ToolExecutionOptions<CONTEXT>,
50
+ ) => AsyncIterable<OUTPUT> | PromiseLike<OUTPUT> | OUTPUT;
@@ -1,6 +1,6 @@
1
- import { ToolResultPart } from './content-part';
2
- import { ProviderOptions } from './provider-options';
3
- import { ToolApprovalResponse } from './tool-approval-response';
1
+ import type { ToolResultPart } from './content-part';
2
+ import type { ProviderOptions } from './provider-options';
3
+ import type { ToolApprovalResponse } from './tool-approval-response';
4
4
 
5
5
  /**
6
6
  * A tool message. It contains the result of one or more tool calls.
@@ -0,0 +1,39 @@
1
+ import type { Context } from './context';
2
+ import type { ModelMessage } from './model-message';
3
+
4
+ /**
5
+ * Function that is called to determine if the tool needs approval before it can be executed.
6
+ *
7
+ * @deprecated Tool approval is handled on a `generateText` / `streamText` level now.
8
+ */
9
+ export type ToolNeedsApprovalFunction<
10
+ INPUT,
11
+ CONTEXT extends Context | unknown | never,
12
+ > = (
13
+ input: INPUT,
14
+ options: {
15
+ /**
16
+ * The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
17
+ */
18
+ toolCallId: string;
19
+
20
+ /**
21
+ * Messages that were sent to the language model to initiate the response that contained the tool call.
22
+ * The messages **do not** include the system prompt nor the assistant response that contained the tool call.
23
+ */
24
+ messages: ModelMessage[];
25
+
26
+ /**
27
+ * Tool context as defined by the tool's context schema.
28
+ * The tool context is specific to the tool and is passed to the tool execution.
29
+ *
30
+ * Treat the context object as immutable inside tools.
31
+ * Mutating the context object can lead to race conditions and unexpected results
32
+ * when tools are called in parallel.
33
+ *
34
+ * If you need to mutate the context, analyze the tool calls and results
35
+ * in `prepareStep` and update it there.
36
+ */
37
+ context: CONTEXT;
38
+ },
39
+ ) => boolean | PromiseLike<boolean>;