@acentric/llm 0.0.0-stage → 0.1.0
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/README.md +128 -2
- package/dist/catalog/anthropic.d.ts +77 -0
- package/dist/catalog/anthropic.d.ts.map +1 -0
- package/dist/catalog/anthropic.js +73 -0
- package/dist/catalog/anthropic.js.map +1 -0
- package/dist/catalog/fireworks.d.ts +93 -0
- package/dist/catalog/fireworks.d.ts.map +1 -0
- package/dist/catalog/fireworks.js +117 -0
- package/dist/catalog/fireworks.js.map +1 -0
- package/dist/catalog/openai.d.ts +103 -0
- package/dist/catalog/openai.d.ts.map +1 -0
- package/dist/catalog/openai.js +102 -0
- package/dist/catalog/openai.js.map +1 -0
- package/dist/client/anthropic/errors.d.ts +4 -0
- package/dist/client/anthropic/errors.d.ts.map +1 -0
- package/dist/client/anthropic/errors.js +80 -0
- package/dist/client/anthropic/errors.js.map +1 -0
- package/dist/client/anthropic/request.d.ts +9 -0
- package/dist/client/anthropic/request.d.ts.map +1 -0
- package/dist/client/anthropic/request.js +232 -0
- package/dist/client/anthropic/request.js.map +1 -0
- package/dist/client/anthropic/response.d.ts +13 -0
- package/dist/client/anthropic/response.d.ts.map +1 -0
- package/dist/client/anthropic/response.js +207 -0
- package/dist/client/anthropic/response.js.map +1 -0
- package/dist/client/direct.d.ts +18 -0
- package/dist/client/direct.d.ts.map +1 -0
- package/dist/client/direct.js +104 -0
- package/dist/client/direct.js.map +1 -0
- package/dist/client/gateway.d.ts +43 -0
- package/dist/client/gateway.d.ts.map +1 -0
- package/dist/client/gateway.js +72 -0
- package/dist/client/gateway.js.map +1 -0
- package/dist/client/http.d.ts +41 -0
- package/dist/client/http.d.ts.map +1 -0
- package/dist/client/http.js +190 -0
- package/dist/client/http.js.map +1 -0
- package/dist/client/llm.d.ts +41 -0
- package/dist/client/llm.d.ts.map +1 -0
- package/dist/client/llm.js +100 -0
- package/dist/client/llm.js.map +1 -0
- package/dist/client/responses/errors.d.ts +13 -0
- package/dist/client/responses/errors.d.ts.map +1 -0
- package/dist/client/responses/errors.js +144 -0
- package/dist/client/responses/errors.js.map +1 -0
- package/dist/client/responses/profile.d.ts +50 -0
- package/dist/client/responses/profile.d.ts.map +1 -0
- package/dist/client/responses/profile.js +4 -0
- package/dist/client/responses/profile.js.map +1 -0
- package/dist/client/responses/providers.d.ts +4 -0
- package/dist/client/responses/providers.d.ts.map +1 -0
- package/dist/client/responses/providers.js +75 -0
- package/dist/client/responses/providers.js.map +1 -0
- package/dist/client/responses/request.d.ts +5 -0
- package/dist/client/responses/request.d.ts.map +1 -0
- package/dist/client/responses/request.js +248 -0
- package/dist/client/responses/request.js.map +1 -0
- package/dist/client/responses/response.d.ts +10 -0
- package/dist/client/responses/response.d.ts.map +1 -0
- package/dist/client/responses/response.js +176 -0
- package/dist/client/responses/response.js.map +1 -0
- package/dist/client/util.d.ts +21 -0
- package/dist/client/util.d.ts.map +1 -0
- package/dist/client/util.js +63 -0
- package/dist/client/util.js.map +1 -0
- package/dist/client.d.ts +9 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +10 -0
- package/dist/client.js.map +1 -0
- package/dist/content.d.ts +38 -0
- package/dist/content.d.ts.map +1 -0
- package/dist/content.js +5 -0
- package/dist/content.js.map +1 -0
- package/dist/convert/anthropic.d.ts +3 -0
- package/dist/convert/anthropic.d.ts.map +1 -0
- package/dist/convert/anthropic.js +114 -0
- package/dist/convert/anthropic.js.map +1 -0
- package/dist/convert/index.d.ts +12 -0
- package/dist/convert/index.d.ts.map +1 -0
- package/dist/convert/index.js +221 -0
- package/dist/convert/index.js.map +1 -0
- package/dist/convert/responses.d.ts +3 -0
- package/dist/convert/responses.d.ts.map +1 -0
- package/dist/convert/responses.js +197 -0
- package/dist/convert/responses.js.map +1 -0
- package/dist/convert/types.d.ts +88 -0
- package/dist/convert/types.d.ts.map +1 -0
- package/dist/convert/types.js +3 -0
- package/dist/convert/types.js.map +1 -0
- package/dist/cost.d.ts +18 -0
- package/dist/cost.d.ts.map +1 -0
- package/dist/cost.js +49 -0
- package/dist/cost.js.map +1 -0
- package/dist/failure.d.ts +90 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/failure.js +111 -0
- package/dist/failure.js.map +1 -0
- package/dist/fields.d.ts +14 -0
- package/dist/fields.d.ts.map +1 -0
- package/dist/fields.js +3 -0
- package/dist/fields.js.map +1 -0
- package/dist/formats/anthropic.d.ts +152 -0
- package/dist/formats/anthropic.d.ts.map +1 -0
- package/dist/formats/anthropic.js +7 -0
- package/dist/formats/anthropic.js.map +1 -0
- package/dist/formats/responses.d.ts +179 -0
- package/dist/formats/responses.d.ts.map +1 -0
- package/dist/formats/responses.js +9 -0
- package/dist/formats/responses.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/json.d.ts +6 -0
- package/dist/json.d.ts.map +1 -0
- package/dist/json.js +10 -0
- package/dist/json.js.map +1 -0
- package/dist/messages.d.ts +82 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +4 -0
- package/dist/messages.js.map +1 -0
- package/dist/model.d.ts +36 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/model.js +4 -0
- package/dist/model.js.map +1 -0
- package/dist/models.d.ts +9 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +19 -0
- package/dist/models.js.map +1 -0
- package/dist/providers/anthropic.d.ts +130 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +5 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/fireworks.d.ts +108 -0
- package/dist/providers/fireworks.d.ts.map +1 -0
- package/dist/providers/fireworks.js +6 -0
- package/dist/providers/fireworks.js.map +1 -0
- package/dist/providers/openai.d.ts +193 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +4 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers.d.ts +50 -0
- package/dist/providers.d.ts.map +1 -0
- package/dist/providers.js +5 -0
- package/dist/providers.js.map +1 -0
- package/dist/read/anthropic.d.ts +15 -0
- package/dist/read/anthropic.d.ts.map +1 -0
- package/dist/read/anthropic.js +56 -0
- package/dist/read/anthropic.js.map +1 -0
- package/dist/read/responses.d.ts +26 -0
- package/dist/read/responses.d.ts.map +1 -0
- package/dist/read/responses.js +121 -0
- package/dist/read/responses.js.map +1 -0
- package/dist/read.d.ts +32 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/read.js +73 -0
- package/dist/read.js.map +1 -0
- package/dist/request.d.ts +23 -0
- package/dist/request.d.ts.map +1 -0
- package/dist/request.js +4 -0
- package/dist/request.js.map +1 -0
- package/dist/response.d.ts +38 -0
- package/dist/response.d.ts.map +1 -0
- package/dist/response.js +4 -0
- package/dist/response.js.map +1 -0
- package/dist/secrets.d.ts +22 -0
- package/dist/secrets.d.ts.map +1 -0
- package/dist/secrets.js +35 -0
- package/dist/secrets.js.map +1 -0
- package/dist/tool-calls.d.ts +28 -0
- package/dist/tool-calls.d.ts.map +1 -0
- package/dist/tool-calls.js +4 -0
- package/dist/tool-calls.js.map +1 -0
- package/dist/tools.d.ts +33 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +4 -0
- package/dist/tools.js.map +1 -0
- package/dist/usage.d.ts +31 -0
- package/dist/usage.d.ts.map +1 -0
- package/dist/usage.js +3 -0
- package/dist/usage.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/package.json +33 -3
- package/src/catalog/anthropic.ts +83 -0
- package/src/catalog/fireworks.ts +121 -0
- package/src/catalog/openai.ts +133 -0
- package/src/client/anthropic/errors.ts +88 -0
- package/src/client/anthropic/request.ts +272 -0
- package/src/client/anthropic/response.ts +236 -0
- package/src/client/direct.ts +157 -0
- package/src/client/gateway.ts +120 -0
- package/src/client/http.ts +231 -0
- package/src/client/llm.ts +151 -0
- package/src/client/responses/errors.ts +166 -0
- package/src/client/responses/profile.ts +55 -0
- package/src/client/responses/providers.ts +87 -0
- package/src/client/responses/request.ts +326 -0
- package/src/client/responses/response.ts +203 -0
- package/src/client/util.ts +81 -0
- package/src/client.ts +20 -0
- package/src/content.ts +46 -0
- package/src/convert/anthropic.ts +115 -0
- package/src/convert/index.ts +275 -0
- package/src/convert/responses.ts +203 -0
- package/src/convert/types.ts +104 -0
- package/src/cost.ts +71 -0
- package/src/failure.ts +164 -0
- package/src/fields.ts +13 -0
- package/src/formats/anthropic.ts +191 -0
- package/src/formats/responses.ts +207 -0
- package/src/index.ts +44 -0
- package/src/json.ts +13 -0
- package/src/messages.ts +99 -0
- package/src/model.ts +41 -0
- package/src/models.ts +23 -0
- package/src/providers/anthropic.ts +137 -0
- package/src/providers/fireworks.ts +140 -0
- package/src/providers/openai.ts +275 -0
- package/src/providers.ts +59 -0
- package/src/read/anthropic.ts +64 -0
- package/src/read/responses.ts +159 -0
- package/src/read.ts +108 -0
- package/src/request.ts +28 -0
- package/src/response.ts +44 -0
- package/src/secrets.ts +40 -0
- package/src/tool-calls.ts +33 -0
- package/src/tools.ts +38 -0
- package/src/usage.ts +33 -0
- package/src/version.ts +6 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// OpenAI models. Standard prices in US dollars per million tokens, and limits,
|
|
2
|
+
// from https://developers.openai.com/api/docs/pricing and the model pages, as
|
|
3
|
+
// of October 2026. Long-context prices are for the whole request once the
|
|
4
|
+
// prompt is over 272,000 tokens.
|
|
5
|
+
function longContext(base, cost) {
|
|
6
|
+
return { base, tiers: [{ aboveInputTokens: 272_000, cost }] };
|
|
7
|
+
}
|
|
8
|
+
const GPT_6_LIMITS = { contextWindow: 1_050_000, maxOutputTokens: 128_000 };
|
|
9
|
+
const VISION = ['text', 'image'];
|
|
10
|
+
export const OPENAI_MODELS = [
|
|
11
|
+
{
|
|
12
|
+
provider: 'openai',
|
|
13
|
+
id: 'gpt-6-astra',
|
|
14
|
+
name: 'GPT-6 Astra',
|
|
15
|
+
...GPT_6_LIMITS,
|
|
16
|
+
input: VISION,
|
|
17
|
+
pricing: longContext({ input: 10, cacheRead: 1, cacheWrite: 12.5, output: 50 }, { input: 20, cacheRead: 2, output: 75 }),
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
provider: 'openai',
|
|
21
|
+
id: 'gpt-6.1-sol',
|
|
22
|
+
name: 'GPT-6.1 Sol',
|
|
23
|
+
...GPT_6_LIMITS,
|
|
24
|
+
input: VISION,
|
|
25
|
+
pricing: longContext({ input: 2, cacheRead: 0.1, cacheWrite: 2.5, output: 10 }, { input: 4, cacheRead: 0.2, output: 15 }),
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
provider: 'openai',
|
|
29
|
+
id: 'gpt-6-sol',
|
|
30
|
+
name: 'GPT-6 Sol',
|
|
31
|
+
...GPT_6_LIMITS,
|
|
32
|
+
input: VISION,
|
|
33
|
+
pricing: longContext({ input: 2, cacheRead: 0.2, cacheWrite: 2.5, output: 10 }, { input: 4, cacheRead: 0.4, output: 15 }),
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
provider: 'openai',
|
|
37
|
+
id: 'gpt-6-luna',
|
|
38
|
+
name: 'GPT-6 Luna',
|
|
39
|
+
...GPT_6_LIMITS,
|
|
40
|
+
input: VISION,
|
|
41
|
+
pricing: longContext({ input: 0.1, cacheRead: 0.01, cacheWrite: 0.125, output: 0.5 }, { input: 0.2, cacheRead: 0.02, output: 0.75 }),
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
provider: 'openai',
|
|
45
|
+
id: 'gpt-5.6-sol',
|
|
46
|
+
name: 'GPT-5.6 Sol',
|
|
47
|
+
...GPT_6_LIMITS,
|
|
48
|
+
input: VISION,
|
|
49
|
+
pricing: longContext({ input: 4, cacheRead: 0.4, cacheWrite: 5, output: 20 }, { input: 8, cacheRead: 0.8, output: 30 }),
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
provider: 'openai',
|
|
53
|
+
id: 'gpt-5.6-terra',
|
|
54
|
+
name: 'GPT-5.6 Terra',
|
|
55
|
+
...GPT_6_LIMITS,
|
|
56
|
+
input: VISION,
|
|
57
|
+
pricing: longContext({ input: 2, cacheRead: 0.2, cacheWrite: 2.5, output: 12 }, { input: 4, cacheRead: 0.4, output: 18 }),
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
provider: 'openai',
|
|
61
|
+
id: 'gpt-5.6-luna',
|
|
62
|
+
name: 'GPT-5.6 Luna',
|
|
63
|
+
...GPT_6_LIMITS,
|
|
64
|
+
input: VISION,
|
|
65
|
+
pricing: longContext({ input: 0.2, cacheRead: 0.02, cacheWrite: 0.25, output: 1.2 }, { input: 0.4, cacheRead: 0.04, output: 1.8 }),
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
provider: 'openai',
|
|
69
|
+
id: 'gpt-5.5',
|
|
70
|
+
name: 'GPT-5.5',
|
|
71
|
+
...GPT_6_LIMITS,
|
|
72
|
+
input: VISION,
|
|
73
|
+
pricing: longContext({ input: 5, cacheRead: 0.5, output: 30 }, { input: 10, cacheRead: 1, output: 45 }),
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
provider: 'openai',
|
|
77
|
+
id: 'gpt-5.4',
|
|
78
|
+
name: 'GPT-5.4',
|
|
79
|
+
...GPT_6_LIMITS,
|
|
80
|
+
input: VISION,
|
|
81
|
+
pricing: longContext({ input: 2.5, cacheRead: 0.25, output: 15 }, { input: 5, cacheRead: 0.5, output: 22.5 }),
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
provider: 'openai',
|
|
85
|
+
id: 'gpt-5.4-mini',
|
|
86
|
+
name: 'GPT-5.4 mini',
|
|
87
|
+
contextWindow: 400_000,
|
|
88
|
+
maxOutputTokens: 128_000,
|
|
89
|
+
input: VISION,
|
|
90
|
+
pricing: { base: { input: 0.75, cacheRead: 0.075, output: 4.5 } },
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
provider: 'openai',
|
|
94
|
+
id: 'gpt-4.1',
|
|
95
|
+
name: 'GPT-4.1',
|
|
96
|
+
contextWindow: 1_047_576,
|
|
97
|
+
maxOutputTokens: 32_768,
|
|
98
|
+
input: VISION,
|
|
99
|
+
pricing: { base: { input: 2, cacheRead: 0.5, output: 8 } },
|
|
100
|
+
},
|
|
101
|
+
];
|
|
102
|
+
//# sourceMappingURL=openai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../src/catalog/openai.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,8EAA8E;AAC9E,0EAA0E;AAC1E,iCAAiC;AAIjC,SAAS,WAAW,CAAC,IAAe,EAAE,IAAe;IACnD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,gBAAgB,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;AAChE,CAAC;AAED,MAAM,YAAY,GAAG,EAAE,aAAa,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAW,CAAC;AACrF,MAAM,MAAM,GAAG,CAAC,MAAM,EAAE,OAAO,CAAU,CAAC;AAE1C,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B;QACE,QAAQ,EAAE,QAAQ;QAClB,EAAE,EAAE,aAAa;QACjB,IAAI,EAAE,aAAa;QACnB,GAAG,YAAY;QACf,KAAK,EAAE,MAAM;QACb,OAAO,EAAE,WAAW,CAClB,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EACzD,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CACxC;KACF;IACD;QACE,QAAQ,EAAE,QAAQ;QAClB,EAAE,EAAE,aA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,OAAO,EAAE,WAAW,CAClB,EAAE,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAC3C,EAAE,KAAK,EAAE,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAC3C;KACF;IACD;QACE,QAAQ,EAAE,QAAQ;QAClB,EAAE,EAAE,cAAc;QAClB,IAAI,EAAE,cAAc;QACpB,aAAa,EAAE,OAAO;QACtB,eAAe,EAAE,OAAO;QACxB,KAAK,EAAE,MAAM;QACb,OAAO,EAAE,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE;KAClE;IACD;QACE,QAAQ,EAAE,QAAQ;QAClB,EAAE,EAAE,SAAS;QACb,IAAI,EAAE,SAAS;QACf,aAAa,EAAE,SAAS;QACxB,eAAe,EAAE,MAAM;QACvB,KAAK,EAAE,MAAM;QACb,OAAO,EAAE,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE;KAC3D;CACgD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/client/anthropic/errors.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAI5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAkB7C,wBAAgB,WAAW,CAAC,MAAM,EAAE,UAAU,GAAG,QAAQ,CA8BxD"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Anthropic failures read into LlmErrors. Anthropic answers
|
|
2
|
+
// `{ type: "error", error: { type, message, details? }, request_id }`; a 413
|
|
3
|
+
// and errors from its edge have other shapes, or a text body.
|
|
4
|
+
import { LlmError } from '../../failure.js';
|
|
5
|
+
import { isObject } from '../../json.js';
|
|
6
|
+
import { retryAfter } from '../http.js';
|
|
7
|
+
import { cut } from '../util.js';
|
|
8
|
+
const KIND_BY_TYPE = {
|
|
9
|
+
authentication_error: 'auth',
|
|
10
|
+
permission_error: 'auth',
|
|
11
|
+
billing_error: 'quota_exceeded',
|
|
12
|
+
not_found_error: 'not_found',
|
|
13
|
+
rate_limit_error: 'rate_limited',
|
|
14
|
+
request_too_large: 'invalid_request',
|
|
15
|
+
overloaded_error: 'overloaded',
|
|
16
|
+
timeout_error: 'timeout',
|
|
17
|
+
api_error: 'provider_error',
|
|
18
|
+
};
|
|
19
|
+
/** A validation message starts with the field at fault: `messages.1.content.0: …`. */
|
|
20
|
+
const FIELD_PREFIX = /^([A-Za-z_][\w-]*(?:\.[\w-]+)*): /;
|
|
21
|
+
export function httpFailure(answer) {
|
|
22
|
+
const { body, status, headers } = answer;
|
|
23
|
+
const error = isObject(body) && isObject(body['error']) ? body['error'] : undefined;
|
|
24
|
+
const type = typeof error?.['type'] === 'string' ? error['type'] : undefined;
|
|
25
|
+
const message = typeof error?.['message'] === 'string' ? error['message'] : undefined;
|
|
26
|
+
const details = isObject(error?.['details']) ? error['details'] : undefined;
|
|
27
|
+
const code = typeof details?.['error_code'] === 'string' ? details['error_code'] : undefined;
|
|
28
|
+
const param = message?.match(FIELD_PREFIX)?.[1];
|
|
29
|
+
const after = retryAfter(headers);
|
|
30
|
+
const shouldRetry = headers.get('x-should-retry');
|
|
31
|
+
return new LlmError(message ??
|
|
32
|
+
(typeof body === 'string' && body !== '' ? body : undefined) ??
|
|
33
|
+
`the Anthropic call failed with HTTP ${status}`, {
|
|
34
|
+
kind: classify(status, type, message, code),
|
|
35
|
+
provider: 'anthropic',
|
|
36
|
+
httpStatus: status,
|
|
37
|
+
providerError: cut(error ?? body),
|
|
38
|
+
...(code === undefined ? {} : { providerCode: code }),
|
|
39
|
+
...(type === undefined ? {} : { providerType: type }),
|
|
40
|
+
...(param === undefined ? {} : { providerParam: param }),
|
|
41
|
+
...(after === undefined ? {} : { retryAfterMs: after }),
|
|
42
|
+
...(shouldRetry === 'true'
|
|
43
|
+
? { retryable: true }
|
|
44
|
+
: shouldRetry === 'false'
|
|
45
|
+
? { retryable: false }
|
|
46
|
+
: {}),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function classify(status, type, message, code) {
|
|
50
|
+
// A usage tier's monthly spend cap: a rate limit that lasts until next month.
|
|
51
|
+
if (code === 'enforced_spend_limit_reached')
|
|
52
|
+
return 'quota_exceeded';
|
|
53
|
+
if (message !== undefined && type === 'invalid_request_error') {
|
|
54
|
+
// "prompt is too long: 205024 tokens > 200000 maximum", with no code.
|
|
55
|
+
if (/^prompt is too long/i.test(message))
|
|
56
|
+
return 'context_overflow';
|
|
57
|
+
if (/reached your specified (workspace )?API usage limits|credit balance is too low/i.test(message)) {
|
|
58
|
+
return 'quota_exceeded';
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const byType = type === undefined ? undefined : KIND_BY_TYPE[type];
|
|
62
|
+
if (byType !== undefined)
|
|
63
|
+
return byType;
|
|
64
|
+
if (status === 401 || status === 403)
|
|
65
|
+
return 'auth';
|
|
66
|
+
if (status === 402)
|
|
67
|
+
return 'quota_exceeded';
|
|
68
|
+
if (status === 404)
|
|
69
|
+
return 'not_found';
|
|
70
|
+
if (status === 429)
|
|
71
|
+
return 'rate_limited';
|
|
72
|
+
if (status === 503 || status === 529)
|
|
73
|
+
return 'overloaded';
|
|
74
|
+
if (status === 504)
|
|
75
|
+
return 'timeout';
|
|
76
|
+
if (status >= 500)
|
|
77
|
+
return 'provider_error';
|
|
78
|
+
return 'invalid_request';
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/client/anthropic/errors.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,6EAA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,CAAC;IAC3C,OAAO,iBAAiB,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { JsonObject } from '@acentric/types';
|
|
2
|
+
import type { LlmRequest } from '../../request.js';
|
|
3
|
+
export type AnthropicRequest = {
|
|
4
|
+
readonly body: JsonObject;
|
|
5
|
+
/** Beta names, for the `anthropic-beta` header. */
|
|
6
|
+
readonly betas: readonly string[];
|
|
7
|
+
};
|
|
8
|
+
export declare function buildRequest(request: LlmRequest<'anthropic'>): AnthropicRequest;
|
|
9
|
+
//# sourceMappingURL=request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../src/client/anthropic/request.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAQ,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAIxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAYnD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,mDAAmD;IACnD,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC,CAAC;AAEF,wBAAgB,YAAY,CAAC,OAAO,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,gBAAgB,CAkC/E"}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
// The body of an Anthropic create-message request. Each of the request's
|
|
2
|
+
// messages becomes one Anthropic message. As for the Responses format, every
|
|
3
|
+
// shape is checked as it is written.
|
|
4
|
+
import { isArray, isObject } from '../../json.js';
|
|
5
|
+
import { findModel } from '../../models.js';
|
|
6
|
+
import { invalidRequest, ownFields, plainText, show } from '../util.js';
|
|
7
|
+
const PROVIDER = 'anthropic';
|
|
8
|
+
const LABEL = 'Anthropic';
|
|
9
|
+
/** Request fields the request itself sets. */
|
|
10
|
+
const OWNED_OPTIONS = ['model', 'messages', 'system'];
|
|
11
|
+
/** The output limit for a model the catalog does not know: the Claude 5 maximum. */
|
|
12
|
+
const DEFAULT_MAX_TOKENS = 128_000;
|
|
13
|
+
export function buildRequest(request) {
|
|
14
|
+
const options = ownFields(PROVIDER, request.options, OWNED_OPTIONS, 'request', 'options');
|
|
15
|
+
if (options['stream'] === true) {
|
|
16
|
+
throw invalidRequest(PROVIDER, 'streaming is not supported: a call returns one finished response');
|
|
17
|
+
}
|
|
18
|
+
const { tools: nativeTools, betas, ...rest } = options;
|
|
19
|
+
if (nativeTools !== undefined && !isArray(nativeTools)) {
|
|
20
|
+
throw invalidRequest(PROVIDER, 'options.tools must be an array of native tool definitions');
|
|
21
|
+
}
|
|
22
|
+
const messages = request.messages;
|
|
23
|
+
if (!isArray(messages))
|
|
24
|
+
throw invalidRequest(PROVIDER, 'messages must be an array');
|
|
25
|
+
const tools = [
|
|
26
|
+
...(request.tools ?? []).map((tool, index) => buildTool(tool, `tools[${index}]`)),
|
|
27
|
+
...(nativeTools ?? []),
|
|
28
|
+
];
|
|
29
|
+
const system = buildSystem(request.instructions);
|
|
30
|
+
const maxTokens = rest['max_tokens'] ?? findModel(PROVIDER, request.model)?.maxOutputTokens ?? DEFAULT_MAX_TOKENS;
|
|
31
|
+
return {
|
|
32
|
+
body: {
|
|
33
|
+
...rest,
|
|
34
|
+
model: request.model,
|
|
35
|
+
max_tokens: maxTokens,
|
|
36
|
+
...(system === undefined ? {} : { system }),
|
|
37
|
+
messages: messages.flatMap((message, index) => buildMessage(message, `messages[${index}]`, request.model)),
|
|
38
|
+
...(tools.length > 0 ? { tools } : {}),
|
|
39
|
+
},
|
|
40
|
+
betas: readBetas(betas),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function readBetas(value) {
|
|
44
|
+
if (value === undefined)
|
|
45
|
+
return [];
|
|
46
|
+
if (isArray(value)) {
|
|
47
|
+
const names = value.filter((name) => typeof name === 'string' && /^[\w.-]+$/.test(name));
|
|
48
|
+
if (names.length === value.length)
|
|
49
|
+
return names;
|
|
50
|
+
}
|
|
51
|
+
throw invalidRequest(PROVIDER, 'options.betas must be an array of beta names, such as "compact-2026-01-12"');
|
|
52
|
+
}
|
|
53
|
+
/** A string stays a string; text parts become blocks, which may carry `cache_control`. */
|
|
54
|
+
function buildSystem(value) {
|
|
55
|
+
if (value === undefined || typeof value === 'string')
|
|
56
|
+
return value;
|
|
57
|
+
if (!isArray(value))
|
|
58
|
+
throw invalidRequest(PROVIDER, 'instructions must be a string or text parts');
|
|
59
|
+
return value.map((part, index) => textBlock(part, `instructions[${index}]`));
|
|
60
|
+
}
|
|
61
|
+
function buildMessage(message, where, model) {
|
|
62
|
+
if (!isObject(message))
|
|
63
|
+
throw invalidRequest(PROVIDER, `${where} must be a message`);
|
|
64
|
+
switch (message['role']) {
|
|
65
|
+
case 'user':
|
|
66
|
+
return [{ role: 'user', content: buildParts(message['content'], where) }];
|
|
67
|
+
case 'system': {
|
|
68
|
+
const content = message['content'];
|
|
69
|
+
if (!isArray(content))
|
|
70
|
+
throw invalidRequest(PROVIDER, `${where}.content must be an array of text parts`);
|
|
71
|
+
return [
|
|
72
|
+
{
|
|
73
|
+
role: 'system',
|
|
74
|
+
content: content.map((part, index) => textBlock(part, `${where}.content[${index}]`)),
|
|
75
|
+
},
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
case 'assistant': {
|
|
79
|
+
if (message['provider'] !== PROVIDER) {
|
|
80
|
+
throw invalidRequest(PROVIDER, `${where} is from ${show(message['provider'])}: convert it before sending it to ${LABEL}`);
|
|
81
|
+
}
|
|
82
|
+
const content = blocks(message['content'], where);
|
|
83
|
+
if (message['model'] === model)
|
|
84
|
+
return [{ role: 'assistant', content }];
|
|
85
|
+
// Another model's thinking is bound to it: some models read it, others
|
|
86
|
+
// ignore it without a word. Its other blocks are sent as written.
|
|
87
|
+
const kept = content.filter((block) => block['type'] !== 'thinking' && block['type'] !== 'redacted_thinking');
|
|
88
|
+
return kept.length > 0 ? [{ role: 'assistant', content: kept }] : [];
|
|
89
|
+
}
|
|
90
|
+
case 'native':
|
|
91
|
+
if (message['provider'] !== PROVIDER) {
|
|
92
|
+
throw invalidRequest(PROVIDER, `${where} holds ${show(message['provider'])} items, which ${LABEL} cannot take`);
|
|
93
|
+
}
|
|
94
|
+
return [{ role: 'user', content: blocks(message['content'], where) }];
|
|
95
|
+
case 'tool_result':
|
|
96
|
+
return [{ role: 'user', content: [buildToolResult(message, where)] }];
|
|
97
|
+
case 'custom':
|
|
98
|
+
throw invalidRequest(PROVIDER, `${where} is the application's own: leave custom messages out`);
|
|
99
|
+
default:
|
|
100
|
+
throw invalidRequest(PROVIDER, `${where} has an unknown role: ${show(message['role'])}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function blocks(value, where) {
|
|
104
|
+
if (!isArray(value))
|
|
105
|
+
throw invalidRequest(PROVIDER, `${where}.content must be an array of blocks`);
|
|
106
|
+
return value.map((block, index) => {
|
|
107
|
+
if (!isObject(block) || typeof block['type'] !== 'string') {
|
|
108
|
+
throw invalidRequest(PROVIDER, `${where}.content[${index}] must be a block with a type`);
|
|
109
|
+
}
|
|
110
|
+
return block;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function buildToolResult(message, where) {
|
|
114
|
+
const callId = message['toolCallId'];
|
|
115
|
+
if (typeof callId !== 'string' || callId === '') {
|
|
116
|
+
throw invalidRequest(PROVIDER, `${where}.toolCallId must be a string that is not empty`);
|
|
117
|
+
}
|
|
118
|
+
const toolType = message['toolType'] ?? 'function';
|
|
119
|
+
if (toolType === 'custom')
|
|
120
|
+
throw invalidRequest(PROVIDER, `${where} answers a custom tool, and ${LABEL} has none`);
|
|
121
|
+
if (toolType !== 'function')
|
|
122
|
+
throw invalidRequest(PROVIDER, `${where}.toolType must be function or custom`);
|
|
123
|
+
const isError = message['isError'];
|
|
124
|
+
if (isError !== undefined && typeof isError !== 'boolean') {
|
|
125
|
+
throw invalidRequest(PROVIDER, `${where}.isError must be true or false`);
|
|
126
|
+
}
|
|
127
|
+
const owned = ['type', 'tool_use_id', 'content', 'is_error'];
|
|
128
|
+
return {
|
|
129
|
+
...ownFields(PROVIDER, message['providerOptions'], owned, where),
|
|
130
|
+
type: 'tool_result',
|
|
131
|
+
tool_use_id: callId,
|
|
132
|
+
content: plainText(message['content']) ?? buildParts(message['content'], where),
|
|
133
|
+
...(isError === undefined ? {} : { is_error: isError }),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function textBlock(part, at) {
|
|
137
|
+
if (!isObject(part) || part['type'] !== 'text' || typeof part['text'] !== 'string') {
|
|
138
|
+
throw invalidRequest(PROVIDER, `${at} must be a text part`);
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
...ownFields(PROVIDER, part['providerOptions'], ['type', 'text'], at),
|
|
142
|
+
type: 'text',
|
|
143
|
+
text: part['text'],
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function buildParts(value, where) {
|
|
147
|
+
if (!isArray(value))
|
|
148
|
+
throw invalidRequest(PROVIDER, `${where}.content must be an array of parts`);
|
|
149
|
+
return value.map((part, index) => buildPart(part, `${where}.content[${index}]`));
|
|
150
|
+
}
|
|
151
|
+
function buildPart(part, at) {
|
|
152
|
+
if (!isObject(part))
|
|
153
|
+
throw invalidRequest(PROVIDER, `${at} must be a content part`);
|
|
154
|
+
const options = part['providerOptions'];
|
|
155
|
+
switch (part['type']) {
|
|
156
|
+
case 'text':
|
|
157
|
+
return textBlock(part, at);
|
|
158
|
+
case 'image':
|
|
159
|
+
return {
|
|
160
|
+
...ownFields(PROVIDER, options, ['type', 'source'], at),
|
|
161
|
+
type: 'image',
|
|
162
|
+
source: mediaSource(part['source'], at, false),
|
|
163
|
+
};
|
|
164
|
+
case 'file': {
|
|
165
|
+
const filename = part['filename'];
|
|
166
|
+
if (filename !== undefined && typeof filename !== 'string') {
|
|
167
|
+
throw invalidRequest(PROVIDER, `${at}.filename must be a string`);
|
|
168
|
+
}
|
|
169
|
+
const owned = filename === undefined ? ['type', 'source'] : ['type', 'source', 'title'];
|
|
170
|
+
return {
|
|
171
|
+
...ownFields(PROVIDER, options, owned, at),
|
|
172
|
+
type: 'document',
|
|
173
|
+
source: mediaSource(part['source'], at, true),
|
|
174
|
+
...(filename === undefined ? {} : { title: filename }),
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
default:
|
|
178
|
+
throw invalidRequest(PROVIDER, `${at} has an unknown type: ${show(part['type'])}`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/** A shared source as Anthropic's. A plain text document goes as text, the only way Anthropic takes it. */
|
|
182
|
+
function mediaSource(source, at, document) {
|
|
183
|
+
if (isObject(source)) {
|
|
184
|
+
const { type, url, id, data, mediaType } = source;
|
|
185
|
+
if (type === 'url' && typeof url === 'string')
|
|
186
|
+
return { type: 'url', url };
|
|
187
|
+
if (type === 'file_id' && typeof id === 'string')
|
|
188
|
+
return { type: 'file', file_id: id };
|
|
189
|
+
if (type === 'base64' && typeof data === 'string' && typeof mediaType === 'string') {
|
|
190
|
+
if (document && mediaType === 'text/plain') {
|
|
191
|
+
return { type: 'text', media_type: 'text/plain', data: decodeText(data, at) };
|
|
192
|
+
}
|
|
193
|
+
return { type: 'base64', media_type: mediaType, data };
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
throw invalidRequest(PROVIDER, `${at}.source must be a url, base64 or file_id source`);
|
|
197
|
+
}
|
|
198
|
+
function decodeText(base64, at) {
|
|
199
|
+
try {
|
|
200
|
+
const bytes = Uint8Array.from(atob(base64), (char) => char.codePointAt(0) ?? 0);
|
|
201
|
+
return new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
throw invalidRequest(PROVIDER, `${at}.source must hold UTF-8 text in base64 for text/plain`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function buildTool(tool, where) {
|
|
208
|
+
if (!isObject(tool) ||
|
|
209
|
+
typeof tool['name'] !== 'string' ||
|
|
210
|
+
typeof tool['description'] !== 'string') {
|
|
211
|
+
throw invalidRequest(PROVIDER, `${where} needs a type, a name and a description`);
|
|
212
|
+
}
|
|
213
|
+
const { name, description, parameters, strict } = tool;
|
|
214
|
+
const at = `tool ${name}`;
|
|
215
|
+
if (tool['type'] === 'custom') {
|
|
216
|
+
throw invalidRequest(PROVIDER, `${at} is a custom tool, which ${LABEL} cannot take: use a function tool`);
|
|
217
|
+
}
|
|
218
|
+
if (tool['type'] !== 'function')
|
|
219
|
+
throw invalidRequest(PROVIDER, `${where} has an unknown type: ${show(tool['type'])}`);
|
|
220
|
+
const owned = ['type', 'name', 'description', 'input_schema', 'strict'];
|
|
221
|
+
const fields = ownFields(PROVIDER, tool['providerOptions'], owned, at);
|
|
222
|
+
if (!isObject(parameters))
|
|
223
|
+
throw invalidRequest(PROVIDER, `${at}: parameters must be a JSON Schema object`);
|
|
224
|
+
return {
|
|
225
|
+
...fields,
|
|
226
|
+
name,
|
|
227
|
+
description,
|
|
228
|
+
input_schema: parameters,
|
|
229
|
+
...(strict === undefined ? {} : { strict }),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
//# sourceMappingURL=request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../../src/client/anthropic/request.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,6EAA6E;AAC7E,qCAAqC;AAIrC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAExE,MAAM,QAAQ,GAAG,WAAW,CAAC;AAC7B,MAAM,KAAK,GAAG,WAAW,CAAC;AAE1B,8CAA8C;AAC9C,MAAM,aAAa,GAAG,CAAC,OAAO,E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CAAC,CAAC,EAAE,CAAC,CAAC;IACxF,MAAM,KAAK,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,QAAQ,CAAC,CAAC;IACxE,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,iBAAiB,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;IACvE,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC;QACvB,MAAM,cAAc,CAAC,QAAQ,EAAE,GAAG,EAAE,2CAA2C,CAAC,CAAC;IACnF,OAAO;QACL,GAAG,MAAM;QACT,IAAI;QACJ,WAAW;QACX,YAAY,EAAE,UAAU;QACxB,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC;KAC5C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { JsonObject } from '@acentric/types';
|
|
2
|
+
import type { LlmRequest } from '../../request.js';
|
|
3
|
+
import type { LlmResponse } from '../../response.js';
|
|
4
|
+
import type { Usage } from '../../usage.js';
|
|
5
|
+
import type { JsonAnswer } from '../http.js';
|
|
6
|
+
export declare function parseResponse(request: LlmRequest<'anthropic'>, answer: JsonAnswer): LlmResponse<'anthropic'>;
|
|
7
|
+
/**
|
|
8
|
+
* Usage as the format reports it: `input_tokens` is only the uncached part.
|
|
9
|
+
* Where a request sampled more than once (compaction, a fallback model), the
|
|
10
|
+
* iterations hold the whole bill and the top-level counts leave some out.
|
|
11
|
+
*/
|
|
12
|
+
export declare function readUsage(raw: JsonObject): Usage;
|
|
13
|
+
//# sourceMappingURL=response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../../src/client/anthropic/response.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAKlD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAc,MAAM,mBAAmB,CAAC;AACjE,OAAO,KAAK,EAAE,KAAK,EAAa,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAoC7C,wBAAgB,aAAa,CAC3B,OAAO,EAAE,UAAU,CAAC,WAAW,CAAC,EAChC,MAAM,EAAE,UAAU,GACjB,WAAW,CAAC,WAAW,CAAC,CAmD1B;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,UAAU,GAAG,KAAK,CAMhD"}
|