@wirecat/cli-core 0.610.0 → 0.612.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/CHANGELOG.md +37 -0
- package/dist/calendar/mcp/index.d.ts +12 -12
- package/dist/cli/enrichment-consents-command.d.ts +19 -0
- package/dist/cli/enrichment-consents-command.js +110 -0
- package/dist/cli/model-catalogue-command.d.ts +8 -0
- package/dist/cli/model-catalogue-command.js +4 -1
- package/dist/embeddings/keys.d.ts +2 -0
- package/dist/embeddings/keys.js +2 -0
- package/dist/errors/reasons.js +1 -0
- package/dist/models/anthropic.js +6 -0
- package/dist/models/index.d.ts +1 -1
- package/dist/models/openai.js +8 -1
- package/dist/models/types.d.ts +7 -0
- package/dist/services/enrichment-setting.d.ts +50 -0
- package/dist/services/enrichment-setting.js +84 -0
- package/dist/services/enrichment.d.ts +111 -0
- package/dist/services/enrichment.js +240 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.js +2 -0
- package/dist/services/metadata.d.ts +1 -1
- package/dist/services/notes-search.d.ts +15 -1
- package/dist/services/notes-search.js +38 -2
- package/dist/services/search-all.js +8 -6
- package/dist/store/exports.d.ts +1 -0
- package/dist/store/exports.js +1 -0
- package/dist/store/sqlite/email-index.d.ts +2 -2
- package/dist/store/sqlite/email-index.js +6 -4
- package/dist/store/sqlite/emails.js +5 -0
- package/dist/store/sqlite/enrichments.d.ts +60 -0
- package/dist/store/sqlite/enrichments.js +113 -0
- package/dist/store/sqlite/entity-types.d.ts +1 -0
- package/dist/store/sqlite/entity-types.js +1 -0
- package/dist/store/sqlite/index-text.d.ts +2 -0
- package/dist/store/sqlite/index-text.js +2 -0
- package/dist/store/sqlite/mail-nearest.js +1 -1
- package/dist/store/sqlite/manifest.js +2 -0
- package/dist/store/sqlite/migrations.generated.js +14 -0
- package/dist/store/sqlite/note-index.d.ts +1 -2
- package/dist/store/sqlite/note-index.js +25 -4
- package/dist/store/sqlite/note-search.js +8 -1
- package/dist/store/sqlite/schema/enrichments.d.ts +137 -0
- package/dist/store/sqlite/schema/enrichments.js +12 -0
- package/dist/store/sqlite/schema.d.ts +1 -0
- package/dist/store/sqlite/schema.js +1 -0
- package/dist/store/store.d.ts +3 -0
- package/dist/store/store.js +5 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,43 @@ Notable changes to `@wirecat/cli-core` (`@wirecat/cli-messaging` up to 0.261.0,
|
|
|
5
5
|
minor version may break callers, and says how under "Changed — may break callers". `pnpm docs:check` checks the
|
|
6
6
|
shape of this file.
|
|
7
7
|
|
|
8
|
+
## 0.612.0 — 08.11.2026
|
|
9
|
+
|
|
10
|
+
### Changed — may break callers
|
|
11
|
+
|
|
12
|
+
- **`models consents` is offered only when the tool asks for it** with `modelCatalogueCommand(app, { enrichment:
|
|
13
|
+
true })`, as memo will. Other CLIs (gcal, mail, drive…) no longer list it: turning enrichment on changes the shared
|
|
14
|
+
store for every CLI, so one tool owns the switch.
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- **Write-time enrichment, off by default.** With the owner's consent, a hosted model reads each note, document and
|
|
19
|
+
email and writes standalone facts and two questions in other words; search finds the record by them and still cites
|
|
20
|
+
the record. `models consents show` gives the state, the records covered and the cost estimate;
|
|
21
|
+
`models consents set openai --model gpt-4o-mini` says what would be sent and changes nothing until `--yes`;
|
|
22
|
+
`models consents revoke` turns it off and deletes what was written. Every answer carries `target` (the provider,
|
|
23
|
+
model and endpoint the estimate is about: the setting in force, the one `set` proposes, or the default offer while
|
|
24
|
+
off) with `key: {present, source, env_var}` (never the key), `per_sync`, `syncs_needed`, `offered` (provider and
|
|
25
|
+
model pairs with their prices), `measured` and `off_command`, so a window can write the consent in its own words. One setting for every WireCat CLI, the
|
|
26
|
+
`enrichment` section of the shared settings file. `embedNotes` and `embedMail` enrich up to 600 records a run before
|
|
27
|
+
they embed, each record once per text; a failed batch leaves its records for the next sync. The text goes into the
|
|
28
|
+
stems and a chunk of its own, never into `--exact`, the trigrams or the record's own chunks. An agent cannot turn it
|
|
29
|
+
on. The key: the tool's `embeddings:<provider>` entry, the environment, then its entry named after the provider
|
|
30
|
+
(`embeddingKeys(app).readPlain`). `enrichRecords`, `enrichmentState`, `readEnrichmentSetting` and `writeEnrichmentSetting` from
|
|
31
|
+
`@wirecat/cli-core/services`; `store.enrichment`.
|
|
32
|
+
- Store version 58: `enrichments`, one row per enriched record, deleted with the record. Additive; `minCompatible`
|
|
33
|
+
stays 56.
|
|
34
|
+
- The model gateway's answer carries `usage` (input and output tokens) for OpenAI and Anthropic.
|
|
35
|
+
|
|
36
|
+
## 0.611.0 — 08.11.2026
|
|
37
|
+
|
|
38
|
+
### Fixed
|
|
39
|
+
|
|
40
|
+
- **In `search all`, a hit only words found keeps its place next to the hits around it.** It takes the cosine of the
|
|
41
|
+
hit above it in its own source, so an exact word's second hit no longer sorts behind every hit meaning found.
|
|
42
|
+
- **cli-core accepts `@wirecat/cli-base` up to 0.85.x.** Its peer range stopped at `<0.83.0`, so a CLI could not take
|
|
43
|
+
cli-base 0.85.0's `hostFetch` and the `network.hosts` manifest next to cli-core. Nothing else changes for a caller.
|
|
44
|
+
|
|
8
45
|
## 0.610.0 — 08.11.2026
|
|
9
46
|
|
|
10
47
|
### Added
|
|
@@ -10,13 +10,13 @@ export declare const calendarTools: ({
|
|
|
10
10
|
inputSchema: {
|
|
11
11
|
type: string;
|
|
12
12
|
properties: {
|
|
13
|
+
limit?: undefined;
|
|
13
14
|
account_id: {
|
|
14
15
|
type: string;
|
|
15
16
|
minimum: number;
|
|
16
17
|
};
|
|
17
18
|
query?: undefined;
|
|
18
19
|
timezone?: undefined;
|
|
19
|
-
limit?: undefined;
|
|
20
20
|
page?: undefined;
|
|
21
21
|
event?: undefined;
|
|
22
22
|
} | {
|
|
@@ -45,9 +45,9 @@ export declare const calendarTools: ({
|
|
|
45
45
|
};
|
|
46
46
|
event?: undefined;
|
|
47
47
|
} | {
|
|
48
|
+
limit?: undefined;
|
|
48
49
|
query?: undefined;
|
|
49
50
|
timezone?: undefined;
|
|
50
|
-
limit?: undefined;
|
|
51
51
|
page?: undefined;
|
|
52
52
|
event: {
|
|
53
53
|
type: string;
|
|
@@ -58,9 +58,9 @@ export declare const calendarTools: ({
|
|
|
58
58
|
minimum: number;
|
|
59
59
|
};
|
|
60
60
|
} | {
|
|
61
|
+
limit?: undefined;
|
|
61
62
|
query?: undefined;
|
|
62
63
|
timezone?: undefined;
|
|
63
|
-
limit?: undefined;
|
|
64
64
|
page?: undefined;
|
|
65
65
|
event?: undefined;
|
|
66
66
|
account_id?: undefined;
|
|
@@ -80,13 +80,13 @@ export declare const calendarTools: ({
|
|
|
80
80
|
inputSchema: {
|
|
81
81
|
type: string;
|
|
82
82
|
properties: {
|
|
83
|
+
limit?: undefined;
|
|
83
84
|
account_id: {
|
|
84
85
|
type: string;
|
|
85
86
|
minimum: number;
|
|
86
87
|
};
|
|
87
88
|
query?: undefined;
|
|
88
89
|
timezone?: undefined;
|
|
89
|
-
limit?: undefined;
|
|
90
90
|
page?: undefined;
|
|
91
91
|
event?: undefined;
|
|
92
92
|
} | {
|
|
@@ -115,9 +115,9 @@ export declare const calendarTools: ({
|
|
|
115
115
|
};
|
|
116
116
|
event?: undefined;
|
|
117
117
|
} | {
|
|
118
|
+
limit?: undefined;
|
|
118
119
|
query?: undefined;
|
|
119
120
|
timezone?: undefined;
|
|
120
|
-
limit?: undefined;
|
|
121
121
|
page?: undefined;
|
|
122
122
|
event: {
|
|
123
123
|
type: string;
|
|
@@ -128,9 +128,9 @@ export declare const calendarTools: ({
|
|
|
128
128
|
minimum: number;
|
|
129
129
|
};
|
|
130
130
|
} | {
|
|
131
|
+
limit?: undefined;
|
|
131
132
|
query?: undefined;
|
|
132
133
|
timezone?: undefined;
|
|
133
|
-
limit?: undefined;
|
|
134
134
|
page?: undefined;
|
|
135
135
|
event?: undefined;
|
|
136
136
|
account_id?: undefined;
|
|
@@ -150,13 +150,13 @@ export declare const calendarTools: ({
|
|
|
150
150
|
inputSchema: {
|
|
151
151
|
type: string;
|
|
152
152
|
properties: {
|
|
153
|
+
limit?: undefined;
|
|
153
154
|
account_id: {
|
|
154
155
|
type: string;
|
|
155
156
|
minimum: number;
|
|
156
157
|
};
|
|
157
158
|
query?: undefined;
|
|
158
159
|
timezone?: undefined;
|
|
159
|
-
limit?: undefined;
|
|
160
160
|
page?: undefined;
|
|
161
161
|
event?: undefined;
|
|
162
162
|
} | {
|
|
@@ -185,9 +185,9 @@ export declare const calendarTools: ({
|
|
|
185
185
|
};
|
|
186
186
|
event?: undefined;
|
|
187
187
|
} | {
|
|
188
|
+
limit?: undefined;
|
|
188
189
|
query?: undefined;
|
|
189
190
|
timezone?: undefined;
|
|
190
|
-
limit?: undefined;
|
|
191
191
|
page?: undefined;
|
|
192
192
|
event: {
|
|
193
193
|
type: string;
|
|
@@ -198,9 +198,9 @@ export declare const calendarTools: ({
|
|
|
198
198
|
minimum: number;
|
|
199
199
|
};
|
|
200
200
|
} | {
|
|
201
|
+
limit?: undefined;
|
|
201
202
|
query?: undefined;
|
|
202
203
|
timezone?: undefined;
|
|
203
|
-
limit?: undefined;
|
|
204
204
|
page?: undefined;
|
|
205
205
|
event?: undefined;
|
|
206
206
|
account_id?: undefined;
|
|
@@ -220,13 +220,13 @@ export declare const calendarTools: ({
|
|
|
220
220
|
inputSchema: {
|
|
221
221
|
type: string;
|
|
222
222
|
properties: {
|
|
223
|
+
limit?: undefined;
|
|
223
224
|
account_id: {
|
|
224
225
|
type: string;
|
|
225
226
|
minimum: number;
|
|
226
227
|
};
|
|
227
228
|
query?: undefined;
|
|
228
229
|
timezone?: undefined;
|
|
229
|
-
limit?: undefined;
|
|
230
230
|
page?: undefined;
|
|
231
231
|
event?: undefined;
|
|
232
232
|
} | {
|
|
@@ -255,9 +255,9 @@ export declare const calendarTools: ({
|
|
|
255
255
|
};
|
|
256
256
|
event?: undefined;
|
|
257
257
|
} | {
|
|
258
|
+
limit?: undefined;
|
|
258
259
|
query?: undefined;
|
|
259
260
|
timezone?: undefined;
|
|
260
|
-
limit?: undefined;
|
|
261
261
|
page?: undefined;
|
|
262
262
|
event: {
|
|
263
263
|
type: string;
|
|
@@ -268,9 +268,9 @@ export declare const calendarTools: ({
|
|
|
268
268
|
minimum: number;
|
|
269
269
|
};
|
|
270
270
|
} | {
|
|
271
|
+
limit?: undefined;
|
|
271
272
|
query?: undefined;
|
|
272
273
|
timezone?: undefined;
|
|
273
|
-
limit?: undefined;
|
|
274
274
|
page?: undefined;
|
|
275
275
|
event?: undefined;
|
|
276
276
|
account_id?: undefined;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type KeyringStore } from "@wirecat/cli-base";
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import type { AppIdentity } from "../ports/app.js";
|
|
4
|
+
import { type EnrichmentState } from "../services/enrichment.js";
|
|
5
|
+
import { type Body } from "./envelope.js";
|
|
6
|
+
export interface EnrichmentConsentsOptions {
|
|
7
|
+
env: () => NodeJS.ProcessEnv;
|
|
8
|
+
/** Where the provider key is looked for; the system keyring when absent. Tests pass memoryKeyring(). */
|
|
9
|
+
keyring?: KeyringStore;
|
|
10
|
+
output: (answer: Body, command: Command) => void;
|
|
11
|
+
diagnostic: (line: string) => void;
|
|
12
|
+
}
|
|
13
|
+
/** What the owner agrees to, from the answer's own fields: a window can write the same text in its language. */
|
|
14
|
+
export declare const consentWording: (command: string, state: EnrichmentState) => string;
|
|
15
|
+
/**
|
|
16
|
+
* Write-time enrichment: the owner's consent that notes, documents and mail go to a hosted model, which writes facts
|
|
17
|
+
* and questions search reads beside each record. Off until `set … --yes`; one setting for every WireCat CLI.
|
|
18
|
+
*/
|
|
19
|
+
export declare const enrichmentConsentsCommand: (app: AppIdentity, options: EnrichmentConsentsOptions) => Command;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import { agentOf } from "../runs/run-context.js";
|
|
5
|
+
import { enrichmentState } from "../services/enrichment.js";
|
|
6
|
+
import { ENRICHMENT_PROVIDERS, enrichmentEndpoint, isEnrichmentProvider, readEnrichmentSetting, writeEnrichmentSetting, } from "../services/enrichment-setting.js";
|
|
7
|
+
import { openStore } from "../store/store.js";
|
|
8
|
+
import { grantsAuthority, LOCAL_READ, LOCAL_WRITE } from "./effects.js";
|
|
9
|
+
import { itemOf } from "./envelope.js";
|
|
10
|
+
const withStore = async (env, work) => {
|
|
11
|
+
const store = await openStore({ env });
|
|
12
|
+
try {
|
|
13
|
+
return await work(store);
|
|
14
|
+
}
|
|
15
|
+
finally {
|
|
16
|
+
await store.close();
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const usd = (value) => (value === null ? "an unknown amount (no price for this model)" : `$${value}`);
|
|
20
|
+
/** What the owner agrees to, from the answer's own fields: a window can write the same text in its language. */
|
|
21
|
+
export const consentWording = (command, state) => `Enrichment sends the text of every note, document and email in this store to ${state.target.provider} ` +
|
|
22
|
+
`(${state.target.endpoint_host}), model ${state.target.model}: ${state.pending} records now, and every ` +
|
|
23
|
+
"record added or changed later, at each sync. The model writes facts and questions about each record; they are " +
|
|
24
|
+
"kept in the store, and search finds the record by them. " +
|
|
25
|
+
"A question in other words finds its record more often in the top 5 and 10, but a question in the record's own " +
|
|
26
|
+
"words gets that record first a little less often (measured on synthetic data: " +
|
|
27
|
+
`${state.measured.own_words_first.off} to ${state.measured.own_words_first.on}). ` +
|
|
28
|
+
`Enriching what is here now costs about ${usd(state.estimate.usd)} ` +
|
|
29
|
+
`(${state.estimate.input_tokens} input and ${state.estimate.output_tokens} output tokens). ` +
|
|
30
|
+
`\`${offCommand(command)}\` turns it off and deletes what the model wrote.`;
|
|
31
|
+
const offCommand = (command) => `${command} models consents revoke`;
|
|
32
|
+
/**
|
|
33
|
+
* Write-time enrichment: the owner's consent that notes, documents and mail go to a hosted model, which writes facts
|
|
34
|
+
* and questions search reads beside each record. Off until `set … --yes`; one setting for every WireCat CLI.
|
|
35
|
+
*/
|
|
36
|
+
export const enrichmentConsentsCommand = (app, options) => {
|
|
37
|
+
const consents = annotate(new Command("consents"), { effects: LOCAL_READ }).description("consent to send stored notes, documents and mail to a hosted model that rewrites them for search; off by default");
|
|
38
|
+
annotate(consents.command("show"), { effects: LOCAL_READ, examples: [`${app.command} models consents show`] })
|
|
39
|
+
.description("whether enrichment is on, with which provider and model, how many records it covers and the cost")
|
|
40
|
+
.action(async function () {
|
|
41
|
+
const env = options.env();
|
|
42
|
+
const state = await withStore(env, (store) => enrichmentState(store, env, undefined, { app, ...(options.keyring ? { keyring: options.keyring } : {}) }));
|
|
43
|
+
options.output(itemOf({ ...state, off_command: offCommand(app.command) }), this);
|
|
44
|
+
});
|
|
45
|
+
grantsAuthority(annotate(consents.command("set"), {
|
|
46
|
+
effects: LOCAL_WRITE,
|
|
47
|
+
examples: [`${app.command} models consents set openai --model gpt-4o-mini --yes`],
|
|
48
|
+
}))
|
|
49
|
+
.description("turn enrichment on for one provider and model; without --yes, say what would be sent and change nothing")
|
|
50
|
+
.argument("<provider>", `the provider that receives the records: ${ENRICHMENT_PROVIDERS.join(" or ")}`)
|
|
51
|
+
.requiredOption("--model <model>", "the provider's model name, such as gpt-4o-mini or claude-haiku-5-5")
|
|
52
|
+
.option("--base-url <url>", "the address of an OpenAI-compatible model API, or the Anthropic API root")
|
|
53
|
+
.option("--yes", "agree that the records go to this provider, and turn enrichment on")
|
|
54
|
+
.action(async function (provider, given) {
|
|
55
|
+
if (!isEnrichmentProvider(provider))
|
|
56
|
+
throw new CliError("validation_error", `enrichment goes to ${ENRICHMENT_PROVIDERS.join(" or ")}, not ${provider}`);
|
|
57
|
+
const env = options.env();
|
|
58
|
+
// An agent that turned this on would send the owner's whole store out; only the owner may.
|
|
59
|
+
if (agentOf(env) && given.yes)
|
|
60
|
+
throw new CliError("permission_error", "only the owner turns enrichment on, not an agent", {
|
|
61
|
+
reason: "enrichment.owner-only",
|
|
62
|
+
});
|
|
63
|
+
const chosen = {
|
|
64
|
+
provider,
|
|
65
|
+
model: given.model,
|
|
66
|
+
...(given.baseUrl === undefined ? {} : { base_url: given.baseUrl }),
|
|
67
|
+
};
|
|
68
|
+
const state = await withStore(env, (store) => enrichmentState(store, env, chosen, { app, ...(options.keyring ? { keyring: options.keyring } : {}) }));
|
|
69
|
+
const consent = consentWording(app.command, state);
|
|
70
|
+
if (!given.yes) {
|
|
71
|
+
options.diagnostic(`${consent}\nNothing changed — add --yes to turn it on.`);
|
|
72
|
+
options.output(itemOf({ ...state, changed: false, consent, off_command: offCommand(app.command) }), this);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const setting = { ...chosen, consented_at: new Date().toISOString() };
|
|
76
|
+
writeEnrichmentSetting(env, setting);
|
|
77
|
+
options.diagnostic(`enrichment is on: ${provider} ${given.model}; the next syncs send ${state.pending} records`);
|
|
78
|
+
options.output(itemOf({
|
|
79
|
+
...state,
|
|
80
|
+
on: true,
|
|
81
|
+
provider,
|
|
82
|
+
model: given.model,
|
|
83
|
+
endpoint: enrichmentEndpoint(setting),
|
|
84
|
+
consented_at: setting.consented_at,
|
|
85
|
+
changed: true,
|
|
86
|
+
consent,
|
|
87
|
+
off_command: offCommand(app.command),
|
|
88
|
+
}), this);
|
|
89
|
+
});
|
|
90
|
+
grantsAuthority(annotate(consents.command("revoke"), {
|
|
91
|
+
effects: LOCAL_WRITE,
|
|
92
|
+
examples: [`${app.command} models consents revoke`],
|
|
93
|
+
}))
|
|
94
|
+
.description("turn enrichment off and delete what the model wrote; search reads only the records' own text again")
|
|
95
|
+
.action(async function () {
|
|
96
|
+
const env = options.env();
|
|
97
|
+
const was = readEnrichmentSetting(env);
|
|
98
|
+
writeEnrichmentSetting(env, undefined);
|
|
99
|
+
const { deleted, state } = await withStore(env, async (store) => ({
|
|
100
|
+
deleted: (await store.enrichment?.clear()) ?? 0,
|
|
101
|
+
state: await enrichmentState(store, env, undefined, {
|
|
102
|
+
app,
|
|
103
|
+
...(options.keyring ? { keyring: options.keyring } : {}),
|
|
104
|
+
}),
|
|
105
|
+
}));
|
|
106
|
+
options.diagnostic(`enrichment is off${was ? ` (was ${was.provider} ${was.model})` : ""}; deleted the text written for ${deleted} records`);
|
|
107
|
+
options.output(itemOf({ ...state, changed: was !== undefined || deleted > 0, deleted }), this);
|
|
108
|
+
});
|
|
109
|
+
return consents;
|
|
110
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type KeyringStore } from "@wirecat/cli-base";
|
|
1
2
|
import { Command } from "commander";
|
|
2
3
|
import { type TextModel } from "../embeddings/models.js";
|
|
3
4
|
import type { AppIdentity } from "../ports/app.js";
|
|
@@ -7,6 +8,13 @@ export declare const MODEL_CATALOGUE_QUERY: import("@wirecat/cli-base/query").Qu
|
|
|
7
8
|
export interface ModelCatalogueOptions {
|
|
8
9
|
kinds: readonly ("audio" | "text")[];
|
|
9
10
|
env: () => NodeJS.ProcessEnv;
|
|
11
|
+
/**
|
|
12
|
+
* Offer `models consents`, the switch for write-time enrichment. Only the tool whose sync enriches asks for it
|
|
13
|
+
* (memo): it changes the shared store for every CLI.
|
|
14
|
+
*/
|
|
15
|
+
enrichment?: boolean;
|
|
16
|
+
/** Where `models consents` looks for the enrichment provider's key; the system keyring when absent. */
|
|
17
|
+
keyring?: KeyringStore;
|
|
10
18
|
output: (answer: Body, command: Command) => void;
|
|
11
19
|
diagnostic: (line: string) => void;
|
|
12
20
|
jsonOption?: boolean;
|
|
@@ -11,6 +11,7 @@ import { install, installedBytes, isInstalled, modelsDirectory } from "../speech
|
|
|
11
11
|
import { DEFAULT_ORDER, orderedModels, speechModel } from "../speech/models.js";
|
|
12
12
|
import { stepLines } from "../terminal/step-lines.js";
|
|
13
13
|
import { FETCH, grantsAuthority, LOCAL_READ, LOCAL_WRITE, NO_EFFECTS } from "./effects.js";
|
|
14
|
+
import { enrichmentConsentsCommand } from "./enrichment-consents-command.js";
|
|
14
15
|
import { itemOf, listOf } from "./envelope.js";
|
|
15
16
|
import { listQuery, nativeTerms, termField, typedQuery, withQuery } from "./list-query.js";
|
|
16
17
|
export const MODEL_CATALOGUE_QUERY = defineQuery({
|
|
@@ -137,8 +138,10 @@ export const modelCatalogueCommand = (app, options) => {
|
|
|
137
138
|
options.output(itemOf(textModelItem(model, env)), this);
|
|
138
139
|
});
|
|
139
140
|
}
|
|
141
|
+
if (options.enrichment === true)
|
|
142
|
+
models.addCommand(enrichmentConsentsCommand(app, options));
|
|
140
143
|
if (options.jsonOption)
|
|
141
|
-
for (const command of models.commands)
|
|
144
|
+
for (const command of models.commands.flatMap((one) => (one.commands.length ? one.commands : [one])))
|
|
142
145
|
command.option("--json", "print JSON");
|
|
143
146
|
return models;
|
|
144
147
|
};
|
|
@@ -11,6 +11,8 @@ export declare const embeddingKeys: (app: AppIdentity, env?: NodeJS.ProcessEnv,
|
|
|
11
11
|
key: string;
|
|
12
12
|
source: CredentialSource | "env";
|
|
13
13
|
} | undefined;
|
|
14
|
+
/** A key kept under the provider's own name, as an owner may have stored it by hand for the whole tool. */
|
|
15
|
+
readPlain: (provider: string) => string | undefined;
|
|
14
16
|
write: (provider: string, key: string) => CredentialSource;
|
|
15
17
|
remove: (provider: string) => CredentialSource[];
|
|
16
18
|
};
|
package/dist/embeddings/keys.js
CHANGED
|
@@ -33,6 +33,8 @@ export const embeddingKeys = (app, env = process.env, keyring) => {
|
|
|
33
33
|
: undefined;
|
|
34
34
|
return shared ? { key: shared, source: "env" } : undefined;
|
|
35
35
|
},
|
|
36
|
+
/** A key kept under the provider's own name, as an owner may have stored it by hand for the whole tool. */
|
|
37
|
+
readPlain: (provider) => credentials(provider).read(provider)?.secret,
|
|
36
38
|
write: (provider, key) => credentials(provider).write(account(provider), key, { signIn: true }),
|
|
37
39
|
remove: (provider) => credentials(provider).remove(account(provider)),
|
|
38
40
|
};
|
package/dist/errors/reasons.js
CHANGED
|
@@ -48,6 +48,7 @@ const PROVIDER_API = [
|
|
|
48
48
|
];
|
|
49
49
|
const OTHERS = [
|
|
50
50
|
["query.time-limit", "timeout", "the search took longer than its time limit; the query itself is valid"],
|
|
51
|
+
["enrichment.owner-only", "permission_error", "only the owner turns enrichment on, not an agent"],
|
|
51
52
|
["model.offline", "permission_error", "downloading a model needs the network; --offline was requested"],
|
|
52
53
|
[
|
|
53
54
|
"contract.unacknowledged-override",
|
package/dist/models/anthropic.js
CHANGED
|
@@ -49,6 +49,12 @@ export const anthropic = {
|
|
|
49
49
|
.filter((block) => block.type === "text")
|
|
50
50
|
.map((block) => block.text)
|
|
51
51
|
.join(""),
|
|
52
|
+
usage: {
|
|
53
|
+
input: response.usage.input_tokens +
|
|
54
|
+
(response.usage.cache_creation_input_tokens ?? 0) +
|
|
55
|
+
(response.usage.cache_read_input_tokens ?? 0),
|
|
56
|
+
output: response.usage.output_tokens,
|
|
57
|
+
},
|
|
52
58
|
tokens: response.usage.input_tokens +
|
|
53
59
|
response.usage.output_tokens +
|
|
54
60
|
(response.usage.cache_creation_input_tokens ?? 0) +
|
package/dist/models/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ModelAdapter, type ModelAnswer, type ModelRequest, type ModelTarget } from "./types.js";
|
|
2
2
|
export type { ModelSettings } from "./settings.js";
|
|
3
3
|
export { modelTarget } from "./settings.js";
|
|
4
|
-
export type { ModelAdapter, ModelAnswer, ModelImage, ModelRequest, ModelTarget } from "./types.js";
|
|
4
|
+
export type { ModelAdapter, ModelAnswer, ModelImage, ModelRequest, ModelTarget, ModelUsage } from "./types.js";
|
|
5
5
|
export interface GatewayDeps {
|
|
6
6
|
resolve: (purpose: string) => ModelTarget | undefined;
|
|
7
7
|
consent: (request: ModelRequest, target: ModelTarget) => boolean | Promise<boolean>;
|
package/dist/models/openai.js
CHANGED
|
@@ -53,6 +53,13 @@ export const openai = {
|
|
|
53
53
|
!Number.isInteger(body.usage?.total_tokens) ||
|
|
54
54
|
(body.usage?.total_tokens ?? 0) < 1)
|
|
55
55
|
throw new Error("incomplete response");
|
|
56
|
-
|
|
56
|
+
const { prompt_tokens: input, completion_tokens: output } = body.usage ?? {};
|
|
57
|
+
return {
|
|
58
|
+
text: choice.message.content,
|
|
59
|
+
tokens: body.usage?.total_tokens,
|
|
60
|
+
...(Number.isInteger(input) && Number.isInteger(output)
|
|
61
|
+
? { usage: { input: input, output: output } }
|
|
62
|
+
: {}),
|
|
63
|
+
};
|
|
57
64
|
}),
|
|
58
65
|
};
|
package/dist/models/types.d.ts
CHANGED
|
@@ -19,9 +19,15 @@ export interface ModelTarget {
|
|
|
19
19
|
model: string;
|
|
20
20
|
baseUrl?: string;
|
|
21
21
|
}
|
|
22
|
+
/** Input and output tokens as the provider reported them, which price differently. */
|
|
23
|
+
export interface ModelUsage {
|
|
24
|
+
input: number;
|
|
25
|
+
output: number;
|
|
26
|
+
}
|
|
22
27
|
export interface ModelAnswer {
|
|
23
28
|
text: string;
|
|
24
29
|
tokens: number;
|
|
30
|
+
usage?: ModelUsage;
|
|
25
31
|
provider: string;
|
|
26
32
|
model: string;
|
|
27
33
|
}
|
|
@@ -33,6 +39,7 @@ export interface ModelAdapter {
|
|
|
33
39
|
}, request: ModelRequest, options: Record<string, unknown>, apiKey: string | undefined, fetcher: typeof fetch) => Promise<{
|
|
34
40
|
text: string;
|
|
35
41
|
tokens: number;
|
|
42
|
+
usage?: ModelUsage;
|
|
36
43
|
}>;
|
|
37
44
|
baseUrl: string;
|
|
38
45
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
export declare const ENRICHMENT_PROVIDERS: readonly ["openai", "anthropic"];
|
|
3
|
+
export type EnrichmentProvider = (typeof ENRICHMENT_PROVIDERS)[number];
|
|
4
|
+
declare const Setting: v.StrictObjectSchema<{
|
|
5
|
+
readonly provider: v.PicklistSchema<readonly ["openai", "anthropic"], undefined>;
|
|
6
|
+
readonly model: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 200, undefined>]>;
|
|
7
|
+
readonly base_url: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "use an HTTP/S endpoint without credentials, query or fragment">]>, undefined>;
|
|
8
|
+
/** When the owner agreed that records go to this provider and endpoint; the setting exists only with it. */
|
|
9
|
+
readonly consented_at: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, undefined>]>;
|
|
10
|
+
}, undefined>;
|
|
11
|
+
export type EnrichmentSetting = v.InferOutput<typeof Setting>;
|
|
12
|
+
export declare const enrichmentSettingPath: (env: NodeJS.ProcessEnv) => string;
|
|
13
|
+
/** The owner's choice, or `undefined` when enrichment is off: no section means off. */
|
|
14
|
+
export declare const readEnrichmentSetting: (env: NodeJS.ProcessEnv) => EnrichmentSetting | undefined;
|
|
15
|
+
export declare const writeEnrichmentSetting: (env: NodeJS.ProcessEnv, setting: EnrichmentSetting | undefined) => void;
|
|
16
|
+
export declare const enrichmentEndpoint: (setting: Pick<EnrichmentSetting, "provider" | "base_url">) => string;
|
|
17
|
+
export declare const isEnrichmentProvider: (value: string) => value is EnrichmentProvider;
|
|
18
|
+
/** What `show` estimates while enrichment is off and nothing is proposed: the measured model. */
|
|
19
|
+
export declare const DEFAULT_OFFER: {
|
|
20
|
+
readonly provider: "openai";
|
|
21
|
+
readonly model: "gpt-4o-mini";
|
|
22
|
+
};
|
|
23
|
+
/** The provider and model pairs offered, each with its price; another model is allowed, with no price. */
|
|
24
|
+
export declare const offeredModels: () => {
|
|
25
|
+
provider: string;
|
|
26
|
+
model: string;
|
|
27
|
+
default: boolean;
|
|
28
|
+
usd_per_million: {
|
|
29
|
+
input: number;
|
|
30
|
+
output: number;
|
|
31
|
+
};
|
|
32
|
+
}[];
|
|
33
|
+
export declare const enrichmentPrice: (provider: string, model: string, baseUrl?: string) => {
|
|
34
|
+
input: number;
|
|
35
|
+
output: number;
|
|
36
|
+
source: string;
|
|
37
|
+
} | undefined;
|
|
38
|
+
export interface EnrichmentEstimate {
|
|
39
|
+
records: number;
|
|
40
|
+
input_tokens: number;
|
|
41
|
+
output_tokens: number;
|
|
42
|
+
/** `null` for a model or endpoint with no known price. */
|
|
43
|
+
usd: number | null;
|
|
44
|
+
}
|
|
45
|
+
export declare const estimateEnrichment: (records: number, chars: number, setting?: Pick<EnrichmentSetting, "provider" | "model" | "base_url">) => EnrichmentEstimate;
|
|
46
|
+
export declare const costOf: (usage: {
|
|
47
|
+
input: number;
|
|
48
|
+
output: number;
|
|
49
|
+
}, setting: Pick<EnrichmentSetting, "provider" | "model" | "base_url">) => number | null;
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import * as v from "valibot";
|
|
3
|
+
import { endpoint } from "../models/endpoint.js";
|
|
4
|
+
import { storePath } from "../store/path.js";
|
|
5
|
+
import { readSharedSection, sharedConfigPath, writeSharedSection } from "../store/shared-config.js";
|
|
6
|
+
const SECTION = "enrichment";
|
|
7
|
+
export const ENRICHMENT_PROVIDERS = ["openai", "anthropic"];
|
|
8
|
+
const DEFAULT_BASE_URLS = {
|
|
9
|
+
openai: "https://api.openai.com/v1",
|
|
10
|
+
anthropic: "https://api.anthropic.com",
|
|
11
|
+
};
|
|
12
|
+
const Setting = v.strictObject({
|
|
13
|
+
provider: v.picklist(ENRICHMENT_PROVIDERS),
|
|
14
|
+
model: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(200)),
|
|
15
|
+
base_url: v.optional(v.pipe(v.string(), v.check((value) => endpoint(value), "use an HTTP/S endpoint without credentials, query or fragment"))),
|
|
16
|
+
/** When the owner agreed that records go to this provider and endpoint; the setting exists only with it. */
|
|
17
|
+
consented_at: v.pipe(v.string(), v.isoTimestamp()),
|
|
18
|
+
});
|
|
19
|
+
export const enrichmentSettingPath = (env) => sharedConfigPath(storePath(env), env);
|
|
20
|
+
/** The owner's choice, or `undefined` when enrichment is off: no section means off. */
|
|
21
|
+
export const readEnrichmentSetting = (env) => {
|
|
22
|
+
const path = enrichmentSettingPath(env);
|
|
23
|
+
const section = readSharedSection(path, SECTION);
|
|
24
|
+
if (section === undefined || section === null)
|
|
25
|
+
return undefined;
|
|
26
|
+
const checked = v.safeParse(Setting, section);
|
|
27
|
+
if (!checked.success)
|
|
28
|
+
throw new CliError("configuration_error", `${path}: enrichment.${v.getDotPath(checked.issues[0]) ?? "settings"} is invalid — ${checked.issues[0].message}`);
|
|
29
|
+
return checked.output;
|
|
30
|
+
};
|
|
31
|
+
export const writeEnrichmentSetting = (env, setting) => writeSharedSection(enrichmentSettingPath(env), SECTION, setting === undefined ? undefined : v.parse(Setting, setting));
|
|
32
|
+
export const enrichmentEndpoint = (setting) => setting.base_url ?? DEFAULT_BASE_URLS[setting.provider];
|
|
33
|
+
export const isEnrichmentProvider = (value) => ENRICHMENT_PROVIDERS.includes(value);
|
|
34
|
+
/** USD per token, from the providers' price pages on 2026-11-08; a model not listed gets no price. */
|
|
35
|
+
const PRICES = {
|
|
36
|
+
"openai/gpt-4o-mini": {
|
|
37
|
+
input: 0.15e-6,
|
|
38
|
+
output: 0.6e-6,
|
|
39
|
+
source: "https://developers.openai.com/api/docs/pricing",
|
|
40
|
+
},
|
|
41
|
+
"anthropic/claude-haiku-5-5": {
|
|
42
|
+
input: 0.1e-6,
|
|
43
|
+
output: 0.5e-6,
|
|
44
|
+
source: "https://platform.claude.com/docs/en/about-claude/pricing",
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
/** What `show` estimates while enrichment is off and nothing is proposed: the measured model. */
|
|
48
|
+
export const DEFAULT_OFFER = { provider: "openai", model: "gpt-4o-mini" };
|
|
49
|
+
/** The provider and model pairs offered, each with its price; another model is allowed, with no price. */
|
|
50
|
+
export const offeredModels = () => Object.entries(PRICES).map(([key, price]) => {
|
|
51
|
+
const [provider, model] = key.split("/");
|
|
52
|
+
return {
|
|
53
|
+
provider,
|
|
54
|
+
model,
|
|
55
|
+
default: provider === DEFAULT_OFFER.provider && model === DEFAULT_OFFER.model,
|
|
56
|
+
usd_per_million: {
|
|
57
|
+
input: Math.round(price.input * 1e8) / 100,
|
|
58
|
+
output: Math.round(price.output * 1e8) / 100,
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
export const enrichmentPrice = (provider, model, baseUrl) => baseUrl === undefined ? PRICES[`${provider}/${model}`] : undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Per record, measured with this prompt and gpt-4o-mini on 1,048 synthetic records of about 100 characters, 20 to a
|
|
65
|
+
* request (cli-testing write-time-enrichment, 2026-11-08): 66 input tokens, 41 of them the prompt's share, and 65
|
|
66
|
+
* output tokens.
|
|
67
|
+
*/
|
|
68
|
+
const OUTPUT_TOKENS_PER_RECORD = 70;
|
|
69
|
+
const PROMPT_TOKENS_PER_RECORD = 40;
|
|
70
|
+
export const estimateEnrichment = (records, chars, setting) => {
|
|
71
|
+
const input = Math.ceil(chars / 4) + records * PROMPT_TOKENS_PER_RECORD;
|
|
72
|
+
const output = records * OUTPUT_TOKENS_PER_RECORD;
|
|
73
|
+
const price = setting && enrichmentPrice(setting.provider, setting.model, setting.base_url);
|
|
74
|
+
return {
|
|
75
|
+
records,
|
|
76
|
+
input_tokens: input,
|
|
77
|
+
output_tokens: output,
|
|
78
|
+
usd: price ? Math.round((input * price.input + output * price.output) * 1_000_000) / 1_000_000 : null,
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
export const costOf = (usage, setting) => {
|
|
82
|
+
const price = enrichmentPrice(setting.provider, setting.model, setting.base_url);
|
|
83
|
+
return price ? Math.round((usage.input * price.input + usage.output * price.output) * 1_000_000) / 1_000_000 : null;
|
|
84
|
+
};
|