negotium 0.21.2 → 0.22.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 (35) hide show
  1. package/dist/agent-helpers.js +52 -6
  2. package/dist/agent-helpers.js.map +7 -7
  3. package/dist/background-bash.js.map +1 -1
  4. package/dist/browser-runtime.js.map +1 -1
  5. package/dist/{chunk-z3qhxy33.js → chunk-bbwa785m.js} +2 -2
  6. package/dist/{chunk-z3qhxy33.js.map → chunk-bbwa785m.js.map} +2 -2
  7. package/dist/chunk-pvp197f1.js.map +1 -1
  8. package/dist/chunk-zjz52hzq.js.map +1 -1
  9. package/dist/hosted-agent.js +2 -2
  10. package/dist/hosted-agent.js.map +2 -2
  11. package/dist/main.js +137 -41
  12. package/dist/main.js.map +12 -12
  13. package/dist/mcp-factories.js +52 -6
  14. package/dist/mcp-factories.js.map +7 -7
  15. package/dist/media.js.map +1 -1
  16. package/dist/prompts.js.map +1 -1
  17. package/dist/query-runtime.js +14 -2
  18. package/dist/query-runtime.js.map +4 -4
  19. package/dist/registry.js +1 -1
  20. package/dist/runtime/src/mcp/session-comm/server.ts +2 -2
  21. package/dist/runtime/src/query/active-rooms.ts +22 -2
  22. package/dist/runtime/src/runtime/inbox.ts +74 -41
  23. package/dist/runtime/src/runtime/turn-runner.ts +4 -2
  24. package/dist/runtime/src/storage/token-stats.ts +62 -1
  25. package/dist/runtime/src/types.ts +6 -1
  26. package/dist/runtime/src/version.ts +1 -1
  27. package/dist/runtime-helpers.js.map +1 -1
  28. package/dist/storage.js +36 -2
  29. package/dist/storage.js.map +4 -4
  30. package/dist/types/packages/core/src/query/active-rooms.d.ts +8 -2
  31. package/dist/types/packages/core/src/storage/token-stats.d.ts +9 -0
  32. package/dist/types/packages/core/src/types.d.ts +6 -1
  33. package/dist/types/packages/core/src/version.d.ts +1 -1
  34. package/dist/vault.js.map +1 -1
  35. package/package.json +2 -2
@@ -5237,7 +5237,7 @@ var init_codex = __esm(async () => {
5237
5237
  });
5238
5238
 
5239
5239
  // ../../packages/core/src/version.ts
5240
- var NEGOTIUM_VERSION = "0.21.2";
5240
+ var NEGOTIUM_VERSION = "0.22.0";
5241
5241
 
5242
5242
  // ../../packages/core/src/agents/codex-native-multi-agent.ts
5243
5243
  import { spawn as spawn2 } from "child_process";
@@ -8866,8 +8866,20 @@ class InterSessionQueue {
8866
8866
  keysForRoom() {
8867
8867
  return Array.from(this.queue.keys());
8868
8868
  }
8869
- drop(topicId) {
8869
+ drop(topicId, reason = "target session was stopped before the request ran") {
8870
+ const bucket = this.queue.get(topicId);
8870
8871
  this.queue.delete(topicId);
8872
+ if (!bucket)
8873
+ return 0;
8874
+ const dropped = bucket.items.slice(bucket.head);
8875
+ for (const inject of dropped) {
8876
+ try {
8877
+ inject.onSettled?.({ queryId: "", kind: "error", error: reason });
8878
+ } catch (err) {
8879
+ logger.warn({ err, topicId, requestId: inject.requestId }, "session inject drop settlement hook failed");
8880
+ }
8881
+ }
8882
+ return dropped.length;
8871
8883
  }
8872
8884
  size(topicId) {
8873
8885
  const bucket = this.queue.get(topicId);
@@ -13735,6 +13747,30 @@ function isQueryRecord(value2) {
13735
13747
  const record = value2;
13736
13748
  return record.schemaVersion === 2 && typeof record.timestamp === "string" && typeof record.session === "string" && typeof record.topicId === "string" && typeof record.agent === "string" && typeof record.model === "string" && typeof record.inputTokens === "number" && typeof record.outputTokens === "number" && typeof record.cacheCreationInputTokens === "number" && typeof record.cacheReadInputTokens === "number" && typeof record.estimatedCostUsd === "number";
13737
13749
  }
13750
+ function previousCumulativeCost(userId, providerSessionId) {
13751
+ let lines;
13752
+ try {
13753
+ lines = readJsonlLines(queriesPath(userId));
13754
+ } catch {
13755
+ return 0;
13756
+ }
13757
+ for (let i = lines.length - 1;i >= 0; i--) {
13758
+ let parsed;
13759
+ try {
13760
+ parsed = JSON.parse(lines[i]);
13761
+ } catch {
13762
+ continue;
13763
+ }
13764
+ if (parsed.providerSessionId !== providerSessionId)
13765
+ continue;
13766
+ if (typeof parsed.cumulativeCostUsd === "number")
13767
+ return parsed.cumulativeCostUsd;
13768
+ if (typeof parsed.estimatedCostUsd === "number")
13769
+ return parsed.estimatedCostUsd;
13770
+ return 0;
13771
+ }
13772
+ return 0;
13773
+ }
13738
13774
  function recordUsage(userId, session, usage, context) {
13739
13775
  const cacheReadInputTokens = usage.cacheReadInputTokens ?? 0;
13740
13776
  const inputTokens = context.agent === "claude" ? usage.inputTokens : Math.max(0, usage.inputTokens - cacheReadInputTokens);
@@ -13744,6 +13780,15 @@ function recordUsage(userId, session, usage, context) {
13744
13780
  cacheCreationInputTokens: usage.cacheCreationInputTokens ?? 0,
13745
13781
  cacheReadInputTokens
13746
13782
  };
13783
+ let estimatedCostUsd;
13784
+ let cumulativeCostUsd;
13785
+ if (usage.costUsd !== undefined) {
13786
+ const previous = context.providerSessionId ? previousCumulativeCost(userId, context.providerSessionId) : 0;
13787
+ estimatedCostUsd = Math.max(0, usage.costUsd - previous);
13788
+ cumulativeCostUsd = usage.costUsd;
13789
+ } else {
13790
+ estimatedCostUsd = estimateUsageCost(context.agent, context.model, normalized);
13791
+ }
13747
13792
  const record = {
13748
13793
  schemaVersion: 2,
13749
13794
  timestamp: new Date().toISOString(),
@@ -13755,7 +13800,8 @@ function recordUsage(userId, session, usage, context) {
13755
13800
  ...normalized,
13756
13801
  ...usage.contextTokens !== undefined ? { contextTokens: usage.contextTokens } : {},
13757
13802
  ...usage.contextWindow !== undefined ? { contextWindow: usage.contextWindow } : {},
13758
- estimatedCostUsd: usage.costUsd ?? estimateUsageCost(context.agent, context.model, normalized)
13803
+ estimatedCostUsd,
13804
+ ...cumulativeCostUsd !== undefined ? { cumulativeCostUsd } : {}
13759
13805
  };
13760
13806
  try {
13761
13807
  appendJsonlEntry(queriesPath(userId), record);
@@ -20640,9 +20686,8 @@ function startAiTurn(params) {
20640
20686
  contextWindow: outcome.usage.contextWindow
20641
20687
  } : undefined, { agent: agentKind, model: resolvedModel, budgetReason: outcome.reason });
20642
20688
  WsHub.get().broadcastTopicNotice(topicId, "warning", "\uC608\uC0B0 \uD55C\uB3C4 \uB3C4\uB2EC");
20643
- } else {
20644
- await deliverAskError(queryId, topic.title, error);
20645
20689
  }
20690
+ await deliverAskError(queryId, topic.title, error);
20646
20691
  await settleSubagentFailure(queryId, error);
20647
20692
  try {
20648
20693
  onSettled?.({ queryId, kind: "error", error });
@@ -20687,6 +20732,7 @@ function startAiTurn(params) {
20687
20732
  WsHub.get().broadcastError(topicId, queryId, error);
20688
20733
  WsHub.get().broadcastTopicNotice(topicId, "error", "\uC751\uB2F5 \uC2E4\uD328");
20689
20734
  }
20735
+ await deliverAskError(queryId, topic.title, error);
20690
20736
  await settleSubagentFailure(queryId, classifyAgentError(error, agentKind));
20691
20737
  try {
20692
20738
  onSettled?.({
@@ -25108,4 +25154,4 @@ export {
25108
25154
  createAgentHealthMcpServer
25109
25155
  };
25110
25156
 
25111
- //# debugId=E5488F6E48B7BEF364756E2164756E21
25157
+ //# debugId=3C37F44558C028FB64756E2164756E21