@wirecat/cli-core 0.611.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +27 -1
  2. package/dist/calendar/mcp/index.d.ts +12 -12
  3. package/dist/cli/enrichment-consents-command.d.ts +19 -0
  4. package/dist/cli/enrichment-consents-command.js +110 -0
  5. package/dist/cli/model-catalogue-command.d.ts +8 -0
  6. package/dist/cli/model-catalogue-command.js +4 -1
  7. package/dist/embeddings/keys.d.ts +2 -0
  8. package/dist/embeddings/keys.js +2 -0
  9. package/dist/errors/reasons.js +1 -0
  10. package/dist/meetings/mcp/index.d.ts +15 -15
  11. package/dist/models/anthropic.js +6 -0
  12. package/dist/models/index.d.ts +1 -1
  13. package/dist/models/openai.js +8 -1
  14. package/dist/models/types.d.ts +7 -0
  15. package/dist/services/enrichment-setting.d.ts +50 -0
  16. package/dist/services/enrichment-setting.js +84 -0
  17. package/dist/services/enrichment.d.ts +111 -0
  18. package/dist/services/enrichment.js +240 -0
  19. package/dist/services/index.d.ts +2 -0
  20. package/dist/services/index.js +2 -0
  21. package/dist/services/metadata.d.ts +1 -1
  22. package/dist/services/notes-search.d.ts +15 -1
  23. package/dist/services/notes-search.js +38 -2
  24. package/dist/store/exports.d.ts +1 -0
  25. package/dist/store/exports.js +1 -0
  26. package/dist/store/sqlite/email-index.d.ts +2 -2
  27. package/dist/store/sqlite/email-index.js +6 -4
  28. package/dist/store/sqlite/emails.js +5 -0
  29. package/dist/store/sqlite/enrichments.d.ts +60 -0
  30. package/dist/store/sqlite/enrichments.js +113 -0
  31. package/dist/store/sqlite/entity-types.d.ts +1 -0
  32. package/dist/store/sqlite/entity-types.js +1 -0
  33. package/dist/store/sqlite/index-text.d.ts +2 -0
  34. package/dist/store/sqlite/index-text.js +2 -0
  35. package/dist/store/sqlite/mail-nearest.js +1 -1
  36. package/dist/store/sqlite/manifest.js +2 -0
  37. package/dist/store/sqlite/migrations.generated.js +14 -0
  38. package/dist/store/sqlite/note-index.d.ts +1 -2
  39. package/dist/store/sqlite/note-index.js +25 -4
  40. package/dist/store/sqlite/note-search.js +8 -1
  41. package/dist/store/sqlite/schema/enrichments.d.ts +137 -0
  42. package/dist/store/sqlite/schema/enrichments.js +12 -0
  43. package/dist/store/sqlite/schema.d.ts +1 -0
  44. package/dist/store/sqlite/schema.js +1 -0
  45. package/dist/store/store.d.ts +3 -0
  46. package/dist/store/store.js +5 -0
  47. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -5,7 +5,33 @@ 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
- ## Unreleased
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.
9
35
 
10
36
  ## 0.611.0 — 08.11.2026
11
37
 
@@ -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
  };
@@ -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
  };
@@ -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",
@@ -38,7 +38,6 @@ export declare const meetingTools: ({
38
38
  max_read_bytes?: undefined;
39
39
  cursor?: undefined;
40
40
  } | {
41
- limit?: undefined;
42
41
  event_id?: undefined;
43
42
  series_id?: undefined;
44
43
  page?: undefined;
@@ -54,11 +53,11 @@ export declare const meetingTools: ({
54
53
  format?: undefined;
55
54
  transcript_id?: undefined;
56
55
  query?: undefined;
56
+ limit?: undefined;
57
57
  scan_limit?: undefined;
58
58
  max_read_bytes?: undefined;
59
59
  cursor?: undefined;
60
60
  } | {
61
- limit?: undefined;
62
61
  event_id?: undefined;
63
62
  series_id?: undefined;
64
63
  page?: undefined;
@@ -76,11 +75,11 @@ export declare const meetingTools: ({
76
75
  format?: undefined;
77
76
  transcript_id?: undefined;
78
77
  query?: undefined;
78
+ limit?: undefined;
79
79
  scan_limit?: undefined;
80
80
  max_read_bytes?: undefined;
81
81
  cursor?: undefined;
82
82
  } | {
83
- limit?: undefined;
84
83
  event_id?: undefined;
85
84
  series_id?: undefined;
86
85
  page?: undefined;
@@ -102,6 +101,7 @@ export declare const meetingTools: ({
102
101
  minimum: number;
103
102
  };
104
103
  query?: undefined;
104
+ limit?: undefined;
105
105
  scan_limit?: undefined;
106
106
  max_read_bytes?: undefined;
107
107
  cursor?: undefined;
@@ -188,7 +188,6 @@ export declare const meetingTools: ({
188
188
  max_read_bytes?: undefined;
189
189
  cursor?: undefined;
190
190
  } | {
191
- limit?: undefined;
192
191
  event_id?: undefined;
193
192
  series_id?: undefined;
194
193
  page?: undefined;
@@ -204,11 +203,11 @@ export declare const meetingTools: ({
204
203
  format?: undefined;
205
204
  transcript_id?: undefined;
206
205
  query?: undefined;
206
+ limit?: undefined;
207
207
  scan_limit?: undefined;
208
208
  max_read_bytes?: undefined;
209
209
  cursor?: undefined;
210
210
  } | {
211
- limit?: undefined;
212
211
  event_id?: undefined;
213
212
  series_id?: undefined;
214
213
  page?: undefined;
@@ -226,11 +225,11 @@ export declare const meetingTools: ({
226
225
  format?: undefined;
227
226
  transcript_id?: undefined;
228
227
  query?: undefined;
228
+ limit?: undefined;
229
229
  scan_limit?: undefined;
230
230
  max_read_bytes?: undefined;
231
231
  cursor?: undefined;
232
232
  } | {
233
- limit?: undefined;
234
233
  event_id?: undefined;
235
234
  series_id?: undefined;
236
235
  page?: undefined;
@@ -252,6 +251,7 @@ export declare const meetingTools: ({
252
251
  minimum: number;
253
252
  };
254
253
  query?: undefined;
254
+ limit?: undefined;
255
255
  scan_limit?: undefined;
256
256
  max_read_bytes?: undefined;
257
257
  cursor?: undefined;
@@ -338,7 +338,6 @@ export declare const meetingTools: ({
338
338
  max_read_bytes?: undefined;
339
339
  cursor?: undefined;
340
340
  } | {
341
- limit?: undefined;
342
341
  event_id?: undefined;
343
342
  series_id?: undefined;
344
343
  page?: undefined;
@@ -354,11 +353,11 @@ export declare const meetingTools: ({
354
353
  format?: undefined;
355
354
  transcript_id?: undefined;
356
355
  query?: undefined;
356
+ limit?: undefined;
357
357
  scan_limit?: undefined;
358
358
  max_read_bytes?: undefined;
359
359
  cursor?: undefined;
360
360
  } | {
361
- limit?: undefined;
362
361
  event_id?: undefined;
363
362
  series_id?: undefined;
364
363
  page?: undefined;
@@ -376,11 +375,11 @@ export declare const meetingTools: ({
376
375
  format?: undefined;
377
376
  transcript_id?: undefined;
378
377
  query?: undefined;
378
+ limit?: undefined;
379
379
  scan_limit?: undefined;
380
380
  max_read_bytes?: undefined;
381
381
  cursor?: undefined;
382
382
  } | {
383
- limit?: undefined;
384
383
  event_id?: undefined;
385
384
  series_id?: undefined;
386
385
  page?: undefined;
@@ -402,6 +401,7 @@ export declare const meetingTools: ({
402
401
  minimum: number;
403
402
  };
404
403
  query?: undefined;
404
+ limit?: undefined;
405
405
  scan_limit?: undefined;
406
406
  max_read_bytes?: undefined;
407
407
  cursor?: undefined;
@@ -488,7 +488,6 @@ export declare const meetingTools: ({
488
488
  max_read_bytes?: undefined;
489
489
  cursor?: undefined;
490
490
  } | {
491
- limit?: undefined;
492
491
  event_id?: undefined;
493
492
  series_id?: undefined;
494
493
  page?: undefined;
@@ -504,11 +503,11 @@ export declare const meetingTools: ({
504
503
  format?: undefined;
505
504
  transcript_id?: undefined;
506
505
  query?: undefined;
506
+ limit?: undefined;
507
507
  scan_limit?: undefined;
508
508
  max_read_bytes?: undefined;
509
509
  cursor?: undefined;
510
510
  } | {
511
- limit?: undefined;
512
511
  event_id?: undefined;
513
512
  series_id?: undefined;
514
513
  page?: undefined;
@@ -526,11 +525,11 @@ export declare const meetingTools: ({
526
525
  format?: undefined;
527
526
  transcript_id?: undefined;
528
527
  query?: undefined;
528
+ limit?: undefined;
529
529
  scan_limit?: undefined;
530
530
  max_read_bytes?: undefined;
531
531
  cursor?: undefined;
532
532
  } | {
533
- limit?: undefined;
534
533
  event_id?: undefined;
535
534
  series_id?: undefined;
536
535
  page?: undefined;
@@ -552,6 +551,7 @@ export declare const meetingTools: ({
552
551
  minimum: number;
553
552
  };
554
553
  query?: undefined;
554
+ limit?: undefined;
555
555
  scan_limit?: undefined;
556
556
  max_read_bytes?: undefined;
557
557
  cursor?: undefined;
@@ -638,7 +638,6 @@ export declare const meetingTools: ({
638
638
  max_read_bytes?: undefined;
639
639
  cursor?: undefined;
640
640
  } | {
641
- limit?: undefined;
642
641
  event_id?: undefined;
643
642
  series_id?: undefined;
644
643
  page?: undefined;
@@ -654,11 +653,11 @@ export declare const meetingTools: ({
654
653
  format?: undefined;
655
654
  transcript_id?: undefined;
656
655
  query?: undefined;
656
+ limit?: undefined;
657
657
  scan_limit?: undefined;
658
658
  max_read_bytes?: undefined;
659
659
  cursor?: undefined;
660
660
  } | {
661
- limit?: undefined;
662
661
  event_id?: undefined;
663
662
  series_id?: undefined;
664
663
  page?: undefined;
@@ -676,11 +675,11 @@ export declare const meetingTools: ({
676
675
  format?: undefined;
677
676
  transcript_id?: undefined;
678
677
  query?: undefined;
678
+ limit?: undefined;
679
679
  scan_limit?: undefined;
680
680
  max_read_bytes?: undefined;
681
681
  cursor?: undefined;
682
682
  } | {
683
- limit?: undefined;
684
683
  event_id?: undefined;
685
684
  series_id?: undefined;
686
685
  page?: undefined;
@@ -702,6 +701,7 @@ export declare const meetingTools: ({
702
701
  minimum: number;
703
702
  };
704
703
  query?: undefined;
704
+ limit?: undefined;
705
705
  scan_limit?: undefined;
706
706
  max_read_bytes?: undefined;
707
707
  cursor?: undefined;
@@ -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) +
@@ -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>;
@@ -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
- return { text: choice.message.content, tokens: body.usage?.total_tokens };
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
  };
@@ -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
  }