@ai-sdk/anthropic 4.0.0-beta.27 → 4.0.0-beta.29

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.
@@ -1,13 +1,13 @@
1
- import { LanguageModelV4, LanguageModelV4CallOptions, LanguageModelV4GenerateResult, LanguageModelV4StreamResult, JSONSchema7, SharedV4ProviderMetadata, SharedV4Warning } from '@ai-sdk/provider';
1
+ import { LanguageModelV4, JSONObject, LanguageModelV4CallOptions, LanguageModelV4GenerateResult, LanguageModelV4StreamResult, JSONSchema7, SharedV4ProviderMetadata, SharedV4Warning } from '@ai-sdk/provider';
2
2
  import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
3
- import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
3
+ import { WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE, Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
4
4
 
5
5
  type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | (string & {});
6
6
 
7
7
  type AnthropicMessagesConfig = {
8
8
  provider: string;
9
9
  baseURL: string;
10
- headers: Resolvable<Record<string, string | undefined>>;
10
+ headers?: Resolvable<Record<string, string | undefined>>;
11
11
  fetch?: FetchFunction;
12
12
  buildRequestUrl?: (baseURL: string, isStreaming: boolean) => string;
13
13
  transformRequestBody?: (args: Record<string, any>, betas: Set<string>) => Record<string, any>;
@@ -28,6 +28,14 @@ declare class AnthropicMessagesLanguageModel implements LanguageModelV4 {
28
28
  readonly modelId: AnthropicMessagesModelId;
29
29
  private readonly config;
30
30
  private readonly generateId;
31
+ static [WORKFLOW_SERIALIZE](model: AnthropicMessagesLanguageModel): {
32
+ modelId: string;
33
+ config: JSONObject;
34
+ };
35
+ static [WORKFLOW_DESERIALIZE](options: {
36
+ modelId: AnthropicMessagesModelId;
37
+ config: AnthropicMessagesConfig;
38
+ }): AnthropicMessagesLanguageModel;
31
39
  constructor(modelId: AnthropicMessagesModelId, config: AnthropicMessagesConfig);
32
40
  supportsUrl(url: URL): boolean;
33
41
  get provider(): string;
@@ -14,7 +14,10 @@ import {
14
14
  parseProviderOptions as parseProviderOptions2,
15
15
  postJsonToApi,
16
16
  resolve,
17
- resolveProviderReference as resolveProviderReference2
17
+ resolveProviderReference as resolveProviderReference2,
18
+ serializeModelOptions,
19
+ WORKFLOW_SERIALIZE,
20
+ WORKFLOW_DESERIALIZE
18
21
  } from "@ai-sdk/provider-utils";
19
22
 
20
23
  // src/anthropic-error.ts
@@ -2235,26 +2238,16 @@ async function convertToAnthropicMessagesPrompt({
2235
2238
  type: "text",
2236
2239
  text: contentPart.text
2237
2240
  };
2238
- case "image-data": {
2239
- return {
2240
- type: "image",
2241
- source: {
2242
- type: "base64",
2243
- media_type: contentPart.mediaType,
2244
- data: contentPart.data
2245
- }
2246
- };
2247
- }
2248
- case "image-url": {
2249
- return {
2250
- type: "image",
2251
- source: {
2252
- type: "url",
2253
- url: contentPart.url
2254
- }
2255
- };
2256
- }
2257
2241
  case "file-url": {
2242
+ if (contentPart.mediaType.startsWith("image/")) {
2243
+ return {
2244
+ type: "image",
2245
+ source: {
2246
+ type: "url",
2247
+ url: contentPart.url
2248
+ }
2249
+ };
2250
+ }
2258
2251
  return {
2259
2252
  type: "document",
2260
2253
  source: {
@@ -2264,6 +2257,16 @@ async function convertToAnthropicMessagesPrompt({
2264
2257
  };
2265
2258
  }
2266
2259
  case "file-data": {
2260
+ if (contentPart.mediaType.startsWith("image/")) {
2261
+ return {
2262
+ type: "image",
2263
+ source: {
2264
+ type: "base64",
2265
+ media_type: contentPart.mediaType,
2266
+ data: contentPart.data
2267
+ }
2268
+ };
2269
+ }
2267
2270
  if (contentPart.mediaType === "application/pdf") {
2268
2271
  betas.add("pdfs-2024-09-25");
2269
2272
  return {
@@ -2910,7 +2913,7 @@ function createCitationSource(citation, citationDocuments, generateId2) {
2910
2913
  }
2911
2914
  };
2912
2915
  }
2913
- var AnthropicMessagesLanguageModel = class {
2916
+ var AnthropicMessagesLanguageModel = class _AnthropicMessagesLanguageModel {
2914
2917
  constructor(modelId, config) {
2915
2918
  this.specificationVersion = "v4";
2916
2919
  var _a;
@@ -2918,6 +2921,15 @@ var AnthropicMessagesLanguageModel = class {
2918
2921
  this.config = config;
2919
2922
  this.generateId = (_a = config.generateId) != null ? _a : generateId;
2920
2923
  }
2924
+ static [WORKFLOW_SERIALIZE](model) {
2925
+ return serializeModelOptions({
2926
+ modelId: model.modelId,
2927
+ config: model.config
2928
+ });
2929
+ }
2930
+ static [WORKFLOW_DESERIALIZE](options) {
2931
+ return new _AnthropicMessagesLanguageModel(options.modelId, options.config);
2932
+ }
2921
2933
  supportsUrl(url) {
2922
2934
  return url.protocol === "https:";
2923
2935
  }
@@ -3340,15 +3352,15 @@ var AnthropicMessagesLanguageModel = class {
3340
3352
  headers
3341
3353
  }) {
3342
3354
  return combineHeaders(
3343
- await resolve(this.config.headers),
3355
+ this.config.headers ? await resolve(this.config.headers) : void 0,
3344
3356
  headers,
3345
3357
  betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {}
3346
3358
  );
3347
3359
  }
3348
3360
  async getBetasFromHeaders(requestHeaders) {
3349
3361
  var _a, _b;
3350
- const configHeaders = await resolve(this.config.headers);
3351
- const configBetaHeader = (_a = configHeaders["anthropic-beta"]) != null ? _a : "";
3362
+ const configHeaders = this.config.headers ? await resolve(this.config.headers) : void 0;
3363
+ const configBetaHeader = (_a = configHeaders == null ? void 0 : configHeaders["anthropic-beta"]) != null ? _a : "";
3352
3364
  const requestBetaHeader = (_b = requestHeaders == null ? void 0 : requestHeaders["anthropic-beta"]) != null ? _b : "";
3353
3365
  return new Set(
3354
3366
  [
@@ -3812,6 +3824,7 @@ var AnthropicMessagesLanguageModel = class {
3812
3824
  };
3813
3825
  }
3814
3826
  async doStream(options) {
3827
+ "use step";
3815
3828
  var _a, _b;
3816
3829
  const {
3817
3830
  args: body,