@ai-sdk/anthropic 4.0.0-beta.26 → 4.0.0-beta.28

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/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@ai-sdk/anthropic",
3
- "version": "4.0.0-beta.26",
3
+ "version": "4.0.0-beta.28",
4
+ "type": "module",
4
5
  "license": "Apache-2.0",
5
6
  "sideEffects": false,
6
7
  "main": "./dist/index.js",
7
- "module": "./dist/index.mjs",
8
8
  "types": "./dist/index.d.ts",
9
9
  "files": [
10
10
  "dist/**/*",
@@ -25,26 +25,25 @@
25
25
  "./package.json": "./package.json",
26
26
  ".": {
27
27
  "types": "./dist/index.d.ts",
28
- "import": "./dist/index.mjs",
29
- "require": "./dist/index.js"
28
+ "import": "./dist/index.js",
29
+ "default": "./dist/index.js"
30
30
  },
31
31
  "./internal": {
32
32
  "types": "./dist/internal/index.d.ts",
33
- "import": "./dist/internal/index.mjs",
34
- "module": "./dist/internal/index.mjs",
35
- "require": "./dist/internal/index.js"
33
+ "import": "./dist/internal/index.js",
34
+ "default": "./dist/internal/index.js"
36
35
  }
37
36
  },
38
37
  "dependencies": {
39
- "@ai-sdk/provider": "4.0.0-beta.10",
40
- "@ai-sdk/provider-utils": "5.0.0-beta.18"
38
+ "@ai-sdk/provider": "4.0.0-beta.12",
39
+ "@ai-sdk/provider-utils": "5.0.0-beta.20"
41
40
  },
42
41
  "devDependencies": {
43
42
  "@types/node": "20.17.24",
44
43
  "tsup": "^8",
45
44
  "typescript": "5.8.3",
46
45
  "zod": "3.25.76",
47
- "@ai-sdk/test-server": "2.0.0-beta.0",
46
+ "@ai-sdk/test-server": "2.0.0-beta.1",
48
47
  "@vercel/ai-tsconfig": "0.0.0"
49
48
  },
50
49
  "peerDependencies": {
@@ -32,6 +32,9 @@ import {
32
32
  Resolvable,
33
33
  resolve,
34
34
  resolveProviderReference,
35
+ serializeModelOptions,
36
+ WORKFLOW_SERIALIZE,
37
+ WORKFLOW_DESERIALIZE,
35
38
  } from '@ai-sdk/provider-utils';
36
39
  import { anthropicFailedResponseHandler } from './anthropic-error';
37
40
  import { AnthropicMessageMetadata } from './anthropic-message-metadata';
@@ -120,7 +123,7 @@ function createCitationSource(
120
123
  type AnthropicMessagesConfig = {
121
124
  provider: string;
122
125
  baseURL: string;
123
- headers: Resolvable<Record<string, string | undefined>>;
126
+ headers?: Resolvable<Record<string, string | undefined>>;
124
127
  fetch?: FetchFunction;
125
128
  buildRequestUrl?: (baseURL: string, isStreaming: boolean) => string;
126
129
  transformRequestBody?: (
@@ -150,6 +153,20 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV4 {
150
153
  private readonly config: AnthropicMessagesConfig;
151
154
  private readonly generateId: () => string;
152
155
 
156
+ static [WORKFLOW_SERIALIZE](model: AnthropicMessagesLanguageModel) {
157
+ return serializeModelOptions({
158
+ modelId: model.modelId,
159
+ config: model.config,
160
+ });
161
+ }
162
+
163
+ static [WORKFLOW_DESERIALIZE](options: {
164
+ modelId: AnthropicMessagesModelId;
165
+ config: AnthropicMessagesConfig;
166
+ }) {
167
+ return new AnthropicMessagesLanguageModel(options.modelId, options.config);
168
+ }
169
+
153
170
  constructor(
154
171
  modelId: AnthropicMessagesModelId,
155
172
  config: AnthropicMessagesConfig,
@@ -714,7 +731,7 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV4 {
714
731
  headers: Record<string, string | undefined> | undefined;
715
732
  }) {
716
733
  return combineHeaders(
717
- await resolve(this.config.headers),
734
+ this.config.headers ? await resolve(this.config.headers) : undefined,
718
735
  headers,
719
736
  betas.size > 0 ? { 'anthropic-beta': Array.from(betas).join(',') } : {},
720
737
  );
@@ -723,9 +740,11 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV4 {
723
740
  private async getBetasFromHeaders(
724
741
  requestHeaders: Record<string, string | undefined> | undefined,
725
742
  ) {
726
- const configHeaders = await resolve(this.config.headers);
743
+ const configHeaders = this.config.headers
744
+ ? await resolve(this.config.headers)
745
+ : undefined;
727
746
 
728
- const configBetaHeader = configHeaders['anthropic-beta'] ?? '';
747
+ const configBetaHeader = configHeaders?.['anthropic-beta'] ?? '';
729
748
  const requestBetaHeader = requestHeaders?.['anthropic-beta'] ?? '';
730
749
 
731
750
  return new Set(
@@ -1279,6 +1298,8 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV4 {
1279
1298
  async doStream(
1280
1299
  options: LanguageModelV4CallOptions,
1281
1300
  ): Promise<LanguageModelV4StreamResult> {
1301
+ 'use step';
1302
+
1282
1303
  const {
1283
1304
  args: body,
1284
1305
  warnings,
@@ -331,26 +331,16 @@ export async function convertToAnthropicMessagesPrompt({
331
331
  type: 'text' as const,
332
332
  text: contentPart.text,
333
333
  };
334
- case 'image-data': {
335
- return {
336
- type: 'image' as const,
337
- source: {
338
- type: 'base64' as const,
339
- media_type: contentPart.mediaType,
340
- data: contentPart.data,
341
- },
342
- };
343
- }
344
- case 'image-url': {
345
- return {
346
- type: 'image' as const,
347
- source: {
348
- type: 'url' as const,
349
- url: contentPart.url,
350
- },
351
- };
352
- }
353
334
  case 'file-url': {
335
+ if (contentPart.mediaType.startsWith('image/')) {
336
+ return {
337
+ type: 'image' as const,
338
+ source: {
339
+ type: 'url' as const,
340
+ url: contentPart.url,
341
+ },
342
+ };
343
+ }
354
344
  return {
355
345
  type: 'document' as const,
356
346
  source: {
@@ -360,6 +350,16 @@ export async function convertToAnthropicMessagesPrompt({
360
350
  };
361
351
  }
362
352
  case 'file-data': {
353
+ if (contentPart.mediaType.startsWith('image/')) {
354
+ return {
355
+ type: 'image' as const,
356
+ source: {
357
+ type: 'base64' as const,
358
+ media_type: contentPart.mediaType,
359
+ data: contentPart.data,
360
+ },
361
+ };
362
+ }
363
363
  if (contentPart.mediaType === 'application/pdf') {
364
364
  betas.add('pdfs-2024-09-25');
365
365
  return {