@ai-sdk/provider-utils 5.0.0-canary.40 → 5.0.0-canary.41
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 +7 -0
- package/dist/index.d.ts +43 -8
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/types/infer-tool-context.ts +33 -4
- package/src/types/infer-tool-set-context.ts +36 -7
- package/src/types/sandbox.ts +2 -2
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1293,9 +1293,9 @@ type Experimental_Sandbox = {
|
|
|
1293
1293
|
*/
|
|
1294
1294
|
readonly description: string;
|
|
1295
1295
|
/**
|
|
1296
|
-
*
|
|
1296
|
+
* Run a command in the sandbox.
|
|
1297
1297
|
*/
|
|
1298
|
-
readonly
|
|
1298
|
+
readonly runCommand: (options: {
|
|
1299
1299
|
/**
|
|
1300
1300
|
* Command to execute in the sandbox.
|
|
1301
1301
|
*/
|
|
@@ -1971,10 +1971,25 @@ type ExecutableTool<TOOL extends Tool = Tool> = TOOL & {
|
|
|
1971
1971
|
*/
|
|
1972
1972
|
declare function isExecutableTool<TOOL extends Tool>(tool: TOOL | undefined): tool is ExecutableTool<TOOL>;
|
|
1973
1973
|
|
|
1974
|
+
/**
|
|
1975
|
+
* Detects the `any` type so untyped tools can be treated as having no explicit
|
|
1976
|
+
* context type.
|
|
1977
|
+
*/
|
|
1978
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
1979
|
+
/**
|
|
1980
|
+
* Detects exact empty object contexts, including `{}` combined with
|
|
1981
|
+
* `undefined`, which do not provide tool-specific context properties.
|
|
1982
|
+
*/
|
|
1983
|
+
type IsEmptyObject<T> = keyof NonNullable<T> extends never ? true : false;
|
|
1984
|
+
/**
|
|
1985
|
+
* Detects context types that come from omitted or broad context declarations
|
|
1986
|
+
* rather than a concrete tool context schema.
|
|
1987
|
+
*/
|
|
1988
|
+
type IsUntypedContext<CONTEXT> = IsAny<CONTEXT> extends true ? true : unknown extends CONTEXT ? true : IsEmptyObject<CONTEXT> extends true ? true : string extends keyof CONTEXT ? CONTEXT extends Context ? true : false : false;
|
|
1974
1989
|
/**
|
|
1975
1990
|
* Infer the context type of a tool.
|
|
1976
1991
|
*/
|
|
1977
|
-
type InferToolContext<TOOL extends Tool> = TOOL extends Tool<any, any, infer CONTEXT> ?
|
|
1992
|
+
type InferToolContext<TOOL extends Tool> = TOOL extends Tool<any, any, infer CONTEXT> ? IsUntypedContext<CONTEXT> extends true ? never : CONTEXT : never;
|
|
1978
1993
|
|
|
1979
1994
|
/**
|
|
1980
1995
|
* Infer the input type of a tool.
|
|
@@ -2017,16 +2032,36 @@ declare function executeTool<TOOL extends Tool>({ tool, input, options, }: {
|
|
|
2017
2032
|
*/
|
|
2018
2033
|
type ToolSet = Record<string, (Tool<never, never, any> | Tool<any, any, any> | Tool<any, never, any> | Tool<never, any, any>) & Pick<Tool<any, any, any>, 'execute' | 'onInputAvailable' | 'onInputStart' | 'onInputDelta' | 'needsApproval'>>;
|
|
2019
2034
|
|
|
2035
|
+
/**
|
|
2036
|
+
* Builds the required portion of the tool context map for tools whose context
|
|
2037
|
+
* type does not include `undefined`.
|
|
2038
|
+
*/
|
|
2039
|
+
type RequiredToolSetContext<TOOLS extends ToolSet> = {
|
|
2040
|
+
[K in keyof TOOLS as InferToolContext<NoInfer<TOOLS[K]>> extends never ? never : undefined extends InferToolContext<NoInfer<TOOLS[K]>> ? never : K]: InferToolContext<NoInfer<TOOLS[K]>>;
|
|
2041
|
+
};
|
|
2042
|
+
/**
|
|
2043
|
+
* Builds the optional portion of the tool context map for tools whose context
|
|
2044
|
+
* object itself may be `undefined`.
|
|
2045
|
+
*/
|
|
2046
|
+
type OptionalToolSetContext<TOOLS extends ToolSet> = {
|
|
2047
|
+
[K in keyof TOOLS as InferToolContext<NoInfer<TOOLS[K]>> extends never ? never : undefined extends InferToolContext<NoInfer<TOOLS[K]>> ? K : never]?: InferToolContext<NoInfer<TOOLS[K]>>;
|
|
2048
|
+
};
|
|
2049
|
+
/**
|
|
2050
|
+
* Flattens intersected mapped types so type equality assertions and editor
|
|
2051
|
+
* hovers show the resulting object shape.
|
|
2052
|
+
*/
|
|
2053
|
+
type Normalize<OBJECT> = {
|
|
2054
|
+
[KEY in keyof OBJECT]: OBJECT[KEY];
|
|
2055
|
+
};
|
|
2020
2056
|
/**
|
|
2021
2057
|
* Infer the context type for a tool set.
|
|
2022
2058
|
*
|
|
2023
|
-
* The inferred type maps each tool name to its
|
|
2059
|
+
* The inferred type maps each contextual tool name to its context type.
|
|
2024
2060
|
*
|
|
2025
|
-
* Tools without
|
|
2061
|
+
* Tools without concrete context are omitted. Tool contexts that include
|
|
2062
|
+
* `undefined` are represented as optional properties.
|
|
2026
2063
|
*/
|
|
2027
|
-
type InferToolSetContext<TOOLS extends ToolSet> =
|
|
2028
|
-
[K in keyof TOOLS as InferToolContext<NoInfer<TOOLS[K]>> extends never ? never : K]: InferToolContext<NoInfer<TOOLS[K]>>;
|
|
2029
|
-
};
|
|
2064
|
+
type InferToolSetContext<TOOLS extends ToolSet> = Normalize<RequiredToolSetContext<TOOLS> & OptionalToolSetContext<TOOLS>>;
|
|
2030
2065
|
|
|
2031
2066
|
/**
|
|
2032
2067
|
* Typed tool call that is returned by generateText and streamText.
|
package/dist/index.js
CHANGED
|
@@ -862,7 +862,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
862
862
|
}
|
|
863
863
|
|
|
864
864
|
// src/version.ts
|
|
865
|
-
var VERSION = true ? "5.0.0-canary.
|
|
865
|
+
var VERSION = true ? "5.0.0-canary.41" : "0.0.0-test";
|
|
866
866
|
|
|
867
867
|
// src/get-from-api.ts
|
|
868
868
|
var getOriginalFetch = () => globalThis.fetch;
|
package/package.json
CHANGED
|
@@ -1,12 +1,41 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Context } from './context';
|
|
2
2
|
import type { Tool } from './tool';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Detects the `any` type so untyped tools can be treated as having no explicit
|
|
6
|
+
* context type.
|
|
7
|
+
*/
|
|
8
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Detects exact empty object contexts, including `{}` combined with
|
|
12
|
+
* `undefined`, which do not provide tool-specific context properties.
|
|
13
|
+
*/
|
|
14
|
+
type IsEmptyObject<T> = keyof NonNullable<T> extends never ? true : false;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Detects context types that come from omitted or broad context declarations
|
|
18
|
+
* rather than a concrete tool context schema.
|
|
19
|
+
*/
|
|
20
|
+
type IsUntypedContext<CONTEXT> =
|
|
21
|
+
IsAny<CONTEXT> extends true
|
|
22
|
+
? true
|
|
23
|
+
: unknown extends CONTEXT
|
|
24
|
+
? true
|
|
25
|
+
: IsEmptyObject<CONTEXT> extends true
|
|
26
|
+
? true
|
|
27
|
+
: string extends keyof CONTEXT
|
|
28
|
+
? CONTEXT extends Context
|
|
29
|
+
? true
|
|
30
|
+
: false
|
|
31
|
+
: false;
|
|
32
|
+
|
|
4
33
|
/**
|
|
5
34
|
* Infer the context type of a tool.
|
|
6
35
|
*/
|
|
7
36
|
export type InferToolContext<TOOL extends Tool> =
|
|
8
37
|
TOOL extends Tool<any, any, infer CONTEXT>
|
|
9
|
-
?
|
|
10
|
-
?
|
|
11
|
-
:
|
|
38
|
+
? IsUntypedContext<CONTEXT> extends true
|
|
39
|
+
? never
|
|
40
|
+
: CONTEXT
|
|
12
41
|
: never;
|
|
@@ -2,14 +2,43 @@ import type { InferToolContext } from './infer-tool-context';
|
|
|
2
2
|
import type { ToolSet } from './tool-set';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
* Builds the required portion of the tool context map for tools whose context
|
|
6
|
+
* type does not include `undefined`.
|
|
7
|
+
*/
|
|
8
|
+
type RequiredToolSetContext<TOOLS extends ToolSet> = {
|
|
9
|
+
[K in keyof TOOLS as InferToolContext<NoInfer<TOOLS[K]>> extends never
|
|
10
|
+
? never
|
|
11
|
+
: undefined extends InferToolContext<NoInfer<TOOLS[K]>>
|
|
12
|
+
? never
|
|
13
|
+
: K]: InferToolContext<NoInfer<TOOLS[K]>>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Builds the optional portion of the tool context map for tools whose context
|
|
18
|
+
* object itself may be `undefined`.
|
|
10
19
|
*/
|
|
11
|
-
|
|
20
|
+
type OptionalToolSetContext<TOOLS extends ToolSet> = {
|
|
12
21
|
[K in keyof TOOLS as InferToolContext<NoInfer<TOOLS[K]>> extends never
|
|
13
22
|
? never
|
|
14
|
-
:
|
|
23
|
+
: undefined extends InferToolContext<NoInfer<TOOLS[K]>>
|
|
24
|
+
? K
|
|
25
|
+
: never]?: InferToolContext<NoInfer<TOOLS[K]>>;
|
|
15
26
|
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Flattens intersected mapped types so type equality assertions and editor
|
|
30
|
+
* hovers show the resulting object shape.
|
|
31
|
+
*/
|
|
32
|
+
type Normalize<OBJECT> = { [KEY in keyof OBJECT]: OBJECT[KEY] };
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Infer the context type for a tool set.
|
|
36
|
+
*
|
|
37
|
+
* The inferred type maps each contextual tool name to its context type.
|
|
38
|
+
*
|
|
39
|
+
* Tools without concrete context are omitted. Tool contexts that include
|
|
40
|
+
* `undefined` are represented as optional properties.
|
|
41
|
+
*/
|
|
42
|
+
export type InferToolSetContext<TOOLS extends ToolSet> = Normalize<
|
|
43
|
+
RequiredToolSetContext<TOOLS> & OptionalToolSetContext<TOOLS>
|
|
44
|
+
>;
|
package/src/types/sandbox.ts
CHANGED
|
@@ -10,9 +10,9 @@ export type Experimental_Sandbox = {
|
|
|
10
10
|
readonly description: string;
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Run a command in the sandbox.
|
|
14
14
|
*/
|
|
15
|
-
readonly
|
|
15
|
+
readonly runCommand: (options: {
|
|
16
16
|
/**
|
|
17
17
|
* Command to execute in the sandbox.
|
|
18
18
|
*/
|