@moxt-ai/mobius 0.0.54 → 0.0.56

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.
@@ -1,7 +1,7 @@
1
1
  import { type RuntimeHeartbeatAckEvent } from "@moxt-ai/mobius-protocol";
2
2
  import type { DaemonTimer } from "./timer.ts";
3
3
  export interface RelayLivenessTransport {
4
- readonly send: (message: string) => void;
4
+ readonly send: (message: string) => boolean;
5
5
  readonly unresponsive: (heartbeatId: string, timeoutMilliseconds: number) => void;
6
6
  }
7
7
  export declare class RelayConnectionLiveness {
@@ -1 +1 @@
1
- {"version":3,"file":"liveness.d.ts","sourceRoot":"","sources":["../../src/relay-connection/liveness.ts"],"names":[],"mappings":"AAEA,OAAO,EAGH,KAAK,wBAAwB,EAChC,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAuB,WAAW,EAAE,MAAM,YAAY,CAAC;AA+BnE,MAAM,WAAW,sBAAsB;IACnC,QAAQ,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,QAAQ,CAAC,YAAY,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,KAAK,IAAI,CAAC;CACrF;AAED,qBAAa,uBAAuB;;IAKhC,YAAY,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,sBAAsB,EAGhE;IAED,QAAQ,CAAC,WAAW,UAAW,wBAAwB,KAAG,IAAI,CAW5D;IAEF,QAAQ,CAAC,KAAK,QAAO,IAAI,CAYvB;IAEF,QAAQ,CAAC,KAAK,QAAO,IAAI,CAYvB;CAoCL"}
1
+ {"version":3,"file":"liveness.d.ts","sourceRoot":"","sources":["../../src/relay-connection/liveness.ts"],"names":[],"mappings":"AAEA,OAAO,EAGH,KAAK,wBAAwB,EAChC,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAuB,WAAW,EAAE,MAAM,YAAY,CAAC;AA+BnE,MAAM,WAAW,sBAAsB;IACnC,QAAQ,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;IAC5C,QAAQ,CAAC,YAAY,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,KAAK,IAAI,CAAC;CACrF;AAED,qBAAa,uBAAuB;;IAKhC,YAAY,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,sBAAsB,EAGhE;IAED,QAAQ,CAAC,WAAW,UAAW,wBAAwB,KAAG,IAAI,CAW5D;IAEF,QAAQ,CAAC,KAAK,QAAO,IAAI,CAYvB;IAEF,QAAQ,CAAC,KAAK,QAAO,IAAI,CAYvB;CAwCL"}
@@ -92,10 +92,14 @@ export class RelayConnectionLiveness {
92
92
  }
93
93
  const heartbeatId = randomUUID();
94
94
  this.#state = new AwaitingHeartbeatAckState(heartbeatId, this.#timer.schedule(this.#handleTimeout, HEARTBEAT_ACK_TIMEOUT_MILLISECONDS));
95
- this.#transport.send(encodeRuntimeHeartbeatEvent({
95
+ const sent = this.#transport.send(encodeRuntimeHeartbeatEvent({
96
96
  heartbeatId,
97
97
  kind: RUNTIME_HEARTBEAT_KIND,
98
98
  }));
99
+ if (!sent && this.#state instanceof AwaitingHeartbeatAckState && this.#state.heartbeatId === heartbeatId) {
100
+ this.#state.timeout.cancel();
101
+ this.#state = new FinishedRelayLivenessState();
102
+ }
99
103
  };
100
104
  }
101
105
  //# sourceMappingURL=liveness.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"liveness.js","sourceRoot":"","sources":["../../src/relay-connection/liveness.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EACH,2BAA2B,EAC3B,sBAAsB,GAEzB,MAAM,0BAA0B,CAAC;AAIlC,MAAM,kCAAkC,GAAG,MAAM,CAAC;AAClD,MAAM,+BAA+B,GAAG,MAAM,CAAC;AAE/C,MAAe,kBAAkB;CAAG;AA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AAI,CAAC,MAAM,GAAG,IAAI,0BAA0B,EAAE,CAAC;QACnD,CAAC;IACL,CAAC,CAAC;CACL"}
@@ -1,5 +1,8 @@
1
1
  import type { AuditStore } from "./audit/audit-store.ts";
2
- import type { DaemonConfig } from "./config.ts";
2
+ import { type DaemonConfig } from "./config.ts";
3
3
  import { type DaemonTimer } from "./relay-connection/timer.ts";
4
- export declare function runDaemon(config: DaemonConfig, audit: AuditStore, signal: AbortSignal, timer?: DaemonTimer): Promise<void>;
4
+ export interface RunDaemonOptions {
5
+ readonly resolveAgentCatalogEnvironment?: (signal: AbortSignal) => Promise<Readonly<NodeJS.ProcessEnv>>;
6
+ }
7
+ export declare function runDaemon(config: DaemonConfig, audit: AuditStore, signal: AbortSignal, timer?: DaemonTimer, options?: RunDaemonOptions): Promise<void>;
5
8
  //# sourceMappingURL=run-daemon.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"run-daemon.d.ts","sourceRoot":"","sources":["../src/run-daemon.ts"],"names":[],"mappings":"AAgJA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAIzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAYhD,OAAO,EAA4B,KAAK,WAAW,EAAqB,MAAM,6BAA6B,CAAC;AA8gF5G,wBAAsB,SAAS,CAC3B,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,WAAW,EACnB,KAAK,GAAE,WAA+B,GACvC,OAAO,CAAC,IAAI,CAAC,CAuJf"}
1
+ {"version":3,"file":"run-daemon.d.ts","sourceRoot":"","sources":["../src/run-daemon.ts"],"names":[],"mappings":"AA0JA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAIzD,OAAO,EAAE,KAAK,YAAY,EAAyB,MAAM,aAAa,CAAC;AAYvE,OAAO,EAA4B,KAAK,WAAW,EAAqB,MAAM,6BAA6B,CAAC;AA8nD5G,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,CAAC,8BAA8B,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;CAC3G;AAkhCD,wBAAsB,SAAS,CAC3B,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,WAAW,EACnB,KAAK,GAAE,WAA+B,EACtC,OAAO,GAAE,gBAAqB,GAC/B,OAAO,CAAC,IAAI,CAAC,CA8Jf"}
@@ -1,12 +1,12 @@
1
1
  import { createHash, randomUUID } from "node:crypto";
2
2
  import { basename } from "node:path";
3
3
  import { styleText } from "node:util";
4
- import { AGENT_ACTIVITY_KIND, AGENT_INSTALL_CANCEL_KIND, AGENT_INSTALL_CANCELLED_KIND, AGENT_INSTALL_COMPLETED_KIND, AGENT_INSTALL_FAILED_KIND, AGENT_INSTALL_PROGRESS_KIND, AGENT_INSTALL_REQUEST_KIND, AGENT_INSTALL_STARTED_KIND, AGENT_MESSAGE_DELTA_KIND, AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE, AGENT_MODEL_EFFORT_RESOLUTION_ON_MODEL_SELECTION, AGENT_MODEL_EFFORT_RESOLUTION_UNAVAILABLE, AGENT_SETTINGS_DISCOVER_KIND, AGENT_SETTINGS_DISCOVERED_KIND, AGENT_SETTINGS_DISCOVERY_FAILED_KIND, decodeAgentInstallCancelCommand, decodeAgentInstallRequestCommand, decodeAgentSettingsDiscoverCommand, decodeFileReadCommand, decodeMessageKind, decodeNativeSessionCancel, decodeNativeSessionCommand, decodeNativeSessionTurnForkCommand, decodeRuntimeDelivery, decodeRuntimeDeliveryCommitted, decodeRuntimeHeartbeatAckEvent, decodeRuntimeLivenessReadyEvent, decodeSessionCancelCommand, decodeSessionConfigureCommand, decodeSessionElicitationRespondCommand, decodeSessionEventAcknowledgement, decodeSessionEventDeferred, decodeSessionEventEnvelope, decodeSessionEventRejection, decodeSessionPermissionRespondCommand, decodeSessionPrepareCommand, decodeSessionPromptCommand, decodeWorkspaceListCommand, encodeAgentActivityEvent, encodeAgentContentEvent, encodeAgentInstallCancelledEvent, encodeAgentInstallCompletedEvent, encodeAgentInstallFailedEvent, encodeAgentInstallProgressEvent, encodeAgentInstallStartedEvent, encodeAgentMessageDeltaEvent, encodeAgentSettingsDiscoveredEvent, encodeAgentSettingsDiscoveryFailedEvent, encodeFileFailedEvent, encodeNativeSessionResult, encodeRuntimeDeliveryReceived, encodeSessionCommandsUpdatedEvent, encodeSessionCompletedEvent, encodeSessionConfigUpdatedEvent, encodeSessionElicitationRequestedEvent, encodeSessionElicitationResolvedEvent, encodeSessionFailedEvent, encodeSessionInfoUpdatedEvent, encodeSessionOperationFailedEvent, encodeSessionPermissionRequestedEvent, encodeSessionPermissionResolvedEvent, encodeSessionReadyEvent, encodeSessionStartedEvent, encodeSessionUsageUpdatedEvent, encodeWorkspaceEntriesEvent, FILE_FAILED_KIND, FILE_READ_KIND, NATIVE_SESSION_CANCEL_KIND, NATIVE_SESSION_REQUEST_KIND, NATIVE_SESSION_TURN_FORK_KIND, RUNTIME_DELIVERY_COMMITTED_KIND, RUNTIME_DELIVERY_KIND, RUNTIME_DELIVERY_RECEIVED_KIND, RUNTIME_HEARTBEAT_ACK_KIND, RUNTIME_LIVENESS_READY_KIND, SESSION_CANCEL_KIND, SESSION_COMPLETED_KIND, SESSION_CONFIGURE_KIND, SESSION_ELICITATION_RESPOND_KIND, SESSION_EVENT_ACK_KIND, SESSION_EVENT_DEFERRED_KIND, SESSION_EVENT_REJECTED_KIND, SESSION_FAILED_KIND, SESSION_PERMISSION_RESPOND_KIND, SESSION_PREPARE_KIND, SESSION_PROMPT_KIND, SESSION_STARTED_KIND, SessionPromptDisposition, WORKSPACE_LIST_KIND, } from "@moxt-ai/mobius-protocol";
4
+ import { AGENT_ACTIVITY_KIND, AGENT_CATALOG_REFRESH_FAILED_KIND, AGENT_CATALOG_REFRESH_KIND, AGENT_CATALOG_REFRESHED_KIND, AGENT_INSTALL_CANCEL_KIND, AGENT_INSTALL_CANCELLED_KIND, AGENT_INSTALL_COMPLETED_KIND, AGENT_INSTALL_FAILED_KIND, AGENT_INSTALL_PROGRESS_KIND, AGENT_INSTALL_REQUEST_KIND, AGENT_INSTALL_STARTED_KIND, AGENT_MESSAGE_DELTA_KIND, AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE, AGENT_MODEL_EFFORT_RESOLUTION_ON_MODEL_SELECTION, AGENT_MODEL_EFFORT_RESOLUTION_UNAVAILABLE, AGENT_SETTINGS_DISCOVER_KIND, AGENT_SETTINGS_DISCOVERED_KIND, AGENT_SETTINGS_DISCOVERY_FAILED_KIND, decodeAgentCatalogRefreshCommand, decodeAgentInstallCancelCommand, decodeAgentInstallRequestCommand, decodeAgentSettingsDiscoverCommand, decodeFileReadCommand, decodeMessageKind, decodeNativeSessionCancel, decodeNativeSessionCommand, decodeNativeSessionTurnForkCommand, decodeRuntimeDelivery, decodeRuntimeDeliveryCommitted, decodeRuntimeHeartbeatAckEvent, decodeRuntimeLivenessReadyEvent, decodeSessionCancelCommand, decodeSessionConfigureCommand, decodeSessionElicitationRespondCommand, decodeSessionEventAcknowledgement, decodeSessionEventDeferred, decodeSessionEventEnvelope, decodeSessionEventRejection, decodeSessionPermissionRespondCommand, decodeSessionPrepareCommand, decodeSessionPromptCommand, decodeWorkspaceListCommand, encodeAgentActivityEvent, encodeAgentCatalogRefreshedEvent, encodeAgentCatalogRefreshFailedEvent, encodeAgentContentEvent, encodeAgentInstallCancelledEvent, encodeAgentInstallCompletedEvent, encodeAgentInstallFailedEvent, encodeAgentInstallProgressEvent, encodeAgentInstallStartedEvent, encodeAgentMessageDeltaEvent, encodeAgentSettingsDiscoveredEvent, encodeAgentSettingsDiscoveryFailedEvent, encodeFileFailedEvent, encodeNativeSessionResult, encodeRuntimeDeliveryReceived, encodeSessionCommandsUpdatedEvent, encodeSessionCompletedEvent, encodeSessionConfigUpdatedEvent, encodeSessionElicitationRequestedEvent, encodeSessionElicitationResolvedEvent, encodeSessionFailedEvent, encodeSessionInfoUpdatedEvent, encodeSessionOperationFailedEvent, encodeSessionPermissionRequestedEvent, encodeSessionPermissionResolvedEvent, encodeSessionReadyEvent, encodeSessionStartedEvent, encodeSessionUsageUpdatedEvent, encodeWorkspaceEntriesEvent, FILE_FAILED_KIND, FILE_READ_KIND, NATIVE_SESSION_CANCEL_KIND, NATIVE_SESSION_REQUEST_KIND, NATIVE_SESSION_TURN_FORK_KIND, RUNTIME_DELIVERY_COMMITTED_KIND, RUNTIME_DELIVERY_KIND, RUNTIME_DELIVERY_RECEIVED_KIND, RUNTIME_HEARTBEAT_ACK_KIND, RUNTIME_LIVENESS_READY_KIND, SESSION_CANCEL_KIND, SESSION_COMPLETED_KIND, SESSION_CONFIGURE_KIND, SESSION_ELICITATION_RESPOND_KIND, SESSION_EVENT_ACK_KIND, SESSION_EVENT_DEFERRED_KIND, SESSION_EVENT_REJECTED_KIND, SESSION_FAILED_KIND, SESSION_PERMISSION_RESPOND_KIND, SESSION_PREPARE_KIND, SESSION_PROMPT_KIND, SESSION_STARTED_KIND, SessionPromptDisposition, WORKSPACE_LIST_KIND, } from "@moxt-ai/mobius-protocol";
5
5
  import { fetch, WebSocket } from "undici";
6
6
  import { AcpExecutionError, AcpSessionManager } from "./acp/session-manager.js";
7
7
  import { SqliteAcpSessionStore } from "./acp/session-store.js";
8
8
  import { agentSettingsAdapterForAgent, applyAgentLaunchSettings } from "./agent-catalog/agent-settings-adapter.js";
9
- import { supportedLocalAgentSpecifications } from "./agent-catalog/discover-local-agents.js";
9
+ import { discoverLocalAgentInventory, supportedLocalAgentSpecifications, } from "./agent-catalog/discover-local-agents.js";
10
10
  import { AgentIntegrationDefinition, LocalAgentCatalogError, } from "./agent-catalog/local-agent.js";
11
11
  import { publishAgentCatalog } from "./agent-catalog/publish-agent-catalog.js";
12
12
  import { AgentInstallationManager, CancelledInstallation, FailedInstallation, RequestedInstallation, RunningInstallation, SucceededInstallation, } from "./agent-installation/agent-installation-manager.js";
@@ -15,6 +15,7 @@ import { streamLocalFile } from "./artifacts/local-file-streamer.js";
15
15
  import { uploadRuntimeArtifact } from "./artifacts/runtime-artifact-uploader.js";
16
16
  import { LocalAuthorizationError } from "./authorization/local-authorization-error.js";
17
17
  import { WorkspaceDirectoryService } from "./authorization/workspace-directory.js";
18
+ import { withDaemonEnvironment } from "./config.js";
18
19
  import { AccumulatingOperationMetrics } from "./infra/operation-metrics.js";
19
20
  import { NativeSessionService } from "./native-sessions/service.js";
20
21
  import { environmentProxyDispatcher } from "./network/environment-proxy.js";
@@ -1216,7 +1217,26 @@ async function installDetectedAgentIntegrations(config, installations, signal) {
1216
1217
  }, signal);
1217
1218
  }
1218
1219
  }
1219
- async function runRelayConnection(config, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher, activeTurns, activeAttemptIds, connectionEpoch, diagnostics, onConnected, signal, timer) {
1220
+ async function refreshAgentCatalog(config, resolveEnvironment, signal) {
1221
+ signal.throwIfAborted();
1222
+ const environment = await resolveEnvironment(signal);
1223
+ signal.throwIfAborted();
1224
+ const inventory = await discoverLocalAgentInventory({
1225
+ defaultWorkspace: config.defaultWorkspace,
1226
+ environment,
1227
+ signal,
1228
+ });
1229
+ const previousCatalog = config.catalog.read();
1230
+ config.catalog.transition(inventory.readyAgents().map((agent) => withDaemonEnvironment(agent, environment)), inventory.installable);
1231
+ try {
1232
+ await publishAgentCatalog(config, signal);
1233
+ }
1234
+ catch (error) {
1235
+ config.catalog.transition(previousCatalog.agents, previousCatalog.installableAgents);
1236
+ throw error;
1237
+ }
1238
+ }
1239
+ async function runRelayConnection(config, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher, activeTurns, activeAttemptIds, connectionEpoch, diagnostics, onConnected, signal, timer, resolveAgentCatalogEnvironment) {
1220
1240
  const relayUrl = new URL(config.relayUrl);
1221
1241
  relayUrl.searchParams.set("deliveryReceipts", "1");
1222
1242
  relayUrl.searchParams.set("liveness", "1");
@@ -1226,6 +1246,7 @@ async function runRelayConnection(config, directories, audit, sessions, installa
1226
1246
  const connectionController = new AbortController();
1227
1247
  const nativeRequests = new Map();
1228
1248
  const agentSettingsDiscoveries = new Map();
1249
+ const agentCatalogRefreshes = new Map();
1229
1250
  installationObserver.connect(socket);
1230
1251
  onConnected();
1231
1252
  try {
@@ -1446,7 +1467,21 @@ async function runRelayConnection(config, directories, audit, sessions, installa
1446
1467
  }
1447
1468
  };
1448
1469
  const connectionLiveness = new RelayConnectionLiveness(timer, {
1449
- send: (message) => send(socket, message),
1470
+ send: (message) => {
1471
+ if (socket.readyState !== WebSocket.OPEN) {
1472
+ return false;
1473
+ }
1474
+ try {
1475
+ send(socket, message);
1476
+ return true;
1477
+ }
1478
+ catch (error) {
1479
+ if (socket.readyState !== WebSocket.OPEN) {
1480
+ return false;
1481
+ }
1482
+ throw error;
1483
+ }
1484
+ },
1450
1485
  unresponsive: (heartbeatId, timeoutMilliseconds) => {
1451
1486
  diagnostics.heartbeatTimedOut(connectionEpoch, heartbeatId, timeoutMilliseconds);
1452
1487
  diagnostics.connectionClosed(connectionEpoch, 4001, "Relay liveness check timed out", "heartbeat_timeout");
@@ -1597,6 +1632,65 @@ async function runRelayConnection(config, directories, audit, sessions, installa
1597
1632
  });
1598
1633
  return;
1599
1634
  }
1635
+ if (kind === AGENT_CATALOG_REFRESH_KIND) {
1636
+ const command = decodeAgentCatalogRefreshCommand(encoded);
1637
+ if (agentCatalogRefreshes.has(command.requestId) || agentCatalogRefreshes.size > 0) {
1638
+ if (socket.readyState === WebSocket.OPEN) {
1639
+ send(socket, encodeAgentCatalogRefreshFailedEvent({
1640
+ code: "agent_catalog_refresh_busy",
1641
+ kind: AGENT_CATALOG_REFRESH_FAILED_KIND,
1642
+ message: "Another local Agent catalog refresh is already running",
1643
+ requestId: command.requestId,
1644
+ }));
1645
+ }
1646
+ return;
1647
+ }
1648
+ const controller = new AbortController();
1649
+ const operationSignal = AbortSignal.any([connectionController.signal, controller.signal]);
1650
+ const timeout = timer.schedule(() => controller.abort(new AcpExecutionError("The local Agent catalog refresh timed out", {}, "agent_catalog_refresh_timeout")), 90_000);
1651
+ const completion = (async () => {
1652
+ try {
1653
+ await refreshAgentCatalog(config, resolveAgentCatalogEnvironment, operationSignal);
1654
+ audit.record({
1655
+ commandId: command.requestId,
1656
+ event: "agent_catalog_refreshed",
1657
+ sessionId: "agent-catalog",
1658
+ });
1659
+ if (socket.readyState === WebSocket.OPEN) {
1660
+ send(socket, encodeAgentCatalogRefreshedEvent({
1661
+ kind: AGENT_CATALOG_REFRESHED_KIND,
1662
+ requestId: command.requestId,
1663
+ }));
1664
+ }
1665
+ }
1666
+ catch (error) {
1667
+ const failure = operationSignal.aborted
1668
+ ? (controller.signal.reason ??
1669
+ new AcpExecutionError("The local Agent catalog refresh was cancelled", {}, "agent_catalog_refresh_cancelled"))
1670
+ : error;
1671
+ audit.record({
1672
+ commandId: command.requestId,
1673
+ details: { code: operationErrorCode(failure) },
1674
+ event: "agent_catalog_refresh_failed",
1675
+ sessionId: "agent-catalog",
1676
+ });
1677
+ if (socket.readyState === WebSocket.OPEN) {
1678
+ send(socket, encodeAgentCatalogRefreshFailedEvent({
1679
+ code: operationErrorCode(failure),
1680
+ kind: AGENT_CATALOG_REFRESH_FAILED_KIND,
1681
+ message: operationErrorMessage(failure),
1682
+ requestId: command.requestId,
1683
+ }));
1684
+ }
1685
+ }
1686
+ finally {
1687
+ timeout.cancel();
1688
+ agentCatalogRefreshes.delete(command.requestId);
1689
+ }
1690
+ })();
1691
+ agentCatalogRefreshes.set(command.requestId, { completion, controller });
1692
+ return;
1693
+ }
1600
1694
  if (kind === NATIVE_SESSION_REQUEST_KIND) {
1601
1695
  const command = decodeNativeSessionCommand(encoded);
1602
1696
  const previous = [...nativeRequests.values()].filter((request) => request.agentId === command.agentId);
@@ -1889,10 +1983,11 @@ async function runRelayConnection(config, directories, audit, sessions, installa
1889
1983
  await Promise.all([
1890
1984
  ...[...nativeRequests.values()].map((request) => request.completion),
1891
1985
  ...[...agentSettingsDiscoveries.values()].map((request) => request.completion),
1986
+ ...[...agentCatalogRefreshes.values()].map((request) => request.completion),
1892
1987
  ]);
1893
1988
  }
1894
1989
  }
1895
- export async function runDaemon(config, audit, signal, timer = systemDaemonTimer) {
1990
+ export async function runDaemon(config, audit, signal, timer = systemDaemonTimer, options = {}) {
1896
1991
  const installationAudit = new AuditInstallationEvents(audit);
1897
1992
  const stateDirectory = config.localContext.stateDirectory;
1898
1993
  const specifications = supportedLocalAgentSpecifications();
@@ -1929,6 +2024,11 @@ export async function runDaemon(config, audit, signal, timer = systemDaemonTimer
1929
2024
  let connectionAnnounced = false;
1930
2025
  let catalogPublished = false;
1931
2026
  let readinessAnnounced = false;
2027
+ const resolveAgentCatalogEnvironment = options.resolveAgentCatalogEnvironment ??
2028
+ (async (catalogSignal) => {
2029
+ catalogSignal.throwIfAborted();
2030
+ return config.localContext.environment;
2031
+ });
1932
2032
  const startAutomaticIntegrationProvisioning = () => {
1933
2033
  if (!connectionAnnounced || !catalogPublished || automaticIntegrationProvisioningStarted) {
1934
2034
  return;
@@ -1971,7 +2071,7 @@ export async function runDaemon(config, audit, signal, timer = systemDaemonTimer
1971
2071
  while (!signal.aborted) {
1972
2072
  connectionEpoch += 1;
1973
2073
  try {
1974
- await runRelayConnection(config, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher, activeTurns, activeAttemptIds, connectionEpoch, diagnostics, announceConnection, signal, timer);
2074
+ await runRelayConnection(config, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher, activeTurns, activeAttemptIds, connectionEpoch, diagnostics, announceConnection, signal, timer, resolveAgentCatalogEnvironment);
1975
2075
  }
1976
2076
  catch (error) {
1977
2077
  if (signal.aborted) {