negotium 0.6.6 → 0.6.7

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-f124y9d0.js} +2 -2
  4. package/dist/{chunk-pxnv3gh2.js.map → chunk-f124y9d0.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 +40 -16
  8. package/dist/main.js.map +12 -12
  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/registry.js CHANGED
@@ -133,7 +133,7 @@ var codexRegistryOperations = {
133
133
  return { sessionId: threadId, rolloutPath };
134
134
  },
135
135
  async forkSession({ parentSessionId }) {
136
- const { forkCodexSession } = await import("./chunk-pxnv3gh2.js");
136
+ const { forkCodexSession } = await import("./chunk-f124y9d0.js");
137
137
  return await forkCodexSession(parentSessionId);
138
138
  },
139
139
  async cleanupRollouts({ sessionIds }) {
@@ -11,6 +11,7 @@ import { COMPLETED_BACKGROUND_SESSION_RETENTION_MS } from "#runtime/background-s
11
11
  import { sanitizeTopicName } from "#security/sanitize";
12
12
  import { appendApiMessage } from "#storage/api-messages";
13
13
  import { getTopicBrief, setTopicBrief } from "#storage/api-topic-brief";
14
+ import { getTopic } from "#storage/api-topics";
14
15
  import { getSharedWikiDir } from "#storage/wiki";
15
16
  import { isTopicSummaryFile, wikiSummaryFilename } from "#storage/wiki-summary-names";
16
17
  import { ensurePersonalGeneral } from "#topics/personal-general";
@@ -69,6 +70,8 @@ function formatArchiverTool(name: string, input: Record<string, unknown>): strin
69
70
  export interface RunArchiverTurnParams {
70
71
  /** Stringified user id (route layer hands us strings). */
71
72
  userId: string;
73
+ /** Topic whose placement selects the matching personal #General room. */
74
+ sourceTopicId?: string;
72
75
  /** Wiki-memory topic id. Derived topics pass their root memory origin here. */
73
76
  topicId?: string;
74
77
  /** Human-readable topic title — becomes the wiki `topic` name. */
@@ -106,7 +109,7 @@ export interface ArchiverStorageHost {
106
109
  readTextFile(path: string): string;
107
110
  fileSize(path: string): number;
108
111
  fileModifiedAt(path: string): number;
109
- getGeneralTopicId(userId: string): string;
112
+ getGeneralTopicId(userId: string, sourceTopicId?: string): string;
110
113
  getTopicBrief(topicId: string): { briefMd: string } | null;
111
114
  setTopicBrief(
112
115
  topicId: string,
@@ -205,6 +208,7 @@ export function createArchiverRuntime(host: ArchiverHost): ArchiverRuntime {
205
208
  const runTurn = (params: RunArchiverTurnParams): boolean => {
206
209
  const {
207
210
  userId,
211
+ sourceTopicId,
208
212
  topicId,
209
213
  topicTitle,
210
214
  archivePath,
@@ -213,6 +217,11 @@ export function createArchiverRuntime(host: ArchiverHost): ArchiverRuntime {
213
217
  mode = "deleted-topic",
214
218
  } = params;
215
219
 
220
+ // Resolve while the source row still exists. Deleted-topic archivers settle
221
+ // after the cascade removes it, but its surface/scope is required to select
222
+ // the same personal General that the originating host mapped.
223
+ const generalTopicId = host.storage.getGeneralTopicId(userId, sourceTopicId);
224
+
216
225
  let definition: AgentDef;
217
226
  try {
218
227
  definition = getAgentDefinition();
@@ -446,6 +455,7 @@ export function createArchiverRuntime(host: ArchiverHost): ArchiverRuntime {
446
455
  ok,
447
456
  mode,
448
457
  topicId,
458
+ generalTopicId,
449
459
  ok && text ? { text, agent, model, usage } : undefined,
450
460
  );
451
461
  });
@@ -525,9 +535,10 @@ function finalizeGeneralMemory(
525
535
  ok: boolean,
526
536
  mode: "deleted-topic" | "active-topic",
527
537
  topicId?: string,
538
+ generalTopicId?: string,
528
539
  generalReply?: GeneralArchiverReply,
529
540
  ): void {
530
- const generalTopicId = host.storage.getGeneralTopicId(userId);
541
+ const resolvedGeneralTopicId = generalTopicId ?? host.storage.getGeneralTopicId(userId, topicId);
531
542
  const date = host.config.now().toISOString().slice(0, 10);
532
543
  try {
533
544
  const summaryPath = ok
@@ -537,7 +548,7 @@ function finalizeGeneralMemory(
537
548
  const oneLine = (summaryMd && distillOneLine(summaryMd)) || `Archived ${messageCount} messages`;
538
549
 
539
550
  // Rolling digest: dedupe same-title, prepend newest, cap at MAX_BRIEF_ENTRIES.
540
- const prev = host.storage.getTopicBrief(generalTopicId);
551
+ const prev = host.storage.getTopicBrief(resolvedGeneralTopicId);
541
552
  const prevEntries = (prev?.briefMd ?? "")
542
553
  .split("\n")
543
554
  .map((l) => l.trim())
@@ -549,7 +560,7 @@ function finalizeGeneralMemory(
549
560
  ].slice(0, MAX_BRIEF_ENTRIES);
550
561
  const briefMd = `# Workspace Memory Hub\n\nRecent memory digest distilled from archived topics (deletions and idle/session-reset snapshots). Use \`wiki_query\` for details.\n\n## Recent Archives\n${rolled.join("\n")}`;
551
562
 
552
- host.storage.setTopicBrief(generalTopicId, {
563
+ host.storage.setTopicBrief(resolvedGeneralTopicId, {
553
564
  briefMd,
554
565
  ...(summaryMd ? { latestSummaryMd: summaryMd, summaryDate: date } : {}),
555
566
  });
@@ -586,13 +597,13 @@ function finalizeGeneralMemory(
586
597
  : { authorId: "system" };
587
598
  const msg = {
588
599
  id: host.config.createId(),
589
- topicId: generalTopicId,
600
+ topicId: resolvedGeneralTopicId,
590
601
  text,
591
602
  ...replyMeta,
592
603
  createdAt: host.config.now().toISOString(),
593
604
  };
594
605
  host.messaging.appendMessage(msg);
595
- host.messaging.broadcastMessage(generalTopicId, msg);
606
+ host.messaging.broadcastMessage(resolvedGeneralTopicId, msg);
596
607
  } catch (err) {
597
608
  host.config.warn({ err, topicTitle }, "archiver: failed to post #General notification");
598
609
  }
@@ -606,7 +617,14 @@ const defaultArchiverRuntime = createArchiverRuntime({
606
617
  readTextFile: (path) => readFileSync(path, "utf-8"),
607
618
  fileSize: (path) => statSync(path).size,
608
619
  fileModifiedAt: (path) => statSync(path).mtimeMs,
609
- getGeneralTopicId: (userId) => ensurePersonalGeneral(userId).id,
620
+ getGeneralTopicId: (userId, sourceTopicId) => {
621
+ const source = sourceTopicId ? getTopic(sourceTopicId) : null;
622
+ return source
623
+ ? ensurePersonalGeneral(userId, source.surface, {
624
+ surfaceScope: source.surfaceScope ?? null,
625
+ }).id
626
+ : ensurePersonalGeneral(userId).id;
627
+ },
610
628
  getTopicBrief,
611
629
  setTopicBrief: (topicId, fields) => {
612
630
  setTopicBrief(topicId, fields);
@@ -181,6 +181,7 @@ export function archiveActiveTopicForMemory(
181
181
  const memoryTitle = memoryTopic.memoryKey?.trim() || memoryTopic.title;
182
182
  const launched = (options.launchArchiver ?? runArchiverTurn)({
183
183
  userId,
184
+ sourceTopicId: topic.id,
184
185
  topicId: memoryTopic.id,
185
186
  topicTitle: memoryTitle,
186
187
  archivePath: job.archivePath,
@@ -55,6 +55,7 @@ export interface DeleteUserTopicParams extends DeleteTopicCascadeOptions {
55
55
  export interface TopicSessionParams {
56
56
  topicId: string;
57
57
  userId: string;
58
+ actorUserId?: string;
58
59
  reason?: string;
59
60
  }
60
61
 
@@ -90,6 +91,7 @@ export const topicService = {
90
91
  }
91
92
  await deleteTopicCascade(topic, params.userId, {
92
93
  ...(params.force !== undefined ? { force: params.force } : {}),
94
+ ...(params.memoryUserId !== undefined ? { memoryUserId: params.memoryUserId } : {}),
93
95
  ...(params.allowManager !== undefined ? { allowManager: params.allowManager } : {}),
94
96
  ...(params.skipArchive !== undefined ? { skipArchive: params.skipArchive } : {}),
95
97
  ...(params.purgeLogs !== undefined ? { purgeLogs: params.purgeLogs } : {}),
@@ -98,7 +100,9 @@ export const topicService = {
98
100
 
99
101
  async reset(params: TopicSessionParams): Promise<RestartTopicSessionResult> {
100
102
  ownerTopic(params.topicId, params.userId);
101
- return restartTopicSession(params.topicId, params.userId, params.reason);
103
+ return restartTopicSession(params.topicId, params.userId, params.reason, {
104
+ memoryUserId: params.actorUserId,
105
+ });
102
106
  },
103
107
 
104
108
  async compact(params: CompactUserTopicParams): Promise<RestartTopicSessionResult> {
@@ -130,6 +130,7 @@ export async function runTurnEventStream(
130
130
  onSessionId?: (sessionId: string) => void,
131
131
  execution?: {
132
132
  silent?: boolean;
133
+ actorUserId?: string;
133
134
  peerBridge?: PeerRuntimeBridgeContext;
134
135
  sourceNode?: string;
135
136
  /** Answer inside this thread instead of the room's main flow (S-13). */
@@ -654,7 +655,7 @@ export async function runTurnEventStream(
654
655
  }
655
656
  }
656
657
  if (!silent) {
657
- scheduleIdleArchiveForTopic(topicId, userId);
658
+ scheduleIdleArchiveForTopic(topicId, execution?.actorUserId ?? userId);
658
659
  hub.broadcastDone(
659
660
  topicId,
660
661
  queryId,
@@ -289,6 +289,7 @@ export async function streamAgentEvents(
289
289
  onSessionId?: (sessionId: string) => void,
290
290
  execution?: {
291
291
  silent?: boolean;
292
+ actorUserId?: string;
292
293
  peerBridge?: PeerRuntimeBridgeContext;
293
294
  sourceNode?: string;
294
295
  threadRootId?: string;
@@ -1721,7 +1722,13 @@ export function startAiTurn(params: StartAiTurnParams): string | null {
1721
1722
  userId,
1722
1723
  !sessionRetried,
1723
1724
  onSessionId,
1724
- { silent, peerBridge, sourceNode, ...(threadRootId ? { threadRootId } : {}) },
1725
+ {
1726
+ silent,
1727
+ actorUserId: params.actorUserId,
1728
+ peerBridge,
1729
+ sourceNode,
1730
+ ...(threadRootId ? { threadRootId } : {}),
1731
+ },
1725
1732
  )
1726
1733
  .then(async (streamOutcome) => {
1727
1734
  let outcome = streamOutcome;
@@ -662,16 +662,18 @@ export class RuntimeGatewayClient {
662
662
  topicId: string,
663
663
  userId: string,
664
664
  reason?: string,
665
+ actorUserId?: string,
665
666
  ): Promise<string | undefined> {
666
- return this.sessionCommand(topicId, userId, "reset", reason);
667
+ return this.sessionCommand(topicId, userId, "reset", reason, actorUserId);
667
668
  }
668
669
 
669
670
  async compactSession(
670
671
  topicId: string,
671
672
  userId: string,
672
673
  reason?: string,
674
+ actorUserId?: string,
673
675
  ): Promise<string | undefined> {
674
- return this.sessionCommand(topicId, userId, "compact", reason);
676
+ return this.sessionCommand(topicId, userId, "compact", reason, actorUserId);
675
677
  }
676
678
 
677
679
  private async sessionCommand(
@@ -679,6 +681,7 @@ export class RuntimeGatewayClient {
679
681
  userId: string,
680
682
  command: "reset" | "compact",
681
683
  reason?: string,
684
+ actorUserId?: string,
682
685
  ): Promise<string | undefined> {
683
686
  const response = await this.send(
684
687
  `/topics/${encodeURIComponent(topicId)}/session/${command}`,
@@ -688,6 +691,7 @@ export class RuntimeGatewayClient {
688
691
  body: JSON.stringify({
689
692
  v: RUNTIME_GATEWAY_VERSION,
690
693
  userId,
694
+ ...(actorUserId ? { actorUserId } : {}),
691
695
  ...(reason ? { reason } : {}),
692
696
  }),
693
697
  },
@@ -157,6 +157,8 @@ export class TopicCleanupRequiredError extends Error {
157
157
 
158
158
  export interface DeleteTopicCascadeOptions {
159
159
  force?: boolean;
160
+ /** Upstream product actor whose personal General receives archive memory. */
161
+ memoryUserId?: string;
160
162
  /** Account deletion may remove that account's otherwise-protected private General. */
161
163
  allowManager?: boolean;
162
164
  /** Account deletion must not recreate a private General via the archiver. */
@@ -256,7 +258,8 @@ async function deleteTopicCascadeImpl(
256
258
  const memoryTopic = topic.memoryKey ? topic : (getTopicMemoryOrigin(topicId) ?? topic);
257
259
  const memoryTitle = memoryTopic.memoryKey?.trim() || memoryTopic.title;
258
260
  runArchiverTurn({
259
- userId,
261
+ userId: options.memoryUserId ?? userId,
262
+ sourceTopicId: topicId,
260
263
  // A memory origin that is also disappearing in this cascade must use
261
264
  // file + General memory only. Passing its id to wiki MCP would let the
262
265
  // detached archiver recreate an orphan api_topic_brief row later.
@@ -91,6 +91,8 @@ export interface CompactedRolloutRequest extends Omit<CompactSummaryRequest, "so
91
91
 
92
92
  export interface RestartTopicSessionOptions {
93
93
  archiveMemory?: typeof archiveActiveTopicForMemory;
94
+ /** Upstream product actor whose personal General receives archive memory. */
95
+ memoryUserId?: string;
94
96
  purgeLogs?: typeof purgeTopicLogs;
95
97
  /** Maximum time to wait for durable memory before leaving the session unchanged. */
96
98
  memoryArchiveWaitMs?: number;
@@ -183,15 +185,19 @@ export async function restartTopicSession(
183
185
  const memoryArchiveSettled = new Promise<void>((resolve) => {
184
186
  settleMemoryArchive = resolve;
185
187
  });
186
- const archiveStatus = (options.archiveMemory ?? archiveActiveTopicForMemory)(topicId, userId, {
187
- reason: "reset",
188
- minMessages: 1,
189
- minExchanges: MIN_MEMORY_ARCHIVE_EXCHANGES,
190
- allowMentionOnly: true,
191
- skipBusyCheck: true,
192
- rawArchivePaths,
193
- onSettled: () => settleMemoryArchive?.(),
194
- });
188
+ const archiveStatus = (options.archiveMemory ?? archiveActiveTopicForMemory)(
189
+ topicId,
190
+ options.memoryUserId ?? userId,
191
+ {
192
+ reason: "reset",
193
+ minMessages: 1,
194
+ minExchanges: MIN_MEMORY_ARCHIVE_EXCHANGES,
195
+ allowMentionOnly: true,
196
+ skipBusyCheck: true,
197
+ rawArchivePaths,
198
+ onSettled: () => settleMemoryArchive?.(),
199
+ },
200
+ );
195
201
  // Keep maintenance ownership until durable memory has settled. All reset
196
202
  // surfaces share this service, so terminal, Telegram, MCP, and embedding
197
203
  // hosts cannot start the fresh session against stale wiki memory.
@@ -1 +1 @@
1
- export const NEGOTIUM_VERSION = "0.6.6";
1
+ export const NEGOTIUM_VERSION = "0.6.7";
@@ -339,19 +339,20 @@ class RuntimeGatewayClient {
339
339
  }
340
340
  return body.aborted;
341
341
  }
342
- async resetSession(topicId, userId, reason) {
343
- return this.sessionCommand(topicId, userId, "reset", reason);
342
+ async resetSession(topicId, userId, reason, actorUserId) {
343
+ return this.sessionCommand(topicId, userId, "reset", reason, actorUserId);
344
344
  }
345
- async compactSession(topicId, userId, reason) {
346
- return this.sessionCommand(topicId, userId, "compact", reason);
345
+ async compactSession(topicId, userId, reason, actorUserId) {
346
+ return this.sessionCommand(topicId, userId, "compact", reason, actorUserId);
347
347
  }
348
- async sessionCommand(topicId, userId, command, reason) {
348
+ async sessionCommand(topicId, userId, command, reason, actorUserId) {
349
349
  const response = await this.send(`/topics/${encodeURIComponent(topicId)}/session/${command}`, {
350
350
  method: "POST",
351
351
  headers: { "content-type": "application/json" },
352
352
  body: JSON.stringify({
353
353
  v: RUNTIME_GATEWAY_VERSION,
354
354
  userId,
355
+ ...actorUserId ? { actorUserId } : {},
355
356
  ...reason ? { reason } : {}
356
357
  })
357
358
  }, command === "compact" ? this.compactTimeoutMs : this.requestTimeoutMs);
@@ -373,4 +374,4 @@ export {
373
374
  RUNTIME_GATEWAY_CONTROL_PATH
374
375
  };
375
376
 
376
- //# debugId=1B400FCBBC9E65B364756E2164756E21
377
+ //# debugId=7F7442752A2C48FD64756E2164756E21
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../packages/core/src/runtime-gateway.ts"],
4
4
  "sourcesContent": [
5
- "export const RUNTIME_GATEWAY_VERSION = 1 as const;\nexport const RUNTIME_GATEWAY_CONTROL_PATH = \"/api/v1/control/runtime/v1\";\n\nexport type RuntimeGatewayErrorKind = \"config\" | \"timeout\" | \"transport\" | \"protocol\" | \"http\";\n\nexport class RuntimeGatewayError extends Error {\n constructor(\n message: string,\n public readonly kind: RuntimeGatewayErrorKind,\n public readonly status?: number,\n ) {\n super(message);\n }\n}\n\nexport interface RuntimeGatewayHealth {\n ok: true;\n v: typeof RUNTIME_GATEWAY_VERSION;\n nodeId?: string;\n aiName?: string;\n capabilities: string[];\n cursor: number;\n}\n\nexport interface RuntimeGatewayTurnInput {\n topicId: string;\n /** Canonical principal on the execution node. */\n userId: string;\n /** Product-side actor, when it differs from the execution principal. */\n actorUserId?: string;\n actorLabel?: string;\n vaultUserId?: string;\n text: string;\n clientMessageId: string;\n requestId?: string;\n allowAutoContinue?: boolean;\n threadRootId?: string;\n respond?: boolean;\n /** Run without adding the injected prompt or output to the visible transcript. */\n silent?: boolean;\n attachments?: string[];\n visualTools?: boolean;\n fileDeliveryTools?: boolean;\n}\n\nexport interface RuntimeGatewayTurnAcknowledgement {\n ok: true;\n v: typeof RUNTIME_GATEWAY_VERSION;\n accepted: true;\n deduplicated: boolean;\n requestId: string;\n clientMessageId: string;\n topicId: string;\n messageId: string;\n cursor: number;\n}\n\nexport interface RuntimeGatewayTopicDeriveInput {\n userId: string;\n copyHistory: boolean;\n name?: string;\n}\n\nexport interface RuntimeGatewayDerivedTopic {\n id: string;\n title: string;\n kind?: string;\n agent?: string;\n defaultModel?: string;\n defaultEffort?: string;\n parentTopicId?: string;\n isFork?: boolean;\n}\n\nexport interface RuntimeGatewaySseEvent {\n id?: number;\n event: string;\n data: unknown;\n}\n\nexport interface RuntimeGatewayTopicUsage {\n queries: number;\n inputTokens: number;\n outputTokens: number;\n cacheCreationInputTokens: number;\n cacheReadInputTokens: number;\n estimatedCostUsd: number;\n}\n\nexport interface RuntimeGatewayManagerTopic {\n id: string;\n title: string;\n kind: \"manager\";\n agent?: \"claude\" | \"codex\" | \"maestro\";\n participants: Array<{ userId: string; role: \"owner\" | \"member\" }>;\n}\n\nexport interface RuntimeGatewayDeletedMessage {\n id: string;\n topicId: string;\n authorId: string;\n text: string;\n deleted: true;\n createdAt: string;\n}\n\nexport interface RuntimeGatewayCronJob {\n id: string;\n name: string;\n executionPrincipalUserId: string;\n actorOwnerUserId: string;\n topicId: string;\n source: \"prompt\" | \"script\";\n script: string | null;\n scriptExists: boolean;\n prompt: string | null;\n promptPreview: string | null;\n summary: string | null;\n schedule: string;\n timezone: string | null;\n enabled: boolean;\n agent: \"claude\" | \"codex\" | \"maestro\" | null;\n model: string | null;\n effort: string | null;\n nextRunAt: string;\n runCount: number;\n lastRun: Record<string, unknown> | null;\n createdAt: string;\n updatedAt: string;\n canMutate: boolean;\n}\n\nexport interface RuntimeGatewayCronCreateInput {\n userId: string;\n actorUserId: string;\n topicId: string;\n name: string;\n script: string;\n schedule: string;\n timezone?: string;\n agent?: \"claude\" | \"codex\" | \"maestro\";\n model?: string;\n effort?: string;\n}\n\nexport interface RuntimeGatewayCronPatch {\n name?: string;\n topicId?: string;\n script?: string;\n schedule?: string;\n timezone?: string | null;\n enabled?: boolean;\n agent?: \"claude\" | \"codex\" | \"maestro\" | null;\n model?: string | null;\n effort?: string | null;\n}\n\nexport type RuntimeGatewayToken = string | (() => string | Promise<string>);\nexport type RuntimeGatewayFetch = (\n input: string | URL | Request,\n init?: RequestInit,\n) => Promise<Response>;\n\nexport interface RuntimeGatewayClientOptions {\n baseUrl: string;\n token: RuntimeGatewayToken;\n /** Loopback control path or an authenticated relay forward prefix. */\n pathPrefix?: string;\n fetch?: RuntimeGatewayFetch;\n requestTimeoutMs?: number;\n compactTimeoutMs?: number;\n}\n\nfunction record(value: unknown): Record<string, unknown> | null {\n return value && typeof value === \"object\" && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : null;\n}\n\nasync function json(response: Response): Promise<unknown> {\n try {\n return await response.json();\n } catch {\n throw new RuntimeGatewayError(\n \"Runtime Gateway returned invalid JSON\",\n \"protocol\",\n response.status,\n );\n }\n}\n\nfunction validHealth(value: unknown): value is RuntimeGatewayHealth {\n const body = record(value);\n return Boolean(\n body?.ok === true &&\n body.v === RUNTIME_GATEWAY_VERSION &&\n Array.isArray(body.capabilities) &&\n typeof body.cursor === \"number\",\n );\n}\n\nfunction validTurnAck(value: unknown): value is RuntimeGatewayTurnAcknowledgement {\n const body = record(value);\n return Boolean(\n body?.ok === true &&\n body.v === RUNTIME_GATEWAY_VERSION &&\n body.accepted === true &&\n typeof body.deduplicated === \"boolean\" &&\n typeof body.requestId === \"string\" &&\n typeof body.clientMessageId === \"string\" &&\n typeof body.topicId === \"string\" &&\n typeof body.messageId === \"string\" &&\n typeof body.cursor === \"number\",\n );\n}\n\nfunction validManagerTopic(value: unknown): value is RuntimeGatewayManagerTopic {\n const topic = record(value);\n return Boolean(\n typeof topic?.id === \"string\" &&\n typeof topic.title === \"string\" &&\n topic.kind === \"manager\" &&\n Array.isArray(topic.participants),\n );\n}\n\nfunction validDeletedMessage(value: unknown): value is RuntimeGatewayDeletedMessage {\n const message = record(value);\n return Boolean(\n typeof message?.id === \"string\" &&\n typeof message.topicId === \"string\" &&\n typeof message.authorId === \"string\" &&\n typeof message.text === \"string\" &&\n message.deleted === true &&\n typeof message.createdAt === \"string\",\n );\n}\n\nfunction validCronJob(value: unknown): value is RuntimeGatewayCronJob {\n const job = record(value);\n return Boolean(\n typeof job?.id === \"string\" &&\n typeof job.name === \"string\" &&\n typeof job.executionPrincipalUserId === \"string\" &&\n typeof job.actorOwnerUserId === \"string\" &&\n typeof job.topicId === \"string\" &&\n typeof job.schedule === \"string\" &&\n typeof job.enabled === \"boolean\" &&\n typeof job.nextRunAt === \"string\" &&\n typeof job.canMutate === \"boolean\",\n );\n}\n\nexport async function* parseRuntimeGatewaySse(\n body: ReadableStream<Uint8Array>,\n): AsyncGenerator<RuntimeGatewaySseEvent> {\n const reader = body.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n let event = \"message\";\n let id: number | undefined;\n let data: string[] = [];\n const flush = (): RuntimeGatewaySseEvent | null => {\n if (data.length === 0) return null;\n const raw = data.join(\"\\n\");\n data = [];\n try {\n return { event, id, data: JSON.parse(raw) };\n } catch {\n throw new RuntimeGatewayError(\"Runtime Gateway SSE event has invalid JSON\", \"protocol\");\n } finally {\n event = \"message\";\n id = undefined;\n }\n };\n try {\n while (true) {\n const chunk = await reader.read();\n if (chunk.done) break;\n buffer += decoder.decode(chunk.value, { stream: true }).replace(/\\r\\n/g, \"\\n\");\n let newline = buffer.indexOf(\"\\n\");\n while (newline >= 0) {\n const line = buffer.slice(0, newline);\n buffer = buffer.slice(newline + 1);\n if (line === \"\") {\n const parsed = flush();\n if (parsed) yield parsed;\n } else if (line.startsWith(\"event:\")) {\n event = line.slice(6).trim() || \"message\";\n } else if (line.startsWith(\"id:\")) {\n const parsed = Number.parseInt(line.slice(3).trim(), 10);\n if (Number.isFinite(parsed)) id = parsed;\n } else if (line.startsWith(\"data:\")) {\n data.push(line.slice(5).trimStart());\n }\n newline = buffer.indexOf(\"\\n\");\n }\n }\n buffer += decoder.decode();\n if (buffer.startsWith(\"data:\")) data.push(buffer.slice(5).trimStart());\n const parsed = flush();\n if (parsed) yield parsed;\n } finally {\n reader.releaseLock();\n }\n}\n\nexport class RuntimeGatewayClient {\n private readonly pathPrefix: string;\n private readonly request: RuntimeGatewayFetch;\n private readonly requestTimeoutMs: number;\n private readonly compactTimeoutMs: number;\n\n constructor(private readonly options: RuntimeGatewayClientOptions) {\n this.pathPrefix = options.pathPrefix ?? RUNTIME_GATEWAY_CONTROL_PATH;\n this.request = options.fetch ?? fetch;\n this.requestTimeoutMs = options.requestTimeoutMs ?? 5_000;\n this.compactTimeoutMs = options.compactTimeoutMs ?? 5 * 60_000;\n }\n\n private endpoint(path: string): string {\n if (!this.options.baseUrl || !this.options.token) {\n throw new RuntimeGatewayError(\"Runtime Gateway is not configured\", \"config\");\n }\n return `${this.options.baseUrl.replace(/\\/+$/, \"\")}${this.pathPrefix}${path}`;\n }\n\n private async authorization(): Promise<string> {\n try {\n const token =\n typeof this.options.token === \"function\" ? await this.options.token() : this.options.token;\n return `Bearer ${token}`;\n } catch (error) {\n throw new RuntimeGatewayError(\n error instanceof Error ? error.message : \"Runtime Gateway token resolution failed\",\n \"config\",\n );\n }\n }\n\n private async send(path: string, init: RequestInit, timeoutMs?: number): Promise<Response> {\n const authorization = await this.authorization();\n try {\n return await this.request(this.endpoint(path), {\n ...init,\n headers: { authorization, ...init.headers },\n signal: timeoutMs === undefined ? init.signal : AbortSignal.timeout(timeoutMs),\n });\n } catch (error) {\n if (error instanceof DOMException && error.name === \"TimeoutError\") {\n throw new RuntimeGatewayError(\"Runtime Gateway request timed out\", \"timeout\");\n }\n throw new RuntimeGatewayError(\"Runtime Gateway request failed\", \"transport\");\n }\n }\n\n async health(): Promise<RuntimeGatewayHealth> {\n const response = await this.send(\"/health\", { method: \"GET\" }, this.requestTimeoutMs);\n if (!response.ok) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway health request failed\",\n \"http\",\n response.status,\n );\n }\n const body = await json(response);\n if (!validHealth(body)) {\n throw new RuntimeGatewayError(\"Runtime Gateway health response is incompatible\", \"protocol\");\n }\n return body;\n }\n\n async submitTurn(input: RuntimeGatewayTurnInput): Promise<RuntimeGatewayTurnAcknowledgement> {\n const response = await this.send(\n \"/turns\",\n {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({ v: RUNTIME_GATEWAY_VERSION, ...input }),\n },\n this.requestTimeoutMs,\n );\n if (response.status !== 202) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway turn was not accepted\",\n \"http\",\n response.status,\n );\n }\n const body = await json(response);\n if (!validTurnAck(body)) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway turn acknowledgement is incompatible\",\n \"protocol\",\n );\n }\n return body;\n }\n\n async deriveTopic(\n topicId: string,\n input: RuntimeGatewayTopicDeriveInput,\n ): Promise<RuntimeGatewayDerivedTopic> {\n const response = await this.send(\n `/topics/${encodeURIComponent(topicId)}/derive`,\n {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({ v: RUNTIME_GATEWAY_VERSION, ...input }),\n },\n this.requestTimeoutMs,\n );\n if (response.status !== 201) {\n throw new RuntimeGatewayError(\"Runtime Gateway topic derive failed\", \"http\", response.status);\n }\n const body = await json(response);\n const topic = record(body)?.topic;\n const topicRecord = record(topic);\n if (\n !topicRecord ||\n typeof topicRecord.id !== \"string\" ||\n typeof topicRecord.title !== \"string\"\n ) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway topic derive response is incompatible\",\n \"protocol\",\n );\n }\n return topic as unknown as RuntimeGatewayDerivedTopic;\n }\n\n async ensureManagerTopic(userId: string): Promise<RuntimeGatewayManagerTopic> {\n const response = await this.send(\n \"/manager-topic\",\n {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({ v: RUNTIME_GATEWAY_VERSION, userId }),\n },\n this.requestTimeoutMs,\n );\n if (!response.ok) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway manager topic request failed\",\n \"http\",\n response.status,\n );\n }\n const body = record(await json(response));\n if (body?.ok !== true || body.v !== RUNTIME_GATEWAY_VERSION || !validManagerTopic(body.topic)) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway manager topic response is incompatible\",\n \"protocol\",\n );\n }\n return body.topic;\n }\n\n async deleteMessage(\n topicId: string,\n messageId: string,\n actorUserId: string,\n allowAdmin = false,\n ): Promise<RuntimeGatewayDeletedMessage> {\n const response = await this.send(\n `/topics/${encodeURIComponent(topicId)}/messages/${encodeURIComponent(messageId)}`,\n {\n method: \"DELETE\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n v: RUNTIME_GATEWAY_VERSION,\n actorUserId,\n ...(allowAdmin ? { allowAdmin: true } : {}),\n }),\n },\n this.requestTimeoutMs,\n );\n if (!response.ok) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway message delete failed\",\n \"http\",\n response.status,\n );\n }\n const body = record(await json(response));\n if (\n body?.ok !== true ||\n body.v !== RUNTIME_GATEWAY_VERSION ||\n !validDeletedMessage(body.message)\n ) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway message delete response is incompatible\",\n \"protocol\",\n );\n }\n return body.message;\n }\n\n private async cronRequest(path: string, init: RequestInit): Promise<Record<string, unknown>> {\n const response = await this.send(path, init, this.requestTimeoutMs);\n if (!response.ok) {\n throw new RuntimeGatewayError(\"Runtime Gateway cron request failed\", \"http\", response.status);\n }\n const body = record(await json(response));\n if (body?.ok !== true || body.v !== RUNTIME_GATEWAY_VERSION) {\n throw new RuntimeGatewayError(\"Runtime Gateway cron response is incompatible\", \"protocol\");\n }\n return body;\n }\n\n async listCronScripts(): Promise<string[]> {\n const body = await this.cronRequest(\"/cron/scripts\", { method: \"GET\" });\n if (!Array.isArray(body.scripts) || !body.scripts.every((value) => typeof value === \"string\")) {\n throw new RuntimeGatewayError(\"Runtime Gateway cron scripts are incompatible\", \"protocol\");\n }\n return body.scripts;\n }\n\n async listCronJobs(\n userId: string,\n actorUserId: string,\n actorIsAdmin = false,\n ): Promise<RuntimeGatewayCronJob[]> {\n const search = new URLSearchParams({\n user: userId,\n actorUserId,\n actorIsAdmin: actorIsAdmin ? \"1\" : \"0\",\n });\n const body = await this.cronRequest(`/cron/jobs?${search}`, { method: \"GET\" });\n if (!Array.isArray(body.jobs) || !body.jobs.every(validCronJob)) {\n throw new RuntimeGatewayError(\"Runtime Gateway cron jobs are incompatible\", \"protocol\");\n }\n return body.jobs;\n }\n\n async createCronJob(input: RuntimeGatewayCronCreateInput): Promise<RuntimeGatewayCronJob> {\n const body = await this.cronRequest(\"/cron/jobs\", {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({ v: RUNTIME_GATEWAY_VERSION, ...input }),\n });\n if (!validCronJob(body.job)) {\n throw new RuntimeGatewayError(\"Runtime Gateway cron job is incompatible\", \"protocol\");\n }\n return body.job;\n }\n\n async updateCronJob(\n jobId: string,\n userId: string,\n actorUserId: string,\n patch: RuntimeGatewayCronPatch,\n actorIsAdmin = false,\n ): Promise<RuntimeGatewayCronJob> {\n const body = await this.cronRequest(`/cron/jobs/${encodeURIComponent(jobId)}`, {\n method: \"PATCH\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n v: RUNTIME_GATEWAY_VERSION,\n userId,\n actorUserId,\n actorIsAdmin,\n patch,\n }),\n });\n if (!validCronJob(body.job)) {\n throw new RuntimeGatewayError(\"Runtime Gateway cron job is incompatible\", \"protocol\");\n }\n return body.job;\n }\n\n async deleteCronJob(\n jobId: string,\n userId: string,\n actorUserId: string,\n actorIsAdmin = false,\n ): Promise<string> {\n const search = new URLSearchParams({\n user: userId,\n actorUserId,\n actorIsAdmin: actorIsAdmin ? \"1\" : \"0\",\n });\n const body = await this.cronRequest(`/cron/jobs/${encodeURIComponent(jobId)}?${search}`, {\n method: \"DELETE\",\n });\n if (typeof body.deleted !== \"string\") {\n throw new RuntimeGatewayError(\"Runtime Gateway cron delete is incompatible\", \"protocol\");\n }\n return body.deleted;\n }\n\n async *events(\n after: number,\n topicId?: string,\n signal?: AbortSignal,\n ): AsyncGenerator<RuntimeGatewaySseEvent> {\n const search = new URLSearchParams({ after: String(Math.max(0, after)) });\n if (topicId) search.set(\"topicId\", topicId);\n const response = await this.send(`/events?${search}`, { method: \"GET\", signal });\n if (!response.ok || !response.body) {\n throw new RuntimeGatewayError(\"Runtime Gateway event stream failed\", \"http\", response.status);\n }\n yield* parseRuntimeGatewaySse(response.body);\n }\n\n async getTopicUsage(topicId: string, userId: string): Promise<RuntimeGatewayTopicUsage> {\n const response = await this.send(\n `/topics/${encodeURIComponent(topicId)}/usage?user=${encodeURIComponent(userId)}`,\n { method: \"GET\" },\n this.requestTimeoutMs,\n );\n if (!response.ok) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway topic usage request failed\",\n \"http\",\n response.status,\n );\n }\n const usage = record(record(await json(response))?.usage);\n const read = (key: keyof RuntimeGatewayTopicUsage): number => {\n const value = usage?.[key];\n return typeof value === \"number\" && Number.isFinite(value) ? value : 0;\n };\n return {\n queries: read(\"queries\"),\n inputTokens: read(\"inputTokens\"),\n outputTokens: read(\"outputTokens\"),\n cacheCreationInputTokens: read(\"cacheCreationInputTokens\"),\n cacheReadInputTokens: read(\"cacheReadInputTokens\"),\n estimatedCostUsd: read(\"estimatedCostUsd\"),\n };\n }\n\n async abortTurn(topicId: string, userId: string): Promise<boolean> {\n const response = await this.send(\n `/topics/${encodeURIComponent(topicId)}/abort`,\n {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({ v: RUNTIME_GATEWAY_VERSION, userId }),\n },\n this.requestTimeoutMs,\n );\n if (!response.ok) {\n throw new RuntimeGatewayError(\"Runtime Gateway turn abort failed\", \"http\", response.status);\n }\n const body = record(await json(response));\n if (\n body?.ok !== true ||\n body.v !== RUNTIME_GATEWAY_VERSION ||\n typeof body.aborted !== \"boolean\"\n ) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway turn abort response is incompatible\",\n \"protocol\",\n );\n }\n return body.aborted;\n }\n\n async resetSession(\n topicId: string,\n userId: string,\n reason?: string,\n ): Promise<string | undefined> {\n return this.sessionCommand(topicId, userId, \"reset\", reason);\n }\n\n async compactSession(\n topicId: string,\n userId: string,\n reason?: string,\n ): Promise<string | undefined> {\n return this.sessionCommand(topicId, userId, \"compact\", reason);\n }\n\n private async sessionCommand(\n topicId: string,\n userId: string,\n command: \"reset\" | \"compact\",\n reason?: string,\n ): Promise<string | undefined> {\n const response = await this.send(\n `/topics/${encodeURIComponent(topicId)}/session/${command}`,\n {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n v: RUNTIME_GATEWAY_VERSION,\n userId,\n ...(reason ? { reason } : {}),\n }),\n },\n command === \"compact\" ? this.compactTimeoutMs : this.requestTimeoutMs,\n );\n if (!response.ok) {\n throw new RuntimeGatewayError(\n `Runtime Gateway session ${command} failed`,\n \"http\",\n response.status,\n );\n }\n const body = record(await json(response));\n if (body?.ok !== true || body.v !== RUNTIME_GATEWAY_VERSION) {\n throw new RuntimeGatewayError(\n `Runtime Gateway session ${command} response is incompatible`,\n \"protocol\",\n );\n }\n return typeof body.result === \"string\" ? body.result : undefined;\n }\n}\n"
5
+ "export const RUNTIME_GATEWAY_VERSION = 1 as const;\nexport const RUNTIME_GATEWAY_CONTROL_PATH = \"/api/v1/control/runtime/v1\";\n\nexport type RuntimeGatewayErrorKind = \"config\" | \"timeout\" | \"transport\" | \"protocol\" | \"http\";\n\nexport class RuntimeGatewayError extends Error {\n constructor(\n message: string,\n public readonly kind: RuntimeGatewayErrorKind,\n public readonly status?: number,\n ) {\n super(message);\n }\n}\n\nexport interface RuntimeGatewayHealth {\n ok: true;\n v: typeof RUNTIME_GATEWAY_VERSION;\n nodeId?: string;\n aiName?: string;\n capabilities: string[];\n cursor: number;\n}\n\nexport interface RuntimeGatewayTurnInput {\n topicId: string;\n /** Canonical principal on the execution node. */\n userId: string;\n /** Product-side actor, when it differs from the execution principal. */\n actorUserId?: string;\n actorLabel?: string;\n vaultUserId?: string;\n text: string;\n clientMessageId: string;\n requestId?: string;\n allowAutoContinue?: boolean;\n threadRootId?: string;\n respond?: boolean;\n /** Run without adding the injected prompt or output to the visible transcript. */\n silent?: boolean;\n attachments?: string[];\n visualTools?: boolean;\n fileDeliveryTools?: boolean;\n}\n\nexport interface RuntimeGatewayTurnAcknowledgement {\n ok: true;\n v: typeof RUNTIME_GATEWAY_VERSION;\n accepted: true;\n deduplicated: boolean;\n requestId: string;\n clientMessageId: string;\n topicId: string;\n messageId: string;\n cursor: number;\n}\n\nexport interface RuntimeGatewayTopicDeriveInput {\n userId: string;\n copyHistory: boolean;\n name?: string;\n}\n\nexport interface RuntimeGatewayDerivedTopic {\n id: string;\n title: string;\n kind?: string;\n agent?: string;\n defaultModel?: string;\n defaultEffort?: string;\n parentTopicId?: string;\n isFork?: boolean;\n}\n\nexport interface RuntimeGatewaySseEvent {\n id?: number;\n event: string;\n data: unknown;\n}\n\nexport interface RuntimeGatewayTopicUsage {\n queries: number;\n inputTokens: number;\n outputTokens: number;\n cacheCreationInputTokens: number;\n cacheReadInputTokens: number;\n estimatedCostUsd: number;\n}\n\nexport interface RuntimeGatewayManagerTopic {\n id: string;\n title: string;\n kind: \"manager\";\n agent?: \"claude\" | \"codex\" | \"maestro\";\n participants: Array<{ userId: string; role: \"owner\" | \"member\" }>;\n}\n\nexport interface RuntimeGatewayDeletedMessage {\n id: string;\n topicId: string;\n authorId: string;\n text: string;\n deleted: true;\n createdAt: string;\n}\n\nexport interface RuntimeGatewayCronJob {\n id: string;\n name: string;\n executionPrincipalUserId: string;\n actorOwnerUserId: string;\n topicId: string;\n source: \"prompt\" | \"script\";\n script: string | null;\n scriptExists: boolean;\n prompt: string | null;\n promptPreview: string | null;\n summary: string | null;\n schedule: string;\n timezone: string | null;\n enabled: boolean;\n agent: \"claude\" | \"codex\" | \"maestro\" | null;\n model: string | null;\n effort: string | null;\n nextRunAt: string;\n runCount: number;\n lastRun: Record<string, unknown> | null;\n createdAt: string;\n updatedAt: string;\n canMutate: boolean;\n}\n\nexport interface RuntimeGatewayCronCreateInput {\n userId: string;\n actorUserId: string;\n topicId: string;\n name: string;\n script: string;\n schedule: string;\n timezone?: string;\n agent?: \"claude\" | \"codex\" | \"maestro\";\n model?: string;\n effort?: string;\n}\n\nexport interface RuntimeGatewayCronPatch {\n name?: string;\n topicId?: string;\n script?: string;\n schedule?: string;\n timezone?: string | null;\n enabled?: boolean;\n agent?: \"claude\" | \"codex\" | \"maestro\" | null;\n model?: string | null;\n effort?: string | null;\n}\n\nexport type RuntimeGatewayToken = string | (() => string | Promise<string>);\nexport type RuntimeGatewayFetch = (\n input: string | URL | Request,\n init?: RequestInit,\n) => Promise<Response>;\n\nexport interface RuntimeGatewayClientOptions {\n baseUrl: string;\n token: RuntimeGatewayToken;\n /** Loopback control path or an authenticated relay forward prefix. */\n pathPrefix?: string;\n fetch?: RuntimeGatewayFetch;\n requestTimeoutMs?: number;\n compactTimeoutMs?: number;\n}\n\nfunction record(value: unknown): Record<string, unknown> | null {\n return value && typeof value === \"object\" && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : null;\n}\n\nasync function json(response: Response): Promise<unknown> {\n try {\n return await response.json();\n } catch {\n throw new RuntimeGatewayError(\n \"Runtime Gateway returned invalid JSON\",\n \"protocol\",\n response.status,\n );\n }\n}\n\nfunction validHealth(value: unknown): value is RuntimeGatewayHealth {\n const body = record(value);\n return Boolean(\n body?.ok === true &&\n body.v === RUNTIME_GATEWAY_VERSION &&\n Array.isArray(body.capabilities) &&\n typeof body.cursor === \"number\",\n );\n}\n\nfunction validTurnAck(value: unknown): value is RuntimeGatewayTurnAcknowledgement {\n const body = record(value);\n return Boolean(\n body?.ok === true &&\n body.v === RUNTIME_GATEWAY_VERSION &&\n body.accepted === true &&\n typeof body.deduplicated === \"boolean\" &&\n typeof body.requestId === \"string\" &&\n typeof body.clientMessageId === \"string\" &&\n typeof body.topicId === \"string\" &&\n typeof body.messageId === \"string\" &&\n typeof body.cursor === \"number\",\n );\n}\n\nfunction validManagerTopic(value: unknown): value is RuntimeGatewayManagerTopic {\n const topic = record(value);\n return Boolean(\n typeof topic?.id === \"string\" &&\n typeof topic.title === \"string\" &&\n topic.kind === \"manager\" &&\n Array.isArray(topic.participants),\n );\n}\n\nfunction validDeletedMessage(value: unknown): value is RuntimeGatewayDeletedMessage {\n const message = record(value);\n return Boolean(\n typeof message?.id === \"string\" &&\n typeof message.topicId === \"string\" &&\n typeof message.authorId === \"string\" &&\n typeof message.text === \"string\" &&\n message.deleted === true &&\n typeof message.createdAt === \"string\",\n );\n}\n\nfunction validCronJob(value: unknown): value is RuntimeGatewayCronJob {\n const job = record(value);\n return Boolean(\n typeof job?.id === \"string\" &&\n typeof job.name === \"string\" &&\n typeof job.executionPrincipalUserId === \"string\" &&\n typeof job.actorOwnerUserId === \"string\" &&\n typeof job.topicId === \"string\" &&\n typeof job.schedule === \"string\" &&\n typeof job.enabled === \"boolean\" &&\n typeof job.nextRunAt === \"string\" &&\n typeof job.canMutate === \"boolean\",\n );\n}\n\nexport async function* parseRuntimeGatewaySse(\n body: ReadableStream<Uint8Array>,\n): AsyncGenerator<RuntimeGatewaySseEvent> {\n const reader = body.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n let event = \"message\";\n let id: number | undefined;\n let data: string[] = [];\n const flush = (): RuntimeGatewaySseEvent | null => {\n if (data.length === 0) return null;\n const raw = data.join(\"\\n\");\n data = [];\n try {\n return { event, id, data: JSON.parse(raw) };\n } catch {\n throw new RuntimeGatewayError(\"Runtime Gateway SSE event has invalid JSON\", \"protocol\");\n } finally {\n event = \"message\";\n id = undefined;\n }\n };\n try {\n while (true) {\n const chunk = await reader.read();\n if (chunk.done) break;\n buffer += decoder.decode(chunk.value, { stream: true }).replace(/\\r\\n/g, \"\\n\");\n let newline = buffer.indexOf(\"\\n\");\n while (newline >= 0) {\n const line = buffer.slice(0, newline);\n buffer = buffer.slice(newline + 1);\n if (line === \"\") {\n const parsed = flush();\n if (parsed) yield parsed;\n } else if (line.startsWith(\"event:\")) {\n event = line.slice(6).trim() || \"message\";\n } else if (line.startsWith(\"id:\")) {\n const parsed = Number.parseInt(line.slice(3).trim(), 10);\n if (Number.isFinite(parsed)) id = parsed;\n } else if (line.startsWith(\"data:\")) {\n data.push(line.slice(5).trimStart());\n }\n newline = buffer.indexOf(\"\\n\");\n }\n }\n buffer += decoder.decode();\n if (buffer.startsWith(\"data:\")) data.push(buffer.slice(5).trimStart());\n const parsed = flush();\n if (parsed) yield parsed;\n } finally {\n reader.releaseLock();\n }\n}\n\nexport class RuntimeGatewayClient {\n private readonly pathPrefix: string;\n private readonly request: RuntimeGatewayFetch;\n private readonly requestTimeoutMs: number;\n private readonly compactTimeoutMs: number;\n\n constructor(private readonly options: RuntimeGatewayClientOptions) {\n this.pathPrefix = options.pathPrefix ?? RUNTIME_GATEWAY_CONTROL_PATH;\n this.request = options.fetch ?? fetch;\n this.requestTimeoutMs = options.requestTimeoutMs ?? 5_000;\n this.compactTimeoutMs = options.compactTimeoutMs ?? 5 * 60_000;\n }\n\n private endpoint(path: string): string {\n if (!this.options.baseUrl || !this.options.token) {\n throw new RuntimeGatewayError(\"Runtime Gateway is not configured\", \"config\");\n }\n return `${this.options.baseUrl.replace(/\\/+$/, \"\")}${this.pathPrefix}${path}`;\n }\n\n private async authorization(): Promise<string> {\n try {\n const token =\n typeof this.options.token === \"function\" ? await this.options.token() : this.options.token;\n return `Bearer ${token}`;\n } catch (error) {\n throw new RuntimeGatewayError(\n error instanceof Error ? error.message : \"Runtime Gateway token resolution failed\",\n \"config\",\n );\n }\n }\n\n private async send(path: string, init: RequestInit, timeoutMs?: number): Promise<Response> {\n const authorization = await this.authorization();\n try {\n return await this.request(this.endpoint(path), {\n ...init,\n headers: { authorization, ...init.headers },\n signal: timeoutMs === undefined ? init.signal : AbortSignal.timeout(timeoutMs),\n });\n } catch (error) {\n if (error instanceof DOMException && error.name === \"TimeoutError\") {\n throw new RuntimeGatewayError(\"Runtime Gateway request timed out\", \"timeout\");\n }\n throw new RuntimeGatewayError(\"Runtime Gateway request failed\", \"transport\");\n }\n }\n\n async health(): Promise<RuntimeGatewayHealth> {\n const response = await this.send(\"/health\", { method: \"GET\" }, this.requestTimeoutMs);\n if (!response.ok) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway health request failed\",\n \"http\",\n response.status,\n );\n }\n const body = await json(response);\n if (!validHealth(body)) {\n throw new RuntimeGatewayError(\"Runtime Gateway health response is incompatible\", \"protocol\");\n }\n return body;\n }\n\n async submitTurn(input: RuntimeGatewayTurnInput): Promise<RuntimeGatewayTurnAcknowledgement> {\n const response = await this.send(\n \"/turns\",\n {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({ v: RUNTIME_GATEWAY_VERSION, ...input }),\n },\n this.requestTimeoutMs,\n );\n if (response.status !== 202) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway turn was not accepted\",\n \"http\",\n response.status,\n );\n }\n const body = await json(response);\n if (!validTurnAck(body)) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway turn acknowledgement is incompatible\",\n \"protocol\",\n );\n }\n return body;\n }\n\n async deriveTopic(\n topicId: string,\n input: RuntimeGatewayTopicDeriveInput,\n ): Promise<RuntimeGatewayDerivedTopic> {\n const response = await this.send(\n `/topics/${encodeURIComponent(topicId)}/derive`,\n {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({ v: RUNTIME_GATEWAY_VERSION, ...input }),\n },\n this.requestTimeoutMs,\n );\n if (response.status !== 201) {\n throw new RuntimeGatewayError(\"Runtime Gateway topic derive failed\", \"http\", response.status);\n }\n const body = await json(response);\n const topic = record(body)?.topic;\n const topicRecord = record(topic);\n if (\n !topicRecord ||\n typeof topicRecord.id !== \"string\" ||\n typeof topicRecord.title !== \"string\"\n ) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway topic derive response is incompatible\",\n \"protocol\",\n );\n }\n return topic as unknown as RuntimeGatewayDerivedTopic;\n }\n\n async ensureManagerTopic(userId: string): Promise<RuntimeGatewayManagerTopic> {\n const response = await this.send(\n \"/manager-topic\",\n {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({ v: RUNTIME_GATEWAY_VERSION, userId }),\n },\n this.requestTimeoutMs,\n );\n if (!response.ok) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway manager topic request failed\",\n \"http\",\n response.status,\n );\n }\n const body = record(await json(response));\n if (body?.ok !== true || body.v !== RUNTIME_GATEWAY_VERSION || !validManagerTopic(body.topic)) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway manager topic response is incompatible\",\n \"protocol\",\n );\n }\n return body.topic;\n }\n\n async deleteMessage(\n topicId: string,\n messageId: string,\n actorUserId: string,\n allowAdmin = false,\n ): Promise<RuntimeGatewayDeletedMessage> {\n const response = await this.send(\n `/topics/${encodeURIComponent(topicId)}/messages/${encodeURIComponent(messageId)}`,\n {\n method: \"DELETE\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n v: RUNTIME_GATEWAY_VERSION,\n actorUserId,\n ...(allowAdmin ? { allowAdmin: true } : {}),\n }),\n },\n this.requestTimeoutMs,\n );\n if (!response.ok) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway message delete failed\",\n \"http\",\n response.status,\n );\n }\n const body = record(await json(response));\n if (\n body?.ok !== true ||\n body.v !== RUNTIME_GATEWAY_VERSION ||\n !validDeletedMessage(body.message)\n ) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway message delete response is incompatible\",\n \"protocol\",\n );\n }\n return body.message;\n }\n\n private async cronRequest(path: string, init: RequestInit): Promise<Record<string, unknown>> {\n const response = await this.send(path, init, this.requestTimeoutMs);\n if (!response.ok) {\n throw new RuntimeGatewayError(\"Runtime Gateway cron request failed\", \"http\", response.status);\n }\n const body = record(await json(response));\n if (body?.ok !== true || body.v !== RUNTIME_GATEWAY_VERSION) {\n throw new RuntimeGatewayError(\"Runtime Gateway cron response is incompatible\", \"protocol\");\n }\n return body;\n }\n\n async listCronScripts(): Promise<string[]> {\n const body = await this.cronRequest(\"/cron/scripts\", { method: \"GET\" });\n if (!Array.isArray(body.scripts) || !body.scripts.every((value) => typeof value === \"string\")) {\n throw new RuntimeGatewayError(\"Runtime Gateway cron scripts are incompatible\", \"protocol\");\n }\n return body.scripts;\n }\n\n async listCronJobs(\n userId: string,\n actorUserId: string,\n actorIsAdmin = false,\n ): Promise<RuntimeGatewayCronJob[]> {\n const search = new URLSearchParams({\n user: userId,\n actorUserId,\n actorIsAdmin: actorIsAdmin ? \"1\" : \"0\",\n });\n const body = await this.cronRequest(`/cron/jobs?${search}`, { method: \"GET\" });\n if (!Array.isArray(body.jobs) || !body.jobs.every(validCronJob)) {\n throw new RuntimeGatewayError(\"Runtime Gateway cron jobs are incompatible\", \"protocol\");\n }\n return body.jobs;\n }\n\n async createCronJob(input: RuntimeGatewayCronCreateInput): Promise<RuntimeGatewayCronJob> {\n const body = await this.cronRequest(\"/cron/jobs\", {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({ v: RUNTIME_GATEWAY_VERSION, ...input }),\n });\n if (!validCronJob(body.job)) {\n throw new RuntimeGatewayError(\"Runtime Gateway cron job is incompatible\", \"protocol\");\n }\n return body.job;\n }\n\n async updateCronJob(\n jobId: string,\n userId: string,\n actorUserId: string,\n patch: RuntimeGatewayCronPatch,\n actorIsAdmin = false,\n ): Promise<RuntimeGatewayCronJob> {\n const body = await this.cronRequest(`/cron/jobs/${encodeURIComponent(jobId)}`, {\n method: \"PATCH\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n v: RUNTIME_GATEWAY_VERSION,\n userId,\n actorUserId,\n actorIsAdmin,\n patch,\n }),\n });\n if (!validCronJob(body.job)) {\n throw new RuntimeGatewayError(\"Runtime Gateway cron job is incompatible\", \"protocol\");\n }\n return body.job;\n }\n\n async deleteCronJob(\n jobId: string,\n userId: string,\n actorUserId: string,\n actorIsAdmin = false,\n ): Promise<string> {\n const search = new URLSearchParams({\n user: userId,\n actorUserId,\n actorIsAdmin: actorIsAdmin ? \"1\" : \"0\",\n });\n const body = await this.cronRequest(`/cron/jobs/${encodeURIComponent(jobId)}?${search}`, {\n method: \"DELETE\",\n });\n if (typeof body.deleted !== \"string\") {\n throw new RuntimeGatewayError(\"Runtime Gateway cron delete is incompatible\", \"protocol\");\n }\n return body.deleted;\n }\n\n async *events(\n after: number,\n topicId?: string,\n signal?: AbortSignal,\n ): AsyncGenerator<RuntimeGatewaySseEvent> {\n const search = new URLSearchParams({ after: String(Math.max(0, after)) });\n if (topicId) search.set(\"topicId\", topicId);\n const response = await this.send(`/events?${search}`, { method: \"GET\", signal });\n if (!response.ok || !response.body) {\n throw new RuntimeGatewayError(\"Runtime Gateway event stream failed\", \"http\", response.status);\n }\n yield* parseRuntimeGatewaySse(response.body);\n }\n\n async getTopicUsage(topicId: string, userId: string): Promise<RuntimeGatewayTopicUsage> {\n const response = await this.send(\n `/topics/${encodeURIComponent(topicId)}/usage?user=${encodeURIComponent(userId)}`,\n { method: \"GET\" },\n this.requestTimeoutMs,\n );\n if (!response.ok) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway topic usage request failed\",\n \"http\",\n response.status,\n );\n }\n const usage = record(record(await json(response))?.usage);\n const read = (key: keyof RuntimeGatewayTopicUsage): number => {\n const value = usage?.[key];\n return typeof value === \"number\" && Number.isFinite(value) ? value : 0;\n };\n return {\n queries: read(\"queries\"),\n inputTokens: read(\"inputTokens\"),\n outputTokens: read(\"outputTokens\"),\n cacheCreationInputTokens: read(\"cacheCreationInputTokens\"),\n cacheReadInputTokens: read(\"cacheReadInputTokens\"),\n estimatedCostUsd: read(\"estimatedCostUsd\"),\n };\n }\n\n async abortTurn(topicId: string, userId: string): Promise<boolean> {\n const response = await this.send(\n `/topics/${encodeURIComponent(topicId)}/abort`,\n {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({ v: RUNTIME_GATEWAY_VERSION, userId }),\n },\n this.requestTimeoutMs,\n );\n if (!response.ok) {\n throw new RuntimeGatewayError(\"Runtime Gateway turn abort failed\", \"http\", response.status);\n }\n const body = record(await json(response));\n if (\n body?.ok !== true ||\n body.v !== RUNTIME_GATEWAY_VERSION ||\n typeof body.aborted !== \"boolean\"\n ) {\n throw new RuntimeGatewayError(\n \"Runtime Gateway turn abort response is incompatible\",\n \"protocol\",\n );\n }\n return body.aborted;\n }\n\n async resetSession(\n topicId: string,\n userId: string,\n reason?: string,\n actorUserId?: string,\n ): Promise<string | undefined> {\n return this.sessionCommand(topicId, userId, \"reset\", reason, actorUserId);\n }\n\n async compactSession(\n topicId: string,\n userId: string,\n reason?: string,\n actorUserId?: string,\n ): Promise<string | undefined> {\n return this.sessionCommand(topicId, userId, \"compact\", reason, actorUserId);\n }\n\n private async sessionCommand(\n topicId: string,\n userId: string,\n command: \"reset\" | \"compact\",\n reason?: string,\n actorUserId?: string,\n ): Promise<string | undefined> {\n const response = await this.send(\n `/topics/${encodeURIComponent(topicId)}/session/${command}`,\n {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n v: RUNTIME_GATEWAY_VERSION,\n userId,\n ...(actorUserId ? { actorUserId } : {}),\n ...(reason ? { reason } : {}),\n }),\n },\n command === \"compact\" ? this.compactTimeoutMs : this.requestTimeoutMs,\n );\n if (!response.ok) {\n throw new RuntimeGatewayError(\n `Runtime Gateway session ${command} failed`,\n \"http\",\n response.status,\n );\n }\n const body = record(await json(response));\n if (body?.ok !== true || body.v !== RUNTIME_GATEWAY_VERSION) {\n throw new RuntimeGatewayError(\n `Runtime Gateway session ${command} response is incompatible`,\n \"protocol\",\n );\n }\n return typeof body.result === \"string\" ? body.result : undefined;\n }\n}\n"
6
6
  ],
7
- "mappings": ";;AAAO,IAAM,0BAA0B;AAChC,IAAM,+BAA+B;AAAA;AAIrC,MAAM,4BAA4B,MAAM;AAAA,EAG3B;AAAA,EACA;AAAA,EAHlB,WAAW,CACT,SACgB,MACA,QAChB;AAAA,IACA,MAAM,OAAO;AAAA,IAHG;AAAA,IACA;AAAA;AAIpB;AAgKA,SAAS,MAAM,CAAC,OAAgD;AAAA,EAC9D,OAAO,SAAS,OAAO,UAAU,aAAa,MAAM,QAAQ,KAAK,IAC5D,QACD;AAAA;AAGN,eAAe,IAAI,CAAC,UAAsC;AAAA,EACxD,IAAI;AAAA,IACF,OAAO,MAAM,SAAS,KAAK;AAAA,IAC3B,MAAM;AAAA,IACN,MAAM,IAAI,oBACR,yCACA,YACA,SAAS,MACX;AAAA;AAAA;AAIJ,SAAS,WAAW,CAAC,OAA+C;AAAA,EAClE,MAAM,OAAO,OAAO,KAAK;AAAA,E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,MACA,MAAM,IAAI,oBACR,uDACA,UACF;AAAA,IACF;AAAA,IACA,OAAO,KAAK;AAAA;AAAA,OAGR,aAAY,CAChB,SACA,QACA,QACA,aAC6B;AAAA,IAC7B,OAAO,KAAK,eAAe,SAAS,QAAQ,SAAS,QAAQ,WAAW;AAAA;AAAA,OAGpE,eAAc,CAClB,SACA,QACA,QACA,aAC6B;AAAA,IAC7B,OAAO,KAAK,eAAe,SAAS,QAAQ,WAAW,QAAQ,WAAW;AAAA;AAAA,OAG9D,eAAc,CAC1B,SACA,QACA,SACA,QACA,aAC6B;AAAA,IAC7B,MAAM,WAAW,MAAM,KAAK,KAC1B,WAAW,mBAAmB,OAAO,aAAa,WAClD;AAAA,MACE,QAAQ;AAAA,MACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,MAC9C,MAAM,KAAK,UAAU;AAAA,QACnB,GAAG;AAAA,QACH;AAAA,WACI,cAAc,EAAE,YAAY,IAAI,CAAC;AAAA,WACjC,SAAS,EAAE,OAAO,IAAI,CAAC;AAAA,MAC7B,CAAC;AAAA,IACH,GACA,YAAY,YAAY,KAAK,mBAAmB,KAAK,gBACvD;AAAA,IACA,KAAK,SAAS,IAAI;AAAA,MAChB,MAAM,IAAI,oBACR,2BAA2B,kBAC3B,QACA,SAAS,MACX;AAAA,IACF;AAAA,IACA,MAAM,OAAO,OAAO,MAAM,KAAK,QAAQ,CAAC;AAAA,IACxC,IAAI,MAAM,OAAO,QAAQ,KAAK,MAAM,yBAAyB;AAAA,MAC3D,MAAM,IAAI,oBACR,2BAA2B,oCAC3B,UACF;AAAA,IACF;AAAA,IACA,OAAO,OAAO,KAAK,WAAW,WAAW,KAAK,SAAS;AAAA;AAE3D;",
8
+ "debugId": "7F7442752A2C48FD64756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -4,6 +4,8 @@ import type { BackgroundSessionDto, MessageDto } from "../types/api";
4
4
  export interface RunArchiverTurnParams {
5
5
  /** Stringified user id (route layer hands us strings). */
6
6
  userId: string;
7
+ /** Topic whose placement selects the matching personal #General room. */
8
+ sourceTopicId?: string;
7
9
  /** Wiki-memory topic id. Derived topics pass their root memory origin here. */
8
10
  topicId?: string;
9
11
  /** Human-readable topic title — becomes the wiki `topic` name. */
@@ -33,7 +35,7 @@ export interface ArchiverStorageHost {
33
35
  readTextFile(path: string): string;
34
36
  fileSize(path: string): number;
35
37
  fileModifiedAt(path: string): number;
36
- getGeneralTopicId(userId: string): string;
38
+ getGeneralTopicId(userId: string, sourceTopicId?: string): string;
37
39
  getTopicBrief(topicId: string): {
38
40
  briefMd: string;
39
41
  } | null;
@@ -25,6 +25,7 @@ export interface TurnEventStreamHooks {
25
25
  }
26
26
  export declare function runTurnEventStream(topicId: string, topicTitle: string, queryId: string, events: AsyncGenerator<UnifiedEvent>, control: RoomQueryControl, agentType: AgentKind, model: string, _effort: EffortLevel | undefined, userId: string, hooks: TurnEventStreamHooks, retryableSessionExpired?: boolean, onSessionId?: (sessionId: string) => void, execution?: {
27
27
  silent?: boolean;
28
+ actorUserId?: string;
28
29
  peerBridge?: PeerRuntimeBridgeContext;
29
30
  sourceNode?: string;
30
31
  /** Answer inside this thread instead of the room's main flow (S-13). */
@@ -29,6 +29,7 @@ export declare function resolveWikiMemoryMirror(wikiDir: string, topicId: string
29
29
  };
30
30
  export declare function streamAgentEvents(topicId: string, topicTitle: string, queryId: string, events: AsyncGenerator<UnifiedEvent>, control: RoomQueryControl, agentType: AgentKind, model: string, effort: EffortLevel | undefined, userId: string, retryableSessionExpired?: boolean, onSessionId?: (sessionId: string) => void, execution?: {
31
31
  silent?: boolean;
32
+ actorUserId?: string;
32
33
  peerBridge?: PeerRuntimeBridgeContext;
33
34
  sourceNode?: string;
34
35
  threadRootId?: string;
@@ -175,7 +175,7 @@ export declare class RuntimeGatewayClient {
175
175
  events(after: number, topicId?: string, signal?: AbortSignal): AsyncGenerator<RuntimeGatewaySseEvent>;
176
176
  getTopicUsage(topicId: string, userId: string): Promise<RuntimeGatewayTopicUsage>;
177
177
  abortTurn(topicId: string, userId: string): Promise<boolean>;
178
- resetSession(topicId: string, userId: string, reason?: string): Promise<string | undefined>;
179
- compactSession(topicId: string, userId: string, reason?: string): Promise<string | undefined>;
178
+ resetSession(topicId: string, userId: string, reason?: string, actorUserId?: string): Promise<string | undefined>;
179
+ compactSession(topicId: string, userId: string, reason?: string, actorUserId?: string): Promise<string | undefined>;
180
180
  private sessionCommand;
181
181
  }
@@ -23,6 +23,8 @@ export declare class TopicCleanupRequiredError extends Error {
23
23
  }
24
24
  export interface DeleteTopicCascadeOptions {
25
25
  force?: boolean;
26
+ /** Upstream product actor whose personal General receives archive memory. */
27
+ memoryUserId?: string;
26
28
  /** Account deletion may remove that account's otherwise-protected private General. */
27
29
  allowManager?: boolean;
28
30
  /** Account deletion must not recreate a private General via the archiver. */
@@ -33,6 +33,8 @@ export interface CompactedRolloutRequest extends Omit<CompactSummaryRequest, "so
33
33
  }
34
34
  export interface RestartTopicSessionOptions {
35
35
  archiveMemory?: typeof archiveActiveTopicForMemory;
36
+ /** Upstream product actor whose personal General receives archive memory. */
37
+ memoryUserId?: string;
36
38
  purgeLogs?: typeof purgeTopicLogs;
37
39
  /** Maximum time to wait for durable memory before leaving the session unchanged. */
38
40
  memoryArchiveWaitMs?: number;
@@ -1 +1 @@
1
- export declare const NEGOTIUM_VERSION = "0.6.6";
1
+ export declare const NEGOTIUM_VERSION = "0.6.7";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "negotium",
3
- "version": "0.6.6",
3
+ "version": "0.6.7",
4
4
  "type": "module",
5
5
  "description": "Install the Negotium multi-agent runtime and CLI with one package",
6
6
  "license": "Apache-2.0",