@moxt-ai/mobius 0.0.47 → 0.0.49
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.
- package/dist/acp/session-manager.d.ts +2 -1
- package/dist/acp/session-manager.d.ts.map +1 -1
- package/dist/acp/session-manager.js +38 -23
- package/dist/acp/session-manager.js.map +1 -1
- package/dist/agent-catalog/agent-specification.d.ts +0 -1
- package/dist/agent-catalog/agent-specification.d.ts.map +1 -1
- package/dist/agent-catalog/agent-specification.js +0 -2
- package/dist/agent-catalog/agent-specification.js.map +1 -1
- package/dist/agent-catalog/agents/pi-agent.d.ts +0 -1
- package/dist/agent-catalog/agents/pi-agent.d.ts.map +1 -1
- package/dist/agent-catalog/agents/pi-agent.js +0 -2
- package/dist/agent-catalog/agents/pi-agent.js.map +1 -1
- package/dist/agent-catalog/discover-agent.d.ts.map +1 -1
- package/dist/agent-catalog/discover-agent.js +2 -2
- package/dist/agent-catalog/discover-agent.js.map +1 -1
- package/dist/agent-catalog/local-agent.d.ts +1 -2
- package/dist/agent-catalog/local-agent.d.ts.map +1 -1
- package/dist/agent-catalog/local-agent.js +2 -7
- package/dist/agent-catalog/local-agent.js.map +1 -1
- package/dist/agent-catalog/publish-agent-catalog.d.ts.map +1 -1
- package/dist/agent-catalog/publish-agent-catalog.js +0 -1
- package/dist/agent-catalog/publish-agent-catalog.js.map +1 -1
- package/dist/artifacts/local-file-streamer.d.ts +3 -0
- package/dist/artifacts/local-file-streamer.d.ts.map +1 -0
- package/dist/artifacts/local-file-streamer.js +82 -0
- package/dist/artifacts/local-file-streamer.js.map +1 -0
- package/dist/authorization/local-raster.d.ts +4 -3
- package/dist/authorization/local-raster.d.ts.map +1 -1
- package/dist/authorization/local-raster.js +22 -12
- package/dist/authorization/local-raster.js.map +1 -1
- package/dist/cli.js +624 -1673
- package/dist/cli.js.map +4 -4
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +664 -1704
- package/dist/index.js.map +4 -4
- package/dist/native-sessions/history-images.js +1 -1
- package/dist/native-sessions/history-images.js.map +1 -1
- package/dist/pairing/pair-local-machine.d.ts.map +1 -1
- package/dist/pairing/pair-local-machine.js +0 -1
- package/dist/pairing/pair-local-machine.js.map +1 -1
- package/dist/run-daemon.d.ts.map +1 -1
- package/dist/run-daemon.js +99 -285
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.js +512 -1388
- package/dist/runtime.js.map +4 -4
- package/package.json +1 -1
- package/dist/bots/bot-context-applicator.d.ts +0 -14
- package/dist/bots/bot-context-applicator.d.ts.map +0 -1
- package/dist/bots/bot-context-applicator.js +0 -32
- package/dist/bots/bot-context-applicator.js.map +0 -1
- package/dist/bots/bot-execution-context.d.ts +0 -20
- package/dist/bots/bot-execution-context.d.ts.map +0 -1
- package/dist/bots/bot-execution-context.js +0 -82
- package/dist/bots/bot-execution-context.js.map +0 -1
- package/dist/bots/bot-message-command.d.ts +0 -6
- package/dist/bots/bot-message-command.d.ts.map +0 -1
- package/dist/bots/bot-message-command.js +0 -140
- package/dist/bots/bot-message-command.js.map +0 -1
- package/dist/bots/bot-outbound-ipc.d.ts +0 -12
- package/dist/bots/bot-outbound-ipc.d.ts.map +0 -1
- package/dist/bots/bot-outbound-ipc.js +0 -245
- package/dist/bots/bot-outbound-ipc.js.map +0 -1
- package/dist/bots/local-bot-execution-authorizer.d.ts +0 -23
- package/dist/bots/local-bot-execution-authorizer.d.ts.map +0 -1
- package/dist/bots/local-bot-execution-authorizer.js +0 -62
- package/dist/bots/local-bot-execution-authorizer.js.map +0 -1
package/dist/run-daemon.js
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { basename
|
|
2
|
+
import { basename } from "node:path";
|
|
3
3
|
import { styleText } from "node:util";
|
|
4
|
-
import { AGENT_ACTIVITY_KIND,
|
|
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_PERMISSION_MODE_CONFIG_ID, 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";
|
|
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 { supportedLocalAgentSpecifications } from "./agent-catalog/discover-local-agents.js";
|
|
9
|
-
import { AgentIntegrationDefinition, LocalAgentCatalogError,
|
|
9
|
+
import { AgentIntegrationDefinition, LocalAgentCatalogError, } from "./agent-catalog/local-agent.js";
|
|
10
10
|
import { publishAgentCatalog } from "./agent-catalog/publish-agent-catalog.js";
|
|
11
11
|
import { AgentInstallationManager, CancelledInstallation, FailedInstallation, RequestedInstallation, RunningInstallation, SucceededInstallation, } from "./agent-installation/agent-installation-manager.js";
|
|
12
12
|
import { FixedInstallationExecutor } from "./agent-installation/fixed-installation-executor.js";
|
|
13
|
+
import { streamLocalFile } from "./artifacts/local-file-streamer.js";
|
|
13
14
|
import { uploadRuntimeArtifact } from "./artifacts/runtime-artifact-uploader.js";
|
|
14
15
|
import { LocalAuthorizationError } from "./authorization/local-authorization-error.js";
|
|
15
16
|
import { WorkspaceDirectoryService } from "./authorization/workspace-directory.js";
|
|
16
|
-
import { EmbeddedBotContextApplicator } from "./bots/bot-context-applicator.js";
|
|
17
|
-
import { BotExecutionContextRegistry } from "./bots/bot-execution-context.js";
|
|
18
|
-
import { BotOutboundIpcServer } from "./bots/bot-outbound-ipc.js";
|
|
19
|
-
import { LocalBotAuthorizationError, LocalBotExecutionAuthorizer } from "./bots/local-bot-execution-authorizer.js";
|
|
20
17
|
import { AccumulatingOperationMetrics } from "./infra/operation-metrics.js";
|
|
21
18
|
import { NativeSessionService } from "./native-sessions/service.js";
|
|
22
19
|
import { environmentProxyDispatcher } from "./network/environment-proxy.js";
|
|
@@ -32,12 +29,6 @@ const RELAY_RECONNECT_DELAY_MILLISECONDS = 500;
|
|
|
32
29
|
const AGENT_ACTIVITY_COALESCING_MILLISECONDS = 100;
|
|
33
30
|
const ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS = 20_000;
|
|
34
31
|
const ACTIVE_TURN_RECONCILIATION_CLOSE_CODE = 4009;
|
|
35
|
-
function botIpcSocketPath() {
|
|
36
|
-
if (process.platform === "win32") {
|
|
37
|
-
return `\\\\.\\pipe\\mobius-bot-${randomUUID()}`;
|
|
38
|
-
}
|
|
39
|
-
return join("/tmp", `mobius-bot-${randomUUID()}.sock`);
|
|
40
|
-
}
|
|
41
32
|
class DaemonAcpObserver {
|
|
42
33
|
#config;
|
|
43
34
|
#record;
|
|
@@ -547,7 +538,6 @@ function operationErrorCode(error) {
|
|
|
547
538
|
if (error instanceof AcpExecutionError ||
|
|
548
539
|
error instanceof LocalAuthorizationError ||
|
|
549
540
|
error instanceof LocalAgentCatalogError ||
|
|
550
|
-
error instanceof LocalBotAuthorizationError ||
|
|
551
541
|
error instanceof PromptArtifactError) {
|
|
552
542
|
return error.code;
|
|
553
543
|
}
|
|
@@ -557,7 +547,6 @@ function operationErrorMessage(error) {
|
|
|
557
547
|
if (error instanceof AcpExecutionError ||
|
|
558
548
|
error instanceof LocalAuthorizationError ||
|
|
559
549
|
error instanceof LocalAgentCatalogError ||
|
|
560
|
-
error instanceof LocalBotAuthorizationError ||
|
|
561
550
|
error instanceof PromptArtifactError) {
|
|
562
551
|
return error.message;
|
|
563
552
|
}
|
|
@@ -778,7 +767,7 @@ async function executePrompt(outbox, publisher, command, config, directories, au
|
|
|
778
767
|
assertCompleteSessionConfiguration(prepared.configOptions, command.sessionConfigurations);
|
|
779
768
|
}
|
|
780
769
|
else {
|
|
781
|
-
await applyCompleteSessionConfiguration(sessions, prepared.configOptions, command.sessionConfigurations, agent, resolved.cwd, resolved.additionalDirectories, command.sessionId, signal);
|
|
770
|
+
await applyCompleteSessionConfiguration(sessions, audit, prepared.configOptions, command.sessionConfigurations, agent, resolved.cwd, resolved.additionalDirectories, command.commandId, command.sessionId, signal);
|
|
782
771
|
}
|
|
783
772
|
}
|
|
784
773
|
audit.record({
|
|
@@ -905,6 +894,26 @@ function assertSessionConfigurationSchema(options, selections) {
|
|
|
905
894
|
}
|
|
906
895
|
}
|
|
907
896
|
}
|
|
897
|
+
function assertSessionConfigurationCoverage(options, selections) {
|
|
898
|
+
const selectionsById = new Map(selections.map((selection) => [selection.configId, selection]));
|
|
899
|
+
if (selectionsById.size !== selections.length) {
|
|
900
|
+
throw invalidSessionConfiguration("The Turn configuration contains duplicate Agent settings");
|
|
901
|
+
}
|
|
902
|
+
for (const option of options) {
|
|
903
|
+
if (!selectionsById.has(option.id)) {
|
|
904
|
+
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
function sessionConfigurationSelectionIsAvailable(option, selection) {
|
|
909
|
+
if (option.type !== selection.valueType) {
|
|
910
|
+
return false;
|
|
911
|
+
}
|
|
912
|
+
if (option.type === "boolean") {
|
|
913
|
+
return selection.value.length === 0;
|
|
914
|
+
}
|
|
915
|
+
return !selection.booleanValue && option.values.some((value) => value.value === selection.value);
|
|
916
|
+
}
|
|
908
917
|
function sessionConfigurationMatches(option, selection) {
|
|
909
918
|
validateSessionConfigurationSelection(option, selection);
|
|
910
919
|
return option.type === "boolean"
|
|
@@ -937,11 +946,57 @@ function assertCompleteSessionConfiguration(options, selections) {
|
|
|
937
946
|
}
|
|
938
947
|
}
|
|
939
948
|
}
|
|
940
|
-
|
|
949
|
+
function assertAppliedSessionConfiguration(options, selections) {
|
|
950
|
+
const selectionsById = new Map(selections.map((selection) => [selection.configId, selection]));
|
|
951
|
+
for (const option of options) {
|
|
952
|
+
const selection = selectionsById.get(option.id);
|
|
953
|
+
if (option.id === AGENT_PERMISSION_MODE_CONFIG_ID) {
|
|
954
|
+
if (selection === undefined || !sessionConfigurationMatches(option, selection)) {
|
|
955
|
+
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
|
|
956
|
+
}
|
|
957
|
+
continue;
|
|
958
|
+
}
|
|
959
|
+
if (selection === undefined || !sessionConfigurationSelectionIsAvailable(option, selection)) {
|
|
960
|
+
continue;
|
|
961
|
+
}
|
|
962
|
+
if (!sessionConfigurationMatches(option, selection)) {
|
|
963
|
+
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
function unavailableSessionConfigurationCategory(selection) {
|
|
968
|
+
if (selection.configId === "model") {
|
|
969
|
+
return "model";
|
|
970
|
+
}
|
|
971
|
+
if (selection.configId === "reasoning_effort") {
|
|
972
|
+
return "thought_level";
|
|
973
|
+
}
|
|
974
|
+
return "unknown";
|
|
975
|
+
}
|
|
976
|
+
async function applySessionConfigurationSelection(sessions, audit, options, selection, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
|
|
941
977
|
const option = options.find((candidate) => candidate.id === selection.configId);
|
|
942
978
|
if (option === undefined) {
|
|
979
|
+
if (selection.configId !== AGENT_PERMISSION_MODE_CONFIG_ID) {
|
|
980
|
+
warnIgnoredSetting(audit, "session_configuration_setting_ignored", commandId, sessionId, agent.id, selection, unavailableSessionConfigurationCategory(selection), "setting_unavailable");
|
|
981
|
+
return options;
|
|
982
|
+
}
|
|
943
983
|
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} is unavailable`);
|
|
944
984
|
}
|
|
985
|
+
if (selection.configId !== AGENT_PERMISSION_MODE_CONFIG_ID) {
|
|
986
|
+
if (option.type !== selection.valueType) {
|
|
987
|
+
warnIgnoredSetting(audit, "session_configuration_setting_ignored", commandId, sessionId, agent.id, selection, option.category, "setting_schema_mismatch");
|
|
988
|
+
return options;
|
|
989
|
+
}
|
|
990
|
+
if ((option.type === "boolean" && selection.value.length > 0) ||
|
|
991
|
+
(option.type === "select" && selection.booleanValue)) {
|
|
992
|
+
warnIgnoredSetting(audit, "session_configuration_setting_ignored", commandId, sessionId, agent.id, selection, option.category, "selection_schema_mismatch");
|
|
993
|
+
return options;
|
|
994
|
+
}
|
|
995
|
+
if (option.type === "select" && !option.values.some((value) => value.value === selection.value)) {
|
|
996
|
+
warnIgnoredSetting(audit, "session_configuration_setting_ignored", commandId, sessionId, agent.id, selection, option.category, "value_unavailable");
|
|
997
|
+
return options;
|
|
998
|
+
}
|
|
999
|
+
}
|
|
945
1000
|
if (sessionConfigurationMatches(option, selection)) {
|
|
946
1001
|
return options;
|
|
947
1002
|
}
|
|
@@ -958,36 +1013,19 @@ async function applySessionConfigurationSelection(sessions, options, selection,
|
|
|
958
1013
|
valueType: selection.valueType,
|
|
959
1014
|
});
|
|
960
1015
|
}
|
|
961
|
-
async function applyCompleteSessionConfiguration(sessions, initialOptions, selections, agent, cwd, additionalDirectories, sessionId, signal) {
|
|
962
|
-
|
|
1016
|
+
async function applyCompleteSessionConfiguration(sessions, audit, initialOptions, selections, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
|
|
1017
|
+
assertSessionConfigurationCoverage(initialOptions, selections);
|
|
963
1018
|
let options = initialOptions;
|
|
964
1019
|
const orderedSelections = selections.toSorted((left, right) => {
|
|
965
1020
|
const priority = sessionConfigurationPriority(left, initialOptions) - sessionConfigurationPriority(right, initialOptions);
|
|
966
1021
|
return priority === 0 ? left.configId.localeCompare(right.configId) : priority;
|
|
967
1022
|
});
|
|
968
1023
|
for (const selection of orderedSelections) {
|
|
969
|
-
options = await applySessionConfigurationSelection(sessions, options, selection, agent, cwd, additionalDirectories, sessionId, signal);
|
|
1024
|
+
options = await applySessionConfigurationSelection(sessions, audit, options, selection, agent, cwd, additionalDirectories, commandId, sessionId, signal);
|
|
970
1025
|
}
|
|
971
|
-
|
|
1026
|
+
assertAppliedSessionConfiguration(options, selections);
|
|
972
1027
|
}
|
|
973
|
-
function
|
|
974
|
-
return new LocalAgentDefinition(agent.id, agent.label, agent.command, agent.arguments, {
|
|
975
|
-
...agent.environment,
|
|
976
|
-
MOBIUS_BOT_CONTEXT: contextHandle,
|
|
977
|
-
MOBIUS_BOT_SOCKET: socketPath,
|
|
978
|
-
MOBIUS_RELAY_TOKEN: "",
|
|
979
|
-
MOBIUS_RELAY_URL: "",
|
|
980
|
-
}, agent.adapterVersion, agent.agentVersion, agent.adapterIdentity, agent.agentIdentity, agent.promptTimeoutMilliseconds, agent.capabilities, agent.permissionProfile);
|
|
981
|
-
}
|
|
982
|
-
function assertPreparedPermission(configOptions, permissionMode) {
|
|
983
|
-
const permission = configOptions.find((option) => option.id === "permission_mode");
|
|
984
|
-
if (permission === undefined ||
|
|
985
|
-
permission.type !== "select" ||
|
|
986
|
-
(permissionMode !== AGENT_DEFAULT_EXECUTION_SETTING && permission.currentValue !== permissionMode)) {
|
|
987
|
-
throw new AcpExecutionError("The required Agent permission mode is unavailable", {}, "invalid_session_configuration");
|
|
988
|
-
}
|
|
989
|
-
}
|
|
990
|
-
function warnIgnoredExecutionSetting(audit, commandId, sessionId, agentId, selection, category, reason) {
|
|
1028
|
+
function warnIgnoredSetting(audit, event, commandId, sessionId, agentId, selection, category, reason) {
|
|
991
1029
|
const details = {
|
|
992
1030
|
agentId,
|
|
993
1031
|
category,
|
|
@@ -995,203 +1033,9 @@ function warnIgnoredExecutionSetting(audit, commandId, sessionId, agentId, selec
|
|
|
995
1033
|
reason,
|
|
996
1034
|
requestedValue: selection.value,
|
|
997
1035
|
};
|
|
998
|
-
const event = "bot_execution_setting_ignored";
|
|
999
1036
|
audit.record({ commandId, details, event, sessionId });
|
|
1000
1037
|
process.stderr.write(`Mobius daemon warning ${JSON.stringify({ commandId, event, sessionId, ...details })}\n`);
|
|
1001
1038
|
}
|
|
1002
|
-
async function applySupportedExecutionSelection(sessions, audit, configOptions, selection, category, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
|
|
1003
|
-
if (selection.value === AGENT_DEFAULT_EXECUTION_SETTING) {
|
|
1004
|
-
return configOptions;
|
|
1005
|
-
}
|
|
1006
|
-
const option = configOptions.find((candidate) => candidate.id === selection.configId);
|
|
1007
|
-
if (option === undefined) {
|
|
1008
|
-
warnIgnoredExecutionSetting(audit, commandId, sessionId, agent.id, selection, category, "setting_unavailable");
|
|
1009
|
-
return configOptions;
|
|
1010
|
-
}
|
|
1011
|
-
if (option.type !== "select" || option.category !== category) {
|
|
1012
|
-
warnIgnoredExecutionSetting(audit, commandId, sessionId, agent.id, selection, category, "setting_schema_mismatch");
|
|
1013
|
-
return configOptions;
|
|
1014
|
-
}
|
|
1015
|
-
if (selection.valueType !== "select" || selection.booleanValue) {
|
|
1016
|
-
warnIgnoredExecutionSetting(audit, commandId, sessionId, agent.id, selection, category, "selection_schema_mismatch");
|
|
1017
|
-
return configOptions;
|
|
1018
|
-
}
|
|
1019
|
-
if (!option.values.some((value) => value.value === selection.value)) {
|
|
1020
|
-
warnIgnoredExecutionSetting(audit, commandId, sessionId, agent.id, selection, category, "value_unavailable");
|
|
1021
|
-
return configOptions;
|
|
1022
|
-
}
|
|
1023
|
-
if (option.currentValue === selection.value) {
|
|
1024
|
-
return configOptions;
|
|
1025
|
-
}
|
|
1026
|
-
return await sessions.configureSession({
|
|
1027
|
-
additionalDirectories,
|
|
1028
|
-
agent,
|
|
1029
|
-
booleanValue: false,
|
|
1030
|
-
configId: selection.configId,
|
|
1031
|
-
cwd,
|
|
1032
|
-
requestId: `cfg_${randomUUID()}`,
|
|
1033
|
-
sessionId,
|
|
1034
|
-
signal,
|
|
1035
|
-
value: selection.value,
|
|
1036
|
-
valueType: "select",
|
|
1037
|
-
});
|
|
1038
|
-
}
|
|
1039
|
-
async function executeBotPrompt(outbox, publisher, command, config, directories, audit, sessions, authorizer, contexts, applicator, ipc, attemptId, activateAttempt, timer, signal) {
|
|
1040
|
-
const activities = new CoalescingDaemonActivityPublisher(timer, (activity) => {
|
|
1041
|
-
publisher.recordAttempt(command.sessionId, encodeDaemonActivity(command, activity), attemptId);
|
|
1042
|
-
});
|
|
1043
|
-
try {
|
|
1044
|
-
const deadline = Date.parse(command.executionDeadlineAt);
|
|
1045
|
-
const remaining = deadline - Date.now();
|
|
1046
|
-
if (!Number.isSafeInteger(deadline) || remaining <= 0) {
|
|
1047
|
-
throw new LocalBotAuthorizationError("turn_expired", "The Bot execution deadline has expired");
|
|
1048
|
-
}
|
|
1049
|
-
const execution = await authorizer.authorize(command, config.catalog, directories, config.bindingId, signal);
|
|
1050
|
-
const resolved = await resolveSessionDirectories(directories, config.bindingId, command.directoryId, command.additionalDirectoryIds, signal);
|
|
1051
|
-
const attachments = await resolvePromptArtifacts(config, command, signal);
|
|
1052
|
-
const applied = await applicator.apply(command, execution, attachments.resources, signal);
|
|
1053
|
-
const deadlineSignal = AbortSignal.timeout(remaining);
|
|
1054
|
-
const executionSignal = AbortSignal.any([signal, deadlineSignal]);
|
|
1055
|
-
const startExecution = () => {
|
|
1056
|
-
audit.record({
|
|
1057
|
-
commandId: command.commandId,
|
|
1058
|
-
details: {
|
|
1059
|
-
behaviorRevisionId: command.behaviorRevisionId,
|
|
1060
|
-
bindingId: command.bindingId,
|
|
1061
|
-
botId: command.botId,
|
|
1062
|
-
executionId: command.executionId,
|
|
1063
|
-
},
|
|
1064
|
-
event: "bot_session_authorized",
|
|
1065
|
-
sessionId: command.sessionId,
|
|
1066
|
-
});
|
|
1067
|
-
outbox.transitionExecution(command.commandId, "running");
|
|
1068
|
-
publisher.recordAttempt(command.sessionId, encodeSessionStartedEvent({
|
|
1069
|
-
attemptId,
|
|
1070
|
-
commandId: command.commandId,
|
|
1071
|
-
kind: SESSION_STARTED_KIND,
|
|
1072
|
-
sessionId: command.sessionId,
|
|
1073
|
-
}), attemptId);
|
|
1074
|
-
activateAttempt();
|
|
1075
|
-
};
|
|
1076
|
-
let stopReason = "steered";
|
|
1077
|
-
if (command.disposition === SessionPromptDisposition.Steer) {
|
|
1078
|
-
startExecution();
|
|
1079
|
-
await sessions.steerPrompt({
|
|
1080
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
1081
|
-
agent: execution.agent,
|
|
1082
|
-
commandId: command.commandId,
|
|
1083
|
-
cwd: resolved.cwd,
|
|
1084
|
-
images: attachments.images,
|
|
1085
|
-
prompt: command.prompt,
|
|
1086
|
-
resources: applied.resources,
|
|
1087
|
-
sessionId: command.sessionId,
|
|
1088
|
-
signal: executionSignal,
|
|
1089
|
-
targetCommandId: command.targetCommandId,
|
|
1090
|
-
});
|
|
1091
|
-
}
|
|
1092
|
-
else {
|
|
1093
|
-
if (command.disposition === SessionPromptDisposition.Queue &&
|
|
1094
|
-
!outbox.isTerminalExecution(command.targetCommandId, command.sessionId)) {
|
|
1095
|
-
throw new AcpExecutionError("The queued Bot prompt target is unavailable", {}, "prompt_queue_target_unavailable");
|
|
1096
|
-
}
|
|
1097
|
-
const lease = contexts.activate(command);
|
|
1098
|
-
try {
|
|
1099
|
-
const agent = botExecutionAgent(execution.agent, lease.context.contextHandle, ipc.socketPath);
|
|
1100
|
-
const prepared = await sessions.prepareExecutionSession({
|
|
1101
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
1102
|
-
agent,
|
|
1103
|
-
cwd: resolved.cwd,
|
|
1104
|
-
sessionId: command.sessionId,
|
|
1105
|
-
signal: executionSignal,
|
|
1106
|
-
});
|
|
1107
|
-
assertPreparedPermission(prepared.configOptions, execution.executionConfiguration.permissionMode);
|
|
1108
|
-
let configOptions = await applySupportedExecutionSelection(sessions, audit, prepared.configOptions, execution.executionConfiguration.model, "model", agent, resolved.cwd, resolved.additionalDirectories, command.commandId, command.sessionId, executionSignal);
|
|
1109
|
-
configOptions = await applySupportedExecutionSelection(sessions, audit, configOptions, execution.executionConfiguration.reasoningEffort, "thought_level", agent, resolved.cwd, resolved.additionalDirectories, command.commandId, command.sessionId, executionSignal);
|
|
1110
|
-
for (const selection of command.sessionConfigurations) {
|
|
1111
|
-
await sessions.configureSession({
|
|
1112
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
1113
|
-
agent,
|
|
1114
|
-
booleanValue: selection.booleanValue,
|
|
1115
|
-
configId: selection.configId,
|
|
1116
|
-
cwd: resolved.cwd,
|
|
1117
|
-
requestId: `cfg_${randomUUID()}`,
|
|
1118
|
-
sessionId: command.sessionId,
|
|
1119
|
-
signal: executionSignal,
|
|
1120
|
-
value: selection.value,
|
|
1121
|
-
valueType: selection.valueType,
|
|
1122
|
-
});
|
|
1123
|
-
}
|
|
1124
|
-
startExecution();
|
|
1125
|
-
const result = await sessions.runPrompt({
|
|
1126
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
1127
|
-
agent,
|
|
1128
|
-
commandId: command.commandId,
|
|
1129
|
-
cwd: resolved.cwd,
|
|
1130
|
-
disposition: command.disposition,
|
|
1131
|
-
images: attachments.images,
|
|
1132
|
-
onActivity: activities.record,
|
|
1133
|
-
onText: (text, messageId) => {
|
|
1134
|
-
publisher.recordAttempt(command.sessionId, encodeAgentMessageDeltaEvent({
|
|
1135
|
-
commandId: command.commandId,
|
|
1136
|
-
kind: AGENT_MESSAGE_DELTA_KIND,
|
|
1137
|
-
messageId,
|
|
1138
|
-
sessionId: command.sessionId,
|
|
1139
|
-
text,
|
|
1140
|
-
}), attemptId);
|
|
1141
|
-
return Promise.resolve();
|
|
1142
|
-
},
|
|
1143
|
-
prompt: command.prompt,
|
|
1144
|
-
resources: applied.resources,
|
|
1145
|
-
sessionId: command.sessionId,
|
|
1146
|
-
signal: executionSignal,
|
|
1147
|
-
targetCommandId: command.targetCommandId,
|
|
1148
|
-
});
|
|
1149
|
-
stopReason = result.stopReason;
|
|
1150
|
-
}
|
|
1151
|
-
finally {
|
|
1152
|
-
lease.release();
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1155
|
-
activities.flush();
|
|
1156
|
-
publisher.recordAttempt(command.sessionId, encodeSessionCompletedEvent({
|
|
1157
|
-
commandId: command.commandId,
|
|
1158
|
-
kind: SESSION_COMPLETED_KIND,
|
|
1159
|
-
sessionId: command.sessionId,
|
|
1160
|
-
stopReason,
|
|
1161
|
-
}), attemptId);
|
|
1162
|
-
outbox.transitionExecution(command.commandId, stopReason === "cancelled" ? "cancelled" : "succeeded");
|
|
1163
|
-
audit.record({
|
|
1164
|
-
commandId: command.commandId,
|
|
1165
|
-
details: { botId: command.botId, executionId: command.executionId },
|
|
1166
|
-
event: stopReason === "cancelled" ? "bot_session_cancelled" : "bot_session_completed",
|
|
1167
|
-
sessionId: command.sessionId,
|
|
1168
|
-
});
|
|
1169
|
-
}
|
|
1170
|
-
catch (error) {
|
|
1171
|
-
activities.flush();
|
|
1172
|
-
const failure = Date.parse(command.executionDeadlineAt) <= Date.now()
|
|
1173
|
-
? new LocalBotAuthorizationError("turn_expired", "The Bot execution deadline has expired", {
|
|
1174
|
-
cause: error,
|
|
1175
|
-
})
|
|
1176
|
-
: error;
|
|
1177
|
-
audit.record({
|
|
1178
|
-
commandId: command.commandId,
|
|
1179
|
-
details: {
|
|
1180
|
-
botId: command.botId,
|
|
1181
|
-
code: operationErrorCode(failure),
|
|
1182
|
-
executionId: command.executionId,
|
|
1183
|
-
},
|
|
1184
|
-
event: "bot_session_failed",
|
|
1185
|
-
sessionId: command.sessionId,
|
|
1186
|
-
});
|
|
1187
|
-
const code = operationErrorCode(failure);
|
|
1188
|
-
reportFailure(publisher, command, code === "session_operation_failed" ? "agent_execution_failed" : code, code === "session_operation_failed"
|
|
1189
|
-
? "The local agent could not complete the Bot request"
|
|
1190
|
-
: operationErrorMessage(failure), attemptId);
|
|
1191
|
-
outbox.transitionExecution(command.commandId, "failed");
|
|
1192
|
-
console.error("Mobius daemon Bot command failed", failure);
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
1039
|
function waitForRelayRetry(signal, timer) {
|
|
1196
1040
|
if (signal.aborted) {
|
|
1197
1041
|
return Promise.resolve();
|
|
@@ -1243,7 +1087,7 @@ async function installDetectedAgentIntegrations(config, installations, signal) {
|
|
|
1243
1087
|
}, signal);
|
|
1244
1088
|
}
|
|
1245
1089
|
}
|
|
1246
|
-
async function runRelayConnection(config, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher,
|
|
1090
|
+
async function runRelayConnection(config, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher, activeTurns, activeAttemptIds, connectionEpoch, diagnostics, onConnected, signal, timer) {
|
|
1247
1091
|
const relayUrl = new URL(config.relayUrl);
|
|
1248
1092
|
relayUrl.searchParams.set("deliveryReceipts", "1");
|
|
1249
1093
|
relayUrl.searchParams.set("liveness", "1");
|
|
@@ -1397,11 +1241,6 @@ async function runRelayConnection(config, directories, audit, sessions, installa
|
|
|
1397
1241
|
}
|
|
1398
1242
|
return;
|
|
1399
1243
|
}
|
|
1400
|
-
if (kind === BOT_SESSION_PROMPT_KIND) {
|
|
1401
|
-
const command = decodeBotSessionPromptCommand(delivery.payload);
|
|
1402
|
-
await processDeliveredPrompt(delivery, command, command.disposition !== SessionPromptDisposition.Steer, (attemptId, activateAttempt, executionSignal) => executeBotPrompt(outbox, publisher, command, config, directories, audit, sessions, authorizer, contexts, applicator, ipc, attemptId, activateAttempt, timer, executionSignal));
|
|
1403
|
-
return;
|
|
1404
|
-
}
|
|
1405
1244
|
if (kind === SESSION_PROMPT_KIND) {
|
|
1406
1245
|
const command = decodeSessionPromptCommand(delivery.payload);
|
|
1407
1246
|
await processDeliveredPrompt(delivery, command, command.disposition !== SessionPromptDisposition.Steer, (attemptId, activateAttempt, executionSignal) => executePrompt(outbox, publisher, command, config, directories, audit, sessions, attemptId, activateAttempt, timer, executionSignal));
|
|
@@ -1445,9 +1284,6 @@ async function runRelayConnection(config, directories, audit, sessions, installa
|
|
|
1445
1284
|
else if (payloadKind === SESSION_PROMPT_KIND) {
|
|
1446
1285
|
payloadSessionId = decodeSessionPromptCommand(delivery.payload).sessionId;
|
|
1447
1286
|
}
|
|
1448
|
-
else if (payloadKind === BOT_SESSION_PROMPT_KIND) {
|
|
1449
|
-
payloadSessionId = decodeBotSessionPromptCommand(delivery.payload).sessionId;
|
|
1450
|
-
}
|
|
1451
1287
|
else {
|
|
1452
1288
|
throw new Error("Runtime delivery contains an unsupported protocol message");
|
|
1453
1289
|
}
|
|
@@ -1759,6 +1595,22 @@ async function runRelayConnection(config, directories, audit, sessions, installa
|
|
|
1759
1595
|
connectionLiveness.acknowledge(decodeRuntimeHeartbeatAckEvent(encoded));
|
|
1760
1596
|
return;
|
|
1761
1597
|
}
|
|
1598
|
+
if (kind === FILE_READ_KIND) {
|
|
1599
|
+
const command = decodeFileReadCommand(encoded);
|
|
1600
|
+
void streamLocalFile(command, (message) => send(socket, message), connectionController.signal).catch((error) => {
|
|
1601
|
+
if (socket.readyState !== WebSocket.OPEN || connectionController.signal.aborted) {
|
|
1602
|
+
return;
|
|
1603
|
+
}
|
|
1604
|
+
send(socket, encodeFileFailedEvent({
|
|
1605
|
+
code: "file_unavailable",
|
|
1606
|
+
kind: FILE_FAILED_KIND,
|
|
1607
|
+
message: error instanceof Error ? error.message : "The local file is unavailable",
|
|
1608
|
+
requestId: command.requestId,
|
|
1609
|
+
sessionId: command.sessionId,
|
|
1610
|
+
}));
|
|
1611
|
+
});
|
|
1612
|
+
return;
|
|
1613
|
+
}
|
|
1762
1614
|
if (kind === SESSION_CANCEL_KIND) {
|
|
1763
1615
|
const cancellation = decodeSessionCancelCommand(encoded);
|
|
1764
1616
|
const turn = activeTurns.get(cancellation.commandId);
|
|
@@ -1840,34 +1692,6 @@ async function runRelayConnection(config, directories, audit, sessions, installa
|
|
|
1840
1692
|
});
|
|
1841
1693
|
return;
|
|
1842
1694
|
}
|
|
1843
|
-
if (kind === BOT_SESSION_PROMPT_KIND) {
|
|
1844
|
-
const command = decodeBotSessionPromptCommand(encoded);
|
|
1845
|
-
if (activeTurns.has(command.commandId)) {
|
|
1846
|
-
return;
|
|
1847
|
-
}
|
|
1848
|
-
const receipt = outbox.claimExecution(command.commandId, command.sessionId, encoded);
|
|
1849
|
-
if (receipt.kind === "duplicate") {
|
|
1850
|
-
return;
|
|
1851
|
-
}
|
|
1852
|
-
const turn = new ActiveDaemonTurn(command, receipt.attemptId);
|
|
1853
|
-
activeTurns.set(command.commandId, turn);
|
|
1854
|
-
void executeBotPrompt(outbox, publisher, command, config, directories, audit, sessions, authorizer, contexts, applicator, ipc, receipt.attemptId, () => {
|
|
1855
|
-
if (command.disposition !== SessionPromptDisposition.Steer) {
|
|
1856
|
-
activeAttemptIds.set(command.sessionId, receipt.attemptId);
|
|
1857
|
-
}
|
|
1858
|
-
}, timer, turn.signal)
|
|
1859
|
-
.catch((error) => {
|
|
1860
|
-
console.error("Mobius daemon Bot turn failed", error);
|
|
1861
|
-
})
|
|
1862
|
-
.finally(() => {
|
|
1863
|
-
activeTurns.delete(command.commandId);
|
|
1864
|
-
if (activeAttemptIds.get(command.sessionId) === receipt.attemptId) {
|
|
1865
|
-
activeAttemptIds.delete(command.sessionId);
|
|
1866
|
-
}
|
|
1867
|
-
turn.finish();
|
|
1868
|
-
});
|
|
1869
|
-
return;
|
|
1870
|
-
}
|
|
1871
1695
|
if (kind !== SESSION_PROMPT_KIND) {
|
|
1872
1696
|
throw new Error("Unsupported protocol message");
|
|
1873
1697
|
}
|
|
@@ -1950,10 +1774,6 @@ export async function runDaemon(config, audit, signal, timer = systemDaemonTimer
|
|
|
1950
1774
|
const sessionStore = new SqliteAcpSessionStore(config.auditDatabasePath);
|
|
1951
1775
|
const outbox = new SessionEventOutbox(config.auditDatabasePath);
|
|
1952
1776
|
const publisher = new DaemonSessionEventPublisher(outbox, timer);
|
|
1953
|
-
const authorizer = new LocalBotExecutionAuthorizer();
|
|
1954
|
-
const contexts = new BotExecutionContextRegistry();
|
|
1955
|
-
const applicator = new EmbeddedBotContextApplicator();
|
|
1956
|
-
const ipc = new BotOutboundIpcServer(botIpcSocketPath(), config.relayUrl, contexts);
|
|
1957
1777
|
const activeTurns = new Map();
|
|
1958
1778
|
const activeAttemptIds = new Map();
|
|
1959
1779
|
const recordSessionEvent = (sessionId, payload) => {
|
|
@@ -2015,11 +1835,10 @@ export async function runDaemon(config, audit, signal, timer = systemDaemonTimer
|
|
|
2015
1835
|
startAutomaticIntegrationProvisioning();
|
|
2016
1836
|
});
|
|
2017
1837
|
try {
|
|
2018
|
-
await ipc.listen(signal);
|
|
2019
1838
|
while (!signal.aborted) {
|
|
2020
1839
|
connectionEpoch += 1;
|
|
2021
1840
|
try {
|
|
2022
|
-
await runRelayConnection(config, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher,
|
|
1841
|
+
await runRelayConnection(config, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher, activeTurns, activeAttemptIds, connectionEpoch, diagnostics, announceConnection, signal, timer);
|
|
2023
1842
|
}
|
|
2024
1843
|
catch (error) {
|
|
2025
1844
|
if (signal.aborted) {
|
|
@@ -2049,23 +1868,18 @@ export async function runDaemon(config, audit, signal, timer = systemDaemonTimer
|
|
|
2049
1868
|
}
|
|
2050
1869
|
finally {
|
|
2051
1870
|
try {
|
|
2052
|
-
await
|
|
1871
|
+
await sessions.close();
|
|
2053
1872
|
}
|
|
2054
1873
|
finally {
|
|
2055
1874
|
try {
|
|
2056
|
-
|
|
1875
|
+
sessionStore.close();
|
|
2057
1876
|
}
|
|
2058
1877
|
finally {
|
|
2059
1878
|
try {
|
|
2060
|
-
|
|
1879
|
+
publisher.close();
|
|
2061
1880
|
}
|
|
2062
1881
|
finally {
|
|
2063
|
-
|
|
2064
|
-
publisher.close();
|
|
2065
|
-
}
|
|
2066
|
-
finally {
|
|
2067
|
-
outbox.close();
|
|
2068
|
-
}
|
|
1882
|
+
outbox.close();
|
|
2069
1883
|
}
|
|
2070
1884
|
}
|
|
2071
1885
|
}
|