@ai-sdk/provider-utils 5.0.15 → 5.0.16
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 +20 -1
- package/dist/index.js +27 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/is-record.ts +6 -0
- package/src/transcription-stream-envelope.ts +11 -14
- package/src/types/index.ts +6 -0
- package/src/types/tool-caller.ts +36 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -39,6 +39,7 @@ export { isBuffer } from './is-buffer';
|
|
|
39
39
|
export { isSameOrigin } from './is-same-origin';
|
|
40
40
|
export { isNonNullable } from './is-non-nullable';
|
|
41
41
|
export { isProviderReference } from './is-provider-reference';
|
|
42
|
+
export { isRecord } from './is-record';
|
|
42
43
|
export { isUrlSupported } from './is-url-supported';
|
|
43
44
|
export * from './load-api-key';
|
|
44
45
|
export { loadOptionalSetting } from './load-optional-setting';
|
package/src/is-record.ts
ADDED
|
@@ -2,6 +2,7 @@ import type {
|
|
|
2
2
|
Experimental_TranscriptionModelV4StreamPart as TranscriptionModelV4StreamPart,
|
|
3
3
|
JSONObject,
|
|
4
4
|
} from '@ai-sdk/provider';
|
|
5
|
+
import { isRecord } from './is-record';
|
|
5
6
|
import { secureJsonParse } from './secure-json-parse';
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -240,7 +241,7 @@ export function parseTranscriptionStreamPart(
|
|
|
240
241
|
case 'transcript-delta':
|
|
241
242
|
return isString(part.delta) &&
|
|
242
243
|
isOptional(part.id, isString) &&
|
|
243
|
-
isOptional(part.providerMetadata,
|
|
244
|
+
isOptional(part.providerMetadata, isRecord)
|
|
244
245
|
? part
|
|
245
246
|
: undefined;
|
|
246
247
|
|
|
@@ -250,7 +251,7 @@ export function parseTranscriptionStreamPart(
|
|
|
250
251
|
isOptional(part.startSecond, isNumber) &&
|
|
251
252
|
isOptional(part.durationInSeconds, isNumber) &&
|
|
252
253
|
isOptional(part.channelIndex, isNumber) &&
|
|
253
|
-
isOptional(part.providerMetadata,
|
|
254
|
+
isOptional(part.providerMetadata, isRecord)
|
|
254
255
|
? part
|
|
255
256
|
: undefined;
|
|
256
257
|
|
|
@@ -260,7 +261,7 @@ export function parseTranscriptionStreamPart(
|
|
|
260
261
|
isOptional(part.startSecond, isNumber) &&
|
|
261
262
|
isOptional(part.endSecond, isNumber) &&
|
|
262
263
|
isOptional(part.channelIndex, isNumber) &&
|
|
263
|
-
isOptional(part.providerMetadata,
|
|
264
|
+
isOptional(part.providerMetadata, isRecord)
|
|
264
265
|
? part
|
|
265
266
|
: undefined;
|
|
266
267
|
|
|
@@ -270,7 +271,7 @@ export function parseTranscriptionStreamPart(
|
|
|
270
271
|
part.segments.every(isSegment) &&
|
|
271
272
|
isOptional(part.language, isString) &&
|
|
272
273
|
isOptional(part.durationInSeconds, isNumber) &&
|
|
273
|
-
isOptional(part.providerMetadata,
|
|
274
|
+
isOptional(part.providerMetadata, isRecord)
|
|
274
275
|
? part
|
|
275
276
|
: undefined;
|
|
276
277
|
|
|
@@ -278,7 +279,7 @@ export function parseTranscriptionStreamPart(
|
|
|
278
279
|
if (
|
|
279
280
|
!(
|
|
280
281
|
isOptional(part.modelId, isString) &&
|
|
281
|
-
isOptional(part.headers,
|
|
282
|
+
isOptional(part.headers, isRecord)
|
|
282
283
|
)
|
|
283
284
|
) {
|
|
284
285
|
return undefined;
|
|
@@ -323,19 +324,15 @@ function isOptional(
|
|
|
323
324
|
return value === undefined || check(value);
|
|
324
325
|
}
|
|
325
326
|
|
|
326
|
-
function isPlainObject(value: unknown): boolean {
|
|
327
|
-
return typeof value === 'object' && value != null && !Array.isArray(value);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
327
|
function isWarning(value: unknown): boolean {
|
|
331
|
-
return
|
|
328
|
+
return isRecord(value) && isString(value.type);
|
|
332
329
|
}
|
|
333
330
|
|
|
334
331
|
function isSegment(value: unknown): boolean {
|
|
335
332
|
return (
|
|
336
|
-
|
|
337
|
-
isString(
|
|
338
|
-
isNumber(
|
|
339
|
-
isNumber(
|
|
333
|
+
isRecord(value) &&
|
|
334
|
+
isString(value.text) &&
|
|
335
|
+
isNumber(value.startSecond) &&
|
|
336
|
+
isNumber(value.endSecond)
|
|
340
337
|
);
|
|
341
338
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -48,6 +48,12 @@ export {
|
|
|
48
48
|
export type { ToolApprovalRequest } from './tool-approval-request';
|
|
49
49
|
export type { ToolApprovalResponse } from './tool-approval-response';
|
|
50
50
|
export type { ToolCall } from './tool-call';
|
|
51
|
+
export {
|
|
52
|
+
getToolCaller as experimental_getToolCaller,
|
|
53
|
+
toolCaller as experimental_toolCaller,
|
|
54
|
+
type ToolCallerDefinition as Experimental_ToolCallerDefinition,
|
|
55
|
+
type ToolCallerTool as Experimental_ToolCallerTool,
|
|
56
|
+
} from './tool-caller';
|
|
51
57
|
export type {
|
|
52
58
|
ToolExecuteFunction,
|
|
53
59
|
ToolExecutionOptions,
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ProviderOptions } from './provider-options';
|
|
2
|
+
import type { Tool } from './tool';
|
|
3
|
+
import type { ToolSet } from './tool-set';
|
|
4
|
+
|
|
5
|
+
const toolCallerSymbol = Symbol.for('vercel.ai.experimental.toolCaller');
|
|
6
|
+
|
|
7
|
+
export type ToolCallerDefinition =
|
|
8
|
+
| {
|
|
9
|
+
type: 'local';
|
|
10
|
+
bind: (tools: ToolSet) => Tool;
|
|
11
|
+
}
|
|
12
|
+
| {
|
|
13
|
+
type: 'provider';
|
|
14
|
+
prepareProviderOptions: (
|
|
15
|
+
providerOptions: ProviderOptions | undefined,
|
|
16
|
+
) => ProviderOptions;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type ToolCallerTool<TOOL extends Tool = Tool> = TOOL & {
|
|
20
|
+
readonly [toolCallerSymbol]: ToolCallerDefinition;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export function toolCaller<TOOL extends Tool>(
|
|
24
|
+
tool: TOOL,
|
|
25
|
+
definition: ToolCallerDefinition,
|
|
26
|
+
): ToolCallerTool<TOOL> {
|
|
27
|
+
return Object.defineProperty({ ...tool }, toolCallerSymbol, {
|
|
28
|
+
value: definition,
|
|
29
|
+
}) as ToolCallerTool<TOOL>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getToolCaller(
|
|
33
|
+
tool: Tool | undefined,
|
|
34
|
+
): ToolCallerDefinition | undefined {
|
|
35
|
+
return (tool as ToolCallerTool | undefined)?.[toolCallerSymbol];
|
|
36
|
+
}
|