@moxt-ai/mobius 0.0.48 → 0.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/acp/session-manager.d.ts +2 -1
- package/dist/acp/session-manager.d.ts.map +1 -1
- package/dist/acp/session-manager.js +34 -11
- package/dist/acp/session-manager.js.map +1 -1
- package/dist/agent-catalog/publish-agent-catalog.d.ts.map +1 -1
- package/dist/agent-catalog/publish-agent-catalog.js +0 -1
- package/dist/agent-catalog/publish-agent-catalog.js.map +1 -1
- package/dist/artifacts/local-file-streamer.d.ts +3 -0
- package/dist/artifacts/local-file-streamer.d.ts.map +1 -0
- package/dist/artifacts/local-file-streamer.js +82 -0
- package/dist/artifacts/local-file-streamer.js.map +1 -0
- package/dist/authorization/local-raster.d.ts +4 -3
- package/dist/authorization/local-raster.d.ts.map +1 -1
- package/dist/authorization/local-raster.js +22 -12
- package/dist/authorization/local-raster.js.map +1 -1
- package/dist/cli.js +1227 -1798
- package/dist/cli.js.map +4 -4
- package/dist/config.d.ts +21 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +32 -2
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +2 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1280 -1839
- package/dist/index.js.map +4 -4
- package/dist/native-sessions/history-images.js +1 -1
- package/dist/native-sessions/history-images.js.map +1 -1
- package/dist/pairing/pair-local-machine.d.ts +5 -2
- package/dist/pairing/pair-local-machine.d.ts.map +1 -1
- package/dist/pairing/pair-local-machine.js +93 -112
- package/dist/pairing/pair-local-machine.js.map +1 -1
- package/dist/run-daemon.d.ts.map +1 -1
- package/dist/run-daemon.js +30 -275
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.d.ts +2 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +1028 -1483
- package/dist/runtime.js.map +4 -4
- package/dist/storage/runtime-installation-store.d.ts +53 -0
- package/dist/storage/runtime-installation-store.d.ts.map +1 -0
- package/dist/storage/runtime-installation-store.js +491 -0
- package/dist/storage/runtime-installation-store.js.map +1 -0
- package/package.json +1 -1
- package/dist/bots/bot-context-applicator.d.ts +0 -14
- package/dist/bots/bot-context-applicator.d.ts.map +0 -1
- package/dist/bots/bot-context-applicator.js +0 -32
- package/dist/bots/bot-context-applicator.js.map +0 -1
- package/dist/bots/bot-execution-context.d.ts +0 -19
- package/dist/bots/bot-execution-context.d.ts.map +0 -1
- package/dist/bots/bot-execution-context.js +0 -75
- package/dist/bots/bot-execution-context.js.map +0 -1
- package/dist/bots/bot-message-command.d.ts +0 -6
- package/dist/bots/bot-message-command.d.ts.map +0 -1
- package/dist/bots/bot-message-command.js +0 -140
- package/dist/bots/bot-message-command.js.map +0 -1
- package/dist/bots/bot-outbound-ipc.d.ts +0 -12
- package/dist/bots/bot-outbound-ipc.d.ts.map +0 -1
- package/dist/bots/bot-outbound-ipc.js +0 -245
- package/dist/bots/bot-outbound-ipc.js.map +0 -1
- package/dist/bots/local-bot-execution-authorizer.d.ts +0 -23
- package/dist/bots/local-bot-execution-authorizer.d.ts.map +0 -1
- package/dist/bots/local-bot-execution-authorizer.js +0 -62
- package/dist/bots/local-bot-execution-authorizer.js.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -11,7 +11,7 @@ import { mkdir as mkdir5 } from "node:fs/promises";
|
|
|
11
11
|
// package.json
|
|
12
12
|
var package_default = {
|
|
13
13
|
name: "@moxt-ai/mobius",
|
|
14
|
-
version: "0.0.
|
|
14
|
+
version: "0.0.50",
|
|
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
|
}
|
|
@@ -5691,7 +5691,7 @@ var recursive = /* @__PURE__ */ new WeakMap();
|
|
|
5691
5691
|
var NONE = 0;
|
|
5692
5692
|
var ASSUMED = 1;
|
|
5693
5693
|
var PROVEN = 2;
|
|
5694
|
-
function isRecursive(inst, stack,
|
|
5694
|
+
function isRecursive(inst, stack, resolve7) {
|
|
5695
5695
|
const cached2 = recursive.get(inst);
|
|
5696
5696
|
if (cached2 !== void 0)
|
|
5697
5697
|
return cached2 ? PROVEN : NONE;
|
|
@@ -5701,7 +5701,7 @@ function isRecursive(inst, stack, resolve5) {
|
|
|
5701
5701
|
let result = NONE;
|
|
5702
5702
|
const check2 = (child) => {
|
|
5703
5703
|
if (result !== PROVEN && child?._zod) {
|
|
5704
|
-
const answer = isRecursive(child, stack,
|
|
5704
|
+
const answer = isRecursive(child, stack, resolve7);
|
|
5705
5705
|
if (answer > result)
|
|
5706
5706
|
result = answer;
|
|
5707
5707
|
}
|
|
@@ -5712,7 +5712,7 @@ function isRecursive(inst, stack, resolve5) {
|
|
|
5712
5712
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
5713
5713
|
if (spread && !desc.enumerable)
|
|
5714
5714
|
continue;
|
|
5715
|
-
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack,
|
|
5715
|
+
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve7) : NONE;
|
|
5716
5716
|
if (child > answer)
|
|
5717
5717
|
answer = child;
|
|
5718
5718
|
}
|
|
@@ -5779,7 +5779,7 @@ function isRecursive(inst, stack, resolve5) {
|
|
|
5779
5779
|
break;
|
|
5780
5780
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
5781
5781
|
case "lazy": {
|
|
5782
|
-
const inner = def._cachedInner ?? (
|
|
5782
|
+
const inner = def._cachedInner ?? (resolve7 ? inst._zod.innerType : void 0);
|
|
5783
5783
|
merge2(inner ? isRecursive(inner, stack, false) : ASSUMED);
|
|
5784
5784
|
break;
|
|
5785
5785
|
}
|
|
@@ -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,198 +24123,599 @@ async function discoverLocalAgentInventory(options) {
|
|
|
24398
24123
|
return new LocalAgentInventory(discoveries);
|
|
24399
24124
|
}
|
|
24400
24125
|
|
|
24401
|
-
// src/
|
|
24402
|
-
import {
|
|
24403
|
-
|
|
24404
|
-
|
|
24405
|
-
|
|
24406
|
-
|
|
24126
|
+
// src/config.ts
|
|
24127
|
+
import { join as join14, resolve as resolve3 } from "node:path";
|
|
24128
|
+
function loadDefaultWorkspace(environment = process.env) {
|
|
24129
|
+
const { MOBIUS_DEFAULT_WORKSPACE: configuredWorkspace } = environment;
|
|
24130
|
+
return configuredWorkspace ?? join14(readStateDirectory(environment), "workspace");
|
|
24131
|
+
}
|
|
24132
|
+
var DaemonLocalContext = class {
|
|
24133
|
+
environment;
|
|
24134
|
+
stateDirectory;
|
|
24135
|
+
constructor(stateDirectory, environment = process.env) {
|
|
24136
|
+
this.stateDirectory = resolve3(stateDirectory);
|
|
24137
|
+
this.environment = Object.freeze({ ...environment, MOBIUS_STATE_DIRECTORY: this.stateDirectory });
|
|
24138
|
+
}
|
|
24139
|
+
};
|
|
24140
|
+
var DaemonReconnectTarget = class {
|
|
24141
|
+
};
|
|
24142
|
+
var OpaqueDaemonReconnectTarget = class extends DaemonReconnectTarget {
|
|
24143
|
+
connectionId;
|
|
24144
|
+
commandArgument;
|
|
24145
|
+
constructor(connectionId2) {
|
|
24146
|
+
super();
|
|
24147
|
+
this.connectionId = connectionId2;
|
|
24148
|
+
this.commandArgument = `--connection ${connectionId2}`;
|
|
24149
|
+
}
|
|
24150
|
+
};
|
|
24151
|
+
var ChannelDaemonReconnectTarget = class extends DaemonReconnectTarget {
|
|
24152
|
+
channelId;
|
|
24153
|
+
commandArgument;
|
|
24154
|
+
constructor(channelId) {
|
|
24155
|
+
super();
|
|
24156
|
+
this.channelId = channelId;
|
|
24157
|
+
this.commandArgument = `--channel ${channelId}`;
|
|
24158
|
+
}
|
|
24159
|
+
};
|
|
24160
|
+
function createDaemonConfig(connection, agents = [], installableAgents = [], localContext = new DaemonLocalContext(readStateDirectory(), process.env), reconnectTarget = new ChannelDaemonReconnectTarget(connection.channelId)) {
|
|
24161
|
+
return {
|
|
24162
|
+
agents,
|
|
24163
|
+
defaultWorkspace: connection.defaultWorkspace,
|
|
24164
|
+
auditDatabasePath: connection.auditDatabasePath,
|
|
24165
|
+
bindingId: "workspace",
|
|
24166
|
+
catalog: new LocalAgentCatalog(agents, installableAgents),
|
|
24167
|
+
channelId: connection.channelId,
|
|
24168
|
+
installableAgents,
|
|
24169
|
+
localContext,
|
|
24170
|
+
reconnectTarget,
|
|
24171
|
+
relayUrl: connection.relayUrl
|
|
24172
|
+
};
|
|
24173
|
+
}
|
|
24174
|
+
|
|
24175
|
+
// src/pairing/pair-local-machine.ts
|
|
24176
|
+
import { mkdir as mkdir4, realpath as realpath6, stat as stat5 } from "node:fs/promises";
|
|
24177
|
+
import { hostname as hostname3 } from "node:os";
|
|
24178
|
+
import { basename, resolve as resolve5 } from "node:path";
|
|
24179
|
+
import { fetch as fetch2 } from "undici";
|
|
24180
|
+
|
|
24181
|
+
// src/storage/runtime-installation-store.ts
|
|
24182
|
+
import { createHash as createHash2, randomUUID } from "node:crypto";
|
|
24183
|
+
import { mkdir as mkdir3, open as open4, rename as rename3, unlink, writeFile as writeFile2 } from "node:fs/promises";
|
|
24184
|
+
import { dirname as dirname3, join as join15, resolve as resolve4 } from "node:path";
|
|
24185
|
+
var APPLICATION_ID_PATTERN = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+){1,31}$/;
|
|
24186
|
+
var CONNECTION_ID_PATTERN = /^mcn_[a-f0-9]{32}$/;
|
|
24187
|
+
var INSTALLATION_ID_PATTERN = /^min_[a-f0-9]{32}$/;
|
|
24188
|
+
var IDENTIFIER_PATTERN4 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
24189
|
+
var RUNTIME_CREDENTIAL_PATTERN = /^[a-zA-Z0-9_-]{32,256}$/;
|
|
24190
|
+
var MAX_FILE_LENGTH = 16 * 1024;
|
|
24191
|
+
var INSTALLATION_POINTER_KEYS = ["installationId", "version"];
|
|
24192
|
+
var CHANNEL_INDEX_KEYS = [
|
|
24193
|
+
"applicationId",
|
|
24194
|
+
"channelId",
|
|
24195
|
+
"connectionId",
|
|
24196
|
+
"installationId",
|
|
24197
|
+
"version"
|
|
24198
|
+
];
|
|
24199
|
+
var VERIFIED_CONNECTION_KEYS = [
|
|
24200
|
+
"applicationId",
|
|
24201
|
+
"channelId",
|
|
24202
|
+
"connectionId",
|
|
24203
|
+
"defaultWorkspace",
|
|
24204
|
+
"installationId",
|
|
24205
|
+
"kind",
|
|
24206
|
+
"relayOrigin",
|
|
24207
|
+
"runtimeCredential",
|
|
24208
|
+
"runtimeId",
|
|
24209
|
+
"version"
|
|
24210
|
+
];
|
|
24211
|
+
var IMPORTED_LEGACY_CONNECTION_KEYS = [
|
|
24212
|
+
"applicationId",
|
|
24213
|
+
"channelId",
|
|
24214
|
+
"connectionId",
|
|
24215
|
+
"defaultWorkspace",
|
|
24216
|
+
"installationId",
|
|
24217
|
+
"kind",
|
|
24218
|
+
"relayOrigin",
|
|
24219
|
+
"runtimeCredential",
|
|
24220
|
+
"version"
|
|
24221
|
+
];
|
|
24222
|
+
var CURRENT_CONNECTION_KEYS = [
|
|
24223
|
+
"defaultWorkspace",
|
|
24224
|
+
"channelId",
|
|
24225
|
+
"relayOrigin",
|
|
24226
|
+
"runtimeCredential"
|
|
24227
|
+
];
|
|
24228
|
+
var LEGACY_CONNECTION_KEYS = ["defaultWorkspace", "channelId", "daemonToken", "relayOrigin"];
|
|
24229
|
+
var RuntimeInstallationStoreError = class extends Error {
|
|
24407
24230
|
code;
|
|
24408
24231
|
constructor(code, message, options = {}) {
|
|
24409
24232
|
super(message, options);
|
|
24410
24233
|
this.code = code;
|
|
24411
|
-
this.name = "
|
|
24234
|
+
this.name = "RuntimeInstallationStoreError";
|
|
24412
24235
|
}
|
|
24413
24236
|
};
|
|
24414
|
-
|
|
24237
|
+
var StoredRuntimeConnection = class {
|
|
24238
|
+
applicationId;
|
|
24239
|
+
channelId;
|
|
24240
|
+
connectionId;
|
|
24241
|
+
defaultWorkspace;
|
|
24242
|
+
installationId;
|
|
24243
|
+
relayOrigin;
|
|
24244
|
+
runtimeCredential;
|
|
24245
|
+
constructor(applicationId, installationId2, connectionId2, channelId, defaultWorkspace, relayOrigin, runtimeCredential2) {
|
|
24246
|
+
this.applicationId = applicationId;
|
|
24247
|
+
this.channelId = channelId;
|
|
24248
|
+
this.connectionId = connectionId2;
|
|
24249
|
+
this.defaultWorkspace = defaultWorkspace;
|
|
24250
|
+
this.installationId = installationId2;
|
|
24251
|
+
this.relayOrigin = relayOrigin;
|
|
24252
|
+
this.runtimeCredential = runtimeCredential2;
|
|
24253
|
+
}
|
|
24254
|
+
};
|
|
24255
|
+
var VerifiedRuntimeConnection = class extends StoredRuntimeConnection {
|
|
24256
|
+
kind = "verified";
|
|
24257
|
+
runtimeId;
|
|
24258
|
+
constructor(applicationId, installationId2, connectionId2, channelId, defaultWorkspace, relayOrigin, runtimeCredential2, runtimeId) {
|
|
24259
|
+
super(applicationId, installationId2, connectionId2, channelId, defaultWorkspace, relayOrigin, runtimeCredential2);
|
|
24260
|
+
this.runtimeId = runtimeId;
|
|
24261
|
+
}
|
|
24262
|
+
};
|
|
24263
|
+
var ImportedLegacyRuntimeConnection = class extends StoredRuntimeConnection {
|
|
24264
|
+
kind = "legacy_imported";
|
|
24265
|
+
constructor(applicationId, installationId2, connectionId2, channelId, defaultWorkspace, relayOrigin, runtimeCredential2) {
|
|
24266
|
+
super(applicationId, installationId2, connectionId2, channelId, defaultWorkspace, relayOrigin, runtimeCredential2);
|
|
24267
|
+
}
|
|
24268
|
+
};
|
|
24269
|
+
function isRecord5(value) {
|
|
24415
24270
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24416
24271
|
}
|
|
24417
|
-
function
|
|
24418
|
-
const
|
|
24419
|
-
|
|
24420
|
-
|
|
24421
|
-
|
|
24422
|
-
|
|
24423
|
-
|
|
24272
|
+
function hasExactKeys(value, expectedKeys) {
|
|
24273
|
+
const keys = Object.keys(value);
|
|
24274
|
+
return keys.length === expectedKeys.length && expectedKeys.every((key) => Object.hasOwn(value, key));
|
|
24275
|
+
}
|
|
24276
|
+
function isNodeError(error62, code) {
|
|
24277
|
+
return typeof error62 === "object" && error62 !== null && "code" in error62 && error62.code === code;
|
|
24278
|
+
}
|
|
24279
|
+
function validateApplicationId(value) {
|
|
24280
|
+
if (!APPLICATION_ID_PATTERN.test(value)) {
|
|
24281
|
+
throw new RuntimeInstallationStoreError("invalid_application_id", "The application ID is invalid");
|
|
24424
24282
|
}
|
|
24425
24283
|
return value;
|
|
24426
24284
|
}
|
|
24427
|
-
function
|
|
24428
|
-
|
|
24429
|
-
|
|
24430
|
-
throw new BotMessageCommandError(
|
|
24431
|
-
"invalid_request",
|
|
24432
|
-
"Usage: mobius bot message send --target <current|alias> --text <message>"
|
|
24433
|
-
);
|
|
24285
|
+
function validateConnectionId(value) {
|
|
24286
|
+
if (!CONNECTION_ID_PATTERN.test(value)) {
|
|
24287
|
+
throw new RuntimeInstallationStoreError("invalid_connection_id", "The local connection ID is invalid");
|
|
24434
24288
|
}
|
|
24435
|
-
|
|
24436
|
-
|
|
24437
|
-
|
|
24289
|
+
return value;
|
|
24290
|
+
}
|
|
24291
|
+
function validateInstallationId(value) {
|
|
24292
|
+
if (!INSTALLATION_ID_PATTERN.test(value)) {
|
|
24293
|
+
throw new RuntimeInstallationStoreError("invalid_installation_id", "The installation ID is invalid");
|
|
24438
24294
|
}
|
|
24439
24295
|
return value;
|
|
24440
24296
|
}
|
|
24441
|
-
function
|
|
24442
|
-
if (
|
|
24443
|
-
throw new
|
|
24444
|
-
"invalid_request",
|
|
24445
|
-
"Usage: mobius bot message send --target <current|alias> --text <message>"
|
|
24446
|
-
);
|
|
24297
|
+
function validateIdentifier(value, code) {
|
|
24298
|
+
if (!IDENTIFIER_PATTERN4.test(value)) {
|
|
24299
|
+
throw new RuntimeInstallationStoreError(code, "The saved Runtime connection is invalid");
|
|
24447
24300
|
}
|
|
24448
|
-
|
|
24449
|
-
|
|
24450
|
-
|
|
24451
|
-
|
|
24452
|
-
|
|
24453
|
-
);
|
|
24301
|
+
return value;
|
|
24302
|
+
}
|
|
24303
|
+
function validateRuntimeCredential(value) {
|
|
24304
|
+
if (!RUNTIME_CREDENTIAL_PATTERN.test(value)) {
|
|
24305
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
24454
24306
|
}
|
|
24307
|
+
return value;
|
|
24455
24308
|
}
|
|
24456
|
-
function
|
|
24457
|
-
let
|
|
24309
|
+
function parseRelayOrigin(value) {
|
|
24310
|
+
let origin;
|
|
24458
24311
|
try {
|
|
24459
|
-
|
|
24312
|
+
origin = new URL(value);
|
|
24460
24313
|
} catch (cause) {
|
|
24461
|
-
throw new
|
|
24314
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid", {
|
|
24462
24315
|
cause
|
|
24463
24316
|
});
|
|
24464
24317
|
}
|
|
24465
|
-
if (
|
|
24466
|
-
throw new
|
|
24318
|
+
if (origin.protocol !== "https:" && origin.protocol !== "http:" || origin.username.length > 0 || origin.password.length > 0 || origin.protocol === "http:" && origin.hostname !== "127.0.0.1" && origin.hostname !== "localhost") {
|
|
24319
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
24320
|
+
}
|
|
24321
|
+
origin.hash = "";
|
|
24322
|
+
origin.pathname = "/";
|
|
24323
|
+
origin.search = "";
|
|
24324
|
+
return origin;
|
|
24325
|
+
}
|
|
24326
|
+
function connectionId() {
|
|
24327
|
+
return `mcn_${randomUUID().replaceAll("-", "")}`;
|
|
24328
|
+
}
|
|
24329
|
+
function installationId() {
|
|
24330
|
+
return `min_${randomUUID().replaceAll("-", "")}`;
|
|
24331
|
+
}
|
|
24332
|
+
function channelIndexFileName(channelId) {
|
|
24333
|
+
return `mci_${createHash2("sha256").update(channelId).digest("hex")}.json`;
|
|
24334
|
+
}
|
|
24335
|
+
function decodeInstallationPointer(value) {
|
|
24336
|
+
if (!isRecord5(value) || !hasExactKeys(value, INSTALLATION_POINTER_KEYS) || value["version"] !== 1) {
|
|
24337
|
+
throw new RuntimeInstallationStoreError("invalid_installation", "The local installation record is invalid");
|
|
24338
|
+
}
|
|
24339
|
+
const storedInstallationId = value["installationId"];
|
|
24340
|
+
if (typeof storedInstallationId !== "string") {
|
|
24341
|
+
throw new RuntimeInstallationStoreError("invalid_installation", "The local installation record is invalid");
|
|
24342
|
+
}
|
|
24343
|
+
return { installationId: validateInstallationId(storedInstallationId) };
|
|
24344
|
+
}
|
|
24345
|
+
function decodeChannelIndex(value) {
|
|
24346
|
+
if (!isRecord5(value) || !hasExactKeys(value, CHANNEL_INDEX_KEYS) || value["version"] !== 1) {
|
|
24347
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
24348
|
+
}
|
|
24349
|
+
const applicationId = value["applicationId"];
|
|
24350
|
+
const channelId = value["channelId"];
|
|
24351
|
+
const connectionId2 = value["connectionId"];
|
|
24352
|
+
const storedInstallationId = value["installationId"];
|
|
24353
|
+
if (typeof applicationId !== "string" || typeof channelId !== "string" || typeof connectionId2 !== "string" || typeof storedInstallationId !== "string") {
|
|
24354
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
24355
|
+
}
|
|
24356
|
+
return {
|
|
24357
|
+
applicationId: validateApplicationId(applicationId),
|
|
24358
|
+
channelId: validateIdentifier(channelId, "invalid_connection"),
|
|
24359
|
+
connectionId: validateConnectionId(connectionId2),
|
|
24360
|
+
installationId: validateInstallationId(storedInstallationId)
|
|
24361
|
+
};
|
|
24362
|
+
}
|
|
24363
|
+
function decodeVerifiedConnection(value) {
|
|
24364
|
+
if (!hasExactKeys(value, VERIFIED_CONNECTION_KEYS) || value["kind"] !== "verified" || value["version"] !== 1) {
|
|
24365
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
24366
|
+
}
|
|
24367
|
+
const applicationId = value["applicationId"];
|
|
24368
|
+
const channelId = value["channelId"];
|
|
24369
|
+
const connectionId2 = value["connectionId"];
|
|
24370
|
+
const defaultWorkspace = value["defaultWorkspace"];
|
|
24371
|
+
const storedInstallationId = value["installationId"];
|
|
24372
|
+
const relayOrigin = value["relayOrigin"];
|
|
24373
|
+
const runtimeCredential2 = value["runtimeCredential"];
|
|
24374
|
+
const runtimeId = value["runtimeId"];
|
|
24375
|
+
if (typeof applicationId !== "string" || typeof channelId !== "string" || typeof connectionId2 !== "string" || typeof defaultWorkspace !== "string" || typeof storedInstallationId !== "string" || typeof relayOrigin !== "string" || typeof runtimeCredential2 !== "string" || typeof runtimeId !== "string") {
|
|
24376
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
24377
|
+
}
|
|
24378
|
+
return new VerifiedRuntimeConnection(
|
|
24379
|
+
validateApplicationId(applicationId),
|
|
24380
|
+
validateInstallationId(storedInstallationId),
|
|
24381
|
+
validateConnectionId(connectionId2),
|
|
24382
|
+
validateIdentifier(channelId, "invalid_connection"),
|
|
24383
|
+
defaultWorkspace,
|
|
24384
|
+
parseRelayOrigin(relayOrigin),
|
|
24385
|
+
validateRuntimeCredential(runtimeCredential2),
|
|
24386
|
+
validateIdentifier(runtimeId, "invalid_connection")
|
|
24387
|
+
);
|
|
24388
|
+
}
|
|
24389
|
+
function decodeImportedLegacyConnection(value) {
|
|
24390
|
+
if (!hasExactKeys(value, IMPORTED_LEGACY_CONNECTION_KEYS) || value["kind"] !== "legacy_imported" || value["version"] !== 1) {
|
|
24391
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
24392
|
+
}
|
|
24393
|
+
const applicationId = value["applicationId"];
|
|
24394
|
+
const channelId = value["channelId"];
|
|
24395
|
+
const connectionId2 = value["connectionId"];
|
|
24396
|
+
const defaultWorkspace = value["defaultWorkspace"];
|
|
24397
|
+
const storedInstallationId = value["installationId"];
|
|
24398
|
+
const relayOrigin = value["relayOrigin"];
|
|
24399
|
+
const runtimeCredential2 = value["runtimeCredential"];
|
|
24400
|
+
if (typeof applicationId !== "string" || typeof channelId !== "string" || typeof connectionId2 !== "string" || typeof defaultWorkspace !== "string" || typeof storedInstallationId !== "string" || typeof relayOrigin !== "string" || typeof runtimeCredential2 !== "string") {
|
|
24401
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
24402
|
+
}
|
|
24403
|
+
return new ImportedLegacyRuntimeConnection(
|
|
24404
|
+
validateApplicationId(applicationId),
|
|
24405
|
+
validateInstallationId(storedInstallationId),
|
|
24406
|
+
validateConnectionId(connectionId2),
|
|
24407
|
+
validateIdentifier(channelId, "invalid_connection"),
|
|
24408
|
+
defaultWorkspace,
|
|
24409
|
+
parseRelayOrigin(relayOrigin),
|
|
24410
|
+
validateRuntimeCredential(runtimeCredential2)
|
|
24411
|
+
);
|
|
24412
|
+
}
|
|
24413
|
+
function decodeConnection(value) {
|
|
24414
|
+
if (!isRecord5(value)) {
|
|
24415
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
24416
|
+
}
|
|
24417
|
+
if (value["kind"] === "verified") {
|
|
24418
|
+
return decodeVerifiedConnection(value);
|
|
24467
24419
|
}
|
|
24468
|
-
if (value["
|
|
24469
|
-
return value
|
|
24420
|
+
if (value["kind"] === "legacy_imported") {
|
|
24421
|
+
return decodeImportedLegacyConnection(value);
|
|
24470
24422
|
}
|
|
24471
|
-
|
|
24472
|
-
|
|
24473
|
-
|
|
24423
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
24424
|
+
}
|
|
24425
|
+
function decodeLegacyConnection(value, expectedChannelId) {
|
|
24426
|
+
if (!isRecord5(value) || !hasExactKeys(value, CURRENT_CONNECTION_KEYS) && !hasExactKeys(value, LEGACY_CONNECTION_KEYS)) {
|
|
24427
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
24474
24428
|
}
|
|
24475
|
-
|
|
24429
|
+
const channelId = value["channelId"];
|
|
24430
|
+
const defaultWorkspace = value["defaultWorkspace"];
|
|
24431
|
+
const relayOrigin = value["relayOrigin"];
|
|
24432
|
+
const runtimeCredential2 = value["runtimeCredential"] ?? value["daemonToken"];
|
|
24433
|
+
if (typeof channelId !== "string" || channelId !== expectedChannelId || typeof defaultWorkspace !== "string" || typeof relayOrigin !== "string" || typeof runtimeCredential2 !== "string") {
|
|
24434
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
24435
|
+
}
|
|
24436
|
+
return {
|
|
24437
|
+
channelId: validateIdentifier(channelId, "invalid_connection"),
|
|
24438
|
+
defaultWorkspace,
|
|
24439
|
+
relayOrigin: parseRelayOrigin(relayOrigin),
|
|
24440
|
+
runtimeCredential: validateRuntimeCredential(runtimeCredential2)
|
|
24441
|
+
};
|
|
24476
24442
|
}
|
|
24477
|
-
async function
|
|
24443
|
+
async function readJsonFile(path2, signal, missingCode) {
|
|
24478
24444
|
signal.throwIfAborted();
|
|
24479
|
-
|
|
24480
|
-
|
|
24481
|
-
|
|
24482
|
-
|
|
24483
|
-
|
|
24484
|
-
|
|
24485
|
-
|
|
24486
|
-
|
|
24487
|
-
}
|
|
24488
|
-
|
|
24489
|
-
|
|
24490
|
-
|
|
24491
|
-
|
|
24492
|
-
|
|
24493
|
-
finish();
|
|
24494
|
-
if (error62 instanceof BotMessageCommandError) {
|
|
24495
|
-
reject(error62);
|
|
24496
|
-
return;
|
|
24445
|
+
let handle;
|
|
24446
|
+
try {
|
|
24447
|
+
handle = await open4(path2, "r");
|
|
24448
|
+
} catch (cause) {
|
|
24449
|
+
if (isNodeError(cause, "ENOENT")) {
|
|
24450
|
+
throw new RuntimeInstallationStoreError(missingCode, "The saved Runtime connection was not found", {
|
|
24451
|
+
cause
|
|
24452
|
+
});
|
|
24453
|
+
}
|
|
24454
|
+
throw new RuntimeInstallationStoreError(
|
|
24455
|
+
"connection_unavailable",
|
|
24456
|
+
"The saved Runtime connection cannot be read",
|
|
24457
|
+
{
|
|
24458
|
+
cause
|
|
24497
24459
|
}
|
|
24498
|
-
|
|
24499
|
-
|
|
24500
|
-
|
|
24501
|
-
|
|
24502
|
-
|
|
24503
|
-
|
|
24504
|
-
);
|
|
24505
|
-
}
|
|
24506
|
-
|
|
24507
|
-
|
|
24508
|
-
|
|
24460
|
+
);
|
|
24461
|
+
}
|
|
24462
|
+
let encoded = "";
|
|
24463
|
+
try {
|
|
24464
|
+
const metadata = await handle.stat();
|
|
24465
|
+
if (!metadata.isFile() || metadata.size > MAX_FILE_LENGTH) {
|
|
24466
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid");
|
|
24467
|
+
}
|
|
24468
|
+
encoded = await handle.readFile({ encoding: "utf8" });
|
|
24469
|
+
} finally {
|
|
24470
|
+
await handle.close();
|
|
24471
|
+
}
|
|
24472
|
+
signal.throwIfAborted();
|
|
24473
|
+
try {
|
|
24474
|
+
return JSON.parse(encoded);
|
|
24475
|
+
} catch (cause) {
|
|
24476
|
+
throw new RuntimeInstallationStoreError("invalid_connection", "The saved Runtime connection is invalid", {
|
|
24477
|
+
cause
|
|
24509
24478
|
});
|
|
24510
|
-
|
|
24511
|
-
|
|
24512
|
-
|
|
24513
|
-
|
|
24514
|
-
|
|
24515
|
-
|
|
24516
|
-
|
|
24517
|
-
|
|
24518
|
-
|
|
24519
|
-
|
|
24479
|
+
}
|
|
24480
|
+
}
|
|
24481
|
+
async function writeJsonAtomically(path2, value, signal) {
|
|
24482
|
+
signal.throwIfAborted();
|
|
24483
|
+
const directory = dirname3(path2);
|
|
24484
|
+
const temporaryPath = join15(directory, `.${randomUUID()}.tmp`);
|
|
24485
|
+
try {
|
|
24486
|
+
await mkdir3(directory, { mode: 448, recursive: true });
|
|
24487
|
+
signal.throwIfAborted();
|
|
24488
|
+
await writeFile2(temporaryPath, `${JSON.stringify(value, null, 2)}
|
|
24489
|
+
`, { flag: "wx", mode: 384 });
|
|
24490
|
+
signal.throwIfAborted();
|
|
24491
|
+
await rename3(temporaryPath, path2);
|
|
24492
|
+
} catch (cause) {
|
|
24493
|
+
await unlink(temporaryPath).catch(() => void 0);
|
|
24494
|
+
signal.throwIfAborted();
|
|
24495
|
+
throw new RuntimeInstallationStoreError("connection_unavailable", "The local Runtime state cannot be written", {
|
|
24496
|
+
cause
|
|
24520
24497
|
});
|
|
24521
|
-
|
|
24522
|
-
|
|
24523
|
-
|
|
24498
|
+
}
|
|
24499
|
+
}
|
|
24500
|
+
var RuntimeInstallationStore = class _RuntimeInstallationStore {
|
|
24501
|
+
applicationId;
|
|
24502
|
+
installationId;
|
|
24503
|
+
stateDirectory;
|
|
24504
|
+
#channelDirectory;
|
|
24505
|
+
#connectionDirectory;
|
|
24506
|
+
constructor(applicationId, installationId2, stateDirectory) {
|
|
24507
|
+
this.applicationId = applicationId;
|
|
24508
|
+
this.installationId = installationId2;
|
|
24509
|
+
this.stateDirectory = stateDirectory;
|
|
24510
|
+
this.#channelDirectory = join15(stateDirectory, "channels");
|
|
24511
|
+
this.#connectionDirectory = join15(stateDirectory, "connections");
|
|
24512
|
+
}
|
|
24513
|
+
static open = async (options, signal) => {
|
|
24514
|
+
signal.throwIfAborted();
|
|
24515
|
+
const applicationId = validateApplicationId(options.applicationId);
|
|
24516
|
+
const rootDirectory = resolve4(options.stateDirectory);
|
|
24517
|
+
const applicationDirectory = join15(rootDirectory, "installations", applicationId);
|
|
24518
|
+
try {
|
|
24519
|
+
await mkdir3(applicationDirectory, { mode: 448, recursive: true });
|
|
24520
|
+
} catch (cause) {
|
|
24521
|
+
throw new RuntimeInstallationStoreError(
|
|
24522
|
+
"installation_unavailable",
|
|
24523
|
+
"The local installation cannot be initialized",
|
|
24524
|
+
{
|
|
24525
|
+
cause
|
|
24526
|
+
}
|
|
24527
|
+
);
|
|
24528
|
+
}
|
|
24529
|
+
const storedInstallationId = await readOrCreateInstallationId(applicationDirectory, signal);
|
|
24530
|
+
const stateDirectory = join15(applicationDirectory, storedInstallationId);
|
|
24531
|
+
try {
|
|
24532
|
+
await mkdir3(stateDirectory, { mode: 448, recursive: true });
|
|
24533
|
+
} catch (cause) {
|
|
24534
|
+
throw new RuntimeInstallationStoreError(
|
|
24535
|
+
"installation_unavailable",
|
|
24536
|
+
"The local installation cannot be initialized",
|
|
24537
|
+
{
|
|
24538
|
+
cause
|
|
24539
|
+
}
|
|
24540
|
+
);
|
|
24541
|
+
}
|
|
24542
|
+
signal.throwIfAborted();
|
|
24543
|
+
return new _RuntimeInstallationStore(applicationId, storedInstallationId, stateDirectory);
|
|
24544
|
+
};
|
|
24545
|
+
connectionPath = (connectionId2) => join15(this.#connectionDirectory, `${validateConnectionId(connectionId2)}.json`);
|
|
24546
|
+
auditDatabasePath = (connectionId2) => join15(this.stateDirectory, "audit", `${validateConnectionId(connectionId2)}.sqlite`);
|
|
24547
|
+
channelIndexPath = (channelId) => join15(this.#channelDirectory, channelIndexFileName(validateIdentifier(channelId, "invalid_channel_id")));
|
|
24548
|
+
readConnection = async (connectionId2, signal) => {
|
|
24549
|
+
const stored = decodeConnection(
|
|
24550
|
+
await readJsonFile(this.connectionPath(connectionId2), signal, "connection_not_found")
|
|
24551
|
+
);
|
|
24552
|
+
if (stored.applicationId !== this.applicationId || stored.installationId !== this.installationId) {
|
|
24553
|
+
throw new RuntimeInstallationStoreError(
|
|
24554
|
+
"connection_owner_mismatch",
|
|
24555
|
+
"The saved Runtime connection belongs to another installation"
|
|
24556
|
+
);
|
|
24557
|
+
}
|
|
24558
|
+
return stored;
|
|
24559
|
+
};
|
|
24560
|
+
#readConnectionForChannel = async (channelId, signal) => {
|
|
24561
|
+
const normalizedChannelId = validateIdentifier(channelId, "invalid_channel_id");
|
|
24562
|
+
const index2 = decodeChannelIndex(
|
|
24563
|
+
await readJsonFile(this.channelIndexPath(normalizedChannelId), signal, "connection_not_found")
|
|
24564
|
+
);
|
|
24565
|
+
if (index2.applicationId !== this.applicationId || index2.installationId !== this.installationId || index2.channelId !== normalizedChannelId) {
|
|
24566
|
+
throw new RuntimeInstallationStoreError(
|
|
24567
|
+
"connection_owner_mismatch",
|
|
24568
|
+
"The saved Runtime connection belongs to another installation"
|
|
24569
|
+
);
|
|
24570
|
+
}
|
|
24571
|
+
return await this.readConnection(index2.connectionId, signal);
|
|
24572
|
+
};
|
|
24573
|
+
migrateLegacyConnection = async (legacyStateDirectory, channelId, signal) => {
|
|
24574
|
+
try {
|
|
24575
|
+
return await this.#readConnectionForChannel(channelId, signal);
|
|
24576
|
+
} catch (cause) {
|
|
24577
|
+
if (!(cause instanceof RuntimeInstallationStoreError) || cause.code !== "connection_not_found") {
|
|
24578
|
+
throw cause;
|
|
24524
24579
|
}
|
|
24525
|
-
|
|
24526
|
-
|
|
24527
|
-
|
|
24528
|
-
|
|
24529
|
-
|
|
24530
|
-
|
|
24531
|
-
|
|
24532
|
-
|
|
24580
|
+
}
|
|
24581
|
+
return await this.importLegacyConnection(legacyStateDirectory, channelId, signal);
|
|
24582
|
+
};
|
|
24583
|
+
saveConnection = async (input2, signal) => {
|
|
24584
|
+
const stored = new VerifiedRuntimeConnection(
|
|
24585
|
+
this.applicationId,
|
|
24586
|
+
this.installationId,
|
|
24587
|
+
connectionId(),
|
|
24588
|
+
validateIdentifier(input2.channelId, "invalid_connection"),
|
|
24589
|
+
input2.defaultWorkspace,
|
|
24590
|
+
parseRelayOrigin(input2.relayOrigin.toString()),
|
|
24591
|
+
validateRuntimeCredential(input2.runtimeCredential),
|
|
24592
|
+
validateIdentifier(input2.runtimeId, "invalid_connection")
|
|
24593
|
+
);
|
|
24594
|
+
await this.writeConnection(stored, signal);
|
|
24595
|
+
return stored;
|
|
24596
|
+
};
|
|
24597
|
+
importLegacyConnection = async (legacyStateDirectory, channelId, signal) => {
|
|
24598
|
+
const normalizedChannelId = validateIdentifier(channelId, "invalid_channel_id");
|
|
24599
|
+
const legacyPath = join15(resolve4(legacyStateDirectory), "connections", `${normalizedChannelId}.json`);
|
|
24600
|
+
const legacy = decodeLegacyConnection(
|
|
24601
|
+
await readJsonFile(legacyPath, signal, "connection_not_found"),
|
|
24602
|
+
normalizedChannelId
|
|
24603
|
+
);
|
|
24604
|
+
const stored = new ImportedLegacyRuntimeConnection(
|
|
24605
|
+
this.applicationId,
|
|
24606
|
+
this.installationId,
|
|
24607
|
+
connectionId(),
|
|
24608
|
+
legacy.channelId,
|
|
24609
|
+
legacy.defaultWorkspace,
|
|
24610
|
+
legacy.relayOrigin,
|
|
24611
|
+
legacy.runtimeCredential
|
|
24612
|
+
);
|
|
24613
|
+
await this.writeConnection(stored, signal);
|
|
24614
|
+
return stored;
|
|
24615
|
+
};
|
|
24616
|
+
writeConnection = async (stored, signal) => {
|
|
24617
|
+
signal.throwIfAborted();
|
|
24618
|
+
try {
|
|
24619
|
+
await this.#readConnectionForChannel(stored.channelId, signal);
|
|
24620
|
+
throw new RuntimeInstallationStoreError(
|
|
24621
|
+
"connection_conflict",
|
|
24622
|
+
"A Runtime connection for this channel already exists in this installation"
|
|
24623
|
+
);
|
|
24624
|
+
} catch (cause) {
|
|
24625
|
+
if (!(cause instanceof RuntimeInstallationStoreError) || cause.code !== "connection_not_found") {
|
|
24626
|
+
throw cause;
|
|
24533
24627
|
}
|
|
24628
|
+
}
|
|
24629
|
+
const connectionPath = this.connectionPath(stored.connectionId);
|
|
24630
|
+
if (stored instanceof VerifiedRuntimeConnection) {
|
|
24631
|
+
await writeJsonAtomically(
|
|
24632
|
+
connectionPath,
|
|
24633
|
+
{
|
|
24634
|
+
applicationId: stored.applicationId,
|
|
24635
|
+
channelId: stored.channelId,
|
|
24636
|
+
connectionId: stored.connectionId,
|
|
24637
|
+
defaultWorkspace: stored.defaultWorkspace,
|
|
24638
|
+
installationId: stored.installationId,
|
|
24639
|
+
kind: stored.kind,
|
|
24640
|
+
relayOrigin: stored.relayOrigin.toString(),
|
|
24641
|
+
runtimeCredential: stored.runtimeCredential,
|
|
24642
|
+
runtimeId: stored.runtimeId,
|
|
24643
|
+
version: 1
|
|
24644
|
+
},
|
|
24645
|
+
signal
|
|
24646
|
+
);
|
|
24647
|
+
} else {
|
|
24648
|
+
await writeJsonAtomically(
|
|
24649
|
+
connectionPath,
|
|
24650
|
+
{
|
|
24651
|
+
applicationId: stored.applicationId,
|
|
24652
|
+
channelId: stored.channelId,
|
|
24653
|
+
connectionId: stored.connectionId,
|
|
24654
|
+
defaultWorkspace: stored.defaultWorkspace,
|
|
24655
|
+
installationId: stored.installationId,
|
|
24656
|
+
kind: stored.kind,
|
|
24657
|
+
relayOrigin: stored.relayOrigin.toString(),
|
|
24658
|
+
runtimeCredential: stored.runtimeCredential,
|
|
24659
|
+
version: 1
|
|
24660
|
+
},
|
|
24661
|
+
signal
|
|
24662
|
+
);
|
|
24663
|
+
}
|
|
24664
|
+
await writeJsonAtomically(
|
|
24665
|
+
this.channelIndexPath(stored.channelId),
|
|
24666
|
+
{
|
|
24667
|
+
applicationId: this.applicationId,
|
|
24668
|
+
channelId: stored.channelId,
|
|
24669
|
+
connectionId: stored.connectionId,
|
|
24670
|
+
installationId: this.installationId,
|
|
24671
|
+
version: 1
|
|
24672
|
+
},
|
|
24673
|
+
signal
|
|
24674
|
+
);
|
|
24675
|
+
};
|
|
24676
|
+
};
|
|
24677
|
+
async function readOrCreateInstallationId(applicationDirectory, signal) {
|
|
24678
|
+
const pointerPath = join15(applicationDirectory, "current.json");
|
|
24679
|
+
try {
|
|
24680
|
+
return decodeInstallationPointer(await readJsonFile(pointerPath, signal, "installation_not_found")).installationId;
|
|
24681
|
+
} catch (cause) {
|
|
24682
|
+
if (!(cause instanceof RuntimeInstallationStoreError) || cause.code !== "installation_not_found") {
|
|
24683
|
+
throw cause;
|
|
24684
|
+
}
|
|
24685
|
+
}
|
|
24686
|
+
const candidate = installationId();
|
|
24687
|
+
try {
|
|
24688
|
+
await writeFile2(pointerPath, `${JSON.stringify({ installationId: candidate, version: 1 })}
|
|
24689
|
+
`, {
|
|
24690
|
+
flag: "wx",
|
|
24691
|
+
mode: 384
|
|
24534
24692
|
});
|
|
24535
|
-
|
|
24536
|
-
})
|
|
24693
|
+
return candidate;
|
|
24694
|
+
} catch (cause) {
|
|
24695
|
+
if (!isNodeError(cause, "EEXIST")) {
|
|
24696
|
+
throw new RuntimeInstallationStoreError(
|
|
24697
|
+
"installation_unavailable",
|
|
24698
|
+
"The local installation cannot be initialized",
|
|
24699
|
+
{
|
|
24700
|
+
cause
|
|
24701
|
+
}
|
|
24702
|
+
);
|
|
24703
|
+
}
|
|
24704
|
+
return decodeInstallationPointer(await readJsonFile(pointerPath, signal, "installation_not_found")).installationId;
|
|
24705
|
+
}
|
|
24537
24706
|
}
|
|
24538
|
-
async function
|
|
24539
|
-
|
|
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
|
-
// src/config.ts
|
|
24560
|
-
import { join as join14 } from "node:path";
|
|
24561
|
-
function loadDefaultWorkspace(environment = process.env) {
|
|
24562
|
-
const { MOBIUS_DEFAULT_WORKSPACE: configuredWorkspace } = environment;
|
|
24563
|
-
return configuredWorkspace ?? join14(readStateDirectory(environment), "workspace");
|
|
24564
|
-
}
|
|
24565
|
-
function createDaemonConfig(connection, agents = [], installableAgents = []) {
|
|
24566
|
-
return {
|
|
24567
|
-
agents,
|
|
24568
|
-
defaultWorkspace: connection.defaultWorkspace,
|
|
24569
|
-
auditDatabasePath: connection.auditDatabasePath,
|
|
24570
|
-
bindingId: "workspace",
|
|
24571
|
-
catalog: new LocalAgentCatalog(agents, installableAgents),
|
|
24572
|
-
channelId: connection.channelId,
|
|
24573
|
-
installableAgents,
|
|
24574
|
-
relayUrl: connection.relayUrl
|
|
24575
|
-
};
|
|
24707
|
+
async function openRuntimeInstallationStore(options, signal) {
|
|
24708
|
+
return await RuntimeInstallationStore.open(options, signal);
|
|
24576
24709
|
}
|
|
24577
24710
|
|
|
24578
24711
|
// src/pairing/pair-local-machine.ts
|
|
24579
|
-
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
24580
|
-
import { mkdir as mkdir3, open as open4, realpath as realpath6, rename as rename3, stat as stat5, writeFile as writeFile2 } from "node:fs/promises";
|
|
24581
|
-
import { hostname as hostname3 } from "node:os";
|
|
24582
|
-
import { basename, join as join15, resolve as resolve3 } from "node:path";
|
|
24583
|
-
import { fetch as fetch2 } from "undici";
|
|
24584
24712
|
var PAIRING_TIMEOUT_MILLISECONDS = 2e4;
|
|
24585
24713
|
var PAIRING_CODE_PATTERN = /^[A-HJ-NP-Z2-9]{4}(?:-[A-HJ-NP-Z2-9]{4}){4}$/;
|
|
24586
24714
|
var IDENTIFIER_PATTERN5 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
24587
|
-
var
|
|
24588
|
-
var MAX_CONNECTION_FILE_LENGTH = 16 * 1024;
|
|
24715
|
+
var TOKEN_PATTERN = /^[a-zA-Z0-9_-]{32,256}$/;
|
|
24589
24716
|
var CLAIM_RESPONSE_KEYS = ["channelId", "daemonToken", "runtimeId"];
|
|
24590
24717
|
var REDEEM_RESPONSE_KEYS = ["channelId", "runtimeCredential", "runtimeId"];
|
|
24591
|
-
var
|
|
24592
|
-
var SAVED_CONNECTION_KEYS = ["defaultWorkspace", "channelId", "relayOrigin", "runtimeCredential"];
|
|
24718
|
+
var MOBIUS_CLI_APPLICATION_ID = "dev.mobius.cli";
|
|
24593
24719
|
var PairingClientError = class extends Error {
|
|
24594
24720
|
code;
|
|
24595
24721
|
constructor(code, message, options = {}) {
|
|
@@ -24598,40 +24724,40 @@ var PairingClientError = class extends Error {
|
|
|
24598
24724
|
this.name = "PairingClientError";
|
|
24599
24725
|
}
|
|
24600
24726
|
};
|
|
24601
|
-
function
|
|
24727
|
+
function isRecord6(value) {
|
|
24602
24728
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24603
24729
|
}
|
|
24604
|
-
function
|
|
24730
|
+
function hasExactKeys2(value, expectedKeys) {
|
|
24605
24731
|
const keys = Object.keys(value);
|
|
24606
24732
|
return keys.length === expectedKeys.length && expectedKeys.every((key) => Object.hasOwn(value, key));
|
|
24607
24733
|
}
|
|
24608
|
-
function readSingleOption(arguments_,
|
|
24734
|
+
function readSingleOption(arguments_, option) {
|
|
24609
24735
|
const values = [];
|
|
24610
24736
|
for (let index2 = 0; index2 < arguments_.length; index2 += 1) {
|
|
24611
|
-
if (arguments_[index2] !==
|
|
24737
|
+
if (arguments_[index2] !== option) {
|
|
24612
24738
|
continue;
|
|
24613
24739
|
}
|
|
24614
24740
|
const value = arguments_[index2 + 1];
|
|
24615
24741
|
if (value === void 0 || value.startsWith("--")) {
|
|
24616
|
-
throw new PairingClientError("invalid_arguments", `${
|
|
24742
|
+
throw new PairingClientError("invalid_arguments", `${option} requires a value`);
|
|
24617
24743
|
}
|
|
24618
24744
|
values.push(value);
|
|
24619
24745
|
index2 += 1;
|
|
24620
24746
|
}
|
|
24621
24747
|
if (values.length !== 1) {
|
|
24622
|
-
throw new PairingClientError("invalid_arguments", `${
|
|
24748
|
+
throw new PairingClientError("invalid_arguments", `${option} must be provided exactly once`);
|
|
24623
24749
|
}
|
|
24624
24750
|
return values[0] ?? "";
|
|
24625
24751
|
}
|
|
24626
24752
|
function assertKnownArguments(arguments_) {
|
|
24627
24753
|
for (let index2 = 0; index2 < arguments_.length; index2 += 2) {
|
|
24628
|
-
const
|
|
24629
|
-
if (
|
|
24630
|
-
throw new PairingClientError("invalid_arguments", `Unknown pairing option: ${
|
|
24754
|
+
const option = arguments_[index2];
|
|
24755
|
+
if (option !== "--url" && option !== "--code" && option !== "--pairing" && option !== "--workspace") {
|
|
24756
|
+
throw new PairingClientError("invalid_arguments", `Unknown pairing option: ${option ?? "missing option"}`);
|
|
24631
24757
|
}
|
|
24632
24758
|
}
|
|
24633
24759
|
}
|
|
24634
|
-
function
|
|
24760
|
+
function parseRelayOrigin2(value) {
|
|
24635
24761
|
let url2;
|
|
24636
24762
|
try {
|
|
24637
24763
|
url2 = new URL(value);
|
|
@@ -24662,13 +24788,13 @@ function parsePairingCode(value) {
|
|
|
24662
24788
|
}
|
|
24663
24789
|
return code;
|
|
24664
24790
|
}
|
|
24665
|
-
function parsePairCommand(arguments_) {
|
|
24791
|
+
function parsePairCommand(arguments_, defaultWorkspace) {
|
|
24666
24792
|
assertKnownArguments(arguments_);
|
|
24667
24793
|
return {
|
|
24668
24794
|
code: parsePairingCode(readSingleOption(arguments_, "--code")),
|
|
24669
24795
|
pairingId: arguments_.includes("--pairing") ? validatePairingId(readSingleOption(arguments_, "--pairing")) : "",
|
|
24670
|
-
relayOrigin:
|
|
24671
|
-
workspace: arguments_.includes("--workspace") ? readSingleOption(arguments_, "--workspace") :
|
|
24796
|
+
relayOrigin: parseRelayOrigin2(readSingleOption(arguments_, "--url")),
|
|
24797
|
+
workspace: arguments_.includes("--workspace") ? readSingleOption(arguments_, "--workspace") : defaultWorkspace
|
|
24672
24798
|
};
|
|
24673
24799
|
}
|
|
24674
24800
|
function validatePairingId(value) {
|
|
@@ -24677,20 +24803,53 @@ function validatePairingId(value) {
|
|
|
24677
24803
|
}
|
|
24678
24804
|
return value;
|
|
24679
24805
|
}
|
|
24680
|
-
|
|
24681
|
-
|
|
24682
|
-
|
|
24806
|
+
var ResumeCommandTarget = class {
|
|
24807
|
+
};
|
|
24808
|
+
var ConnectionResumeCommandTarget = class extends ResumeCommandTarget {
|
|
24809
|
+
connectionId;
|
|
24810
|
+
constructor(connectionId2) {
|
|
24811
|
+
super();
|
|
24812
|
+
this.connectionId = connectionId2;
|
|
24683
24813
|
}
|
|
24684
|
-
|
|
24685
|
-
|
|
24686
|
-
|
|
24814
|
+
resume = async (installation, signal, environment) => await resumeMobiusRuntime(installation, this.connectionId, signal, environment);
|
|
24815
|
+
};
|
|
24816
|
+
var LegacyChannelResumeCommandTarget = class extends ResumeCommandTarget {
|
|
24817
|
+
channelId;
|
|
24818
|
+
constructor(channelId) {
|
|
24819
|
+
super();
|
|
24820
|
+
this.channelId = channelId;
|
|
24687
24821
|
}
|
|
24688
|
-
|
|
24822
|
+
resume = async (installation, signal, environment) => await resumeLegacyChannel(installation, this.channelId, signal, environment);
|
|
24823
|
+
};
|
|
24824
|
+
function parseResumeArgument(arguments_) {
|
|
24825
|
+
if (arguments_.length !== 2) {
|
|
24826
|
+
throw new PairingClientError(
|
|
24827
|
+
"invalid_arguments",
|
|
24828
|
+
"Usage: mobius start --connection <connection-id> or mobius start --channel <legacy-channel-id>"
|
|
24829
|
+
);
|
|
24830
|
+
}
|
|
24831
|
+
const value = arguments_[1] ?? "";
|
|
24832
|
+
if (arguments_[0] === "--connection") {
|
|
24833
|
+
if (!/^mcn_[a-f0-9]{32}$/.test(value)) {
|
|
24834
|
+
throw new PairingClientError("invalid_connection_id", "The saved Runtime connection ID is invalid");
|
|
24835
|
+
}
|
|
24836
|
+
return new ConnectionResumeCommandTarget(value);
|
|
24837
|
+
}
|
|
24838
|
+
if (arguments_[0] === "--channel") {
|
|
24839
|
+
if (!IDENTIFIER_PATTERN5.test(value)) {
|
|
24840
|
+
throw new PairingClientError("invalid_channel_id", "The saved channel ID is invalid");
|
|
24841
|
+
}
|
|
24842
|
+
return new LegacyChannelResumeCommandTarget(value);
|
|
24843
|
+
}
|
|
24844
|
+
throw new PairingClientError(
|
|
24845
|
+
"invalid_arguments",
|
|
24846
|
+
"Usage: mobius start --connection <connection-id> or mobius start --channel <legacy-channel-id>"
|
|
24847
|
+
);
|
|
24689
24848
|
}
|
|
24690
24849
|
async function resolveDefaultWorkspace(path2) {
|
|
24691
|
-
const requestedWorkspace =
|
|
24850
|
+
const requestedWorkspace = resolve5(path2);
|
|
24692
24851
|
try {
|
|
24693
|
-
await
|
|
24852
|
+
await mkdir4(requestedWorkspace, { recursive: true, mode: 448 });
|
|
24694
24853
|
const defaultWorkspace = await realpath6(requestedWorkspace);
|
|
24695
24854
|
const metadata = await stat5(defaultWorkspace);
|
|
24696
24855
|
if (!metadata.isDirectory()) {
|
|
@@ -24721,9 +24880,9 @@ async function readJsonResponse(response) {
|
|
|
24721
24880
|
}
|
|
24722
24881
|
}
|
|
24723
24882
|
function readRelayError(value) {
|
|
24724
|
-
if (
|
|
24883
|
+
if (isRecord6(value)) {
|
|
24725
24884
|
const error62 = value["error"];
|
|
24726
|
-
if (
|
|
24885
|
+
if (isRecord6(error62)) {
|
|
24727
24886
|
const code = error62["code"];
|
|
24728
24887
|
const message = error62["message"];
|
|
24729
24888
|
if (typeof code === "string" && typeof message === "string") {
|
|
@@ -24734,13 +24893,13 @@ function readRelayError(value) {
|
|
|
24734
24893
|
return new PairingClientError("pairing_failed", "The relay could not pair this machine");
|
|
24735
24894
|
}
|
|
24736
24895
|
function decodePairingResponse(value, credentialField, expectedKeys) {
|
|
24737
|
-
if (!
|
|
24896
|
+
if (!isRecord6(value) || !hasExactKeys2(value, expectedKeys)) {
|
|
24738
24897
|
throw new PairingClientError("invalid_relay_response", "The relay returned an invalid pairing response");
|
|
24739
24898
|
}
|
|
24740
24899
|
const channelId = value["channelId"];
|
|
24741
24900
|
const runtimeCredential2 = value[credentialField];
|
|
24742
24901
|
const runtimeId = value["runtimeId"];
|
|
24743
|
-
if (typeof channelId !== "string" || !IDENTIFIER_PATTERN5.test(channelId) || typeof runtimeCredential2 !== "string" || !
|
|
24902
|
+
if (typeof channelId !== "string" || !IDENTIFIER_PATTERN5.test(channelId) || typeof runtimeCredential2 !== "string" || !TOKEN_PATTERN.test(runtimeCredential2) || typeof runtimeId !== "string" || !IDENTIFIER_PATTERN5.test(runtimeId)) {
|
|
24744
24903
|
throw new PairingClientError("invalid_relay_response", "The relay returned an invalid pairing response");
|
|
24745
24904
|
}
|
|
24746
24905
|
return { channelId, runtimeCredential: runtimeCredential2, runtimeId };
|
|
@@ -24750,7 +24909,6 @@ async function claimPairing(options, defaultWorkspace, localAgents, installableA
|
|
|
24750
24909
|
agentPath: agent.agentIdentity.requestedPath,
|
|
24751
24910
|
agentVersion: agent.agentVersion,
|
|
24752
24911
|
agentSettingsDiscovery: true,
|
|
24753
|
-
botSessionConfiguration: true,
|
|
24754
24912
|
capabilities: agent.capabilities,
|
|
24755
24913
|
id: agent.id,
|
|
24756
24914
|
label: agent.label,
|
|
@@ -24781,155 +24939,114 @@ async function claimPairing(options, defaultWorkspace, localAgents, installableA
|
|
|
24781
24939
|
}
|
|
24782
24940
|
return options.pairingId.length > 0 ? decodePairingResponse(value, "runtimeCredential", REDEEM_RESPONSE_KEYS) : decodePairingResponse(value, "daemonToken", CLAIM_RESPONSE_KEYS);
|
|
24783
24941
|
}
|
|
24784
|
-
async function persistConnection(channelId, relayOrigin, runtimeCredential2, defaultWorkspace, environment) {
|
|
24785
|
-
const connectionsDirectory = join15(readStateDirectory(environment), "connections");
|
|
24786
|
-
await mkdir3(connectionsDirectory, { mode: 448, recursive: true });
|
|
24787
|
-
const connectionPath = join15(connectionsDirectory, `${channelId}.json`);
|
|
24788
|
-
const temporaryPath = join15(connectionsDirectory, `.${channelId}.${randomUUID2()}.tmp`);
|
|
24789
|
-
await writeFile2(
|
|
24790
|
-
temporaryPath,
|
|
24791
|
-
`${JSON.stringify(
|
|
24792
|
-
{
|
|
24793
|
-
defaultWorkspace,
|
|
24794
|
-
channelId,
|
|
24795
|
-
relayOrigin: relayOrigin.toString(),
|
|
24796
|
-
runtimeCredential: runtimeCredential2
|
|
24797
|
-
},
|
|
24798
|
-
null,
|
|
24799
|
-
2
|
|
24800
|
-
)}
|
|
24801
|
-
`,
|
|
24802
|
-
{ flag: "wx", mode: 384 }
|
|
24803
|
-
);
|
|
24804
|
-
await rename3(temporaryPath, connectionPath);
|
|
24805
|
-
return connectionPath;
|
|
24806
|
-
}
|
|
24807
|
-
function decodeSavedConnection(value, expectedChannelId) {
|
|
24808
|
-
if (!isRecord7(value) || !hasExactKeys(value, SAVED_CONNECTION_KEYS) && !hasExactKeys(value, LEGACY_SAVED_CONNECTION_KEYS)) {
|
|
24809
|
-
throw new PairingClientError("invalid_connection", "The saved connection is invalid");
|
|
24810
|
-
}
|
|
24811
|
-
const defaultWorkspace = value["defaultWorkspace"];
|
|
24812
|
-
const channelId = value["channelId"];
|
|
24813
|
-
const runtimeCredential2 = value["runtimeCredential"] ?? value["daemonToken"];
|
|
24814
|
-
const relayOrigin = value["relayOrigin"];
|
|
24815
|
-
if (typeof defaultWorkspace !== "string" || typeof channelId !== "string" || channelId !== expectedChannelId || !IDENTIFIER_PATTERN5.test(channelId) || typeof runtimeCredential2 !== "string" || !TOKEN_PATTERN2.test(runtimeCredential2) || typeof relayOrigin !== "string") {
|
|
24816
|
-
throw new PairingClientError("invalid_connection", "The saved connection is invalid");
|
|
24817
|
-
}
|
|
24818
|
-
return {
|
|
24819
|
-
defaultWorkspace,
|
|
24820
|
-
channelId,
|
|
24821
|
-
relayOrigin: parseRelayOrigin(relayOrigin),
|
|
24822
|
-
runtimeCredential: runtimeCredential2
|
|
24823
|
-
};
|
|
24824
|
-
}
|
|
24825
|
-
async function readSavedConnection(channelId, environment) {
|
|
24826
|
-
const connectionPath = join15(readStateDirectory(environment), "connections", `${channelId}.json`);
|
|
24827
|
-
let encoded = "";
|
|
24828
|
-
const handle = await open4(connectionPath, "r");
|
|
24829
|
-
try {
|
|
24830
|
-
const metadata = await handle.stat();
|
|
24831
|
-
if (!metadata.isFile() || metadata.size > MAX_CONNECTION_FILE_LENGTH) {
|
|
24832
|
-
throw new PairingClientError("invalid_connection", "The saved connection is invalid");
|
|
24833
|
-
}
|
|
24834
|
-
encoded = await handle.readFile({ encoding: "utf8" });
|
|
24835
|
-
} finally {
|
|
24836
|
-
await handle.close();
|
|
24837
|
-
}
|
|
24838
|
-
let value;
|
|
24839
|
-
try {
|
|
24840
|
-
value = JSON.parse(encoded);
|
|
24841
|
-
} catch (error62) {
|
|
24842
|
-
throw new PairingClientError("invalid_connection", "The saved connection is invalid", { cause: error62 });
|
|
24843
|
-
}
|
|
24844
|
-
const connection = decodeSavedConnection(value, channelId);
|
|
24845
|
-
return {
|
|
24846
|
-
defaultWorkspace: await resolveDefaultWorkspace(connection.defaultWorkspace),
|
|
24847
|
-
channelId: connection.channelId,
|
|
24848
|
-
relayOrigin: connection.relayOrigin,
|
|
24849
|
-
runtimeCredential: connection.runtimeCredential
|
|
24850
|
-
};
|
|
24851
|
-
}
|
|
24852
24942
|
function assertInventoryUsable(inventory) {
|
|
24853
24943
|
if (inventory.available.length + inventory.installable.length === 0) {
|
|
24854
24944
|
throw new PairingClientError("no_supported_agent", "No supported Agent is available for local discovery");
|
|
24855
24945
|
}
|
|
24856
24946
|
}
|
|
24857
|
-
function buildPairedDaemon(connection,
|
|
24947
|
+
function buildPairedDaemon(installation, connection, defaultWorkspace, inventory, localContext) {
|
|
24858
24948
|
assertInventoryUsable(inventory);
|
|
24859
24949
|
const relayUrl = mobiusApiUrl(connection.relayOrigin, "/v1/runtimes/connect");
|
|
24860
24950
|
relayUrl.protocol = relayUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
24861
24951
|
relayUrl.searchParams.set("token", connection.runtimeCredential);
|
|
24862
|
-
const auditDatabasePath = join15(readStateDirectory(environment), "audit", `${connection.channelId}.sqlite`);
|
|
24863
24952
|
return {
|
|
24864
24953
|
channelUrl: new URL(`/channels/${encodeURIComponent(connection.channelId)}`, connection.relayOrigin).toString(),
|
|
24954
|
+
connectionId: connection.connectionId,
|
|
24865
24955
|
config: createDaemonConfig(
|
|
24866
24956
|
{
|
|
24867
|
-
defaultWorkspace
|
|
24868
|
-
auditDatabasePath,
|
|
24957
|
+
defaultWorkspace,
|
|
24958
|
+
auditDatabasePath: installation.auditDatabasePath(connection.connectionId),
|
|
24869
24959
|
channelId: connection.channelId,
|
|
24870
24960
|
relayUrl
|
|
24871
24961
|
},
|
|
24872
24962
|
inventory.readyAgents(),
|
|
24873
|
-
inventory.installable
|
|
24963
|
+
inventory.installable,
|
|
24964
|
+
localContext,
|
|
24965
|
+
new OpaqueDaemonReconnectTarget(connection.connectionId)
|
|
24874
24966
|
),
|
|
24875
|
-
connectionPath
|
|
24967
|
+
connectionPath: installation.connectionPath(connection.connectionId)
|
|
24876
24968
|
};
|
|
24877
24969
|
}
|
|
24878
|
-
async function pairRuntime(options, signal, environment) {
|
|
24970
|
+
async function pairRuntime(installation, options, signal, environment) {
|
|
24971
|
+
const localContext = new DaemonLocalContext(installation.stateDirectory, environment);
|
|
24879
24972
|
const defaultWorkspace = await resolveDefaultWorkspace(options.workspace);
|
|
24880
24973
|
const inventory = await discoverLocalAgentInventory({
|
|
24881
24974
|
defaultWorkspace,
|
|
24882
|
-
environment,
|
|
24975
|
+
environment: localContext.environment,
|
|
24883
24976
|
signal
|
|
24884
24977
|
});
|
|
24885
24978
|
assertInventoryUsable(inventory);
|
|
24886
24979
|
const agents = inventory.readyAgents();
|
|
24887
24980
|
const claim2 = await claimPairing(options, defaultWorkspace, agents, inventory.installable, signal);
|
|
24888
|
-
const
|
|
24889
|
-
claim2.channelId,
|
|
24890
|
-
options.relayOrigin,
|
|
24891
|
-
claim2.runtimeCredential,
|
|
24892
|
-
defaultWorkspace,
|
|
24893
|
-
environment
|
|
24894
|
-
);
|
|
24895
|
-
return buildPairedDaemon(
|
|
24981
|
+
const connection = await installation.saveConnection(
|
|
24896
24982
|
{
|
|
24897
|
-
defaultWorkspace,
|
|
24898
24983
|
channelId: claim2.channelId,
|
|
24984
|
+
defaultWorkspace,
|
|
24899
24985
|
relayOrigin: options.relayOrigin,
|
|
24900
|
-
runtimeCredential: claim2.runtimeCredential
|
|
24986
|
+
runtimeCredential: claim2.runtimeCredential,
|
|
24987
|
+
runtimeId: claim2.runtimeId
|
|
24901
24988
|
},
|
|
24902
|
-
|
|
24903
|
-
inventory,
|
|
24904
|
-
environment
|
|
24989
|
+
signal
|
|
24905
24990
|
);
|
|
24991
|
+
return buildPairedDaemon(installation, connection, defaultWorkspace, inventory, localContext);
|
|
24906
24992
|
}
|
|
24907
|
-
async function
|
|
24908
|
-
|
|
24909
|
-
|
|
24910
|
-
async function resumeMobiusRuntime(channelId, signal, environment = process.env) {
|
|
24911
|
-
const normalizedChannelId = validatePairingId(channelId);
|
|
24912
|
-
const connectionPath = join15(readStateDirectory(environment), "connections", `${normalizedChannelId}.json`);
|
|
24913
|
-
const connection = await readSavedConnection(normalizedChannelId, environment);
|
|
24993
|
+
async function resumeRuntimeConnection(installation, connection, signal, environment) {
|
|
24994
|
+
const localContext = new DaemonLocalContext(installation.stateDirectory, environment);
|
|
24995
|
+
const defaultWorkspace = await resolveDefaultWorkspace(connection.defaultWorkspace);
|
|
24914
24996
|
const inventory = await discoverLocalAgentInventory({
|
|
24915
|
-
defaultWorkspace
|
|
24916
|
-
environment,
|
|
24997
|
+
defaultWorkspace,
|
|
24998
|
+
environment: localContext.environment,
|
|
24917
24999
|
signal
|
|
24918
25000
|
});
|
|
24919
|
-
return buildPairedDaemon(connection,
|
|
25001
|
+
return buildPairedDaemon(installation, connection, defaultWorkspace, inventory, localContext);
|
|
25002
|
+
}
|
|
25003
|
+
async function resumeMobiusRuntime(installation, connectionId2, signal, environment = process.env) {
|
|
25004
|
+
const connection = await installation.readConnection(connectionId2, signal);
|
|
25005
|
+
return await resumeRuntimeConnection(installation, connection, signal, environment);
|
|
25006
|
+
}
|
|
25007
|
+
async function resumeLegacyChannel(installation, channelId, signal, environment) {
|
|
25008
|
+
const connection = await installation.migrateLegacyConnection(readStateDirectory(environment), channelId, signal);
|
|
25009
|
+
return await resumeRuntimeConnection(installation, connection, signal, environment);
|
|
25010
|
+
}
|
|
25011
|
+
async function openMobiusCliInstallation(signal, environment) {
|
|
25012
|
+
return await openRuntimeInstallationStore(
|
|
25013
|
+
{
|
|
25014
|
+
applicationId: MOBIUS_CLI_APPLICATION_ID,
|
|
25015
|
+
stateDirectory: readStateDirectory(environment)
|
|
25016
|
+
},
|
|
25017
|
+
signal
|
|
25018
|
+
);
|
|
25019
|
+
}
|
|
25020
|
+
async function pairLocalMachine(arguments_, signal = new AbortController().signal) {
|
|
25021
|
+
const requested = parsePairCommand(arguments_, "");
|
|
25022
|
+
const installation = await openMobiusCliInstallation(signal, process.env);
|
|
25023
|
+
const localContext = new DaemonLocalContext(installation.stateDirectory, process.env);
|
|
25024
|
+
return await pairRuntime(
|
|
25025
|
+
installation,
|
|
25026
|
+
{
|
|
25027
|
+
code: requested.code,
|
|
25028
|
+
pairingId: requested.pairingId,
|
|
25029
|
+
relayOrigin: requested.relayOrigin,
|
|
25030
|
+
workspace: arguments_.includes("--workspace") ? requested.workspace : loadDefaultWorkspace(localContext.environment)
|
|
25031
|
+
},
|
|
25032
|
+
signal,
|
|
25033
|
+
process.env
|
|
25034
|
+
);
|
|
24920
25035
|
}
|
|
24921
25036
|
async function resumeLocalMachine(arguments_, signal = new AbortController().signal) {
|
|
24922
|
-
|
|
25037
|
+
const target = parseResumeArgument(arguments_);
|
|
25038
|
+
const installation = await openMobiusCliInstallation(signal, process.env);
|
|
25039
|
+
return await target.resume(installation, signal, process.env);
|
|
24923
25040
|
}
|
|
24924
25041
|
|
|
24925
25042
|
// src/audit/audit-store.ts
|
|
24926
25043
|
import { mkdirSync } from "node:fs";
|
|
24927
|
-
import { dirname as
|
|
25044
|
+
import { dirname as dirname4 } from "node:path";
|
|
24928
25045
|
import { DatabaseSync } from "node:sqlite";
|
|
24929
25046
|
var AuditStore = class {
|
|
24930
25047
|
database;
|
|
24931
25048
|
constructor(path2) {
|
|
24932
|
-
mkdirSync(
|
|
25049
|
+
mkdirSync(dirname4(path2), { recursive: true });
|
|
24933
25050
|
this.database = new DatabaseSync(path2);
|
|
24934
25051
|
this.database.exec(`
|
|
24935
25052
|
CREATE TABLE IF NOT EXISTS audit_events (
|
|
@@ -24971,10 +25088,10 @@ var AuditStore = class {
|
|
|
24971
25088
|
};
|
|
24972
25089
|
|
|
24973
25090
|
// src/run-daemon.ts
|
|
24974
|
-
import { randomUUID as
|
|
24975
|
-
import { basename as
|
|
25091
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
25092
|
+
import { basename as basename7 } from "node:path";
|
|
24976
25093
|
import { styleText } from "node:util";
|
|
24977
|
-
import { fetch as
|
|
25094
|
+
import { fetch as fetch6, WebSocket as WebSocket2 } from "undici";
|
|
24978
25095
|
|
|
24979
25096
|
// src/acp/session-manager.ts
|
|
24980
25097
|
import { spawn as spawn3 } from "node:child_process";
|
|
@@ -24986,10 +25103,11 @@ import {
|
|
|
24986
25103
|
} from "@agentclientprotocol/sdk";
|
|
24987
25104
|
|
|
24988
25105
|
// src/authorization/local-raster.ts
|
|
24989
|
-
import { readFile as readFile2, realpath as realpath7, stat as stat6 } from "node:fs/promises";
|
|
25106
|
+
import { open as open5, readFile as readFile2, realpath as realpath7, stat as stat6 } from "node:fs/promises";
|
|
24990
25107
|
import { basename as basename2, isAbsolute as isAbsolute8, normalize as normalize2 } from "node:path";
|
|
24991
25108
|
import { fileURLToPath } from "node:url";
|
|
24992
|
-
var MAX_LOCAL_RASTER_BYTES =
|
|
25109
|
+
var MAX_LOCAL_RASTER_BYTES = 128 * 1024 * 1024;
|
|
25110
|
+
var MAX_INLINE_RASTER_BYTES = 3e6;
|
|
24993
25111
|
var PNG_SIGNATURE = Uint8Array.of(137, 80, 78, 71);
|
|
24994
25112
|
var JPEG_SIGNATURE = Uint8Array.of(255, 216, 255);
|
|
24995
25113
|
var GIF87_SIGNATURE = new TextEncoder().encode("GIF87a");
|
|
@@ -25000,12 +25118,17 @@ var LocalRasterImage = class {
|
|
|
25000
25118
|
bytes;
|
|
25001
25119
|
mimeType;
|
|
25002
25120
|
name;
|
|
25003
|
-
|
|
25121
|
+
sourceUri;
|
|
25122
|
+
constructor(name, mimeType, bytes, sourceUri = "") {
|
|
25004
25123
|
this.bytes = bytes;
|
|
25005
25124
|
this.mimeType = mimeType;
|
|
25006
25125
|
this.name = name;
|
|
25126
|
+
this.sourceUri = sourceUri;
|
|
25007
25127
|
}
|
|
25008
|
-
base64 = () =>
|
|
25128
|
+
base64 = async () => {
|
|
25129
|
+
const bytes = this.bytes ?? new Uint8Array(await readFile2(this.sourceUri));
|
|
25130
|
+
return Buffer.from(bytes).toString("base64");
|
|
25131
|
+
};
|
|
25009
25132
|
};
|
|
25010
25133
|
function startsWith(bytes, signature, offset = 0) {
|
|
25011
25134
|
if (bytes.byteLength < offset + signature.byteLength) {
|
|
@@ -25029,14 +25152,14 @@ function sniffRasterMime(bytes) {
|
|
|
25029
25152
|
return null;
|
|
25030
25153
|
}
|
|
25031
25154
|
function readInlineRaster(data, name = "Image") {
|
|
25032
|
-
if (data.length === 0 || data.length > Math.ceil(
|
|
25155
|
+
if (data.length === 0 || data.length > Math.ceil(MAX_INLINE_RASTER_BYTES / 3) * 4 || data.length % 4 !== 0) {
|
|
25033
25156
|
return null;
|
|
25034
25157
|
}
|
|
25035
25158
|
if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(data)) {
|
|
25036
25159
|
return null;
|
|
25037
25160
|
}
|
|
25038
25161
|
const bytes = new Uint8Array(Buffer.from(data, "base64"));
|
|
25039
|
-
if (bytes.byteLength < 1 || bytes.byteLength >
|
|
25162
|
+
if (bytes.byteLength < 1 || bytes.byteLength > MAX_INLINE_RASTER_BYTES) {
|
|
25040
25163
|
return null;
|
|
25041
25164
|
}
|
|
25042
25165
|
const mimeType = sniffRasterMime(bytes);
|
|
@@ -25104,16 +25227,19 @@ async function readLocalRaster(uri, signal) {
|
|
|
25104
25227
|
if (!targetMetadata.isFile() || targetMetadata.size < 1 || targetMetadata.size > MAX_LOCAL_RASTER_BYTES) {
|
|
25105
25228
|
return null;
|
|
25106
25229
|
}
|
|
25107
|
-
const
|
|
25108
|
-
|
|
25109
|
-
|
|
25110
|
-
|
|
25230
|
+
const handle = await open5(target, "r");
|
|
25231
|
+
const header = new Uint8Array(12);
|
|
25232
|
+
try {
|
|
25233
|
+
await handle.read(header, 0, header.byteLength, 0);
|
|
25234
|
+
} finally {
|
|
25235
|
+
await handle.close();
|
|
25111
25236
|
}
|
|
25112
|
-
|
|
25237
|
+
signal.throwIfAborted();
|
|
25238
|
+
const mimeType = sniffRasterMime(header);
|
|
25113
25239
|
if (mimeType === null) {
|
|
25114
25240
|
return null;
|
|
25115
25241
|
}
|
|
25116
|
-
return new LocalRasterImage(basename2(target) || "Image", mimeType,
|
|
25242
|
+
return new LocalRasterImage(basename2(target) || "Image", mimeType, null, target);
|
|
25117
25243
|
}
|
|
25118
25244
|
|
|
25119
25245
|
// src/authorization/local-video.ts
|
|
@@ -25239,7 +25365,7 @@ async function resolveMessageImages(message, usedCharacters, signal) {
|
|
|
25239
25365
|
if (local === null) {
|
|
25240
25366
|
return "[Image unavailable]";
|
|
25241
25367
|
}
|
|
25242
|
-
const data = local.base64();
|
|
25368
|
+
const data = await local.base64();
|
|
25243
25369
|
if (usedCharacters + imageCharacters + data.length > SESSION_HISTORY_IMAGE_CHARACTER_LIMIT) {
|
|
25244
25370
|
return "[Image unavailable]";
|
|
25245
25371
|
}
|
|
@@ -25275,7 +25401,7 @@ async function replaceImageMarkers(text3, replace) {
|
|
|
25275
25401
|
|
|
25276
25402
|
// src/acp/activity.ts
|
|
25277
25403
|
var TRUNCATION_MARKER = "\n\u2026 output truncated by Mobius";
|
|
25278
|
-
function
|
|
25404
|
+
function isRecord7(value) {
|
|
25279
25405
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25280
25406
|
}
|
|
25281
25407
|
var AcpActivity = class _AcpActivity {
|
|
@@ -25509,16 +25635,16 @@ async function normalizeToolContent(content3, prepareContent) {
|
|
|
25509
25635
|
return normalized;
|
|
25510
25636
|
}
|
|
25511
25637
|
function rawMcpToolContent(rawOutput) {
|
|
25512
|
-
if (!
|
|
25638
|
+
if (!isRecord7(rawOutput)) {
|
|
25513
25639
|
return [];
|
|
25514
25640
|
}
|
|
25515
|
-
const result =
|
|
25641
|
+
const result = isRecord7(rawOutput["result"]) ? rawOutput["result"] : rawOutput;
|
|
25516
25642
|
const content3 = result["content"];
|
|
25517
25643
|
if (!Array.isArray(content3)) {
|
|
25518
25644
|
return [];
|
|
25519
25645
|
}
|
|
25520
25646
|
return content3.flatMap((item) => {
|
|
25521
|
-
if (!
|
|
25647
|
+
if (!isRecord7(item) || item["type"] !== "image" || typeof item["data"] !== "string" || typeof item["mimeType"] !== "string") {
|
|
25522
25648
|
return [];
|
|
25523
25649
|
}
|
|
25524
25650
|
const uri = item["uri"];
|
|
@@ -25595,7 +25721,7 @@ function contentPhase(content3) {
|
|
|
25595
25721
|
return "";
|
|
25596
25722
|
}
|
|
25597
25723
|
const codex = metadata["codex"];
|
|
25598
|
-
if (!
|
|
25724
|
+
if (!isRecord7(codex)) {
|
|
25599
25725
|
return "";
|
|
25600
25726
|
}
|
|
25601
25727
|
const phase = codex["phase"];
|
|
@@ -28382,10 +28508,10 @@ function resolveAll(constructs2, events, context) {
|
|
|
28382
28508
|
const called = [];
|
|
28383
28509
|
let index2 = -1;
|
|
28384
28510
|
while (++index2 < constructs2.length) {
|
|
28385
|
-
const
|
|
28386
|
-
if (
|
|
28387
|
-
events =
|
|
28388
|
-
called.push(
|
|
28511
|
+
const resolve7 = constructs2[index2].resolveAll;
|
|
28512
|
+
if (resolve7 && !called.includes(resolve7)) {
|
|
28513
|
+
events = resolve7(events, context);
|
|
28514
|
+
called.push(resolve7);
|
|
28389
28515
|
}
|
|
28390
28516
|
}
|
|
28391
28517
|
return events;
|
|
@@ -28399,7 +28525,7 @@ var attention = {
|
|
|
28399
28525
|
};
|
|
28400
28526
|
function resolveAllAttention(events, context) {
|
|
28401
28527
|
let index2 = -1;
|
|
28402
|
-
let
|
|
28528
|
+
let open6;
|
|
28403
28529
|
let group;
|
|
28404
28530
|
let text3;
|
|
28405
28531
|
let openingSequence;
|
|
@@ -28409,16 +28535,16 @@ function resolveAllAttention(events, context) {
|
|
|
28409
28535
|
let offset;
|
|
28410
28536
|
while (++index2 < events.length) {
|
|
28411
28537
|
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[
|
|
28538
|
+
open6 = index2;
|
|
28539
|
+
while (open6--) {
|
|
28540
|
+
if (events[open6][0] === "exit" && events[open6][1].type === "attentionSequence" && events[open6][1]._open && // If the markers are the same:
|
|
28541
|
+
context.sliceSerialize(events[open6][1]).charCodeAt(0) === context.sliceSerialize(events[index2][1]).charCodeAt(0)) {
|
|
28542
|
+
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
28543
|
continue;
|
|
28418
28544
|
}
|
|
28419
|
-
use = events[
|
|
28545
|
+
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
28546
|
const start = {
|
|
28421
|
-
...events[
|
|
28547
|
+
...events[open6][1].end
|
|
28422
28548
|
};
|
|
28423
28549
|
const end = {
|
|
28424
28550
|
...events[index2][1].start
|
|
@@ -28429,7 +28555,7 @@ function resolveAllAttention(events, context) {
|
|
|
28429
28555
|
type: use > 1 ? "strongSequence" : "emphasisSequence",
|
|
28430
28556
|
start,
|
|
28431
28557
|
end: {
|
|
28432
|
-
...events[
|
|
28558
|
+
...events[open6][1].end
|
|
28433
28559
|
}
|
|
28434
28560
|
};
|
|
28435
28561
|
closingSequence = {
|
|
@@ -28442,7 +28568,7 @@ function resolveAllAttention(events, context) {
|
|
|
28442
28568
|
text3 = {
|
|
28443
28569
|
type: use > 1 ? "strongText" : "emphasisText",
|
|
28444
28570
|
start: {
|
|
28445
|
-
...events[
|
|
28571
|
+
...events[open6][1].end
|
|
28446
28572
|
},
|
|
28447
28573
|
end: {
|
|
28448
28574
|
...events[index2][1].start
|
|
@@ -28457,18 +28583,18 @@ function resolveAllAttention(events, context) {
|
|
|
28457
28583
|
...closingSequence.end
|
|
28458
28584
|
}
|
|
28459
28585
|
};
|
|
28460
|
-
events[
|
|
28586
|
+
events[open6][1].end = {
|
|
28461
28587
|
...openingSequence.start
|
|
28462
28588
|
};
|
|
28463
28589
|
events[index2][1].start = {
|
|
28464
28590
|
...closingSequence.end
|
|
28465
28591
|
};
|
|
28466
28592
|
nextEvents = [];
|
|
28467
|
-
if (events[
|
|
28468
|
-
nextEvents = push(nextEvents, [["enter", events[
|
|
28593
|
+
if (events[open6][1].end.offset - events[open6][1].start.offset) {
|
|
28594
|
+
nextEvents = push(nextEvents, [["enter", events[open6][1], context], ["exit", events[open6][1], context]]);
|
|
28469
28595
|
}
|
|
28470
28596
|
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(
|
|
28597
|
+
nextEvents = push(nextEvents, resolveAll(context.parser.constructs.insideSpan.null, events.slice(open6 + 1, index2), context));
|
|
28472
28598
|
nextEvents = push(nextEvents, [["exit", text3, context], ["enter", closingSequence, context], ["exit", closingSequence, context], ["exit", group, context]]);
|
|
28473
28599
|
if (events[index2][1].end.offset - events[index2][1].start.offset) {
|
|
28474
28600
|
offset = 2;
|
|
@@ -28476,8 +28602,8 @@ function resolveAllAttention(events, context) {
|
|
|
28476
28602
|
} else {
|
|
28477
28603
|
offset = 0;
|
|
28478
28604
|
}
|
|
28479
|
-
splice(events,
|
|
28480
|
-
index2 =
|
|
28605
|
+
splice(events, open6 - 1, index2 - open6 + 3, nextEvents);
|
|
28606
|
+
index2 = open6 + nextEvents.length - offset - 2;
|
|
28481
28607
|
break;
|
|
28482
28608
|
}
|
|
28483
28609
|
}
|
|
@@ -28509,10 +28635,10 @@ function tokenizeAttention(effects, ok2) {
|
|
|
28509
28635
|
}
|
|
28510
28636
|
const token = effects.exit("attentionSequence");
|
|
28511
28637
|
const after = classifyCharacter(code);
|
|
28512
|
-
const
|
|
28638
|
+
const open6 = !after || after === 2 && before || attentionMarkers2.includes(code);
|
|
28513
28639
|
const close = !before || before === 2 && after || attentionMarkers2.includes(previous2);
|
|
28514
|
-
token._open = Boolean(marker === 42 ?
|
|
28515
|
-
token._close = Boolean(marker === 42 ? close : close && (after || !
|
|
28640
|
+
token._open = Boolean(marker === 42 ? open6 : open6 && (before || !close));
|
|
28641
|
+
token._close = Boolean(marker === 42 ? close : close && (after || !open6));
|
|
28516
28642
|
return ok2(code);
|
|
28517
28643
|
}
|
|
28518
28644
|
}
|
|
@@ -28536,9 +28662,9 @@ function tokenizeAutolink(effects, ok2, nok) {
|
|
|
28536
28662
|
effects.consume(code);
|
|
28537
28663
|
effects.exit("autolinkMarker");
|
|
28538
28664
|
effects.enter("autolinkProtocol");
|
|
28539
|
-
return
|
|
28665
|
+
return open6;
|
|
28540
28666
|
}
|
|
28541
|
-
function
|
|
28667
|
+
function open6(code) {
|
|
28542
28668
|
if (asciiAlpha(code)) {
|
|
28543
28669
|
effects.consume(code);
|
|
28544
28670
|
return schemeOrEmailAtext;
|
|
@@ -28738,9 +28864,9 @@ function tokenizeCharacterReference(effects, ok2, nok) {
|
|
|
28738
28864
|
effects.enter("characterReferenceMarker");
|
|
28739
28865
|
effects.consume(code);
|
|
28740
28866
|
effects.exit("characterReferenceMarker");
|
|
28741
|
-
return
|
|
28867
|
+
return open6;
|
|
28742
28868
|
}
|
|
28743
|
-
function
|
|
28869
|
+
function open6(code) {
|
|
28744
28870
|
if (code === 35) {
|
|
28745
28871
|
effects.enter("characterReferenceMarkerNumeric");
|
|
28746
28872
|
effects.consume(code);
|
|
@@ -30109,9 +30235,9 @@ function tokenizeHtmlFlow(effects, ok2, nok) {
|
|
|
30109
30235
|
effects.enter("htmlFlow");
|
|
30110
30236
|
effects.enter("htmlFlowData");
|
|
30111
30237
|
effects.consume(code);
|
|
30112
|
-
return
|
|
30238
|
+
return open6;
|
|
30113
30239
|
}
|
|
30114
|
-
function
|
|
30240
|
+
function open6(code) {
|
|
30115
30241
|
if (code === 33) {
|
|
30116
30242
|
effects.consume(code);
|
|
30117
30243
|
return declarationOpen;
|
|
@@ -30459,9 +30585,9 @@ function tokenizeHtmlText(effects, ok2, nok) {
|
|
|
30459
30585
|
effects.enter("htmlText");
|
|
30460
30586
|
effects.enter("htmlTextData");
|
|
30461
30587
|
effects.consume(code);
|
|
30462
|
-
return
|
|
30588
|
+
return open6;
|
|
30463
30589
|
}
|
|
30464
|
-
function
|
|
30590
|
+
function open6(code) {
|
|
30465
30591
|
if (code === 33) {
|
|
30466
30592
|
effects.consume(code);
|
|
30467
30593
|
return declarationOpen;
|
|
@@ -30787,12 +30913,12 @@ function resolveToLabelEnd(events, context) {
|
|
|
30787
30913
|
let index2 = events.length;
|
|
30788
30914
|
let offset = 0;
|
|
30789
30915
|
let token;
|
|
30790
|
-
let
|
|
30916
|
+
let open6;
|
|
30791
30917
|
let close;
|
|
30792
30918
|
let media;
|
|
30793
30919
|
while (index2--) {
|
|
30794
30920
|
token = events[index2][1];
|
|
30795
|
-
if (
|
|
30921
|
+
if (open6) {
|
|
30796
30922
|
if (token.type === "link" || token.type === "labelLink" && token._inactive) {
|
|
30797
30923
|
break;
|
|
30798
30924
|
}
|
|
@@ -30801,7 +30927,7 @@ function resolveToLabelEnd(events, context) {
|
|
|
30801
30927
|
}
|
|
30802
30928
|
} else if (close) {
|
|
30803
30929
|
if (events[index2][0] === "enter" && (token.type === "labelImage" || token.type === "labelLink") && !token._balanced) {
|
|
30804
|
-
|
|
30930
|
+
open6 = index2;
|
|
30805
30931
|
if (token.type !== "labelLink") {
|
|
30806
30932
|
offset = 2;
|
|
30807
30933
|
break;
|
|
@@ -30812,9 +30938,9 @@ function resolveToLabelEnd(events, context) {
|
|
|
30812
30938
|
}
|
|
30813
30939
|
}
|
|
30814
30940
|
const group = {
|
|
30815
|
-
type: events[
|
|
30941
|
+
type: events[open6][1].type === "labelLink" ? "link" : "image",
|
|
30816
30942
|
start: {
|
|
30817
|
-
...events[
|
|
30943
|
+
...events[open6][1].start
|
|
30818
30944
|
},
|
|
30819
30945
|
end: {
|
|
30820
30946
|
...events[events.length - 1][1].end
|
|
@@ -30823,7 +30949,7 @@ function resolveToLabelEnd(events, context) {
|
|
|
30823
30949
|
const label = {
|
|
30824
30950
|
type: "label",
|
|
30825
30951
|
start: {
|
|
30826
|
-
...events[
|
|
30952
|
+
...events[open6][1].start
|
|
30827
30953
|
},
|
|
30828
30954
|
end: {
|
|
30829
30955
|
...events[close][1].end
|
|
@@ -30832,20 +30958,20 @@ function resolveToLabelEnd(events, context) {
|
|
|
30832
30958
|
const text3 = {
|
|
30833
30959
|
type: "labelText",
|
|
30834
30960
|
start: {
|
|
30835
|
-
...events[
|
|
30961
|
+
...events[open6 + offset + 2][1].end
|
|
30836
30962
|
},
|
|
30837
30963
|
end: {
|
|
30838
30964
|
...events[close - 2][1].start
|
|
30839
30965
|
}
|
|
30840
30966
|
};
|
|
30841
30967
|
media = [["enter", group, context], ["enter", label, context]];
|
|
30842
|
-
media = push(media, events.slice(
|
|
30968
|
+
media = push(media, events.slice(open6 + 1, open6 + offset + 3));
|
|
30843
30969
|
media = push(media, [["enter", text3, context]]);
|
|
30844
|
-
media = push(media, resolveAll(context.parser.constructs.insideSpan.null, events.slice(
|
|
30970
|
+
media = push(media, resolveAll(context.parser.constructs.insideSpan.null, events.slice(open6 + offset + 4, close - 3), context));
|
|
30845
30971
|
media = push(media, [["exit", text3, context], events[close - 2], events[close - 1], ["exit", label, context]]);
|
|
30846
30972
|
media = push(media, events.slice(close + 1));
|
|
30847
30973
|
media = push(media, [["exit", group, context]]);
|
|
30848
|
-
splice(events,
|
|
30974
|
+
splice(events, open6, events.length, media);
|
|
30849
30975
|
return events;
|
|
30850
30976
|
}
|
|
30851
30977
|
function tokenizeLabelEnd(effects, ok2, nok) {
|
|
@@ -30990,9 +31116,9 @@ function tokenizeLabelStartImage(effects, ok2, nok) {
|
|
|
30990
31116
|
effects.enter("labelImageMarker");
|
|
30991
31117
|
effects.consume(code);
|
|
30992
31118
|
effects.exit("labelImageMarker");
|
|
30993
|
-
return
|
|
31119
|
+
return open6;
|
|
30994
31120
|
}
|
|
30995
|
-
function
|
|
31121
|
+
function open6(code) {
|
|
30996
31122
|
if (code === 91) {
|
|
30997
31123
|
effects.enter("labelMarker");
|
|
30998
31124
|
effects.consume(code);
|
|
@@ -32296,8 +32422,8 @@ function compiler(options) {
|
|
|
32296
32422
|
return length;
|
|
32297
32423
|
}
|
|
32298
32424
|
function opener(create, and) {
|
|
32299
|
-
return
|
|
32300
|
-
function
|
|
32425
|
+
return open6;
|
|
32426
|
+
function open6(token) {
|
|
32301
32427
|
enter.call(this, create(token), token);
|
|
32302
32428
|
if (and) and.call(this, token);
|
|
32303
32429
|
}
|
|
@@ -32329,18 +32455,18 @@ function compiler(options) {
|
|
|
32329
32455
|
}
|
|
32330
32456
|
function exit2(token, onExitError) {
|
|
32331
32457
|
const node3 = this.stack.pop();
|
|
32332
|
-
const
|
|
32333
|
-
if (!
|
|
32458
|
+
const open6 = this.tokenStack.pop();
|
|
32459
|
+
if (!open6) {
|
|
32334
32460
|
throw new Error("Cannot close `" + token.type + "` (" + stringifyPosition({
|
|
32335
32461
|
start: token.start,
|
|
32336
32462
|
end: token.end
|
|
32337
32463
|
}) + "): it\u2019s not open");
|
|
32338
|
-
} else if (
|
|
32464
|
+
} else if (open6[0].type !== token.type) {
|
|
32339
32465
|
if (onExitError) {
|
|
32340
|
-
onExitError.call(this, token,
|
|
32466
|
+
onExitError.call(this, token, open6[0]);
|
|
32341
32467
|
} else {
|
|
32342
|
-
const handler =
|
|
32343
|
-
handler.call(this, token,
|
|
32468
|
+
const handler = open6[1] || defaultOnError;
|
|
32469
|
+
handler.call(this, token, open6[0]);
|
|
32344
32470
|
}
|
|
32345
32471
|
}
|
|
32346
32472
|
node3.position.end = point2(token.end);
|
|
@@ -33024,7 +33150,7 @@ var SessionConfigProtocolError = class extends Error {
|
|
|
33024
33150
|
this.name = "SessionConfigProtocolError";
|
|
33025
33151
|
}
|
|
33026
33152
|
};
|
|
33027
|
-
function
|
|
33153
|
+
function isRecord8(value) {
|
|
33028
33154
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33029
33155
|
}
|
|
33030
33156
|
function readString2(value, fallback = "") {
|
|
@@ -33036,13 +33162,13 @@ function truncate2(value, maximum) {
|
|
|
33036
33162
|
function readBoolean(value, fallback = false) {
|
|
33037
33163
|
return typeof value === "boolean" ? value : fallback;
|
|
33038
33164
|
}
|
|
33039
|
-
function normalizeConfigValue(
|
|
33165
|
+
function normalizeConfigValue(option, groupId = "", groupName = "") {
|
|
33040
33166
|
return {
|
|
33041
|
-
description: truncate2(readString2(
|
|
33167
|
+
description: truncate2(readString2(option["description"]), 500),
|
|
33042
33168
|
groupId: truncate2(groupId, 128),
|
|
33043
33169
|
groupName: truncate2(groupName, 255),
|
|
33044
|
-
name: truncate2(readString2(
|
|
33045
|
-
value: truncate2(readString2(
|
|
33170
|
+
name: truncate2(readString2(option["name"], readString2(option["value"])), 255),
|
|
33171
|
+
value: truncate2(readString2(option["value"]), 500)
|
|
33046
33172
|
};
|
|
33047
33173
|
}
|
|
33048
33174
|
function normalizeConfigValues(value) {
|
|
@@ -33051,7 +33177,7 @@ function normalizeConfigValues(value) {
|
|
|
33051
33177
|
}
|
|
33052
33178
|
const normalized = [];
|
|
33053
33179
|
for (const entry of value) {
|
|
33054
|
-
if (!
|
|
33180
|
+
if (!isRecord8(entry)) {
|
|
33055
33181
|
continue;
|
|
33056
33182
|
}
|
|
33057
33183
|
const groupedOptions = entry["options"];
|
|
@@ -33059,7 +33185,7 @@ function normalizeConfigValues(value) {
|
|
|
33059
33185
|
const groupId = readString2(entry["group"]);
|
|
33060
33186
|
const groupName = readString2(entry["name"]);
|
|
33061
33187
|
for (const groupedOption of groupedOptions) {
|
|
33062
|
-
if (
|
|
33188
|
+
if (isRecord8(groupedOption)) {
|
|
33063
33189
|
normalized.push(normalizeConfigValue(groupedOption, groupId, groupName));
|
|
33064
33190
|
}
|
|
33065
33191
|
}
|
|
@@ -33072,21 +33198,21 @@ function normalizeConfigValues(value) {
|
|
|
33072
33198
|
function normalizeConfigOptions(value, modes) {
|
|
33073
33199
|
const normalized = [];
|
|
33074
33200
|
if (Array.isArray(value)) {
|
|
33075
|
-
for (const
|
|
33076
|
-
if (!
|
|
33201
|
+
for (const option of value) {
|
|
33202
|
+
if (!isRecord8(option)) {
|
|
33077
33203
|
continue;
|
|
33078
33204
|
}
|
|
33079
|
-
const id = truncate2(readString2(
|
|
33080
|
-
const name = truncate2(readString2(
|
|
33205
|
+
const id = truncate2(readString2(option["id"]), 128);
|
|
33206
|
+
const name = truncate2(readString2(option["name"], id), 255);
|
|
33081
33207
|
if (id.length === 0 || name.length === 0) {
|
|
33082
33208
|
continue;
|
|
33083
33209
|
}
|
|
33084
|
-
if (
|
|
33210
|
+
if (option["type"] === "boolean") {
|
|
33085
33211
|
normalized.push({
|
|
33086
|
-
booleanValue: readBoolean(
|
|
33087
|
-
category: truncate2(readString2(
|
|
33212
|
+
booleanValue: readBoolean(option["currentValue"]),
|
|
33213
|
+
category: truncate2(readString2(option["category"]), 128),
|
|
33088
33214
|
currentValue: "",
|
|
33089
|
-
description: truncate2(readString2(
|
|
33215
|
+
description: truncate2(readString2(option["description"]), 500),
|
|
33090
33216
|
id,
|
|
33091
33217
|
name,
|
|
33092
33218
|
type: "boolean",
|
|
@@ -33094,15 +33220,15 @@ function normalizeConfigOptions(value, modes) {
|
|
|
33094
33220
|
});
|
|
33095
33221
|
continue;
|
|
33096
33222
|
}
|
|
33097
|
-
if (
|
|
33098
|
-
const values = normalizeConfigValues(
|
|
33099
|
-
const currentValue = truncate2(readString2(
|
|
33223
|
+
if (option["type"] === "select") {
|
|
33224
|
+
const values = normalizeConfigValues(option["options"]);
|
|
33225
|
+
const currentValue = truncate2(readString2(option["currentValue"]), 500);
|
|
33100
33226
|
if (currentValue.length > 0 && values.some((entry) => entry.value === currentValue)) {
|
|
33101
33227
|
normalized.push({
|
|
33102
33228
|
booleanValue: false,
|
|
33103
|
-
category: truncate2(readString2(
|
|
33229
|
+
category: truncate2(readString2(option["category"]), 128),
|
|
33104
33230
|
currentValue,
|
|
33105
|
-
description: truncate2(readString2(
|
|
33231
|
+
description: truncate2(readString2(option["description"]), 500),
|
|
33106
33232
|
id,
|
|
33107
33233
|
name,
|
|
33108
33234
|
type: "select",
|
|
@@ -33112,12 +33238,12 @@ function normalizeConfigOptions(value, modes) {
|
|
|
33112
33238
|
}
|
|
33113
33239
|
}
|
|
33114
33240
|
}
|
|
33115
|
-
if (
|
|
33241
|
+
if (isRecord8(modes)) {
|
|
33116
33242
|
const values = [];
|
|
33117
33243
|
const availableModes = modes["availableModes"];
|
|
33118
33244
|
if (Array.isArray(availableModes)) {
|
|
33119
33245
|
for (const mode of availableModes) {
|
|
33120
|
-
if (!
|
|
33246
|
+
if (!isRecord8(mode)) {
|
|
33121
33247
|
continue;
|
|
33122
33248
|
}
|
|
33123
33249
|
const id = truncate2(readString2(mode["id"]), 500);
|
|
@@ -33150,14 +33276,14 @@ function normalizeConfigOptions(value, modes) {
|
|
|
33150
33276
|
return normalized.slice(0, 100);
|
|
33151
33277
|
}
|
|
33152
33278
|
function insertRequiredOption(current, required2, afterCategory = "") {
|
|
33153
|
-
if (current.some((
|
|
33279
|
+
if (current.some((option) => option.id === required2.id || option.category === required2.category)) {
|
|
33154
33280
|
return current;
|
|
33155
33281
|
}
|
|
33156
33282
|
if (current.length < MAXIMUM_CONFIG_OPTIONS) {
|
|
33157
33283
|
if (afterCategory.length === 0) {
|
|
33158
33284
|
return [required2, ...current];
|
|
33159
33285
|
}
|
|
33160
|
-
const index3 = current.findIndex((
|
|
33286
|
+
const index3 = current.findIndex((option) => option.category === afterCategory);
|
|
33161
33287
|
if (index3 < 0) {
|
|
33162
33288
|
return [...current, required2];
|
|
33163
33289
|
}
|
|
@@ -33166,7 +33292,7 @@ function insertRequiredOption(current, required2, afterCategory = "") {
|
|
|
33166
33292
|
if (afterCategory.length === 0) {
|
|
33167
33293
|
return [required2, ...current.slice(0, MAXIMUM_CONFIG_OPTIONS - 1)];
|
|
33168
33294
|
}
|
|
33169
|
-
const index2 = current.findIndex((
|
|
33295
|
+
const index2 = current.findIndex((option) => option.category === afterCategory);
|
|
33170
33296
|
if (index2 < 0) {
|
|
33171
33297
|
return [...current.slice(0, MAXIMUM_CONFIG_OPTIONS - 1), required2];
|
|
33172
33298
|
}
|
|
@@ -33179,11 +33305,11 @@ function insertRequiredOption(current, required2, afterCategory = "") {
|
|
|
33179
33305
|
}
|
|
33180
33306
|
return [...current.slice(0, MAXIMUM_CONFIG_OPTIONS - 2), anchor2, required2];
|
|
33181
33307
|
}
|
|
33182
|
-
function validRequiredSelect(
|
|
33183
|
-
return
|
|
33308
|
+
function validRequiredSelect(option) {
|
|
33309
|
+
return option.type === "select" && option.currentValue.length > 0 && option.values.some((value) => value.value === option.currentValue);
|
|
33184
33310
|
}
|
|
33185
33311
|
function ensureModelOption(current) {
|
|
33186
|
-
const existing = current.find((
|
|
33312
|
+
const existing = current.find((option) => option.id === "model" || option.category === "model");
|
|
33187
33313
|
if (existing !== void 0 && validRequiredSelect(existing)) {
|
|
33188
33314
|
return current;
|
|
33189
33315
|
}
|
|
@@ -33206,12 +33332,12 @@ function ensureModelOption(current) {
|
|
|
33206
33332
|
]
|
|
33207
33333
|
};
|
|
33208
33334
|
return insertRequiredOption(
|
|
33209
|
-
current.filter((
|
|
33335
|
+
current.filter((option) => option.id !== "model" && option.category !== "model"),
|
|
33210
33336
|
unavailable
|
|
33211
33337
|
);
|
|
33212
33338
|
}
|
|
33213
33339
|
function ensureReasoningEffortOption(current) {
|
|
33214
|
-
const existing = current.find((
|
|
33340
|
+
const existing = current.find((option) => option.id === "reasoning_effort" || option.category === "thought_level");
|
|
33215
33341
|
if (existing !== void 0 && validRequiredSelect(existing)) {
|
|
33216
33342
|
return current;
|
|
33217
33343
|
}
|
|
@@ -33234,7 +33360,7 @@ function ensureReasoningEffortOption(current) {
|
|
|
33234
33360
|
]
|
|
33235
33361
|
};
|
|
33236
33362
|
return insertRequiredOption(
|
|
33237
|
-
current.filter((
|
|
33363
|
+
current.filter((option) => option.id !== "reasoning_effort" && option.category !== "thought_level"),
|
|
33238
33364
|
unavailable,
|
|
33239
33365
|
"model"
|
|
33240
33366
|
);
|
|
@@ -33242,34 +33368,34 @@ function ensureReasoningEffortOption(current) {
|
|
|
33242
33368
|
function ensureRequiredExecutionOptions(current, permission) {
|
|
33243
33369
|
const normalized = ensureReasoningEffortOption(ensureModelOption(current));
|
|
33244
33370
|
const model = normalized.find(
|
|
33245
|
-
(
|
|
33371
|
+
(option) => (option.id === "model" || option.category === "model") && validRequiredSelect(option)
|
|
33246
33372
|
);
|
|
33247
33373
|
const reasoningEffort = normalized.find(
|
|
33248
|
-
(
|
|
33374
|
+
(option) => (option.id === "reasoning_effort" || option.category === "thought_level") && validRequiredSelect(option)
|
|
33249
33375
|
);
|
|
33250
33376
|
if (model === void 0 || reasoningEffort === void 0) {
|
|
33251
33377
|
throw new SessionConfigProtocolError("The required Agent execution settings are unavailable");
|
|
33252
33378
|
}
|
|
33253
33379
|
const optional2 = normalized.filter(
|
|
33254
|
-
(
|
|
33380
|
+
(option) => option.id !== permission.id && option.category !== permission.category && option.id !== "model" && option.category !== "model" && option.id !== "reasoning_effort" && option.category !== "thought_level"
|
|
33255
33381
|
);
|
|
33256
33382
|
return [permission, model, reasoningEffort, ...optional2].slice(0, MAXIMUM_CONFIG_OPTIONS);
|
|
33257
33383
|
}
|
|
33258
33384
|
function normalizeStandardLifecycle(response) {
|
|
33259
|
-
const lifecycle =
|
|
33385
|
+
const lifecycle = isRecord8(response) ? response : {};
|
|
33260
33386
|
return ensureReasoningEffortOption(normalizeConfigOptions(lifecycle["configOptions"], lifecycle["modes"]));
|
|
33261
33387
|
}
|
|
33262
33388
|
function replaceStandardConfigOptions(current, value) {
|
|
33263
33389
|
const next = normalizeConfigOptions(value, void 0);
|
|
33264
|
-
const withMode = next.some((
|
|
33390
|
+
const withMode = next.some((option) => option.category === "mode") ? next : [...current.filter((option) => option.category === "mode"), ...next].slice(0, 100);
|
|
33265
33391
|
return ensureReasoningEffortOption(withMode);
|
|
33266
33392
|
}
|
|
33267
33393
|
function updateCurrentValue(current, configId, value) {
|
|
33268
|
-
return current.map((
|
|
33394
|
+
return current.map((option) => option.id === configId ? { ...option, currentValue: value } : option);
|
|
33269
33395
|
}
|
|
33270
33396
|
var StandardSessionConfigProtocol = class {
|
|
33271
33397
|
configure = async (current, change, nativeSessionId, transport) => {
|
|
33272
|
-
const existing = current.find((
|
|
33398
|
+
const existing = current.find((option) => option.id === change.configId);
|
|
33273
33399
|
if (existing === void 0) {
|
|
33274
33400
|
return current;
|
|
33275
33401
|
}
|
|
@@ -33298,7 +33424,7 @@ var StandardSessionConfigProtocol = class {
|
|
|
33298
33424
|
"ACP agent exited while changing session configuration",
|
|
33299
33425
|
change.signal
|
|
33300
33426
|
);
|
|
33301
|
-
if (!
|
|
33427
|
+
if (!isRecord8(response) || !Array.isArray(response["configOptions"])) {
|
|
33302
33428
|
throw new SessionConfigProtocolError("The Agent returned an invalid session configuration response");
|
|
33303
33429
|
}
|
|
33304
33430
|
return replaceStandardConfigOptions(current, response["configOptions"]);
|
|
@@ -33312,31 +33438,31 @@ var standardSessionConfigProtocol = new StandardSessionConfigProtocol();
|
|
|
33312
33438
|
var LEGACY_MODEL_CONFIG_ID = "grok_build_legacy_model";
|
|
33313
33439
|
var LEGACY_REASONING_EFFORT_CONFIG_ID = "grok_build_legacy_reasoning_effort";
|
|
33314
33440
|
function legacyOptions(response) {
|
|
33315
|
-
if (!
|
|
33441
|
+
if (!isRecord8(response)) {
|
|
33316
33442
|
return [];
|
|
33317
33443
|
}
|
|
33318
33444
|
const metadata = response["_meta"];
|
|
33319
|
-
if (!
|
|
33445
|
+
if (!isRecord8(metadata)) {
|
|
33320
33446
|
return [];
|
|
33321
33447
|
}
|
|
33322
33448
|
const sessionConfig = metadata["x.ai/sessionConfig"];
|
|
33323
|
-
if (!
|
|
33449
|
+
if (!isRecord8(sessionConfig) || !Array.isArray(sessionConfig["options"])) {
|
|
33324
33450
|
return [];
|
|
33325
33451
|
}
|
|
33326
|
-
return sessionConfig["options"].slice(0, 500).filter(
|
|
33452
|
+
return sessionConfig["options"].slice(0, 500).filter(isRecord8);
|
|
33327
33453
|
}
|
|
33328
|
-
function legacyValue(
|
|
33329
|
-
const value = readString2(
|
|
33454
|
+
function legacyValue(option) {
|
|
33455
|
+
const value = readString2(option["id"]);
|
|
33330
33456
|
return {
|
|
33331
|
-
description: readString2(
|
|
33457
|
+
description: readString2(option["description"]).slice(0, 500),
|
|
33332
33458
|
groupId: "",
|
|
33333
33459
|
groupName: "",
|
|
33334
|
-
name: readString2(
|
|
33460
|
+
name: readString2(option["label"], value).slice(0, 255),
|
|
33335
33461
|
value: value.slice(0, 500)
|
|
33336
33462
|
};
|
|
33337
33463
|
}
|
|
33338
33464
|
function modelsRecord(response) {
|
|
33339
|
-
if (!
|
|
33465
|
+
if (!isRecord8(response) || !isRecord8(response["models"])) {
|
|
33340
33466
|
return {};
|
|
33341
33467
|
}
|
|
33342
33468
|
return response["models"];
|
|
@@ -33345,9 +33471,9 @@ function legacyModelOptions(response) {
|
|
|
33345
33471
|
const options = legacyOptions(response);
|
|
33346
33472
|
const models = modelsRecord(response);
|
|
33347
33473
|
const values = [];
|
|
33348
|
-
for (const
|
|
33349
|
-
if (
|
|
33350
|
-
const value = legacyValue(
|
|
33474
|
+
for (const option of options) {
|
|
33475
|
+
if (option["category"] === "model") {
|
|
33476
|
+
const value = legacyValue(option);
|
|
33351
33477
|
if (value.value.length > 0 && !values.some((existing) => existing.value === value.value)) {
|
|
33352
33478
|
values.push(value);
|
|
33353
33479
|
}
|
|
@@ -33355,7 +33481,7 @@ function legacyModelOptions(response) {
|
|
|
33355
33481
|
}
|
|
33356
33482
|
if (values.length === 0 && Array.isArray(models["availableModels"])) {
|
|
33357
33483
|
for (const model of models["availableModels"]) {
|
|
33358
|
-
if (!
|
|
33484
|
+
if (!isRecord8(model)) {
|
|
33359
33485
|
continue;
|
|
33360
33486
|
}
|
|
33361
33487
|
const value = readString2(model["modelId"]).slice(0, 500);
|
|
@@ -33373,7 +33499,7 @@ function legacyModelOptions(response) {
|
|
|
33373
33499
|
}
|
|
33374
33500
|
}
|
|
33375
33501
|
}
|
|
33376
|
-
const selected = options.find((
|
|
33502
|
+
const selected = options.find((option) => option["category"] === "model" && option["selected"] === true);
|
|
33377
33503
|
const currentValue = readString2(
|
|
33378
33504
|
models["currentModelId"],
|
|
33379
33505
|
selected === void 0 ? "" : readString2(selected["id"])
|
|
@@ -33396,11 +33522,11 @@ function legacyModelOptions(response) {
|
|
|
33396
33522
|
function legacyReasoningEffortOptions(response) {
|
|
33397
33523
|
const options = legacyOptions(response);
|
|
33398
33524
|
const values = [];
|
|
33399
|
-
for (const
|
|
33400
|
-
if (
|
|
33525
|
+
for (const option of options) {
|
|
33526
|
+
if (option["category"] !== "mode") {
|
|
33401
33527
|
continue;
|
|
33402
33528
|
}
|
|
33403
|
-
const value = legacyValue(
|
|
33529
|
+
const value = legacyValue(option);
|
|
33404
33530
|
if (value.value.length > 0 && !values.some((existing) => existing.value === value.value)) {
|
|
33405
33531
|
values.push(value);
|
|
33406
33532
|
}
|
|
@@ -33408,7 +33534,7 @@ function legacyReasoningEffortOptions(response) {
|
|
|
33408
33534
|
if (values.length === 0) {
|
|
33409
33535
|
return [];
|
|
33410
33536
|
}
|
|
33411
|
-
const selected = options.find((
|
|
33537
|
+
const selected = options.find((option) => option["category"] === "mode" && option["selected"] === true);
|
|
33412
33538
|
if (selected === void 0) {
|
|
33413
33539
|
values.unshift({
|
|
33414
33540
|
description: "Use the selected model's default reasoning effort",
|
|
@@ -33435,41 +33561,41 @@ function legacyReasoningEffortOptions(response) {
|
|
|
33435
33561
|
return [result];
|
|
33436
33562
|
}
|
|
33437
33563
|
function normalizeGrokLifecycle(response) {
|
|
33438
|
-
const lifecycle =
|
|
33564
|
+
const lifecycle = isRecord8(response) ? response : {};
|
|
33439
33565
|
const standard = normalizeConfigOptions(lifecycle["configOptions"], lifecycle["modes"]);
|
|
33440
33566
|
const normalized = [...standard];
|
|
33441
|
-
if (!normalized.some((
|
|
33567
|
+
if (!normalized.some((option) => option.category === "model")) {
|
|
33442
33568
|
normalized.push(...legacyModelOptions(response));
|
|
33443
33569
|
}
|
|
33444
|
-
if (!normalized.some((
|
|
33570
|
+
if (!normalized.some((option) => option.category === "thought_level")) {
|
|
33445
33571
|
const efforts = legacyReasoningEffortOptions(response);
|
|
33446
33572
|
if (efforts.length > 0) {
|
|
33447
|
-
const modelIndex = normalized.findIndex((
|
|
33573
|
+
const modelIndex = normalized.findIndex((option) => option.category === "model");
|
|
33448
33574
|
normalized.splice(modelIndex < 0 ? normalized.length : modelIndex + 1, 0, ...efforts);
|
|
33449
33575
|
}
|
|
33450
33576
|
}
|
|
33451
33577
|
return ensureReasoningEffortOption(normalized.slice(0, 100));
|
|
33452
33578
|
}
|
|
33453
33579
|
function updateCurrentValue2(current, category, value) {
|
|
33454
|
-
return current.map((
|
|
33580
|
+
return current.map((option) => option.category === category ? { ...option, currentValue: value } : option);
|
|
33455
33581
|
}
|
|
33456
33582
|
function validateGrokResponse(response, modelId) {
|
|
33457
|
-
if (!
|
|
33583
|
+
if (!isRecord8(response) || !isRecord8(response["_meta"])) {
|
|
33458
33584
|
throw new SessionConfigProtocolError("Grok Build returned an invalid session configuration response");
|
|
33459
33585
|
}
|
|
33460
33586
|
const model = response["_meta"]["model"];
|
|
33461
|
-
const appliedModel =
|
|
33587
|
+
const appliedModel = isRecord8(model) ? model["Ok"] : model;
|
|
33462
33588
|
if (appliedModel !== modelId) {
|
|
33463
33589
|
throw new SessionConfigProtocolError("Grok Build returned an invalid session configuration response");
|
|
33464
33590
|
}
|
|
33465
33591
|
}
|
|
33466
33592
|
var GrokBuildSessionConfigProtocol = class {
|
|
33467
33593
|
configure = async (current, change, nativeSessionId, transport) => {
|
|
33468
|
-
const existing = current.find((
|
|
33594
|
+
const existing = current.find((option) => option.id === change.configId);
|
|
33469
33595
|
if (existing === void 0 || existing.id !== LEGACY_MODEL_CONFIG_ID && existing.id !== LEGACY_REASONING_EFFORT_CONFIG_ID) {
|
|
33470
33596
|
return await standardSessionConfigProtocol.configure(current, change, nativeSessionId, transport);
|
|
33471
33597
|
}
|
|
33472
|
-
const model = current.find((
|
|
33598
|
+
const model = current.find((option) => option.category === "model");
|
|
33473
33599
|
if (model === void 0) {
|
|
33474
33600
|
return current;
|
|
33475
33601
|
}
|
|
@@ -33495,10 +33621,10 @@ var GrokBuildSessionConfigProtocol = class {
|
|
|
33495
33621
|
validateGrokResponse(response, modelId);
|
|
33496
33622
|
const updated = updateCurrentValue2(current, existing.category, change.value);
|
|
33497
33623
|
return existing.category === "thought_level" ? updated.map(
|
|
33498
|
-
(
|
|
33499
|
-
...
|
|
33500
|
-
values:
|
|
33501
|
-
} :
|
|
33624
|
+
(option) => option.category === "thought_level" ? {
|
|
33625
|
+
...option,
|
|
33626
|
+
values: option.values.filter((value) => value.value !== AGENT_DEFAULT_REASONING_EFFORT)
|
|
33627
|
+
} : option
|
|
33502
33628
|
) : updated;
|
|
33503
33629
|
};
|
|
33504
33630
|
normalizeLifecycle = (response) => normalizeGrokLifecycle(response);
|
|
@@ -33565,7 +33691,7 @@ var AcpHistoryReplay = class {
|
|
|
33565
33691
|
|
|
33566
33692
|
// src/acp/session-store.ts
|
|
33567
33693
|
import { mkdirSync as mkdirSync2 } from "node:fs";
|
|
33568
|
-
import { dirname as
|
|
33694
|
+
import { dirname as dirname5 } from "node:path";
|
|
33569
33695
|
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
33570
33696
|
var AcpStoredSession = class {
|
|
33571
33697
|
additionalDirectories;
|
|
@@ -33668,7 +33794,7 @@ var MemoryAcpSessionStore = class {
|
|
|
33668
33794
|
var SqliteAcpSessionStore = class {
|
|
33669
33795
|
#database;
|
|
33670
33796
|
constructor(path2) {
|
|
33671
|
-
mkdirSync2(
|
|
33797
|
+
mkdirSync2(dirname5(path2), { recursive: true });
|
|
33672
33798
|
this.#database = new DatabaseSync2(path2);
|
|
33673
33799
|
this.#database.exec(`
|
|
33674
33800
|
CREATE TABLE IF NOT EXISTS acp_deleted_sessions (session_id TEXT PRIMARY KEY) STRICT;
|
|
@@ -33969,7 +34095,7 @@ function createWritableAcpStream(output2) {
|
|
|
33969
34095
|
if (outputFailure !== void 0) {
|
|
33970
34096
|
return Promise.reject(outputFailure);
|
|
33971
34097
|
}
|
|
33972
|
-
return new Promise((
|
|
34098
|
+
return new Promise((resolve7, reject) => {
|
|
33973
34099
|
pendingWriteFailures.add(reject);
|
|
33974
34100
|
output2.write(chunk, (error62) => {
|
|
33975
34101
|
pendingWriteFailures.delete(reject);
|
|
@@ -33982,7 +34108,7 @@ function createWritableAcpStream(output2) {
|
|
|
33982
34108
|
reject(outputFailure);
|
|
33983
34109
|
return;
|
|
33984
34110
|
}
|
|
33985
|
-
|
|
34111
|
+
resolve7();
|
|
33986
34112
|
});
|
|
33987
34113
|
});
|
|
33988
34114
|
}
|
|
@@ -33991,7 +34117,7 @@ function createWritableAcpStream(output2) {
|
|
|
33991
34117
|
function truncate3(value, maximumLength) {
|
|
33992
34118
|
return value.length <= maximumLength ? value : `${value.slice(0, Math.max(0, maximumLength - 1))}\u2026`;
|
|
33993
34119
|
}
|
|
33994
|
-
function
|
|
34120
|
+
function isRecord9(value) {
|
|
33995
34121
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33996
34122
|
}
|
|
33997
34123
|
function readString4(value, fallback = "") {
|
|
@@ -34024,12 +34150,12 @@ function normalizeElicitationOptions(schema) {
|
|
|
34024
34150
|
const normalized = [];
|
|
34025
34151
|
const oneOf = schema["oneOf"];
|
|
34026
34152
|
if (Array.isArray(oneOf)) {
|
|
34027
|
-
for (const
|
|
34028
|
-
if (
|
|
34153
|
+
for (const option of oneOf) {
|
|
34154
|
+
if (isRecord9(option) && typeof option["const"] === "string") {
|
|
34029
34155
|
normalized.push({
|
|
34030
|
-
description: truncate3(readString4(
|
|
34031
|
-
label: truncate3(readString4(
|
|
34032
|
-
value: truncate3(
|
|
34156
|
+
description: truncate3(readString4(option["description"]), 500),
|
|
34157
|
+
label: truncate3(readString4(option["title"], option["const"]), 255),
|
|
34158
|
+
value: truncate3(option["const"], 500)
|
|
34033
34159
|
});
|
|
34034
34160
|
}
|
|
34035
34161
|
}
|
|
@@ -34045,7 +34171,7 @@ function normalizeElicitationOptions(schema) {
|
|
|
34045
34171
|
return normalized.slice(0, 200);
|
|
34046
34172
|
}
|
|
34047
34173
|
const items = schema["items"];
|
|
34048
|
-
if (!
|
|
34174
|
+
if (!isRecord9(items)) {
|
|
34049
34175
|
return normalized;
|
|
34050
34176
|
}
|
|
34051
34177
|
const anyOf = items["anyOf"];
|
|
@@ -34058,7 +34184,7 @@ function numericString(value) {
|
|
|
34058
34184
|
return typeof value === "number" && Number.isFinite(value) ? value.toString() : "";
|
|
34059
34185
|
}
|
|
34060
34186
|
function normalizeElicitationFields(requestedSchema) {
|
|
34061
|
-
if (!
|
|
34187
|
+
if (!isRecord9(requestedSchema) || !isRecord9(requestedSchema["properties"])) {
|
|
34062
34188
|
return [];
|
|
34063
34189
|
}
|
|
34064
34190
|
const properties2 = requestedSchema["properties"];
|
|
@@ -34068,7 +34194,7 @@ function normalizeElicitationFields(requestedSchema) {
|
|
|
34068
34194
|
);
|
|
34069
34195
|
const normalized = [];
|
|
34070
34196
|
for (const [name, property] of Object.entries(properties2)) {
|
|
34071
|
-
if (!
|
|
34197
|
+
if (!isRecord9(property)) {
|
|
34072
34198
|
continue;
|
|
34073
34199
|
}
|
|
34074
34200
|
const type = elicitationFieldType(property["type"]);
|
|
@@ -34159,7 +34285,7 @@ function validateElicitationContent(encoded, requestedSchema) {
|
|
|
34159
34285
|
"invalid_elicitation_response"
|
|
34160
34286
|
);
|
|
34161
34287
|
}
|
|
34162
|
-
if (!
|
|
34288
|
+
if (!isRecord9(decoded) || !isRecord9(requestedSchema) || !isRecord9(requestedSchema["properties"])) {
|
|
34163
34289
|
throw new AcpExecutionError(
|
|
34164
34290
|
"Elicitation response does not match the requested form",
|
|
34165
34291
|
{},
|
|
@@ -34179,7 +34305,7 @@ function validateElicitationContent(encoded, requestedSchema) {
|
|
|
34179
34305
|
const validated = {};
|
|
34180
34306
|
for (const [name, value] of Object.entries(decoded)) {
|
|
34181
34307
|
const property = properties2[name];
|
|
34182
|
-
if (!
|
|
34308
|
+
if (!isRecord9(property)) {
|
|
34183
34309
|
throw new AcpExecutionError(
|
|
34184
34310
|
`Elicitation field ${name} was not requested`,
|
|
34185
34311
|
{},
|
|
@@ -34216,7 +34342,7 @@ function validateElicitationContent(encoded, requestedSchema) {
|
|
|
34216
34342
|
);
|
|
34217
34343
|
}
|
|
34218
34344
|
const allowed = normalizeElicitationOptions(property);
|
|
34219
|
-
if (allowed.length > 0 && value.some((entry) => !allowed.some((
|
|
34345
|
+
if (allowed.length > 0 && value.some((entry) => !allowed.some((option) => option.value === entry))) {
|
|
34220
34346
|
throw new AcpExecutionError(
|
|
34221
34347
|
`Elicitation field ${name} contains an invalid selection`,
|
|
34222
34348
|
{},
|
|
@@ -34332,6 +34458,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
34332
34458
|
#permissionProfile;
|
|
34333
34459
|
#sessionConfigProtocol;
|
|
34334
34460
|
#store;
|
|
34461
|
+
#emittedToolImages = /* @__PURE__ */ new Set();
|
|
34335
34462
|
#verifiedAgentVersion;
|
|
34336
34463
|
#preSessionUpdateBytes = 0;
|
|
34337
34464
|
#agentName = "";
|
|
@@ -34394,9 +34521,9 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
34394
34521
|
stderr.on("data", (chunk) => {
|
|
34395
34522
|
process.stderr.write(`[${agent.id}-acp] ${chunk}`);
|
|
34396
34523
|
});
|
|
34397
|
-
this.#processExit = new Promise((
|
|
34398
|
-
this.#child.once("error",
|
|
34399
|
-
this.#child.once("exit",
|
|
34524
|
+
this.#processExit = new Promise((resolve7) => {
|
|
34525
|
+
this.#child.once("error", resolve7);
|
|
34526
|
+
this.#child.once("exit", resolve7);
|
|
34400
34527
|
});
|
|
34401
34528
|
const stream = ndJsonStream2(createWritableAcpStream(stdin), readableWebStream(stdout));
|
|
34402
34529
|
this.#connection = createAcpClient(this).connect(stream);
|
|
@@ -34552,19 +34679,19 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
34552
34679
|
}
|
|
34553
34680
|
};
|
|
34554
34681
|
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) {
|
|
34682
|
+
if (content3.type === "image" && content3.uri.length > 0) {
|
|
34562
34683
|
const signal = AbortSignal.timeout(2e4);
|
|
34563
34684
|
const raster = await readLocalRaster(content3.uri, signal);
|
|
34564
34685
|
if (raster !== null) {
|
|
34565
34686
|
return await this.importRaster(raster, signal);
|
|
34566
34687
|
}
|
|
34567
34688
|
}
|
|
34689
|
+
if (content3.type === "image" && content3.data.length > 0) {
|
|
34690
|
+
const raster = readInlineRaster(content3.data, content3.name);
|
|
34691
|
+
if (raster !== null) {
|
|
34692
|
+
return await this.importRaster(raster, AbortSignal.timeout(2e4));
|
|
34693
|
+
}
|
|
34694
|
+
}
|
|
34568
34695
|
if (content3.type === "video" && content3.data.length > 0) {
|
|
34569
34696
|
const video = readInlineVideo(content3.data, content3.mimeType, content3.name);
|
|
34570
34697
|
if (video === null) {
|
|
@@ -34585,6 +34712,22 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
34585
34712
|
sessionId: this.#mobiusSessionId
|
|
34586
34713
|
});
|
|
34587
34714
|
};
|
|
34715
|
+
emitToolImages = async (update) => {
|
|
34716
|
+
if (update.status !== "completed") {
|
|
34717
|
+
return;
|
|
34718
|
+
}
|
|
34719
|
+
for (const [index2, item] of (update.content ?? []).entries()) {
|
|
34720
|
+
if (item.type !== "content" || item.content.type !== "image") {
|
|
34721
|
+
continue;
|
|
34722
|
+
}
|
|
34723
|
+
const key = `${update.toolCallId}:${index2.toString()}`;
|
|
34724
|
+
if (this.#emittedToolImages.has(key)) {
|
|
34725
|
+
continue;
|
|
34726
|
+
}
|
|
34727
|
+
this.#emittedToolImages.add(key);
|
|
34728
|
+
await this.emitAgentContent(normalizeContentBlock(item.content), `tool-${key}`);
|
|
34729
|
+
}
|
|
34730
|
+
};
|
|
34588
34731
|
emitRaster = async (raster, messageId, signal) => {
|
|
34589
34732
|
const content3 = await this.importRaster(raster, signal);
|
|
34590
34733
|
await this.#getObserver().onContent({
|
|
@@ -34596,14 +34739,14 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
34596
34739
|
sessionId: this.#mobiusSessionId
|
|
34597
34740
|
});
|
|
34598
34741
|
};
|
|
34599
|
-
importRaster = async (raster,
|
|
34600
|
-
|
|
34601
|
-
|
|
34602
|
-
|
|
34603
|
-
|
|
34604
|
-
|
|
34605
|
-
|
|
34606
|
-
);
|
|
34742
|
+
importRaster = async (raster, _signal) => {
|
|
34743
|
+
if (raster.sourceUri.length > 0) {
|
|
34744
|
+
return {
|
|
34745
|
+
...imageDisplayContent(raster.mimeType, raster.name, "", ""),
|
|
34746
|
+
uri: raster.sourceUri
|
|
34747
|
+
};
|
|
34748
|
+
}
|
|
34749
|
+
return imageDisplayContent(raster.mimeType, raster.name, await raster.base64(), "");
|
|
34607
34750
|
};
|
|
34608
34751
|
importVideo = async (video, signal) => {
|
|
34609
34752
|
const artifactId = await this.#getObserver().importLocalArtifact(this.#mobiusSessionId, video, signal);
|
|
@@ -34890,7 +35033,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
34890
35033
|
};
|
|
34891
35034
|
nativeSessionId = () => this.#nativeSessionId;
|
|
34892
35035
|
configure = async (options) => {
|
|
34893
|
-
const existing = this.#configOptions.find((
|
|
35036
|
+
const existing = this.#configOptions.find((option) => option.id === options.configId);
|
|
34894
35037
|
if (existing === void 0 || existing.type !== options.valueType) {
|
|
34895
35038
|
throw new AcpExecutionError(
|
|
34896
35039
|
"The requested ACP configuration option is unavailable",
|
|
@@ -35087,7 +35230,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
35087
35230
|
"ACP agent exited during steering",
|
|
35088
35231
|
options.signal
|
|
35089
35232
|
);
|
|
35090
|
-
if (!
|
|
35233
|
+
if (!isRecord9(response)) {
|
|
35091
35234
|
throw new AcpExecutionError(
|
|
35092
35235
|
"ACP agent returned an invalid steering response",
|
|
35093
35236
|
{},
|
|
@@ -35202,10 +35345,10 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
35202
35345
|
onPermission = async (request, signal) => {
|
|
35203
35346
|
this.assertNativeSession(request.sessionId);
|
|
35204
35347
|
const interactionId = `permission-${crypto.randomUUID()}`;
|
|
35205
|
-
const options = request.options.slice(0, 20).map((
|
|
35206
|
-
kind:
|
|
35207
|
-
name: truncate3(
|
|
35208
|
-
optionId: truncate3(
|
|
35348
|
+
const options = request.options.slice(0, 20).map((option) => ({
|
|
35349
|
+
kind: option.kind,
|
|
35350
|
+
name: truncate3(option.name, 255),
|
|
35351
|
+
optionId: truncate3(option.optionId, 255)
|
|
35209
35352
|
}));
|
|
35210
35353
|
if (options.length === 0) {
|
|
35211
35354
|
throw new AcpExecutionError(
|
|
@@ -35214,7 +35357,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
35214
35357
|
"invalid_agent_permission_request"
|
|
35215
35358
|
);
|
|
35216
35359
|
}
|
|
35217
|
-
const pending = new PendingPermission(interactionId, new Set(options.map((
|
|
35360
|
+
const pending = new PendingPermission(interactionId, new Set(options.map((option) => option.optionId)));
|
|
35218
35361
|
this.#pendingPermissions.set(interactionId, pending);
|
|
35219
35362
|
const abort = () => {
|
|
35220
35363
|
void this.cancelPermission(interactionId);
|
|
@@ -35383,6 +35526,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
35383
35526
|
}
|
|
35384
35527
|
if (update.sessionUpdate === "tool_call_update") {
|
|
35385
35528
|
await this.#turn.activities.recordToolCallUpdate(update);
|
|
35529
|
+
await this.emitToolImages(update);
|
|
35386
35530
|
return;
|
|
35387
35531
|
}
|
|
35388
35532
|
if (update.sessionUpdate === "plan") {
|
|
@@ -35422,7 +35566,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
35422
35566
|
}
|
|
35423
35567
|
if (update.sessionUpdate === "current_mode_update") {
|
|
35424
35568
|
this.#configOptions = this.#configOptions.map(
|
|
35425
|
-
(
|
|
35569
|
+
(option) => option.category === "mode" ? { ...option, currentValue: update.currentModeId } : option
|
|
35426
35570
|
);
|
|
35427
35571
|
this.#configRevision += 1;
|
|
35428
35572
|
await this.emitConfigUpdate();
|
|
@@ -35955,7 +36099,7 @@ var AcpSessionManager = class {
|
|
|
35955
36099
|
if (desired.id === PERMISSION_MODE_CONFIG_ID) {
|
|
35956
36100
|
continue;
|
|
35957
36101
|
}
|
|
35958
|
-
const current = runtime.prepared().configOptions.find((
|
|
36102
|
+
const current = runtime.prepared().configOptions.find((option) => option.id === desired.id);
|
|
35959
36103
|
if (current === void 0 || current.type !== desired.type) {
|
|
35960
36104
|
continue;
|
|
35961
36105
|
}
|
|
@@ -36061,7 +36205,7 @@ var AcpSessionManager = class {
|
|
|
36061
36205
|
async (runtime) => await runtime.close()
|
|
36062
36206
|
);
|
|
36063
36207
|
/**
|
|
36064
|
-
*
|
|
36208
|
+
* Retained for Agents that expose a separate persisted configuration channel.
|
|
36065
36209
|
* Use inspectAgentSettings for Agent-scoped settings discovery.
|
|
36066
36210
|
*/
|
|
36067
36211
|
inspectSession = async (options, metrics = unmeasuredOperationMetrics) => {
|
|
@@ -36655,7 +36799,6 @@ async function publishAgentCatalog(config2, signal) {
|
|
|
36655
36799
|
agentPath: agent.agentIdentity.requestedPath,
|
|
36656
36800
|
agentVersion: agent.agentVersion,
|
|
36657
36801
|
agentSettingsDiscovery: true,
|
|
36658
|
-
botSessionConfiguration: true,
|
|
36659
36802
|
capabilities: agent.capabilities,
|
|
36660
36803
|
id: agent.id,
|
|
36661
36804
|
label: agent.label,
|
|
@@ -36947,7 +37090,7 @@ var AgentInstallationManager = class {
|
|
|
36947
37090
|
|
|
36948
37091
|
// src/agent-installation/fixed-installation-executor.ts
|
|
36949
37092
|
import { realpathSync as realpathSync2, statSync as statSync2 } from "node:fs";
|
|
36950
|
-
import { resolve as
|
|
37093
|
+
import { resolve as resolve6 } from "node:path";
|
|
36951
37094
|
function findSpecification(specifications, agentId) {
|
|
36952
37095
|
for (const specification of specifications) {
|
|
36953
37096
|
if (specification.id === agentId) {
|
|
@@ -36958,7 +37101,7 @@ function findSpecification(specifications, agentId) {
|
|
|
36958
37101
|
}
|
|
36959
37102
|
function resolveDefaultWorkspace2(path2) {
|
|
36960
37103
|
try {
|
|
36961
|
-
const directory = realpathSync2(
|
|
37104
|
+
const directory = realpathSync2(resolve6(path2));
|
|
36962
37105
|
if (!statSync2(directory).isDirectory()) {
|
|
36963
37106
|
throw new Error("Default workspace is not a directory");
|
|
36964
37107
|
}
|
|
@@ -36973,7 +37116,7 @@ function resolveDefaultWorkspace2(path2) {
|
|
|
36973
37116
|
}
|
|
36974
37117
|
function resolveIntegrationStateDirectory(path2) {
|
|
36975
37118
|
try {
|
|
36976
|
-
const directory = realpathSync2(
|
|
37119
|
+
const directory = realpathSync2(resolve6(path2));
|
|
36977
37120
|
const metadata = statSync2(directory);
|
|
36978
37121
|
if (!metadata.isDirectory() || typeof process.getuid === "function" && metadata.uid !== process.getuid()) {
|
|
36979
37122
|
throw new Error("Installation directory is not user-owned");
|
|
@@ -37142,8 +37285,93 @@ var FixedInstallationExecutor = class {
|
|
|
37142
37285
|
};
|
|
37143
37286
|
};
|
|
37144
37287
|
|
|
37288
|
+
// src/artifacts/local-file-streamer.ts
|
|
37289
|
+
import { createReadStream as createReadStream2 } from "node:fs";
|
|
37290
|
+
import { realpath as realpath8, stat as stat7 } from "node:fs/promises";
|
|
37291
|
+
import { basename as basename4, isAbsolute as isAbsolute9, normalize as normalize3 } from "node:path";
|
|
37292
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
37293
|
+
var CHUNK_BYTES = 192 * 1024;
|
|
37294
|
+
function requestedPath(value) {
|
|
37295
|
+
if (value.includes("\0")) {
|
|
37296
|
+
return null;
|
|
37297
|
+
}
|
|
37298
|
+
if (value.startsWith("file:")) {
|
|
37299
|
+
try {
|
|
37300
|
+
const url2 = new URL(value);
|
|
37301
|
+
return url2.protocol === "file:" && url2.host.length === 0 ? fileURLToPath2(url2) : null;
|
|
37302
|
+
} catch {
|
|
37303
|
+
return null;
|
|
37304
|
+
}
|
|
37305
|
+
}
|
|
37306
|
+
return value;
|
|
37307
|
+
}
|
|
37308
|
+
async function resolveFile(value, signal) {
|
|
37309
|
+
const requested = requestedPath(value);
|
|
37310
|
+
if (requested === null || !isAbsolute9(requested) || normalize3(requested) !== requested) {
|
|
37311
|
+
return null;
|
|
37312
|
+
}
|
|
37313
|
+
try {
|
|
37314
|
+
const target = await realpath8(requested);
|
|
37315
|
+
signal.throwIfAborted();
|
|
37316
|
+
return isAbsolute9(target) && normalize3(target) === target ? target : null;
|
|
37317
|
+
} catch {
|
|
37318
|
+
signal.throwIfAborted();
|
|
37319
|
+
return null;
|
|
37320
|
+
}
|
|
37321
|
+
}
|
|
37322
|
+
async function streamLocalFile(command, send2, signal) {
|
|
37323
|
+
const target = await resolveFile(command.path, signal);
|
|
37324
|
+
if (target === null) {
|
|
37325
|
+
throw new Error("The local file is unavailable");
|
|
37326
|
+
}
|
|
37327
|
+
const before = await stat7(target);
|
|
37328
|
+
signal.throwIfAborted();
|
|
37329
|
+
if (!before.isFile() || before.size < 1 || before.size > command.maxBytes) {
|
|
37330
|
+
throw new Error("The local file is too large to read");
|
|
37331
|
+
}
|
|
37332
|
+
const raster = await readLocalRaster(target, signal);
|
|
37333
|
+
send2(
|
|
37334
|
+
encodeFileBeginEvent({
|
|
37335
|
+
byteLength: before.size,
|
|
37336
|
+
kind: FILE_BEGIN_KIND,
|
|
37337
|
+
mediaType: raster?.mimeType ?? "application/octet-stream",
|
|
37338
|
+
modifiedAt: before.mtime.toISOString(),
|
|
37339
|
+
name: basename4(target) || "file",
|
|
37340
|
+
requestId: command.requestId,
|
|
37341
|
+
sessionId: command.sessionId
|
|
37342
|
+
})
|
|
37343
|
+
);
|
|
37344
|
+
let sequence = 0;
|
|
37345
|
+
const stream = createReadStream2(target, { highWaterMark: CHUNK_BYTES, signal });
|
|
37346
|
+
for await (const value of stream) {
|
|
37347
|
+
const bytes = value instanceof Uint8Array ? value : new Uint8Array(value);
|
|
37348
|
+
send2(
|
|
37349
|
+
encodeFileChunkEvent({
|
|
37350
|
+
data: Buffer.from(bytes).toString("base64"),
|
|
37351
|
+
kind: FILE_CHUNK_KIND,
|
|
37352
|
+
requestId: command.requestId,
|
|
37353
|
+
sequence,
|
|
37354
|
+
sessionId: command.sessionId
|
|
37355
|
+
})
|
|
37356
|
+
);
|
|
37357
|
+
sequence += 1;
|
|
37358
|
+
}
|
|
37359
|
+
const after = await stat7(target);
|
|
37360
|
+
signal.throwIfAborted();
|
|
37361
|
+
if (after.size !== before.size || after.mtimeMs !== before.mtimeMs) {
|
|
37362
|
+
throw new Error("The local file changed during transfer");
|
|
37363
|
+
}
|
|
37364
|
+
send2(
|
|
37365
|
+
encodeFileEndEvent({
|
|
37366
|
+
kind: FILE_END_KIND,
|
|
37367
|
+
requestId: command.requestId,
|
|
37368
|
+
sessionId: command.sessionId
|
|
37369
|
+
})
|
|
37370
|
+
);
|
|
37371
|
+
}
|
|
37372
|
+
|
|
37145
37373
|
// src/artifacts/runtime-artifact-uploader.ts
|
|
37146
|
-
import { createHash as
|
|
37374
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
37147
37375
|
|
|
37148
37376
|
// ../mobius-sdk/src/errors.ts
|
|
37149
37377
|
var MobiusError = class extends Error {
|
|
@@ -37172,11 +37400,11 @@ var IDENTIFIER_PATTERN6 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
|
37172
37400
|
function invalidResponse(message) {
|
|
37173
37401
|
return new MobiusProtocolError(message);
|
|
37174
37402
|
}
|
|
37175
|
-
function
|
|
37403
|
+
function isRecord10(value) {
|
|
37176
37404
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
37177
37405
|
}
|
|
37178
37406
|
function record3(value, name) {
|
|
37179
|
-
if (!
|
|
37407
|
+
if (!isRecord10(value)) {
|
|
37180
37408
|
throw invalidResponse(`The service returned an invalid ${name}`);
|
|
37181
37409
|
}
|
|
37182
37410
|
return value;
|
|
@@ -37462,7 +37690,7 @@ async function uploadRuntimeArtifact(config2, sessionId, artifact, signal) {
|
|
|
37462
37690
|
artifact.name,
|
|
37463
37691
|
artifact.mimeType,
|
|
37464
37692
|
artifact.bytes.byteLength,
|
|
37465
|
-
|
|
37693
|
+
createHash3("sha256").update(artifact.bytes).digest("hex")
|
|
37466
37694
|
);
|
|
37467
37695
|
} catch (cause) {
|
|
37468
37696
|
translateSdkError(cause);
|
|
@@ -37537,9 +37765,9 @@ var LocalAuthorizationError = class extends Error {
|
|
|
37537
37765
|
};
|
|
37538
37766
|
|
|
37539
37767
|
// src/authorization/workspace-directory.ts
|
|
37540
|
-
import { readdir as readdir2, realpath as
|
|
37768
|
+
import { readdir as readdir2, realpath as realpath9, stat as stat8 } from "node:fs/promises";
|
|
37541
37769
|
import { homedir as homedir2 } from "node:os";
|
|
37542
|
-
import { basename as
|
|
37770
|
+
import { basename as basename5, dirname as dirname6, isAbsolute as isAbsolute10, join as join16, normalize as normalize4, relative as relative4 } from "node:path";
|
|
37543
37771
|
var WorkspaceDirectoryListing = class {
|
|
37544
37772
|
directoryId;
|
|
37545
37773
|
directoryLabel;
|
|
@@ -37565,7 +37793,7 @@ function decodePath(value, prefix) {
|
|
|
37565
37793
|
throw new LocalAuthorizationError("The directory identifier is invalid");
|
|
37566
37794
|
}
|
|
37567
37795
|
const decoded = Buffer.from(encoded, "base64url").toString("utf8");
|
|
37568
|
-
if (Buffer.from(decoded, "utf8").toString("base64url") !== encoded || decoded.includes("\0") ||
|
|
37796
|
+
if (Buffer.from(decoded, "utf8").toString("base64url") !== encoded || decoded.includes("\0") || normalize4(decoded) !== decoded) {
|
|
37569
37797
|
throw new LocalAuthorizationError("The directory identifier is invalid");
|
|
37570
37798
|
}
|
|
37571
37799
|
return decoded;
|
|
@@ -37591,7 +37819,7 @@ var WorkspaceDirectoryService = class {
|
|
|
37591
37819
|
}
|
|
37592
37820
|
if (id.startsWith("path-")) {
|
|
37593
37821
|
const path2 = decodePath(id, "path-");
|
|
37594
|
-
if (
|
|
37822
|
+
if (isAbsolute10(path2)) {
|
|
37595
37823
|
return path2;
|
|
37596
37824
|
}
|
|
37597
37825
|
}
|
|
@@ -37599,15 +37827,15 @@ var WorkspaceDirectoryService = class {
|
|
|
37599
37827
|
};
|
|
37600
37828
|
resolvePath = async (requested, signal) => {
|
|
37601
37829
|
signal.throwIfAborted();
|
|
37602
|
-
if (!
|
|
37830
|
+
if (!isAbsolute10(requested) || requested.includes("\0") || normalize4(requested) !== requested) {
|
|
37603
37831
|
throw new LocalAuthorizationError("The local directory path is invalid");
|
|
37604
37832
|
}
|
|
37605
37833
|
try {
|
|
37606
|
-
const target = await
|
|
37834
|
+
const target = await realpath9(requested);
|
|
37607
37835
|
signal.throwIfAborted();
|
|
37608
|
-
const metadata = await
|
|
37836
|
+
const metadata = await stat8(target);
|
|
37609
37837
|
signal.throwIfAborted();
|
|
37610
|
-
if (!
|
|
37838
|
+
if (!isAbsolute10(target) || normalize4(target) !== target || !metadata.isDirectory()) {
|
|
37611
37839
|
throw new LocalAuthorizationError("The selected location is not a directory");
|
|
37612
37840
|
}
|
|
37613
37841
|
return target;
|
|
@@ -37623,15 +37851,15 @@ var WorkspaceDirectoryService = class {
|
|
|
37623
37851
|
};
|
|
37624
37852
|
label = (path2) => {
|
|
37625
37853
|
const suffix = relative4(homedir2(), path2);
|
|
37626
|
-
return suffix === "" ? "~" : !
|
|
37854
|
+
return suffix === "" ? "~" : !isAbsolute10(suffix) && suffix !== ".." && !suffix.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) ? `~/${suffix.replaceAll("\\", "/")}` : path2;
|
|
37627
37855
|
};
|
|
37628
|
-
identify = async (bindingId,
|
|
37856
|
+
identify = async (bindingId, requestedPath2, signal) => {
|
|
37629
37857
|
this.authorizeMachine(bindingId);
|
|
37630
|
-
const path2 = await this.resolvePath(
|
|
37858
|
+
const path2 = await this.resolvePath(requestedPath2, signal);
|
|
37631
37859
|
return {
|
|
37632
37860
|
path: path2,
|
|
37633
37861
|
directoryId: encodePath(path2),
|
|
37634
|
-
name:
|
|
37862
|
+
name: basename5(path2) || path2,
|
|
37635
37863
|
label: this.label(path2)
|
|
37636
37864
|
};
|
|
37637
37865
|
};
|
|
@@ -37663,7 +37891,7 @@ var WorkspaceDirectoryService = class {
|
|
|
37663
37891
|
}
|
|
37664
37892
|
}
|
|
37665
37893
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
37666
|
-
const parent =
|
|
37894
|
+
const parent = dirname6(target);
|
|
37667
37895
|
return new WorkspaceDirectoryListing(
|
|
37668
37896
|
id,
|
|
37669
37897
|
this.label(target),
|
|
@@ -37687,436 +37915,9 @@ var WorkspaceDirectoryService = class {
|
|
|
37687
37915
|
};
|
|
37688
37916
|
};
|
|
37689
37917
|
|
|
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
37918
|
// src/native-sessions/service.ts
|
|
38118
|
-
import { randomUUID as
|
|
38119
|
-
import { basename as
|
|
37919
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
37920
|
+
import { basename as basename6 } from "node:path";
|
|
38120
37921
|
|
|
38121
37922
|
// src/native-sessions/codex-history.ts
|
|
38122
37923
|
import { spawn as spawn4 } from "node:child_process";
|
|
@@ -38410,7 +38211,7 @@ var NativeSessionService = class {
|
|
|
38410
38211
|
if (authorized === null) {
|
|
38411
38212
|
return null;
|
|
38412
38213
|
}
|
|
38413
|
-
const entryId =
|
|
38214
|
+
const entryId = randomUUID2();
|
|
38414
38215
|
if (this.#entries.size >= 5e3) {
|
|
38415
38216
|
this.#entries.clear();
|
|
38416
38217
|
}
|
|
@@ -38464,7 +38265,7 @@ var NativeSessionService = class {
|
|
|
38464
38265
|
"invalid_native_session_response"
|
|
38465
38266
|
);
|
|
38466
38267
|
}
|
|
38467
|
-
nextCursor =
|
|
38268
|
+
nextCursor = randomUUID2();
|
|
38468
38269
|
if (this.#cursors.size >= 500) {
|
|
38469
38270
|
this.#cursors.clear();
|
|
38470
38271
|
}
|
|
@@ -38625,7 +38426,7 @@ var NativeSessionService = class {
|
|
|
38625
38426
|
}
|
|
38626
38427
|
resolvedPaths.add(path2);
|
|
38627
38428
|
additionalDirectories.push(path2);
|
|
38628
|
-
additionalEntries.push({ directoryId: directoryId2, name:
|
|
38429
|
+
additionalEntries.push({ directoryId: directoryId2, name: basename6(path2) });
|
|
38629
38430
|
}
|
|
38630
38431
|
const listing = await this.#directories.list(this.#config.bindingId, command.directoryId, signal);
|
|
38631
38432
|
const opened = await this.#sessions.forkSessionAtTurn(
|
|
@@ -38782,13 +38583,13 @@ var NativeSessionService = class {
|
|
|
38782
38583
|
};
|
|
38783
38584
|
|
|
38784
38585
|
// src/prompt-artifact-resolver.ts
|
|
38785
|
-
import { createHash as
|
|
38786
|
-
import { fetch as
|
|
38586
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
38587
|
+
import { fetch as fetch5 } from "undici";
|
|
38787
38588
|
var ARTIFACT_SCHEME = "mobius-artifact:";
|
|
38788
38589
|
var ARTIFACT_DOWNLOAD_TIMEOUT_MILLISECONDS = 2e4;
|
|
38789
38590
|
var MAX_AGENT_IMAGE_BASE64_LENGTH = 4e6;
|
|
38790
38591
|
var MAX_AGENT_RESOURCE_BYTE_LENGTH = 1e6;
|
|
38791
|
-
var
|
|
38592
|
+
var IDENTIFIER_PATTERN7 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
38792
38593
|
var PromptArtifactError = class extends Error {
|
|
38793
38594
|
code;
|
|
38794
38595
|
constructor(code, message, options = {}) {
|
|
@@ -38831,7 +38632,7 @@ function parseReference(resource) {
|
|
|
38831
38632
|
const encodedByteLength2 = url2.searchParams.get("byteLength") ?? "";
|
|
38832
38633
|
const sha256 = url2.searchParams.get("sha256") ?? "";
|
|
38833
38634
|
const byteLength = Number(encodedByteLength2);
|
|
38834
|
-
if (url2.protocol !== ARTIFACT_SCHEME || url2.hash.length > 0 || resource.type !== "link" || resource.text.length > 0 || !
|
|
38635
|
+
if (url2.protocol !== ARTIFACT_SCHEME || url2.hash.length > 0 || resource.type !== "link" || resource.text.length > 0 || !IDENTIFIER_PATTERN7.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
38636
|
throw new PromptArtifactError("artifact_reference_invalid", "The prompt artifact reference is invalid");
|
|
38836
38637
|
}
|
|
38837
38638
|
return new PromptArtifactReference(artifactId, byteLength, sha256, resource);
|
|
@@ -38897,7 +38698,7 @@ async function download(config2, command, reference, signal) {
|
|
|
38897
38698
|
const requestSignal = AbortSignal.any([signal, timeoutSignal]);
|
|
38898
38699
|
let response;
|
|
38899
38700
|
try {
|
|
38900
|
-
response = await
|
|
38701
|
+
response = await fetch5(downloadUrl(config2, command, reference), {
|
|
38901
38702
|
dispatcher: environmentProxyDispatcher,
|
|
38902
38703
|
headers: {
|
|
38903
38704
|
accept: reference.resource.mimeType,
|
|
@@ -38921,7 +38722,7 @@ async function download(config2, command, reference, signal) {
|
|
|
38921
38722
|
);
|
|
38922
38723
|
}
|
|
38923
38724
|
const bytes = await responseBytes(response, reference.byteLength, requestSignal);
|
|
38924
|
-
if (
|
|
38725
|
+
if (createHash4("sha256").update(bytes).digest("hex") !== reference.sha256) {
|
|
38925
38726
|
throw new PromptArtifactError(
|
|
38926
38727
|
"artifact_integrity_failed",
|
|
38927
38728
|
"The prompt artifact failed integrity validation"
|
|
@@ -39011,7 +38812,7 @@ var RelayConnectionError = class extends Error {
|
|
|
39011
38812
|
};
|
|
39012
38813
|
function connectRelay(url2, signal) {
|
|
39013
38814
|
signal.throwIfAborted();
|
|
39014
|
-
return new Promise((
|
|
38815
|
+
return new Promise((resolve7, reject) => {
|
|
39015
38816
|
const endpoint = new URL(url2);
|
|
39016
38817
|
const headers = runtimeAuthorization(endpoint);
|
|
39017
38818
|
endpoint.searchParams.delete("token");
|
|
@@ -39074,7 +38875,7 @@ function connectRelay(url2, signal) {
|
|
|
39074
38875
|
}
|
|
39075
38876
|
finished = true;
|
|
39076
38877
|
cleanup();
|
|
39077
|
-
|
|
38878
|
+
resolve7(socket);
|
|
39078
38879
|
};
|
|
39079
38880
|
function onTimeout() {
|
|
39080
38881
|
fail(
|
|
@@ -39230,7 +39031,7 @@ var RelayConnectionDiagnostics = class {
|
|
|
39230
39031
|
};
|
|
39231
39032
|
|
|
39232
39033
|
// src/relay-connection/liveness.ts
|
|
39233
|
-
import { randomUUID as
|
|
39034
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
39234
39035
|
var HEARTBEAT_ACK_TIMEOUT_MILLISECONDS = 1e4;
|
|
39235
39036
|
var HEARTBEAT_INTERVAL_MILLISECONDS = 2e4;
|
|
39236
39037
|
var RelayLivenessState = class {
|
|
@@ -39319,7 +39120,7 @@ var RelayConnectionLiveness = class {
|
|
|
39319
39120
|
}
|
|
39320
39121
|
throw new Error("Heartbeat was scheduled in an invalid state");
|
|
39321
39122
|
}
|
|
39322
|
-
const heartbeatId =
|
|
39123
|
+
const heartbeatId = randomUUID3();
|
|
39323
39124
|
this.#state = new AwaitingHeartbeatAckState(
|
|
39324
39125
|
heartbeatId,
|
|
39325
39126
|
this.#timer.schedule(this.#handleTimeout, HEARTBEAT_ACK_TIMEOUT_MILLISECONDS)
|
|
@@ -39934,12 +39735,6 @@ var RELAY_RECONNECT_DELAY_MILLISECONDS = 500;
|
|
|
39934
39735
|
var AGENT_ACTIVITY_COALESCING_MILLISECONDS = 100;
|
|
39935
39736
|
var ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS = 2e4;
|
|
39936
39737
|
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
39738
|
var DaemonAcpObserver = class {
|
|
39944
39739
|
#config;
|
|
39945
39740
|
#record;
|
|
@@ -40157,7 +39952,7 @@ async function reconcileActiveTurn(config2, turn, signal) {
|
|
|
40157
39952
|
const requestSignal = AbortSignal.any([signal, timeoutSignal]);
|
|
40158
39953
|
let response;
|
|
40159
39954
|
try {
|
|
40160
|
-
response = await
|
|
39955
|
+
response = await fetch6(activeTurnReconciliationEndpoint(config2, turn), {
|
|
40161
39956
|
body: JSON.stringify({ outcome: { kind: "running" } }),
|
|
40162
39957
|
dispatcher: environmentProxyDispatcher,
|
|
40163
39958
|
headers: { ...runtimeAuthorization(config2.relayUrl), "content-type": "application/json" },
|
|
@@ -40469,13 +40264,13 @@ function reportFailure(publisher, command, code, message, attemptId) {
|
|
|
40469
40264
|
);
|
|
40470
40265
|
}
|
|
40471
40266
|
function operationErrorCode(error62) {
|
|
40472
|
-
if (error62 instanceof AcpExecutionError || error62 instanceof LocalAuthorizationError || error62 instanceof LocalAgentCatalogError || error62 instanceof
|
|
40267
|
+
if (error62 instanceof AcpExecutionError || error62 instanceof LocalAuthorizationError || error62 instanceof LocalAgentCatalogError || error62 instanceof PromptArtifactError) {
|
|
40473
40268
|
return error62.code;
|
|
40474
40269
|
}
|
|
40475
40270
|
return "session_operation_failed";
|
|
40476
40271
|
}
|
|
40477
40272
|
function operationErrorMessage(error62) {
|
|
40478
|
-
if (error62 instanceof AcpExecutionError || error62 instanceof LocalAuthorizationError || error62 instanceof LocalAgentCatalogError || error62 instanceof
|
|
40273
|
+
if (error62 instanceof AcpExecutionError || error62 instanceof LocalAuthorizationError || error62 instanceof LocalAgentCatalogError || error62 instanceof PromptArtifactError) {
|
|
40479
40274
|
return error62.message;
|
|
40480
40275
|
}
|
|
40481
40276
|
return "The local agent operation could not be completed";
|
|
@@ -40510,7 +40305,7 @@ async function resolveSessionDirectories(directories, bindingId, directoryId2, a
|
|
|
40510
40305
|
additionalDirectories.push(directory);
|
|
40511
40306
|
additionalDirectoryEntries.push({
|
|
40512
40307
|
directoryId: additionalDirectoryId,
|
|
40513
|
-
name:
|
|
40308
|
+
name: basename7(directory)
|
|
40514
40309
|
});
|
|
40515
40310
|
}
|
|
40516
40311
|
return new ResolvedSessionDirectories(cwd, additionalDirectories, additionalDirectoryEntries);
|
|
@@ -40855,11 +40650,11 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
40855
40650
|
function invalidSessionConfiguration(message) {
|
|
40856
40651
|
return new AcpExecutionError(message, {}, "invalid_session_configuration");
|
|
40857
40652
|
}
|
|
40858
|
-
function validateSessionConfigurationSelection(
|
|
40859
|
-
if (
|
|
40653
|
+
function validateSessionConfigurationSelection(option, selection) {
|
|
40654
|
+
if (option.type !== selection.valueType) {
|
|
40860
40655
|
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} changed type`);
|
|
40861
40656
|
}
|
|
40862
|
-
if (
|
|
40657
|
+
if (option.type === "boolean") {
|
|
40863
40658
|
if (selection.value.length > 0) {
|
|
40864
40659
|
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} has an invalid value`);
|
|
40865
40660
|
}
|
|
@@ -40868,7 +40663,7 @@ function validateSessionConfigurationSelection(option2, selection) {
|
|
|
40868
40663
|
if (selection.booleanValue) {
|
|
40869
40664
|
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} has an invalid value`);
|
|
40870
40665
|
}
|
|
40871
|
-
if (!
|
|
40666
|
+
if (!option.values.some((value) => value.value === selection.value)) {
|
|
40872
40667
|
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} has an unavailable value`);
|
|
40873
40668
|
}
|
|
40874
40669
|
}
|
|
@@ -40880,10 +40675,10 @@ function assertSessionConfigurationSchema(options, selections) {
|
|
|
40880
40675
|
if (selectionsById.size !== selections.length) {
|
|
40881
40676
|
throw invalidSessionConfiguration("The Turn configuration contains duplicate Agent settings");
|
|
40882
40677
|
}
|
|
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 ${
|
|
40678
|
+
for (const option of options) {
|
|
40679
|
+
const selection = selectionsById.get(option.id);
|
|
40680
|
+
if (selection === void 0 || selection.valueType !== option.type || option.type === "boolean" && selection.value.length > 0 || option.type === "select" && selection.booleanValue) {
|
|
40681
|
+
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
|
|
40887
40682
|
}
|
|
40888
40683
|
}
|
|
40889
40684
|
}
|
|
@@ -40892,37 +40687,37 @@ function assertSessionConfigurationCoverage(options, selections) {
|
|
|
40892
40687
|
if (selectionsById.size !== selections.length) {
|
|
40893
40688
|
throw invalidSessionConfiguration("The Turn configuration contains duplicate Agent settings");
|
|
40894
40689
|
}
|
|
40895
|
-
for (const
|
|
40896
|
-
if (!selectionsById.has(
|
|
40897
|
-
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${
|
|
40690
|
+
for (const option of options) {
|
|
40691
|
+
if (!selectionsById.has(option.id)) {
|
|
40692
|
+
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
|
|
40898
40693
|
}
|
|
40899
40694
|
}
|
|
40900
40695
|
}
|
|
40901
|
-
function sessionConfigurationSelectionIsAvailable(
|
|
40902
|
-
if (
|
|
40696
|
+
function sessionConfigurationSelectionIsAvailable(option, selection) {
|
|
40697
|
+
if (option.type !== selection.valueType) {
|
|
40903
40698
|
return false;
|
|
40904
40699
|
}
|
|
40905
|
-
if (
|
|
40700
|
+
if (option.type === "boolean") {
|
|
40906
40701
|
return selection.value.length === 0;
|
|
40907
40702
|
}
|
|
40908
|
-
return !selection.booleanValue &&
|
|
40703
|
+
return !selection.booleanValue && option.values.some((value) => value.value === selection.value);
|
|
40909
40704
|
}
|
|
40910
|
-
function sessionConfigurationMatches(
|
|
40911
|
-
validateSessionConfigurationSelection(
|
|
40912
|
-
return
|
|
40705
|
+
function sessionConfigurationMatches(option, selection) {
|
|
40706
|
+
validateSessionConfigurationSelection(option, selection);
|
|
40707
|
+
return option.type === "boolean" ? option.booleanValue === selection.booleanValue : option.currentValue === selection.value;
|
|
40913
40708
|
}
|
|
40914
40709
|
function sessionConfigurationPriority(selection, options) {
|
|
40915
40710
|
if (selection.configId === "permission_mode") {
|
|
40916
40711
|
return 0;
|
|
40917
40712
|
}
|
|
40918
|
-
const
|
|
40919
|
-
if (selection.configId === "model" ||
|
|
40713
|
+
const option = options.find((candidate) => candidate.id === selection.configId);
|
|
40714
|
+
if (selection.configId === "model" || option?.category === "model") {
|
|
40920
40715
|
return 1;
|
|
40921
40716
|
}
|
|
40922
|
-
if (selection.configId === "reasoning_effort" ||
|
|
40717
|
+
if (selection.configId === "reasoning_effort" || option?.category === "thought_level") {
|
|
40923
40718
|
return 2;
|
|
40924
40719
|
}
|
|
40925
|
-
if (
|
|
40720
|
+
if (option?.category === "model_config") {
|
|
40926
40721
|
return 3;
|
|
40927
40722
|
}
|
|
40928
40723
|
return 4;
|
|
@@ -40930,28 +40725,28 @@ function sessionConfigurationPriority(selection, options) {
|
|
|
40930
40725
|
function assertCompleteSessionConfiguration(options, selections) {
|
|
40931
40726
|
assertSessionConfigurationSchema(options, selections);
|
|
40932
40727
|
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 ${
|
|
40728
|
+
for (const option of options) {
|
|
40729
|
+
const selection = selectionsById.get(option.id);
|
|
40730
|
+
if (selection === void 0 || !sessionConfigurationMatches(option, selection)) {
|
|
40731
|
+
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
|
|
40937
40732
|
}
|
|
40938
40733
|
}
|
|
40939
40734
|
}
|
|
40940
40735
|
function assertAppliedSessionConfiguration(options, selections) {
|
|
40941
40736
|
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 ${
|
|
40737
|
+
for (const option of options) {
|
|
40738
|
+
const selection = selectionsById.get(option.id);
|
|
40739
|
+
if (option.id === AGENT_PERMISSION_MODE_CONFIG_ID) {
|
|
40740
|
+
if (selection === void 0 || !sessionConfigurationMatches(option, selection)) {
|
|
40741
|
+
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
|
|
40947
40742
|
}
|
|
40948
40743
|
continue;
|
|
40949
40744
|
}
|
|
40950
|
-
if (selection === void 0 || !sessionConfigurationSelectionIsAvailable(
|
|
40745
|
+
if (selection === void 0 || !sessionConfigurationSelectionIsAvailable(option, selection)) {
|
|
40951
40746
|
continue;
|
|
40952
40747
|
}
|
|
40953
|
-
if (!sessionConfigurationMatches(
|
|
40954
|
-
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${
|
|
40748
|
+
if (!sessionConfigurationMatches(option, selection)) {
|
|
40749
|
+
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
|
|
40955
40750
|
}
|
|
40956
40751
|
}
|
|
40957
40752
|
}
|
|
@@ -40965,8 +40760,8 @@ function unavailableSessionConfigurationCategory(selection) {
|
|
|
40965
40760
|
return "unknown";
|
|
40966
40761
|
}
|
|
40967
40762
|
async function applySessionConfigurationSelection(sessions, audit, options, selection, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
|
|
40968
|
-
const
|
|
40969
|
-
if (
|
|
40763
|
+
const option = options.find((candidate) => candidate.id === selection.configId);
|
|
40764
|
+
if (option === void 0) {
|
|
40970
40765
|
if (selection.configId !== AGENT_PERMISSION_MODE_CONFIG_ID) {
|
|
40971
40766
|
warnIgnoredSetting(
|
|
40972
40767
|
audit,
|
|
@@ -40983,7 +40778,7 @@ async function applySessionConfigurationSelection(sessions, audit, options, sele
|
|
|
40983
40778
|
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} is unavailable`);
|
|
40984
40779
|
}
|
|
40985
40780
|
if (selection.configId !== AGENT_PERMISSION_MODE_CONFIG_ID) {
|
|
40986
|
-
if (
|
|
40781
|
+
if (option.type !== selection.valueType) {
|
|
40987
40782
|
warnIgnoredSetting(
|
|
40988
40783
|
audit,
|
|
40989
40784
|
"session_configuration_setting_ignored",
|
|
@@ -40991,12 +40786,12 @@ async function applySessionConfigurationSelection(sessions, audit, options, sele
|
|
|
40991
40786
|
sessionId,
|
|
40992
40787
|
agent.id,
|
|
40993
40788
|
selection,
|
|
40994
|
-
|
|
40789
|
+
option.category,
|
|
40995
40790
|
"setting_schema_mismatch"
|
|
40996
40791
|
);
|
|
40997
40792
|
return options;
|
|
40998
40793
|
}
|
|
40999
|
-
if (
|
|
40794
|
+
if (option.type === "boolean" && selection.value.length > 0 || option.type === "select" && selection.booleanValue) {
|
|
41000
40795
|
warnIgnoredSetting(
|
|
41001
40796
|
audit,
|
|
41002
40797
|
"session_configuration_setting_ignored",
|
|
@@ -41004,12 +40799,12 @@ async function applySessionConfigurationSelection(sessions, audit, options, sele
|
|
|
41004
40799
|
sessionId,
|
|
41005
40800
|
agent.id,
|
|
41006
40801
|
selection,
|
|
41007
|
-
|
|
40802
|
+
option.category,
|
|
41008
40803
|
"selection_schema_mismatch"
|
|
41009
40804
|
);
|
|
41010
40805
|
return options;
|
|
41011
40806
|
}
|
|
41012
|
-
if (
|
|
40807
|
+
if (option.type === "select" && !option.values.some((value) => value.value === selection.value)) {
|
|
41013
40808
|
warnIgnoredSetting(
|
|
41014
40809
|
audit,
|
|
41015
40810
|
"session_configuration_setting_ignored",
|
|
@@ -41017,13 +40812,13 @@ async function applySessionConfigurationSelection(sessions, audit, options, sele
|
|
|
41017
40812
|
sessionId,
|
|
41018
40813
|
agent.id,
|
|
41019
40814
|
selection,
|
|
41020
|
-
|
|
40815
|
+
option.category,
|
|
41021
40816
|
"value_unavailable"
|
|
41022
40817
|
);
|
|
41023
40818
|
return options;
|
|
41024
40819
|
}
|
|
41025
40820
|
}
|
|
41026
|
-
if (sessionConfigurationMatches(
|
|
40821
|
+
if (sessionConfigurationMatches(option, selection)) {
|
|
41027
40822
|
return options;
|
|
41028
40823
|
}
|
|
41029
40824
|
return await sessions.configureSession({
|
|
@@ -41032,7 +40827,7 @@ async function applySessionConfigurationSelection(sessions, audit, options, sele
|
|
|
41032
40827
|
booleanValue: selection.booleanValue,
|
|
41033
40828
|
configId: selection.configId,
|
|
41034
40829
|
cwd,
|
|
41035
|
-
requestId: `cfg_${
|
|
40830
|
+
requestId: `cfg_${randomUUID4()}`,
|
|
41036
40831
|
sessionId,
|
|
41037
40832
|
signal,
|
|
41038
40833
|
value: selection.value,
|
|
@@ -41062,37 +40857,6 @@ async function applyCompleteSessionConfiguration(sessions, audit, initialOptions
|
|
|
41062
40857
|
}
|
|
41063
40858
|
assertAppliedSessionConfiguration(options, selections);
|
|
41064
40859
|
}
|
|
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
40860
|
function warnIgnoredSetting(audit, event, commandId, sessionId, agentId, selection, category, reason) {
|
|
41097
40861
|
const details = {
|
|
41098
40862
|
agentId,
|
|
@@ -41105,284 +40869,16 @@ function warnIgnoredSetting(audit, event, commandId, sessionId, agentId, selecti
|
|
|
41105
40869
|
process.stderr.write(`Mobius daemon warning ${JSON.stringify({ commandId, event, sessionId, ...details })}
|
|
41106
40870
|
`);
|
|
41107
40871
|
}
|
|
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
40872
|
function waitForRelayRetry(signal, timer) {
|
|
41377
40873
|
if (signal.aborted) {
|
|
41378
40874
|
return Promise.resolve();
|
|
41379
40875
|
}
|
|
41380
|
-
return new Promise((
|
|
40876
|
+
return new Promise((resolve7) => {
|
|
41381
40877
|
const retry = timer.schedule(finish, RELAY_RECONNECT_DELAY_MILLISECONDS);
|
|
41382
40878
|
function finish() {
|
|
41383
40879
|
retry.cancel();
|
|
41384
40880
|
signal.removeEventListener("abort", finish);
|
|
41385
|
-
|
|
40881
|
+
resolve7();
|
|
41386
40882
|
}
|
|
41387
40883
|
signal.addEventListener("abort", finish, { once: true });
|
|
41388
40884
|
});
|
|
@@ -41419,13 +40915,13 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
|
|
|
41419
40915
|
{
|
|
41420
40916
|
agentId: agent.id,
|
|
41421
40917
|
kind: AGENT_INSTALL_REQUEST_KIND,
|
|
41422
|
-
requestId: `automatic-integration-${
|
|
40918
|
+
requestId: `automatic-integration-${randomUUID4()}`
|
|
41423
40919
|
},
|
|
41424
40920
|
signal
|
|
41425
40921
|
);
|
|
41426
40922
|
}
|
|
41427
40923
|
}
|
|
41428
|
-
async function runRelayConnection(config2, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher,
|
|
40924
|
+
async function runRelayConnection(config2, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher, activeTurns, activeAttemptIds, connectionEpoch, diagnostics, onConnected, signal, timer) {
|
|
41429
40925
|
const relayUrl = new URL(config2.relayUrl);
|
|
41430
40926
|
relayUrl.searchParams.set("deliveryReceipts", "1");
|
|
41431
40927
|
relayUrl.searchParams.set("liveness", "1");
|
|
@@ -41438,7 +40934,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
41438
40934
|
installationObserver.connect(socket);
|
|
41439
40935
|
onConnected();
|
|
41440
40936
|
try {
|
|
41441
|
-
await new Promise((
|
|
40937
|
+
await new Promise((resolve7, reject) => {
|
|
41442
40938
|
let finished = false;
|
|
41443
40939
|
const cleanup = () => {
|
|
41444
40940
|
connectionLiveness.close();
|
|
@@ -41456,7 +40952,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
41456
40952
|
}
|
|
41457
40953
|
finished = true;
|
|
41458
40954
|
cleanup();
|
|
41459
|
-
|
|
40955
|
+
resolve7();
|
|
41460
40956
|
};
|
|
41461
40957
|
const rejectConnection = (failure2) => {
|
|
41462
40958
|
if (finished) {
|
|
@@ -41591,32 +41087,6 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
41591
41087
|
}
|
|
41592
41088
|
return;
|
|
41593
41089
|
}
|
|
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
41090
|
if (kind === SESSION_PROMPT_KIND) {
|
|
41621
41091
|
const command = decodeSessionPromptCommand(delivery.payload);
|
|
41622
41092
|
await processDeliveredPrompt(
|
|
@@ -41674,8 +41144,6 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
41674
41144
|
payloadSessionId = decodeSessionElicitationRespondCommand(delivery.payload).sessionId;
|
|
41675
41145
|
} else if (payloadKind === SESSION_PROMPT_KIND) {
|
|
41676
41146
|
payloadSessionId = decodeSessionPromptCommand(delivery.payload).sessionId;
|
|
41677
|
-
} else if (payloadKind === BOT_SESSION_PROMPT_KIND) {
|
|
41678
|
-
payloadSessionId = decodeBotSessionPromptCommand(delivery.payload).sessionId;
|
|
41679
41147
|
} else {
|
|
41680
41148
|
throw new Error("Runtime delivery contains an unsupported protocol message");
|
|
41681
41149
|
}
|
|
@@ -41931,7 +41399,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
41931
41399
|
try {
|
|
41932
41400
|
operationSignal.throwIfAborted();
|
|
41933
41401
|
if (previous2.length > 0) {
|
|
41934
|
-
await new Promise((
|
|
41402
|
+
await new Promise((resolve8, reject2) => {
|
|
41935
41403
|
const cancel = () => reject2(operationSignal.reason);
|
|
41936
41404
|
operationSignal.addEventListener("abort", cancel, {
|
|
41937
41405
|
once: true
|
|
@@ -41939,7 +41407,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
41939
41407
|
void Promise.all(previous2.map((request) => request.completion)).then(
|
|
41940
41408
|
() => {
|
|
41941
41409
|
operationSignal.removeEventListener("abort", cancel);
|
|
41942
|
-
|
|
41410
|
+
resolve8();
|
|
41943
41411
|
},
|
|
41944
41412
|
(error62) => {
|
|
41945
41413
|
operationSignal.removeEventListener("abort", cancel);
|
|
@@ -42013,13 +41481,13 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
42013
41481
|
try {
|
|
42014
41482
|
operationSignal.throwIfAborted();
|
|
42015
41483
|
if (previous2.length > 0) {
|
|
42016
|
-
await new Promise((
|
|
41484
|
+
await new Promise((resolve8, reject2) => {
|
|
42017
41485
|
const cancel = () => reject2(operationSignal.reason);
|
|
42018
41486
|
operationSignal.addEventListener("abort", cancel, { once: true });
|
|
42019
41487
|
void Promise.all(previous2.map((request) => request.completion)).then(
|
|
42020
41488
|
() => {
|
|
42021
41489
|
operationSignal.removeEventListener("abort", cancel);
|
|
42022
|
-
|
|
41490
|
+
resolve8();
|
|
42023
41491
|
},
|
|
42024
41492
|
(error62) => {
|
|
42025
41493
|
operationSignal.removeEventListener("abort", cancel);
|
|
@@ -42068,6 +41536,29 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
42068
41536
|
connectionLiveness.acknowledge(decodeRuntimeHeartbeatAckEvent(encoded));
|
|
42069
41537
|
return;
|
|
42070
41538
|
}
|
|
41539
|
+
if (kind === FILE_READ_KIND) {
|
|
41540
|
+
const command2 = decodeFileReadCommand(encoded);
|
|
41541
|
+
void streamLocalFile(
|
|
41542
|
+
command2,
|
|
41543
|
+
(message) => send(socket, message),
|
|
41544
|
+
connectionController.signal
|
|
41545
|
+
).catch((error62) => {
|
|
41546
|
+
if (socket.readyState !== WebSocket2.OPEN || connectionController.signal.aborted) {
|
|
41547
|
+
return;
|
|
41548
|
+
}
|
|
41549
|
+
send(
|
|
41550
|
+
socket,
|
|
41551
|
+
encodeFileFailedEvent({
|
|
41552
|
+
code: "file_unavailable",
|
|
41553
|
+
kind: FILE_FAILED_KIND,
|
|
41554
|
+
message: error62 instanceof Error ? error62.message : "The local file is unavailable",
|
|
41555
|
+
requestId: command2.requestId,
|
|
41556
|
+
sessionId: command2.sessionId
|
|
41557
|
+
})
|
|
41558
|
+
);
|
|
41559
|
+
});
|
|
41560
|
+
return;
|
|
41561
|
+
}
|
|
42071
41562
|
if (kind === SESSION_CANCEL_KIND) {
|
|
42072
41563
|
const cancellation = decodeSessionCancelCommand(encoded);
|
|
42073
41564
|
const turn2 = activeTurns.get(cancellation.commandId);
|
|
@@ -42161,48 +41652,6 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
42161
41652
|
});
|
|
42162
41653
|
return;
|
|
42163
41654
|
}
|
|
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
41655
|
if (kind !== SESSION_PROMPT_KIND) {
|
|
42207
41656
|
throw new Error("Unsupported protocol message");
|
|
42208
41657
|
}
|
|
@@ -42293,23 +41742,19 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
42293
41742
|
}
|
|
42294
41743
|
async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
42295
41744
|
const installationAudit = new AuditInstallationEvents(audit);
|
|
42296
|
-
const stateDirectory =
|
|
41745
|
+
const stateDirectory = config2.localContext.stateDirectory;
|
|
42297
41746
|
const specifications = supportedLocalAgentSpecifications();
|
|
42298
41747
|
const installationExecutor = new FixedInstallationExecutor({
|
|
42299
41748
|
defaultWorkspace: config2.defaultWorkspace,
|
|
42300
41749
|
audit: installationAudit,
|
|
42301
41750
|
catalog: config2.catalog,
|
|
42302
|
-
environment:
|
|
41751
|
+
environment: config2.localContext.environment,
|
|
42303
41752
|
publishCatalog: async (installationSignal) => await publishAgentCatalog(config2, installationSignal),
|
|
42304
41753
|
stateDirectory
|
|
42305
41754
|
});
|
|
42306
41755
|
const sessionStore = new SqliteAcpSessionStore(config2.auditDatabasePath);
|
|
42307
41756
|
const outbox = new SessionEventOutbox(config2.auditDatabasePath);
|
|
42308
41757
|
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
41758
|
const activeTurns = /* @__PURE__ */ new Map();
|
|
42314
41759
|
const activeAttemptIds = /* @__PURE__ */ new Map();
|
|
42315
41760
|
const recordSessionEvent = (sessionId, payload) => {
|
|
@@ -42362,10 +41807,10 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
42362
41807
|
return;
|
|
42363
41808
|
}
|
|
42364
41809
|
connectionAnnounced = true;
|
|
42365
|
-
const reconnectCommand = `npx --yes @moxt-ai/mobius start
|
|
41810
|
+
const reconnectCommand = `npx --yes @moxt-ai/mobius start ${config2.reconnectTarget.commandArgument}`;
|
|
42366
41811
|
process.stdout.write("Mobius daemon connected to the relay.\n\n");
|
|
42367
41812
|
process.stdout.write(
|
|
42368
|
-
`${styleText(["bold", "yellow"], `Reconnect this
|
|
41813
|
+
`${styleText(["bold", "yellow"], `Reconnect this local connection later:
|
|
42369
41814
|
${reconnectCommand}`)}
|
|
42370
41815
|
|
|
42371
41816
|
`
|
|
@@ -42383,7 +41828,6 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
42383
41828
|
startAutomaticIntegrationProvisioning();
|
|
42384
41829
|
});
|
|
42385
41830
|
try {
|
|
42386
|
-
await ipc.listen(signal);
|
|
42387
41831
|
while (!signal.aborted) {
|
|
42388
41832
|
connectionEpoch += 1;
|
|
42389
41833
|
try {
|
|
@@ -42397,10 +41841,6 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
42397
41841
|
nativeSessions,
|
|
42398
41842
|
outbox,
|
|
42399
41843
|
publisher,
|
|
42400
|
-
authorizer,
|
|
42401
|
-
contexts,
|
|
42402
|
-
applicator,
|
|
42403
|
-
ipc,
|
|
42404
41844
|
activeTurns,
|
|
42405
41845
|
activeAttemptIds,
|
|
42406
41846
|
connectionEpoch,
|
|
@@ -42433,19 +41873,15 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
42433
41873
|
await installations.close();
|
|
42434
41874
|
} finally {
|
|
42435
41875
|
try {
|
|
42436
|
-
await
|
|
41876
|
+
await sessions.close();
|
|
42437
41877
|
} finally {
|
|
42438
41878
|
try {
|
|
42439
|
-
|
|
41879
|
+
sessionStore.close();
|
|
42440
41880
|
} finally {
|
|
42441
41881
|
try {
|
|
42442
|
-
|
|
41882
|
+
publisher.close();
|
|
42443
41883
|
} finally {
|
|
42444
|
-
|
|
42445
|
-
publisher.close();
|
|
42446
|
-
} finally {
|
|
42447
|
-
outbox.close();
|
|
42448
|
-
}
|
|
41884
|
+
outbox.close();
|
|
42449
41885
|
}
|
|
42450
41886
|
}
|
|
42451
41887
|
}
|
|
@@ -42456,7 +41892,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
42456
41892
|
}
|
|
42457
41893
|
|
|
42458
41894
|
// src/runtime.ts
|
|
42459
|
-
var
|
|
41895
|
+
var RUNTIME_CREDENTIAL_PATTERN2 = /^[a-zA-Z0-9_-]{32,256}$/;
|
|
42460
41896
|
var MobiusRuntimeConfigurationError = class extends Error {
|
|
42461
41897
|
code = "runtime_configuration_invalid";
|
|
42462
41898
|
constructor(message, options = {}) {
|
|
@@ -42480,7 +41916,7 @@ function validateRuntimeRelay(relayUrl) {
|
|
|
42480
41916
|
if (credential.length === 0) {
|
|
42481
41917
|
throw new MobiusRuntimeConfigurationError("The Runtime relay credential is required");
|
|
42482
41918
|
}
|
|
42483
|
-
if (!
|
|
41919
|
+
if (!RUNTIME_CREDENTIAL_PATTERN2.test(credential)) {
|
|
42484
41920
|
throw new MobiusRuntimeConfigurationError("The Runtime relay credential is invalid");
|
|
42485
41921
|
}
|
|
42486
41922
|
}
|
|
@@ -42519,19 +41955,18 @@ var USAGE = `Mobius CLI
|
|
|
42519
41955
|
Usage:
|
|
42520
41956
|
mobius --version
|
|
42521
41957
|
mobius pair --url <relay-url> --pairing <runtime-pairing-id> --code <pairing-code> [--workspace <directory>]
|
|
42522
|
-
mobius start --
|
|
41958
|
+
mobius start --connection <connection-id>
|
|
41959
|
+
mobius start --channel <legacy-channel-id>
|
|
42523
41960
|
mobius agents [--json]
|
|
42524
|
-
mobius bot message send --target <current|alias> --text <message>
|
|
42525
41961
|
|
|
42526
41962
|
Commands:
|
|
42527
41963
|
--version Print the installed Mobius CLI version
|
|
42528
41964
|
pair Pair this machine and start its local daemon
|
|
42529
|
-
start Start the local daemon for a saved
|
|
41965
|
+
start Start the local daemon for a saved connection
|
|
42530
41966
|
agents Show detected, missing, and integration-ready Agents
|
|
42531
|
-
bot Send a message from an active execution
|
|
42532
41967
|
|
|
42533
41968
|
Pairing grants this browser access to the machine with your user account's permissions.
|
|
42534
|
-
New conversations default to
|
|
41969
|
+
New conversations default to this Mobius installation's private workspace; choose other directories in the browser.
|
|
42535
41970
|
`;
|
|
42536
41971
|
async function main() {
|
|
42537
41972
|
const command = process.argv[2];
|
|
@@ -42549,27 +41984,18 @@ async function main() {
|
|
|
42549
41984
|
if (arguments_.length > 1 || arguments_.length === 1 && arguments_[0] !== "--json") {
|
|
42550
41985
|
throw new Error("Usage: mobius agents [--json]");
|
|
42551
41986
|
}
|
|
42552
|
-
|
|
41987
|
+
const installation = await openMobiusCliInstallation(shutdown.signal, process.env);
|
|
41988
|
+
const localContext = new DaemonLocalContext(installation.stateDirectory, process.env);
|
|
41989
|
+
const defaultWorkspace = loadDefaultWorkspace(localContext.environment);
|
|
41990
|
+
await mkdir5(defaultWorkspace, { recursive: true, mode: 448 });
|
|
42553
41991
|
const inventory = await discoverLocalAgentInventory({
|
|
42554
|
-
defaultWorkspace
|
|
42555
|
-
environment:
|
|
41992
|
+
defaultWorkspace,
|
|
41993
|
+
environment: localContext.environment,
|
|
42556
41994
|
signal: shutdown.signal
|
|
42557
41995
|
});
|
|
42558
41996
|
process.stdout.write(formatAgentDiagnostics(inventory, arguments_[0] === "--json"));
|
|
42559
41997
|
return;
|
|
42560
41998
|
}
|
|
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
41999
|
let config2;
|
|
42574
42000
|
if (command === "pair") {
|
|
42575
42001
|
process.stdout.write(`mobius version: ${package_default.version}
|
|
@@ -42578,6 +42004,10 @@ async function main() {
|
|
|
42578
42004
|
config2 = paired.config;
|
|
42579
42005
|
process.stdout.write("\nLocal machine paired.\n");
|
|
42580
42006
|
process.stdout.write(`Channel: ${paired.channelUrl}
|
|
42007
|
+
`);
|
|
42008
|
+
process.stdout.write(`Connection ID: ${paired.connectionId}
|
|
42009
|
+
`);
|
|
42010
|
+
process.stdout.write(`Restart: mobius start --connection ${paired.connectionId}
|
|
42581
42011
|
`);
|
|
42582
42012
|
process.stdout.write("Open this channel in any browser while the daemon is running.\n");
|
|
42583
42013
|
process.stdout.write(`Connection saved to ${paired.connectionPath}
|
|
@@ -42585,7 +42015,7 @@ async function main() {
|
|
|
42585
42015
|
} else if (command === "start") {
|
|
42586
42016
|
const paired = await resumeLocalMachine(process.argv.slice(3), shutdown.signal);
|
|
42587
42017
|
config2 = paired.config;
|
|
42588
|
-
process.stdout.write("\nSaved local
|
|
42018
|
+
process.stdout.write("\nSaved local Runtime connection loaded.\n");
|
|
42589
42019
|
process.stdout.write(`Channel: ${paired.channelUrl}
|
|
42590
42020
|
`);
|
|
42591
42021
|
process.stdout.write("Open this channel in any browser while the daemon is running.\n");
|
|
@@ -42604,8 +42034,7 @@ try {
|
|
|
42604
42034
|
} catch (error62) {
|
|
42605
42035
|
if (!shutdown.signal.aborted) {
|
|
42606
42036
|
const message = error62 instanceof Error ? error62.message : "Unknown failure";
|
|
42607
|
-
|
|
42608
|
-
process.stderr.write(`Mobius daemon failed: ${code}${message}
|
|
42037
|
+
process.stderr.write(`Mobius daemon failed: ${message}
|
|
42609
42038
|
`);
|
|
42610
42039
|
process.exitCode = 1;
|
|
42611
42040
|
}
|