negotium 0.2.31 → 0.2.32

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.
package/dist/main.js CHANGED
@@ -1868,7 +1868,7 @@ var exports_version = {};
1868
1868
  __export(exports_version, {
1869
1869
  NEGOTIUM_VERSION: () => NEGOTIUM_VERSION
1870
1870
  });
1871
- var NEGOTIUM_VERSION = "0.2.31";
1871
+ var NEGOTIUM_VERSION = "0.2.32";
1872
1872
 
1873
1873
  // ../../packages/core/src/agents/codex-native-multi-agent.ts
1874
1874
  import { spawn } from "child_process";
@@ -17473,7 +17473,6 @@ async function runTurnEventStream(topicId, topicTitle, queryId, events, control,
17473
17473
  const emitPendingAssistantMessage = (usage) => {
17474
17474
  const text2 = pendingText.trimEnd();
17475
17475
  pendingText = "";
17476
- pendingSawDelta = false;
17477
17476
  if (silent || !text2.trim())
17478
17477
  return null;
17479
17478
  const message = {
@@ -17546,7 +17545,11 @@ async function runTurnEventStream(topicId, topicTitle, queryId, events, control,
17546
17545
  break;
17547
17546
  }
17548
17547
  case "text":
17549
- if (!pendingSawDelta) {
17548
+ if (pendingSawDelta) {
17549
+ pendingSawDelta = false;
17550
+ break;
17551
+ }
17552
+ {
17550
17553
  const incoming = event.content;
17551
17554
  accumulatedText += incoming;
17552
17555
  pendingText += incoming;
@@ -21904,6 +21907,18 @@ function clearPendingAskForEntry(scope, entry, topicName, reason) {
21904
21907
  function entryFromLabel(entry) {
21905
21908
  return entry.fromTitle?.trim() || entry.from;
21906
21909
  }
21910
+ function callerScope(entry, getTopic2) {
21911
+ const fromTopicId = "fromTopicId" in entry ? entry.fromTopicId : undefined;
21912
+ if (!fromTopicId)
21913
+ return { kind: "unscoped" };
21914
+ const surface = getTopic2(fromTopicId)?.surface;
21915
+ return surface ? { kind: "surface", on: surface } : { kind: "deny" };
21916
+ }
21917
+ function scopeToLookupOpts(scope) {
21918
+ if (scope.kind === "deny")
21919
+ return null;
21920
+ return scope.kind === "surface" ? { surface: scope.on } : {};
21921
+ }
21907
21922
  async function resolveEntryCallerTopic(scope, entry) {
21908
21923
  const { getTopic: getTopic2, getTopicByNameForUser: getTopicByNameForUser2 } = await init_api_topics().then(() => exports_api_topics);
21909
21924
  if (entry.fromTopicId) {
@@ -21911,7 +21926,10 @@ async function resolveEntryCallerTopic(scope, entry) {
21911
21926
  if (byId?.participants.some((p) => p.userId === scope.userId))
21912
21927
  return byId;
21913
21928
  }
21914
- return getTopicByNameForUser2(entry.from, String(scope.userId));
21929
+ const opts = scopeToLookupOpts(callerScope(entry, getTopic2));
21930
+ if (!opts)
21931
+ return null;
21932
+ return getTopicByNameForUser2(entry.from, String(scope.userId), opts);
21915
21933
  }
21916
21934
  function notifyCallerTopic(callerTopicId, targetLabel, message) {
21917
21935
  const msg = {
@@ -22197,7 +22215,8 @@ async function processTopicInbox(args) {
22197
22215
  seenRequestIds.add(entry.requestId);
22198
22216
  }
22199
22217
  const byId = topicId ? getTopic2(topicId) : null;
22200
- const topic = topicId ? byId?.participants.some((participant) => participant.userId === userId) ? byId : null : getTopicByNameForUser2(topicName, userId);
22218
+ const nameLookupOpts = scopeToLookupOpts(callerScope(entry, getTopic2));
22219
+ const topic = topicId ? byId?.participants.some((participant) => participant.userId === userId) ? byId : null : nameLookupOpts && getTopicByNameForUser2(topicName, userId, nameLookupOpts);
22201
22220
  if (!topic) {
22202
22221
  logger.warn({ topicName, from: entry.from }, "session-inbox: topic not found, dropping");
22203
22222
  if (entry.type === "ask") {
@@ -23369,13 +23388,14 @@ function resolveTopicForUser(ctx, ref) {
23369
23388
  if (!trimmed)
23370
23389
  return { error: "Error: topic is required." };
23371
23390
  const notFound = `Error: topic '${trimmed}' not found (or not uniquely named). Use list_topics to see available topics.`;
23391
+ const surface = callerSurface(ctx);
23372
23392
  const byId = getTopic(trimmed);
23373
23393
  if (byId) {
23374
- if (!isParticipant(byId, ctx.userId))
23394
+ if (!isParticipant(byId, ctx.userId) || byId.surface !== surface)
23375
23395
  return { error: notFound };
23376
23396
  return { topic: byId };
23377
23397
  }
23378
- const byTitle = getTopicByNameForUser(trimmed, ctx.userId, { surface: callerSurface(ctx) });
23398
+ const byTitle = getTopicByNameForUser(trimmed, ctx.userId, { surface });
23379
23399
  if (byTitle)
23380
23400
  return { topic: byTitle };
23381
23401
  return { error: notFound };
@@ -39448,6 +39468,13 @@ var init_telegram_api = __esm(() => {
39448
39468
  });
39449
39469
 
39450
39470
  // ../../adapters/telegram/src/commands.ts
39471
+ function resolveTelegramTopicArg(argument, userId) {
39472
+ const byName = getTopicByNameForUser(argument, userId, { surface: "telegram" });
39473
+ if (byName)
39474
+ return byName;
39475
+ const byId = getTopic(argument);
39476
+ return byId?.surface === "telegram" ? byId : null;
39477
+ }
39451
39478
  function createTelegramCommandRouter(context) {
39452
39479
  const { userId, reply, currentTopicId, bindMapping, loadTopic, unloadTopic, abortTurn } = context;
39453
39480
  return async function handleCommand(text2, chatId, threadId, telegramUserId) {
@@ -39544,7 +39571,7 @@ function createTelegramCommandRouter(context) {
39544
39571
  reply(chatId, threadId, "usage: /load <topic>");
39545
39572
  return;
39546
39573
  }
39547
- const candidate = getTopicByNameForUser(argument, userId) ?? getTopic(argument);
39574
+ const candidate = resolveTelegramTopicArg(argument, userId);
39548
39575
  const topic = candidate && isTopicVisible(candidate) ? candidate : null;
39549
39576
  if (!topic || !loadTopic(chatId, topic.id, threadId)) {
39550
39577
  reply(chatId, threadId, `no visible topic matching "${argument}"`);
@@ -39589,7 +39616,7 @@ function createTelegramCommandRouter(context) {
39589
39616
  case "/del!": {
39590
39617
  const force = command === "/del!";
39591
39618
  const topicId = currentTopicId(chatId, threadId);
39592
- const topic = argument ? getTopicByNameForUser(argument, userId) : topicId ? getTopic(topicId) : null;
39619
+ const topic = argument ? resolveTelegramTopicArg(argument, userId) : topicId ? getTopic(topicId) : null;
39593
39620
  if (!topic) {
39594
39621
  reply(chatId, threadId, argument ? `no topic named "${argument}"` : "this chat has no topic \u2014 usage: /del [name]");
39595
39622
  return;
@@ -42957,11 +42984,11 @@ async function peerSupportsRemoteAsk(node) {
42957
42984
  }
42958
42985
  }
42959
42986
  async function findNode(nodeName, fromTopicId) {
42960
- const callerScope = fromTopicId ? getTopic(fromTopicId)?.surfaceScope ?? null : null;
42987
+ const callerScope2 = fromTopicId ? getTopic(fromTopicId)?.surfaceScope ?? null : null;
42961
42988
  const select = (nodes) => {
42962
42989
  let candidates = nodes.filter((node) => node.nodeName === nodeName);
42963
- if (callerScope) {
42964
- candidates = candidates.filter((node) => surfaceScopeForCell(node.viaCellId) === callerScope);
42990
+ if (callerScope2) {
42991
+ candidates = candidates.filter((node) => surfaceScopeForCell(node.viaCellId) === callerScope2);
42965
42992
  }
42966
42993
  if (candidates.length === 0)
42967
42994
  return null;
@@ -43074,12 +43101,12 @@ async function sessions(userId, sourceQueryId, fromTopicId) {
43074
43101
  const selves = new Map(nodes.filter((node) => node.self).map((node) => [node.viaCellId, node]));
43075
43102
  if (selves.size === 0)
43076
43103
  return { ok: false, nodes: [] };
43077
- const callerScope = fromTopicId ? getTopic(fromTopicId)?.surfaceScope ?? null : null;
43104
+ const callerScope2 = fromTopicId ? getTopic(fromTopicId)?.surfaceScope ?? null : null;
43078
43105
  return {
43079
43106
  ok: true,
43080
43107
  nodes: await Promise.all(nodes.filter((node) => {
43081
43108
  const self = selves.get(node.viaCellId);
43082
- if (callerScope && surfaceScopeForCell(node.viaCellId) !== callerScope)
43109
+ if (callerScope2 && surfaceScopeForCell(node.viaCellId) !== callerScope2)
43083
43110
  return false;
43084
43111
  return !node.self && node.nodeName && self && (self.isPrimary || node.isPrimary);
43085
43112
  }).map(async (node) => {
@@ -46036,4 +46063,4 @@ switch (command) {
46036
46063
  }
46037
46064
  }
46038
46065
 
46039
- //# debugId=295C7100524DA6AC64756E2164756E21
46066
+ //# debugId=B3AFD0752FA1AFAA64756E2164756E21