@ai-sdk/provider-utils 5.0.0-beta.21 → 5.0.0-beta.23
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.ts +16 -21
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/as-array.ts +12 -0
- package/src/index.ts +2 -0
- package/src/types/infer-tool-set-context.ts +7 -9
- package/src/types/union-to-intersection.ts +0 -17
package/package.json
CHANGED
package/src/as-array.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A value that can be provided either as a single item, an array of items,
|
|
3
|
+
* or be left undefined.
|
|
4
|
+
*/
|
|
5
|
+
export type Arrayable<T> = T | T[] | undefined;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Normalizes a possibly undefined or non-array value into an array.
|
|
9
|
+
*/
|
|
10
|
+
export function asArray<T>(value: Arrayable<T>): T[] {
|
|
11
|
+
return value === undefined ? [] : Array.isArray(value) ? value : [value];
|
|
12
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { asArray } from './as-array';
|
|
2
|
+
export type { Arrayable } from './as-array';
|
|
1
3
|
export * from './combine-headers';
|
|
2
4
|
export { convertAsyncIteratorToReadableStream } from './convert-async-iterator-to-readable-stream';
|
|
3
5
|
export { convertImageModelFileToDataUri } from './convert-image-model-file-to-data-uri';
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import type { InferToolContext } from './infer-tool-context';
|
|
2
2
|
import type { ToolSet } from './tool-set';
|
|
3
|
-
import type { UnionToIntersection } from './union-to-intersection';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Infer the context type for a tool set.
|
|
7
6
|
*
|
|
8
|
-
* The inferred type
|
|
9
|
-
* tools in the set.
|
|
7
|
+
* The inferred type maps each tool name to its required context type.
|
|
10
8
|
*
|
|
11
|
-
*
|
|
9
|
+
* Tools without required context properties are omitted from the result.
|
|
12
10
|
*/
|
|
13
|
-
export type InferToolSetContext<TOOLS extends ToolSet> =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
export type InferToolSetContext<TOOLS extends ToolSet> = {
|
|
12
|
+
[K in keyof TOOLS as InferToolContext<NoInfer<TOOLS[K]>> extends never
|
|
13
|
+
? never
|
|
14
|
+
: K]: InferToolContext<NoInfer<TOOLS[K]>>;
|
|
15
|
+
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converts a union type `U` into an intersection type.
|
|
3
|
-
*
|
|
4
|
-
* For example:
|
|
5
|
-
* type A = { a: number };
|
|
6
|
-
* type B = { b: string };
|
|
7
|
-
* type Union = A | B;
|
|
8
|
-
* type Intersection = UnionToIntersection<Union>;
|
|
9
|
-
* // Intersection is: { a: number } & { b: string }
|
|
10
|
-
*
|
|
11
|
-
* This is useful when you have a union of object types and need a type with all possible properties.
|
|
12
|
-
*/
|
|
13
|
-
export type UnionToIntersection<U> = (
|
|
14
|
-
U extends unknown ? (arg: U) => void : never
|
|
15
|
-
) extends (arg: infer I) => void
|
|
16
|
-
? I
|
|
17
|
-
: never;
|