@moxt-ai/mobius 0.0.48 → 0.0.50
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 +34 -11
- package/dist/acp/session-manager.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 +1227 -1798
- package/dist/cli.js.map +4 -4
- package/dist/config.d.ts +21 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +32 -2
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +2 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1280 -1839
- 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 +5 -2
- package/dist/pairing/pair-local-machine.d.ts.map +1 -1
- package/dist/pairing/pair-local-machine.js +93 -112
- package/dist/pairing/pair-local-machine.js.map +1 -1
- package/dist/run-daemon.d.ts.map +1 -1
- package/dist/run-daemon.js +30 -275
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.d.ts +2 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +1028 -1483
- package/dist/runtime.js.map +4 -4
- package/dist/storage/runtime-installation-store.d.ts +53 -0
- package/dist/storage/runtime-installation-store.d.ts.map +1 -0
- package/dist/storage/runtime-installation-store.js +491 -0
- package/dist/storage/runtime-installation-store.js.map +1 -0
- 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 -19
- package/dist/bots/bot-execution-context.d.ts.map +0 -1
- package/dist/bots/bot-execution-context.js +0 -75
- 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";
|
|
@@ -27,17 +24,10 @@ import { RelayConnectionLiveness } from "./relay-connection/liveness.js";
|
|
|
27
24
|
import { relayHttpEndpoint, runtimeAuthorization } from "./relay-connection/runtime-authentication.js";
|
|
28
25
|
import { RuntimeDeliveryInboxCapacityError, SessionEventOutbox } from "./relay-connection/session-event-outbox.js";
|
|
29
26
|
import { systemDaemonTimer } from "./relay-connection/timer.js";
|
|
30
|
-
import { readStateDirectory } from "./storage/state-directory.js";
|
|
31
27
|
const RELAY_RECONNECT_DELAY_MILLISECONDS = 500;
|
|
32
28
|
const AGENT_ACTIVITY_COALESCING_MILLISECONDS = 100;
|
|
33
29
|
const ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS = 20_000;
|
|
34
30
|
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
31
|
class DaemonAcpObserver {
|
|
42
32
|
#config;
|
|
43
33
|
#record;
|
|
@@ -547,7 +537,6 @@ function operationErrorCode(error) {
|
|
|
547
537
|
if (error instanceof AcpExecutionError ||
|
|
548
538
|
error instanceof LocalAuthorizationError ||
|
|
549
539
|
error instanceof LocalAgentCatalogError ||
|
|
550
|
-
error instanceof LocalBotAuthorizationError ||
|
|
551
540
|
error instanceof PromptArtifactError) {
|
|
552
541
|
return error.code;
|
|
553
542
|
}
|
|
@@ -557,7 +546,6 @@ function operationErrorMessage(error) {
|
|
|
557
546
|
if (error instanceof AcpExecutionError ||
|
|
558
547
|
error instanceof LocalAuthorizationError ||
|
|
559
548
|
error instanceof LocalAgentCatalogError ||
|
|
560
|
-
error instanceof LocalBotAuthorizationError ||
|
|
561
549
|
error instanceof PromptArtifactError) {
|
|
562
550
|
return error.message;
|
|
563
551
|
}
|
|
@@ -1036,23 +1024,6 @@ async function applyCompleteSessionConfiguration(sessions, audit, initialOptions
|
|
|
1036
1024
|
}
|
|
1037
1025
|
assertAppliedSessionConfiguration(options, selections);
|
|
1038
1026
|
}
|
|
1039
|
-
function botExecutionAgent(agent, contextHandle, socketPath) {
|
|
1040
|
-
return new LocalAgentDefinition(agent.id, agent.label, agent.command, agent.arguments, {
|
|
1041
|
-
...agent.environment,
|
|
1042
|
-
MOBIUS_BOT_CONTEXT: contextHandle,
|
|
1043
|
-
MOBIUS_BOT_SOCKET: socketPath,
|
|
1044
|
-
MOBIUS_RELAY_TOKEN: "",
|
|
1045
|
-
MOBIUS_RELAY_URL: "",
|
|
1046
|
-
}, agent.adapterVersion, agent.agentVersion, agent.adapterIdentity, agent.agentIdentity, agent.capabilities, agent.permissionProfile);
|
|
1047
|
-
}
|
|
1048
|
-
function assertPreparedPermission(configOptions, permissionMode) {
|
|
1049
|
-
const permission = configOptions.find((option) => option.id === "permission_mode");
|
|
1050
|
-
if (permission === undefined ||
|
|
1051
|
-
permission.type !== "select" ||
|
|
1052
|
-
(permissionMode !== AGENT_DEFAULT_EXECUTION_SETTING && permission.currentValue !== permissionMode)) {
|
|
1053
|
-
throw new AcpExecutionError("The required Agent permission mode is unavailable", {}, "invalid_session_configuration");
|
|
1054
|
-
}
|
|
1055
|
-
}
|
|
1056
1027
|
function warnIgnoredSetting(audit, event, commandId, sessionId, agentId, selection, category, reason) {
|
|
1057
1028
|
const details = {
|
|
1058
1029
|
agentId,
|
|
@@ -1064,192 +1035,6 @@ function warnIgnoredSetting(audit, event, commandId, sessionId, agentId, selecti
|
|
|
1064
1035
|
audit.record({ commandId, details, event, sessionId });
|
|
1065
1036
|
process.stderr.write(`Mobius daemon warning ${JSON.stringify({ commandId, event, sessionId, ...details })}\n`);
|
|
1066
1037
|
}
|
|
1067
|
-
async function applySupportedExecutionSelection(sessions, audit, configOptions, selection, category, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
|
|
1068
|
-
if (selection.value === AGENT_DEFAULT_EXECUTION_SETTING) {
|
|
1069
|
-
return configOptions;
|
|
1070
|
-
}
|
|
1071
|
-
const option = configOptions.find((candidate) => candidate.id === selection.configId);
|
|
1072
|
-
if (option === undefined) {
|
|
1073
|
-
warnIgnoredSetting(audit, "bot_execution_setting_ignored", commandId, sessionId, agent.id, selection, category, "setting_unavailable");
|
|
1074
|
-
return configOptions;
|
|
1075
|
-
}
|
|
1076
|
-
if (option.type !== "select" || option.category !== category) {
|
|
1077
|
-
warnIgnoredSetting(audit, "bot_execution_setting_ignored", commandId, sessionId, agent.id, selection, category, "setting_schema_mismatch");
|
|
1078
|
-
return configOptions;
|
|
1079
|
-
}
|
|
1080
|
-
if (selection.valueType !== "select" || selection.booleanValue) {
|
|
1081
|
-
warnIgnoredSetting(audit, "bot_execution_setting_ignored", commandId, sessionId, agent.id, selection, category, "selection_schema_mismatch");
|
|
1082
|
-
return configOptions;
|
|
1083
|
-
}
|
|
1084
|
-
if (!option.values.some((value) => value.value === selection.value)) {
|
|
1085
|
-
warnIgnoredSetting(audit, "bot_execution_setting_ignored", commandId, sessionId, agent.id, selection, category, "value_unavailable");
|
|
1086
|
-
return configOptions;
|
|
1087
|
-
}
|
|
1088
|
-
if (option.currentValue === selection.value) {
|
|
1089
|
-
return configOptions;
|
|
1090
|
-
}
|
|
1091
|
-
return await sessions.configureSession({
|
|
1092
|
-
additionalDirectories,
|
|
1093
|
-
agent,
|
|
1094
|
-
booleanValue: false,
|
|
1095
|
-
configId: selection.configId,
|
|
1096
|
-
cwd,
|
|
1097
|
-
requestId: `cfg_${randomUUID()}`,
|
|
1098
|
-
sessionId,
|
|
1099
|
-
signal,
|
|
1100
|
-
value: selection.value,
|
|
1101
|
-
valueType: "select",
|
|
1102
|
-
});
|
|
1103
|
-
}
|
|
1104
|
-
async function executeBotPrompt(outbox, publisher, command, config, directories, audit, sessions, authorizer, contexts, applicator, ipc, attemptId, activateAttempt, timer, signal) {
|
|
1105
|
-
const activities = new CoalescingDaemonActivityPublisher(timer, (activity) => {
|
|
1106
|
-
publisher.recordAttempt(command.sessionId, encodeDaemonActivity(command, activity), attemptId);
|
|
1107
|
-
});
|
|
1108
|
-
try {
|
|
1109
|
-
const startDeadline = Date.parse(command.executionDeadlineAt);
|
|
1110
|
-
if (!Number.isSafeInteger(startDeadline) || startDeadline <= Date.now()) {
|
|
1111
|
-
throw new LocalBotAuthorizationError("turn_expired", "The Bot execution start deadline has expired");
|
|
1112
|
-
}
|
|
1113
|
-
const execution = await authorizer.authorize(command, config.catalog, directories, config.bindingId, signal);
|
|
1114
|
-
const resolved = await resolveSessionDirectories(directories, config.bindingId, command.directoryId, command.additionalDirectoryIds, signal);
|
|
1115
|
-
const attachments = await resolvePromptArtifacts(config, command, signal);
|
|
1116
|
-
const applied = await applicator.apply(command, execution, attachments.resources, signal);
|
|
1117
|
-
const startExecution = () => {
|
|
1118
|
-
audit.record({
|
|
1119
|
-
commandId: command.commandId,
|
|
1120
|
-
details: {
|
|
1121
|
-
behaviorRevisionId: command.behaviorRevisionId,
|
|
1122
|
-
bindingId: command.bindingId,
|
|
1123
|
-
botId: command.botId,
|
|
1124
|
-
executionId: command.executionId,
|
|
1125
|
-
},
|
|
1126
|
-
event: "bot_session_authorized",
|
|
1127
|
-
sessionId: command.sessionId,
|
|
1128
|
-
});
|
|
1129
|
-
outbox.transitionExecution(command.commandId, "running");
|
|
1130
|
-
publisher.recordAttempt(command.sessionId, encodeSessionStartedEvent({
|
|
1131
|
-
attemptId,
|
|
1132
|
-
commandId: command.commandId,
|
|
1133
|
-
kind: SESSION_STARTED_KIND,
|
|
1134
|
-
sessionId: command.sessionId,
|
|
1135
|
-
}), attemptId);
|
|
1136
|
-
activateAttempt();
|
|
1137
|
-
};
|
|
1138
|
-
let stopReason = "steered";
|
|
1139
|
-
if (command.disposition === SessionPromptDisposition.Steer) {
|
|
1140
|
-
startExecution();
|
|
1141
|
-
await sessions.steerPrompt({
|
|
1142
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
1143
|
-
agent: execution.agent,
|
|
1144
|
-
commandId: command.commandId,
|
|
1145
|
-
cwd: resolved.cwd,
|
|
1146
|
-
images: attachments.images,
|
|
1147
|
-
prompt: command.prompt,
|
|
1148
|
-
resources: applied.resources,
|
|
1149
|
-
sessionId: command.sessionId,
|
|
1150
|
-
signal,
|
|
1151
|
-
targetCommandId: command.targetCommandId,
|
|
1152
|
-
});
|
|
1153
|
-
}
|
|
1154
|
-
else {
|
|
1155
|
-
if (command.disposition === SessionPromptDisposition.Queue &&
|
|
1156
|
-
!outbox.isTerminalExecution(command.targetCommandId, command.sessionId)) {
|
|
1157
|
-
throw new AcpExecutionError("The queued Bot prompt target is unavailable", {}, "prompt_queue_target_unavailable");
|
|
1158
|
-
}
|
|
1159
|
-
const lease = contexts.activate(command);
|
|
1160
|
-
try {
|
|
1161
|
-
const agent = botExecutionAgent(execution.agent, lease.context.contextHandle, ipc.socketPath);
|
|
1162
|
-
const prepared = await sessions.prepareExecutionSession({
|
|
1163
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
1164
|
-
agent,
|
|
1165
|
-
cwd: resolved.cwd,
|
|
1166
|
-
sessionId: command.sessionId,
|
|
1167
|
-
signal,
|
|
1168
|
-
});
|
|
1169
|
-
assertPreparedPermission(prepared.configOptions, execution.executionConfiguration.permissionMode);
|
|
1170
|
-
let configOptions = await applySupportedExecutionSelection(sessions, audit, prepared.configOptions, execution.executionConfiguration.model, "model", agent, resolved.cwd, resolved.additionalDirectories, command.commandId, command.sessionId, signal);
|
|
1171
|
-
configOptions = await applySupportedExecutionSelection(sessions, audit, configOptions, execution.executionConfiguration.reasoningEffort, "thought_level", agent, resolved.cwd, resolved.additionalDirectories, command.commandId, command.sessionId, signal);
|
|
1172
|
-
for (const selection of command.sessionConfigurations) {
|
|
1173
|
-
await sessions.configureSession({
|
|
1174
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
1175
|
-
agent,
|
|
1176
|
-
booleanValue: selection.booleanValue,
|
|
1177
|
-
configId: selection.configId,
|
|
1178
|
-
cwd: resolved.cwd,
|
|
1179
|
-
requestId: `cfg_${randomUUID()}`,
|
|
1180
|
-
sessionId: command.sessionId,
|
|
1181
|
-
signal,
|
|
1182
|
-
value: selection.value,
|
|
1183
|
-
valueType: selection.valueType,
|
|
1184
|
-
});
|
|
1185
|
-
}
|
|
1186
|
-
startExecution();
|
|
1187
|
-
const result = await sessions.runPrompt({
|
|
1188
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
1189
|
-
agent,
|
|
1190
|
-
commandId: command.commandId,
|
|
1191
|
-
cwd: resolved.cwd,
|
|
1192
|
-
disposition: command.disposition,
|
|
1193
|
-
images: attachments.images,
|
|
1194
|
-
onActivity: activities.record,
|
|
1195
|
-
onText: (text, messageId) => {
|
|
1196
|
-
publisher.recordAttempt(command.sessionId, encodeAgentMessageDeltaEvent({
|
|
1197
|
-
commandId: command.commandId,
|
|
1198
|
-
kind: AGENT_MESSAGE_DELTA_KIND,
|
|
1199
|
-
messageId,
|
|
1200
|
-
sessionId: command.sessionId,
|
|
1201
|
-
text,
|
|
1202
|
-
}), attemptId);
|
|
1203
|
-
return Promise.resolve();
|
|
1204
|
-
},
|
|
1205
|
-
prompt: command.prompt,
|
|
1206
|
-
resources: applied.resources,
|
|
1207
|
-
sessionId: command.sessionId,
|
|
1208
|
-
signal,
|
|
1209
|
-
targetCommandId: command.targetCommandId,
|
|
1210
|
-
});
|
|
1211
|
-
stopReason = result.stopReason;
|
|
1212
|
-
}
|
|
1213
|
-
finally {
|
|
1214
|
-
lease.release();
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
activities.flush();
|
|
1218
|
-
publisher.recordAttempt(command.sessionId, encodeSessionCompletedEvent({
|
|
1219
|
-
commandId: command.commandId,
|
|
1220
|
-
kind: SESSION_COMPLETED_KIND,
|
|
1221
|
-
sessionId: command.sessionId,
|
|
1222
|
-
stopReason,
|
|
1223
|
-
}), attemptId);
|
|
1224
|
-
outbox.transitionExecution(command.commandId, stopReason === "cancelled" ? "cancelled" : "succeeded");
|
|
1225
|
-
audit.record({
|
|
1226
|
-
commandId: command.commandId,
|
|
1227
|
-
details: { botId: command.botId, executionId: command.executionId },
|
|
1228
|
-
event: stopReason === "cancelled" ? "bot_session_cancelled" : "bot_session_completed",
|
|
1229
|
-
sessionId: command.sessionId,
|
|
1230
|
-
});
|
|
1231
|
-
}
|
|
1232
|
-
catch (error) {
|
|
1233
|
-
activities.flush();
|
|
1234
|
-
const failure = error;
|
|
1235
|
-
audit.record({
|
|
1236
|
-
commandId: command.commandId,
|
|
1237
|
-
details: {
|
|
1238
|
-
botId: command.botId,
|
|
1239
|
-
code: operationErrorCode(failure),
|
|
1240
|
-
executionId: command.executionId,
|
|
1241
|
-
},
|
|
1242
|
-
event: "bot_session_failed",
|
|
1243
|
-
sessionId: command.sessionId,
|
|
1244
|
-
});
|
|
1245
|
-
const code = operationErrorCode(failure);
|
|
1246
|
-
reportFailure(publisher, command, code === "session_operation_failed" ? "agent_execution_failed" : code, code === "session_operation_failed"
|
|
1247
|
-
? "The local agent could not complete the Bot request"
|
|
1248
|
-
: operationErrorMessage(failure), attemptId);
|
|
1249
|
-
outbox.transitionExecution(command.commandId, "failed");
|
|
1250
|
-
console.error("Mobius daemon Bot command failed", failure);
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
1038
|
function waitForRelayRetry(signal, timer) {
|
|
1254
1039
|
if (signal.aborted) {
|
|
1255
1040
|
return Promise.resolve();
|
|
@@ -1301,7 +1086,7 @@ async function installDetectedAgentIntegrations(config, installations, signal) {
|
|
|
1301
1086
|
}, signal);
|
|
1302
1087
|
}
|
|
1303
1088
|
}
|
|
1304
|
-
async function runRelayConnection(config, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher,
|
|
1089
|
+
async function runRelayConnection(config, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher, activeTurns, activeAttemptIds, connectionEpoch, diagnostics, onConnected, signal, timer) {
|
|
1305
1090
|
const relayUrl = new URL(config.relayUrl);
|
|
1306
1091
|
relayUrl.searchParams.set("deliveryReceipts", "1");
|
|
1307
1092
|
relayUrl.searchParams.set("liveness", "1");
|
|
@@ -1455,11 +1240,6 @@ async function runRelayConnection(config, directories, audit, sessions, installa
|
|
|
1455
1240
|
}
|
|
1456
1241
|
return;
|
|
1457
1242
|
}
|
|
1458
|
-
if (kind === BOT_SESSION_PROMPT_KIND) {
|
|
1459
|
-
const command = decodeBotSessionPromptCommand(delivery.payload);
|
|
1460
|
-
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));
|
|
1461
|
-
return;
|
|
1462
|
-
}
|
|
1463
1243
|
if (kind === SESSION_PROMPT_KIND) {
|
|
1464
1244
|
const command = decodeSessionPromptCommand(delivery.payload);
|
|
1465
1245
|
await processDeliveredPrompt(delivery, command, command.disposition !== SessionPromptDisposition.Steer, (attemptId, activateAttempt, executionSignal) => executePrompt(outbox, publisher, command, config, directories, audit, sessions, attemptId, activateAttempt, timer, executionSignal));
|
|
@@ -1503,9 +1283,6 @@ async function runRelayConnection(config, directories, audit, sessions, installa
|
|
|
1503
1283
|
else if (payloadKind === SESSION_PROMPT_KIND) {
|
|
1504
1284
|
payloadSessionId = decodeSessionPromptCommand(delivery.payload).sessionId;
|
|
1505
1285
|
}
|
|
1506
|
-
else if (payloadKind === BOT_SESSION_PROMPT_KIND) {
|
|
1507
|
-
payloadSessionId = decodeBotSessionPromptCommand(delivery.payload).sessionId;
|
|
1508
|
-
}
|
|
1509
1286
|
else {
|
|
1510
1287
|
throw new Error("Runtime delivery contains an unsupported protocol message");
|
|
1511
1288
|
}
|
|
@@ -1817,6 +1594,22 @@ async function runRelayConnection(config, directories, audit, sessions, installa
|
|
|
1817
1594
|
connectionLiveness.acknowledge(decodeRuntimeHeartbeatAckEvent(encoded));
|
|
1818
1595
|
return;
|
|
1819
1596
|
}
|
|
1597
|
+
if (kind === FILE_READ_KIND) {
|
|
1598
|
+
const command = decodeFileReadCommand(encoded);
|
|
1599
|
+
void streamLocalFile(command, (message) => send(socket, message), connectionController.signal).catch((error) => {
|
|
1600
|
+
if (socket.readyState !== WebSocket.OPEN || connectionController.signal.aborted) {
|
|
1601
|
+
return;
|
|
1602
|
+
}
|
|
1603
|
+
send(socket, encodeFileFailedEvent({
|
|
1604
|
+
code: "file_unavailable",
|
|
1605
|
+
kind: FILE_FAILED_KIND,
|
|
1606
|
+
message: error instanceof Error ? error.message : "The local file is unavailable",
|
|
1607
|
+
requestId: command.requestId,
|
|
1608
|
+
sessionId: command.sessionId,
|
|
1609
|
+
}));
|
|
1610
|
+
});
|
|
1611
|
+
return;
|
|
1612
|
+
}
|
|
1820
1613
|
if (kind === SESSION_CANCEL_KIND) {
|
|
1821
1614
|
const cancellation = decodeSessionCancelCommand(encoded);
|
|
1822
1615
|
const turn = activeTurns.get(cancellation.commandId);
|
|
@@ -1898,34 +1691,6 @@ async function runRelayConnection(config, directories, audit, sessions, installa
|
|
|
1898
1691
|
});
|
|
1899
1692
|
return;
|
|
1900
1693
|
}
|
|
1901
|
-
if (kind === BOT_SESSION_PROMPT_KIND) {
|
|
1902
|
-
const command = decodeBotSessionPromptCommand(encoded);
|
|
1903
|
-
if (activeTurns.has(command.commandId)) {
|
|
1904
|
-
return;
|
|
1905
|
-
}
|
|
1906
|
-
const receipt = outbox.claimExecution(command.commandId, command.sessionId, encoded);
|
|
1907
|
-
if (receipt.kind === "duplicate") {
|
|
1908
|
-
return;
|
|
1909
|
-
}
|
|
1910
|
-
const turn = new ActiveDaemonTurn(command, receipt.attemptId);
|
|
1911
|
-
activeTurns.set(command.commandId, turn);
|
|
1912
|
-
void executeBotPrompt(outbox, publisher, command, config, directories, audit, sessions, authorizer, contexts, applicator, ipc, receipt.attemptId, () => {
|
|
1913
|
-
if (command.disposition !== SessionPromptDisposition.Steer) {
|
|
1914
|
-
activeAttemptIds.set(command.sessionId, receipt.attemptId);
|
|
1915
|
-
}
|
|
1916
|
-
}, timer, turn.signal)
|
|
1917
|
-
.catch((error) => {
|
|
1918
|
-
console.error("Mobius daemon Bot turn failed", error);
|
|
1919
|
-
})
|
|
1920
|
-
.finally(() => {
|
|
1921
|
-
activeTurns.delete(command.commandId);
|
|
1922
|
-
if (activeAttemptIds.get(command.sessionId) === receipt.attemptId) {
|
|
1923
|
-
activeAttemptIds.delete(command.sessionId);
|
|
1924
|
-
}
|
|
1925
|
-
turn.finish();
|
|
1926
|
-
});
|
|
1927
|
-
return;
|
|
1928
|
-
}
|
|
1929
1694
|
if (kind !== SESSION_PROMPT_KIND) {
|
|
1930
1695
|
throw new Error("Unsupported protocol message");
|
|
1931
1696
|
}
|
|
@@ -1995,23 +1760,19 @@ async function runRelayConnection(config, directories, audit, sessions, installa
|
|
|
1995
1760
|
}
|
|
1996
1761
|
export async function runDaemon(config, audit, signal, timer = systemDaemonTimer) {
|
|
1997
1762
|
const installationAudit = new AuditInstallationEvents(audit);
|
|
1998
|
-
const stateDirectory =
|
|
1763
|
+
const stateDirectory = config.localContext.stateDirectory;
|
|
1999
1764
|
const specifications = supportedLocalAgentSpecifications();
|
|
2000
1765
|
const installationExecutor = new FixedInstallationExecutor({
|
|
2001
1766
|
defaultWorkspace: config.defaultWorkspace,
|
|
2002
1767
|
audit: installationAudit,
|
|
2003
1768
|
catalog: config.catalog,
|
|
2004
|
-
environment:
|
|
1769
|
+
environment: config.localContext.environment,
|
|
2005
1770
|
publishCatalog: async (installationSignal) => await publishAgentCatalog(config, installationSignal),
|
|
2006
1771
|
stateDirectory,
|
|
2007
1772
|
});
|
|
2008
1773
|
const sessionStore = new SqliteAcpSessionStore(config.auditDatabasePath);
|
|
2009
1774
|
const outbox = new SessionEventOutbox(config.auditDatabasePath);
|
|
2010
1775
|
const publisher = new DaemonSessionEventPublisher(outbox, timer);
|
|
2011
|
-
const authorizer = new LocalBotExecutionAuthorizer();
|
|
2012
|
-
const contexts = new BotExecutionContextRegistry();
|
|
2013
|
-
const applicator = new EmbeddedBotContextApplicator();
|
|
2014
|
-
const ipc = new BotOutboundIpcServer(botIpcSocketPath(), config.relayUrl, contexts);
|
|
2015
1776
|
const activeTurns = new Map();
|
|
2016
1777
|
const activeAttemptIds = new Map();
|
|
2017
1778
|
const recordSessionEvent = (sessionId, payload) => {
|
|
@@ -2057,9 +1818,9 @@ export async function runDaemon(config, audit, signal, timer = systemDaemonTimer
|
|
|
2057
1818
|
return;
|
|
2058
1819
|
}
|
|
2059
1820
|
connectionAnnounced = true;
|
|
2060
|
-
const reconnectCommand = `npx --yes @moxt-ai/mobius start
|
|
1821
|
+
const reconnectCommand = `npx --yes @moxt-ai/mobius start ${config.reconnectTarget.commandArgument}`;
|
|
2061
1822
|
process.stdout.write("Mobius daemon connected to the relay.\n\n");
|
|
2062
|
-
process.stdout.write(`${styleText(["bold", "yellow"], `Reconnect this
|
|
1823
|
+
process.stdout.write(`${styleText(["bold", "yellow"], `Reconnect this local connection later:\n ${reconnectCommand}`)}\n\n`);
|
|
2063
1824
|
announceReadiness();
|
|
2064
1825
|
startAutomaticIntegrationProvisioning();
|
|
2065
1826
|
};
|
|
@@ -2073,11 +1834,10 @@ export async function runDaemon(config, audit, signal, timer = systemDaemonTimer
|
|
|
2073
1834
|
startAutomaticIntegrationProvisioning();
|
|
2074
1835
|
});
|
|
2075
1836
|
try {
|
|
2076
|
-
await ipc.listen(signal);
|
|
2077
1837
|
while (!signal.aborted) {
|
|
2078
1838
|
connectionEpoch += 1;
|
|
2079
1839
|
try {
|
|
2080
|
-
await runRelayConnection(config, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher,
|
|
1840
|
+
await runRelayConnection(config, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher, activeTurns, activeAttemptIds, connectionEpoch, diagnostics, announceConnection, signal, timer);
|
|
2081
1841
|
}
|
|
2082
1842
|
catch (error) {
|
|
2083
1843
|
if (signal.aborted) {
|
|
@@ -2107,23 +1867,18 @@ export async function runDaemon(config, audit, signal, timer = systemDaemonTimer
|
|
|
2107
1867
|
}
|
|
2108
1868
|
finally {
|
|
2109
1869
|
try {
|
|
2110
|
-
await
|
|
1870
|
+
await sessions.close();
|
|
2111
1871
|
}
|
|
2112
1872
|
finally {
|
|
2113
1873
|
try {
|
|
2114
|
-
|
|
1874
|
+
sessionStore.close();
|
|
2115
1875
|
}
|
|
2116
1876
|
finally {
|
|
2117
1877
|
try {
|
|
2118
|
-
|
|
1878
|
+
publisher.close();
|
|
2119
1879
|
}
|
|
2120
1880
|
finally {
|
|
2121
|
-
|
|
2122
|
-
publisher.close();
|
|
2123
|
-
}
|
|
2124
|
-
finally {
|
|
2125
|
-
outbox.close();
|
|
2126
|
-
}
|
|
1881
|
+
outbox.close();
|
|
2127
1882
|
}
|
|
2128
1883
|
}
|
|
2129
1884
|
}
|