@core-ai/anthropic 0.6.1 → 0.7.1
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/dist/index.d.ts +29 -27
- package/dist/index.js +35 -37
- package/package.json +4 -5
package/dist/index.d.ts
CHANGED
|
@@ -18,22 +18,27 @@ type AnthropicReasoningMetadata = {
|
|
|
18
18
|
redactedData?: string;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
+
declare const anthropicCacheControlSchema: z.ZodObject<{
|
|
22
|
+
type: z.ZodLiteral<"ephemeral">;
|
|
23
|
+
ttl: z.ZodOptional<z.ZodEnum<{
|
|
24
|
+
"5m": "5m";
|
|
25
|
+
"1h": "1h";
|
|
26
|
+
}>>;
|
|
27
|
+
}, z.core.$strict>;
|
|
28
|
+
type AnthropicCacheControl = z.infer<typeof anthropicCacheControlSchema>;
|
|
21
29
|
declare const anthropicGenerateProviderOptionsSchema: z.ZodObject<{
|
|
22
30
|
topK: z.ZodOptional<z.ZodNumber>;
|
|
23
|
-
stopSequences: z.ZodOptional<z.ZodArray<z.ZodString
|
|
24
|
-
betas: z.ZodOptional<z.ZodArray<z.ZodString
|
|
31
|
+
stopSequences: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
32
|
+
betas: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
25
33
|
outputConfig: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
betas?: string[] | undefined;
|
|
35
|
-
outputConfig?: Record<string, unknown> | undefined;
|
|
36
|
-
}>;
|
|
34
|
+
cacheControl: z.ZodOptional<z.ZodObject<{
|
|
35
|
+
type: z.ZodLiteral<"ephemeral">;
|
|
36
|
+
ttl: z.ZodOptional<z.ZodEnum<{
|
|
37
|
+
"5m": "5m";
|
|
38
|
+
"1h": "1h";
|
|
39
|
+
}>>;
|
|
40
|
+
}, z.core.$strict>>;
|
|
41
|
+
}, z.core.$strict>;
|
|
37
42
|
type AnthropicGenerateProviderOptions = z.infer<typeof anthropicGenerateProviderOptionsSchema>;
|
|
38
43
|
declare module '@core-ai/core-ai' {
|
|
39
44
|
interface GenerateProviderOptions {
|
|
@@ -42,20 +47,17 @@ declare module '@core-ai/core-ai' {
|
|
|
42
47
|
}
|
|
43
48
|
declare const anthropicProviderOptionsSchema: z.ZodObject<{
|
|
44
49
|
topK: z.ZodOptional<z.ZodNumber>;
|
|
45
|
-
stopSequences: z.ZodOptional<z.ZodArray<z.ZodString
|
|
46
|
-
betas: z.ZodOptional<z.ZodArray<z.ZodString
|
|
50
|
+
stopSequences: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
51
|
+
betas: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
47
52
|
outputConfig: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
betas?: string[] | undefined;
|
|
57
|
-
outputConfig?: Record<string, unknown> | undefined;
|
|
58
|
-
}>;
|
|
53
|
+
cacheControl: z.ZodOptional<z.ZodObject<{
|
|
54
|
+
type: z.ZodLiteral<"ephemeral">;
|
|
55
|
+
ttl: z.ZodOptional<z.ZodEnum<{
|
|
56
|
+
"5m": "5m";
|
|
57
|
+
"1h": "1h";
|
|
58
|
+
}>>;
|
|
59
|
+
}, z.core.$strict>>;
|
|
60
|
+
}, z.core.$strict>;
|
|
59
61
|
type AnthropicProviderOptions = AnthropicGenerateProviderOptions;
|
|
60
62
|
|
|
61
|
-
export { type AnthropicGenerateProviderOptions, type AnthropicProviderOptions as AnthropicModelProviderOptions, type AnthropicProvider, type AnthropicProviderOptions$1 as AnthropicProviderOptions, type AnthropicReasoningMetadata, anthropicGenerateProviderOptionsSchema, anthropicProviderOptionsSchema, createAnthropic };
|
|
63
|
+
export { type AnthropicCacheControl, type AnthropicGenerateProviderOptions, type AnthropicProviderOptions as AnthropicModelProviderOptions, type AnthropicProvider, type AnthropicProviderOptions$1 as AnthropicProviderOptions, type AnthropicReasoningMetadata, anthropicCacheControlSchema, anthropicGenerateProviderOptionsSchema, anthropicProviderOptionsSchema, createAnthropic };
|
package/dist/index.js
CHANGED
|
@@ -12,10 +12,18 @@ import {
|
|
|
12
12
|
|
|
13
13
|
// src/chat-adapter.ts
|
|
14
14
|
import { APIError } from "@anthropic-ai/sdk";
|
|
15
|
-
import {
|
|
16
|
-
|
|
15
|
+
import {
|
|
16
|
+
asObject,
|
|
17
|
+
getProviderMetadata,
|
|
18
|
+
ProviderError,
|
|
19
|
+
safeParseJsonObject,
|
|
20
|
+
zodSchemaToJsonSchema
|
|
21
|
+
} from "@core-ai/core-ai";
|
|
17
22
|
|
|
18
23
|
// src/model-capabilities.ts
|
|
24
|
+
import {
|
|
25
|
+
stripModelDateSuffix
|
|
26
|
+
} from "@core-ai/core-ai";
|
|
19
27
|
var DEFAULT_CAPABILITIES = {
|
|
20
28
|
reasoning: {
|
|
21
29
|
thinkingMode: "adaptive",
|
|
@@ -78,45 +86,48 @@ var MODEL_CAPABILITIES = {
|
|
|
78
86
|
}
|
|
79
87
|
}
|
|
80
88
|
};
|
|
89
|
+
var ANTHROPIC_ADAPTIVE_EFFORT_MAP = {
|
|
90
|
+
minimal: "low",
|
|
91
|
+
low: "low",
|
|
92
|
+
medium: "medium",
|
|
93
|
+
high: "high"
|
|
94
|
+
};
|
|
95
|
+
var ANTHROPIC_MANUAL_BUDGET_MAP = {
|
|
96
|
+
minimal: 1024,
|
|
97
|
+
low: 2048,
|
|
98
|
+
medium: 8192,
|
|
99
|
+
high: 32768,
|
|
100
|
+
max: 65536
|
|
101
|
+
};
|
|
81
102
|
function getAnthropicModelCapabilities(modelId) {
|
|
82
103
|
const normalizedModelId = normalizeModelId(modelId);
|
|
83
104
|
return MODEL_CAPABILITIES[normalizedModelId] ?? DEFAULT_CAPABILITIES;
|
|
84
105
|
}
|
|
85
106
|
function normalizeModelId(modelId) {
|
|
86
|
-
return modelId
|
|
107
|
+
return stripModelDateSuffix(modelId);
|
|
87
108
|
}
|
|
88
109
|
function toAnthropicAdaptiveEffort(effort, supportsMaxEffort) {
|
|
89
|
-
if (effort === "minimal") {
|
|
90
|
-
return "low";
|
|
91
|
-
}
|
|
92
110
|
if (effort === "max") {
|
|
93
111
|
return supportsMaxEffort ? "max" : "high";
|
|
94
112
|
}
|
|
95
|
-
return effort;
|
|
113
|
+
return ANTHROPIC_ADAPTIVE_EFFORT_MAP[effort];
|
|
96
114
|
}
|
|
97
115
|
function toAnthropicManualBudget(effort) {
|
|
98
|
-
|
|
99
|
-
return 1024;
|
|
100
|
-
}
|
|
101
|
-
if (effort === "low") {
|
|
102
|
-
return 2048;
|
|
103
|
-
}
|
|
104
|
-
if (effort === "medium") {
|
|
105
|
-
return 8192;
|
|
106
|
-
}
|
|
107
|
-
if (effort === "high") {
|
|
108
|
-
return 32768;
|
|
109
|
-
}
|
|
110
|
-
return 65536;
|
|
116
|
+
return ANTHROPIC_MANUAL_BUDGET_MAP[effort];
|
|
111
117
|
}
|
|
112
118
|
|
|
113
119
|
// src/provider-options.ts
|
|
114
120
|
import { z } from "zod";
|
|
121
|
+
var anthropicCacheControlSchema = z.object({
|
|
122
|
+
type: z.literal("ephemeral"),
|
|
123
|
+
ttl: z.enum(["5m", "1h"]).optional()
|
|
124
|
+
}).strict();
|
|
115
125
|
var anthropicGenerateProviderOptionsSchema = z.object({
|
|
116
126
|
topK: z.number().int().optional(),
|
|
117
127
|
stopSequences: z.array(z.string()).optional(),
|
|
118
128
|
betas: z.array(z.string()).optional(),
|
|
119
|
-
outputConfig: z.record(z.string(), z.unknown()).optional()
|
|
129
|
+
outputConfig: z.record(z.string(), z.unknown()).optional(),
|
|
130
|
+
cacheControl: anthropicCacheControlSchema.optional()
|
|
120
131
|
}).strict();
|
|
121
132
|
function parseAnthropicGenerateProviderOptions(providerOptions) {
|
|
122
133
|
const rawOptions = providerOptions?.anthropic;
|
|
@@ -334,8 +345,7 @@ function createStructuredOutputOptions(options) {
|
|
|
334
345
|
};
|
|
335
346
|
}
|
|
336
347
|
function toAnthropicJsonSchema(schema) {
|
|
337
|
-
|
|
338
|
-
return normalizeAnthropicJsonSchema(rawSchema);
|
|
348
|
+
return normalizeAnthropicJsonSchema(zodSchemaToJsonSchema(schema));
|
|
339
349
|
}
|
|
340
350
|
function normalizeAnthropicJsonSchema(value) {
|
|
341
351
|
const normalized = normalizeAnthropicJsonValue(value);
|
|
@@ -485,6 +495,7 @@ function mapAnthropicProviderOptionsToRequest(baseRequest, providerOptions) {
|
|
|
485
495
|
];
|
|
486
496
|
const mergedRequest = {
|
|
487
497
|
...baseRequest,
|
|
498
|
+
...providerOptions.cacheControl ? { cache_control: providerOptions.cacheControl } : {},
|
|
488
499
|
...providerOptions.topK !== void 0 ? { top_k: providerOptions.topK } : {},
|
|
489
500
|
...providerOptions.stopSequences ? { stop_sequences: providerOptions.stopSequences } : {},
|
|
490
501
|
...Object.keys(mergedOutputConfig).length > 0 ? { output_config: mergedOutputConfig } : {},
|
|
@@ -723,20 +734,6 @@ function mapStopReason(reason) {
|
|
|
723
734
|
}
|
|
724
735
|
return "unknown";
|
|
725
736
|
}
|
|
726
|
-
function safeParseJsonObject(json) {
|
|
727
|
-
try {
|
|
728
|
-
const parsed = JSON.parse(json);
|
|
729
|
-
return asObject(parsed);
|
|
730
|
-
} catch {
|
|
731
|
-
return {};
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
function asObject(value) {
|
|
735
|
-
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
736
|
-
return value;
|
|
737
|
-
}
|
|
738
|
-
return {};
|
|
739
|
-
}
|
|
740
737
|
function asStringArray(value) {
|
|
741
738
|
if (!Array.isArray(value)) {
|
|
742
739
|
return [];
|
|
@@ -973,6 +970,7 @@ function createAnthropic(options = {}) {
|
|
|
973
970
|
};
|
|
974
971
|
}
|
|
975
972
|
export {
|
|
973
|
+
anthropicCacheControlSchema,
|
|
976
974
|
anthropicGenerateProviderOptionsSchema,
|
|
977
975
|
anthropicProviderOptionsSchema,
|
|
978
976
|
createAnthropic
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@core-ai/anthropic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Anthropic provider package for @core-ai/core-ai",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Omnifact (https://omnifact.ai)",
|
|
@@ -42,12 +42,11 @@
|
|
|
42
42
|
"test:watch": "vitest"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@core-ai/core-ai": "^0.
|
|
46
|
-
"@anthropic-ai/sdk": "^0.78.0"
|
|
47
|
-
"zod-to-json-schema": "^3.25.1"
|
|
45
|
+
"@core-ai/core-ai": "^0.7.1",
|
|
46
|
+
"@anthropic-ai/sdk": "^0.78.0"
|
|
48
47
|
},
|
|
49
48
|
"peerDependencies": {
|
|
50
|
-
"zod": "^
|
|
49
|
+
"zod": "^4.0.0"
|
|
51
50
|
},
|
|
52
51
|
"devDependencies": {
|
|
53
52
|
"@core-ai/eslint-config": "*",
|