@otium-team/negotium 0.24.0 → 0.24.2

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 (52) hide show
  1. package/dist/agent-helpers.js +61 -25
  2. package/dist/agent-helpers.js.map +9 -9
  3. package/dist/background-bash.js +3 -2
  4. package/dist/background-bash.js.map +3 -3
  5. package/dist/browser-runtime.js +21 -5
  6. package/dist/browser-runtime.js.map +5 -5
  7. package/dist/{chunk-fzfzskjq.js → chunk-7jdavm0e.js} +20 -4
  8. package/dist/{chunk-fzfzskjq.js.map → chunk-7jdavm0e.js.map} +4 -4
  9. package/dist/{chunk-3r4xfhkx.js → chunk-8nr3h475.js} +3 -3
  10. package/dist/{chunk-3r4xfhkx.js.map → chunk-8nr3h475.js.map} +2 -2
  11. package/dist/{chunk-hn2cqdd0.js → chunk-q701c7k3.js} +1 -1
  12. package/dist/{chunk-pesnv5zv.js → chunk-r3q0kjed.js} +4 -3
  13. package/dist/{chunk-pesnv5zv.js.map → chunk-r3q0kjed.js.map} +3 -3
  14. package/dist/{chunk-d1c2wt8q.js → chunk-wcs8ztpt.js} +4 -2
  15. package/dist/{chunk-d1c2wt8q.js.map → chunk-wcs8ztpt.js.map} +1 -1
  16. package/dist/hosted-agent.js +22 -6
  17. package/dist/hosted-agent.js.map +4 -4
  18. package/dist/main.js +161 -46
  19. package/dist/main.js.map +13 -13
  20. package/dist/mcp-factories.js +61 -25
  21. package/dist/mcp-factories.js.map +9 -9
  22. package/dist/media.js +3 -2
  23. package/dist/media.js.map +3 -3
  24. package/dist/prompts.js +3 -2
  25. package/dist/prompts.js.map +3 -3
  26. package/dist/query-runtime.js +3 -2
  27. package/dist/query-runtime.js.map +3 -3
  28. package/dist/registry.js +3 -3
  29. package/dist/rollout.js +2 -2
  30. package/dist/runtime/src/agents/mcp-tools/ask-user.ts +56 -1
  31. package/dist/runtime/src/application/submit-runtime-gateway-turn.ts +86 -0
  32. package/dist/runtime/src/application/topic-service.ts +11 -1
  33. package/dist/runtime/src/application/turn-follow-ups.ts +7 -0
  34. package/dist/runtime/src/platform/config.ts +9 -1
  35. package/dist/runtime/src/platform/playwright/vault-broker.ts +6 -2
  36. package/dist/runtime/src/runtime/turn-runner.ts +58 -23
  37. package/dist/runtime/src/storage/vault-public.ts +1 -0
  38. package/dist/runtime/src/storage/vault.ts +36 -4
  39. package/dist/runtime/src/version.ts +1 -1
  40. package/dist/runtime-helpers.js +3 -2
  41. package/dist/runtime-helpers.js.map +3 -3
  42. package/dist/types/packages/core/src/agents/mcp-tools/ask-user.d.ts +14 -0
  43. package/dist/types/packages/core/src/platform/config.d.ts +9 -1
  44. package/dist/types/packages/core/src/runtime/turn-runner.d.ts +12 -0
  45. package/dist/types/packages/core/src/storage/vault-public.d.ts +1 -1
  46. package/dist/types/packages/core/src/storage/vault.d.ts +10 -0
  47. package/dist/types/packages/core/src/version.d.ts +1 -1
  48. package/dist/vault.js +27 -5
  49. package/dist/vault.js.map +4 -4
  50. package/install-browser-rs.mjs +4 -4
  51. package/package.json +1 -1
  52. /package/dist/{chunk-hn2cqdd0.js.map → chunk-q701c7k3.js.map} +0 -0
@@ -1,10 +1,12 @@
1
1
  import { createHash, randomUUID } from "node:crypto";
2
+ import { answerOpenAskUserQuestionWithText } from "#agents/mcp-tools/ask-user";
2
3
  import { hostMcpGrantRefusal, isReservedRuntimeMcpServerName } from "#platform/mcp-config";
3
4
  import { abortRoom, getRoomQuery } from "#query/active-rooms";
4
5
  import { AbortReason } from "#query/types";
5
6
  import { stampActorTopicScope } from "#runtime/actor-topic-scope";
6
7
  import { resolveAttachmentByFileId } from "#runtime/file-hooks";
7
8
  import { describeQuotedAuthor } from "#runtime/thread-context";
9
+ import { preemptSessionInjectForUserTurn } from "#runtime/turn-runner";
8
10
  import {
9
11
  renderUserTurnBatch,
10
12
  renderUserTurnPrompt,
@@ -246,6 +248,73 @@ export class RuntimeGatewayTopicUnavailableError extends Error {
246
248
  }
247
249
  }
248
250
 
251
+ /**
252
+ * A message typed while the running turn waits on an `ask_user_question` card
253
+ * in the same flow is that card's answer, in the person's own words. Queuing it
254
+ * as a turn would leave it behind the card until the card times out, with the
255
+ * room looking frozen. Plain text only: a message with attachments, a quote, or
256
+ * no AI response keeps the normal path, as does a sender who may not answer the
257
+ * card (the same participant rule as pressing a button). Null means "not an
258
+ * answer"; the caller carries on as before.
259
+ */
260
+ export function answerOpenAskWithMessage(
261
+ params: SubmitRuntimeGatewayTurnParams,
262
+ ): SubmitRuntimeGatewayTurnResult | null {
263
+ const text = params.text.trim();
264
+ if (
265
+ !text ||
266
+ params.respond === false ||
267
+ params.silent === true ||
268
+ params.parentId ||
269
+ params.attachments?.length ||
270
+ isTopicClaimAbortFenced(params.topic.id)
271
+ ) {
272
+ return null;
273
+ }
274
+ const requestId = params.requestId ?? params.clientMessageId;
275
+ const actorUserId = params.actorUserId ?? params.userId;
276
+ const sourceAdapter = params.sourceAdapter?.trim() || "runtime-gateway";
277
+ const answered = answerOpenAskUserQuestionWithText(params.topic.id, text, params.userId, {
278
+ ...(params.threadRootId ? { threadRootId: params.threadRootId } : {}),
279
+ answerMessage: {
280
+ authorId: actorUserId,
281
+ ...(params.actorLabel ? { authorName: params.actorLabel } : {}),
282
+ sourceAdapter,
283
+ sourceMessageId: params.clientMessageId,
284
+ },
285
+ });
286
+ if (!answered?.ok) return null;
287
+
288
+ const message = answered.answerMessage;
289
+ const submission: RuntimeGatewaySubmission = {
290
+ clientMessageId: params.clientMessageId,
291
+ requestId,
292
+ topicId: params.topic.id,
293
+ messageId: message.id,
294
+ userId: params.userId,
295
+ createdAt: message.createdAt,
296
+ ackCursor: 0,
297
+ messageCursor: 0,
298
+ payloadHash: gatewayPayloadHash(params, requestId, actorUserId),
299
+ };
300
+ db.transaction(() => {
301
+ const acceptedEvent = appendRuntimeEvent("runtime-gateway-ingress", {
302
+ type: "ai-status",
303
+ topicId: params.topic.id,
304
+ payload: {
305
+ kind: "turn_accepted",
306
+ requestId,
307
+ clientMessageId: params.clientMessageId,
308
+ messageId: message.id,
309
+ delivery: "answered",
310
+ },
311
+ });
312
+ submission.ackCursor = acceptedEvent.seq;
313
+ recordRuntimeGatewaySubmission(submission);
314
+ })();
315
+ return { ...submission, message, deduplicated: false };
316
+ }
317
+
249
318
  export function submitRuntimeGatewayTurn(
250
319
  params: SubmitRuntimeGatewayTurnParams,
251
320
  ): SubmitRuntimeGatewayTurnResult {
@@ -276,6 +345,9 @@ export function submitRuntimeGatewayTurn(
276
345
  // atomically, by the `api_messages` trigger inside the transaction below.
277
346
  if (isTopicClaimAbortFenced(params.topic.id)) throw new RuntimeGatewayTopicUnavailableError();
278
347
 
348
+ const answeredAsk = answerOpenAskWithMessage(params);
349
+ if (answeredAsk) return answeredAsk;
350
+
279
351
  // Remember what this adapter grants for the room, so the turns that never
280
352
  // see an adapter — tell/ask, cron, auto-continue, subagent reports — inherit
281
353
  // it instead of silently running without the tools.
@@ -338,6 +410,11 @@ export function submitRuntimeGatewayTurn(
338
410
  // never recorded, stays a separate queue entry), and only a folded turn has
339
411
  // a replacement batch to resume from after the abort.
340
412
  let steersActiveTurn = false;
413
+ // Whether this message should preempt a session-inject (a tell, an ask, or a
414
+ // delegated subagent task) the room is running. Such a turn has no durable
415
+ // user request, so `active` is null and nothing above can steer it, while
416
+ // its room lease keeps the durable worker from ever claiming this message.
417
+ let preemptsSessionInject = false;
341
418
  let delivery: "injected" | "queued" | "steered" | "started" | undefined;
342
419
  try {
343
420
  db.transaction(() => {
@@ -431,6 +508,11 @@ export function submitRuntimeGatewayTurn(
431
508
  });
432
509
  steersActiveTurn =
433
510
  active !== null && merged.supersededRequestIds.includes(active.requestId);
511
+ preemptsSessionInject =
512
+ active === null &&
513
+ params.steer !== false &&
514
+ params.inject !== true &&
515
+ params.silent !== true;
434
516
  delivery = steersActiveTurn ? "steered" : active ? "queued" : "started";
435
517
  }
436
518
  }
@@ -479,6 +561,10 @@ export function submitRuntimeGatewayTurn(
479
561
  // request waits its turn in the queue and runs with its own actor and
480
562
  // assertion.
481
563
  if (steersActiveTurn) abortRoom(params.topic.id, AbortReason.Internal);
564
+ // A steer behind a session-inject: re-queue that inject behind this message
565
+ // and abort it, so the room lease is released and this message's turn starts.
566
+ // No-op when the room is idle or runs a person's turn.
567
+ else if (preemptsSessionInject) preemptSessionInjectForUserTurn(params.topic.id);
482
568
 
483
569
  return { ...submission, message, deduplicated: false };
484
570
  }
@@ -7,12 +7,14 @@ import { answerPendingVaultSecretRequest } from "#agents/mcp-tools/request-vault
7
7
  import { WsHub } from "#bus";
8
8
  import { abortRoom, getRoomQuery } from "#query/active-rooms";
9
9
  import { AbortReason } from "#query/types";
10
+ import { preemptSessionInjectForUserTurn } from "#runtime/turn-runner";
10
11
  import { getTopic } from "#storage/api-topics";
11
12
  import { getRuntimeTurnLease } from "#storage/runtime-leases";
12
13
  import { beginRuntimeTopicMaintenance } from "#storage/runtime-topic-state";
13
14
  import {
14
15
  cancelRuntimeUserTurnRequestsBeforeEpoch,
15
16
  foldQueuedIntoActiveRuntimeUserTurnRequest,
17
+ getRuntimeUserTurnRequest,
16
18
  } from "#storage/runtime-turn-requests";
17
19
  import { type RegisterTopicOptions, registerTopic } from "#topics/create";
18
20
  import { createDerivedTopic } from "#topics/derive";
@@ -157,7 +159,15 @@ export const topicService = {
157
159
  steerQueuedTurn(topicId: string, userId: string): boolean {
158
160
  participantTopic(topicId, userId);
159
161
  const folded = foldQueuedIntoActiveRuntimeUserTurnRequest(topicId, randomUUID());
160
- if (!folded) return false;
162
+ if (!folded) {
163
+ // Nothing to fold because the room runs a session-inject (a tell, an ask,
164
+ // or a delegated subagent task), not a person's turn. Its lease keeps the
165
+ // queued messages from ever being claimed, so preempt it instead: it is
166
+ // re-queued behind them and the queued turn starts once the room frees.
167
+ const queued = getRuntimeUserTurnRequest(topicId);
168
+ if (queued?.status !== "pending") return false;
169
+ return preemptSessionInjectForUserTurn(topicId);
170
+ }
161
171
  // Abort in-process immediately when this runtime process holds the turn
162
172
  // (the common single-process case); `requestRuntimeTurnAbort` alone would
163
173
  // only mark the lease and wait for the next ~1s heartbeat poll to notice.
@@ -36,6 +36,7 @@ import { isRuntimeTopicMaintenance } from "#storage/runtime-topic-state";
36
36
  import { getRuntimeUserTurnRequest } from "#storage/runtime-turn-requests";
37
37
  import type { AttachmentDto } from "#types/api";
38
38
  import {
39
+ answerOpenAskWithMessage,
39
40
  type SubmitRuntimeGatewayTurnParams,
40
41
  type SubmitRuntimeGatewayTurnResult,
41
42
  submitRuntimeGatewayTurn,
@@ -116,6 +117,12 @@ export function holdOrSubmitRuntimeGatewayTurn(
116
117
  const alreadySent = findRuntimeGatewaySubmission(params.clientMessageId, requestId) !== null;
117
118
  const waiting = listRuntimeFollowUps(topicId).length > 0;
118
119
  const paused = areRuntimeFollowUpsPaused(topicId);
120
+ // An open question is waiting for exactly this: answer it instead of holding
121
+ // the message behind the question until the question times out.
122
+ if (!alreadySent) {
123
+ const answered = answerOpenAskWithMessage(params);
124
+ if (answered) return { held: false, submission: answered };
125
+ }
119
126
  const holdable = !alreadySent && params.respond !== false && params.silent !== true;
120
127
  if (holdable && (isRoomWorking(topicId) || (waiting && !paused))) {
121
128
  const { topic: _topic, text, ...rest } = params;
@@ -139,7 +139,7 @@ export function resolveOutputLanguage(): string {
139
139
  export const BINARY_EXTENSION = process.platform === "win32" ? ".exe" : "";
140
140
 
141
141
  /** Browser.rs release tested with this Negotium version. */
142
- export const BROWSER_RS_VERSION = "v0.7.7";
142
+ export const BROWSER_RS_VERSION = "v0.8.1";
143
143
  /** Require the authenticated listener and the current Browser.rs tool contract. */
144
144
  export const BROWSER_RS_MIN_SECURE_VERSION = "0.2.1";
145
145
 
@@ -438,6 +438,14 @@ export const VAULT_MASTER_KEY = loadOrCreateLocalSecret(
438
438
  // Agent/tool subprocesses inherit process.env. Keep the loaded key in this
439
439
  // process only so `env`/`ps` inside an agent workspace cannot reveal it.
440
440
  delete process.env.NEGOTIUM_VAULT_MASTER_KEY;
441
+ /**
442
+ * Owner id of the Vault rows every user of this node may use, or undefined for none.
443
+ *
444
+ * A `{{KEY}}` a user has not saved themselves is then read from this owner's rows, and those values
445
+ * are redacted from every user's tool output. For a deployment whose users share some credentials
446
+ * (one office's certificate) while keeping their own (each member's login).
447
+ */
448
+ export const VAULT_SHARED_USER_ID = process.env.NEGOTIUM_VAULT_SHARED_USER?.trim() || undefined;
441
449
 
442
450
  /** The node's single open port: runtime MCP endpoint + node API. */
443
451
  export const NEGOTIUM_PORT = parseInt(process.env.NEGOTIUM_PORT || "7777", 10);
@@ -3,7 +3,11 @@ import { createServer, type Server, type Socket } from "node:net";
3
3
  import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
5
5
  import { ipcEndpoint, restrictIpcEndpoint } from "#platform/ipc";
6
- import { redactVaultSecrets, vaultGetValue, vaultSubstituteDetailed } from "#storage/vault-public";
6
+ import {
7
+ redactVaultSecrets,
8
+ vaultResolveValue,
9
+ vaultSubstituteDetailed,
10
+ } from "#storage/vault-public";
7
11
 
8
12
  const MAX_REQUEST_BYTES = 16 * 1024 * 1024;
9
13
  const DEFAULT_OUTPUT_LIMIT = 100_000;
@@ -172,7 +176,7 @@ export async function createBrowserVaultBroker(userId: string): Promise<BrowserV
172
176
  const substituted = deepMapStrings(request.value, (text) => {
173
177
  const result = vaultSubstituteDetailed(userId, text);
174
178
  for (const key of result.usedKeys) {
175
- const secret = vaultGetValue(userId, key);
179
+ const secret = vaultResolveValue(userId, key);
176
180
  if (secret === undefined) continue;
177
181
  for (const form of encodedSecretForms(secret)) retainedForms.set(form, key);
178
182
  }
@@ -1414,29 +1414,7 @@ export function startAiTurn(params: StartAiTurnParams): string | null {
1414
1414
  }
1415
1415
  // The preempted turn was itself a session-inject → re-queue it so the
1416
1416
  // inter-session work isn't lost; it resumes after the user's turn.
1417
- if (running.injectParams) {
1418
- const runningInject = running.injectParams;
1419
- // A silent ask fork may already contain a partially-consumed provider
1420
- // rollout. Requeue only its recipe, never that mutable rollout; the old
1421
- // turn's finally block owns cleanup and the replay prepares a fresh fork.
1422
- const requeuedInject = prepareInjectReplayAfterUserPreemption(runningInject);
1423
- const queued = deferInject(requeuedInject);
1424
- running.injectRequeued = queued;
1425
- if (queued && runningInject.prepareSession) {
1426
- // The queued copy retained requestId, so detach it from the dying
1427
- // control. The async preparation may still publish an old fork after
1428
- // this abort; finally must clean that fork instead of mistaking it for
1429
- // the queued replay's resource.
1430
- running.injectParams = { ...runningInject, requestId: undefined };
1431
- } else if (!queued && runningInject.forkHandle) {
1432
- cleanupAgentFork(runningInject.forkHandle);
1433
- running.injectParams = {
1434
- ...runningInject,
1435
- forkHandle: undefined,
1436
- sessionId: undefined,
1437
- };
1438
- }
1439
- }
1417
+ requeueSessionInjectForUserPreemption(running);
1440
1418
  running.abortReason = AbortReason.Internal;
1441
1419
  running.abortController.abort();
1442
1420
  logger.info(
@@ -2303,6 +2281,63 @@ export function startAiTurn(params: StartAiTurnParams): string | null {
2303
2281
  return queryId;
2304
2282
  }
2305
2283
 
2284
+ /**
2285
+ * Re-queue a running session-inject (tell, ask, delegated subagent task) that
2286
+ * a person's turn is about to preempt, so its work resumes after that turn.
2287
+ * Marks the control so the aborted run settles as requeued, not as a failure.
2288
+ * Returns whether the inject is now waiting in the inter-session queue.
2289
+ */
2290
+ function requeueSessionInjectForUserPreemption(running: RoomQueryControl): boolean {
2291
+ const runningInject = running.injectParams;
2292
+ if (!runningInject) return false;
2293
+ // A silent ask fork may already contain a partially-consumed provider
2294
+ // rollout. Requeue only its recipe, never that mutable rollout; the old
2295
+ // turn's finally block owns cleanup and the replay prepares a fresh fork.
2296
+ const requeuedInject = prepareInjectReplayAfterUserPreemption(runningInject);
2297
+ const queued = deferInject(requeuedInject);
2298
+ running.injectRequeued = queued;
2299
+ if (queued && runningInject.prepareSession) {
2300
+ // The queued copy retained requestId, so detach it from the dying
2301
+ // control. The async preparation may still publish an old fork after
2302
+ // this abort; finally must clean that fork instead of mistaking it for
2303
+ // the queued replay's resource.
2304
+ running.injectParams = { ...runningInject, requestId: undefined };
2305
+ } else if (!queued && runningInject.forkHandle) {
2306
+ cleanupAgentFork(runningInject.forkHandle);
2307
+ running.injectParams = {
2308
+ ...runningInject,
2309
+ forkHandle: undefined,
2310
+ sessionId: undefined,
2311
+ };
2312
+ }
2313
+ return queued;
2314
+ }
2315
+
2316
+ /**
2317
+ * A person's steer arrived while this process runs a session-inject in the
2318
+ * topic room (a tell, an ask, or a delegated subagent task). Their durable
2319
+ * turn cannot be claimed while that inject holds the room lease, so the
2320
+ * abort-replace path in {@link startAiTurn} is never reached. Preempt it here
2321
+ * instead: re-queue the inject behind the person's turn and abort it, which
2322
+ * releases the lease so the durable worker starts the person's turn.
2323
+ *
2324
+ * Does nothing (returns false) when the room is idle, runs a person's turn,
2325
+ * or runs an inject that could not be re-queued, so no work is ever dropped.
2326
+ */
2327
+ export function preemptSessionInjectForUserTurn(topicId: string): boolean {
2328
+ const running = getRoomQuery(topicId);
2329
+ if (!running || isUserOrigin(running.origin) || !running.injectParams) return false;
2330
+ if (running.abortController.signal.aborted) return false;
2331
+ if (!requeueSessionInjectForUserPreemption(running)) return false;
2332
+ running.abortReason = AbortReason.Internal;
2333
+ running.abortController.abort();
2334
+ logger.info(
2335
+ { topicId, supersededQueryId: running.queryId, supersededOrigin: running.origin },
2336
+ "ai: user steer preempted running session-inject",
2337
+ );
2338
+ return true;
2339
+ }
2340
+
2306
2341
  export function wasLocallyRequeuedAfterUserPreemption(
2307
2342
  outcomeKind: StreamAgentOutcome["kind"],
2308
2343
  control: Pick<RoomQueryControl, "abortReason" | "injectParams" | "injectRequeued">,
@@ -21,6 +21,7 @@ export {
21
21
  vaultHasKey,
22
22
  vaultList,
23
23
  vaultListWithValues,
24
+ vaultResolveValue,
24
25
  vaultSet,
25
26
  vaultSubstituteDetailed,
26
27
  } from "#storage/vault";
@@ -1,6 +1,6 @@
1
1
  import { chmodSync, mkdirSync } from "node:fs";
2
2
  import { join } from "node:path";
3
- import { VAULT_MASTER_KEY } from "#platform/config";
3
+ import { VAULT_MASTER_KEY, VAULT_SHARED_USER_ID } from "#platform/config";
4
4
  import { closeDatabase, Database } from "#storage/sqlite";
5
5
  import { resolveStorageDataDir } from "#storage/storage-host";
6
6
  import { decryptVaultValue, encryptVaultValue, isEncryptedVaultValue } from "#storage/vault-crypto";
@@ -13,10 +13,21 @@ export interface VaultStorageOptions {
13
13
  masterKey?: string;
14
14
  /** Prior keys rows may still be encrypted under; migrated onto `masterKey`. */
15
15
  legacyMasterKeys?: readonly string[];
16
+ /**
17
+ * Owner id of the rows every user may use (see `VAULT_SHARED_USER_ID`). Omitted keeps the
18
+ * process default; null turns sharing off.
19
+ */
20
+ sharedUserId?: string | null;
16
21
  }
17
22
 
18
23
  let vaultDb: VaultDatabase | undefined;
19
24
  let vaultMasterKey = VAULT_MASTER_KEY;
25
+ let vaultSharedUserId = VAULT_SHARED_USER_ID;
26
+
27
+ /** The shared owner whose rows `userId` may also use; none for that owner itself. */
28
+ function sharedOwnerFor(userId: string): string | undefined {
29
+ return vaultSharedUserId && vaultSharedUserId !== userId ? vaultSharedUserId : undefined;
30
+ }
20
31
 
21
32
  function initializeVaultDatabase(database: VaultDatabase): void {
22
33
  database.exec("PRAGMA journal_mode = WAL");
@@ -148,6 +159,7 @@ export function configureVaultStorage(options: VaultStorageOptions): () => void
148
159
  }
149
160
  const previousDb = vaultDb;
150
161
  const previousMasterKey = vaultMasterKey;
162
+ const previousSharedUserId = vaultSharedUserId;
151
163
  const configuredDb =
152
164
  options.database ?? openVaultDatabase(options.dataDir ?? resolveStorageDataDir());
153
165
  const targetKey = options.masterKey ?? VAULT_MASTER_KEY;
@@ -168,6 +180,7 @@ export function configureVaultStorage(options: VaultStorageOptions): () => void
168
180
  }
169
181
  vaultDb = configuredDb;
170
182
  vaultMasterKey = targetKey;
183
+ if (options.sharedUserId !== undefined) vaultSharedUserId = options.sharedUserId ?? undefined;
171
184
  let disposed = false;
172
185
  return () => {
173
186
  if (disposed) return;
@@ -177,6 +190,7 @@ export function configureVaultStorage(options: VaultStorageOptions): () => void
177
190
  }
178
191
  vaultDb = previousDb;
179
192
  vaultMasterKey = previousMasterKey;
193
+ vaultSharedUserId = previousSharedUserId;
180
194
  };
181
195
  }
182
196
 
@@ -304,6 +318,17 @@ export function vaultGetValue(userId: string, key: string): string | undefined {
304
318
  return row ? decryptRow(userId, row.key, row.value) : undefined;
305
319
  }
306
320
 
321
+ /**
322
+ * The value `{{KEY}}` stands for in `userId`'s tool inputs: their own row, else the shared owner's.
323
+ * A user's own value wins, so a member can keep a personal credential under a shared name.
324
+ */
325
+ export function vaultResolveValue(userId: string, key: string): string | undefined {
326
+ const own = vaultGetValue(userId, key);
327
+ if (own !== undefined) return own;
328
+ const shared = sharedOwnerFor(userId);
329
+ return shared ? vaultGetValue(shared, key) : undefined;
330
+ }
331
+
307
332
  export interface VaultSubstitutionResult {
308
333
  text: string;
309
334
  usedKeys: string[];
@@ -315,7 +340,7 @@ export function vaultSubstituteDetailed(userId: string, text: string): VaultSubs
315
340
  const usedKeys = new Set<string>();
316
341
  const substituted = text.replace(/\{\{([^}]+)\}\}/g, (match, rawKey: string) => {
317
342
  const key = normalizeVaultKey(rawKey);
318
- if (!entries.has(key)) entries.set(key, vaultGetValue(userId, key));
343
+ if (!entries.has(key)) entries.set(key, vaultResolveValue(userId, key));
319
344
  const value = entries.get(key);
320
345
  if (value === undefined) return match;
321
346
  usedKeys.add(key);
@@ -326,7 +351,10 @@ export function vaultSubstituteDetailed(userId: string, text: string): VaultSubs
326
351
 
327
352
  /** Detect real {{KEY}} references without decrypting any Vault values. */
328
353
  export function valueReferencesVaultKey(userId: string, value: unknown): boolean {
329
- const keys = new Set(vaultList(userId).map((entry) => entry.key));
354
+ const shared = sharedOwnerFor(userId);
355
+ const keys = new Set(
356
+ [...vaultList(userId), ...(shared ? vaultList(shared) : [])].map((entry) => entry.key),
357
+ );
330
358
  const visit = (candidate: unknown): boolean => {
331
359
  if (typeof candidate === "string") {
332
360
  for (const match of candidate.matchAll(/\{\{([^}]+)\}\}/g)) {
@@ -357,7 +385,11 @@ function encodedSecretForms(value: string): string[] {
357
385
 
358
386
  /** Scrub raw and common encoded forms before tool output reaches a model. */
359
387
  export function redactVaultSecrets(userId: string, text: string): string {
360
- const candidates = vaultListDecryptableValues(userId)
388
+ const shared = sharedOwnerFor(userId);
389
+ const candidates = [
390
+ ...vaultListDecryptableValues(userId),
391
+ ...(shared ? vaultListDecryptableValues(shared) : []),
392
+ ]
361
393
  .flatMap((entry) => encodedSecretForms(entry.value).map((form) => ({ form, key: entry.key })))
362
394
  .sort((a, b) => b.form.length - a.form.length || a.key.localeCompare(b.key));
363
395
  if (candidates.length === 0) return text;
@@ -1 +1 @@
1
- export const NEGOTIUM_VERSION = "0.24.0";
1
+ export const NEGOTIUM_VERSION = "0.24.2";
@@ -563,7 +563,7 @@ var SESSION_WORKSPACE_DIR = resolve(STATE_DIR, "data", "sessions");
563
563
  var CLAUDE_EXECUTABLE_ENV = envText("NEGOTIUM_CLAUDE_EXECUTABLE");
564
564
  var CLAUDE_EXECUTABLE = CLAUDE_EXECUTABLE_ENV ? resolve(CLAUDE_EXECUTABLE_ENV) : undefined;
565
565
  var BINARY_EXTENSION = process.platform === "win32" ? ".exe" : "";
566
- var BROWSER_RS_VERSION = "v0.7.7";
566
+ var BROWSER_RS_VERSION = "v0.8.1";
567
567
  var BROWSER_RS_MIN_SECURE_VERSION = "0.2.1";
568
568
  function versionAtLeast(actualVersion, minimumVersion) {
569
569
  const actual = actualVersion.split(".").map(Number);
@@ -685,6 +685,7 @@ var NODE_CONTROL_TOKEN = loadOrCreateLocalSecret("NEGOTIUM_CONTROL_TOKEN", "node
685
685
  var NODE_ID = loadOrCreateLocalSecret("NEGOTIUM_NODE_ID", "node-id");
686
686
  var VAULT_MASTER_KEY = loadOrCreateLocalSecret("NEGOTIUM_VAULT_MASTER_KEY", "vault-master-key", { persistEnvValue: true });
687
687
  delete process.env.NEGOTIUM_VAULT_MASTER_KEY;
688
+ var VAULT_SHARED_USER_ID = process.env.NEGOTIUM_VAULT_SHARED_USER?.trim() || undefined;
688
689
  var NEGOTIUM_PORT = parseInt(process.env.NEGOTIUM_PORT || "7777", 10);
689
690
  var hostname = process.env.HOSTNAME || "127.0.0.1";
690
691
  var DATA_DIR = resolveLocalStateDir("NEGOTIUM_DATA_DIR", "data");
@@ -1818,4 +1819,4 @@ export {
1818
1819
  writeJsonlFile
1819
1820
  };
1820
1821
 
1821
- //# debugId=54A225805CC28D1964756E2164756E21
1822
+ //# debugId=109C75203D7173FC64756E2164756E21