@wirecat/cli-core 0.686.0 → 0.688.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 (97) hide show
  1. package/CHANGELOG.md +114 -0
  2. package/dist/background/daily-archive-timer.d.ts +1 -1
  3. package/dist/cli/account-remove.js +21 -3
  4. package/dist/cli/documents/testing/source-contract.js +18 -9
  5. package/dist/cli/documents/words.d.ts +1 -1
  6. package/dist/cli/envelope.js +2 -3
  7. package/dist/cli/meeting-batch.js +5 -1
  8. package/dist/cli/meeting-passage-text.d.ts +1 -1
  9. package/dist/cli/meeting-passage-text.js +3 -5
  10. package/dist/cli/messenger/conversations-command.js +4 -0
  11. package/dist/cli/messenger/messages-search-command.js +6 -1
  12. package/dist/cli/messenger/search-answers.js +2 -0
  13. package/dist/cli/messenger/store-maintenance-command.js +3 -2
  14. package/dist/cli/search-left-out.d.ts +3 -0
  15. package/dist/cli/search-left-out.js +12 -0
  16. package/dist/cli/store-settings.js +23 -4
  17. package/dist/cli/untrusted-marks.d.ts +2 -0
  18. package/dist/cli/untrusted-marks.js +6 -0
  19. package/dist/crm/cli/files.d.ts +68 -0
  20. package/dist/crm/cli/files.js +616 -0
  21. package/dist/crm/cli/index.d.ts +1 -0
  22. package/dist/crm/cli/index.js +3 -0
  23. package/dist/crm/cli/search-all.js +3 -2
  24. package/dist/crm/file-fetch.d.ts +15 -0
  25. package/dist/crm/file-fetch.js +61 -0
  26. package/dist/crm/files.d.ts +16 -0
  27. package/dist/crm/files.js +56 -0
  28. package/dist/crm/foreign-contacts.d.ts +16 -4
  29. package/dist/crm/foreign-contacts.js +8 -4
  30. package/dist/crm/index.d.ts +3 -1
  31. package/dist/crm/index.js +3 -0
  32. package/dist/crm/source.d.ts +37 -0
  33. package/dist/crm/source.js +2 -1
  34. package/dist/crm/testing/files-contract.d.ts +17 -0
  35. package/dist/crm/testing/files-contract.js +142 -0
  36. package/dist/crm/testing/index.d.ts +2 -1
  37. package/dist/crm/testing/index.js +2 -1
  38. package/dist/crm/testing/source.d.ts +36 -1
  39. package/dist/crm/testing/source.js +55 -1
  40. package/dist/crm/values.d.ts +2 -1
  41. package/dist/crm/values.js +4 -2
  42. package/dist/entities/hit.d.ts +3 -3
  43. package/dist/entities/hit.js +14 -3
  44. package/dist/entities/index.d.ts +1 -1
  45. package/dist/errors/reasons.js +12 -1
  46. package/dist/files/safe-name.d.ts +2 -1
  47. package/dist/files/safe-name.js +21 -3
  48. package/dist/meetings/cli/index.d.ts +1 -1
  49. package/dist/meetings/cli/index.js +10 -6
  50. package/dist/meetings/mcp/index.d.ts +15 -15
  51. package/dist/meetings/mcp/passage.d.ts +6 -2
  52. package/dist/meetings/mcp/passage.js +7 -3
  53. package/dist/meetings/read-through.d.ts +2 -0
  54. package/dist/meetings/read-through.js +7 -2
  55. package/dist/meetings/source.d.ts +2 -2
  56. package/dist/oauth/storage.js +21 -4
  57. package/dist/search/lucene/resolved.d.ts +2 -0
  58. package/dist/search/respell.d.ts +10 -0
  59. package/dist/search/respell.js +63 -0
  60. package/dist/search/stem.d.ts +16 -3
  61. package/dist/search/stem.js +32 -4
  62. package/dist/services/documents/plan.js +26 -5
  63. package/dist/services/documents/sync.js +4 -1
  64. package/dist/services/embeddings-search.js +190 -140
  65. package/dist/services/embeddings.d.ts +8 -0
  66. package/dist/services/messages-archive-search.js +55 -3
  67. package/dist/services/messages-search.d.ts +2 -1
  68. package/dist/services/messages-search.js +19 -7
  69. package/dist/services/messages.d.ts +8 -0
  70. package/dist/services/metadata.d.ts +1 -1
  71. package/dist/services/named-chat.d.ts +20 -0
  72. package/dist/services/named-chat.js +63 -0
  73. package/dist/services/search-all.d.ts +7 -2
  74. package/dist/services/search-all.js +35 -1
  75. package/dist/store/accounts.d.ts +2 -1
  76. package/dist/store/exports.d.ts +2 -1
  77. package/dist/store/exports.js +2 -1
  78. package/dist/store/recover.js +2 -0
  79. package/dist/store/search-index.d.ts +2 -0
  80. package/dist/store/search-index.js +1 -0
  81. package/dist/store/sqlite/account-purge.js +1 -0
  82. package/dist/store/sqlite/crm-files.d.ts +70 -0
  83. package/dist/store/sqlite/crm-files.js +174 -0
  84. package/dist/store/sqlite/crm-settings.d.ts +42 -1
  85. package/dist/store/sqlite/crm-settings.js +46 -2
  86. package/dist/store/sqlite/lucene-fields.d.ts +2 -0
  87. package/dist/store/sqlite/lucene-fields.js +6 -2
  88. package/dist/store/sqlite/lucene.js +13 -7
  89. package/dist/store/sqlite/manifest.js +2 -0
  90. package/dist/store/sqlite/migrations.generated.js +17 -0
  91. package/dist/store/sqlite/schema.d.ts +329 -0
  92. package/dist/store/sqlite/schema.js +28 -0
  93. package/dist/store/sqlite/stems.d.ts +2 -0
  94. package/dist/store/sqlite/stems.js +5 -0
  95. package/dist/store/store.d.ts +3 -0
  96. package/dist/store/store.js +5 -0
  97. package/package.json +2 -2
@@ -1,3 +1,4 @@
1
+ import { withoutFileLinks } from "./files.js";
1
2
  export const isRaw = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
2
3
  export const fieldOf = (value, key) => (isRaw(value) ? value[key] : undefined);
3
4
  export const rawsOf = (value) => (Array.isArray(value) ? value.filter(isRaw) : []);
@@ -59,7 +60,8 @@ export const fullName = (...parts) => parts
59
60
  const optionLabel = (field, option) => field.options?.find(({ id }) => id === String(option))?.label ?? String(option);
60
61
  /**
61
62
  * A record's custom values, by code, as the port keeps them: each with its field's label, and a list field's option
62
- * ids turned into their labels with `option_id` beside (both lists on a multiple field).
63
+ * ids turned into their labels with `option_id` beside (both lists on a multiple field). A file field's tokened link
64
+ * is removed, so it reaches neither the store nor an answer.
63
65
  */
64
66
  export const crmValuesOf = (values, fields) => {
65
67
  const byCode = new Map(fields.map((field) => [field.code, field]));
@@ -67,7 +69,7 @@ export const crmValuesOf = (values, fields) => {
67
69
  const field = byCode.get(code);
68
70
  const label = field?.label ?? null;
69
71
  if (!field?.options)
70
- return [code, { label, value }];
72
+ return [code, { label, value: withoutFileLinks(value) }];
71
73
  if (Array.isArray(value))
72
74
  return [code, { label, value: value.map((one) => optionLabel(field, one)), option_id: value.map(String) }];
73
75
  return [code, { label, value: optionLabel(field, value), option_id: String(value) }];
@@ -1,10 +1,10 @@
1
1
  import * as v from "valibot";
2
2
  /**
3
- * One result of `search all`: a message, a mail, a note, a calendar event, a meeting passage, a deal, a lead, or an
4
- * invoice, payment, order, contract, subscription, product or wallet.
3
+ * One result of `search all`: a message, a mail, a note, a calendar event, a meeting passage, a deal, a lead, the text
4
+ * of a downloaded CRM file, or an invoice, payment, order, contract, subscription, product or wallet.
5
5
  */
6
6
  export declare const hit: v.StrictObjectSchema<{
7
- readonly kind: v.PicklistSchema<["message", "mail", "note", "document", "event", "meeting", "deal", "lead", "invoice", "payment", "order", "contract", "subscription", "product", "wallet"], undefined>;
7
+ readonly kind: v.PicklistSchema<["message", "mail", "note", "document", "event", "meeting", "deal", "lead", "crm_file", "invoice", "payment", "order", "contract", "subscription", "product", "wallet"], undefined>;
8
8
  readonly ref: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>;
9
9
  readonly provider: v.StringSchema<undefined>;
10
10
  readonly url: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
@@ -3,11 +3,22 @@ import { BUSINESS_KINDS } from "../domain/business.js";
3
3
  import { hitFile } from "./attachment.js";
4
4
  import { count, reference, text, time, untrusted } from "./fields.js";
5
5
  /**
6
- * One result of `search all`: a message, a mail, a note, a calendar event, a meeting passage, a deal, a lead, or an
7
- * invoice, payment, order, contract, subscription, product or wallet.
6
+ * One result of `search all`: a message, a mail, a note, a calendar event, a meeting passage, a deal, a lead, the text
7
+ * of a downloaded CRM file, or an invoice, payment, order, contract, subscription, product or wallet.
8
8
  */
9
9
  export const hit = v.strictObject({
10
- kind: v.picklist(["message", "mail", "note", "document", "event", "meeting", "deal", "lead", ...BUSINESS_KINDS]),
10
+ kind: v.picklist([
11
+ "message",
12
+ "mail",
13
+ "note",
14
+ "document",
15
+ "event",
16
+ "meeting",
17
+ "deal",
18
+ "lead",
19
+ "crm_file",
20
+ ...BUSINESS_KINDS,
21
+ ]),
11
22
  ref: reference,
12
23
  provider: text,
13
24
  url: v.optional(text),
@@ -4371,7 +4371,7 @@ export declare const ENTITIES: {
4371
4371
  readonly untrusted: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
4372
4372
  }, undefined>;
4373
4373
  readonly hit: v.StrictObjectSchema<{
4374
- readonly kind: v.PicklistSchema<["message", "mail", "note", "document", "event", "meeting", "deal", "lead", "invoice", "payment", "order", "contract", "subscription", "product", "wallet"], undefined>;
4374
+ readonly kind: v.PicklistSchema<["message", "mail", "note", "document", "event", "meeting", "deal", "lead", "crm_file", "invoice", "payment", "order", "contract", "subscription", "product", "wallet"], undefined>;
4375
4375
  readonly ref: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>;
4376
4376
  readonly provider: v.StringSchema<undefined>;
4377
4377
  readonly url: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
@@ -453,8 +453,19 @@ const OTHERS = [
453
453
  [
454
454
  "crm.foreign-contacts-spent",
455
455
  "permission_error",
456
- "the day's views of contacts and companies that are not yours are spent",
456
+ "the day's reads of records that are not yours (contacts, companies, other people's files) are spent",
457
457
  ],
458
+ validation("crm.files-limit-range", "a files setting takes a whole number within its range; it is never clamped"),
459
+ validation("crm.file-too-large", "the file is larger than the download may take; --max-size raises it up to 2048 MB"),
460
+ validation("crm.files-disk-full", "the account's files folder is at its files.max_total_mb even after dropping"),
461
+ ["crm.file-unavailable", "provider_error", "the CRM did not give the file; its link is never shown"],
462
+ ["crm.files-denied", "permission_error", "the profile's files.download level stops downloading files"],
463
+ [
464
+ "crm.file-exists",
465
+ "conflict",
466
+ "the --dir folder already holds a file of that name, which a download never overwrites",
467
+ ],
468
+ ["crm.scope-missing", "permission_error", "the CRM sign-in lacks a scope one kind of a record's files needs"],
458
469
  [
459
470
  "crm.client-reads-admin-only",
460
471
  "permission_error",
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * A name another person chose cannot climb out of the folder, cannot be a dot file we would then
3
- * hide, and carries no control or direction character to rewrite the terminal or disguise its extension.
3
+ * hide, carries no control or direction character to rewrite the terminal or disguise its extension, and is at most
4
+ * 200 bytes, its extension kept.
4
5
  */
5
6
  export declare const safeName: (name: string | undefined, platform?: NodeJS.Platform) => string | undefined;
@@ -1,7 +1,25 @@
1
- import { basename } from "node:path";
1
+ import { basename, extname } from "node:path";
2
+ /** Below the 255 bytes most file systems allow a name, leaving room for a prefix such as a provider id. */
3
+ const MOST_NAME_BYTES = 200;
4
+ const bytesOf = (text) => Buffer.byteLength(text, "utf8");
5
+ /** A name cut to `most` bytes at a whole character, its extension kept. */
6
+ const shortened = (name, most) => {
7
+ if (bytesOf(name) <= most)
8
+ return name;
9
+ const extension = extname(name);
10
+ const kept = bytesOf(extension) <= 32 ? extension : "";
11
+ let stem = "";
12
+ for (const character of name.slice(0, name.length - kept.length)) {
13
+ if (bytesOf(stem + character) + bytesOf(kept) > most)
14
+ break;
15
+ stem += character;
16
+ }
17
+ return stem + kept;
18
+ };
2
19
  /**
3
20
  * A name another person chose cannot climb out of the folder, cannot be a dot file we would then
4
- * hide, and carries no control or direction character to rewrite the terminal or disguise its extension.
21
+ * hide, carries no control or direction character to rewrite the terminal or disguise its extension, and is at most
22
+ * 200 bytes, its extension kept.
5
23
  */
6
24
  export const safeName = (name, platform = process.platform) => {
7
25
  let plain = name === undefined
@@ -14,5 +32,5 @@ export const safeName = (name, platform = process.platform) => {
14
32
  if (/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(plain))
15
33
  return undefined;
16
34
  }
17
- return plain === "" ? undefined : plain;
35
+ return plain === "" ? undefined : shortened(plain, MOST_NAME_BYTES);
18
36
  };
@@ -52,7 +52,7 @@ export interface MeetingCommandDeps {
52
52
  * asks when the command's key is at `ask` and refuses when nobody can answer. Without it the writes refuse.
53
53
  */
54
54
  askFirst?: (command: Command) => Promise<void>;
55
- /** The run's stop signal; the meeting writes and `meetings invitation` pass it to the service. */
55
+ /** The run's stop signal; `list`, `show`, the meeting writes and `meetings invitation` pass it to the service. */
56
56
  signal?: () => AbortSignal | undefined;
57
57
  }
58
58
  export { addMeetingPassageCommand, createMeetingPassageCommand, type MeetingPassageFlags, meetingPassageRequest, } from "./passage.js";
@@ -50,12 +50,16 @@ const addMeetingCommandsDefinition = (program, deps) => {
50
50
  const opts = command.optsWithGlobals();
51
51
  deps.write(value, opts.json ? "json" : opts.jsonl ? "jsonl" : "text");
52
52
  };
53
- const access = (command, backend) => ({
54
- ...(backend === undefined ? {} : { backend }),
55
- offline: command.optsWithGlobals().offline === true,
56
- timezone: timezoneOf(deps.timezone),
57
- ...(deps.now ? { now: deps.now() } : {}),
58
- });
53
+ const access = (command, backend) => {
54
+ const signal = deps.signal?.();
55
+ return {
56
+ ...(backend === undefined ? {} : { backend }),
57
+ offline: command.optsWithGlobals().offline === true,
58
+ timezone: timezoneOf(deps.timezone),
59
+ ...(deps.now ? { now: deps.now() } : {}),
60
+ ...(signal ? { signal } : {}),
61
+ };
62
+ };
59
63
  const list = queryWordsAfterOptions(group.command("list").description("meetings, newest first: the service's and the stored ones, kept in the store"))
60
64
  .argument("[query...]", "field:value terms that narrow the list — the fields are below")
61
65
  .addHelpText("after", `\n${fieldsHelp(MEETING_QUERY, MEETING_QUERY_GUIDE)}\n${BACKEND_HELP}`);
@@ -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;
@@ -1,5 +1,5 @@
1
1
  import { type FailureContext } from "@wirecat/cli-base";
2
- import { type MeetingPassageReader } from "../passage.js";
2
+ import { type MeetingPassageOutputFormat, type MeetingPassageReader, type MeetingPassageResult } from "../passage.js";
3
3
  export declare const meetingPassageTool: {
4
4
  name: string;
5
5
  description: string;
@@ -50,7 +50,11 @@ export declare const meetingPassageTool: {
50
50
  additionalProperties: boolean;
51
51
  };
52
52
  };
53
- export declare const callMeetingPassageTool: (read: MeetingPassageReader, input: unknown, signal?: AbortSignal, failure?: FailureContext) => Promise<({
53
+ /**
54
+ * `forRun` is how the host prints the passage in this run: `passageForRun` from `@wirecat/cli-core/cli`, which marks
55
+ * the cues in a scheduled agent's run. This module cannot read the run's mark.
56
+ */
57
+ export declare const callMeetingPassageTool: (read: MeetingPassageReader, input: unknown, signal?: AbortSignal, failure?: FailureContext, forRun?: (result: MeetingPassageResult, format: MeetingPassageOutputFormat) => MeetingPassageResult) => Promise<({
54
58
  content: {
55
59
  type: "text";
56
60
  text: string;
@@ -1,5 +1,5 @@
1
1
  import { CliError, errorObjectOf, isCliError, mcpErrorResult } from "@wirecat/cli-base";
2
- import { markedPassage, validateMeetingPassage } from "../passage.js";
2
+ import { markedPassage, validateMeetingPassage, } from "../passage.js";
3
3
  import { agentResult, UNTRUSTED_NEUTRAL } from "./agent-text.js";
4
4
  const count = { type: "integer", minimum: 0, maximum: 999 };
5
5
  export const meetingPassageTool = {
@@ -21,7 +21,11 @@ export const meetingPassageTool = {
21
21
  additionalProperties: false,
22
22
  },
23
23
  };
24
- export const callMeetingPassageTool = async (read, input, signal, failure = {}) => {
24
+ /**
25
+ * `forRun` is how the host prints the passage in this run: `passageForRun` from `@wirecat/cli-core/cli`, which marks
26
+ * the cues in a scheduled agent's run. This module cannot read the run's mark.
27
+ */
28
+ export const callMeetingPassageTool = async (read, input, signal, failure = {}, forRun = (result) => result) => {
25
29
  try {
26
30
  if (!input || typeof input !== "object" || Array.isArray(input))
27
31
  throw new CliError("validation_error", "expected passage arguments");
@@ -40,7 +44,7 @@ export const callMeetingPassageTool = async (read, input, signal, failure = {})
40
44
  const reference = args.reference;
41
45
  validateMeetingPassage(reference, options);
42
46
  signal?.throwIfAborted();
43
- const result = markedPassage(await read(reference, options));
47
+ const result = forRun(markedPassage(await read(reference, options)), options.format);
44
48
  signal?.throwIfAborted();
45
49
  return agentResult({ content: [{ type: "text", text: result.content }], structuredContent: result.packet });
46
50
  }
@@ -35,6 +35,8 @@ export interface MeetingServerAccess {
35
35
  offline?: boolean;
36
36
  now?: number;
37
37
  timezone?: string;
38
+ /** The run's stop signal: handed to the service, and a stopped read never answers from the store instead. */
39
+ signal?: AbortSignal;
38
40
  }
39
41
  type FoundIn = NonNullable<MeetingItem["found_in"]>;
40
42
  interface ServerStep {
@@ -183,15 +183,18 @@ export const askServerForList = async (source, store, accountId, query, access)
183
183
  for (const call of asked) {
184
184
  let cursor = null;
185
185
  for (let page = 0; page < MEETING_SERVER_BOUNDS.pages; page++) {
186
+ access.signal?.throwIfAborted();
186
187
  step.report.calls += 1;
187
188
  let answer;
188
189
  try {
189
- answer = await source.find(call.window, call.terms, cursor);
190
+ answer = await source.find(call.window, call.terms, cursor, access.signal);
190
191
  }
191
192
  catch (error) {
193
+ access.signal?.throwIfAborted();
192
194
  return skip(reasonOf(error), error);
193
195
  }
194
196
  for (const found of answer.meetings) {
197
+ access.signal?.throwIfAborted();
195
198
  if (seen.has(found.meeting.occurrence.id))
196
199
  continue;
197
200
  seen.add(found.meeting.occurrence.id);
@@ -324,12 +327,14 @@ export const meetingShowThrough = async (source, store, accountId, meeting, acce
324
327
  return fromStore("unsupported");
325
328
  if (access.offline)
326
329
  return fromStore("offline");
330
+ access.signal?.throwIfAborted();
327
331
  step.report.calls = 1;
328
332
  let full;
329
333
  try {
330
- full = await source.get(providerId);
334
+ full = await source.get(providerId, access.signal);
331
335
  }
332
336
  catch (error) {
337
+ access.signal?.throwIfAborted();
333
338
  return fromStore(reasonOf(error), error);
334
339
  }
335
340
  if (!full) {
@@ -84,7 +84,7 @@ export interface MeetingSource {
84
84
  * The meetings that may match, for `meetings list`: one page from `cursor` (`null` first). Each meeting's
85
85
  * `occurrence.id` is the one `meetings()` gives, so the row it is kept as is the row `sync` writes.
86
86
  */
87
- find?(window: MeetingWindow, terms: readonly MeetingTerm[], cursor: string | null): Promise<FoundMeetings>;
87
+ find?(window: MeetingWindow, terms: readonly MeetingTerm[], cursor: string | null, signal?: AbortSignal): Promise<FoundMeetings>;
88
88
  /** One meeting by the service's id, for `meetings show`; `null` when the service has none. */
89
- get?(id: string): Promise<FullMeeting | null>;
89
+ get?(id: string, signal?: AbortSignal): Promise<FullMeeting | null>;
90
90
  }
@@ -198,8 +198,9 @@ export const zoomTokenCodec = {
198
198
  });
199
199
  },
200
200
  };
201
- // The keyring's own words go to `--debug` and the run record as the cause, never into the answer; a store that
202
- // echoes what it was handed loses the secret from them first.
201
+ // On a write or a removal the keyring's own words go to `--debug` and the run record as the cause, never into the
202
+ // answer; a store that echoes what it was handed loses the secret from them first. A read's failure is cli-base's own
203
+ // keyring.unreachable, which names the platform's reason.
203
204
  const keyringFailure = (thrown, secret) => {
204
205
  const failure = new CliError("configuration_error", "could not reach the saved sign-in; use an available keyring or file storage", { reason: "oauth.not-saved" });
205
206
  const words = thrown instanceof Error ? thrown.message : String(thrown);
@@ -221,9 +222,25 @@ export const credentialStorage = (options) => {
221
222
  return credentials.read(name)?.secret;
222
223
  }
223
224
  catch (error) {
225
+ // cli-base's own error already says what to do, in words safe for the answer.
226
+ if (error instanceof CliError)
227
+ throw error;
224
228
  throw keyringFailure(error);
225
229
  }
226
230
  };
231
+ // A sign-in on a machine with no keyring writes to the file, so an old entry it cannot read is no old entry. With
232
+ // `storage: "keyring"` there is no file to fall back on: the save would fail too, after the browser.
233
+ const fallsBack = options.credentials.storage !== "keyring";
234
+ const replaced = (name) => {
235
+ try {
236
+ return raw(name);
237
+ }
238
+ catch (error) {
239
+ if (fallsBack && error instanceof CliError && error.details.reason === "keyring.unreachable")
240
+ return undefined;
241
+ throw error;
242
+ }
243
+ };
227
244
  const save = (value, writeOptions) => {
228
245
  try {
229
246
  credentials.write(account, value, writeOptions);
@@ -252,13 +269,13 @@ export const credentialStorage = (options) => {
252
269
  moved,
253
270
  ...(codec.rotating ? { rotating: true } : {}),
254
271
  probe: () => {
255
- raw(account);
272
+ replaced(account);
256
273
  },
257
274
  read: () => {
258
275
  const value = current();
259
276
  return value === undefined ? undefined : codec.decode(value);
260
277
  },
261
- write: (input, writeOptions) => save(codec.encode({ ...input, previous: raw(account), ...(writeOptions?.signIn ? { signIn: true } : {}) }), writeOptions),
278
+ write: (input, writeOptions) => save(codec.encode({ ...input, previous: replaced(account), ...(writeOptions?.signIn ? { signIn: true } : {}) }), writeOptions),
262
279
  remove: () => {
263
280
  try {
264
281
  return credentials.remove(account);
@@ -38,6 +38,8 @@ export interface QueryExecution {
38
38
  id: string;
39
39
  }[];
40
40
  limit: number;
41
+ /** At most this many hits from one chat, so a large chat cannot fill the page; counts and groups ignore it. */
42
+ perChat?: number;
41
43
  newest?: boolean;
42
44
  signal?: AbortSignal;
43
45
  timeLimitMs?: number;
@@ -0,0 +1,10 @@
1
+ import { type Vocabulary } from "./correct.js";
2
+ /** A Cyrillic word as Latin letters, the way a Latin name is written in Russian («хецнер», «ноксвел» for noxvel). */
3
+ export declare const latinSpellings: (word: string) => string[];
4
+ /**
5
+ * For each word no message holds, not even as the beginning of a longer one, the words the store does hold that it
6
+ * may stand for: its Latin spelling or the nearest known spellings of that, and only when there are none, its own
7
+ * nearest known spellings (up to two edits, as `correctWords` allows). A word any message holds is left alone, so a
8
+ * correct word never turns into another.
9
+ */
10
+ export declare const respelled: (vocabulary: Vocabulary, words: string[]) => Promise<Map<string, string[]>>;
@@ -0,0 +1,63 @@
1
+ import { normalize } from "../store/normalize.js";
2
+ import { correctWords } from "./correct.js";
3
+ const LATIN = {
4
+ а: "a",
5
+ б: "b",
6
+ в: "v",
7
+ г: "g",
8
+ д: "d",
9
+ е: "e",
10
+ ж: "zh",
11
+ з: "z",
12
+ и: "i",
13
+ к: "k",
14
+ л: "l",
15
+ м: "m",
16
+ н: "n",
17
+ о: "o",
18
+ п: "p",
19
+ р: "r",
20
+ с: "s",
21
+ т: "t",
22
+ у: "u",
23
+ ф: "f",
24
+ х: "h",
25
+ ц: "ts",
26
+ ч: "ch",
27
+ ш: "sh",
28
+ щ: "sch",
29
+ ъ: "",
30
+ ы: "y",
31
+ ь: "",
32
+ э: "e",
33
+ ю: "yu",
34
+ я: "ya",
35
+ };
36
+ /** A Cyrillic word as Latin letters, the way a Latin name is written in Russian («хецнер», «ноксвел» for noxvel). */
37
+ export const latinSpellings = (word) => {
38
+ if (!/\p{Script=Cyrillic}/u.test(word))
39
+ return [];
40
+ const plain = [...normalize(word)].map((letter) => LATIN[letter] ?? letter).join("");
41
+ return [...new Set([plain, plain.replaceAll("ks", "x")])];
42
+ };
43
+ /**
44
+ * For each word no message holds, not even as the beginning of a longer one, the words the store does hold that it
45
+ * may stand for: its Latin spelling or the nearest known spellings of that, and only when there are none, its own
46
+ * nearest known spellings (up to two edits, as `correctWords` allows). A word any message holds is left alone, so a
47
+ * correct word never turns into another.
48
+ */
49
+ export const respelled = async (vocabulary, words) => {
50
+ const known = await vocabulary.knownTerms(words);
51
+ const found = new Map();
52
+ for (const word of words.filter((one) => !known.has(one))) {
53
+ const latin = latinSpellings(word);
54
+ const held = await vocabulary.knownTerms(latin);
55
+ const nearLatin = await correctWords(vocabulary, latin.filter((one) => !held.has(one)));
56
+ const asLatin = [...new Set([...held, ...[...nearLatin.values()].flat()])];
57
+ // A Latin name found in Latin letters says what the word was; its Cyrillic neighbours are then other words.
58
+ const forms = asLatin.length ? asLatin : ((await correctWords(vocabulary, [word])).get(normalize(word)) ?? []);
59
+ if (forms.length)
60
+ found.set(word, forms);
61
+ }
62
+ return found;
63
+ };