@rivus/agent 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -94,6 +94,9 @@ interface InvocationAuthorityRef {
94
94
  }
95
95
  interface InvocationAuthority {
96
96
  readonly agentId: string;
97
+ readonly allowedActorOpenIds?: ReadonlyArray<string>;
98
+ readonly conversationId?: string;
99
+ readonly endpointId?: string;
97
100
  readonly instanceId: string;
98
101
  readonly memory?: AgentMemoryAuthority;
99
102
  readonly runId: string;
package/dist/pi.js CHANGED
@@ -88,6 +88,9 @@ function createPiToolProxyDefinitions(options) {
88
88
  const result = await options.broker.execute({
89
89
  authority: createInvocationAuthority({
90
90
  agentId: options.agentId,
91
+ allowedActorOpenIds: invocation.allowedActorOpenIds,
92
+ ...invocation.memory?.conversationId ? { conversationId: invocation.memory.conversationId } : {},
93
+ endpointId: invocation.endpointId,
91
94
  instanceId: options.instanceId,
92
95
  ...invocation.memory ? { memory: {
93
96
  ...invocation.memory,
@@ -1,5 +1,5 @@
1
1
  import { t as MEMORY_SCOPES } from "./agent-memory.js";
2
- import { n as resolveRivusAgentDefinition, r as deepFreeze, t as createRivusPluginCatalog } from "./rivus-plugin-registry.js";
2
+ import { h as narrowBackgroundSessionDefinition, n as resolveRivusAgentDefinition, r as deepFreeze, t as createRivusPluginCatalog } from "./rivus-plugin-registry.js";
3
3
  import { createRequire } from "node:module";
4
4
  import { Effect } from "effect";
5
5
  import { createHash, randomUUID } from "node:crypto";
@@ -109,7 +109,7 @@ async function loadRivusDeployment(options) {
109
109
  continue;
110
110
  }
111
111
  try {
112
- const baseDefinition = resolveRivusAgentDefinition(catalog, agent);
112
+ const baseDefinition = resolveRivusAgentDefinition(catalog, agent, { backgroundSessions: options.manifest.backgroundSessions?.enabled === true });
113
113
  const projectSpace = agent.projectSpaceId ? options.manifest.projectSpaces?.find(({ id }) => id === agent.projectSpaceId) : void 0;
114
114
  const definition = projectSpace ? deepFreeze({
115
115
  ...baseDefinition,
@@ -224,6 +224,13 @@ function validateRivusDeploymentManifest(manifest) {
224
224
  if (!defaultEndpoint) throw new Error(`default endpoint does not exist: ${manifest.defaultEndpointId}`);
225
225
  if (defaultEndpoint.agentId !== defaultAgent.agentId) throw new Error("default endpoint is not bound to the default agent");
226
226
  if (!defaultEndpoint.enabled) throw new Error("default endpoint must be enabled");
227
+ if (manifest.backgroundSessions) validateBackgroundSessions(manifest.backgroundSessions);
228
+ }
229
+ function validateBackgroundSessions(config) {
230
+ if (config.required && !config.enabled) throw new Error("backgroundSessions.required requires backgroundSessions.enabled");
231
+ if (config.leaseRenewalIntervalMs >= config.leaseMs) throw new Error("backgroundSessions.leaseRenewalIntervalMs must be shorter than leaseMs");
232
+ if (config.stepTimeoutMs <= 0 || config.maxConcurrentSessions <= 0 || config.leaseMs <= 0) throw new Error("backgroundSessions durations and concurrency must be positive");
233
+ if (config.retryBackoffMs <= 0 || config.sessionLifetimeMs <= 0 || config.maxConsecutiveFailures <= 0) throw new Error("backgroundSessions retry and lifetime limits must be positive");
227
234
  }
228
235
  function validateRelativeProjectPath(value, owner) {
229
236
  if (value.trim() === "" || isAbsolute(value) || value.includes("\0")) throw new Error(`${owner} must be a non-empty relative path`);
@@ -433,6 +440,7 @@ function createFeishuCardRollover(options) {
433
440
  const leaseMs = options.leaseMs ?? 51e4;
434
441
  if (!Number.isSafeInteger(leaseMs) || leaseMs < 1) throw new Error("Feishu card stream lease must be a positive integer");
435
442
  const counters = createCounters();
443
+ const latestTextByRun = /* @__PURE__ */ new Map();
436
444
  const liveRuns = /* @__PURE__ */ new Map();
437
445
  const semaphore = Effect.unsafeMakeSemaphore(1);
438
446
  const exclusive = (effect) => semaphore.withPermits(1)(effect);
@@ -448,7 +456,7 @@ function createFeishuCardRollover(options) {
448
456
  const presentationId = (runId, generation) => `${runId}#${generation}`;
449
457
  const publishProgress = (action) => Effect.suspend(() => {
450
458
  const chain = options.store.chain(action.runId);
451
- if (chain && acceptsCardPresentationProgress(chain)) return options.publisher.publish(action);
459
+ if (chain && acceptsCardPresentationProgress(chain)) return options.publisher.publish(action).pipe(Effect.tap(() => Effect.sync(() => latestTextByRun.set(action.runId, action.text))));
452
460
  return recordNow({
453
461
  ...chain ? {
454
462
  generation: chain.activeGeneration,
@@ -458,20 +466,28 @@ function createFeishuCardRollover(options) {
458
466
  type: "stale_update_dropped"
459
467
  });
460
468
  });
461
- const publishTerminal = (action) => options.publisher.publish(action).pipe(Effect.tapError((error) => recordNow({
462
- error,
463
- runId: action.runId,
464
- type: "terminal_delivery_failed"
465
- })), Effect.tap(() => options.store.markTerminal({
466
- runId: action.runId,
467
- terminalReceiptId: `${action.runId}:${action.type}`
468
- }).pipe(Effect.catchAll((error) => recordNow({
469
- error,
470
- runId: action.runId,
471
- type: "presentation_write_failed"
472
- })))), Effect.ensuring(Effect.sync(() => {
473
- liveRuns.delete(action.runId);
474
- })));
469
+ const publishTerminal = (action) => {
470
+ const latestText = latestTextByRun.get(action.runId);
471
+ const resolvedAction = action.type === "cancel" && action.text === void 0 && latestText !== void 0 ? {
472
+ ...action,
473
+ text: latestText
474
+ } : action;
475
+ return options.publisher.publish(resolvedAction).pipe(Effect.tapError((error) => recordNow({
476
+ error,
477
+ runId: action.runId,
478
+ type: "terminal_delivery_failed"
479
+ })), Effect.tap(() => options.store.markTerminal({
480
+ runId: action.runId,
481
+ terminalReceiptId: `${action.runId}:${action.type}`
482
+ }).pipe(Effect.catchAll((error) => recordNow({
483
+ error,
484
+ runId: action.runId,
485
+ type: "presentation_write_failed"
486
+ })))), Effect.ensuring(Effect.sync(() => {
487
+ latestTextByRun.delete(action.runId);
488
+ liveRuns.delete(action.runId);
489
+ })));
490
+ };
475
491
  const publishAction = (action) => {
476
492
  switch (action.type) {
477
493
  case "update_text": return publishProgress(action);
@@ -505,6 +521,7 @@ function createFeishuCardRollover(options) {
505
521
  };
506
522
  const predecessor = start.presentation;
507
523
  const generation = predecessor.generation + 1;
524
+ const text = latestTextByRun.get(runId);
508
525
  record({
509
526
  cardId: predecessor.cardId,
510
527
  generation,
@@ -517,7 +534,8 @@ function createFeishuCardRollover(options) {
517
534
  const created = yield* options.createSuccessor({
518
535
  generation,
519
536
  presentationId: successorId,
520
- run
537
+ run,
538
+ ...text === void 0 ? {} : { text }
521
539
  }).pipe(Effect.map((target) => ({ target })), Effect.catchAll((error) => options.store.failHandoff({
522
540
  failedAt: startedAt.toISOString(),
523
541
  runId
@@ -539,6 +557,7 @@ function createFeishuCardRollover(options) {
539
557
  };
540
558
  yield* options.publisher.publish({
541
559
  runId,
560
+ ...text === void 0 ? {} : { text },
542
561
  type: "handoff"
543
562
  }).pipe(Effect.catchAll((error) => recordNow({
544
563
  cardId: predecessor.cardId,
@@ -584,6 +603,7 @@ function createFeishuCardRollover(options) {
584
603
  runId: run.runId,
585
604
  sourceMessageId: run.messageId
586
605
  });
606
+ latestTextByRun.delete(run.runId);
587
607
  liveRuns.set(run.runId, run);
588
608
  return presentation;
589
609
  })),
@@ -605,6 +625,7 @@ function createFeishuCardRollover(options) {
605
625
  },
606
626
  publish: (action) => exclusive(publishAction(action)),
607
627
  releaseRun: (runId) => Effect.sync(() => {
628
+ latestTextByRun.delete(runId);
608
629
  liveRuns.delete(runId);
609
630
  }),
610
631
  recover: () => exclusive(Effect.gen(function* () {
@@ -642,6 +663,19 @@ function createCounters() {
642
663
  };
643
664
  }
644
665
  //#endregion
666
+ //#region src/application/background-session/background-session-config.ts
667
+ const DEFAULT_BACKGROUND_SESSION_STEP_TIMEOUT_MS = 300 * 1e3;
668
+ const DEFAULT_BACKGROUND_SESSION_MAX_CONCURRENT_SESSIONS = 4;
669
+ const DEFAULT_BACKGROUND_SESSION_LEASE_MS = 3e4;
670
+ const DEFAULT_BACKGROUND_SESSION_LEASE_RENEWAL_INTERVAL_MS = 1e4;
671
+ const DEFAULT_BACKGROUND_SESSION_MAX_CONSECUTIVE_FAILURES = 3;
672
+ const DEFAULT_BACKGROUND_SESSION_RETRY_BACKOFF_MS = 3e4;
673
+ const DEFAULT_BACKGROUND_SESSION_LIFETIME_MS = 1440 * 60 * 1e3;
674
+ const DEFAULT_BACKGROUND_SESSION_SUPERVISOR_INTERVAL_MS = 1e3;
675
+ function resolveBackgroundSessionSupervisorIntervalMs(leaseMs) {
676
+ return Math.min(5e3, Math.max(200, Math.floor(leaseMs / 10)));
677
+ }
678
+ //#endregion
645
679
  //#region src/infrastructure/config/rivus-deployment-manifest.ts
646
680
  var RivusDeploymentManifestError = class extends Error {
647
681
  manifestPath;
@@ -670,12 +704,17 @@ function parseManifest(value) {
670
704
  exactKeys(root, [
671
705
  "agents",
672
706
  "automations",
707
+ "backgroundSessions",
673
708
  "defaultAgentId",
674
709
  "defaultEndpointId",
675
710
  "endpoints",
676
711
  "plugins",
677
712
  "projectSpaces"
678
- ], "manifest", ["automations", "projectSpaces"]);
713
+ ], "manifest", [
714
+ "automations",
715
+ "backgroundSessions",
716
+ "projectSpaces"
717
+ ]);
679
718
  const plugins = array(root.plugins, "manifest.plugins").map((entry, index) => {
680
719
  const plugin = record(entry, `manifest.plugins[${index}]`);
681
720
  exactKeys(plugin, [
@@ -802,9 +841,11 @@ function parseManifest(value) {
802
841
  workingDirectory: string(projectSpace.workingDirectory, `manifest.projectSpaces[${index}].workingDirectory`)
803
842
  });
804
843
  });
844
+ const backgroundSessions = root.backgroundSessions === void 0 ? void 0 : parseBackgroundSessions(record(root.backgroundSessions, "manifest.backgroundSessions"));
805
845
  return Object.freeze({
806
846
  agents: Object.freeze(agents),
807
847
  automations: Object.freeze(automations),
848
+ ...backgroundSessions ? { backgroundSessions } : {},
808
849
  defaultAgentId: string(root.defaultAgentId, "manifest.defaultAgentId"),
809
850
  defaultEndpointId: string(root.defaultEndpointId, "manifest.defaultEndpointId"),
810
851
  endpoints: Object.freeze(endpoints),
@@ -812,6 +853,38 @@ function parseManifest(value) {
812
853
  projectSpaces: Object.freeze(projectSpaces)
813
854
  });
814
855
  }
856
+ function parseBackgroundSessions(value) {
857
+ exactKeys(value, [
858
+ "enabled",
859
+ "leaseMs",
860
+ "leaseRenewalIntervalMs",
861
+ "maxConsecutiveFailures",
862
+ "maxConcurrentSessions",
863
+ "required",
864
+ "retryBackoffMs",
865
+ "sessionLifetimeMs",
866
+ "stepTimeoutMs"
867
+ ], "manifest.backgroundSessions", [
868
+ "leaseMs",
869
+ "leaseRenewalIntervalMs",
870
+ "maxConsecutiveFailures",
871
+ "maxConcurrentSessions",
872
+ "retryBackoffMs",
873
+ "sessionLifetimeMs",
874
+ "stepTimeoutMs"
875
+ ]);
876
+ return Object.freeze({
877
+ enabled: boolean(value.enabled, "manifest.backgroundSessions.enabled"),
878
+ required: boolean(value.required, "manifest.backgroundSessions.required"),
879
+ stepTimeoutMs: positiveInteger(value.stepTimeoutMs ?? 3e5, "manifest.backgroundSessions.stepTimeoutMs"),
880
+ maxConcurrentSessions: positiveInteger(value.maxConcurrentSessions ?? 4, "manifest.backgroundSessions.maxConcurrentSessions"),
881
+ leaseMs: positiveInteger(value.leaseMs ?? 3e4, "manifest.backgroundSessions.leaseMs"),
882
+ leaseRenewalIntervalMs: positiveInteger(value.leaseRenewalIntervalMs ?? 1e4, "manifest.backgroundSessions.leaseRenewalIntervalMs"),
883
+ maxConsecutiveFailures: positiveInteger(value.maxConsecutiveFailures ?? 3, "manifest.backgroundSessions.maxConsecutiveFailures"),
884
+ retryBackoffMs: positiveInteger(value.retryBackoffMs ?? 3e4, "manifest.backgroundSessions.retryBackoffMs"),
885
+ sessionLifetimeMs: positiveInteger(value.sessionLifetimeMs ?? 864e5, "manifest.backgroundSessions.sessionLifetimeMs")
886
+ });
887
+ }
815
888
  function record(value, path) {
816
889
  if (value === null || typeof value !== "object" || Array.isArray(value)) throw new Error(`${path} must be an object`);
817
890
  return value;
@@ -1178,7 +1251,7 @@ function createAgentInstanceRegistry(options = {}) {
1178
1251
  skillGrantRevision: definition.skillGrantSet.revision,
1179
1252
  toolGrantRevision: definition.toolGrantSet.revision
1180
1253
  });
1181
- const bindingId = binding.kind === "endpoint" ? binding.endpointId : binding.automationId;
1254
+ const bindingId = binding.kind === "endpoint" ? binding.endpointId : binding.kind === "automation" ? binding.automationId : binding.agentId;
1182
1255
  const bindingKey = `${binding.kind}:${bindingId}:${definition.agentId}`;
1183
1256
  const existing = records.get(bindingKey);
1184
1257
  if (existing) {
@@ -1203,6 +1276,10 @@ function createAgentInstanceRegistry(options = {}) {
1203
1276
  automationId,
1204
1277
  kind: "automation"
1205
1278
  }, definition),
1279
+ resolveBackgroundSession: (agentId, definition) => resolveBinding({
1280
+ agentId,
1281
+ kind: "background-session"
1282
+ }, definition),
1206
1283
  resolveEndpoint: (endpointId, definition) => resolveBinding({
1207
1284
  endpointId,
1208
1285
  kind: "endpoint"
@@ -1282,6 +1359,7 @@ function createRivusAgentHost(options) {
1282
1359
  const definitions = new Map(options.definitions.map((definition) => [definition.agentId, definition]));
1283
1360
  const endpoints = /* @__PURE__ */ new Map();
1284
1361
  const automations = /* @__PURE__ */ new Map();
1362
+ const backgroundSessions = /* @__PURE__ */ new Map();
1285
1363
  for (const endpoint of options.endpoints) {
1286
1364
  if (endpoints.has(endpoint.id)) throw new InvalidRivusEndpointBinding(`duplicate endpoint: ${endpoint.id}`);
1287
1365
  const definition = definitions.get(endpoint.agentId);
@@ -1294,6 +1372,11 @@ function createRivusAgentHost(options) {
1294
1372
  if (!definitions.has(automation.definition.agentId)) throw new InvalidRivusEndpointBinding(`unknown automation agent: ${automation.definition.agentId}`);
1295
1373
  automations.set(automation.id, options.runtimePool.registry.resolveAutomation(automation.id, automation.definition));
1296
1374
  }
1375
+ for (const backgroundSession of options.backgroundSessions ?? []) {
1376
+ if (backgroundSessions.has(backgroundSession.agentId)) throw new InvalidRivusEndpointBinding(`duplicate background session agent: ${backgroundSession.agentId}`);
1377
+ if (!definitions.has(backgroundSession.agentId)) throw new InvalidRivusEndpointBinding(`unknown background session agent: ${backgroundSession.agentId}`);
1378
+ backgroundSessions.set(backgroundSession.agentId, options.runtimePool.registry.resolveBackgroundSession(backgroundSession.agentId, backgroundSession.definition));
1379
+ }
1297
1380
  const resolveEndpoint = (endpointId) => {
1298
1381
  const instance = endpoints.get(endpointId);
1299
1382
  if (!instance) throw new InvalidRivusEndpointBinding(`unknown endpoint: ${endpointId}`);
@@ -1304,11 +1387,19 @@ function createRivusAgentHost(options) {
1304
1387
  if (!instance) throw new InvalidRivusEndpointBinding(`unknown automation: ${automationId}`);
1305
1388
  return instance;
1306
1389
  };
1390
+ const resolveBackgroundSession = (agentId) => {
1391
+ const instance = backgroundSessions.get(agentId);
1392
+ if (!instance) throw new InvalidRivusEndpointBinding(`unknown background session agent: ${agentId}`);
1393
+ return instance;
1394
+ };
1307
1395
  return {
1396
+ cancelBackgroundSession: (agentId, input) => options.runtimePool.cancel(resolveBackgroundSession(agentId), input),
1308
1397
  cancelEndpoint: (endpointId, input) => options.runtimePool.cancel(resolveEndpoint(endpointId), input),
1309
1398
  handleAutomation: (automationId, input) => options.runtimePool.run(resolveAutomation(automationId), input),
1399
+ handleBackgroundSession: (agentId, input) => options.runtimePool.run(resolveBackgroundSession(agentId), input),
1310
1400
  handleEndpoint: (endpointId, input) => options.runtimePool.run(resolveEndpoint(endpointId), input),
1311
1401
  resolveAutomation,
1402
+ resolveBackgroundSession,
1312
1403
  resolveEndpoint
1313
1404
  };
1314
1405
  }
@@ -1345,9 +1436,15 @@ async function createRivusDeploymentDaemon(options) {
1345
1436
  })));
1346
1437
  const definitions = new Map(deployment.definitions.map((definition) => [definition.agentId, definition]));
1347
1438
  const automationDefinitions = new Map(deployment.automationDefinitions.map((definition) => [definition.id, definition]));
1439
+ const backgroundSessionsConfig = deployment.manifest.backgroundSessions;
1440
+ const backgroundDefinitions = /* @__PURE__ */ new Map();
1441
+ if (backgroundSessionsConfig?.enabled) for (const agent of deployment.agents) {
1442
+ if (agent.status !== "enabled" || !agent.definition) continue;
1443
+ backgroundDefinitions.set(agent.agentId, narrowBackgroundSessionDefinition(agent.definition));
1444
+ }
1348
1445
  const runtimePool = createAgentRuntimePool({
1349
1446
  createRuntime: (instance) => {
1350
- const definition = instance.binding.kind === "automation" ? automationDefinitions.get(instance.binding.automationId)?.runtimeDefinition : definitions.get(instance.agentId);
1447
+ const definition = instance.binding.kind === "automation" ? automationDefinitions.get(instance.binding.automationId)?.runtimeDefinition : instance.binding.kind === "background-session" ? backgroundDefinitions.get(instance.agentId) : definitions.get(instance.agentId);
1351
1448
  if (!definition) throw new RivusDeploymentDaemonLifecycleError(`runtime instance references unknown agent: ${instance.agentId}`);
1352
1449
  const projectSpace = definition.projectSpaceId ? projectSpaces.get(definition.projectSpaceId) : void 0;
1353
1450
  return options.createRuntime({
@@ -1378,11 +1475,20 @@ async function createRivusDeploymentDaemon(options) {
1378
1475
  lifecycle: definition.enabled && agentEnabled ? "stopped" : "disabled"
1379
1476
  };
1380
1477
  });
1478
+ const backgroundSessionSlot = backgroundSessionsConfig ? {
1479
+ agentEnabled: backgroundDefinitions.size > 0,
1480
+ definition: backgroundSessionsConfig,
1481
+ lifecycle: backgroundSessionsConfig.enabled && backgroundDefinitions.size > 0 ? "stopped" : "disabled"
1482
+ } : void 0;
1381
1483
  const host = createRivusAgentHost({
1382
1484
  automations: automationSlots.filter((slot) => slot.definition.enabled && slot.agentEnabled && slot.resolvedDefinition !== void 0).map((slot) => ({
1383
1485
  definition: slot.resolvedDefinition.runtimeDefinition,
1384
1486
  id: slot.definition.id
1385
1487
  })),
1488
+ ...backgroundSessionSlot ? { backgroundSessions: [...backgroundDefinitions].map(([agentId, definition]) => ({
1489
+ agentId,
1490
+ definition
1491
+ })) } : {},
1386
1492
  definitions: deployment.definitions,
1387
1493
  endpoints: slots.filter((slot) => slot.definition.enabled && slot.agentEnabled).map((slot) => ({
1388
1494
  agentId: slot.definition.agentId,
@@ -1410,7 +1516,15 @@ async function createRivusDeploymentDaemon(options) {
1410
1516
  agentId: slot.definition.agentId,
1411
1517
  automationId: slot.definition.id
1412
1518
  });
1413
- const allSlots = [...slots, ...automationSlots];
1519
+ const backgroundSessionStatus = (slot) => Object.freeze({
1520
+ ...componentStatus(slot),
1521
+ ...slot.adapter?.status ? { supervisor: slot.adapter.status() } : {}
1522
+ });
1523
+ const allSlots = [
1524
+ ...slots,
1525
+ ...automationSlots,
1526
+ ...backgroundSessionSlot ? [backgroundSessionSlot] : []
1527
+ ];
1414
1528
  const isReady = () => allSlots.every(isSlotReady);
1415
1529
  const failedRequiredEndpointIds = () => slots.filter((slot) => slot.definition.enabled && slot.definition.required && slot.lifecycle !== "running").map((slot) => slot.definition.id);
1416
1530
  const failedRequiredAutomationIds = () => automationSlots.filter((slot) => slot.definition.enabled && slot.definition.required && slot.lifecycle !== "running").map((slot) => slot.definition.id);
@@ -1423,6 +1537,7 @@ async function createRivusDeploymentDaemon(options) {
1423
1537
  const status = () => Object.freeze({
1424
1538
  agents: deployment.agents,
1425
1539
  automations: Object.freeze(automationSlots.map(automationStatus)),
1540
+ ...backgroundSessionSlot ? { backgroundSessions: backgroundSessionStatus(backgroundSessionSlot) } : {},
1426
1541
  defaultAgentId: deployment.manifest.defaultAgentId,
1427
1542
  defaultEndpointId: deployment.manifest.defaultEndpointId,
1428
1543
  endpoints: Object.freeze(slots.map(endpointStatus)),
@@ -1487,6 +1602,18 @@ async function createRivusDeploymentDaemon(options) {
1487
1602
  });
1488
1603
  degraded ||= slotDegraded;
1489
1604
  }
1605
+ if (backgroundSessionSlot) {
1606
+ const slotDegraded = await startSlot(backgroundSessionSlot, true, async () => {
1607
+ if (!options.createBackgroundSession) throw new RivusDeploymentDaemonLifecycleError("deployment bootstrap does not provide Background Session adapters");
1608
+ return options.createBackgroundSession({
1609
+ agentIds: [...backgroundDefinitions.keys()],
1610
+ cancel: (input) => host.cancelBackgroundSession(input.agentId, input),
1611
+ config: backgroundSessionSlot.definition,
1612
+ run: (input) => host.handleBackgroundSession(input.agentId, input)
1613
+ });
1614
+ });
1615
+ degraded ||= slotDegraded;
1616
+ }
1490
1617
  lifecycle = degraded ? "degraded" : "running";
1491
1618
  assertRequiredReadiness();
1492
1619
  },
@@ -1500,6 +1627,7 @@ async function createRivusDeploymentDaemon(options) {
1500
1627
  lifecycle = "stopping";
1501
1628
  const errors = [];
1502
1629
  await stopSlots(automationSlots, errors);
1630
+ if (backgroundSessionSlot) await stopSlots([backgroundSessionSlot], errors);
1503
1631
  await stopSlots(slots, errors);
1504
1632
  try {
1505
1633
  await runtimePool.disposeAll();
@@ -1640,6 +1768,7 @@ async function createConfiguredRivusDeploymentDaemon(options) {
1640
1768
  const manifest = await loadRivusDeploymentManifest(options.manifestPath, options.manifestOptions);
1641
1769
  return createRivusDeploymentDaemon({
1642
1770
  ...options.createAutomation ? { createAutomation: options.createAutomation } : {},
1771
+ ...options.createBackgroundSession ? { createBackgroundSession: options.createBackgroundSession } : {},
1643
1772
  createEndpoint: options.createEndpoint,
1644
1773
  createRuntime: options.createRuntime,
1645
1774
  deploymentRoot: dirname(options.manifestPath),
@@ -2954,6 +3083,17 @@ function toRedactedDeploymentManifest(manifest) {
2954
3083
  templateId,
2955
3084
  timeZone
2956
3085
  })),
3086
+ ...manifest.backgroundSessions ? { backgroundSessions: {
3087
+ enabled: manifest.backgroundSessions.enabled,
3088
+ leaseMs: manifest.backgroundSessions.leaseMs,
3089
+ leaseRenewalIntervalMs: manifest.backgroundSessions.leaseRenewalIntervalMs,
3090
+ maxConsecutiveFailures: manifest.backgroundSessions.maxConsecutiveFailures,
3091
+ maxConcurrentSessions: manifest.backgroundSessions.maxConcurrentSessions,
3092
+ required: manifest.backgroundSessions.required,
3093
+ retryBackoffMs: manifest.backgroundSessions.retryBackoffMs,
3094
+ sessionLifetimeMs: manifest.backgroundSessions.sessionLifetimeMs,
3095
+ stepTimeoutMs: manifest.backgroundSessions.stepTimeoutMs
3096
+ } } : {},
2957
3097
  defaultAgentId: manifest.defaultAgentId,
2958
3098
  defaultEndpointId: manifest.defaultEndpointId,
2959
3099
  endpoints: manifest.endpoints.map(({ agentId, credentialRef, enabled, id, required, sessionNamespace }) => ({
@@ -3095,4 +3235,4 @@ function hasRecoveryRunner(daemon) {
3095
3235
  return typeof daemon.openRecoveryControl === "function";
3096
3236
  }
3097
3237
  //#endregion
3098
- export { CardPresentationTransitionDenied as A, FeishuEndpointCredentialError as B, loadRivusDaemonConfig as C, loadRivusDeploymentManifest as D, RivusDeploymentManifestError as E, completeCardPresentationHandoff as F, validateRivusDeploymentManifest as G, loadMergedLocalEnvFile as H, createCardPresentationChain as I, failCardPresentationHandoff as L, activeCardPresentation as M, beginCardPresentationHandoff as N, DEFAULT_CARD_STREAM_LEASE_MS as O, compensateCardPresentationHandoff as P, isCardPresentationHandoffDue as R, RivusDaemonConfigError as S, resolveNodeRivusPluginModulePath as T, RivusPluginLoadError as U, resolveFeishuEndpointCredentials as V, loadRivusDeployment as W, createStableId as _, InvalidRivusProjectSpace as a, createRivusEnvFromOpenClawConfig as b, RivusDeploymentReadinessError as c, createRivusAgentHost as d, AgentInstanceBusy as f, createAgentInstanceRegistry as g, AgentInstanceConflict as h, resolveRivusProjectSpace as i, acceptsCardPresentationProgress as j, createFeishuCardRollover as k, createRivusDeploymentDaemon as l, createAgentRuntimePool as m, createRivusDeploymentCliProcess as n, RivusDeploymentAutomationReadinessError as o, AgentRuntimeDisposed as p, createConfiguredRivusDeploymentDaemon as r, RivusDeploymentDaemonLifecycleError as s, runRivusDaemonCli as t, InvalidRivusEndpointBinding as u, createRivusDaemonShutdownController as v, loadNodeRivusPluginModule as w, formatRivusEnvFile as x, OpenClawEnvImportError as y, markCardPresentationTerminal as z };
3238
+ export { loadRivusDeployment as $, DEFAULT_BACKGROUND_SESSION_LIFETIME_MS as A, acceptsCardPresentationProgress as B, loadRivusDaemonConfig as C, loadRivusDeploymentManifest as D, RivusDeploymentManifestError as E, DEFAULT_BACKGROUND_SESSION_SUPERVISOR_INTERVAL_MS as F, createCardPresentationChain as G, beginCardPresentationHandoff as H, resolveBackgroundSessionSupervisorIntervalMs as I, markCardPresentationTerminal as J, failCardPresentationHandoff as K, DEFAULT_CARD_STREAM_LEASE_MS as L, DEFAULT_BACKGROUND_SESSION_MAX_CONSECUTIVE_FAILURES as M, DEFAULT_BACKGROUND_SESSION_RETRY_BACKOFF_MS as N, DEFAULT_BACKGROUND_SESSION_LEASE_MS as O, DEFAULT_BACKGROUND_SESSION_STEP_TIMEOUT_MS as P, RivusPluginLoadError as Q, createFeishuCardRollover as R, RivusDaemonConfigError as S, resolveNodeRivusPluginModulePath as T, compensateCardPresentationHandoff as U, activeCardPresentation as V, completeCardPresentationHandoff as W, resolveFeishuEndpointCredentials as X, FeishuEndpointCredentialError as Y, loadMergedLocalEnvFile as Z, createStableId as _, InvalidRivusProjectSpace as a, createRivusEnvFromOpenClawConfig as b, RivusDeploymentReadinessError as c, createRivusAgentHost as d, validateRivusDeploymentManifest as et, AgentInstanceBusy as f, createAgentInstanceRegistry as g, AgentInstanceConflict as h, resolveRivusProjectSpace as i, DEFAULT_BACKGROUND_SESSION_MAX_CONCURRENT_SESSIONS as j, DEFAULT_BACKGROUND_SESSION_LEASE_RENEWAL_INTERVAL_MS as k, createRivusDeploymentDaemon as l, createAgentRuntimePool as m, createRivusDeploymentCliProcess as n, RivusDeploymentAutomationReadinessError as o, AgentRuntimeDisposed as p, isCardPresentationHandoffDue as q, createConfiguredRivusDeploymentDaemon as r, RivusDeploymentDaemonLifecycleError as s, runRivusDaemonCli as t, InvalidRivusEndpointBinding as u, createRivusDaemonShutdownController as v, loadNodeRivusPluginModule as w, formatRivusEnvFile as x, OpenClawEnvImportError as y, CardPresentationTransitionDenied as z };