@ai-sdk/anthropic 4.0.0-beta.19 → 4.0.0-beta.21
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 +18 -0
- package/dist/index.d.mts +12 -4
- package/dist/index.d.ts +12 -4
- package/dist/index.js +152 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +155 -8
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +16 -6
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +18 -7
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/anthropic-messages-language-model.ts +8 -1
- package/src/anthropic-messages-options.ts +12 -5
- package/src/anthropic-provider.ts +17 -0
- package/src/skills/anthropic-skills-api.ts +44 -0
- package/src/skills/anthropic-skills.ts +136 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 4.0.0-beta.21
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 34bd95d: feat(ai): add support for uploading provider skills using the provider references abstraction
|
|
8
|
+
- Updated dependencies [34bd95d]
|
|
9
|
+
- Updated dependencies [008271d]
|
|
10
|
+
- @ai-sdk/provider@4.0.0-beta.8
|
|
11
|
+
- @ai-sdk/provider-utils@5.0.0-beta.14
|
|
12
|
+
|
|
13
|
+
## 4.0.0-beta.20
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [b0c2869]
|
|
18
|
+
- Updated dependencies [7e26e81]
|
|
19
|
+
- @ai-sdk/provider-utils@5.0.0-beta.13
|
|
20
|
+
|
|
3
21
|
## 4.0.0-beta.19
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JSONObject, ProviderV4, LanguageModelV4, FilesV4 } from '@ai-sdk/provider';
|
|
1
|
+
import { JSONObject, ProviderV4, LanguageModelV4, FilesV4, SkillsV4 } from '@ai-sdk/provider';
|
|
2
2
|
import { z } from 'zod/v4';
|
|
3
3
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
4
4
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
@@ -164,11 +164,15 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
|
|
|
164
164
|
}, z.core.$strip>>>;
|
|
165
165
|
container: z.ZodOptional<z.ZodObject<{
|
|
166
166
|
id: z.ZodOptional<z.ZodString>;
|
|
167
|
-
skills: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
168
|
-
type: z.
|
|
167
|
+
skills: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
168
|
+
type: z.ZodLiteral<"anthropic">;
|
|
169
169
|
skillId: z.ZodString;
|
|
170
170
|
version: z.ZodOptional<z.ZodString>;
|
|
171
|
-
}, z.core.$strip
|
|
171
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
172
|
+
type: z.ZodLiteral<"custom">;
|
|
173
|
+
providerReference: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
174
|
+
version: z.ZodOptional<z.ZodString>;
|
|
175
|
+
}, z.core.$strip>]>>>;
|
|
172
176
|
}, z.core.$strip>>;
|
|
173
177
|
toolStreaming: z.ZodOptional<z.ZodBoolean>;
|
|
174
178
|
effort: z.ZodOptional<z.ZodEnum<{
|
|
@@ -1026,6 +1030,10 @@ interface AnthropicProvider extends ProviderV4 {
|
|
|
1026
1030
|
*/
|
|
1027
1031
|
textEmbeddingModel(modelId: string): never;
|
|
1028
1032
|
files(): FilesV4;
|
|
1033
|
+
/**
|
|
1034
|
+
* Returns a SkillsV4 interface for uploading skills to Anthropic.
|
|
1035
|
+
*/
|
|
1036
|
+
skills(): SkillsV4;
|
|
1029
1037
|
/**
|
|
1030
1038
|
* Anthropic-specific computer use tool.
|
|
1031
1039
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JSONObject, ProviderV4, LanguageModelV4, FilesV4 } from '@ai-sdk/provider';
|
|
1
|
+
import { JSONObject, ProviderV4, LanguageModelV4, FilesV4, SkillsV4 } from '@ai-sdk/provider';
|
|
2
2
|
import { z } from 'zod/v4';
|
|
3
3
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
4
4
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
@@ -164,11 +164,15 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
|
|
|
164
164
|
}, z.core.$strip>>>;
|
|
165
165
|
container: z.ZodOptional<z.ZodObject<{
|
|
166
166
|
id: z.ZodOptional<z.ZodString>;
|
|
167
|
-
skills: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
168
|
-
type: z.
|
|
167
|
+
skills: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
168
|
+
type: z.ZodLiteral<"anthropic">;
|
|
169
169
|
skillId: z.ZodString;
|
|
170
170
|
version: z.ZodOptional<z.ZodString>;
|
|
171
|
-
}, z.core.$strip
|
|
171
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
172
|
+
type: z.ZodLiteral<"custom">;
|
|
173
|
+
providerReference: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
174
|
+
version: z.ZodOptional<z.ZodString>;
|
|
175
|
+
}, z.core.$strip>]>>>;
|
|
172
176
|
}, z.core.$strip>>;
|
|
173
177
|
toolStreaming: z.ZodOptional<z.ZodBoolean>;
|
|
174
178
|
effort: z.ZodOptional<z.ZodEnum<{
|
|
@@ -1026,6 +1030,10 @@ interface AnthropicProvider extends ProviderV4 {
|
|
|
1026
1030
|
*/
|
|
1027
1031
|
textEmbeddingModel(modelId: string): never;
|
|
1028
1032
|
files(): FilesV4;
|
|
1033
|
+
/**
|
|
1034
|
+
* Returns a SkillsV4 interface for uploading skills to Anthropic.
|
|
1035
|
+
*/
|
|
1036
|
+
skills(): SkillsV4;
|
|
1029
1037
|
/**
|
|
1030
1038
|
* Anthropic-specific computer use tool.
|
|
1031
1039
|
*/
|
package/dist/index.js
CHANGED
|
@@ -29,7 +29,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
29
29
|
|
|
30
30
|
// src/anthropic-provider.ts
|
|
31
31
|
var import_provider4 = require("@ai-sdk/provider");
|
|
32
|
-
var
|
|
32
|
+
var import_provider_utils29 = require("@ai-sdk/provider-utils");
|
|
33
33
|
|
|
34
34
|
// src/anthropic-files.ts
|
|
35
35
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
@@ -980,11 +980,18 @@ var anthropicLanguageModelOptions = import_v44.z.object({
|
|
|
980
980
|
container: import_v44.z.object({
|
|
981
981
|
id: import_v44.z.string().optional(),
|
|
982
982
|
skills: import_v44.z.array(
|
|
983
|
-
import_v44.z.
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
983
|
+
import_v44.z.discriminatedUnion("type", [
|
|
984
|
+
import_v44.z.object({
|
|
985
|
+
type: import_v44.z.literal("anthropic"),
|
|
986
|
+
skillId: import_v44.z.string(),
|
|
987
|
+
version: import_v44.z.string().optional()
|
|
988
|
+
}),
|
|
989
|
+
import_v44.z.object({
|
|
990
|
+
type: import_v44.z.literal("custom"),
|
|
991
|
+
providerReference: import_v44.z.record(import_v44.z.string(), import_v44.z.string()),
|
|
992
|
+
version: import_v44.z.string().optional()
|
|
993
|
+
})
|
|
994
|
+
])
|
|
988
995
|
).optional()
|
|
989
996
|
}).optional(),
|
|
990
997
|
/**
|
|
@@ -3164,7 +3171,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3164
3171
|
id: anthropicOptions.container.id,
|
|
3165
3172
|
skills: anthropicOptions.container.skills.map((skill) => ({
|
|
3166
3173
|
type: skill.type,
|
|
3167
|
-
skill_id: skill.
|
|
3174
|
+
skill_id: skill.type === "custom" ? (0, import_provider_utils16.resolveProviderReference)({
|
|
3175
|
+
reference: skill.providerReference,
|
|
3176
|
+
provider: "anthropic"
|
|
3177
|
+
}) : skill.skillId,
|
|
3168
3178
|
version: skill.version
|
|
3169
3179
|
}))
|
|
3170
3180
|
}
|
|
@@ -5237,14 +5247,136 @@ var anthropicTools = {
|
|
|
5237
5247
|
toolSearchBm25_20251119
|
|
5238
5248
|
};
|
|
5239
5249
|
|
|
5250
|
+
// src/skills/anthropic-skills.ts
|
|
5251
|
+
var import_provider_utils28 = require("@ai-sdk/provider-utils");
|
|
5252
|
+
|
|
5253
|
+
// src/skills/anthropic-skills-api.ts
|
|
5254
|
+
var import_provider_utils27 = require("@ai-sdk/provider-utils");
|
|
5255
|
+
var import_v424 = require("zod/v4");
|
|
5256
|
+
var anthropicSkillResponseSchema = (0, import_provider_utils27.lazySchema)(
|
|
5257
|
+
() => (0, import_provider_utils27.zodSchema)(
|
|
5258
|
+
import_v424.z.object({
|
|
5259
|
+
id: import_v424.z.string(),
|
|
5260
|
+
display_title: import_v424.z.string().nullish(),
|
|
5261
|
+
name: import_v424.z.string().nullish(),
|
|
5262
|
+
description: import_v424.z.string().nullish(),
|
|
5263
|
+
latest_version: import_v424.z.string().nullish(),
|
|
5264
|
+
source: import_v424.z.string(),
|
|
5265
|
+
created_at: import_v424.z.string(),
|
|
5266
|
+
updated_at: import_v424.z.string()
|
|
5267
|
+
})
|
|
5268
|
+
)
|
|
5269
|
+
);
|
|
5270
|
+
var anthropicSkillVersionListResponseSchema = (0, import_provider_utils27.lazySchema)(
|
|
5271
|
+
() => (0, import_provider_utils27.zodSchema)(
|
|
5272
|
+
import_v424.z.object({
|
|
5273
|
+
data: import_v424.z.array(
|
|
5274
|
+
import_v424.z.object({
|
|
5275
|
+
version: import_v424.z.string()
|
|
5276
|
+
})
|
|
5277
|
+
)
|
|
5278
|
+
})
|
|
5279
|
+
)
|
|
5280
|
+
);
|
|
5281
|
+
var anthropicSkillVersionResponseSchema = (0, import_provider_utils27.lazySchema)(
|
|
5282
|
+
() => (0, import_provider_utils27.zodSchema)(
|
|
5283
|
+
import_v424.z.object({
|
|
5284
|
+
type: import_v424.z.string(),
|
|
5285
|
+
skill_id: import_v424.z.string(),
|
|
5286
|
+
name: import_v424.z.string().nullish(),
|
|
5287
|
+
description: import_v424.z.string().nullish()
|
|
5288
|
+
})
|
|
5289
|
+
)
|
|
5290
|
+
);
|
|
5291
|
+
|
|
5292
|
+
// src/skills/anthropic-skills.ts
|
|
5293
|
+
var AnthropicSkills = class {
|
|
5294
|
+
constructor(config) {
|
|
5295
|
+
this.config = config;
|
|
5296
|
+
this.specificationVersion = "v4";
|
|
5297
|
+
}
|
|
5298
|
+
get provider() {
|
|
5299
|
+
return this.config.provider;
|
|
5300
|
+
}
|
|
5301
|
+
async getHeaders() {
|
|
5302
|
+
return (0, import_provider_utils28.combineHeaders)(await (0, import_provider_utils28.resolve)(this.config.headers), {
|
|
5303
|
+
"anthropic-beta": "skills-2025-10-02"
|
|
5304
|
+
});
|
|
5305
|
+
}
|
|
5306
|
+
async fetchVersionMetadata({
|
|
5307
|
+
skillId,
|
|
5308
|
+
version,
|
|
5309
|
+
headers
|
|
5310
|
+
}) {
|
|
5311
|
+
const { value: versionResponse } = await (0, import_provider_utils28.getFromApi)({
|
|
5312
|
+
url: `${this.config.baseURL}/skills/${skillId}/versions/${version}`,
|
|
5313
|
+
headers,
|
|
5314
|
+
failedResponseHandler: anthropicFailedResponseHandler,
|
|
5315
|
+
successfulResponseHandler: (0, import_provider_utils28.createJsonResponseHandler)(
|
|
5316
|
+
anthropicSkillVersionResponseSchema
|
|
5317
|
+
),
|
|
5318
|
+
fetch: this.config.fetch
|
|
5319
|
+
});
|
|
5320
|
+
return {
|
|
5321
|
+
...versionResponse.name != null ? { name: versionResponse.name } : {},
|
|
5322
|
+
...versionResponse.description != null ? { description: versionResponse.description } : {}
|
|
5323
|
+
};
|
|
5324
|
+
}
|
|
5325
|
+
async upload(params) {
|
|
5326
|
+
var _a, _b;
|
|
5327
|
+
const warnings = [];
|
|
5328
|
+
const formData = new FormData();
|
|
5329
|
+
if (params.displayTitle != null) {
|
|
5330
|
+
formData.append("display_title", params.displayTitle);
|
|
5331
|
+
}
|
|
5332
|
+
for (const file of params.files) {
|
|
5333
|
+
const content = typeof file.content === "string" ? (0, import_provider_utils28.convertBase64ToUint8Array)(file.content) : file.content;
|
|
5334
|
+
formData.append("files[]", new Blob([content]), file.path);
|
|
5335
|
+
}
|
|
5336
|
+
const headers = await this.getHeaders();
|
|
5337
|
+
const { value: response } = await (0, import_provider_utils28.postFormDataToApi)({
|
|
5338
|
+
url: `${this.config.baseURL}/skills`,
|
|
5339
|
+
headers,
|
|
5340
|
+
formData,
|
|
5341
|
+
failedResponseHandler: anthropicFailedResponseHandler,
|
|
5342
|
+
successfulResponseHandler: (0, import_provider_utils28.createJsonResponseHandler)(
|
|
5343
|
+
anthropicSkillResponseSchema
|
|
5344
|
+
),
|
|
5345
|
+
fetch: this.config.fetch
|
|
5346
|
+
});
|
|
5347
|
+
const versionMetadata = response.latest_version != null ? await this.fetchVersionMetadata({
|
|
5348
|
+
skillId: response.id,
|
|
5349
|
+
version: response.latest_version,
|
|
5350
|
+
headers
|
|
5351
|
+
}) : {};
|
|
5352
|
+
const name = (_a = versionMetadata.name) != null ? _a : response.name;
|
|
5353
|
+
const description = (_b = versionMetadata.description) != null ? _b : response.description;
|
|
5354
|
+
return {
|
|
5355
|
+
providerReference: { anthropic: response.id },
|
|
5356
|
+
...response.display_title != null ? { displayTitle: response.display_title } : {},
|
|
5357
|
+
...name != null ? { name } : {},
|
|
5358
|
+
...description != null ? { description } : {},
|
|
5359
|
+
...response.latest_version != null ? { latestVersion: response.latest_version } : {},
|
|
5360
|
+
providerMetadata: {
|
|
5361
|
+
anthropic: {
|
|
5362
|
+
...response.source != null ? { source: response.source } : {},
|
|
5363
|
+
...response.created_at != null ? { createdAt: response.created_at } : {},
|
|
5364
|
+
...response.updated_at != null ? { updatedAt: response.updated_at } : {}
|
|
5365
|
+
}
|
|
5366
|
+
},
|
|
5367
|
+
warnings
|
|
5368
|
+
};
|
|
5369
|
+
}
|
|
5370
|
+
};
|
|
5371
|
+
|
|
5240
5372
|
// src/version.ts
|
|
5241
|
-
var VERSION = true ? "4.0.0-beta.
|
|
5373
|
+
var VERSION = true ? "4.0.0-beta.21" : "0.0.0-test";
|
|
5242
5374
|
|
|
5243
5375
|
// src/anthropic-provider.ts
|
|
5244
5376
|
function createAnthropic(options = {}) {
|
|
5245
5377
|
var _a, _b;
|
|
5246
|
-
const baseURL = (_a = (0,
|
|
5247
|
-
(0,
|
|
5378
|
+
const baseURL = (_a = (0, import_provider_utils29.withoutTrailingSlash)(
|
|
5379
|
+
(0, import_provider_utils29.loadOptionalSetting)({
|
|
5248
5380
|
settingValue: options.baseURL,
|
|
5249
5381
|
environmentVariableName: "ANTHROPIC_BASE_URL"
|
|
5250
5382
|
})
|
|
@@ -5258,13 +5390,13 @@ function createAnthropic(options = {}) {
|
|
|
5258
5390
|
}
|
|
5259
5391
|
const getHeaders = () => {
|
|
5260
5392
|
const authHeaders = options.authToken ? { Authorization: `Bearer ${options.authToken}` } : {
|
|
5261
|
-
"x-api-key": (0,
|
|
5393
|
+
"x-api-key": (0, import_provider_utils29.loadApiKey)({
|
|
5262
5394
|
apiKey: options.apiKey,
|
|
5263
5395
|
environmentVariableName: "ANTHROPIC_API_KEY",
|
|
5264
5396
|
description: "Anthropic"
|
|
5265
5397
|
})
|
|
5266
5398
|
};
|
|
5267
|
-
return (0,
|
|
5399
|
+
return (0, import_provider_utils29.withUserAgentSuffix)(
|
|
5268
5400
|
{
|
|
5269
5401
|
"anthropic-version": "2023-06-01",
|
|
5270
5402
|
...authHeaders,
|
|
@@ -5280,13 +5412,19 @@ function createAnthropic(options = {}) {
|
|
|
5280
5412
|
baseURL,
|
|
5281
5413
|
headers: getHeaders,
|
|
5282
5414
|
fetch: options.fetch,
|
|
5283
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
|
5415
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils29.generateId,
|
|
5284
5416
|
supportedUrls: () => ({
|
|
5285
5417
|
"image/*": [/^https?:\/\/.*$/],
|
|
5286
5418
|
"application/pdf": [/^https?:\/\/.*$/]
|
|
5287
5419
|
})
|
|
5288
5420
|
});
|
|
5289
5421
|
};
|
|
5422
|
+
const createSkills = () => new AnthropicSkills({
|
|
5423
|
+
provider: `${providerName.replace(".messages", "")}.skills`,
|
|
5424
|
+
baseURL,
|
|
5425
|
+
headers: getHeaders,
|
|
5426
|
+
fetch: options.fetch
|
|
5427
|
+
});
|
|
5290
5428
|
const provider = function(modelId) {
|
|
5291
5429
|
if (new.target) {
|
|
5292
5430
|
throw new Error(
|
|
@@ -5312,6 +5450,7 @@ function createAnthropic(options = {}) {
|
|
|
5312
5450
|
headers: getHeaders,
|
|
5313
5451
|
fetch: options.fetch
|
|
5314
5452
|
});
|
|
5453
|
+
provider.skills = createSkills;
|
|
5315
5454
|
provider.tools = anthropicTools;
|
|
5316
5455
|
return provider;
|
|
5317
5456
|
}
|