@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/runtime.js
CHANGED
|
@@ -5,8 +5,8 @@ var __export = (target, all2) => {
|
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
// src/runtime.ts
|
|
8
|
-
import { mkdir as
|
|
9
|
-
import { dirname as
|
|
8
|
+
import { mkdir as mkdir4, realpath as realpath10, stat as stat9 } from "node:fs/promises";
|
|
9
|
+
import { dirname as dirname7, join as join17, resolve as resolve5 } from "node:path";
|
|
10
10
|
|
|
11
11
|
// src/agent-catalog/local-agent.ts
|
|
12
12
|
import { realpathSync, statSync } from "node:fs";
|
|
@@ -78,12 +78,12 @@ var ExecutableIdentity = class {
|
|
|
78
78
|
realPath;
|
|
79
79
|
requestedPath;
|
|
80
80
|
size;
|
|
81
|
-
constructor(
|
|
81
|
+
constructor(requestedPath2, realPath_, device, inode, size, changedAtMilliseconds) {
|
|
82
82
|
this.changedAtMilliseconds = changedAtMilliseconds;
|
|
83
83
|
this.device = device;
|
|
84
84
|
this.inode = inode;
|
|
85
85
|
this.realPath = realPath_;
|
|
86
|
-
this.requestedPath =
|
|
86
|
+
this.requestedPath = requestedPath2;
|
|
87
87
|
this.size = size;
|
|
88
88
|
}
|
|
89
89
|
matches = (candidate) => this.requestedPath === candidate.requestedPath && this.realPath === candidate.realPath && this.device === candidate.device && this.inode === candidate.inode && this.size === candidate.size && this.changedAtMilliseconds === candidate.changedAtMilliseconds;
|
|
@@ -123,8 +123,8 @@ function executableExtensions(executableName, environment, platform) {
|
|
|
123
123
|
const extensions = configured.split(";").map((extension2) => extension2.trim()).filter((extension2) => extension2.length > 0).map((extension2) => extension2.startsWith(".") ? extension2 : `.${extension2}`);
|
|
124
124
|
return extensions.length > 0 ? extensions : [".EXE"];
|
|
125
125
|
}
|
|
126
|
-
async function resolveExecutablePath(
|
|
127
|
-
const absoluteRequestedPath = resolve(
|
|
126
|
+
async function resolveExecutablePath(requestedPath2, platform = process.platform) {
|
|
127
|
+
const absoluteRequestedPath = resolve(requestedPath2);
|
|
128
128
|
try {
|
|
129
129
|
const resolvedPath = await realpath(absoluteRequestedPath);
|
|
130
130
|
const metadata = await stat(resolvedPath);
|
|
@@ -157,8 +157,8 @@ async function findExecutableOnPath(executableName, environment, platform = proc
|
|
|
157
157
|
continue;
|
|
158
158
|
}
|
|
159
159
|
for (const extension2 of extensions) {
|
|
160
|
-
const
|
|
161
|
-
const executable = await resolveExecutablePath(
|
|
160
|
+
const requestedPath2 = resolve(join(entry, `${executableName}${extension2}`));
|
|
161
|
+
const executable = await resolveExecutablePath(requestedPath2, platform);
|
|
162
162
|
if (executable !== null) {
|
|
163
163
|
return executable;
|
|
164
164
|
}
|
|
@@ -20364,6 +20364,11 @@ var AGENT_INSTALL_CANCELLED_KIND = "agent.integration.install.cancelled";
|
|
|
20364
20364
|
var AGENT_SETTINGS_DISCOVER_KIND = "agent.settings.discover";
|
|
20365
20365
|
var AGENT_SETTINGS_DISCOVERED_KIND = "agent.settings.discovered";
|
|
20366
20366
|
var AGENT_SETTINGS_DISCOVERY_FAILED_KIND = "agent.settings.discovery.failed";
|
|
20367
|
+
var FILE_READ_KIND = "file.read";
|
|
20368
|
+
var FILE_BEGIN_KIND = "file.begin";
|
|
20369
|
+
var FILE_CHUNK_KIND = "file.chunk";
|
|
20370
|
+
var FILE_END_KIND = "file.end";
|
|
20371
|
+
var FILE_FAILED_KIND = "file.failed";
|
|
20367
20372
|
var IDENTIFIER_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
20368
20373
|
var DIRECTORY_IDENTIFIER_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/;
|
|
20369
20374
|
var IDENTIFIER = external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN);
|
|
@@ -20374,6 +20379,41 @@ var workspaceEntrySchema = external_exports.strictObject({
|
|
|
20374
20379
|
directoryId: DIRECTORY_IDENTIFIER,
|
|
20375
20380
|
name: external_exports.string().min(1).max(255)
|
|
20376
20381
|
}).readonly();
|
|
20382
|
+
var fileReadCommandSchema = external_exports.strictObject({
|
|
20383
|
+
kind: external_exports.literal(FILE_READ_KIND),
|
|
20384
|
+
maxBytes: external_exports.number().int().positive().max(128 * 1024 * 1024),
|
|
20385
|
+
requestId: IDENTIFIER,
|
|
20386
|
+
sessionId: IDENTIFIER,
|
|
20387
|
+
path: external_exports.string().min(1).max(4096)
|
|
20388
|
+
}).readonly();
|
|
20389
|
+
var fileBeginEventSchema = external_exports.strictObject({
|
|
20390
|
+
byteLength: external_exports.number().int().positive().max(128 * 1024 * 1024),
|
|
20391
|
+
kind: external_exports.literal(FILE_BEGIN_KIND),
|
|
20392
|
+
mediaType: external_exports.string().min(1).max(255),
|
|
20393
|
+
modifiedAt: external_exports.iso.datetime({ offset: true }),
|
|
20394
|
+
name: external_exports.string().min(1).max(500),
|
|
20395
|
+
requestId: IDENTIFIER,
|
|
20396
|
+
sessionId: IDENTIFIER
|
|
20397
|
+
}).readonly();
|
|
20398
|
+
var fileChunkEventSchema = external_exports.strictObject({
|
|
20399
|
+
data: external_exports.string().min(1).max(4e5),
|
|
20400
|
+
kind: external_exports.literal(FILE_CHUNK_KIND),
|
|
20401
|
+
requestId: IDENTIFIER,
|
|
20402
|
+
sequence: external_exports.number().int().nonnegative().max(1024),
|
|
20403
|
+
sessionId: IDENTIFIER
|
|
20404
|
+
}).readonly();
|
|
20405
|
+
var fileEndEventSchema = external_exports.strictObject({
|
|
20406
|
+
kind: external_exports.literal(FILE_END_KIND),
|
|
20407
|
+
requestId: IDENTIFIER,
|
|
20408
|
+
sessionId: IDENTIFIER
|
|
20409
|
+
}).readonly();
|
|
20410
|
+
var fileFailedEventSchema = external_exports.strictObject({
|
|
20411
|
+
code: IDENTIFIER,
|
|
20412
|
+
kind: external_exports.literal(FILE_FAILED_KIND),
|
|
20413
|
+
message: external_exports.string().min(1).max(500),
|
|
20414
|
+
requestId: IDENTIFIER,
|
|
20415
|
+
sessionId: IDENTIFIER
|
|
20416
|
+
}).readonly();
|
|
20377
20417
|
var configValueSchema = external_exports.strictObject({
|
|
20378
20418
|
description: SHORT_TEXT,
|
|
20379
20419
|
groupId: external_exports.string().max(128),
|
|
@@ -20590,7 +20630,7 @@ var sessionPrepareCommandSchema = external_exports.strictObject({
|
|
|
20590
20630
|
kind: external_exports.literal(SESSION_PREPARE_KIND),
|
|
20591
20631
|
requestId: IDENTIFIER,
|
|
20592
20632
|
sessionState: external_exports.literal("provisioned").optional(),
|
|
20593
|
-
/**
|
|
20633
|
+
/** Marks an inspection-only Session preparation. */
|
|
20594
20634
|
transient: external_exports.boolean().optional()
|
|
20595
20635
|
}).superRefine((command, context) => {
|
|
20596
20636
|
if (command.transient === true && command.sessionState === "provisioned") {
|
|
@@ -20811,11 +20851,15 @@ var decodeRecordedAgentContentValue = (value) => decodeValue(value, recordedDisp
|
|
|
20811
20851
|
var decodePromptImagesValue = (value) => decodeValue(value, external_exports.array(promptImageSchema).max(8).readonly());
|
|
20812
20852
|
var decodePromptResourcesValue = (value) => decodeValue(value, external_exports.array(promptResourceSchema).max(16).readonly());
|
|
20813
20853
|
var decodeSessionConfigurationSelections = (value) => decodeValue(value, sessionConfigurationSelectionsSchema);
|
|
20814
|
-
var decodeAgentExecutionConfiguration = (value) => decodeValue(value, agentExecutionConfigurationSchema);
|
|
20815
20854
|
var encode3 = (message, schema) => JSON.stringify(decodeValue(message, schema));
|
|
20816
20855
|
var decodeAgentSettingsDiscoverCommand = (encoded) => decode3(encoded, agentSettingsDiscoverCommandSchema);
|
|
20817
20856
|
var encodeAgentSettingsDiscoveredEvent = (message) => encode3(message, agentSettingsDiscoveredEventSchema);
|
|
20818
20857
|
var encodeAgentSettingsDiscoveryFailedEvent = (message) => encode3(message, agentSettingsDiscoveryFailedEventSchema);
|
|
20858
|
+
var decodeFileReadCommand = (encoded) => decode3(encoded, fileReadCommandSchema);
|
|
20859
|
+
var encodeFileBeginEvent = (message) => encode3(message, fileBeginEventSchema);
|
|
20860
|
+
var encodeFileChunkEvent = (message) => encode3(message, fileChunkEventSchema);
|
|
20861
|
+
var encodeFileEndEvent = (message) => encode3(message, fileEndEventSchema);
|
|
20862
|
+
var encodeFileFailedEvent = (message) => encode3(message, fileFailedEventSchema);
|
|
20819
20863
|
var decodeWorkspaceListCommand = (encoded) => decode3(encoded, workspaceListCommandSchema);
|
|
20820
20864
|
var encodeWorkspaceEntriesEvent = (message) => encode3(message, workspaceEntriesEventSchema);
|
|
20821
20865
|
var decodeSessionPrepareCommand = (encoded) => decode3(encoded, sessionPrepareCommandSchema);
|
|
@@ -21295,325 +21339,6 @@ function encodeSessionFailedEvent(message) {
|
|
|
21295
21339
|
return JSON.stringify(decodeSessionFailedEvent(JSON.stringify(message)));
|
|
21296
21340
|
}
|
|
21297
21341
|
|
|
21298
|
-
// ../protocol/src/bot.ts
|
|
21299
|
-
var BOT_SESSION_PROMPT_KIND = "bot.session.prompt";
|
|
21300
|
-
var IDENTIFIER_PATTERN3 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
21301
|
-
var DIRECTORY_IDENTIFIER_PATTERN3 = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/;
|
|
21302
|
-
var TOKEN_PATTERN = /^[a-zA-Z0-9_-]{32,256}$/;
|
|
21303
|
-
var SHA256_PATTERN = /^[a-f0-9]{64}$/;
|
|
21304
|
-
var MAX_INSTRUCTIONS_LENGTH = 1e5;
|
|
21305
|
-
var BotDeliveryTargetReference = class {
|
|
21306
|
-
alias;
|
|
21307
|
-
deliveryTargetId;
|
|
21308
|
-
constructor(alias, deliveryTargetId) {
|
|
21309
|
-
this.alias = alias;
|
|
21310
|
-
this.deliveryTargetId = deliveryTargetId;
|
|
21311
|
-
}
|
|
21312
|
-
};
|
|
21313
|
-
var BotReplyRoute = class {
|
|
21314
|
-
};
|
|
21315
|
-
var OwnerBotReplyRoute = class extends BotReplyRoute {
|
|
21316
|
-
kind = "owner";
|
|
21317
|
-
};
|
|
21318
|
-
var BotConnectionReplyRoute = class extends BotReplyRoute {
|
|
21319
|
-
connectionId;
|
|
21320
|
-
deliveryTargetId;
|
|
21321
|
-
kind = "connection";
|
|
21322
|
-
constructor(connectionId, deliveryTargetId) {
|
|
21323
|
-
super();
|
|
21324
|
-
this.connectionId = connectionId;
|
|
21325
|
-
this.deliveryTargetId = deliveryTargetId;
|
|
21326
|
-
}
|
|
21327
|
-
};
|
|
21328
|
-
var BotSessionPromptCommand = class {
|
|
21329
|
-
additionalDirectoryIds;
|
|
21330
|
-
agentId;
|
|
21331
|
-
allowedDeliveryTargets;
|
|
21332
|
-
behaviorDigest;
|
|
21333
|
-
behaviorInstructions;
|
|
21334
|
-
behaviorRevisionId;
|
|
21335
|
-
bindingId;
|
|
21336
|
-
bindingRevision;
|
|
21337
|
-
botId;
|
|
21338
|
-
commandId;
|
|
21339
|
-
conversationId;
|
|
21340
|
-
directoryId;
|
|
21341
|
-
disposition;
|
|
21342
|
-
executionCapabilityId;
|
|
21343
|
-
executionCapabilitySecret;
|
|
21344
|
-
executionDeadlineAt;
|
|
21345
|
-
executionId;
|
|
21346
|
-
executionConfiguration;
|
|
21347
|
-
images;
|
|
21348
|
-
kind = BOT_SESSION_PROMPT_KIND;
|
|
21349
|
-
prompt;
|
|
21350
|
-
replyRoute;
|
|
21351
|
-
resources;
|
|
21352
|
-
sessionConfigurations;
|
|
21353
|
-
sessionId;
|
|
21354
|
-
targetCommandId;
|
|
21355
|
-
turnId;
|
|
21356
|
-
constructor(sessionId, commandId, agentId, bindingId, directoryId2, additionalDirectoryIds, images, resources, prompt, executionId, executionCapabilityId, executionCapabilitySecret, executionDeadlineAt, botId, conversationId, turnId, behaviorRevisionId, bindingRevision, behaviorInstructions, behaviorDigest, allowedDeliveryTargets, replyRoute, executionConfiguration, sessionConfigurations = [], disposition = SessionPromptDisposition.Reject, targetCommandId = "") {
|
|
21357
|
-
this.sessionId = sessionId;
|
|
21358
|
-
this.commandId = commandId;
|
|
21359
|
-
this.agentId = agentId;
|
|
21360
|
-
this.bindingId = bindingId;
|
|
21361
|
-
this.directoryId = directoryId2;
|
|
21362
|
-
this.disposition = disposition;
|
|
21363
|
-
this.additionalDirectoryIds = Object.freeze([...additionalDirectoryIds]);
|
|
21364
|
-
this.images = Object.freeze([...images]);
|
|
21365
|
-
this.resources = Object.freeze([...resources]);
|
|
21366
|
-
this.prompt = prompt;
|
|
21367
|
-
this.executionId = executionId;
|
|
21368
|
-
this.executionCapabilityId = executionCapabilityId;
|
|
21369
|
-
this.executionCapabilitySecret = executionCapabilitySecret;
|
|
21370
|
-
this.executionDeadlineAt = executionDeadlineAt;
|
|
21371
|
-
this.botId = botId;
|
|
21372
|
-
this.conversationId = conversationId;
|
|
21373
|
-
this.turnId = turnId;
|
|
21374
|
-
this.behaviorRevisionId = behaviorRevisionId;
|
|
21375
|
-
this.bindingRevision = bindingRevision;
|
|
21376
|
-
this.behaviorInstructions = behaviorInstructions;
|
|
21377
|
-
this.behaviorDigest = behaviorDigest;
|
|
21378
|
-
this.allowedDeliveryTargets = Object.freeze(
|
|
21379
|
-
allowedDeliveryTargets.map(
|
|
21380
|
-
(target) => new BotDeliveryTargetReference(target.alias, target.deliveryTargetId)
|
|
21381
|
-
)
|
|
21382
|
-
);
|
|
21383
|
-
this.replyRoute = replyRoute;
|
|
21384
|
-
this.executionConfiguration = decodeAgentExecutionConfiguration(executionConfiguration);
|
|
21385
|
-
this.sessionConfigurations = Object.freeze([...sessionConfigurations]);
|
|
21386
|
-
this.targetCommandId = targetCommandId;
|
|
21387
|
-
}
|
|
21388
|
-
toJSON() {
|
|
21389
|
-
const { disposition, sessionConfigurations, targetCommandId, ...command } = this;
|
|
21390
|
-
return {
|
|
21391
|
-
...command,
|
|
21392
|
-
...sessionConfigurations.length === 0 ? {} : { sessionConfigurations },
|
|
21393
|
-
...disposition === SessionPromptDisposition.Reject ? {} : { disposition, targetCommandId }
|
|
21394
|
-
};
|
|
21395
|
-
}
|
|
21396
|
-
};
|
|
21397
|
-
function isRecord3(value) {
|
|
21398
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21399
|
-
}
|
|
21400
|
-
function parseJson3(encoded) {
|
|
21401
|
-
let value;
|
|
21402
|
-
try {
|
|
21403
|
-
value = JSON.parse(encoded);
|
|
21404
|
-
} catch (cause) {
|
|
21405
|
-
throw new ProtocolMessageError("Message is not valid JSON", { cause });
|
|
21406
|
-
}
|
|
21407
|
-
if (!isRecord3(value)) {
|
|
21408
|
-
throw new ProtocolMessageError("Message must be a JSON object");
|
|
21409
|
-
}
|
|
21410
|
-
return value;
|
|
21411
|
-
}
|
|
21412
|
-
function assertExactKeys2(value, expected) {
|
|
21413
|
-
const keys = Object.keys(value);
|
|
21414
|
-
if (keys.length !== expected.length || keys.some((key) => !expected.includes(key))) {
|
|
21415
|
-
throw new ProtocolMessageError("Message fields do not match the Bot protocol");
|
|
21416
|
-
}
|
|
21417
|
-
}
|
|
21418
|
-
function assertKeysWithOptional(value, expected, optional2) {
|
|
21419
|
-
const keys = Object.keys(value);
|
|
21420
|
-
if (keys.length < expected.length || keys.length > expected.length + optional2.length || expected.some((key) => !Object.hasOwn(value, key)) || keys.some((key) => !expected.includes(key) && !optional2.includes(key))) {
|
|
21421
|
-
throw new ProtocolMessageError("Message fields do not match the Bot protocol");
|
|
21422
|
-
}
|
|
21423
|
-
}
|
|
21424
|
-
function readText2(value, key, maximumLength, allowEmpty) {
|
|
21425
|
-
const field = value[key];
|
|
21426
|
-
if (typeof field !== "string" || field.length > maximumLength || !allowEmpty && field.length === 0) {
|
|
21427
|
-
throw new ProtocolMessageError(`Invalid Bot protocol field: ${key}`);
|
|
21428
|
-
}
|
|
21429
|
-
return field;
|
|
21430
|
-
}
|
|
21431
|
-
function readIdentifier2(value, key) {
|
|
21432
|
-
const field = readText2(value, key, 128, false);
|
|
21433
|
-
if (!IDENTIFIER_PATTERN3.test(field)) {
|
|
21434
|
-
throw new ProtocolMessageError(`Invalid Bot identifier field: ${key}`);
|
|
21435
|
-
}
|
|
21436
|
-
return field;
|
|
21437
|
-
}
|
|
21438
|
-
function readDirectoryIdentifier2(value, key) {
|
|
21439
|
-
const field = readText2(value, key, 2048, false);
|
|
21440
|
-
if (!DIRECTORY_IDENTIFIER_PATTERN3.test(field)) {
|
|
21441
|
-
throw new ProtocolMessageError(`Invalid Bot directory field: ${key}`);
|
|
21442
|
-
}
|
|
21443
|
-
return field;
|
|
21444
|
-
}
|
|
21445
|
-
function readInteger(value, key) {
|
|
21446
|
-
const field = value[key];
|
|
21447
|
-
if (typeof field !== "number" || !Number.isSafeInteger(field) || field < 1) {
|
|
21448
|
-
throw new ProtocolMessageError(`Invalid Bot integer field: ${key}`);
|
|
21449
|
-
}
|
|
21450
|
-
return field;
|
|
21451
|
-
}
|
|
21452
|
-
function readTimestamp(value, key) {
|
|
21453
|
-
const field = readText2(value, key, 64, false);
|
|
21454
|
-
if (Number.isNaN(Date.parse(field))) {
|
|
21455
|
-
throw new ProtocolMessageError(`Invalid Bot timestamp field: ${key}`);
|
|
21456
|
-
}
|
|
21457
|
-
return field;
|
|
21458
|
-
}
|
|
21459
|
-
function readDigest(value, key) {
|
|
21460
|
-
const field = readText2(value, key, 64, false);
|
|
21461
|
-
if (!SHA256_PATTERN.test(field)) {
|
|
21462
|
-
throw new ProtocolMessageError(`Invalid Bot digest field: ${key}`);
|
|
21463
|
-
}
|
|
21464
|
-
return field;
|
|
21465
|
-
}
|
|
21466
|
-
function readToken(value, key) {
|
|
21467
|
-
const field = readText2(value, key, 256, false);
|
|
21468
|
-
if (!TOKEN_PATTERN.test(field)) {
|
|
21469
|
-
throw new ProtocolMessageError(`Invalid Bot token field: ${key}`);
|
|
21470
|
-
}
|
|
21471
|
-
return field;
|
|
21472
|
-
}
|
|
21473
|
-
function readIdentifiers(value, key, maximumCount) {
|
|
21474
|
-
const field = value[key];
|
|
21475
|
-
if (!Array.isArray(field) || field.length > maximumCount) {
|
|
21476
|
-
throw new ProtocolMessageError(`Invalid Bot identifier list: ${key}`);
|
|
21477
|
-
}
|
|
21478
|
-
const identifiers = [];
|
|
21479
|
-
const unique = /* @__PURE__ */ new Set();
|
|
21480
|
-
for (const candidate of field) {
|
|
21481
|
-
if (typeof candidate !== "string" || !IDENTIFIER_PATTERN3.test(candidate) || unique.has(candidate)) {
|
|
21482
|
-
throw new ProtocolMessageError(`Invalid Bot identifier list: ${key}`);
|
|
21483
|
-
}
|
|
21484
|
-
unique.add(candidate);
|
|
21485
|
-
identifiers.push(candidate);
|
|
21486
|
-
}
|
|
21487
|
-
return Object.freeze(identifiers);
|
|
21488
|
-
}
|
|
21489
|
-
function readTargets(value, key) {
|
|
21490
|
-
const field = value[key];
|
|
21491
|
-
if (!Array.isArray(field) || field.length > 64) {
|
|
21492
|
-
throw new ProtocolMessageError(`Invalid Bot delivery targets: ${key}`);
|
|
21493
|
-
}
|
|
21494
|
-
const targets = [];
|
|
21495
|
-
const identifiers = /* @__PURE__ */ new Set();
|
|
21496
|
-
const aliases = /* @__PURE__ */ new Set();
|
|
21497
|
-
for (const candidate of field) {
|
|
21498
|
-
if (!isRecord3(candidate)) {
|
|
21499
|
-
throw new ProtocolMessageError(`Invalid Bot delivery targets: ${key}`);
|
|
21500
|
-
}
|
|
21501
|
-
assertExactKeys2(candidate, ["alias", "deliveryTargetId"]);
|
|
21502
|
-
const alias = readIdentifier2(candidate, "alias");
|
|
21503
|
-
const deliveryTargetId = readIdentifier2(candidate, "deliveryTargetId");
|
|
21504
|
-
if (aliases.has(alias) || identifiers.has(deliveryTargetId)) {
|
|
21505
|
-
throw new ProtocolMessageError(`Duplicate Bot delivery target: ${key}`);
|
|
21506
|
-
}
|
|
21507
|
-
aliases.add(alias);
|
|
21508
|
-
identifiers.add(deliveryTargetId);
|
|
21509
|
-
targets.push(new BotDeliveryTargetReference(alias, deliveryTargetId));
|
|
21510
|
-
}
|
|
21511
|
-
return Object.freeze(targets);
|
|
21512
|
-
}
|
|
21513
|
-
function readSessionConfigurations(value) {
|
|
21514
|
-
if (!Object.hasOwn(value, "sessionConfigurations")) {
|
|
21515
|
-
return [];
|
|
21516
|
-
}
|
|
21517
|
-
return decodeSessionConfigurationSelections(value["sessionConfigurations"]);
|
|
21518
|
-
}
|
|
21519
|
-
function readReplyRoute(value) {
|
|
21520
|
-
if (!isRecord3(value)) {
|
|
21521
|
-
throw new ProtocolMessageError("Invalid Bot reply route");
|
|
21522
|
-
}
|
|
21523
|
-
const kind = readText2(value, "kind", 32, false);
|
|
21524
|
-
if (kind === "owner") {
|
|
21525
|
-
assertExactKeys2(value, ["kind"]);
|
|
21526
|
-
return new OwnerBotReplyRoute();
|
|
21527
|
-
}
|
|
21528
|
-
if (kind === "connection") {
|
|
21529
|
-
assertExactKeys2(value, ["connectionId", "deliveryTargetId", "kind"]);
|
|
21530
|
-
return new BotConnectionReplyRoute(
|
|
21531
|
-
readIdentifier2(value, "connectionId"),
|
|
21532
|
-
readIdentifier2(value, "deliveryTargetId")
|
|
21533
|
-
);
|
|
21534
|
-
}
|
|
21535
|
-
throw new ProtocolMessageError("Invalid Bot reply route");
|
|
21536
|
-
}
|
|
21537
|
-
function decodeBotSessionPromptCommand(encoded) {
|
|
21538
|
-
const value = parseJson3(encoded);
|
|
21539
|
-
assertKeysWithOptional(
|
|
21540
|
-
value,
|
|
21541
|
-
[
|
|
21542
|
-
"additionalDirectoryIds",
|
|
21543
|
-
"agentId",
|
|
21544
|
-
"allowedDeliveryTargets",
|
|
21545
|
-
"behaviorDigest",
|
|
21546
|
-
"behaviorInstructions",
|
|
21547
|
-
"behaviorRevisionId",
|
|
21548
|
-
"bindingId",
|
|
21549
|
-
"bindingRevision",
|
|
21550
|
-
"botId",
|
|
21551
|
-
"commandId",
|
|
21552
|
-
"conversationId",
|
|
21553
|
-
"directoryId",
|
|
21554
|
-
"executionCapabilityId",
|
|
21555
|
-
"executionCapabilitySecret",
|
|
21556
|
-
"executionDeadlineAt",
|
|
21557
|
-
"executionId",
|
|
21558
|
-
"executionConfiguration",
|
|
21559
|
-
"images",
|
|
21560
|
-
"kind",
|
|
21561
|
-
"prompt",
|
|
21562
|
-
"replyRoute",
|
|
21563
|
-
"resources",
|
|
21564
|
-
"sessionId",
|
|
21565
|
-
"turnId"
|
|
21566
|
-
],
|
|
21567
|
-
["disposition", "sessionConfigurations", "targetCommandId"]
|
|
21568
|
-
);
|
|
21569
|
-
if (value["kind"] !== BOT_SESSION_PROMPT_KIND) {
|
|
21570
|
-
throw new ProtocolMessageError("Invalid Bot Session prompt kind");
|
|
21571
|
-
}
|
|
21572
|
-
const rawDisposition = value["disposition"];
|
|
21573
|
-
let disposition;
|
|
21574
|
-
if (rawDisposition === void 0 || rawDisposition === SessionPromptDisposition.Reject) {
|
|
21575
|
-
disposition = SessionPromptDisposition.Reject;
|
|
21576
|
-
} else if (rawDisposition === SessionPromptDisposition.Queue) {
|
|
21577
|
-
disposition = SessionPromptDisposition.Queue;
|
|
21578
|
-
} else if (rawDisposition === SessionPromptDisposition.Steer) {
|
|
21579
|
-
disposition = SessionPromptDisposition.Steer;
|
|
21580
|
-
} else {
|
|
21581
|
-
throw new ProtocolMessageError("Invalid Bot Session prompt disposition");
|
|
21582
|
-
}
|
|
21583
|
-
const targetCommandId = value["targetCommandId"] === void 0 ? "" : readText2(value, "targetCommandId", 128, false);
|
|
21584
|
-
if (disposition === SessionPromptDisposition.Reject && targetCommandId.length > 0 || disposition !== SessionPromptDisposition.Reject && !IDENTIFIER_PATTERN3.test(targetCommandId)) {
|
|
21585
|
-
throw new ProtocolMessageError("Bot Session prompt disposition has an invalid target command");
|
|
21586
|
-
}
|
|
21587
|
-
return new BotSessionPromptCommand(
|
|
21588
|
-
readIdentifier2(value, "sessionId"),
|
|
21589
|
-
readIdentifier2(value, "commandId"),
|
|
21590
|
-
readIdentifier2(value, "agentId"),
|
|
21591
|
-
readIdentifier2(value, "bindingId"),
|
|
21592
|
-
readDirectoryIdentifier2(value, "directoryId"),
|
|
21593
|
-
readIdentifiers(value, "additionalDirectoryIds", 16),
|
|
21594
|
-
decodePromptImagesValue(value["images"]),
|
|
21595
|
-
decodePromptResourcesValue(value["resources"]),
|
|
21596
|
-
readText2(value, "prompt", 1e4, false),
|
|
21597
|
-
readIdentifier2(value, "executionId"),
|
|
21598
|
-
readIdentifier2(value, "executionCapabilityId"),
|
|
21599
|
-
readToken(value, "executionCapabilitySecret"),
|
|
21600
|
-
readTimestamp(value, "executionDeadlineAt"),
|
|
21601
|
-
readIdentifier2(value, "botId"),
|
|
21602
|
-
readIdentifier2(value, "conversationId"),
|
|
21603
|
-
readIdentifier2(value, "turnId"),
|
|
21604
|
-
readIdentifier2(value, "behaviorRevisionId"),
|
|
21605
|
-
readInteger(value, "bindingRevision"),
|
|
21606
|
-
readText2(value, "behaviorInstructions", MAX_INSTRUCTIONS_LENGTH, true),
|
|
21607
|
-
readDigest(value, "behaviorDigest"),
|
|
21608
|
-
readTargets(value, "allowedDeliveryTargets"),
|
|
21609
|
-
readReplyRoute(value["replyRoute"]),
|
|
21610
|
-
decodeAgentExecutionConfiguration(value["executionConfiguration"]),
|
|
21611
|
-
readSessionConfigurations(value),
|
|
21612
|
-
disposition,
|
|
21613
|
-
targetCommandId
|
|
21614
|
-
);
|
|
21615
|
-
}
|
|
21616
|
-
|
|
21617
21342
|
// ../protocol/src/mobius-api.ts
|
|
21618
21343
|
var MOBIUS_API_PREFIX = "/mobius/api";
|
|
21619
21344
|
var API_PREFIX_PATTERN = /^\/[a-zA-Z0-9._~-]+(?:\/[a-zA-Z0-9._~-]+)*$/;
|
|
@@ -21826,13 +21551,13 @@ var SessionEventRejectionCode = {
|
|
|
21826
21551
|
SessionNotFound: "session_not_found",
|
|
21827
21552
|
SessionRejected: "session_rejected"
|
|
21828
21553
|
};
|
|
21829
|
-
var
|
|
21554
|
+
var IDENTIFIER_PATTERN3 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
21830
21555
|
var CURSOR_PATTERN = /^[A-Za-z0-9_-]{1,512}$/;
|
|
21831
21556
|
var MAX_RECORDED_EVENT_LENGTH = 8 * 1024 * 1024;
|
|
21832
21557
|
var DECIMAL_SEQUENCE_PATTERN = /^(?:0|[1-9][0-9]*)$/;
|
|
21833
21558
|
var eventSourceSchema = external_exports.discriminatedUnion("kind", [
|
|
21834
21559
|
external_exports.strictObject({
|
|
21835
|
-
attemptId: external_exports.string().min(1).max(128).regex(
|
|
21560
|
+
attemptId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
|
|
21836
21561
|
kind: external_exports.literal("attempt"),
|
|
21837
21562
|
sourceSeq: external_exports.string().min(1).max(40).regex(DECIMAL_SEQUENCE_PATTERN)
|
|
21838
21563
|
}).readonly(),
|
|
@@ -21842,41 +21567,41 @@ var eventSourceSchema = external_exports.discriminatedUnion("kind", [
|
|
|
21842
21567
|
}).readonly()
|
|
21843
21568
|
]);
|
|
21844
21569
|
var eventEnvelopeSchema = external_exports.strictObject({
|
|
21845
|
-
eventId: external_exports.string().min(1).max(128).regex(
|
|
21570
|
+
eventId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
|
|
21846
21571
|
kind: external_exports.literal(SESSION_EVENT_KIND),
|
|
21847
21572
|
payload: external_exports.string().min(2).max(MAX_RECORDED_EVENT_LENGTH),
|
|
21848
|
-
sessionId: external_exports.string().min(1).max(128).regex(
|
|
21573
|
+
sessionId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
|
|
21849
21574
|
source: eventSourceSchema
|
|
21850
21575
|
}).readonly();
|
|
21851
21576
|
var committedEventSchema = external_exports.strictObject({
|
|
21852
21577
|
cursor: external_exports.string().min(1).max(512).regex(CURSOR_PATTERN),
|
|
21853
|
-
eventId: external_exports.string().min(1).max(128).regex(
|
|
21578
|
+
eventId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
|
|
21854
21579
|
kind: external_exports.literal(SESSION_EVENT_COMMITTED_KIND),
|
|
21855
21580
|
payload: external_exports.string().min(2).max(MAX_RECORDED_EVENT_LENGTH),
|
|
21856
21581
|
recordedAt: external_exports.string().datetime({ offset: true }),
|
|
21857
21582
|
sequence: external_exports.string().min(1).max(40).regex(DECIMAL_SEQUENCE_PATTERN),
|
|
21858
|
-
sessionId: external_exports.string().min(1).max(128).regex(
|
|
21583
|
+
sessionId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
|
|
21859
21584
|
source: eventSourceSchema
|
|
21860
21585
|
}).readonly();
|
|
21861
21586
|
var eventAcknowledgementSchema = external_exports.strictObject({
|
|
21862
21587
|
cursor: external_exports.string().min(1).max(512).regex(CURSOR_PATTERN),
|
|
21863
21588
|
duplicate: external_exports.boolean(),
|
|
21864
|
-
eventId: external_exports.string().min(1).max(128).regex(
|
|
21589
|
+
eventId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
|
|
21865
21590
|
kind: external_exports.literal(SESSION_EVENT_ACK_KIND),
|
|
21866
21591
|
sequence: external_exports.string().min(1).max(40).regex(DECIMAL_SEQUENCE_PATTERN),
|
|
21867
|
-
sessionId: external_exports.string().min(1).max(128).regex(
|
|
21592
|
+
sessionId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3)
|
|
21868
21593
|
}).readonly();
|
|
21869
21594
|
var eventDeferredSchema = external_exports.strictObject({
|
|
21870
|
-
eventId: external_exports.string().min(1).max(128).regex(
|
|
21595
|
+
eventId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
|
|
21871
21596
|
kind: external_exports.literal(SESSION_EVENT_DEFERRED_KIND),
|
|
21872
21597
|
retryAfterMilliseconds: external_exports.number().int().min(100).max(6e4),
|
|
21873
|
-
sessionId: external_exports.string().min(1).max(128).regex(
|
|
21598
|
+
sessionId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3)
|
|
21874
21599
|
}).readonly();
|
|
21875
21600
|
var eventRejectionSchema = external_exports.strictObject({
|
|
21876
21601
|
code: external_exports.enum(SessionEventRejectionCode),
|
|
21877
|
-
eventId: external_exports.string().min(1).max(128).regex(
|
|
21602
|
+
eventId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
|
|
21878
21603
|
kind: external_exports.literal(SESSION_EVENT_REJECTED_KIND),
|
|
21879
|
-
sessionId: external_exports.string().min(1).max(128).regex(
|
|
21604
|
+
sessionId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3)
|
|
21880
21605
|
}).readonly();
|
|
21881
21606
|
function decode5(encoded, schema) {
|
|
21882
21607
|
let value;
|
|
@@ -22127,11 +21852,7 @@ var LocalAgentDefinition = class _LocalAgentDefinition {
|
|
|
22127
21852
|
id;
|
|
22128
21853
|
label;
|
|
22129
21854
|
permissionProfile;
|
|
22130
|
-
|
|
22131
|
-
constructor(id, label, command, arguments_, environment = {}, adapterVersion = "", agentVersion = "", adapterIdentity = readTrustedIdentity(command), agentIdentity = adapterIdentity, promptTimeoutMilliseconds = 30 * 60 * 1e3, capabilities = unsupportedSessionCapabilities(), permissionProfile = permissionProfileForAgent(id)) {
|
|
22132
|
-
if (!Number.isSafeInteger(promptTimeoutMilliseconds) || promptTimeoutMilliseconds < 1) {
|
|
22133
|
-
throw new Error("The local Agent prompt deadline is invalid");
|
|
22134
|
-
}
|
|
21855
|
+
constructor(id, label, command, arguments_, environment = {}, adapterVersion = "", agentVersion = "", adapterIdentity = readTrustedIdentity(command), agentIdentity = adapterIdentity, capabilities = unsupportedSessionCapabilities(), permissionProfile = permissionProfileForAgent(id)) {
|
|
22135
21856
|
this.adapterIdentity = adapterIdentity;
|
|
22136
21857
|
this.adapterPath = adapterIdentity.realPath;
|
|
22137
21858
|
this.adapterVersion = adapterVersion;
|
|
@@ -22141,7 +21862,6 @@ var LocalAgentDefinition = class _LocalAgentDefinition {
|
|
|
22141
21862
|
this.id = id;
|
|
22142
21863
|
this.label = label;
|
|
22143
21864
|
this.permissionProfile = permissionProfile;
|
|
22144
|
-
this.promptTimeoutMilliseconds = promptTimeoutMilliseconds;
|
|
22145
21865
|
this.command = adapterIdentity.realPath;
|
|
22146
21866
|
this.arguments = Object.freeze([...arguments_]);
|
|
22147
21867
|
this.environment = permissionProfile.apply(environment, permissionProfile.currentMode(environment));
|
|
@@ -22160,7 +21880,6 @@ var LocalAgentDefinition = class _LocalAgentDefinition {
|
|
|
22160
21880
|
this.agentVersion,
|
|
22161
21881
|
this.adapterIdentity,
|
|
22162
21882
|
this.agentIdentity,
|
|
22163
|
-
this.promptTimeoutMilliseconds,
|
|
22164
21883
|
this.capabilities,
|
|
22165
21884
|
this.permissionProfile
|
|
22166
21885
|
);
|
|
@@ -22397,7 +22116,7 @@ var ManagedNpmPackageError = class extends Error {
|
|
|
22397
22116
|
this.name = "ManagedNpmPackageError";
|
|
22398
22117
|
}
|
|
22399
22118
|
};
|
|
22400
|
-
function
|
|
22119
|
+
function isRecord3(value) {
|
|
22401
22120
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22402
22121
|
}
|
|
22403
22122
|
function packagePath(root, packageName) {
|
|
@@ -22419,7 +22138,7 @@ async function readJsonRecord(path2, maximumBytes) {
|
|
|
22419
22138
|
);
|
|
22420
22139
|
}
|
|
22421
22140
|
const value = JSON.parse(await handle.readFile({ encoding: "utf8" }));
|
|
22422
|
-
if (!
|
|
22141
|
+
if (!isRecord3(value)) {
|
|
22423
22142
|
throw new ManagedNpmPackageError(
|
|
22424
22143
|
"managed_package_verification_failed",
|
|
22425
22144
|
"The managed npm package metadata is invalid"
|
|
@@ -22445,7 +22164,7 @@ function readBinPath(packageMetadata, executableName) {
|
|
|
22445
22164
|
if (typeof bin === "string") {
|
|
22446
22165
|
return bin;
|
|
22447
22166
|
}
|
|
22448
|
-
if (
|
|
22167
|
+
if (isRecord3(bin) && typeof bin[executableName] === "string") {
|
|
22449
22168
|
return bin[executableName];
|
|
22450
22169
|
}
|
|
22451
22170
|
throw new ManagedNpmPackageError(
|
|
@@ -22461,7 +22180,7 @@ function verifyPackageLockEntry(lock, definition2, verifyDependencyClosure) {
|
|
|
22461
22180
|
);
|
|
22462
22181
|
}
|
|
22463
22182
|
const packages = lock["packages"];
|
|
22464
|
-
if (!
|
|
22183
|
+
if (!isRecord3(packages)) {
|
|
22465
22184
|
throw new ManagedNpmPackageError(
|
|
22466
22185
|
"managed_package_verification_failed",
|
|
22467
22186
|
"The managed npm package lockfile is invalid"
|
|
@@ -22475,7 +22194,7 @@ function verifyPackageLockEntry(lock, definition2, verifyDependencyClosure) {
|
|
|
22475
22194
|
if (verifyDependencyClosure && normalizedKey.length > 0) {
|
|
22476
22195
|
let resolved;
|
|
22477
22196
|
try {
|
|
22478
|
-
if (!normalizedKey.split("/").includes("node_modules") || !
|
|
22197
|
+
if (!normalizedKey.split("/").includes("node_modules") || !isRecord3(candidate) || typeof candidate["version"] !== "string" || candidate["version"].length === 0 || typeof candidate["integrity"] !== "string" || !/^sha512-[A-Za-z0-9+/]{86}==$/.test(candidate["integrity"]) || typeof candidate["resolved"] !== "string") {
|
|
22479
22198
|
throw new Error("Invalid locked dependency");
|
|
22480
22199
|
}
|
|
22481
22200
|
resolved = new URL(candidate["resolved"]);
|
|
@@ -22498,7 +22217,7 @@ function verifyPackageLockEntry(lock, definition2, verifyDependencyClosure) {
|
|
|
22498
22217
|
matches += 1;
|
|
22499
22218
|
}
|
|
22500
22219
|
}
|
|
22501
|
-
if (matches !== 1 || !
|
|
22220
|
+
if (matches !== 1 || !isRecord3(entry) || entry["integrity"] !== definition2.integrity || entry["resolved"] !== definition2.tarballUrl || entry["version"] !== definition2.version) {
|
|
22502
22221
|
throw new ManagedNpmPackageError(
|
|
22503
22222
|
"managed_package_verification_failed",
|
|
22504
22223
|
"The managed npm package lockfile does not match the pinned artifact"
|
|
@@ -22679,7 +22398,6 @@ function normalizeVersionOutput(output2) {
|
|
|
22679
22398
|
// src/agent-catalog/agent-specification.ts
|
|
22680
22399
|
var VERSION_PROBE_TIMEOUT_MILLISECONDS = 3e3;
|
|
22681
22400
|
var ACP_PROBE_TIMEOUT_MILLISECONDS = 5e3;
|
|
22682
|
-
var DEFAULT_PROMPT_TIMEOUT_MILLISECONDS = 30 * 60 * 1e3;
|
|
22683
22401
|
var LocalAgentSpecification = class {
|
|
22684
22402
|
acpProbeTimeoutMilliseconds = ACP_PROBE_TIMEOUT_MILLISECONDS;
|
|
22685
22403
|
authenticationCommand = () => "";
|
|
@@ -22687,7 +22405,6 @@ var LocalAgentSpecification = class {
|
|
|
22687
22405
|
agentVersionArguments = ["--version"];
|
|
22688
22406
|
normalizeAdapterVersion = normalizeVersionOutput;
|
|
22689
22407
|
normalizeAgentVersion = normalizeVersionOutput;
|
|
22690
|
-
promptTimeoutMilliseconds = DEFAULT_PROMPT_TIMEOUT_MILLISECONDS;
|
|
22691
22408
|
versionProbeTimeoutMilliseconds = VERSION_PROBE_TIMEOUT_MILLISECONDS;
|
|
22692
22409
|
resolveManagedAgent = async (stateDirectory, platform, signal) => {
|
|
22693
22410
|
signal.throwIfAborted();
|
|
@@ -23311,7 +23028,7 @@ var ManagedAgentArchiveError = class extends Error {
|
|
|
23311
23028
|
this.name = "ManagedAgentArchiveError";
|
|
23312
23029
|
}
|
|
23313
23030
|
};
|
|
23314
|
-
function
|
|
23031
|
+
function isRecord4(value) {
|
|
23315
23032
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23316
23033
|
}
|
|
23317
23034
|
function isContainedPath3(root, candidate) {
|
|
@@ -23368,7 +23085,7 @@ async function readManifest(path2) {
|
|
|
23368
23085
|
);
|
|
23369
23086
|
}
|
|
23370
23087
|
const parsed = JSON.parse(await handle.readFile({ encoding: "utf8" }));
|
|
23371
|
-
if (!
|
|
23088
|
+
if (!isRecord4(parsed)) {
|
|
23372
23089
|
throw new ManagedAgentArchiveError(
|
|
23373
23090
|
"managed_archive_verification_failed",
|
|
23374
23091
|
"The managed Agent archive manifest is invalid"
|
|
@@ -23539,7 +23256,6 @@ var PI_AGENT_PACKAGE = new SriManagedNpmPackageDefinition(
|
|
|
23539
23256
|
|
|
23540
23257
|
// src/agent-catalog/agents/pi-agent.ts
|
|
23541
23258
|
var ACP_PROBE_TIMEOUT_MILLISECONDS2 = 3e4;
|
|
23542
|
-
var PROMPT_TIMEOUT_MILLISECONDS = 5 * 60 * 1e3;
|
|
23543
23259
|
var PiAgentSpecification = class extends BridgedAcpAgentDefinition {
|
|
23544
23260
|
acpProbeTimeoutMilliseconds = ACP_PROBE_TIMEOUT_MILLISECONDS2;
|
|
23545
23261
|
adapterEnvironmentVariable = "PI_ACP_PI_COMMAND";
|
|
@@ -23571,7 +23287,6 @@ var PiAgentSpecification = class extends BridgedAcpAgentDefinition {
|
|
|
23571
23287
|
"bundle",
|
|
23572
23288
|
"cli.js"
|
|
23573
23289
|
];
|
|
23574
|
-
promptTimeoutMilliseconds = PROMPT_TIMEOUT_MILLISECONDS;
|
|
23575
23290
|
resolveManagedAgent = async (stateDirectory, _platform, signal) => {
|
|
23576
23291
|
signal.throwIfAborted();
|
|
23577
23292
|
const executable = await validateManagedNpmPackage(
|
|
@@ -23683,8 +23398,8 @@ var WorkBuddyAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
23683
23398
|
requestedPaths.unshift(join11(homeDirectory, "Applications", ...WORKBUDDY_MACOS_EXECUTABLE_PATH));
|
|
23684
23399
|
}
|
|
23685
23400
|
const executables = [];
|
|
23686
|
-
for (const
|
|
23687
|
-
const executable = await resolveExecutablePath(
|
|
23401
|
+
for (const requestedPath2 of requestedPaths) {
|
|
23402
|
+
const executable = await resolveExecutablePath(requestedPath2, "darwin");
|
|
23688
23403
|
context.signal.throwIfAborted();
|
|
23689
23404
|
if (executable !== null) {
|
|
23690
23405
|
executables.push(executable);
|
|
@@ -23772,41 +23487,41 @@ var DiscoveryAcpHandler = class {
|
|
|
23772
23487
|
};
|
|
23773
23488
|
function readableAcpStream(input2) {
|
|
23774
23489
|
let byteLength = 0;
|
|
23775
|
-
let
|
|
23490
|
+
let open6 = true;
|
|
23776
23491
|
return new ReadableStream({
|
|
23777
23492
|
start(controller) {
|
|
23778
23493
|
input2.on("data", (chunk) => {
|
|
23779
|
-
if (!
|
|
23494
|
+
if (!open6) {
|
|
23780
23495
|
return;
|
|
23781
23496
|
}
|
|
23782
23497
|
if (!(chunk instanceof Uint8Array)) {
|
|
23783
|
-
|
|
23498
|
+
open6 = false;
|
|
23784
23499
|
controller.error(new Error("ACP adapter produced invalid output"));
|
|
23785
23500
|
return;
|
|
23786
23501
|
}
|
|
23787
23502
|
byteLength += chunk.byteLength;
|
|
23788
23503
|
if (byteLength > ACP_OUTPUT_LIMIT_BYTES) {
|
|
23789
|
-
|
|
23504
|
+
open6 = false;
|
|
23790
23505
|
controller.error(new Error("ACP adapter output limit exceeded"));
|
|
23791
23506
|
return;
|
|
23792
23507
|
}
|
|
23793
23508
|
controller.enqueue(new Uint8Array(chunk));
|
|
23794
23509
|
});
|
|
23795
23510
|
input2.once("end", () => {
|
|
23796
|
-
if (
|
|
23797
|
-
|
|
23511
|
+
if (open6) {
|
|
23512
|
+
open6 = false;
|
|
23798
23513
|
controller.close();
|
|
23799
23514
|
}
|
|
23800
23515
|
});
|
|
23801
23516
|
input2.once("error", (error62) => {
|
|
23802
|
-
if (
|
|
23803
|
-
|
|
23517
|
+
if (open6) {
|
|
23518
|
+
open6 = false;
|
|
23804
23519
|
controller.error(error62);
|
|
23805
23520
|
}
|
|
23806
23521
|
});
|
|
23807
23522
|
},
|
|
23808
23523
|
cancel() {
|
|
23809
|
-
|
|
23524
|
+
open6 = false;
|
|
23810
23525
|
}
|
|
23811
23526
|
});
|
|
23812
23527
|
}
|
|
@@ -24077,7 +23792,7 @@ async function resolveAdapterExecutable(specification, context) {
|
|
|
24077
23792
|
const executables = await resolveAdapterExecutables(specification, context);
|
|
24078
23793
|
return executables[0] ?? null;
|
|
24079
23794
|
}
|
|
24080
|
-
async function probeVersion(executable, arguments_, environment, defaultWorkspace, signal, timeoutMilliseconds,
|
|
23795
|
+
async function probeVersion(executable, arguments_, environment, defaultWorkspace, signal, timeoutMilliseconds, normalize5 = normalizeVersionOutput) {
|
|
24081
23796
|
const result = await runBoundedProcess({
|
|
24082
23797
|
arguments: arguments_,
|
|
24083
23798
|
command: executable.path,
|
|
@@ -24086,7 +23801,7 @@ async function probeVersion(executable, arguments_, environment, defaultWorkspac
|
|
|
24086
23801
|
signal,
|
|
24087
23802
|
timeoutMilliseconds
|
|
24088
23803
|
});
|
|
24089
|
-
const version2 =
|
|
23804
|
+
const version2 = normalize5(result.stdout || result.stderr);
|
|
24090
23805
|
if (version2.length === 0) {
|
|
24091
23806
|
throw new ProcessExecutionError("process_exit_failed", "The executable did not report a version");
|
|
24092
23807
|
}
|
|
@@ -24223,8 +23938,7 @@ async function discoverAgent(specification, context) {
|
|
|
24223
23938
|
adapterVersion,
|
|
24224
23939
|
agentVersion,
|
|
24225
23940
|
adapter.identity,
|
|
24226
|
-
agent.identity
|
|
24227
|
-
specification.promptTimeoutMilliseconds
|
|
23941
|
+
agent.identity
|
|
24228
23942
|
);
|
|
24229
23943
|
try {
|
|
24230
23944
|
const readiness = await probeAcpReadiness(
|
|
@@ -24250,7 +23964,6 @@ async function discoverAgent(specification, context) {
|
|
|
24250
23964
|
agentVersion,
|
|
24251
23965
|
adapter.identity,
|
|
24252
23966
|
agent.identity,
|
|
24253
|
-
specification.promptTimeoutMilliseconds,
|
|
24254
23967
|
readiness.capabilities
|
|
24255
23968
|
)
|
|
24256
23969
|
);
|
|
@@ -24347,9 +24060,9 @@ function createDaemonConfig(connection, agents = [], installableAgents = []) {
|
|
|
24347
24060
|
|
|
24348
24061
|
// src/run-daemon.ts
|
|
24349
24062
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
24350
|
-
import { basename as
|
|
24063
|
+
import { basename as basename6 } from "node:path";
|
|
24351
24064
|
import { styleText } from "node:util";
|
|
24352
|
-
import { fetch as
|
|
24065
|
+
import { fetch as fetch5, WebSocket as WebSocket2 } from "undici";
|
|
24353
24066
|
|
|
24354
24067
|
// src/acp/session-manager.ts
|
|
24355
24068
|
import { spawn as spawn3 } from "node:child_process";
|
|
@@ -24361,10 +24074,11 @@ import {
|
|
|
24361
24074
|
} from "@agentclientprotocol/sdk";
|
|
24362
24075
|
|
|
24363
24076
|
// src/authorization/local-raster.ts
|
|
24364
|
-
import { readFile as readFile2, realpath as realpath6, stat as stat5 } from "node:fs/promises";
|
|
24077
|
+
import { open as open4, readFile as readFile2, realpath as realpath6, stat as stat5 } from "node:fs/promises";
|
|
24365
24078
|
import { basename, isAbsolute as isAbsolute8, normalize as normalize2 } from "node:path";
|
|
24366
24079
|
import { fileURLToPath } from "node:url";
|
|
24367
|
-
var MAX_LOCAL_RASTER_BYTES =
|
|
24080
|
+
var MAX_LOCAL_RASTER_BYTES = 128 * 1024 * 1024;
|
|
24081
|
+
var MAX_INLINE_RASTER_BYTES = 3e6;
|
|
24368
24082
|
var PNG_SIGNATURE = Uint8Array.of(137, 80, 78, 71);
|
|
24369
24083
|
var JPEG_SIGNATURE = Uint8Array.of(255, 216, 255);
|
|
24370
24084
|
var GIF87_SIGNATURE = new TextEncoder().encode("GIF87a");
|
|
@@ -24375,12 +24089,17 @@ var LocalRasterImage = class {
|
|
|
24375
24089
|
bytes;
|
|
24376
24090
|
mimeType;
|
|
24377
24091
|
name;
|
|
24378
|
-
|
|
24092
|
+
sourceUri;
|
|
24093
|
+
constructor(name, mimeType, bytes, sourceUri = "") {
|
|
24379
24094
|
this.bytes = bytes;
|
|
24380
24095
|
this.mimeType = mimeType;
|
|
24381
24096
|
this.name = name;
|
|
24097
|
+
this.sourceUri = sourceUri;
|
|
24382
24098
|
}
|
|
24383
|
-
base64 = () =>
|
|
24099
|
+
base64 = async () => {
|
|
24100
|
+
const bytes = this.bytes ?? new Uint8Array(await readFile2(this.sourceUri));
|
|
24101
|
+
return Buffer.from(bytes).toString("base64");
|
|
24102
|
+
};
|
|
24384
24103
|
};
|
|
24385
24104
|
function startsWith(bytes, signature, offset = 0) {
|
|
24386
24105
|
if (bytes.byteLength < offset + signature.byteLength) {
|
|
@@ -24404,14 +24123,14 @@ function sniffRasterMime(bytes) {
|
|
|
24404
24123
|
return null;
|
|
24405
24124
|
}
|
|
24406
24125
|
function readInlineRaster(data, name = "Image") {
|
|
24407
|
-
if (data.length === 0 || data.length > Math.ceil(
|
|
24126
|
+
if (data.length === 0 || data.length > Math.ceil(MAX_INLINE_RASTER_BYTES / 3) * 4 || data.length % 4 !== 0) {
|
|
24408
24127
|
return null;
|
|
24409
24128
|
}
|
|
24410
24129
|
if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(data)) {
|
|
24411
24130
|
return null;
|
|
24412
24131
|
}
|
|
24413
24132
|
const bytes = new Uint8Array(Buffer.from(data, "base64"));
|
|
24414
|
-
if (bytes.byteLength < 1 || bytes.byteLength >
|
|
24133
|
+
if (bytes.byteLength < 1 || bytes.byteLength > MAX_INLINE_RASTER_BYTES) {
|
|
24415
24134
|
return null;
|
|
24416
24135
|
}
|
|
24417
24136
|
const mimeType = sniffRasterMime(bytes);
|
|
@@ -24479,16 +24198,19 @@ async function readLocalRaster(uri, signal) {
|
|
|
24479
24198
|
if (!targetMetadata.isFile() || targetMetadata.size < 1 || targetMetadata.size > MAX_LOCAL_RASTER_BYTES) {
|
|
24480
24199
|
return null;
|
|
24481
24200
|
}
|
|
24482
|
-
const
|
|
24483
|
-
|
|
24484
|
-
|
|
24485
|
-
|
|
24201
|
+
const handle = await open4(target, "r");
|
|
24202
|
+
const header = new Uint8Array(12);
|
|
24203
|
+
try {
|
|
24204
|
+
await handle.read(header, 0, header.byteLength, 0);
|
|
24205
|
+
} finally {
|
|
24206
|
+
await handle.close();
|
|
24486
24207
|
}
|
|
24487
|
-
|
|
24208
|
+
signal.throwIfAborted();
|
|
24209
|
+
const mimeType = sniffRasterMime(header);
|
|
24488
24210
|
if (mimeType === null) {
|
|
24489
24211
|
return null;
|
|
24490
24212
|
}
|
|
24491
|
-
return new LocalRasterImage(basename(target) || "Image", mimeType,
|
|
24213
|
+
return new LocalRasterImage(basename(target) || "Image", mimeType, null, target);
|
|
24492
24214
|
}
|
|
24493
24215
|
|
|
24494
24216
|
// src/authorization/local-video.ts
|
|
@@ -24614,7 +24336,7 @@ async function resolveMessageImages(message, usedCharacters, signal) {
|
|
|
24614
24336
|
if (local === null) {
|
|
24615
24337
|
return "[Image unavailable]";
|
|
24616
24338
|
}
|
|
24617
|
-
const data = local.base64();
|
|
24339
|
+
const data = await local.base64();
|
|
24618
24340
|
if (usedCharacters + imageCharacters + data.length > SESSION_HISTORY_IMAGE_CHARACTER_LIMIT) {
|
|
24619
24341
|
return "[Image unavailable]";
|
|
24620
24342
|
}
|
|
@@ -24650,7 +24372,7 @@ async function replaceImageMarkers(text3, replace) {
|
|
|
24650
24372
|
|
|
24651
24373
|
// src/acp/activity.ts
|
|
24652
24374
|
var TRUNCATION_MARKER = "\n\u2026 output truncated by Mobius";
|
|
24653
|
-
function
|
|
24375
|
+
function isRecord5(value) {
|
|
24654
24376
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24655
24377
|
}
|
|
24656
24378
|
var AcpActivity = class _AcpActivity {
|
|
@@ -24884,16 +24606,16 @@ async function normalizeToolContent(content3, prepareContent) {
|
|
|
24884
24606
|
return normalized;
|
|
24885
24607
|
}
|
|
24886
24608
|
function rawMcpToolContent(rawOutput) {
|
|
24887
|
-
if (!
|
|
24609
|
+
if (!isRecord5(rawOutput)) {
|
|
24888
24610
|
return [];
|
|
24889
24611
|
}
|
|
24890
|
-
const result =
|
|
24612
|
+
const result = isRecord5(rawOutput["result"]) ? rawOutput["result"] : rawOutput;
|
|
24891
24613
|
const content3 = result["content"];
|
|
24892
24614
|
if (!Array.isArray(content3)) {
|
|
24893
24615
|
return [];
|
|
24894
24616
|
}
|
|
24895
24617
|
return content3.flatMap((item) => {
|
|
24896
|
-
if (!
|
|
24618
|
+
if (!isRecord5(item) || item["type"] !== "image" || typeof item["data"] !== "string" || typeof item["mimeType"] !== "string") {
|
|
24897
24619
|
return [];
|
|
24898
24620
|
}
|
|
24899
24621
|
const uri = item["uri"];
|
|
@@ -24970,7 +24692,7 @@ function contentPhase(content3) {
|
|
|
24970
24692
|
return "";
|
|
24971
24693
|
}
|
|
24972
24694
|
const codex = metadata["codex"];
|
|
24973
|
-
if (!
|
|
24695
|
+
if (!isRecord5(codex)) {
|
|
24974
24696
|
return "";
|
|
24975
24697
|
}
|
|
24976
24698
|
const phase = codex["phase"];
|
|
@@ -27774,7 +27496,7 @@ var attention = {
|
|
|
27774
27496
|
};
|
|
27775
27497
|
function resolveAllAttention(events, context) {
|
|
27776
27498
|
let index2 = -1;
|
|
27777
|
-
let
|
|
27499
|
+
let open6;
|
|
27778
27500
|
let group;
|
|
27779
27501
|
let text3;
|
|
27780
27502
|
let openingSequence;
|
|
@@ -27784,16 +27506,16 @@ function resolveAllAttention(events, context) {
|
|
|
27784
27506
|
let offset;
|
|
27785
27507
|
while (++index2 < events.length) {
|
|
27786
27508
|
if (events[index2][0] === "enter" && events[index2][1].type === "attentionSequence" && events[index2][1]._close) {
|
|
27787
|
-
|
|
27788
|
-
while (
|
|
27789
|
-
if (events[
|
|
27790
|
-
context.sliceSerialize(events[
|
|
27791
|
-
if ((events[
|
|
27509
|
+
open6 = index2;
|
|
27510
|
+
while (open6--) {
|
|
27511
|
+
if (events[open6][0] === "exit" && events[open6][1].type === "attentionSequence" && events[open6][1]._open && // If the markers are the same:
|
|
27512
|
+
context.sliceSerialize(events[open6][1]).charCodeAt(0) === context.sliceSerialize(events[index2][1]).charCodeAt(0)) {
|
|
27513
|
+
if ((events[open6][1]._close || events[index2][1]._open) && (events[index2][1].end.offset - events[index2][1].start.offset) % 3 && !((events[open6][1].end.offset - events[open6][1].start.offset + events[index2][1].end.offset - events[index2][1].start.offset) % 3)) {
|
|
27792
27514
|
continue;
|
|
27793
27515
|
}
|
|
27794
|
-
use = events[
|
|
27516
|
+
use = events[open6][1].end.offset - events[open6][1].start.offset > 1 && events[index2][1].end.offset - events[index2][1].start.offset > 1 ? 2 : 1;
|
|
27795
27517
|
const start = {
|
|
27796
|
-
...events[
|
|
27518
|
+
...events[open6][1].end
|
|
27797
27519
|
};
|
|
27798
27520
|
const end = {
|
|
27799
27521
|
...events[index2][1].start
|
|
@@ -27804,7 +27526,7 @@ function resolveAllAttention(events, context) {
|
|
|
27804
27526
|
type: use > 1 ? "strongSequence" : "emphasisSequence",
|
|
27805
27527
|
start,
|
|
27806
27528
|
end: {
|
|
27807
|
-
...events[
|
|
27529
|
+
...events[open6][1].end
|
|
27808
27530
|
}
|
|
27809
27531
|
};
|
|
27810
27532
|
closingSequence = {
|
|
@@ -27817,7 +27539,7 @@ function resolveAllAttention(events, context) {
|
|
|
27817
27539
|
text3 = {
|
|
27818
27540
|
type: use > 1 ? "strongText" : "emphasisText",
|
|
27819
27541
|
start: {
|
|
27820
|
-
...events[
|
|
27542
|
+
...events[open6][1].end
|
|
27821
27543
|
},
|
|
27822
27544
|
end: {
|
|
27823
27545
|
...events[index2][1].start
|
|
@@ -27832,18 +27554,18 @@ function resolveAllAttention(events, context) {
|
|
|
27832
27554
|
...closingSequence.end
|
|
27833
27555
|
}
|
|
27834
27556
|
};
|
|
27835
|
-
events[
|
|
27557
|
+
events[open6][1].end = {
|
|
27836
27558
|
...openingSequence.start
|
|
27837
27559
|
};
|
|
27838
27560
|
events[index2][1].start = {
|
|
27839
27561
|
...closingSequence.end
|
|
27840
27562
|
};
|
|
27841
27563
|
nextEvents = [];
|
|
27842
|
-
if (events[
|
|
27843
|
-
nextEvents = push(nextEvents, [["enter", events[
|
|
27564
|
+
if (events[open6][1].end.offset - events[open6][1].start.offset) {
|
|
27565
|
+
nextEvents = push(nextEvents, [["enter", events[open6][1], context], ["exit", events[open6][1], context]]);
|
|
27844
27566
|
}
|
|
27845
27567
|
nextEvents = push(nextEvents, [["enter", group, context], ["enter", openingSequence, context], ["exit", openingSequence, context], ["enter", text3, context]]);
|
|
27846
|
-
nextEvents = push(nextEvents, resolveAll(context.parser.constructs.insideSpan.null, events.slice(
|
|
27568
|
+
nextEvents = push(nextEvents, resolveAll(context.parser.constructs.insideSpan.null, events.slice(open6 + 1, index2), context));
|
|
27847
27569
|
nextEvents = push(nextEvents, [["exit", text3, context], ["enter", closingSequence, context], ["exit", closingSequence, context], ["exit", group, context]]);
|
|
27848
27570
|
if (events[index2][1].end.offset - events[index2][1].start.offset) {
|
|
27849
27571
|
offset = 2;
|
|
@@ -27851,8 +27573,8 @@ function resolveAllAttention(events, context) {
|
|
|
27851
27573
|
} else {
|
|
27852
27574
|
offset = 0;
|
|
27853
27575
|
}
|
|
27854
|
-
splice(events,
|
|
27855
|
-
index2 =
|
|
27576
|
+
splice(events, open6 - 1, index2 - open6 + 3, nextEvents);
|
|
27577
|
+
index2 = open6 + nextEvents.length - offset - 2;
|
|
27856
27578
|
break;
|
|
27857
27579
|
}
|
|
27858
27580
|
}
|
|
@@ -27884,10 +27606,10 @@ function tokenizeAttention(effects, ok2) {
|
|
|
27884
27606
|
}
|
|
27885
27607
|
const token = effects.exit("attentionSequence");
|
|
27886
27608
|
const after = classifyCharacter(code);
|
|
27887
|
-
const
|
|
27609
|
+
const open6 = !after || after === 2 && before || attentionMarkers2.includes(code);
|
|
27888
27610
|
const close = !before || before === 2 && after || attentionMarkers2.includes(previous2);
|
|
27889
|
-
token._open = Boolean(marker === 42 ?
|
|
27890
|
-
token._close = Boolean(marker === 42 ? close : close && (after || !
|
|
27611
|
+
token._open = Boolean(marker === 42 ? open6 : open6 && (before || !close));
|
|
27612
|
+
token._close = Boolean(marker === 42 ? close : close && (after || !open6));
|
|
27891
27613
|
return ok2(code);
|
|
27892
27614
|
}
|
|
27893
27615
|
}
|
|
@@ -27911,9 +27633,9 @@ function tokenizeAutolink(effects, ok2, nok) {
|
|
|
27911
27633
|
effects.consume(code);
|
|
27912
27634
|
effects.exit("autolinkMarker");
|
|
27913
27635
|
effects.enter("autolinkProtocol");
|
|
27914
|
-
return
|
|
27636
|
+
return open6;
|
|
27915
27637
|
}
|
|
27916
|
-
function
|
|
27638
|
+
function open6(code) {
|
|
27917
27639
|
if (asciiAlpha(code)) {
|
|
27918
27640
|
effects.consume(code);
|
|
27919
27641
|
return schemeOrEmailAtext;
|
|
@@ -28113,9 +27835,9 @@ function tokenizeCharacterReference(effects, ok2, nok) {
|
|
|
28113
27835
|
effects.enter("characterReferenceMarker");
|
|
28114
27836
|
effects.consume(code);
|
|
28115
27837
|
effects.exit("characterReferenceMarker");
|
|
28116
|
-
return
|
|
27838
|
+
return open6;
|
|
28117
27839
|
}
|
|
28118
|
-
function
|
|
27840
|
+
function open6(code) {
|
|
28119
27841
|
if (code === 35) {
|
|
28120
27842
|
effects.enter("characterReferenceMarkerNumeric");
|
|
28121
27843
|
effects.consume(code);
|
|
@@ -29484,9 +29206,9 @@ function tokenizeHtmlFlow(effects, ok2, nok) {
|
|
|
29484
29206
|
effects.enter("htmlFlow");
|
|
29485
29207
|
effects.enter("htmlFlowData");
|
|
29486
29208
|
effects.consume(code);
|
|
29487
|
-
return
|
|
29209
|
+
return open6;
|
|
29488
29210
|
}
|
|
29489
|
-
function
|
|
29211
|
+
function open6(code) {
|
|
29490
29212
|
if (code === 33) {
|
|
29491
29213
|
effects.consume(code);
|
|
29492
29214
|
return declarationOpen;
|
|
@@ -29834,9 +29556,9 @@ function tokenizeHtmlText(effects, ok2, nok) {
|
|
|
29834
29556
|
effects.enter("htmlText");
|
|
29835
29557
|
effects.enter("htmlTextData");
|
|
29836
29558
|
effects.consume(code);
|
|
29837
|
-
return
|
|
29559
|
+
return open6;
|
|
29838
29560
|
}
|
|
29839
|
-
function
|
|
29561
|
+
function open6(code) {
|
|
29840
29562
|
if (code === 33) {
|
|
29841
29563
|
effects.consume(code);
|
|
29842
29564
|
return declarationOpen;
|
|
@@ -30162,12 +29884,12 @@ function resolveToLabelEnd(events, context) {
|
|
|
30162
29884
|
let index2 = events.length;
|
|
30163
29885
|
let offset = 0;
|
|
30164
29886
|
let token;
|
|
30165
|
-
let
|
|
29887
|
+
let open6;
|
|
30166
29888
|
let close;
|
|
30167
29889
|
let media;
|
|
30168
29890
|
while (index2--) {
|
|
30169
29891
|
token = events[index2][1];
|
|
30170
|
-
if (
|
|
29892
|
+
if (open6) {
|
|
30171
29893
|
if (token.type === "link" || token.type === "labelLink" && token._inactive) {
|
|
30172
29894
|
break;
|
|
30173
29895
|
}
|
|
@@ -30176,7 +29898,7 @@ function resolveToLabelEnd(events, context) {
|
|
|
30176
29898
|
}
|
|
30177
29899
|
} else if (close) {
|
|
30178
29900
|
if (events[index2][0] === "enter" && (token.type === "labelImage" || token.type === "labelLink") && !token._balanced) {
|
|
30179
|
-
|
|
29901
|
+
open6 = index2;
|
|
30180
29902
|
if (token.type !== "labelLink") {
|
|
30181
29903
|
offset = 2;
|
|
30182
29904
|
break;
|
|
@@ -30187,9 +29909,9 @@ function resolveToLabelEnd(events, context) {
|
|
|
30187
29909
|
}
|
|
30188
29910
|
}
|
|
30189
29911
|
const group = {
|
|
30190
|
-
type: events[
|
|
29912
|
+
type: events[open6][1].type === "labelLink" ? "link" : "image",
|
|
30191
29913
|
start: {
|
|
30192
|
-
...events[
|
|
29914
|
+
...events[open6][1].start
|
|
30193
29915
|
},
|
|
30194
29916
|
end: {
|
|
30195
29917
|
...events[events.length - 1][1].end
|
|
@@ -30198,7 +29920,7 @@ function resolveToLabelEnd(events, context) {
|
|
|
30198
29920
|
const label = {
|
|
30199
29921
|
type: "label",
|
|
30200
29922
|
start: {
|
|
30201
|
-
...events[
|
|
29923
|
+
...events[open6][1].start
|
|
30202
29924
|
},
|
|
30203
29925
|
end: {
|
|
30204
29926
|
...events[close][1].end
|
|
@@ -30207,20 +29929,20 @@ function resolveToLabelEnd(events, context) {
|
|
|
30207
29929
|
const text3 = {
|
|
30208
29930
|
type: "labelText",
|
|
30209
29931
|
start: {
|
|
30210
|
-
...events[
|
|
29932
|
+
...events[open6 + offset + 2][1].end
|
|
30211
29933
|
},
|
|
30212
29934
|
end: {
|
|
30213
29935
|
...events[close - 2][1].start
|
|
30214
29936
|
}
|
|
30215
29937
|
};
|
|
30216
29938
|
media = [["enter", group, context], ["enter", label, context]];
|
|
30217
|
-
media = push(media, events.slice(
|
|
29939
|
+
media = push(media, events.slice(open6 + 1, open6 + offset + 3));
|
|
30218
29940
|
media = push(media, [["enter", text3, context]]);
|
|
30219
|
-
media = push(media, resolveAll(context.parser.constructs.insideSpan.null, events.slice(
|
|
29941
|
+
media = push(media, resolveAll(context.parser.constructs.insideSpan.null, events.slice(open6 + offset + 4, close - 3), context));
|
|
30220
29942
|
media = push(media, [["exit", text3, context], events[close - 2], events[close - 1], ["exit", label, context]]);
|
|
30221
29943
|
media = push(media, events.slice(close + 1));
|
|
30222
29944
|
media = push(media, [["exit", group, context]]);
|
|
30223
|
-
splice(events,
|
|
29945
|
+
splice(events, open6, events.length, media);
|
|
30224
29946
|
return events;
|
|
30225
29947
|
}
|
|
30226
29948
|
function tokenizeLabelEnd(effects, ok2, nok) {
|
|
@@ -30365,9 +30087,9 @@ function tokenizeLabelStartImage(effects, ok2, nok) {
|
|
|
30365
30087
|
effects.enter("labelImageMarker");
|
|
30366
30088
|
effects.consume(code);
|
|
30367
30089
|
effects.exit("labelImageMarker");
|
|
30368
|
-
return
|
|
30090
|
+
return open6;
|
|
30369
30091
|
}
|
|
30370
|
-
function
|
|
30092
|
+
function open6(code) {
|
|
30371
30093
|
if (code === 91) {
|
|
30372
30094
|
effects.enter("labelMarker");
|
|
30373
30095
|
effects.consume(code);
|
|
@@ -31671,8 +31393,8 @@ function compiler(options) {
|
|
|
31671
31393
|
return length;
|
|
31672
31394
|
}
|
|
31673
31395
|
function opener(create, and) {
|
|
31674
|
-
return
|
|
31675
|
-
function
|
|
31396
|
+
return open6;
|
|
31397
|
+
function open6(token) {
|
|
31676
31398
|
enter.call(this, create(token), token);
|
|
31677
31399
|
if (and) and.call(this, token);
|
|
31678
31400
|
}
|
|
@@ -31704,18 +31426,18 @@ function compiler(options) {
|
|
|
31704
31426
|
}
|
|
31705
31427
|
function exit2(token, onExitError) {
|
|
31706
31428
|
const node3 = this.stack.pop();
|
|
31707
|
-
const
|
|
31708
|
-
if (!
|
|
31429
|
+
const open6 = this.tokenStack.pop();
|
|
31430
|
+
if (!open6) {
|
|
31709
31431
|
throw new Error("Cannot close `" + token.type + "` (" + stringifyPosition({
|
|
31710
31432
|
start: token.start,
|
|
31711
31433
|
end: token.end
|
|
31712
31434
|
}) + "): it\u2019s not open");
|
|
31713
|
-
} else if (
|
|
31435
|
+
} else if (open6[0].type !== token.type) {
|
|
31714
31436
|
if (onExitError) {
|
|
31715
|
-
onExitError.call(this, token,
|
|
31437
|
+
onExitError.call(this, token, open6[0]);
|
|
31716
31438
|
} else {
|
|
31717
|
-
const handler =
|
|
31718
|
-
handler.call(this, token,
|
|
31439
|
+
const handler = open6[1] || defaultOnError;
|
|
31440
|
+
handler.call(this, token, open6[0]);
|
|
31719
31441
|
}
|
|
31720
31442
|
}
|
|
31721
31443
|
node3.position.end = point2(token.end);
|
|
@@ -32399,7 +32121,7 @@ var SessionConfigProtocolError = class extends Error {
|
|
|
32399
32121
|
this.name = "SessionConfigProtocolError";
|
|
32400
32122
|
}
|
|
32401
32123
|
};
|
|
32402
|
-
function
|
|
32124
|
+
function isRecord6(value) {
|
|
32403
32125
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
32404
32126
|
}
|
|
32405
32127
|
function readString2(value, fallback = "") {
|
|
@@ -32426,7 +32148,7 @@ function normalizeConfigValues(value) {
|
|
|
32426
32148
|
}
|
|
32427
32149
|
const normalized = [];
|
|
32428
32150
|
for (const entry of value) {
|
|
32429
|
-
if (!
|
|
32151
|
+
if (!isRecord6(entry)) {
|
|
32430
32152
|
continue;
|
|
32431
32153
|
}
|
|
32432
32154
|
const groupedOptions = entry["options"];
|
|
@@ -32434,7 +32156,7 @@ function normalizeConfigValues(value) {
|
|
|
32434
32156
|
const groupId = readString2(entry["group"]);
|
|
32435
32157
|
const groupName = readString2(entry["name"]);
|
|
32436
32158
|
for (const groupedOption of groupedOptions) {
|
|
32437
|
-
if (
|
|
32159
|
+
if (isRecord6(groupedOption)) {
|
|
32438
32160
|
normalized.push(normalizeConfigValue(groupedOption, groupId, groupName));
|
|
32439
32161
|
}
|
|
32440
32162
|
}
|
|
@@ -32448,7 +32170,7 @@ function normalizeConfigOptions(value, modes) {
|
|
|
32448
32170
|
const normalized = [];
|
|
32449
32171
|
if (Array.isArray(value)) {
|
|
32450
32172
|
for (const option of value) {
|
|
32451
|
-
if (!
|
|
32173
|
+
if (!isRecord6(option)) {
|
|
32452
32174
|
continue;
|
|
32453
32175
|
}
|
|
32454
32176
|
const id = truncate2(readString2(option["id"]), 128);
|
|
@@ -32487,12 +32209,12 @@ function normalizeConfigOptions(value, modes) {
|
|
|
32487
32209
|
}
|
|
32488
32210
|
}
|
|
32489
32211
|
}
|
|
32490
|
-
if (
|
|
32212
|
+
if (isRecord6(modes)) {
|
|
32491
32213
|
const values = [];
|
|
32492
32214
|
const availableModes = modes["availableModes"];
|
|
32493
32215
|
if (Array.isArray(availableModes)) {
|
|
32494
32216
|
for (const mode of availableModes) {
|
|
32495
|
-
if (!
|
|
32217
|
+
if (!isRecord6(mode)) {
|
|
32496
32218
|
continue;
|
|
32497
32219
|
}
|
|
32498
32220
|
const id = truncate2(readString2(mode["id"]), 500);
|
|
@@ -32631,7 +32353,7 @@ function ensureRequiredExecutionOptions(current, permission) {
|
|
|
32631
32353
|
return [permission, model, reasoningEffort, ...optional2].slice(0, MAXIMUM_CONFIG_OPTIONS);
|
|
32632
32354
|
}
|
|
32633
32355
|
function normalizeStandardLifecycle(response) {
|
|
32634
|
-
const lifecycle =
|
|
32356
|
+
const lifecycle = isRecord6(response) ? response : {};
|
|
32635
32357
|
return ensureReasoningEffortOption(normalizeConfigOptions(lifecycle["configOptions"], lifecycle["modes"]));
|
|
32636
32358
|
}
|
|
32637
32359
|
function replaceStandardConfigOptions(current, value) {
|
|
@@ -32673,7 +32395,7 @@ var StandardSessionConfigProtocol = class {
|
|
|
32673
32395
|
"ACP agent exited while changing session configuration",
|
|
32674
32396
|
change.signal
|
|
32675
32397
|
);
|
|
32676
|
-
if (!
|
|
32398
|
+
if (!isRecord6(response) || !Array.isArray(response["configOptions"])) {
|
|
32677
32399
|
throw new SessionConfigProtocolError("The Agent returned an invalid session configuration response");
|
|
32678
32400
|
}
|
|
32679
32401
|
return replaceStandardConfigOptions(current, response["configOptions"]);
|
|
@@ -32687,18 +32409,18 @@ var standardSessionConfigProtocol = new StandardSessionConfigProtocol();
|
|
|
32687
32409
|
var LEGACY_MODEL_CONFIG_ID = "grok_build_legacy_model";
|
|
32688
32410
|
var LEGACY_REASONING_EFFORT_CONFIG_ID = "grok_build_legacy_reasoning_effort";
|
|
32689
32411
|
function legacyOptions(response) {
|
|
32690
|
-
if (!
|
|
32412
|
+
if (!isRecord6(response)) {
|
|
32691
32413
|
return [];
|
|
32692
32414
|
}
|
|
32693
32415
|
const metadata = response["_meta"];
|
|
32694
|
-
if (!
|
|
32416
|
+
if (!isRecord6(metadata)) {
|
|
32695
32417
|
return [];
|
|
32696
32418
|
}
|
|
32697
32419
|
const sessionConfig = metadata["x.ai/sessionConfig"];
|
|
32698
|
-
if (!
|
|
32420
|
+
if (!isRecord6(sessionConfig) || !Array.isArray(sessionConfig["options"])) {
|
|
32699
32421
|
return [];
|
|
32700
32422
|
}
|
|
32701
|
-
return sessionConfig["options"].slice(0, 500).filter(
|
|
32423
|
+
return sessionConfig["options"].slice(0, 500).filter(isRecord6);
|
|
32702
32424
|
}
|
|
32703
32425
|
function legacyValue(option) {
|
|
32704
32426
|
const value = readString2(option["id"]);
|
|
@@ -32711,7 +32433,7 @@ function legacyValue(option) {
|
|
|
32711
32433
|
};
|
|
32712
32434
|
}
|
|
32713
32435
|
function modelsRecord(response) {
|
|
32714
|
-
if (!
|
|
32436
|
+
if (!isRecord6(response) || !isRecord6(response["models"])) {
|
|
32715
32437
|
return {};
|
|
32716
32438
|
}
|
|
32717
32439
|
return response["models"];
|
|
@@ -32730,7 +32452,7 @@ function legacyModelOptions(response) {
|
|
|
32730
32452
|
}
|
|
32731
32453
|
if (values.length === 0 && Array.isArray(models["availableModels"])) {
|
|
32732
32454
|
for (const model of models["availableModels"]) {
|
|
32733
|
-
if (!
|
|
32455
|
+
if (!isRecord6(model)) {
|
|
32734
32456
|
continue;
|
|
32735
32457
|
}
|
|
32736
32458
|
const value = readString2(model["modelId"]).slice(0, 500);
|
|
@@ -32810,7 +32532,7 @@ function legacyReasoningEffortOptions(response) {
|
|
|
32810
32532
|
return [result];
|
|
32811
32533
|
}
|
|
32812
32534
|
function normalizeGrokLifecycle(response) {
|
|
32813
|
-
const lifecycle =
|
|
32535
|
+
const lifecycle = isRecord6(response) ? response : {};
|
|
32814
32536
|
const standard = normalizeConfigOptions(lifecycle["configOptions"], lifecycle["modes"]);
|
|
32815
32537
|
const normalized = [...standard];
|
|
32816
32538
|
if (!normalized.some((option) => option.category === "model")) {
|
|
@@ -32829,11 +32551,11 @@ function updateCurrentValue2(current, category, value) {
|
|
|
32829
32551
|
return current.map((option) => option.category === category ? { ...option, currentValue: value } : option);
|
|
32830
32552
|
}
|
|
32831
32553
|
function validateGrokResponse(response, modelId) {
|
|
32832
|
-
if (!
|
|
32554
|
+
if (!isRecord6(response) || !isRecord6(response["_meta"])) {
|
|
32833
32555
|
throw new SessionConfigProtocolError("Grok Build returned an invalid session configuration response");
|
|
32834
32556
|
}
|
|
32835
32557
|
const model = response["_meta"]["model"];
|
|
32836
|
-
const appliedModel =
|
|
32558
|
+
const appliedModel = isRecord6(model) ? model["Ok"] : model;
|
|
32837
32559
|
if (appliedModel !== modelId) {
|
|
32838
32560
|
throw new SessionConfigProtocolError("Grok Build returned an invalid session configuration response");
|
|
32839
32561
|
}
|
|
@@ -33147,6 +32869,7 @@ var MAX_ACP_PROCESSES = 10;
|
|
|
33147
32869
|
var MAX_PRE_SESSION_UPDATES = 100;
|
|
33148
32870
|
var MAX_PRE_SESSION_UPDATE_BYTES = 1024 * 1024;
|
|
33149
32871
|
var SESSION_CONTROL_COMMAND_ID = "session-control";
|
|
32872
|
+
var SESSION_CONTROL_TIMEOUT_MILLISECONDS = 3e4;
|
|
33150
32873
|
var NullAcpSessionObserver = class {
|
|
33151
32874
|
importLocalArtifact = (_sessionId, _artifact, signal) => {
|
|
33152
32875
|
signal.throwIfAborted();
|
|
@@ -33365,7 +33088,7 @@ function createWritableAcpStream(output2) {
|
|
|
33365
33088
|
function truncate3(value, maximumLength) {
|
|
33366
33089
|
return value.length <= maximumLength ? value : `${value.slice(0, Math.max(0, maximumLength - 1))}\u2026`;
|
|
33367
33090
|
}
|
|
33368
|
-
function
|
|
33091
|
+
function isRecord7(value) {
|
|
33369
33092
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33370
33093
|
}
|
|
33371
33094
|
function readString4(value, fallback = "") {
|
|
@@ -33399,7 +33122,7 @@ function normalizeElicitationOptions(schema) {
|
|
|
33399
33122
|
const oneOf = schema["oneOf"];
|
|
33400
33123
|
if (Array.isArray(oneOf)) {
|
|
33401
33124
|
for (const option of oneOf) {
|
|
33402
|
-
if (
|
|
33125
|
+
if (isRecord7(option) && typeof option["const"] === "string") {
|
|
33403
33126
|
normalized.push({
|
|
33404
33127
|
description: truncate3(readString4(option["description"]), 500),
|
|
33405
33128
|
label: truncate3(readString4(option["title"], option["const"]), 255),
|
|
@@ -33419,7 +33142,7 @@ function normalizeElicitationOptions(schema) {
|
|
|
33419
33142
|
return normalized.slice(0, 200);
|
|
33420
33143
|
}
|
|
33421
33144
|
const items = schema["items"];
|
|
33422
|
-
if (!
|
|
33145
|
+
if (!isRecord7(items)) {
|
|
33423
33146
|
return normalized;
|
|
33424
33147
|
}
|
|
33425
33148
|
const anyOf = items["anyOf"];
|
|
@@ -33432,7 +33155,7 @@ function numericString(value) {
|
|
|
33432
33155
|
return typeof value === "number" && Number.isFinite(value) ? value.toString() : "";
|
|
33433
33156
|
}
|
|
33434
33157
|
function normalizeElicitationFields(requestedSchema) {
|
|
33435
|
-
if (!
|
|
33158
|
+
if (!isRecord7(requestedSchema) || !isRecord7(requestedSchema["properties"])) {
|
|
33436
33159
|
return [];
|
|
33437
33160
|
}
|
|
33438
33161
|
const properties2 = requestedSchema["properties"];
|
|
@@ -33442,7 +33165,7 @@ function normalizeElicitationFields(requestedSchema) {
|
|
|
33442
33165
|
);
|
|
33443
33166
|
const normalized = [];
|
|
33444
33167
|
for (const [name, property] of Object.entries(properties2)) {
|
|
33445
|
-
if (!
|
|
33168
|
+
if (!isRecord7(property)) {
|
|
33446
33169
|
continue;
|
|
33447
33170
|
}
|
|
33448
33171
|
const type = elicitationFieldType(property["type"]);
|
|
@@ -33533,7 +33256,7 @@ function validateElicitationContent(encoded, requestedSchema) {
|
|
|
33533
33256
|
"invalid_elicitation_response"
|
|
33534
33257
|
);
|
|
33535
33258
|
}
|
|
33536
|
-
if (!
|
|
33259
|
+
if (!isRecord7(decoded) || !isRecord7(requestedSchema) || !isRecord7(requestedSchema["properties"])) {
|
|
33537
33260
|
throw new AcpExecutionError(
|
|
33538
33261
|
"Elicitation response does not match the requested form",
|
|
33539
33262
|
{},
|
|
@@ -33553,7 +33276,7 @@ function validateElicitationContent(encoded, requestedSchema) {
|
|
|
33553
33276
|
const validated = {};
|
|
33554
33277
|
for (const [name, value] of Object.entries(decoded)) {
|
|
33555
33278
|
const property = properties2[name];
|
|
33556
|
-
if (!
|
|
33279
|
+
if (!isRecord7(property)) {
|
|
33557
33280
|
throw new AcpExecutionError(
|
|
33558
33281
|
`Elicitation field ${name} was not requested`,
|
|
33559
33282
|
{},
|
|
@@ -33706,6 +33429,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
33706
33429
|
#permissionProfile;
|
|
33707
33430
|
#sessionConfigProtocol;
|
|
33708
33431
|
#store;
|
|
33432
|
+
#emittedToolImages = /* @__PURE__ */ new Set();
|
|
33709
33433
|
#verifiedAgentVersion;
|
|
33710
33434
|
#preSessionUpdateBytes = 0;
|
|
33711
33435
|
#agentName = "";
|
|
@@ -33926,19 +33650,19 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
33926
33650
|
}
|
|
33927
33651
|
};
|
|
33928
33652
|
prepareAgentContent = async (content3) => {
|
|
33929
|
-
if (content3.type === "image" && content3.
|
|
33930
|
-
const raster = readInlineRaster(content3.data, content3.name);
|
|
33931
|
-
if (raster !== null) {
|
|
33932
|
-
return await this.importRaster(raster, AbortSignal.timeout(2e4));
|
|
33933
|
-
}
|
|
33934
|
-
}
|
|
33935
|
-
if (content3.type === "image" && content3.data.length === 0 && content3.uri.length > 0) {
|
|
33653
|
+
if (content3.type === "image" && content3.uri.length > 0) {
|
|
33936
33654
|
const signal = AbortSignal.timeout(2e4);
|
|
33937
33655
|
const raster = await readLocalRaster(content3.uri, signal);
|
|
33938
33656
|
if (raster !== null) {
|
|
33939
33657
|
return await this.importRaster(raster, signal);
|
|
33940
33658
|
}
|
|
33941
33659
|
}
|
|
33660
|
+
if (content3.type === "image" && content3.data.length > 0) {
|
|
33661
|
+
const raster = readInlineRaster(content3.data, content3.name);
|
|
33662
|
+
if (raster !== null) {
|
|
33663
|
+
return await this.importRaster(raster, AbortSignal.timeout(2e4));
|
|
33664
|
+
}
|
|
33665
|
+
}
|
|
33942
33666
|
if (content3.type === "video" && content3.data.length > 0) {
|
|
33943
33667
|
const video = readInlineVideo(content3.data, content3.mimeType, content3.name);
|
|
33944
33668
|
if (video === null) {
|
|
@@ -33959,6 +33683,22 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
33959
33683
|
sessionId: this.#mobiusSessionId
|
|
33960
33684
|
});
|
|
33961
33685
|
};
|
|
33686
|
+
emitToolImages = async (update) => {
|
|
33687
|
+
if (update.status !== "completed") {
|
|
33688
|
+
return;
|
|
33689
|
+
}
|
|
33690
|
+
for (const [index2, item] of (update.content ?? []).entries()) {
|
|
33691
|
+
if (item.type !== "content" || item.content.type !== "image") {
|
|
33692
|
+
continue;
|
|
33693
|
+
}
|
|
33694
|
+
const key = `${update.toolCallId}:${index2.toString()}`;
|
|
33695
|
+
if (this.#emittedToolImages.has(key)) {
|
|
33696
|
+
continue;
|
|
33697
|
+
}
|
|
33698
|
+
this.#emittedToolImages.add(key);
|
|
33699
|
+
await this.emitAgentContent(normalizeContentBlock(item.content), `tool-${key}`);
|
|
33700
|
+
}
|
|
33701
|
+
};
|
|
33962
33702
|
emitRaster = async (raster, messageId, signal) => {
|
|
33963
33703
|
const content3 = await this.importRaster(raster, signal);
|
|
33964
33704
|
await this.#getObserver().onContent({
|
|
@@ -33970,14 +33710,14 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
33970
33710
|
sessionId: this.#mobiusSessionId
|
|
33971
33711
|
});
|
|
33972
33712
|
};
|
|
33973
|
-
importRaster = async (raster,
|
|
33974
|
-
|
|
33975
|
-
|
|
33976
|
-
|
|
33977
|
-
|
|
33978
|
-
|
|
33979
|
-
|
|
33980
|
-
);
|
|
33713
|
+
importRaster = async (raster, _signal) => {
|
|
33714
|
+
if (raster.sourceUri.length > 0) {
|
|
33715
|
+
return {
|
|
33716
|
+
...imageDisplayContent(raster.mimeType, raster.name, "", ""),
|
|
33717
|
+
uri: raster.sourceUri
|
|
33718
|
+
};
|
|
33719
|
+
}
|
|
33720
|
+
return imageDisplayContent(raster.mimeType, raster.name, await raster.base64(), "");
|
|
33981
33721
|
};
|
|
33982
33722
|
importVideo = async (video, signal) => {
|
|
33983
33723
|
const artifactId = await this.#getObserver().importLocalArtifact(this.#mobiusSessionId, video, signal);
|
|
@@ -34461,7 +34201,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
34461
34201
|
"ACP agent exited during steering",
|
|
34462
34202
|
options.signal
|
|
34463
34203
|
);
|
|
34464
|
-
if (!
|
|
34204
|
+
if (!isRecord7(response)) {
|
|
34465
34205
|
throw new AcpExecutionError(
|
|
34466
34206
|
"ACP agent returned an invalid steering response",
|
|
34467
34207
|
{},
|
|
@@ -34757,6 +34497,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
34757
34497
|
}
|
|
34758
34498
|
if (update.sessionUpdate === "tool_call_update") {
|
|
34759
34499
|
await this.#turn.activities.recordToolCallUpdate(update);
|
|
34500
|
+
await this.emitToolImages(update);
|
|
34760
34501
|
return;
|
|
34761
34502
|
}
|
|
34762
34503
|
if (update.sessionUpdate === "plan") {
|
|
@@ -35435,7 +35176,7 @@ var AcpSessionManager = class {
|
|
|
35435
35176
|
async (runtime) => await runtime.close()
|
|
35436
35177
|
);
|
|
35437
35178
|
/**
|
|
35438
|
-
*
|
|
35179
|
+
* Retained for Agents that expose a separate persisted configuration channel.
|
|
35439
35180
|
* Use inspectAgentSettings for Agent-scoped settings discovery.
|
|
35440
35181
|
*/
|
|
35441
35182
|
inspectSession = async (options, metrics = unmeasuredOperationMetrics) => {
|
|
@@ -35597,7 +35338,7 @@ var AcpSessionManager = class {
|
|
|
35597
35338
|
() => deadlineController.abort(
|
|
35598
35339
|
new AcpExecutionError("The steering request exceeded its deadline", {}, "steering_timeout")
|
|
35599
35340
|
),
|
|
35600
|
-
|
|
35341
|
+
SESSION_CONTROL_TIMEOUT_MILLISECONDS
|
|
35601
35342
|
);
|
|
35602
35343
|
deadline.unref();
|
|
35603
35344
|
try {
|
|
@@ -35622,28 +35363,13 @@ var AcpSessionManager = class {
|
|
|
35622
35363
|
if (this.#activeSessionIds.has(options.sessionId)) {
|
|
35623
35364
|
throw new AcpExecutionError("Another prompt is already running in this conversation", {}, "session_busy");
|
|
35624
35365
|
}
|
|
35625
|
-
const deadlineController = new AbortController();
|
|
35626
|
-
const deadlineError = new AcpExecutionError(
|
|
35627
|
-
"The local Agent prompt exceeded its deadline",
|
|
35628
|
-
{},
|
|
35629
|
-
"prompt_timeout"
|
|
35630
|
-
);
|
|
35631
|
-
const deadline = setTimeout(
|
|
35632
|
-
() => deadlineController.abort(deadlineError),
|
|
35633
|
-
options.agent.promptTimeoutMilliseconds
|
|
35634
|
-
);
|
|
35635
|
-
deadline.unref();
|
|
35636
|
-
const boundedOptions = {
|
|
35637
|
-
...options,
|
|
35638
|
-
signal: AbortSignal.any([options.signal, deadlineController.signal])
|
|
35639
|
-
};
|
|
35640
35366
|
this.#activeSessionIds.add(options.sessionId);
|
|
35641
35367
|
this.#activeCommandIds.set(options.sessionId, options.commandId);
|
|
35642
35368
|
try {
|
|
35643
35369
|
if (this.#cancellationRequests.has(options.sessionId)) {
|
|
35644
35370
|
return { stopReason: "cancelled" };
|
|
35645
35371
|
}
|
|
35646
|
-
const runtime = await this.ensureSession(
|
|
35372
|
+
const runtime = await this.ensureSession(options);
|
|
35647
35373
|
if (this.#nativeOperations.has(`${options.agent.id}:${runtime.nativeSessionId()}`)) {
|
|
35648
35374
|
throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
|
|
35649
35375
|
}
|
|
@@ -35651,7 +35377,7 @@ var AcpSessionManager = class {
|
|
|
35651
35377
|
return { stopReason: "cancelled" };
|
|
35652
35378
|
}
|
|
35653
35379
|
try {
|
|
35654
|
-
const result = await runtime.prompt(
|
|
35380
|
+
const result = await runtime.prompt(options);
|
|
35655
35381
|
return this.#cancellationRequests.has(options.sessionId) ? { stopReason: "cancelled" } : result;
|
|
35656
35382
|
} catch (error62) {
|
|
35657
35383
|
if (this.#cancellationRequests.has(options.sessionId)) {
|
|
@@ -35679,7 +35405,6 @@ var AcpSessionManager = class {
|
|
|
35679
35405
|
cause: error62
|
|
35680
35406
|
});
|
|
35681
35407
|
} finally {
|
|
35682
|
-
clearTimeout(deadline);
|
|
35683
35408
|
try {
|
|
35684
35409
|
await this.#cancellationRequests.get(options.sessionId);
|
|
35685
35410
|
} finally {
|
|
@@ -36045,7 +35770,6 @@ async function publishAgentCatalog(config2, signal) {
|
|
|
36045
35770
|
agentPath: agent.agentIdentity.requestedPath,
|
|
36046
35771
|
agentVersion: agent.agentVersion,
|
|
36047
35772
|
agentSettingsDiscovery: true,
|
|
36048
|
-
botSessionConfiguration: true,
|
|
36049
35773
|
capabilities: agent.capabilities,
|
|
36050
35774
|
id: agent.id,
|
|
36051
35775
|
label: agent.label,
|
|
@@ -36532,6 +36256,91 @@ var FixedInstallationExecutor = class {
|
|
|
36532
36256
|
};
|
|
36533
36257
|
};
|
|
36534
36258
|
|
|
36259
|
+
// src/artifacts/local-file-streamer.ts
|
|
36260
|
+
import { createReadStream as createReadStream2 } from "node:fs";
|
|
36261
|
+
import { realpath as realpath7, stat as stat6 } from "node:fs/promises";
|
|
36262
|
+
import { basename as basename3, isAbsolute as isAbsolute9, normalize as normalize3 } from "node:path";
|
|
36263
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
36264
|
+
var CHUNK_BYTES = 192 * 1024;
|
|
36265
|
+
function requestedPath(value) {
|
|
36266
|
+
if (value.includes("\0")) {
|
|
36267
|
+
return null;
|
|
36268
|
+
}
|
|
36269
|
+
if (value.startsWith("file:")) {
|
|
36270
|
+
try {
|
|
36271
|
+
const url2 = new URL(value);
|
|
36272
|
+
return url2.protocol === "file:" && url2.host.length === 0 ? fileURLToPath2(url2) : null;
|
|
36273
|
+
} catch {
|
|
36274
|
+
return null;
|
|
36275
|
+
}
|
|
36276
|
+
}
|
|
36277
|
+
return value;
|
|
36278
|
+
}
|
|
36279
|
+
async function resolveFile(value, signal) {
|
|
36280
|
+
const requested = requestedPath(value);
|
|
36281
|
+
if (requested === null || !isAbsolute9(requested) || normalize3(requested) !== requested) {
|
|
36282
|
+
return null;
|
|
36283
|
+
}
|
|
36284
|
+
try {
|
|
36285
|
+
const target = await realpath7(requested);
|
|
36286
|
+
signal.throwIfAborted();
|
|
36287
|
+
return isAbsolute9(target) && normalize3(target) === target ? target : null;
|
|
36288
|
+
} catch {
|
|
36289
|
+
signal.throwIfAborted();
|
|
36290
|
+
return null;
|
|
36291
|
+
}
|
|
36292
|
+
}
|
|
36293
|
+
async function streamLocalFile(command, send2, signal) {
|
|
36294
|
+
const target = await resolveFile(command.path, signal);
|
|
36295
|
+
if (target === null) {
|
|
36296
|
+
throw new Error("The local file is unavailable");
|
|
36297
|
+
}
|
|
36298
|
+
const before = await stat6(target);
|
|
36299
|
+
signal.throwIfAborted();
|
|
36300
|
+
if (!before.isFile() || before.size < 1 || before.size > command.maxBytes) {
|
|
36301
|
+
throw new Error("The local file is too large to read");
|
|
36302
|
+
}
|
|
36303
|
+
const raster = await readLocalRaster(target, signal);
|
|
36304
|
+
send2(
|
|
36305
|
+
encodeFileBeginEvent({
|
|
36306
|
+
byteLength: before.size,
|
|
36307
|
+
kind: FILE_BEGIN_KIND,
|
|
36308
|
+
mediaType: raster?.mimeType ?? "application/octet-stream",
|
|
36309
|
+
modifiedAt: before.mtime.toISOString(),
|
|
36310
|
+
name: basename3(target) || "file",
|
|
36311
|
+
requestId: command.requestId,
|
|
36312
|
+
sessionId: command.sessionId
|
|
36313
|
+
})
|
|
36314
|
+
);
|
|
36315
|
+
let sequence = 0;
|
|
36316
|
+
const stream = createReadStream2(target, { highWaterMark: CHUNK_BYTES, signal });
|
|
36317
|
+
for await (const value of stream) {
|
|
36318
|
+
const bytes = value instanceof Uint8Array ? value : new Uint8Array(value);
|
|
36319
|
+
send2(
|
|
36320
|
+
encodeFileChunkEvent({
|
|
36321
|
+
data: Buffer.from(bytes).toString("base64"),
|
|
36322
|
+
kind: FILE_CHUNK_KIND,
|
|
36323
|
+
requestId: command.requestId,
|
|
36324
|
+
sequence,
|
|
36325
|
+
sessionId: command.sessionId
|
|
36326
|
+
})
|
|
36327
|
+
);
|
|
36328
|
+
sequence += 1;
|
|
36329
|
+
}
|
|
36330
|
+
const after = await stat6(target);
|
|
36331
|
+
signal.throwIfAborted();
|
|
36332
|
+
if (after.size !== before.size || after.mtimeMs !== before.mtimeMs) {
|
|
36333
|
+
throw new Error("The local file changed during transfer");
|
|
36334
|
+
}
|
|
36335
|
+
send2(
|
|
36336
|
+
encodeFileEndEvent({
|
|
36337
|
+
kind: FILE_END_KIND,
|
|
36338
|
+
requestId: command.requestId,
|
|
36339
|
+
sessionId: command.sessionId
|
|
36340
|
+
})
|
|
36341
|
+
);
|
|
36342
|
+
}
|
|
36343
|
+
|
|
36535
36344
|
// src/artifacts/runtime-artifact-uploader.ts
|
|
36536
36345
|
import { createHash as createHash2 } from "node:crypto";
|
|
36537
36346
|
|
|
@@ -36558,15 +36367,15 @@ var MobiusValidationError = class extends MobiusError {
|
|
|
36558
36367
|
};
|
|
36559
36368
|
|
|
36560
36369
|
// ../mobius-sdk/src/resources.ts
|
|
36561
|
-
var
|
|
36370
|
+
var IDENTIFIER_PATTERN4 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
36562
36371
|
function invalidResponse(message) {
|
|
36563
36372
|
return new MobiusProtocolError(message);
|
|
36564
36373
|
}
|
|
36565
|
-
function
|
|
36374
|
+
function isRecord8(value) {
|
|
36566
36375
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
36567
36376
|
}
|
|
36568
36377
|
function record3(value, name) {
|
|
36569
|
-
if (!
|
|
36378
|
+
if (!isRecord8(value)) {
|
|
36570
36379
|
throw invalidResponse(`The service returned an invalid ${name}`);
|
|
36571
36380
|
}
|
|
36572
36381
|
return value;
|
|
@@ -36580,7 +36389,7 @@ function stringField(value, field, maximumLength = 85e5) {
|
|
|
36580
36389
|
}
|
|
36581
36390
|
function identifierField(value, field) {
|
|
36582
36391
|
const candidate = stringField(value, field, 128);
|
|
36583
|
-
if (!
|
|
36392
|
+
if (!IDENTIFIER_PATTERN4.test(candidate)) {
|
|
36584
36393
|
throw invalidResponse(`The service returned an invalid ${field}`);
|
|
36585
36394
|
}
|
|
36586
36395
|
return candidate;
|
|
@@ -36927,9 +36736,9 @@ var LocalAuthorizationError = class extends Error {
|
|
|
36927
36736
|
};
|
|
36928
36737
|
|
|
36929
36738
|
// src/authorization/workspace-directory.ts
|
|
36930
|
-
import { readdir as readdir2, realpath as
|
|
36739
|
+
import { readdir as readdir2, realpath as realpath8, stat as stat7 } from "node:fs/promises";
|
|
36931
36740
|
import { homedir as homedir2 } from "node:os";
|
|
36932
|
-
import { basename as
|
|
36741
|
+
import { basename as basename4, dirname as dirname5, isAbsolute as isAbsolute10, join as join15, normalize as normalize4, relative as relative4 } from "node:path";
|
|
36933
36742
|
var WorkspaceDirectoryListing = class {
|
|
36934
36743
|
directoryId;
|
|
36935
36744
|
directoryLabel;
|
|
@@ -36955,7 +36764,7 @@ function decodePath(value, prefix) {
|
|
|
36955
36764
|
throw new LocalAuthorizationError("The directory identifier is invalid");
|
|
36956
36765
|
}
|
|
36957
36766
|
const decoded = Buffer.from(encoded, "base64url").toString("utf8");
|
|
36958
|
-
if (Buffer.from(decoded, "utf8").toString("base64url") !== encoded || decoded.includes("\0") ||
|
|
36767
|
+
if (Buffer.from(decoded, "utf8").toString("base64url") !== encoded || decoded.includes("\0") || normalize4(decoded) !== decoded) {
|
|
36959
36768
|
throw new LocalAuthorizationError("The directory identifier is invalid");
|
|
36960
36769
|
}
|
|
36961
36770
|
return decoded;
|
|
@@ -36981,7 +36790,7 @@ var WorkspaceDirectoryService = class {
|
|
|
36981
36790
|
}
|
|
36982
36791
|
if (id.startsWith("path-")) {
|
|
36983
36792
|
const path2 = decodePath(id, "path-");
|
|
36984
|
-
if (
|
|
36793
|
+
if (isAbsolute10(path2)) {
|
|
36985
36794
|
return path2;
|
|
36986
36795
|
}
|
|
36987
36796
|
}
|
|
@@ -36989,15 +36798,15 @@ var WorkspaceDirectoryService = class {
|
|
|
36989
36798
|
};
|
|
36990
36799
|
resolvePath = async (requested, signal) => {
|
|
36991
36800
|
signal.throwIfAborted();
|
|
36992
|
-
if (!
|
|
36801
|
+
if (!isAbsolute10(requested) || requested.includes("\0") || normalize4(requested) !== requested) {
|
|
36993
36802
|
throw new LocalAuthorizationError("The local directory path is invalid");
|
|
36994
36803
|
}
|
|
36995
36804
|
try {
|
|
36996
|
-
const target = await
|
|
36805
|
+
const target = await realpath8(requested);
|
|
36997
36806
|
signal.throwIfAborted();
|
|
36998
|
-
const metadata = await
|
|
36807
|
+
const metadata = await stat7(target);
|
|
36999
36808
|
signal.throwIfAborted();
|
|
37000
|
-
if (!
|
|
36809
|
+
if (!isAbsolute10(target) || normalize4(target) !== target || !metadata.isDirectory()) {
|
|
37001
36810
|
throw new LocalAuthorizationError("The selected location is not a directory");
|
|
37002
36811
|
}
|
|
37003
36812
|
return target;
|
|
@@ -37013,15 +36822,15 @@ var WorkspaceDirectoryService = class {
|
|
|
37013
36822
|
};
|
|
37014
36823
|
label = (path2) => {
|
|
37015
36824
|
const suffix = relative4(homedir2(), path2);
|
|
37016
|
-
return suffix === "" ? "~" : !
|
|
36825
|
+
return suffix === "" ? "~" : !isAbsolute10(suffix) && suffix !== ".." && !suffix.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) ? `~/${suffix.replaceAll("\\", "/")}` : path2;
|
|
37017
36826
|
};
|
|
37018
|
-
identify = async (bindingId,
|
|
36827
|
+
identify = async (bindingId, requestedPath2, signal) => {
|
|
37019
36828
|
this.authorizeMachine(bindingId);
|
|
37020
|
-
const path2 = await this.resolvePath(
|
|
36829
|
+
const path2 = await this.resolvePath(requestedPath2, signal);
|
|
37021
36830
|
return {
|
|
37022
36831
|
path: path2,
|
|
37023
36832
|
directoryId: encodePath(path2),
|
|
37024
|
-
name:
|
|
36833
|
+
name: basename4(path2) || path2,
|
|
37025
36834
|
label: this.label(path2)
|
|
37026
36835
|
};
|
|
37027
36836
|
};
|
|
@@ -37077,446 +36886,9 @@ var WorkspaceDirectoryService = class {
|
|
|
37077
36886
|
};
|
|
37078
36887
|
};
|
|
37079
36888
|
|
|
37080
|
-
// src/bots/local-bot-execution-authorizer.ts
|
|
37081
|
-
var LocalBotAuthorizationError = class extends Error {
|
|
37082
|
-
code;
|
|
37083
|
-
constructor(code, message, options = {}) {
|
|
37084
|
-
super(message, options);
|
|
37085
|
-
this.code = code;
|
|
37086
|
-
this.name = "LocalBotAuthorizationError";
|
|
37087
|
-
}
|
|
37088
|
-
};
|
|
37089
|
-
var AuthorizedLocalBotExecution = class {
|
|
37090
|
-
agent;
|
|
37091
|
-
behaviorDigest;
|
|
37092
|
-
behaviorRevisionId;
|
|
37093
|
-
bindingId;
|
|
37094
|
-
bindingRevision;
|
|
37095
|
-
botId;
|
|
37096
|
-
executionConfiguration;
|
|
37097
|
-
workspacePath;
|
|
37098
|
-
workspaceRef;
|
|
37099
|
-
constructor(command, agent, workspacePath) {
|
|
37100
|
-
this.agent = agent;
|
|
37101
|
-
this.behaviorDigest = command.behaviorDigest;
|
|
37102
|
-
this.behaviorRevisionId = command.behaviorRevisionId;
|
|
37103
|
-
this.bindingId = command.bindingId;
|
|
37104
|
-
this.bindingRevision = command.bindingRevision;
|
|
37105
|
-
this.botId = command.botId;
|
|
37106
|
-
this.executionConfiguration = command.executionConfiguration;
|
|
37107
|
-
this.workspacePath = workspacePath;
|
|
37108
|
-
this.workspaceRef = command.directoryId;
|
|
37109
|
-
}
|
|
37110
|
-
};
|
|
37111
|
-
var LocalBotExecutionAuthorizer = class {
|
|
37112
|
-
authorize = async (command, catalog, directories, bindingAuthorityId, signal) => {
|
|
37113
|
-
signal.throwIfAborted();
|
|
37114
|
-
let agent;
|
|
37115
|
-
try {
|
|
37116
|
-
agent = catalog.find(command.agentId).withPermissionMode(command.executionConfiguration.permissionMode);
|
|
37117
|
-
} catch (cause) {
|
|
37118
|
-
if (cause instanceof AgentPermissionConfigurationError) {
|
|
37119
|
-
throw new LocalBotAuthorizationError("binding_incompatible", cause.message, { cause });
|
|
37120
|
-
}
|
|
37121
|
-
throw cause;
|
|
37122
|
-
}
|
|
37123
|
-
const [adapterUnchanged, agentUnchanged] = await Promise.all([
|
|
37124
|
-
revalidateExecutable(agent.adapterIdentity),
|
|
37125
|
-
revalidateExecutable(agent.agentIdentity)
|
|
37126
|
-
]);
|
|
37127
|
-
signal.throwIfAborted();
|
|
37128
|
-
if (!adapterUnchanged || !agentUnchanged) {
|
|
37129
|
-
throw new LocalBotAuthorizationError(
|
|
37130
|
-
"binding_incompatible",
|
|
37131
|
-
"The local Agent executable changed while the Runtime is active; restart the Runtime"
|
|
37132
|
-
);
|
|
37133
|
-
}
|
|
37134
|
-
if (command.behaviorInstructions.length > 0 && !agent.capabilities.embeddedContextPrompt) {
|
|
37135
|
-
throw new LocalBotAuthorizationError(
|
|
37136
|
-
"binding_incompatible",
|
|
37137
|
-
"The local Agent cannot apply the Bot behavior"
|
|
37138
|
-
);
|
|
37139
|
-
}
|
|
37140
|
-
const workspacePath = await directories.resolve(bindingAuthorityId, command.directoryId, signal);
|
|
37141
|
-
signal.throwIfAborted();
|
|
37142
|
-
return new AuthorizedLocalBotExecution(command, agent, workspacePath);
|
|
37143
|
-
};
|
|
37144
|
-
};
|
|
37145
|
-
|
|
37146
|
-
// src/bots/bot-context-applicator.ts
|
|
37147
|
-
var AppliedBotContext = class {
|
|
37148
|
-
resources;
|
|
37149
|
-
constructor(resources) {
|
|
37150
|
-
this.resources = Object.freeze([...resources]);
|
|
37151
|
-
}
|
|
37152
|
-
};
|
|
37153
|
-
var EmbeddedBotContextApplicator = class {
|
|
37154
|
-
apply = async (command, execution, resources, signal) => {
|
|
37155
|
-
signal.throwIfAborted();
|
|
37156
|
-
if (execution.botId !== command.botId || execution.behaviorRevisionId !== command.behaviorRevisionId || execution.behaviorDigest !== command.behaviorDigest) {
|
|
37157
|
-
throw new LocalBotAuthorizationError(
|
|
37158
|
-
"binding_incompatible",
|
|
37159
|
-
"The Bot behavior does not match the execution target"
|
|
37160
|
-
);
|
|
37161
|
-
}
|
|
37162
|
-
if (command.behaviorInstructions.length === 0) {
|
|
37163
|
-
return new AppliedBotContext(resources);
|
|
37164
|
-
}
|
|
37165
|
-
if (!execution.agent.capabilities.embeddedContextPrompt) {
|
|
37166
|
-
throw new LocalBotAuthorizationError(
|
|
37167
|
-
"binding_incompatible",
|
|
37168
|
-
"The local Agent cannot enforce the Bot behavior context"
|
|
37169
|
-
);
|
|
37170
|
-
}
|
|
37171
|
-
const trustedContext = {
|
|
37172
|
-
mimeType: "text/markdown",
|
|
37173
|
-
name: "Mobius Bot behavior",
|
|
37174
|
-
text: command.behaviorInstructions,
|
|
37175
|
-
type: "embedded",
|
|
37176
|
-
uri: `mobius://bots/${encodeURIComponent(command.botId)}/behavior-revisions/${encodeURIComponent(command.behaviorRevisionId)}?sha256=${command.behaviorDigest}`
|
|
37177
|
-
};
|
|
37178
|
-
return new AppliedBotContext([trustedContext, ...resources]);
|
|
37179
|
-
};
|
|
37180
|
-
};
|
|
37181
|
-
|
|
37182
|
-
// src/bots/bot-execution-context.ts
|
|
37183
|
-
import { randomBytes } from "node:crypto";
|
|
37184
|
-
var ActiveBotExecutionContext = class {
|
|
37185
|
-
command;
|
|
37186
|
-
contextHandle;
|
|
37187
|
-
constructor(contextHandle, command) {
|
|
37188
|
-
this.contextHandle = contextHandle;
|
|
37189
|
-
this.command = command;
|
|
37190
|
-
}
|
|
37191
|
-
resolveTarget = (target) => {
|
|
37192
|
-
if (target === "current") {
|
|
37193
|
-
if (!(this.command.replyRoute instanceof BotConnectionReplyRoute)) {
|
|
37194
|
-
throw new LocalBotAuthorizationError(
|
|
37195
|
-
"delivery_target_not_allowed",
|
|
37196
|
-
"This Bot conversation has no external reply target"
|
|
37197
|
-
);
|
|
37198
|
-
}
|
|
37199
|
-
return this.command.replyRoute.deliveryTargetId;
|
|
37200
|
-
}
|
|
37201
|
-
const resolved = this.command.allowedDeliveryTargets.find((candidate) => candidate.alias === target);
|
|
37202
|
-
if (resolved === void 0) {
|
|
37203
|
-
throw new LocalBotAuthorizationError(
|
|
37204
|
-
"delivery_target_not_allowed",
|
|
37205
|
-
"The named Bot delivery target is not approved"
|
|
37206
|
-
);
|
|
37207
|
-
}
|
|
37208
|
-
return resolved.deliveryTargetId;
|
|
37209
|
-
};
|
|
37210
|
-
};
|
|
37211
|
-
var BotExecutionContextLease = class {
|
|
37212
|
-
context;
|
|
37213
|
-
#release;
|
|
37214
|
-
#released = false;
|
|
37215
|
-
constructor(context, release) {
|
|
37216
|
-
this.context = context;
|
|
37217
|
-
this.#release = release;
|
|
37218
|
-
}
|
|
37219
|
-
release = () => {
|
|
37220
|
-
if (this.#released) {
|
|
37221
|
-
return;
|
|
37222
|
-
}
|
|
37223
|
-
this.#released = true;
|
|
37224
|
-
this.#release();
|
|
37225
|
-
};
|
|
37226
|
-
};
|
|
37227
|
-
var BotExecutionContextRegistry = class {
|
|
37228
|
-
#activeByHandle = /* @__PURE__ */ new Map();
|
|
37229
|
-
#handlesBySession = /* @__PURE__ */ new Map();
|
|
37230
|
-
#inactiveHandles = /* @__PURE__ */ new Set();
|
|
37231
|
-
#now;
|
|
37232
|
-
constructor(now = Date.now) {
|
|
37233
|
-
this.#now = now;
|
|
37234
|
-
}
|
|
37235
|
-
activate = (command) => {
|
|
37236
|
-
let handle = this.#handlesBySession.get(command.sessionId);
|
|
37237
|
-
if (handle === void 0) {
|
|
37238
|
-
handle = `ctx_${Buffer.from(randomBytes(32)).toString("base64url")}`;
|
|
37239
|
-
this.#handlesBySession.set(command.sessionId, handle);
|
|
37240
|
-
}
|
|
37241
|
-
if (this.#activeByHandle.has(handle)) {
|
|
37242
|
-
throw new LocalBotAuthorizationError("session_busy", "The Bot execution context is already active");
|
|
37243
|
-
}
|
|
37244
|
-
const context = new ActiveBotExecutionContext(handle, command);
|
|
37245
|
-
this.#inactiveHandles.delete(handle);
|
|
37246
|
-
this.#activeByHandle.set(handle, context);
|
|
37247
|
-
return new BotExecutionContextLease(context, () => {
|
|
37248
|
-
if (this.#activeByHandle.get(handle) === context) {
|
|
37249
|
-
this.#activeByHandle.delete(handle);
|
|
37250
|
-
this.#inactiveHandles.add(handle);
|
|
37251
|
-
}
|
|
37252
|
-
});
|
|
37253
|
-
};
|
|
37254
|
-
read = (handle) => {
|
|
37255
|
-
const context = this.#activeByHandle.get(handle);
|
|
37256
|
-
if (context === void 0) {
|
|
37257
|
-
if (this.#inactiveHandles.has(handle)) {
|
|
37258
|
-
throw new LocalBotAuthorizationError(
|
|
37259
|
-
"execution_capability_expired",
|
|
37260
|
-
"The Bot execution capability has expired"
|
|
37261
|
-
);
|
|
37262
|
-
}
|
|
37263
|
-
throw new LocalBotAuthorizationError(
|
|
37264
|
-
"execution_context_required",
|
|
37265
|
-
"An active Bot execution context is required"
|
|
37266
|
-
);
|
|
37267
|
-
}
|
|
37268
|
-
if (Date.parse(context.command.executionDeadlineAt) <= this.#now()) {
|
|
37269
|
-
throw new LocalBotAuthorizationError(
|
|
37270
|
-
"execution_capability_expired",
|
|
37271
|
-
"The Bot execution capability has expired"
|
|
37272
|
-
);
|
|
37273
|
-
}
|
|
37274
|
-
return context;
|
|
37275
|
-
};
|
|
37276
|
-
};
|
|
37277
|
-
|
|
37278
|
-
// src/bots/bot-outbound-ipc.ts
|
|
37279
|
-
import { chmod as chmod2, mkdir as mkdir3, unlink } from "node:fs/promises";
|
|
37280
|
-
import { createServer } from "node:net";
|
|
37281
|
-
import { dirname as dirname6, isAbsolute as isAbsolute10 } from "node:path";
|
|
37282
|
-
import { fetch as fetch4 } from "undici";
|
|
37283
|
-
var BOT_IPC_REQUEST_LIMIT = 32 * 1024;
|
|
37284
|
-
var BOT_IPC_TIMEOUT_MILLISECONDS = 2e4;
|
|
37285
|
-
var BOT_RELAY_TIMEOUT_MILLISECONDS = 2e4;
|
|
37286
|
-
var IDENTIFIER_PATTERN6 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
37287
|
-
var WINDOWS_NAMED_PIPE_PREFIX = "\\\\.\\pipe\\";
|
|
37288
|
-
var BotOutboundIpcRequest = class {
|
|
37289
|
-
contextHandle;
|
|
37290
|
-
idempotencyKey;
|
|
37291
|
-
target;
|
|
37292
|
-
text;
|
|
37293
|
-
constructor(contextHandle, idempotencyKey, target, text3) {
|
|
37294
|
-
this.contextHandle = contextHandle;
|
|
37295
|
-
this.idempotencyKey = idempotencyKey;
|
|
37296
|
-
this.target = target;
|
|
37297
|
-
this.text = text3;
|
|
37298
|
-
}
|
|
37299
|
-
};
|
|
37300
|
-
function isRecord10(value) {
|
|
37301
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
37302
|
-
}
|
|
37303
|
-
function decodeRequest(encoded) {
|
|
37304
|
-
let value;
|
|
37305
|
-
try {
|
|
37306
|
-
value = JSON.parse(encoded);
|
|
37307
|
-
} catch (cause) {
|
|
37308
|
-
throw new LocalBotAuthorizationError("invalid_request", "The local Bot request is invalid", { cause });
|
|
37309
|
-
}
|
|
37310
|
-
if (!isRecord10(value)) {
|
|
37311
|
-
throw new LocalBotAuthorizationError("invalid_request", "The local Bot request is invalid");
|
|
37312
|
-
}
|
|
37313
|
-
const keys = Object.keys(value);
|
|
37314
|
-
if (keys.length !== 4 || !keys.every((key) => ["contextHandle", "idempotencyKey", "target", "text"].includes(key))) {
|
|
37315
|
-
throw new LocalBotAuthorizationError("invalid_request", "The local Bot request fields are invalid");
|
|
37316
|
-
}
|
|
37317
|
-
const contextHandle = value["contextHandle"];
|
|
37318
|
-
const idempotencyKey = value["idempotencyKey"];
|
|
37319
|
-
const target = value["target"];
|
|
37320
|
-
const text3 = value["text"];
|
|
37321
|
-
if (typeof contextHandle !== "string" || !/^ctx_[a-zA-Z0-9_-]{43}$/.test(contextHandle) || typeof idempotencyKey !== "string" || !IDENTIFIER_PATTERN6.test(idempotencyKey) || typeof target !== "string" || !IDENTIFIER_PATTERN6.test(target) || typeof text3 !== "string" || text3.trim().length === 0 || text3.length > 1e4) {
|
|
37322
|
-
throw new LocalBotAuthorizationError("invalid_request", "The local Bot request is invalid");
|
|
37323
|
-
}
|
|
37324
|
-
return new BotOutboundIpcRequest(contextHandle, idempotencyKey, target, text3);
|
|
37325
|
-
}
|
|
37326
|
-
function relayEndpoint(relayUrl, context, target) {
|
|
37327
|
-
const endpoint = new URL(relayUrl);
|
|
37328
|
-
if (endpoint.protocol !== "ws:" && endpoint.protocol !== "wss:") {
|
|
37329
|
-
throw new LocalBotAuthorizationError("bot_service_unavailable", "The Mobius Relay URL is invalid");
|
|
37330
|
-
}
|
|
37331
|
-
endpoint.protocol = endpoint.protocol === "wss:" ? "https:" : "http:";
|
|
37332
|
-
endpoint.search = "";
|
|
37333
|
-
const execution = encodeURIComponent(context.command.executionId);
|
|
37334
|
-
if (target === "current") {
|
|
37335
|
-
context.resolveTarget(target);
|
|
37336
|
-
endpoint.pathname = `${MOBIUS_API_PREFIX}/v1/bot-executions/${execution}/reply-messages`;
|
|
37337
|
-
return endpoint;
|
|
37338
|
-
}
|
|
37339
|
-
const deliveryTargetId = context.resolveTarget(target);
|
|
37340
|
-
endpoint.pathname = `${MOBIUS_API_PREFIX}/v1/bot-executions/${execution}/delivery-targets/${encodeURIComponent(deliveryTargetId)}/messages`;
|
|
37341
|
-
return endpoint;
|
|
37342
|
-
}
|
|
37343
|
-
function daemonToken(relayUrl) {
|
|
37344
|
-
const token = relayUrl.searchParams.get("token") ?? "";
|
|
37345
|
-
if (!/^[a-zA-Z0-9_-]{32,256}$/.test(token)) {
|
|
37346
|
-
throw new LocalBotAuthorizationError("bot_service_unavailable", "The Runtime credential is unavailable");
|
|
37347
|
-
}
|
|
37348
|
-
return token;
|
|
37349
|
-
}
|
|
37350
|
-
async function decodeRelayResponse(response) {
|
|
37351
|
-
const encoded = await response.text();
|
|
37352
|
-
let value;
|
|
37353
|
-
try {
|
|
37354
|
-
value = JSON.parse(encoded);
|
|
37355
|
-
} catch (cause) {
|
|
37356
|
-
throw new LocalBotAuthorizationError("bot_service_unavailable", "The Mobius Relay returned invalid data", {
|
|
37357
|
-
cause
|
|
37358
|
-
});
|
|
37359
|
-
}
|
|
37360
|
-
if (response.status === 202 && isRecord10(value) && typeof value["outboundMessageId"] === "string") {
|
|
37361
|
-
return value["outboundMessageId"];
|
|
37362
|
-
}
|
|
37363
|
-
if (isRecord10(value) && isRecord10(value["error"])) {
|
|
37364
|
-
const error62 = value["error"];
|
|
37365
|
-
if (typeof error62["code"] === "string" && typeof error62["message"] === "string") {
|
|
37366
|
-
throw new LocalBotAuthorizationError(error62["code"], error62["message"]);
|
|
37367
|
-
}
|
|
37368
|
-
}
|
|
37369
|
-
throw new LocalBotAuthorizationError("bot_service_unavailable", "The Mobius Relay rejected the Bot action");
|
|
37370
|
-
}
|
|
37371
|
-
var BotOutboundIpcServer = class {
|
|
37372
|
-
#registry;
|
|
37373
|
-
#relayUrl;
|
|
37374
|
-
#server;
|
|
37375
|
-
#socketPath;
|
|
37376
|
-
#usesFilesystemSocket;
|
|
37377
|
-
constructor(socketPath, relayUrl, registry2) {
|
|
37378
|
-
const usesFilesystemSocket = !socketPath.startsWith(WINDOWS_NAMED_PIPE_PREFIX);
|
|
37379
|
-
if (usesFilesystemSocket && !isAbsolute10(socketPath)) {
|
|
37380
|
-
throw new Error("The Bot IPC path must be absolute");
|
|
37381
|
-
}
|
|
37382
|
-
this.#registry = registry2;
|
|
37383
|
-
this.#relayUrl = new URL(relayUrl);
|
|
37384
|
-
this.#server = createServer({ allowHalfOpen: true }, (socket) => this.accept(socket));
|
|
37385
|
-
this.#socketPath = socketPath;
|
|
37386
|
-
this.#usesFilesystemSocket = usesFilesystemSocket;
|
|
37387
|
-
}
|
|
37388
|
-
get socketPath() {
|
|
37389
|
-
return this.#socketPath;
|
|
37390
|
-
}
|
|
37391
|
-
listen = async (signal) => {
|
|
37392
|
-
signal.throwIfAborted();
|
|
37393
|
-
if (this.#usesFilesystemSocket) {
|
|
37394
|
-
await mkdir3(dirname6(this.#socketPath), { mode: 448, recursive: true });
|
|
37395
|
-
await unlink(this.#socketPath).catch((error62) => {
|
|
37396
|
-
if (!isRecord10(error62) || error62["code"] !== "ENOENT") {
|
|
37397
|
-
throw error62;
|
|
37398
|
-
}
|
|
37399
|
-
});
|
|
37400
|
-
}
|
|
37401
|
-
await new Promise((resolve6, reject) => {
|
|
37402
|
-
const fail = (error62) => reject(error62);
|
|
37403
|
-
this.#server.once("error", fail);
|
|
37404
|
-
this.#server.listen(this.#socketPath, () => {
|
|
37405
|
-
this.#server.removeListener("error", fail);
|
|
37406
|
-
resolve6();
|
|
37407
|
-
});
|
|
37408
|
-
});
|
|
37409
|
-
if (this.#usesFilesystemSocket) {
|
|
37410
|
-
await chmod2(this.#socketPath, 384);
|
|
37411
|
-
}
|
|
37412
|
-
signal.addEventListener("abort", this.abort, { once: true });
|
|
37413
|
-
if (signal.aborted) {
|
|
37414
|
-
this.abort();
|
|
37415
|
-
}
|
|
37416
|
-
};
|
|
37417
|
-
close = async () => {
|
|
37418
|
-
if (this.#server.listening) {
|
|
37419
|
-
await new Promise((resolve6, reject) => {
|
|
37420
|
-
this.#server.close((error62) => {
|
|
37421
|
-
if (error62 === void 0) {
|
|
37422
|
-
resolve6();
|
|
37423
|
-
return;
|
|
37424
|
-
}
|
|
37425
|
-
reject(error62);
|
|
37426
|
-
});
|
|
37427
|
-
});
|
|
37428
|
-
}
|
|
37429
|
-
if (this.#usesFilesystemSocket) {
|
|
37430
|
-
await unlink(this.#socketPath).catch((error62) => {
|
|
37431
|
-
if (!isRecord10(error62) || error62["code"] !== "ENOENT") {
|
|
37432
|
-
throw error62;
|
|
37433
|
-
}
|
|
37434
|
-
});
|
|
37435
|
-
}
|
|
37436
|
-
};
|
|
37437
|
-
#abort = () => {
|
|
37438
|
-
this.#server.close();
|
|
37439
|
-
};
|
|
37440
|
-
abort = () => this.#abort();
|
|
37441
|
-
accept = (socket) => {
|
|
37442
|
-
const chunks = [];
|
|
37443
|
-
let length = 0;
|
|
37444
|
-
let rejected = false;
|
|
37445
|
-
const controller = new AbortController();
|
|
37446
|
-
socket.setTimeout(BOT_IPC_TIMEOUT_MILLISECONDS, () => {
|
|
37447
|
-
controller.abort(new Error("Bot IPC request timed out"));
|
|
37448
|
-
socket.destroy();
|
|
37449
|
-
});
|
|
37450
|
-
socket.on("data", (chunk) => {
|
|
37451
|
-
length += chunk.byteLength;
|
|
37452
|
-
if (length > BOT_IPC_REQUEST_LIMIT) {
|
|
37453
|
-
rejected = true;
|
|
37454
|
-
controller.abort(new Error("Bot IPC request is too large"));
|
|
37455
|
-
socket.end(
|
|
37456
|
-
JSON.stringify({
|
|
37457
|
-
error: { code: "invalid_request", message: "The local Bot request is too large" },
|
|
37458
|
-
ok: false
|
|
37459
|
-
})
|
|
37460
|
-
);
|
|
37461
|
-
return;
|
|
37462
|
-
}
|
|
37463
|
-
chunks.push(chunk);
|
|
37464
|
-
});
|
|
37465
|
-
socket.once("error", () => controller.abort());
|
|
37466
|
-
socket.once("close", () => controller.abort());
|
|
37467
|
-
socket.once("end", () => {
|
|
37468
|
-
if (rejected) {
|
|
37469
|
-
return;
|
|
37470
|
-
}
|
|
37471
|
-
void this.handle(Buffer.concat(chunks).toString("utf8").trim(), controller.signal).then(
|
|
37472
|
-
(outboundMessageId) => {
|
|
37473
|
-
if (!socket.destroyed) {
|
|
37474
|
-
socket.end(JSON.stringify({ ok: true, outboundMessageId }));
|
|
37475
|
-
}
|
|
37476
|
-
},
|
|
37477
|
-
(error62) => {
|
|
37478
|
-
if (socket.destroyed) {
|
|
37479
|
-
return;
|
|
37480
|
-
}
|
|
37481
|
-
const code = error62 instanceof LocalBotAuthorizationError ? error62.code : "bot_service_unavailable";
|
|
37482
|
-
const message = error62 instanceof LocalBotAuthorizationError ? error62.message : "The local Bot action could not be completed";
|
|
37483
|
-
socket.end(JSON.stringify({ error: { code, message }, ok: false }));
|
|
37484
|
-
}
|
|
37485
|
-
);
|
|
37486
|
-
});
|
|
37487
|
-
};
|
|
37488
|
-
handle = async (encoded, signal) => {
|
|
37489
|
-
const request = decodeRequest(encoded);
|
|
37490
|
-
const context = this.#registry.read(request.contextHandle);
|
|
37491
|
-
const timeout = AbortSignal.timeout(BOT_RELAY_TIMEOUT_MILLISECONDS);
|
|
37492
|
-
const requestSignal = AbortSignal.any([signal, timeout]);
|
|
37493
|
-
let response;
|
|
37494
|
-
try {
|
|
37495
|
-
response = await fetch4(relayEndpoint(this.#relayUrl, context, request.target), {
|
|
37496
|
-
body: JSON.stringify({ idempotencyKey: request.idempotencyKey, text: request.text }),
|
|
37497
|
-
headers: {
|
|
37498
|
-
authorization: `Bearer ${daemonToken(this.#relayUrl)}`,
|
|
37499
|
-
"content-type": "application/json",
|
|
37500
|
-
"x-mobius-bot-execution-capability": context.command.executionCapabilitySecret
|
|
37501
|
-
},
|
|
37502
|
-
method: "POST",
|
|
37503
|
-
signal: requestSignal
|
|
37504
|
-
});
|
|
37505
|
-
} catch (cause) {
|
|
37506
|
-
signal.throwIfAborted();
|
|
37507
|
-
throw new LocalBotAuthorizationError(
|
|
37508
|
-
timeout.aborted ? "bot_service_timeout" : "bot_service_unavailable",
|
|
37509
|
-
timeout.aborted ? "The Mobius Bot action timed out" : "The Mobius Relay is unavailable",
|
|
37510
|
-
{ cause }
|
|
37511
|
-
);
|
|
37512
|
-
}
|
|
37513
|
-
return await decodeRelayResponse(response);
|
|
37514
|
-
};
|
|
37515
|
-
};
|
|
37516
|
-
|
|
37517
36889
|
// src/native-sessions/service.ts
|
|
37518
36890
|
import { randomUUID } from "node:crypto";
|
|
37519
|
-
import { basename as
|
|
36891
|
+
import { basename as basename5 } from "node:path";
|
|
37520
36892
|
|
|
37521
36893
|
// src/native-sessions/codex-history.ts
|
|
37522
36894
|
import { spawn as spawn4 } from "node:child_process";
|
|
@@ -38025,7 +37397,7 @@ var NativeSessionService = class {
|
|
|
38025
37397
|
}
|
|
38026
37398
|
resolvedPaths.add(path2);
|
|
38027
37399
|
additionalDirectories.push(path2);
|
|
38028
|
-
additionalEntries.push({ directoryId: directoryId2, name:
|
|
37400
|
+
additionalEntries.push({ directoryId: directoryId2, name: basename5(path2) });
|
|
38029
37401
|
}
|
|
38030
37402
|
const listing = await this.#directories.list(this.#config.bindingId, command.directoryId, signal);
|
|
38031
37403
|
const opened = await this.#sessions.forkSessionAtTurn(
|
|
@@ -38183,12 +37555,12 @@ var NativeSessionService = class {
|
|
|
38183
37555
|
|
|
38184
37556
|
// src/prompt-artifact-resolver.ts
|
|
38185
37557
|
import { createHash as createHash3 } from "node:crypto";
|
|
38186
|
-
import { fetch as
|
|
37558
|
+
import { fetch as fetch4 } from "undici";
|
|
38187
37559
|
var ARTIFACT_SCHEME = "mobius-artifact:";
|
|
38188
37560
|
var ARTIFACT_DOWNLOAD_TIMEOUT_MILLISECONDS = 2e4;
|
|
38189
37561
|
var MAX_AGENT_IMAGE_BASE64_LENGTH = 4e6;
|
|
38190
37562
|
var MAX_AGENT_RESOURCE_BYTE_LENGTH = 1e6;
|
|
38191
|
-
var
|
|
37563
|
+
var IDENTIFIER_PATTERN5 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
38192
37564
|
var PromptArtifactError = class extends Error {
|
|
38193
37565
|
code;
|
|
38194
37566
|
constructor(code, message, options = {}) {
|
|
@@ -38231,7 +37603,7 @@ function parseReference(resource) {
|
|
|
38231
37603
|
const encodedByteLength2 = url2.searchParams.get("byteLength") ?? "";
|
|
38232
37604
|
const sha256 = url2.searchParams.get("sha256") ?? "";
|
|
38233
37605
|
const byteLength = Number(encodedByteLength2);
|
|
38234
|
-
if (url2.protocol !== ARTIFACT_SCHEME || url2.hash.length > 0 || resource.type !== "link" || resource.text.length > 0 || !
|
|
37606
|
+
if (url2.protocol !== ARTIFACT_SCHEME || url2.hash.length > 0 || resource.type !== "link" || resource.text.length > 0 || !IDENTIFIER_PATTERN5.test(artifactId) || keys.length !== 2 || keys[0] !== "byteLength" || keys[1] !== "sha256" || !/^[1-9][0-9]*$/.test(encodedByteLength2) || !Number.isSafeInteger(byteLength) || !/^[a-f0-9]{64}$/.test(sha256)) {
|
|
38235
37607
|
throw new PromptArtifactError("artifact_reference_invalid", "The prompt artifact reference is invalid");
|
|
38236
37608
|
}
|
|
38237
37609
|
return new PromptArtifactReference(artifactId, byteLength, sha256, resource);
|
|
@@ -38297,7 +37669,7 @@ async function download(config2, command, reference, signal) {
|
|
|
38297
37669
|
const requestSignal = AbortSignal.any([signal, timeoutSignal]);
|
|
38298
37670
|
let response;
|
|
38299
37671
|
try {
|
|
38300
|
-
response = await
|
|
37672
|
+
response = await fetch4(downloadUrl(config2, command, reference), {
|
|
38301
37673
|
dispatcher: environmentProxyDispatcher,
|
|
38302
37674
|
headers: {
|
|
38303
37675
|
accept: reference.resource.mimeType,
|
|
@@ -38735,7 +38107,7 @@ var RelayConnectionLiveness = class {
|
|
|
38735
38107
|
|
|
38736
38108
|
// src/relay-connection/session-event-outbox.ts
|
|
38737
38109
|
import { mkdirSync as mkdirSync3 } from "node:fs";
|
|
38738
|
-
import { dirname as
|
|
38110
|
+
import { dirname as dirname6 } from "node:path";
|
|
38739
38111
|
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
38740
38112
|
var DEFAULT_OUTBOX_LIMITS = {
|
|
38741
38113
|
criticalEventBytes: 136 * 1024 * 1024,
|
|
@@ -38801,7 +38173,7 @@ var SessionEventOutbox = class {
|
|
|
38801
38173
|
constructor(path2, limits = DEFAULT_OUTBOX_LIMITS) {
|
|
38802
38174
|
validateLimits(limits);
|
|
38803
38175
|
this.#limits = limits;
|
|
38804
|
-
mkdirSync3(
|
|
38176
|
+
mkdirSync3(dirname6(path2), { recursive: true });
|
|
38805
38177
|
this.#database = new DatabaseSync3(path2);
|
|
38806
38178
|
this.#database.exec(`
|
|
38807
38179
|
CREATE TABLE IF NOT EXISTS relay_session_event_outbox (
|
|
@@ -39334,12 +38706,6 @@ var RELAY_RECONNECT_DELAY_MILLISECONDS = 500;
|
|
|
39334
38706
|
var AGENT_ACTIVITY_COALESCING_MILLISECONDS = 100;
|
|
39335
38707
|
var ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS = 2e4;
|
|
39336
38708
|
var ACTIVE_TURN_RECONCILIATION_CLOSE_CODE = 4009;
|
|
39337
|
-
function botIpcSocketPath() {
|
|
39338
|
-
if (process.platform === "win32") {
|
|
39339
|
-
return `\\\\.\\pipe\\mobius-bot-${randomUUID3()}`;
|
|
39340
|
-
}
|
|
39341
|
-
return join16("/tmp", `mobius-bot-${randomUUID3()}.sock`);
|
|
39342
|
-
}
|
|
39343
38709
|
var DaemonAcpObserver = class {
|
|
39344
38710
|
#config;
|
|
39345
38711
|
#record;
|
|
@@ -39557,7 +38923,7 @@ async function reconcileActiveTurn(config2, turn, signal) {
|
|
|
39557
38923
|
const requestSignal = AbortSignal.any([signal, timeoutSignal]);
|
|
39558
38924
|
let response;
|
|
39559
38925
|
try {
|
|
39560
|
-
response = await
|
|
38926
|
+
response = await fetch5(activeTurnReconciliationEndpoint(config2, turn), {
|
|
39561
38927
|
body: JSON.stringify({ outcome: { kind: "running" } }),
|
|
39562
38928
|
dispatcher: environmentProxyDispatcher,
|
|
39563
38929
|
headers: { ...runtimeAuthorization(config2.relayUrl), "content-type": "application/json" },
|
|
@@ -39869,13 +39235,13 @@ function reportFailure(publisher, command, code, message, attemptId) {
|
|
|
39869
39235
|
);
|
|
39870
39236
|
}
|
|
39871
39237
|
function operationErrorCode(error62) {
|
|
39872
|
-
if (error62 instanceof AcpExecutionError || error62 instanceof LocalAuthorizationError || error62 instanceof LocalAgentCatalogError || error62 instanceof
|
|
39238
|
+
if (error62 instanceof AcpExecutionError || error62 instanceof LocalAuthorizationError || error62 instanceof LocalAgentCatalogError || error62 instanceof PromptArtifactError) {
|
|
39873
39239
|
return error62.code;
|
|
39874
39240
|
}
|
|
39875
39241
|
return "session_operation_failed";
|
|
39876
39242
|
}
|
|
39877
39243
|
function operationErrorMessage(error62) {
|
|
39878
|
-
if (error62 instanceof AcpExecutionError || error62 instanceof LocalAuthorizationError || error62 instanceof LocalAgentCatalogError || error62 instanceof
|
|
39244
|
+
if (error62 instanceof AcpExecutionError || error62 instanceof LocalAuthorizationError || error62 instanceof LocalAgentCatalogError || error62 instanceof PromptArtifactError) {
|
|
39879
39245
|
return error62.message;
|
|
39880
39246
|
}
|
|
39881
39247
|
return "The local agent operation could not be completed";
|
|
@@ -39910,7 +39276,7 @@ async function resolveSessionDirectories(directories, bindingId, directoryId2, a
|
|
|
39910
39276
|
additionalDirectories.push(directory);
|
|
39911
39277
|
additionalDirectoryEntries.push({
|
|
39912
39278
|
directoryId: additionalDirectoryId,
|
|
39913
|
-
name:
|
|
39279
|
+
name: basename6(directory)
|
|
39914
39280
|
});
|
|
39915
39281
|
}
|
|
39916
39282
|
return new ResolvedSessionDirectories(cwd, additionalDirectories, additionalDirectoryEntries);
|
|
@@ -40140,11 +39506,13 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
40140
39506
|
} else {
|
|
40141
39507
|
await applyCompleteSessionConfiguration(
|
|
40142
39508
|
sessions,
|
|
39509
|
+
audit,
|
|
40143
39510
|
prepared.configOptions,
|
|
40144
39511
|
command.sessionConfigurations,
|
|
40145
39512
|
agent,
|
|
40146
39513
|
resolved.cwd,
|
|
40147
39514
|
resolved.additionalDirectories,
|
|
39515
|
+
command.commandId,
|
|
40148
39516
|
command.sessionId,
|
|
40149
39517
|
signal
|
|
40150
39518
|
);
|
|
@@ -40285,6 +39653,26 @@ function assertSessionConfigurationSchema(options, selections) {
|
|
|
40285
39653
|
}
|
|
40286
39654
|
}
|
|
40287
39655
|
}
|
|
39656
|
+
function assertSessionConfigurationCoverage(options, selections) {
|
|
39657
|
+
const selectionsById = new Map(selections.map((selection) => [selection.configId, selection]));
|
|
39658
|
+
if (selectionsById.size !== selections.length) {
|
|
39659
|
+
throw invalidSessionConfiguration("The Turn configuration contains duplicate Agent settings");
|
|
39660
|
+
}
|
|
39661
|
+
for (const option of options) {
|
|
39662
|
+
if (!selectionsById.has(option.id)) {
|
|
39663
|
+
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
|
|
39664
|
+
}
|
|
39665
|
+
}
|
|
39666
|
+
}
|
|
39667
|
+
function sessionConfigurationSelectionIsAvailable(option, selection) {
|
|
39668
|
+
if (option.type !== selection.valueType) {
|
|
39669
|
+
return false;
|
|
39670
|
+
}
|
|
39671
|
+
if (option.type === "boolean") {
|
|
39672
|
+
return selection.value.length === 0;
|
|
39673
|
+
}
|
|
39674
|
+
return !selection.booleanValue && option.values.some((value) => value.value === selection.value);
|
|
39675
|
+
}
|
|
40288
39676
|
function sessionConfigurationMatches(option, selection) {
|
|
40289
39677
|
validateSessionConfigurationSelection(option, selection);
|
|
40290
39678
|
return option.type === "boolean" ? option.booleanValue === selection.booleanValue : option.currentValue === selection.value;
|
|
@@ -40315,11 +39703,92 @@ function assertCompleteSessionConfiguration(options, selections) {
|
|
|
40315
39703
|
}
|
|
40316
39704
|
}
|
|
40317
39705
|
}
|
|
40318
|
-
|
|
39706
|
+
function assertAppliedSessionConfiguration(options, selections) {
|
|
39707
|
+
const selectionsById = new Map(selections.map((selection) => [selection.configId, selection]));
|
|
39708
|
+
for (const option of options) {
|
|
39709
|
+
const selection = selectionsById.get(option.id);
|
|
39710
|
+
if (option.id === AGENT_PERMISSION_MODE_CONFIG_ID) {
|
|
39711
|
+
if (selection === void 0 || !sessionConfigurationMatches(option, selection)) {
|
|
39712
|
+
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
|
|
39713
|
+
}
|
|
39714
|
+
continue;
|
|
39715
|
+
}
|
|
39716
|
+
if (selection === void 0 || !sessionConfigurationSelectionIsAvailable(option, selection)) {
|
|
39717
|
+
continue;
|
|
39718
|
+
}
|
|
39719
|
+
if (!sessionConfigurationMatches(option, selection)) {
|
|
39720
|
+
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
|
|
39721
|
+
}
|
|
39722
|
+
}
|
|
39723
|
+
}
|
|
39724
|
+
function unavailableSessionConfigurationCategory(selection) {
|
|
39725
|
+
if (selection.configId === "model") {
|
|
39726
|
+
return "model";
|
|
39727
|
+
}
|
|
39728
|
+
if (selection.configId === "reasoning_effort") {
|
|
39729
|
+
return "thought_level";
|
|
39730
|
+
}
|
|
39731
|
+
return "unknown";
|
|
39732
|
+
}
|
|
39733
|
+
async function applySessionConfigurationSelection(sessions, audit, options, selection, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
|
|
40319
39734
|
const option = options.find((candidate) => candidate.id === selection.configId);
|
|
40320
39735
|
if (option === void 0) {
|
|
39736
|
+
if (selection.configId !== AGENT_PERMISSION_MODE_CONFIG_ID) {
|
|
39737
|
+
warnIgnoredSetting(
|
|
39738
|
+
audit,
|
|
39739
|
+
"session_configuration_setting_ignored",
|
|
39740
|
+
commandId,
|
|
39741
|
+
sessionId,
|
|
39742
|
+
agent.id,
|
|
39743
|
+
selection,
|
|
39744
|
+
unavailableSessionConfigurationCategory(selection),
|
|
39745
|
+
"setting_unavailable"
|
|
39746
|
+
);
|
|
39747
|
+
return options;
|
|
39748
|
+
}
|
|
40321
39749
|
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} is unavailable`);
|
|
40322
39750
|
}
|
|
39751
|
+
if (selection.configId !== AGENT_PERMISSION_MODE_CONFIG_ID) {
|
|
39752
|
+
if (option.type !== selection.valueType) {
|
|
39753
|
+
warnIgnoredSetting(
|
|
39754
|
+
audit,
|
|
39755
|
+
"session_configuration_setting_ignored",
|
|
39756
|
+
commandId,
|
|
39757
|
+
sessionId,
|
|
39758
|
+
agent.id,
|
|
39759
|
+
selection,
|
|
39760
|
+
option.category,
|
|
39761
|
+
"setting_schema_mismatch"
|
|
39762
|
+
);
|
|
39763
|
+
return options;
|
|
39764
|
+
}
|
|
39765
|
+
if (option.type === "boolean" && selection.value.length > 0 || option.type === "select" && selection.booleanValue) {
|
|
39766
|
+
warnIgnoredSetting(
|
|
39767
|
+
audit,
|
|
39768
|
+
"session_configuration_setting_ignored",
|
|
39769
|
+
commandId,
|
|
39770
|
+
sessionId,
|
|
39771
|
+
agent.id,
|
|
39772
|
+
selection,
|
|
39773
|
+
option.category,
|
|
39774
|
+
"selection_schema_mismatch"
|
|
39775
|
+
);
|
|
39776
|
+
return options;
|
|
39777
|
+
}
|
|
39778
|
+
if (option.type === "select" && !option.values.some((value) => value.value === selection.value)) {
|
|
39779
|
+
warnIgnoredSetting(
|
|
39780
|
+
audit,
|
|
39781
|
+
"session_configuration_setting_ignored",
|
|
39782
|
+
commandId,
|
|
39783
|
+
sessionId,
|
|
39784
|
+
agent.id,
|
|
39785
|
+
selection,
|
|
39786
|
+
option.category,
|
|
39787
|
+
"value_unavailable"
|
|
39788
|
+
);
|
|
39789
|
+
return options;
|
|
39790
|
+
}
|
|
39791
|
+
}
|
|
40323
39792
|
if (sessionConfigurationMatches(option, selection)) {
|
|
40324
39793
|
return options;
|
|
40325
39794
|
}
|
|
@@ -40336,8 +39805,8 @@ async function applySessionConfigurationSelection(sessions, options, selection,
|
|
|
40336
39805
|
valueType: selection.valueType
|
|
40337
39806
|
});
|
|
40338
39807
|
}
|
|
40339
|
-
async function applyCompleteSessionConfiguration(sessions, initialOptions, selections, agent, cwd, additionalDirectories, sessionId, signal) {
|
|
40340
|
-
|
|
39808
|
+
async function applyCompleteSessionConfiguration(sessions, audit, initialOptions, selections, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
|
|
39809
|
+
assertSessionConfigurationCoverage(initialOptions, selections);
|
|
40341
39810
|
let options = initialOptions;
|
|
40342
39811
|
const orderedSelections = selections.toSorted((left, right) => {
|
|
40343
39812
|
const priority = sessionConfigurationPriority(left, initialOptions) - sessionConfigurationPriority(right, initialOptions);
|
|
@@ -40346,50 +39815,20 @@ async function applyCompleteSessionConfiguration(sessions, initialOptions, selec
|
|
|
40346
39815
|
for (const selection of orderedSelections) {
|
|
40347
39816
|
options = await applySessionConfigurationSelection(
|
|
40348
39817
|
sessions,
|
|
39818
|
+
audit,
|
|
40349
39819
|
options,
|
|
40350
39820
|
selection,
|
|
40351
39821
|
agent,
|
|
40352
39822
|
cwd,
|
|
40353
39823
|
additionalDirectories,
|
|
39824
|
+
commandId,
|
|
40354
39825
|
sessionId,
|
|
40355
39826
|
signal
|
|
40356
39827
|
);
|
|
40357
39828
|
}
|
|
40358
|
-
|
|
40359
|
-
}
|
|
40360
|
-
function botExecutionAgent(agent, contextHandle, socketPath) {
|
|
40361
|
-
return new LocalAgentDefinition(
|
|
40362
|
-
agent.id,
|
|
40363
|
-
agent.label,
|
|
40364
|
-
agent.command,
|
|
40365
|
-
agent.arguments,
|
|
40366
|
-
{
|
|
40367
|
-
...agent.environment,
|
|
40368
|
-
MOBIUS_BOT_CONTEXT: contextHandle,
|
|
40369
|
-
MOBIUS_BOT_SOCKET: socketPath,
|
|
40370
|
-
MOBIUS_RELAY_TOKEN: "",
|
|
40371
|
-
MOBIUS_RELAY_URL: ""
|
|
40372
|
-
},
|
|
40373
|
-
agent.adapterVersion,
|
|
40374
|
-
agent.agentVersion,
|
|
40375
|
-
agent.adapterIdentity,
|
|
40376
|
-
agent.agentIdentity,
|
|
40377
|
-
agent.promptTimeoutMilliseconds,
|
|
40378
|
-
agent.capabilities,
|
|
40379
|
-
agent.permissionProfile
|
|
40380
|
-
);
|
|
40381
|
-
}
|
|
40382
|
-
function assertPreparedPermission(configOptions, permissionMode) {
|
|
40383
|
-
const permission = configOptions.find((option) => option.id === "permission_mode");
|
|
40384
|
-
if (permission === void 0 || permission.type !== "select" || permissionMode !== AGENT_DEFAULT_EXECUTION_SETTING && permission.currentValue !== permissionMode) {
|
|
40385
|
-
throw new AcpExecutionError(
|
|
40386
|
-
"The required Agent permission mode is unavailable",
|
|
40387
|
-
{},
|
|
40388
|
-
"invalid_session_configuration"
|
|
40389
|
-
);
|
|
40390
|
-
}
|
|
39829
|
+
assertAppliedSessionConfiguration(options, selections);
|
|
40391
39830
|
}
|
|
40392
|
-
function
|
|
39831
|
+
function warnIgnoredSetting(audit, event, commandId, sessionId, agentId, selection, category, reason) {
|
|
40393
39832
|
const details = {
|
|
40394
39833
|
agentId,
|
|
40395
39834
|
category,
|
|
@@ -40397,264 +39836,10 @@ function warnIgnoredExecutionSetting(audit, commandId, sessionId, agentId, selec
|
|
|
40397
39836
|
reason,
|
|
40398
39837
|
requestedValue: selection.value
|
|
40399
39838
|
};
|
|
40400
|
-
const event = "bot_execution_setting_ignored";
|
|
40401
39839
|
audit.record({ commandId, details, event, sessionId });
|
|
40402
39840
|
process.stderr.write(`Mobius daemon warning ${JSON.stringify({ commandId, event, sessionId, ...details })}
|
|
40403
39841
|
`);
|
|
40404
39842
|
}
|
|
40405
|
-
async function applySupportedExecutionSelection(sessions, audit, configOptions, selection, category, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
|
|
40406
|
-
if (selection.value === AGENT_DEFAULT_EXECUTION_SETTING) {
|
|
40407
|
-
return configOptions;
|
|
40408
|
-
}
|
|
40409
|
-
const option = configOptions.find((candidate) => candidate.id === selection.configId);
|
|
40410
|
-
if (option === void 0) {
|
|
40411
|
-
warnIgnoredExecutionSetting(audit, commandId, sessionId, agent.id, selection, category, "setting_unavailable");
|
|
40412
|
-
return configOptions;
|
|
40413
|
-
}
|
|
40414
|
-
if (option.type !== "select" || option.category !== category) {
|
|
40415
|
-
warnIgnoredExecutionSetting(
|
|
40416
|
-
audit,
|
|
40417
|
-
commandId,
|
|
40418
|
-
sessionId,
|
|
40419
|
-
agent.id,
|
|
40420
|
-
selection,
|
|
40421
|
-
category,
|
|
40422
|
-
"setting_schema_mismatch"
|
|
40423
|
-
);
|
|
40424
|
-
return configOptions;
|
|
40425
|
-
}
|
|
40426
|
-
if (selection.valueType !== "select" || selection.booleanValue) {
|
|
40427
|
-
warnIgnoredExecutionSetting(
|
|
40428
|
-
audit,
|
|
40429
|
-
commandId,
|
|
40430
|
-
sessionId,
|
|
40431
|
-
agent.id,
|
|
40432
|
-
selection,
|
|
40433
|
-
category,
|
|
40434
|
-
"selection_schema_mismatch"
|
|
40435
|
-
);
|
|
40436
|
-
return configOptions;
|
|
40437
|
-
}
|
|
40438
|
-
if (!option.values.some((value) => value.value === selection.value)) {
|
|
40439
|
-
warnIgnoredExecutionSetting(audit, commandId, sessionId, agent.id, selection, category, "value_unavailable");
|
|
40440
|
-
return configOptions;
|
|
40441
|
-
}
|
|
40442
|
-
if (option.currentValue === selection.value) {
|
|
40443
|
-
return configOptions;
|
|
40444
|
-
}
|
|
40445
|
-
return await sessions.configureSession({
|
|
40446
|
-
additionalDirectories,
|
|
40447
|
-
agent,
|
|
40448
|
-
booleanValue: false,
|
|
40449
|
-
configId: selection.configId,
|
|
40450
|
-
cwd,
|
|
40451
|
-
requestId: `cfg_${randomUUID3()}`,
|
|
40452
|
-
sessionId,
|
|
40453
|
-
signal,
|
|
40454
|
-
value: selection.value,
|
|
40455
|
-
valueType: "select"
|
|
40456
|
-
});
|
|
40457
|
-
}
|
|
40458
|
-
async function executeBotPrompt(outbox, publisher, command, config2, directories, audit, sessions, authorizer, contexts, applicator, ipc, attemptId, activateAttempt, timer, signal) {
|
|
40459
|
-
const activities = new CoalescingDaemonActivityPublisher(timer, (activity) => {
|
|
40460
|
-
publisher.recordAttempt(command.sessionId, encodeDaemonActivity(command, activity), attemptId);
|
|
40461
|
-
});
|
|
40462
|
-
try {
|
|
40463
|
-
const deadline = Date.parse(command.executionDeadlineAt);
|
|
40464
|
-
const remaining = deadline - Date.now();
|
|
40465
|
-
if (!Number.isSafeInteger(deadline) || remaining <= 0) {
|
|
40466
|
-
throw new LocalBotAuthorizationError("turn_expired", "The Bot execution deadline has expired");
|
|
40467
|
-
}
|
|
40468
|
-
const execution = await authorizer.authorize(command, config2.catalog, directories, config2.bindingId, signal);
|
|
40469
|
-
const resolved = await resolveSessionDirectories(
|
|
40470
|
-
directories,
|
|
40471
|
-
config2.bindingId,
|
|
40472
|
-
command.directoryId,
|
|
40473
|
-
command.additionalDirectoryIds,
|
|
40474
|
-
signal
|
|
40475
|
-
);
|
|
40476
|
-
const attachments = await resolvePromptArtifacts(config2, command, signal);
|
|
40477
|
-
const applied = await applicator.apply(command, execution, attachments.resources, signal);
|
|
40478
|
-
const deadlineSignal = AbortSignal.timeout(remaining);
|
|
40479
|
-
const executionSignal = AbortSignal.any([signal, deadlineSignal]);
|
|
40480
|
-
const startExecution = () => {
|
|
40481
|
-
audit.record({
|
|
40482
|
-
commandId: command.commandId,
|
|
40483
|
-
details: {
|
|
40484
|
-
behaviorRevisionId: command.behaviorRevisionId,
|
|
40485
|
-
bindingId: command.bindingId,
|
|
40486
|
-
botId: command.botId,
|
|
40487
|
-
executionId: command.executionId
|
|
40488
|
-
},
|
|
40489
|
-
event: "bot_session_authorized",
|
|
40490
|
-
sessionId: command.sessionId
|
|
40491
|
-
});
|
|
40492
|
-
outbox.transitionExecution(command.commandId, "running");
|
|
40493
|
-
publisher.recordAttempt(
|
|
40494
|
-
command.sessionId,
|
|
40495
|
-
encodeSessionStartedEvent({
|
|
40496
|
-
attemptId,
|
|
40497
|
-
commandId: command.commandId,
|
|
40498
|
-
kind: SESSION_STARTED_KIND,
|
|
40499
|
-
sessionId: command.sessionId
|
|
40500
|
-
}),
|
|
40501
|
-
attemptId
|
|
40502
|
-
);
|
|
40503
|
-
activateAttempt();
|
|
40504
|
-
};
|
|
40505
|
-
let stopReason = "steered";
|
|
40506
|
-
if (command.disposition === SessionPromptDisposition.Steer) {
|
|
40507
|
-
startExecution();
|
|
40508
|
-
await sessions.steerPrompt({
|
|
40509
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
40510
|
-
agent: execution.agent,
|
|
40511
|
-
commandId: command.commandId,
|
|
40512
|
-
cwd: resolved.cwd,
|
|
40513
|
-
images: attachments.images,
|
|
40514
|
-
prompt: command.prompt,
|
|
40515
|
-
resources: applied.resources,
|
|
40516
|
-
sessionId: command.sessionId,
|
|
40517
|
-
signal: executionSignal,
|
|
40518
|
-
targetCommandId: command.targetCommandId
|
|
40519
|
-
});
|
|
40520
|
-
} else {
|
|
40521
|
-
if (command.disposition === SessionPromptDisposition.Queue && !outbox.isTerminalExecution(command.targetCommandId, command.sessionId)) {
|
|
40522
|
-
throw new AcpExecutionError(
|
|
40523
|
-
"The queued Bot prompt target is unavailable",
|
|
40524
|
-
{},
|
|
40525
|
-
"prompt_queue_target_unavailable"
|
|
40526
|
-
);
|
|
40527
|
-
}
|
|
40528
|
-
const lease = contexts.activate(command);
|
|
40529
|
-
try {
|
|
40530
|
-
const agent = botExecutionAgent(execution.agent, lease.context.contextHandle, ipc.socketPath);
|
|
40531
|
-
const prepared = await sessions.prepareExecutionSession({
|
|
40532
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
40533
|
-
agent,
|
|
40534
|
-
cwd: resolved.cwd,
|
|
40535
|
-
sessionId: command.sessionId,
|
|
40536
|
-
signal: executionSignal
|
|
40537
|
-
});
|
|
40538
|
-
assertPreparedPermission(prepared.configOptions, execution.executionConfiguration.permissionMode);
|
|
40539
|
-
let configOptions = await applySupportedExecutionSelection(
|
|
40540
|
-
sessions,
|
|
40541
|
-
audit,
|
|
40542
|
-
prepared.configOptions,
|
|
40543
|
-
execution.executionConfiguration.model,
|
|
40544
|
-
"model",
|
|
40545
|
-
agent,
|
|
40546
|
-
resolved.cwd,
|
|
40547
|
-
resolved.additionalDirectories,
|
|
40548
|
-
command.commandId,
|
|
40549
|
-
command.sessionId,
|
|
40550
|
-
executionSignal
|
|
40551
|
-
);
|
|
40552
|
-
configOptions = await applySupportedExecutionSelection(
|
|
40553
|
-
sessions,
|
|
40554
|
-
audit,
|
|
40555
|
-
configOptions,
|
|
40556
|
-
execution.executionConfiguration.reasoningEffort,
|
|
40557
|
-
"thought_level",
|
|
40558
|
-
agent,
|
|
40559
|
-
resolved.cwd,
|
|
40560
|
-
resolved.additionalDirectories,
|
|
40561
|
-
command.commandId,
|
|
40562
|
-
command.sessionId,
|
|
40563
|
-
executionSignal
|
|
40564
|
-
);
|
|
40565
|
-
for (const selection of command.sessionConfigurations) {
|
|
40566
|
-
await sessions.configureSession({
|
|
40567
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
40568
|
-
agent,
|
|
40569
|
-
booleanValue: selection.booleanValue,
|
|
40570
|
-
configId: selection.configId,
|
|
40571
|
-
cwd: resolved.cwd,
|
|
40572
|
-
requestId: `cfg_${randomUUID3()}`,
|
|
40573
|
-
sessionId: command.sessionId,
|
|
40574
|
-
signal: executionSignal,
|
|
40575
|
-
value: selection.value,
|
|
40576
|
-
valueType: selection.valueType
|
|
40577
|
-
});
|
|
40578
|
-
}
|
|
40579
|
-
startExecution();
|
|
40580
|
-
const result = await sessions.runPrompt({
|
|
40581
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
40582
|
-
agent,
|
|
40583
|
-
commandId: command.commandId,
|
|
40584
|
-
cwd: resolved.cwd,
|
|
40585
|
-
disposition: command.disposition,
|
|
40586
|
-
images: attachments.images,
|
|
40587
|
-
onActivity: activities.record,
|
|
40588
|
-
onText: (text3, messageId) => {
|
|
40589
|
-
publisher.recordAttempt(
|
|
40590
|
-
command.sessionId,
|
|
40591
|
-
encodeAgentMessageDeltaEvent({
|
|
40592
|
-
commandId: command.commandId,
|
|
40593
|
-
kind: AGENT_MESSAGE_DELTA_KIND,
|
|
40594
|
-
messageId,
|
|
40595
|
-
sessionId: command.sessionId,
|
|
40596
|
-
text: text3
|
|
40597
|
-
}),
|
|
40598
|
-
attemptId
|
|
40599
|
-
);
|
|
40600
|
-
return Promise.resolve();
|
|
40601
|
-
},
|
|
40602
|
-
prompt: command.prompt,
|
|
40603
|
-
resources: applied.resources,
|
|
40604
|
-
sessionId: command.sessionId,
|
|
40605
|
-
signal: executionSignal,
|
|
40606
|
-
targetCommandId: command.targetCommandId
|
|
40607
|
-
});
|
|
40608
|
-
stopReason = result.stopReason;
|
|
40609
|
-
} finally {
|
|
40610
|
-
lease.release();
|
|
40611
|
-
}
|
|
40612
|
-
}
|
|
40613
|
-
activities.flush();
|
|
40614
|
-
publisher.recordAttempt(
|
|
40615
|
-
command.sessionId,
|
|
40616
|
-
encodeSessionCompletedEvent({
|
|
40617
|
-
commandId: command.commandId,
|
|
40618
|
-
kind: SESSION_COMPLETED_KIND,
|
|
40619
|
-
sessionId: command.sessionId,
|
|
40620
|
-
stopReason
|
|
40621
|
-
}),
|
|
40622
|
-
attemptId
|
|
40623
|
-
);
|
|
40624
|
-
outbox.transitionExecution(command.commandId, stopReason === "cancelled" ? "cancelled" : "succeeded");
|
|
40625
|
-
audit.record({
|
|
40626
|
-
commandId: command.commandId,
|
|
40627
|
-
details: { botId: command.botId, executionId: command.executionId },
|
|
40628
|
-
event: stopReason === "cancelled" ? "bot_session_cancelled" : "bot_session_completed",
|
|
40629
|
-
sessionId: command.sessionId
|
|
40630
|
-
});
|
|
40631
|
-
} catch (error62) {
|
|
40632
|
-
activities.flush();
|
|
40633
|
-
const failure2 = Date.parse(command.executionDeadlineAt) <= Date.now() ? new LocalBotAuthorizationError("turn_expired", "The Bot execution deadline has expired", {
|
|
40634
|
-
cause: error62
|
|
40635
|
-
}) : error62;
|
|
40636
|
-
audit.record({
|
|
40637
|
-
commandId: command.commandId,
|
|
40638
|
-
details: {
|
|
40639
|
-
botId: command.botId,
|
|
40640
|
-
code: operationErrorCode(failure2),
|
|
40641
|
-
executionId: command.executionId
|
|
40642
|
-
},
|
|
40643
|
-
event: "bot_session_failed",
|
|
40644
|
-
sessionId: command.sessionId
|
|
40645
|
-
});
|
|
40646
|
-
const code = operationErrorCode(failure2);
|
|
40647
|
-
reportFailure(
|
|
40648
|
-
publisher,
|
|
40649
|
-
command,
|
|
40650
|
-
code === "session_operation_failed" ? "agent_execution_failed" : code,
|
|
40651
|
-
code === "session_operation_failed" ? "The local agent could not complete the Bot request" : operationErrorMessage(failure2),
|
|
40652
|
-
attemptId
|
|
40653
|
-
);
|
|
40654
|
-
outbox.transitionExecution(command.commandId, "failed");
|
|
40655
|
-
console.error("Mobius daemon Bot command failed", failure2);
|
|
40656
|
-
}
|
|
40657
|
-
}
|
|
40658
39843
|
function waitForRelayRetry(signal, timer) {
|
|
40659
39844
|
if (signal.aborted) {
|
|
40660
39845
|
return Promise.resolve();
|
|
@@ -40707,7 +39892,7 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
|
|
|
40707
39892
|
);
|
|
40708
39893
|
}
|
|
40709
39894
|
}
|
|
40710
|
-
async function runRelayConnection(config2, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher,
|
|
39895
|
+
async function runRelayConnection(config2, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher, activeTurns, activeAttemptIds, connectionEpoch, diagnostics, onConnected, signal, timer) {
|
|
40711
39896
|
const relayUrl = new URL(config2.relayUrl);
|
|
40712
39897
|
relayUrl.searchParams.set("deliveryReceipts", "1");
|
|
40713
39898
|
relayUrl.searchParams.set("liveness", "1");
|
|
@@ -40873,32 +40058,6 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
40873
40058
|
}
|
|
40874
40059
|
return;
|
|
40875
40060
|
}
|
|
40876
|
-
if (kind === BOT_SESSION_PROMPT_KIND) {
|
|
40877
|
-
const command = decodeBotSessionPromptCommand(delivery.payload);
|
|
40878
|
-
await processDeliveredPrompt(
|
|
40879
|
-
delivery,
|
|
40880
|
-
command,
|
|
40881
|
-
command.disposition !== SessionPromptDisposition.Steer,
|
|
40882
|
-
(attemptId, activateAttempt, executionSignal) => executeBotPrompt(
|
|
40883
|
-
outbox,
|
|
40884
|
-
publisher,
|
|
40885
|
-
command,
|
|
40886
|
-
config2,
|
|
40887
|
-
directories,
|
|
40888
|
-
audit,
|
|
40889
|
-
sessions,
|
|
40890
|
-
authorizer,
|
|
40891
|
-
contexts,
|
|
40892
|
-
applicator,
|
|
40893
|
-
ipc,
|
|
40894
|
-
attemptId,
|
|
40895
|
-
activateAttempt,
|
|
40896
|
-
timer,
|
|
40897
|
-
executionSignal
|
|
40898
|
-
)
|
|
40899
|
-
);
|
|
40900
|
-
return;
|
|
40901
|
-
}
|
|
40902
40061
|
if (kind === SESSION_PROMPT_KIND) {
|
|
40903
40062
|
const command = decodeSessionPromptCommand(delivery.payload);
|
|
40904
40063
|
await processDeliveredPrompt(
|
|
@@ -40956,8 +40115,6 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
40956
40115
|
payloadSessionId = decodeSessionElicitationRespondCommand(delivery.payload).sessionId;
|
|
40957
40116
|
} else if (payloadKind === SESSION_PROMPT_KIND) {
|
|
40958
40117
|
payloadSessionId = decodeSessionPromptCommand(delivery.payload).sessionId;
|
|
40959
|
-
} else if (payloadKind === BOT_SESSION_PROMPT_KIND) {
|
|
40960
|
-
payloadSessionId = decodeBotSessionPromptCommand(delivery.payload).sessionId;
|
|
40961
40118
|
} else {
|
|
40962
40119
|
throw new Error("Runtime delivery contains an unsupported protocol message");
|
|
40963
40120
|
}
|
|
@@ -41350,6 +40507,29 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
41350
40507
|
connectionLiveness.acknowledge(decodeRuntimeHeartbeatAckEvent(encoded));
|
|
41351
40508
|
return;
|
|
41352
40509
|
}
|
|
40510
|
+
if (kind === FILE_READ_KIND) {
|
|
40511
|
+
const command2 = decodeFileReadCommand(encoded);
|
|
40512
|
+
void streamLocalFile(
|
|
40513
|
+
command2,
|
|
40514
|
+
(message) => send(socket, message),
|
|
40515
|
+
connectionController.signal
|
|
40516
|
+
).catch((error62) => {
|
|
40517
|
+
if (socket.readyState !== WebSocket2.OPEN || connectionController.signal.aborted) {
|
|
40518
|
+
return;
|
|
40519
|
+
}
|
|
40520
|
+
send(
|
|
40521
|
+
socket,
|
|
40522
|
+
encodeFileFailedEvent({
|
|
40523
|
+
code: "file_unavailable",
|
|
40524
|
+
kind: FILE_FAILED_KIND,
|
|
40525
|
+
message: error62 instanceof Error ? error62.message : "The local file is unavailable",
|
|
40526
|
+
requestId: command2.requestId,
|
|
40527
|
+
sessionId: command2.sessionId
|
|
40528
|
+
})
|
|
40529
|
+
);
|
|
40530
|
+
});
|
|
40531
|
+
return;
|
|
40532
|
+
}
|
|
41353
40533
|
if (kind === SESSION_CANCEL_KIND) {
|
|
41354
40534
|
const cancellation = decodeSessionCancelCommand(encoded);
|
|
41355
40535
|
const turn2 = activeTurns.get(cancellation.commandId);
|
|
@@ -41443,48 +40623,6 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
41443
40623
|
});
|
|
41444
40624
|
return;
|
|
41445
40625
|
}
|
|
41446
|
-
if (kind === BOT_SESSION_PROMPT_KIND) {
|
|
41447
|
-
const command2 = decodeBotSessionPromptCommand(encoded);
|
|
41448
|
-
if (activeTurns.has(command2.commandId)) {
|
|
41449
|
-
return;
|
|
41450
|
-
}
|
|
41451
|
-
const receipt2 = outbox.claimExecution(command2.commandId, command2.sessionId, encoded);
|
|
41452
|
-
if (receipt2.kind === "duplicate") {
|
|
41453
|
-
return;
|
|
41454
|
-
}
|
|
41455
|
-
const turn2 = new ActiveDaemonTurn(command2, receipt2.attemptId);
|
|
41456
|
-
activeTurns.set(command2.commandId, turn2);
|
|
41457
|
-
void executeBotPrompt(
|
|
41458
|
-
outbox,
|
|
41459
|
-
publisher,
|
|
41460
|
-
command2,
|
|
41461
|
-
config2,
|
|
41462
|
-
directories,
|
|
41463
|
-
audit,
|
|
41464
|
-
sessions,
|
|
41465
|
-
authorizer,
|
|
41466
|
-
contexts,
|
|
41467
|
-
applicator,
|
|
41468
|
-
ipc,
|
|
41469
|
-
receipt2.attemptId,
|
|
41470
|
-
() => {
|
|
41471
|
-
if (command2.disposition !== SessionPromptDisposition.Steer) {
|
|
41472
|
-
activeAttemptIds.set(command2.sessionId, receipt2.attemptId);
|
|
41473
|
-
}
|
|
41474
|
-
},
|
|
41475
|
-
timer,
|
|
41476
|
-
turn2.signal
|
|
41477
|
-
).catch((error62) => {
|
|
41478
|
-
console.error("Mobius daemon Bot turn failed", error62);
|
|
41479
|
-
}).finally(() => {
|
|
41480
|
-
activeTurns.delete(command2.commandId);
|
|
41481
|
-
if (activeAttemptIds.get(command2.sessionId) === receipt2.attemptId) {
|
|
41482
|
-
activeAttemptIds.delete(command2.sessionId);
|
|
41483
|
-
}
|
|
41484
|
-
turn2.finish();
|
|
41485
|
-
});
|
|
41486
|
-
return;
|
|
41487
|
-
}
|
|
41488
40626
|
if (kind !== SESSION_PROMPT_KIND) {
|
|
41489
40627
|
throw new Error("Unsupported protocol message");
|
|
41490
40628
|
}
|
|
@@ -41588,10 +40726,6 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
41588
40726
|
const sessionStore = new SqliteAcpSessionStore(config2.auditDatabasePath);
|
|
41589
40727
|
const outbox = new SessionEventOutbox(config2.auditDatabasePath);
|
|
41590
40728
|
const publisher = new DaemonSessionEventPublisher(outbox, timer);
|
|
41591
|
-
const authorizer = new LocalBotExecutionAuthorizer();
|
|
41592
|
-
const contexts = new BotExecutionContextRegistry();
|
|
41593
|
-
const applicator = new EmbeddedBotContextApplicator();
|
|
41594
|
-
const ipc = new BotOutboundIpcServer(botIpcSocketPath(), config2.relayUrl, contexts);
|
|
41595
40729
|
const activeTurns = /* @__PURE__ */ new Map();
|
|
41596
40730
|
const activeAttemptIds = /* @__PURE__ */ new Map();
|
|
41597
40731
|
const recordSessionEvent = (sessionId, payload) => {
|
|
@@ -41665,7 +40799,6 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
41665
40799
|
startAutomaticIntegrationProvisioning();
|
|
41666
40800
|
});
|
|
41667
40801
|
try {
|
|
41668
|
-
await ipc.listen(signal);
|
|
41669
40802
|
while (!signal.aborted) {
|
|
41670
40803
|
connectionEpoch += 1;
|
|
41671
40804
|
try {
|
|
@@ -41679,10 +40812,6 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
41679
40812
|
nativeSessions,
|
|
41680
40813
|
outbox,
|
|
41681
40814
|
publisher,
|
|
41682
|
-
authorizer,
|
|
41683
|
-
contexts,
|
|
41684
|
-
applicator,
|
|
41685
|
-
ipc,
|
|
41686
40815
|
activeTurns,
|
|
41687
40816
|
activeAttemptIds,
|
|
41688
40817
|
connectionEpoch,
|
|
@@ -41715,19 +40844,15 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
41715
40844
|
await installations.close();
|
|
41716
40845
|
} finally {
|
|
41717
40846
|
try {
|
|
41718
|
-
await
|
|
40847
|
+
await sessions.close();
|
|
41719
40848
|
} finally {
|
|
41720
40849
|
try {
|
|
41721
|
-
|
|
40850
|
+
sessionStore.close();
|
|
41722
40851
|
} finally {
|
|
41723
40852
|
try {
|
|
41724
|
-
|
|
40853
|
+
publisher.close();
|
|
41725
40854
|
} finally {
|
|
41726
|
-
|
|
41727
|
-
publisher.close();
|
|
41728
|
-
} finally {
|
|
41729
|
-
outbox.close();
|
|
41730
|
-
}
|
|
40855
|
+
outbox.close();
|
|
41731
40856
|
}
|
|
41732
40857
|
}
|
|
41733
40858
|
}
|
|
@@ -41739,14 +40864,14 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
41739
40864
|
|
|
41740
40865
|
// src/pairing/pair-local-machine.ts
|
|
41741
40866
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
41742
|
-
import { mkdir as
|
|
40867
|
+
import { mkdir as mkdir3, open as open5, realpath as realpath9, rename as rename3, stat as stat8, writeFile as writeFile2 } from "node:fs/promises";
|
|
41743
40868
|
import { hostname as hostname3 } from "node:os";
|
|
41744
|
-
import { basename as
|
|
41745
|
-
import { fetch as
|
|
40869
|
+
import { basename as basename7, join as join16, resolve as resolve4 } from "node:path";
|
|
40870
|
+
import { fetch as fetch6 } from "undici";
|
|
41746
40871
|
var PAIRING_TIMEOUT_MILLISECONDS = 2e4;
|
|
41747
40872
|
var PAIRING_CODE_PATTERN = /^[A-HJ-NP-Z2-9]{4}(?:-[A-HJ-NP-Z2-9]{4}){4}$/;
|
|
41748
|
-
var
|
|
41749
|
-
var
|
|
40873
|
+
var IDENTIFIER_PATTERN6 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
40874
|
+
var TOKEN_PATTERN = /^[a-zA-Z0-9_-]{32,256}$/;
|
|
41750
40875
|
var MAX_CONNECTION_FILE_LENGTH = 16 * 1024;
|
|
41751
40876
|
var CLAIM_RESPONSE_KEYS = ["channelId", "daemonToken", "runtimeId"];
|
|
41752
40877
|
var REDEEM_RESPONSE_KEYS = ["channelId", "runtimeCredential", "runtimeId"];
|
|
@@ -41760,7 +40885,7 @@ var PairingClientError = class extends Error {
|
|
|
41760
40885
|
this.name = "PairingClientError";
|
|
41761
40886
|
}
|
|
41762
40887
|
};
|
|
41763
|
-
function
|
|
40888
|
+
function isRecord9(value) {
|
|
41764
40889
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
41765
40890
|
}
|
|
41766
40891
|
function hasExactKeys(value, expectedKeys) {
|
|
@@ -41799,7 +40924,7 @@ function parsePairingCode(value) {
|
|
|
41799
40924
|
return code;
|
|
41800
40925
|
}
|
|
41801
40926
|
function validatePairingId(value) {
|
|
41802
|
-
if (!
|
|
40927
|
+
if (!IDENTIFIER_PATTERN6.test(value)) {
|
|
41803
40928
|
throw new PairingClientError("invalid_pairing_id", "The Runtime pairing ID is invalid");
|
|
41804
40929
|
}
|
|
41805
40930
|
return value;
|
|
@@ -41807,9 +40932,9 @@ function validatePairingId(value) {
|
|
|
41807
40932
|
async function resolveDefaultWorkspace2(path2) {
|
|
41808
40933
|
const requestedWorkspace = resolve4(path2);
|
|
41809
40934
|
try {
|
|
41810
|
-
await
|
|
41811
|
-
const defaultWorkspace = await
|
|
41812
|
-
const metadata = await
|
|
40935
|
+
await mkdir3(requestedWorkspace, { recursive: true, mode: 448 });
|
|
40936
|
+
const defaultWorkspace = await realpath9(requestedWorkspace);
|
|
40937
|
+
const metadata = await stat8(defaultWorkspace);
|
|
41813
40938
|
if (!metadata.isDirectory()) {
|
|
41814
40939
|
throw new PairingClientError("invalid_workspace", "The default workspace is not a directory");
|
|
41815
40940
|
}
|
|
@@ -41838,9 +40963,9 @@ async function readJsonResponse(response) {
|
|
|
41838
40963
|
}
|
|
41839
40964
|
}
|
|
41840
40965
|
function readRelayError(value) {
|
|
41841
|
-
if (
|
|
40966
|
+
if (isRecord9(value)) {
|
|
41842
40967
|
const error62 = value["error"];
|
|
41843
|
-
if (
|
|
40968
|
+
if (isRecord9(error62)) {
|
|
41844
40969
|
const code = error62["code"];
|
|
41845
40970
|
const message = error62["message"];
|
|
41846
40971
|
if (typeof code === "string" && typeof message === "string") {
|
|
@@ -41851,13 +40976,13 @@ function readRelayError(value) {
|
|
|
41851
40976
|
return new PairingClientError("pairing_failed", "The relay could not pair this machine");
|
|
41852
40977
|
}
|
|
41853
40978
|
function decodePairingResponse(value, credentialField, expectedKeys) {
|
|
41854
|
-
if (!
|
|
40979
|
+
if (!isRecord9(value) || !hasExactKeys(value, expectedKeys)) {
|
|
41855
40980
|
throw new PairingClientError("invalid_relay_response", "The relay returned an invalid pairing response");
|
|
41856
40981
|
}
|
|
41857
40982
|
const channelId = value["channelId"];
|
|
41858
40983
|
const runtimeCredential2 = value[credentialField];
|
|
41859
40984
|
const runtimeId = value["runtimeId"];
|
|
41860
|
-
if (typeof channelId !== "string" || !
|
|
40985
|
+
if (typeof channelId !== "string" || !IDENTIFIER_PATTERN6.test(channelId) || typeof runtimeCredential2 !== "string" || !TOKEN_PATTERN.test(runtimeCredential2) || typeof runtimeId !== "string" || !IDENTIFIER_PATTERN6.test(runtimeId)) {
|
|
41861
40986
|
throw new PairingClientError("invalid_relay_response", "The relay returned an invalid pairing response");
|
|
41862
40987
|
}
|
|
41863
40988
|
return { channelId, runtimeCredential: runtimeCredential2, runtimeId };
|
|
@@ -41867,7 +40992,6 @@ async function claimPairing(options, defaultWorkspace, localAgents, installableA
|
|
|
41867
40992
|
agentPath: agent.agentIdentity.requestedPath,
|
|
41868
40993
|
agentVersion: agent.agentVersion,
|
|
41869
40994
|
agentSettingsDiscovery: true,
|
|
41870
|
-
botSessionConfiguration: true,
|
|
41871
40995
|
capabilities: agent.capabilities,
|
|
41872
40996
|
id: agent.id,
|
|
41873
40997
|
label: agent.label,
|
|
@@ -41876,13 +41000,13 @@ async function claimPairing(options, defaultWorkspace, localAgents, installableA
|
|
|
41876
41000
|
const endpoint = options.pairingId.length > 0 ? mobiusApiUrl(options.relayOrigin, `/v1/runtime-pairings/${encodeURIComponent(options.pairingId)}/redeem`) : mobiusApiUrl(options.relayOrigin, "/pairings/claim");
|
|
41877
41001
|
let response;
|
|
41878
41002
|
try {
|
|
41879
|
-
response = await
|
|
41003
|
+
response = await fetch6(endpoint, {
|
|
41880
41004
|
body: JSON.stringify({
|
|
41881
41005
|
agents,
|
|
41882
41006
|
installableAgents,
|
|
41883
41007
|
machineName: hostname3(),
|
|
41884
41008
|
pairingCode: options.code,
|
|
41885
|
-
workspaceName:
|
|
41009
|
+
workspaceName: basename7(defaultWorkspace) || "Local workspace"
|
|
41886
41010
|
}),
|
|
41887
41011
|
dispatcher: environmentProxyDispatcher,
|
|
41888
41012
|
headers: { "content-type": "application/json" },
|
|
@@ -41899,10 +41023,10 @@ async function claimPairing(options, defaultWorkspace, localAgents, installableA
|
|
|
41899
41023
|
return options.pairingId.length > 0 ? decodePairingResponse(value, "runtimeCredential", REDEEM_RESPONSE_KEYS) : decodePairingResponse(value, "daemonToken", CLAIM_RESPONSE_KEYS);
|
|
41900
41024
|
}
|
|
41901
41025
|
async function persistConnection(channelId, relayOrigin, runtimeCredential2, defaultWorkspace, environment) {
|
|
41902
|
-
const connectionsDirectory =
|
|
41903
|
-
await
|
|
41904
|
-
const connectionPath =
|
|
41905
|
-
const temporaryPath =
|
|
41026
|
+
const connectionsDirectory = join16(readStateDirectory(environment), "connections");
|
|
41027
|
+
await mkdir3(connectionsDirectory, { mode: 448, recursive: true });
|
|
41028
|
+
const connectionPath = join16(connectionsDirectory, `${channelId}.json`);
|
|
41029
|
+
const temporaryPath = join16(connectionsDirectory, `.${channelId}.${randomUUID4()}.tmp`);
|
|
41906
41030
|
await writeFile2(
|
|
41907
41031
|
temporaryPath,
|
|
41908
41032
|
`${JSON.stringify(
|
|
@@ -41922,14 +41046,14 @@ async function persistConnection(channelId, relayOrigin, runtimeCredential2, def
|
|
|
41922
41046
|
return connectionPath;
|
|
41923
41047
|
}
|
|
41924
41048
|
function decodeSavedConnection(value, expectedChannelId) {
|
|
41925
|
-
if (!
|
|
41049
|
+
if (!isRecord9(value) || !hasExactKeys(value, SAVED_CONNECTION_KEYS) && !hasExactKeys(value, LEGACY_SAVED_CONNECTION_KEYS)) {
|
|
41926
41050
|
throw new PairingClientError("invalid_connection", "The saved connection is invalid");
|
|
41927
41051
|
}
|
|
41928
41052
|
const defaultWorkspace = value["defaultWorkspace"];
|
|
41929
41053
|
const channelId = value["channelId"];
|
|
41930
41054
|
const runtimeCredential2 = value["runtimeCredential"] ?? value["daemonToken"];
|
|
41931
41055
|
const relayOrigin = value["relayOrigin"];
|
|
41932
|
-
if (typeof defaultWorkspace !== "string" || typeof channelId !== "string" || channelId !== expectedChannelId || !
|
|
41056
|
+
if (typeof defaultWorkspace !== "string" || typeof channelId !== "string" || channelId !== expectedChannelId || !IDENTIFIER_PATTERN6.test(channelId) || typeof runtimeCredential2 !== "string" || !TOKEN_PATTERN.test(runtimeCredential2) || typeof relayOrigin !== "string") {
|
|
41933
41057
|
throw new PairingClientError("invalid_connection", "The saved connection is invalid");
|
|
41934
41058
|
}
|
|
41935
41059
|
return {
|
|
@@ -41940,9 +41064,9 @@ function decodeSavedConnection(value, expectedChannelId) {
|
|
|
41940
41064
|
};
|
|
41941
41065
|
}
|
|
41942
41066
|
async function readSavedConnection(channelId, environment) {
|
|
41943
|
-
const connectionPath =
|
|
41067
|
+
const connectionPath = join16(readStateDirectory(environment), "connections", `${channelId}.json`);
|
|
41944
41068
|
let encoded = "";
|
|
41945
|
-
const handle = await
|
|
41069
|
+
const handle = await open5(connectionPath, "r");
|
|
41946
41070
|
try {
|
|
41947
41071
|
const metadata = await handle.stat();
|
|
41948
41072
|
if (!metadata.isFile() || metadata.size > MAX_CONNECTION_FILE_LENGTH) {
|
|
@@ -41976,7 +41100,7 @@ function buildPairedDaemon(connection, connectionPath, inventory, environment) {
|
|
|
41976
41100
|
const relayUrl = mobiusApiUrl(connection.relayOrigin, "/v1/runtimes/connect");
|
|
41977
41101
|
relayUrl.protocol = relayUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
41978
41102
|
relayUrl.searchParams.set("token", connection.runtimeCredential);
|
|
41979
|
-
const auditDatabasePath =
|
|
41103
|
+
const auditDatabasePath = join16(readStateDirectory(environment), "audit", `${connection.channelId}.sqlite`);
|
|
41980
41104
|
return {
|
|
41981
41105
|
channelUrl: new URL(`/channels/${encodeURIComponent(connection.channelId)}`, connection.relayOrigin).toString(),
|
|
41982
41106
|
config: createDaemonConfig(
|
|
@@ -42035,7 +41159,7 @@ async function pairMobiusRuntime(options, signal, environment = process.env) {
|
|
|
42035
41159
|
}
|
|
42036
41160
|
async function resumeMobiusRuntime(channelId, signal, environment = process.env) {
|
|
42037
41161
|
const normalizedChannelId = validatePairingId(channelId);
|
|
42038
|
-
const connectionPath =
|
|
41162
|
+
const connectionPath = join16(readStateDirectory(environment), "connections", `${normalizedChannelId}.json`);
|
|
42039
41163
|
const connection = await readSavedConnection(normalizedChannelId, environment);
|
|
42040
41164
|
const inventory = await discoverLocalAgentInventory({
|
|
42041
41165
|
defaultWorkspace: connection.defaultWorkspace,
|
|
@@ -42046,7 +41170,7 @@ async function resumeMobiusRuntime(channelId, signal, environment = process.env)
|
|
|
42046
41170
|
}
|
|
42047
41171
|
|
|
42048
41172
|
// src/runtime.ts
|
|
42049
|
-
var
|
|
41173
|
+
var IDENTIFIER_PATTERN7 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
42050
41174
|
var RUNTIME_CREDENTIAL_PATTERN = /^[a-zA-Z0-9_-]{32,256}$/;
|
|
42051
41175
|
var MobiusRuntimeConfigurationError = class extends Error {
|
|
42052
41176
|
code = "runtime_configuration_invalid";
|
|
@@ -42098,11 +41222,11 @@ function relayUrlFromConnection(connection) {
|
|
|
42098
41222
|
}
|
|
42099
41223
|
function loadMobiusRuntimeConnection(environment = process.env) {
|
|
42100
41224
|
const channelId = requiredEnvironmentValue(environment, "MOBIUS_CHANNEL_ID");
|
|
42101
|
-
if (!
|
|
41225
|
+
if (!IDENTIFIER_PATTERN7.test(channelId)) {
|
|
42102
41226
|
throw new MobiusRuntimeConfigurationError("MOBIUS_CHANNEL_ID is invalid");
|
|
42103
41227
|
}
|
|
42104
41228
|
return Object.freeze({
|
|
42105
|
-
auditDatabasePath: environment["MOBIUS_AUDIT_DATABASE"]?.trim() ||
|
|
41229
|
+
auditDatabasePath: environment["MOBIUS_AUDIT_DATABASE"]?.trim() || join17(readStateDirectory(environment), "audit", `${channelId}.sqlite`),
|
|
42106
41230
|
channelId,
|
|
42107
41231
|
defaultWorkspace: loadDefaultWorkspace(environment),
|
|
42108
41232
|
relayUrl: requiredEnvironmentValue(environment, "MOBIUS_RELAY_URL"),
|
|
@@ -42112,9 +41236,9 @@ function loadMobiusRuntimeConnection(environment = process.env) {
|
|
|
42112
41236
|
async function resolveWorkspace(path2) {
|
|
42113
41237
|
const requested = resolve5(path2);
|
|
42114
41238
|
try {
|
|
42115
|
-
await
|
|
42116
|
-
const resolved = await
|
|
42117
|
-
const metadata = await
|
|
41239
|
+
await mkdir4(requested, { recursive: true, mode: 448 });
|
|
41240
|
+
const resolved = await realpath10(requested);
|
|
41241
|
+
const metadata = await stat9(resolved);
|
|
42118
41242
|
if (!metadata.isDirectory()) {
|
|
42119
41243
|
throw new MobiusRuntimeConfigurationError("The Runtime workspace is not a directory");
|
|
42120
41244
|
}
|
|
@@ -42131,7 +41255,7 @@ async function createMobiusRuntimeEngine(connection, signal, environment = proce
|
|
|
42131
41255
|
const relayUrl = relayUrlFromConnection(connection);
|
|
42132
41256
|
const defaultWorkspace = await resolveWorkspace(connection.defaultWorkspace);
|
|
42133
41257
|
const auditDatabasePath = resolve5(connection.auditDatabasePath);
|
|
42134
|
-
await
|
|
41258
|
+
await mkdir4(dirname7(auditDatabasePath), { recursive: true, mode: 448 });
|
|
42135
41259
|
const inventory = await discoverLocalAgentInventory({
|
|
42136
41260
|
defaultWorkspace,
|
|
42137
41261
|
environment,
|