negotium 0.6.6 → 0.6.8

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 (30) hide show
  1. package/dist/agent-helpers.js +168 -152
  2. package/dist/agent-helpers.js.map +11 -11
  3. package/dist/{chunk-pxnv3gh2.js → chunk-45qc90k9.js} +2 -2
  4. package/dist/{chunk-pxnv3gh2.js.map → chunk-45qc90k9.js.map} +2 -2
  5. package/dist/hosted-agent.js +2 -2
  6. package/dist/hosted-agent.js.map +2 -2
  7. package/dist/main.js +42 -17
  8. package/dist/main.js.map +13 -13
  9. package/dist/mcp-factories.js +29 -13
  10. package/dist/mcp-factories.js.map +9 -9
  11. package/dist/registry.js +1 -1
  12. package/dist/runtime/src/agents/archiver.ts +25 -7
  13. package/dist/runtime/src/agents/idle-archiver.ts +1 -0
  14. package/dist/runtime/src/application/topic-service.ts +5 -1
  15. package/dist/runtime/src/runtime/turn-event-stream.ts +2 -1
  16. package/dist/runtime/src/runtime/turn-runner.ts +8 -1
  17. package/dist/runtime/src/runtime-gateway.ts +6 -2
  18. package/dist/runtime/src/topics/lifecycle.ts +4 -1
  19. package/dist/runtime/src/topics/session.ts +15 -9
  20. package/dist/runtime/src/version.ts +1 -1
  21. package/dist/runtime-gateway.js +7 -6
  22. package/dist/runtime-gateway.js.map +3 -3
  23. package/dist/types/packages/core/src/agents/archiver.d.ts +3 -1
  24. package/dist/types/packages/core/src/runtime/turn-event-stream.d.ts +1 -0
  25. package/dist/types/packages/core/src/runtime/turn-runner.d.ts +1 -0
  26. package/dist/types/packages/core/src/runtime-gateway.d.ts +2 -2
  27. package/dist/types/packages/core/src/topics/lifecycle.d.ts +2 -0
  28. package/dist/types/packages/core/src/topics/session.d.ts +2 -0
  29. package/dist/types/packages/core/src/version.d.ts +1 -1
  30. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -3674,7 +3674,7 @@ var exports_version = {};
3674
3674
  __export(exports_version, {
3675
3675
  NEGOTIUM_VERSION: () => NEGOTIUM_VERSION
3676
3676
  });
3677
- var NEGOTIUM_VERSION = "0.6.6";
3677
+ var NEGOTIUM_VERSION = "0.6.8";
3678
3678
 
3679
3679
  // ../../packages/core/src/agents/codex-native-multi-agent.ts
3680
3680
  import { spawn as spawn2 } from "child_process";
@@ -12479,6 +12479,7 @@ function createArchiverRuntime(host) {
12479
12479
  const runTurn = (params) => {
12480
12480
  const {
12481
12481
  userId,
12482
+ sourceTopicId,
12482
12483
  topicId,
12483
12484
  topicTitle,
12484
12485
  archivePath,
@@ -12486,6 +12487,7 @@ function createArchiverRuntime(host) {
12486
12487
  messageCount,
12487
12488
  mode = "deleted-topic"
12488
12489
  } = params;
12490
+ const generalTopicId = host.storage.getGeneralTopicId(userId, sourceTopicId);
12489
12491
  let definition;
12490
12492
  try {
12491
12493
  definition = getAgentDefinition();
@@ -12644,7 +12646,7 @@ function createArchiverRuntime(host) {
12644
12646
  }
12645
12647
  }
12646
12648
  const text = finalText.trimEnd();
12647
- finalizeGeneralMemory(host, userId, topicTitle, messageCount, startMs, ok, mode, topicId, ok && text ? { text, agent, model, usage } : undefined);
12649
+ finalizeGeneralMemory(host, userId, topicTitle, messageCount, startMs, ok, mode, topicId, generalTopicId, ok && text ? { text, agent, model, usage } : undefined);
12648
12650
  });
12649
12651
  topicQueues.set(safeTopic, work);
12650
12652
  work.finally(() => {
@@ -12690,14 +12692,14 @@ function findSummaryFile(storage, topicTitle, date, sinceMs, topicId) {
12690
12692
  }
12691
12693
  return best?.path ?? null;
12692
12694
  }
12693
- function finalizeGeneralMemory(host, userId, topicTitle, messageCount, startMs, ok, mode, topicId, generalReply) {
12694
- const generalTopicId = host.storage.getGeneralTopicId(userId);
12695
+ function finalizeGeneralMemory(host, userId, topicTitle, messageCount, startMs, ok, mode, topicId, generalTopicId, generalReply) {
12696
+ const resolvedGeneralTopicId = generalTopicId ?? host.storage.getGeneralTopicId(userId, topicId);
12695
12697
  const date = host.config.now().toISOString().slice(0, 10);
12696
12698
  try {
12697
12699
  const summaryPath = ok ? findSummaryFile(host.storage, topicTitle, date, startMs, topicId) : null;
12698
12700
  const summaryMd = summaryPath ? host.storage.readTextFile(summaryPath) : "";
12699
12701
  const oneLine = summaryMd && distillOneLine(summaryMd) || `Archived ${messageCount} messages`;
12700
- const prev = host.storage.getTopicBrief(generalTopicId);
12702
+ const prev = host.storage.getTopicBrief(resolvedGeneralTopicId);
12701
12703
  const prevEntries = (prev?.briefMd ?? "").split(`
12702
12704
  `).map((l) => l.trim()).filter((l) => l.startsWith("- "));
12703
12705
  const newEntry = `- **${topicTitle}** (${date}): ${oneLine}`;
@@ -12712,7 +12714,7 @@ Recent memory digest distilled from archived topics (deletions and idle/session-
12712
12714
  ## Recent Archives
12713
12715
  ${rolled.join(`
12714
12716
  `)}`;
12715
- host.storage.setTopicBrief(generalTopicId, {
12717
+ host.storage.setTopicBrief(resolvedGeneralTopicId, {
12716
12718
  briefMd,
12717
12719
  ...summaryMd ? { latestSummaryMd: summaryMd, summaryDate: date } : {}
12718
12720
  });
@@ -12731,13 +12733,13 @@ ${rolled.join(`
12731
12733
  } : { authorId: "system" };
12732
12734
  const msg = {
12733
12735
  id: host.config.createId(),
12734
- topicId: generalTopicId,
12736
+ topicId: resolvedGeneralTopicId,
12735
12737
  text,
12736
12738
  ...replyMeta,
12737
12739
  createdAt: host.config.now().toISOString()
12738
12740
  };
12739
12741
  host.messaging.appendMessage(msg);
12740
- host.messaging.broadcastMessage(generalTopicId, msg);
12742
+ host.messaging.broadcastMessage(resolvedGeneralTopicId, msg);
12741
12743
  } catch (err) {
12742
12744
  host.config.warn({ err, topicTitle }, "archiver: failed to post #General notification");
12743
12745
  }
@@ -12759,6 +12761,7 @@ var init_archiver = __esm(async () => {
12759
12761
  init_background_session_policy();
12760
12762
  await init_api_messages();
12761
12763
  await init_api_topic_brief();
12764
+ await init_api_topics();
12762
12765
  await init_wiki();
12763
12766
  init_wiki_summary_names();
12764
12767
  await init_personal_general();
@@ -12770,7 +12773,12 @@ var init_archiver = __esm(async () => {
12770
12773
  readTextFile: (path) => readFileSync14(path, "utf-8"),
12771
12774
  fileSize: (path) => statSync7(path).size,
12772
12775
  fileModifiedAt: (path) => statSync7(path).mtimeMs,
12773
- getGeneralTopicId: (userId) => ensurePersonalGeneral(userId).id,
12776
+ getGeneralTopicId: (userId, sourceTopicId) => {
12777
+ const source = sourceTopicId ? getTopic(sourceTopicId) : null;
12778
+ return source ? ensurePersonalGeneral(userId, source.surface, {
12779
+ surfaceScope: source.surfaceScope ?? null
12780
+ }).id : ensurePersonalGeneral(userId).id;
12781
+ },
12774
12782
  getTopicBrief,
12775
12783
  setTopicBrief: (topicId, fields) => {
12776
12784
  setTopicBrief(topicId, fields);
@@ -13270,6 +13278,7 @@ function archiveActiveTopicForMemory(topicId, userId, options) {
13270
13278
  const memoryTitle = memoryTopic.memoryKey?.trim() || memoryTopic.title;
13271
13279
  const launched = (options.launchArchiver ?? runArchiverTurn)({
13272
13280
  userId,
13281
+ sourceTopicId: topic.id,
13273
13282
  topicId: memoryTopic.id,
13274
13283
  topicTitle: memoryTitle,
13275
13284
  archivePath: job.archivePath,
@@ -14074,7 +14083,7 @@ async function restartTopicSession(topicId, userId, reason = "topic-session-rest
14074
14083
  const memoryArchiveSettled = new Promise((resolve15) => {
14075
14084
  settleMemoryArchive = resolve15;
14076
14085
  });
14077
- const archiveStatus = (options.archiveMemory ?? archiveActiveTopicForMemory)(topicId, userId, {
14086
+ const archiveStatus = (options.archiveMemory ?? archiveActiveTopicForMemory)(topicId, options.memoryUserId ?? userId, {
14078
14087
  reason: "reset",
14079
14088
  minMessages: 1,
14080
14089
  minExchanges: MIN_MEMORY_ARCHIVE_EXCHANGES,
@@ -17065,7 +17074,8 @@ async function deleteTopicCascadeImpl(topic, userId, options, deletingAncestorId
17065
17074
  const memoryTopic = topic.memoryKey ? topic : getTopicMemoryOrigin(topicId) ?? topic;
17066
17075
  const memoryTitle = memoryTopic.memoryKey?.trim() || memoryTopic.title;
17067
17076
  runArchiverTurn({
17068
- userId,
17077
+ userId: options.memoryUserId ?? userId,
17078
+ sourceTopicId: topicId,
17069
17079
  ...memoryTopic.id !== topicId && !deletingTopicIds.has(memoryTopic.id) ? { topicId: memoryTopic.id } : {},
17070
17080
  topicTitle: memoryTitle,
17071
17081
  archivePath: archived.path,
@@ -18335,7 +18345,7 @@ ${JSON.stringify(event.input ?? {})}`);
18335
18345
  }
18336
18346
  }
18337
18347
  if (!silent) {
18338
- scheduleIdleArchiveForTopic(topicId, userId);
18348
+ scheduleIdleArchiveForTopic(topicId, execution?.actorUserId ?? userId);
18339
18349
  hub.broadcastDone(topicId, queryId, event.usage ? {
18340
18350
  input: event.usage.inputTokens,
18341
18351
  output: event.usage.outputTokens,
@@ -19721,7 +19731,13 @@ function startAiTurn(params) {
19721
19731
  WsHub.get().broadcastTyping(topicId, "ai");
19722
19732
  WsHub.get().broadcastAiActive(topicId, queryId);
19723
19733
  }
19724
- streamAgentEvents(topicId, topic.title, queryId, events, control, agentKind, resolvedModel, resolvedEffort, userId, !sessionRetried, onSessionId, { silent, peerBridge, sourceNode, ...threadRootId ? { threadRootId } : {} }).then(async (streamOutcome) => {
19734
+ streamAgentEvents(topicId, topic.title, queryId, events, control, agentKind, resolvedModel, resolvedEffort, userId, !sessionRetried, onSessionId, {
19735
+ silent,
19736
+ actorUserId: params.actorUserId,
19737
+ peerBridge,
19738
+ sourceNode,
19739
+ ...threadRootId ? { threadRootId } : {}
19740
+ }).then(async (streamOutcome) => {
19725
19741
  let outcome = streamOutcome;
19726
19742
  if (outcome.kind === "session-expired") {
19727
19743
  const retry = resolveSessionRetry({
@@ -21406,6 +21422,7 @@ var init_topic_service = __esm(async () => {
21406
21422
  }
21407
21423
  await deleteTopicCascade(topic, params.userId, {
21408
21424
  ...params.force !== undefined ? { force: params.force } : {},
21425
+ ...params.memoryUserId !== undefined ? { memoryUserId: params.memoryUserId } : {},
21409
21426
  ...params.allowManager !== undefined ? { allowManager: params.allowManager } : {},
21410
21427
  ...params.skipArchive !== undefined ? { skipArchive: params.skipArchive } : {},
21411
21428
  ...params.purgeLogs !== undefined ? { purgeLogs: params.purgeLogs } : {}
@@ -21413,7 +21430,9 @@ var init_topic_service = __esm(async () => {
21413
21430
  },
21414
21431
  async reset(params) {
21415
21432
  ownerTopic(params.topicId, params.userId);
21416
- return restartTopicSession(params.topicId, params.userId, params.reason);
21433
+ return restartTopicSession(params.topicId, params.userId, params.reason, {
21434
+ memoryUserId: params.actorUserId
21435
+ });
21417
21436
  },
21418
21437
  async compact(params) {
21419
21438
  ownerTopic(params.topicId, params.userId);
@@ -33013,10 +33032,12 @@ function createNodeControlHandler(options) {
33013
33032
  if (!topic || !topicInRequestScope(req, topic))
33014
33033
  return jsonError(404, "Topic not found");
33015
33034
  const userId = requiredText(body.userId, "userId");
33035
+ const actorUserId = body.actorUserId === undefined ? undefined : requiredText(body.actorUserId, "actorUserId");
33016
33036
  const reason = body.reason === undefined ? undefined : requiredText(body.reason, "reason");
33017
33037
  const result = await topicService.reset({
33018
33038
  topicId,
33019
33039
  userId,
33040
+ actorUserId,
33020
33041
  reason: reason ?? "runtime-contract-session-reset"
33021
33042
  });
33022
33043
  if (result.isError)
@@ -33037,10 +33058,12 @@ function createNodeControlHandler(options) {
33037
33058
  if (!topic || !topicInRequestScope(req, topic))
33038
33059
  return jsonError(404, "Topic not found");
33039
33060
  const userId = requiredText(body.userId, "userId");
33061
+ const actorUserId = body.actorUserId === undefined ? undefined : requiredText(body.actorUserId, "actorUserId");
33040
33062
  const reason = body.reason === undefined ? undefined : requiredText(body.reason, "reason");
33041
33063
  const result = await topicService.compact({
33042
33064
  topicId,
33043
33065
  userId,
33066
+ actorUserId,
33044
33067
  reason: reason ?? "runtime-contract-session-compact",
33045
33068
  compactSession: options.compactSession
33046
33069
  });
@@ -33128,8 +33151,9 @@ function createNodeControlHandler(options) {
33128
33151
  if (!topic || !topicInRequestScope(req, topic))
33129
33152
  return jsonError(404, "Topic not found");
33130
33153
  const userId = requiredText(url.searchParams.get("user"), "user");
33154
+ const actorUserId = url.searchParams.get("actor")?.trim() || undefined;
33131
33155
  try {
33132
- await topicService.delete({ topicId, userId });
33156
+ await topicService.delete({ topicId, userId, memoryUserId: actorUserId });
33133
33157
  } catch (err2) {
33134
33158
  if (err2 instanceof TopicServiceError) {
33135
33159
  const status = err2.code === "TOPIC_NOT_FOUND" ? 404 : err2.code === "TOPIC_FORBIDDEN" ? 403 : 400;
@@ -33961,7 +33985,8 @@ async function startDefaultNode(opts = {}) {
33961
33985
  const modules = [];
33962
33986
  if (process.env.NEGOTIUM_CRON !== "0") {
33963
33987
  const { createCronModule: createCronModule2 } = await init_src4().then(() => exports_src2);
33964
- modules.push(createCronModule2());
33988
+ const trustedLocal = process.env.NEGOTIUM_CRON_TRUSTED_LOCAL === "1";
33989
+ modules.push(createCronModule2(trustedLocal ? { host: { authorize: () => true } } : {}));
33965
33990
  }
33966
33991
  const port = opts.port === 0 ? readFixedNodePort() ?? await availableLoopbackPort() : opts.port;
33967
33992
  return startNode({ ...opts, port, modules });
@@ -48727,4 +48752,4 @@ switch (command) {
48727
48752
  }
48728
48753
  }
48729
48754
 
48730
- //# debugId=679BF40C457A90DE64756E2164756E21
48755
+ //# debugId=13376A79B7F9FD5464756E2164756E21