@moxt-ai/mobius 0.0.48 → 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 +34 -11
- package/dist/acp/session-manager.js.map +1 -1
- package/dist/agent-catalog/publish-agent-catalog.d.ts.map +1 -1
- package/dist/agent-catalog/publish-agent-catalog.js +0 -1
- package/dist/agent-catalog/publish-agent-catalog.js.map +1 -1
- package/dist/artifacts/local-file-streamer.d.ts +3 -0
- package/dist/artifacts/local-file-streamer.d.ts.map +1 -0
- package/dist/artifacts/local-file-streamer.js +82 -0
- package/dist/artifacts/local-file-streamer.js.map +1 -0
- package/dist/authorization/local-raster.d.ts +4 -3
- package/dist/authorization/local-raster.d.ts.map +1 -1
- package/dist/authorization/local-raster.js +22 -12
- package/dist/authorization/local-raster.js.map +1 -1
- package/dist/cli.js +529 -1659
- 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 +569 -1690
- 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 +26 -270
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.js +396 -1353
- 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 -19
- package/dist/bots/bot-execution-context.d.ts.map +0 -1
- package/dist/bots/bot-execution-context.js +0 -75
- package/dist/bots/bot-execution-context.js.map +0 -1
- package/dist/bots/bot-message-command.d.ts +0 -6
- package/dist/bots/bot-message-command.d.ts.map +0 -1
- package/dist/bots/bot-message-command.js +0 -140
- package/dist/bots/bot-message-command.js.map +0 -1
- package/dist/bots/bot-outbound-ipc.d.ts +0 -12
- package/dist/bots/bot-outbound-ipc.d.ts.map +0 -1
- package/dist/bots/bot-outbound-ipc.js +0 -245
- package/dist/bots/bot-outbound-ipc.js.map +0 -1
- package/dist/bots/local-bot-execution-authorizer.d.ts +0 -23
- package/dist/bots/local-bot-execution-authorizer.d.ts.map +0 -1
- package/dist/bots/local-bot-execution-authorizer.js +0 -62
- package/dist/bots/local-bot-execution-authorizer.js.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -6,12 +6,12 @@ var __export = (target, all2) => {
|
|
|
6
6
|
};
|
|
7
7
|
|
|
8
8
|
// src/cli.ts
|
|
9
|
-
import { mkdir as
|
|
9
|
+
import { mkdir as mkdir4 } from "node:fs/promises";
|
|
10
10
|
|
|
11
11
|
// package.json
|
|
12
12
|
var package_default = {
|
|
13
13
|
name: "@moxt-ai/mobius",
|
|
14
|
-
version: "0.0.
|
|
14
|
+
version: "0.0.49",
|
|
15
15
|
description: "Mobius CLI for pairing and running local AI agent services.",
|
|
16
16
|
type: "module",
|
|
17
17
|
bin: {
|
|
@@ -145,12 +145,12 @@ var ExecutableIdentity = class {
|
|
|
145
145
|
realPath;
|
|
146
146
|
requestedPath;
|
|
147
147
|
size;
|
|
148
|
-
constructor(
|
|
148
|
+
constructor(requestedPath2, realPath_, device, inode, size, changedAtMilliseconds) {
|
|
149
149
|
this.changedAtMilliseconds = changedAtMilliseconds;
|
|
150
150
|
this.device = device;
|
|
151
151
|
this.inode = inode;
|
|
152
152
|
this.realPath = realPath_;
|
|
153
|
-
this.requestedPath =
|
|
153
|
+
this.requestedPath = requestedPath2;
|
|
154
154
|
this.size = size;
|
|
155
155
|
}
|
|
156
156
|
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;
|
|
@@ -190,8 +190,8 @@ function executableExtensions(executableName, environment, platform) {
|
|
|
190
190
|
const extensions = configured.split(";").map((extension2) => extension2.trim()).filter((extension2) => extension2.length > 0).map((extension2) => extension2.startsWith(".") ? extension2 : `.${extension2}`);
|
|
191
191
|
return extensions.length > 0 ? extensions : [".EXE"];
|
|
192
192
|
}
|
|
193
|
-
async function resolveExecutablePath(
|
|
194
|
-
const absoluteRequestedPath = resolve(
|
|
193
|
+
async function resolveExecutablePath(requestedPath2, platform = process.platform) {
|
|
194
|
+
const absoluteRequestedPath = resolve(requestedPath2);
|
|
195
195
|
try {
|
|
196
196
|
const resolvedPath = await realpath(absoluteRequestedPath);
|
|
197
197
|
const metadata = await stat(resolvedPath);
|
|
@@ -224,8 +224,8 @@ async function findExecutableOnPath(executableName, environment, platform = proc
|
|
|
224
224
|
continue;
|
|
225
225
|
}
|
|
226
226
|
for (const extension2 of extensions) {
|
|
227
|
-
const
|
|
228
|
-
const executable = await resolveExecutablePath(
|
|
227
|
+
const requestedPath2 = resolve(join(entry, `${executableName}${extension2}`));
|
|
228
|
+
const executable = await resolveExecutablePath(requestedPath2, platform);
|
|
229
229
|
if (executable !== null) {
|
|
230
230
|
return executable;
|
|
231
231
|
}
|
|
@@ -4334,7 +4334,7 @@ var $ZodUnion = /* @__PURE__ */ $constructor("$ZodUnion", (inst, def) => {
|
|
|
4334
4334
|
defineLazyInternal(inst, "optout", (zod) => zod.def.options.some((o) => o._zod.optout === "optional") ? "optional" : void 0);
|
|
4335
4335
|
defineLazyInternal(inst, "values", (zod) => {
|
|
4336
4336
|
if (zod.def.options.every((o) => o._zod.values)) {
|
|
4337
|
-
return new Set(zod.def.options.flatMap((
|
|
4337
|
+
return new Set(zod.def.options.flatMap((option) => Array.from(option._zod.values)));
|
|
4338
4338
|
}
|
|
4339
4339
|
return void 0;
|
|
4340
4340
|
});
|
|
@@ -4352,8 +4352,8 @@ var $ZodUnion = /* @__PURE__ */ $constructor("$ZodUnion", (inst, def) => {
|
|
|
4352
4352
|
}
|
|
4353
4353
|
let async = false;
|
|
4354
4354
|
const results = [];
|
|
4355
|
-
for (const
|
|
4356
|
-
const result =
|
|
4355
|
+
for (const option of def.options) {
|
|
4356
|
+
const result = option._zod.run({
|
|
4357
4357
|
value: payload.value,
|
|
4358
4358
|
issues: []
|
|
4359
4359
|
}, ctx);
|
|
@@ -4412,8 +4412,8 @@ var $ZodXor = /* @__PURE__ */ $constructor("$ZodXor", (inst, def) => {
|
|
|
4412
4412
|
}
|
|
4413
4413
|
let async = false;
|
|
4414
4414
|
const results = [];
|
|
4415
|
-
for (const
|
|
4416
|
-
const result =
|
|
4415
|
+
for (const option of def.options) {
|
|
4416
|
+
const result = option._zod.run({
|
|
4417
4417
|
value: payload.value,
|
|
4418
4418
|
issues: []
|
|
4419
4419
|
}, ctx);
|
|
@@ -4438,24 +4438,24 @@ function getDiscriminatedOption(union2, value) {
|
|
|
4438
4438
|
map2 = discriminatorMap(internals.def);
|
|
4439
4439
|
internals.bag.optionsMap = map2;
|
|
4440
4440
|
}
|
|
4441
|
-
const
|
|
4442
|
-
if (
|
|
4441
|
+
const option = map2.get(value);
|
|
4442
|
+
if (option === null)
|
|
4443
4443
|
throw new Error(`Ambiguous discriminator value "${String(value)}"`);
|
|
4444
|
-
return
|
|
4444
|
+
return option;
|
|
4445
4445
|
}
|
|
4446
4446
|
function discriminatorMap(def) {
|
|
4447
4447
|
const map2 = /* @__PURE__ */ new Map();
|
|
4448
|
-
for (const
|
|
4449
|
-
const values =
|
|
4448
|
+
for (const option of def.options) {
|
|
4449
|
+
const values = option._zod.propValues?.[def.discriminator];
|
|
4450
4450
|
if (!values || values.size === 0)
|
|
4451
|
-
throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(
|
|
4451
|
+
throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
|
|
4452
4452
|
for (const value of values) {
|
|
4453
4453
|
if (map2.has(value)) {
|
|
4454
4454
|
if (value !== void 0)
|
|
4455
4455
|
throw new Error(`Duplicate discriminator value "${String(value)}"`);
|
|
4456
4456
|
map2.set(value, null);
|
|
4457
4457
|
} else {
|
|
4458
|
-
map2.set(value,
|
|
4458
|
+
map2.set(value, option);
|
|
4459
4459
|
}
|
|
4460
4460
|
}
|
|
4461
4461
|
}
|
|
@@ -4468,10 +4468,10 @@ var $ZodDiscriminatedUnion = /* @__PURE__ */ $constructor("$ZodDiscriminatedUnio
|
|
|
4468
4468
|
defineLazyInternal(inst, "propValues", (zod) => {
|
|
4469
4469
|
const propValues = {};
|
|
4470
4470
|
let undefinedCount = 0;
|
|
4471
|
-
for (const
|
|
4472
|
-
const pv =
|
|
4471
|
+
for (const option of zod.def.options) {
|
|
4472
|
+
const pv = option._zod.propValues;
|
|
4473
4473
|
if (!pv || Object.keys(pv).length === 0)
|
|
4474
|
-
throw new Error(`Invalid discriminated union option at index "${zod.def.options.indexOf(
|
|
4474
|
+
throw new Error(`Invalid discriminated union option at index "${zod.def.options.indexOf(option)}"`);
|
|
4475
4475
|
if (pv[zod.def.discriminator]?.has(void 0))
|
|
4476
4476
|
undefinedCount++;
|
|
4477
4477
|
for (const [k, v] of Object.entries(pv)) {
|
|
@@ -4487,8 +4487,8 @@ var $ZodDiscriminatedUnion = /* @__PURE__ */ $constructor("$ZodDiscriminatedUnio
|
|
|
4487
4487
|
propValues[zod.def.discriminator]?.delete(void 0);
|
|
4488
4488
|
return propValues;
|
|
4489
4489
|
});
|
|
4490
|
-
def.options.forEach((
|
|
4491
|
-
const propShape = rawShape(
|
|
4490
|
+
def.options.forEach((option, i) => {
|
|
4491
|
+
const propShape = rawShape(option._zod.def);
|
|
4492
4492
|
if (propShape && !Object.prototype.hasOwnProperty.call(propShape, def.discriminator)) {
|
|
4493
4493
|
throw new Error(`Invalid discriminated union option at index "${i}"`);
|
|
4494
4494
|
}
|
|
@@ -14788,8 +14788,8 @@ function generateDiscriminatedUnionCheck(doc, ctx, def, accessor) {
|
|
|
14788
14788
|
doc.write(`let ${outputVar};`);
|
|
14789
14789
|
let firstBranch = true;
|
|
14790
14790
|
const claimed = /* @__PURE__ */ new Set();
|
|
14791
|
-
for (const
|
|
14792
|
-
const values =
|
|
14791
|
+
for (const option of def.options) {
|
|
14792
|
+
const values = option._zod.propValues?.[def.discriminator];
|
|
14793
14793
|
if (!values || values.size === 0) {
|
|
14794
14794
|
throw new ZodCompileUnsupportedError("discriminated union option without static discriminator values");
|
|
14795
14795
|
}
|
|
@@ -14803,7 +14803,7 @@ function generateDiscriminatedUnionCheck(doc, ctx, def, accessor) {
|
|
|
14803
14803
|
const prefix = firstBranch ? "if" : "else if";
|
|
14804
14804
|
doc.write(`${prefix} (${conditions.join(" || ")}) {`);
|
|
14805
14805
|
doc.indented((d) => {
|
|
14806
|
-
const branchOutput = generateCheck(d, ctx,
|
|
14806
|
+
const branchOutput = generateCheck(d, ctx, option, accessor);
|
|
14807
14807
|
d.write(`${outputVar} = ${branchOutput};`);
|
|
14808
14808
|
});
|
|
14809
14809
|
doc.write(`}`);
|
|
@@ -16385,14 +16385,14 @@ function compactTypeUnion(schema) {
|
|
|
16385
16385
|
if (!Array.isArray(options) || options.length === 0 || schema.type !== void 0)
|
|
16386
16386
|
return;
|
|
16387
16387
|
const types = [];
|
|
16388
|
-
for (const
|
|
16389
|
-
if (!
|
|
16388
|
+
for (const option of options) {
|
|
16389
|
+
if (!option || typeof option !== "object")
|
|
16390
16390
|
return;
|
|
16391
|
-
compactTypeUnion(
|
|
16392
|
-
const keys = Object.keys(
|
|
16391
|
+
compactTypeUnion(option);
|
|
16392
|
+
const keys = Object.keys(option);
|
|
16393
16393
|
if (keys.length !== 1 || keys[0] !== "type")
|
|
16394
16394
|
return;
|
|
16395
|
-
const type =
|
|
16395
|
+
const type = option.type;
|
|
16396
16396
|
for (const member of Array.isArray(type) ? type : [type]) {
|
|
16397
16397
|
if (typeof member !== "string")
|
|
16398
16398
|
return;
|
|
@@ -16682,8 +16682,8 @@ function isTransforming(_schema, _ctx) {
|
|
|
16682
16682
|
return false;
|
|
16683
16683
|
}
|
|
16684
16684
|
if (def.type === "union") {
|
|
16685
|
-
for (const
|
|
16686
|
-
if (isTransforming(
|
|
16685
|
+
for (const option of def.options) {
|
|
16686
|
+
if (isTransforming(option, ctx))
|
|
16687
16687
|
return true;
|
|
16688
16688
|
}
|
|
16689
16689
|
return false;
|
|
@@ -20431,6 +20431,11 @@ var AGENT_INSTALL_CANCELLED_KIND = "agent.integration.install.cancelled";
|
|
|
20431
20431
|
var AGENT_SETTINGS_DISCOVER_KIND = "agent.settings.discover";
|
|
20432
20432
|
var AGENT_SETTINGS_DISCOVERED_KIND = "agent.settings.discovered";
|
|
20433
20433
|
var AGENT_SETTINGS_DISCOVERY_FAILED_KIND = "agent.settings.discovery.failed";
|
|
20434
|
+
var FILE_READ_KIND = "file.read";
|
|
20435
|
+
var FILE_BEGIN_KIND = "file.begin";
|
|
20436
|
+
var FILE_CHUNK_KIND = "file.chunk";
|
|
20437
|
+
var FILE_END_KIND = "file.end";
|
|
20438
|
+
var FILE_FAILED_KIND = "file.failed";
|
|
20434
20439
|
var IDENTIFIER_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
20435
20440
|
var DIRECTORY_IDENTIFIER_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/;
|
|
20436
20441
|
var IDENTIFIER = external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN);
|
|
@@ -20441,6 +20446,41 @@ var workspaceEntrySchema = external_exports.strictObject({
|
|
|
20441
20446
|
directoryId: DIRECTORY_IDENTIFIER,
|
|
20442
20447
|
name: external_exports.string().min(1).max(255)
|
|
20443
20448
|
}).readonly();
|
|
20449
|
+
var fileReadCommandSchema = external_exports.strictObject({
|
|
20450
|
+
kind: external_exports.literal(FILE_READ_KIND),
|
|
20451
|
+
maxBytes: external_exports.number().int().positive().max(128 * 1024 * 1024),
|
|
20452
|
+
requestId: IDENTIFIER,
|
|
20453
|
+
sessionId: IDENTIFIER,
|
|
20454
|
+
path: external_exports.string().min(1).max(4096)
|
|
20455
|
+
}).readonly();
|
|
20456
|
+
var fileBeginEventSchema = external_exports.strictObject({
|
|
20457
|
+
byteLength: external_exports.number().int().positive().max(128 * 1024 * 1024),
|
|
20458
|
+
kind: external_exports.literal(FILE_BEGIN_KIND),
|
|
20459
|
+
mediaType: external_exports.string().min(1).max(255),
|
|
20460
|
+
modifiedAt: external_exports.iso.datetime({ offset: true }),
|
|
20461
|
+
name: external_exports.string().min(1).max(500),
|
|
20462
|
+
requestId: IDENTIFIER,
|
|
20463
|
+
sessionId: IDENTIFIER
|
|
20464
|
+
}).readonly();
|
|
20465
|
+
var fileChunkEventSchema = external_exports.strictObject({
|
|
20466
|
+
data: external_exports.string().min(1).max(4e5),
|
|
20467
|
+
kind: external_exports.literal(FILE_CHUNK_KIND),
|
|
20468
|
+
requestId: IDENTIFIER,
|
|
20469
|
+
sequence: external_exports.number().int().nonnegative().max(1024),
|
|
20470
|
+
sessionId: IDENTIFIER
|
|
20471
|
+
}).readonly();
|
|
20472
|
+
var fileEndEventSchema = external_exports.strictObject({
|
|
20473
|
+
kind: external_exports.literal(FILE_END_KIND),
|
|
20474
|
+
requestId: IDENTIFIER,
|
|
20475
|
+
sessionId: IDENTIFIER
|
|
20476
|
+
}).readonly();
|
|
20477
|
+
var fileFailedEventSchema = external_exports.strictObject({
|
|
20478
|
+
code: IDENTIFIER,
|
|
20479
|
+
kind: external_exports.literal(FILE_FAILED_KIND),
|
|
20480
|
+
message: external_exports.string().min(1).max(500),
|
|
20481
|
+
requestId: IDENTIFIER,
|
|
20482
|
+
sessionId: IDENTIFIER
|
|
20483
|
+
}).readonly();
|
|
20444
20484
|
var configValueSchema = external_exports.strictObject({
|
|
20445
20485
|
description: SHORT_TEXT,
|
|
20446
20486
|
groupId: external_exports.string().max(128),
|
|
@@ -20657,7 +20697,7 @@ var sessionPrepareCommandSchema = external_exports.strictObject({
|
|
|
20657
20697
|
kind: external_exports.literal(SESSION_PREPARE_KIND),
|
|
20658
20698
|
requestId: IDENTIFIER,
|
|
20659
20699
|
sessionState: external_exports.literal("provisioned").optional(),
|
|
20660
|
-
/**
|
|
20700
|
+
/** Marks an inspection-only Session preparation. */
|
|
20661
20701
|
transient: external_exports.boolean().optional()
|
|
20662
20702
|
}).superRefine((command, context) => {
|
|
20663
20703
|
if (command.transient === true && command.sessionState === "provisioned") {
|
|
@@ -20878,11 +20918,15 @@ var decodeRecordedAgentContentValue = (value) => decodeValue(value, recordedDisp
|
|
|
20878
20918
|
var decodePromptImagesValue = (value) => decodeValue(value, external_exports.array(promptImageSchema).max(8).readonly());
|
|
20879
20919
|
var decodePromptResourcesValue = (value) => decodeValue(value, external_exports.array(promptResourceSchema).max(16).readonly());
|
|
20880
20920
|
var decodeSessionConfigurationSelections = (value) => decodeValue(value, sessionConfigurationSelectionsSchema);
|
|
20881
|
-
var decodeAgentExecutionConfiguration = (value) => decodeValue(value, agentExecutionConfigurationSchema);
|
|
20882
20921
|
var encode3 = (message, schema) => JSON.stringify(decodeValue(message, schema));
|
|
20883
20922
|
var decodeAgentSettingsDiscoverCommand = (encoded) => decode3(encoded, agentSettingsDiscoverCommandSchema);
|
|
20884
20923
|
var encodeAgentSettingsDiscoveredEvent = (message) => encode3(message, agentSettingsDiscoveredEventSchema);
|
|
20885
20924
|
var encodeAgentSettingsDiscoveryFailedEvent = (message) => encode3(message, agentSettingsDiscoveryFailedEventSchema);
|
|
20925
|
+
var decodeFileReadCommand = (encoded) => decode3(encoded, fileReadCommandSchema);
|
|
20926
|
+
var encodeFileBeginEvent = (message) => encode3(message, fileBeginEventSchema);
|
|
20927
|
+
var encodeFileChunkEvent = (message) => encode3(message, fileChunkEventSchema);
|
|
20928
|
+
var encodeFileEndEvent = (message) => encode3(message, fileEndEventSchema);
|
|
20929
|
+
var encodeFileFailedEvent = (message) => encode3(message, fileFailedEventSchema);
|
|
20886
20930
|
var decodeWorkspaceListCommand = (encoded) => decode3(encoded, workspaceListCommandSchema);
|
|
20887
20931
|
var encodeWorkspaceEntriesEvent = (message) => encode3(message, workspaceEntriesEventSchema);
|
|
20888
20932
|
var decodeSessionPrepareCommand = (encoded) => decode3(encoded, sessionPrepareCommandSchema);
|
|
@@ -21362,325 +21406,6 @@ function encodeSessionFailedEvent(message) {
|
|
|
21362
21406
|
return JSON.stringify(decodeSessionFailedEvent(JSON.stringify(message)));
|
|
21363
21407
|
}
|
|
21364
21408
|
|
|
21365
|
-
// ../protocol/src/bot.ts
|
|
21366
|
-
var BOT_SESSION_PROMPT_KIND = "bot.session.prompt";
|
|
21367
|
-
var IDENTIFIER_PATTERN3 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
21368
|
-
var DIRECTORY_IDENTIFIER_PATTERN3 = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/;
|
|
21369
|
-
var TOKEN_PATTERN = /^[a-zA-Z0-9_-]{32,256}$/;
|
|
21370
|
-
var SHA256_PATTERN = /^[a-f0-9]{64}$/;
|
|
21371
|
-
var MAX_INSTRUCTIONS_LENGTH = 1e5;
|
|
21372
|
-
var BotDeliveryTargetReference = class {
|
|
21373
|
-
alias;
|
|
21374
|
-
deliveryTargetId;
|
|
21375
|
-
constructor(alias, deliveryTargetId) {
|
|
21376
|
-
this.alias = alias;
|
|
21377
|
-
this.deliveryTargetId = deliveryTargetId;
|
|
21378
|
-
}
|
|
21379
|
-
};
|
|
21380
|
-
var BotReplyRoute = class {
|
|
21381
|
-
};
|
|
21382
|
-
var OwnerBotReplyRoute = class extends BotReplyRoute {
|
|
21383
|
-
kind = "owner";
|
|
21384
|
-
};
|
|
21385
|
-
var BotConnectionReplyRoute = class extends BotReplyRoute {
|
|
21386
|
-
connectionId;
|
|
21387
|
-
deliveryTargetId;
|
|
21388
|
-
kind = "connection";
|
|
21389
|
-
constructor(connectionId, deliveryTargetId) {
|
|
21390
|
-
super();
|
|
21391
|
-
this.connectionId = connectionId;
|
|
21392
|
-
this.deliveryTargetId = deliveryTargetId;
|
|
21393
|
-
}
|
|
21394
|
-
};
|
|
21395
|
-
var BotSessionPromptCommand = class {
|
|
21396
|
-
additionalDirectoryIds;
|
|
21397
|
-
agentId;
|
|
21398
|
-
allowedDeliveryTargets;
|
|
21399
|
-
behaviorDigest;
|
|
21400
|
-
behaviorInstructions;
|
|
21401
|
-
behaviorRevisionId;
|
|
21402
|
-
bindingId;
|
|
21403
|
-
bindingRevision;
|
|
21404
|
-
botId;
|
|
21405
|
-
commandId;
|
|
21406
|
-
conversationId;
|
|
21407
|
-
directoryId;
|
|
21408
|
-
disposition;
|
|
21409
|
-
executionCapabilityId;
|
|
21410
|
-
executionCapabilitySecret;
|
|
21411
|
-
executionDeadlineAt;
|
|
21412
|
-
executionId;
|
|
21413
|
-
executionConfiguration;
|
|
21414
|
-
images;
|
|
21415
|
-
kind = BOT_SESSION_PROMPT_KIND;
|
|
21416
|
-
prompt;
|
|
21417
|
-
replyRoute;
|
|
21418
|
-
resources;
|
|
21419
|
-
sessionConfigurations;
|
|
21420
|
-
sessionId;
|
|
21421
|
-
targetCommandId;
|
|
21422
|
-
turnId;
|
|
21423
|
-
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 = "") {
|
|
21424
|
-
this.sessionId = sessionId;
|
|
21425
|
-
this.commandId = commandId;
|
|
21426
|
-
this.agentId = agentId;
|
|
21427
|
-
this.bindingId = bindingId;
|
|
21428
|
-
this.directoryId = directoryId2;
|
|
21429
|
-
this.disposition = disposition;
|
|
21430
|
-
this.additionalDirectoryIds = Object.freeze([...additionalDirectoryIds]);
|
|
21431
|
-
this.images = Object.freeze([...images]);
|
|
21432
|
-
this.resources = Object.freeze([...resources]);
|
|
21433
|
-
this.prompt = prompt;
|
|
21434
|
-
this.executionId = executionId;
|
|
21435
|
-
this.executionCapabilityId = executionCapabilityId;
|
|
21436
|
-
this.executionCapabilitySecret = executionCapabilitySecret;
|
|
21437
|
-
this.executionDeadlineAt = executionDeadlineAt;
|
|
21438
|
-
this.botId = botId;
|
|
21439
|
-
this.conversationId = conversationId;
|
|
21440
|
-
this.turnId = turnId;
|
|
21441
|
-
this.behaviorRevisionId = behaviorRevisionId;
|
|
21442
|
-
this.bindingRevision = bindingRevision;
|
|
21443
|
-
this.behaviorInstructions = behaviorInstructions;
|
|
21444
|
-
this.behaviorDigest = behaviorDigest;
|
|
21445
|
-
this.allowedDeliveryTargets = Object.freeze(
|
|
21446
|
-
allowedDeliveryTargets.map(
|
|
21447
|
-
(target) => new BotDeliveryTargetReference(target.alias, target.deliveryTargetId)
|
|
21448
|
-
)
|
|
21449
|
-
);
|
|
21450
|
-
this.replyRoute = replyRoute;
|
|
21451
|
-
this.executionConfiguration = decodeAgentExecutionConfiguration(executionConfiguration);
|
|
21452
|
-
this.sessionConfigurations = Object.freeze([...sessionConfigurations]);
|
|
21453
|
-
this.targetCommandId = targetCommandId;
|
|
21454
|
-
}
|
|
21455
|
-
toJSON() {
|
|
21456
|
-
const { disposition, sessionConfigurations, targetCommandId, ...command } = this;
|
|
21457
|
-
return {
|
|
21458
|
-
...command,
|
|
21459
|
-
...sessionConfigurations.length === 0 ? {} : { sessionConfigurations },
|
|
21460
|
-
...disposition === SessionPromptDisposition.Reject ? {} : { disposition, targetCommandId }
|
|
21461
|
-
};
|
|
21462
|
-
}
|
|
21463
|
-
};
|
|
21464
|
-
function isRecord3(value) {
|
|
21465
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21466
|
-
}
|
|
21467
|
-
function parseJson3(encoded) {
|
|
21468
|
-
let value;
|
|
21469
|
-
try {
|
|
21470
|
-
value = JSON.parse(encoded);
|
|
21471
|
-
} catch (cause) {
|
|
21472
|
-
throw new ProtocolMessageError("Message is not valid JSON", { cause });
|
|
21473
|
-
}
|
|
21474
|
-
if (!isRecord3(value)) {
|
|
21475
|
-
throw new ProtocolMessageError("Message must be a JSON object");
|
|
21476
|
-
}
|
|
21477
|
-
return value;
|
|
21478
|
-
}
|
|
21479
|
-
function assertExactKeys2(value, expected) {
|
|
21480
|
-
const keys = Object.keys(value);
|
|
21481
|
-
if (keys.length !== expected.length || keys.some((key) => !expected.includes(key))) {
|
|
21482
|
-
throw new ProtocolMessageError("Message fields do not match the Bot protocol");
|
|
21483
|
-
}
|
|
21484
|
-
}
|
|
21485
|
-
function assertKeysWithOptional(value, expected, optional2) {
|
|
21486
|
-
const keys = Object.keys(value);
|
|
21487
|
-
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))) {
|
|
21488
|
-
throw new ProtocolMessageError("Message fields do not match the Bot protocol");
|
|
21489
|
-
}
|
|
21490
|
-
}
|
|
21491
|
-
function readText2(value, key, maximumLength, allowEmpty) {
|
|
21492
|
-
const field = value[key];
|
|
21493
|
-
if (typeof field !== "string" || field.length > maximumLength || !allowEmpty && field.length === 0) {
|
|
21494
|
-
throw new ProtocolMessageError(`Invalid Bot protocol field: ${key}`);
|
|
21495
|
-
}
|
|
21496
|
-
return field;
|
|
21497
|
-
}
|
|
21498
|
-
function readIdentifier2(value, key) {
|
|
21499
|
-
const field = readText2(value, key, 128, false);
|
|
21500
|
-
if (!IDENTIFIER_PATTERN3.test(field)) {
|
|
21501
|
-
throw new ProtocolMessageError(`Invalid Bot identifier field: ${key}`);
|
|
21502
|
-
}
|
|
21503
|
-
return field;
|
|
21504
|
-
}
|
|
21505
|
-
function readDirectoryIdentifier2(value, key) {
|
|
21506
|
-
const field = readText2(value, key, 2048, false);
|
|
21507
|
-
if (!DIRECTORY_IDENTIFIER_PATTERN3.test(field)) {
|
|
21508
|
-
throw new ProtocolMessageError(`Invalid Bot directory field: ${key}`);
|
|
21509
|
-
}
|
|
21510
|
-
return field;
|
|
21511
|
-
}
|
|
21512
|
-
function readInteger(value, key) {
|
|
21513
|
-
const field = value[key];
|
|
21514
|
-
if (typeof field !== "number" || !Number.isSafeInteger(field) || field < 1) {
|
|
21515
|
-
throw new ProtocolMessageError(`Invalid Bot integer field: ${key}`);
|
|
21516
|
-
}
|
|
21517
|
-
return field;
|
|
21518
|
-
}
|
|
21519
|
-
function readTimestamp(value, key) {
|
|
21520
|
-
const field = readText2(value, key, 64, false);
|
|
21521
|
-
if (Number.isNaN(Date.parse(field))) {
|
|
21522
|
-
throw new ProtocolMessageError(`Invalid Bot timestamp field: ${key}`);
|
|
21523
|
-
}
|
|
21524
|
-
return field;
|
|
21525
|
-
}
|
|
21526
|
-
function readDigest(value, key) {
|
|
21527
|
-
const field = readText2(value, key, 64, false);
|
|
21528
|
-
if (!SHA256_PATTERN.test(field)) {
|
|
21529
|
-
throw new ProtocolMessageError(`Invalid Bot digest field: ${key}`);
|
|
21530
|
-
}
|
|
21531
|
-
return field;
|
|
21532
|
-
}
|
|
21533
|
-
function readToken(value, key) {
|
|
21534
|
-
const field = readText2(value, key, 256, false);
|
|
21535
|
-
if (!TOKEN_PATTERN.test(field)) {
|
|
21536
|
-
throw new ProtocolMessageError(`Invalid Bot token field: ${key}`);
|
|
21537
|
-
}
|
|
21538
|
-
return field;
|
|
21539
|
-
}
|
|
21540
|
-
function readIdentifiers(value, key, maximumCount) {
|
|
21541
|
-
const field = value[key];
|
|
21542
|
-
if (!Array.isArray(field) || field.length > maximumCount) {
|
|
21543
|
-
throw new ProtocolMessageError(`Invalid Bot identifier list: ${key}`);
|
|
21544
|
-
}
|
|
21545
|
-
const identifiers = [];
|
|
21546
|
-
const unique = /* @__PURE__ */ new Set();
|
|
21547
|
-
for (const candidate of field) {
|
|
21548
|
-
if (typeof candidate !== "string" || !IDENTIFIER_PATTERN3.test(candidate) || unique.has(candidate)) {
|
|
21549
|
-
throw new ProtocolMessageError(`Invalid Bot identifier list: ${key}`);
|
|
21550
|
-
}
|
|
21551
|
-
unique.add(candidate);
|
|
21552
|
-
identifiers.push(candidate);
|
|
21553
|
-
}
|
|
21554
|
-
return Object.freeze(identifiers);
|
|
21555
|
-
}
|
|
21556
|
-
function readTargets(value, key) {
|
|
21557
|
-
const field = value[key];
|
|
21558
|
-
if (!Array.isArray(field) || field.length > 64) {
|
|
21559
|
-
throw new ProtocolMessageError(`Invalid Bot delivery targets: ${key}`);
|
|
21560
|
-
}
|
|
21561
|
-
const targets = [];
|
|
21562
|
-
const identifiers = /* @__PURE__ */ new Set();
|
|
21563
|
-
const aliases = /* @__PURE__ */ new Set();
|
|
21564
|
-
for (const candidate of field) {
|
|
21565
|
-
if (!isRecord3(candidate)) {
|
|
21566
|
-
throw new ProtocolMessageError(`Invalid Bot delivery targets: ${key}`);
|
|
21567
|
-
}
|
|
21568
|
-
assertExactKeys2(candidate, ["alias", "deliveryTargetId"]);
|
|
21569
|
-
const alias = readIdentifier2(candidate, "alias");
|
|
21570
|
-
const deliveryTargetId = readIdentifier2(candidate, "deliveryTargetId");
|
|
21571
|
-
if (aliases.has(alias) || identifiers.has(deliveryTargetId)) {
|
|
21572
|
-
throw new ProtocolMessageError(`Duplicate Bot delivery target: ${key}`);
|
|
21573
|
-
}
|
|
21574
|
-
aliases.add(alias);
|
|
21575
|
-
identifiers.add(deliveryTargetId);
|
|
21576
|
-
targets.push(new BotDeliveryTargetReference(alias, deliveryTargetId));
|
|
21577
|
-
}
|
|
21578
|
-
return Object.freeze(targets);
|
|
21579
|
-
}
|
|
21580
|
-
function readSessionConfigurations(value) {
|
|
21581
|
-
if (!Object.hasOwn(value, "sessionConfigurations")) {
|
|
21582
|
-
return [];
|
|
21583
|
-
}
|
|
21584
|
-
return decodeSessionConfigurationSelections(value["sessionConfigurations"]);
|
|
21585
|
-
}
|
|
21586
|
-
function readReplyRoute(value) {
|
|
21587
|
-
if (!isRecord3(value)) {
|
|
21588
|
-
throw new ProtocolMessageError("Invalid Bot reply route");
|
|
21589
|
-
}
|
|
21590
|
-
const kind = readText2(value, "kind", 32, false);
|
|
21591
|
-
if (kind === "owner") {
|
|
21592
|
-
assertExactKeys2(value, ["kind"]);
|
|
21593
|
-
return new OwnerBotReplyRoute();
|
|
21594
|
-
}
|
|
21595
|
-
if (kind === "connection") {
|
|
21596
|
-
assertExactKeys2(value, ["connectionId", "deliveryTargetId", "kind"]);
|
|
21597
|
-
return new BotConnectionReplyRoute(
|
|
21598
|
-
readIdentifier2(value, "connectionId"),
|
|
21599
|
-
readIdentifier2(value, "deliveryTargetId")
|
|
21600
|
-
);
|
|
21601
|
-
}
|
|
21602
|
-
throw new ProtocolMessageError("Invalid Bot reply route");
|
|
21603
|
-
}
|
|
21604
|
-
function decodeBotSessionPromptCommand(encoded) {
|
|
21605
|
-
const value = parseJson3(encoded);
|
|
21606
|
-
assertKeysWithOptional(
|
|
21607
|
-
value,
|
|
21608
|
-
[
|
|
21609
|
-
"additionalDirectoryIds",
|
|
21610
|
-
"agentId",
|
|
21611
|
-
"allowedDeliveryTargets",
|
|
21612
|
-
"behaviorDigest",
|
|
21613
|
-
"behaviorInstructions",
|
|
21614
|
-
"behaviorRevisionId",
|
|
21615
|
-
"bindingId",
|
|
21616
|
-
"bindingRevision",
|
|
21617
|
-
"botId",
|
|
21618
|
-
"commandId",
|
|
21619
|
-
"conversationId",
|
|
21620
|
-
"directoryId",
|
|
21621
|
-
"executionCapabilityId",
|
|
21622
|
-
"executionCapabilitySecret",
|
|
21623
|
-
"executionDeadlineAt",
|
|
21624
|
-
"executionId",
|
|
21625
|
-
"executionConfiguration",
|
|
21626
|
-
"images",
|
|
21627
|
-
"kind",
|
|
21628
|
-
"prompt",
|
|
21629
|
-
"replyRoute",
|
|
21630
|
-
"resources",
|
|
21631
|
-
"sessionId",
|
|
21632
|
-
"turnId"
|
|
21633
|
-
],
|
|
21634
|
-
["disposition", "sessionConfigurations", "targetCommandId"]
|
|
21635
|
-
);
|
|
21636
|
-
if (value["kind"] !== BOT_SESSION_PROMPT_KIND) {
|
|
21637
|
-
throw new ProtocolMessageError("Invalid Bot Session prompt kind");
|
|
21638
|
-
}
|
|
21639
|
-
const rawDisposition = value["disposition"];
|
|
21640
|
-
let disposition;
|
|
21641
|
-
if (rawDisposition === void 0 || rawDisposition === SessionPromptDisposition.Reject) {
|
|
21642
|
-
disposition = SessionPromptDisposition.Reject;
|
|
21643
|
-
} else if (rawDisposition === SessionPromptDisposition.Queue) {
|
|
21644
|
-
disposition = SessionPromptDisposition.Queue;
|
|
21645
|
-
} else if (rawDisposition === SessionPromptDisposition.Steer) {
|
|
21646
|
-
disposition = SessionPromptDisposition.Steer;
|
|
21647
|
-
} else {
|
|
21648
|
-
throw new ProtocolMessageError("Invalid Bot Session prompt disposition");
|
|
21649
|
-
}
|
|
21650
|
-
const targetCommandId = value["targetCommandId"] === void 0 ? "" : readText2(value, "targetCommandId", 128, false);
|
|
21651
|
-
if (disposition === SessionPromptDisposition.Reject && targetCommandId.length > 0 || disposition !== SessionPromptDisposition.Reject && !IDENTIFIER_PATTERN3.test(targetCommandId)) {
|
|
21652
|
-
throw new ProtocolMessageError("Bot Session prompt disposition has an invalid target command");
|
|
21653
|
-
}
|
|
21654
|
-
return new BotSessionPromptCommand(
|
|
21655
|
-
readIdentifier2(value, "sessionId"),
|
|
21656
|
-
readIdentifier2(value, "commandId"),
|
|
21657
|
-
readIdentifier2(value, "agentId"),
|
|
21658
|
-
readIdentifier2(value, "bindingId"),
|
|
21659
|
-
readDirectoryIdentifier2(value, "directoryId"),
|
|
21660
|
-
readIdentifiers(value, "additionalDirectoryIds", 16),
|
|
21661
|
-
decodePromptImagesValue(value["images"]),
|
|
21662
|
-
decodePromptResourcesValue(value["resources"]),
|
|
21663
|
-
readText2(value, "prompt", 1e4, false),
|
|
21664
|
-
readIdentifier2(value, "executionId"),
|
|
21665
|
-
readIdentifier2(value, "executionCapabilityId"),
|
|
21666
|
-
readToken(value, "executionCapabilitySecret"),
|
|
21667
|
-
readTimestamp(value, "executionDeadlineAt"),
|
|
21668
|
-
readIdentifier2(value, "botId"),
|
|
21669
|
-
readIdentifier2(value, "conversationId"),
|
|
21670
|
-
readIdentifier2(value, "turnId"),
|
|
21671
|
-
readIdentifier2(value, "behaviorRevisionId"),
|
|
21672
|
-
readInteger(value, "bindingRevision"),
|
|
21673
|
-
readText2(value, "behaviorInstructions", MAX_INSTRUCTIONS_LENGTH, true),
|
|
21674
|
-
readDigest(value, "behaviorDigest"),
|
|
21675
|
-
readTargets(value, "allowedDeliveryTargets"),
|
|
21676
|
-
readReplyRoute(value["replyRoute"]),
|
|
21677
|
-
decodeAgentExecutionConfiguration(value["executionConfiguration"]),
|
|
21678
|
-
readSessionConfigurations(value),
|
|
21679
|
-
disposition,
|
|
21680
|
-
targetCommandId
|
|
21681
|
-
);
|
|
21682
|
-
}
|
|
21683
|
-
|
|
21684
21409
|
// ../protocol/src/mobius-api.ts
|
|
21685
21410
|
var MOBIUS_API_PREFIX = "/mobius/api";
|
|
21686
21411
|
var API_PREFIX_PATTERN = /^\/[a-zA-Z0-9._~-]+(?:\/[a-zA-Z0-9._~-]+)*$/;
|
|
@@ -21893,13 +21618,13 @@ var SessionEventRejectionCode = {
|
|
|
21893
21618
|
SessionNotFound: "session_not_found",
|
|
21894
21619
|
SessionRejected: "session_rejected"
|
|
21895
21620
|
};
|
|
21896
|
-
var
|
|
21621
|
+
var IDENTIFIER_PATTERN3 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
21897
21622
|
var CURSOR_PATTERN = /^[A-Za-z0-9_-]{1,512}$/;
|
|
21898
21623
|
var MAX_RECORDED_EVENT_LENGTH = 8 * 1024 * 1024;
|
|
21899
21624
|
var DECIMAL_SEQUENCE_PATTERN = /^(?:0|[1-9][0-9]*)$/;
|
|
21900
21625
|
var eventSourceSchema = external_exports.discriminatedUnion("kind", [
|
|
21901
21626
|
external_exports.strictObject({
|
|
21902
|
-
attemptId: external_exports.string().min(1).max(128).regex(
|
|
21627
|
+
attemptId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
|
|
21903
21628
|
kind: external_exports.literal("attempt"),
|
|
21904
21629
|
sourceSeq: external_exports.string().min(1).max(40).regex(DECIMAL_SEQUENCE_PATTERN)
|
|
21905
21630
|
}).readonly(),
|
|
@@ -21909,41 +21634,41 @@ var eventSourceSchema = external_exports.discriminatedUnion("kind", [
|
|
|
21909
21634
|
}).readonly()
|
|
21910
21635
|
]);
|
|
21911
21636
|
var eventEnvelopeSchema = external_exports.strictObject({
|
|
21912
|
-
eventId: external_exports.string().min(1).max(128).regex(
|
|
21637
|
+
eventId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
|
|
21913
21638
|
kind: external_exports.literal(SESSION_EVENT_KIND),
|
|
21914
21639
|
payload: external_exports.string().min(2).max(MAX_RECORDED_EVENT_LENGTH),
|
|
21915
|
-
sessionId: external_exports.string().min(1).max(128).regex(
|
|
21640
|
+
sessionId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
|
|
21916
21641
|
source: eventSourceSchema
|
|
21917
21642
|
}).readonly();
|
|
21918
21643
|
var committedEventSchema = external_exports.strictObject({
|
|
21919
21644
|
cursor: external_exports.string().min(1).max(512).regex(CURSOR_PATTERN),
|
|
21920
|
-
eventId: external_exports.string().min(1).max(128).regex(
|
|
21645
|
+
eventId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
|
|
21921
21646
|
kind: external_exports.literal(SESSION_EVENT_COMMITTED_KIND),
|
|
21922
21647
|
payload: external_exports.string().min(2).max(MAX_RECORDED_EVENT_LENGTH),
|
|
21923
21648
|
recordedAt: external_exports.string().datetime({ offset: true }),
|
|
21924
21649
|
sequence: external_exports.string().min(1).max(40).regex(DECIMAL_SEQUENCE_PATTERN),
|
|
21925
|
-
sessionId: external_exports.string().min(1).max(128).regex(
|
|
21650
|
+
sessionId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
|
|
21926
21651
|
source: eventSourceSchema
|
|
21927
21652
|
}).readonly();
|
|
21928
21653
|
var eventAcknowledgementSchema = external_exports.strictObject({
|
|
21929
21654
|
cursor: external_exports.string().min(1).max(512).regex(CURSOR_PATTERN),
|
|
21930
21655
|
duplicate: external_exports.boolean(),
|
|
21931
|
-
eventId: external_exports.string().min(1).max(128).regex(
|
|
21656
|
+
eventId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
|
|
21932
21657
|
kind: external_exports.literal(SESSION_EVENT_ACK_KIND),
|
|
21933
21658
|
sequence: external_exports.string().min(1).max(40).regex(DECIMAL_SEQUENCE_PATTERN),
|
|
21934
|
-
sessionId: external_exports.string().min(1).max(128).regex(
|
|
21659
|
+
sessionId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3)
|
|
21935
21660
|
}).readonly();
|
|
21936
21661
|
var eventDeferredSchema = external_exports.strictObject({
|
|
21937
|
-
eventId: external_exports.string().min(1).max(128).regex(
|
|
21662
|
+
eventId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
|
|
21938
21663
|
kind: external_exports.literal(SESSION_EVENT_DEFERRED_KIND),
|
|
21939
21664
|
retryAfterMilliseconds: external_exports.number().int().min(100).max(6e4),
|
|
21940
|
-
sessionId: external_exports.string().min(1).max(128).regex(
|
|
21665
|
+
sessionId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3)
|
|
21941
21666
|
}).readonly();
|
|
21942
21667
|
var eventRejectionSchema = external_exports.strictObject({
|
|
21943
21668
|
code: external_exports.enum(SessionEventRejectionCode),
|
|
21944
|
-
eventId: external_exports.string().min(1).max(128).regex(
|
|
21669
|
+
eventId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
|
|
21945
21670
|
kind: external_exports.literal(SESSION_EVENT_REJECTED_KIND),
|
|
21946
|
-
sessionId: external_exports.string().min(1).max(128).regex(
|
|
21671
|
+
sessionId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3)
|
|
21947
21672
|
}).readonly();
|
|
21948
21673
|
function decode5(encoded, schema) {
|
|
21949
21674
|
let value;
|
|
@@ -22523,7 +22248,7 @@ var ManagedNpmPackageError = class extends Error {
|
|
|
22523
22248
|
this.name = "ManagedNpmPackageError";
|
|
22524
22249
|
}
|
|
22525
22250
|
};
|
|
22526
|
-
function
|
|
22251
|
+
function isRecord3(value) {
|
|
22527
22252
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22528
22253
|
}
|
|
22529
22254
|
function packagePath(root, packageName) {
|
|
@@ -22545,7 +22270,7 @@ async function readJsonRecord(path2, maximumBytes) {
|
|
|
22545
22270
|
);
|
|
22546
22271
|
}
|
|
22547
22272
|
const value = JSON.parse(await handle.readFile({ encoding: "utf8" }));
|
|
22548
|
-
if (!
|
|
22273
|
+
if (!isRecord3(value)) {
|
|
22549
22274
|
throw new ManagedNpmPackageError(
|
|
22550
22275
|
"managed_package_verification_failed",
|
|
22551
22276
|
"The managed npm package metadata is invalid"
|
|
@@ -22571,7 +22296,7 @@ function readBinPath(packageMetadata, executableName) {
|
|
|
22571
22296
|
if (typeof bin === "string") {
|
|
22572
22297
|
return bin;
|
|
22573
22298
|
}
|
|
22574
|
-
if (
|
|
22299
|
+
if (isRecord3(bin) && typeof bin[executableName] === "string") {
|
|
22575
22300
|
return bin[executableName];
|
|
22576
22301
|
}
|
|
22577
22302
|
throw new ManagedNpmPackageError(
|
|
@@ -22587,7 +22312,7 @@ function verifyPackageLockEntry(lock, definition2, verifyDependencyClosure) {
|
|
|
22587
22312
|
);
|
|
22588
22313
|
}
|
|
22589
22314
|
const packages = lock["packages"];
|
|
22590
|
-
if (!
|
|
22315
|
+
if (!isRecord3(packages)) {
|
|
22591
22316
|
throw new ManagedNpmPackageError(
|
|
22592
22317
|
"managed_package_verification_failed",
|
|
22593
22318
|
"The managed npm package lockfile is invalid"
|
|
@@ -22601,7 +22326,7 @@ function verifyPackageLockEntry(lock, definition2, verifyDependencyClosure) {
|
|
|
22601
22326
|
if (verifyDependencyClosure && normalizedKey.length > 0) {
|
|
22602
22327
|
let resolved;
|
|
22603
22328
|
try {
|
|
22604
|
-
if (!normalizedKey.split("/").includes("node_modules") || !
|
|
22329
|
+
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") {
|
|
22605
22330
|
throw new Error("Invalid locked dependency");
|
|
22606
22331
|
}
|
|
22607
22332
|
resolved = new URL(candidate["resolved"]);
|
|
@@ -22624,7 +22349,7 @@ function verifyPackageLockEntry(lock, definition2, verifyDependencyClosure) {
|
|
|
22624
22349
|
matches += 1;
|
|
22625
22350
|
}
|
|
22626
22351
|
}
|
|
22627
|
-
if (matches !== 1 || !
|
|
22352
|
+
if (matches !== 1 || !isRecord3(entry) || entry["integrity"] !== definition2.integrity || entry["resolved"] !== definition2.tarballUrl || entry["version"] !== definition2.version) {
|
|
22628
22353
|
throw new ManagedNpmPackageError(
|
|
22629
22354
|
"managed_package_verification_failed",
|
|
22630
22355
|
"The managed npm package lockfile does not match the pinned artifact"
|
|
@@ -23435,7 +23160,7 @@ var ManagedAgentArchiveError = class extends Error {
|
|
|
23435
23160
|
this.name = "ManagedAgentArchiveError";
|
|
23436
23161
|
}
|
|
23437
23162
|
};
|
|
23438
|
-
function
|
|
23163
|
+
function isRecord4(value) {
|
|
23439
23164
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23440
23165
|
}
|
|
23441
23166
|
function isContainedPath3(root, candidate) {
|
|
@@ -23492,7 +23217,7 @@ async function readManifest(path2) {
|
|
|
23492
23217
|
);
|
|
23493
23218
|
}
|
|
23494
23219
|
const parsed = JSON.parse(await handle.readFile({ encoding: "utf8" }));
|
|
23495
|
-
if (!
|
|
23220
|
+
if (!isRecord4(parsed)) {
|
|
23496
23221
|
throw new ManagedAgentArchiveError(
|
|
23497
23222
|
"managed_archive_verification_failed",
|
|
23498
23223
|
"The managed Agent archive manifest is invalid"
|
|
@@ -23805,8 +23530,8 @@ var WorkBuddyAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
23805
23530
|
requestedPaths.unshift(join11(homeDirectory, "Applications", ...WORKBUDDY_MACOS_EXECUTABLE_PATH));
|
|
23806
23531
|
}
|
|
23807
23532
|
const executables = [];
|
|
23808
|
-
for (const
|
|
23809
|
-
const executable = await resolveExecutablePath(
|
|
23533
|
+
for (const requestedPath2 of requestedPaths) {
|
|
23534
|
+
const executable = await resolveExecutablePath(requestedPath2, "darwin");
|
|
23810
23535
|
context.signal.throwIfAborted();
|
|
23811
23536
|
if (executable !== null) {
|
|
23812
23537
|
executables.push(executable);
|
|
@@ -23894,41 +23619,41 @@ var DiscoveryAcpHandler = class {
|
|
|
23894
23619
|
};
|
|
23895
23620
|
function readableAcpStream(input2) {
|
|
23896
23621
|
let byteLength = 0;
|
|
23897
|
-
let
|
|
23622
|
+
let open6 = true;
|
|
23898
23623
|
return new ReadableStream({
|
|
23899
23624
|
start(controller) {
|
|
23900
23625
|
input2.on("data", (chunk) => {
|
|
23901
|
-
if (!
|
|
23626
|
+
if (!open6) {
|
|
23902
23627
|
return;
|
|
23903
23628
|
}
|
|
23904
23629
|
if (!(chunk instanceof Uint8Array)) {
|
|
23905
|
-
|
|
23630
|
+
open6 = false;
|
|
23906
23631
|
controller.error(new Error("ACP adapter produced invalid output"));
|
|
23907
23632
|
return;
|
|
23908
23633
|
}
|
|
23909
23634
|
byteLength += chunk.byteLength;
|
|
23910
23635
|
if (byteLength > ACP_OUTPUT_LIMIT_BYTES) {
|
|
23911
|
-
|
|
23636
|
+
open6 = false;
|
|
23912
23637
|
controller.error(new Error("ACP adapter output limit exceeded"));
|
|
23913
23638
|
return;
|
|
23914
23639
|
}
|
|
23915
23640
|
controller.enqueue(new Uint8Array(chunk));
|
|
23916
23641
|
});
|
|
23917
23642
|
input2.once("end", () => {
|
|
23918
|
-
if (
|
|
23919
|
-
|
|
23643
|
+
if (open6) {
|
|
23644
|
+
open6 = false;
|
|
23920
23645
|
controller.close();
|
|
23921
23646
|
}
|
|
23922
23647
|
});
|
|
23923
23648
|
input2.once("error", (error62) => {
|
|
23924
|
-
if (
|
|
23925
|
-
|
|
23649
|
+
if (open6) {
|
|
23650
|
+
open6 = false;
|
|
23926
23651
|
controller.error(error62);
|
|
23927
23652
|
}
|
|
23928
23653
|
});
|
|
23929
23654
|
},
|
|
23930
23655
|
cancel() {
|
|
23931
|
-
|
|
23656
|
+
open6 = false;
|
|
23932
23657
|
}
|
|
23933
23658
|
});
|
|
23934
23659
|
}
|
|
@@ -24199,7 +23924,7 @@ async function resolveAdapterExecutable(specification, context) {
|
|
|
24199
23924
|
const executables = await resolveAdapterExecutables(specification, context);
|
|
24200
23925
|
return executables[0] ?? null;
|
|
24201
23926
|
}
|
|
24202
|
-
async function probeVersion(executable, arguments_, environment, defaultWorkspace, signal, timeoutMilliseconds,
|
|
23927
|
+
async function probeVersion(executable, arguments_, environment, defaultWorkspace, signal, timeoutMilliseconds, normalize5 = normalizeVersionOutput) {
|
|
24203
23928
|
const result = await runBoundedProcess({
|
|
24204
23929
|
arguments: arguments_,
|
|
24205
23930
|
command: executable.path,
|
|
@@ -24208,7 +23933,7 @@ async function probeVersion(executable, arguments_, environment, defaultWorkspac
|
|
|
24208
23933
|
signal,
|
|
24209
23934
|
timeoutMilliseconds
|
|
24210
23935
|
});
|
|
24211
|
-
const version2 =
|
|
23936
|
+
const version2 = normalize5(result.stdout || result.stderr);
|
|
24212
23937
|
if (version2.length === 0) {
|
|
24213
23938
|
throw new ProcessExecutionError("process_exit_failed", "The executable did not report a version");
|
|
24214
23939
|
}
|
|
@@ -24398,164 +24123,6 @@ async function discoverLocalAgentInventory(options) {
|
|
|
24398
24123
|
return new LocalAgentInventory(discoveries);
|
|
24399
24124
|
}
|
|
24400
24125
|
|
|
24401
|
-
// src/bots/bot-message-command.ts
|
|
24402
|
-
import { randomUUID } from "node:crypto";
|
|
24403
|
-
import { createConnection } from "node:net";
|
|
24404
|
-
var BOT_IPC_RESPONSE_LIMIT = 64 * 1024;
|
|
24405
|
-
var BOT_IPC_TIMEOUT_MILLISECONDS = 2e4;
|
|
24406
|
-
var BotMessageCommandError = class extends Error {
|
|
24407
|
-
code;
|
|
24408
|
-
constructor(code, message, options = {}) {
|
|
24409
|
-
super(message, options);
|
|
24410
|
-
this.code = code;
|
|
24411
|
-
this.name = "BotMessageCommandError";
|
|
24412
|
-
}
|
|
24413
|
-
};
|
|
24414
|
-
function isRecord6(value) {
|
|
24415
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24416
|
-
}
|
|
24417
|
-
function requiredEnvironment(environment, name) {
|
|
24418
|
-
const value = environment[name]?.trim();
|
|
24419
|
-
if (value === void 0 || value.length === 0) {
|
|
24420
|
-
throw new BotMessageCommandError(
|
|
24421
|
-
"execution_context_required",
|
|
24422
|
-
"This command is available only inside an active Mobius Bot execution"
|
|
24423
|
-
);
|
|
24424
|
-
}
|
|
24425
|
-
return value;
|
|
24426
|
-
}
|
|
24427
|
-
function option(arguments_, name) {
|
|
24428
|
-
const index2 = arguments_.indexOf(name);
|
|
24429
|
-
if (index2 < 0 || index2 + 1 >= arguments_.length || arguments_[index2 + 1]?.startsWith("--") === true) {
|
|
24430
|
-
throw new BotMessageCommandError(
|
|
24431
|
-
"invalid_request",
|
|
24432
|
-
"Usage: mobius bot message send --target <current|alias> --text <message>"
|
|
24433
|
-
);
|
|
24434
|
-
}
|
|
24435
|
-
const value = arguments_[index2 + 1];
|
|
24436
|
-
if (value === void 0) {
|
|
24437
|
-
throw new BotMessageCommandError("invalid_request", "The Bot message option is missing");
|
|
24438
|
-
}
|
|
24439
|
-
return value;
|
|
24440
|
-
}
|
|
24441
|
-
function validateArguments(arguments_) {
|
|
24442
|
-
if (arguments_.length !== 4) {
|
|
24443
|
-
throw new BotMessageCommandError(
|
|
24444
|
-
"invalid_request",
|
|
24445
|
-
"Usage: mobius bot message send --target <current|alias> --text <message>"
|
|
24446
|
-
);
|
|
24447
|
-
}
|
|
24448
|
-
const names = [arguments_[0], arguments_[2]];
|
|
24449
|
-
if (!names.includes("--target") || !names.includes("--text") || names[0] === names[1]) {
|
|
24450
|
-
throw new BotMessageCommandError(
|
|
24451
|
-
"invalid_request",
|
|
24452
|
-
"Usage: mobius bot message send --target <current|alias> --text <message>"
|
|
24453
|
-
);
|
|
24454
|
-
}
|
|
24455
|
-
}
|
|
24456
|
-
function decodeResponse(encoded) {
|
|
24457
|
-
let value;
|
|
24458
|
-
try {
|
|
24459
|
-
value = JSON.parse(encoded);
|
|
24460
|
-
} catch (cause) {
|
|
24461
|
-
throw new BotMessageCommandError("bot_service_unavailable", "The local Bot service returned invalid data", {
|
|
24462
|
-
cause
|
|
24463
|
-
});
|
|
24464
|
-
}
|
|
24465
|
-
if (!isRecord6(value) || typeof value["ok"] !== "boolean") {
|
|
24466
|
-
throw new BotMessageCommandError("bot_service_unavailable", "The local Bot service returned invalid data");
|
|
24467
|
-
}
|
|
24468
|
-
if (value["ok"] === true && typeof value["outboundMessageId"] === "string") {
|
|
24469
|
-
return value["outboundMessageId"];
|
|
24470
|
-
}
|
|
24471
|
-
const error62 = value["error"];
|
|
24472
|
-
if (value["ok"] === false && isRecord6(error62) && typeof error62["code"] === "string" && typeof error62["message"] === "string") {
|
|
24473
|
-
throw new BotMessageCommandError(error62["code"], error62["message"]);
|
|
24474
|
-
}
|
|
24475
|
-
throw new BotMessageCommandError("bot_service_unavailable", "The local Bot service returned invalid data");
|
|
24476
|
-
}
|
|
24477
|
-
async function requestLocalBotService(socketPath, payload, signal) {
|
|
24478
|
-
signal.throwIfAborted();
|
|
24479
|
-
return await new Promise((resolve5, reject) => {
|
|
24480
|
-
const socket = createConnection(socketPath);
|
|
24481
|
-
const chunks = [];
|
|
24482
|
-
let length = 0;
|
|
24483
|
-
let finished = false;
|
|
24484
|
-
const finish = () => {
|
|
24485
|
-
socket.removeAllListeners();
|
|
24486
|
-
socket.destroy();
|
|
24487
|
-
};
|
|
24488
|
-
const fail = (error62) => {
|
|
24489
|
-
if (finished) {
|
|
24490
|
-
return;
|
|
24491
|
-
}
|
|
24492
|
-
finished = true;
|
|
24493
|
-
finish();
|
|
24494
|
-
if (error62 instanceof BotMessageCommandError) {
|
|
24495
|
-
reject(error62);
|
|
24496
|
-
return;
|
|
24497
|
-
}
|
|
24498
|
-
reject(
|
|
24499
|
-
new BotMessageCommandError(
|
|
24500
|
-
"execution_context_required",
|
|
24501
|
-
"The active Mobius Bot execution is unavailable",
|
|
24502
|
-
{ cause: error62 }
|
|
24503
|
-
)
|
|
24504
|
-
);
|
|
24505
|
-
};
|
|
24506
|
-
const abort = () => fail(signal.reason);
|
|
24507
|
-
socket.setTimeout(BOT_IPC_TIMEOUT_MILLISECONDS, () => {
|
|
24508
|
-
fail(new BotMessageCommandError("bot_service_unavailable", "The local Bot service timed out"));
|
|
24509
|
-
});
|
|
24510
|
-
socket.once("error", fail);
|
|
24511
|
-
socket.once("connect", () => socket.end(`${payload}
|
|
24512
|
-
`));
|
|
24513
|
-
socket.on("data", (chunk) => {
|
|
24514
|
-
length += chunk.byteLength;
|
|
24515
|
-
if (length > BOT_IPC_RESPONSE_LIMIT) {
|
|
24516
|
-
fail(new BotMessageCommandError("bot_service_unavailable", "The local Bot response is too large"));
|
|
24517
|
-
return;
|
|
24518
|
-
}
|
|
24519
|
-
chunks.push(chunk);
|
|
24520
|
-
});
|
|
24521
|
-
socket.once("end", () => {
|
|
24522
|
-
if (finished) {
|
|
24523
|
-
return;
|
|
24524
|
-
}
|
|
24525
|
-
finished = true;
|
|
24526
|
-
signal.removeEventListener("abort", abort);
|
|
24527
|
-
try {
|
|
24528
|
-
resolve5(decodeResponse(Buffer.concat(chunks).toString("utf8")));
|
|
24529
|
-
} catch (error62) {
|
|
24530
|
-
reject(error62);
|
|
24531
|
-
} finally {
|
|
24532
|
-
finish();
|
|
24533
|
-
}
|
|
24534
|
-
});
|
|
24535
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
24536
|
-
});
|
|
24537
|
-
}
|
|
24538
|
-
async function executeBotMessageCommand(arguments_, environment, signal) {
|
|
24539
|
-
validateArguments(arguments_);
|
|
24540
|
-
const contextHandle = requiredEnvironment(environment, "MOBIUS_BOT_CONTEXT");
|
|
24541
|
-
const socketPath = requiredEnvironment(environment, "MOBIUS_BOT_SOCKET");
|
|
24542
|
-
const target = option(arguments_, "--target");
|
|
24543
|
-
const text3 = option(arguments_, "--text");
|
|
24544
|
-
if (!/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/.test(target) || text3.trim().length === 0 || text3.length > 1e4) {
|
|
24545
|
-
throw new BotMessageCommandError("invalid_request", "The Bot outbound message is invalid");
|
|
24546
|
-
}
|
|
24547
|
-
return await requestLocalBotService(
|
|
24548
|
-
socketPath,
|
|
24549
|
-
JSON.stringify({
|
|
24550
|
-
contextHandle,
|
|
24551
|
-
idempotencyKey: `cli_${randomUUID()}`,
|
|
24552
|
-
target,
|
|
24553
|
-
text: text3
|
|
24554
|
-
}),
|
|
24555
|
-
signal
|
|
24556
|
-
);
|
|
24557
|
-
}
|
|
24558
|
-
|
|
24559
24126
|
// src/config.ts
|
|
24560
24127
|
import { join as join14 } from "node:path";
|
|
24561
24128
|
function loadDefaultWorkspace(environment = process.env) {
|
|
@@ -24576,15 +24143,15 @@ function createDaemonConfig(connection, agents = [], installableAgents = []) {
|
|
|
24576
24143
|
}
|
|
24577
24144
|
|
|
24578
24145
|
// src/pairing/pair-local-machine.ts
|
|
24579
|
-
import { randomUUID
|
|
24146
|
+
import { randomUUID } from "node:crypto";
|
|
24580
24147
|
import { mkdir as mkdir3, open as open4, realpath as realpath6, rename as rename3, stat as stat5, writeFile as writeFile2 } from "node:fs/promises";
|
|
24581
24148
|
import { hostname as hostname3 } from "node:os";
|
|
24582
24149
|
import { basename, join as join15, resolve as resolve3 } from "node:path";
|
|
24583
24150
|
import { fetch as fetch2 } from "undici";
|
|
24584
24151
|
var PAIRING_TIMEOUT_MILLISECONDS = 2e4;
|
|
24585
24152
|
var PAIRING_CODE_PATTERN = /^[A-HJ-NP-Z2-9]{4}(?:-[A-HJ-NP-Z2-9]{4}){4}$/;
|
|
24586
|
-
var
|
|
24587
|
-
var
|
|
24153
|
+
var IDENTIFIER_PATTERN4 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
24154
|
+
var TOKEN_PATTERN = /^[a-zA-Z0-9_-]{32,256}$/;
|
|
24588
24155
|
var MAX_CONNECTION_FILE_LENGTH = 16 * 1024;
|
|
24589
24156
|
var CLAIM_RESPONSE_KEYS = ["channelId", "daemonToken", "runtimeId"];
|
|
24590
24157
|
var REDEEM_RESPONSE_KEYS = ["channelId", "runtimeCredential", "runtimeId"];
|
|
@@ -24598,36 +24165,36 @@ var PairingClientError = class extends Error {
|
|
|
24598
24165
|
this.name = "PairingClientError";
|
|
24599
24166
|
}
|
|
24600
24167
|
};
|
|
24601
|
-
function
|
|
24168
|
+
function isRecord5(value) {
|
|
24602
24169
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24603
24170
|
}
|
|
24604
24171
|
function hasExactKeys(value, expectedKeys) {
|
|
24605
24172
|
const keys = Object.keys(value);
|
|
24606
24173
|
return keys.length === expectedKeys.length && expectedKeys.every((key) => Object.hasOwn(value, key));
|
|
24607
24174
|
}
|
|
24608
|
-
function readSingleOption(arguments_,
|
|
24175
|
+
function readSingleOption(arguments_, option) {
|
|
24609
24176
|
const values = [];
|
|
24610
24177
|
for (let index2 = 0; index2 < arguments_.length; index2 += 1) {
|
|
24611
|
-
if (arguments_[index2] !==
|
|
24178
|
+
if (arguments_[index2] !== option) {
|
|
24612
24179
|
continue;
|
|
24613
24180
|
}
|
|
24614
24181
|
const value = arguments_[index2 + 1];
|
|
24615
24182
|
if (value === void 0 || value.startsWith("--")) {
|
|
24616
|
-
throw new PairingClientError("invalid_arguments", `${
|
|
24183
|
+
throw new PairingClientError("invalid_arguments", `${option} requires a value`);
|
|
24617
24184
|
}
|
|
24618
24185
|
values.push(value);
|
|
24619
24186
|
index2 += 1;
|
|
24620
24187
|
}
|
|
24621
24188
|
if (values.length !== 1) {
|
|
24622
|
-
throw new PairingClientError("invalid_arguments", `${
|
|
24189
|
+
throw new PairingClientError("invalid_arguments", `${option} must be provided exactly once`);
|
|
24623
24190
|
}
|
|
24624
24191
|
return values[0] ?? "";
|
|
24625
24192
|
}
|
|
24626
24193
|
function assertKnownArguments(arguments_) {
|
|
24627
24194
|
for (let index2 = 0; index2 < arguments_.length; index2 += 2) {
|
|
24628
|
-
const
|
|
24629
|
-
if (
|
|
24630
|
-
throw new PairingClientError("invalid_arguments", `Unknown pairing option: ${
|
|
24195
|
+
const option = arguments_[index2];
|
|
24196
|
+
if (option !== "--url" && option !== "--code" && option !== "--pairing" && option !== "--workspace") {
|
|
24197
|
+
throw new PairingClientError("invalid_arguments", `Unknown pairing option: ${option ?? "missing option"}`);
|
|
24631
24198
|
}
|
|
24632
24199
|
}
|
|
24633
24200
|
}
|
|
@@ -24672,7 +24239,7 @@ function parsePairCommand(arguments_) {
|
|
|
24672
24239
|
};
|
|
24673
24240
|
}
|
|
24674
24241
|
function validatePairingId(value) {
|
|
24675
|
-
if (!
|
|
24242
|
+
if (!IDENTIFIER_PATTERN4.test(value)) {
|
|
24676
24243
|
throw new PairingClientError("invalid_pairing_id", "The Runtime pairing ID is invalid");
|
|
24677
24244
|
}
|
|
24678
24245
|
return value;
|
|
@@ -24682,7 +24249,7 @@ function parseChannelArgument(arguments_) {
|
|
|
24682
24249
|
throw new PairingClientError("invalid_arguments", "Usage: mobius start --channel <channel-id>");
|
|
24683
24250
|
}
|
|
24684
24251
|
const channelId = arguments_[1] ?? "";
|
|
24685
|
-
if (!
|
|
24252
|
+
if (!IDENTIFIER_PATTERN4.test(channelId)) {
|
|
24686
24253
|
throw new PairingClientError("invalid_channel_id", "The saved channel ID is invalid");
|
|
24687
24254
|
}
|
|
24688
24255
|
return channelId;
|
|
@@ -24721,9 +24288,9 @@ async function readJsonResponse(response) {
|
|
|
24721
24288
|
}
|
|
24722
24289
|
}
|
|
24723
24290
|
function readRelayError(value) {
|
|
24724
|
-
if (
|
|
24291
|
+
if (isRecord5(value)) {
|
|
24725
24292
|
const error62 = value["error"];
|
|
24726
|
-
if (
|
|
24293
|
+
if (isRecord5(error62)) {
|
|
24727
24294
|
const code = error62["code"];
|
|
24728
24295
|
const message = error62["message"];
|
|
24729
24296
|
if (typeof code === "string" && typeof message === "string") {
|
|
@@ -24734,13 +24301,13 @@ function readRelayError(value) {
|
|
|
24734
24301
|
return new PairingClientError("pairing_failed", "The relay could not pair this machine");
|
|
24735
24302
|
}
|
|
24736
24303
|
function decodePairingResponse(value, credentialField, expectedKeys) {
|
|
24737
|
-
if (!
|
|
24304
|
+
if (!isRecord5(value) || !hasExactKeys(value, expectedKeys)) {
|
|
24738
24305
|
throw new PairingClientError("invalid_relay_response", "The relay returned an invalid pairing response");
|
|
24739
24306
|
}
|
|
24740
24307
|
const channelId = value["channelId"];
|
|
24741
24308
|
const runtimeCredential2 = value[credentialField];
|
|
24742
24309
|
const runtimeId = value["runtimeId"];
|
|
24743
|
-
if (typeof channelId !== "string" || !
|
|
24310
|
+
if (typeof channelId !== "string" || !IDENTIFIER_PATTERN4.test(channelId) || typeof runtimeCredential2 !== "string" || !TOKEN_PATTERN.test(runtimeCredential2) || typeof runtimeId !== "string" || !IDENTIFIER_PATTERN4.test(runtimeId)) {
|
|
24744
24311
|
throw new PairingClientError("invalid_relay_response", "The relay returned an invalid pairing response");
|
|
24745
24312
|
}
|
|
24746
24313
|
return { channelId, runtimeCredential: runtimeCredential2, runtimeId };
|
|
@@ -24750,7 +24317,6 @@ async function claimPairing(options, defaultWorkspace, localAgents, installableA
|
|
|
24750
24317
|
agentPath: agent.agentIdentity.requestedPath,
|
|
24751
24318
|
agentVersion: agent.agentVersion,
|
|
24752
24319
|
agentSettingsDiscovery: true,
|
|
24753
|
-
botSessionConfiguration: true,
|
|
24754
24320
|
capabilities: agent.capabilities,
|
|
24755
24321
|
id: agent.id,
|
|
24756
24322
|
label: agent.label,
|
|
@@ -24785,7 +24351,7 @@ async function persistConnection(channelId, relayOrigin, runtimeCredential2, def
|
|
|
24785
24351
|
const connectionsDirectory = join15(readStateDirectory(environment), "connections");
|
|
24786
24352
|
await mkdir3(connectionsDirectory, { mode: 448, recursive: true });
|
|
24787
24353
|
const connectionPath = join15(connectionsDirectory, `${channelId}.json`);
|
|
24788
|
-
const temporaryPath = join15(connectionsDirectory, `.${channelId}.${
|
|
24354
|
+
const temporaryPath = join15(connectionsDirectory, `.${channelId}.${randomUUID()}.tmp`);
|
|
24789
24355
|
await writeFile2(
|
|
24790
24356
|
temporaryPath,
|
|
24791
24357
|
`${JSON.stringify(
|
|
@@ -24805,14 +24371,14 @@ async function persistConnection(channelId, relayOrigin, runtimeCredential2, def
|
|
|
24805
24371
|
return connectionPath;
|
|
24806
24372
|
}
|
|
24807
24373
|
function decodeSavedConnection(value, expectedChannelId) {
|
|
24808
|
-
if (!
|
|
24374
|
+
if (!isRecord5(value) || !hasExactKeys(value, SAVED_CONNECTION_KEYS) && !hasExactKeys(value, LEGACY_SAVED_CONNECTION_KEYS)) {
|
|
24809
24375
|
throw new PairingClientError("invalid_connection", "The saved connection is invalid");
|
|
24810
24376
|
}
|
|
24811
24377
|
const defaultWorkspace = value["defaultWorkspace"];
|
|
24812
24378
|
const channelId = value["channelId"];
|
|
24813
24379
|
const runtimeCredential2 = value["runtimeCredential"] ?? value["daemonToken"];
|
|
24814
24380
|
const relayOrigin = value["relayOrigin"];
|
|
24815
|
-
if (typeof defaultWorkspace !== "string" || typeof channelId !== "string" || channelId !== expectedChannelId || !
|
|
24381
|
+
if (typeof defaultWorkspace !== "string" || typeof channelId !== "string" || channelId !== expectedChannelId || !IDENTIFIER_PATTERN4.test(channelId) || typeof runtimeCredential2 !== "string" || !TOKEN_PATTERN.test(runtimeCredential2) || typeof relayOrigin !== "string") {
|
|
24816
24382
|
throw new PairingClientError("invalid_connection", "The saved connection is invalid");
|
|
24817
24383
|
}
|
|
24818
24384
|
return {
|
|
@@ -24971,10 +24537,10 @@ var AuditStore = class {
|
|
|
24971
24537
|
};
|
|
24972
24538
|
|
|
24973
24539
|
// src/run-daemon.ts
|
|
24974
|
-
import { randomUUID as
|
|
24975
|
-
import { basename as
|
|
24540
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
24541
|
+
import { basename as basename7 } from "node:path";
|
|
24976
24542
|
import { styleText } from "node:util";
|
|
24977
|
-
import { fetch as
|
|
24543
|
+
import { fetch as fetch6, WebSocket as WebSocket2 } from "undici";
|
|
24978
24544
|
|
|
24979
24545
|
// src/acp/session-manager.ts
|
|
24980
24546
|
import { spawn as spawn3 } from "node:child_process";
|
|
@@ -24986,10 +24552,11 @@ import {
|
|
|
24986
24552
|
} from "@agentclientprotocol/sdk";
|
|
24987
24553
|
|
|
24988
24554
|
// src/authorization/local-raster.ts
|
|
24989
|
-
import { readFile as readFile2, realpath as realpath7, stat as stat6 } from "node:fs/promises";
|
|
24555
|
+
import { open as open5, readFile as readFile2, realpath as realpath7, stat as stat6 } from "node:fs/promises";
|
|
24990
24556
|
import { basename as basename2, isAbsolute as isAbsolute8, normalize as normalize2 } from "node:path";
|
|
24991
24557
|
import { fileURLToPath } from "node:url";
|
|
24992
|
-
var MAX_LOCAL_RASTER_BYTES =
|
|
24558
|
+
var MAX_LOCAL_RASTER_BYTES = 128 * 1024 * 1024;
|
|
24559
|
+
var MAX_INLINE_RASTER_BYTES = 3e6;
|
|
24993
24560
|
var PNG_SIGNATURE = Uint8Array.of(137, 80, 78, 71);
|
|
24994
24561
|
var JPEG_SIGNATURE = Uint8Array.of(255, 216, 255);
|
|
24995
24562
|
var GIF87_SIGNATURE = new TextEncoder().encode("GIF87a");
|
|
@@ -25000,12 +24567,17 @@ var LocalRasterImage = class {
|
|
|
25000
24567
|
bytes;
|
|
25001
24568
|
mimeType;
|
|
25002
24569
|
name;
|
|
25003
|
-
|
|
24570
|
+
sourceUri;
|
|
24571
|
+
constructor(name, mimeType, bytes, sourceUri = "") {
|
|
25004
24572
|
this.bytes = bytes;
|
|
25005
24573
|
this.mimeType = mimeType;
|
|
25006
24574
|
this.name = name;
|
|
24575
|
+
this.sourceUri = sourceUri;
|
|
25007
24576
|
}
|
|
25008
|
-
base64 = () =>
|
|
24577
|
+
base64 = async () => {
|
|
24578
|
+
const bytes = this.bytes ?? new Uint8Array(await readFile2(this.sourceUri));
|
|
24579
|
+
return Buffer.from(bytes).toString("base64");
|
|
24580
|
+
};
|
|
25009
24581
|
};
|
|
25010
24582
|
function startsWith(bytes, signature, offset = 0) {
|
|
25011
24583
|
if (bytes.byteLength < offset + signature.byteLength) {
|
|
@@ -25029,14 +24601,14 @@ function sniffRasterMime(bytes) {
|
|
|
25029
24601
|
return null;
|
|
25030
24602
|
}
|
|
25031
24603
|
function readInlineRaster(data, name = "Image") {
|
|
25032
|
-
if (data.length === 0 || data.length > Math.ceil(
|
|
24604
|
+
if (data.length === 0 || data.length > Math.ceil(MAX_INLINE_RASTER_BYTES / 3) * 4 || data.length % 4 !== 0) {
|
|
25033
24605
|
return null;
|
|
25034
24606
|
}
|
|
25035
24607
|
if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(data)) {
|
|
25036
24608
|
return null;
|
|
25037
24609
|
}
|
|
25038
24610
|
const bytes = new Uint8Array(Buffer.from(data, "base64"));
|
|
25039
|
-
if (bytes.byteLength < 1 || bytes.byteLength >
|
|
24611
|
+
if (bytes.byteLength < 1 || bytes.byteLength > MAX_INLINE_RASTER_BYTES) {
|
|
25040
24612
|
return null;
|
|
25041
24613
|
}
|
|
25042
24614
|
const mimeType = sniffRasterMime(bytes);
|
|
@@ -25104,16 +24676,19 @@ async function readLocalRaster(uri, signal) {
|
|
|
25104
24676
|
if (!targetMetadata.isFile() || targetMetadata.size < 1 || targetMetadata.size > MAX_LOCAL_RASTER_BYTES) {
|
|
25105
24677
|
return null;
|
|
25106
24678
|
}
|
|
25107
|
-
const
|
|
25108
|
-
|
|
25109
|
-
|
|
25110
|
-
|
|
24679
|
+
const handle = await open5(target, "r");
|
|
24680
|
+
const header = new Uint8Array(12);
|
|
24681
|
+
try {
|
|
24682
|
+
await handle.read(header, 0, header.byteLength, 0);
|
|
24683
|
+
} finally {
|
|
24684
|
+
await handle.close();
|
|
25111
24685
|
}
|
|
25112
|
-
|
|
24686
|
+
signal.throwIfAborted();
|
|
24687
|
+
const mimeType = sniffRasterMime(header);
|
|
25113
24688
|
if (mimeType === null) {
|
|
25114
24689
|
return null;
|
|
25115
24690
|
}
|
|
25116
|
-
return new LocalRasterImage(basename2(target) || "Image", mimeType,
|
|
24691
|
+
return new LocalRasterImage(basename2(target) || "Image", mimeType, null, target);
|
|
25117
24692
|
}
|
|
25118
24693
|
|
|
25119
24694
|
// src/authorization/local-video.ts
|
|
@@ -25239,7 +24814,7 @@ async function resolveMessageImages(message, usedCharacters, signal) {
|
|
|
25239
24814
|
if (local === null) {
|
|
25240
24815
|
return "[Image unavailable]";
|
|
25241
24816
|
}
|
|
25242
|
-
const data = local.base64();
|
|
24817
|
+
const data = await local.base64();
|
|
25243
24818
|
if (usedCharacters + imageCharacters + data.length > SESSION_HISTORY_IMAGE_CHARACTER_LIMIT) {
|
|
25244
24819
|
return "[Image unavailable]";
|
|
25245
24820
|
}
|
|
@@ -25275,7 +24850,7 @@ async function replaceImageMarkers(text3, replace) {
|
|
|
25275
24850
|
|
|
25276
24851
|
// src/acp/activity.ts
|
|
25277
24852
|
var TRUNCATION_MARKER = "\n\u2026 output truncated by Mobius";
|
|
25278
|
-
function
|
|
24853
|
+
function isRecord6(value) {
|
|
25279
24854
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25280
24855
|
}
|
|
25281
24856
|
var AcpActivity = class _AcpActivity {
|
|
@@ -25509,16 +25084,16 @@ async function normalizeToolContent(content3, prepareContent) {
|
|
|
25509
25084
|
return normalized;
|
|
25510
25085
|
}
|
|
25511
25086
|
function rawMcpToolContent(rawOutput) {
|
|
25512
|
-
if (!
|
|
25087
|
+
if (!isRecord6(rawOutput)) {
|
|
25513
25088
|
return [];
|
|
25514
25089
|
}
|
|
25515
|
-
const result =
|
|
25090
|
+
const result = isRecord6(rawOutput["result"]) ? rawOutput["result"] : rawOutput;
|
|
25516
25091
|
const content3 = result["content"];
|
|
25517
25092
|
if (!Array.isArray(content3)) {
|
|
25518
25093
|
return [];
|
|
25519
25094
|
}
|
|
25520
25095
|
return content3.flatMap((item) => {
|
|
25521
|
-
if (!
|
|
25096
|
+
if (!isRecord6(item) || item["type"] !== "image" || typeof item["data"] !== "string" || typeof item["mimeType"] !== "string") {
|
|
25522
25097
|
return [];
|
|
25523
25098
|
}
|
|
25524
25099
|
const uri = item["uri"];
|
|
@@ -25595,7 +25170,7 @@ function contentPhase(content3) {
|
|
|
25595
25170
|
return "";
|
|
25596
25171
|
}
|
|
25597
25172
|
const codex = metadata["codex"];
|
|
25598
|
-
if (!
|
|
25173
|
+
if (!isRecord6(codex)) {
|
|
25599
25174
|
return "";
|
|
25600
25175
|
}
|
|
25601
25176
|
const phase = codex["phase"];
|
|
@@ -28399,7 +27974,7 @@ var attention = {
|
|
|
28399
27974
|
};
|
|
28400
27975
|
function resolveAllAttention(events, context) {
|
|
28401
27976
|
let index2 = -1;
|
|
28402
|
-
let
|
|
27977
|
+
let open6;
|
|
28403
27978
|
let group;
|
|
28404
27979
|
let text3;
|
|
28405
27980
|
let openingSequence;
|
|
@@ -28409,16 +27984,16 @@ function resolveAllAttention(events, context) {
|
|
|
28409
27984
|
let offset;
|
|
28410
27985
|
while (++index2 < events.length) {
|
|
28411
27986
|
if (events[index2][0] === "enter" && events[index2][1].type === "attentionSequence" && events[index2][1]._close) {
|
|
28412
|
-
|
|
28413
|
-
while (
|
|
28414
|
-
if (events[
|
|
28415
|
-
context.sliceSerialize(events[
|
|
28416
|
-
if ((events[
|
|
27987
|
+
open6 = index2;
|
|
27988
|
+
while (open6--) {
|
|
27989
|
+
if (events[open6][0] === "exit" && events[open6][1].type === "attentionSequence" && events[open6][1]._open && // If the markers are the same:
|
|
27990
|
+
context.sliceSerialize(events[open6][1]).charCodeAt(0) === context.sliceSerialize(events[index2][1]).charCodeAt(0)) {
|
|
27991
|
+
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)) {
|
|
28417
27992
|
continue;
|
|
28418
27993
|
}
|
|
28419
|
-
use = events[
|
|
27994
|
+
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;
|
|
28420
27995
|
const start = {
|
|
28421
|
-
...events[
|
|
27996
|
+
...events[open6][1].end
|
|
28422
27997
|
};
|
|
28423
27998
|
const end = {
|
|
28424
27999
|
...events[index2][1].start
|
|
@@ -28429,7 +28004,7 @@ function resolveAllAttention(events, context) {
|
|
|
28429
28004
|
type: use > 1 ? "strongSequence" : "emphasisSequence",
|
|
28430
28005
|
start,
|
|
28431
28006
|
end: {
|
|
28432
|
-
...events[
|
|
28007
|
+
...events[open6][1].end
|
|
28433
28008
|
}
|
|
28434
28009
|
};
|
|
28435
28010
|
closingSequence = {
|
|
@@ -28442,7 +28017,7 @@ function resolveAllAttention(events, context) {
|
|
|
28442
28017
|
text3 = {
|
|
28443
28018
|
type: use > 1 ? "strongText" : "emphasisText",
|
|
28444
28019
|
start: {
|
|
28445
|
-
...events[
|
|
28020
|
+
...events[open6][1].end
|
|
28446
28021
|
},
|
|
28447
28022
|
end: {
|
|
28448
28023
|
...events[index2][1].start
|
|
@@ -28457,18 +28032,18 @@ function resolveAllAttention(events, context) {
|
|
|
28457
28032
|
...closingSequence.end
|
|
28458
28033
|
}
|
|
28459
28034
|
};
|
|
28460
|
-
events[
|
|
28035
|
+
events[open6][1].end = {
|
|
28461
28036
|
...openingSequence.start
|
|
28462
28037
|
};
|
|
28463
28038
|
events[index2][1].start = {
|
|
28464
28039
|
...closingSequence.end
|
|
28465
28040
|
};
|
|
28466
28041
|
nextEvents = [];
|
|
28467
|
-
if (events[
|
|
28468
|
-
nextEvents = push(nextEvents, [["enter", events[
|
|
28042
|
+
if (events[open6][1].end.offset - events[open6][1].start.offset) {
|
|
28043
|
+
nextEvents = push(nextEvents, [["enter", events[open6][1], context], ["exit", events[open6][1], context]]);
|
|
28469
28044
|
}
|
|
28470
28045
|
nextEvents = push(nextEvents, [["enter", group, context], ["enter", openingSequence, context], ["exit", openingSequence, context], ["enter", text3, context]]);
|
|
28471
|
-
nextEvents = push(nextEvents, resolveAll(context.parser.constructs.insideSpan.null, events.slice(
|
|
28046
|
+
nextEvents = push(nextEvents, resolveAll(context.parser.constructs.insideSpan.null, events.slice(open6 + 1, index2), context));
|
|
28472
28047
|
nextEvents = push(nextEvents, [["exit", text3, context], ["enter", closingSequence, context], ["exit", closingSequence, context], ["exit", group, context]]);
|
|
28473
28048
|
if (events[index2][1].end.offset - events[index2][1].start.offset) {
|
|
28474
28049
|
offset = 2;
|
|
@@ -28476,8 +28051,8 @@ function resolveAllAttention(events, context) {
|
|
|
28476
28051
|
} else {
|
|
28477
28052
|
offset = 0;
|
|
28478
28053
|
}
|
|
28479
|
-
splice(events,
|
|
28480
|
-
index2 =
|
|
28054
|
+
splice(events, open6 - 1, index2 - open6 + 3, nextEvents);
|
|
28055
|
+
index2 = open6 + nextEvents.length - offset - 2;
|
|
28481
28056
|
break;
|
|
28482
28057
|
}
|
|
28483
28058
|
}
|
|
@@ -28509,10 +28084,10 @@ function tokenizeAttention(effects, ok2) {
|
|
|
28509
28084
|
}
|
|
28510
28085
|
const token = effects.exit("attentionSequence");
|
|
28511
28086
|
const after = classifyCharacter(code);
|
|
28512
|
-
const
|
|
28087
|
+
const open6 = !after || after === 2 && before || attentionMarkers2.includes(code);
|
|
28513
28088
|
const close = !before || before === 2 && after || attentionMarkers2.includes(previous2);
|
|
28514
|
-
token._open = Boolean(marker === 42 ?
|
|
28515
|
-
token._close = Boolean(marker === 42 ? close : close && (after || !
|
|
28089
|
+
token._open = Boolean(marker === 42 ? open6 : open6 && (before || !close));
|
|
28090
|
+
token._close = Boolean(marker === 42 ? close : close && (after || !open6));
|
|
28516
28091
|
return ok2(code);
|
|
28517
28092
|
}
|
|
28518
28093
|
}
|
|
@@ -28536,9 +28111,9 @@ function tokenizeAutolink(effects, ok2, nok) {
|
|
|
28536
28111
|
effects.consume(code);
|
|
28537
28112
|
effects.exit("autolinkMarker");
|
|
28538
28113
|
effects.enter("autolinkProtocol");
|
|
28539
|
-
return
|
|
28114
|
+
return open6;
|
|
28540
28115
|
}
|
|
28541
|
-
function
|
|
28116
|
+
function open6(code) {
|
|
28542
28117
|
if (asciiAlpha(code)) {
|
|
28543
28118
|
effects.consume(code);
|
|
28544
28119
|
return schemeOrEmailAtext;
|
|
@@ -28738,9 +28313,9 @@ function tokenizeCharacterReference(effects, ok2, nok) {
|
|
|
28738
28313
|
effects.enter("characterReferenceMarker");
|
|
28739
28314
|
effects.consume(code);
|
|
28740
28315
|
effects.exit("characterReferenceMarker");
|
|
28741
|
-
return
|
|
28316
|
+
return open6;
|
|
28742
28317
|
}
|
|
28743
|
-
function
|
|
28318
|
+
function open6(code) {
|
|
28744
28319
|
if (code === 35) {
|
|
28745
28320
|
effects.enter("characterReferenceMarkerNumeric");
|
|
28746
28321
|
effects.consume(code);
|
|
@@ -30109,9 +29684,9 @@ function tokenizeHtmlFlow(effects, ok2, nok) {
|
|
|
30109
29684
|
effects.enter("htmlFlow");
|
|
30110
29685
|
effects.enter("htmlFlowData");
|
|
30111
29686
|
effects.consume(code);
|
|
30112
|
-
return
|
|
29687
|
+
return open6;
|
|
30113
29688
|
}
|
|
30114
|
-
function
|
|
29689
|
+
function open6(code) {
|
|
30115
29690
|
if (code === 33) {
|
|
30116
29691
|
effects.consume(code);
|
|
30117
29692
|
return declarationOpen;
|
|
@@ -30459,9 +30034,9 @@ function tokenizeHtmlText(effects, ok2, nok) {
|
|
|
30459
30034
|
effects.enter("htmlText");
|
|
30460
30035
|
effects.enter("htmlTextData");
|
|
30461
30036
|
effects.consume(code);
|
|
30462
|
-
return
|
|
30037
|
+
return open6;
|
|
30463
30038
|
}
|
|
30464
|
-
function
|
|
30039
|
+
function open6(code) {
|
|
30465
30040
|
if (code === 33) {
|
|
30466
30041
|
effects.consume(code);
|
|
30467
30042
|
return declarationOpen;
|
|
@@ -30787,12 +30362,12 @@ function resolveToLabelEnd(events, context) {
|
|
|
30787
30362
|
let index2 = events.length;
|
|
30788
30363
|
let offset = 0;
|
|
30789
30364
|
let token;
|
|
30790
|
-
let
|
|
30365
|
+
let open6;
|
|
30791
30366
|
let close;
|
|
30792
30367
|
let media;
|
|
30793
30368
|
while (index2--) {
|
|
30794
30369
|
token = events[index2][1];
|
|
30795
|
-
if (
|
|
30370
|
+
if (open6) {
|
|
30796
30371
|
if (token.type === "link" || token.type === "labelLink" && token._inactive) {
|
|
30797
30372
|
break;
|
|
30798
30373
|
}
|
|
@@ -30801,7 +30376,7 @@ function resolveToLabelEnd(events, context) {
|
|
|
30801
30376
|
}
|
|
30802
30377
|
} else if (close) {
|
|
30803
30378
|
if (events[index2][0] === "enter" && (token.type === "labelImage" || token.type === "labelLink") && !token._balanced) {
|
|
30804
|
-
|
|
30379
|
+
open6 = index2;
|
|
30805
30380
|
if (token.type !== "labelLink") {
|
|
30806
30381
|
offset = 2;
|
|
30807
30382
|
break;
|
|
@@ -30812,9 +30387,9 @@ function resolveToLabelEnd(events, context) {
|
|
|
30812
30387
|
}
|
|
30813
30388
|
}
|
|
30814
30389
|
const group = {
|
|
30815
|
-
type: events[
|
|
30390
|
+
type: events[open6][1].type === "labelLink" ? "link" : "image",
|
|
30816
30391
|
start: {
|
|
30817
|
-
...events[
|
|
30392
|
+
...events[open6][1].start
|
|
30818
30393
|
},
|
|
30819
30394
|
end: {
|
|
30820
30395
|
...events[events.length - 1][1].end
|
|
@@ -30823,7 +30398,7 @@ function resolveToLabelEnd(events, context) {
|
|
|
30823
30398
|
const label = {
|
|
30824
30399
|
type: "label",
|
|
30825
30400
|
start: {
|
|
30826
|
-
...events[
|
|
30401
|
+
...events[open6][1].start
|
|
30827
30402
|
},
|
|
30828
30403
|
end: {
|
|
30829
30404
|
...events[close][1].end
|
|
@@ -30832,20 +30407,20 @@ function resolveToLabelEnd(events, context) {
|
|
|
30832
30407
|
const text3 = {
|
|
30833
30408
|
type: "labelText",
|
|
30834
30409
|
start: {
|
|
30835
|
-
...events[
|
|
30410
|
+
...events[open6 + offset + 2][1].end
|
|
30836
30411
|
},
|
|
30837
30412
|
end: {
|
|
30838
30413
|
...events[close - 2][1].start
|
|
30839
30414
|
}
|
|
30840
30415
|
};
|
|
30841
30416
|
media = [["enter", group, context], ["enter", label, context]];
|
|
30842
|
-
media = push(media, events.slice(
|
|
30417
|
+
media = push(media, events.slice(open6 + 1, open6 + offset + 3));
|
|
30843
30418
|
media = push(media, [["enter", text3, context]]);
|
|
30844
|
-
media = push(media, resolveAll(context.parser.constructs.insideSpan.null, events.slice(
|
|
30419
|
+
media = push(media, resolveAll(context.parser.constructs.insideSpan.null, events.slice(open6 + offset + 4, close - 3), context));
|
|
30845
30420
|
media = push(media, [["exit", text3, context], events[close - 2], events[close - 1], ["exit", label, context]]);
|
|
30846
30421
|
media = push(media, events.slice(close + 1));
|
|
30847
30422
|
media = push(media, [["exit", group, context]]);
|
|
30848
|
-
splice(events,
|
|
30423
|
+
splice(events, open6, events.length, media);
|
|
30849
30424
|
return events;
|
|
30850
30425
|
}
|
|
30851
30426
|
function tokenizeLabelEnd(effects, ok2, nok) {
|
|
@@ -30990,9 +30565,9 @@ function tokenizeLabelStartImage(effects, ok2, nok) {
|
|
|
30990
30565
|
effects.enter("labelImageMarker");
|
|
30991
30566
|
effects.consume(code);
|
|
30992
30567
|
effects.exit("labelImageMarker");
|
|
30993
|
-
return
|
|
30568
|
+
return open6;
|
|
30994
30569
|
}
|
|
30995
|
-
function
|
|
30570
|
+
function open6(code) {
|
|
30996
30571
|
if (code === 91) {
|
|
30997
30572
|
effects.enter("labelMarker");
|
|
30998
30573
|
effects.consume(code);
|
|
@@ -32296,8 +31871,8 @@ function compiler(options) {
|
|
|
32296
31871
|
return length;
|
|
32297
31872
|
}
|
|
32298
31873
|
function opener(create, and) {
|
|
32299
|
-
return
|
|
32300
|
-
function
|
|
31874
|
+
return open6;
|
|
31875
|
+
function open6(token) {
|
|
32301
31876
|
enter.call(this, create(token), token);
|
|
32302
31877
|
if (and) and.call(this, token);
|
|
32303
31878
|
}
|
|
@@ -32329,18 +31904,18 @@ function compiler(options) {
|
|
|
32329
31904
|
}
|
|
32330
31905
|
function exit2(token, onExitError) {
|
|
32331
31906
|
const node3 = this.stack.pop();
|
|
32332
|
-
const
|
|
32333
|
-
if (!
|
|
31907
|
+
const open6 = this.tokenStack.pop();
|
|
31908
|
+
if (!open6) {
|
|
32334
31909
|
throw new Error("Cannot close `" + token.type + "` (" + stringifyPosition({
|
|
32335
31910
|
start: token.start,
|
|
32336
31911
|
end: token.end
|
|
32337
31912
|
}) + "): it\u2019s not open");
|
|
32338
|
-
} else if (
|
|
31913
|
+
} else if (open6[0].type !== token.type) {
|
|
32339
31914
|
if (onExitError) {
|
|
32340
|
-
onExitError.call(this, token,
|
|
31915
|
+
onExitError.call(this, token, open6[0]);
|
|
32341
31916
|
} else {
|
|
32342
|
-
const handler =
|
|
32343
|
-
handler.call(this, token,
|
|
31917
|
+
const handler = open6[1] || defaultOnError;
|
|
31918
|
+
handler.call(this, token, open6[0]);
|
|
32344
31919
|
}
|
|
32345
31920
|
}
|
|
32346
31921
|
node3.position.end = point2(token.end);
|
|
@@ -33024,7 +32599,7 @@ var SessionConfigProtocolError = class extends Error {
|
|
|
33024
32599
|
this.name = "SessionConfigProtocolError";
|
|
33025
32600
|
}
|
|
33026
32601
|
};
|
|
33027
|
-
function
|
|
32602
|
+
function isRecord7(value) {
|
|
33028
32603
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33029
32604
|
}
|
|
33030
32605
|
function readString2(value, fallback = "") {
|
|
@@ -33036,13 +32611,13 @@ function truncate2(value, maximum) {
|
|
|
33036
32611
|
function readBoolean(value, fallback = false) {
|
|
33037
32612
|
return typeof value === "boolean" ? value : fallback;
|
|
33038
32613
|
}
|
|
33039
|
-
function normalizeConfigValue(
|
|
32614
|
+
function normalizeConfigValue(option, groupId = "", groupName = "") {
|
|
33040
32615
|
return {
|
|
33041
|
-
description: truncate2(readString2(
|
|
32616
|
+
description: truncate2(readString2(option["description"]), 500),
|
|
33042
32617
|
groupId: truncate2(groupId, 128),
|
|
33043
32618
|
groupName: truncate2(groupName, 255),
|
|
33044
|
-
name: truncate2(readString2(
|
|
33045
|
-
value: truncate2(readString2(
|
|
32619
|
+
name: truncate2(readString2(option["name"], readString2(option["value"])), 255),
|
|
32620
|
+
value: truncate2(readString2(option["value"]), 500)
|
|
33046
32621
|
};
|
|
33047
32622
|
}
|
|
33048
32623
|
function normalizeConfigValues(value) {
|
|
@@ -33051,7 +32626,7 @@ function normalizeConfigValues(value) {
|
|
|
33051
32626
|
}
|
|
33052
32627
|
const normalized = [];
|
|
33053
32628
|
for (const entry of value) {
|
|
33054
|
-
if (!
|
|
32629
|
+
if (!isRecord7(entry)) {
|
|
33055
32630
|
continue;
|
|
33056
32631
|
}
|
|
33057
32632
|
const groupedOptions = entry["options"];
|
|
@@ -33059,7 +32634,7 @@ function normalizeConfigValues(value) {
|
|
|
33059
32634
|
const groupId = readString2(entry["group"]);
|
|
33060
32635
|
const groupName = readString2(entry["name"]);
|
|
33061
32636
|
for (const groupedOption of groupedOptions) {
|
|
33062
|
-
if (
|
|
32637
|
+
if (isRecord7(groupedOption)) {
|
|
33063
32638
|
normalized.push(normalizeConfigValue(groupedOption, groupId, groupName));
|
|
33064
32639
|
}
|
|
33065
32640
|
}
|
|
@@ -33072,21 +32647,21 @@ function normalizeConfigValues(value) {
|
|
|
33072
32647
|
function normalizeConfigOptions(value, modes) {
|
|
33073
32648
|
const normalized = [];
|
|
33074
32649
|
if (Array.isArray(value)) {
|
|
33075
|
-
for (const
|
|
33076
|
-
if (!
|
|
32650
|
+
for (const option of value) {
|
|
32651
|
+
if (!isRecord7(option)) {
|
|
33077
32652
|
continue;
|
|
33078
32653
|
}
|
|
33079
|
-
const id = truncate2(readString2(
|
|
33080
|
-
const name = truncate2(readString2(
|
|
32654
|
+
const id = truncate2(readString2(option["id"]), 128);
|
|
32655
|
+
const name = truncate2(readString2(option["name"], id), 255);
|
|
33081
32656
|
if (id.length === 0 || name.length === 0) {
|
|
33082
32657
|
continue;
|
|
33083
32658
|
}
|
|
33084
|
-
if (
|
|
32659
|
+
if (option["type"] === "boolean") {
|
|
33085
32660
|
normalized.push({
|
|
33086
|
-
booleanValue: readBoolean(
|
|
33087
|
-
category: truncate2(readString2(
|
|
32661
|
+
booleanValue: readBoolean(option["currentValue"]),
|
|
32662
|
+
category: truncate2(readString2(option["category"]), 128),
|
|
33088
32663
|
currentValue: "",
|
|
33089
|
-
description: truncate2(readString2(
|
|
32664
|
+
description: truncate2(readString2(option["description"]), 500),
|
|
33090
32665
|
id,
|
|
33091
32666
|
name,
|
|
33092
32667
|
type: "boolean",
|
|
@@ -33094,15 +32669,15 @@ function normalizeConfigOptions(value, modes) {
|
|
|
33094
32669
|
});
|
|
33095
32670
|
continue;
|
|
33096
32671
|
}
|
|
33097
|
-
if (
|
|
33098
|
-
const values = normalizeConfigValues(
|
|
33099
|
-
const currentValue = truncate2(readString2(
|
|
32672
|
+
if (option["type"] === "select") {
|
|
32673
|
+
const values = normalizeConfigValues(option["options"]);
|
|
32674
|
+
const currentValue = truncate2(readString2(option["currentValue"]), 500);
|
|
33100
32675
|
if (currentValue.length > 0 && values.some((entry) => entry.value === currentValue)) {
|
|
33101
32676
|
normalized.push({
|
|
33102
32677
|
booleanValue: false,
|
|
33103
|
-
category: truncate2(readString2(
|
|
32678
|
+
category: truncate2(readString2(option["category"]), 128),
|
|
33104
32679
|
currentValue,
|
|
33105
|
-
description: truncate2(readString2(
|
|
32680
|
+
description: truncate2(readString2(option["description"]), 500),
|
|
33106
32681
|
id,
|
|
33107
32682
|
name,
|
|
33108
32683
|
type: "select",
|
|
@@ -33112,12 +32687,12 @@ function normalizeConfigOptions(value, modes) {
|
|
|
33112
32687
|
}
|
|
33113
32688
|
}
|
|
33114
32689
|
}
|
|
33115
|
-
if (
|
|
32690
|
+
if (isRecord7(modes)) {
|
|
33116
32691
|
const values = [];
|
|
33117
32692
|
const availableModes = modes["availableModes"];
|
|
33118
32693
|
if (Array.isArray(availableModes)) {
|
|
33119
32694
|
for (const mode of availableModes) {
|
|
33120
|
-
if (!
|
|
32695
|
+
if (!isRecord7(mode)) {
|
|
33121
32696
|
continue;
|
|
33122
32697
|
}
|
|
33123
32698
|
const id = truncate2(readString2(mode["id"]), 500);
|
|
@@ -33150,14 +32725,14 @@ function normalizeConfigOptions(value, modes) {
|
|
|
33150
32725
|
return normalized.slice(0, 100);
|
|
33151
32726
|
}
|
|
33152
32727
|
function insertRequiredOption(current, required2, afterCategory = "") {
|
|
33153
|
-
if (current.some((
|
|
32728
|
+
if (current.some((option) => option.id === required2.id || option.category === required2.category)) {
|
|
33154
32729
|
return current;
|
|
33155
32730
|
}
|
|
33156
32731
|
if (current.length < MAXIMUM_CONFIG_OPTIONS) {
|
|
33157
32732
|
if (afterCategory.length === 0) {
|
|
33158
32733
|
return [required2, ...current];
|
|
33159
32734
|
}
|
|
33160
|
-
const index3 = current.findIndex((
|
|
32735
|
+
const index3 = current.findIndex((option) => option.category === afterCategory);
|
|
33161
32736
|
if (index3 < 0) {
|
|
33162
32737
|
return [...current, required2];
|
|
33163
32738
|
}
|
|
@@ -33166,7 +32741,7 @@ function insertRequiredOption(current, required2, afterCategory = "") {
|
|
|
33166
32741
|
if (afterCategory.length === 0) {
|
|
33167
32742
|
return [required2, ...current.slice(0, MAXIMUM_CONFIG_OPTIONS - 1)];
|
|
33168
32743
|
}
|
|
33169
|
-
const index2 = current.findIndex((
|
|
32744
|
+
const index2 = current.findIndex((option) => option.category === afterCategory);
|
|
33170
32745
|
if (index2 < 0) {
|
|
33171
32746
|
return [...current.slice(0, MAXIMUM_CONFIG_OPTIONS - 1), required2];
|
|
33172
32747
|
}
|
|
@@ -33179,11 +32754,11 @@ function insertRequiredOption(current, required2, afterCategory = "") {
|
|
|
33179
32754
|
}
|
|
33180
32755
|
return [...current.slice(0, MAXIMUM_CONFIG_OPTIONS - 2), anchor2, required2];
|
|
33181
32756
|
}
|
|
33182
|
-
function validRequiredSelect(
|
|
33183
|
-
return
|
|
32757
|
+
function validRequiredSelect(option) {
|
|
32758
|
+
return option.type === "select" && option.currentValue.length > 0 && option.values.some((value) => value.value === option.currentValue);
|
|
33184
32759
|
}
|
|
33185
32760
|
function ensureModelOption(current) {
|
|
33186
|
-
const existing = current.find((
|
|
32761
|
+
const existing = current.find((option) => option.id === "model" || option.category === "model");
|
|
33187
32762
|
if (existing !== void 0 && validRequiredSelect(existing)) {
|
|
33188
32763
|
return current;
|
|
33189
32764
|
}
|
|
@@ -33206,12 +32781,12 @@ function ensureModelOption(current) {
|
|
|
33206
32781
|
]
|
|
33207
32782
|
};
|
|
33208
32783
|
return insertRequiredOption(
|
|
33209
|
-
current.filter((
|
|
32784
|
+
current.filter((option) => option.id !== "model" && option.category !== "model"),
|
|
33210
32785
|
unavailable
|
|
33211
32786
|
);
|
|
33212
32787
|
}
|
|
33213
32788
|
function ensureReasoningEffortOption(current) {
|
|
33214
|
-
const existing = current.find((
|
|
32789
|
+
const existing = current.find((option) => option.id === "reasoning_effort" || option.category === "thought_level");
|
|
33215
32790
|
if (existing !== void 0 && validRequiredSelect(existing)) {
|
|
33216
32791
|
return current;
|
|
33217
32792
|
}
|
|
@@ -33234,7 +32809,7 @@ function ensureReasoningEffortOption(current) {
|
|
|
33234
32809
|
]
|
|
33235
32810
|
};
|
|
33236
32811
|
return insertRequiredOption(
|
|
33237
|
-
current.filter((
|
|
32812
|
+
current.filter((option) => option.id !== "reasoning_effort" && option.category !== "thought_level"),
|
|
33238
32813
|
unavailable,
|
|
33239
32814
|
"model"
|
|
33240
32815
|
);
|
|
@@ -33242,34 +32817,34 @@ function ensureReasoningEffortOption(current) {
|
|
|
33242
32817
|
function ensureRequiredExecutionOptions(current, permission) {
|
|
33243
32818
|
const normalized = ensureReasoningEffortOption(ensureModelOption(current));
|
|
33244
32819
|
const model = normalized.find(
|
|
33245
|
-
(
|
|
32820
|
+
(option) => (option.id === "model" || option.category === "model") && validRequiredSelect(option)
|
|
33246
32821
|
);
|
|
33247
32822
|
const reasoningEffort = normalized.find(
|
|
33248
|
-
(
|
|
32823
|
+
(option) => (option.id === "reasoning_effort" || option.category === "thought_level") && validRequiredSelect(option)
|
|
33249
32824
|
);
|
|
33250
32825
|
if (model === void 0 || reasoningEffort === void 0) {
|
|
33251
32826
|
throw new SessionConfigProtocolError("The required Agent execution settings are unavailable");
|
|
33252
32827
|
}
|
|
33253
32828
|
const optional2 = normalized.filter(
|
|
33254
|
-
(
|
|
32829
|
+
(option) => option.id !== permission.id && option.category !== permission.category && option.id !== "model" && option.category !== "model" && option.id !== "reasoning_effort" && option.category !== "thought_level"
|
|
33255
32830
|
);
|
|
33256
32831
|
return [permission, model, reasoningEffort, ...optional2].slice(0, MAXIMUM_CONFIG_OPTIONS);
|
|
33257
32832
|
}
|
|
33258
32833
|
function normalizeStandardLifecycle(response) {
|
|
33259
|
-
const lifecycle =
|
|
32834
|
+
const lifecycle = isRecord7(response) ? response : {};
|
|
33260
32835
|
return ensureReasoningEffortOption(normalizeConfigOptions(lifecycle["configOptions"], lifecycle["modes"]));
|
|
33261
32836
|
}
|
|
33262
32837
|
function replaceStandardConfigOptions(current, value) {
|
|
33263
32838
|
const next = normalizeConfigOptions(value, void 0);
|
|
33264
|
-
const withMode = next.some((
|
|
32839
|
+
const withMode = next.some((option) => option.category === "mode") ? next : [...current.filter((option) => option.category === "mode"), ...next].slice(0, 100);
|
|
33265
32840
|
return ensureReasoningEffortOption(withMode);
|
|
33266
32841
|
}
|
|
33267
32842
|
function updateCurrentValue(current, configId, value) {
|
|
33268
|
-
return current.map((
|
|
32843
|
+
return current.map((option) => option.id === configId ? { ...option, currentValue: value } : option);
|
|
33269
32844
|
}
|
|
33270
32845
|
var StandardSessionConfigProtocol = class {
|
|
33271
32846
|
configure = async (current, change, nativeSessionId, transport) => {
|
|
33272
|
-
const existing = current.find((
|
|
32847
|
+
const existing = current.find((option) => option.id === change.configId);
|
|
33273
32848
|
if (existing === void 0) {
|
|
33274
32849
|
return current;
|
|
33275
32850
|
}
|
|
@@ -33298,7 +32873,7 @@ var StandardSessionConfigProtocol = class {
|
|
|
33298
32873
|
"ACP agent exited while changing session configuration",
|
|
33299
32874
|
change.signal
|
|
33300
32875
|
);
|
|
33301
|
-
if (!
|
|
32876
|
+
if (!isRecord7(response) || !Array.isArray(response["configOptions"])) {
|
|
33302
32877
|
throw new SessionConfigProtocolError("The Agent returned an invalid session configuration response");
|
|
33303
32878
|
}
|
|
33304
32879
|
return replaceStandardConfigOptions(current, response["configOptions"]);
|
|
@@ -33312,31 +32887,31 @@ var standardSessionConfigProtocol = new StandardSessionConfigProtocol();
|
|
|
33312
32887
|
var LEGACY_MODEL_CONFIG_ID = "grok_build_legacy_model";
|
|
33313
32888
|
var LEGACY_REASONING_EFFORT_CONFIG_ID = "grok_build_legacy_reasoning_effort";
|
|
33314
32889
|
function legacyOptions(response) {
|
|
33315
|
-
if (!
|
|
32890
|
+
if (!isRecord7(response)) {
|
|
33316
32891
|
return [];
|
|
33317
32892
|
}
|
|
33318
32893
|
const metadata = response["_meta"];
|
|
33319
|
-
if (!
|
|
32894
|
+
if (!isRecord7(metadata)) {
|
|
33320
32895
|
return [];
|
|
33321
32896
|
}
|
|
33322
32897
|
const sessionConfig = metadata["x.ai/sessionConfig"];
|
|
33323
|
-
if (!
|
|
32898
|
+
if (!isRecord7(sessionConfig) || !Array.isArray(sessionConfig["options"])) {
|
|
33324
32899
|
return [];
|
|
33325
32900
|
}
|
|
33326
|
-
return sessionConfig["options"].slice(0, 500).filter(
|
|
32901
|
+
return sessionConfig["options"].slice(0, 500).filter(isRecord7);
|
|
33327
32902
|
}
|
|
33328
|
-
function legacyValue(
|
|
33329
|
-
const value = readString2(
|
|
32903
|
+
function legacyValue(option) {
|
|
32904
|
+
const value = readString2(option["id"]);
|
|
33330
32905
|
return {
|
|
33331
|
-
description: readString2(
|
|
32906
|
+
description: readString2(option["description"]).slice(0, 500),
|
|
33332
32907
|
groupId: "",
|
|
33333
32908
|
groupName: "",
|
|
33334
|
-
name: readString2(
|
|
32909
|
+
name: readString2(option["label"], value).slice(0, 255),
|
|
33335
32910
|
value: value.slice(0, 500)
|
|
33336
32911
|
};
|
|
33337
32912
|
}
|
|
33338
32913
|
function modelsRecord(response) {
|
|
33339
|
-
if (!
|
|
32914
|
+
if (!isRecord7(response) || !isRecord7(response["models"])) {
|
|
33340
32915
|
return {};
|
|
33341
32916
|
}
|
|
33342
32917
|
return response["models"];
|
|
@@ -33345,9 +32920,9 @@ function legacyModelOptions(response) {
|
|
|
33345
32920
|
const options = legacyOptions(response);
|
|
33346
32921
|
const models = modelsRecord(response);
|
|
33347
32922
|
const values = [];
|
|
33348
|
-
for (const
|
|
33349
|
-
if (
|
|
33350
|
-
const value = legacyValue(
|
|
32923
|
+
for (const option of options) {
|
|
32924
|
+
if (option["category"] === "model") {
|
|
32925
|
+
const value = legacyValue(option);
|
|
33351
32926
|
if (value.value.length > 0 && !values.some((existing) => existing.value === value.value)) {
|
|
33352
32927
|
values.push(value);
|
|
33353
32928
|
}
|
|
@@ -33355,7 +32930,7 @@ function legacyModelOptions(response) {
|
|
|
33355
32930
|
}
|
|
33356
32931
|
if (values.length === 0 && Array.isArray(models["availableModels"])) {
|
|
33357
32932
|
for (const model of models["availableModels"]) {
|
|
33358
|
-
if (!
|
|
32933
|
+
if (!isRecord7(model)) {
|
|
33359
32934
|
continue;
|
|
33360
32935
|
}
|
|
33361
32936
|
const value = readString2(model["modelId"]).slice(0, 500);
|
|
@@ -33373,7 +32948,7 @@ function legacyModelOptions(response) {
|
|
|
33373
32948
|
}
|
|
33374
32949
|
}
|
|
33375
32950
|
}
|
|
33376
|
-
const selected = options.find((
|
|
32951
|
+
const selected = options.find((option) => option["category"] === "model" && option["selected"] === true);
|
|
33377
32952
|
const currentValue = readString2(
|
|
33378
32953
|
models["currentModelId"],
|
|
33379
32954
|
selected === void 0 ? "" : readString2(selected["id"])
|
|
@@ -33396,11 +32971,11 @@ function legacyModelOptions(response) {
|
|
|
33396
32971
|
function legacyReasoningEffortOptions(response) {
|
|
33397
32972
|
const options = legacyOptions(response);
|
|
33398
32973
|
const values = [];
|
|
33399
|
-
for (const
|
|
33400
|
-
if (
|
|
32974
|
+
for (const option of options) {
|
|
32975
|
+
if (option["category"] !== "mode") {
|
|
33401
32976
|
continue;
|
|
33402
32977
|
}
|
|
33403
|
-
const value = legacyValue(
|
|
32978
|
+
const value = legacyValue(option);
|
|
33404
32979
|
if (value.value.length > 0 && !values.some((existing) => existing.value === value.value)) {
|
|
33405
32980
|
values.push(value);
|
|
33406
32981
|
}
|
|
@@ -33408,7 +32983,7 @@ function legacyReasoningEffortOptions(response) {
|
|
|
33408
32983
|
if (values.length === 0) {
|
|
33409
32984
|
return [];
|
|
33410
32985
|
}
|
|
33411
|
-
const selected = options.find((
|
|
32986
|
+
const selected = options.find((option) => option["category"] === "mode" && option["selected"] === true);
|
|
33412
32987
|
if (selected === void 0) {
|
|
33413
32988
|
values.unshift({
|
|
33414
32989
|
description: "Use the selected model's default reasoning effort",
|
|
@@ -33435,41 +33010,41 @@ function legacyReasoningEffortOptions(response) {
|
|
|
33435
33010
|
return [result];
|
|
33436
33011
|
}
|
|
33437
33012
|
function normalizeGrokLifecycle(response) {
|
|
33438
|
-
const lifecycle =
|
|
33013
|
+
const lifecycle = isRecord7(response) ? response : {};
|
|
33439
33014
|
const standard = normalizeConfigOptions(lifecycle["configOptions"], lifecycle["modes"]);
|
|
33440
33015
|
const normalized = [...standard];
|
|
33441
|
-
if (!normalized.some((
|
|
33016
|
+
if (!normalized.some((option) => option.category === "model")) {
|
|
33442
33017
|
normalized.push(...legacyModelOptions(response));
|
|
33443
33018
|
}
|
|
33444
|
-
if (!normalized.some((
|
|
33019
|
+
if (!normalized.some((option) => option.category === "thought_level")) {
|
|
33445
33020
|
const efforts = legacyReasoningEffortOptions(response);
|
|
33446
33021
|
if (efforts.length > 0) {
|
|
33447
|
-
const modelIndex = normalized.findIndex((
|
|
33022
|
+
const modelIndex = normalized.findIndex((option) => option.category === "model");
|
|
33448
33023
|
normalized.splice(modelIndex < 0 ? normalized.length : modelIndex + 1, 0, ...efforts);
|
|
33449
33024
|
}
|
|
33450
33025
|
}
|
|
33451
33026
|
return ensureReasoningEffortOption(normalized.slice(0, 100));
|
|
33452
33027
|
}
|
|
33453
33028
|
function updateCurrentValue2(current, category, value) {
|
|
33454
|
-
return current.map((
|
|
33029
|
+
return current.map((option) => option.category === category ? { ...option, currentValue: value } : option);
|
|
33455
33030
|
}
|
|
33456
33031
|
function validateGrokResponse(response, modelId) {
|
|
33457
|
-
if (!
|
|
33032
|
+
if (!isRecord7(response) || !isRecord7(response["_meta"])) {
|
|
33458
33033
|
throw new SessionConfigProtocolError("Grok Build returned an invalid session configuration response");
|
|
33459
33034
|
}
|
|
33460
33035
|
const model = response["_meta"]["model"];
|
|
33461
|
-
const appliedModel =
|
|
33036
|
+
const appliedModel = isRecord7(model) ? model["Ok"] : model;
|
|
33462
33037
|
if (appliedModel !== modelId) {
|
|
33463
33038
|
throw new SessionConfigProtocolError("Grok Build returned an invalid session configuration response");
|
|
33464
33039
|
}
|
|
33465
33040
|
}
|
|
33466
33041
|
var GrokBuildSessionConfigProtocol = class {
|
|
33467
33042
|
configure = async (current, change, nativeSessionId, transport) => {
|
|
33468
|
-
const existing = current.find((
|
|
33043
|
+
const existing = current.find((option) => option.id === change.configId);
|
|
33469
33044
|
if (existing === void 0 || existing.id !== LEGACY_MODEL_CONFIG_ID && existing.id !== LEGACY_REASONING_EFFORT_CONFIG_ID) {
|
|
33470
33045
|
return await standardSessionConfigProtocol.configure(current, change, nativeSessionId, transport);
|
|
33471
33046
|
}
|
|
33472
|
-
const model = current.find((
|
|
33047
|
+
const model = current.find((option) => option.category === "model");
|
|
33473
33048
|
if (model === void 0) {
|
|
33474
33049
|
return current;
|
|
33475
33050
|
}
|
|
@@ -33495,10 +33070,10 @@ var GrokBuildSessionConfigProtocol = class {
|
|
|
33495
33070
|
validateGrokResponse(response, modelId);
|
|
33496
33071
|
const updated = updateCurrentValue2(current, existing.category, change.value);
|
|
33497
33072
|
return existing.category === "thought_level" ? updated.map(
|
|
33498
|
-
(
|
|
33499
|
-
...
|
|
33500
|
-
values:
|
|
33501
|
-
} :
|
|
33073
|
+
(option) => option.category === "thought_level" ? {
|
|
33074
|
+
...option,
|
|
33075
|
+
values: option.values.filter((value) => value.value !== AGENT_DEFAULT_REASONING_EFFORT)
|
|
33076
|
+
} : option
|
|
33502
33077
|
) : updated;
|
|
33503
33078
|
};
|
|
33504
33079
|
normalizeLifecycle = (response) => normalizeGrokLifecycle(response);
|
|
@@ -33991,7 +33566,7 @@ function createWritableAcpStream(output2) {
|
|
|
33991
33566
|
function truncate3(value, maximumLength) {
|
|
33992
33567
|
return value.length <= maximumLength ? value : `${value.slice(0, Math.max(0, maximumLength - 1))}\u2026`;
|
|
33993
33568
|
}
|
|
33994
|
-
function
|
|
33569
|
+
function isRecord8(value) {
|
|
33995
33570
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33996
33571
|
}
|
|
33997
33572
|
function readString4(value, fallback = "") {
|
|
@@ -34024,12 +33599,12 @@ function normalizeElicitationOptions(schema) {
|
|
|
34024
33599
|
const normalized = [];
|
|
34025
33600
|
const oneOf = schema["oneOf"];
|
|
34026
33601
|
if (Array.isArray(oneOf)) {
|
|
34027
|
-
for (const
|
|
34028
|
-
if (
|
|
33602
|
+
for (const option of oneOf) {
|
|
33603
|
+
if (isRecord8(option) && typeof option["const"] === "string") {
|
|
34029
33604
|
normalized.push({
|
|
34030
|
-
description: truncate3(readString4(
|
|
34031
|
-
label: truncate3(readString4(
|
|
34032
|
-
value: truncate3(
|
|
33605
|
+
description: truncate3(readString4(option["description"]), 500),
|
|
33606
|
+
label: truncate3(readString4(option["title"], option["const"]), 255),
|
|
33607
|
+
value: truncate3(option["const"], 500)
|
|
34033
33608
|
});
|
|
34034
33609
|
}
|
|
34035
33610
|
}
|
|
@@ -34045,7 +33620,7 @@ function normalizeElicitationOptions(schema) {
|
|
|
34045
33620
|
return normalized.slice(0, 200);
|
|
34046
33621
|
}
|
|
34047
33622
|
const items = schema["items"];
|
|
34048
|
-
if (!
|
|
33623
|
+
if (!isRecord8(items)) {
|
|
34049
33624
|
return normalized;
|
|
34050
33625
|
}
|
|
34051
33626
|
const anyOf = items["anyOf"];
|
|
@@ -34058,7 +33633,7 @@ function numericString(value) {
|
|
|
34058
33633
|
return typeof value === "number" && Number.isFinite(value) ? value.toString() : "";
|
|
34059
33634
|
}
|
|
34060
33635
|
function normalizeElicitationFields(requestedSchema) {
|
|
34061
|
-
if (!
|
|
33636
|
+
if (!isRecord8(requestedSchema) || !isRecord8(requestedSchema["properties"])) {
|
|
34062
33637
|
return [];
|
|
34063
33638
|
}
|
|
34064
33639
|
const properties2 = requestedSchema["properties"];
|
|
@@ -34068,7 +33643,7 @@ function normalizeElicitationFields(requestedSchema) {
|
|
|
34068
33643
|
);
|
|
34069
33644
|
const normalized = [];
|
|
34070
33645
|
for (const [name, property] of Object.entries(properties2)) {
|
|
34071
|
-
if (!
|
|
33646
|
+
if (!isRecord8(property)) {
|
|
34072
33647
|
continue;
|
|
34073
33648
|
}
|
|
34074
33649
|
const type = elicitationFieldType(property["type"]);
|
|
@@ -34159,7 +33734,7 @@ function validateElicitationContent(encoded, requestedSchema) {
|
|
|
34159
33734
|
"invalid_elicitation_response"
|
|
34160
33735
|
);
|
|
34161
33736
|
}
|
|
34162
|
-
if (!
|
|
33737
|
+
if (!isRecord8(decoded) || !isRecord8(requestedSchema) || !isRecord8(requestedSchema["properties"])) {
|
|
34163
33738
|
throw new AcpExecutionError(
|
|
34164
33739
|
"Elicitation response does not match the requested form",
|
|
34165
33740
|
{},
|
|
@@ -34179,7 +33754,7 @@ function validateElicitationContent(encoded, requestedSchema) {
|
|
|
34179
33754
|
const validated = {};
|
|
34180
33755
|
for (const [name, value] of Object.entries(decoded)) {
|
|
34181
33756
|
const property = properties2[name];
|
|
34182
|
-
if (!
|
|
33757
|
+
if (!isRecord8(property)) {
|
|
34183
33758
|
throw new AcpExecutionError(
|
|
34184
33759
|
`Elicitation field ${name} was not requested`,
|
|
34185
33760
|
{},
|
|
@@ -34216,7 +33791,7 @@ function validateElicitationContent(encoded, requestedSchema) {
|
|
|
34216
33791
|
);
|
|
34217
33792
|
}
|
|
34218
33793
|
const allowed = normalizeElicitationOptions(property);
|
|
34219
|
-
if (allowed.length > 0 && value.some((entry) => !allowed.some((
|
|
33794
|
+
if (allowed.length > 0 && value.some((entry) => !allowed.some((option) => option.value === entry))) {
|
|
34220
33795
|
throw new AcpExecutionError(
|
|
34221
33796
|
`Elicitation field ${name} contains an invalid selection`,
|
|
34222
33797
|
{},
|
|
@@ -34332,6 +33907,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
34332
33907
|
#permissionProfile;
|
|
34333
33908
|
#sessionConfigProtocol;
|
|
34334
33909
|
#store;
|
|
33910
|
+
#emittedToolImages = /* @__PURE__ */ new Set();
|
|
34335
33911
|
#verifiedAgentVersion;
|
|
34336
33912
|
#preSessionUpdateBytes = 0;
|
|
34337
33913
|
#agentName = "";
|
|
@@ -34552,19 +34128,19 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
34552
34128
|
}
|
|
34553
34129
|
};
|
|
34554
34130
|
prepareAgentContent = async (content3) => {
|
|
34555
|
-
if (content3.type === "image" && content3.
|
|
34556
|
-
const raster = readInlineRaster(content3.data, content3.name);
|
|
34557
|
-
if (raster !== null) {
|
|
34558
|
-
return await this.importRaster(raster, AbortSignal.timeout(2e4));
|
|
34559
|
-
}
|
|
34560
|
-
}
|
|
34561
|
-
if (content3.type === "image" && content3.data.length === 0 && content3.uri.length > 0) {
|
|
34131
|
+
if (content3.type === "image" && content3.uri.length > 0) {
|
|
34562
34132
|
const signal = AbortSignal.timeout(2e4);
|
|
34563
34133
|
const raster = await readLocalRaster(content3.uri, signal);
|
|
34564
34134
|
if (raster !== null) {
|
|
34565
34135
|
return await this.importRaster(raster, signal);
|
|
34566
34136
|
}
|
|
34567
34137
|
}
|
|
34138
|
+
if (content3.type === "image" && content3.data.length > 0) {
|
|
34139
|
+
const raster = readInlineRaster(content3.data, content3.name);
|
|
34140
|
+
if (raster !== null) {
|
|
34141
|
+
return await this.importRaster(raster, AbortSignal.timeout(2e4));
|
|
34142
|
+
}
|
|
34143
|
+
}
|
|
34568
34144
|
if (content3.type === "video" && content3.data.length > 0) {
|
|
34569
34145
|
const video = readInlineVideo(content3.data, content3.mimeType, content3.name);
|
|
34570
34146
|
if (video === null) {
|
|
@@ -34585,6 +34161,22 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
34585
34161
|
sessionId: this.#mobiusSessionId
|
|
34586
34162
|
});
|
|
34587
34163
|
};
|
|
34164
|
+
emitToolImages = async (update) => {
|
|
34165
|
+
if (update.status !== "completed") {
|
|
34166
|
+
return;
|
|
34167
|
+
}
|
|
34168
|
+
for (const [index2, item] of (update.content ?? []).entries()) {
|
|
34169
|
+
if (item.type !== "content" || item.content.type !== "image") {
|
|
34170
|
+
continue;
|
|
34171
|
+
}
|
|
34172
|
+
const key = `${update.toolCallId}:${index2.toString()}`;
|
|
34173
|
+
if (this.#emittedToolImages.has(key)) {
|
|
34174
|
+
continue;
|
|
34175
|
+
}
|
|
34176
|
+
this.#emittedToolImages.add(key);
|
|
34177
|
+
await this.emitAgentContent(normalizeContentBlock(item.content), `tool-${key}`);
|
|
34178
|
+
}
|
|
34179
|
+
};
|
|
34588
34180
|
emitRaster = async (raster, messageId, signal) => {
|
|
34589
34181
|
const content3 = await this.importRaster(raster, signal);
|
|
34590
34182
|
await this.#getObserver().onContent({
|
|
@@ -34596,14 +34188,14 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
34596
34188
|
sessionId: this.#mobiusSessionId
|
|
34597
34189
|
});
|
|
34598
34190
|
};
|
|
34599
|
-
importRaster = async (raster,
|
|
34600
|
-
|
|
34601
|
-
|
|
34602
|
-
|
|
34603
|
-
|
|
34604
|
-
|
|
34605
|
-
|
|
34606
|
-
);
|
|
34191
|
+
importRaster = async (raster, _signal) => {
|
|
34192
|
+
if (raster.sourceUri.length > 0) {
|
|
34193
|
+
return {
|
|
34194
|
+
...imageDisplayContent(raster.mimeType, raster.name, "", ""),
|
|
34195
|
+
uri: raster.sourceUri
|
|
34196
|
+
};
|
|
34197
|
+
}
|
|
34198
|
+
return imageDisplayContent(raster.mimeType, raster.name, await raster.base64(), "");
|
|
34607
34199
|
};
|
|
34608
34200
|
importVideo = async (video, signal) => {
|
|
34609
34201
|
const artifactId = await this.#getObserver().importLocalArtifact(this.#mobiusSessionId, video, signal);
|
|
@@ -34890,7 +34482,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
34890
34482
|
};
|
|
34891
34483
|
nativeSessionId = () => this.#nativeSessionId;
|
|
34892
34484
|
configure = async (options) => {
|
|
34893
|
-
const existing = this.#configOptions.find((
|
|
34485
|
+
const existing = this.#configOptions.find((option) => option.id === options.configId);
|
|
34894
34486
|
if (existing === void 0 || existing.type !== options.valueType) {
|
|
34895
34487
|
throw new AcpExecutionError(
|
|
34896
34488
|
"The requested ACP configuration option is unavailable",
|
|
@@ -35087,7 +34679,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
35087
34679
|
"ACP agent exited during steering",
|
|
35088
34680
|
options.signal
|
|
35089
34681
|
);
|
|
35090
|
-
if (!
|
|
34682
|
+
if (!isRecord8(response)) {
|
|
35091
34683
|
throw new AcpExecutionError(
|
|
35092
34684
|
"ACP agent returned an invalid steering response",
|
|
35093
34685
|
{},
|
|
@@ -35202,10 +34794,10 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
35202
34794
|
onPermission = async (request, signal) => {
|
|
35203
34795
|
this.assertNativeSession(request.sessionId);
|
|
35204
34796
|
const interactionId = `permission-${crypto.randomUUID()}`;
|
|
35205
|
-
const options = request.options.slice(0, 20).map((
|
|
35206
|
-
kind:
|
|
35207
|
-
name: truncate3(
|
|
35208
|
-
optionId: truncate3(
|
|
34797
|
+
const options = request.options.slice(0, 20).map((option) => ({
|
|
34798
|
+
kind: option.kind,
|
|
34799
|
+
name: truncate3(option.name, 255),
|
|
34800
|
+
optionId: truncate3(option.optionId, 255)
|
|
35209
34801
|
}));
|
|
35210
34802
|
if (options.length === 0) {
|
|
35211
34803
|
throw new AcpExecutionError(
|
|
@@ -35214,7 +34806,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
35214
34806
|
"invalid_agent_permission_request"
|
|
35215
34807
|
);
|
|
35216
34808
|
}
|
|
35217
|
-
const pending = new PendingPermission(interactionId, new Set(options.map((
|
|
34809
|
+
const pending = new PendingPermission(interactionId, new Set(options.map((option) => option.optionId)));
|
|
35218
34810
|
this.#pendingPermissions.set(interactionId, pending);
|
|
35219
34811
|
const abort = () => {
|
|
35220
34812
|
void this.cancelPermission(interactionId);
|
|
@@ -35383,6 +34975,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
35383
34975
|
}
|
|
35384
34976
|
if (update.sessionUpdate === "tool_call_update") {
|
|
35385
34977
|
await this.#turn.activities.recordToolCallUpdate(update);
|
|
34978
|
+
await this.emitToolImages(update);
|
|
35386
34979
|
return;
|
|
35387
34980
|
}
|
|
35388
34981
|
if (update.sessionUpdate === "plan") {
|
|
@@ -35422,7 +35015,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
35422
35015
|
}
|
|
35423
35016
|
if (update.sessionUpdate === "current_mode_update") {
|
|
35424
35017
|
this.#configOptions = this.#configOptions.map(
|
|
35425
|
-
(
|
|
35018
|
+
(option) => option.category === "mode" ? { ...option, currentValue: update.currentModeId } : option
|
|
35426
35019
|
);
|
|
35427
35020
|
this.#configRevision += 1;
|
|
35428
35021
|
await this.emitConfigUpdate();
|
|
@@ -35955,7 +35548,7 @@ var AcpSessionManager = class {
|
|
|
35955
35548
|
if (desired.id === PERMISSION_MODE_CONFIG_ID) {
|
|
35956
35549
|
continue;
|
|
35957
35550
|
}
|
|
35958
|
-
const current = runtime.prepared().configOptions.find((
|
|
35551
|
+
const current = runtime.prepared().configOptions.find((option) => option.id === desired.id);
|
|
35959
35552
|
if (current === void 0 || current.type !== desired.type) {
|
|
35960
35553
|
continue;
|
|
35961
35554
|
}
|
|
@@ -36061,7 +35654,7 @@ var AcpSessionManager = class {
|
|
|
36061
35654
|
async (runtime) => await runtime.close()
|
|
36062
35655
|
);
|
|
36063
35656
|
/**
|
|
36064
|
-
*
|
|
35657
|
+
* Retained for Agents that expose a separate persisted configuration channel.
|
|
36065
35658
|
* Use inspectAgentSettings for Agent-scoped settings discovery.
|
|
36066
35659
|
*/
|
|
36067
35660
|
inspectSession = async (options, metrics = unmeasuredOperationMetrics) => {
|
|
@@ -36655,7 +36248,6 @@ async function publishAgentCatalog(config2, signal) {
|
|
|
36655
36248
|
agentPath: agent.agentIdentity.requestedPath,
|
|
36656
36249
|
agentVersion: agent.agentVersion,
|
|
36657
36250
|
agentSettingsDiscovery: true,
|
|
36658
|
-
botSessionConfiguration: true,
|
|
36659
36251
|
capabilities: agent.capabilities,
|
|
36660
36252
|
id: agent.id,
|
|
36661
36253
|
label: agent.label,
|
|
@@ -37142,6 +36734,91 @@ var FixedInstallationExecutor = class {
|
|
|
37142
36734
|
};
|
|
37143
36735
|
};
|
|
37144
36736
|
|
|
36737
|
+
// src/artifacts/local-file-streamer.ts
|
|
36738
|
+
import { createReadStream as createReadStream2 } from "node:fs";
|
|
36739
|
+
import { realpath as realpath8, stat as stat7 } from "node:fs/promises";
|
|
36740
|
+
import { basename as basename4, isAbsolute as isAbsolute9, normalize as normalize3 } from "node:path";
|
|
36741
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
36742
|
+
var CHUNK_BYTES = 192 * 1024;
|
|
36743
|
+
function requestedPath(value) {
|
|
36744
|
+
if (value.includes("\0")) {
|
|
36745
|
+
return null;
|
|
36746
|
+
}
|
|
36747
|
+
if (value.startsWith("file:")) {
|
|
36748
|
+
try {
|
|
36749
|
+
const url2 = new URL(value);
|
|
36750
|
+
return url2.protocol === "file:" && url2.host.length === 0 ? fileURLToPath2(url2) : null;
|
|
36751
|
+
} catch {
|
|
36752
|
+
return null;
|
|
36753
|
+
}
|
|
36754
|
+
}
|
|
36755
|
+
return value;
|
|
36756
|
+
}
|
|
36757
|
+
async function resolveFile(value, signal) {
|
|
36758
|
+
const requested = requestedPath(value);
|
|
36759
|
+
if (requested === null || !isAbsolute9(requested) || normalize3(requested) !== requested) {
|
|
36760
|
+
return null;
|
|
36761
|
+
}
|
|
36762
|
+
try {
|
|
36763
|
+
const target = await realpath8(requested);
|
|
36764
|
+
signal.throwIfAborted();
|
|
36765
|
+
return isAbsolute9(target) && normalize3(target) === target ? target : null;
|
|
36766
|
+
} catch {
|
|
36767
|
+
signal.throwIfAborted();
|
|
36768
|
+
return null;
|
|
36769
|
+
}
|
|
36770
|
+
}
|
|
36771
|
+
async function streamLocalFile(command, send2, signal) {
|
|
36772
|
+
const target = await resolveFile(command.path, signal);
|
|
36773
|
+
if (target === null) {
|
|
36774
|
+
throw new Error("The local file is unavailable");
|
|
36775
|
+
}
|
|
36776
|
+
const before = await stat7(target);
|
|
36777
|
+
signal.throwIfAborted();
|
|
36778
|
+
if (!before.isFile() || before.size < 1 || before.size > command.maxBytes) {
|
|
36779
|
+
throw new Error("The local file is too large to read");
|
|
36780
|
+
}
|
|
36781
|
+
const raster = await readLocalRaster(target, signal);
|
|
36782
|
+
send2(
|
|
36783
|
+
encodeFileBeginEvent({
|
|
36784
|
+
byteLength: before.size,
|
|
36785
|
+
kind: FILE_BEGIN_KIND,
|
|
36786
|
+
mediaType: raster?.mimeType ?? "application/octet-stream",
|
|
36787
|
+
modifiedAt: before.mtime.toISOString(),
|
|
36788
|
+
name: basename4(target) || "file",
|
|
36789
|
+
requestId: command.requestId,
|
|
36790
|
+
sessionId: command.sessionId
|
|
36791
|
+
})
|
|
36792
|
+
);
|
|
36793
|
+
let sequence = 0;
|
|
36794
|
+
const stream = createReadStream2(target, { highWaterMark: CHUNK_BYTES, signal });
|
|
36795
|
+
for await (const value of stream) {
|
|
36796
|
+
const bytes = value instanceof Uint8Array ? value : new Uint8Array(value);
|
|
36797
|
+
send2(
|
|
36798
|
+
encodeFileChunkEvent({
|
|
36799
|
+
data: Buffer.from(bytes).toString("base64"),
|
|
36800
|
+
kind: FILE_CHUNK_KIND,
|
|
36801
|
+
requestId: command.requestId,
|
|
36802
|
+
sequence,
|
|
36803
|
+
sessionId: command.sessionId
|
|
36804
|
+
})
|
|
36805
|
+
);
|
|
36806
|
+
sequence += 1;
|
|
36807
|
+
}
|
|
36808
|
+
const after = await stat7(target);
|
|
36809
|
+
signal.throwIfAborted();
|
|
36810
|
+
if (after.size !== before.size || after.mtimeMs !== before.mtimeMs) {
|
|
36811
|
+
throw new Error("The local file changed during transfer");
|
|
36812
|
+
}
|
|
36813
|
+
send2(
|
|
36814
|
+
encodeFileEndEvent({
|
|
36815
|
+
kind: FILE_END_KIND,
|
|
36816
|
+
requestId: command.requestId,
|
|
36817
|
+
sessionId: command.sessionId
|
|
36818
|
+
})
|
|
36819
|
+
);
|
|
36820
|
+
}
|
|
36821
|
+
|
|
37145
36822
|
// src/artifacts/runtime-artifact-uploader.ts
|
|
37146
36823
|
import { createHash as createHash2 } from "node:crypto";
|
|
37147
36824
|
|
|
@@ -37168,15 +36845,15 @@ var MobiusValidationError = class extends MobiusError {
|
|
|
37168
36845
|
};
|
|
37169
36846
|
|
|
37170
36847
|
// ../mobius-sdk/src/resources.ts
|
|
37171
|
-
var
|
|
36848
|
+
var IDENTIFIER_PATTERN5 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
37172
36849
|
function invalidResponse(message) {
|
|
37173
36850
|
return new MobiusProtocolError(message);
|
|
37174
36851
|
}
|
|
37175
|
-
function
|
|
36852
|
+
function isRecord9(value) {
|
|
37176
36853
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
37177
36854
|
}
|
|
37178
36855
|
function record3(value, name) {
|
|
37179
|
-
if (!
|
|
36856
|
+
if (!isRecord9(value)) {
|
|
37180
36857
|
throw invalidResponse(`The service returned an invalid ${name}`);
|
|
37181
36858
|
}
|
|
37182
36859
|
return value;
|
|
@@ -37190,7 +36867,7 @@ function stringField(value, field, maximumLength = 85e5) {
|
|
|
37190
36867
|
}
|
|
37191
36868
|
function identifierField(value, field) {
|
|
37192
36869
|
const candidate = stringField(value, field, 128);
|
|
37193
|
-
if (!
|
|
36870
|
+
if (!IDENTIFIER_PATTERN5.test(candidate)) {
|
|
37194
36871
|
throw invalidResponse(`The service returned an invalid ${field}`);
|
|
37195
36872
|
}
|
|
37196
36873
|
return candidate;
|
|
@@ -37537,9 +37214,9 @@ var LocalAuthorizationError = class extends Error {
|
|
|
37537
37214
|
};
|
|
37538
37215
|
|
|
37539
37216
|
// src/authorization/workspace-directory.ts
|
|
37540
|
-
import { readdir as readdir2, realpath as
|
|
37217
|
+
import { readdir as readdir2, realpath as realpath9, stat as stat8 } from "node:fs/promises";
|
|
37541
37218
|
import { homedir as homedir2 } from "node:os";
|
|
37542
|
-
import { basename as
|
|
37219
|
+
import { basename as basename5, dirname as dirname5, isAbsolute as isAbsolute10, join as join16, normalize as normalize4, relative as relative4 } from "node:path";
|
|
37543
37220
|
var WorkspaceDirectoryListing = class {
|
|
37544
37221
|
directoryId;
|
|
37545
37222
|
directoryLabel;
|
|
@@ -37565,7 +37242,7 @@ function decodePath(value, prefix) {
|
|
|
37565
37242
|
throw new LocalAuthorizationError("The directory identifier is invalid");
|
|
37566
37243
|
}
|
|
37567
37244
|
const decoded = Buffer.from(encoded, "base64url").toString("utf8");
|
|
37568
|
-
if (Buffer.from(decoded, "utf8").toString("base64url") !== encoded || decoded.includes("\0") ||
|
|
37245
|
+
if (Buffer.from(decoded, "utf8").toString("base64url") !== encoded || decoded.includes("\0") || normalize4(decoded) !== decoded) {
|
|
37569
37246
|
throw new LocalAuthorizationError("The directory identifier is invalid");
|
|
37570
37247
|
}
|
|
37571
37248
|
return decoded;
|
|
@@ -37591,7 +37268,7 @@ var WorkspaceDirectoryService = class {
|
|
|
37591
37268
|
}
|
|
37592
37269
|
if (id.startsWith("path-")) {
|
|
37593
37270
|
const path2 = decodePath(id, "path-");
|
|
37594
|
-
if (
|
|
37271
|
+
if (isAbsolute10(path2)) {
|
|
37595
37272
|
return path2;
|
|
37596
37273
|
}
|
|
37597
37274
|
}
|
|
@@ -37599,15 +37276,15 @@ var WorkspaceDirectoryService = class {
|
|
|
37599
37276
|
};
|
|
37600
37277
|
resolvePath = async (requested, signal) => {
|
|
37601
37278
|
signal.throwIfAborted();
|
|
37602
|
-
if (!
|
|
37279
|
+
if (!isAbsolute10(requested) || requested.includes("\0") || normalize4(requested) !== requested) {
|
|
37603
37280
|
throw new LocalAuthorizationError("The local directory path is invalid");
|
|
37604
37281
|
}
|
|
37605
37282
|
try {
|
|
37606
|
-
const target = await
|
|
37283
|
+
const target = await realpath9(requested);
|
|
37607
37284
|
signal.throwIfAborted();
|
|
37608
|
-
const metadata = await
|
|
37285
|
+
const metadata = await stat8(target);
|
|
37609
37286
|
signal.throwIfAborted();
|
|
37610
|
-
if (!
|
|
37287
|
+
if (!isAbsolute10(target) || normalize4(target) !== target || !metadata.isDirectory()) {
|
|
37611
37288
|
throw new LocalAuthorizationError("The selected location is not a directory");
|
|
37612
37289
|
}
|
|
37613
37290
|
return target;
|
|
@@ -37623,15 +37300,15 @@ var WorkspaceDirectoryService = class {
|
|
|
37623
37300
|
};
|
|
37624
37301
|
label = (path2) => {
|
|
37625
37302
|
const suffix = relative4(homedir2(), path2);
|
|
37626
|
-
return suffix === "" ? "~" : !
|
|
37303
|
+
return suffix === "" ? "~" : !isAbsolute10(suffix) && suffix !== ".." && !suffix.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) ? `~/${suffix.replaceAll("\\", "/")}` : path2;
|
|
37627
37304
|
};
|
|
37628
|
-
identify = async (bindingId,
|
|
37305
|
+
identify = async (bindingId, requestedPath2, signal) => {
|
|
37629
37306
|
this.authorizeMachine(bindingId);
|
|
37630
|
-
const path2 = await this.resolvePath(
|
|
37307
|
+
const path2 = await this.resolvePath(requestedPath2, signal);
|
|
37631
37308
|
return {
|
|
37632
37309
|
path: path2,
|
|
37633
37310
|
directoryId: encodePath(path2),
|
|
37634
|
-
name:
|
|
37311
|
+
name: basename5(path2) || path2,
|
|
37635
37312
|
label: this.label(path2)
|
|
37636
37313
|
};
|
|
37637
37314
|
};
|
|
@@ -37687,436 +37364,9 @@ var WorkspaceDirectoryService = class {
|
|
|
37687
37364
|
};
|
|
37688
37365
|
};
|
|
37689
37366
|
|
|
37690
|
-
// src/bots/local-bot-execution-authorizer.ts
|
|
37691
|
-
var LocalBotAuthorizationError = class extends Error {
|
|
37692
|
-
code;
|
|
37693
|
-
constructor(code, message, options = {}) {
|
|
37694
|
-
super(message, options);
|
|
37695
|
-
this.code = code;
|
|
37696
|
-
this.name = "LocalBotAuthorizationError";
|
|
37697
|
-
}
|
|
37698
|
-
};
|
|
37699
|
-
var AuthorizedLocalBotExecution = class {
|
|
37700
|
-
agent;
|
|
37701
|
-
behaviorDigest;
|
|
37702
|
-
behaviorRevisionId;
|
|
37703
|
-
bindingId;
|
|
37704
|
-
bindingRevision;
|
|
37705
|
-
botId;
|
|
37706
|
-
executionConfiguration;
|
|
37707
|
-
workspacePath;
|
|
37708
|
-
workspaceRef;
|
|
37709
|
-
constructor(command, agent, workspacePath) {
|
|
37710
|
-
this.agent = agent;
|
|
37711
|
-
this.behaviorDigest = command.behaviorDigest;
|
|
37712
|
-
this.behaviorRevisionId = command.behaviorRevisionId;
|
|
37713
|
-
this.bindingId = command.bindingId;
|
|
37714
|
-
this.bindingRevision = command.bindingRevision;
|
|
37715
|
-
this.botId = command.botId;
|
|
37716
|
-
this.executionConfiguration = command.executionConfiguration;
|
|
37717
|
-
this.workspacePath = workspacePath;
|
|
37718
|
-
this.workspaceRef = command.directoryId;
|
|
37719
|
-
}
|
|
37720
|
-
};
|
|
37721
|
-
var LocalBotExecutionAuthorizer = class {
|
|
37722
|
-
authorize = async (command, catalog, directories, bindingAuthorityId, signal) => {
|
|
37723
|
-
signal.throwIfAborted();
|
|
37724
|
-
let agent;
|
|
37725
|
-
try {
|
|
37726
|
-
agent = catalog.find(command.agentId).withPermissionMode(command.executionConfiguration.permissionMode);
|
|
37727
|
-
} catch (cause) {
|
|
37728
|
-
if (cause instanceof AgentPermissionConfigurationError) {
|
|
37729
|
-
throw new LocalBotAuthorizationError("binding_incompatible", cause.message, { cause });
|
|
37730
|
-
}
|
|
37731
|
-
throw cause;
|
|
37732
|
-
}
|
|
37733
|
-
const [adapterUnchanged, agentUnchanged] = await Promise.all([
|
|
37734
|
-
revalidateExecutable(agent.adapterIdentity),
|
|
37735
|
-
revalidateExecutable(agent.agentIdentity)
|
|
37736
|
-
]);
|
|
37737
|
-
signal.throwIfAborted();
|
|
37738
|
-
if (!adapterUnchanged || !agentUnchanged) {
|
|
37739
|
-
throw new LocalBotAuthorizationError(
|
|
37740
|
-
"binding_incompatible",
|
|
37741
|
-
"The local Agent executable changed while the Runtime is active; restart the Runtime"
|
|
37742
|
-
);
|
|
37743
|
-
}
|
|
37744
|
-
if (command.behaviorInstructions.length > 0 && !agent.capabilities.embeddedContextPrompt) {
|
|
37745
|
-
throw new LocalBotAuthorizationError(
|
|
37746
|
-
"binding_incompatible",
|
|
37747
|
-
"The local Agent cannot apply the Bot behavior"
|
|
37748
|
-
);
|
|
37749
|
-
}
|
|
37750
|
-
const workspacePath = await directories.resolve(bindingAuthorityId, command.directoryId, signal);
|
|
37751
|
-
signal.throwIfAborted();
|
|
37752
|
-
return new AuthorizedLocalBotExecution(command, agent, workspacePath);
|
|
37753
|
-
};
|
|
37754
|
-
};
|
|
37755
|
-
|
|
37756
|
-
// src/bots/bot-context-applicator.ts
|
|
37757
|
-
var AppliedBotContext = class {
|
|
37758
|
-
resources;
|
|
37759
|
-
constructor(resources) {
|
|
37760
|
-
this.resources = Object.freeze([...resources]);
|
|
37761
|
-
}
|
|
37762
|
-
};
|
|
37763
|
-
var EmbeddedBotContextApplicator = class {
|
|
37764
|
-
apply = async (command, execution, resources, signal) => {
|
|
37765
|
-
signal.throwIfAborted();
|
|
37766
|
-
if (execution.botId !== command.botId || execution.behaviorRevisionId !== command.behaviorRevisionId || execution.behaviorDigest !== command.behaviorDigest) {
|
|
37767
|
-
throw new LocalBotAuthorizationError(
|
|
37768
|
-
"binding_incompatible",
|
|
37769
|
-
"The Bot behavior does not match the execution target"
|
|
37770
|
-
);
|
|
37771
|
-
}
|
|
37772
|
-
if (command.behaviorInstructions.length === 0) {
|
|
37773
|
-
return new AppliedBotContext(resources);
|
|
37774
|
-
}
|
|
37775
|
-
if (!execution.agent.capabilities.embeddedContextPrompt) {
|
|
37776
|
-
throw new LocalBotAuthorizationError(
|
|
37777
|
-
"binding_incompatible",
|
|
37778
|
-
"The local Agent cannot enforce the Bot behavior context"
|
|
37779
|
-
);
|
|
37780
|
-
}
|
|
37781
|
-
const trustedContext = {
|
|
37782
|
-
mimeType: "text/markdown",
|
|
37783
|
-
name: "Mobius Bot behavior",
|
|
37784
|
-
text: command.behaviorInstructions,
|
|
37785
|
-
type: "embedded",
|
|
37786
|
-
uri: `mobius://bots/${encodeURIComponent(command.botId)}/behavior-revisions/${encodeURIComponent(command.behaviorRevisionId)}?sha256=${command.behaviorDigest}`
|
|
37787
|
-
};
|
|
37788
|
-
return new AppliedBotContext([trustedContext, ...resources]);
|
|
37789
|
-
};
|
|
37790
|
-
};
|
|
37791
|
-
|
|
37792
|
-
// src/bots/bot-execution-context.ts
|
|
37793
|
-
import { randomBytes } from "node:crypto";
|
|
37794
|
-
var ActiveBotExecutionContext = class {
|
|
37795
|
-
command;
|
|
37796
|
-
contextHandle;
|
|
37797
|
-
constructor(contextHandle, command) {
|
|
37798
|
-
this.contextHandle = contextHandle;
|
|
37799
|
-
this.command = command;
|
|
37800
|
-
}
|
|
37801
|
-
resolveTarget = (target) => {
|
|
37802
|
-
if (target === "current") {
|
|
37803
|
-
if (!(this.command.replyRoute instanceof BotConnectionReplyRoute)) {
|
|
37804
|
-
throw new LocalBotAuthorizationError(
|
|
37805
|
-
"delivery_target_not_allowed",
|
|
37806
|
-
"This Bot conversation has no external reply target"
|
|
37807
|
-
);
|
|
37808
|
-
}
|
|
37809
|
-
return this.command.replyRoute.deliveryTargetId;
|
|
37810
|
-
}
|
|
37811
|
-
const resolved = this.command.allowedDeliveryTargets.find((candidate) => candidate.alias === target);
|
|
37812
|
-
if (resolved === void 0) {
|
|
37813
|
-
throw new LocalBotAuthorizationError(
|
|
37814
|
-
"delivery_target_not_allowed",
|
|
37815
|
-
"The named Bot delivery target is not approved"
|
|
37816
|
-
);
|
|
37817
|
-
}
|
|
37818
|
-
return resolved.deliveryTargetId;
|
|
37819
|
-
};
|
|
37820
|
-
};
|
|
37821
|
-
var BotExecutionContextLease = class {
|
|
37822
|
-
context;
|
|
37823
|
-
#release;
|
|
37824
|
-
#released = false;
|
|
37825
|
-
constructor(context, release) {
|
|
37826
|
-
this.context = context;
|
|
37827
|
-
this.#release = release;
|
|
37828
|
-
}
|
|
37829
|
-
release = () => {
|
|
37830
|
-
if (this.#released) {
|
|
37831
|
-
return;
|
|
37832
|
-
}
|
|
37833
|
-
this.#released = true;
|
|
37834
|
-
this.#release();
|
|
37835
|
-
};
|
|
37836
|
-
};
|
|
37837
|
-
var BotExecutionContextRegistry = class {
|
|
37838
|
-
#activeByHandle = /* @__PURE__ */ new Map();
|
|
37839
|
-
#handlesBySession = /* @__PURE__ */ new Map();
|
|
37840
|
-
#inactiveHandles = /* @__PURE__ */ new Set();
|
|
37841
|
-
activate = (command) => {
|
|
37842
|
-
let handle = this.#handlesBySession.get(command.sessionId);
|
|
37843
|
-
if (handle === void 0) {
|
|
37844
|
-
handle = `ctx_${Buffer.from(randomBytes(32)).toString("base64url")}`;
|
|
37845
|
-
this.#handlesBySession.set(command.sessionId, handle);
|
|
37846
|
-
}
|
|
37847
|
-
if (this.#activeByHandle.has(handle)) {
|
|
37848
|
-
throw new LocalBotAuthorizationError("session_busy", "The Bot execution context is already active");
|
|
37849
|
-
}
|
|
37850
|
-
const context = new ActiveBotExecutionContext(handle, command);
|
|
37851
|
-
this.#inactiveHandles.delete(handle);
|
|
37852
|
-
this.#activeByHandle.set(handle, context);
|
|
37853
|
-
return new BotExecutionContextLease(context, () => {
|
|
37854
|
-
if (this.#activeByHandle.get(handle) === context) {
|
|
37855
|
-
this.#activeByHandle.delete(handle);
|
|
37856
|
-
this.#inactiveHandles.add(handle);
|
|
37857
|
-
}
|
|
37858
|
-
});
|
|
37859
|
-
};
|
|
37860
|
-
read = (handle) => {
|
|
37861
|
-
const context = this.#activeByHandle.get(handle);
|
|
37862
|
-
if (context === void 0) {
|
|
37863
|
-
if (this.#inactiveHandles.has(handle)) {
|
|
37864
|
-
throw new LocalBotAuthorizationError(
|
|
37865
|
-
"execution_capability_expired",
|
|
37866
|
-
"The Bot execution capability has expired"
|
|
37867
|
-
);
|
|
37868
|
-
}
|
|
37869
|
-
throw new LocalBotAuthorizationError(
|
|
37870
|
-
"execution_context_required",
|
|
37871
|
-
"An active Bot execution context is required"
|
|
37872
|
-
);
|
|
37873
|
-
}
|
|
37874
|
-
return context;
|
|
37875
|
-
};
|
|
37876
|
-
};
|
|
37877
|
-
|
|
37878
|
-
// src/bots/bot-outbound-ipc.ts
|
|
37879
|
-
import { chmod as chmod2, mkdir as mkdir4, unlink } from "node:fs/promises";
|
|
37880
|
-
import { createServer } from "node:net";
|
|
37881
|
-
import { dirname as dirname6, isAbsolute as isAbsolute10 } from "node:path";
|
|
37882
|
-
import { fetch as fetch5 } from "undici";
|
|
37883
|
-
var BOT_IPC_REQUEST_LIMIT = 32 * 1024;
|
|
37884
|
-
var BOT_IPC_TIMEOUT_MILLISECONDS2 = 2e4;
|
|
37885
|
-
var BOT_RELAY_TIMEOUT_MILLISECONDS = 2e4;
|
|
37886
|
-
var IDENTIFIER_PATTERN7 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
37887
|
-
var WINDOWS_NAMED_PIPE_PREFIX = "\\\\.\\pipe\\";
|
|
37888
|
-
var BotOutboundIpcRequest = class {
|
|
37889
|
-
contextHandle;
|
|
37890
|
-
idempotencyKey;
|
|
37891
|
-
target;
|
|
37892
|
-
text;
|
|
37893
|
-
constructor(contextHandle, idempotencyKey, target, text3) {
|
|
37894
|
-
this.contextHandle = contextHandle;
|
|
37895
|
-
this.idempotencyKey = idempotencyKey;
|
|
37896
|
-
this.target = target;
|
|
37897
|
-
this.text = text3;
|
|
37898
|
-
}
|
|
37899
|
-
};
|
|
37900
|
-
function isRecord12(value) {
|
|
37901
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
37902
|
-
}
|
|
37903
|
-
function decodeRequest(encoded) {
|
|
37904
|
-
let value;
|
|
37905
|
-
try {
|
|
37906
|
-
value = JSON.parse(encoded);
|
|
37907
|
-
} catch (cause) {
|
|
37908
|
-
throw new LocalBotAuthorizationError("invalid_request", "The local Bot request is invalid", { cause });
|
|
37909
|
-
}
|
|
37910
|
-
if (!isRecord12(value)) {
|
|
37911
|
-
throw new LocalBotAuthorizationError("invalid_request", "The local Bot request is invalid");
|
|
37912
|
-
}
|
|
37913
|
-
const keys = Object.keys(value);
|
|
37914
|
-
if (keys.length !== 4 || !keys.every((key) => ["contextHandle", "idempotencyKey", "target", "text"].includes(key))) {
|
|
37915
|
-
throw new LocalBotAuthorizationError("invalid_request", "The local Bot request fields are invalid");
|
|
37916
|
-
}
|
|
37917
|
-
const contextHandle = value["contextHandle"];
|
|
37918
|
-
const idempotencyKey = value["idempotencyKey"];
|
|
37919
|
-
const target = value["target"];
|
|
37920
|
-
const text3 = value["text"];
|
|
37921
|
-
if (typeof contextHandle !== "string" || !/^ctx_[a-zA-Z0-9_-]{43}$/.test(contextHandle) || typeof idempotencyKey !== "string" || !IDENTIFIER_PATTERN7.test(idempotencyKey) || typeof target !== "string" || !IDENTIFIER_PATTERN7.test(target) || typeof text3 !== "string" || text3.trim().length === 0 || text3.length > 1e4) {
|
|
37922
|
-
throw new LocalBotAuthorizationError("invalid_request", "The local Bot request is invalid");
|
|
37923
|
-
}
|
|
37924
|
-
return new BotOutboundIpcRequest(contextHandle, idempotencyKey, target, text3);
|
|
37925
|
-
}
|
|
37926
|
-
function relayEndpoint(relayUrl, context, target) {
|
|
37927
|
-
const endpoint = new URL(relayUrl);
|
|
37928
|
-
if (endpoint.protocol !== "ws:" && endpoint.protocol !== "wss:") {
|
|
37929
|
-
throw new LocalBotAuthorizationError("bot_service_unavailable", "The Mobius Relay URL is invalid");
|
|
37930
|
-
}
|
|
37931
|
-
endpoint.protocol = endpoint.protocol === "wss:" ? "https:" : "http:";
|
|
37932
|
-
endpoint.search = "";
|
|
37933
|
-
const execution = encodeURIComponent(context.command.executionId);
|
|
37934
|
-
if (target === "current") {
|
|
37935
|
-
context.resolveTarget(target);
|
|
37936
|
-
endpoint.pathname = `${MOBIUS_API_PREFIX}/v1/bot-executions/${execution}/reply-messages`;
|
|
37937
|
-
return endpoint;
|
|
37938
|
-
}
|
|
37939
|
-
const deliveryTargetId = context.resolveTarget(target);
|
|
37940
|
-
endpoint.pathname = `${MOBIUS_API_PREFIX}/v1/bot-executions/${execution}/delivery-targets/${encodeURIComponent(deliveryTargetId)}/messages`;
|
|
37941
|
-
return endpoint;
|
|
37942
|
-
}
|
|
37943
|
-
function daemonToken(relayUrl) {
|
|
37944
|
-
const token = relayUrl.searchParams.get("token") ?? "";
|
|
37945
|
-
if (!/^[a-zA-Z0-9_-]{32,256}$/.test(token)) {
|
|
37946
|
-
throw new LocalBotAuthorizationError("bot_service_unavailable", "The Runtime credential is unavailable");
|
|
37947
|
-
}
|
|
37948
|
-
return token;
|
|
37949
|
-
}
|
|
37950
|
-
async function decodeRelayResponse(response) {
|
|
37951
|
-
const encoded = await response.text();
|
|
37952
|
-
let value;
|
|
37953
|
-
try {
|
|
37954
|
-
value = JSON.parse(encoded);
|
|
37955
|
-
} catch (cause) {
|
|
37956
|
-
throw new LocalBotAuthorizationError("bot_service_unavailable", "The Mobius Relay returned invalid data", {
|
|
37957
|
-
cause
|
|
37958
|
-
});
|
|
37959
|
-
}
|
|
37960
|
-
if (response.status === 202 && isRecord12(value) && typeof value["outboundMessageId"] === "string") {
|
|
37961
|
-
return value["outboundMessageId"];
|
|
37962
|
-
}
|
|
37963
|
-
if (isRecord12(value) && isRecord12(value["error"])) {
|
|
37964
|
-
const error62 = value["error"];
|
|
37965
|
-
if (typeof error62["code"] === "string" && typeof error62["message"] === "string") {
|
|
37966
|
-
throw new LocalBotAuthorizationError(error62["code"], error62["message"]);
|
|
37967
|
-
}
|
|
37968
|
-
}
|
|
37969
|
-
throw new LocalBotAuthorizationError("bot_service_unavailable", "The Mobius Relay rejected the Bot action");
|
|
37970
|
-
}
|
|
37971
|
-
var BotOutboundIpcServer = class {
|
|
37972
|
-
#registry;
|
|
37973
|
-
#relayUrl;
|
|
37974
|
-
#server;
|
|
37975
|
-
#socketPath;
|
|
37976
|
-
#usesFilesystemSocket;
|
|
37977
|
-
constructor(socketPath, relayUrl, registry2) {
|
|
37978
|
-
const usesFilesystemSocket = !socketPath.startsWith(WINDOWS_NAMED_PIPE_PREFIX);
|
|
37979
|
-
if (usesFilesystemSocket && !isAbsolute10(socketPath)) {
|
|
37980
|
-
throw new Error("The Bot IPC path must be absolute");
|
|
37981
|
-
}
|
|
37982
|
-
this.#registry = registry2;
|
|
37983
|
-
this.#relayUrl = new URL(relayUrl);
|
|
37984
|
-
this.#server = createServer({ allowHalfOpen: true }, (socket) => this.accept(socket));
|
|
37985
|
-
this.#socketPath = socketPath;
|
|
37986
|
-
this.#usesFilesystemSocket = usesFilesystemSocket;
|
|
37987
|
-
}
|
|
37988
|
-
get socketPath() {
|
|
37989
|
-
return this.#socketPath;
|
|
37990
|
-
}
|
|
37991
|
-
listen = async (signal) => {
|
|
37992
|
-
signal.throwIfAborted();
|
|
37993
|
-
if (this.#usesFilesystemSocket) {
|
|
37994
|
-
await mkdir4(dirname6(this.#socketPath), { mode: 448, recursive: true });
|
|
37995
|
-
await unlink(this.#socketPath).catch((error62) => {
|
|
37996
|
-
if (!isRecord12(error62) || error62["code"] !== "ENOENT") {
|
|
37997
|
-
throw error62;
|
|
37998
|
-
}
|
|
37999
|
-
});
|
|
38000
|
-
}
|
|
38001
|
-
await new Promise((resolve5, reject) => {
|
|
38002
|
-
const fail = (error62) => reject(error62);
|
|
38003
|
-
this.#server.once("error", fail);
|
|
38004
|
-
this.#server.listen(this.#socketPath, () => {
|
|
38005
|
-
this.#server.removeListener("error", fail);
|
|
38006
|
-
resolve5();
|
|
38007
|
-
});
|
|
38008
|
-
});
|
|
38009
|
-
if (this.#usesFilesystemSocket) {
|
|
38010
|
-
await chmod2(this.#socketPath, 384);
|
|
38011
|
-
}
|
|
38012
|
-
signal.addEventListener("abort", this.abort, { once: true });
|
|
38013
|
-
if (signal.aborted) {
|
|
38014
|
-
this.abort();
|
|
38015
|
-
}
|
|
38016
|
-
};
|
|
38017
|
-
close = async () => {
|
|
38018
|
-
if (this.#server.listening) {
|
|
38019
|
-
await new Promise((resolve5, reject) => {
|
|
38020
|
-
this.#server.close((error62) => {
|
|
38021
|
-
if (error62 === void 0) {
|
|
38022
|
-
resolve5();
|
|
38023
|
-
return;
|
|
38024
|
-
}
|
|
38025
|
-
reject(error62);
|
|
38026
|
-
});
|
|
38027
|
-
});
|
|
38028
|
-
}
|
|
38029
|
-
if (this.#usesFilesystemSocket) {
|
|
38030
|
-
await unlink(this.#socketPath).catch((error62) => {
|
|
38031
|
-
if (!isRecord12(error62) || error62["code"] !== "ENOENT") {
|
|
38032
|
-
throw error62;
|
|
38033
|
-
}
|
|
38034
|
-
});
|
|
38035
|
-
}
|
|
38036
|
-
};
|
|
38037
|
-
#abort = () => {
|
|
38038
|
-
this.#server.close();
|
|
38039
|
-
};
|
|
38040
|
-
abort = () => this.#abort();
|
|
38041
|
-
accept = (socket) => {
|
|
38042
|
-
const chunks = [];
|
|
38043
|
-
let length = 0;
|
|
38044
|
-
let rejected = false;
|
|
38045
|
-
const controller = new AbortController();
|
|
38046
|
-
socket.setTimeout(BOT_IPC_TIMEOUT_MILLISECONDS2, () => {
|
|
38047
|
-
controller.abort(new Error("Bot IPC request timed out"));
|
|
38048
|
-
socket.destroy();
|
|
38049
|
-
});
|
|
38050
|
-
socket.on("data", (chunk) => {
|
|
38051
|
-
length += chunk.byteLength;
|
|
38052
|
-
if (length > BOT_IPC_REQUEST_LIMIT) {
|
|
38053
|
-
rejected = true;
|
|
38054
|
-
controller.abort(new Error("Bot IPC request is too large"));
|
|
38055
|
-
socket.end(
|
|
38056
|
-
JSON.stringify({
|
|
38057
|
-
error: { code: "invalid_request", message: "The local Bot request is too large" },
|
|
38058
|
-
ok: false
|
|
38059
|
-
})
|
|
38060
|
-
);
|
|
38061
|
-
return;
|
|
38062
|
-
}
|
|
38063
|
-
chunks.push(chunk);
|
|
38064
|
-
});
|
|
38065
|
-
socket.once("error", () => controller.abort());
|
|
38066
|
-
socket.once("close", () => controller.abort());
|
|
38067
|
-
socket.once("end", () => {
|
|
38068
|
-
if (rejected) {
|
|
38069
|
-
return;
|
|
38070
|
-
}
|
|
38071
|
-
void this.handle(Buffer.concat(chunks).toString("utf8").trim(), controller.signal).then(
|
|
38072
|
-
(outboundMessageId) => {
|
|
38073
|
-
if (!socket.destroyed) {
|
|
38074
|
-
socket.end(JSON.stringify({ ok: true, outboundMessageId }));
|
|
38075
|
-
}
|
|
38076
|
-
},
|
|
38077
|
-
(error62) => {
|
|
38078
|
-
if (socket.destroyed) {
|
|
38079
|
-
return;
|
|
38080
|
-
}
|
|
38081
|
-
const code = error62 instanceof LocalBotAuthorizationError ? error62.code : "bot_service_unavailable";
|
|
38082
|
-
const message = error62 instanceof LocalBotAuthorizationError ? error62.message : "The local Bot action could not be completed";
|
|
38083
|
-
socket.end(JSON.stringify({ error: { code, message }, ok: false }));
|
|
38084
|
-
}
|
|
38085
|
-
);
|
|
38086
|
-
});
|
|
38087
|
-
};
|
|
38088
|
-
handle = async (encoded, signal) => {
|
|
38089
|
-
const request = decodeRequest(encoded);
|
|
38090
|
-
const context = this.#registry.read(request.contextHandle);
|
|
38091
|
-
const timeout = AbortSignal.timeout(BOT_RELAY_TIMEOUT_MILLISECONDS);
|
|
38092
|
-
const requestSignal = AbortSignal.any([signal, timeout]);
|
|
38093
|
-
let response;
|
|
38094
|
-
try {
|
|
38095
|
-
response = await fetch5(relayEndpoint(this.#relayUrl, context, request.target), {
|
|
38096
|
-
body: JSON.stringify({ idempotencyKey: request.idempotencyKey, text: request.text }),
|
|
38097
|
-
headers: {
|
|
38098
|
-
authorization: `Bearer ${daemonToken(this.#relayUrl)}`,
|
|
38099
|
-
"content-type": "application/json",
|
|
38100
|
-
"x-mobius-bot-execution-capability": context.command.executionCapabilitySecret
|
|
38101
|
-
},
|
|
38102
|
-
method: "POST",
|
|
38103
|
-
signal: requestSignal
|
|
38104
|
-
});
|
|
38105
|
-
} catch (cause) {
|
|
38106
|
-
signal.throwIfAborted();
|
|
38107
|
-
throw new LocalBotAuthorizationError(
|
|
38108
|
-
timeout.aborted ? "bot_service_timeout" : "bot_service_unavailable",
|
|
38109
|
-
timeout.aborted ? "The Mobius Bot action timed out" : "The Mobius Relay is unavailable",
|
|
38110
|
-
{ cause }
|
|
38111
|
-
);
|
|
38112
|
-
}
|
|
38113
|
-
return await decodeRelayResponse(response);
|
|
38114
|
-
};
|
|
38115
|
-
};
|
|
38116
|
-
|
|
38117
37367
|
// src/native-sessions/service.ts
|
|
38118
|
-
import { randomUUID as
|
|
38119
|
-
import { basename as
|
|
37368
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
37369
|
+
import { basename as basename6 } from "node:path";
|
|
38120
37370
|
|
|
38121
37371
|
// src/native-sessions/codex-history.ts
|
|
38122
37372
|
import { spawn as spawn4 } from "node:child_process";
|
|
@@ -38410,7 +37660,7 @@ var NativeSessionService = class {
|
|
|
38410
37660
|
if (authorized === null) {
|
|
38411
37661
|
return null;
|
|
38412
37662
|
}
|
|
38413
|
-
const entryId =
|
|
37663
|
+
const entryId = randomUUID2();
|
|
38414
37664
|
if (this.#entries.size >= 5e3) {
|
|
38415
37665
|
this.#entries.clear();
|
|
38416
37666
|
}
|
|
@@ -38464,7 +37714,7 @@ var NativeSessionService = class {
|
|
|
38464
37714
|
"invalid_native_session_response"
|
|
38465
37715
|
);
|
|
38466
37716
|
}
|
|
38467
|
-
nextCursor =
|
|
37717
|
+
nextCursor = randomUUID2();
|
|
38468
37718
|
if (this.#cursors.size >= 500) {
|
|
38469
37719
|
this.#cursors.clear();
|
|
38470
37720
|
}
|
|
@@ -38625,7 +37875,7 @@ var NativeSessionService = class {
|
|
|
38625
37875
|
}
|
|
38626
37876
|
resolvedPaths.add(path2);
|
|
38627
37877
|
additionalDirectories.push(path2);
|
|
38628
|
-
additionalEntries.push({ directoryId: directoryId2, name:
|
|
37878
|
+
additionalEntries.push({ directoryId: directoryId2, name: basename6(path2) });
|
|
38629
37879
|
}
|
|
38630
37880
|
const listing = await this.#directories.list(this.#config.bindingId, command.directoryId, signal);
|
|
38631
37881
|
const opened = await this.#sessions.forkSessionAtTurn(
|
|
@@ -38783,12 +38033,12 @@ var NativeSessionService = class {
|
|
|
38783
38033
|
|
|
38784
38034
|
// src/prompt-artifact-resolver.ts
|
|
38785
38035
|
import { createHash as createHash3 } from "node:crypto";
|
|
38786
|
-
import { fetch as
|
|
38036
|
+
import { fetch as fetch5 } from "undici";
|
|
38787
38037
|
var ARTIFACT_SCHEME = "mobius-artifact:";
|
|
38788
38038
|
var ARTIFACT_DOWNLOAD_TIMEOUT_MILLISECONDS = 2e4;
|
|
38789
38039
|
var MAX_AGENT_IMAGE_BASE64_LENGTH = 4e6;
|
|
38790
38040
|
var MAX_AGENT_RESOURCE_BYTE_LENGTH = 1e6;
|
|
38791
|
-
var
|
|
38041
|
+
var IDENTIFIER_PATTERN6 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
38792
38042
|
var PromptArtifactError = class extends Error {
|
|
38793
38043
|
code;
|
|
38794
38044
|
constructor(code, message, options = {}) {
|
|
@@ -38831,7 +38081,7 @@ function parseReference(resource) {
|
|
|
38831
38081
|
const encodedByteLength2 = url2.searchParams.get("byteLength") ?? "";
|
|
38832
38082
|
const sha256 = url2.searchParams.get("sha256") ?? "";
|
|
38833
38083
|
const byteLength = Number(encodedByteLength2);
|
|
38834
|
-
if (url2.protocol !== ARTIFACT_SCHEME || url2.hash.length > 0 || resource.type !== "link" || resource.text.length > 0 || !
|
|
38084
|
+
if (url2.protocol !== ARTIFACT_SCHEME || url2.hash.length > 0 || resource.type !== "link" || resource.text.length > 0 || !IDENTIFIER_PATTERN6.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)) {
|
|
38835
38085
|
throw new PromptArtifactError("artifact_reference_invalid", "The prompt artifact reference is invalid");
|
|
38836
38086
|
}
|
|
38837
38087
|
return new PromptArtifactReference(artifactId, byteLength, sha256, resource);
|
|
@@ -38897,7 +38147,7 @@ async function download(config2, command, reference, signal) {
|
|
|
38897
38147
|
const requestSignal = AbortSignal.any([signal, timeoutSignal]);
|
|
38898
38148
|
let response;
|
|
38899
38149
|
try {
|
|
38900
|
-
response = await
|
|
38150
|
+
response = await fetch5(downloadUrl(config2, command, reference), {
|
|
38901
38151
|
dispatcher: environmentProxyDispatcher,
|
|
38902
38152
|
headers: {
|
|
38903
38153
|
accept: reference.resource.mimeType,
|
|
@@ -39230,7 +38480,7 @@ var RelayConnectionDiagnostics = class {
|
|
|
39230
38480
|
};
|
|
39231
38481
|
|
|
39232
38482
|
// src/relay-connection/liveness.ts
|
|
39233
|
-
import { randomUUID as
|
|
38483
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
39234
38484
|
var HEARTBEAT_ACK_TIMEOUT_MILLISECONDS = 1e4;
|
|
39235
38485
|
var HEARTBEAT_INTERVAL_MILLISECONDS = 2e4;
|
|
39236
38486
|
var RelayLivenessState = class {
|
|
@@ -39319,7 +38569,7 @@ var RelayConnectionLiveness = class {
|
|
|
39319
38569
|
}
|
|
39320
38570
|
throw new Error("Heartbeat was scheduled in an invalid state");
|
|
39321
38571
|
}
|
|
39322
|
-
const heartbeatId =
|
|
38572
|
+
const heartbeatId = randomUUID3();
|
|
39323
38573
|
this.#state = new AwaitingHeartbeatAckState(
|
|
39324
38574
|
heartbeatId,
|
|
39325
38575
|
this.#timer.schedule(this.#handleTimeout, HEARTBEAT_ACK_TIMEOUT_MILLISECONDS)
|
|
@@ -39335,7 +38585,7 @@ var RelayConnectionLiveness = class {
|
|
|
39335
38585
|
|
|
39336
38586
|
// src/relay-connection/session-event-outbox.ts
|
|
39337
38587
|
import { mkdirSync as mkdirSync3 } from "node:fs";
|
|
39338
|
-
import { dirname as
|
|
38588
|
+
import { dirname as dirname6 } from "node:path";
|
|
39339
38589
|
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
39340
38590
|
var DEFAULT_OUTBOX_LIMITS = {
|
|
39341
38591
|
criticalEventBytes: 136 * 1024 * 1024,
|
|
@@ -39401,7 +38651,7 @@ var SessionEventOutbox = class {
|
|
|
39401
38651
|
constructor(path2, limits = DEFAULT_OUTBOX_LIMITS) {
|
|
39402
38652
|
validateLimits(limits);
|
|
39403
38653
|
this.#limits = limits;
|
|
39404
|
-
mkdirSync3(
|
|
38654
|
+
mkdirSync3(dirname6(path2), { recursive: true });
|
|
39405
38655
|
this.#database = new DatabaseSync3(path2);
|
|
39406
38656
|
this.#database.exec(`
|
|
39407
38657
|
CREATE TABLE IF NOT EXISTS relay_session_event_outbox (
|
|
@@ -39934,12 +39184,6 @@ var RELAY_RECONNECT_DELAY_MILLISECONDS = 500;
|
|
|
39934
39184
|
var AGENT_ACTIVITY_COALESCING_MILLISECONDS = 100;
|
|
39935
39185
|
var ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS = 2e4;
|
|
39936
39186
|
var ACTIVE_TURN_RECONCILIATION_CLOSE_CODE = 4009;
|
|
39937
|
-
function botIpcSocketPath() {
|
|
39938
|
-
if (process.platform === "win32") {
|
|
39939
|
-
return `\\\\.\\pipe\\mobius-bot-${randomUUID5()}`;
|
|
39940
|
-
}
|
|
39941
|
-
return join17("/tmp", `mobius-bot-${randomUUID5()}.sock`);
|
|
39942
|
-
}
|
|
39943
39187
|
var DaemonAcpObserver = class {
|
|
39944
39188
|
#config;
|
|
39945
39189
|
#record;
|
|
@@ -40157,7 +39401,7 @@ async function reconcileActiveTurn(config2, turn, signal) {
|
|
|
40157
39401
|
const requestSignal = AbortSignal.any([signal, timeoutSignal]);
|
|
40158
39402
|
let response;
|
|
40159
39403
|
try {
|
|
40160
|
-
response = await
|
|
39404
|
+
response = await fetch6(activeTurnReconciliationEndpoint(config2, turn), {
|
|
40161
39405
|
body: JSON.stringify({ outcome: { kind: "running" } }),
|
|
40162
39406
|
dispatcher: environmentProxyDispatcher,
|
|
40163
39407
|
headers: { ...runtimeAuthorization(config2.relayUrl), "content-type": "application/json" },
|
|
@@ -40469,13 +39713,13 @@ function reportFailure(publisher, command, code, message, attemptId) {
|
|
|
40469
39713
|
);
|
|
40470
39714
|
}
|
|
40471
39715
|
function operationErrorCode(error62) {
|
|
40472
|
-
if (error62 instanceof AcpExecutionError || error62 instanceof LocalAuthorizationError || error62 instanceof LocalAgentCatalogError || error62 instanceof
|
|
39716
|
+
if (error62 instanceof AcpExecutionError || error62 instanceof LocalAuthorizationError || error62 instanceof LocalAgentCatalogError || error62 instanceof PromptArtifactError) {
|
|
40473
39717
|
return error62.code;
|
|
40474
39718
|
}
|
|
40475
39719
|
return "session_operation_failed";
|
|
40476
39720
|
}
|
|
40477
39721
|
function operationErrorMessage(error62) {
|
|
40478
|
-
if (error62 instanceof AcpExecutionError || error62 instanceof LocalAuthorizationError || error62 instanceof LocalAgentCatalogError || error62 instanceof
|
|
39722
|
+
if (error62 instanceof AcpExecutionError || error62 instanceof LocalAuthorizationError || error62 instanceof LocalAgentCatalogError || error62 instanceof PromptArtifactError) {
|
|
40479
39723
|
return error62.message;
|
|
40480
39724
|
}
|
|
40481
39725
|
return "The local agent operation could not be completed";
|
|
@@ -40510,7 +39754,7 @@ async function resolveSessionDirectories(directories, bindingId, directoryId2, a
|
|
|
40510
39754
|
additionalDirectories.push(directory);
|
|
40511
39755
|
additionalDirectoryEntries.push({
|
|
40512
39756
|
directoryId: additionalDirectoryId,
|
|
40513
|
-
name:
|
|
39757
|
+
name: basename7(directory)
|
|
40514
39758
|
});
|
|
40515
39759
|
}
|
|
40516
39760
|
return new ResolvedSessionDirectories(cwd, additionalDirectories, additionalDirectoryEntries);
|
|
@@ -40855,11 +40099,11 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
40855
40099
|
function invalidSessionConfiguration(message) {
|
|
40856
40100
|
return new AcpExecutionError(message, {}, "invalid_session_configuration");
|
|
40857
40101
|
}
|
|
40858
|
-
function validateSessionConfigurationSelection(
|
|
40859
|
-
if (
|
|
40102
|
+
function validateSessionConfigurationSelection(option, selection) {
|
|
40103
|
+
if (option.type !== selection.valueType) {
|
|
40860
40104
|
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} changed type`);
|
|
40861
40105
|
}
|
|
40862
|
-
if (
|
|
40106
|
+
if (option.type === "boolean") {
|
|
40863
40107
|
if (selection.value.length > 0) {
|
|
40864
40108
|
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} has an invalid value`);
|
|
40865
40109
|
}
|
|
@@ -40868,7 +40112,7 @@ function validateSessionConfigurationSelection(option2, selection) {
|
|
|
40868
40112
|
if (selection.booleanValue) {
|
|
40869
40113
|
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} has an invalid value`);
|
|
40870
40114
|
}
|
|
40871
|
-
if (!
|
|
40115
|
+
if (!option.values.some((value) => value.value === selection.value)) {
|
|
40872
40116
|
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} has an unavailable value`);
|
|
40873
40117
|
}
|
|
40874
40118
|
}
|
|
@@ -40880,10 +40124,10 @@ function assertSessionConfigurationSchema(options, selections) {
|
|
|
40880
40124
|
if (selectionsById.size !== selections.length) {
|
|
40881
40125
|
throw invalidSessionConfiguration("The Turn configuration contains duplicate Agent settings");
|
|
40882
40126
|
}
|
|
40883
|
-
for (const
|
|
40884
|
-
const selection = selectionsById.get(
|
|
40885
|
-
if (selection === void 0 || selection.valueType !==
|
|
40886
|
-
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${
|
|
40127
|
+
for (const option of options) {
|
|
40128
|
+
const selection = selectionsById.get(option.id);
|
|
40129
|
+
if (selection === void 0 || selection.valueType !== option.type || option.type === "boolean" && selection.value.length > 0 || option.type === "select" && selection.booleanValue) {
|
|
40130
|
+
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
|
|
40887
40131
|
}
|
|
40888
40132
|
}
|
|
40889
40133
|
}
|
|
@@ -40892,37 +40136,37 @@ function assertSessionConfigurationCoverage(options, selections) {
|
|
|
40892
40136
|
if (selectionsById.size !== selections.length) {
|
|
40893
40137
|
throw invalidSessionConfiguration("The Turn configuration contains duplicate Agent settings");
|
|
40894
40138
|
}
|
|
40895
|
-
for (const
|
|
40896
|
-
if (!selectionsById.has(
|
|
40897
|
-
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${
|
|
40139
|
+
for (const option of options) {
|
|
40140
|
+
if (!selectionsById.has(option.id)) {
|
|
40141
|
+
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
|
|
40898
40142
|
}
|
|
40899
40143
|
}
|
|
40900
40144
|
}
|
|
40901
|
-
function sessionConfigurationSelectionIsAvailable(
|
|
40902
|
-
if (
|
|
40145
|
+
function sessionConfigurationSelectionIsAvailable(option, selection) {
|
|
40146
|
+
if (option.type !== selection.valueType) {
|
|
40903
40147
|
return false;
|
|
40904
40148
|
}
|
|
40905
|
-
if (
|
|
40149
|
+
if (option.type === "boolean") {
|
|
40906
40150
|
return selection.value.length === 0;
|
|
40907
40151
|
}
|
|
40908
|
-
return !selection.booleanValue &&
|
|
40152
|
+
return !selection.booleanValue && option.values.some((value) => value.value === selection.value);
|
|
40909
40153
|
}
|
|
40910
|
-
function sessionConfigurationMatches(
|
|
40911
|
-
validateSessionConfigurationSelection(
|
|
40912
|
-
return
|
|
40154
|
+
function sessionConfigurationMatches(option, selection) {
|
|
40155
|
+
validateSessionConfigurationSelection(option, selection);
|
|
40156
|
+
return option.type === "boolean" ? option.booleanValue === selection.booleanValue : option.currentValue === selection.value;
|
|
40913
40157
|
}
|
|
40914
40158
|
function sessionConfigurationPriority(selection, options) {
|
|
40915
40159
|
if (selection.configId === "permission_mode") {
|
|
40916
40160
|
return 0;
|
|
40917
40161
|
}
|
|
40918
|
-
const
|
|
40919
|
-
if (selection.configId === "model" ||
|
|
40162
|
+
const option = options.find((candidate) => candidate.id === selection.configId);
|
|
40163
|
+
if (selection.configId === "model" || option?.category === "model") {
|
|
40920
40164
|
return 1;
|
|
40921
40165
|
}
|
|
40922
|
-
if (selection.configId === "reasoning_effort" ||
|
|
40166
|
+
if (selection.configId === "reasoning_effort" || option?.category === "thought_level") {
|
|
40923
40167
|
return 2;
|
|
40924
40168
|
}
|
|
40925
|
-
if (
|
|
40169
|
+
if (option?.category === "model_config") {
|
|
40926
40170
|
return 3;
|
|
40927
40171
|
}
|
|
40928
40172
|
return 4;
|
|
@@ -40930,28 +40174,28 @@ function sessionConfigurationPriority(selection, options) {
|
|
|
40930
40174
|
function assertCompleteSessionConfiguration(options, selections) {
|
|
40931
40175
|
assertSessionConfigurationSchema(options, selections);
|
|
40932
40176
|
const selectionsById = new Map(selections.map((selection) => [selection.configId, selection]));
|
|
40933
|
-
for (const
|
|
40934
|
-
const selection = selectionsById.get(
|
|
40935
|
-
if (selection === void 0 || !sessionConfigurationMatches(
|
|
40936
|
-
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${
|
|
40177
|
+
for (const option of options) {
|
|
40178
|
+
const selection = selectionsById.get(option.id);
|
|
40179
|
+
if (selection === void 0 || !sessionConfigurationMatches(option, selection)) {
|
|
40180
|
+
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
|
|
40937
40181
|
}
|
|
40938
40182
|
}
|
|
40939
40183
|
}
|
|
40940
40184
|
function assertAppliedSessionConfiguration(options, selections) {
|
|
40941
40185
|
const selectionsById = new Map(selections.map((selection) => [selection.configId, selection]));
|
|
40942
|
-
for (const
|
|
40943
|
-
const selection = selectionsById.get(
|
|
40944
|
-
if (
|
|
40945
|
-
if (selection === void 0 || !sessionConfigurationMatches(
|
|
40946
|
-
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${
|
|
40186
|
+
for (const option of options) {
|
|
40187
|
+
const selection = selectionsById.get(option.id);
|
|
40188
|
+
if (option.id === AGENT_PERMISSION_MODE_CONFIG_ID) {
|
|
40189
|
+
if (selection === void 0 || !sessionConfigurationMatches(option, selection)) {
|
|
40190
|
+
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
|
|
40947
40191
|
}
|
|
40948
40192
|
continue;
|
|
40949
40193
|
}
|
|
40950
|
-
if (selection === void 0 || !sessionConfigurationSelectionIsAvailable(
|
|
40194
|
+
if (selection === void 0 || !sessionConfigurationSelectionIsAvailable(option, selection)) {
|
|
40951
40195
|
continue;
|
|
40952
40196
|
}
|
|
40953
|
-
if (!sessionConfigurationMatches(
|
|
40954
|
-
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${
|
|
40197
|
+
if (!sessionConfigurationMatches(option, selection)) {
|
|
40198
|
+
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
|
|
40955
40199
|
}
|
|
40956
40200
|
}
|
|
40957
40201
|
}
|
|
@@ -40965,8 +40209,8 @@ function unavailableSessionConfigurationCategory(selection) {
|
|
|
40965
40209
|
return "unknown";
|
|
40966
40210
|
}
|
|
40967
40211
|
async function applySessionConfigurationSelection(sessions, audit, options, selection, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
|
|
40968
|
-
const
|
|
40969
|
-
if (
|
|
40212
|
+
const option = options.find((candidate) => candidate.id === selection.configId);
|
|
40213
|
+
if (option === void 0) {
|
|
40970
40214
|
if (selection.configId !== AGENT_PERMISSION_MODE_CONFIG_ID) {
|
|
40971
40215
|
warnIgnoredSetting(
|
|
40972
40216
|
audit,
|
|
@@ -40983,7 +40227,7 @@ async function applySessionConfigurationSelection(sessions, audit, options, sele
|
|
|
40983
40227
|
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} is unavailable`);
|
|
40984
40228
|
}
|
|
40985
40229
|
if (selection.configId !== AGENT_PERMISSION_MODE_CONFIG_ID) {
|
|
40986
|
-
if (
|
|
40230
|
+
if (option.type !== selection.valueType) {
|
|
40987
40231
|
warnIgnoredSetting(
|
|
40988
40232
|
audit,
|
|
40989
40233
|
"session_configuration_setting_ignored",
|
|
@@ -40991,12 +40235,12 @@ async function applySessionConfigurationSelection(sessions, audit, options, sele
|
|
|
40991
40235
|
sessionId,
|
|
40992
40236
|
agent.id,
|
|
40993
40237
|
selection,
|
|
40994
|
-
|
|
40238
|
+
option.category,
|
|
40995
40239
|
"setting_schema_mismatch"
|
|
40996
40240
|
);
|
|
40997
40241
|
return options;
|
|
40998
40242
|
}
|
|
40999
|
-
if (
|
|
40243
|
+
if (option.type === "boolean" && selection.value.length > 0 || option.type === "select" && selection.booleanValue) {
|
|
41000
40244
|
warnIgnoredSetting(
|
|
41001
40245
|
audit,
|
|
41002
40246
|
"session_configuration_setting_ignored",
|
|
@@ -41004,12 +40248,12 @@ async function applySessionConfigurationSelection(sessions, audit, options, sele
|
|
|
41004
40248
|
sessionId,
|
|
41005
40249
|
agent.id,
|
|
41006
40250
|
selection,
|
|
41007
|
-
|
|
40251
|
+
option.category,
|
|
41008
40252
|
"selection_schema_mismatch"
|
|
41009
40253
|
);
|
|
41010
40254
|
return options;
|
|
41011
40255
|
}
|
|
41012
|
-
if (
|
|
40256
|
+
if (option.type === "select" && !option.values.some((value) => value.value === selection.value)) {
|
|
41013
40257
|
warnIgnoredSetting(
|
|
41014
40258
|
audit,
|
|
41015
40259
|
"session_configuration_setting_ignored",
|
|
@@ -41017,13 +40261,13 @@ async function applySessionConfigurationSelection(sessions, audit, options, sele
|
|
|
41017
40261
|
sessionId,
|
|
41018
40262
|
agent.id,
|
|
41019
40263
|
selection,
|
|
41020
|
-
|
|
40264
|
+
option.category,
|
|
41021
40265
|
"value_unavailable"
|
|
41022
40266
|
);
|
|
41023
40267
|
return options;
|
|
41024
40268
|
}
|
|
41025
40269
|
}
|
|
41026
|
-
if (sessionConfigurationMatches(
|
|
40270
|
+
if (sessionConfigurationMatches(option, selection)) {
|
|
41027
40271
|
return options;
|
|
41028
40272
|
}
|
|
41029
40273
|
return await sessions.configureSession({
|
|
@@ -41032,7 +40276,7 @@ async function applySessionConfigurationSelection(sessions, audit, options, sele
|
|
|
41032
40276
|
booleanValue: selection.booleanValue,
|
|
41033
40277
|
configId: selection.configId,
|
|
41034
40278
|
cwd,
|
|
41035
|
-
requestId: `cfg_${
|
|
40279
|
+
requestId: `cfg_${randomUUID4()}`,
|
|
41036
40280
|
sessionId,
|
|
41037
40281
|
signal,
|
|
41038
40282
|
value: selection.value,
|
|
@@ -41062,37 +40306,6 @@ async function applyCompleteSessionConfiguration(sessions, audit, initialOptions
|
|
|
41062
40306
|
}
|
|
41063
40307
|
assertAppliedSessionConfiguration(options, selections);
|
|
41064
40308
|
}
|
|
41065
|
-
function botExecutionAgent(agent, contextHandle, socketPath) {
|
|
41066
|
-
return new LocalAgentDefinition(
|
|
41067
|
-
agent.id,
|
|
41068
|
-
agent.label,
|
|
41069
|
-
agent.command,
|
|
41070
|
-
agent.arguments,
|
|
41071
|
-
{
|
|
41072
|
-
...agent.environment,
|
|
41073
|
-
MOBIUS_BOT_CONTEXT: contextHandle,
|
|
41074
|
-
MOBIUS_BOT_SOCKET: socketPath,
|
|
41075
|
-
MOBIUS_RELAY_TOKEN: "",
|
|
41076
|
-
MOBIUS_RELAY_URL: ""
|
|
41077
|
-
},
|
|
41078
|
-
agent.adapterVersion,
|
|
41079
|
-
agent.agentVersion,
|
|
41080
|
-
agent.adapterIdentity,
|
|
41081
|
-
agent.agentIdentity,
|
|
41082
|
-
agent.capabilities,
|
|
41083
|
-
agent.permissionProfile
|
|
41084
|
-
);
|
|
41085
|
-
}
|
|
41086
|
-
function assertPreparedPermission(configOptions, permissionMode) {
|
|
41087
|
-
const permission = configOptions.find((option2) => option2.id === "permission_mode");
|
|
41088
|
-
if (permission === void 0 || permission.type !== "select" || permissionMode !== AGENT_DEFAULT_EXECUTION_SETTING && permission.currentValue !== permissionMode) {
|
|
41089
|
-
throw new AcpExecutionError(
|
|
41090
|
-
"The required Agent permission mode is unavailable",
|
|
41091
|
-
{},
|
|
41092
|
-
"invalid_session_configuration"
|
|
41093
|
-
);
|
|
41094
|
-
}
|
|
41095
|
-
}
|
|
41096
40309
|
function warnIgnoredSetting(audit, event, commandId, sessionId, agentId, selection, category, reason) {
|
|
41097
40310
|
const details = {
|
|
41098
40311
|
agentId,
|
|
@@ -41105,274 +40318,6 @@ function warnIgnoredSetting(audit, event, commandId, sessionId, agentId, selecti
|
|
|
41105
40318
|
process.stderr.write(`Mobius daemon warning ${JSON.stringify({ commandId, event, sessionId, ...details })}
|
|
41106
40319
|
`);
|
|
41107
40320
|
}
|
|
41108
|
-
async function applySupportedExecutionSelection(sessions, audit, configOptions, selection, category, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
|
|
41109
|
-
if (selection.value === AGENT_DEFAULT_EXECUTION_SETTING) {
|
|
41110
|
-
return configOptions;
|
|
41111
|
-
}
|
|
41112
|
-
const option2 = configOptions.find((candidate) => candidate.id === selection.configId);
|
|
41113
|
-
if (option2 === void 0) {
|
|
41114
|
-
warnIgnoredSetting(
|
|
41115
|
-
audit,
|
|
41116
|
-
"bot_execution_setting_ignored",
|
|
41117
|
-
commandId,
|
|
41118
|
-
sessionId,
|
|
41119
|
-
agent.id,
|
|
41120
|
-
selection,
|
|
41121
|
-
category,
|
|
41122
|
-
"setting_unavailable"
|
|
41123
|
-
);
|
|
41124
|
-
return configOptions;
|
|
41125
|
-
}
|
|
41126
|
-
if (option2.type !== "select" || option2.category !== category) {
|
|
41127
|
-
warnIgnoredSetting(
|
|
41128
|
-
audit,
|
|
41129
|
-
"bot_execution_setting_ignored",
|
|
41130
|
-
commandId,
|
|
41131
|
-
sessionId,
|
|
41132
|
-
agent.id,
|
|
41133
|
-
selection,
|
|
41134
|
-
category,
|
|
41135
|
-
"setting_schema_mismatch"
|
|
41136
|
-
);
|
|
41137
|
-
return configOptions;
|
|
41138
|
-
}
|
|
41139
|
-
if (selection.valueType !== "select" || selection.booleanValue) {
|
|
41140
|
-
warnIgnoredSetting(
|
|
41141
|
-
audit,
|
|
41142
|
-
"bot_execution_setting_ignored",
|
|
41143
|
-
commandId,
|
|
41144
|
-
sessionId,
|
|
41145
|
-
agent.id,
|
|
41146
|
-
selection,
|
|
41147
|
-
category,
|
|
41148
|
-
"selection_schema_mismatch"
|
|
41149
|
-
);
|
|
41150
|
-
return configOptions;
|
|
41151
|
-
}
|
|
41152
|
-
if (!option2.values.some((value) => value.value === selection.value)) {
|
|
41153
|
-
warnIgnoredSetting(
|
|
41154
|
-
audit,
|
|
41155
|
-
"bot_execution_setting_ignored",
|
|
41156
|
-
commandId,
|
|
41157
|
-
sessionId,
|
|
41158
|
-
agent.id,
|
|
41159
|
-
selection,
|
|
41160
|
-
category,
|
|
41161
|
-
"value_unavailable"
|
|
41162
|
-
);
|
|
41163
|
-
return configOptions;
|
|
41164
|
-
}
|
|
41165
|
-
if (option2.currentValue === selection.value) {
|
|
41166
|
-
return configOptions;
|
|
41167
|
-
}
|
|
41168
|
-
return await sessions.configureSession({
|
|
41169
|
-
additionalDirectories,
|
|
41170
|
-
agent,
|
|
41171
|
-
booleanValue: false,
|
|
41172
|
-
configId: selection.configId,
|
|
41173
|
-
cwd,
|
|
41174
|
-
requestId: `cfg_${randomUUID5()}`,
|
|
41175
|
-
sessionId,
|
|
41176
|
-
signal,
|
|
41177
|
-
value: selection.value,
|
|
41178
|
-
valueType: "select"
|
|
41179
|
-
});
|
|
41180
|
-
}
|
|
41181
|
-
async function executeBotPrompt(outbox, publisher, command, config2, directories, audit, sessions, authorizer, contexts, applicator, ipc, attemptId, activateAttempt, timer, signal) {
|
|
41182
|
-
const activities = new CoalescingDaemonActivityPublisher(timer, (activity) => {
|
|
41183
|
-
publisher.recordAttempt(command.sessionId, encodeDaemonActivity(command, activity), attemptId);
|
|
41184
|
-
});
|
|
41185
|
-
try {
|
|
41186
|
-
const startDeadline = Date.parse(command.executionDeadlineAt);
|
|
41187
|
-
if (!Number.isSafeInteger(startDeadline) || startDeadline <= Date.now()) {
|
|
41188
|
-
throw new LocalBotAuthorizationError("turn_expired", "The Bot execution start deadline has expired");
|
|
41189
|
-
}
|
|
41190
|
-
const execution = await authorizer.authorize(command, config2.catalog, directories, config2.bindingId, signal);
|
|
41191
|
-
const resolved = await resolveSessionDirectories(
|
|
41192
|
-
directories,
|
|
41193
|
-
config2.bindingId,
|
|
41194
|
-
command.directoryId,
|
|
41195
|
-
command.additionalDirectoryIds,
|
|
41196
|
-
signal
|
|
41197
|
-
);
|
|
41198
|
-
const attachments = await resolvePromptArtifacts(config2, command, signal);
|
|
41199
|
-
const applied = await applicator.apply(command, execution, attachments.resources, signal);
|
|
41200
|
-
const startExecution = () => {
|
|
41201
|
-
audit.record({
|
|
41202
|
-
commandId: command.commandId,
|
|
41203
|
-
details: {
|
|
41204
|
-
behaviorRevisionId: command.behaviorRevisionId,
|
|
41205
|
-
bindingId: command.bindingId,
|
|
41206
|
-
botId: command.botId,
|
|
41207
|
-
executionId: command.executionId
|
|
41208
|
-
},
|
|
41209
|
-
event: "bot_session_authorized",
|
|
41210
|
-
sessionId: command.sessionId
|
|
41211
|
-
});
|
|
41212
|
-
outbox.transitionExecution(command.commandId, "running");
|
|
41213
|
-
publisher.recordAttempt(
|
|
41214
|
-
command.sessionId,
|
|
41215
|
-
encodeSessionStartedEvent({
|
|
41216
|
-
attemptId,
|
|
41217
|
-
commandId: command.commandId,
|
|
41218
|
-
kind: SESSION_STARTED_KIND,
|
|
41219
|
-
sessionId: command.sessionId
|
|
41220
|
-
}),
|
|
41221
|
-
attemptId
|
|
41222
|
-
);
|
|
41223
|
-
activateAttempt();
|
|
41224
|
-
};
|
|
41225
|
-
let stopReason = "steered";
|
|
41226
|
-
if (command.disposition === SessionPromptDisposition.Steer) {
|
|
41227
|
-
startExecution();
|
|
41228
|
-
await sessions.steerPrompt({
|
|
41229
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
41230
|
-
agent: execution.agent,
|
|
41231
|
-
commandId: command.commandId,
|
|
41232
|
-
cwd: resolved.cwd,
|
|
41233
|
-
images: attachments.images,
|
|
41234
|
-
prompt: command.prompt,
|
|
41235
|
-
resources: applied.resources,
|
|
41236
|
-
sessionId: command.sessionId,
|
|
41237
|
-
signal,
|
|
41238
|
-
targetCommandId: command.targetCommandId
|
|
41239
|
-
});
|
|
41240
|
-
} else {
|
|
41241
|
-
if (command.disposition === SessionPromptDisposition.Queue && !outbox.isTerminalExecution(command.targetCommandId, command.sessionId)) {
|
|
41242
|
-
throw new AcpExecutionError(
|
|
41243
|
-
"The queued Bot prompt target is unavailable",
|
|
41244
|
-
{},
|
|
41245
|
-
"prompt_queue_target_unavailable"
|
|
41246
|
-
);
|
|
41247
|
-
}
|
|
41248
|
-
const lease = contexts.activate(command);
|
|
41249
|
-
try {
|
|
41250
|
-
const agent = botExecutionAgent(execution.agent, lease.context.contextHandle, ipc.socketPath);
|
|
41251
|
-
const prepared = await sessions.prepareExecutionSession({
|
|
41252
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
41253
|
-
agent,
|
|
41254
|
-
cwd: resolved.cwd,
|
|
41255
|
-
sessionId: command.sessionId,
|
|
41256
|
-
signal
|
|
41257
|
-
});
|
|
41258
|
-
assertPreparedPermission(prepared.configOptions, execution.executionConfiguration.permissionMode);
|
|
41259
|
-
let configOptions = await applySupportedExecutionSelection(
|
|
41260
|
-
sessions,
|
|
41261
|
-
audit,
|
|
41262
|
-
prepared.configOptions,
|
|
41263
|
-
execution.executionConfiguration.model,
|
|
41264
|
-
"model",
|
|
41265
|
-
agent,
|
|
41266
|
-
resolved.cwd,
|
|
41267
|
-
resolved.additionalDirectories,
|
|
41268
|
-
command.commandId,
|
|
41269
|
-
command.sessionId,
|
|
41270
|
-
signal
|
|
41271
|
-
);
|
|
41272
|
-
configOptions = await applySupportedExecutionSelection(
|
|
41273
|
-
sessions,
|
|
41274
|
-
audit,
|
|
41275
|
-
configOptions,
|
|
41276
|
-
execution.executionConfiguration.reasoningEffort,
|
|
41277
|
-
"thought_level",
|
|
41278
|
-
agent,
|
|
41279
|
-
resolved.cwd,
|
|
41280
|
-
resolved.additionalDirectories,
|
|
41281
|
-
command.commandId,
|
|
41282
|
-
command.sessionId,
|
|
41283
|
-
signal
|
|
41284
|
-
);
|
|
41285
|
-
for (const selection of command.sessionConfigurations) {
|
|
41286
|
-
await sessions.configureSession({
|
|
41287
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
41288
|
-
agent,
|
|
41289
|
-
booleanValue: selection.booleanValue,
|
|
41290
|
-
configId: selection.configId,
|
|
41291
|
-
cwd: resolved.cwd,
|
|
41292
|
-
requestId: `cfg_${randomUUID5()}`,
|
|
41293
|
-
sessionId: command.sessionId,
|
|
41294
|
-
signal,
|
|
41295
|
-
value: selection.value,
|
|
41296
|
-
valueType: selection.valueType
|
|
41297
|
-
});
|
|
41298
|
-
}
|
|
41299
|
-
startExecution();
|
|
41300
|
-
const result = await sessions.runPrompt({
|
|
41301
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
41302
|
-
agent,
|
|
41303
|
-
commandId: command.commandId,
|
|
41304
|
-
cwd: resolved.cwd,
|
|
41305
|
-
disposition: command.disposition,
|
|
41306
|
-
images: attachments.images,
|
|
41307
|
-
onActivity: activities.record,
|
|
41308
|
-
onText: (text3, messageId) => {
|
|
41309
|
-
publisher.recordAttempt(
|
|
41310
|
-
command.sessionId,
|
|
41311
|
-
encodeAgentMessageDeltaEvent({
|
|
41312
|
-
commandId: command.commandId,
|
|
41313
|
-
kind: AGENT_MESSAGE_DELTA_KIND,
|
|
41314
|
-
messageId,
|
|
41315
|
-
sessionId: command.sessionId,
|
|
41316
|
-
text: text3
|
|
41317
|
-
}),
|
|
41318
|
-
attemptId
|
|
41319
|
-
);
|
|
41320
|
-
return Promise.resolve();
|
|
41321
|
-
},
|
|
41322
|
-
prompt: command.prompt,
|
|
41323
|
-
resources: applied.resources,
|
|
41324
|
-
sessionId: command.sessionId,
|
|
41325
|
-
signal,
|
|
41326
|
-
targetCommandId: command.targetCommandId
|
|
41327
|
-
});
|
|
41328
|
-
stopReason = result.stopReason;
|
|
41329
|
-
} finally {
|
|
41330
|
-
lease.release();
|
|
41331
|
-
}
|
|
41332
|
-
}
|
|
41333
|
-
activities.flush();
|
|
41334
|
-
publisher.recordAttempt(
|
|
41335
|
-
command.sessionId,
|
|
41336
|
-
encodeSessionCompletedEvent({
|
|
41337
|
-
commandId: command.commandId,
|
|
41338
|
-
kind: SESSION_COMPLETED_KIND,
|
|
41339
|
-
sessionId: command.sessionId,
|
|
41340
|
-
stopReason
|
|
41341
|
-
}),
|
|
41342
|
-
attemptId
|
|
41343
|
-
);
|
|
41344
|
-
outbox.transitionExecution(command.commandId, stopReason === "cancelled" ? "cancelled" : "succeeded");
|
|
41345
|
-
audit.record({
|
|
41346
|
-
commandId: command.commandId,
|
|
41347
|
-
details: { botId: command.botId, executionId: command.executionId },
|
|
41348
|
-
event: stopReason === "cancelled" ? "bot_session_cancelled" : "bot_session_completed",
|
|
41349
|
-
sessionId: command.sessionId
|
|
41350
|
-
});
|
|
41351
|
-
} catch (error62) {
|
|
41352
|
-
activities.flush();
|
|
41353
|
-
const failure2 = error62;
|
|
41354
|
-
audit.record({
|
|
41355
|
-
commandId: command.commandId,
|
|
41356
|
-
details: {
|
|
41357
|
-
botId: command.botId,
|
|
41358
|
-
code: operationErrorCode(failure2),
|
|
41359
|
-
executionId: command.executionId
|
|
41360
|
-
},
|
|
41361
|
-
event: "bot_session_failed",
|
|
41362
|
-
sessionId: command.sessionId
|
|
41363
|
-
});
|
|
41364
|
-
const code = operationErrorCode(failure2);
|
|
41365
|
-
reportFailure(
|
|
41366
|
-
publisher,
|
|
41367
|
-
command,
|
|
41368
|
-
code === "session_operation_failed" ? "agent_execution_failed" : code,
|
|
41369
|
-
code === "session_operation_failed" ? "The local agent could not complete the Bot request" : operationErrorMessage(failure2),
|
|
41370
|
-
attemptId
|
|
41371
|
-
);
|
|
41372
|
-
outbox.transitionExecution(command.commandId, "failed");
|
|
41373
|
-
console.error("Mobius daemon Bot command failed", failure2);
|
|
41374
|
-
}
|
|
41375
|
-
}
|
|
41376
40321
|
function waitForRelayRetry(signal, timer) {
|
|
41377
40322
|
if (signal.aborted) {
|
|
41378
40323
|
return Promise.resolve();
|
|
@@ -41419,13 +40364,13 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
|
|
|
41419
40364
|
{
|
|
41420
40365
|
agentId: agent.id,
|
|
41421
40366
|
kind: AGENT_INSTALL_REQUEST_KIND,
|
|
41422
|
-
requestId: `automatic-integration-${
|
|
40367
|
+
requestId: `automatic-integration-${randomUUID4()}`
|
|
41423
40368
|
},
|
|
41424
40369
|
signal
|
|
41425
40370
|
);
|
|
41426
40371
|
}
|
|
41427
40372
|
}
|
|
41428
|
-
async function runRelayConnection(config2, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher,
|
|
40373
|
+
async function runRelayConnection(config2, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher, activeTurns, activeAttemptIds, connectionEpoch, diagnostics, onConnected, signal, timer) {
|
|
41429
40374
|
const relayUrl = new URL(config2.relayUrl);
|
|
41430
40375
|
relayUrl.searchParams.set("deliveryReceipts", "1");
|
|
41431
40376
|
relayUrl.searchParams.set("liveness", "1");
|
|
@@ -41591,32 +40536,6 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
41591
40536
|
}
|
|
41592
40537
|
return;
|
|
41593
40538
|
}
|
|
41594
|
-
if (kind === BOT_SESSION_PROMPT_KIND) {
|
|
41595
|
-
const command = decodeBotSessionPromptCommand(delivery.payload);
|
|
41596
|
-
await processDeliveredPrompt(
|
|
41597
|
-
delivery,
|
|
41598
|
-
command,
|
|
41599
|
-
command.disposition !== SessionPromptDisposition.Steer,
|
|
41600
|
-
(attemptId, activateAttempt, executionSignal) => executeBotPrompt(
|
|
41601
|
-
outbox,
|
|
41602
|
-
publisher,
|
|
41603
|
-
command,
|
|
41604
|
-
config2,
|
|
41605
|
-
directories,
|
|
41606
|
-
audit,
|
|
41607
|
-
sessions,
|
|
41608
|
-
authorizer,
|
|
41609
|
-
contexts,
|
|
41610
|
-
applicator,
|
|
41611
|
-
ipc,
|
|
41612
|
-
attemptId,
|
|
41613
|
-
activateAttempt,
|
|
41614
|
-
timer,
|
|
41615
|
-
executionSignal
|
|
41616
|
-
)
|
|
41617
|
-
);
|
|
41618
|
-
return;
|
|
41619
|
-
}
|
|
41620
40539
|
if (kind === SESSION_PROMPT_KIND) {
|
|
41621
40540
|
const command = decodeSessionPromptCommand(delivery.payload);
|
|
41622
40541
|
await processDeliveredPrompt(
|
|
@@ -41674,8 +40593,6 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
41674
40593
|
payloadSessionId = decodeSessionElicitationRespondCommand(delivery.payload).sessionId;
|
|
41675
40594
|
} else if (payloadKind === SESSION_PROMPT_KIND) {
|
|
41676
40595
|
payloadSessionId = decodeSessionPromptCommand(delivery.payload).sessionId;
|
|
41677
|
-
} else if (payloadKind === BOT_SESSION_PROMPT_KIND) {
|
|
41678
|
-
payloadSessionId = decodeBotSessionPromptCommand(delivery.payload).sessionId;
|
|
41679
40596
|
} else {
|
|
41680
40597
|
throw new Error("Runtime delivery contains an unsupported protocol message");
|
|
41681
40598
|
}
|
|
@@ -42068,6 +40985,29 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
42068
40985
|
connectionLiveness.acknowledge(decodeRuntimeHeartbeatAckEvent(encoded));
|
|
42069
40986
|
return;
|
|
42070
40987
|
}
|
|
40988
|
+
if (kind === FILE_READ_KIND) {
|
|
40989
|
+
const command2 = decodeFileReadCommand(encoded);
|
|
40990
|
+
void streamLocalFile(
|
|
40991
|
+
command2,
|
|
40992
|
+
(message) => send(socket, message),
|
|
40993
|
+
connectionController.signal
|
|
40994
|
+
).catch((error62) => {
|
|
40995
|
+
if (socket.readyState !== WebSocket2.OPEN || connectionController.signal.aborted) {
|
|
40996
|
+
return;
|
|
40997
|
+
}
|
|
40998
|
+
send(
|
|
40999
|
+
socket,
|
|
41000
|
+
encodeFileFailedEvent({
|
|
41001
|
+
code: "file_unavailable",
|
|
41002
|
+
kind: FILE_FAILED_KIND,
|
|
41003
|
+
message: error62 instanceof Error ? error62.message : "The local file is unavailable",
|
|
41004
|
+
requestId: command2.requestId,
|
|
41005
|
+
sessionId: command2.sessionId
|
|
41006
|
+
})
|
|
41007
|
+
);
|
|
41008
|
+
});
|
|
41009
|
+
return;
|
|
41010
|
+
}
|
|
42071
41011
|
if (kind === SESSION_CANCEL_KIND) {
|
|
42072
41012
|
const cancellation = decodeSessionCancelCommand(encoded);
|
|
42073
41013
|
const turn2 = activeTurns.get(cancellation.commandId);
|
|
@@ -42161,48 +41101,6 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
42161
41101
|
});
|
|
42162
41102
|
return;
|
|
42163
41103
|
}
|
|
42164
|
-
if (kind === BOT_SESSION_PROMPT_KIND) {
|
|
42165
|
-
const command2 = decodeBotSessionPromptCommand(encoded);
|
|
42166
|
-
if (activeTurns.has(command2.commandId)) {
|
|
42167
|
-
return;
|
|
42168
|
-
}
|
|
42169
|
-
const receipt2 = outbox.claimExecution(command2.commandId, command2.sessionId, encoded);
|
|
42170
|
-
if (receipt2.kind === "duplicate") {
|
|
42171
|
-
return;
|
|
42172
|
-
}
|
|
42173
|
-
const turn2 = new ActiveDaemonTurn(command2, receipt2.attemptId);
|
|
42174
|
-
activeTurns.set(command2.commandId, turn2);
|
|
42175
|
-
void executeBotPrompt(
|
|
42176
|
-
outbox,
|
|
42177
|
-
publisher,
|
|
42178
|
-
command2,
|
|
42179
|
-
config2,
|
|
42180
|
-
directories,
|
|
42181
|
-
audit,
|
|
42182
|
-
sessions,
|
|
42183
|
-
authorizer,
|
|
42184
|
-
contexts,
|
|
42185
|
-
applicator,
|
|
42186
|
-
ipc,
|
|
42187
|
-
receipt2.attemptId,
|
|
42188
|
-
() => {
|
|
42189
|
-
if (command2.disposition !== SessionPromptDisposition.Steer) {
|
|
42190
|
-
activeAttemptIds.set(command2.sessionId, receipt2.attemptId);
|
|
42191
|
-
}
|
|
42192
|
-
},
|
|
42193
|
-
timer,
|
|
42194
|
-
turn2.signal
|
|
42195
|
-
).catch((error62) => {
|
|
42196
|
-
console.error("Mobius daemon Bot turn failed", error62);
|
|
42197
|
-
}).finally(() => {
|
|
42198
|
-
activeTurns.delete(command2.commandId);
|
|
42199
|
-
if (activeAttemptIds.get(command2.sessionId) === receipt2.attemptId) {
|
|
42200
|
-
activeAttemptIds.delete(command2.sessionId);
|
|
42201
|
-
}
|
|
42202
|
-
turn2.finish();
|
|
42203
|
-
});
|
|
42204
|
-
return;
|
|
42205
|
-
}
|
|
42206
41104
|
if (kind !== SESSION_PROMPT_KIND) {
|
|
42207
41105
|
throw new Error("Unsupported protocol message");
|
|
42208
41106
|
}
|
|
@@ -42306,10 +41204,6 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
42306
41204
|
const sessionStore = new SqliteAcpSessionStore(config2.auditDatabasePath);
|
|
42307
41205
|
const outbox = new SessionEventOutbox(config2.auditDatabasePath);
|
|
42308
41206
|
const publisher = new DaemonSessionEventPublisher(outbox, timer);
|
|
42309
|
-
const authorizer = new LocalBotExecutionAuthorizer();
|
|
42310
|
-
const contexts = new BotExecutionContextRegistry();
|
|
42311
|
-
const applicator = new EmbeddedBotContextApplicator();
|
|
42312
|
-
const ipc = new BotOutboundIpcServer(botIpcSocketPath(), config2.relayUrl, contexts);
|
|
42313
41207
|
const activeTurns = /* @__PURE__ */ new Map();
|
|
42314
41208
|
const activeAttemptIds = /* @__PURE__ */ new Map();
|
|
42315
41209
|
const recordSessionEvent = (sessionId, payload) => {
|
|
@@ -42383,7 +41277,6 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
42383
41277
|
startAutomaticIntegrationProvisioning();
|
|
42384
41278
|
});
|
|
42385
41279
|
try {
|
|
42386
|
-
await ipc.listen(signal);
|
|
42387
41280
|
while (!signal.aborted) {
|
|
42388
41281
|
connectionEpoch += 1;
|
|
42389
41282
|
try {
|
|
@@ -42397,10 +41290,6 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
42397
41290
|
nativeSessions,
|
|
42398
41291
|
outbox,
|
|
42399
41292
|
publisher,
|
|
42400
|
-
authorizer,
|
|
42401
|
-
contexts,
|
|
42402
|
-
applicator,
|
|
42403
|
-
ipc,
|
|
42404
41293
|
activeTurns,
|
|
42405
41294
|
activeAttemptIds,
|
|
42406
41295
|
connectionEpoch,
|
|
@@ -42433,19 +41322,15 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
42433
41322
|
await installations.close();
|
|
42434
41323
|
} finally {
|
|
42435
41324
|
try {
|
|
42436
|
-
await
|
|
41325
|
+
await sessions.close();
|
|
42437
41326
|
} finally {
|
|
42438
41327
|
try {
|
|
42439
|
-
|
|
41328
|
+
sessionStore.close();
|
|
42440
41329
|
} finally {
|
|
42441
41330
|
try {
|
|
42442
|
-
|
|
41331
|
+
publisher.close();
|
|
42443
41332
|
} finally {
|
|
42444
|
-
|
|
42445
|
-
publisher.close();
|
|
42446
|
-
} finally {
|
|
42447
|
-
outbox.close();
|
|
42448
|
-
}
|
|
41333
|
+
outbox.close();
|
|
42449
41334
|
}
|
|
42450
41335
|
}
|
|
42451
41336
|
}
|
|
@@ -42521,14 +41406,12 @@ Usage:
|
|
|
42521
41406
|
mobius pair --url <relay-url> --pairing <runtime-pairing-id> --code <pairing-code> [--workspace <directory>]
|
|
42522
41407
|
mobius start --channel <channel-id>
|
|
42523
41408
|
mobius agents [--json]
|
|
42524
|
-
mobius bot message send --target <current|alias> --text <message>
|
|
42525
41409
|
|
|
42526
41410
|
Commands:
|
|
42527
41411
|
--version Print the installed Mobius CLI version
|
|
42528
41412
|
pair Pair this machine and start its local daemon
|
|
42529
41413
|
start Start the local daemon for a saved channel
|
|
42530
41414
|
agents Show detected, missing, and integration-ready Agents
|
|
42531
|
-
bot Send a message from an active execution
|
|
42532
41415
|
|
|
42533
41416
|
Pairing grants this browser access to the machine with your user account's permissions.
|
|
42534
41417
|
New conversations default to ~/.mobius/workspace; choose other directories in the browser.
|
|
@@ -42549,7 +41432,7 @@ async function main() {
|
|
|
42549
41432
|
if (arguments_.length > 1 || arguments_.length === 1 && arguments_[0] !== "--json") {
|
|
42550
41433
|
throw new Error("Usage: mobius agents [--json]");
|
|
42551
41434
|
}
|
|
42552
|
-
await
|
|
41435
|
+
await mkdir4(loadDefaultWorkspace(), { recursive: true, mode: 448 });
|
|
42553
41436
|
const inventory = await discoverLocalAgentInventory({
|
|
42554
41437
|
defaultWorkspace: loadDefaultWorkspace(),
|
|
42555
41438
|
environment: process.env,
|
|
@@ -42558,18 +41441,6 @@ async function main() {
|
|
|
42558
41441
|
process.stdout.write(formatAgentDiagnostics(inventory, arguments_[0] === "--json"));
|
|
42559
41442
|
return;
|
|
42560
41443
|
}
|
|
42561
|
-
if (command === "bot") {
|
|
42562
|
-
if (process.argv[3] !== "message" || process.argv[4] !== "send") {
|
|
42563
|
-
throw new BotMessageCommandError(
|
|
42564
|
-
"invalid_request",
|
|
42565
|
-
"Usage: mobius bot message send --target <current|alias> --text <message>"
|
|
42566
|
-
);
|
|
42567
|
-
}
|
|
42568
|
-
const outboundMessageId = await executeBotMessageCommand(process.argv.slice(5), process.env, shutdown.signal);
|
|
42569
|
-
process.stdout.write(`${JSON.stringify({ outboundMessageId })}
|
|
42570
|
-
`);
|
|
42571
|
-
return;
|
|
42572
|
-
}
|
|
42573
41444
|
let config2;
|
|
42574
41445
|
if (command === "pair") {
|
|
42575
41446
|
process.stdout.write(`mobius version: ${package_default.version}
|
|
@@ -42604,8 +41475,7 @@ try {
|
|
|
42604
41475
|
} catch (error62) {
|
|
42605
41476
|
if (!shutdown.signal.aborted) {
|
|
42606
41477
|
const message = error62 instanceof Error ? error62.message : "Unknown failure";
|
|
42607
|
-
|
|
42608
|
-
process.stderr.write(`Mobius daemon failed: ${code}${message}
|
|
41478
|
+
process.stderr.write(`Mobius daemon failed: ${message}
|
|
42609
41479
|
`);
|
|
42610
41480
|
process.exitCode = 1;
|
|
42611
41481
|
}
|