openmates 0.27.0-alpha.79 → 0.27.0-alpha.80

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.
@@ -6260,11 +6260,14 @@ async function decodePersonalProjectCandidates(client2, rows2) {
6260
6260
  };
6261
6261
  }));
6262
6262
  }
6263
- async function loadActiveCliProjectContext(client2, chatId, text8, onCatalog) {
6264
- const active = await client2.getActiveProjectFocus(chatId);
6263
+ async function loadActiveCliProjectContext(client2, chatId, text8, onCatalog, prefetched) {
6264
+ const active = await (prefetched?.activeFocusRead ?? client2.getActiveProjectFocus(chatId));
6265
+ prefetched?.assertCurrent();
6265
6266
  if (!active) return {};
6266
6267
  const options = { teamId: active.team_id, personal: !active.team_id };
6267
- const detail = await client2.getProject(active.project_id, options);
6268
+ const detail = prefetched ? await prefetched.projectRead : await client2.getProject(active.project_id, options);
6269
+ prefetched?.assertCurrent();
6270
+ if (!detail) throw new Error("Active Project discovery unavailable.");
6268
6271
  const key = await client2.decryptProjectKey(detail.project, options);
6269
6272
  const result = {
6270
6273
  projectId: active.project_id,
@@ -6317,6 +6320,7 @@ async function loadActiveCliProjectContext(client2, chatId, text8, onCatalog) {
6317
6320
  }
6318
6321
  onCatalog?.(result.project_focus_catalog ?? []);
6319
6322
  let selected = [];
6323
+ prefetched?.assertCurrent();
6320
6324
  if (text8?.trim() && candidates.length) selected = await client2.selectProjectContext(
6321
6325
  active.project_id,
6322
6326
  { chat_id: chatId, text: text8.slice(0, 8e3), candidates: candidates.slice(0, 24) },
@@ -6444,6 +6448,43 @@ function taskContextOwner(client2) {
6444
6448
  throw new Error("Task context workspace changed");
6445
6449
  };
6446
6450
  }
6451
+ var prefetchedDiscovery = /* @__PURE__ */ new WeakMap();
6452
+ var discoveryScope = (options) => JSON.stringify([options.teamId ?? null, options.personal === true]);
6453
+ function prefetchCliJevDiscovery(client2, chatId, options) {
6454
+ const assertCurrent = taskContextOwner(client2);
6455
+ const activeFocusRead = client2.getActiveProjectFocus(chatId);
6456
+ const projectRead = activeFocusRead.then((active) => {
6457
+ assertCurrent();
6458
+ return active ? client2.getProject(active.project_id, { teamId: active.team_id, personal: !active.team_id }) : null;
6459
+ });
6460
+ void activeFocusRead.catch(() => {
6461
+ });
6462
+ void projectRead.catch(() => {
6463
+ });
6464
+ const ticket = Object.freeze({});
6465
+ prefetchedDiscovery.set(ticket, {
6466
+ client: client2,
6467
+ chatId,
6468
+ scope: discoveryScope(options),
6469
+ assertCurrent,
6470
+ activeFocusRead,
6471
+ projectRead,
6472
+ plansRead: client2.listUserPlans({ ...options, chatId, activeOnly: false }).catch(() => []),
6473
+ directoryRead: client2.listUserTaskDiscoveryPage(options).catch(() => []),
6474
+ linkedRead: client2.listUserTasks({ ...options, chatId, limit: 100 }).catch(() => [])
6475
+ });
6476
+ return ticket;
6477
+ }
6478
+ function consumeDiscovery(client2, chatId, options, ticket) {
6479
+ if (!ticket) return;
6480
+ const reads = prefetchedDiscovery.get(ticket);
6481
+ prefetchedDiscovery.delete(ticket);
6482
+ if (!reads || reads.client !== client2 || reads.chatId !== chatId || reads.scope !== discoveryScope(options)) {
6483
+ throw new Error("Invalid same-send context discovery ticket.");
6484
+ }
6485
+ reads.assertCurrent();
6486
+ return reads;
6487
+ }
6447
6488
  async function collectRelatedCliTaskContext(client2, chatId, options, records, nowSeconds3 = Date.now() / 1e3, requiredIds = /* @__PURE__ */ new Set()) {
6448
6489
  const assertTaskOwner = taskContextOwner(client2);
6449
6490
  const owned = records.filter((record10) => typeof record10.task_id === "string" && record10.task_id.length > 0 && record10.task_id.length <= 128 && Number.isSafeInteger(record10.version) && Number(record10.version) >= 1);
@@ -6504,8 +6545,13 @@ async function collectRelatedCliTaskContext(client2, chatId, options, records, n
6504
6545
  return candidates;
6505
6546
  }
6506
6547
  async function prepareCliJevContext(client2, chatId, options, supplied = {}, text8, discovery = {}) {
6507
- const assertTaskOwner = taskContextOwner(client2);
6508
- const plansRead = discovery.sdkMintedChatId ? Promise.resolve([]) : typeof client2.listUserPlans === "function" ? client2.listUserPlans({ ...options, chatId, activeOnly: false }).catch(() => []) : Promise.resolve([]);
6548
+ const prefetched = consumeDiscovery(client2, chatId, options, discovery.prefetchedDiscovery);
6549
+ const currentOwner3 = taskContextOwner(client2);
6550
+ const assertTaskOwner = () => {
6551
+ currentOwner3();
6552
+ prefetched?.assertCurrent();
6553
+ };
6554
+ const plansRead = prefetched?.plansRead ?? (discovery.sdkMintedChatId ? Promise.resolve([]) : typeof client2.listUserPlans === "function" ? client2.listUserPlans({ ...options, chatId, activeOnly: false }).catch(() => []) : Promise.resolve([]));
6509
6555
  let candidates = [];
6510
6556
  let active = {};
6511
6557
  let tasks = [];
@@ -6514,12 +6560,13 @@ async function prepareCliJevContext(client2, chatId, options, supplied = {}, tex
6514
6560
  const catalogReady = new Promise((resolve20) => {
6515
6561
  resolveCatalog = resolve20;
6516
6562
  });
6517
- const activeReady = discovery.sdkMintedChatId ? Promise.resolve().then(() => resolveCatalog([])) : loadActiveCliProjectContext(client2, chatId, text8, resolveCatalog).then((value) => {
6563
+ const activeReady = discovery.sdkMintedChatId ? Promise.resolve().then(() => resolveCatalog([])) : loadActiveCliProjectContext(client2, chatId, text8, resolveCatalog, prefetched).then((value) => {
6518
6564
  active = value;
6519
6565
  }).catch(() => {
6520
6566
  }).finally(() => resolveCatalog([]));
6521
6567
  await Promise.all([
6522
6568
  (discovery.verifiedProjectCandidates ? Promise.resolve(discovery.verifiedProjectCandidates) : discovery.usePersonalRoutingDirectory ? client2.listPersonalProjectRoutingDirectory().then((rows2) => decodePersonalProjectCandidates(client2, rows2)) : discoverCliProjectCandidates(client2, options, Boolean(discovery.onProjectRouting))).then((value) => {
6569
+ assertTaskOwner();
6523
6570
  candidates = value;
6524
6571
  discovery.onProjectRouting?.({ project_focus_candidates: (discovery.verifiedProjectCandidates ?? supplied.project_focus_candidates ?? value).slice(0, 40) });
6525
6572
  }).catch((error) => {
@@ -6528,8 +6575,8 @@ async function prepareCliJevContext(client2, chatId, options, supplied = {}, tex
6528
6575
  (async () => {
6529
6576
  const taskClient = client2;
6530
6577
  const [directory, linked] = await Promise.all([
6531
- taskClient.listUserTaskDiscoveryPage?.(options).catch(() => []) ?? Promise.resolve([]),
6532
- discovery.sdkMintedChatId ? Promise.resolve([]) : client2.listUserTasks({ ...options, chatId, limit: 100 }).catch(() => [])
6578
+ prefetched?.directoryRead ?? taskClient.listUserTaskDiscoveryPage?.(options).catch(() => []) ?? Promise.resolve([]),
6579
+ prefetched?.linkedRead ?? (discovery.sdkMintedChatId ? Promise.resolve([]) : client2.listUserTasks({ ...options, chatId, limit: 100 }).catch(() => []))
6533
6580
  ]);
6534
6581
  assertTaskOwner();
6535
6582
  const records = /* @__PURE__ */ new Map();
@@ -16399,6 +16446,10 @@ var OpenMatesClient = class _OpenMatesClient {
16399
16446
  params.learningMode?.ageGroup ?? null
16400
16447
  ]);
16401
16448
  if (!params.incognito && params.chatId) readSavedPrivacyHistory();
16449
+ const followupDiscoveryOwner = !params.incognito && params.chatId && !teamId && !params.projectId ? this.preparedChatOwner(this.requireSession(), teamId) : null;
16450
+ const followupDiscoveryRead = followupDiscoveryOwner ? withHttpAbortSignal(historyAbort.signal, async () => prefetchCliJevDiscovery(this, chatId, { personal: true, teamId })) : null;
16451
+ void followupDiscoveryRead?.catch(() => {
16452
+ });
16402
16453
  const memoryStartedAt = performance.now();
16403
16454
  let availableMemories = params.memorySnapshot ?? [];
16404
16455
  let memoryCountsLoaded = false;
@@ -16895,7 +16946,12 @@ var OpenMatesClient = class _OpenMatesClient {
16895
16946
  messagePayload.client_context_request_id = contextRequestId;
16896
16947
  }
16897
16948
  pendingContext = (async () => {
16949
+ const prefetchedDiscovery2 = followupDiscoveryRead ? await followupDiscoveryRead : void 0;
16950
+ if (followupDiscoveryOwner && !this.preparedChatOwnerCurrent(followupDiscoveryOwner, teamId)) {
16951
+ throw new Error("Chat workspace changed during context discovery.");
16952
+ }
16898
16953
  const prepared = earlyContext ? await earlyContext : { ok: true, value: await withHttpAbortSignal(earlyContextAbort.signal, () => prepareCliJevContext(this, chatId, contextScope, suppliedContext, finalMessage, {
16954
+ prefetchedDiscovery: prefetchedDiscovery2,
16899
16955
  sdkMintedChatId,
16900
16956
  onRouting: publishRouting,
16901
16957
  verifiedProjectCandidates: verifiedProjectCandidates ?? void 0,
@@ -23103,7 +23159,13 @@ Required: ${schema.required.join(", ")}`
23103
23159
  clearInteractiveChatViewer() {
23104
23160
  const controller = this.interactiveViewerOpenController;
23105
23161
  this.interactiveViewerOpenController = null;
23106
- controller?.abort();
23162
+ if (controller) {
23163
+ const reason = Object.assign(new Error("Interactive chat viewer superseded"), {
23164
+ name: "OpenMatesViewerSupersededError",
23165
+ code: "OPENMATES_VIEWER_SUPERSEDED"
23166
+ });
23167
+ controller.abort(reason);
23168
+ }
23107
23169
  this.interactiveViewerGeneration = (this.interactiveViewerGeneration ?? 0) + 1;
23108
23170
  this.interactiveViewerChatId = null;
23109
23171
  const ws = this.interactiveViewerSocket;
package/dist/cli.js CHANGED
@@ -21,7 +21,7 @@ import {
21
21
  shouldRequireTrustedAccountGuard,
22
22
  waitForSafeE2ETotpWindow,
23
23
  waitForWorkflowRun
24
- } from "./chunk-RIVIWS3I.js";
24
+ } from "./chunk-VTD4VHNF.js";
25
25
  import "./chunk-IWKP55ZB.js";
26
26
  import "./chunk-F2U6KIMR.js";
27
27
  import "./chunk-W5Q6FXNZ.js";
package/dist/index.js CHANGED
@@ -44,7 +44,7 @@ import {
44
44
  selectAssistantMessagesForSpeech,
45
45
  serializeToYaml,
46
46
  summarizeAssistantSpeech
47
- } from "./chunk-RIVIWS3I.js";
47
+ } from "./chunk-VTD4VHNF.js";
48
48
  import "./chunk-IWKP55ZB.js";
49
49
  import "./chunk-F2U6KIMR.js";
50
50
  import "./chunk-W5Q6FXNZ.js";
@@ -17,47 +17,47 @@
17
17
  {
18
18
  "name": "libggml-base.so",
19
19
  "bytes": 1110088,
20
- "sha256": "636d0eea820a4c50419cedaf017c101318cc957cbf30d7c10eed76e58a0eb023"
20
+ "sha256": "c6d10b8188dbc89a72589bef007cd007c45b4ea6dfc10e406b5ca88610e570b8"
21
21
  },
22
22
  {
23
23
  "name": "libggml-base.so.0",
24
24
  "bytes": 1110088,
25
- "sha256": "636d0eea820a4c50419cedaf017c101318cc957cbf30d7c10eed76e58a0eb023"
25
+ "sha256": "c6d10b8188dbc89a72589bef007cd007c45b4ea6dfc10e406b5ca88610e570b8"
26
26
  },
27
27
  {
28
28
  "name": "libggml-base.so.0.15.1",
29
29
  "bytes": 1110088,
30
- "sha256": "636d0eea820a4c50419cedaf017c101318cc957cbf30d7c10eed76e58a0eb023"
30
+ "sha256": "c6d10b8188dbc89a72589bef007cd007c45b4ea6dfc10e406b5ca88610e570b8"
31
31
  },
32
32
  {
33
33
  "name": "libggml-cpu.so",
34
34
  "bytes": 869800,
35
- "sha256": "6a778c182f6d27081ec59e9a3e47e38e11081396a579073cce8c2e082fe405de"
35
+ "sha256": "79eab04afa8a345c040fd5eb6590a05b04863c6cb9b4c1fed97c2d32bf93a8d1"
36
36
  },
37
37
  {
38
38
  "name": "libggml-cpu.so.0",
39
39
  "bytes": 869800,
40
- "sha256": "6a778c182f6d27081ec59e9a3e47e38e11081396a579073cce8c2e082fe405de"
40
+ "sha256": "79eab04afa8a345c040fd5eb6590a05b04863c6cb9b4c1fed97c2d32bf93a8d1"
41
41
  },
42
42
  {
43
43
  "name": "libggml-cpu.so.0.15.1",
44
44
  "bytes": 869800,
45
- "sha256": "6a778c182f6d27081ec59e9a3e47e38e11081396a579073cce8c2e082fe405de"
45
+ "sha256": "79eab04afa8a345c040fd5eb6590a05b04863c6cb9b4c1fed97c2d32bf93a8d1"
46
46
  },
47
47
  {
48
48
  "name": "libggml.so",
49
49
  "bytes": 1899104,
50
- "sha256": "0101ffecb825b3648f287ed70367ef7cb1addfc9545feb820bfa9601572e846c"
50
+ "sha256": "e5276ea43e5719ab303adb0c1e7cef05e6c22db6642ec8e5216d2dd2000814cf"
51
51
  },
52
52
  {
53
53
  "name": "libggml.so.0",
54
54
  "bytes": 1899104,
55
- "sha256": "0101ffecb825b3648f287ed70367ef7cb1addfc9545feb820bfa9601572e846c"
55
+ "sha256": "e5276ea43e5719ab303adb0c1e7cef05e6c22db6642ec8e5216d2dd2000814cf"
56
56
  },
57
57
  {
58
58
  "name": "libggml.so.0.15.1",
59
59
  "bytes": 1899104,
60
- "sha256": "0101ffecb825b3648f287ed70367ef7cb1addfc9545feb820bfa9601572e846c"
60
+ "sha256": "e5276ea43e5719ab303adb0c1e7cef05e6c22db6642ec8e5216d2dd2000814cf"
61
61
  },
62
62
  {
63
63
  "name": "openmates-pii-worker",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openmates",
3
- "version": "0.27.0-alpha.79",
3
+ "version": "0.27.0-alpha.80",
4
4
  "description": "OpenMates CLI and SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",