@wirecat/cli-core 0.608.0 → 0.609.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 (68) hide show
  1. package/CHANGELOG.md +67 -1
  2. package/dist/background/deliver.d.ts +12 -1
  3. package/dist/background/deliver.js +38 -5
  4. package/dist/background/report/render.d.ts +61 -0
  5. package/dist/background/report/render.js +208 -0
  6. package/dist/background/report/schema.d.ts +66 -0
  7. package/dist/background/report/schema.js +191 -0
  8. package/dist/background/report/templates/morning-digest.email.en.liquid +79 -0
  9. package/dist/background/report/templates/morning-digest.email.ru.liquid +79 -0
  10. package/dist/background/report/templates/morning-digest.telegram.en.liquid +77 -0
  11. package/dist/background/report/templates/morning-digest.telegram.ru.liquid +77 -0
  12. package/dist/background/report/templates/morning-digest.text.en.liquid +76 -0
  13. package/dist/background/report/templates/morning-digest.text.ru.liquid +76 -0
  14. package/dist/background/report/view.d.ts +88 -0
  15. package/dist/background/report/view.js +152 -0
  16. package/dist/background/schedules.d.ts +6 -1
  17. package/dist/background/schedules.js +24 -7
  18. package/dist/cli/embedding-choice.d.ts +4 -1
  19. package/dist/cli/embedding-choice.js +6 -3
  20. package/dist/cli/messenger/models-command.js +46 -18
  21. package/dist/cli/messenger/search-answers.js +11 -2
  22. package/dist/cli/model-catalogue-command.d.ts +33 -0
  23. package/dist/cli/model-catalogue-command.js +110 -21
  24. package/dist/cli/schedule/schedule-command.js +18 -0
  25. package/dist/cli/store-settings.js +39 -3
  26. package/dist/crm/cli/csv.d.ts +18 -5
  27. package/dist/crm/cli/csv.js +30 -19
  28. package/dist/crm/cli/index.d.ts +1 -0
  29. package/dist/crm/cli/index.js +1 -0
  30. package/dist/embeddings/models.d.ts +185 -5
  31. package/dist/embeddings/models.js +119 -5
  32. package/dist/entities/index.d.ts +24 -0
  33. package/dist/entities/index.js +2 -1
  34. package/dist/entities/model.d.ts +42 -1
  35. package/dist/entities/model.js +20 -1
  36. package/dist/render/liquid.d.ts +14 -0
  37. package/dist/render/liquid.js +30 -0
  38. package/dist/replies/template.js +3 -22
  39. package/dist/search/lucene/plain.js +4 -1
  40. package/dist/search/question-plan.js +2 -1
  41. package/dist/sends/permissions.js +4 -0
  42. package/dist/services/embeddings-maintenance.d.ts +1 -1
  43. package/dist/services/embeddings-maintenance.js +6 -6
  44. package/dist/services/index.d.ts +2 -0
  45. package/dist/services/index.js +2 -0
  46. package/dist/services/meeting-model.d.ts +1 -1
  47. package/dist/services/meeting-model.js +4 -4
  48. package/dist/services/messages-meaning.js +25 -4
  49. package/dist/services/model-downloads.js +1 -1
  50. package/dist/services/notes-search.d.ts +1 -1
  51. package/dist/services/notes-search.js +2 -2
  52. package/dist/services/search-all.d.ts +2 -0
  53. package/dist/services/search-all.js +30 -8
  54. package/dist/services/text-model-choice.d.ts +50 -0
  55. package/dist/services/text-model-choice.js +151 -0
  56. package/dist/store/exports.d.ts +1 -0
  57. package/dist/store/exports.js +1 -0
  58. package/dist/store/index.d.ts +1 -0
  59. package/dist/store/index.js +1 -0
  60. package/dist/store/sqlite/owner-languages.d.ts +13 -0
  61. package/dist/store/sqlite/owner-languages.js +49 -0
  62. package/dist/store/sqlite/reported-relations.js +5 -1
  63. package/dist/store/sqlite/vectors.d.ts +2 -0
  64. package/dist/store/sqlite/vectors.js +5 -0
  65. package/dist/store/vectors.d.ts +2 -0
  66. package/dist/store/vectors.js +1 -0
  67. package/package.json +2 -2
  68. package/parity.json +13 -0
@@ -0,0 +1,49 @@
1
+ import { CliError } from "@wirecat/cli-base";
2
+ const KEY = "ownerLanguages";
3
+ // A fixed list, not Intl.DisplayNames: a Node built with small-icu knows only English names, and the setting
4
+ // must be refused or accepted the same everywhere.
5
+ const ISO_639_1 = new Set(("aa ab ae af ak am an ar as av ay az ba be bg bi bm bn bo br bs ca ce ch co cr cs cu cv cy da de dv dz ee el en " +
6
+ "eo es et eu fa ff fi fj fo fr fy ga gd gl gn gu gv ha he hi ho hr ht hu hy hz ia id ie ig ii ik io is it iu ja jv " +
7
+ "ka kg ki kj kk kl km kn ko kr ks ku kv kw ky la lb lg li ln lo lt lu lv mg mh mi mk ml mn mr ms mt my na nb nd ne " +
8
+ "ng nl nn no nr nv ny oc oj om or os pa pi pl ps pt qu rm rn ro ru rw sa sc sd se sg si sk sl sm sn so sq sr ss st " +
9
+ "su sv sw ta te tg th ti tk tl tn to tr ts tt tw ty ug uk ur uz ve vi vo wa wo xh yi yo za zh zu").split(" "));
10
+ /** Unset, the owner reads Russian, the same default as `AppIdentity.locale`, not the system's language. */
11
+ export const DEFAULT_OWNER_LANGUAGES = ["ru"];
12
+ /** `ru, EN,ru` → `["ru", "en"]`: ISO 639-1 codes in the owner's order, each once. */
13
+ export const parseOwnerLanguages = (value) => {
14
+ const codes = value
15
+ .split(/[\s,]+/)
16
+ .map((one) => one.trim().toLowerCase())
17
+ .filter(Boolean);
18
+ const unknown = codes.filter((one) => !ISO_639_1.has(one));
19
+ if (codes.length === 0 || unknown.length > 0)
20
+ throw new CliError("validation_error", `owner_languages takes ISO 639-1 language codes, the language the owner reads first first (ru,en) — ${unknown.length > 0 ? `not ${unknown.join(", ")}` : "at least one"}`);
21
+ return [...new Set(codes)];
22
+ };
23
+ /** What `config set owner_languages` saved; `undefined` while the default applies, or when a newer tool saved one. */
24
+ export const savedOwnerLanguages = (database) => {
25
+ const row = database.prepare("SELECT value FROM store_settings WHERE key = ?").get(KEY);
26
+ if (!row)
27
+ return undefined;
28
+ try {
29
+ return parseOwnerLanguages(JSON.parse(String(row.value)).join(","));
30
+ }
31
+ catch {
32
+ return undefined;
33
+ }
34
+ };
35
+ /**
36
+ * The languages the owner reads, primary first: everything written for him is in the first; a title quoted in a
37
+ * later one stays untranslated.
38
+ */
39
+ export const ownerLanguages = (database) => savedOwnerLanguages(database) ?? DEFAULT_OWNER_LANGUAGES;
40
+ export const saveOwnerLanguages = (database, languages, now) => {
41
+ if (languages === undefined) {
42
+ database.prepare("DELETE FROM store_settings WHERE key = ?").run(KEY);
43
+ return;
44
+ }
45
+ database
46
+ .prepare("INSERT INTO store_settings (key, value, at) VALUES (?, ?, ?) " +
47
+ "ON CONFLICT (key) DO UPDATE SET value = excluded.value, at = excluded.at")
48
+ .run(KEY, JSON.stringify(languages), now);
49
+ };
@@ -7,6 +7,9 @@ import { relationProposalsOver } from "./relation-proposals.js";
7
7
  import { checkStoredRole } from "./relation-roles.js";
8
8
  import { referenceOfThing, thingOf } from "./things.js";
9
9
  import { write } from "./transaction.js";
10
+ // links_relationship_key's WHERE, word for word: without it SQLite cannot use that partial index, picks
11
+ // (to_type, to_id) and reads every link of a busy end, such as a deal owner's, for each relationship (#2623).
12
+ const KEYED = "kind IN ('member-of', 'related-to', 'reports-to', 'customer-of', 'partner-of') AND to_id IS NOT NULL";
10
13
  const metadataOf = (relation) => relation.metadata && Object.keys(relation.metadata).length ? JSON.stringify(relation.metadata) : null;
11
14
  /** The call, inside a transaction the caller holds: a CRM page saves its rows and their relationships together. */
12
15
  export const syncReportedIn = (context, key, relationships, scope, { source = "import", by = { bot: key.provider, kind: "rule" } } = {}) => {
@@ -26,7 +29,8 @@ export const syncReportedIn = (context, key, relationships, scope, { source = "i
26
29
  };
27
30
  const seen = new Set();
28
31
  const issue = (relation, reason, message) => result.issues.push({ reason, message, from: relation.from, to: relation.to, kind: relation.kind });
29
- const sameKey = "kind = ? AND from_type = ? AND from_id = ? AND to_type = ? AND to_id = ? AND anchor IS NULL AND ifnull(role, '') = ?";
32
+ const sameKey = `${KEYED} AND kind = ? AND from_type = ? AND from_id = ? AND to_type = ? AND to_id = ? ` +
33
+ "AND anchor IS NULL AND ifnull(role, '') = ?";
30
34
  for (const relation of relationships) {
31
35
  let from = thingOf(database, relation.from);
32
36
  let to = thingOf(database, relation.to);
@@ -116,3 +116,5 @@ export declare const readiness: ({ orm }: StoreContext, chatKey: number, model:
116
116
  missing: number;
117
117
  };
118
118
  } | undefined;
119
+ /** The primary key starts with `model`, so each count reads only that model's rows. */
120
+ export declare const vectorCounts: ({ orm }: StoreContext, models: string[]) => Map<string, number>;
@@ -332,3 +332,8 @@ export const readiness = ({ orm }, chatKey, model) => {
332
332
  vectors: { chunks, embedded: Number(vectors?.embedded ?? 0), current, stale, missing: chunks - current - stale },
333
333
  };
334
334
  };
335
+ /** The primary key starts with `model`, so each count reads only that model's rows. */
336
+ export const vectorCounts = ({ orm }, models) => new Map(models.map((model) => [
337
+ model,
338
+ Number(orm.get(sql `SELECT count(*) AS n FROM embeddings WHERE model = ${model}`)?.n ?? 0),
339
+ ]));
@@ -154,6 +154,8 @@ export interface VectorsStore extends AccountVectors {
154
154
  }[]): Promise<void>;
155
155
  /** Which of these chunk hashes already have a vector of `model`. */
156
156
  embeddedHashes(model: string, hashes: string[]): Promise<Set<string>>;
157
+ /** How many chunk texts have a vector of each of these models. */
158
+ vectorCounts(models: string[]): Promise<Map<string, number>>;
157
159
  }
158
160
  export declare const accountVectorsOver: (context: StoreContext, mail: () => MailStore) => AccountVectors;
159
161
  export declare const vectorsStoreOver: (context: StoreContext, keyed: AccountVectors) => VectorsStore;
@@ -275,4 +275,5 @@ export const vectorsStoreOver = (context, keyed) => ({
275
275
  write(context.database, () => vectors.saveVectors(context, model, dims, rows));
276
276
  },
277
277
  embeddedHashes: async (model, hashes) => imageChunks.embeddedHashes(context, model, hashes),
278
+ vectorCounts: async (models) => vectors.vectorCounts(context, models),
278
279
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirecat/cli-core",
3
- "version": "0.608.0",
3
+ "version": "0.609.0",
4
4
  "description": "The messenger-neutral half of a messaging CLI: domain model, message locators, rendering, name resolution, the SQLite seam, the command skeleton and shared read commands, the send guard, run records and the message store",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Viacheslav Ptsarev",
@@ -193,7 +193,7 @@
193
193
  }
194
194
  },
195
195
  "scripts": {
196
- "build": "tsc --build --force && node scripts/bundle-drizzle.ts && node scripts/copy-snowball.ts && node scripts/copy-chart-fonts.ts",
196
+ "build": "tsc --build --force && node scripts/bundle-drizzle.ts && node scripts/copy-snowball.ts && node scripts/copy-chart-fonts.ts && node scripts/copy-report-templates.ts",
197
197
  "check:dist": "node scripts/check-dist.ts",
198
198
  "typecheck": "tsc --build --force --emitDeclarationOnly && tsc -p tsconfig.test.json && tsc -p tsconfig.scripts.json",
199
199
  "lint": "biome check .",
package/parity.json CHANGED
@@ -796,6 +796,10 @@
796
796
  "default": "5s",
797
797
  "note": "max's own copy is worded differently until T6 moves the command onto the shared one (e13)"
798
798
  },
799
+ "--payload": {
800
+ "value": "<json>",
801
+ "meaning": "the data of what to do, as JSON"
802
+ },
799
803
  "--per-chat": {
800
804
  "meaning": "at most this many per chat, such as 1/12h",
801
805
  "value": "<limit>"
@@ -3633,6 +3637,12 @@
3633
3637
  "models": {
3634
3638
  "in": "all"
3635
3639
  },
3640
+ "models add": {
3641
+ "in": "all",
3642
+ "options": {
3643
+ "--payload": "all"
3644
+ }
3645
+ },
3636
3646
  "models download": {
3637
3647
  "in": "all",
3638
3648
  "options": {
@@ -3651,6 +3661,9 @@
3651
3661
  "models list": {
3652
3662
  "in": "all"
3653
3663
  },
3664
+ "models set": {
3665
+ "in": "all"
3666
+ },
3654
3667
  "polls": {
3655
3668
  "in": "all"
3656
3669
  },