@ai-sdk/provider-utils 5.0.0-beta.16 → 5.0.0-beta.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.
- package/CHANGELOG.md +12 -0
- package/dist/index.d.mts +14 -7
- package/dist/index.d.ts +14 -7
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/has-required-key.ts +6 -0
- package/src/index.ts +1 -0
- package/src/response-handler.ts +1 -1
- package/src/secure-json-parse.ts +1 -1
- package/src/to-json-schema/zod3-to-json-schema/parsers/date.ts +1 -1
- package/src/to-json-schema/zod3-to-json-schema/parsers/intersection.ts +1 -1
- package/src/to-json-schema/zod3-to-json-schema/parsers/record.ts +2 -2
- package/src/types/infer-tool-context.ts +7 -2
- package/src/types/tool.ts +14 -5
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -20,6 +20,7 @@ export { createIdGenerator, generateId, type IdGenerator } from './generate-id';
|
|
|
20
20
|
export * from './get-error-message';
|
|
21
21
|
export * from './get-from-api';
|
|
22
22
|
export { getRuntimeEnvironmentUserAgent } from './get-runtime-environment-user-agent';
|
|
23
|
+
export type { HasRequiredKey } from './has-required-key';
|
|
23
24
|
export { injectJsonInstructionIntoMessages } from './inject-json-instruction';
|
|
24
25
|
export * from './is-abort-error';
|
|
25
26
|
export { isNonNullable } from './is-non-nullable';
|
package/src/response-handler.ts
CHANGED
package/src/secure-json-parse.ts
CHANGED
|
@@ -83,7 +83,7 @@ export function secureJsonParse(text: string) {
|
|
|
83
83
|
try {
|
|
84
84
|
// Performance optimization, see https://github.com/fastify/secure-json-parse/pull/90
|
|
85
85
|
Error.stackTraceLimit = 0;
|
|
86
|
-
} catch
|
|
86
|
+
} catch {
|
|
87
87
|
// Fallback in case Error is immutable (v8 readonly)
|
|
88
88
|
return _parse(text);
|
|
89
89
|
}
|
|
@@ -42,7 +42,7 @@ export function parseIntersectionDef(
|
|
|
42
42
|
'additionalProperties' in schema &&
|
|
43
43
|
schema.additionalProperties === false
|
|
44
44
|
) {
|
|
45
|
-
const { additionalProperties, ...rest } = schema;
|
|
45
|
+
const { additionalProperties: _additionalProperties, ...rest } = schema;
|
|
46
46
|
nestedSchema = rest;
|
|
47
47
|
}
|
|
48
48
|
mergedAllOf.push(nestedSchema);
|
|
@@ -38,7 +38,7 @@ export function parseRecordDef(
|
|
|
38
38
|
def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodString &&
|
|
39
39
|
def.keyType._def.checks?.length
|
|
40
40
|
) {
|
|
41
|
-
const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
|
|
41
|
+
const { type: _type, ...keyType } = parseStringDef(def.keyType._def, refs);
|
|
42
42
|
|
|
43
43
|
return {
|
|
44
44
|
...schema,
|
|
@@ -56,7 +56,7 @@ export function parseRecordDef(
|
|
|
56
56
|
def.keyType._def.type._def.typeName === ZodFirstPartyTypeKind.ZodString &&
|
|
57
57
|
def.keyType._def.type._def.checks?.length
|
|
58
58
|
) {
|
|
59
|
-
const { type, ...keyType } = parseBrandedDef(
|
|
59
|
+
const { type: _type, ...keyType } = parseBrandedDef(
|
|
60
60
|
def.keyType._def,
|
|
61
61
|
refs,
|
|
62
62
|
) as JsonSchema7StringType;
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import { HasRequiredKey } from '../has-required-key';
|
|
1
2
|
import type { Tool } from './tool';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Infer the context type of a tool.
|
|
5
6
|
*/
|
|
6
|
-
export type InferToolContext<TOOL extends Tool
|
|
7
|
-
TOOL extends Tool<any, any, infer CONTEXT>
|
|
7
|
+
export type InferToolContext<TOOL extends Tool> =
|
|
8
|
+
TOOL extends Tool<any, any, infer CONTEXT>
|
|
9
|
+
? HasRequiredKey<CONTEXT> extends true
|
|
10
|
+
? CONTEXT
|
|
11
|
+
: never
|
|
12
|
+
: never;
|
package/src/types/tool.ts
CHANGED
|
@@ -8,7 +8,9 @@ import { Context } from './context';
|
|
|
8
8
|
/**
|
|
9
9
|
* Additional options that are sent into each tool execution.
|
|
10
10
|
*/
|
|
11
|
-
export interface ToolExecutionOptions<
|
|
11
|
+
export interface ToolExecutionOptions<
|
|
12
|
+
CONTEXT extends Context | unknown | never,
|
|
13
|
+
> {
|
|
12
14
|
/**
|
|
13
15
|
* The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
|
|
14
16
|
*/
|
|
@@ -41,7 +43,10 @@ export interface ToolExecutionOptions<CONTEXT extends Context> {
|
|
|
41
43
|
/**
|
|
42
44
|
* Function that is called to determine if the tool needs approval before it can be executed.
|
|
43
45
|
*/
|
|
44
|
-
export type ToolNeedsApprovalFunction<
|
|
46
|
+
export type ToolNeedsApprovalFunction<
|
|
47
|
+
INPUT,
|
|
48
|
+
CONTEXT extends Context | unknown | never,
|
|
49
|
+
> = (
|
|
45
50
|
input: INPUT,
|
|
46
51
|
options: {
|
|
47
52
|
/**
|
|
@@ -72,7 +77,11 @@ export type ToolNeedsApprovalFunction<INPUT, CONTEXT extends Context> = (
|
|
|
72
77
|
/**
|
|
73
78
|
* Function that executes the tool and returns either a single result or a stream of results.
|
|
74
79
|
*/
|
|
75
|
-
export type ToolExecuteFunction<
|
|
80
|
+
export type ToolExecuteFunction<
|
|
81
|
+
INPUT,
|
|
82
|
+
OUTPUT,
|
|
83
|
+
CONTEXT extends Context | unknown | never,
|
|
84
|
+
> = (
|
|
76
85
|
input: INPUT,
|
|
77
86
|
options: ToolExecutionOptions<CONTEXT>,
|
|
78
87
|
) => AsyncIterable<OUTPUT> | PromiseLike<OUTPUT> | OUTPUT;
|
|
@@ -91,7 +100,7 @@ type NeverOptional<N, T> = 0 extends 1 & N
|
|
|
91
100
|
type ToolOutputProperties<
|
|
92
101
|
INPUT,
|
|
93
102
|
OUTPUT,
|
|
94
|
-
CONTEXT extends Context,
|
|
103
|
+
CONTEXT extends Context | unknown | never,
|
|
95
104
|
> = NeverOptional<
|
|
96
105
|
OUTPUT,
|
|
97
106
|
| {
|
|
@@ -122,7 +131,7 @@ type ToolOutputProperties<
|
|
|
122
131
|
export type Tool<
|
|
123
132
|
INPUT extends JSONValue | unknown | never = any,
|
|
124
133
|
OUTPUT extends JSONValue | unknown | never = any,
|
|
125
|
-
CONTEXT extends Context =
|
|
134
|
+
CONTEXT extends Context | unknown | never = any,
|
|
126
135
|
> = {
|
|
127
136
|
/**
|
|
128
137
|
* An optional description of what the tool does.
|