@wirecat/cli-core 0.611.0 → 0.613.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 (63) hide show
  1. package/CHANGELOG.md +62 -1
  2. package/dist/background/report/render.d.ts +10 -1
  3. package/dist/background/report/render.js +20 -7
  4. package/dist/background/report/schema.d.ts +37 -0
  5. package/dist/background/report/schema.js +98 -4
  6. package/dist/background/report/templates/morning-digest.email.en.liquid +49 -8
  7. package/dist/background/report/templates/morning-digest.email.ru.liquid +49 -8
  8. package/dist/background/report/templates/morning-digest.telegram.en.liquid +49 -9
  9. package/dist/background/report/templates/morning-digest.telegram.ru.liquid +49 -9
  10. package/dist/background/report/templates/morning-digest.text.en.liquid +49 -9
  11. package/dist/background/report/templates/morning-digest.text.ru.liquid +49 -9
  12. package/dist/background/report/view.d.ts +34 -3
  13. package/dist/background/report/view.js +59 -5
  14. package/dist/background/schedules.js +19 -3
  15. package/dist/calendar/mcp/index.d.ts +12 -12
  16. package/dist/cli/enrichment-consents-command.d.ts +19 -0
  17. package/dist/cli/enrichment-consents-command.js +110 -0
  18. package/dist/cli/model-catalogue-command.d.ts +8 -0
  19. package/dist/cli/model-catalogue-command.js +4 -1
  20. package/dist/domain/links.d.ts +72 -0
  21. package/dist/domain/links.js +139 -0
  22. package/dist/embeddings/keys.d.ts +2 -0
  23. package/dist/embeddings/keys.js +2 -0
  24. package/dist/errors/reasons.js +1 -0
  25. package/dist/index.d.ts +1 -0
  26. package/dist/index.js +1 -0
  27. package/dist/meetings/mcp/index.d.ts +15 -15
  28. package/dist/models/anthropic.js +6 -0
  29. package/dist/models/index.d.ts +1 -1
  30. package/dist/models/openai.js +8 -1
  31. package/dist/models/types.d.ts +7 -0
  32. package/dist/services/enrichment-setting.d.ts +50 -0
  33. package/dist/services/enrichment-setting.js +84 -0
  34. package/dist/services/enrichment.d.ts +111 -0
  35. package/dist/services/enrichment.js +240 -0
  36. package/dist/services/index.d.ts +2 -0
  37. package/dist/services/index.js +2 -0
  38. package/dist/services/notes-search.d.ts +15 -1
  39. package/dist/services/notes-search.js +38 -2
  40. package/dist/store/exports.d.ts +1 -0
  41. package/dist/store/exports.js +1 -0
  42. package/dist/store/sqlite/email-index.d.ts +2 -2
  43. package/dist/store/sqlite/email-index.js +6 -4
  44. package/dist/store/sqlite/emails.js +5 -0
  45. package/dist/store/sqlite/enrichments.d.ts +60 -0
  46. package/dist/store/sqlite/enrichments.js +113 -0
  47. package/dist/store/sqlite/entity-types.d.ts +1 -0
  48. package/dist/store/sqlite/entity-types.js +1 -0
  49. package/dist/store/sqlite/index-text.d.ts +2 -0
  50. package/dist/store/sqlite/index-text.js +2 -0
  51. package/dist/store/sqlite/mail-nearest.js +1 -1
  52. package/dist/store/sqlite/manifest.js +2 -0
  53. package/dist/store/sqlite/migrations.generated.js +14 -0
  54. package/dist/store/sqlite/note-index.d.ts +1 -2
  55. package/dist/store/sqlite/note-index.js +25 -4
  56. package/dist/store/sqlite/note-search.js +8 -1
  57. package/dist/store/sqlite/schema/enrichments.d.ts +137 -0
  58. package/dist/store/sqlite/schema/enrichments.js +12 -0
  59. package/dist/store/sqlite/schema.d.ts +1 -0
  60. package/dist/store/sqlite/schema.js +1 -0
  61. package/dist/store/store.d.ts +3 -0
  62. package/dist/store/store.js +5 -0
  63. package/package.json +2 -2
@@ -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
  };
@@ -0,0 +1,72 @@
1
+ /**
2
+ * What a WireCat link opens. A link only opens a screen in WireCat Desktop: no kind performs an action, a proposal
3
+ * link shows the proposal and the owner presses Confirm or Reject there.
4
+ */
5
+ export type DeepLinkTarget = {
6
+ type: "message";
7
+ provider: string;
8
+ account: string;
9
+ chat: string;
10
+ message: string;
11
+ } | {
12
+ type: "chat";
13
+ provider: string;
14
+ account: string;
15
+ chat: string;
16
+ } | {
17
+ type: "task";
18
+ id: string;
19
+ } | {
20
+ type: "tasks";
21
+ filter: "overdue" | "today" | "tomorrow";
22
+ } | {
23
+ type: "tasks";
24
+ filter: "new";
25
+ since: string;
26
+ }
27
+ /** A review id as `memo review` shows it (`17070`, `fact:512`): not a reference, so it is one encoded part. */
28
+ | {
29
+ type: "proposal";
30
+ id: string;
31
+ } | {
32
+ type: "digest";
33
+ date: string;
34
+ } | {
35
+ type: "sync";
36
+ tool: string;
37
+ account?: string;
38
+ };
39
+ export type LinkForm = "web" | "app";
40
+ export interface LinkConfig {
41
+ /** The bounce page: the path goes after its `#`, so the host never sees it. */
42
+ base: string;
43
+ enabled: boolean;
44
+ }
45
+ export declare const LINK_VERSION = "v1";
46
+ export declare const DEFAULT_LINK_CONFIG: LinkConfig;
47
+ /** `/v1/msg/max/1001/-2002/3003`, the part both forms share. */
48
+ export declare const formatLink: (target: DeepLinkTarget) => string;
49
+ /**
50
+ * The target of a link in either form (`https://…#/v1/…`, `wirecat://open/v1/…`) or of its bare path (`/v1/…`), or
51
+ * `null` for anything else: another version, an unknown kind, a part too many or empty, a path over 512 characters.
52
+ */
53
+ export declare const parseLink: (text: string) => DeepLinkTarget | null;
54
+ /**
55
+ * The target a ref names, or `null` when it names nothing a link opens. A store reference (`msg:`, `chat:`, `task:`)
56
+ * is read by its own grammar; the kinds that are no reference are written as their path with a colon after the
57
+ * kind: `proposal:fact%3A512`, `tasks:overdue`, `tasks:new/2026-11-07T08%3A00%3A00Z`, `digest:2026-11-08`,
58
+ * `sync:telegram/1001`.
59
+ */
60
+ export declare const linkTargetOf: (ref: string) => DeepLinkTarget | null;
61
+ /** The `links` section of the shared config, with the default for what is missing or not a usable value. */
62
+ export declare const linkConfigOf: (section: unknown) => LinkConfig;
63
+ /**
64
+ * The one way to build a WireCat link: the web form for messages and mail (an https page that hands it to the app),
65
+ * the app form for a desktop terminal. `null` when links are off (`links.enabled: false`, or `WIRECAT_LINKS=off` for
66
+ * one run) or the ref names nothing a link opens; the caller then leaves the link out.
67
+ */
68
+ export declare const linkFor: (ref: DeepLinkTarget | string, { form, config, env, }: {
69
+ form: LinkForm;
70
+ config?: LinkConfig;
71
+ env?: NodeJS.ProcessEnv;
72
+ }) => string | null;
@@ -0,0 +1,139 @@
1
+ import { parseReference } from "./references.js";
2
+ export const LINK_VERSION = "v1";
3
+ export const DEFAULT_LINK_CONFIG = { base: "https://wirecat.dev/o", enabled: true };
4
+ const APP_PREFIX = "wirecat://open";
5
+ const MAX_PATH = 512;
6
+ const MAX_SEGMENTS = 6;
7
+ const TASK_FILTERS = ["overdue", "today", "tomorrow"];
8
+ const DATE = /^\d{4}-\d{2}-\d{2}$/;
9
+ const DATE_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})$/;
10
+ const isMoment = (text, pattern) => pattern.test(text) && !Number.isNaN(Date.parse(text));
11
+ const partsOf = (target) => {
12
+ switch (target.type) {
13
+ case "message":
14
+ return ["msg", target.provider, target.account, target.chat, target.message];
15
+ case "chat":
16
+ return ["chat", target.provider, target.account, target.chat];
17
+ case "task":
18
+ return ["task", target.id];
19
+ case "tasks":
20
+ return target.filter === "new" ? ["tasks", "new", target.since] : ["tasks", target.filter];
21
+ case "proposal":
22
+ return ["proposal", target.id];
23
+ case "digest":
24
+ return ["digest", target.date];
25
+ case "sync":
26
+ return target.account === undefined ? ["sync", target.tool] : ["sync", target.tool, target.account];
27
+ }
28
+ };
29
+ /** The path after the version, `msg/max/1001/-2002/3003`: each part percent-encoded, so no id can add a part. */
30
+ const pathOf = (target) => partsOf(target).map(encodeURIComponent).join("/");
31
+ const targetOfParts = (parts) => {
32
+ const [kind, ...rest] = parts;
33
+ const [a = "", b = "", c = "", d = ""] = rest;
34
+ switch (kind) {
35
+ case "msg":
36
+ return rest.length === 4 ? { type: "message", provider: a, account: b, chat: c, message: d } : null;
37
+ case "chat":
38
+ return rest.length === 3 ? { type: "chat", provider: a, account: b, chat: c } : null;
39
+ case "task":
40
+ return rest.length === 1 ? { type: "task", id: a } : null;
41
+ case "tasks":
42
+ if (rest.length === 1 && TASK_FILTERS.includes(a))
43
+ return { type: "tasks", filter: a };
44
+ return rest.length === 2 && a === "new" && (isMoment(b, DATE) || isMoment(b, DATE_TIME))
45
+ ? { type: "tasks", filter: "new", since: b }
46
+ : null;
47
+ case "proposal":
48
+ return rest.length === 1 ? { type: "proposal", id: a } : null;
49
+ case "digest":
50
+ return rest.length === 1 && isMoment(a, DATE) ? { type: "digest", date: a } : null;
51
+ case "sync":
52
+ return rest.length === 1 || rest.length === 2
53
+ ? { type: "sync", tool: a, ...(rest.length === 2 ? { account: b } : {}) }
54
+ : null;
55
+ default:
56
+ return null;
57
+ }
58
+ };
59
+ /** A path after the version, or `null`: an empty part or one that does not decode is not a WireCat link. */
60
+ const targetOfPath = (path) => {
61
+ const raw = path.split("/");
62
+ if (raw.some((part) => part === ""))
63
+ return null;
64
+ try {
65
+ return targetOfParts(raw.map(decodeURIComponent));
66
+ }
67
+ catch {
68
+ return null;
69
+ }
70
+ };
71
+ /** `/v1/msg/max/1001/-2002/3003`, the part both forms share. */
72
+ export const formatLink = (target) => `/${LINK_VERSION}/${pathOf(target)}`;
73
+ /**
74
+ * The target of a link in either form (`https://…#/v1/…`, `wirecat://open/v1/…`) or of its bare path (`/v1/…`), or
75
+ * `null` for anything else: another version, an unknown kind, a part too many or empty, a path over 512 characters.
76
+ */
77
+ export const parseLink = (text) => {
78
+ const link = text.trim();
79
+ const path = link.startsWith(`${APP_PREFIX}/`)
80
+ ? link.slice(APP_PREFIX.length)
81
+ : link.startsWith("https://") && link.includes("#")
82
+ ? link.slice(link.indexOf("#") + 1)
83
+ : link;
84
+ if (path.length > MAX_PATH || !path.startsWith(`/${LINK_VERSION}/`))
85
+ return null;
86
+ // A later version may add extras as a query; a v1 reader ignores them rather than refusing the link.
87
+ const rest = path.split("?")[0].slice(LINK_VERSION.length + 2);
88
+ if (rest.split("/").length + 1 > MAX_SEGMENTS)
89
+ return null;
90
+ return targetOfPath(rest);
91
+ };
92
+ const LINK_ONLY = new Set(["tasks", "proposal", "digest", "sync"]);
93
+ const FROM_REFERENCE = new Set(["message", "chat", "task"]);
94
+ /**
95
+ * The target a ref names, or `null` when it names nothing a link opens. A store reference (`msg:`, `chat:`, `task:`)
96
+ * is read by its own grammar; the kinds that are no reference are written as their path with a colon after the
97
+ * kind: `proposal:fact%3A512`, `tasks:overdue`, `tasks:new/2026-11-07T08%3A00%3A00Z`, `digest:2026-11-08`,
98
+ * `sync:telegram/1001`.
99
+ */
100
+ export const linkTargetOf = (ref) => {
101
+ const text = ref.trim();
102
+ const colon = text.indexOf(":");
103
+ if (colon < 0)
104
+ return null;
105
+ const kind = text.slice(0, colon);
106
+ if (LINK_ONLY.has(kind))
107
+ return targetOfPath(`${kind}/${text.slice(colon + 1)}`);
108
+ try {
109
+ const reference = parseReference(text);
110
+ return FROM_REFERENCE.has(reference.type) ? reference : null;
111
+ }
112
+ catch {
113
+ return null;
114
+ }
115
+ };
116
+ /** The `links` section of the shared config, with the default for what is missing or not a usable value. */
117
+ export const linkConfigOf = (section) => {
118
+ const value = section && typeof section === "object" ? section : {};
119
+ const base = typeof value.base === "string" && /^https:\/\/[^\s#?]+$/.test(value.base)
120
+ ? value.base.replace(/\/+$/, "")
121
+ : DEFAULT_LINK_CONFIG.base;
122
+ return { base, enabled: typeof value.enabled === "boolean" ? value.enabled : DEFAULT_LINK_CONFIG.enabled };
123
+ };
124
+ /**
125
+ * The one way to build a WireCat link: the web form for messages and mail (an https page that hands it to the app),
126
+ * the app form for a desktop terminal. `null` when links are off (`links.enabled: false`, or `WIRECAT_LINKS=off` for
127
+ * one run) or the ref names nothing a link opens; the caller then leaves the link out.
128
+ */
129
+ export const linkFor = (ref, { form, config = DEFAULT_LINK_CONFIG, env = process.env, }) => {
130
+ if (!config.enabled || env.WIRECAT_LINKS === "off")
131
+ return null;
132
+ const target = typeof ref === "string" ? linkTargetOf(ref) : ref;
133
+ if (target === null)
134
+ return null;
135
+ const path = formatLink(target);
136
+ if (path.length > MAX_PATH || parseLink(path) === null)
137
+ return null;
138
+ return form === "app" ? `${APP_PREFIX}${path}` : `${config.base}#${path}`;
139
+ };
@@ -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",
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export { CRM_KINDS, type CrmDepartment, type CrmField, type CrmItem, type CrmKin
6
6
  export { DEAL_KINDS, DEAL_ROLES, DEAL_STATUSES, type DealKind, type DealRole, type DealStatus, STAGE_OUTCOMES, type StageOutcome, } from "./domain/deals.js";
7
7
  export { FINANCE_REVIEWS, type FinanceReview, INVOICE_DIRECTIONS, INVOICE_STATUSES, type InvoiceDirection, type InvoiceStatus, MONEY_DIRECTIONS, type MoneyDirection, } from "./domain/finance.js";
8
8
  export { type FormattedText, type HtmlFormatting, type MarkdownFormatting, type TextSpan, validateFormattedText, } from "./domain/formatting.js";
9
+ export { DEFAULT_LINK_CONFIG, type DeepLinkTarget, formatLink, LINK_VERSION, type LinkConfig, type LinkForm, linkConfigOf, linkFor, linkTargetOf, parseLink, } from "./domain/links.js";
9
10
  export { formatLocator, isLocator, type MessageLocator, parseLocator } from "./domain/locator.js";
10
11
  export { type Markup, parseMarkdown } from "./domain/markdown.js";
11
12
  export { parseMarkdownSpans } from "./domain/markdown-spans.js";
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ export { CRM_KINDS, isItemKind, } from "./domain/crm.js";
5
5
  export { DEAL_KINDS, DEAL_ROLES, DEAL_STATUSES, STAGE_OUTCOMES, } from "./domain/deals.js";
6
6
  export { FINANCE_REVIEWS, INVOICE_DIRECTIONS, INVOICE_STATUSES, MONEY_DIRECTIONS, } from "./domain/finance.js";
7
7
  export { validateFormattedText, } from "./domain/formatting.js";
8
+ export { DEFAULT_LINK_CONFIG, formatLink, LINK_VERSION, linkConfigOf, linkFor, linkTargetOf, parseLink, } from "./domain/links.js";
8
9
  export { formatLocator, isLocator, parseLocator } from "./domain/locator.js";
9
10
  export { parseMarkdown } from "./domain/markdown.js";
10
11
  export { parseMarkdownSpans } from "./domain/markdown-spans.js";
@@ -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>;