ai 7.0.177 → 7.0.179
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 +33 -0
- package/dist/default-stop-condition-wtuJTiTo.js +4213 -0
- package/dist/default-stop-condition-wtuJTiTo.js.map +1 -0
- package/dist/index-CM_8u8gB.d.ts +12107 -0
- package/dist/index-CM_8u8gB.d.ts.map +1 -0
- package/dist/index.d.ts +3 -11788
- package/dist/index.js +680 -4732
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +4 -3301
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +2 -3819
- package/dist/simulate-readable-stream-Bi5kQKbv.js +25 -0
- package/dist/simulate-readable-stream-Bi5kQKbv.js.map +1 -0
- package/dist/simulate-readable-stream-BuwR4IbD.d.ts +21 -0
- package/dist/simulate-readable-stream-BuwR4IbD.d.ts.map +1 -0
- package/dist/test/index.d.ts +2 -20
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/index.js +3 -23
- package/dist/test/index.js.map +1 -1
- package/docs/02-foundations/02-providers-and-models.mdx +1 -0
- package/docs/03-agents/06-policy-tool-approvals.mdx +27 -2
- package/docs/03-agents/06-tool-approvals.mdx +2 -1
- package/docs/03-ai-sdk-core/18-tools.mdx +7 -2
- package/docs/03-ai-sdk-core/33-extractions.mdx +21 -4
- package/docs/03-ai-sdk-core/36-realtime.mdx +3 -1
- package/docs/03-ai-sdk-core/36-transcription.mdx +2 -2
- package/docs/03-ai-sdk-core/37-speech.mdx +1 -0
- package/docs/03-ai-sdk-core/60-telemetry.mdx +52 -4
- package/docs/03-ai-sdk-core/65-lifecycle-callbacks.mdx +124 -2
- package/docs/07-reference/01-ai-sdk-core/14-extract.mdx +13 -4
- package/docs/07-reference/02-ai-sdk-ui/05-use-realtime.mdx +6 -2
- package/docs/07-reference/05-ai-sdk-errors/ai-extraction-refusal-error.mdx +33 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-extraction-unsupported-field-type-error.mdx +36 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-invalid-tool-approval-signature-error.mdx +1 -0
- package/package.json +13 -13
- package/src/agent/tool-loop-agent-settings.ts +2 -1
- package/src/extract/extract-events.ts +135 -0
- package/src/extract/extract.ts +177 -74
- package/src/extract/index.ts +6 -0
- package/src/extract/restricted-telemetry-dispatcher.ts +97 -0
- package/src/generate-text/execute-tools-from-stream.ts +14 -8
- package/src/generate-text/generate-text.ts +26 -10
- package/src/generate-text/stream-language-model-call.ts +3 -0
- package/src/generate-text/stream-text.ts +11 -2
- package/src/realtime/browser-realtime-live-websocket.ts +23 -5
- package/src/realtime/realtime-session.ts +68 -29
- package/src/telemetry/create-telemetry-dispatcher.ts +12 -0
- package/src/telemetry/filter-telemetry-event.ts +2 -0
- package/src/telemetry/redact-telemetry-credentials.ts +13 -1
- package/src/telemetry/telemetry.ts +34 -0
- package/src/telemetry/tracing-channel.ts +2 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/internal/index.js.map +0 -1
|
@@ -79,6 +79,8 @@ and Node.js `ai:telemetry` subscribers. Raw provider bodies and provider metadat
|
|
|
79
79
|
are omitted when either recording option is disabled. Raw tracing span results
|
|
80
80
|
are also omitted in that case because they can contain both inputs and outputs.
|
|
81
81
|
Tracing span errors use a generic failure message.
|
|
82
|
+
File download errors are always sent with the file URL redacted, because the URL
|
|
83
|
+
can be a signed link to a private file.
|
|
82
84
|
Application lifecycle callbacks and returned results retain their full content.
|
|
83
85
|
|
|
84
86
|
OpenAI Code Interpreter and shell domain secrets, and MCP authorization and
|
|
@@ -557,6 +559,29 @@ integration.
|
|
|
557
559
|
type: '(event: Experimental_DecideEndEvent) => void | PromiseLike<void>',
|
|
558
560
|
description: 'Called when an experimental decision operation completes.',
|
|
559
561
|
},
|
|
562
|
+
{
|
|
563
|
+
name: 'experimental_onExtractStart',
|
|
564
|
+
type: '(event: Experimental_ExtractStartEvent) => void | PromiseLike<void>',
|
|
565
|
+
description: 'Called when an experimental extraction operation begins.',
|
|
566
|
+
},
|
|
567
|
+
{
|
|
568
|
+
name: 'experimental_onExtractionModelCallStart',
|
|
569
|
+
type: '(event: Experimental_ExtractionModelCallStartEvent) => void | PromiseLike<void>',
|
|
570
|
+
description:
|
|
571
|
+
'Called when the logical extraction model call begins. The call includes any provider retries.',
|
|
572
|
+
},
|
|
573
|
+
{
|
|
574
|
+
name: 'experimental_onExtractionModelCallEnd',
|
|
575
|
+
type: '(event: Experimental_ExtractionModelCallEndEvent) => void | PromiseLike<void>',
|
|
576
|
+
description:
|
|
577
|
+
'Called when the logical extraction model call, including any retries, completes.',
|
|
578
|
+
},
|
|
579
|
+
{
|
|
580
|
+
name: 'experimental_onExtractEnd',
|
|
581
|
+
type: '(event: Experimental_ExtractEndEvent) => void | PromiseLike<void>',
|
|
582
|
+
description:
|
|
583
|
+
'Called when an experimental extraction operation completes.',
|
|
584
|
+
},
|
|
560
585
|
{
|
|
561
586
|
name: 'onEnd',
|
|
562
587
|
type: '(event: GenerateTextEndEvent) => void | PromiseLike<void>',
|
|
@@ -578,8 +603,8 @@ integration.
|
|
|
578
603
|
]}
|
|
579
604
|
/>
|
|
580
605
|
|
|
581
|
-
Experimental decision events use the
|
|
582
|
-
They are not included in the stable `onStart` and `onEnd` event unions.
|
|
606
|
+
Experimental decision and extraction events use the `experimental_*` callbacks
|
|
607
|
+
above. They are not included in the stable `onStart` and `onEnd` event unions.
|
|
583
608
|
|
|
584
609
|
The event types for each method are the same as the corresponding [lifecycle callbacks](/docs/ai-sdk-core/lifecycle-callbacks). See the lifecycle callbacks documentation for the full property reference of each event.
|
|
585
610
|
|
|
@@ -789,6 +814,27 @@ semantic-convention attributes. Enable the `experimental_decision`
|
|
|
789
814
|
supplemental option to record them under AI SDK-specific
|
|
790
815
|
`ai.decision.*` attributes.
|
|
791
816
|
|
|
817
|
+
#### experimental_extract
|
|
818
|
+
|
|
819
|
+
For `experimental_extract`, the integration records two spans with `CLIENT`
|
|
820
|
+
kind: an **`extract {modelId}`** root span for the whole operation and one
|
|
821
|
+
**`extract {modelId}`** child span for extraction model work, including
|
|
822
|
+
retries. Both include the provider and requested model with
|
|
823
|
+
`gen_ai.operation.name: "extract"`. Token usage is recorded on the child span.
|
|
824
|
+
When extraction attributes are enabled, answers are recorded on both spans so
|
|
825
|
+
the operation span contains its output.
|
|
826
|
+
|
|
827
|
+
`extract` is an AI SDK-defined custom operation name, like `decide`.
|
|
828
|
+
Extraction state, fields, reference date, and answers do not have applicable
|
|
829
|
+
GenAI semantic-convention attributes. Enable the `experimental_extraction`
|
|
830
|
+
supplemental option to record them under AI SDK-specific `ai.extraction.*`
|
|
831
|
+
attributes. Request headers and provider options can contain credentials, so
|
|
832
|
+
they are not sent to telemetry integrations or `ai:telemetry` subscribers for
|
|
833
|
+
extraction, and extraction spans do not record request headers. File URLs and
|
|
834
|
+
provider file references in extraction state are replaced with `[redacted]`,
|
|
835
|
+
and extraction spans do not record provider metadata, which can contain document
|
|
836
|
+
content such as OCR text.
|
|
837
|
+
|
|
792
838
|
#### GenAI span details
|
|
793
839
|
|
|
794
840
|
##### GenAI message format
|
|
@@ -844,10 +890,10 @@ registerTelemetry(
|
|
|
844
890
|
|
|
845
891
|
The callback runs when each span is created and receives:
|
|
846
892
|
|
|
847
|
-
- `spanType`: the type of span being created (`operation`, `step`, `languageModel`, `tool`, `embedding`, `reranking`, or `
|
|
893
|
+
- `spanType`: the type of span being created (`operation`, `step`, `languageModel`, `tool`, `embedding`, `reranking`, `experimental_decision`, or `experimental_extraction`).
|
|
848
894
|
- `operationId`: the AI SDK operation ID for the current call, such as `ai.generateText` or `ai.streamText`.
|
|
849
895
|
- `callId`: the unique ID for the current AI SDK call.
|
|
850
|
-
- `runtimeContext`: the telemetry-filtered runtime context for text generation, embedding, reranking, and
|
|
896
|
+
- `runtimeContext`: the telemetry-filtered runtime context for text generation, embedding, reranking, decision, and extraction spans. Text generation spans also reflect updates from `prepareStep`.
|
|
851
897
|
|
|
852
898
|
Custom attributes are merged with AI SDK attributes on the span. AI SDK-owned
|
|
853
899
|
attributes take precedence when a custom attribute uses the same key.
|
|
@@ -908,6 +954,7 @@ registerTelemetry(
|
|
|
908
954
|
embedding: true,
|
|
909
955
|
reranking: true,
|
|
910
956
|
experimental_decision: true,
|
|
957
|
+
experimental_extraction: true,
|
|
911
958
|
runtimeContext: true,
|
|
912
959
|
headers: true,
|
|
913
960
|
toolChoice: true,
|
|
@@ -923,6 +970,7 @@ The available options are:
|
|
|
923
970
|
- `embedding`: embedding inputs and outputs.
|
|
924
971
|
- `reranking`: rerank input documents and ranking output.
|
|
925
972
|
- `experimental_decision`: experimental decision state, questions, and answers.
|
|
973
|
+
- `experimental_extraction`: experimental extraction state, fields, reference date, and answers.
|
|
926
974
|
- `runtimeContext`: `ai.settings.context.*`.
|
|
927
975
|
- `headers`: `ai.request.headers.*`.
|
|
928
976
|
- `toolChoice`: `ai.prompt.toolChoice`.
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: Lifecycle Callbacks
|
|
3
|
-
description: Observe AI SDK lifecycle events in generateText, streamText, embed, embedMany, rerank, and
|
|
3
|
+
description: Observe AI SDK lifecycle events in generateText, streamText, embed, embedMany, rerank, experimental_decide, and experimental_extract calls
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Lifecycle Callbacks
|
|
7
7
|
|
|
8
8
|
Event callbacks let you run your own code at important points in an AI SDK call.
|
|
9
|
-
You can attach them directly to `generateText`, `streamText`, `embed`, `embedMany`, `rerank`, and `
|
|
9
|
+
You can attach them directly to `generateText`, `streamText`, `embed`, `embedMany`, `rerank`, `experimental_decide`, and `experimental_extract` calls to observe what happened, record usage, debug multi-step generations, and monitor tool execution.
|
|
10
10
|
|
|
11
11
|
They are especially useful when you want application-specific logic close to the call site:
|
|
12
12
|
|
|
@@ -480,6 +480,25 @@ const result = await generateText({
|
|
|
480
480
|
]}
|
|
481
481
|
/>
|
|
482
482
|
|
|
483
|
+
### `experimental_extract`
|
|
484
|
+
|
|
485
|
+
<PropertiesTable
|
|
486
|
+
content={[
|
|
487
|
+
{
|
|
488
|
+
name: 'onStart',
|
|
489
|
+
type: '(event: Experimental_ExtractStartEvent) => void | Promise<void>',
|
|
490
|
+
description:
|
|
491
|
+
'Called when the extraction operation begins, before the extraction model is called.',
|
|
492
|
+
},
|
|
493
|
+
{
|
|
494
|
+
name: 'onEnd',
|
|
495
|
+
type: '(event: Experimental_ExtractEndEvent) => void | Promise<void>',
|
|
496
|
+
description:
|
|
497
|
+
'Called when the extraction operation completes successfully.',
|
|
498
|
+
},
|
|
499
|
+
]}
|
|
500
|
+
/>
|
|
501
|
+
|
|
483
502
|
## Event Data Reference
|
|
484
503
|
|
|
485
504
|
The exact event data depends on the callback. The tables below summarize the fields you will most commonly use.
|
|
@@ -1285,3 +1304,106 @@ Includes every `onStart` field plus:
|
|
|
1285
1304
|
},
|
|
1286
1305
|
]}
|
|
1287
1306
|
/>
|
|
1307
|
+
|
|
1308
|
+
### Extraction Events
|
|
1309
|
+
|
|
1310
|
+
Extraction callbacks are experimental. Their exported types are
|
|
1311
|
+
`Experimental_ExtractStartEvent` and `Experimental_ExtractEndEvent`.
|
|
1312
|
+
|
|
1313
|
+
#### onStart
|
|
1314
|
+
|
|
1315
|
+
<PropertiesTable
|
|
1316
|
+
content={[
|
|
1317
|
+
{
|
|
1318
|
+
name: 'callId',
|
|
1319
|
+
type: 'string',
|
|
1320
|
+
description: 'Unique identifier for this extraction call.',
|
|
1321
|
+
},
|
|
1322
|
+
{
|
|
1323
|
+
name: 'operationId',
|
|
1324
|
+
type: "'ai.extract'",
|
|
1325
|
+
description: 'Extraction operation identifier.',
|
|
1326
|
+
},
|
|
1327
|
+
{
|
|
1328
|
+
name: 'runtimeContext',
|
|
1329
|
+
type: 'RUNTIME_CONTEXT',
|
|
1330
|
+
description: 'Full user-defined runtime context.',
|
|
1331
|
+
},
|
|
1332
|
+
{
|
|
1333
|
+
name: 'provider',
|
|
1334
|
+
type: 'string',
|
|
1335
|
+
description: 'Provider identifier for the extraction model.',
|
|
1336
|
+
},
|
|
1337
|
+
{
|
|
1338
|
+
name: 'modelId',
|
|
1339
|
+
type: 'string',
|
|
1340
|
+
description: 'Extraction model identifier.',
|
|
1341
|
+
},
|
|
1342
|
+
{
|
|
1343
|
+
name: 'state',
|
|
1344
|
+
type: 'string | object | array',
|
|
1345
|
+
description: 'Shared state to extract field values from.',
|
|
1346
|
+
},
|
|
1347
|
+
{
|
|
1348
|
+
name: 'fields',
|
|
1349
|
+
type: 'Readonly<Record<string, Experimental_ExtractionField>>',
|
|
1350
|
+
description: 'Fields to extract from the shared state.',
|
|
1351
|
+
},
|
|
1352
|
+
{
|
|
1353
|
+
name: 'referenceDate',
|
|
1354
|
+
type: 'string | undefined',
|
|
1355
|
+
description:
|
|
1356
|
+
'YYYY-MM-DD date that anchors relative dates and dates without a year.',
|
|
1357
|
+
},
|
|
1358
|
+
{
|
|
1359
|
+
name: 'maxRetries',
|
|
1360
|
+
type: 'number',
|
|
1361
|
+
description: 'Maximum number of retries for the model call.',
|
|
1362
|
+
},
|
|
1363
|
+
{
|
|
1364
|
+
name: 'headers',
|
|
1365
|
+
type: 'Record<string, string> | undefined',
|
|
1366
|
+
description: 'Additional HTTP headers sent with the request.',
|
|
1367
|
+
},
|
|
1368
|
+
{
|
|
1369
|
+
name: 'providerOptions',
|
|
1370
|
+
type: 'ProviderOptions',
|
|
1371
|
+
description: 'Provider-specific options.',
|
|
1372
|
+
},
|
|
1373
|
+
]}
|
|
1374
|
+
/>
|
|
1375
|
+
|
|
1376
|
+
#### onEnd
|
|
1377
|
+
|
|
1378
|
+
Includes every `onStart` field plus:
|
|
1379
|
+
|
|
1380
|
+
<PropertiesTable
|
|
1381
|
+
content={[
|
|
1382
|
+
{
|
|
1383
|
+
name: 'answers',
|
|
1384
|
+
type: 'Record<string, Experimental_ExtractionAnswer>',
|
|
1385
|
+
description: 'Exactly one typed answer per field ID.',
|
|
1386
|
+
},
|
|
1387
|
+
{
|
|
1388
|
+
name: 'usage',
|
|
1389
|
+
type: '{ inputTokens: number | undefined; outputTokens: number | undefined; totalTokens: number | undefined }',
|
|
1390
|
+
description: 'Token usage for the extraction operation.',
|
|
1391
|
+
},
|
|
1392
|
+
{
|
|
1393
|
+
name: 'warnings',
|
|
1394
|
+
type: 'Array<Warning>',
|
|
1395
|
+
description: 'Warnings from the extraction model.',
|
|
1396
|
+
},
|
|
1397
|
+
{
|
|
1398
|
+
name: 'providerMetadata',
|
|
1399
|
+
type: 'ProviderMetadata | undefined',
|
|
1400
|
+
description: 'Optional provider-specific metadata.',
|
|
1401
|
+
},
|
|
1402
|
+
{
|
|
1403
|
+
name: 'response',
|
|
1404
|
+
type: '{ id?: string; timestamp: Date; modelId: string; headers?: Record<string, string>; body?: unknown }',
|
|
1405
|
+
description:
|
|
1406
|
+
'Response metadata including the resolved model and timestamp.',
|
|
1407
|
+
},
|
|
1408
|
+
]}
|
|
1409
|
+
/>
|
|
@@ -27,11 +27,18 @@ Extracts a nonempty map of typed fields from one state. See
|
|
|
27
27
|
| `experimental_download` | `Experimental_DownloadFunction` | Required for remote file URLs in state. Use `createDownload({ fetch })` with a DNS-protected transport for untrusted URLs. |
|
|
28
28
|
| `headers` | `Record<string, string>` | Additional HTTP headers. |
|
|
29
29
|
| `providerOptions` | `ProviderOptions` | Provider-specific options. |
|
|
30
|
+
| `telemetry` | `TelemetryOptions` | Telemetry configuration, including per-call integrations, input/output recording, and a function ID. |
|
|
31
|
+
| `runtimeContext` | `Record<string, unknown>` | Context available to lifecycle callbacks and selectively included in telemetry with `telemetry.includeRuntimeContext`. |
|
|
32
|
+
| `onStart` | `(event: Experimental_ExtractStartEvent) => void` | Called when the extraction operation begins. |
|
|
33
|
+
| `onEnd` | `(event: Experimental_ExtractEndEvent) => void` | Called when the extraction operation completes successfully. |
|
|
30
34
|
|
|
31
35
|
Remote file URLs are rejected with `DownloadError` unless `experimental_download`
|
|
32
36
|
is supplied. The model's `fetch` option does not apply to these downloads. See
|
|
33
37
|
[Secure URL Fetching](/docs/advanced/secure-url-fetching#core-file-downloads).
|
|
34
38
|
|
|
39
|
+
See [Lifecycle Callbacks](/docs/ai-sdk-core/lifecycle-callbacks#experimental_extract)
|
|
40
|
+
for the complete `onStart` and `onEnd` event fields.
|
|
41
|
+
|
|
35
42
|
## Fields
|
|
36
43
|
|
|
37
44
|
| Type | Options |
|
|
@@ -59,8 +66,10 @@ Returns `Promise<Experimental_ExtractionResult<FIELDS>>`:
|
|
|
59
66
|
|
|
60
67
|
## Errors
|
|
61
68
|
|
|
62
|
-
Unsupported field types throw
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
69
|
+
Unsupported field types throw
|
|
70
|
+
[`Experimental_ExtractionUnsupportedFieldTypeError`](/docs/reference/ai-sdk-errors/ai-extraction-unsupported-field-type-error),
|
|
71
|
+
before provider I/O or, for AI Gateway models, after the gateway rejects the
|
|
72
|
+
field. Invalid inputs throw `InvalidArgumentError`; malformed answers throw
|
|
73
|
+
`InvalidResponseDataError`. Fields the model refuses throw
|
|
74
|
+
[`Experimental_ExtractionRefusalError`](/docs/reference/ai-sdk-errors/ai-extraction-refusal-error). Model instances must implement v4; other
|
|
66
75
|
versions throw `UnsupportedModelVersionError`.
|
|
@@ -83,8 +83,12 @@ function LiveConversation() {
|
|
|
83
83
|
}
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
The current continuous browser runtime supports a JSON/PCM16 WebSocket
|
|
87
|
-
profile
|
|
86
|
+
The current continuous browser runtime supports a JSON/PCM16 WebSocket media
|
|
87
|
+
profile, through an application relay (`api.websocket`) or, for models that declare
|
|
88
|
+
the `client-secret-websocket` connection, straight to the provider with a
|
|
89
|
+
short-lived token (`api.token`). AI Gateway Live models support the token flow; see
|
|
90
|
+
[AI Gateway Live models](/providers/ai-sdk-providers/ai-gateway#live-models).
|
|
91
|
+
Continuous conversation semantics alone do not guarantee support for every
|
|
88
92
|
codec or transport. Applications with their own audio pipeline can use the low-level
|
|
89
93
|
provider for other supported codecs. OpenAI-specific settings
|
|
90
94
|
live under `providerOptions.openai` and use camelCase fields; the provider converts
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: AI_ExtractionRefusalError
|
|
3
|
+
description: Identify extraction fields that a model declined to extract.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# AI_ExtractionRefusalError
|
|
7
|
+
|
|
8
|
+
This experimental error identifies fields that an extraction model declined to
|
|
9
|
+
extract, such as a field the provider's safety policy refuses. It is exported
|
|
10
|
+
from `ai` and `@ai-sdk/provider` as `Experimental_ExtractionRefusalError`.
|
|
11
|
+
|
|
12
|
+
Extraction models report a refusal as an answer with `type: 'refusal'`.
|
|
13
|
+
`experimental_extract` throws this error when any answer is a refusal, after the
|
|
14
|
+
provider call and without retrying it.
|
|
15
|
+
|
|
16
|
+
## Properties
|
|
17
|
+
|
|
18
|
+
- `fieldIds`: The IDs of the refused fields.
|
|
19
|
+
- `provider`: The provider of the extraction model.
|
|
20
|
+
- `modelId`: The extraction model ID.
|
|
21
|
+
- `message`: A description of the refused fields and model.
|
|
22
|
+
|
|
23
|
+
## Checking for this Error
|
|
24
|
+
|
|
25
|
+
Use the marker-based `isInstance` check, which works across package copies:
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { Experimental_ExtractionRefusalError as ExtractionRefusalError } from 'ai';
|
|
29
|
+
|
|
30
|
+
if (ExtractionRefusalError.isInstance(error)) {
|
|
31
|
+
console.log(error.fieldIds, error.modelId);
|
|
32
|
+
}
|
|
33
|
+
```
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: AI_ExtractionUnsupportedFieldTypeError
|
|
3
|
+
description: Identify an extraction field type that a model does not support.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# AI_ExtractionUnsupportedFieldTypeError
|
|
7
|
+
|
|
8
|
+
This experimental error identifies a field whose type is unsupported by an
|
|
9
|
+
extraction model. It is exported from `ai` and `@ai-sdk/provider` as
|
|
10
|
+
`Experimental_ExtractionUnsupportedFieldTypeError`.
|
|
11
|
+
|
|
12
|
+
`experimental_extract` throws it before any provider request when the field type
|
|
13
|
+
is not in the model's `supportedFieldTypes`. AI Gateway extraction models support
|
|
14
|
+
different field types per model, so they throw it after the request, when the
|
|
15
|
+
gateway rejects the field.
|
|
16
|
+
|
|
17
|
+
## Properties
|
|
18
|
+
|
|
19
|
+
- `fieldId`: The ID of the unsupported field.
|
|
20
|
+
- `fieldType`: The requested field type.
|
|
21
|
+
- `provider`: The provider of the extraction model.
|
|
22
|
+
- `modelId`: The extraction model ID.
|
|
23
|
+
- `message`: A description of the unsupported field and model. Providers can
|
|
24
|
+
supply a custom message.
|
|
25
|
+
|
|
26
|
+
## Checking for this Error
|
|
27
|
+
|
|
28
|
+
Use the marker-based `isInstance` check, which works across package copies:
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { Experimental_ExtractionUnsupportedFieldTypeError as ExtractionUnsupportedFieldTypeError } from 'ai';
|
|
32
|
+
|
|
33
|
+
if (ExtractionUnsupportedFieldTypeError.isInstance(error)) {
|
|
34
|
+
console.log(error.fieldId, error.fieldType, error.modelId);
|
|
35
|
+
}
|
|
36
|
+
```
|
|
@@ -10,6 +10,7 @@ This error occurs when `experimental_toolApprovalSecret` is configured and a too
|
|
|
10
10
|
Common causes:
|
|
11
11
|
|
|
12
12
|
- The approval was fabricated by the client (no signature present)
|
|
13
|
+
- The client approved a tool call that the server denied automatically (automatic denials are not signed)
|
|
13
14
|
- The tool arguments were modified after the approval was signed
|
|
14
15
|
- The server secret changed between issuance and verification (e.g. after key rotation without overlap)
|
|
15
16
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.179",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "AI SDK by Vercel - build apps like ChatGPT, Claude, Gemini, and more with a single interface for any model using the Vercel AI Gateway or go direct to OpenAI, Anthropic, Google, or any other model provider.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -43,20 +43,20 @@
|
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@ai-sdk/gateway": "4.0.
|
|
46
|
+
"@ai-sdk/gateway": "4.0.152",
|
|
47
47
|
"@ai-sdk/provider": "4.0.39",
|
|
48
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
48
|
+
"@ai-sdk/provider-utils": "5.0.83"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@ai-sdk/amazon-bedrock": "5.0.
|
|
52
|
-
"@ai-sdk/deepseek": "3.0.
|
|
53
|
-
"@ai-sdk/google": "4.0.
|
|
54
|
-
"@ai-sdk/groq": "4.0.
|
|
55
|
-
"@ai-sdk/huggingface": "2.0.
|
|
56
|
-
"@ai-sdk/moonshotai": "3.0.
|
|
57
|
-
"@ai-sdk/openai": "4.0.
|
|
51
|
+
"@ai-sdk/amazon-bedrock": "5.0.146",
|
|
52
|
+
"@ai-sdk/deepseek": "3.0.89",
|
|
53
|
+
"@ai-sdk/google": "4.0.124",
|
|
54
|
+
"@ai-sdk/groq": "4.0.86",
|
|
55
|
+
"@ai-sdk/huggingface": "2.0.95",
|
|
56
|
+
"@ai-sdk/moonshotai": "3.0.95",
|
|
57
|
+
"@ai-sdk/openai": "4.0.122",
|
|
58
58
|
"@ai-sdk/test-server": "2.0.4",
|
|
59
|
-
"@ai-sdk/xai": "5.0.
|
|
59
|
+
"@ai-sdk/xai": "5.0.48",
|
|
60
60
|
"@edge-runtime/vm": "^5.0.0",
|
|
61
61
|
"@smithy/eventstream-codec": "^4.3.3",
|
|
62
62
|
"@smithy/util-utf8": "^4.3.3",
|
|
@@ -117,8 +117,8 @@
|
|
|
117
117
|
"scripts": {
|
|
118
118
|
"build": "pnpm clean && tsdown",
|
|
119
119
|
"build:watch": "pnpm clean && tsdown --watch",
|
|
120
|
-
"clean": "del-cli docs skills
|
|
121
|
-
"type-check": "tsc --
|
|
120
|
+
"clean": "del-cli docs skills",
|
|
121
|
+
"type-check": "tsc --noEmit",
|
|
122
122
|
"test": "pnpm test:node && pnpm test:edge",
|
|
123
123
|
"test:update": "pnpm test:node -u",
|
|
124
124
|
"test:watch": "vitest --config vitest.node.config.js",
|
|
@@ -159,8 +159,9 @@ export type ToolLoopAgentSettings<
|
|
|
159
159
|
|
|
160
160
|
/**
|
|
161
161
|
* Secret for HMAC-signing tool approval requests. When set, the server
|
|
162
|
-
* signs
|
|
162
|
+
* signs approval requests at issuance and verifies the signature when
|
|
163
163
|
* the approval is replayed, preventing client-forged approvals.
|
|
164
|
+
* Approval requests for automatically denied tool calls are not signed.
|
|
164
165
|
*/
|
|
165
166
|
experimental_toolApprovalSecret?: string | Uint8Array;
|
|
166
167
|
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Experimental_ExtractionModelV4CallOptions as ExtractionModelV4CallOptions,
|
|
3
|
+
Experimental_ExtractionModelV4Field as ExtractionField,
|
|
4
|
+
Experimental_ExtractionModelV4Result as ExtractionModelV4Result,
|
|
5
|
+
} from '@ai-sdk/provider';
|
|
6
|
+
import type { Context, ProviderOptions } from '@ai-sdk/provider-utils';
|
|
7
|
+
import type { DecisionState } from '../decide/decision-state';
|
|
8
|
+
import type { ExtractionResult } from './extraction-result';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Event passed to the `onStart` callback for extraction operations.
|
|
12
|
+
*
|
|
13
|
+
* Called when the operation begins, before the extraction model is called.
|
|
14
|
+
*/
|
|
15
|
+
export type ExtractStartEvent<RUNTIME_CONTEXT extends Context = Context> = {
|
|
16
|
+
/** User-defined runtime context. */
|
|
17
|
+
readonly runtimeContext: RUNTIME_CONTEXT;
|
|
18
|
+
|
|
19
|
+
/** Unique identifier for this extraction call, used to correlate events. */
|
|
20
|
+
readonly callId: string;
|
|
21
|
+
|
|
22
|
+
/** Identifies the operation type (`ai.extract`). */
|
|
23
|
+
readonly operationId: 'ai.extract';
|
|
24
|
+
|
|
25
|
+
/** The provider identifier. */
|
|
26
|
+
readonly provider: string;
|
|
27
|
+
|
|
28
|
+
/** The extraction model identifier. */
|
|
29
|
+
readonly modelId: string;
|
|
30
|
+
|
|
31
|
+
/** The shared state to extract field values from. */
|
|
32
|
+
readonly state: DecisionState;
|
|
33
|
+
|
|
34
|
+
/** The fields to extract from the shared state. */
|
|
35
|
+
readonly fields: Readonly<Record<string, ExtractionField>>;
|
|
36
|
+
|
|
37
|
+
/** `YYYY-MM-DD` date that anchors relative dates and dates without a year. */
|
|
38
|
+
readonly referenceDate?: string;
|
|
39
|
+
|
|
40
|
+
/** Maximum output tokens requested for the extraction. */
|
|
41
|
+
readonly maxOutputTokens?: number;
|
|
42
|
+
|
|
43
|
+
/** Reasoning effort requested for the extraction. */
|
|
44
|
+
readonly reasoning?: ExtractionModelV4CallOptions['reasoning'];
|
|
45
|
+
|
|
46
|
+
/** Maximum number of retries for the extraction model call. */
|
|
47
|
+
readonly maxRetries: number;
|
|
48
|
+
|
|
49
|
+
/** Additional HTTP headers sent with the request. */
|
|
50
|
+
readonly headers: Record<string, string> | undefined;
|
|
51
|
+
|
|
52
|
+
/** Additional provider-specific options. */
|
|
53
|
+
readonly providerOptions: ProviderOptions;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Event passed to the `onEnd` callback for extraction operations.
|
|
58
|
+
*
|
|
59
|
+
* Called when the operation completes successfully.
|
|
60
|
+
*/
|
|
61
|
+
export type ExtractEndEvent<RUNTIME_CONTEXT extends Context = Context> =
|
|
62
|
+
ExtractStartEvent<RUNTIME_CONTEXT> & {
|
|
63
|
+
/** Exactly one typed answer per field ID. */
|
|
64
|
+
readonly answers: ExtractionResult<
|
|
65
|
+
Record<string, ExtractionField>
|
|
66
|
+
>['answers'];
|
|
67
|
+
|
|
68
|
+
/** Token usage for the extraction operation. */
|
|
69
|
+
readonly usage: ExtractionResult<Record<string, ExtractionField>>['usage'];
|
|
70
|
+
|
|
71
|
+
/** Warnings from the extraction model. */
|
|
72
|
+
readonly warnings: ExtractionResult<
|
|
73
|
+
Record<string, ExtractionField>
|
|
74
|
+
>['warnings'];
|
|
75
|
+
|
|
76
|
+
/** Optional provider-specific metadata. */
|
|
77
|
+
readonly providerMetadata: ExtractionResult<
|
|
78
|
+
Record<string, ExtractionField>
|
|
79
|
+
>['providerMetadata'];
|
|
80
|
+
|
|
81
|
+
/** Response metadata, including the resolved model ID and timestamp. */
|
|
82
|
+
readonly response: ExtractionResult<
|
|
83
|
+
Record<string, ExtractionField>
|
|
84
|
+
>['response'];
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Event fired when the extraction model call begins.
|
|
89
|
+
*
|
|
90
|
+
* The logical model call includes any provider retries.
|
|
91
|
+
*/
|
|
92
|
+
export type ExtractionModelCallStartEvent = {
|
|
93
|
+
/** Unique identifier for the outer extraction call. */
|
|
94
|
+
readonly callId: string;
|
|
95
|
+
|
|
96
|
+
/** Identifies the inner operation (`ai.extract.doExtract`). */
|
|
97
|
+
readonly operationId: 'ai.extract.doExtract';
|
|
98
|
+
|
|
99
|
+
/** The provider identifier. */
|
|
100
|
+
readonly provider: string;
|
|
101
|
+
|
|
102
|
+
/** The extraction model identifier. */
|
|
103
|
+
readonly modelId: string;
|
|
104
|
+
|
|
105
|
+
/** The shared state to extract field values from. */
|
|
106
|
+
readonly state: ExtractionModelV4CallOptions['state'];
|
|
107
|
+
|
|
108
|
+
/** The fields to extract from the shared state. */
|
|
109
|
+
readonly fields: ExtractionModelV4CallOptions['fields'];
|
|
110
|
+
|
|
111
|
+
/** `YYYY-MM-DD` date that anchors relative dates and dates without a year. */
|
|
112
|
+
readonly referenceDate?: ExtractionModelV4CallOptions['referenceDate'];
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Event fired after the extraction model response has been validated.
|
|
117
|
+
*
|
|
118
|
+
* Contains the result of the logical model call, including any retries.
|
|
119
|
+
*/
|
|
120
|
+
export type ExtractionModelCallEndEvent = ExtractionModelCallStartEvent & {
|
|
121
|
+
/** Exactly one answer per field ID. */
|
|
122
|
+
readonly answers: ExtractionModelV4Result['answers'];
|
|
123
|
+
|
|
124
|
+
/** Token usage reported by the extraction model. */
|
|
125
|
+
readonly usage?: ExtractionModelV4Result['usage'];
|
|
126
|
+
|
|
127
|
+
/** Warnings from the extraction model. */
|
|
128
|
+
readonly warnings: ExtractionModelV4Result['warnings'];
|
|
129
|
+
|
|
130
|
+
/** Optional provider-specific metadata. */
|
|
131
|
+
readonly providerMetadata?: ExtractionModelV4Result['providerMetadata'];
|
|
132
|
+
|
|
133
|
+
/** Optional raw response metadata from the provider. */
|
|
134
|
+
readonly response?: ExtractionModelV4Result['response'];
|
|
135
|
+
};
|