@newses/plugin-digest-summary 0.2.0 → 0.3.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/README.md +195 -30
- package/dist/digest.d.ts +64 -15
- package/dist/digest.js +254 -81
- package/dist/index.d.ts +22 -3
- package/dist/index.js +54 -25
- package/dist/prices.d.ts +8 -2
- package/dist/prices.js +12 -4
- package/dist/prompts.d.ts +23 -3
- package/dist/prompts.js +58 -20
- package/dist/providers/anthropic.d.ts +47 -0
- package/dist/providers/anthropic.js +126 -0
- package/dist/providers/bedrock.d.ts +25 -0
- package/dist/providers/bedrock.js +112 -0
- package/dist/providers/http.d.ts +24 -0
- package/dist/providers/http.js +77 -0
- package/dist/providers/index.d.ts +5 -0
- package/dist/providers/index.js +14 -0
- package/dist/providers/ollama.d.ts +9 -0
- package/dist/providers/ollama.js +137 -0
- package/dist/providers/openai.d.ts +9 -0
- package/dist/providers/openai.js +116 -0
- package/dist/providers/types.d.ts +65 -0
- package/dist/providers/types.js +1 -0
- package/dist/settings.d.ts +70 -3
- package/dist/settings.js +130 -7
- package/dist/tokens.d.ts +2 -0
- package/dist/tokens.js +2 -0
- package/package.json +10 -5
- package/dist/claude.d.ts +0 -19
- package/dist/claude.js +0 -49
package/dist/settings.d.ts
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Who writes the overview: Claude through the Anthropic API or through Amazon Bedrock, a model on
|
|
4
|
+
* an Ollama server, or one on a server speaking the OpenAI chat completions API (llama.cpp, vLLM,
|
|
5
|
+
* LM Studio, LocalAI…).
|
|
6
|
+
*/
|
|
7
|
+
export declare const PROVIDERS: readonly ["anthropic", "bedrock", "ollama", "openai"];
|
|
8
|
+
/** The Claude models an admin can choose: the current Opus, Sonnet, and Haiku. */
|
|
3
9
|
export declare const MODELS: readonly ["claude-opus-5-5", "claude-sonnet-5-5", "claude-haiku-5-5"];
|
|
10
|
+
/**
|
|
11
|
+
* Where Bedrock runs a request sent to its region: in any region worldwide, at Anthropic's list
|
|
12
|
+
* prices, or only within the region's geography (the US, the EU, Australia, Japan), for 10% more.
|
|
13
|
+
*/
|
|
14
|
+
export declare const BEDROCK_ROUTINGS: readonly ["global", "geography"];
|
|
15
|
+
/**
|
|
16
|
+
* Bedrock's geographic inference profiles for the Claude models an admin can choose: the regions
|
|
17
|
+
* requests may be sent to, and the models each has. Canada's regions use the US profile, which
|
|
18
|
+
* all three models have (https://docs.aws.amazon.com/bedrock/latest/userguide/, the model cards,
|
|
19
|
+
* November 2026). Other regions route globally only.
|
|
20
|
+
*/
|
|
21
|
+
export declare const BEDROCK_GEOGRAPHIES: {
|
|
22
|
+
readonly us: {
|
|
23
|
+
readonly name: "the US";
|
|
24
|
+
readonly regions: readonly ["us-east-1", "us-east-2", "us-west-1", "us-west-2", "ca-central-1", "ca-west-1"];
|
|
25
|
+
readonly models: readonly ["claude-opus-5-5", "claude-sonnet-5-5", "claude-haiku-5-5"];
|
|
26
|
+
};
|
|
27
|
+
readonly eu: {
|
|
28
|
+
readonly name: "the EU";
|
|
29
|
+
readonly regions: readonly ["eu-central-1", "eu-central-2", "eu-north-1", "eu-south-1", "eu-south-2", "eu-west-1", "eu-west-2", "eu-west-3"];
|
|
30
|
+
readonly models: readonly ["claude-opus-5-5", "claude-sonnet-5-5", "claude-haiku-5-5"];
|
|
31
|
+
};
|
|
32
|
+
readonly au: {
|
|
33
|
+
readonly name: "Australia";
|
|
34
|
+
readonly regions: readonly ["ap-southeast-2", "ap-southeast-4"];
|
|
35
|
+
readonly models: readonly ["claude-opus-5-5", "claude-sonnet-5-5", "claude-haiku-5-5"];
|
|
36
|
+
};
|
|
37
|
+
readonly jp: {
|
|
38
|
+
readonly name: "Japan";
|
|
39
|
+
readonly regions: readonly ["ap-northeast-1", "ap-northeast-3"];
|
|
40
|
+
readonly models: readonly ["claude-opus-5-5", "claude-haiku-5-5"];
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export type BedrockGeography = keyof typeof BEDROCK_GEOGRAPHIES;
|
|
44
|
+
/** The geography a region's requests stay within, when Bedrock has one there. */
|
|
45
|
+
export declare function geographyOf(region: string): BedrockGeography | null;
|
|
4
46
|
/** How much the model thinks before it writes. */
|
|
5
47
|
export declare const EFFORTS: readonly ["low", "medium", "high"];
|
|
6
48
|
/** Which of a user's feeds the overview reads. */
|
|
@@ -40,9 +82,22 @@ export declare const DEFAULT_SECTIONS: readonly [{
|
|
|
40
82
|
readonly name: "Other";
|
|
41
83
|
readonly about: "Notable stories that fit no other section";
|
|
42
84
|
}];
|
|
43
|
-
/**
|
|
85
|
+
/** The context a self-hosted model is given, in tokens, at least and by default. */
|
|
86
|
+
export declare const MIN_CONTEXT_TOKENS = 8192;
|
|
87
|
+
export declare const DEFAULT_CONTEXT_TOKENS = 16384;
|
|
88
|
+
/**
|
|
89
|
+
* What an admin sets for the server: who writes the overview and how it is reached, the model,
|
|
90
|
+
* the budgets, and what users may add. Anthropic needs the API key; Bedrock, its own API key; a
|
|
91
|
+
* self-hosted server, its URL.
|
|
92
|
+
*/
|
|
44
93
|
export declare const instanceSettings: z.ZodObject<{
|
|
45
|
-
|
|
94
|
+
provider: z.ZodDefault<z.ZodEnum<{
|
|
95
|
+
anthropic: "anthropic";
|
|
96
|
+
bedrock: "bedrock";
|
|
97
|
+
ollama: "ollama";
|
|
98
|
+
openai: "openai";
|
|
99
|
+
}>>;
|
|
100
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
46
101
|
model: z.ZodDefault<z.ZodEnum<{
|
|
47
102
|
"claude-opus-5-5": "claude-opus-5-5";
|
|
48
103
|
"claude-sonnet-5-5": "claude-sonnet-5-5";
|
|
@@ -53,6 +108,18 @@ export declare const instanceSettings: z.ZodObject<{
|
|
|
53
108
|
medium: "medium";
|
|
54
109
|
high: "high";
|
|
55
110
|
}>>;
|
|
111
|
+
bedrockApiKey: z.ZodOptional<z.ZodString>;
|
|
112
|
+
bedrockRegion: z.ZodDefault<z.ZodString>;
|
|
113
|
+
bedrockRouting: z.ZodDefault<z.ZodEnum<{
|
|
114
|
+
global: "global";
|
|
115
|
+
geography: "geography";
|
|
116
|
+
}>>;
|
|
117
|
+
baseUrl: z.ZodOptional<z.ZodURL>;
|
|
118
|
+
localApiKey: z.ZodOptional<z.ZodString>;
|
|
119
|
+
localModel: z.ZodDefault<z.ZodString>;
|
|
120
|
+
contextTokens: z.ZodDefault<z.ZodNumber>;
|
|
121
|
+
parallelRequests: z.ZodDefault<z.ZodNumber>;
|
|
122
|
+
thinking: z.ZodDefault<z.ZodBoolean>;
|
|
56
123
|
monthlyTokens: z.ZodDefault<z.ZodNumber>;
|
|
57
124
|
userMonthlyTokens: z.ZodDefault<z.ZodNumber>;
|
|
58
125
|
allowInstructions: z.ZodDefault<z.ZodBoolean>;
|
package/dist/settings.js
CHANGED
|
@@ -1,7 +1,64 @@
|
|
|
1
|
-
import { DIGEST_LIMITS, feeds, multiline, secret } from '@newses/plugin-api';
|
|
1
|
+
import { DIGEST_LIMITS, feeds, multiline, secret, shownWhen, url } from '@newses/plugin-api';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Who writes the overview: Claude through the Anthropic API or through Amazon Bedrock, a model on
|
|
5
|
+
* an Ollama server, or one on a server speaking the OpenAI chat completions API (llama.cpp, vLLM,
|
|
6
|
+
* LM Studio, LocalAI…).
|
|
7
|
+
*/
|
|
8
|
+
export const PROVIDERS = ['anthropic', 'bedrock', 'ollama', 'openai'];
|
|
9
|
+
/** The Claude models an admin can choose: the current Opus, Sonnet, and Haiku. */
|
|
4
10
|
export const MODELS = ['claude-opus-5-5', 'claude-sonnet-5-5', 'claude-haiku-5-5'];
|
|
11
|
+
/**
|
|
12
|
+
* Where Bedrock runs a request sent to its region: in any region worldwide, at Anthropic's list
|
|
13
|
+
* prices, or only within the region's geography (the US, the EU, Australia, Japan), for 10% more.
|
|
14
|
+
*/
|
|
15
|
+
export const BEDROCK_ROUTINGS = ['global', 'geography'];
|
|
16
|
+
/** An AWS region's code, such as `us-east-1` or `ap-southeast-2`. */
|
|
17
|
+
const BEDROCK_REGION = /^[a-z]{2}(-[a-z]+)+-\d{1,2}$/;
|
|
18
|
+
/**
|
|
19
|
+
* Bedrock's geographic inference profiles for the Claude models an admin can choose: the regions
|
|
20
|
+
* requests may be sent to, and the models each has. Canada's regions use the US profile, which
|
|
21
|
+
* all three models have (https://docs.aws.amazon.com/bedrock/latest/userguide/, the model cards,
|
|
22
|
+
* November 2026). Other regions route globally only.
|
|
23
|
+
*/
|
|
24
|
+
export const BEDROCK_GEOGRAPHIES = {
|
|
25
|
+
us: {
|
|
26
|
+
name: 'the US',
|
|
27
|
+
regions: ['us-east-1', 'us-east-2', 'us-west-1', 'us-west-2', 'ca-central-1', 'ca-west-1'],
|
|
28
|
+
models: ['claude-opus-5-5', 'claude-sonnet-5-5', 'claude-haiku-5-5'],
|
|
29
|
+
},
|
|
30
|
+
eu: {
|
|
31
|
+
name: 'the EU',
|
|
32
|
+
regions: [
|
|
33
|
+
'eu-central-1',
|
|
34
|
+
'eu-central-2',
|
|
35
|
+
'eu-north-1',
|
|
36
|
+
'eu-south-1',
|
|
37
|
+
'eu-south-2',
|
|
38
|
+
'eu-west-1',
|
|
39
|
+
'eu-west-2',
|
|
40
|
+
'eu-west-3',
|
|
41
|
+
],
|
|
42
|
+
models: ['claude-opus-5-5', 'claude-sonnet-5-5', 'claude-haiku-5-5'],
|
|
43
|
+
},
|
|
44
|
+
au: {
|
|
45
|
+
name: 'Australia',
|
|
46
|
+
regions: ['ap-southeast-2', 'ap-southeast-4'],
|
|
47
|
+
models: ['claude-opus-5-5', 'claude-sonnet-5-5', 'claude-haiku-5-5'],
|
|
48
|
+
},
|
|
49
|
+
jp: {
|
|
50
|
+
name: 'Japan',
|
|
51
|
+
regions: ['ap-northeast-1', 'ap-northeast-3'],
|
|
52
|
+
models: ['claude-opus-5-5', 'claude-haiku-5-5'],
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
/** The geography a region's requests stay within, when Bedrock has one there. */
|
|
56
|
+
export function geographyOf(region) {
|
|
57
|
+
for (const [geography, { regions }] of Object.entries(BEDROCK_GEOGRAPHIES))
|
|
58
|
+
if (regions.includes(region))
|
|
59
|
+
return geography;
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
5
62
|
/** How much the model thinks before it writes. */
|
|
6
63
|
export const EFFORTS = ['low', 'medium', 'high'];
|
|
7
64
|
/** Which of a user's feeds the overview reads. */
|
|
@@ -24,15 +81,81 @@ export const DEFAULT_SECTIONS = [
|
|
|
24
81
|
{ name: 'Culture', about: 'Arts, entertainment, books, games, and media' },
|
|
25
82
|
{ name: 'Other', about: 'Notable stories that fit no other section' },
|
|
26
83
|
];
|
|
84
|
+
/** The context a self-hosted model is given, in tokens, at least and by default. */
|
|
85
|
+
export const MIN_CONTEXT_TOKENS = 8_192;
|
|
86
|
+
export const DEFAULT_CONTEXT_TOKENS = 16_384;
|
|
27
87
|
const tokens = z.number().int().min(0).max(1_000_000_000);
|
|
28
|
-
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Settings the form shows only for Anthropic, for Claude from either, for Bedrock, for a
|
|
90
|
+
* self-hosted model, or for Ollama.
|
|
91
|
+
*/
|
|
92
|
+
const anthropicOnly = { provider: ['anthropic'] };
|
|
93
|
+
const claude = { provider: ['anthropic', 'bedrock'] };
|
|
94
|
+
const bedrockOnly = { provider: ['bedrock'] };
|
|
95
|
+
const selfHosted = { provider: ['ollama', 'openai'] };
|
|
96
|
+
const ollamaOnly = { provider: ['ollama'] };
|
|
97
|
+
/**
|
|
98
|
+
* What an admin sets for the server: who writes the overview and how it is reached, the model,
|
|
99
|
+
* the budgets, and what users may add. Anthropic needs the API key; Bedrock, its own API key; a
|
|
100
|
+
* self-hosted server, its URL.
|
|
101
|
+
*/
|
|
102
|
+
export const instanceSettings = z
|
|
103
|
+
.object({
|
|
104
|
+
provider: z.enum(PROVIDERS).default('anthropic'),
|
|
105
|
+
apiKey: shownWhen(anthropicOnly, secret().optional()),
|
|
106
|
+
model: shownWhen(claude, z.enum(MODELS).default('claude-opus-5-5')),
|
|
107
|
+
effort: shownWhen(claude, z.enum(EFFORTS).default('low')),
|
|
108
|
+
// Never the Anthropic key, which is sent only to Anthropic.
|
|
109
|
+
bedrockApiKey: shownWhen(bedrockOnly, secret().optional()),
|
|
110
|
+
bedrockRegion: shownWhen(bedrockOnly, z.string().trim().toLowerCase().regex(BEDROCK_REGION).default('us-east-1')),
|
|
111
|
+
bedrockRouting: shownWhen(bedrockOnly, z.enum(BEDROCK_ROUTINGS).default('global')),
|
|
112
|
+
baseUrl: shownWhen(selfHosted, url().optional()),
|
|
113
|
+
// Never the Anthropic key, which is sent only to Anthropic.
|
|
114
|
+
localApiKey: shownWhen(selfHosted, secret().optional()),
|
|
115
|
+
localModel: shownWhen(selfHosted, z.string().trim().min(1).max(200).default('qwen3:8b')),
|
|
116
|
+
contextTokens: shownWhen(selfHosted, z.number().int().min(MIN_CONTEXT_TOKENS).max(1_000_000).default(DEFAULT_CONTEXT_TOKENS)),
|
|
117
|
+
parallelRequests: shownWhen(selfHosted, z.number().int().min(1).max(6).default(1)),
|
|
118
|
+
thinking: shownWhen(ollamaOnly, z.boolean().default(false)),
|
|
33
119
|
monthlyTokens: tokens.default(10_000_000),
|
|
34
120
|
userMonthlyTokens: tokens.default(1_000_000),
|
|
35
121
|
allowInstructions: z.boolean().default(true),
|
|
122
|
+
})
|
|
123
|
+
.superRefine((settings, context) => {
|
|
124
|
+
if (settings.provider === 'anthropic' && !settings.apiKey)
|
|
125
|
+
context.addIssue({
|
|
126
|
+
code: 'custom',
|
|
127
|
+
path: ['apiKey'],
|
|
128
|
+
message: 'Anthropic needs an API key',
|
|
129
|
+
});
|
|
130
|
+
if (settings.provider === 'bedrock') {
|
|
131
|
+
if (!settings.bedrockApiKey)
|
|
132
|
+
context.addIssue({
|
|
133
|
+
code: 'custom',
|
|
134
|
+
path: ['bedrockApiKey'],
|
|
135
|
+
message: 'Bedrock needs an API key',
|
|
136
|
+
});
|
|
137
|
+
if (settings.bedrockRouting === 'geography') {
|
|
138
|
+
const geography = geographyOf(settings.bedrockRegion);
|
|
139
|
+
if (!geography)
|
|
140
|
+
context.addIssue({
|
|
141
|
+
code: 'custom',
|
|
142
|
+
path: ['bedrockRouting'],
|
|
143
|
+
message: `Bedrock routes requests from ${settings.bedrockRegion} only globally`,
|
|
144
|
+
});
|
|
145
|
+
else if (!BEDROCK_GEOGRAPHIES[geography].models.includes(settings.model))
|
|
146
|
+
context.addIssue({
|
|
147
|
+
code: 'custom',
|
|
148
|
+
path: ['bedrockRouting'],
|
|
149
|
+
message: `Bedrock has ${settings.model} within ${BEDROCK_GEOGRAPHIES[geography].name} only globally`,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if ((settings.provider === 'ollama' || settings.provider === 'openai') && !settings.baseUrl)
|
|
154
|
+
context.addIssue({
|
|
155
|
+
code: 'custom',
|
|
156
|
+
path: ['baseUrl'],
|
|
157
|
+
message: 'A self-hosted model needs its server’s URL',
|
|
158
|
+
});
|
|
36
159
|
});
|
|
37
160
|
/** A section of the overview, by name, with what goes in it. */
|
|
38
161
|
export const section = z.object({
|
package/dist/tokens.d.ts
ADDED
package/dist/tokens.js
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@newses/plugin-digest-summary",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "A Newses plugin that opens your email digest with an overview of the common themes of your unread articles, written by Claude",
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"description": "A Newses plugin that opens your email digest with an overview of the common themes of your unread articles, written by Claude, through Anthropic or Amazon Bedrock, or a self-hosted model (Ollama, llama.cpp, vLLM\u2026)",
|
|
5
5
|
"license": "AGPL-3.0-or-later",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -12,7 +12,12 @@
|
|
|
12
12
|
"newses-plugin",
|
|
13
13
|
"digest",
|
|
14
14
|
"claude",
|
|
15
|
-
"anthropic"
|
|
15
|
+
"anthropic",
|
|
16
|
+
"bedrock",
|
|
17
|
+
"aws",
|
|
18
|
+
"ollama",
|
|
19
|
+
"llm",
|
|
20
|
+
"self-hosted"
|
|
16
21
|
],
|
|
17
22
|
"type": "module",
|
|
18
23
|
"exports": {
|
|
@@ -38,12 +43,12 @@
|
|
|
38
43
|
"prepack": "npm run build"
|
|
39
44
|
},
|
|
40
45
|
"peerDependencies": {
|
|
41
|
-
"@newses/plugin-api": "^0.1.
|
|
46
|
+
"@newses/plugin-api": "^0.1.3",
|
|
42
47
|
"zod": "^4.6.7"
|
|
43
48
|
},
|
|
44
49
|
"devDependencies": {
|
|
45
50
|
"@eslint/js": "^10.0.1",
|
|
46
|
-
"@newses/plugin-api": "^0.1.
|
|
51
|
+
"@newses/plugin-api": "^0.1.3",
|
|
47
52
|
"@types/node": "^24.19.1",
|
|
48
53
|
"eslint": "^10.12.0",
|
|
49
54
|
"eslint-config-prettier": "^10.1.8",
|
package/dist/claude.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import Anthropic from '@anthropic-ai/sdk';
|
|
2
|
-
import type { InstanceSettings } from './settings.js';
|
|
3
|
-
/** The API's host, which an admin approves for the plugin. */
|
|
4
|
-
export declare const API_HOST = "api.anthropic.com";
|
|
5
|
-
/** Server-side fallback when the model declines, on direct requests only. */
|
|
6
|
-
export declare const FALLBACK_BETA = "server-side-fallback-2026-07-01";
|
|
7
|
-
/**
|
|
8
|
-
* A client sending requests through the hook's `fetch`, with the key from the settings. The host,
|
|
9
|
-
* key, and logging are set here, so nothing in the server's environment (`ANTHROPIC_*`) changes
|
|
10
|
-
* where requests go or what credentials they carry.
|
|
11
|
-
*/
|
|
12
|
-
export declare function clientFor(settings: Pick<InstanceSettings, 'apiKey'>, fetch: typeof globalThis.fetch): Anthropic;
|
|
13
|
-
/** The text a response ends with: its text blocks after any switch to a fallback model. */
|
|
14
|
-
export declare function finalText(content: readonly {
|
|
15
|
-
type: string;
|
|
16
|
-
text?: string;
|
|
17
|
-
}[]): string;
|
|
18
|
-
/** An API failure as people read it, without anything from the request. */
|
|
19
|
-
export declare function failureText(error: unknown): string;
|
package/dist/claude.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import Anthropic from '@anthropic-ai/sdk';
|
|
2
|
-
/** The API's host, which an admin approves for the plugin. */
|
|
3
|
-
export const API_HOST = 'api.anthropic.com';
|
|
4
|
-
/** Server-side fallback when the model declines, on direct requests only. */
|
|
5
|
-
export const FALLBACK_BETA = 'server-side-fallback-2026-07-01';
|
|
6
|
-
/**
|
|
7
|
-
* A client sending requests through the hook's `fetch`, with the key from the settings. The host,
|
|
8
|
-
* key, and logging are set here, so nothing in the server's environment (`ANTHROPIC_*`) changes
|
|
9
|
-
* where requests go or what credentials they carry.
|
|
10
|
-
*/
|
|
11
|
-
export function clientFor(settings, fetch) {
|
|
12
|
-
return new Anthropic({
|
|
13
|
-
apiKey: settings.apiKey,
|
|
14
|
-
authToken: null,
|
|
15
|
-
baseURL: `https://${API_HOST}`,
|
|
16
|
-
fetch,
|
|
17
|
-
maxRetries: 1,
|
|
18
|
-
timeout: 40_000,
|
|
19
|
-
logLevel: 'off',
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
/** The text a response ends with: its text blocks after any switch to a fallback model. */
|
|
23
|
-
export function finalText(content) {
|
|
24
|
-
const switched = content.findLastIndex((block) => block.type === 'fallback');
|
|
25
|
-
return content
|
|
26
|
-
.slice(switched + 1)
|
|
27
|
-
.map((block) => (block.type === 'text' ? (block.text ?? '') : ''))
|
|
28
|
-
.join('');
|
|
29
|
-
}
|
|
30
|
-
/** An API failure as people read it, without anything from the request. */
|
|
31
|
-
export function failureText(error) {
|
|
32
|
-
if (error instanceof Anthropic.AuthenticationError)
|
|
33
|
-
return 'The API key was refused (HTTP 401): check it in the server’s settings';
|
|
34
|
-
if (error instanceof Anthropic.PermissionDeniedError)
|
|
35
|
-
return 'The API key may not use this model (HTTP 403)';
|
|
36
|
-
if (error instanceof Anthropic.NotFoundError)
|
|
37
|
-
return 'The model was not found (HTTP 404)';
|
|
38
|
-
if (error instanceof Anthropic.RateLimitError)
|
|
39
|
-
return 'Rate limited by the API (HTTP 429)';
|
|
40
|
-
if (error instanceof Anthropic.APIConnectionTimeoutError)
|
|
41
|
-
return 'The API did not answer in time';
|
|
42
|
-
if (error instanceof Anthropic.APIConnectionError)
|
|
43
|
-
return error.cause instanceof Error
|
|
44
|
-
? `The API could not be reached: ${error.cause.message}`
|
|
45
|
-
: 'The API could not be reached';
|
|
46
|
-
if (error instanceof Anthropic.APIError && error.status !== undefined)
|
|
47
|
-
return `The API answered HTTP ${String(error.status)}`;
|
|
48
|
-
return error instanceof Error ? error.message : String(error);
|
|
49
|
-
}
|