negotium 0.2.23 → 0.2.25

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 (48) hide show
  1. package/dist/agent-helpers.js +84 -30
  2. package/dist/agent-helpers.js.map +6 -6
  3. package/dist/background-bash.js +2 -1
  4. package/dist/background-bash.js.map +3 -3
  5. package/dist/browser-runtime.js +2 -1
  6. package/dist/browser-runtime.js.map +3 -3
  7. package/dist/{chunk-rhp26p2c.js → chunk-1y2xw0xe.js} +2 -1
  8. package/dist/{chunk-rhp26p2c.js.map → chunk-1y2xw0xe.js.map} +3 -3
  9. package/dist/hosted-agent.js +3 -2
  10. package/dist/hosted-agent.js.map +4 -4
  11. package/dist/main.js +224 -366
  12. package/dist/main.js.map +27 -28
  13. package/dist/mcp-factories.js +86 -31
  14. package/dist/mcp-factories.js.map +7 -7
  15. package/dist/prompts.js +2 -1
  16. package/dist/prompts.js.map +3 -3
  17. package/dist/query-runtime.js +2 -1
  18. package/dist/query-runtime.js.map +3 -3
  19. package/dist/registry.js +3 -3
  20. package/dist/registry.js.map +2 -2
  21. package/dist/rollout.js +1 -1
  22. package/dist/runtime/src/index.ts +3 -7
  23. package/dist/runtime/src/mcp/session-comm/default-host.ts +6 -1
  24. package/dist/runtime/src/mcp/session-comm/topic-catalog.ts +17 -1
  25. package/dist/runtime/src/mcp/session-comm/topics.ts +23 -1
  26. package/dist/runtime/src/node-host.ts +4 -4
  27. package/dist/runtime/src/platform/config.ts +12 -0
  28. package/dist/runtime/src/storage/api-topics.ts +160 -52
  29. package/dist/runtime/src/storage/storage-public.ts +0 -1
  30. package/dist/runtime/src/topics/create.ts +12 -6
  31. package/dist/runtime/src/topics/derive.ts +20 -11
  32. package/dist/runtime/src/types/api.ts +8 -4
  33. package/dist/runtime/src/version.ts +1 -1
  34. package/dist/runtime-helpers.js +2 -1
  35. package/dist/runtime-helpers.js.map +3 -3
  36. package/dist/storage.js +92 -38
  37. package/dist/storage.js.map +3 -3
  38. package/dist/types/packages/core/src/mcp/session-comm/topic-catalog.d.ts +7 -0
  39. package/dist/types/packages/core/src/platform/config.d.ts +12 -0
  40. package/dist/types/packages/core/src/storage/api-topics.d.ts +34 -19
  41. package/dist/types/packages/core/src/storage/storage-public.d.ts +1 -1
  42. package/dist/types/packages/core/src/topics/derive.d.ts +13 -4
  43. package/dist/types/packages/core/src/types/api.d.ts +8 -4
  44. package/dist/types/packages/core/src/version.d.ts +1 -1
  45. package/dist/vault.js +2 -1
  46. package/dist/vault.js.map +3 -3
  47. package/package.json +1 -1
  48. package/dist/runtime/src/application/switch-topic-access-mode.ts +0 -110
@@ -1,110 +0,0 @@
1
- import { WsHub } from "#bus";
2
- import { getTopic, listTopics, setTopicAccessModes } from "#storage/api-topics";
3
- import type { TopicAccessMode, TopicDto } from "#types/api";
4
-
5
- export type SwitchTopicAccessModeResult =
6
- | { ok: true; accessMode: TopicAccessMode; text: string; topicIds: string[] }
7
- | { ok: false; error: string };
8
-
9
- export interface SwitchTopicAccessModeParams {
10
- topicId: string;
11
- userId: string;
12
- accessMode: TopicAccessMode;
13
- }
14
-
15
- /**
16
- * Every subagent room reachable from `rootTopicId`, deepest-first order aside.
17
- *
18
- * Mirrors the traversal `deleteTopicCascade` already uses: only `isSubagent`
19
- * children are owned by their parent, while fork/spawn rooms are independent
20
- * and must keep their own privacy. `seen` guards against a parent cycle left
21
- * behind by reparenting, which would otherwise loop forever.
22
- */
23
- function collectSubagentDescendants(rootTopicId: string): TopicDto[] {
24
- const all = listTopics();
25
- const childrenByParent = new Map<string, TopicDto[]>();
26
- for (const topic of all) {
27
- if (!topic.isSubagent || !topic.parentTopicId) continue;
28
- const siblings = childrenByParent.get(topic.parentTopicId);
29
- if (siblings) siblings.push(topic);
30
- else childrenByParent.set(topic.parentTopicId, [topic]);
31
- }
32
- const descendants: TopicDto[] = [];
33
- const seen = new Set<string>([rootTopicId]);
34
- const queue = [rootTopicId];
35
- while (queue.length > 0) {
36
- const parentId = queue.shift() as string;
37
- for (const child of childrenByParent.get(parentId) ?? []) {
38
- if (seen.has(child.id)) continue;
39
- seen.add(child.id);
40
- descendants.push(child);
41
- queue.push(child.id);
42
- }
43
- }
44
- return descendants;
45
- }
46
-
47
- /** Change whether a user-owned topic is local-only or shared with connected adapters. */
48
- export function switchTopicAccessMode(
49
- params: SwitchTopicAccessModeParams,
50
- ): SwitchTopicAccessModeResult {
51
- const topic = getTopic(params.topicId);
52
- if (!topic) return { ok: false, error: "Topic not found" };
53
- const owner = topic.participants.some(
54
- (participant) => participant.userId === params.userId && participant.role === "owner",
55
- );
56
- if (!owner) return { ok: false, error: "Only topic owners can change privacy" };
57
- // A subagent room is owned by the room that spawned it, so its privacy is not
58
- // its own to change: allowing it would let a worker room escape the parent's
59
- // setting, and the next parent switch would silently overwrite it anyway.
60
- if (topic.isSubagent) {
61
- return {
62
- ok: false,
63
- error: "Subagent rooms inherit privacy from their parent topic",
64
- };
65
- }
66
-
67
- // Subagents hold the parent's conversation context, so leaving them behind on
68
- // the old mode would either expose work the user just made private or strand
69
- // half a delegation tree off the Hub. New rooms already inherit the parent's
70
- // access mode at creation (`createDerivedTopic`); this keeps existing ones in
71
- // step.
72
- const descendants = collectSubagentDescendants(topic.id);
73
- const changed = [topic, ...descendants].filter(
74
- (candidate) => (candidate.accessMode ?? "private") !== params.accessMode,
75
- );
76
- if (changed.length === 0) {
77
- return {
78
- ok: true,
79
- accessMode: params.accessMode,
80
- text:
81
- params.accessMode === "shared"
82
- ? `"${topic.title}" is already public to the connected Otium Hub.`
83
- : `"${topic.title}" is already private to this worker.`,
84
- topicIds: [],
85
- };
86
- }
87
-
88
- setTopicAccessModes(
89
- changed.map((candidate) => candidate.id),
90
- params.accessMode,
91
- );
92
- // Broadcast only after the write commits: an event emitted inside the
93
- // transaction would announce a state a rollback could still take back.
94
- for (const candidate of changed) WsHub.get().broadcastTopicUpdated(candidate.id);
95
-
96
- const subagentCount = changed.filter((candidate) => candidate.id !== topic.id).length;
97
- const suffix =
98
- subagentCount > 0
99
- ? ` (${subagentCount} subagent room${subagentCount === 1 ? "" : "s"} updated)`
100
- : "";
101
- return {
102
- ok: true,
103
- accessMode: params.accessMode,
104
- topicIds: changed.map((candidate) => candidate.id),
105
- text:
106
- (params.accessMode === "shared"
107
- ? `"${topic.title}" is public to the connected Otium Hub.`
108
- : `"${topic.title}" is private to this worker.`) + suffix,
109
- };
110
- }