@core-ai/anthropic 0.7.0 → 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 +23 -1
- package/dist/index.js +34 -34
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -18,11 +18,26 @@ 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
31
|
stopSequences: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
24
32
|
betas: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
25
33
|
outputConfig: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
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>>;
|
|
26
41
|
}, z.core.$strict>;
|
|
27
42
|
type AnthropicGenerateProviderOptions = z.infer<typeof anthropicGenerateProviderOptionsSchema>;
|
|
28
43
|
declare module '@core-ai/core-ai' {
|
|
@@ -35,7 +50,14 @@ declare const anthropicProviderOptionsSchema: z.ZodObject<{
|
|
|
35
50
|
stopSequences: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
36
51
|
betas: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
37
52
|
outputConfig: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
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>>;
|
|
38
60
|
}, z.core.$strict>;
|
|
39
61
|
type AnthropicProviderOptions = AnthropicGenerateProviderOptions;
|
|
40
62
|
|
|
41
|
-
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,9 +12,18 @@ import {
|
|
|
12
12
|
|
|
13
13
|
// src/chat-adapter.ts
|
|
14
14
|
import { APIError } from "@anthropic-ai/sdk";
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
asObject,
|
|
17
|
+
getProviderMetadata,
|
|
18
|
+
ProviderError,
|
|
19
|
+
safeParseJsonObject,
|
|
20
|
+
zodSchemaToJsonSchema
|
|
21
|
+
} from "@core-ai/core-ai";
|
|
16
22
|
|
|
17
23
|
// src/model-capabilities.ts
|
|
24
|
+
import {
|
|
25
|
+
stripModelDateSuffix
|
|
26
|
+
} from "@core-ai/core-ai";
|
|
18
27
|
var DEFAULT_CAPABILITIES = {
|
|
19
28
|
reasoning: {
|
|
20
29
|
thinkingMode: "adaptive",
|
|
@@ -77,45 +86,48 @@ var MODEL_CAPABILITIES = {
|
|
|
77
86
|
}
|
|
78
87
|
}
|
|
79
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
|
+
};
|
|
80
102
|
function getAnthropicModelCapabilities(modelId) {
|
|
81
103
|
const normalizedModelId = normalizeModelId(modelId);
|
|
82
104
|
return MODEL_CAPABILITIES[normalizedModelId] ?? DEFAULT_CAPABILITIES;
|
|
83
105
|
}
|
|
84
106
|
function normalizeModelId(modelId) {
|
|
85
|
-
return modelId
|
|
107
|
+
return stripModelDateSuffix(modelId);
|
|
86
108
|
}
|
|
87
109
|
function toAnthropicAdaptiveEffort(effort, supportsMaxEffort) {
|
|
88
|
-
if (effort === "minimal") {
|
|
89
|
-
return "low";
|
|
90
|
-
}
|
|
91
110
|
if (effort === "max") {
|
|
92
111
|
return supportsMaxEffort ? "max" : "high";
|
|
93
112
|
}
|
|
94
|
-
return effort;
|
|
113
|
+
return ANTHROPIC_ADAPTIVE_EFFORT_MAP[effort];
|
|
95
114
|
}
|
|
96
115
|
function toAnthropicManualBudget(effort) {
|
|
97
|
-
|
|
98
|
-
return 1024;
|
|
99
|
-
}
|
|
100
|
-
if (effort === "low") {
|
|
101
|
-
return 2048;
|
|
102
|
-
}
|
|
103
|
-
if (effort === "medium") {
|
|
104
|
-
return 8192;
|
|
105
|
-
}
|
|
106
|
-
if (effort === "high") {
|
|
107
|
-
return 32768;
|
|
108
|
-
}
|
|
109
|
-
return 65536;
|
|
116
|
+
return ANTHROPIC_MANUAL_BUDGET_MAP[effort];
|
|
110
117
|
}
|
|
111
118
|
|
|
112
119
|
// src/provider-options.ts
|
|
113
120
|
import { z } from "zod";
|
|
121
|
+
var anthropicCacheControlSchema = z.object({
|
|
122
|
+
type: z.literal("ephemeral"),
|
|
123
|
+
ttl: z.enum(["5m", "1h"]).optional()
|
|
124
|
+
}).strict();
|
|
114
125
|
var anthropicGenerateProviderOptionsSchema = z.object({
|
|
115
126
|
topK: z.number().int().optional(),
|
|
116
127
|
stopSequences: z.array(z.string()).optional(),
|
|
117
128
|
betas: z.array(z.string()).optional(),
|
|
118
|
-
outputConfig: z.record(z.string(), z.unknown()).optional()
|
|
129
|
+
outputConfig: z.record(z.string(), z.unknown()).optional(),
|
|
130
|
+
cacheControl: anthropicCacheControlSchema.optional()
|
|
119
131
|
}).strict();
|
|
120
132
|
function parseAnthropicGenerateProviderOptions(providerOptions) {
|
|
121
133
|
const rawOptions = providerOptions?.anthropic;
|
|
@@ -483,6 +495,7 @@ function mapAnthropicProviderOptionsToRequest(baseRequest, providerOptions) {
|
|
|
483
495
|
];
|
|
484
496
|
const mergedRequest = {
|
|
485
497
|
...baseRequest,
|
|
498
|
+
...providerOptions.cacheControl ? { cache_control: providerOptions.cacheControl } : {},
|
|
486
499
|
...providerOptions.topK !== void 0 ? { top_k: providerOptions.topK } : {},
|
|
487
500
|
...providerOptions.stopSequences ? { stop_sequences: providerOptions.stopSequences } : {},
|
|
488
501
|
...Object.keys(mergedOutputConfig).length > 0 ? { output_config: mergedOutputConfig } : {},
|
|
@@ -721,20 +734,6 @@ function mapStopReason(reason) {
|
|
|
721
734
|
}
|
|
722
735
|
return "unknown";
|
|
723
736
|
}
|
|
724
|
-
function safeParseJsonObject(json) {
|
|
725
|
-
try {
|
|
726
|
-
const parsed = JSON.parse(json);
|
|
727
|
-
return asObject(parsed);
|
|
728
|
-
} catch {
|
|
729
|
-
return {};
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
function asObject(value) {
|
|
733
|
-
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
734
|
-
return value;
|
|
735
|
-
}
|
|
736
|
-
return {};
|
|
737
|
-
}
|
|
738
737
|
function asStringArray(value) {
|
|
739
738
|
if (!Array.isArray(value)) {
|
|
740
739
|
return [];
|
|
@@ -971,6 +970,7 @@ function createAnthropic(options = {}) {
|
|
|
971
970
|
};
|
|
972
971
|
}
|
|
973
972
|
export {
|
|
973
|
+
anthropicCacheControlSchema,
|
|
974
974
|
anthropicGenerateProviderOptionsSchema,
|
|
975
975
|
anthropicProviderOptionsSchema,
|
|
976
976
|
createAnthropic
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@core-ai/anthropic",
|
|
3
|
-
"version": "0.7.
|
|
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,7 +42,7 @@
|
|
|
42
42
|
"test:watch": "vitest"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@core-ai/core-ai": "^0.7.
|
|
45
|
+
"@core-ai/core-ai": "^0.7.1",
|
|
46
46
|
"@anthropic-ai/sdk": "^0.78.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|