@newses/plugin-digest-summary 0.2.0 → 0.3.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 +115 -30
- package/dist/digest.d.ts +64 -15
- package/dist/digest.js +253 -80
- package/dist/index.d.ts +15 -3
- package/dist/index.js +43 -24
- package/dist/prompts.d.ts +23 -3
- package/dist/prompts.js +58 -20
- package/dist/{claude.d.ts → providers/anthropic.d.ts} +9 -1
- package/dist/providers/anthropic.js +108 -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 +11 -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 +25 -3
- package/dist/settings.js +45 -7
- package/dist/tokens.d.ts +2 -0
- package/dist/tokens.js +2 -0
- package/package.json +8 -5
- package/dist/claude.js +0 -49
package/README.md
CHANGED
|
@@ -1,10 +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, 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 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
|
-
- Requests go to
|
|
7
|
+
- Requests go to the model an admin chooses:
|
|
8
|
+
- **Anthropic:** `api.anthropic.com`, with the server's API key, under the terms of that key's Anthropic account.
|
|
9
|
+
- **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.
|
|
8
10
|
- What is sent, for each digest:
|
|
9
11
|
- the digest's language;
|
|
10
12
|
- how many unread articles it has;
|
|
@@ -12,65 +14,133 @@ A [Newses](https://newses.app) server plugin that opens each user's email digest
|
|
|
12
14
|
- the user's sections (names and what goes in each), length, and whether there is a lead;
|
|
13
15
|
- the user's own instructions, when they wrote some and an admin allows them.
|
|
14
16
|
|
|
15
|
-
That covers the up to 100 articles the digest lists and up to 2,000 more that it counts.
|
|
17
|
+
That covers the up to 100 articles the digest lists and up to 2,000 more that it counts; a self-hosted model gets the newest of them that its context holds.
|
|
16
18
|
|
|
17
19
|
- Never sent: articles from feeds with a login, pages a user published from outside any feed, links, authors, and anything else about the user.
|
|
18
20
|
- Only for users who turn the plugin on for themselves.
|
|
19
21
|
|
|
20
22
|
## Install
|
|
21
23
|
|
|
22
|
-
The server's operator installs it at an exact version, `@newses/plugin-digest-summary@0.
|
|
24
|
+
The server's operator installs it at an exact version, `@newses/plugin-digest-summary@0.3.0`. 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`.
|
|
23
25
|
|
|
24
26
|
- **Docker:** add it to `PLUGINS` in `.env` and start with the plugins override ([Self-hosting](https://newses.app/guide/self-hosting#plugins)).
|
|
25
27
|
- **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)).
|
|
26
28
|
|
|
27
29
|
Then, in Settings > Plugins:
|
|
28
30
|
|
|
29
|
-
1. An admin
|
|
30
|
-
|
|
31
|
+
1. An admin chooses where the model comes from, then turns the plugin on for the server:
|
|
32
|
+
- **Anthropic:** create an API key in the [Claude Console](https://platform.claude.com) (API keys), enter it, and approve the host `api.anthropic.com`.
|
|
33
|
+
- **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
|
+
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
|
+
|
|
36
|
+
## Self-hosted models
|
|
37
|
+
|
|
38
|
+
### Standalone Ollama with Docker
|
|
39
|
+
|
|
40
|
+
[examples/docker](examples/docker) runs Ollama as a project of its own beside a Newses that runs in Docker on the same host. It joins Newses' network, where the plugin reaches it as `http://ollama:11434`, and Newses' compose files stay as they are.
|
|
41
|
+
|
|
42
|
+
1. Start Newses first: Ollama joins its network, `<project>_default` (`newses_default` by default; `docker network ls` lists it).
|
|
43
|
+
2. In `examples/docker` (or a copy of it): `cp .env.example .env`. Set the model and context, and `NEWSES_NETWORK` if yours differs. With an NVIDIA GPU, uncomment `COMPOSE_FILE` (see [GPU](#gpu)).
|
|
44
|
+
3. `docker compose up -d`. `ollama-pull` pulls the model once Ollama is up, then exits; `docker compose logs -f ollama-pull` shows how far it got.
|
|
45
|
+
4. In Newses' `.env`, set `PLUGIN_TRUSTED_HOSTS=ollama`, which lets plugins reach `ollama` on the private network without letting feeds reach it. Then `docker compose up -d` there recreates its containers.
|
|
46
|
+
5. In Settings > Plugins, add `ollama` to the approved hosts. Then set: Model from "Ollama, self-hosted"; URL `http://ollama:11434`; model and context as in step 2. "Send test" checks that Ollama has the model and the context.
|
|
47
|
+
|
|
48
|
+
- **Its port:** Ollama has no authentication, so its port is published on the host's loopback only (`127.0.0.1:11434`, `OLLAMA_PORT`), for `curl` and `scripts/measure-effort.mjs`.
|
|
49
|
+
- **Another model:** change `OLLAMA_MODEL`, run `docker compose up -d` again, then change the plugin's model.
|
|
50
|
+
- **When Newses' network is recreated** (after a `docker compose down` there), run `docker compose up -d --force-recreate` in Ollama's folder to join the new one. While Ollama is attached, `down` in Newses' folder warns that the network is still in use.
|
|
51
|
+
|
|
52
|
+
### Inside the Newses stack
|
|
53
|
+
|
|
54
|
+
To run Ollama as part of Newses' own project instead:
|
|
55
|
+
|
|
56
|
+
1. Copy `compose.ollama.yaml` (and `compose.ollama-gpu.yaml`) beside Newses' `compose.yaml`.
|
|
57
|
+
2. In Newses' `.env`, add them to `COMPOSE_FILE`, such as `compose.yaml:compose.plugins.yaml:compose.ollama.yaml:compose.ollama-gpu.yaml`, with `PLUGIN_TRUSTED_HOSTS=ollama`, `OLLAMA_MODEL`, and `OLLAMA_CONTEXT_LENGTH`.
|
|
58
|
+
3. `docker compose up -d`. Its port is not published.
|
|
59
|
+
|
|
60
|
+
### GPU
|
|
61
|
+
|
|
62
|
+
`compose.ollama-gpu.yaml` gives Ollama the host's NVIDIA GPUs, in either setup. Docker Desktop (Windows with WSL 2) has GPU support built in. Docker Engine on Linux, in WSL too, needs the NVIDIA driver and the [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html): install it, run `sudo nvidia-ctk runtime configure --runtime=docker`, and restart Docker. `docker run --rm --gpus all ubuntu nvidia-smi` checks it. Without the toolkit, Docker refuses the file with "could not select device driver nvidia". Without a GPU, leave the file out: Ollama runs on the CPU, slowly.
|
|
63
|
+
|
|
64
|
+
Ollama runs as a user other than root (10001), and `ollama-volume` gives it the models' volume on each start. Under WSL, CUDA started as root reads every PCI device, and WSL's virtio-fs device takes about 3 minutes to answer, so Ollama gives up on the GPU and uses the CPU. `docker compose logs ollama | grep "inference compute"` shows which it found: `library=CUDA` and the card's name, or `library=cpu`.
|
|
65
|
+
|
|
66
|
+
### Ollama or another server elsewhere
|
|
67
|
+
|
|
68
|
+
- **Ollama on the host:** for example on macOS, where Docker has no GPU, or on Windows. Run Ollama there with `OLLAMA_HOST=0.0.0.0`, add `extra_hosts: ['host.docker.internal:host-gateway']` to `server` and `worker` (Docker Desktop has it already), and set `PLUGIN_TRUSTED_HOSTS=host.docker.internal`. Then approve `host.docker.internal`, with the URL `http://host.docker.internal:11434`.
|
|
69
|
+
- **On another machine:** Ollama has no keys, so put a proxy that checks a bearer token in front of it, preferably over https. Set the token as the self-hosted server's key, and approve the machine's host. A private address also needs it in `PLUGIN_TRUSTED_HOSTS`.
|
|
70
|
+
- **llama.cpp, vLLM, LM Studio, LocalAI:** choose "Self-hosted server with the OpenAI API", with the URL ending in `/v1`, such as `http://llama:8080/v1`. Start the server with at least the context set (llama.cpp's `-c 16384`, vLLM's `--max-model-len`). Set the self-hosted server's key if it asks for one.
|
|
71
|
+
- **On a public address:** the server needs no `PLUGIN_TRUSTED_HOSTS`, only approval. Use https.
|
|
72
|
+
- **AWS:** the functions run outside any VPC, so they reach only a model server on a public https address.
|
|
73
|
+
|
|
74
|
+
### Choosing a model and context
|
|
75
|
+
|
|
76
|
+
The overview is written in the digest's language, so prefer multilingual models. Models whose answers follow a JSON schema closely work best.
|
|
77
|
+
|
|
78
|
+
| GPU memory | Models to try | Context |
|
|
79
|
+
| ------------- | ---------------------------------------- | ------------------------------------------------------ |
|
|
80
|
+
| None (CPU) | `qwen3:4b`, `gemma3:4b` | 8,192: about 20 articles a part; expect parts left out |
|
|
81
|
+
| 8 GB | `qwen3:4b`, `gemma3:4b` | 16,384 |
|
|
82
|
+
| 12–16 GB | `qwen3:8b` (default), `gemma3:12b` | 16,384–32,768 |
|
|
83
|
+
| 24 GB or more | `qwen3:14b`, `gemma3:27b`, `gpt-oss:20b` | 32,768 |
|
|
84
|
+
|
|
85
|
+
- **Context:** after the output and the prompt, a 16,384 context leaves about 9,000 tokens for articles in each request, some 90 articles at about 100 tokens each. A digest is read in up to 6 such parts, so about 550 articles, then one more request writes the overview from them. More context reads more articles, but takes more memory and longer.
|
|
86
|
+
- **Time:** a digest waits 5 minutes for its plugins. The parts have about 3 of them, one after another unless "Requests at once" is higher; parts not read by then are left out, and the overview says so. "Estimate cost" shows how long a digest would take at the speed Ollama last answered at.
|
|
87
|
+
- **Thinking:** for models that think, such as Qwen 3, it is off by default; on, the model thinks before writing the overview, which is slower. Parts of a large digest are read without thinking.
|
|
88
|
+
- **Several users:** their digests share the one model, each waiting its turn while Ollama answers another; `OLLAMA_NUM_PARALLEL` (with "Requests at once") answers more at once, using more memory.
|
|
89
|
+
- **Measure:** `scripts/measure-effort.mjs --provider ollama` writes overviews of sample digests with your model and settings and says how long each took (see [Costs](#costs)).
|
|
31
90
|
|
|
32
91
|
## Settings
|
|
33
92
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
|
37
|
-
|
|
|
38
|
-
|
|
|
39
|
-
|
|
|
40
|
-
|
|
|
41
|
-
|
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
-
|
|
|
45
|
-
|
|
|
46
|
-
|
|
|
47
|
-
|
|
|
48
|
-
|
|
|
93
|
+
The form shows the settings of the provider chosen under "Model from"; the others keep their values.
|
|
94
|
+
|
|
95
|
+
| Setting | Who | What it does |
|
|
96
|
+
| ------------------------------------- | ----- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
97
|
+
| Model from | Admin | Anthropic (default), Ollama, or a self-hosted server with the OpenAI API |
|
|
98
|
+
| 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 |
|
|
101
|
+
| 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
|
+
| 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
|
+
| Self-hosted model | Admin | As the server names it: `qwen3:8b` by default |
|
|
104
|
+
| Context, in tokens | Admin | 16,384 by default, at least 8,192: sent to Ollama with each request; an OpenAI API server must be started with at least as much |
|
|
105
|
+
| Requests at once | Admin | 1 by default, up to 6: parts of a large digest a self-hosted model reads together |
|
|
106
|
+
| Let the self-hosted model think first | Admin | Off by default; for Ollama models that think |
|
|
107
|
+
| Tokens a month, for the server | Admin | 10,000,000 by default; once used, no overviews are written until the month ends (UTC) |
|
|
108
|
+
| Tokens a month, for each user | Admin | 1,000,000 by default; counts the user's overviews |
|
|
109
|
+
| Users may add their own instructions | Admin | On by default; when off, users' instructions are kept but not sent |
|
|
110
|
+
| Feeds to read | User | All my feeds (default), only the feeds chosen, or all but the feeds chosen |
|
|
111
|
+
| Feeds | User | Picked from the user's subscriptions |
|
|
112
|
+
| Sections | User | Up to 12, in order, each a name and what goes in it; by default World, Politics, Business, Technology, Science, Health, Sports, Culture, and Other. Sections nothing fits are left out |
|
|
113
|
+
| Length | User | Brief (up to 2 short points a section), standard (default, 3), or detailed (5 longer ones) |
|
|
114
|
+
| Points shown as | User | Paragraphs (default) or bullets |
|
|
115
|
+
| Open with a lead | User | On by default: a paragraph on what ties stories together across sections |
|
|
116
|
+
| Your instructions | User | Up to 1,000 characters on what to focus on, leave out, or how to write |
|
|
49
117
|
|
|
50
118
|
## How it works
|
|
51
119
|
|
|
52
|
-
| Digest size
|
|
53
|
-
|
|
|
54
|
-
| Up to about 100,000 tokens (some 800 articles) | One request reads every chosen article, grouped by feed, and writes the overview
|
|
55
|
-
| Larger
|
|
120
|
+
| Digest size | What happens |
|
|
121
|
+
| --------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
122
|
+
| Up to about 100,000 tokens (some 800 articles); self-hosted, what one request's context holds | One request reads every chosen article, grouped by feed, and writes the overview |
|
|
123
|
+
| Larger | The articles are split, in their feeds' order, into as few parts as they take, at most 6, of about the same size: a feed stays whole where that keeps its part within a tenth of its share, and otherwise goes on in the next part. The parts are read at once (self-hosted: as many at once as "Requests at once"). Each part sorts its stories into the user's sections and gives each section's themes, with how many articles each covers and the refs of those it draws on. A last request writes the overview from them |
|
|
124
|
+
| Self-hosted, larger than 6 parts hold | The newest articles that 6 parts hold are read, and the model is told how many the digest has |
|
|
56
125
|
|
|
57
126
|
- **Sections and citations:** the answer is a lead and sections of points, each section one of the user's (an enum in the output format, so none is made up), its heading the name in the digest's language. Each point cites the refs of up to 5 articles; the plugin turns them into entry ids, leaving out refs it never gave, and the server links each cited article by its title and feed name to the article in Newses, whether the digest lists it or only counts it. Neither the model nor the plugin writes a link.
|
|
58
127
|
- **Limits:** points beyond the length's count, and then, from the end, points beyond the digest's 8,000 characters of sections, are left out.
|
|
59
128
|
|
|
60
129
|
- **Time limit:** a digest waits at most 5 minutes for its plugins. The parts have about 60% of that, and the last request the rest.
|
|
61
130
|
- **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.
|
|
62
|
-
- **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).
|
|
131
|
+
- **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.
|
|
63
132
|
- **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.
|
|
64
|
-
- **Declined requests:** when
|
|
133
|
+
- **Declined requests:** when Claude declines a request, the server's default fallback model answers instead (server-side fallback).
|
|
134
|
+
- **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.
|
|
65
135
|
|
|
66
136
|
## Costs
|
|
67
137
|
|
|
68
|
-
|
|
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.
|
|
69
139
|
|
|
70
140
|
- **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.
|
|
71
141
|
- **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.
|
|
72
142
|
- **What is counted:** every token, input and output, of every attempt, fallbacks included, against both budgets. "Send test" shows the counts.
|
|
73
|
-
- **Estimate:** "Estimate cost" under "For me" shows what the overview of a test digest now would cost, making no request: the tokens it expects, priced at Anthropic's list prices 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.
|
|
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 Anthropic: the tokens it expects, priced at Anthropic's list prices 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.
|
|
74
144
|
|
|
75
145
|
To choose the effort, measure it on digests like yours, billed to your key:
|
|
76
146
|
|
|
@@ -79,6 +149,13 @@ npm install && npm run build
|
|
|
79
149
|
ANTHROPIC_API_KEY=sk-ant-... node scripts/measure-effort.mjs [DIGEST.json ...] --efforts low,medium,high [--copies 100] [--length brief|standard|detailed] [--instructions TEXT]
|
|
80
150
|
```
|
|
81
151
|
|
|
152
|
+
Or a self-hosted model, with a server the script can reach (publish Ollama's port to `127.0.0.1` while you measure):
|
|
153
|
+
|
|
154
|
+
```sh
|
|
155
|
+
node scripts/measure-effort.mjs --provider ollama --base-url http://localhost:11434 --model qwen3:8b [--context 16384] [--parallel 1] [--thinking] [--copies 5]
|
|
156
|
+
node scripts/measure-effort.mjs --provider openai --base-url http://localhost:8080/v1 --model MODEL [--context 16384]
|
|
157
|
+
```
|
|
158
|
+
|
|
82
159
|
- **Digest files:** a digest file is what the plugin's `digest.compose` hook is given. [scripts/sample-digest.json](scripts/sample-digest.json) is the default, and includes an article that tries to give the model instructions.
|
|
83
160
|
- **Larger digests:** `--copies N` adds N copies of its articles as unlisted ones, to measure a digest read in parts.
|
|
84
161
|
- **Reader settings:** `--length` and `--instructions` measure those settings, with the default sections. The script prints each section's points with the titles of the articles they cite.
|
|
@@ -87,11 +164,19 @@ ANTHROPIC_API_KEY=sk-ant-... node scripts/measure-effort.mjs [DIGEST.json ...] -
|
|
|
87
164
|
|
|
88
165
|
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.
|
|
89
166
|
|
|
167
|
+
"Send test" says what to change for a self-hosted model:
|
|
168
|
+
|
|
169
|
+
- a host that is not approved: add it under Approved hosts;
|
|
170
|
+
- a host on a private network: the operator adds it to `PLUGIN_TRUSTED_HOSTS`;
|
|
171
|
+
- a model the server does not have: `ollama pull`;
|
|
172
|
+
- a context larger than the model takes;
|
|
173
|
+
- thinking turned on for a model that does not think.
|
|
174
|
+
|
|
90
175
|
## Development
|
|
91
176
|
|
|
92
177
|
Node 24 and npm: `npm install`, then `npm run check` (lint, typecheck, format check, tests) and `npm run build`.
|
|
93
178
|
|
|
94
|
-
- **Tests** run the hooks as the server does with `@newses/plugin-api/testing`, against a stand-in for the
|
|
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/`).
|
|
95
180
|
- **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.
|
|
96
181
|
|
|
97
182
|
## Licence
|
package/dist/digest.d.ts
CHANGED
|
@@ -1,24 +1,41 @@
|
|
|
1
|
-
import Anthropic from '@anthropic-ai/sdk';
|
|
2
1
|
import { type DigestComposeInput, type DigestEntry, type DigestSection, type PluginLogger, type PluginStore } from '@newses/plugin-api';
|
|
2
|
+
import { PART_TOKENS } from './providers/anthropic.js';
|
|
3
|
+
import type { Capacity, Provider } from './providers/index.js';
|
|
3
4
|
import { type FeedArticles, type Overview } from './prompts.js';
|
|
4
5
|
import { type RequestTokens } from './prices.js';
|
|
5
6
|
import { type InstanceSettings, type UserSettings } from './settings.js';
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
/** Parts read
|
|
7
|
+
import { estimateTokens } from './tokens.js';
|
|
8
|
+
export { estimateTokens, PART_TOKENS };
|
|
9
|
+
/** Parts a digest is read in, at most; a larger one has larger parts, or reads the newest. */
|
|
9
10
|
export declare const MAX_PARTS = 6;
|
|
10
11
|
export declare const OUTPUT_ESTIMATE: {
|
|
11
12
|
readonly brief: 3000;
|
|
12
13
|
readonly standard: 5000;
|
|
13
14
|
readonly detailed: 8000;
|
|
14
15
|
};
|
|
16
|
+
export declare const LOCAL_OUTPUT: {
|
|
17
|
+
readonly brief: 2000;
|
|
18
|
+
readonly standard: 4000;
|
|
19
|
+
readonly detailed: 7000;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Output tokens the requests are given (and expected to use): a part's, and the overview's; a
|
|
23
|
+
* self-hosted model's at most half its context, leaving the rest to the prompt.
|
|
24
|
+
*/
|
|
25
|
+
export declare function outputTokens(capacity: Capacity, length: UserSettings['length']): {
|
|
26
|
+
part: number;
|
|
27
|
+
overview: number;
|
|
28
|
+
};
|
|
15
29
|
/**
|
|
16
30
|
* The requests reading articles of `whole` tokens are expected to take: one, or parts and a
|
|
17
31
|
* merge; `preferences` is the tokens of the reader's preferences each request carries.
|
|
18
32
|
*/
|
|
19
33
|
export declare function plannedRequests(partTokens: readonly number[] | null, whole: number, options: {
|
|
20
34
|
preferences: number;
|
|
21
|
-
|
|
35
|
+
output: {
|
|
36
|
+
part: number;
|
|
37
|
+
overview: number;
|
|
38
|
+
};
|
|
22
39
|
}): RequestTokens[];
|
|
23
40
|
/** What a digest's overview ended as, for the log. */
|
|
24
41
|
export type DigestOutcome = 'written'
|
|
@@ -36,11 +53,12 @@ export declare function byFeed(entries: readonly DigestEntry[]): {
|
|
|
36
53
|
feeds: FeedArticles[];
|
|
37
54
|
ids: Map<string, number>;
|
|
38
55
|
};
|
|
39
|
-
/** Tokens a text is about, rounded up: some 3 characters each. */
|
|
40
|
-
export declare const estimateTokens: (text: string) => number;
|
|
41
56
|
/**
|
|
42
|
-
* Feeds packed into parts of
|
|
43
|
-
*
|
|
57
|
+
* Feeds packed, in order, into as few parts of at most `limit` tokens as they take, each part
|
|
58
|
+
* about the same size: the articles' tokens shared evenly between them. A feed joins a part whole
|
|
59
|
+
* when that keeps it within `PART_STRETCH` of its share; otherwise its articles fill the part to
|
|
60
|
+
* its share and go on in the next. Every part but the last reaches its share, so there are never
|
|
61
|
+
* more parts than the fewest the articles take.
|
|
44
62
|
*/
|
|
45
63
|
export declare function partsOf(feeds: readonly FeedArticles[], limit: number): FeedArticles[][];
|
|
46
64
|
/**
|
|
@@ -57,12 +75,35 @@ export declare function preferencesOf(settings: InstanceSettings, userSettings:
|
|
|
57
75
|
parts: string;
|
|
58
76
|
};
|
|
59
77
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
78
|
+
* Article tokens one request to a self-hosted model may carry: its context, less the output it
|
|
79
|
+
* may write, the longer system prompt, and the reader's preferences, of which `CONTEXT_SHARE`;
|
|
80
|
+
* at least one article's worth.
|
|
63
81
|
*/
|
|
64
|
-
export declare function
|
|
82
|
+
export declare function contextLimit(capacity: Extract<Capacity, {
|
|
83
|
+
kind: 'context';
|
|
84
|
+
}>, output: {
|
|
85
|
+
part: number;
|
|
86
|
+
overview: number;
|
|
87
|
+
}, preferences: string): number;
|
|
88
|
+
/**
|
|
89
|
+
* Parts a self-hosted model may read a digest in: at most `MAX_PARTS`, and no more than the
|
|
90
|
+
* request merging their themes holds in its context; one when it holds none.
|
|
91
|
+
*/
|
|
92
|
+
export declare function contextParts(capacity: Extract<Capacity, {
|
|
93
|
+
kind: 'context';
|
|
94
|
+
}>, output: {
|
|
95
|
+
part: number;
|
|
96
|
+
overview: number;
|
|
97
|
+
}, preferences: string): number;
|
|
98
|
+
/**
|
|
99
|
+
* How a digest's overview would be read: the user's chosen entries of those listed and unlisted
|
|
100
|
+
* (a self-hosted model's, the newest its parts hold), by feed with their refs, the reader's
|
|
101
|
+
* preferences, in one request or in parts, the requests' output tokens and expected tokens;
|
|
102
|
+
* null with none chosen. `total` is every unread article the digest counts.
|
|
103
|
+
*/
|
|
104
|
+
export declare function planOf(input: DigestComposeInput, settings: InstanceSettings, userSettings: UserSettings, capacity?: Capacity): {
|
|
65
105
|
entries: DigestEntry[];
|
|
106
|
+
chosen: number;
|
|
66
107
|
feeds: FeedArticles[];
|
|
67
108
|
ids: Map<string, number>;
|
|
68
109
|
preferences: {
|
|
@@ -76,7 +117,12 @@ export declare function planOf(input: DigestComposeInput, settings: InstanceSett
|
|
|
76
117
|
};
|
|
77
118
|
total: number;
|
|
78
119
|
parts: FeedArticles[][] | null;
|
|
120
|
+
maxParts: number;
|
|
79
121
|
planned: RequestTokens[];
|
|
122
|
+
output: {
|
|
123
|
+
part: number;
|
|
124
|
+
overview: number;
|
|
125
|
+
};
|
|
80
126
|
} | null;
|
|
81
127
|
/** The overview as the digest takes it: the lead as its overview, then its sections. */
|
|
82
128
|
export declare function additionsOf(overview: Overview, userSettings: Pick<UserSettings, 'lead' | 'style'>): {
|
|
@@ -85,9 +131,12 @@ export declare function additionsOf(overview: Overview, userSettings: Pick<UserS
|
|
|
85
131
|
};
|
|
86
132
|
/**
|
|
87
133
|
* What the overview of a digest is expected to cost, making no request, as plain text: how it
|
|
88
|
-
* would be read, its tokens, and US dollars at list prices, or why it would add nothing.
|
|
134
|
+
* would be read, its tokens, and US dollars at list prices, or why it would add nothing. A
|
|
135
|
+
* self-hosted model's has no price, but how many articles its context holds, and how long it
|
|
136
|
+
* would take at the speed it last answered at.
|
|
89
137
|
*/
|
|
90
138
|
export declare function estimate(options: {
|
|
139
|
+
provider: Pick<Provider, 'label' | 'capacity' | 'parallel'>;
|
|
91
140
|
settings: InstanceSettings;
|
|
92
141
|
userSettings: UserSettings;
|
|
93
142
|
input: DigestComposeInput;
|
|
@@ -108,7 +157,7 @@ export interface Composed {
|
|
|
108
157
|
* unreadable, out of time), the digest goes out without it.
|
|
109
158
|
*/
|
|
110
159
|
export declare function compose(options: {
|
|
111
|
-
|
|
160
|
+
provider: Provider;
|
|
112
161
|
settings: InstanceSettings;
|
|
113
162
|
userSettings: UserSettings;
|
|
114
163
|
input: DigestComposeInput;
|