@ai-sdk/anthropic 4.0.84 → 4.0.86
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 +28 -0
- package/dist/index.d.ts +138 -176
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +90 -44
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +10 -10
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +88 -42
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +48 -4
- package/package.json +3 -3
- package/src/anthropic-api.ts +144 -130
- package/src/anthropic-batch.ts +8 -7
- package/src/anthropic-language-model-options.ts +417 -398
- package/src/anthropic-language-model.ts +64 -1
- package/src/convert-to-anthropic-prompt.ts +2 -2
- package/src/skills/anthropic-skills.ts +1 -11
|
@@ -3203,8 +3203,71 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
3203
3203
|
}),
|
|
3204
3204
|
);
|
|
3205
3205
|
|
|
3206
|
+
let hasOutput = false;
|
|
3207
|
+
let hasStreamError = false;
|
|
3208
|
+
let lastFinish:
|
|
3209
|
+
| Extract<LanguageModelV4StreamPart, { type: 'finish' }>
|
|
3210
|
+
| undefined;
|
|
3211
|
+
const streamWithFinishReason = transformedStream.pipeThrough(
|
|
3212
|
+
new TransformStream<LanguageModelV4StreamPart, LanguageModelV4StreamPart>(
|
|
3213
|
+
{
|
|
3214
|
+
transform(chunk, controller) {
|
|
3215
|
+
switch (chunk.type) {
|
|
3216
|
+
case 'response-metadata':
|
|
3217
|
+
hasOutput = false;
|
|
3218
|
+
break;
|
|
3219
|
+
case 'finish':
|
|
3220
|
+
hasOutput = false;
|
|
3221
|
+
lastFinish = chunk;
|
|
3222
|
+
break;
|
|
3223
|
+
case 'error':
|
|
3224
|
+
hasStreamError = true;
|
|
3225
|
+
break;
|
|
3226
|
+
case 'text-delta':
|
|
3227
|
+
case 'reasoning-delta':
|
|
3228
|
+
case 'tool-input-delta':
|
|
3229
|
+
hasOutput ||= chunk.delta.length > 0;
|
|
3230
|
+
break;
|
|
3231
|
+
case 'tool-call':
|
|
3232
|
+
hasOutput = true;
|
|
3233
|
+
break;
|
|
3234
|
+
}
|
|
3235
|
+
controller.enqueue(chunk);
|
|
3236
|
+
},
|
|
3237
|
+
flush(controller) {
|
|
3238
|
+
// Preserve the existing no-output error path. Only partial output
|
|
3239
|
+
// without a finish chunk receives an interrupted finish reason.
|
|
3240
|
+
if (hasOutput && !hasStreamError) {
|
|
3241
|
+
controller.enqueue({
|
|
3242
|
+
type: 'finish',
|
|
3243
|
+
finishReason: { unified: 'interrupted', raw: undefined },
|
|
3244
|
+
// Keep the usage and metadata core already had before the cutoff.
|
|
3245
|
+
usage: lastFinish?.usage ?? {
|
|
3246
|
+
inputTokens: {
|
|
3247
|
+
total: undefined,
|
|
3248
|
+
noCache: undefined,
|
|
3249
|
+
cacheRead: undefined,
|
|
3250
|
+
cacheWrite: undefined,
|
|
3251
|
+
},
|
|
3252
|
+
outputTokens: {
|
|
3253
|
+
total: undefined,
|
|
3254
|
+
text: undefined,
|
|
3255
|
+
reasoning: undefined,
|
|
3256
|
+
},
|
|
3257
|
+
},
|
|
3258
|
+
...(lastFinish?.providerMetadata != null
|
|
3259
|
+
? { providerMetadata: lastFinish.providerMetadata }
|
|
3260
|
+
: {}),
|
|
3261
|
+
});
|
|
3262
|
+
}
|
|
3263
|
+
},
|
|
3264
|
+
},
|
|
3265
|
+
),
|
|
3266
|
+
);
|
|
3267
|
+
|
|
3206
3268
|
// The first chunk needs to be pulled immediately to check if it is an error
|
|
3207
|
-
const [streamForFirstChunk, streamForConsumer] =
|
|
3269
|
+
const [streamForFirstChunk, streamForConsumer] =
|
|
3270
|
+
streamWithFinishReason.tee();
|
|
3208
3271
|
|
|
3209
3272
|
const firstChunkReader = streamForFirstChunk.getReader();
|
|
3210
3273
|
try {
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
type ToolNameMapping,
|
|
23
23
|
} from '@ai-sdk/provider-utils';
|
|
24
24
|
import {
|
|
25
|
-
|
|
25
|
+
anthropicFallbackContentSchemaValidator,
|
|
26
26
|
anthropicReasoningMetadataSchema,
|
|
27
27
|
type AnthropicAssistantMessage,
|
|
28
28
|
type AnthropicImageContent,
|
|
@@ -880,7 +880,7 @@ export async function convertToAnthropicPrompt({
|
|
|
880
880
|
|
|
881
881
|
const fallbackMetadata = await safeValidateTypes({
|
|
882
882
|
value: part.providerOptions?.anthropic,
|
|
883
|
-
schema:
|
|
883
|
+
schema: anthropicFallbackContentSchemaValidator,
|
|
884
884
|
});
|
|
885
885
|
|
|
886
886
|
if (!fallbackMetadata.success) {
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
combineHeaders,
|
|
4
4
|
convertInlineFileDataToUint8Array,
|
|
5
5
|
createJsonResponseHandler,
|
|
6
|
+
encodePathSegment,
|
|
6
7
|
getFromApi,
|
|
7
8
|
postFormDataToApi,
|
|
8
9
|
resolve,
|
|
@@ -22,17 +23,6 @@ interface AnthropicSkillsConfig {
|
|
|
22
23
|
fetch?: FetchFunction;
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
function encodePathSegment(value: string): string {
|
|
26
|
-
const encodedValue = encodeURIComponent(value);
|
|
27
|
-
|
|
28
|
-
// URL parsing normalizes both literal and percent-encoded dot segments.
|
|
29
|
-
return encodedValue === '.'
|
|
30
|
-
? '%252E'
|
|
31
|
-
: encodedValue === '..'
|
|
32
|
-
? '%252E%252E'
|
|
33
|
-
: encodedValue;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
26
|
export class AnthropicSkills implements SkillsV4 {
|
|
37
27
|
readonly specificationVersion = 'v4';
|
|
38
28
|
|