@newses/plugin-digest-summary 0.3.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 +90 -10
- package/dist/digest.js +2 -2
- package/dist/index.d.ts +8 -1
- package/dist/index.js +16 -6
- package/dist/prices.d.ts +8 -2
- package/dist/prices.js +12 -4
- package/dist/providers/anthropic.d.ts +26 -6
- package/dist/providers/anthropic.js +35 -17
- package/dist/providers/bedrock.d.ts +25 -0
- package/dist/providers/bedrock.js +112 -0
- package/dist/providers/index.js +3 -0
- package/dist/settings.d.ts +49 -4
- package/dist/settings.js +93 -8
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
# Newses digest summary plugin
|
|
2
2
|
|
|
3
|
-
A [Newses](https://newses.app) server plugin that opens each user's email digest with an overview of what their unread articles are about: a lead on their common themes, then topic sections (world, politics, technology, sports…) whose points link the articles they draw on. Claude writes it through the Anthropic API, or a model you host yourself (Ollama, llama.cpp, vLLM, LM Studio…), with the sections, length, style, and instructions each user chooses.
|
|
3
|
+
A [Newses](https://newses.app) server plugin that opens each user's email digest with an overview of what their unread articles are about: a lead on their common themes, then topic sections (world, politics, technology, sports…) whose points link the articles they draw on. Claude writes it through the Anthropic API or Amazon Bedrock, or a model you host yourself (Ollama, llama.cpp, vLLM, LM Studio…), with the sections, length, style, and instructions each user chooses.
|
|
4
4
|
|
|
5
5
|
## What is sent, and to whom
|
|
6
6
|
|
|
7
7
|
- Requests go to the model an admin chooses:
|
|
8
8
|
- **Anthropic:** `api.anthropic.com`, with the server's API key, under the terms of that key's Anthropic account.
|
|
9
|
+
- **Amazon Bedrock:** `bedrock-runtime.REGION.amazonaws.com` in the region the admin sets, with the server's Bedrock API key, under the terms of that key's AWS account. Bedrock runs each request in any region worldwide, or only within the region's geography, as the admin chooses.
|
|
9
10
|
- **Self-hosted:** the server at the URL the admin sets, such as Ollama on the Newses stack's own Docker network. Nothing leaves your network unless that server is elsewhere.
|
|
10
11
|
- What is sent, for each digest:
|
|
11
12
|
- the digest's language;
|
|
@@ -21,7 +22,7 @@ A [Newses](https://newses.app) server plugin that opens each user's email digest
|
|
|
21
22
|
|
|
22
23
|
## Install
|
|
23
24
|
|
|
24
|
-
The server's operator installs it at an exact version, `@newses/plugin-digest-summary@0.3.
|
|
25
|
+
The server's operator installs it at an exact version, `@newses/plugin-digest-summary@0.3.1`. It needs a server with plugin API 0.1.3 or later, which links the articles sections cite and shows only the settings of the model's provider. A self-hosted model on a private network, such as the Docker network, also needs a server that knows `PLUGIN_TRUSTED_HOSTS`.
|
|
25
26
|
|
|
26
27
|
- **Docker:** add it to `PLUGINS` in `.env` and start with the plugins override ([Self-hosting](https://newses.app/guide/self-hosting#plugins)).
|
|
27
28
|
- **AWS:** add it to the stage's `plugins` in the deployment config, then `scripts/store-deploy-config.sh --apply --release STAGE` ([Plugins](https://newses.app/guide/plugins)).
|
|
@@ -30,9 +31,74 @@ Then, in Settings > Plugins:
|
|
|
30
31
|
|
|
31
32
|
1. An admin chooses where the model comes from, then turns the plugin on for the server:
|
|
32
33
|
- **Anthropic:** create an API key in the [Claude Console](https://platform.claude.com) (API keys), enter it, and approve the host `api.anthropic.com`.
|
|
34
|
+
- **Amazon Bedrock:** create a Bedrock API key with `scripts/bedrock-setup.mjs` (see [Amazon Bedrock](#amazon-bedrock)), choose "Amazon Bedrock (Claude)", enter the key and the region, and approve the region's host, such as `bedrock-runtime.us-east-1.amazonaws.com`.
|
|
33
35
|
- **Self-hosted:** approve the model server's host (`ollama`), choose "Ollama, self-hosted" or the OpenAI API, and set the server's URL, the model, and its context (see [Self-hosted models](#self-hosted-models)).
|
|
34
36
|
2. Each user who wants an overview turns it on for themselves under "For me", and chooses which feeds it reads, its sections, length, and style. "Send test" checks the key or the model server, says how many tokens this month used, and sends a test digest.
|
|
35
37
|
|
|
38
|
+
## Amazon Bedrock
|
|
39
|
+
|
|
40
|
+
Claude on Bedrock is billed to an AWS account, through Bedrock's Messages API at `https://bedrock-runtime.REGION.amazonaws.com/anthropic`, with a long-term Bedrock API key that belongs to an IAM user.
|
|
41
|
+
|
|
42
|
+
In a checkout of this repository, `scripts/bedrock-setup.mjs` does steps 1 to 3, asking for the region, routing, IAM user, and how long the key lasts. It shows what it will change and asks first. It keeps the key in an SSM parameter of the region as a SecureString (`/newses/USER/bedrock-api-key`, `--ssm NAME`, or `--no-ssm`), and prints the command that reads it back. Then it checks the key with the plugin's own request and lists what to enter in Newses. Rerun it to replace the key: it keeps the user, offers to delete the earlier key, and at AWS's limit of 2 keys per user deletes one first. It needs the AWS CLI 2.27.42 or later, signed in to the account that pays, with permission to manage IAM users and Bedrock model access:
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
npm install && npm run build
|
|
46
|
+
node scripts/bedrock-setup.mjs [--profile NAME] [--region us-east-1] [--routing global|geography] [--days 90]
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
By hand:
|
|
50
|
+
|
|
51
|
+
1. **Model access:** the first request for each model subscribes the account to it in AWS Marketplace. The key's IAM user may not subscribe, so subscribe first with credentials that may: open Claude Opus, Sonnet, and Haiku 5.5 in the Bedrock console's playground, or run `aws bedrock create-foundation-model-agreement` with the offer token from `aws bedrock list-foundation-model-agreement-offers`. `aws bedrock get-foundation-model-availability --model-id anthropic.claude-opus-5-5` shows the access status.
|
|
52
|
+
2. **An IAM user for the key**, allowed to invoke only these models through the region's inference profiles. In `bedrock-digest-policy.json`, with your region and account:
|
|
53
|
+
|
|
54
|
+
```json
|
|
55
|
+
{
|
|
56
|
+
"Version": "2012-10-17",
|
|
57
|
+
"Statement": [
|
|
58
|
+
{ "Effect": "Allow", "Action": "bedrock:CallWithBearerToken", "Resource": "*" },
|
|
59
|
+
{
|
|
60
|
+
"Effect": "Allow",
|
|
61
|
+
"Action": "bedrock:InvokeModel",
|
|
62
|
+
"Resource": "arn:aws:bedrock:REGION:ACCOUNT:inference-profile/*.anthropic.claude-*-5-5"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"Effect": "Allow",
|
|
66
|
+
"Action": "bedrock:InvokeModel",
|
|
67
|
+
"Resource": [
|
|
68
|
+
"arn:aws:bedrock:*::foundation-model/anthropic.claude-*-5-5",
|
|
69
|
+
"arn:aws:bedrock:::foundation-model/anthropic.claude-*-5-5"
|
|
70
|
+
],
|
|
71
|
+
"Condition": {
|
|
72
|
+
"StringLike": {
|
|
73
|
+
"bedrock:InferenceProfileArn": "arn:aws:bedrock:REGION:ACCOUNT:inference-profile/*.anthropic.claude-*-5-5"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
3. **The key**, which expires after the days you give it:
|
|
82
|
+
|
|
83
|
+
```sh
|
|
84
|
+
aws iam create-user --user-name newses-digest
|
|
85
|
+
aws iam put-user-policy --user-name newses-digest --policy-name bedrock-digest \
|
|
86
|
+
--policy-document file://bedrock-digest-policy.json
|
|
87
|
+
aws iam create-service-specific-credential --user-name newses-digest \
|
|
88
|
+
--service-name bedrock.amazonaws.com --credential-age-days 90
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
The key is `ServiceSpecificCredential.ServiceCredentialSecret` in the answer. Before it expires, create another, enter it, and delete the old one with `aws iam delete-service-specific-credential`.
|
|
92
|
+
|
|
93
|
+
4. **In Newses:** choose "Amazon Bedrock (Claude)", enter the key and the region, choose the routing, and approve the region's host. "Send test" sends a request of a few tokens to check the key, its permissions, and the model.
|
|
94
|
+
|
|
95
|
+
| Routing | Where Bedrock runs requests | Price | Model |
|
|
96
|
+
| ------------------------------ | -------------------------------------------------------------------------------- | ----------------------- | ------------------------------------------------------ |
|
|
97
|
+
| Any region worldwide (default) | Any commercial AWS region | Anthropic's list prices | `global.anthropic.claude-opus-5-5` |
|
|
98
|
+
| Within the region's geography | The US (with Canada's regions), the EU, Australia, or Japan, from a region there | 10% more | `us.`, `eu.`, `au.`, or `jp.anthropic.claude-opus-5-5` |
|
|
99
|
+
|
|
100
|
+
Sonnet 5.5 has no Japan geography; other regions route globally only.
|
|
101
|
+
|
|
36
102
|
## Self-hosted models
|
|
37
103
|
|
|
38
104
|
### Standalone Ollama with Docker
|
|
@@ -94,10 +160,13 @@ The form shows the settings of the provider chosen under "Model from"; the other
|
|
|
94
160
|
|
|
95
161
|
| Setting | Who | What it does |
|
|
96
162
|
| ------------------------------------- | ----- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
97
|
-
| Model from | Admin | Anthropic (default), Ollama, or a self-hosted server with the OpenAI API
|
|
163
|
+
| Model from | Admin | Anthropic (default), Amazon Bedrock, Ollama, or a self-hosted server with the OpenAI API |
|
|
98
164
|
| Anthropic API key | Admin | Every Anthropic request is billed to it; sent only to Anthropic; a secret |
|
|
99
|
-
| Claude model | Admin | With Anthropic: Claude Opus 5.5 (default), Sonnet 5.5, or Haiku 5.5
|
|
100
|
-
| Claude effort | Admin | With Anthropic: how much Claude thinks before it writes: low (default), medium, or high; higher costs more tokens and takes longer
|
|
165
|
+
| Claude model | Admin | With Anthropic or Bedrock: Claude Opus 5.5 (default), Sonnet 5.5, or Haiku 5.5 |
|
|
166
|
+
| Claude effort | Admin | With Anthropic or Bedrock: how much Claude thinks before it writes: low (default), medium, or high; higher costs more tokens and takes longer |
|
|
167
|
+
| Bedrock API key | Admin | A long-term Bedrock API key; every Bedrock request is billed to its AWS account; sent only to Bedrock; a secret |
|
|
168
|
+
| Bedrock region | Admin | The AWS region requests are sent to: `us-east-1` by default; its host must be approved |
|
|
169
|
+
| Bedrock routing | Admin | Any region worldwide (default), or within the region's geography for 10% more |
|
|
101
170
|
| Self-hosted server's URL | Admin | Ollama's (`http://ollama:11434`), or the OpenAI API's, ending in `/v1`; its host must be approved |
|
|
102
171
|
| Self-hosted server's key | Admin | Only if the server asks for one (an OpenAI API server started with a key, or an Ollama behind a proxy), sent as a bearer token; a secret |
|
|
103
172
|
| Self-hosted model | Admin | As the server names it: `qwen3:8b` by default |
|
|
@@ -130,23 +199,24 @@ The form shows the settings of the provider chosen under "Model from"; the other
|
|
|
130
199
|
- **When an answer is missing:** if a request fails, runs out of time, is declined, is cut off, or is not the format asked for, the digest goes out without an overview. When only some parts answer, the overview is written from them and its lead (or, without one, a note of its own) says how many articles it covers and how many parts ran out of time or failed.
|
|
131
200
|
- **Untrusted feed text:** it sits in the user turn, escaped inside tags. The system prompt says to summarise only, and to take no instructions from articles. The answer must be JSON of the overview, or of a part's themes, alone (structured outputs; Ollama's `format`, the OpenAI API's `response_format`). Small self-hosted models follow instructions in articles more readily than Claude, but the format still leaves room for nothing but a summary, and refs the plugin never gave are dropped.
|
|
132
201
|
- **The user's preferences:** a second system block, after the fixed one that is cached, gives the sections, length, lead, and the user's instructions, escaped. The model follows the instructions on what to cover and how to write; they cannot change the format, make articles anything but material, or ask for anything but a summary. Each user's instructions reach only their own digest, within their monthly budget.
|
|
133
|
-
- **Declined requests:** when Claude declines a request, the server's default fallback model answers instead (server-side fallback).
|
|
202
|
+
- **Declined requests:** when Claude declines a request through Anthropic, the server's default fallback model answers instead (server-side fallback). Bedrock has no server-side fallback, so a declined request leaves the digest without an overview.
|
|
134
203
|
- **Self-hosted context:** the plugin sizes each request to the context set, from an estimate of 3 characters a token, using 85% of it, and asks Ollama to refuse a prompt that does not fit rather than cut it short.
|
|
135
204
|
|
|
136
205
|
## Costs
|
|
137
206
|
|
|
138
|
-
With Anthropic, every request is billed to the API key at [Anthropic's prices](https://platform.claude.com/docs/en/about-claude/pricing), per million tokens of input and output; thinking counts as output. A self-hosted model costs nothing a token; its tokens still count against the budgets, which bound the time it spends.
|
|
207
|
+
With Anthropic, every request is billed to the API key at [Anthropic's prices](https://platform.claude.com/docs/en/about-claude/pricing), per million tokens of input and output; thinking counts as output. With Bedrock, AWS bills the key's account at [Bedrock's prices](https://aws.amazon.com/bedrock/pricing/): Anthropic's for global routing, and 10% more within a geography. A self-hosted model costs nothing a token; its tokens still count against the budgets, which bound the time it spends.
|
|
139
208
|
|
|
140
209
|
- **Size:** an article takes about 100 input tokens, so a digest of 1,000 unread articles reads about 100,000. The overview takes 1,000 to 8,000 output tokens, depending on length and effort.
|
|
141
210
|
- **Budget check:** before a digest, the plugin estimates its tokens. When the server's or the user's budget left is smaller than that, it makes no request.
|
|
142
211
|
- **What is counted:** every token, input and output, of every attempt, fallbacks included, against both budgets. "Send test" shows the counts.
|
|
143
|
-
- **Estimate:** "Estimate cost" under "For me" shows what the overview of a test digest now would cost, making no request. With a self-hosted model, it shows how many articles its context holds and, with Ollama, how long it would take at the speed it last answered at. With
|
|
212
|
+
- **Estimate:** "Estimate cost" under "For me" shows what the overview of a test digest now would cost, making no request. With a self-hosted model, it shows how many articles its context holds and, with Ollama, how long it would take at the speed it last answered at. With Claude: the tokens it expects, priced at Anthropic's list prices (10% more for Bedrock within a geography) for the three models as of November 2026 (5-minute cache writes at 1.25 times input; Haiku's higher price for prompts over 100,000 tokens), with 3,000 output tokens a part, and 3,000, 5,000, or 8,000 for the overview by length. It counts neither discounts nor answers from a fallback model, and says when the budget left would stop it.
|
|
144
213
|
|
|
145
214
|
To choose the effort, measure it on digests like yours, billed to your key:
|
|
146
215
|
|
|
147
216
|
```sh
|
|
148
217
|
npm install && npm run build
|
|
149
218
|
ANTHROPIC_API_KEY=sk-ant-... node scripts/measure-effort.mjs [DIGEST.json ...] --efforts low,medium,high [--copies 100] [--length brief|standard|detailed] [--instructions TEXT]
|
|
219
|
+
AWS_BEARER_TOKEN_BEDROCK=... node scripts/measure-effort.mjs --provider bedrock --region us-east-1 [--routing global|geography] [--efforts low]
|
|
150
220
|
```
|
|
151
221
|
|
|
152
222
|
Or a self-hosted model, with a server the script can reach (publish Ollama's port to `127.0.0.1` while you measure):
|
|
@@ -164,7 +234,17 @@ node scripts/measure-effort.mjs --provider openai --base-url http://localhost:80
|
|
|
164
234
|
|
|
165
235
|
A request that fails, is declined, or runs out of time leaves the digest without an overview, and never fails the digest. The server's log says why.
|
|
166
236
|
|
|
167
|
-
"Send test" says what to change for
|
|
237
|
+
"Send test" says what to change for Bedrock:
|
|
238
|
+
|
|
239
|
+
- a region whose host is not approved: add it under Approved hosts;
|
|
240
|
+
- a key refused (HTTP 401): enter a current one;
|
|
241
|
+
- a key that may not use the model in the region (HTTP 403): the IAM user's policy, or the account's access to the model;
|
|
242
|
+
- a model or profile the region does not have (HTTP 404 or 400, with Bedrock's message);
|
|
243
|
+
- the account's quota used up for now (HTTP 429).
|
|
244
|
+
|
|
245
|
+
The settings refuse routing within a geography that the region or the model does not have.
|
|
246
|
+
|
|
247
|
+
And for a self-hosted model:
|
|
168
248
|
|
|
169
249
|
- a host that is not approved: add it under Approved hosts;
|
|
170
250
|
- a host on a private network: the operator adds it to `PLUGIN_TRUSTED_HOSTS`;
|
|
@@ -176,7 +256,7 @@ A request that fails, is declined, or runs out of time leaves the digest without
|
|
|
176
256
|
|
|
177
257
|
Node 24 and npm: `npm install`, then `npm run check` (lint, typecheck, format check, tests) and `npm run build`.
|
|
178
258
|
|
|
179
|
-
- **Tests** run the hooks as the server does with `@newses/plugin-api/testing`, against a stand-in for the Anthropic, Ollama, and OpenAI APIs that answers with responses shaped as theirs (`src/test/`).
|
|
259
|
+
- **Tests** run the hooks as the server does with `@newses/plugin-api/testing`, against a stand-in for the Anthropic, Bedrock, Ollama, and OpenAI APIs that answers with responses shaped as theirs (`src/test/`).
|
|
180
260
|
- **Releases** are version tags (`v1.2.3`), published to npm with provenance by the Publish workflow. The plugin's `version` in `src/index.ts` and `package.json` must match.
|
|
181
261
|
|
|
182
262
|
## Licence
|
package/dist/digest.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DIGEST_LIMITS, } from '@newses/plugin-api';
|
|
2
2
|
import { PART_TOKENS } from './providers/anthropic.js';
|
|
3
3
|
import { MERGE_SYSTEM, mergePrompt, OVERVIEW_SYSTEM, overviewPrompt, PART_SYSTEM, partFormat, partPrompt, partThemes, preferencesText, readPart, readSections, sectionsFormat, sectionsOf, } from './prompts.js';
|
|
4
|
-
import { costOf, dollars, tokensIn } from './prices.js';
|
|
4
|
+
import { costOf, dollars, premiumOf, tokensIn } from './prices.js';
|
|
5
5
|
import { DEFAULT_SECTIONS, INSTRUCTIONS_LENGTH, } from './settings.js';
|
|
6
6
|
import { estimateTokens } from './tokens.js';
|
|
7
7
|
import { count, remaining } from './usage.js';
|
|
@@ -339,7 +339,7 @@ export async function estimate(options) {
|
|
|
339
339
|
return `A test digest now: ${articles}, about ${formatted(tokens)} tokens, more than the ${formatted(left)} left of this month's budget, so it would add nothing.`;
|
|
340
340
|
const { capacity } = provider;
|
|
341
341
|
if (capacity.kind === 'grow')
|
|
342
|
-
return `A test digest now: ${articles} in ${requests} to ${provider.label}, about ${formatted(tokens)} tokens, ${dollars(costOf(settings.model, plan.planned))}. The output is estimated.`;
|
|
342
|
+
return `A test digest now: ${articles} in ${requests} to ${provider.label}, about ${formatted(tokens)} tokens, ${dollars(costOf(settings.model, plan.planned, premiumOf(settings)))}. The output is estimated.`;
|
|
343
343
|
const held = count < plan.chosen
|
|
344
344
|
? `: the newest ${formatted(count)} of ${formatted(plan.chosen)}, as many as ${formatted(capacity.contextTokens)} tokens of context hold in ${String(plan.maxParts)} ${plan.maxParts === 1 ? 'request' : 'parts'}`
|
|
345
345
|
: '';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Opens each user's email digest with an overview of what their unread articles are about, in
|
|
3
3
|
* topic sections whose points link the articles they draw on, written by Claude through the
|
|
4
|
-
* Anthropic API or by a self-hosted model (Ollama, or a server with the OpenAI chat completions
|
|
4
|
+
* Anthropic API or Amazon Bedrock, or by a self-hosted model (Ollama, or a server with the OpenAI chat completions
|
|
5
5
|
* API) from the titles and excerpts of the unread articles the digest counts, of the feeds the
|
|
6
6
|
* user chooses, with the sections, length, style, and instructions the user chooses.
|
|
7
7
|
*/
|
|
8
8
|
declare const _default: import("@newses/plugin-api").PluginDefinition<import("zod").ZodObject<{
|
|
9
9
|
provider: import("zod").ZodDefault<import("zod").ZodEnum<{
|
|
10
10
|
anthropic: "anthropic";
|
|
11
|
+
bedrock: "bedrock";
|
|
11
12
|
ollama: "ollama";
|
|
12
13
|
openai: "openai";
|
|
13
14
|
}>>;
|
|
@@ -22,6 +23,12 @@ declare const _default: import("@newses/plugin-api").PluginDefinition<import("zo
|
|
|
22
23
|
medium: "medium";
|
|
23
24
|
high: "high";
|
|
24
25
|
}>>;
|
|
26
|
+
bedrockApiKey: import("zod").ZodOptional<import("zod").ZodString>;
|
|
27
|
+
bedrockRegion: import("zod").ZodDefault<import("zod").ZodString>;
|
|
28
|
+
bedrockRouting: import("zod").ZodDefault<import("zod").ZodEnum<{
|
|
29
|
+
global: "global";
|
|
30
|
+
geography: "geography";
|
|
31
|
+
}>>;
|
|
25
32
|
baseUrl: import("zod").ZodOptional<import("zod").ZodURL>;
|
|
26
33
|
localApiKey: import("zod").ZodOptional<import("zod").ZodString>;
|
|
27
34
|
localModel: import("zod").ZodDefault<import("zod").ZodString>;
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { definePlugin, DIGEST_LIMITS } from '@newses/plugin-api';
|
|
|
2
2
|
import { compose, estimate } from './digest.js';
|
|
3
3
|
import { providerFor } from './providers/index.js';
|
|
4
4
|
import { API_HOST } from './providers/anthropic.js';
|
|
5
|
+
import { BEDROCK_HOST_REGIONS, bedrockHost } from './providers/bedrock.js';
|
|
5
6
|
import { instanceSettings, userSettings } from './settings.js';
|
|
6
7
|
import { usedThisMonth } from './usage.js';
|
|
7
8
|
/** Of the digest's time, what is left unused, for counting what came back. */
|
|
@@ -12,31 +13,32 @@ const OLLAMA_HOST = 'ollama';
|
|
|
12
13
|
/**
|
|
13
14
|
* Opens each user's email digest with an overview of what their unread articles are about, in
|
|
14
15
|
* topic sections whose points link the articles they draw on, written by Claude through the
|
|
15
|
-
* Anthropic API or by a self-hosted model (Ollama, or a server with the OpenAI chat completions
|
|
16
|
+
* Anthropic API or Amazon Bedrock, or by a self-hosted model (Ollama, or a server with the OpenAI chat completions
|
|
16
17
|
* API) from the titles and excerpts of the unread articles the digest counts, of the feeds the
|
|
17
18
|
* user chooses, with the sections, length, style, and instructions the user chooses.
|
|
18
19
|
*/
|
|
19
20
|
export default definePlugin({
|
|
20
21
|
id: 'digest-summary',
|
|
21
22
|
// Keep in step with package.json; a test checks they match.
|
|
22
|
-
version: '0.3.
|
|
23
|
+
version: '0.3.1',
|
|
23
24
|
apiVersion: '^0.1.3',
|
|
24
25
|
scopes: ['user'],
|
|
25
|
-
hosts: [API_HOST, OLLAMA_HOST],
|
|
26
|
+
hosts: [API_HOST, ...BEDROCK_HOST_REGIONS.map(bedrockHost), OLLAMA_HOST],
|
|
26
27
|
settings: { instance: instanceSettings, user: userSettings },
|
|
27
28
|
messages: {
|
|
28
29
|
en: {
|
|
29
30
|
name: 'Digest summary',
|
|
30
|
-
description: 'Opens your email digest with an overview of what your unread articles are about, written by an AI model: a lead on their common themes, then topic sections whose points link the articles they draw on. The title, feed name, and first lines of the unread articles of the feeds you choose go, with your sections and instructions, to the model the server’s admin chose: Claude through Anthropic (api.anthropic.com), with the server’s API key under Anthropic’s commercial terms, or a model the server’s operator runs, at the address the admin set. Articles from feeds with a login, and pages you published, are never sent, nor are links.',
|
|
31
|
+
description: 'Opens your email digest with an overview of what your unread articles are about, written by an AI model: a lead on their common themes, then topic sections whose points link the articles they draw on. The title, feed name, and first lines of the unread articles of the feeds you choose go, with your sections and instructions, to the model the server’s admin chose: Claude through Anthropic (api.anthropic.com), with the server’s API key under Anthropic’s commercial terms; Claude through Amazon Bedrock (bedrock-runtime.REGION.amazonaws.com, in the region the admin set), with the server’s Bedrock API key under that AWS account’s terms; or a model the server’s operator runs, at the address the admin set. Articles from feeds with a login, and pages you published, are never sent, nor are links.',
|
|
31
32
|
'settings.provider': 'Model from',
|
|
32
|
-
'settings.provider.hint': 'Anthropic bills each request to the API key. A self-hosted model runs on a server you run, such as the Ollama of the plugin’s Docker example
|
|
33
|
+
'settings.provider.hint': 'Anthropic bills each request to the API key, and Amazon Bedrock to the AWS account of its API key. A self-hosted model runs on a server you run, such as the Ollama of the plugin’s Docker example. Each needs its host approved above.',
|
|
33
34
|
'settings.provider.option.anthropic': 'Anthropic (Claude)',
|
|
35
|
+
'settings.provider.option.bedrock': 'Amazon Bedrock (Claude)',
|
|
34
36
|
'settings.provider.option.ollama': 'Ollama, self-hosted',
|
|
35
37
|
'settings.provider.option.openai': 'Self-hosted server with the OpenAI API (llama.cpp, vLLM, LM Studio…)',
|
|
36
38
|
'settings.apiKey': 'Anthropic API key',
|
|
37
39
|
'settings.apiKey.hint': 'From the Claude Console (platform.claude.com), under API keys: every request is billed to it. Sent only to Anthropic. Stored as a secret.',
|
|
38
40
|
'settings.model': 'Claude model',
|
|
39
|
-
'settings.model.hint': 'Opus writes best, Haiku costs least.',
|
|
41
|
+
'settings.model.hint': 'Opus writes best, Haiku costs least. The same models on Bedrock.',
|
|
40
42
|
'settings.model.option.claude-opus-5-5': 'Claude Opus 5.5',
|
|
41
43
|
'settings.model.option.claude-sonnet-5-5': 'Claude Sonnet 5.5',
|
|
42
44
|
'settings.model.option.claude-haiku-5-5': 'Claude Haiku 5.5',
|
|
@@ -45,6 +47,14 @@ export default definePlugin({
|
|
|
45
47
|
'settings.effort.option.low': 'Low',
|
|
46
48
|
'settings.effort.option.medium': 'Medium',
|
|
47
49
|
'settings.effort.option.high': 'High',
|
|
50
|
+
'settings.bedrockApiKey': 'Bedrock API key',
|
|
51
|
+
'settings.bedrockApiKey.hint': 'A long-term Amazon Bedrock API key, from the Bedrock console (API keys) or the IAM user it belongs to, which needs bedrock:InvokeModel and bedrock:CallWithBearerToken: every request is billed to its AWS account. Give it an expiry and replace it before then. Sent only to Bedrock. Stored as a secret.',
|
|
52
|
+
'settings.bedrockRegion': 'Bedrock region',
|
|
53
|
+
'settings.bedrockRegion.hint': 'The AWS region requests are sent to, such as us-east-1 or eu-west-1. Approve its host above: bedrock-runtime.REGION.amazonaws.com.',
|
|
54
|
+
'settings.bedrockRouting': 'Bedrock routing',
|
|
55
|
+
'settings.bedrockRouting.hint': 'Where Bedrock may run each request. Within the region’s geography (the US, which includes Canada’s regions, the EU, Australia, or Japan) costs 10% more.',
|
|
56
|
+
'settings.bedrockRouting.option.global': 'Any region worldwide',
|
|
57
|
+
'settings.bedrockRouting.option.geography': 'Within the region’s geography',
|
|
48
58
|
'settings.baseUrl': 'Self-hosted server’s URL',
|
|
49
59
|
'settings.baseUrl.hint': 'Ollama’s, such as http://ollama:11434; or the OpenAI API’s, ending in /v1, such as http://llama:8080/v1. Its host must be approved above, and, on a private network, listed in the server’s PLUGIN_TRUSTED_HOSTS.',
|
|
50
60
|
'settings.localApiKey': 'Self-hosted server’s key',
|
package/dist/prices.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import type { InstanceSettings } from './settings.js';
|
|
2
|
+
/**
|
|
3
|
+
* What the settings' route costs, as a multiple of Anthropic's list prices: Bedrock's global
|
|
4
|
+
* routing costs the same, and routing within a geography 10% more, for Claude 4.5 and later
|
|
5
|
+
* (https://aws.amazon.com/bedrock/pricing/, November 2026).
|
|
6
|
+
*/
|
|
7
|
+
export declare const premiumOf: (settings: Pick<InstanceSettings, "provider" | "bedrockRouting">) => 1 | 1.1;
|
|
2
8
|
/** One request's tokens, by how they are billed; estimated before a digest. */
|
|
3
9
|
export interface RequestTokens {
|
|
4
10
|
input: number;
|
|
@@ -6,8 +12,8 @@ export interface RequestTokens {
|
|
|
6
12
|
cacheRead: number;
|
|
7
13
|
output: number;
|
|
8
14
|
}
|
|
9
|
-
/** What requests cost with a model, in US dollars. */
|
|
10
|
-
export declare function costOf(model: InstanceSettings['model'], requests: readonly RequestTokens[]): number;
|
|
15
|
+
/** What requests cost with a model, in US dollars, times a route's premium. */
|
|
16
|
+
export declare function costOf(model: InstanceSettings['model'], requests: readonly RequestTokens[], premium?: number): number;
|
|
11
17
|
/** Every token of some requests. */
|
|
12
18
|
export declare const tokensIn: (requests: readonly RequestTokens[]) => number;
|
|
13
19
|
/** US dollars for a message: `about $0.95`, or `less than $0.01`. */
|
package/dist/prices.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Anthropic's list prices for the models an admin can choose, standard tier, in US dollars per
|
|
3
|
-
* million tokens (https://platform.claude.com/docs/en/about-claude/pricing, November 2026)
|
|
3
|
+
* million tokens (https://platform.claude.com/docs/en/about-claude/pricing, November 2026), which
|
|
4
|
+
* Bedrock charges too for global routing.
|
|
4
5
|
* Haiku costs more for a request whose prompt is over `over.prompt` tokens. Discounts, other
|
|
5
6
|
* tiers, and fallbacks to other models are not counted, so costs are estimates.
|
|
6
7
|
*/
|
|
@@ -16,9 +17,15 @@ const PRICES = {
|
|
|
16
17
|
};
|
|
17
18
|
/** Writing the prompt cache (5 minutes) costs this many times input. */
|
|
18
19
|
const CACHE_WRITE = 1.25;
|
|
19
|
-
/**
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
/**
|
|
21
|
+
* What the settings' route costs, as a multiple of Anthropic's list prices: Bedrock's global
|
|
22
|
+
* routing costs the same, and routing within a geography 10% more, for Claude 4.5 and later
|
|
23
|
+
* (https://aws.amazon.com/bedrock/pricing/, November 2026).
|
|
24
|
+
*/
|
|
25
|
+
export const premiumOf = (settings) => settings.provider === 'bedrock' && settings.bedrockRouting === 'geography' ? 1.1 : 1;
|
|
26
|
+
/** What requests cost with a model, in US dollars, times a route's premium. */
|
|
27
|
+
export function costOf(model, requests, premium = 1) {
|
|
28
|
+
const cost = requests.reduce((sum, request) => {
|
|
22
29
|
const prompt = request.input + request.cacheWrite + request.cacheRead;
|
|
23
30
|
const base = PRICES[model];
|
|
24
31
|
const price = base.over && prompt > base.over.prompt ? base.over : base;
|
|
@@ -29,6 +36,7 @@ export function costOf(model, requests) {
|
|
|
29
36
|
request.output * price.output) /
|
|
30
37
|
1_000_000);
|
|
31
38
|
}, 0);
|
|
39
|
+
return cost * premium;
|
|
32
40
|
}
|
|
33
41
|
/** Every token of some requests. */
|
|
34
42
|
export const tokensIn = (requests) => requests.reduce((sum, r) => sum + r.input + r.cacheWrite + r.cacheRead + r.output, 0);
|
|
@@ -8,11 +8,16 @@ export declare const FALLBACK_BETA = "server-side-fallback-2026-07-01";
|
|
|
8
8
|
/** Input tokens one request reads at most; a larger digest is read in parts. */
|
|
9
9
|
export declare const PART_TOKENS = 100000;
|
|
10
10
|
/**
|
|
11
|
-
* A client sending requests through the hook's `fetch`, with
|
|
12
|
-
* key, and logging are set here, so
|
|
13
|
-
* where requests go or what
|
|
11
|
+
* A client sending requests through the hook's `fetch` to `baseURL`, with `apiKey` as a bearer
|
|
12
|
+
* token, or in `x-api-key` when `header` says so. The host, key, and logging are set here, so
|
|
13
|
+
* nothing in the server's environment (`ANTHROPIC_*`) changes where requests go or what
|
|
14
|
+
* credentials they carry.
|
|
14
15
|
*/
|
|
15
|
-
export declare function clientFor(
|
|
16
|
+
export declare function clientFor(options: {
|
|
17
|
+
baseURL: string;
|
|
18
|
+
apiKey: string | undefined;
|
|
19
|
+
header?: 'bearer' | 'x-api-key';
|
|
20
|
+
}, fetch: typeof globalThis.fetch): Anthropic;
|
|
16
21
|
/** The text a response ends with: its text blocks after any switch to a fallback model. */
|
|
17
22
|
export declare function finalText(content: readonly {
|
|
18
23
|
type: string;
|
|
@@ -21,7 +26,22 @@ export declare function finalText(content: readonly {
|
|
|
21
26
|
/** An API failure as people read it, without anything from the request. */
|
|
22
27
|
export declare function failureText(error: unknown): string;
|
|
23
28
|
/**
|
|
24
|
-
* Claude through
|
|
25
|
-
* server's default fallback model when the model declines
|
|
29
|
+
* Claude through a Messages API: the fixed prompt cached for every reader's digests, structured
|
|
30
|
+
* outputs, and, where the API has it, the server's default fallback model when the model declines.
|
|
26
31
|
*/
|
|
32
|
+
export declare function messagesProvider(options: {
|
|
33
|
+
name: Provider['name'];
|
|
34
|
+
label: string;
|
|
35
|
+
client: Anthropic;
|
|
36
|
+
/** The model as the API names it: `claude-opus-5-5`, `global.anthropic.claude-opus-5-5`. */
|
|
37
|
+
model: string;
|
|
38
|
+
effort: InstanceSettings['effort'];
|
|
39
|
+
/** Whether the API falls back to another model when the model declines. */
|
|
40
|
+
fallback: boolean;
|
|
41
|
+
check: (signal: AbortSignal) => Promise<{
|
|
42
|
+
ok: boolean;
|
|
43
|
+
message: string;
|
|
44
|
+
}>;
|
|
45
|
+
}): Provider;
|
|
46
|
+
/** Claude through the Anthropic API, with the server's default fallback model. */
|
|
27
47
|
export declare function anthropicProvider(settings: Pick<InstanceSettings, 'apiKey' | 'model' | 'effort'>, fetch: typeof globalThis.fetch): Provider;
|
|
@@ -9,15 +9,21 @@ export const PART_TOKENS = 100_000;
|
|
|
9
9
|
/** A request's `max_tokens`, thinking included. */
|
|
10
10
|
const MAX_TOKENS = 16_000;
|
|
11
11
|
/**
|
|
12
|
-
* A client sending requests through the hook's `fetch`, with
|
|
13
|
-
* key, and logging are set here, so
|
|
14
|
-
* where requests go or what
|
|
12
|
+
* A client sending requests through the hook's `fetch` to `baseURL`, with `apiKey` as a bearer
|
|
13
|
+
* token, or in `x-api-key` when `header` says so. The host, key, and logging are set here, so
|
|
14
|
+
* nothing in the server's environment (`ANTHROPIC_*`) changes where requests go or what
|
|
15
|
+
* credentials they carry.
|
|
15
16
|
*/
|
|
16
|
-
export function clientFor(
|
|
17
|
+
export function clientFor(options, fetch) {
|
|
18
|
+
const apiKey = options.apiKey ?? '';
|
|
17
19
|
return new Anthropic({
|
|
18
|
-
|
|
20
|
+
// Given in code, so the SDK reads no key, token, or profile of its own.
|
|
21
|
+
apiKey,
|
|
19
22
|
authToken: null,
|
|
20
|
-
|
|
23
|
+
...(options.header === 'x-api-key' && {
|
|
24
|
+
defaultHeaders: { authorization: null, 'x-api-key': apiKey },
|
|
25
|
+
}),
|
|
26
|
+
baseURL: options.baseURL,
|
|
21
27
|
fetch,
|
|
22
28
|
maxRetries: 1,
|
|
23
29
|
timeout: 40_000,
|
|
@@ -53,25 +59,24 @@ export function failureText(error) {
|
|
|
53
59
|
return error instanceof Error ? error.message : String(error);
|
|
54
60
|
}
|
|
55
61
|
/**
|
|
56
|
-
* Claude through
|
|
57
|
-
* server's default fallback model when the model declines
|
|
62
|
+
* Claude through a Messages API: the fixed prompt cached for every reader's digests, structured
|
|
63
|
+
* outputs, and, where the API has it, the server's default fallback model when the model declines.
|
|
58
64
|
*/
|
|
59
|
-
export function
|
|
60
|
-
const client =
|
|
65
|
+
export function messagesProvider(options) {
|
|
66
|
+
const { client } = options;
|
|
61
67
|
return {
|
|
62
|
-
name:
|
|
63
|
-
label:
|
|
68
|
+
name: options.name,
|
|
69
|
+
label: options.label,
|
|
64
70
|
capacity: { kind: 'grow', partTokens: PART_TOKENS },
|
|
65
71
|
parallel: 6,
|
|
66
72
|
async ask(request) {
|
|
67
73
|
let response;
|
|
68
74
|
try {
|
|
69
75
|
response = await client.beta.messages.create({
|
|
70
|
-
model:
|
|
76
|
+
model: options.model,
|
|
71
77
|
max_tokens: MAX_TOKENS,
|
|
72
|
-
betas: [FALLBACK_BETA],
|
|
73
|
-
|
|
74
|
-
output_config: { effort: settings.effort, format: request.format },
|
|
78
|
+
...(options.fallback && { betas: [FALLBACK_BETA], fallbacks: 'default' }),
|
|
79
|
+
output_config: { effort: options.effort, format: request.format },
|
|
75
80
|
// The fixed prompt first, cached for every reader's digests; then the reader's own.
|
|
76
81
|
system: [
|
|
77
82
|
{ type: 'text', text: request.system[0], cache_control: { type: 'ephemeral' } },
|
|
@@ -95,6 +100,19 @@ export function anthropicProvider(settings, fetch) {
|
|
|
95
100
|
return { ok: false, outcome: 'invalid', tokens };
|
|
96
101
|
return { ok: true, text: finalText(response.content), tokens };
|
|
97
102
|
},
|
|
103
|
+
check: options.check,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/** Claude through the Anthropic API, with the server's default fallback model. */
|
|
107
|
+
export function anthropicProvider(settings, fetch) {
|
|
108
|
+
const client = clientFor({ baseURL: `https://${API_HOST}`, apiKey: settings.apiKey }, fetch);
|
|
109
|
+
return messagesProvider({
|
|
110
|
+
name: 'anthropic',
|
|
111
|
+
label: `${settings.model} at ${settings.effort} effort`,
|
|
112
|
+
client,
|
|
113
|
+
model: settings.model,
|
|
114
|
+
effort: settings.effort,
|
|
115
|
+
fallback: true,
|
|
98
116
|
async check(signal) {
|
|
99
117
|
try {
|
|
100
118
|
await client.models.retrieve(settings.model, null, { signal });
|
|
@@ -104,5 +122,5 @@ export function anthropicProvider(settings, fetch) {
|
|
|
104
122
|
}
|
|
105
123
|
return { ok: true, message: `The API key works with ${settings.model}.` };
|
|
106
124
|
},
|
|
107
|
-
};
|
|
125
|
+
});
|
|
108
126
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type InstanceSettings } from '../settings.js';
|
|
2
|
+
import type { Provider } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* The regions whose hosts the plugin asks for, the most used with Claude, so an admin can pick
|
|
5
|
+
* theirs among them; an admin may approve any other region's host too.
|
|
6
|
+
*/
|
|
7
|
+
export declare const BEDROCK_HOST_REGIONS: readonly ["us-east-1", "us-east-2", "us-west-2", "ca-central-1", "eu-central-1", "eu-west-1", "eu-west-2", "eu-west-3", "ap-northeast-1", "ap-southeast-2"];
|
|
8
|
+
/** The host of Bedrock's runtime in a region, which an admin approves for the plugin. */
|
|
9
|
+
export declare const bedrockHost: (region: string) => string;
|
|
10
|
+
type BedrockSettings = Pick<InstanceSettings, 'bedrockApiKey' | 'bedrockRegion' | 'bedrockRouting' | 'model' | 'effort'>;
|
|
11
|
+
/**
|
|
12
|
+
* The inference profile a request names: `global.anthropic.claude-opus-5-5`, or, routed within
|
|
13
|
+
* the region's geography, `eu.anthropic.claude-opus-5-5`. The settings refuse a geography the
|
|
14
|
+
* region or model does not have.
|
|
15
|
+
*/
|
|
16
|
+
export declare function bedrockModel(settings: BedrockSettings): string;
|
|
17
|
+
/** A Bedrock failure as people read it, saying what to change, without anything from the request. */
|
|
18
|
+
export declare function bedrockFailureText(error: unknown, settings: BedrockSettings): string;
|
|
19
|
+
/**
|
|
20
|
+
* Claude through Amazon Bedrock's Messages API, at its runtime in the region set, with the server's
|
|
21
|
+
* Bedrock API key in `x-api-key`. As with Anthropic, the fixed prompt is cached and answers are
|
|
22
|
+
* held to the format; Bedrock has no server-side fallback, so a refusal is the answer.
|
|
23
|
+
*/
|
|
24
|
+
export declare function bedrockProvider(settings: BedrockSettings, fetch: typeof globalThis.fetch): Provider;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
2
|
+
import { BEDROCK_GEOGRAPHIES, geographyOf } from '../settings.js';
|
|
3
|
+
import { clientFor, messagesProvider } from './anthropic.js';
|
|
4
|
+
import { reachText } from './http.js';
|
|
5
|
+
/**
|
|
6
|
+
* The regions whose hosts the plugin asks for, the most used with Claude, so an admin can pick
|
|
7
|
+
* theirs among them; an admin may approve any other region's host too.
|
|
8
|
+
*/
|
|
9
|
+
export const BEDROCK_HOST_REGIONS = [
|
|
10
|
+
'us-east-1',
|
|
11
|
+
'us-east-2',
|
|
12
|
+
'us-west-2',
|
|
13
|
+
'ca-central-1',
|
|
14
|
+
'eu-central-1',
|
|
15
|
+
'eu-west-1',
|
|
16
|
+
'eu-west-2',
|
|
17
|
+
'eu-west-3',
|
|
18
|
+
'ap-northeast-1',
|
|
19
|
+
'ap-southeast-2',
|
|
20
|
+
];
|
|
21
|
+
/** The host of Bedrock's runtime in a region, which an admin approves for the plugin. */
|
|
22
|
+
export const bedrockHost = (region) => `bedrock-runtime.${region}.amazonaws.com`;
|
|
23
|
+
/**
|
|
24
|
+
* The inference profile a request names: `global.anthropic.claude-opus-5-5`, or, routed within
|
|
25
|
+
* the region's geography, `eu.anthropic.claude-opus-5-5`. The settings refuse a geography the
|
|
26
|
+
* region or model does not have.
|
|
27
|
+
*/
|
|
28
|
+
export function bedrockModel(settings) {
|
|
29
|
+
const geography = settings.bedrockRouting === 'geography' ? geographyOf(settings.bedrockRegion) : null;
|
|
30
|
+
return `${geography ?? 'global'}.anthropic.${settings.model}`;
|
|
31
|
+
}
|
|
32
|
+
/** Where requests may run, for the messages: `in us-east-1`, `in eu-west-1, within the EU`. */
|
|
33
|
+
function whereOf(settings) {
|
|
34
|
+
const geography = settings.bedrockRouting === 'geography' ? geographyOf(settings.bedrockRegion) : null;
|
|
35
|
+
return geography
|
|
36
|
+
? `in ${settings.bedrockRegion}, within ${BEDROCK_GEOGRAPHIES[geography].name}`
|
|
37
|
+
: `in ${settings.bedrockRegion}`;
|
|
38
|
+
}
|
|
39
|
+
/** The message in an error's body: AWS's `{message}`, or the Messages API's `{error: {message}}`. */
|
|
40
|
+
function detailOf(body) {
|
|
41
|
+
if (typeof body !== 'object' || body === null)
|
|
42
|
+
return null;
|
|
43
|
+
const record = body;
|
|
44
|
+
const nested = record.error;
|
|
45
|
+
const message = record.message ??
|
|
46
|
+
record.Message ??
|
|
47
|
+
(typeof nested === 'object' && nested !== null
|
|
48
|
+
? nested.message
|
|
49
|
+
: null);
|
|
50
|
+
return typeof message === 'string' && message ? message.slice(0, 200) : null;
|
|
51
|
+
}
|
|
52
|
+
/** A Bedrock failure as people read it, saying what to change, without anything from the request. */
|
|
53
|
+
export function bedrockFailureText(error, settings) {
|
|
54
|
+
const host = bedrockHost(settings.bedrockRegion);
|
|
55
|
+
const where = whereOf(settings);
|
|
56
|
+
if (error instanceof Anthropic.APIConnectionTimeoutError)
|
|
57
|
+
return `${host} did not answer in time`;
|
|
58
|
+
if (error instanceof Anthropic.APIConnectionError)
|
|
59
|
+
return reachText(error.cause ?? error, host);
|
|
60
|
+
if (error instanceof Anthropic.APIError && error.status !== undefined) {
|
|
61
|
+
const detail = detailOf(error.error);
|
|
62
|
+
const said = detail ? `: ${detail}` : '';
|
|
63
|
+
if (error.status === 401)
|
|
64
|
+
return 'Bedrock refused the API key (HTTP 401): check it in the server’s settings';
|
|
65
|
+
if (error.status === 403)
|
|
66
|
+
return `The Bedrock API key may not use ${settings.model} ${where} (HTTP 403): its IAM user needs bedrock:InvokeModel and bedrock:CallWithBearerToken, and the AWS account access to the model${said}`;
|
|
67
|
+
if (error.status === 404)
|
|
68
|
+
return `Bedrock has no ${settings.model} ${where} (HTTP 404)${said}`;
|
|
69
|
+
if (error.status === 429)
|
|
70
|
+
return `Rate limited by Bedrock (HTTP 429): the account’s quota for ${settings.model} ${where} is used up for now`;
|
|
71
|
+
return `Bedrock answered HTTP ${String(error.status)}${said}`;
|
|
72
|
+
}
|
|
73
|
+
return error instanceof Error ? error.message : String(error);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Claude through Amazon Bedrock's Messages API, at its runtime in the region set, with the server's
|
|
77
|
+
* Bedrock API key in `x-api-key`. As with Anthropic, the fixed prompt is cached and answers are
|
|
78
|
+
* held to the format; Bedrock has no server-side fallback, so a refusal is the answer.
|
|
79
|
+
*/
|
|
80
|
+
export function bedrockProvider(settings, fetch) {
|
|
81
|
+
const client = clientFor({
|
|
82
|
+
baseURL: `https://${bedrockHost(settings.bedrockRegion)}/anthropic`,
|
|
83
|
+
apiKey: settings.bedrockApiKey,
|
|
84
|
+
header: 'x-api-key',
|
|
85
|
+
}, fetch);
|
|
86
|
+
const model = bedrockModel(settings);
|
|
87
|
+
const where = whereOf(settings);
|
|
88
|
+
return messagesProvider({
|
|
89
|
+
name: 'bedrock',
|
|
90
|
+
label: `${settings.model} at ${settings.effort} effort on Bedrock ${where}`,
|
|
91
|
+
client,
|
|
92
|
+
model,
|
|
93
|
+
effort: settings.effort,
|
|
94
|
+
fallback: false,
|
|
95
|
+
// Bedrock's runtime neither lists models nor counts tokens for these, so a request of a few
|
|
96
|
+
// tokens checks the key, its permissions, and the model.
|
|
97
|
+
async check(signal) {
|
|
98
|
+
try {
|
|
99
|
+
await client.beta.messages.create({
|
|
100
|
+
model,
|
|
101
|
+
max_tokens: 16,
|
|
102
|
+
output_config: { effort: 'low' },
|
|
103
|
+
messages: [{ role: 'user', content: 'Hello' }],
|
|
104
|
+
}, { signal, timeout: 20_000, maxRetries: 0 });
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
return { ok: false, message: bedrockFailureText(error, settings) };
|
|
108
|
+
}
|
|
109
|
+
return { ok: true, message: `The Bedrock API key works with ${model} ${where}.` };
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
}
|
package/dist/providers/index.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { anthropicProvider } from './anthropic.js';
|
|
2
|
+
import { bedrockProvider } from './bedrock.js';
|
|
2
3
|
import { ollamaProvider } from './ollama.js';
|
|
3
4
|
import { openaiProvider } from './openai.js';
|
|
4
5
|
/** The model the settings choose, sending its requests through the hook's `fetch`. */
|
|
5
6
|
export function providerFor(settings, fetch) {
|
|
7
|
+
if (settings.provider === 'bedrock')
|
|
8
|
+
return bedrockProvider(settings, fetch);
|
|
6
9
|
if (settings.provider === 'ollama')
|
|
7
10
|
return ollamaProvider(settings, fetch);
|
|
8
11
|
if (settings.provider === 'openai')
|
package/dist/settings.d.ts
CHANGED
|
@@ -1,11 +1,48 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
/**
|
|
3
|
-
* Who writes the overview: Claude through the Anthropic API, a model on
|
|
4
|
-
* on a server speaking the OpenAI chat completions API (llama.cpp, vLLM,
|
|
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…).
|
|
5
6
|
*/
|
|
6
|
-
export declare const PROVIDERS: readonly ["anthropic", "ollama", "openai"];
|
|
7
|
+
export declare const PROVIDERS: readonly ["anthropic", "bedrock", "ollama", "openai"];
|
|
7
8
|
/** The Claude models an admin can choose: the current Opus, Sonnet, and Haiku. */
|
|
8
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;
|
|
9
46
|
/** How much the model thinks before it writes. */
|
|
10
47
|
export declare const EFFORTS: readonly ["low", "medium", "high"];
|
|
11
48
|
/** Which of a user's feeds the overview reads. */
|
|
@@ -50,11 +87,13 @@ export declare const MIN_CONTEXT_TOKENS = 8192;
|
|
|
50
87
|
export declare const DEFAULT_CONTEXT_TOKENS = 16384;
|
|
51
88
|
/**
|
|
52
89
|
* What an admin sets for the server: who writes the overview and how it is reached, the model,
|
|
53
|
-
* the budgets, and what users may add. Anthropic needs the API key;
|
|
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.
|
|
54
92
|
*/
|
|
55
93
|
export declare const instanceSettings: z.ZodObject<{
|
|
56
94
|
provider: z.ZodDefault<z.ZodEnum<{
|
|
57
95
|
anthropic: "anthropic";
|
|
96
|
+
bedrock: "bedrock";
|
|
58
97
|
ollama: "ollama";
|
|
59
98
|
openai: "openai";
|
|
60
99
|
}>>;
|
|
@@ -69,6 +108,12 @@ export declare const instanceSettings: z.ZodObject<{
|
|
|
69
108
|
medium: "medium";
|
|
70
109
|
high: "high";
|
|
71
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
|
+
}>>;
|
|
72
117
|
baseUrl: z.ZodOptional<z.ZodURL>;
|
|
73
118
|
localApiKey: z.ZodOptional<z.ZodString>;
|
|
74
119
|
localModel: z.ZodDefault<z.ZodString>;
|
package/dist/settings.js
CHANGED
|
@@ -1,12 +1,64 @@
|
|
|
1
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, a model on
|
|
5
|
-
* on a server speaking the OpenAI chat completions API (llama.cpp, vLLM,
|
|
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…).
|
|
6
7
|
*/
|
|
7
|
-
export const PROVIDERS = ['anthropic', 'ollama', 'openai'];
|
|
8
|
+
export const PROVIDERS = ['anthropic', 'bedrock', 'ollama', 'openai'];
|
|
8
9
|
/** The Claude models an admin can choose: the current Opus, Sonnet, and Haiku. */
|
|
9
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
|
+
}
|
|
10
62
|
/** How much the model thinks before it writes. */
|
|
11
63
|
export const EFFORTS = ['low', 'medium', 'high'];
|
|
12
64
|
/** Which of a user's feeds the overview reads. */
|
|
@@ -33,20 +85,30 @@ export const DEFAULT_SECTIONS = [
|
|
|
33
85
|
export const MIN_CONTEXT_TOKENS = 8_192;
|
|
34
86
|
export const DEFAULT_CONTEXT_TOKENS = 16_384;
|
|
35
87
|
const tokens = z.number().int().min(0).max(1_000_000_000);
|
|
36
|
-
/**
|
|
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
|
+
*/
|
|
37
92
|
const anthropicOnly = { provider: ['anthropic'] };
|
|
93
|
+
const claude = { provider: ['anthropic', 'bedrock'] };
|
|
94
|
+
const bedrockOnly = { provider: ['bedrock'] };
|
|
38
95
|
const selfHosted = { provider: ['ollama', 'openai'] };
|
|
39
96
|
const ollamaOnly = { provider: ['ollama'] };
|
|
40
97
|
/**
|
|
41
98
|
* What an admin sets for the server: who writes the overview and how it is reached, the model,
|
|
42
|
-
* the budgets, and what users may add. Anthropic needs the API key;
|
|
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.
|
|
43
101
|
*/
|
|
44
102
|
export const instanceSettings = z
|
|
45
103
|
.object({
|
|
46
104
|
provider: z.enum(PROVIDERS).default('anthropic'),
|
|
47
105
|
apiKey: shownWhen(anthropicOnly, secret().optional()),
|
|
48
|
-
model: shownWhen(
|
|
49
|
-
effort: shownWhen(
|
|
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')),
|
|
50
112
|
baseUrl: shownWhen(selfHosted, url().optional()),
|
|
51
113
|
// Never the Anthropic key, which is sent only to Anthropic.
|
|
52
114
|
localApiKey: shownWhen(selfHosted, secret().optional()),
|
|
@@ -65,7 +127,30 @@ export const instanceSettings = z
|
|
|
65
127
|
path: ['apiKey'],
|
|
66
128
|
message: 'Anthropic needs an API key',
|
|
67
129
|
});
|
|
68
|
-
if (settings.provider
|
|
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)
|
|
69
154
|
context.addIssue({
|
|
70
155
|
code: 'custom',
|
|
71
156
|
path: ['baseUrl'],
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@newses/plugin-digest-summary",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"description": "A Newses plugin that opens your email digest with an overview of the common themes of your unread articles, written by Claude or a self-hosted model (Ollama, llama.cpp, vLLM\u2026)",
|
|
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",
|
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
"digest",
|
|
14
14
|
"claude",
|
|
15
15
|
"anthropic",
|
|
16
|
+
"bedrock",
|
|
17
|
+
"aws",
|
|
16
18
|
"ollama",
|
|
17
19
|
"llm",
|
|
18
20
|
"self-hosted"
|