@otium-team/negotium 0.24.1 → 0.24.3

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 (54) hide show
  1. package/bin/negotium.mjs +0 -0
  2. package/dist/agent-helpers.js +43 -23
  3. package/dist/agent-helpers.js.map +9 -9
  4. package/dist/background-bash.js +3 -2
  5. package/dist/background-bash.js.map +3 -3
  6. package/dist/browser-runtime.js +21 -5
  7. package/dist/browser-runtime.js.map +6 -6
  8. package/dist/{chunk-fzfzskjq.js → chunk-7jdavm0e.js} +20 -4
  9. package/dist/{chunk-fzfzskjq.js.map → chunk-7jdavm0e.js.map} +4 -4
  10. package/dist/{chunk-hn2cqdd0.js → chunk-q701c7k3.js} +1 -1
  11. package/dist/{chunk-pesnv5zv.js → chunk-r3q0kjed.js} +4 -3
  12. package/dist/{chunk-pesnv5zv.js.map → chunk-r3q0kjed.js.map} +3 -3
  13. package/dist/{chunk-kfckfff2.js → chunk-rpymxwjr.js} +3 -3
  14. package/dist/{chunk-kfckfff2.js.map → chunk-rpymxwjr.js.map} +2 -2
  15. package/dist/{chunk-d1c2wt8q.js → chunk-wcs8ztpt.js} +4 -2
  16. package/dist/{chunk-d1c2wt8q.js.map → chunk-wcs8ztpt.js.map} +1 -1
  17. package/dist/hosted-agent.js +22 -6
  18. package/dist/hosted-agent.js.map +4 -4
  19. package/dist/main.js +107 -44
  20. package/dist/main.js.map +14 -14
  21. package/dist/mcp-factories.js +43 -23
  22. package/dist/mcp-factories.js.map +9 -9
  23. package/dist/media.js +3 -2
  24. package/dist/media.js.map +3 -3
  25. package/dist/prompts.js +3 -2
  26. package/dist/prompts.js.map +3 -3
  27. package/dist/query-runtime.js +3 -2
  28. package/dist/query-runtime.js.map +3 -3
  29. package/dist/registry.js +3 -3
  30. package/dist/rollout.js +2 -2
  31. package/dist/runtime/src/application/submit-runtime-gateway-turn.ts +15 -0
  32. package/dist/runtime/src/application/topic-service.ts +11 -1
  33. package/dist/runtime/src/mcp/session-history-server.ts +0 -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/browser-profiles.ts +16 -0
  38. package/dist/runtime/src/storage/vault-public.ts +1 -0
  39. package/dist/runtime/src/storage/vault.ts +36 -4
  40. package/dist/runtime/src/topics/update.ts +22 -1
  41. package/dist/runtime/src/version.ts +1 -1
  42. package/dist/runtime-helpers.js +3 -2
  43. package/dist/runtime-helpers.js.map +3 -3
  44. package/dist/types/packages/core/src/platform/config.d.ts +9 -1
  45. package/dist/types/packages/core/src/runtime/turn-runner.d.ts +12 -0
  46. package/dist/types/packages/core/src/storage/browser-profiles.d.ts +7 -0
  47. package/dist/types/packages/core/src/storage/vault-public.d.ts +1 -1
  48. package/dist/types/packages/core/src/storage/vault.d.ts +10 -0
  49. package/dist/types/packages/core/src/version.d.ts +1 -1
  50. package/dist/vault.js +27 -5
  51. package/dist/vault.js.map +4 -4
  52. package/install-browser-rs.mjs +4 -4
  53. package/package.json +1 -1
  54. /package/dist/{chunk-hn2cqdd0.js.map → chunk-q701c7k3.js.map} +0 -0
@@ -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">,
@@ -91,6 +91,22 @@ export function createBrowserProfile(ownerId: string, rawName: string): string {
91
91
  return name;
92
92
  }
93
93
 
94
+ /**
95
+ * The host's assignment of a room to a browser profile (`PATCH /topics/:id`
96
+ * `browserProfile`): the room's owner's, as `assignTopicBrowserProfile` makes
97
+ * it when the owner asks from inside the room. `null` returns the room to the
98
+ * default profile. Takes effect on the room's next turn.
99
+ */
100
+ export function setTopicBrowserProfile(topicId: string, profile: string | null): void {
101
+ const owner = getBrowserProfileOwner(topicId, "");
102
+ if (!owner) throw new Error(`Topic "${topicId}" not found or has no owner.`);
103
+ assignTopicBrowserProfile({
104
+ topicId,
105
+ actorUserId: owner,
106
+ profile: profile ?? DEFAULT_BROWSER_PROFILE,
107
+ });
108
+ }
109
+
94
110
  export function assignTopicBrowserProfile(opts: {
95
111
  topicId: string;
96
112
  actorUserId: string;
@@ -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;
@@ -27,7 +27,12 @@ import {
27
27
  setTopicPlugins,
28
28
  upsertTopic,
29
29
  } from "#storage/api-topics";
30
- import { isBrowserConnectPort, setTopicBrowserConnectPort } from "#storage/browser-profiles";
30
+ import {
31
+ isBrowserConnectPort,
32
+ normalizeBrowserProfileName,
33
+ setTopicBrowserConnectPort,
34
+ setTopicBrowserProfile,
35
+ } from "#storage/browser-profiles";
31
36
  import { db } from "#storage/forum-db";
32
37
  import { getTopicHostMcpGrant } from "#storage/topic-host-mcp-grants";
33
38
  import { TopicValidationError } from "#topics/create";
@@ -58,6 +63,12 @@ export interface UpdateTopicSettingsOptions {
58
63
  * its browser tools attach there. `null` returns the room to its profile.
59
64
  */
60
65
  browserConnectPort?: number | null;
66
+ /**
67
+ * The named browser profile the room's browser tools use from its next
68
+ * turn: rooms on one profile share one browser and its logins. `null`
69
+ * returns the room to the default profile.
70
+ */
71
+ browserProfile?: string | null;
61
72
  /**
62
73
  * Absolute paths of Agent Plugins folders (`#topics/plugins`) whose
63
74
  * skills and servers every turn of the room gets, in this order. Each is
@@ -192,6 +203,15 @@ export function updateTopicSettings(opts: UpdateTopicSettingsOptions): TopicDto
192
203
  ) {
193
204
  throw new TopicValidationError("browserConnectPort must be an integer from 1024 to 65535");
194
205
  }
206
+ if (opts.browserProfile !== undefined && opts.browserProfile !== null) {
207
+ try {
208
+ normalizeBrowserProfileName(opts.browserProfile);
209
+ } catch (err) {
210
+ throw new TopicValidationError(
211
+ `browserProfile: ${err instanceof Error ? err.message : String(err)}`,
212
+ );
213
+ }
214
+ }
195
215
 
196
216
  if (opts.plugins) checkTopicPlugins(current, opts.plugins);
197
217
 
@@ -279,6 +299,7 @@ export function updateTopicSettings(opts: UpdateTopicSettingsOptions): TopicDto
279
299
  if (opts.browserConnectPort !== undefined) {
280
300
  setTopicBrowserConnectPort(next.id, opts.browserConnectPort);
281
301
  }
302
+ if (opts.browserProfile !== undefined) setTopicBrowserProfile(next.id, opts.browserProfile);
282
303
  if (opts.plugins !== undefined) setTopicPlugins(next.id, opts.plugins);
283
304
 
284
305
  // `resolveTopicTurnExecution` reads `config.model ?? topic.defaultModel`, so a
@@ -1 +1 @@
1
- export const NEGOTIUM_VERSION = "0.24.1";
1
+ export const NEGOTIUM_VERSION = "0.24.3";
@@ -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