@moxt-ai/mobius 0.0.47 → 0.0.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/acp/session-manager.d.ts +2 -1
- package/dist/acp/session-manager.d.ts.map +1 -1
- package/dist/acp/session-manager.js +38 -23
- package/dist/acp/session-manager.js.map +1 -1
- package/dist/agent-catalog/agent-specification.d.ts +0 -1
- package/dist/agent-catalog/agent-specification.d.ts.map +1 -1
- package/dist/agent-catalog/agent-specification.js +0 -2
- package/dist/agent-catalog/agent-specification.js.map +1 -1
- package/dist/agent-catalog/agents/pi-agent.d.ts +0 -1
- package/dist/agent-catalog/agents/pi-agent.d.ts.map +1 -1
- package/dist/agent-catalog/agents/pi-agent.js +0 -2
- package/dist/agent-catalog/agents/pi-agent.js.map +1 -1
- package/dist/agent-catalog/discover-agent.d.ts.map +1 -1
- package/dist/agent-catalog/discover-agent.js +2 -2
- package/dist/agent-catalog/discover-agent.js.map +1 -1
- package/dist/agent-catalog/local-agent.d.ts +1 -2
- package/dist/agent-catalog/local-agent.d.ts.map +1 -1
- package/dist/agent-catalog/local-agent.js +2 -7
- package/dist/agent-catalog/local-agent.js.map +1 -1
- package/dist/agent-catalog/publish-agent-catalog.d.ts.map +1 -1
- package/dist/agent-catalog/publish-agent-catalog.js +0 -1
- package/dist/agent-catalog/publish-agent-catalog.js.map +1 -1
- package/dist/artifacts/local-file-streamer.d.ts +3 -0
- package/dist/artifacts/local-file-streamer.d.ts.map +1 -0
- package/dist/artifacts/local-file-streamer.js +82 -0
- package/dist/artifacts/local-file-streamer.js.map +1 -0
- package/dist/authorization/local-raster.d.ts +4 -3
- package/dist/authorization/local-raster.d.ts.map +1 -1
- package/dist/authorization/local-raster.js +22 -12
- package/dist/authorization/local-raster.js.map +1 -1
- package/dist/cli.js +624 -1673
- package/dist/cli.js.map +4 -4
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +664 -1704
- package/dist/index.js.map +4 -4
- package/dist/native-sessions/history-images.js +1 -1
- package/dist/native-sessions/history-images.js.map +1 -1
- package/dist/pairing/pair-local-machine.d.ts.map +1 -1
- package/dist/pairing/pair-local-machine.js +0 -1
- package/dist/pairing/pair-local-machine.js.map +1 -1
- package/dist/run-daemon.d.ts.map +1 -1
- package/dist/run-daemon.js +99 -285
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.js +512 -1388
- package/dist/runtime.js.map +4 -4
- package/package.json +1 -1
- package/dist/bots/bot-context-applicator.d.ts +0 -14
- package/dist/bots/bot-context-applicator.d.ts.map +0 -1
- package/dist/bots/bot-context-applicator.js +0 -32
- package/dist/bots/bot-context-applicator.js.map +0 -1
- package/dist/bots/bot-execution-context.d.ts +0 -20
- package/dist/bots/bot-execution-context.d.ts.map +0 -1
- package/dist/bots/bot-execution-context.js +0 -82
- package/dist/bots/bot-execution-context.js.map +0 -1
- package/dist/bots/bot-message-command.d.ts +0 -6
- package/dist/bots/bot-message-command.d.ts.map +0 -1
- package/dist/bots/bot-message-command.js +0 -140
- package/dist/bots/bot-message-command.js.map +0 -1
- package/dist/bots/bot-outbound-ipc.d.ts +0 -12
- package/dist/bots/bot-outbound-ipc.d.ts.map +0 -1
- package/dist/bots/bot-outbound-ipc.js +0 -245
- package/dist/bots/bot-outbound-ipc.js.map +0 -1
- package/dist/bots/local-bot-execution-authorizer.d.ts +0 -23
- package/dist/bots/local-bot-execution-authorizer.d.ts.map +0 -1
- package/dist/bots/local-bot-execution-authorizer.js +0 -62
- package/dist/bots/local-bot-execution-authorizer.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -3710,7 +3710,7 @@ var $ZodUnion = /* @__PURE__ */ $constructor("$ZodUnion", (inst, def) => {
|
|
|
3710
3710
|
defineLazyInternal(inst, "optout", (zod) => zod.def.options.some((o) => o._zod.optout === "optional") ? "optional" : void 0);
|
|
3711
3711
|
defineLazyInternal(inst, "values", (zod) => {
|
|
3712
3712
|
if (zod.def.options.every((o) => o._zod.values)) {
|
|
3713
|
-
return new Set(zod.def.options.flatMap((
|
|
3713
|
+
return new Set(zod.def.options.flatMap((option) => Array.from(option._zod.values)));
|
|
3714
3714
|
}
|
|
3715
3715
|
return void 0;
|
|
3716
3716
|
});
|
|
@@ -3728,8 +3728,8 @@ var $ZodUnion = /* @__PURE__ */ $constructor("$ZodUnion", (inst, def) => {
|
|
|
3728
3728
|
}
|
|
3729
3729
|
let async = false;
|
|
3730
3730
|
const results = [];
|
|
3731
|
-
for (const
|
|
3732
|
-
const result =
|
|
3731
|
+
for (const option of def.options) {
|
|
3732
|
+
const result = option._zod.run({
|
|
3733
3733
|
value: payload.value,
|
|
3734
3734
|
issues: []
|
|
3735
3735
|
}, ctx);
|
|
@@ -3788,8 +3788,8 @@ var $ZodXor = /* @__PURE__ */ $constructor("$ZodXor", (inst, def) => {
|
|
|
3788
3788
|
}
|
|
3789
3789
|
let async = false;
|
|
3790
3790
|
const results = [];
|
|
3791
|
-
for (const
|
|
3792
|
-
const result =
|
|
3791
|
+
for (const option of def.options) {
|
|
3792
|
+
const result = option._zod.run({
|
|
3793
3793
|
value: payload.value,
|
|
3794
3794
|
issues: []
|
|
3795
3795
|
}, ctx);
|
|
@@ -3814,24 +3814,24 @@ function getDiscriminatedOption(union2, value) {
|
|
|
3814
3814
|
map2 = discriminatorMap(internals.def);
|
|
3815
3815
|
internals.bag.optionsMap = map2;
|
|
3816
3816
|
}
|
|
3817
|
-
const
|
|
3818
|
-
if (
|
|
3817
|
+
const option = map2.get(value);
|
|
3818
|
+
if (option === null)
|
|
3819
3819
|
throw new Error(`Ambiguous discriminator value "${String(value)}"`);
|
|
3820
|
-
return
|
|
3820
|
+
return option;
|
|
3821
3821
|
}
|
|
3822
3822
|
function discriminatorMap(def) {
|
|
3823
3823
|
const map2 = /* @__PURE__ */ new Map();
|
|
3824
|
-
for (const
|
|
3825
|
-
const values =
|
|
3824
|
+
for (const option of def.options) {
|
|
3825
|
+
const values = option._zod.propValues?.[def.discriminator];
|
|
3826
3826
|
if (!values || values.size === 0)
|
|
3827
|
-
throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(
|
|
3827
|
+
throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
|
|
3828
3828
|
for (const value of values) {
|
|
3829
3829
|
if (map2.has(value)) {
|
|
3830
3830
|
if (value !== void 0)
|
|
3831
3831
|
throw new Error(`Duplicate discriminator value "${String(value)}"`);
|
|
3832
3832
|
map2.set(value, null);
|
|
3833
3833
|
} else {
|
|
3834
|
-
map2.set(value,
|
|
3834
|
+
map2.set(value, option);
|
|
3835
3835
|
}
|
|
3836
3836
|
}
|
|
3837
3837
|
}
|
|
@@ -3844,10 +3844,10 @@ var $ZodDiscriminatedUnion = /* @__PURE__ */ $constructor("$ZodDiscriminatedUnio
|
|
|
3844
3844
|
defineLazyInternal(inst, "propValues", (zod) => {
|
|
3845
3845
|
const propValues = {};
|
|
3846
3846
|
let undefinedCount = 0;
|
|
3847
|
-
for (const
|
|
3848
|
-
const pv =
|
|
3847
|
+
for (const option of zod.def.options) {
|
|
3848
|
+
const pv = option._zod.propValues;
|
|
3849
3849
|
if (!pv || Object.keys(pv).length === 0)
|
|
3850
|
-
throw new Error(`Invalid discriminated union option at index "${zod.def.options.indexOf(
|
|
3850
|
+
throw new Error(`Invalid discriminated union option at index "${zod.def.options.indexOf(option)}"`);
|
|
3851
3851
|
if (pv[zod.def.discriminator]?.has(void 0))
|
|
3852
3852
|
undefinedCount++;
|
|
3853
3853
|
for (const [k, v] of Object.entries(pv)) {
|
|
@@ -3863,8 +3863,8 @@ var $ZodDiscriminatedUnion = /* @__PURE__ */ $constructor("$ZodDiscriminatedUnio
|
|
|
3863
3863
|
propValues[zod.def.discriminator]?.delete(void 0);
|
|
3864
3864
|
return propValues;
|
|
3865
3865
|
});
|
|
3866
|
-
def.options.forEach((
|
|
3867
|
-
const propShape = rawShape(
|
|
3866
|
+
def.options.forEach((option, i) => {
|
|
3867
|
+
const propShape = rawShape(option._zod.def);
|
|
3868
3868
|
if (propShape && !Object.prototype.hasOwnProperty.call(propShape, def.discriminator)) {
|
|
3869
3869
|
throw new Error(`Invalid discriminated union option at index "${i}"`);
|
|
3870
3870
|
}
|
|
@@ -14164,8 +14164,8 @@ function generateDiscriminatedUnionCheck(doc, ctx, def, accessor) {
|
|
|
14164
14164
|
doc.write(`let ${outputVar};`);
|
|
14165
14165
|
let firstBranch = true;
|
|
14166
14166
|
const claimed = /* @__PURE__ */ new Set();
|
|
14167
|
-
for (const
|
|
14168
|
-
const values =
|
|
14167
|
+
for (const option of def.options) {
|
|
14168
|
+
const values = option._zod.propValues?.[def.discriminator];
|
|
14169
14169
|
if (!values || values.size === 0) {
|
|
14170
14170
|
throw new ZodCompileUnsupportedError("discriminated union option without static discriminator values");
|
|
14171
14171
|
}
|
|
@@ -14179,7 +14179,7 @@ function generateDiscriminatedUnionCheck(doc, ctx, def, accessor) {
|
|
|
14179
14179
|
const prefix = firstBranch ? "if" : "else if";
|
|
14180
14180
|
doc.write(`${prefix} (${conditions.join(" || ")}) {`);
|
|
14181
14181
|
doc.indented((d) => {
|
|
14182
|
-
const branchOutput = generateCheck(d, ctx,
|
|
14182
|
+
const branchOutput = generateCheck(d, ctx, option, accessor);
|
|
14183
14183
|
d.write(`${outputVar} = ${branchOutput};`);
|
|
14184
14184
|
});
|
|
14185
14185
|
doc.write(`}`);
|
|
@@ -15761,14 +15761,14 @@ function compactTypeUnion(schema) {
|
|
|
15761
15761
|
if (!Array.isArray(options) || options.length === 0 || schema.type !== void 0)
|
|
15762
15762
|
return;
|
|
15763
15763
|
const types = [];
|
|
15764
|
-
for (const
|
|
15765
|
-
if (!
|
|
15764
|
+
for (const option of options) {
|
|
15765
|
+
if (!option || typeof option !== "object")
|
|
15766
15766
|
return;
|
|
15767
|
-
compactTypeUnion(
|
|
15768
|
-
const keys = Object.keys(
|
|
15767
|
+
compactTypeUnion(option);
|
|
15768
|
+
const keys = Object.keys(option);
|
|
15769
15769
|
if (keys.length !== 1 || keys[0] !== "type")
|
|
15770
15770
|
return;
|
|
15771
|
-
const type =
|
|
15771
|
+
const type = option.type;
|
|
15772
15772
|
for (const member of Array.isArray(type) ? type : [type]) {
|
|
15773
15773
|
if (typeof member !== "string")
|
|
15774
15774
|
return;
|
|
@@ -16058,8 +16058,8 @@ function isTransforming(_schema, _ctx) {
|
|
|
16058
16058
|
return false;
|
|
16059
16059
|
}
|
|
16060
16060
|
if (def.type === "union") {
|
|
16061
|
-
for (const
|
|
16062
|
-
if (isTransforming(
|
|
16061
|
+
for (const option of def.options) {
|
|
16062
|
+
if (isTransforming(option, ctx))
|
|
16063
16063
|
return true;
|
|
16064
16064
|
}
|
|
16065
16065
|
return false;
|
|
@@ -19807,6 +19807,11 @@ var AGENT_INSTALL_CANCELLED_KIND = "agent.integration.install.cancelled";
|
|
|
19807
19807
|
var AGENT_SETTINGS_DISCOVER_KIND = "agent.settings.discover";
|
|
19808
19808
|
var AGENT_SETTINGS_DISCOVERED_KIND = "agent.settings.discovered";
|
|
19809
19809
|
var AGENT_SETTINGS_DISCOVERY_FAILED_KIND = "agent.settings.discovery.failed";
|
|
19810
|
+
var FILE_READ_KIND = "file.read";
|
|
19811
|
+
var FILE_BEGIN_KIND = "file.begin";
|
|
19812
|
+
var FILE_CHUNK_KIND = "file.chunk";
|
|
19813
|
+
var FILE_END_KIND = "file.end";
|
|
19814
|
+
var FILE_FAILED_KIND = "file.failed";
|
|
19810
19815
|
var IDENTIFIER_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
19811
19816
|
var DIRECTORY_IDENTIFIER_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/;
|
|
19812
19817
|
var IDENTIFIER = external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN);
|
|
@@ -19817,6 +19822,41 @@ var workspaceEntrySchema = external_exports.strictObject({
|
|
|
19817
19822
|
directoryId: DIRECTORY_IDENTIFIER,
|
|
19818
19823
|
name: external_exports.string().min(1).max(255)
|
|
19819
19824
|
}).readonly();
|
|
19825
|
+
var fileReadCommandSchema = external_exports.strictObject({
|
|
19826
|
+
kind: external_exports.literal(FILE_READ_KIND),
|
|
19827
|
+
maxBytes: external_exports.number().int().positive().max(128 * 1024 * 1024),
|
|
19828
|
+
requestId: IDENTIFIER,
|
|
19829
|
+
sessionId: IDENTIFIER,
|
|
19830
|
+
path: external_exports.string().min(1).max(4096)
|
|
19831
|
+
}).readonly();
|
|
19832
|
+
var fileBeginEventSchema = external_exports.strictObject({
|
|
19833
|
+
byteLength: external_exports.number().int().positive().max(128 * 1024 * 1024),
|
|
19834
|
+
kind: external_exports.literal(FILE_BEGIN_KIND),
|
|
19835
|
+
mediaType: external_exports.string().min(1).max(255),
|
|
19836
|
+
modifiedAt: external_exports.iso.datetime({ offset: true }),
|
|
19837
|
+
name: external_exports.string().min(1).max(500),
|
|
19838
|
+
requestId: IDENTIFIER,
|
|
19839
|
+
sessionId: IDENTIFIER
|
|
19840
|
+
}).readonly();
|
|
19841
|
+
var fileChunkEventSchema = external_exports.strictObject({
|
|
19842
|
+
data: external_exports.string().min(1).max(4e5),
|
|
19843
|
+
kind: external_exports.literal(FILE_CHUNK_KIND),
|
|
19844
|
+
requestId: IDENTIFIER,
|
|
19845
|
+
sequence: external_exports.number().int().nonnegative().max(1024),
|
|
19846
|
+
sessionId: IDENTIFIER
|
|
19847
|
+
}).readonly();
|
|
19848
|
+
var fileEndEventSchema = external_exports.strictObject({
|
|
19849
|
+
kind: external_exports.literal(FILE_END_KIND),
|
|
19850
|
+
requestId: IDENTIFIER,
|
|
19851
|
+
sessionId: IDENTIFIER
|
|
19852
|
+
}).readonly();
|
|
19853
|
+
var fileFailedEventSchema = external_exports.strictObject({
|
|
19854
|
+
code: IDENTIFIER,
|
|
19855
|
+
kind: external_exports.literal(FILE_FAILED_KIND),
|
|
19856
|
+
message: external_exports.string().min(1).max(500),
|
|
19857
|
+
requestId: IDENTIFIER,
|
|
19858
|
+
sessionId: IDENTIFIER
|
|
19859
|
+
}).readonly();
|
|
19820
19860
|
var configValueSchema = external_exports.strictObject({
|
|
19821
19861
|
description: SHORT_TEXT,
|
|
19822
19862
|
groupId: external_exports.string().max(128),
|
|
@@ -20033,7 +20073,7 @@ var sessionPrepareCommandSchema = external_exports.strictObject({
|
|
|
20033
20073
|
kind: external_exports.literal(SESSION_PREPARE_KIND),
|
|
20034
20074
|
requestId: IDENTIFIER,
|
|
20035
20075
|
sessionState: external_exports.literal("provisioned").optional(),
|
|
20036
|
-
/**
|
|
20076
|
+
/** Marks an inspection-only Session preparation. */
|
|
20037
20077
|
transient: external_exports.boolean().optional()
|
|
20038
20078
|
}).superRefine((command, context) => {
|
|
20039
20079
|
if (command.transient === true && command.sessionState === "provisioned") {
|
|
@@ -20254,11 +20294,15 @@ var decodeRecordedAgentContentValue = (value) => decodeValue(value, recordedDisp
|
|
|
20254
20294
|
var decodePromptImagesValue = (value) => decodeValue(value, external_exports.array(promptImageSchema).max(8).readonly());
|
|
20255
20295
|
var decodePromptResourcesValue = (value) => decodeValue(value, external_exports.array(promptResourceSchema).max(16).readonly());
|
|
20256
20296
|
var decodeSessionConfigurationSelections = (value) => decodeValue(value, sessionConfigurationSelectionsSchema);
|
|
20257
|
-
var decodeAgentExecutionConfiguration = (value) => decodeValue(value, agentExecutionConfigurationSchema);
|
|
20258
20297
|
var encode3 = (message, schema) => JSON.stringify(decodeValue(message, schema));
|
|
20259
20298
|
var decodeAgentSettingsDiscoverCommand = (encoded) => decode3(encoded, agentSettingsDiscoverCommandSchema);
|
|
20260
20299
|
var encodeAgentSettingsDiscoveredEvent = (message) => encode3(message, agentSettingsDiscoveredEventSchema);
|
|
20261
20300
|
var encodeAgentSettingsDiscoveryFailedEvent = (message) => encode3(message, agentSettingsDiscoveryFailedEventSchema);
|
|
20301
|
+
var decodeFileReadCommand = (encoded) => decode3(encoded, fileReadCommandSchema);
|
|
20302
|
+
var encodeFileBeginEvent = (message) => encode3(message, fileBeginEventSchema);
|
|
20303
|
+
var encodeFileChunkEvent = (message) => encode3(message, fileChunkEventSchema);
|
|
20304
|
+
var encodeFileEndEvent = (message) => encode3(message, fileEndEventSchema);
|
|
20305
|
+
var encodeFileFailedEvent = (message) => encode3(message, fileFailedEventSchema);
|
|
20262
20306
|
var decodeWorkspaceListCommand = (encoded) => decode3(encoded, workspaceListCommandSchema);
|
|
20263
20307
|
var encodeWorkspaceEntriesEvent = (message) => encode3(message, workspaceEntriesEventSchema);
|
|
20264
20308
|
var decodeSessionPrepareCommand = (encoded) => decode3(encoded, sessionPrepareCommandSchema);
|
|
@@ -20738,325 +20782,6 @@ function encodeSessionFailedEvent(message) {
|
|
|
20738
20782
|
return JSON.stringify(decodeSessionFailedEvent(JSON.stringify(message)));
|
|
20739
20783
|
}
|
|
20740
20784
|
|
|
20741
|
-
// ../protocol/src/bot.ts
|
|
20742
|
-
var BOT_SESSION_PROMPT_KIND = "bot.session.prompt";
|
|
20743
|
-
var IDENTIFIER_PATTERN3 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
20744
|
-
var DIRECTORY_IDENTIFIER_PATTERN3 = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/;
|
|
20745
|
-
var TOKEN_PATTERN = /^[a-zA-Z0-9_-]{32,256}$/;
|
|
20746
|
-
var SHA256_PATTERN = /^[a-f0-9]{64}$/;
|
|
20747
|
-
var MAX_INSTRUCTIONS_LENGTH = 1e5;
|
|
20748
|
-
var BotDeliveryTargetReference = class {
|
|
20749
|
-
alias;
|
|
20750
|
-
deliveryTargetId;
|
|
20751
|
-
constructor(alias, deliveryTargetId) {
|
|
20752
|
-
this.alias = alias;
|
|
20753
|
-
this.deliveryTargetId = deliveryTargetId;
|
|
20754
|
-
}
|
|
20755
|
-
};
|
|
20756
|
-
var BotReplyRoute = class {
|
|
20757
|
-
};
|
|
20758
|
-
var OwnerBotReplyRoute = class extends BotReplyRoute {
|
|
20759
|
-
kind = "owner";
|
|
20760
|
-
};
|
|
20761
|
-
var BotConnectionReplyRoute = class extends BotReplyRoute {
|
|
20762
|
-
connectionId;
|
|
20763
|
-
deliveryTargetId;
|
|
20764
|
-
kind = "connection";
|
|
20765
|
-
constructor(connectionId, deliveryTargetId) {
|
|
20766
|
-
super();
|
|
20767
|
-
this.connectionId = connectionId;
|
|
20768
|
-
this.deliveryTargetId = deliveryTargetId;
|
|
20769
|
-
}
|
|
20770
|
-
};
|
|
20771
|
-
var BotSessionPromptCommand = class {
|
|
20772
|
-
additionalDirectoryIds;
|
|
20773
|
-
agentId;
|
|
20774
|
-
allowedDeliveryTargets;
|
|
20775
|
-
behaviorDigest;
|
|
20776
|
-
behaviorInstructions;
|
|
20777
|
-
behaviorRevisionId;
|
|
20778
|
-
bindingId;
|
|
20779
|
-
bindingRevision;
|
|
20780
|
-
botId;
|
|
20781
|
-
commandId;
|
|
20782
|
-
conversationId;
|
|
20783
|
-
directoryId;
|
|
20784
|
-
disposition;
|
|
20785
|
-
executionCapabilityId;
|
|
20786
|
-
executionCapabilitySecret;
|
|
20787
|
-
executionDeadlineAt;
|
|
20788
|
-
executionId;
|
|
20789
|
-
executionConfiguration;
|
|
20790
|
-
images;
|
|
20791
|
-
kind = BOT_SESSION_PROMPT_KIND;
|
|
20792
|
-
prompt;
|
|
20793
|
-
replyRoute;
|
|
20794
|
-
resources;
|
|
20795
|
-
sessionConfigurations;
|
|
20796
|
-
sessionId;
|
|
20797
|
-
targetCommandId;
|
|
20798
|
-
turnId;
|
|
20799
|
-
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 = "") {
|
|
20800
|
-
this.sessionId = sessionId;
|
|
20801
|
-
this.commandId = commandId;
|
|
20802
|
-
this.agentId = agentId;
|
|
20803
|
-
this.bindingId = bindingId;
|
|
20804
|
-
this.directoryId = directoryId2;
|
|
20805
|
-
this.disposition = disposition;
|
|
20806
|
-
this.additionalDirectoryIds = Object.freeze([...additionalDirectoryIds]);
|
|
20807
|
-
this.images = Object.freeze([...images]);
|
|
20808
|
-
this.resources = Object.freeze([...resources]);
|
|
20809
|
-
this.prompt = prompt;
|
|
20810
|
-
this.executionId = executionId;
|
|
20811
|
-
this.executionCapabilityId = executionCapabilityId;
|
|
20812
|
-
this.executionCapabilitySecret = executionCapabilitySecret;
|
|
20813
|
-
this.executionDeadlineAt = executionDeadlineAt;
|
|
20814
|
-
this.botId = botId;
|
|
20815
|
-
this.conversationId = conversationId;
|
|
20816
|
-
this.turnId = turnId;
|
|
20817
|
-
this.behaviorRevisionId = behaviorRevisionId;
|
|
20818
|
-
this.bindingRevision = bindingRevision;
|
|
20819
|
-
this.behaviorInstructions = behaviorInstructions;
|
|
20820
|
-
this.behaviorDigest = behaviorDigest;
|
|
20821
|
-
this.allowedDeliveryTargets = Object.freeze(
|
|
20822
|
-
allowedDeliveryTargets.map(
|
|
20823
|
-
(target) => new BotDeliveryTargetReference(target.alias, target.deliveryTargetId)
|
|
20824
|
-
)
|
|
20825
|
-
);
|
|
20826
|
-
this.replyRoute = replyRoute;
|
|
20827
|
-
this.executionConfiguration = decodeAgentExecutionConfiguration(executionConfiguration);
|
|
20828
|
-
this.sessionConfigurations = Object.freeze([...sessionConfigurations]);
|
|
20829
|
-
this.targetCommandId = targetCommandId;
|
|
20830
|
-
}
|
|
20831
|
-
toJSON() {
|
|
20832
|
-
const { disposition, sessionConfigurations, targetCommandId, ...command } = this;
|
|
20833
|
-
return {
|
|
20834
|
-
...command,
|
|
20835
|
-
...sessionConfigurations.length === 0 ? {} : { sessionConfigurations },
|
|
20836
|
-
...disposition === SessionPromptDisposition.Reject ? {} : { disposition, targetCommandId }
|
|
20837
|
-
};
|
|
20838
|
-
}
|
|
20839
|
-
};
|
|
20840
|
-
function isRecord2(value) {
|
|
20841
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20842
|
-
}
|
|
20843
|
-
function parseJson3(encoded) {
|
|
20844
|
-
let value;
|
|
20845
|
-
try {
|
|
20846
|
-
value = JSON.parse(encoded);
|
|
20847
|
-
} catch (cause) {
|
|
20848
|
-
throw new ProtocolMessageError("Message is not valid JSON", { cause });
|
|
20849
|
-
}
|
|
20850
|
-
if (!isRecord2(value)) {
|
|
20851
|
-
throw new ProtocolMessageError("Message must be a JSON object");
|
|
20852
|
-
}
|
|
20853
|
-
return value;
|
|
20854
|
-
}
|
|
20855
|
-
function assertExactKeys2(value, expected) {
|
|
20856
|
-
const keys = Object.keys(value);
|
|
20857
|
-
if (keys.length !== expected.length || keys.some((key) => !expected.includes(key))) {
|
|
20858
|
-
throw new ProtocolMessageError("Message fields do not match the Bot protocol");
|
|
20859
|
-
}
|
|
20860
|
-
}
|
|
20861
|
-
function assertKeysWithOptional(value, expected, optional2) {
|
|
20862
|
-
const keys = Object.keys(value);
|
|
20863
|
-
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))) {
|
|
20864
|
-
throw new ProtocolMessageError("Message fields do not match the Bot protocol");
|
|
20865
|
-
}
|
|
20866
|
-
}
|
|
20867
|
-
function readText2(value, key, maximumLength, allowEmpty) {
|
|
20868
|
-
const field = value[key];
|
|
20869
|
-
if (typeof field !== "string" || field.length > maximumLength || !allowEmpty && field.length === 0) {
|
|
20870
|
-
throw new ProtocolMessageError(`Invalid Bot protocol field: ${key}`);
|
|
20871
|
-
}
|
|
20872
|
-
return field;
|
|
20873
|
-
}
|
|
20874
|
-
function readIdentifier2(value, key) {
|
|
20875
|
-
const field = readText2(value, key, 128, false);
|
|
20876
|
-
if (!IDENTIFIER_PATTERN3.test(field)) {
|
|
20877
|
-
throw new ProtocolMessageError(`Invalid Bot identifier field: ${key}`);
|
|
20878
|
-
}
|
|
20879
|
-
return field;
|
|
20880
|
-
}
|
|
20881
|
-
function readDirectoryIdentifier2(value, key) {
|
|
20882
|
-
const field = readText2(value, key, 2048, false);
|
|
20883
|
-
if (!DIRECTORY_IDENTIFIER_PATTERN3.test(field)) {
|
|
20884
|
-
throw new ProtocolMessageError(`Invalid Bot directory field: ${key}`);
|
|
20885
|
-
}
|
|
20886
|
-
return field;
|
|
20887
|
-
}
|
|
20888
|
-
function readInteger(value, key) {
|
|
20889
|
-
const field = value[key];
|
|
20890
|
-
if (typeof field !== "number" || !Number.isSafeInteger(field) || field < 1) {
|
|
20891
|
-
throw new ProtocolMessageError(`Invalid Bot integer field: ${key}`);
|
|
20892
|
-
}
|
|
20893
|
-
return field;
|
|
20894
|
-
}
|
|
20895
|
-
function readTimestamp(value, key) {
|
|
20896
|
-
const field = readText2(value, key, 64, false);
|
|
20897
|
-
if (Number.isNaN(Date.parse(field))) {
|
|
20898
|
-
throw new ProtocolMessageError(`Invalid Bot timestamp field: ${key}`);
|
|
20899
|
-
}
|
|
20900
|
-
return field;
|
|
20901
|
-
}
|
|
20902
|
-
function readDigest(value, key) {
|
|
20903
|
-
const field = readText2(value, key, 64, false);
|
|
20904
|
-
if (!SHA256_PATTERN.test(field)) {
|
|
20905
|
-
throw new ProtocolMessageError(`Invalid Bot digest field: ${key}`);
|
|
20906
|
-
}
|
|
20907
|
-
return field;
|
|
20908
|
-
}
|
|
20909
|
-
function readToken(value, key) {
|
|
20910
|
-
const field = readText2(value, key, 256, false);
|
|
20911
|
-
if (!TOKEN_PATTERN.test(field)) {
|
|
20912
|
-
throw new ProtocolMessageError(`Invalid Bot token field: ${key}`);
|
|
20913
|
-
}
|
|
20914
|
-
return field;
|
|
20915
|
-
}
|
|
20916
|
-
function readIdentifiers(value, key, maximumCount) {
|
|
20917
|
-
const field = value[key];
|
|
20918
|
-
if (!Array.isArray(field) || field.length > maximumCount) {
|
|
20919
|
-
throw new ProtocolMessageError(`Invalid Bot identifier list: ${key}`);
|
|
20920
|
-
}
|
|
20921
|
-
const identifiers = [];
|
|
20922
|
-
const unique = /* @__PURE__ */ new Set();
|
|
20923
|
-
for (const candidate of field) {
|
|
20924
|
-
if (typeof candidate !== "string" || !IDENTIFIER_PATTERN3.test(candidate) || unique.has(candidate)) {
|
|
20925
|
-
throw new ProtocolMessageError(`Invalid Bot identifier list: ${key}`);
|
|
20926
|
-
}
|
|
20927
|
-
unique.add(candidate);
|
|
20928
|
-
identifiers.push(candidate);
|
|
20929
|
-
}
|
|
20930
|
-
return Object.freeze(identifiers);
|
|
20931
|
-
}
|
|
20932
|
-
function readTargets(value, key) {
|
|
20933
|
-
const field = value[key];
|
|
20934
|
-
if (!Array.isArray(field) || field.length > 64) {
|
|
20935
|
-
throw new ProtocolMessageError(`Invalid Bot delivery targets: ${key}`);
|
|
20936
|
-
}
|
|
20937
|
-
const targets = [];
|
|
20938
|
-
const identifiers = /* @__PURE__ */ new Set();
|
|
20939
|
-
const aliases = /* @__PURE__ */ new Set();
|
|
20940
|
-
for (const candidate of field) {
|
|
20941
|
-
if (!isRecord2(candidate)) {
|
|
20942
|
-
throw new ProtocolMessageError(`Invalid Bot delivery targets: ${key}`);
|
|
20943
|
-
}
|
|
20944
|
-
assertExactKeys2(candidate, ["alias", "deliveryTargetId"]);
|
|
20945
|
-
const alias = readIdentifier2(candidate, "alias");
|
|
20946
|
-
const deliveryTargetId = readIdentifier2(candidate, "deliveryTargetId");
|
|
20947
|
-
if (aliases.has(alias) || identifiers.has(deliveryTargetId)) {
|
|
20948
|
-
throw new ProtocolMessageError(`Duplicate Bot delivery target: ${key}`);
|
|
20949
|
-
}
|
|
20950
|
-
aliases.add(alias);
|
|
20951
|
-
identifiers.add(deliveryTargetId);
|
|
20952
|
-
targets.push(new BotDeliveryTargetReference(alias, deliveryTargetId));
|
|
20953
|
-
}
|
|
20954
|
-
return Object.freeze(targets);
|
|
20955
|
-
}
|
|
20956
|
-
function readSessionConfigurations(value) {
|
|
20957
|
-
if (!Object.hasOwn(value, "sessionConfigurations")) {
|
|
20958
|
-
return [];
|
|
20959
|
-
}
|
|
20960
|
-
return decodeSessionConfigurationSelections(value["sessionConfigurations"]);
|
|
20961
|
-
}
|
|
20962
|
-
function readReplyRoute(value) {
|
|
20963
|
-
if (!isRecord2(value)) {
|
|
20964
|
-
throw new ProtocolMessageError("Invalid Bot reply route");
|
|
20965
|
-
}
|
|
20966
|
-
const kind = readText2(value, "kind", 32, false);
|
|
20967
|
-
if (kind === "owner") {
|
|
20968
|
-
assertExactKeys2(value, ["kind"]);
|
|
20969
|
-
return new OwnerBotReplyRoute();
|
|
20970
|
-
}
|
|
20971
|
-
if (kind === "connection") {
|
|
20972
|
-
assertExactKeys2(value, ["connectionId", "deliveryTargetId", "kind"]);
|
|
20973
|
-
return new BotConnectionReplyRoute(
|
|
20974
|
-
readIdentifier2(value, "connectionId"),
|
|
20975
|
-
readIdentifier2(value, "deliveryTargetId")
|
|
20976
|
-
);
|
|
20977
|
-
}
|
|
20978
|
-
throw new ProtocolMessageError("Invalid Bot reply route");
|
|
20979
|
-
}
|
|
20980
|
-
function decodeBotSessionPromptCommand(encoded) {
|
|
20981
|
-
const value = parseJson3(encoded);
|
|
20982
|
-
assertKeysWithOptional(
|
|
20983
|
-
value,
|
|
20984
|
-
[
|
|
20985
|
-
"additionalDirectoryIds",
|
|
20986
|
-
"agentId",
|
|
20987
|
-
"allowedDeliveryTargets",
|
|
20988
|
-
"behaviorDigest",
|
|
20989
|
-
"behaviorInstructions",
|
|
20990
|
-
"behaviorRevisionId",
|
|
20991
|
-
"bindingId",
|
|
20992
|
-
"bindingRevision",
|
|
20993
|
-
"botId",
|
|
20994
|
-
"commandId",
|
|
20995
|
-
"conversationId",
|
|
20996
|
-
"directoryId",
|
|
20997
|
-
"executionCapabilityId",
|
|
20998
|
-
"executionCapabilitySecret",
|
|
20999
|
-
"executionDeadlineAt",
|
|
21000
|
-
"executionId",
|
|
21001
|
-
"executionConfiguration",
|
|
21002
|
-
"images",
|
|
21003
|
-
"kind",
|
|
21004
|
-
"prompt",
|
|
21005
|
-
"replyRoute",
|
|
21006
|
-
"resources",
|
|
21007
|
-
"sessionId",
|
|
21008
|
-
"turnId"
|
|
21009
|
-
],
|
|
21010
|
-
["disposition", "sessionConfigurations", "targetCommandId"]
|
|
21011
|
-
);
|
|
21012
|
-
if (value["kind"] !== BOT_SESSION_PROMPT_KIND) {
|
|
21013
|
-
throw new ProtocolMessageError("Invalid Bot Session prompt kind");
|
|
21014
|
-
}
|
|
21015
|
-
const rawDisposition = value["disposition"];
|
|
21016
|
-
let disposition;
|
|
21017
|
-
if (rawDisposition === void 0 || rawDisposition === SessionPromptDisposition.Reject) {
|
|
21018
|
-
disposition = SessionPromptDisposition.Reject;
|
|
21019
|
-
} else if (rawDisposition === SessionPromptDisposition.Queue) {
|
|
21020
|
-
disposition = SessionPromptDisposition.Queue;
|
|
21021
|
-
} else if (rawDisposition === SessionPromptDisposition.Steer) {
|
|
21022
|
-
disposition = SessionPromptDisposition.Steer;
|
|
21023
|
-
} else {
|
|
21024
|
-
throw new ProtocolMessageError("Invalid Bot Session prompt disposition");
|
|
21025
|
-
}
|
|
21026
|
-
const targetCommandId = value["targetCommandId"] === void 0 ? "" : readText2(value, "targetCommandId", 128, false);
|
|
21027
|
-
if (disposition === SessionPromptDisposition.Reject && targetCommandId.length > 0 || disposition !== SessionPromptDisposition.Reject && !IDENTIFIER_PATTERN3.test(targetCommandId)) {
|
|
21028
|
-
throw new ProtocolMessageError("Bot Session prompt disposition has an invalid target command");
|
|
21029
|
-
}
|
|
21030
|
-
return new BotSessionPromptCommand(
|
|
21031
|
-
readIdentifier2(value, "sessionId"),
|
|
21032
|
-
readIdentifier2(value, "commandId"),
|
|
21033
|
-
readIdentifier2(value, "agentId"),
|
|
21034
|
-
readIdentifier2(value, "bindingId"),
|
|
21035
|
-
readDirectoryIdentifier2(value, "directoryId"),
|
|
21036
|
-
readIdentifiers(value, "additionalDirectoryIds", 16),
|
|
21037
|
-
decodePromptImagesValue(value["images"]),
|
|
21038
|
-
decodePromptResourcesValue(value["resources"]),
|
|
21039
|
-
readText2(value, "prompt", 1e4, false),
|
|
21040
|
-
readIdentifier2(value, "executionId"),
|
|
21041
|
-
readIdentifier2(value, "executionCapabilityId"),
|
|
21042
|
-
readToken(value, "executionCapabilitySecret"),
|
|
21043
|
-
readTimestamp(value, "executionDeadlineAt"),
|
|
21044
|
-
readIdentifier2(value, "botId"),
|
|
21045
|
-
readIdentifier2(value, "conversationId"),
|
|
21046
|
-
readIdentifier2(value, "turnId"),
|
|
21047
|
-
readIdentifier2(value, "behaviorRevisionId"),
|
|
21048
|
-
readInteger(value, "bindingRevision"),
|
|
21049
|
-
readText2(value, "behaviorInstructions", MAX_INSTRUCTIONS_LENGTH, true),
|
|
21050
|
-
readDigest(value, "behaviorDigest"),
|
|
21051
|
-
readTargets(value, "allowedDeliveryTargets"),
|
|
21052
|
-
readReplyRoute(value["replyRoute"]),
|
|
21053
|
-
decodeAgentExecutionConfiguration(value["executionConfiguration"]),
|
|
21054
|
-
readSessionConfigurations(value),
|
|
21055
|
-
disposition,
|
|
21056
|
-
targetCommandId
|
|
21057
|
-
);
|
|
21058
|
-
}
|
|
21059
|
-
|
|
21060
20785
|
// ../protocol/src/mobius-api.ts
|
|
21061
20786
|
var MOBIUS_API_PREFIX = "/mobius/api";
|
|
21062
20787
|
var API_PREFIX_PATTERN = /^\/[a-zA-Z0-9._~-]+(?:\/[a-zA-Z0-9._~-]+)*$/;
|
|
@@ -21269,13 +20994,13 @@ var SessionEventRejectionCode = {
|
|
|
21269
20994
|
SessionNotFound: "session_not_found",
|
|
21270
20995
|
SessionRejected: "session_rejected"
|
|
21271
20996
|
};
|
|
21272
|
-
var
|
|
20997
|
+
var IDENTIFIER_PATTERN3 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
21273
20998
|
var CURSOR_PATTERN = /^[A-Za-z0-9_-]{1,512}$/;
|
|
21274
20999
|
var MAX_RECORDED_EVENT_LENGTH = 8 * 1024 * 1024;
|
|
21275
21000
|
var DECIMAL_SEQUENCE_PATTERN = /^(?:0|[1-9][0-9]*)$/;
|
|
21276
21001
|
var eventSourceSchema = external_exports.discriminatedUnion("kind", [
|
|
21277
21002
|
external_exports.strictObject({
|
|
21278
|
-
attemptId: external_exports.string().min(1).max(128).regex(
|
|
21003
|
+
attemptId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
|
|
21279
21004
|
kind: external_exports.literal("attempt"),
|
|
21280
21005
|
sourceSeq: external_exports.string().min(1).max(40).regex(DECIMAL_SEQUENCE_PATTERN)
|
|
21281
21006
|
}).readonly(),
|
|
@@ -21285,41 +21010,41 @@ var eventSourceSchema = external_exports.discriminatedUnion("kind", [
|
|
|
21285
21010
|
}).readonly()
|
|
21286
21011
|
]);
|
|
21287
21012
|
var eventEnvelopeSchema = external_exports.strictObject({
|
|
21288
|
-
eventId: external_exports.string().min(1).max(128).regex(
|
|
21013
|
+
eventId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
|
|
21289
21014
|
kind: external_exports.literal(SESSION_EVENT_KIND),
|
|
21290
21015
|
payload: external_exports.string().min(2).max(MAX_RECORDED_EVENT_LENGTH),
|
|
21291
|
-
sessionId: external_exports.string().min(1).max(128).regex(
|
|
21016
|
+
sessionId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
|
|
21292
21017
|
source: eventSourceSchema
|
|
21293
21018
|
}).readonly();
|
|
21294
21019
|
var committedEventSchema = external_exports.strictObject({
|
|
21295
21020
|
cursor: external_exports.string().min(1).max(512).regex(CURSOR_PATTERN),
|
|
21296
|
-
eventId: external_exports.string().min(1).max(128).regex(
|
|
21021
|
+
eventId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
|
|
21297
21022
|
kind: external_exports.literal(SESSION_EVENT_COMMITTED_KIND),
|
|
21298
21023
|
payload: external_exports.string().min(2).max(MAX_RECORDED_EVENT_LENGTH),
|
|
21299
21024
|
recordedAt: external_exports.string().datetime({ offset: true }),
|
|
21300
21025
|
sequence: external_exports.string().min(1).max(40).regex(DECIMAL_SEQUENCE_PATTERN),
|
|
21301
|
-
sessionId: external_exports.string().min(1).max(128).regex(
|
|
21026
|
+
sessionId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
|
|
21302
21027
|
source: eventSourceSchema
|
|
21303
21028
|
}).readonly();
|
|
21304
21029
|
var eventAcknowledgementSchema = external_exports.strictObject({
|
|
21305
21030
|
cursor: external_exports.string().min(1).max(512).regex(CURSOR_PATTERN),
|
|
21306
21031
|
duplicate: external_exports.boolean(),
|
|
21307
|
-
eventId: external_exports.string().min(1).max(128).regex(
|
|
21032
|
+
eventId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
|
|
21308
21033
|
kind: external_exports.literal(SESSION_EVENT_ACK_KIND),
|
|
21309
21034
|
sequence: external_exports.string().min(1).max(40).regex(DECIMAL_SEQUENCE_PATTERN),
|
|
21310
|
-
sessionId: external_exports.string().min(1).max(128).regex(
|
|
21035
|
+
sessionId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3)
|
|
21311
21036
|
}).readonly();
|
|
21312
21037
|
var eventDeferredSchema = external_exports.strictObject({
|
|
21313
|
-
eventId: external_exports.string().min(1).max(128).regex(
|
|
21038
|
+
eventId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
|
|
21314
21039
|
kind: external_exports.literal(SESSION_EVENT_DEFERRED_KIND),
|
|
21315
21040
|
retryAfterMilliseconds: external_exports.number().int().min(100).max(6e4),
|
|
21316
|
-
sessionId: external_exports.string().min(1).max(128).regex(
|
|
21041
|
+
sessionId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3)
|
|
21317
21042
|
}).readonly();
|
|
21318
21043
|
var eventRejectionSchema = external_exports.strictObject({
|
|
21319
21044
|
code: external_exports.enum(SessionEventRejectionCode),
|
|
21320
|
-
eventId: external_exports.string().min(1).max(128).regex(
|
|
21045
|
+
eventId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3),
|
|
21321
21046
|
kind: external_exports.literal(SESSION_EVENT_REJECTED_KIND),
|
|
21322
|
-
sessionId: external_exports.string().min(1).max(128).regex(
|
|
21047
|
+
sessionId: external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN3)
|
|
21323
21048
|
}).readonly();
|
|
21324
21049
|
function decode5(encoded, schema) {
|
|
21325
21050
|
let value;
|
|
@@ -21355,15 +21080,15 @@ var decodeSessionEventRejection = (encoded) => decode5(encoded, eventRejectionSc
|
|
|
21355
21080
|
import { realpathSync, statSync } from "node:fs";
|
|
21356
21081
|
|
|
21357
21082
|
// src/acp/session-capabilities.ts
|
|
21358
|
-
function
|
|
21083
|
+
function isRecord2(value) {
|
|
21359
21084
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21360
21085
|
}
|
|
21361
21086
|
function hasTrueChildField(value, childKey, fieldKey) {
|
|
21362
|
-
if (!
|
|
21087
|
+
if (!isRecord2(value)) {
|
|
21363
21088
|
return false;
|
|
21364
21089
|
}
|
|
21365
21090
|
const child = Reflect.get(value, childKey);
|
|
21366
|
-
return
|
|
21091
|
+
return isRecord2(child) && Reflect.get(child, fieldKey) === true;
|
|
21367
21092
|
}
|
|
21368
21093
|
function unsupportedSessionCapabilities() {
|
|
21369
21094
|
return Object.freeze({
|
|
@@ -21421,12 +21146,12 @@ var ExecutableIdentity = class {
|
|
|
21421
21146
|
realPath;
|
|
21422
21147
|
requestedPath;
|
|
21423
21148
|
size;
|
|
21424
|
-
constructor(
|
|
21149
|
+
constructor(requestedPath2, realPath_, device, inode, size, changedAtMilliseconds) {
|
|
21425
21150
|
this.changedAtMilliseconds = changedAtMilliseconds;
|
|
21426
21151
|
this.device = device;
|
|
21427
21152
|
this.inode = inode;
|
|
21428
21153
|
this.realPath = realPath_;
|
|
21429
|
-
this.requestedPath =
|
|
21154
|
+
this.requestedPath = requestedPath2;
|
|
21430
21155
|
this.size = size;
|
|
21431
21156
|
}
|
|
21432
21157
|
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;
|
|
@@ -21466,8 +21191,8 @@ function executableExtensions(executableName, environment, platform) {
|
|
|
21466
21191
|
const extensions = configured.split(";").map((extension2) => extension2.trim()).filter((extension2) => extension2.length > 0).map((extension2) => extension2.startsWith(".") ? extension2 : `.${extension2}`);
|
|
21467
21192
|
return extensions.length > 0 ? extensions : [".EXE"];
|
|
21468
21193
|
}
|
|
21469
|
-
async function resolveExecutablePath(
|
|
21470
|
-
const absoluteRequestedPath = resolve(
|
|
21194
|
+
async function resolveExecutablePath(requestedPath2, platform = process.platform) {
|
|
21195
|
+
const absoluteRequestedPath = resolve(requestedPath2);
|
|
21471
21196
|
try {
|
|
21472
21197
|
const resolvedPath = await realpath(absoluteRequestedPath);
|
|
21473
21198
|
const metadata = await stat(resolvedPath);
|
|
@@ -21500,8 +21225,8 @@ async function findExecutableOnPath(executableName, environment, platform = proc
|
|
|
21500
21225
|
continue;
|
|
21501
21226
|
}
|
|
21502
21227
|
for (const extension2 of extensions) {
|
|
21503
|
-
const
|
|
21504
|
-
const executable = await resolveExecutablePath(
|
|
21228
|
+
const requestedPath2 = resolve(join(entry, `${executableName}${extension2}`));
|
|
21229
|
+
const executable = await resolveExecutablePath(requestedPath2, platform);
|
|
21505
21230
|
if (executable !== null) {
|
|
21506
21231
|
return executable;
|
|
21507
21232
|
}
|
|
@@ -22154,11 +21879,7 @@ var LocalAgentDefinition = class _LocalAgentDefinition {
|
|
|
22154
21879
|
id;
|
|
22155
21880
|
label;
|
|
22156
21881
|
permissionProfile;
|
|
22157
|
-
|
|
22158
|
-
constructor(id, label, command, arguments_, environment = {}, adapterVersion = "", agentVersion = "", adapterIdentity = readTrustedIdentity(command), agentIdentity = adapterIdentity, promptTimeoutMilliseconds = 30 * 60 * 1e3, capabilities = unsupportedSessionCapabilities(), permissionProfile = permissionProfileForAgent(id)) {
|
|
22159
|
-
if (!Number.isSafeInteger(promptTimeoutMilliseconds) || promptTimeoutMilliseconds < 1) {
|
|
22160
|
-
throw new Error("The local Agent prompt deadline is invalid");
|
|
22161
|
-
}
|
|
21882
|
+
constructor(id, label, command, arguments_, environment = {}, adapterVersion = "", agentVersion = "", adapterIdentity = readTrustedIdentity(command), agentIdentity = adapterIdentity, capabilities = unsupportedSessionCapabilities(), permissionProfile = permissionProfileForAgent(id)) {
|
|
22162
21883
|
this.adapterIdentity = adapterIdentity;
|
|
22163
21884
|
this.adapterPath = adapterIdentity.realPath;
|
|
22164
21885
|
this.adapterVersion = adapterVersion;
|
|
@@ -22168,7 +21889,6 @@ var LocalAgentDefinition = class _LocalAgentDefinition {
|
|
|
22168
21889
|
this.id = id;
|
|
22169
21890
|
this.label = label;
|
|
22170
21891
|
this.permissionProfile = permissionProfile;
|
|
22171
|
-
this.promptTimeoutMilliseconds = promptTimeoutMilliseconds;
|
|
22172
21892
|
this.command = adapterIdentity.realPath;
|
|
22173
21893
|
this.arguments = Object.freeze([...arguments_]);
|
|
22174
21894
|
this.environment = permissionProfile.apply(environment, permissionProfile.currentMode(environment));
|
|
@@ -22187,7 +21907,6 @@ var LocalAgentDefinition = class _LocalAgentDefinition {
|
|
|
22187
21907
|
this.agentVersion,
|
|
22188
21908
|
this.adapterIdentity,
|
|
22189
21909
|
this.agentIdentity,
|
|
22190
|
-
this.promptTimeoutMilliseconds,
|
|
22191
21910
|
this.capabilities,
|
|
22192
21911
|
this.permissionProfile
|
|
22193
21912
|
);
|
|
@@ -22327,10 +22046,11 @@ import {
|
|
|
22327
22046
|
} from "@agentclientprotocol/sdk";
|
|
22328
22047
|
|
|
22329
22048
|
// src/authorization/local-raster.ts
|
|
22330
|
-
import { readFile as readFile2, realpath as realpath2, stat as stat2 } from "node:fs/promises";
|
|
22049
|
+
import { open as open2, readFile as readFile2, realpath as realpath2, stat as stat2 } from "node:fs/promises";
|
|
22331
22050
|
import { basename, isAbsolute, normalize } from "node:path";
|
|
22332
22051
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
22333
|
-
var MAX_LOCAL_RASTER_BYTES =
|
|
22052
|
+
var MAX_LOCAL_RASTER_BYTES = 128 * 1024 * 1024;
|
|
22053
|
+
var MAX_INLINE_RASTER_BYTES = 3e6;
|
|
22334
22054
|
var PNG_SIGNATURE = Uint8Array.of(137, 80, 78, 71);
|
|
22335
22055
|
var JPEG_SIGNATURE = Uint8Array.of(255, 216, 255);
|
|
22336
22056
|
var GIF87_SIGNATURE = new TextEncoder().encode("GIF87a");
|
|
@@ -22341,12 +22061,17 @@ var LocalRasterImage = class {
|
|
|
22341
22061
|
bytes;
|
|
22342
22062
|
mimeType;
|
|
22343
22063
|
name;
|
|
22344
|
-
|
|
22064
|
+
sourceUri;
|
|
22065
|
+
constructor(name, mimeType, bytes, sourceUri = "") {
|
|
22345
22066
|
this.bytes = bytes;
|
|
22346
22067
|
this.mimeType = mimeType;
|
|
22347
22068
|
this.name = name;
|
|
22069
|
+
this.sourceUri = sourceUri;
|
|
22348
22070
|
}
|
|
22349
|
-
base64 = () =>
|
|
22071
|
+
base64 = async () => {
|
|
22072
|
+
const bytes = this.bytes ?? new Uint8Array(await readFile2(this.sourceUri));
|
|
22073
|
+
return Buffer.from(bytes).toString("base64");
|
|
22074
|
+
};
|
|
22350
22075
|
};
|
|
22351
22076
|
function startsWith(bytes, signature, offset = 0) {
|
|
22352
22077
|
if (bytes.byteLength < offset + signature.byteLength) {
|
|
@@ -22370,14 +22095,14 @@ function sniffRasterMime(bytes) {
|
|
|
22370
22095
|
return null;
|
|
22371
22096
|
}
|
|
22372
22097
|
function readInlineRaster(data, name = "Image") {
|
|
22373
|
-
if (data.length === 0 || data.length > Math.ceil(
|
|
22098
|
+
if (data.length === 0 || data.length > Math.ceil(MAX_INLINE_RASTER_BYTES / 3) * 4 || data.length % 4 !== 0) {
|
|
22374
22099
|
return null;
|
|
22375
22100
|
}
|
|
22376
22101
|
if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(data)) {
|
|
22377
22102
|
return null;
|
|
22378
22103
|
}
|
|
22379
22104
|
const bytes = new Uint8Array(Buffer.from(data, "base64"));
|
|
22380
|
-
if (bytes.byteLength < 1 || bytes.byteLength >
|
|
22105
|
+
if (bytes.byteLength < 1 || bytes.byteLength > MAX_INLINE_RASTER_BYTES) {
|
|
22381
22106
|
return null;
|
|
22382
22107
|
}
|
|
22383
22108
|
const mimeType = sniffRasterMime(bytes);
|
|
@@ -22445,16 +22170,19 @@ async function readLocalRaster(uri, signal) {
|
|
|
22445
22170
|
if (!targetMetadata.isFile() || targetMetadata.size < 1 || targetMetadata.size > MAX_LOCAL_RASTER_BYTES) {
|
|
22446
22171
|
return null;
|
|
22447
22172
|
}
|
|
22448
|
-
const
|
|
22449
|
-
|
|
22450
|
-
|
|
22451
|
-
|
|
22173
|
+
const handle = await open2(target, "r");
|
|
22174
|
+
const header = new Uint8Array(12);
|
|
22175
|
+
try {
|
|
22176
|
+
await handle.read(header, 0, header.byteLength, 0);
|
|
22177
|
+
} finally {
|
|
22178
|
+
await handle.close();
|
|
22452
22179
|
}
|
|
22453
|
-
|
|
22180
|
+
signal.throwIfAborted();
|
|
22181
|
+
const mimeType = sniffRasterMime(header);
|
|
22454
22182
|
if (mimeType === null) {
|
|
22455
22183
|
return null;
|
|
22456
22184
|
}
|
|
22457
|
-
return new LocalRasterImage(basename(target) || "Image", mimeType,
|
|
22185
|
+
return new LocalRasterImage(basename(target) || "Image", mimeType, null, target);
|
|
22458
22186
|
}
|
|
22459
22187
|
|
|
22460
22188
|
// src/authorization/local-video.ts
|
|
@@ -22580,7 +22308,7 @@ async function resolveMessageImages(message, usedCharacters, signal) {
|
|
|
22580
22308
|
if (local === null) {
|
|
22581
22309
|
return "[Image unavailable]";
|
|
22582
22310
|
}
|
|
22583
|
-
const data = local.base64();
|
|
22311
|
+
const data = await local.base64();
|
|
22584
22312
|
if (usedCharacters + imageCharacters + data.length > SESSION_HISTORY_IMAGE_CHARACTER_LIMIT) {
|
|
22585
22313
|
return "[Image unavailable]";
|
|
22586
22314
|
}
|
|
@@ -22616,7 +22344,7 @@ async function replaceImageMarkers(text3, replace) {
|
|
|
22616
22344
|
|
|
22617
22345
|
// src/acp/activity.ts
|
|
22618
22346
|
var TRUNCATION_MARKER = "\n\u2026 output truncated by Mobius";
|
|
22619
|
-
function
|
|
22347
|
+
function isRecord3(value) {
|
|
22620
22348
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22621
22349
|
}
|
|
22622
22350
|
var AcpActivity = class _AcpActivity {
|
|
@@ -22850,16 +22578,16 @@ async function normalizeToolContent(content3, prepareContent) {
|
|
|
22850
22578
|
return normalized;
|
|
22851
22579
|
}
|
|
22852
22580
|
function rawMcpToolContent(rawOutput) {
|
|
22853
|
-
if (!
|
|
22581
|
+
if (!isRecord3(rawOutput)) {
|
|
22854
22582
|
return [];
|
|
22855
22583
|
}
|
|
22856
|
-
const result =
|
|
22584
|
+
const result = isRecord3(rawOutput["result"]) ? rawOutput["result"] : rawOutput;
|
|
22857
22585
|
const content3 = result["content"];
|
|
22858
22586
|
if (!Array.isArray(content3)) {
|
|
22859
22587
|
return [];
|
|
22860
22588
|
}
|
|
22861
22589
|
return content3.flatMap((item) => {
|
|
22862
|
-
if (!
|
|
22590
|
+
if (!isRecord3(item) || item["type"] !== "image" || typeof item["data"] !== "string" || typeof item["mimeType"] !== "string") {
|
|
22863
22591
|
return [];
|
|
22864
22592
|
}
|
|
22865
22593
|
const uri = item["uri"];
|
|
@@ -22936,7 +22664,7 @@ function contentPhase(content3) {
|
|
|
22936
22664
|
return "";
|
|
22937
22665
|
}
|
|
22938
22666
|
const codex = metadata["codex"];
|
|
22939
|
-
if (!
|
|
22667
|
+
if (!isRecord3(codex)) {
|
|
22940
22668
|
return "";
|
|
22941
22669
|
}
|
|
22942
22670
|
const phase = codex["phase"];
|
|
@@ -25740,7 +25468,7 @@ var attention = {
|
|
|
25740
25468
|
};
|
|
25741
25469
|
function resolveAllAttention(events, context) {
|
|
25742
25470
|
let index2 = -1;
|
|
25743
|
-
let
|
|
25471
|
+
let open6;
|
|
25744
25472
|
let group;
|
|
25745
25473
|
let text3;
|
|
25746
25474
|
let openingSequence;
|
|
@@ -25750,16 +25478,16 @@ function resolveAllAttention(events, context) {
|
|
|
25750
25478
|
let offset;
|
|
25751
25479
|
while (++index2 < events.length) {
|
|
25752
25480
|
if (events[index2][0] === "enter" && events[index2][1].type === "attentionSequence" && events[index2][1]._close) {
|
|
25753
|
-
|
|
25754
|
-
while (
|
|
25755
|
-
if (events[
|
|
25756
|
-
context.sliceSerialize(events[
|
|
25757
|
-
if ((events[
|
|
25481
|
+
open6 = index2;
|
|
25482
|
+
while (open6--) {
|
|
25483
|
+
if (events[open6][0] === "exit" && events[open6][1].type === "attentionSequence" && events[open6][1]._open && // If the markers are the same:
|
|
25484
|
+
context.sliceSerialize(events[open6][1]).charCodeAt(0) === context.sliceSerialize(events[index2][1]).charCodeAt(0)) {
|
|
25485
|
+
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)) {
|
|
25758
25486
|
continue;
|
|
25759
25487
|
}
|
|
25760
|
-
use = events[
|
|
25488
|
+
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;
|
|
25761
25489
|
const start = {
|
|
25762
|
-
...events[
|
|
25490
|
+
...events[open6][1].end
|
|
25763
25491
|
};
|
|
25764
25492
|
const end = {
|
|
25765
25493
|
...events[index2][1].start
|
|
@@ -25770,7 +25498,7 @@ function resolveAllAttention(events, context) {
|
|
|
25770
25498
|
type: use > 1 ? "strongSequence" : "emphasisSequence",
|
|
25771
25499
|
start,
|
|
25772
25500
|
end: {
|
|
25773
|
-
...events[
|
|
25501
|
+
...events[open6][1].end
|
|
25774
25502
|
}
|
|
25775
25503
|
};
|
|
25776
25504
|
closingSequence = {
|
|
@@ -25783,7 +25511,7 @@ function resolveAllAttention(events, context) {
|
|
|
25783
25511
|
text3 = {
|
|
25784
25512
|
type: use > 1 ? "strongText" : "emphasisText",
|
|
25785
25513
|
start: {
|
|
25786
|
-
...events[
|
|
25514
|
+
...events[open6][1].end
|
|
25787
25515
|
},
|
|
25788
25516
|
end: {
|
|
25789
25517
|
...events[index2][1].start
|
|
@@ -25798,18 +25526,18 @@ function resolveAllAttention(events, context) {
|
|
|
25798
25526
|
...closingSequence.end
|
|
25799
25527
|
}
|
|
25800
25528
|
};
|
|
25801
|
-
events[
|
|
25529
|
+
events[open6][1].end = {
|
|
25802
25530
|
...openingSequence.start
|
|
25803
25531
|
};
|
|
25804
25532
|
events[index2][1].start = {
|
|
25805
25533
|
...closingSequence.end
|
|
25806
25534
|
};
|
|
25807
25535
|
nextEvents = [];
|
|
25808
|
-
if (events[
|
|
25809
|
-
nextEvents = push(nextEvents, [["enter", events[
|
|
25536
|
+
if (events[open6][1].end.offset - events[open6][1].start.offset) {
|
|
25537
|
+
nextEvents = push(nextEvents, [["enter", events[open6][1], context], ["exit", events[open6][1], context]]);
|
|
25810
25538
|
}
|
|
25811
25539
|
nextEvents = push(nextEvents, [["enter", group, context], ["enter", openingSequence, context], ["exit", openingSequence, context], ["enter", text3, context]]);
|
|
25812
|
-
nextEvents = push(nextEvents, resolveAll(context.parser.constructs.insideSpan.null, events.slice(
|
|
25540
|
+
nextEvents = push(nextEvents, resolveAll(context.parser.constructs.insideSpan.null, events.slice(open6 + 1, index2), context));
|
|
25813
25541
|
nextEvents = push(nextEvents, [["exit", text3, context], ["enter", closingSequence, context], ["exit", closingSequence, context], ["exit", group, context]]);
|
|
25814
25542
|
if (events[index2][1].end.offset - events[index2][1].start.offset) {
|
|
25815
25543
|
offset = 2;
|
|
@@ -25817,8 +25545,8 @@ function resolveAllAttention(events, context) {
|
|
|
25817
25545
|
} else {
|
|
25818
25546
|
offset = 0;
|
|
25819
25547
|
}
|
|
25820
|
-
splice(events,
|
|
25821
|
-
index2 =
|
|
25548
|
+
splice(events, open6 - 1, index2 - open6 + 3, nextEvents);
|
|
25549
|
+
index2 = open6 + nextEvents.length - offset - 2;
|
|
25822
25550
|
break;
|
|
25823
25551
|
}
|
|
25824
25552
|
}
|
|
@@ -25850,10 +25578,10 @@ function tokenizeAttention(effects, ok2) {
|
|
|
25850
25578
|
}
|
|
25851
25579
|
const token = effects.exit("attentionSequence");
|
|
25852
25580
|
const after = classifyCharacter(code);
|
|
25853
|
-
const
|
|
25581
|
+
const open6 = !after || after === 2 && before || attentionMarkers2.includes(code);
|
|
25854
25582
|
const close = !before || before === 2 && after || attentionMarkers2.includes(previous2);
|
|
25855
|
-
token._open = Boolean(marker === 42 ?
|
|
25856
|
-
token._close = Boolean(marker === 42 ? close : close && (after || !
|
|
25583
|
+
token._open = Boolean(marker === 42 ? open6 : open6 && (before || !close));
|
|
25584
|
+
token._close = Boolean(marker === 42 ? close : close && (after || !open6));
|
|
25857
25585
|
return ok2(code);
|
|
25858
25586
|
}
|
|
25859
25587
|
}
|
|
@@ -25877,9 +25605,9 @@ function tokenizeAutolink(effects, ok2, nok) {
|
|
|
25877
25605
|
effects.consume(code);
|
|
25878
25606
|
effects.exit("autolinkMarker");
|
|
25879
25607
|
effects.enter("autolinkProtocol");
|
|
25880
|
-
return
|
|
25608
|
+
return open6;
|
|
25881
25609
|
}
|
|
25882
|
-
function
|
|
25610
|
+
function open6(code) {
|
|
25883
25611
|
if (asciiAlpha(code)) {
|
|
25884
25612
|
effects.consume(code);
|
|
25885
25613
|
return schemeOrEmailAtext;
|
|
@@ -26079,9 +25807,9 @@ function tokenizeCharacterReference(effects, ok2, nok) {
|
|
|
26079
25807
|
effects.enter("characterReferenceMarker");
|
|
26080
25808
|
effects.consume(code);
|
|
26081
25809
|
effects.exit("characterReferenceMarker");
|
|
26082
|
-
return
|
|
25810
|
+
return open6;
|
|
26083
25811
|
}
|
|
26084
|
-
function
|
|
25812
|
+
function open6(code) {
|
|
26085
25813
|
if (code === 35) {
|
|
26086
25814
|
effects.enter("characterReferenceMarkerNumeric");
|
|
26087
25815
|
effects.consume(code);
|
|
@@ -27450,9 +27178,9 @@ function tokenizeHtmlFlow(effects, ok2, nok) {
|
|
|
27450
27178
|
effects.enter("htmlFlow");
|
|
27451
27179
|
effects.enter("htmlFlowData");
|
|
27452
27180
|
effects.consume(code);
|
|
27453
|
-
return
|
|
27181
|
+
return open6;
|
|
27454
27182
|
}
|
|
27455
|
-
function
|
|
27183
|
+
function open6(code) {
|
|
27456
27184
|
if (code === 33) {
|
|
27457
27185
|
effects.consume(code);
|
|
27458
27186
|
return declarationOpen;
|
|
@@ -27800,9 +27528,9 @@ function tokenizeHtmlText(effects, ok2, nok) {
|
|
|
27800
27528
|
effects.enter("htmlText");
|
|
27801
27529
|
effects.enter("htmlTextData");
|
|
27802
27530
|
effects.consume(code);
|
|
27803
|
-
return
|
|
27531
|
+
return open6;
|
|
27804
27532
|
}
|
|
27805
|
-
function
|
|
27533
|
+
function open6(code) {
|
|
27806
27534
|
if (code === 33) {
|
|
27807
27535
|
effects.consume(code);
|
|
27808
27536
|
return declarationOpen;
|
|
@@ -28128,12 +27856,12 @@ function resolveToLabelEnd(events, context) {
|
|
|
28128
27856
|
let index2 = events.length;
|
|
28129
27857
|
let offset = 0;
|
|
28130
27858
|
let token;
|
|
28131
|
-
let
|
|
27859
|
+
let open6;
|
|
28132
27860
|
let close;
|
|
28133
27861
|
let media;
|
|
28134
27862
|
while (index2--) {
|
|
28135
27863
|
token = events[index2][1];
|
|
28136
|
-
if (
|
|
27864
|
+
if (open6) {
|
|
28137
27865
|
if (token.type === "link" || token.type === "labelLink" && token._inactive) {
|
|
28138
27866
|
break;
|
|
28139
27867
|
}
|
|
@@ -28142,7 +27870,7 @@ function resolveToLabelEnd(events, context) {
|
|
|
28142
27870
|
}
|
|
28143
27871
|
} else if (close) {
|
|
28144
27872
|
if (events[index2][0] === "enter" && (token.type === "labelImage" || token.type === "labelLink") && !token._balanced) {
|
|
28145
|
-
|
|
27873
|
+
open6 = index2;
|
|
28146
27874
|
if (token.type !== "labelLink") {
|
|
28147
27875
|
offset = 2;
|
|
28148
27876
|
break;
|
|
@@ -28153,9 +27881,9 @@ function resolveToLabelEnd(events, context) {
|
|
|
28153
27881
|
}
|
|
28154
27882
|
}
|
|
28155
27883
|
const group = {
|
|
28156
|
-
type: events[
|
|
27884
|
+
type: events[open6][1].type === "labelLink" ? "link" : "image",
|
|
28157
27885
|
start: {
|
|
28158
|
-
...events[
|
|
27886
|
+
...events[open6][1].start
|
|
28159
27887
|
},
|
|
28160
27888
|
end: {
|
|
28161
27889
|
...events[events.length - 1][1].end
|
|
@@ -28164,7 +27892,7 @@ function resolveToLabelEnd(events, context) {
|
|
|
28164
27892
|
const label = {
|
|
28165
27893
|
type: "label",
|
|
28166
27894
|
start: {
|
|
28167
|
-
...events[
|
|
27895
|
+
...events[open6][1].start
|
|
28168
27896
|
},
|
|
28169
27897
|
end: {
|
|
28170
27898
|
...events[close][1].end
|
|
@@ -28173,20 +27901,20 @@ function resolveToLabelEnd(events, context) {
|
|
|
28173
27901
|
const text3 = {
|
|
28174
27902
|
type: "labelText",
|
|
28175
27903
|
start: {
|
|
28176
|
-
...events[
|
|
27904
|
+
...events[open6 + offset + 2][1].end
|
|
28177
27905
|
},
|
|
28178
27906
|
end: {
|
|
28179
27907
|
...events[close - 2][1].start
|
|
28180
27908
|
}
|
|
28181
27909
|
};
|
|
28182
27910
|
media = [["enter", group, context], ["enter", label, context]];
|
|
28183
|
-
media = push(media, events.slice(
|
|
27911
|
+
media = push(media, events.slice(open6 + 1, open6 + offset + 3));
|
|
28184
27912
|
media = push(media, [["enter", text3, context]]);
|
|
28185
|
-
media = push(media, resolveAll(context.parser.constructs.insideSpan.null, events.slice(
|
|
27913
|
+
media = push(media, resolveAll(context.parser.constructs.insideSpan.null, events.slice(open6 + offset + 4, close - 3), context));
|
|
28186
27914
|
media = push(media, [["exit", text3, context], events[close - 2], events[close - 1], ["exit", label, context]]);
|
|
28187
27915
|
media = push(media, events.slice(close + 1));
|
|
28188
27916
|
media = push(media, [["exit", group, context]]);
|
|
28189
|
-
splice(events,
|
|
27917
|
+
splice(events, open6, events.length, media);
|
|
28190
27918
|
return events;
|
|
28191
27919
|
}
|
|
28192
27920
|
function tokenizeLabelEnd(effects, ok2, nok) {
|
|
@@ -28331,9 +28059,9 @@ function tokenizeLabelStartImage(effects, ok2, nok) {
|
|
|
28331
28059
|
effects.enter("labelImageMarker");
|
|
28332
28060
|
effects.consume(code);
|
|
28333
28061
|
effects.exit("labelImageMarker");
|
|
28334
|
-
return
|
|
28062
|
+
return open6;
|
|
28335
28063
|
}
|
|
28336
|
-
function
|
|
28064
|
+
function open6(code) {
|
|
28337
28065
|
if (code === 91) {
|
|
28338
28066
|
effects.enter("labelMarker");
|
|
28339
28067
|
effects.consume(code);
|
|
@@ -29637,8 +29365,8 @@ function compiler(options) {
|
|
|
29637
29365
|
return length;
|
|
29638
29366
|
}
|
|
29639
29367
|
function opener(create, and) {
|
|
29640
|
-
return
|
|
29641
|
-
function
|
|
29368
|
+
return open6;
|
|
29369
|
+
function open6(token) {
|
|
29642
29370
|
enter.call(this, create(token), token);
|
|
29643
29371
|
if (and) and.call(this, token);
|
|
29644
29372
|
}
|
|
@@ -29670,18 +29398,18 @@ function compiler(options) {
|
|
|
29670
29398
|
}
|
|
29671
29399
|
function exit2(token, onExitError) {
|
|
29672
29400
|
const node3 = this.stack.pop();
|
|
29673
|
-
const
|
|
29674
|
-
if (!
|
|
29401
|
+
const open6 = this.tokenStack.pop();
|
|
29402
|
+
if (!open6) {
|
|
29675
29403
|
throw new Error("Cannot close `" + token.type + "` (" + stringifyPosition({
|
|
29676
29404
|
start: token.start,
|
|
29677
29405
|
end: token.end
|
|
29678
29406
|
}) + "): it\u2019s not open");
|
|
29679
|
-
} else if (
|
|
29407
|
+
} else if (open6[0].type !== token.type) {
|
|
29680
29408
|
if (onExitError) {
|
|
29681
|
-
onExitError.call(this, token,
|
|
29409
|
+
onExitError.call(this, token, open6[0]);
|
|
29682
29410
|
} else {
|
|
29683
|
-
const handler =
|
|
29684
|
-
handler.call(this, token,
|
|
29411
|
+
const handler = open6[1] || defaultOnError;
|
|
29412
|
+
handler.call(this, token, open6[0]);
|
|
29685
29413
|
}
|
|
29686
29414
|
}
|
|
29687
29415
|
node3.position.end = point2(token.end);
|
|
@@ -30365,7 +30093,7 @@ var SessionConfigProtocolError = class extends Error {
|
|
|
30365
30093
|
this.name = "SessionConfigProtocolError";
|
|
30366
30094
|
}
|
|
30367
30095
|
};
|
|
30368
|
-
function
|
|
30096
|
+
function isRecord4(value) {
|
|
30369
30097
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
30370
30098
|
}
|
|
30371
30099
|
function readString2(value, fallback = "") {
|
|
@@ -30377,13 +30105,13 @@ function truncate2(value, maximum) {
|
|
|
30377
30105
|
function readBoolean(value, fallback = false) {
|
|
30378
30106
|
return typeof value === "boolean" ? value : fallback;
|
|
30379
30107
|
}
|
|
30380
|
-
function normalizeConfigValue(
|
|
30108
|
+
function normalizeConfigValue(option, groupId = "", groupName = "") {
|
|
30381
30109
|
return {
|
|
30382
|
-
description: truncate2(readString2(
|
|
30110
|
+
description: truncate2(readString2(option["description"]), 500),
|
|
30383
30111
|
groupId: truncate2(groupId, 128),
|
|
30384
30112
|
groupName: truncate2(groupName, 255),
|
|
30385
|
-
name: truncate2(readString2(
|
|
30386
|
-
value: truncate2(readString2(
|
|
30113
|
+
name: truncate2(readString2(option["name"], readString2(option["value"])), 255),
|
|
30114
|
+
value: truncate2(readString2(option["value"]), 500)
|
|
30387
30115
|
};
|
|
30388
30116
|
}
|
|
30389
30117
|
function normalizeConfigValues(value) {
|
|
@@ -30392,7 +30120,7 @@ function normalizeConfigValues(value) {
|
|
|
30392
30120
|
}
|
|
30393
30121
|
const normalized = [];
|
|
30394
30122
|
for (const entry of value) {
|
|
30395
|
-
if (!
|
|
30123
|
+
if (!isRecord4(entry)) {
|
|
30396
30124
|
continue;
|
|
30397
30125
|
}
|
|
30398
30126
|
const groupedOptions = entry["options"];
|
|
@@ -30400,7 +30128,7 @@ function normalizeConfigValues(value) {
|
|
|
30400
30128
|
const groupId = readString2(entry["group"]);
|
|
30401
30129
|
const groupName = readString2(entry["name"]);
|
|
30402
30130
|
for (const groupedOption of groupedOptions) {
|
|
30403
|
-
if (
|
|
30131
|
+
if (isRecord4(groupedOption)) {
|
|
30404
30132
|
normalized.push(normalizeConfigValue(groupedOption, groupId, groupName));
|
|
30405
30133
|
}
|
|
30406
30134
|
}
|
|
@@ -30413,21 +30141,21 @@ function normalizeConfigValues(value) {
|
|
|
30413
30141
|
function normalizeConfigOptions(value, modes) {
|
|
30414
30142
|
const normalized = [];
|
|
30415
30143
|
if (Array.isArray(value)) {
|
|
30416
|
-
for (const
|
|
30417
|
-
if (!
|
|
30144
|
+
for (const option of value) {
|
|
30145
|
+
if (!isRecord4(option)) {
|
|
30418
30146
|
continue;
|
|
30419
30147
|
}
|
|
30420
|
-
const id = truncate2(readString2(
|
|
30421
|
-
const name = truncate2(readString2(
|
|
30148
|
+
const id = truncate2(readString2(option["id"]), 128);
|
|
30149
|
+
const name = truncate2(readString2(option["name"], id), 255);
|
|
30422
30150
|
if (id.length === 0 || name.length === 0) {
|
|
30423
30151
|
continue;
|
|
30424
30152
|
}
|
|
30425
|
-
if (
|
|
30153
|
+
if (option["type"] === "boolean") {
|
|
30426
30154
|
normalized.push({
|
|
30427
|
-
booleanValue: readBoolean(
|
|
30428
|
-
category: truncate2(readString2(
|
|
30155
|
+
booleanValue: readBoolean(option["currentValue"]),
|
|
30156
|
+
category: truncate2(readString2(option["category"]), 128),
|
|
30429
30157
|
currentValue: "",
|
|
30430
|
-
description: truncate2(readString2(
|
|
30158
|
+
description: truncate2(readString2(option["description"]), 500),
|
|
30431
30159
|
id,
|
|
30432
30160
|
name,
|
|
30433
30161
|
type: "boolean",
|
|
@@ -30435,15 +30163,15 @@ function normalizeConfigOptions(value, modes) {
|
|
|
30435
30163
|
});
|
|
30436
30164
|
continue;
|
|
30437
30165
|
}
|
|
30438
|
-
if (
|
|
30439
|
-
const values = normalizeConfigValues(
|
|
30440
|
-
const currentValue = truncate2(readString2(
|
|
30166
|
+
if (option["type"] === "select") {
|
|
30167
|
+
const values = normalizeConfigValues(option["options"]);
|
|
30168
|
+
const currentValue = truncate2(readString2(option["currentValue"]), 500);
|
|
30441
30169
|
if (currentValue.length > 0 && values.some((entry) => entry.value === currentValue)) {
|
|
30442
30170
|
normalized.push({
|
|
30443
30171
|
booleanValue: false,
|
|
30444
|
-
category: truncate2(readString2(
|
|
30172
|
+
category: truncate2(readString2(option["category"]), 128),
|
|
30445
30173
|
currentValue,
|
|
30446
|
-
description: truncate2(readString2(
|
|
30174
|
+
description: truncate2(readString2(option["description"]), 500),
|
|
30447
30175
|
id,
|
|
30448
30176
|
name,
|
|
30449
30177
|
type: "select",
|
|
@@ -30453,12 +30181,12 @@ function normalizeConfigOptions(value, modes) {
|
|
|
30453
30181
|
}
|
|
30454
30182
|
}
|
|
30455
30183
|
}
|
|
30456
|
-
if (
|
|
30184
|
+
if (isRecord4(modes)) {
|
|
30457
30185
|
const values = [];
|
|
30458
30186
|
const availableModes = modes["availableModes"];
|
|
30459
30187
|
if (Array.isArray(availableModes)) {
|
|
30460
30188
|
for (const mode of availableModes) {
|
|
30461
|
-
if (!
|
|
30189
|
+
if (!isRecord4(mode)) {
|
|
30462
30190
|
continue;
|
|
30463
30191
|
}
|
|
30464
30192
|
const id = truncate2(readString2(mode["id"]), 500);
|
|
@@ -30491,14 +30219,14 @@ function normalizeConfigOptions(value, modes) {
|
|
|
30491
30219
|
return normalized.slice(0, 100);
|
|
30492
30220
|
}
|
|
30493
30221
|
function insertRequiredOption(current, required2, afterCategory = "") {
|
|
30494
|
-
if (current.some((
|
|
30222
|
+
if (current.some((option) => option.id === required2.id || option.category === required2.category)) {
|
|
30495
30223
|
return current;
|
|
30496
30224
|
}
|
|
30497
30225
|
if (current.length < MAXIMUM_CONFIG_OPTIONS) {
|
|
30498
30226
|
if (afterCategory.length === 0) {
|
|
30499
30227
|
return [required2, ...current];
|
|
30500
30228
|
}
|
|
30501
|
-
const index3 = current.findIndex((
|
|
30229
|
+
const index3 = current.findIndex((option) => option.category === afterCategory);
|
|
30502
30230
|
if (index3 < 0) {
|
|
30503
30231
|
return [...current, required2];
|
|
30504
30232
|
}
|
|
@@ -30507,7 +30235,7 @@ function insertRequiredOption(current, required2, afterCategory = "") {
|
|
|
30507
30235
|
if (afterCategory.length === 0) {
|
|
30508
30236
|
return [required2, ...current.slice(0, MAXIMUM_CONFIG_OPTIONS - 1)];
|
|
30509
30237
|
}
|
|
30510
|
-
const index2 = current.findIndex((
|
|
30238
|
+
const index2 = current.findIndex((option) => option.category === afterCategory);
|
|
30511
30239
|
if (index2 < 0) {
|
|
30512
30240
|
return [...current.slice(0, MAXIMUM_CONFIG_OPTIONS - 1), required2];
|
|
30513
30241
|
}
|
|
@@ -30520,11 +30248,11 @@ function insertRequiredOption(current, required2, afterCategory = "") {
|
|
|
30520
30248
|
}
|
|
30521
30249
|
return [...current.slice(0, MAXIMUM_CONFIG_OPTIONS - 2), anchor2, required2];
|
|
30522
30250
|
}
|
|
30523
|
-
function validRequiredSelect(
|
|
30524
|
-
return
|
|
30251
|
+
function validRequiredSelect(option) {
|
|
30252
|
+
return option.type === "select" && option.currentValue.length > 0 && option.values.some((value) => value.value === option.currentValue);
|
|
30525
30253
|
}
|
|
30526
30254
|
function ensureModelOption(current) {
|
|
30527
|
-
const existing = current.find((
|
|
30255
|
+
const existing = current.find((option) => option.id === "model" || option.category === "model");
|
|
30528
30256
|
if (existing !== void 0 && validRequiredSelect(existing)) {
|
|
30529
30257
|
return current;
|
|
30530
30258
|
}
|
|
@@ -30547,12 +30275,12 @@ function ensureModelOption(current) {
|
|
|
30547
30275
|
]
|
|
30548
30276
|
};
|
|
30549
30277
|
return insertRequiredOption(
|
|
30550
|
-
current.filter((
|
|
30278
|
+
current.filter((option) => option.id !== "model" && option.category !== "model"),
|
|
30551
30279
|
unavailable
|
|
30552
30280
|
);
|
|
30553
30281
|
}
|
|
30554
30282
|
function ensureReasoningEffortOption(current) {
|
|
30555
|
-
const existing = current.find((
|
|
30283
|
+
const existing = current.find((option) => option.id === "reasoning_effort" || option.category === "thought_level");
|
|
30556
30284
|
if (existing !== void 0 && validRequiredSelect(existing)) {
|
|
30557
30285
|
return current;
|
|
30558
30286
|
}
|
|
@@ -30575,7 +30303,7 @@ function ensureReasoningEffortOption(current) {
|
|
|
30575
30303
|
]
|
|
30576
30304
|
};
|
|
30577
30305
|
return insertRequiredOption(
|
|
30578
|
-
current.filter((
|
|
30306
|
+
current.filter((option) => option.id !== "reasoning_effort" && option.category !== "thought_level"),
|
|
30579
30307
|
unavailable,
|
|
30580
30308
|
"model"
|
|
30581
30309
|
);
|
|
@@ -30583,34 +30311,34 @@ function ensureReasoningEffortOption(current) {
|
|
|
30583
30311
|
function ensureRequiredExecutionOptions(current, permission) {
|
|
30584
30312
|
const normalized = ensureReasoningEffortOption(ensureModelOption(current));
|
|
30585
30313
|
const model = normalized.find(
|
|
30586
|
-
(
|
|
30314
|
+
(option) => (option.id === "model" || option.category === "model") && validRequiredSelect(option)
|
|
30587
30315
|
);
|
|
30588
30316
|
const reasoningEffort = normalized.find(
|
|
30589
|
-
(
|
|
30317
|
+
(option) => (option.id === "reasoning_effort" || option.category === "thought_level") && validRequiredSelect(option)
|
|
30590
30318
|
);
|
|
30591
30319
|
if (model === void 0 || reasoningEffort === void 0) {
|
|
30592
30320
|
throw new SessionConfigProtocolError("The required Agent execution settings are unavailable");
|
|
30593
30321
|
}
|
|
30594
30322
|
const optional2 = normalized.filter(
|
|
30595
|
-
(
|
|
30323
|
+
(option) => option.id !== permission.id && option.category !== permission.category && option.id !== "model" && option.category !== "model" && option.id !== "reasoning_effort" && option.category !== "thought_level"
|
|
30596
30324
|
);
|
|
30597
30325
|
return [permission, model, reasoningEffort, ...optional2].slice(0, MAXIMUM_CONFIG_OPTIONS);
|
|
30598
30326
|
}
|
|
30599
30327
|
function normalizeStandardLifecycle(response) {
|
|
30600
|
-
const lifecycle =
|
|
30328
|
+
const lifecycle = isRecord4(response) ? response : {};
|
|
30601
30329
|
return ensureReasoningEffortOption(normalizeConfigOptions(lifecycle["configOptions"], lifecycle["modes"]));
|
|
30602
30330
|
}
|
|
30603
30331
|
function replaceStandardConfigOptions(current, value) {
|
|
30604
30332
|
const next = normalizeConfigOptions(value, void 0);
|
|
30605
|
-
const withMode = next.some((
|
|
30333
|
+
const withMode = next.some((option) => option.category === "mode") ? next : [...current.filter((option) => option.category === "mode"), ...next].slice(0, 100);
|
|
30606
30334
|
return ensureReasoningEffortOption(withMode);
|
|
30607
30335
|
}
|
|
30608
30336
|
function updateCurrentValue(current, configId, value) {
|
|
30609
|
-
return current.map((
|
|
30337
|
+
return current.map((option) => option.id === configId ? { ...option, currentValue: value } : option);
|
|
30610
30338
|
}
|
|
30611
30339
|
var StandardSessionConfigProtocol = class {
|
|
30612
30340
|
configure = async (current, change, nativeSessionId, transport) => {
|
|
30613
|
-
const existing = current.find((
|
|
30341
|
+
const existing = current.find((option) => option.id === change.configId);
|
|
30614
30342
|
if (existing === void 0) {
|
|
30615
30343
|
return current;
|
|
30616
30344
|
}
|
|
@@ -30639,7 +30367,7 @@ var StandardSessionConfigProtocol = class {
|
|
|
30639
30367
|
"ACP agent exited while changing session configuration",
|
|
30640
30368
|
change.signal
|
|
30641
30369
|
);
|
|
30642
|
-
if (!
|
|
30370
|
+
if (!isRecord4(response) || !Array.isArray(response["configOptions"])) {
|
|
30643
30371
|
throw new SessionConfigProtocolError("The Agent returned an invalid session configuration response");
|
|
30644
30372
|
}
|
|
30645
30373
|
return replaceStandardConfigOptions(current, response["configOptions"]);
|
|
@@ -30653,31 +30381,31 @@ var standardSessionConfigProtocol = new StandardSessionConfigProtocol();
|
|
|
30653
30381
|
var LEGACY_MODEL_CONFIG_ID = "grok_build_legacy_model";
|
|
30654
30382
|
var LEGACY_REASONING_EFFORT_CONFIG_ID = "grok_build_legacy_reasoning_effort";
|
|
30655
30383
|
function legacyOptions(response) {
|
|
30656
|
-
if (!
|
|
30384
|
+
if (!isRecord4(response)) {
|
|
30657
30385
|
return [];
|
|
30658
30386
|
}
|
|
30659
30387
|
const metadata = response["_meta"];
|
|
30660
|
-
if (!
|
|
30388
|
+
if (!isRecord4(metadata)) {
|
|
30661
30389
|
return [];
|
|
30662
30390
|
}
|
|
30663
30391
|
const sessionConfig = metadata["x.ai/sessionConfig"];
|
|
30664
|
-
if (!
|
|
30392
|
+
if (!isRecord4(sessionConfig) || !Array.isArray(sessionConfig["options"])) {
|
|
30665
30393
|
return [];
|
|
30666
30394
|
}
|
|
30667
|
-
return sessionConfig["options"].slice(0, 500).filter(
|
|
30395
|
+
return sessionConfig["options"].slice(0, 500).filter(isRecord4);
|
|
30668
30396
|
}
|
|
30669
|
-
function legacyValue(
|
|
30670
|
-
const value = readString2(
|
|
30397
|
+
function legacyValue(option) {
|
|
30398
|
+
const value = readString2(option["id"]);
|
|
30671
30399
|
return {
|
|
30672
|
-
description: readString2(
|
|
30400
|
+
description: readString2(option["description"]).slice(0, 500),
|
|
30673
30401
|
groupId: "",
|
|
30674
30402
|
groupName: "",
|
|
30675
|
-
name: readString2(
|
|
30403
|
+
name: readString2(option["label"], value).slice(0, 255),
|
|
30676
30404
|
value: value.slice(0, 500)
|
|
30677
30405
|
};
|
|
30678
30406
|
}
|
|
30679
30407
|
function modelsRecord(response) {
|
|
30680
|
-
if (!
|
|
30408
|
+
if (!isRecord4(response) || !isRecord4(response["models"])) {
|
|
30681
30409
|
return {};
|
|
30682
30410
|
}
|
|
30683
30411
|
return response["models"];
|
|
@@ -30686,9 +30414,9 @@ function legacyModelOptions(response) {
|
|
|
30686
30414
|
const options = legacyOptions(response);
|
|
30687
30415
|
const models = modelsRecord(response);
|
|
30688
30416
|
const values = [];
|
|
30689
|
-
for (const
|
|
30690
|
-
if (
|
|
30691
|
-
const value = legacyValue(
|
|
30417
|
+
for (const option of options) {
|
|
30418
|
+
if (option["category"] === "model") {
|
|
30419
|
+
const value = legacyValue(option);
|
|
30692
30420
|
if (value.value.length > 0 && !values.some((existing) => existing.value === value.value)) {
|
|
30693
30421
|
values.push(value);
|
|
30694
30422
|
}
|
|
@@ -30696,7 +30424,7 @@ function legacyModelOptions(response) {
|
|
|
30696
30424
|
}
|
|
30697
30425
|
if (values.length === 0 && Array.isArray(models["availableModels"])) {
|
|
30698
30426
|
for (const model of models["availableModels"]) {
|
|
30699
|
-
if (!
|
|
30427
|
+
if (!isRecord4(model)) {
|
|
30700
30428
|
continue;
|
|
30701
30429
|
}
|
|
30702
30430
|
const value = readString2(model["modelId"]).slice(0, 500);
|
|
@@ -30714,7 +30442,7 @@ function legacyModelOptions(response) {
|
|
|
30714
30442
|
}
|
|
30715
30443
|
}
|
|
30716
30444
|
}
|
|
30717
|
-
const selected = options.find((
|
|
30445
|
+
const selected = options.find((option) => option["category"] === "model" && option["selected"] === true);
|
|
30718
30446
|
const currentValue = readString2(
|
|
30719
30447
|
models["currentModelId"],
|
|
30720
30448
|
selected === void 0 ? "" : readString2(selected["id"])
|
|
@@ -30737,11 +30465,11 @@ function legacyModelOptions(response) {
|
|
|
30737
30465
|
function legacyReasoningEffortOptions(response) {
|
|
30738
30466
|
const options = legacyOptions(response);
|
|
30739
30467
|
const values = [];
|
|
30740
|
-
for (const
|
|
30741
|
-
if (
|
|
30468
|
+
for (const option of options) {
|
|
30469
|
+
if (option["category"] !== "mode") {
|
|
30742
30470
|
continue;
|
|
30743
30471
|
}
|
|
30744
|
-
const value = legacyValue(
|
|
30472
|
+
const value = legacyValue(option);
|
|
30745
30473
|
if (value.value.length > 0 && !values.some((existing) => existing.value === value.value)) {
|
|
30746
30474
|
values.push(value);
|
|
30747
30475
|
}
|
|
@@ -30749,7 +30477,7 @@ function legacyReasoningEffortOptions(response) {
|
|
|
30749
30477
|
if (values.length === 0) {
|
|
30750
30478
|
return [];
|
|
30751
30479
|
}
|
|
30752
|
-
const selected = options.find((
|
|
30480
|
+
const selected = options.find((option) => option["category"] === "mode" && option["selected"] === true);
|
|
30753
30481
|
if (selected === void 0) {
|
|
30754
30482
|
values.unshift({
|
|
30755
30483
|
description: "Use the selected model's default reasoning effort",
|
|
@@ -30776,41 +30504,41 @@ function legacyReasoningEffortOptions(response) {
|
|
|
30776
30504
|
return [result];
|
|
30777
30505
|
}
|
|
30778
30506
|
function normalizeGrokLifecycle(response) {
|
|
30779
|
-
const lifecycle =
|
|
30507
|
+
const lifecycle = isRecord4(response) ? response : {};
|
|
30780
30508
|
const standard = normalizeConfigOptions(lifecycle["configOptions"], lifecycle["modes"]);
|
|
30781
30509
|
const normalized = [...standard];
|
|
30782
|
-
if (!normalized.some((
|
|
30510
|
+
if (!normalized.some((option) => option.category === "model")) {
|
|
30783
30511
|
normalized.push(...legacyModelOptions(response));
|
|
30784
30512
|
}
|
|
30785
|
-
if (!normalized.some((
|
|
30513
|
+
if (!normalized.some((option) => option.category === "thought_level")) {
|
|
30786
30514
|
const efforts = legacyReasoningEffortOptions(response);
|
|
30787
30515
|
if (efforts.length > 0) {
|
|
30788
|
-
const modelIndex = normalized.findIndex((
|
|
30516
|
+
const modelIndex = normalized.findIndex((option) => option.category === "model");
|
|
30789
30517
|
normalized.splice(modelIndex < 0 ? normalized.length : modelIndex + 1, 0, ...efforts);
|
|
30790
30518
|
}
|
|
30791
30519
|
}
|
|
30792
30520
|
return ensureReasoningEffortOption(normalized.slice(0, 100));
|
|
30793
30521
|
}
|
|
30794
30522
|
function updateCurrentValue2(current, category, value) {
|
|
30795
|
-
return current.map((
|
|
30523
|
+
return current.map((option) => option.category === category ? { ...option, currentValue: value } : option);
|
|
30796
30524
|
}
|
|
30797
30525
|
function validateGrokResponse(response, modelId) {
|
|
30798
|
-
if (!
|
|
30526
|
+
if (!isRecord4(response) || !isRecord4(response["_meta"])) {
|
|
30799
30527
|
throw new SessionConfigProtocolError("Grok Build returned an invalid session configuration response");
|
|
30800
30528
|
}
|
|
30801
30529
|
const model = response["_meta"]["model"];
|
|
30802
|
-
const appliedModel =
|
|
30530
|
+
const appliedModel = isRecord4(model) ? model["Ok"] : model;
|
|
30803
30531
|
if (appliedModel !== modelId) {
|
|
30804
30532
|
throw new SessionConfigProtocolError("Grok Build returned an invalid session configuration response");
|
|
30805
30533
|
}
|
|
30806
30534
|
}
|
|
30807
30535
|
var GrokBuildSessionConfigProtocol = class {
|
|
30808
30536
|
configure = async (current, change, nativeSessionId, transport) => {
|
|
30809
|
-
const existing = current.find((
|
|
30537
|
+
const existing = current.find((option) => option.id === change.configId);
|
|
30810
30538
|
if (existing === void 0 || existing.id !== LEGACY_MODEL_CONFIG_ID && existing.id !== LEGACY_REASONING_EFFORT_CONFIG_ID) {
|
|
30811
30539
|
return await standardSessionConfigProtocol.configure(current, change, nativeSessionId, transport);
|
|
30812
30540
|
}
|
|
30813
|
-
const model = current.find((
|
|
30541
|
+
const model = current.find((option) => option.category === "model");
|
|
30814
30542
|
if (model === void 0) {
|
|
30815
30543
|
return current;
|
|
30816
30544
|
}
|
|
@@ -30836,10 +30564,10 @@ var GrokBuildSessionConfigProtocol = class {
|
|
|
30836
30564
|
validateGrokResponse(response, modelId);
|
|
30837
30565
|
const updated = updateCurrentValue2(current, existing.category, change.value);
|
|
30838
30566
|
return existing.category === "thought_level" ? updated.map(
|
|
30839
|
-
(
|
|
30840
|
-
...
|
|
30841
|
-
values:
|
|
30842
|
-
} :
|
|
30567
|
+
(option) => option.category === "thought_level" ? {
|
|
30568
|
+
...option,
|
|
30569
|
+
values: option.values.filter((value) => value.value !== AGENT_DEFAULT_REASONING_EFFORT)
|
|
30570
|
+
} : option
|
|
30843
30571
|
) : updated;
|
|
30844
30572
|
};
|
|
30845
30573
|
normalizeLifecycle = (response) => normalizeGrokLifecycle(response);
|
|
@@ -31113,6 +30841,7 @@ var MAX_ACP_PROCESSES = 10;
|
|
|
31113
30841
|
var MAX_PRE_SESSION_UPDATES = 100;
|
|
31114
30842
|
var MAX_PRE_SESSION_UPDATE_BYTES = 1024 * 1024;
|
|
31115
30843
|
var SESSION_CONTROL_COMMAND_ID = "session-control";
|
|
30844
|
+
var SESSION_CONTROL_TIMEOUT_MILLISECONDS = 3e4;
|
|
31116
30845
|
var NullAcpSessionObserver = class {
|
|
31117
30846
|
importLocalArtifact = (_sessionId, _artifact, signal) => {
|
|
31118
30847
|
signal.throwIfAborted();
|
|
@@ -31331,7 +31060,7 @@ function createWritableAcpStream(output2) {
|
|
|
31331
31060
|
function truncate3(value, maximumLength) {
|
|
31332
31061
|
return value.length <= maximumLength ? value : `${value.slice(0, Math.max(0, maximumLength - 1))}\u2026`;
|
|
31333
31062
|
}
|
|
31334
|
-
function
|
|
31063
|
+
function isRecord5(value) {
|
|
31335
31064
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31336
31065
|
}
|
|
31337
31066
|
function readString4(value, fallback = "") {
|
|
@@ -31364,12 +31093,12 @@ function normalizeElicitationOptions(schema) {
|
|
|
31364
31093
|
const normalized = [];
|
|
31365
31094
|
const oneOf = schema["oneOf"];
|
|
31366
31095
|
if (Array.isArray(oneOf)) {
|
|
31367
|
-
for (const
|
|
31368
|
-
if (
|
|
31096
|
+
for (const option of oneOf) {
|
|
31097
|
+
if (isRecord5(option) && typeof option["const"] === "string") {
|
|
31369
31098
|
normalized.push({
|
|
31370
|
-
description: truncate3(readString4(
|
|
31371
|
-
label: truncate3(readString4(
|
|
31372
|
-
value: truncate3(
|
|
31099
|
+
description: truncate3(readString4(option["description"]), 500),
|
|
31100
|
+
label: truncate3(readString4(option["title"], option["const"]), 255),
|
|
31101
|
+
value: truncate3(option["const"], 500)
|
|
31373
31102
|
});
|
|
31374
31103
|
}
|
|
31375
31104
|
}
|
|
@@ -31385,7 +31114,7 @@ function normalizeElicitationOptions(schema) {
|
|
|
31385
31114
|
return normalized.slice(0, 200);
|
|
31386
31115
|
}
|
|
31387
31116
|
const items = schema["items"];
|
|
31388
|
-
if (!
|
|
31117
|
+
if (!isRecord5(items)) {
|
|
31389
31118
|
return normalized;
|
|
31390
31119
|
}
|
|
31391
31120
|
const anyOf = items["anyOf"];
|
|
@@ -31398,7 +31127,7 @@ function numericString(value) {
|
|
|
31398
31127
|
return typeof value === "number" && Number.isFinite(value) ? value.toString() : "";
|
|
31399
31128
|
}
|
|
31400
31129
|
function normalizeElicitationFields(requestedSchema) {
|
|
31401
|
-
if (!
|
|
31130
|
+
if (!isRecord5(requestedSchema) || !isRecord5(requestedSchema["properties"])) {
|
|
31402
31131
|
return [];
|
|
31403
31132
|
}
|
|
31404
31133
|
const properties2 = requestedSchema["properties"];
|
|
@@ -31408,7 +31137,7 @@ function normalizeElicitationFields(requestedSchema) {
|
|
|
31408
31137
|
);
|
|
31409
31138
|
const normalized = [];
|
|
31410
31139
|
for (const [name, property] of Object.entries(properties2)) {
|
|
31411
|
-
if (!
|
|
31140
|
+
if (!isRecord5(property)) {
|
|
31412
31141
|
continue;
|
|
31413
31142
|
}
|
|
31414
31143
|
const type = elicitationFieldType(property["type"]);
|
|
@@ -31499,7 +31228,7 @@ function validateElicitationContent(encoded, requestedSchema) {
|
|
|
31499
31228
|
"invalid_elicitation_response"
|
|
31500
31229
|
);
|
|
31501
31230
|
}
|
|
31502
|
-
if (!
|
|
31231
|
+
if (!isRecord5(decoded) || !isRecord5(requestedSchema) || !isRecord5(requestedSchema["properties"])) {
|
|
31503
31232
|
throw new AcpExecutionError(
|
|
31504
31233
|
"Elicitation response does not match the requested form",
|
|
31505
31234
|
{},
|
|
@@ -31519,7 +31248,7 @@ function validateElicitationContent(encoded, requestedSchema) {
|
|
|
31519
31248
|
const validated = {};
|
|
31520
31249
|
for (const [name, value] of Object.entries(decoded)) {
|
|
31521
31250
|
const property = properties2[name];
|
|
31522
|
-
if (!
|
|
31251
|
+
if (!isRecord5(property)) {
|
|
31523
31252
|
throw new AcpExecutionError(
|
|
31524
31253
|
`Elicitation field ${name} was not requested`,
|
|
31525
31254
|
{},
|
|
@@ -31556,7 +31285,7 @@ function validateElicitationContent(encoded, requestedSchema) {
|
|
|
31556
31285
|
);
|
|
31557
31286
|
}
|
|
31558
31287
|
const allowed = normalizeElicitationOptions(property);
|
|
31559
|
-
if (allowed.length > 0 && value.some((entry) => !allowed.some((
|
|
31288
|
+
if (allowed.length > 0 && value.some((entry) => !allowed.some((option) => option.value === entry))) {
|
|
31560
31289
|
throw new AcpExecutionError(
|
|
31561
31290
|
`Elicitation field ${name} contains an invalid selection`,
|
|
31562
31291
|
{},
|
|
@@ -31672,6 +31401,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
31672
31401
|
#permissionProfile;
|
|
31673
31402
|
#sessionConfigProtocol;
|
|
31674
31403
|
#store;
|
|
31404
|
+
#emittedToolImages = /* @__PURE__ */ new Set();
|
|
31675
31405
|
#verifiedAgentVersion;
|
|
31676
31406
|
#preSessionUpdateBytes = 0;
|
|
31677
31407
|
#agentName = "";
|
|
@@ -31892,19 +31622,19 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
31892
31622
|
}
|
|
31893
31623
|
};
|
|
31894
31624
|
prepareAgentContent = async (content3) => {
|
|
31895
|
-
if (content3.type === "image" && content3.
|
|
31896
|
-
const raster = readInlineRaster(content3.data, content3.name);
|
|
31897
|
-
if (raster !== null) {
|
|
31898
|
-
return await this.importRaster(raster, AbortSignal.timeout(2e4));
|
|
31899
|
-
}
|
|
31900
|
-
}
|
|
31901
|
-
if (content3.type === "image" && content3.data.length === 0 && content3.uri.length > 0) {
|
|
31625
|
+
if (content3.type === "image" && content3.uri.length > 0) {
|
|
31902
31626
|
const signal = AbortSignal.timeout(2e4);
|
|
31903
31627
|
const raster = await readLocalRaster(content3.uri, signal);
|
|
31904
31628
|
if (raster !== null) {
|
|
31905
31629
|
return await this.importRaster(raster, signal);
|
|
31906
31630
|
}
|
|
31907
31631
|
}
|
|
31632
|
+
if (content3.type === "image" && content3.data.length > 0) {
|
|
31633
|
+
const raster = readInlineRaster(content3.data, content3.name);
|
|
31634
|
+
if (raster !== null) {
|
|
31635
|
+
return await this.importRaster(raster, AbortSignal.timeout(2e4));
|
|
31636
|
+
}
|
|
31637
|
+
}
|
|
31908
31638
|
if (content3.type === "video" && content3.data.length > 0) {
|
|
31909
31639
|
const video = readInlineVideo(content3.data, content3.mimeType, content3.name);
|
|
31910
31640
|
if (video === null) {
|
|
@@ -31925,6 +31655,22 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
31925
31655
|
sessionId: this.#mobiusSessionId
|
|
31926
31656
|
});
|
|
31927
31657
|
};
|
|
31658
|
+
emitToolImages = async (update) => {
|
|
31659
|
+
if (update.status !== "completed") {
|
|
31660
|
+
return;
|
|
31661
|
+
}
|
|
31662
|
+
for (const [index2, item] of (update.content ?? []).entries()) {
|
|
31663
|
+
if (item.type !== "content" || item.content.type !== "image") {
|
|
31664
|
+
continue;
|
|
31665
|
+
}
|
|
31666
|
+
const key = `${update.toolCallId}:${index2.toString()}`;
|
|
31667
|
+
if (this.#emittedToolImages.has(key)) {
|
|
31668
|
+
continue;
|
|
31669
|
+
}
|
|
31670
|
+
this.#emittedToolImages.add(key);
|
|
31671
|
+
await this.emitAgentContent(normalizeContentBlock(item.content), `tool-${key}`);
|
|
31672
|
+
}
|
|
31673
|
+
};
|
|
31928
31674
|
emitRaster = async (raster, messageId, signal) => {
|
|
31929
31675
|
const content3 = await this.importRaster(raster, signal);
|
|
31930
31676
|
await this.#getObserver().onContent({
|
|
@@ -31936,14 +31682,14 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
31936
31682
|
sessionId: this.#mobiusSessionId
|
|
31937
31683
|
});
|
|
31938
31684
|
};
|
|
31939
|
-
importRaster = async (raster,
|
|
31940
|
-
|
|
31941
|
-
|
|
31942
|
-
|
|
31943
|
-
|
|
31944
|
-
|
|
31945
|
-
|
|
31946
|
-
);
|
|
31685
|
+
importRaster = async (raster, _signal) => {
|
|
31686
|
+
if (raster.sourceUri.length > 0) {
|
|
31687
|
+
return {
|
|
31688
|
+
...imageDisplayContent(raster.mimeType, raster.name, "", ""),
|
|
31689
|
+
uri: raster.sourceUri
|
|
31690
|
+
};
|
|
31691
|
+
}
|
|
31692
|
+
return imageDisplayContent(raster.mimeType, raster.name, await raster.base64(), "");
|
|
31947
31693
|
};
|
|
31948
31694
|
importVideo = async (video, signal) => {
|
|
31949
31695
|
const artifactId = await this.#getObserver().importLocalArtifact(this.#mobiusSessionId, video, signal);
|
|
@@ -32230,7 +31976,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
32230
31976
|
};
|
|
32231
31977
|
nativeSessionId = () => this.#nativeSessionId;
|
|
32232
31978
|
configure = async (options) => {
|
|
32233
|
-
const existing = this.#configOptions.find((
|
|
31979
|
+
const existing = this.#configOptions.find((option) => option.id === options.configId);
|
|
32234
31980
|
if (existing === void 0 || existing.type !== options.valueType) {
|
|
32235
31981
|
throw new AcpExecutionError(
|
|
32236
31982
|
"The requested ACP configuration option is unavailable",
|
|
@@ -32427,7 +32173,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
32427
32173
|
"ACP agent exited during steering",
|
|
32428
32174
|
options.signal
|
|
32429
32175
|
);
|
|
32430
|
-
if (!
|
|
32176
|
+
if (!isRecord5(response)) {
|
|
32431
32177
|
throw new AcpExecutionError(
|
|
32432
32178
|
"ACP agent returned an invalid steering response",
|
|
32433
32179
|
{},
|
|
@@ -32542,10 +32288,10 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
32542
32288
|
onPermission = async (request, signal) => {
|
|
32543
32289
|
this.assertNativeSession(request.sessionId);
|
|
32544
32290
|
const interactionId = `permission-${crypto.randomUUID()}`;
|
|
32545
|
-
const options = request.options.slice(0, 20).map((
|
|
32546
|
-
kind:
|
|
32547
|
-
name: truncate3(
|
|
32548
|
-
optionId: truncate3(
|
|
32291
|
+
const options = request.options.slice(0, 20).map((option) => ({
|
|
32292
|
+
kind: option.kind,
|
|
32293
|
+
name: truncate3(option.name, 255),
|
|
32294
|
+
optionId: truncate3(option.optionId, 255)
|
|
32549
32295
|
}));
|
|
32550
32296
|
if (options.length === 0) {
|
|
32551
32297
|
throw new AcpExecutionError(
|
|
@@ -32554,7 +32300,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
32554
32300
|
"invalid_agent_permission_request"
|
|
32555
32301
|
);
|
|
32556
32302
|
}
|
|
32557
|
-
const pending = new PendingPermission(interactionId, new Set(options.map((
|
|
32303
|
+
const pending = new PendingPermission(interactionId, new Set(options.map((option) => option.optionId)));
|
|
32558
32304
|
this.#pendingPermissions.set(interactionId, pending);
|
|
32559
32305
|
const abort = () => {
|
|
32560
32306
|
void this.cancelPermission(interactionId);
|
|
@@ -32723,6 +32469,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
32723
32469
|
}
|
|
32724
32470
|
if (update.sessionUpdate === "tool_call_update") {
|
|
32725
32471
|
await this.#turn.activities.recordToolCallUpdate(update);
|
|
32472
|
+
await this.emitToolImages(update);
|
|
32726
32473
|
return;
|
|
32727
32474
|
}
|
|
32728
32475
|
if (update.sessionUpdate === "plan") {
|
|
@@ -32762,7 +32509,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
32762
32509
|
}
|
|
32763
32510
|
if (update.sessionUpdate === "current_mode_update") {
|
|
32764
32511
|
this.#configOptions = this.#configOptions.map(
|
|
32765
|
-
(
|
|
32512
|
+
(option) => option.category === "mode" ? { ...option, currentValue: update.currentModeId } : option
|
|
32766
32513
|
);
|
|
32767
32514
|
this.#configRevision += 1;
|
|
32768
32515
|
await this.emitConfigUpdate();
|
|
@@ -33295,7 +33042,7 @@ var AcpSessionManager = class {
|
|
|
33295
33042
|
if (desired.id === PERMISSION_MODE_CONFIG_ID) {
|
|
33296
33043
|
continue;
|
|
33297
33044
|
}
|
|
33298
|
-
const current = runtime.prepared().configOptions.find((
|
|
33045
|
+
const current = runtime.prepared().configOptions.find((option) => option.id === desired.id);
|
|
33299
33046
|
if (current === void 0 || current.type !== desired.type) {
|
|
33300
33047
|
continue;
|
|
33301
33048
|
}
|
|
@@ -33401,7 +33148,7 @@ var AcpSessionManager = class {
|
|
|
33401
33148
|
async (runtime) => await runtime.close()
|
|
33402
33149
|
);
|
|
33403
33150
|
/**
|
|
33404
|
-
*
|
|
33151
|
+
* Retained for Agents that expose a separate persisted configuration channel.
|
|
33405
33152
|
* Use inspectAgentSettings for Agent-scoped settings discovery.
|
|
33406
33153
|
*/
|
|
33407
33154
|
inspectSession = async (options, metrics = unmeasuredOperationMetrics) => {
|
|
@@ -33563,7 +33310,7 @@ var AcpSessionManager = class {
|
|
|
33563
33310
|
() => deadlineController.abort(
|
|
33564
33311
|
new AcpExecutionError("The steering request exceeded its deadline", {}, "steering_timeout")
|
|
33565
33312
|
),
|
|
33566
|
-
|
|
33313
|
+
SESSION_CONTROL_TIMEOUT_MILLISECONDS
|
|
33567
33314
|
);
|
|
33568
33315
|
deadline.unref();
|
|
33569
33316
|
try {
|
|
@@ -33588,28 +33335,13 @@ var AcpSessionManager = class {
|
|
|
33588
33335
|
if (this.#activeSessionIds.has(options.sessionId)) {
|
|
33589
33336
|
throw new AcpExecutionError("Another prompt is already running in this conversation", {}, "session_busy");
|
|
33590
33337
|
}
|
|
33591
|
-
const deadlineController = new AbortController();
|
|
33592
|
-
const deadlineError = new AcpExecutionError(
|
|
33593
|
-
"The local Agent prompt exceeded its deadline",
|
|
33594
|
-
{},
|
|
33595
|
-
"prompt_timeout"
|
|
33596
|
-
);
|
|
33597
|
-
const deadline = setTimeout(
|
|
33598
|
-
() => deadlineController.abort(deadlineError),
|
|
33599
|
-
options.agent.promptTimeoutMilliseconds
|
|
33600
|
-
);
|
|
33601
|
-
deadline.unref();
|
|
33602
|
-
const boundedOptions = {
|
|
33603
|
-
...options,
|
|
33604
|
-
signal: AbortSignal.any([options.signal, deadlineController.signal])
|
|
33605
|
-
};
|
|
33606
33338
|
this.#activeSessionIds.add(options.sessionId);
|
|
33607
33339
|
this.#activeCommandIds.set(options.sessionId, options.commandId);
|
|
33608
33340
|
try {
|
|
33609
33341
|
if (this.#cancellationRequests.has(options.sessionId)) {
|
|
33610
33342
|
return { stopReason: "cancelled" };
|
|
33611
33343
|
}
|
|
33612
|
-
const runtime = await this.ensureSession(
|
|
33344
|
+
const runtime = await this.ensureSession(options);
|
|
33613
33345
|
if (this.#nativeOperations.has(`${options.agent.id}:${runtime.nativeSessionId()}`)) {
|
|
33614
33346
|
throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
|
|
33615
33347
|
}
|
|
@@ -33617,7 +33349,7 @@ var AcpSessionManager = class {
|
|
|
33617
33349
|
return { stopReason: "cancelled" };
|
|
33618
33350
|
}
|
|
33619
33351
|
try {
|
|
33620
|
-
const result = await runtime.prompt(
|
|
33352
|
+
const result = await runtime.prompt(options);
|
|
33621
33353
|
return this.#cancellationRequests.has(options.sessionId) ? { stopReason: "cancelled" } : result;
|
|
33622
33354
|
} catch (error62) {
|
|
33623
33355
|
if (this.#cancellationRequests.has(options.sessionId)) {
|
|
@@ -33645,7 +33377,6 @@ var AcpSessionManager = class {
|
|
|
33645
33377
|
cause: error62
|
|
33646
33378
|
});
|
|
33647
33379
|
} finally {
|
|
33648
|
-
clearTimeout(deadline);
|
|
33649
33380
|
try {
|
|
33650
33381
|
await this.#cancellationRequests.get(options.sessionId);
|
|
33651
33382
|
} finally {
|
|
@@ -34037,573 +33768,12 @@ var LocalAuthorizationError = class extends Error {
|
|
|
34037
33768
|
}
|
|
34038
33769
|
};
|
|
34039
33770
|
|
|
34040
|
-
// src/bots/bot-execution-context.ts
|
|
34041
|
-
import { randomBytes } from "node:crypto";
|
|
34042
|
-
|
|
34043
|
-
// src/bots/local-bot-execution-authorizer.ts
|
|
34044
|
-
var LocalBotAuthorizationError = class extends Error {
|
|
34045
|
-
code;
|
|
34046
|
-
constructor(code, message, options = {}) {
|
|
34047
|
-
super(message, options);
|
|
34048
|
-
this.code = code;
|
|
34049
|
-
this.name = "LocalBotAuthorizationError";
|
|
34050
|
-
}
|
|
34051
|
-
};
|
|
34052
|
-
var AuthorizedLocalBotExecution = class {
|
|
34053
|
-
agent;
|
|
34054
|
-
behaviorDigest;
|
|
34055
|
-
behaviorRevisionId;
|
|
34056
|
-
bindingId;
|
|
34057
|
-
bindingRevision;
|
|
34058
|
-
botId;
|
|
34059
|
-
executionConfiguration;
|
|
34060
|
-
workspacePath;
|
|
34061
|
-
workspaceRef;
|
|
34062
|
-
constructor(command, agent, workspacePath) {
|
|
34063
|
-
this.agent = agent;
|
|
34064
|
-
this.behaviorDigest = command.behaviorDigest;
|
|
34065
|
-
this.behaviorRevisionId = command.behaviorRevisionId;
|
|
34066
|
-
this.bindingId = command.bindingId;
|
|
34067
|
-
this.bindingRevision = command.bindingRevision;
|
|
34068
|
-
this.botId = command.botId;
|
|
34069
|
-
this.executionConfiguration = command.executionConfiguration;
|
|
34070
|
-
this.workspacePath = workspacePath;
|
|
34071
|
-
this.workspaceRef = command.directoryId;
|
|
34072
|
-
}
|
|
34073
|
-
};
|
|
34074
|
-
var LocalBotExecutionAuthorizer = class {
|
|
34075
|
-
authorize = async (command, catalog, directories, bindingAuthorityId, signal) => {
|
|
34076
|
-
signal.throwIfAborted();
|
|
34077
|
-
let agent;
|
|
34078
|
-
try {
|
|
34079
|
-
agent = catalog.find(command.agentId).withPermissionMode(command.executionConfiguration.permissionMode);
|
|
34080
|
-
} catch (cause) {
|
|
34081
|
-
if (cause instanceof AgentPermissionConfigurationError) {
|
|
34082
|
-
throw new LocalBotAuthorizationError("binding_incompatible", cause.message, { cause });
|
|
34083
|
-
}
|
|
34084
|
-
throw cause;
|
|
34085
|
-
}
|
|
34086
|
-
const [adapterUnchanged, agentUnchanged] = await Promise.all([
|
|
34087
|
-
revalidateExecutable(agent.adapterIdentity),
|
|
34088
|
-
revalidateExecutable(agent.agentIdentity)
|
|
34089
|
-
]);
|
|
34090
|
-
signal.throwIfAborted();
|
|
34091
|
-
if (!adapterUnchanged || !agentUnchanged) {
|
|
34092
|
-
throw new LocalBotAuthorizationError(
|
|
34093
|
-
"binding_incompatible",
|
|
34094
|
-
"The local Agent executable changed while the Runtime is active; restart the Runtime"
|
|
34095
|
-
);
|
|
34096
|
-
}
|
|
34097
|
-
if (command.behaviorInstructions.length > 0 && !agent.capabilities.embeddedContextPrompt) {
|
|
34098
|
-
throw new LocalBotAuthorizationError(
|
|
34099
|
-
"binding_incompatible",
|
|
34100
|
-
"The local Agent cannot apply the Bot behavior"
|
|
34101
|
-
);
|
|
34102
|
-
}
|
|
34103
|
-
const workspacePath = await directories.resolve(bindingAuthorityId, command.directoryId, signal);
|
|
34104
|
-
signal.throwIfAborted();
|
|
34105
|
-
return new AuthorizedLocalBotExecution(command, agent, workspacePath);
|
|
34106
|
-
};
|
|
34107
|
-
};
|
|
34108
|
-
|
|
34109
|
-
// src/bots/bot-execution-context.ts
|
|
34110
|
-
var ActiveBotExecutionContext = class {
|
|
34111
|
-
command;
|
|
34112
|
-
contextHandle;
|
|
34113
|
-
constructor(contextHandle, command) {
|
|
34114
|
-
this.contextHandle = contextHandle;
|
|
34115
|
-
this.command = command;
|
|
34116
|
-
}
|
|
34117
|
-
resolveTarget = (target) => {
|
|
34118
|
-
if (target === "current") {
|
|
34119
|
-
if (!(this.command.replyRoute instanceof BotConnectionReplyRoute)) {
|
|
34120
|
-
throw new LocalBotAuthorizationError(
|
|
34121
|
-
"delivery_target_not_allowed",
|
|
34122
|
-
"This Bot conversation has no external reply target"
|
|
34123
|
-
);
|
|
34124
|
-
}
|
|
34125
|
-
return this.command.replyRoute.deliveryTargetId;
|
|
34126
|
-
}
|
|
34127
|
-
const resolved = this.command.allowedDeliveryTargets.find((candidate) => candidate.alias === target);
|
|
34128
|
-
if (resolved === void 0) {
|
|
34129
|
-
throw new LocalBotAuthorizationError(
|
|
34130
|
-
"delivery_target_not_allowed",
|
|
34131
|
-
"The named Bot delivery target is not approved"
|
|
34132
|
-
);
|
|
34133
|
-
}
|
|
34134
|
-
return resolved.deliveryTargetId;
|
|
34135
|
-
};
|
|
34136
|
-
};
|
|
34137
|
-
var BotExecutionContextLease = class {
|
|
34138
|
-
context;
|
|
34139
|
-
#release;
|
|
34140
|
-
#released = false;
|
|
34141
|
-
constructor(context, release) {
|
|
34142
|
-
this.context = context;
|
|
34143
|
-
this.#release = release;
|
|
34144
|
-
}
|
|
34145
|
-
release = () => {
|
|
34146
|
-
if (this.#released) {
|
|
34147
|
-
return;
|
|
34148
|
-
}
|
|
34149
|
-
this.#released = true;
|
|
34150
|
-
this.#release();
|
|
34151
|
-
};
|
|
34152
|
-
};
|
|
34153
|
-
var BotExecutionContextRegistry = class {
|
|
34154
|
-
#activeByHandle = /* @__PURE__ */ new Map();
|
|
34155
|
-
#handlesBySession = /* @__PURE__ */ new Map();
|
|
34156
|
-
#inactiveHandles = /* @__PURE__ */ new Set();
|
|
34157
|
-
#now;
|
|
34158
|
-
constructor(now = Date.now) {
|
|
34159
|
-
this.#now = now;
|
|
34160
|
-
}
|
|
34161
|
-
activate = (command) => {
|
|
34162
|
-
let handle = this.#handlesBySession.get(command.sessionId);
|
|
34163
|
-
if (handle === void 0) {
|
|
34164
|
-
handle = `ctx_${Buffer.from(randomBytes(32)).toString("base64url")}`;
|
|
34165
|
-
this.#handlesBySession.set(command.sessionId, handle);
|
|
34166
|
-
}
|
|
34167
|
-
if (this.#activeByHandle.has(handle)) {
|
|
34168
|
-
throw new LocalBotAuthorizationError("session_busy", "The Bot execution context is already active");
|
|
34169
|
-
}
|
|
34170
|
-
const context = new ActiveBotExecutionContext(handle, command);
|
|
34171
|
-
this.#inactiveHandles.delete(handle);
|
|
34172
|
-
this.#activeByHandle.set(handle, context);
|
|
34173
|
-
return new BotExecutionContextLease(context, () => {
|
|
34174
|
-
if (this.#activeByHandle.get(handle) === context) {
|
|
34175
|
-
this.#activeByHandle.delete(handle);
|
|
34176
|
-
this.#inactiveHandles.add(handle);
|
|
34177
|
-
}
|
|
34178
|
-
});
|
|
34179
|
-
};
|
|
34180
|
-
read = (handle) => {
|
|
34181
|
-
const context = this.#activeByHandle.get(handle);
|
|
34182
|
-
if (context === void 0) {
|
|
34183
|
-
if (this.#inactiveHandles.has(handle)) {
|
|
34184
|
-
throw new LocalBotAuthorizationError(
|
|
34185
|
-
"execution_capability_expired",
|
|
34186
|
-
"The Bot execution capability has expired"
|
|
34187
|
-
);
|
|
34188
|
-
}
|
|
34189
|
-
throw new LocalBotAuthorizationError(
|
|
34190
|
-
"execution_context_required",
|
|
34191
|
-
"An active Bot execution context is required"
|
|
34192
|
-
);
|
|
34193
|
-
}
|
|
34194
|
-
if (Date.parse(context.command.executionDeadlineAt) <= this.#now()) {
|
|
34195
|
-
throw new LocalBotAuthorizationError(
|
|
34196
|
-
"execution_capability_expired",
|
|
34197
|
-
"The Bot execution capability has expired"
|
|
34198
|
-
);
|
|
34199
|
-
}
|
|
34200
|
-
return context;
|
|
34201
|
-
};
|
|
34202
|
-
};
|
|
34203
|
-
|
|
34204
|
-
// src/bots/bot-message-command.ts
|
|
34205
|
-
import { randomUUID } from "node:crypto";
|
|
34206
|
-
import { createConnection } from "node:net";
|
|
34207
|
-
var BOT_IPC_RESPONSE_LIMIT = 64 * 1024;
|
|
34208
|
-
var BOT_IPC_TIMEOUT_MILLISECONDS = 2e4;
|
|
34209
|
-
var BotMessageCommandError = class extends Error {
|
|
34210
|
-
code;
|
|
34211
|
-
constructor(code, message, options = {}) {
|
|
34212
|
-
super(message, options);
|
|
34213
|
-
this.code = code;
|
|
34214
|
-
this.name = "BotMessageCommandError";
|
|
34215
|
-
}
|
|
34216
|
-
};
|
|
34217
|
-
function isRecord7(value) {
|
|
34218
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
34219
|
-
}
|
|
34220
|
-
function requiredEnvironment(environment, name) {
|
|
34221
|
-
const value = environment[name]?.trim();
|
|
34222
|
-
if (value === void 0 || value.length === 0) {
|
|
34223
|
-
throw new BotMessageCommandError(
|
|
34224
|
-
"execution_context_required",
|
|
34225
|
-
"This command is available only inside an active Mobius Bot execution"
|
|
34226
|
-
);
|
|
34227
|
-
}
|
|
34228
|
-
return value;
|
|
34229
|
-
}
|
|
34230
|
-
function option(arguments_, name) {
|
|
34231
|
-
const index2 = arguments_.indexOf(name);
|
|
34232
|
-
if (index2 < 0 || index2 + 1 >= arguments_.length || arguments_[index2 + 1]?.startsWith("--") === true) {
|
|
34233
|
-
throw new BotMessageCommandError(
|
|
34234
|
-
"invalid_request",
|
|
34235
|
-
"Usage: mobius bot message send --target <current|alias> --text <message>"
|
|
34236
|
-
);
|
|
34237
|
-
}
|
|
34238
|
-
const value = arguments_[index2 + 1];
|
|
34239
|
-
if (value === void 0) {
|
|
34240
|
-
throw new BotMessageCommandError("invalid_request", "The Bot message option is missing");
|
|
34241
|
-
}
|
|
34242
|
-
return value;
|
|
34243
|
-
}
|
|
34244
|
-
function validateArguments(arguments_) {
|
|
34245
|
-
if (arguments_.length !== 4) {
|
|
34246
|
-
throw new BotMessageCommandError(
|
|
34247
|
-
"invalid_request",
|
|
34248
|
-
"Usage: mobius bot message send --target <current|alias> --text <message>"
|
|
34249
|
-
);
|
|
34250
|
-
}
|
|
34251
|
-
const names = [arguments_[0], arguments_[2]];
|
|
34252
|
-
if (!names.includes("--target") || !names.includes("--text") || names[0] === names[1]) {
|
|
34253
|
-
throw new BotMessageCommandError(
|
|
34254
|
-
"invalid_request",
|
|
34255
|
-
"Usage: mobius bot message send --target <current|alias> --text <message>"
|
|
34256
|
-
);
|
|
34257
|
-
}
|
|
34258
|
-
}
|
|
34259
|
-
function decodeResponse(encoded) {
|
|
34260
|
-
let value;
|
|
34261
|
-
try {
|
|
34262
|
-
value = JSON.parse(encoded);
|
|
34263
|
-
} catch (cause) {
|
|
34264
|
-
throw new BotMessageCommandError("bot_service_unavailable", "The local Bot service returned invalid data", {
|
|
34265
|
-
cause
|
|
34266
|
-
});
|
|
34267
|
-
}
|
|
34268
|
-
if (!isRecord7(value) || typeof value["ok"] !== "boolean") {
|
|
34269
|
-
throw new BotMessageCommandError("bot_service_unavailable", "The local Bot service returned invalid data");
|
|
34270
|
-
}
|
|
34271
|
-
if (value["ok"] === true && typeof value["outboundMessageId"] === "string") {
|
|
34272
|
-
return value["outboundMessageId"];
|
|
34273
|
-
}
|
|
34274
|
-
const error62 = value["error"];
|
|
34275
|
-
if (value["ok"] === false && isRecord7(error62) && typeof error62["code"] === "string" && typeof error62["message"] === "string") {
|
|
34276
|
-
throw new BotMessageCommandError(error62["code"], error62["message"]);
|
|
34277
|
-
}
|
|
34278
|
-
throw new BotMessageCommandError("bot_service_unavailable", "The local Bot service returned invalid data");
|
|
34279
|
-
}
|
|
34280
|
-
async function requestLocalBotService(socketPath, payload, signal) {
|
|
34281
|
-
signal.throwIfAborted();
|
|
34282
|
-
return await new Promise((resolve6, reject) => {
|
|
34283
|
-
const socket = createConnection(socketPath);
|
|
34284
|
-
const chunks = [];
|
|
34285
|
-
let length = 0;
|
|
34286
|
-
let finished = false;
|
|
34287
|
-
const finish = () => {
|
|
34288
|
-
socket.removeAllListeners();
|
|
34289
|
-
socket.destroy();
|
|
34290
|
-
};
|
|
34291
|
-
const fail = (error62) => {
|
|
34292
|
-
if (finished) {
|
|
34293
|
-
return;
|
|
34294
|
-
}
|
|
34295
|
-
finished = true;
|
|
34296
|
-
finish();
|
|
34297
|
-
if (error62 instanceof BotMessageCommandError) {
|
|
34298
|
-
reject(error62);
|
|
34299
|
-
return;
|
|
34300
|
-
}
|
|
34301
|
-
reject(
|
|
34302
|
-
new BotMessageCommandError(
|
|
34303
|
-
"execution_context_required",
|
|
34304
|
-
"The active Mobius Bot execution is unavailable",
|
|
34305
|
-
{ cause: error62 }
|
|
34306
|
-
)
|
|
34307
|
-
);
|
|
34308
|
-
};
|
|
34309
|
-
const abort = () => fail(signal.reason);
|
|
34310
|
-
socket.setTimeout(BOT_IPC_TIMEOUT_MILLISECONDS, () => {
|
|
34311
|
-
fail(new BotMessageCommandError("bot_service_unavailable", "The local Bot service timed out"));
|
|
34312
|
-
});
|
|
34313
|
-
socket.once("error", fail);
|
|
34314
|
-
socket.once("connect", () => socket.end(`${payload}
|
|
34315
|
-
`));
|
|
34316
|
-
socket.on("data", (chunk) => {
|
|
34317
|
-
length += chunk.byteLength;
|
|
34318
|
-
if (length > BOT_IPC_RESPONSE_LIMIT) {
|
|
34319
|
-
fail(new BotMessageCommandError("bot_service_unavailable", "The local Bot response is too large"));
|
|
34320
|
-
return;
|
|
34321
|
-
}
|
|
34322
|
-
chunks.push(chunk);
|
|
34323
|
-
});
|
|
34324
|
-
socket.once("end", () => {
|
|
34325
|
-
if (finished) {
|
|
34326
|
-
return;
|
|
34327
|
-
}
|
|
34328
|
-
finished = true;
|
|
34329
|
-
signal.removeEventListener("abort", abort);
|
|
34330
|
-
try {
|
|
34331
|
-
resolve6(decodeResponse(Buffer.concat(chunks).toString("utf8")));
|
|
34332
|
-
} catch (error62) {
|
|
34333
|
-
reject(error62);
|
|
34334
|
-
} finally {
|
|
34335
|
-
finish();
|
|
34336
|
-
}
|
|
34337
|
-
});
|
|
34338
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
34339
|
-
});
|
|
34340
|
-
}
|
|
34341
|
-
async function executeBotMessageCommand(arguments_, environment, signal) {
|
|
34342
|
-
validateArguments(arguments_);
|
|
34343
|
-
const contextHandle = requiredEnvironment(environment, "MOBIUS_BOT_CONTEXT");
|
|
34344
|
-
const socketPath = requiredEnvironment(environment, "MOBIUS_BOT_SOCKET");
|
|
34345
|
-
const target = option(arguments_, "--target");
|
|
34346
|
-
const text3 = option(arguments_, "--text");
|
|
34347
|
-
if (!/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/.test(target) || text3.trim().length === 0 || text3.length > 1e4) {
|
|
34348
|
-
throw new BotMessageCommandError("invalid_request", "The Bot outbound message is invalid");
|
|
34349
|
-
}
|
|
34350
|
-
return await requestLocalBotService(
|
|
34351
|
-
socketPath,
|
|
34352
|
-
JSON.stringify({
|
|
34353
|
-
contextHandle,
|
|
34354
|
-
idempotencyKey: `cli_${randomUUID()}`,
|
|
34355
|
-
target,
|
|
34356
|
-
text: text3
|
|
34357
|
-
}),
|
|
34358
|
-
signal
|
|
34359
|
-
);
|
|
34360
|
-
}
|
|
34361
|
-
|
|
34362
|
-
// src/bots/bot-outbound-ipc.ts
|
|
34363
|
-
import { chmod, mkdir, unlink } from "node:fs/promises";
|
|
34364
|
-
import { createServer } from "node:net";
|
|
34365
|
-
import { dirname as dirname3, isAbsolute as isAbsolute2 } from "node:path";
|
|
34366
|
-
import { fetch } from "undici";
|
|
34367
|
-
var BOT_IPC_REQUEST_LIMIT = 32 * 1024;
|
|
34368
|
-
var BOT_IPC_TIMEOUT_MILLISECONDS2 = 2e4;
|
|
34369
|
-
var BOT_RELAY_TIMEOUT_MILLISECONDS = 2e4;
|
|
34370
|
-
var IDENTIFIER_PATTERN5 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
34371
|
-
var WINDOWS_NAMED_PIPE_PREFIX = "\\\\.\\pipe\\";
|
|
34372
|
-
var BotOutboundIpcRequest = class {
|
|
34373
|
-
contextHandle;
|
|
34374
|
-
idempotencyKey;
|
|
34375
|
-
target;
|
|
34376
|
-
text;
|
|
34377
|
-
constructor(contextHandle, idempotencyKey, target, text3) {
|
|
34378
|
-
this.contextHandle = contextHandle;
|
|
34379
|
-
this.idempotencyKey = idempotencyKey;
|
|
34380
|
-
this.target = target;
|
|
34381
|
-
this.text = text3;
|
|
34382
|
-
}
|
|
34383
|
-
};
|
|
34384
|
-
function isRecord8(value) {
|
|
34385
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
34386
|
-
}
|
|
34387
|
-
function decodeRequest(encoded) {
|
|
34388
|
-
let value;
|
|
34389
|
-
try {
|
|
34390
|
-
value = JSON.parse(encoded);
|
|
34391
|
-
} catch (cause) {
|
|
34392
|
-
throw new LocalBotAuthorizationError("invalid_request", "The local Bot request is invalid", { cause });
|
|
34393
|
-
}
|
|
34394
|
-
if (!isRecord8(value)) {
|
|
34395
|
-
throw new LocalBotAuthorizationError("invalid_request", "The local Bot request is invalid");
|
|
34396
|
-
}
|
|
34397
|
-
const keys = Object.keys(value);
|
|
34398
|
-
if (keys.length !== 4 || !keys.every((key) => ["contextHandle", "idempotencyKey", "target", "text"].includes(key))) {
|
|
34399
|
-
throw new LocalBotAuthorizationError("invalid_request", "The local Bot request fields are invalid");
|
|
34400
|
-
}
|
|
34401
|
-
const contextHandle = value["contextHandle"];
|
|
34402
|
-
const idempotencyKey = value["idempotencyKey"];
|
|
34403
|
-
const target = value["target"];
|
|
34404
|
-
const text3 = value["text"];
|
|
34405
|
-
if (typeof contextHandle !== "string" || !/^ctx_[a-zA-Z0-9_-]{43}$/.test(contextHandle) || typeof idempotencyKey !== "string" || !IDENTIFIER_PATTERN5.test(idempotencyKey) || typeof target !== "string" || !IDENTIFIER_PATTERN5.test(target) || typeof text3 !== "string" || text3.trim().length === 0 || text3.length > 1e4) {
|
|
34406
|
-
throw new LocalBotAuthorizationError("invalid_request", "The local Bot request is invalid");
|
|
34407
|
-
}
|
|
34408
|
-
return new BotOutboundIpcRequest(contextHandle, idempotencyKey, target, text3);
|
|
34409
|
-
}
|
|
34410
|
-
function relayEndpoint(relayUrl, context, target) {
|
|
34411
|
-
const endpoint = new URL(relayUrl);
|
|
34412
|
-
if (endpoint.protocol !== "ws:" && endpoint.protocol !== "wss:") {
|
|
34413
|
-
throw new LocalBotAuthorizationError("bot_service_unavailable", "The Mobius Relay URL is invalid");
|
|
34414
|
-
}
|
|
34415
|
-
endpoint.protocol = endpoint.protocol === "wss:" ? "https:" : "http:";
|
|
34416
|
-
endpoint.search = "";
|
|
34417
|
-
const execution = encodeURIComponent(context.command.executionId);
|
|
34418
|
-
if (target === "current") {
|
|
34419
|
-
context.resolveTarget(target);
|
|
34420
|
-
endpoint.pathname = `${MOBIUS_API_PREFIX}/v1/bot-executions/${execution}/reply-messages`;
|
|
34421
|
-
return endpoint;
|
|
34422
|
-
}
|
|
34423
|
-
const deliveryTargetId = context.resolveTarget(target);
|
|
34424
|
-
endpoint.pathname = `${MOBIUS_API_PREFIX}/v1/bot-executions/${execution}/delivery-targets/${encodeURIComponent(deliveryTargetId)}/messages`;
|
|
34425
|
-
return endpoint;
|
|
34426
|
-
}
|
|
34427
|
-
function daemonToken(relayUrl) {
|
|
34428
|
-
const token = relayUrl.searchParams.get("token") ?? "";
|
|
34429
|
-
if (!/^[a-zA-Z0-9_-]{32,256}$/.test(token)) {
|
|
34430
|
-
throw new LocalBotAuthorizationError("bot_service_unavailable", "The Runtime credential is unavailable");
|
|
34431
|
-
}
|
|
34432
|
-
return token;
|
|
34433
|
-
}
|
|
34434
|
-
async function decodeRelayResponse(response) {
|
|
34435
|
-
const encoded = await response.text();
|
|
34436
|
-
let value;
|
|
34437
|
-
try {
|
|
34438
|
-
value = JSON.parse(encoded);
|
|
34439
|
-
} catch (cause) {
|
|
34440
|
-
throw new LocalBotAuthorizationError("bot_service_unavailable", "The Mobius Relay returned invalid data", {
|
|
34441
|
-
cause
|
|
34442
|
-
});
|
|
34443
|
-
}
|
|
34444
|
-
if (response.status === 202 && isRecord8(value) && typeof value["outboundMessageId"] === "string") {
|
|
34445
|
-
return value["outboundMessageId"];
|
|
34446
|
-
}
|
|
34447
|
-
if (isRecord8(value) && isRecord8(value["error"])) {
|
|
34448
|
-
const error62 = value["error"];
|
|
34449
|
-
if (typeof error62["code"] === "string" && typeof error62["message"] === "string") {
|
|
34450
|
-
throw new LocalBotAuthorizationError(error62["code"], error62["message"]);
|
|
34451
|
-
}
|
|
34452
|
-
}
|
|
34453
|
-
throw new LocalBotAuthorizationError("bot_service_unavailable", "The Mobius Relay rejected the Bot action");
|
|
34454
|
-
}
|
|
34455
|
-
var BotOutboundIpcServer = class {
|
|
34456
|
-
#registry;
|
|
34457
|
-
#relayUrl;
|
|
34458
|
-
#server;
|
|
34459
|
-
#socketPath;
|
|
34460
|
-
#usesFilesystemSocket;
|
|
34461
|
-
constructor(socketPath, relayUrl, registry2) {
|
|
34462
|
-
const usesFilesystemSocket = !socketPath.startsWith(WINDOWS_NAMED_PIPE_PREFIX);
|
|
34463
|
-
if (usesFilesystemSocket && !isAbsolute2(socketPath)) {
|
|
34464
|
-
throw new Error("The Bot IPC path must be absolute");
|
|
34465
|
-
}
|
|
34466
|
-
this.#registry = registry2;
|
|
34467
|
-
this.#relayUrl = new URL(relayUrl);
|
|
34468
|
-
this.#server = createServer({ allowHalfOpen: true }, (socket) => this.accept(socket));
|
|
34469
|
-
this.#socketPath = socketPath;
|
|
34470
|
-
this.#usesFilesystemSocket = usesFilesystemSocket;
|
|
34471
|
-
}
|
|
34472
|
-
get socketPath() {
|
|
34473
|
-
return this.#socketPath;
|
|
34474
|
-
}
|
|
34475
|
-
listen = async (signal) => {
|
|
34476
|
-
signal.throwIfAborted();
|
|
34477
|
-
if (this.#usesFilesystemSocket) {
|
|
34478
|
-
await mkdir(dirname3(this.#socketPath), { mode: 448, recursive: true });
|
|
34479
|
-
await unlink(this.#socketPath).catch((error62) => {
|
|
34480
|
-
if (!isRecord8(error62) || error62["code"] !== "ENOENT") {
|
|
34481
|
-
throw error62;
|
|
34482
|
-
}
|
|
34483
|
-
});
|
|
34484
|
-
}
|
|
34485
|
-
await new Promise((resolve6, reject) => {
|
|
34486
|
-
const fail = (error62) => reject(error62);
|
|
34487
|
-
this.#server.once("error", fail);
|
|
34488
|
-
this.#server.listen(this.#socketPath, () => {
|
|
34489
|
-
this.#server.removeListener("error", fail);
|
|
34490
|
-
resolve6();
|
|
34491
|
-
});
|
|
34492
|
-
});
|
|
34493
|
-
if (this.#usesFilesystemSocket) {
|
|
34494
|
-
await chmod(this.#socketPath, 384);
|
|
34495
|
-
}
|
|
34496
|
-
signal.addEventListener("abort", this.abort, { once: true });
|
|
34497
|
-
if (signal.aborted) {
|
|
34498
|
-
this.abort();
|
|
34499
|
-
}
|
|
34500
|
-
};
|
|
34501
|
-
close = async () => {
|
|
34502
|
-
if (this.#server.listening) {
|
|
34503
|
-
await new Promise((resolve6, reject) => {
|
|
34504
|
-
this.#server.close((error62) => {
|
|
34505
|
-
if (error62 === void 0) {
|
|
34506
|
-
resolve6();
|
|
34507
|
-
return;
|
|
34508
|
-
}
|
|
34509
|
-
reject(error62);
|
|
34510
|
-
});
|
|
34511
|
-
});
|
|
34512
|
-
}
|
|
34513
|
-
if (this.#usesFilesystemSocket) {
|
|
34514
|
-
await unlink(this.#socketPath).catch((error62) => {
|
|
34515
|
-
if (!isRecord8(error62) || error62["code"] !== "ENOENT") {
|
|
34516
|
-
throw error62;
|
|
34517
|
-
}
|
|
34518
|
-
});
|
|
34519
|
-
}
|
|
34520
|
-
};
|
|
34521
|
-
#abort = () => {
|
|
34522
|
-
this.#server.close();
|
|
34523
|
-
};
|
|
34524
|
-
abort = () => this.#abort();
|
|
34525
|
-
accept = (socket) => {
|
|
34526
|
-
const chunks = [];
|
|
34527
|
-
let length = 0;
|
|
34528
|
-
let rejected = false;
|
|
34529
|
-
const controller = new AbortController();
|
|
34530
|
-
socket.setTimeout(BOT_IPC_TIMEOUT_MILLISECONDS2, () => {
|
|
34531
|
-
controller.abort(new Error("Bot IPC request timed out"));
|
|
34532
|
-
socket.destroy();
|
|
34533
|
-
});
|
|
34534
|
-
socket.on("data", (chunk) => {
|
|
34535
|
-
length += chunk.byteLength;
|
|
34536
|
-
if (length > BOT_IPC_REQUEST_LIMIT) {
|
|
34537
|
-
rejected = true;
|
|
34538
|
-
controller.abort(new Error("Bot IPC request is too large"));
|
|
34539
|
-
socket.end(
|
|
34540
|
-
JSON.stringify({
|
|
34541
|
-
error: { code: "invalid_request", message: "The local Bot request is too large" },
|
|
34542
|
-
ok: false
|
|
34543
|
-
})
|
|
34544
|
-
);
|
|
34545
|
-
return;
|
|
34546
|
-
}
|
|
34547
|
-
chunks.push(chunk);
|
|
34548
|
-
});
|
|
34549
|
-
socket.once("error", () => controller.abort());
|
|
34550
|
-
socket.once("close", () => controller.abort());
|
|
34551
|
-
socket.once("end", () => {
|
|
34552
|
-
if (rejected) {
|
|
34553
|
-
return;
|
|
34554
|
-
}
|
|
34555
|
-
void this.handle(Buffer.concat(chunks).toString("utf8").trim(), controller.signal).then(
|
|
34556
|
-
(outboundMessageId) => {
|
|
34557
|
-
if (!socket.destroyed) {
|
|
34558
|
-
socket.end(JSON.stringify({ ok: true, outboundMessageId }));
|
|
34559
|
-
}
|
|
34560
|
-
},
|
|
34561
|
-
(error62) => {
|
|
34562
|
-
if (socket.destroyed) {
|
|
34563
|
-
return;
|
|
34564
|
-
}
|
|
34565
|
-
const code = error62 instanceof LocalBotAuthorizationError ? error62.code : "bot_service_unavailable";
|
|
34566
|
-
const message = error62 instanceof LocalBotAuthorizationError ? error62.message : "The local Bot action could not be completed";
|
|
34567
|
-
socket.end(JSON.stringify({ error: { code, message }, ok: false }));
|
|
34568
|
-
}
|
|
34569
|
-
);
|
|
34570
|
-
});
|
|
34571
|
-
};
|
|
34572
|
-
handle = async (encoded, signal) => {
|
|
34573
|
-
const request = decodeRequest(encoded);
|
|
34574
|
-
const context = this.#registry.read(request.contextHandle);
|
|
34575
|
-
const timeout = AbortSignal.timeout(BOT_RELAY_TIMEOUT_MILLISECONDS);
|
|
34576
|
-
const requestSignal = AbortSignal.any([signal, timeout]);
|
|
34577
|
-
let response;
|
|
34578
|
-
try {
|
|
34579
|
-
response = await fetch(relayEndpoint(this.#relayUrl, context, request.target), {
|
|
34580
|
-
body: JSON.stringify({ idempotencyKey: request.idempotencyKey, text: request.text }),
|
|
34581
|
-
headers: {
|
|
34582
|
-
authorization: `Bearer ${daemonToken(this.#relayUrl)}`,
|
|
34583
|
-
"content-type": "application/json",
|
|
34584
|
-
"x-mobius-bot-execution-capability": context.command.executionCapabilitySecret
|
|
34585
|
-
},
|
|
34586
|
-
method: "POST",
|
|
34587
|
-
signal: requestSignal
|
|
34588
|
-
});
|
|
34589
|
-
} catch (cause) {
|
|
34590
|
-
signal.throwIfAborted();
|
|
34591
|
-
throw new LocalBotAuthorizationError(
|
|
34592
|
-
timeout.aborted ? "bot_service_timeout" : "bot_service_unavailable",
|
|
34593
|
-
timeout.aborted ? "The Mobius Bot action timed out" : "The Mobius Relay is unavailable",
|
|
34594
|
-
{ cause }
|
|
34595
|
-
);
|
|
34596
|
-
}
|
|
34597
|
-
return await decodeRelayResponse(response);
|
|
34598
|
-
};
|
|
34599
|
-
};
|
|
34600
|
-
|
|
34601
33771
|
// src/pairing/pair-local-machine.ts
|
|
34602
|
-
import { randomUUID
|
|
34603
|
-
import { mkdir as
|
|
33772
|
+
import { randomUUID } from "node:crypto";
|
|
33773
|
+
import { mkdir as mkdir3, open as open5, realpath as realpath7, rename as rename3, stat as stat6, writeFile as writeFile2 } from "node:fs/promises";
|
|
34604
33774
|
import { hostname as hostname3 } from "node:os";
|
|
34605
33775
|
import { basename as basename3, join as join15, resolve as resolve3 } from "node:path";
|
|
34606
|
-
import { fetch as
|
|
33776
|
+
import { fetch as fetch2 } from "undici";
|
|
34607
33777
|
|
|
34608
33778
|
// src/agent-catalog/agent-discovery.ts
|
|
34609
33779
|
var AgentDiscovery = class {
|
|
@@ -34712,8 +33882,8 @@ var LocalAgentInventory = class {
|
|
|
34712
33882
|
};
|
|
34713
33883
|
|
|
34714
33884
|
// src/agent-installation/managed-npm-package.ts
|
|
34715
|
-
import { mkdir
|
|
34716
|
-
import { delimiter, dirname as
|
|
33885
|
+
import { mkdir, mkdtemp, open as open3, realpath as realpath3, rename, rm, stat as stat3 } from "node:fs/promises";
|
|
33886
|
+
import { delimiter, dirname as dirname3, isAbsolute as isAbsolute2, join as join4, relative, sep } from "node:path";
|
|
34717
33887
|
var INSTALL_TIMEOUT_MILLISECONDS = 5 * 60 * 1e3;
|
|
34718
33888
|
var PACKAGE_METADATA_LIMIT_BYTES = 64 * 1024;
|
|
34719
33889
|
var PACKAGE_LOCK_LIMIT_BYTES = 8 * 1024 * 1024;
|
|
@@ -34760,7 +33930,7 @@ var ManagedNpmPackageError = class extends Error {
|
|
|
34760
33930
|
this.name = "ManagedNpmPackageError";
|
|
34761
33931
|
}
|
|
34762
33932
|
};
|
|
34763
|
-
function
|
|
33933
|
+
function isRecord6(value) {
|
|
34764
33934
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
34765
33935
|
}
|
|
34766
33936
|
function packagePath(root, packageName) {
|
|
@@ -34768,11 +33938,11 @@ function packagePath(root, packageName) {
|
|
|
34768
33938
|
}
|
|
34769
33939
|
function isContainedPath(root, candidate) {
|
|
34770
33940
|
const difference = relative(root, candidate);
|
|
34771
|
-
return difference.length > 0 && difference !== ".." && !difference.startsWith(`..${sep}`) && !
|
|
33941
|
+
return difference.length > 0 && difference !== ".." && !difference.startsWith(`..${sep}`) && !isAbsolute2(difference);
|
|
34772
33942
|
}
|
|
34773
33943
|
async function readJsonRecord(path2, maximumBytes) {
|
|
34774
33944
|
try {
|
|
34775
|
-
const handle = await
|
|
33945
|
+
const handle = await open3(path2, "r");
|
|
34776
33946
|
try {
|
|
34777
33947
|
const metadata = await handle.stat();
|
|
34778
33948
|
if (!metadata.isFile() || metadata.size > maximumBytes) {
|
|
@@ -34782,7 +33952,7 @@ async function readJsonRecord(path2, maximumBytes) {
|
|
|
34782
33952
|
);
|
|
34783
33953
|
}
|
|
34784
33954
|
const value = JSON.parse(await handle.readFile({ encoding: "utf8" }));
|
|
34785
|
-
if (!
|
|
33955
|
+
if (!isRecord6(value)) {
|
|
34786
33956
|
throw new ManagedNpmPackageError(
|
|
34787
33957
|
"managed_package_verification_failed",
|
|
34788
33958
|
"The managed npm package metadata is invalid"
|
|
@@ -34808,7 +33978,7 @@ function readBinPath(packageMetadata, executableName) {
|
|
|
34808
33978
|
if (typeof bin === "string") {
|
|
34809
33979
|
return bin;
|
|
34810
33980
|
}
|
|
34811
|
-
if (
|
|
33981
|
+
if (isRecord6(bin) && typeof bin[executableName] === "string") {
|
|
34812
33982
|
return bin[executableName];
|
|
34813
33983
|
}
|
|
34814
33984
|
throw new ManagedNpmPackageError(
|
|
@@ -34824,7 +33994,7 @@ function verifyPackageLockEntry(lock, definition2, verifyDependencyClosure) {
|
|
|
34824
33994
|
);
|
|
34825
33995
|
}
|
|
34826
33996
|
const packages = lock["packages"];
|
|
34827
|
-
if (!
|
|
33997
|
+
if (!isRecord6(packages)) {
|
|
34828
33998
|
throw new ManagedNpmPackageError(
|
|
34829
33999
|
"managed_package_verification_failed",
|
|
34830
34000
|
"The managed npm package lockfile is invalid"
|
|
@@ -34838,7 +34008,7 @@ function verifyPackageLockEntry(lock, definition2, verifyDependencyClosure) {
|
|
|
34838
34008
|
if (verifyDependencyClosure && normalizedKey.length > 0) {
|
|
34839
34009
|
let resolved;
|
|
34840
34010
|
try {
|
|
34841
|
-
if (!normalizedKey.split("/").includes("node_modules") || !
|
|
34011
|
+
if (!normalizedKey.split("/").includes("node_modules") || !isRecord6(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") {
|
|
34842
34012
|
throw new Error("Invalid locked dependency");
|
|
34843
34013
|
}
|
|
34844
34014
|
resolved = new URL(candidate["resolved"]);
|
|
@@ -34861,7 +34031,7 @@ function verifyPackageLockEntry(lock, definition2, verifyDependencyClosure) {
|
|
|
34861
34031
|
matches += 1;
|
|
34862
34032
|
}
|
|
34863
34033
|
}
|
|
34864
|
-
if (matches !== 1 || !
|
|
34034
|
+
if (matches !== 1 || !isRecord6(entry) || entry["integrity"] !== definition2.integrity || entry["resolved"] !== definition2.tarballUrl || entry["version"] !== definition2.version) {
|
|
34865
34035
|
throw new ManagedNpmPackageError(
|
|
34866
34036
|
"managed_package_verification_failed",
|
|
34867
34037
|
"The managed npm package lockfile does not match the pinned artifact"
|
|
@@ -34943,8 +34113,8 @@ var ManagedNpmPackageInstaller = class {
|
|
|
34943
34113
|
throw error62;
|
|
34944
34114
|
}
|
|
34945
34115
|
}
|
|
34946
|
-
const parent =
|
|
34947
|
-
await
|
|
34116
|
+
const parent = dirname3(root);
|
|
34117
|
+
await mkdir(parent, { mode: 448, recursive: true });
|
|
34948
34118
|
const staging = await mkdtemp(join4(parent, `.${definition2.version}.staging-`));
|
|
34949
34119
|
try {
|
|
34950
34120
|
const npm = await findExecutableOnPath(process.platform === "win32" ? "npm.cmd" : "npm", environment);
|
|
@@ -34978,7 +34148,7 @@ var ManagedNpmPackageInstaller = class {
|
|
|
34978
34148
|
NPM_CONFIG_IGNORE_SCRIPTS: "true",
|
|
34979
34149
|
NPM_CONFIG_PACKAGE_LOCK: "true",
|
|
34980
34150
|
NPM_CONFIG_REGISTRY: "https://registry.npmjs.org/",
|
|
34981
|
-
PATH: `${
|
|
34151
|
+
PATH: `${dirname3(process.execPath)}${delimiter}/usr/bin${delimiter}/bin`
|
|
34982
34152
|
};
|
|
34983
34153
|
if (definition2.includeOptionalDependencies) {
|
|
34984
34154
|
installEnvironment["NPM_CONFIG_INCLUDE"] = "optional";
|
|
@@ -35042,7 +34212,6 @@ function normalizeVersionOutput(output2) {
|
|
|
35042
34212
|
// src/agent-catalog/agent-specification.ts
|
|
35043
34213
|
var VERSION_PROBE_TIMEOUT_MILLISECONDS = 3e3;
|
|
35044
34214
|
var ACP_PROBE_TIMEOUT_MILLISECONDS = 5e3;
|
|
35045
|
-
var DEFAULT_PROMPT_TIMEOUT_MILLISECONDS = 30 * 60 * 1e3;
|
|
35046
34215
|
var LocalAgentSpecification = class {
|
|
35047
34216
|
acpProbeTimeoutMilliseconds = ACP_PROBE_TIMEOUT_MILLISECONDS;
|
|
35048
34217
|
authenticationCommand = () => "";
|
|
@@ -35050,7 +34219,6 @@ var LocalAgentSpecification = class {
|
|
|
35050
34219
|
agentVersionArguments = ["--version"];
|
|
35051
34220
|
normalizeAdapterVersion = normalizeVersionOutput;
|
|
35052
34221
|
normalizeAgentVersion = normalizeVersionOutput;
|
|
35053
|
-
promptTimeoutMilliseconds = DEFAULT_PROMPT_TIMEOUT_MILLISECONDS;
|
|
35054
34222
|
versionProbeTimeoutMilliseconds = VERSION_PROBE_TIMEOUT_MILLISECONDS;
|
|
35055
34223
|
resolveManagedAgent = async (stateDirectory, platform, signal) => {
|
|
35056
34224
|
signal.throwIfAborted();
|
|
@@ -35163,12 +34331,12 @@ var AgentProbeError = class extends Error {
|
|
|
35163
34331
|
};
|
|
35164
34332
|
|
|
35165
34333
|
// src/agent-catalog/agents/resolve-user-local-executable.ts
|
|
35166
|
-
import { isAbsolute as
|
|
34334
|
+
import { isAbsolute as isAbsolute3, join as join6 } from "node:path";
|
|
35167
34335
|
async function resolveUserLocalExecutable(executableName, context) {
|
|
35168
34336
|
context.signal.throwIfAborted();
|
|
35169
34337
|
const platform = context.platform ?? process.platform;
|
|
35170
34338
|
const homeDirectory = context.environment["HOME"];
|
|
35171
|
-
if (platform === "win32" || homeDirectory === void 0 || !
|
|
34339
|
+
if (platform === "win32" || homeDirectory === void 0 || !isAbsolute3(homeDirectory)) {
|
|
35172
34340
|
return [];
|
|
35173
34341
|
}
|
|
35174
34342
|
const executable = await resolveExecutablePath(join6(homeDirectory, ".local", "bin", executableName), platform);
|
|
@@ -35257,7 +34425,7 @@ var CursorCliAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
35257
34425
|
|
|
35258
34426
|
// src/agent-catalog/agents/deepseek-harness-agent.ts
|
|
35259
34427
|
import { realpath as realpath4, stat as stat4 } from "node:fs/promises";
|
|
35260
|
-
import { isAbsolute as
|
|
34428
|
+
import { isAbsolute as isAbsolute4, join as join7, normalize as normalize2 } from "node:path";
|
|
35261
34429
|
|
|
35262
34430
|
// src/agent-installation/deepseek-managed-package.ts
|
|
35263
34431
|
var DeepSeekHarnessManagedPackage = class extends SriManagedNpmPackageDefinition {
|
|
@@ -35275,7 +34443,7 @@ var DEEPSEEK_HARNESS_PACKAGE = new DeepSeekHarnessManagedPackage(
|
|
|
35275
34443
|
|
|
35276
34444
|
// src/agent-catalog/agents/deepseek-harness-agent.ts
|
|
35277
34445
|
async function validateAgentHome(path2) {
|
|
35278
|
-
if (!
|
|
34446
|
+
if (!isAbsolute4(path2) || normalize2(path2) !== path2) {
|
|
35279
34447
|
throw new AgentProbeError("agent_environment_invalid", "The configured Agent home is invalid");
|
|
35280
34448
|
}
|
|
35281
34449
|
try {
|
|
@@ -35394,7 +34562,7 @@ var GeminiCliAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
35394
34562
|
|
|
35395
34563
|
// src/agent-catalog/agents/grok-build-agent.ts
|
|
35396
34564
|
import { realpath as realpath5 } from "node:fs/promises";
|
|
35397
|
-
import { isAbsolute as
|
|
34565
|
+
import { isAbsolute as isAbsolute5, join as join8, relative as relative2, sep as sep2 } from "node:path";
|
|
35398
34566
|
import {
|
|
35399
34567
|
RequestError as RequestError2
|
|
35400
34568
|
} from "@agentclientprotocol/sdk";
|
|
@@ -35460,7 +34628,7 @@ function grokBuildManagedPackage(platform, architecture) {
|
|
|
35460
34628
|
// src/agent-catalog/agents/grok-build-agent.ts
|
|
35461
34629
|
function isContainedPath2(root, candidate) {
|
|
35462
34630
|
const difference = relative2(root, candidate);
|
|
35463
|
-
return difference.length > 0 && difference !== ".." && !difference.startsWith(`..${sep2}`) && !
|
|
34631
|
+
return difference.length > 0 && difference !== ".." && !difference.startsWith(`..${sep2}`) && !isAbsolute5(difference);
|
|
35464
34632
|
}
|
|
35465
34633
|
var GrokBuildAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
35466
34634
|
adapterVersion = GROK_BUILD_MANAGED_VERSION;
|
|
@@ -35561,11 +34729,11 @@ import { join as join10 } from "node:path";
|
|
|
35561
34729
|
// src/agent-installation/managed-agent-archive.ts
|
|
35562
34730
|
import { createHash } from "node:crypto";
|
|
35563
34731
|
import { createReadStream } from "node:fs";
|
|
35564
|
-
import { chmod
|
|
35565
|
-
import { delimiter as delimiter2, dirname as
|
|
34732
|
+
import { chmod, copyFile, mkdir as mkdir2, mkdtemp as mkdtemp2, open as open4, realpath as realpath6, rename as rename2, rm as rm2, stat as stat5, writeFile } from "node:fs/promises";
|
|
34733
|
+
import { delimiter as delimiter2, dirname as dirname4, isAbsolute as isAbsolute6, join as join9, relative as relative3, sep as sep3 } from "node:path";
|
|
35566
34734
|
|
|
35567
34735
|
// src/agent-installation/verified-download.ts
|
|
35568
|
-
import { fetch
|
|
34736
|
+
import { fetch } from "undici";
|
|
35569
34737
|
|
|
35570
34738
|
// src/network/environment-proxy.ts
|
|
35571
34739
|
import { EnvHttpProxyAgent } from "undici";
|
|
@@ -35663,12 +34831,12 @@ var ManagedAgentArchiveError = class extends Error {
|
|
|
35663
34831
|
this.name = "ManagedAgentArchiveError";
|
|
35664
34832
|
}
|
|
35665
34833
|
};
|
|
35666
|
-
function
|
|
34834
|
+
function isRecord7(value) {
|
|
35667
34835
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
35668
34836
|
}
|
|
35669
34837
|
function isContainedPath3(root, candidate) {
|
|
35670
34838
|
const difference = relative3(root, candidate);
|
|
35671
|
-
return difference.length > 0 && difference !== ".." && !difference.startsWith(`..${sep3}`) && !
|
|
34839
|
+
return difference.length > 0 && difference !== ".." && !difference.startsWith(`..${sep3}`) && !isAbsolute6(difference);
|
|
35672
34840
|
}
|
|
35673
34841
|
async function hashFile(path2, signal) {
|
|
35674
34842
|
signal.throwIfAborted();
|
|
@@ -35703,7 +34871,7 @@ async function hashFile(path2, signal) {
|
|
|
35703
34871
|
async function readManifest(path2) {
|
|
35704
34872
|
let handle;
|
|
35705
34873
|
try {
|
|
35706
|
-
handle = await
|
|
34874
|
+
handle = await open4(path2, "r");
|
|
35707
34875
|
} catch (error62) {
|
|
35708
34876
|
throw new ManagedAgentArchiveError(
|
|
35709
34877
|
"managed_archive_verification_failed",
|
|
@@ -35720,7 +34888,7 @@ async function readManifest(path2) {
|
|
|
35720
34888
|
);
|
|
35721
34889
|
}
|
|
35722
34890
|
const parsed = JSON.parse(await handle.readFile({ encoding: "utf8" }));
|
|
35723
|
-
if (!
|
|
34891
|
+
if (!isRecord7(parsed)) {
|
|
35724
34892
|
throw new ManagedAgentArchiveError(
|
|
35725
34893
|
"managed_archive_verification_failed",
|
|
35726
34894
|
"The managed Agent archive manifest is invalid"
|
|
@@ -35891,7 +35059,6 @@ var PI_AGENT_PACKAGE = new SriManagedNpmPackageDefinition(
|
|
|
35891
35059
|
|
|
35892
35060
|
// src/agent-catalog/agents/pi-agent.ts
|
|
35893
35061
|
var ACP_PROBE_TIMEOUT_MILLISECONDS2 = 3e4;
|
|
35894
|
-
var PROMPT_TIMEOUT_MILLISECONDS = 5 * 60 * 1e3;
|
|
35895
35062
|
var PiAgentSpecification = class extends BridgedAcpAgentDefinition {
|
|
35896
35063
|
acpProbeTimeoutMilliseconds = ACP_PROBE_TIMEOUT_MILLISECONDS2;
|
|
35897
35064
|
adapterEnvironmentVariable = "PI_ACP_PI_COMMAND";
|
|
@@ -35923,7 +35090,6 @@ var PiAgentSpecification = class extends BridgedAcpAgentDefinition {
|
|
|
35923
35090
|
"bundle",
|
|
35924
35091
|
"cli.js"
|
|
35925
35092
|
];
|
|
35926
|
-
promptTimeoutMilliseconds = PROMPT_TIMEOUT_MILLISECONDS;
|
|
35927
35093
|
resolveManagedAgent = async (stateDirectory, _platform, signal) => {
|
|
35928
35094
|
signal.throwIfAborted();
|
|
35929
35095
|
const executable = await validateManagedNpmPackage(
|
|
@@ -35965,7 +35131,7 @@ var PiAgentSpecification = class extends BridgedAcpAgentDefinition {
|
|
|
35965
35131
|
};
|
|
35966
35132
|
|
|
35967
35133
|
// src/agent-catalog/agents/workbuddy-agent.ts
|
|
35968
|
-
import { isAbsolute as
|
|
35134
|
+
import { isAbsolute as isAbsolute7, join as join12 } from "node:path";
|
|
35969
35135
|
|
|
35970
35136
|
// src/agent-installation/workbuddy-managed-package.ts
|
|
35971
35137
|
var WORKBUDDY_MANAGED_VERSION = "2.146.0";
|
|
@@ -36031,12 +35197,12 @@ var WorkBuddyAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
36031
35197
|
}
|
|
36032
35198
|
const requestedPaths = [join12("/Applications", ...WORKBUDDY_MACOS_EXECUTABLE_PATH)];
|
|
36033
35199
|
const homeDirectory = context.environment["HOME"];
|
|
36034
|
-
if (homeDirectory !== void 0 &&
|
|
35200
|
+
if (homeDirectory !== void 0 && isAbsolute7(homeDirectory)) {
|
|
36035
35201
|
requestedPaths.unshift(join12(homeDirectory, "Applications", ...WORKBUDDY_MACOS_EXECUTABLE_PATH));
|
|
36036
35202
|
}
|
|
36037
35203
|
const executables = [];
|
|
36038
|
-
for (const
|
|
36039
|
-
const executable = await resolveExecutablePath(
|
|
35204
|
+
for (const requestedPath2 of requestedPaths) {
|
|
35205
|
+
const executable = await resolveExecutablePath(requestedPath2, "darwin");
|
|
36040
35206
|
context.signal.throwIfAborted();
|
|
36041
35207
|
if (executable !== null) {
|
|
36042
35208
|
executables.push(executable);
|
|
@@ -36095,41 +35261,41 @@ var DiscoveryAcpHandler = class {
|
|
|
36095
35261
|
};
|
|
36096
35262
|
function readableAcpStream(input2) {
|
|
36097
35263
|
let byteLength = 0;
|
|
36098
|
-
let
|
|
35264
|
+
let open6 = true;
|
|
36099
35265
|
return new ReadableStream({
|
|
36100
35266
|
start(controller) {
|
|
36101
35267
|
input2.on("data", (chunk) => {
|
|
36102
|
-
if (!
|
|
35268
|
+
if (!open6) {
|
|
36103
35269
|
return;
|
|
36104
35270
|
}
|
|
36105
35271
|
if (!(chunk instanceof Uint8Array)) {
|
|
36106
|
-
|
|
35272
|
+
open6 = false;
|
|
36107
35273
|
controller.error(new Error("ACP adapter produced invalid output"));
|
|
36108
35274
|
return;
|
|
36109
35275
|
}
|
|
36110
35276
|
byteLength += chunk.byteLength;
|
|
36111
35277
|
if (byteLength > ACP_OUTPUT_LIMIT_BYTES) {
|
|
36112
|
-
|
|
35278
|
+
open6 = false;
|
|
36113
35279
|
controller.error(new Error("ACP adapter output limit exceeded"));
|
|
36114
35280
|
return;
|
|
36115
35281
|
}
|
|
36116
35282
|
controller.enqueue(new Uint8Array(chunk));
|
|
36117
35283
|
});
|
|
36118
35284
|
input2.once("end", () => {
|
|
36119
|
-
if (
|
|
36120
|
-
|
|
35285
|
+
if (open6) {
|
|
35286
|
+
open6 = false;
|
|
36121
35287
|
controller.close();
|
|
36122
35288
|
}
|
|
36123
35289
|
});
|
|
36124
35290
|
input2.once("error", (error62) => {
|
|
36125
|
-
if (
|
|
36126
|
-
|
|
35291
|
+
if (open6) {
|
|
35292
|
+
open6 = false;
|
|
36127
35293
|
controller.error(error62);
|
|
36128
35294
|
}
|
|
36129
35295
|
});
|
|
36130
35296
|
},
|
|
36131
35297
|
cancel() {
|
|
36132
|
-
|
|
35298
|
+
open6 = false;
|
|
36133
35299
|
}
|
|
36134
35300
|
});
|
|
36135
35301
|
}
|
|
@@ -36241,7 +35407,7 @@ async function probeAcpReadiness(specification, agent, environment, defaultWorks
|
|
|
36241
35407
|
}
|
|
36242
35408
|
|
|
36243
35409
|
// src/agent-catalog/executable-discovery.ts
|
|
36244
|
-
import { isAbsolute as
|
|
35410
|
+
import { isAbsolute as isAbsolute8, join as join14 } from "node:path";
|
|
36245
35411
|
|
|
36246
35412
|
// src/agent-installation/managed-adapter-installer.ts
|
|
36247
35413
|
import { join as join13 } from "node:path";
|
|
@@ -36346,7 +35512,7 @@ async function resolveManagedAdapterExecutable(specification, context) {
|
|
|
36346
35512
|
async function resolveSpecificationExecutables(executableName, overrideVariable, resolveInstalled, resolveManaged, context) {
|
|
36347
35513
|
const override = context.environment[overrideVariable];
|
|
36348
35514
|
if (override !== void 0) {
|
|
36349
|
-
if (override.length === 0 || !
|
|
35515
|
+
if (override.length === 0 || !isAbsolute8(override)) {
|
|
36350
35516
|
return [];
|
|
36351
35517
|
}
|
|
36352
35518
|
const executable = await resolveExecutablePath(override, context.platform);
|
|
@@ -36400,7 +35566,7 @@ async function resolveAdapterExecutable(specification, context) {
|
|
|
36400
35566
|
const executables = await resolveAdapterExecutables(specification, context);
|
|
36401
35567
|
return executables[0] ?? null;
|
|
36402
35568
|
}
|
|
36403
|
-
async function probeVersion(executable, arguments_, environment, defaultWorkspace, signal, timeoutMilliseconds,
|
|
35569
|
+
async function probeVersion(executable, arguments_, environment, defaultWorkspace, signal, timeoutMilliseconds, normalize5 = normalizeVersionOutput) {
|
|
36404
35570
|
const result = await runBoundedProcess({
|
|
36405
35571
|
arguments: arguments_,
|
|
36406
35572
|
command: executable.path,
|
|
@@ -36409,7 +35575,7 @@ async function probeVersion(executable, arguments_, environment, defaultWorkspac
|
|
|
36409
35575
|
signal,
|
|
36410
35576
|
timeoutMilliseconds
|
|
36411
35577
|
});
|
|
36412
|
-
const version2 =
|
|
35578
|
+
const version2 = normalize5(result.stdout || result.stderr);
|
|
36413
35579
|
if (version2.length === 0) {
|
|
36414
35580
|
throw new ProcessExecutionError("process_exit_failed", "The executable did not report a version");
|
|
36415
35581
|
}
|
|
@@ -36546,8 +35712,7 @@ async function discoverAgent(specification, context) {
|
|
|
36546
35712
|
adapterVersion,
|
|
36547
35713
|
agentVersion,
|
|
36548
35714
|
adapter.identity,
|
|
36549
|
-
agent.identity
|
|
36550
|
-
specification.promptTimeoutMilliseconds
|
|
35715
|
+
agent.identity
|
|
36551
35716
|
);
|
|
36552
35717
|
try {
|
|
36553
35718
|
const readiness = await probeAcpReadiness(
|
|
@@ -36573,7 +35738,6 @@ async function discoverAgent(specification, context) {
|
|
|
36573
35738
|
agentVersion,
|
|
36574
35739
|
adapter.identity,
|
|
36575
35740
|
agent.identity,
|
|
36576
|
-
specification.promptTimeoutMilliseconds,
|
|
36577
35741
|
readiness.capabilities
|
|
36578
35742
|
)
|
|
36579
35743
|
);
|
|
@@ -36604,8 +35768,8 @@ async function discoverLocalAgentInventory(options) {
|
|
|
36604
35768
|
// src/pairing/pair-local-machine.ts
|
|
36605
35769
|
var PAIRING_TIMEOUT_MILLISECONDS = 2e4;
|
|
36606
35770
|
var PAIRING_CODE_PATTERN = /^[A-HJ-NP-Z2-9]{4}(?:-[A-HJ-NP-Z2-9]{4}){4}$/;
|
|
36607
|
-
var
|
|
36608
|
-
var
|
|
35771
|
+
var IDENTIFIER_PATTERN4 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
35772
|
+
var TOKEN_PATTERN = /^[a-zA-Z0-9_-]{32,256}$/;
|
|
36609
35773
|
var MAX_CONNECTION_FILE_LENGTH = 16 * 1024;
|
|
36610
35774
|
var CLAIM_RESPONSE_KEYS = ["channelId", "daemonToken", "runtimeId"];
|
|
36611
35775
|
var REDEEM_RESPONSE_KEYS = ["channelId", "runtimeCredential", "runtimeId"];
|
|
@@ -36619,36 +35783,36 @@ var PairingClientError = class extends Error {
|
|
|
36619
35783
|
this.name = "PairingClientError";
|
|
36620
35784
|
}
|
|
36621
35785
|
};
|
|
36622
|
-
function
|
|
35786
|
+
function isRecord8(value) {
|
|
36623
35787
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
36624
35788
|
}
|
|
36625
35789
|
function hasExactKeys(value, expectedKeys) {
|
|
36626
35790
|
const keys = Object.keys(value);
|
|
36627
35791
|
return keys.length === expectedKeys.length && expectedKeys.every((key) => Object.hasOwn(value, key));
|
|
36628
35792
|
}
|
|
36629
|
-
function readSingleOption(arguments_,
|
|
35793
|
+
function readSingleOption(arguments_, option) {
|
|
36630
35794
|
const values = [];
|
|
36631
35795
|
for (let index2 = 0; index2 < arguments_.length; index2 += 1) {
|
|
36632
|
-
if (arguments_[index2] !==
|
|
35796
|
+
if (arguments_[index2] !== option) {
|
|
36633
35797
|
continue;
|
|
36634
35798
|
}
|
|
36635
35799
|
const value = arguments_[index2 + 1];
|
|
36636
35800
|
if (value === void 0 || value.startsWith("--")) {
|
|
36637
|
-
throw new PairingClientError("invalid_arguments", `${
|
|
35801
|
+
throw new PairingClientError("invalid_arguments", `${option} requires a value`);
|
|
36638
35802
|
}
|
|
36639
35803
|
values.push(value);
|
|
36640
35804
|
index2 += 1;
|
|
36641
35805
|
}
|
|
36642
35806
|
if (values.length !== 1) {
|
|
36643
|
-
throw new PairingClientError("invalid_arguments", `${
|
|
35807
|
+
throw new PairingClientError("invalid_arguments", `${option} must be provided exactly once`);
|
|
36644
35808
|
}
|
|
36645
35809
|
return values[0] ?? "";
|
|
36646
35810
|
}
|
|
36647
35811
|
function assertKnownArguments(arguments_) {
|
|
36648
35812
|
for (let index2 = 0; index2 < arguments_.length; index2 += 2) {
|
|
36649
|
-
const
|
|
36650
|
-
if (
|
|
36651
|
-
throw new PairingClientError("invalid_arguments", `Unknown pairing option: ${
|
|
35813
|
+
const option = arguments_[index2];
|
|
35814
|
+
if (option !== "--url" && option !== "--code" && option !== "--pairing" && option !== "--workspace") {
|
|
35815
|
+
throw new PairingClientError("invalid_arguments", `Unknown pairing option: ${option ?? "missing option"}`);
|
|
36652
35816
|
}
|
|
36653
35817
|
}
|
|
36654
35818
|
}
|
|
@@ -36693,7 +35857,7 @@ function parsePairCommand(arguments_) {
|
|
|
36693
35857
|
};
|
|
36694
35858
|
}
|
|
36695
35859
|
function validatePairingId(value) {
|
|
36696
|
-
if (!
|
|
35860
|
+
if (!IDENTIFIER_PATTERN4.test(value)) {
|
|
36697
35861
|
throw new PairingClientError("invalid_pairing_id", "The Runtime pairing ID is invalid");
|
|
36698
35862
|
}
|
|
36699
35863
|
return value;
|
|
@@ -36703,7 +35867,7 @@ function parseChannelArgument(arguments_) {
|
|
|
36703
35867
|
throw new PairingClientError("invalid_arguments", "Usage: mobius start --channel <channel-id>");
|
|
36704
35868
|
}
|
|
36705
35869
|
const channelId = arguments_[1] ?? "";
|
|
36706
|
-
if (!
|
|
35870
|
+
if (!IDENTIFIER_PATTERN4.test(channelId)) {
|
|
36707
35871
|
throw new PairingClientError("invalid_channel_id", "The saved channel ID is invalid");
|
|
36708
35872
|
}
|
|
36709
35873
|
return channelId;
|
|
@@ -36711,7 +35875,7 @@ function parseChannelArgument(arguments_) {
|
|
|
36711
35875
|
async function resolveDefaultWorkspace(path2) {
|
|
36712
35876
|
const requestedWorkspace = resolve3(path2);
|
|
36713
35877
|
try {
|
|
36714
|
-
await
|
|
35878
|
+
await mkdir3(requestedWorkspace, { recursive: true, mode: 448 });
|
|
36715
35879
|
const defaultWorkspace = await realpath7(requestedWorkspace);
|
|
36716
35880
|
const metadata = await stat6(defaultWorkspace);
|
|
36717
35881
|
if (!metadata.isDirectory()) {
|
|
@@ -36742,9 +35906,9 @@ async function readJsonResponse(response) {
|
|
|
36742
35906
|
}
|
|
36743
35907
|
}
|
|
36744
35908
|
function readRelayError(value) {
|
|
36745
|
-
if (
|
|
35909
|
+
if (isRecord8(value)) {
|
|
36746
35910
|
const error62 = value["error"];
|
|
36747
|
-
if (
|
|
35911
|
+
if (isRecord8(error62)) {
|
|
36748
35912
|
const code = error62["code"];
|
|
36749
35913
|
const message = error62["message"];
|
|
36750
35914
|
if (typeof code === "string" && typeof message === "string") {
|
|
@@ -36755,13 +35919,13 @@ function readRelayError(value) {
|
|
|
36755
35919
|
return new PairingClientError("pairing_failed", "The relay could not pair this machine");
|
|
36756
35920
|
}
|
|
36757
35921
|
function decodePairingResponse(value, credentialField, expectedKeys) {
|
|
36758
|
-
if (!
|
|
35922
|
+
if (!isRecord8(value) || !hasExactKeys(value, expectedKeys)) {
|
|
36759
35923
|
throw new PairingClientError("invalid_relay_response", "The relay returned an invalid pairing response");
|
|
36760
35924
|
}
|
|
36761
35925
|
const channelId = value["channelId"];
|
|
36762
35926
|
const runtimeCredential2 = value[credentialField];
|
|
36763
35927
|
const runtimeId = value["runtimeId"];
|
|
36764
|
-
if (typeof channelId !== "string" || !
|
|
35928
|
+
if (typeof channelId !== "string" || !IDENTIFIER_PATTERN4.test(channelId) || typeof runtimeCredential2 !== "string" || !TOKEN_PATTERN.test(runtimeCredential2) || typeof runtimeId !== "string" || !IDENTIFIER_PATTERN4.test(runtimeId)) {
|
|
36765
35929
|
throw new PairingClientError("invalid_relay_response", "The relay returned an invalid pairing response");
|
|
36766
35930
|
}
|
|
36767
35931
|
return { channelId, runtimeCredential: runtimeCredential2, runtimeId };
|
|
@@ -36771,7 +35935,6 @@ async function claimPairing(options, defaultWorkspace, localAgents, installableA
|
|
|
36771
35935
|
agentPath: agent.agentIdentity.requestedPath,
|
|
36772
35936
|
agentVersion: agent.agentVersion,
|
|
36773
35937
|
agentSettingsDiscovery: true,
|
|
36774
|
-
botSessionConfiguration: true,
|
|
36775
35938
|
capabilities: agent.capabilities,
|
|
36776
35939
|
id: agent.id,
|
|
36777
35940
|
label: agent.label,
|
|
@@ -36780,7 +35943,7 @@ async function claimPairing(options, defaultWorkspace, localAgents, installableA
|
|
|
36780
35943
|
const endpoint = options.pairingId.length > 0 ? mobiusApiUrl(options.relayOrigin, `/v1/runtime-pairings/${encodeURIComponent(options.pairingId)}/redeem`) : mobiusApiUrl(options.relayOrigin, "/pairings/claim");
|
|
36781
35944
|
let response;
|
|
36782
35945
|
try {
|
|
36783
|
-
response = await
|
|
35946
|
+
response = await fetch2(endpoint, {
|
|
36784
35947
|
body: JSON.stringify({
|
|
36785
35948
|
agents,
|
|
36786
35949
|
installableAgents,
|
|
@@ -36804,9 +35967,9 @@ async function claimPairing(options, defaultWorkspace, localAgents, installableA
|
|
|
36804
35967
|
}
|
|
36805
35968
|
async function persistConnection(channelId, relayOrigin, runtimeCredential2, defaultWorkspace, environment) {
|
|
36806
35969
|
const connectionsDirectory = join15(readStateDirectory(environment), "connections");
|
|
36807
|
-
await
|
|
35970
|
+
await mkdir3(connectionsDirectory, { mode: 448, recursive: true });
|
|
36808
35971
|
const connectionPath = join15(connectionsDirectory, `${channelId}.json`);
|
|
36809
|
-
const temporaryPath = join15(connectionsDirectory, `.${channelId}.${
|
|
35972
|
+
const temporaryPath = join15(connectionsDirectory, `.${channelId}.${randomUUID()}.tmp`);
|
|
36810
35973
|
await writeFile2(
|
|
36811
35974
|
temporaryPath,
|
|
36812
35975
|
`${JSON.stringify(
|
|
@@ -36826,14 +35989,14 @@ async function persistConnection(channelId, relayOrigin, runtimeCredential2, def
|
|
|
36826
35989
|
return connectionPath;
|
|
36827
35990
|
}
|
|
36828
35991
|
function decodeSavedConnection(value, expectedChannelId) {
|
|
36829
|
-
if (!
|
|
35992
|
+
if (!isRecord8(value) || !hasExactKeys(value, SAVED_CONNECTION_KEYS) && !hasExactKeys(value, LEGACY_SAVED_CONNECTION_KEYS)) {
|
|
36830
35993
|
throw new PairingClientError("invalid_connection", "The saved connection is invalid");
|
|
36831
35994
|
}
|
|
36832
35995
|
const defaultWorkspace = value["defaultWorkspace"];
|
|
36833
35996
|
const channelId = value["channelId"];
|
|
36834
35997
|
const runtimeCredential2 = value["runtimeCredential"] ?? value["daemonToken"];
|
|
36835
35998
|
const relayOrigin = value["relayOrigin"];
|
|
36836
|
-
if (typeof defaultWorkspace !== "string" || typeof channelId !== "string" || channelId !== expectedChannelId || !
|
|
35999
|
+
if (typeof defaultWorkspace !== "string" || typeof channelId !== "string" || channelId !== expectedChannelId || !IDENTIFIER_PATTERN4.test(channelId) || typeof runtimeCredential2 !== "string" || !TOKEN_PATTERN.test(runtimeCredential2) || typeof relayOrigin !== "string") {
|
|
36837
36000
|
throw new PairingClientError("invalid_connection", "The saved connection is invalid");
|
|
36838
36001
|
}
|
|
36839
36002
|
return {
|
|
@@ -36846,7 +36009,7 @@ function decodeSavedConnection(value, expectedChannelId) {
|
|
|
36846
36009
|
async function readSavedConnection(channelId, environment) {
|
|
36847
36010
|
const connectionPath = join15(readStateDirectory(environment), "connections", `${channelId}.json`);
|
|
36848
36011
|
let encoded = "";
|
|
36849
|
-
const handle = await
|
|
36012
|
+
const handle = await open5(connectionPath, "r");
|
|
36850
36013
|
try {
|
|
36851
36014
|
const metadata = await handle.stat();
|
|
36852
36015
|
if (!metadata.isFile() || metadata.size > MAX_CONNECTION_FILE_LENGTH) {
|
|
@@ -36956,13 +36119,13 @@ async function resumeLocalMachine(arguments_, signal = new AbortController().sig
|
|
|
36956
36119
|
}
|
|
36957
36120
|
|
|
36958
36121
|
// src/run-daemon.ts
|
|
36959
|
-
import { randomUUID as
|
|
36960
|
-
import { basename as
|
|
36122
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
36123
|
+
import { basename as basename7 } from "node:path";
|
|
36961
36124
|
import { styleText } from "node:util";
|
|
36962
|
-
import { fetch as
|
|
36125
|
+
import { fetch as fetch6, WebSocket as WebSocket2 } from "undici";
|
|
36963
36126
|
|
|
36964
36127
|
// src/agent-catalog/publish-agent-catalog.ts
|
|
36965
|
-
import { fetch as
|
|
36128
|
+
import { fetch as fetch3 } from "undici";
|
|
36966
36129
|
|
|
36967
36130
|
// src/relay-connection/runtime-authentication.ts
|
|
36968
36131
|
function runtimeCredential(relayUrl) {
|
|
@@ -37008,13 +36171,12 @@ async function publishAgentCatalog(config2, signal) {
|
|
|
37008
36171
|
let response;
|
|
37009
36172
|
const catalog = config2.catalog.read();
|
|
37010
36173
|
try {
|
|
37011
|
-
response = await
|
|
36174
|
+
response = await fetch3(catalogEndpoint(config2), {
|
|
37012
36175
|
body: JSON.stringify({
|
|
37013
36176
|
agents: catalog.agents.map((agent) => ({
|
|
37014
36177
|
agentPath: agent.agentIdentity.requestedPath,
|
|
37015
36178
|
agentVersion: agent.agentVersion,
|
|
37016
36179
|
agentSettingsDiscovery: true,
|
|
37017
|
-
botSessionConfiguration: true,
|
|
37018
36180
|
capabilities: agent.capabilities,
|
|
37019
36181
|
id: agent.id,
|
|
37020
36182
|
label: agent.label,
|
|
@@ -37501,6 +36663,91 @@ var FixedInstallationExecutor = class {
|
|
|
37501
36663
|
};
|
|
37502
36664
|
};
|
|
37503
36665
|
|
|
36666
|
+
// src/artifacts/local-file-streamer.ts
|
|
36667
|
+
import { createReadStream as createReadStream2 } from "node:fs";
|
|
36668
|
+
import { realpath as realpath8, stat as stat7 } from "node:fs/promises";
|
|
36669
|
+
import { basename as basename4, isAbsolute as isAbsolute9, normalize as normalize3 } from "node:path";
|
|
36670
|
+
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
36671
|
+
var CHUNK_BYTES = 192 * 1024;
|
|
36672
|
+
function requestedPath(value) {
|
|
36673
|
+
if (value.includes("\0")) {
|
|
36674
|
+
return null;
|
|
36675
|
+
}
|
|
36676
|
+
if (value.startsWith("file:")) {
|
|
36677
|
+
try {
|
|
36678
|
+
const url2 = new URL(value);
|
|
36679
|
+
return url2.protocol === "file:" && url2.host.length === 0 ? fileURLToPath3(url2) : null;
|
|
36680
|
+
} catch {
|
|
36681
|
+
return null;
|
|
36682
|
+
}
|
|
36683
|
+
}
|
|
36684
|
+
return value;
|
|
36685
|
+
}
|
|
36686
|
+
async function resolveFile(value, signal) {
|
|
36687
|
+
const requested = requestedPath(value);
|
|
36688
|
+
if (requested === null || !isAbsolute9(requested) || normalize3(requested) !== requested) {
|
|
36689
|
+
return null;
|
|
36690
|
+
}
|
|
36691
|
+
try {
|
|
36692
|
+
const target = await realpath8(requested);
|
|
36693
|
+
signal.throwIfAborted();
|
|
36694
|
+
return isAbsolute9(target) && normalize3(target) === target ? target : null;
|
|
36695
|
+
} catch {
|
|
36696
|
+
signal.throwIfAborted();
|
|
36697
|
+
return null;
|
|
36698
|
+
}
|
|
36699
|
+
}
|
|
36700
|
+
async function streamLocalFile(command, send2, signal) {
|
|
36701
|
+
const target = await resolveFile(command.path, signal);
|
|
36702
|
+
if (target === null) {
|
|
36703
|
+
throw new Error("The local file is unavailable");
|
|
36704
|
+
}
|
|
36705
|
+
const before = await stat7(target);
|
|
36706
|
+
signal.throwIfAborted();
|
|
36707
|
+
if (!before.isFile() || before.size < 1 || before.size > command.maxBytes) {
|
|
36708
|
+
throw new Error("The local file is too large to read");
|
|
36709
|
+
}
|
|
36710
|
+
const raster = await readLocalRaster(target, signal);
|
|
36711
|
+
send2(
|
|
36712
|
+
encodeFileBeginEvent({
|
|
36713
|
+
byteLength: before.size,
|
|
36714
|
+
kind: FILE_BEGIN_KIND,
|
|
36715
|
+
mediaType: raster?.mimeType ?? "application/octet-stream",
|
|
36716
|
+
modifiedAt: before.mtime.toISOString(),
|
|
36717
|
+
name: basename4(target) || "file",
|
|
36718
|
+
requestId: command.requestId,
|
|
36719
|
+
sessionId: command.sessionId
|
|
36720
|
+
})
|
|
36721
|
+
);
|
|
36722
|
+
let sequence = 0;
|
|
36723
|
+
const stream = createReadStream2(target, { highWaterMark: CHUNK_BYTES, signal });
|
|
36724
|
+
for await (const value of stream) {
|
|
36725
|
+
const bytes = value instanceof Uint8Array ? value : new Uint8Array(value);
|
|
36726
|
+
send2(
|
|
36727
|
+
encodeFileChunkEvent({
|
|
36728
|
+
data: Buffer.from(bytes).toString("base64"),
|
|
36729
|
+
kind: FILE_CHUNK_KIND,
|
|
36730
|
+
requestId: command.requestId,
|
|
36731
|
+
sequence,
|
|
36732
|
+
sessionId: command.sessionId
|
|
36733
|
+
})
|
|
36734
|
+
);
|
|
36735
|
+
sequence += 1;
|
|
36736
|
+
}
|
|
36737
|
+
const after = await stat7(target);
|
|
36738
|
+
signal.throwIfAborted();
|
|
36739
|
+
if (after.size !== before.size || after.mtimeMs !== before.mtimeMs) {
|
|
36740
|
+
throw new Error("The local file changed during transfer");
|
|
36741
|
+
}
|
|
36742
|
+
send2(
|
|
36743
|
+
encodeFileEndEvent({
|
|
36744
|
+
kind: FILE_END_KIND,
|
|
36745
|
+
requestId: command.requestId,
|
|
36746
|
+
sessionId: command.sessionId
|
|
36747
|
+
})
|
|
36748
|
+
);
|
|
36749
|
+
}
|
|
36750
|
+
|
|
37504
36751
|
// src/artifacts/runtime-artifact-uploader.ts
|
|
37505
36752
|
import { createHash as createHash2 } from "node:crypto";
|
|
37506
36753
|
|
|
@@ -37527,15 +36774,15 @@ var MobiusValidationError = class extends MobiusError {
|
|
|
37527
36774
|
};
|
|
37528
36775
|
|
|
37529
36776
|
// ../mobius-sdk/src/resources.ts
|
|
37530
|
-
var
|
|
36777
|
+
var IDENTIFIER_PATTERN5 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
37531
36778
|
function invalidResponse(message) {
|
|
37532
36779
|
return new MobiusProtocolError(message);
|
|
37533
36780
|
}
|
|
37534
|
-
function
|
|
36781
|
+
function isRecord9(value) {
|
|
37535
36782
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
37536
36783
|
}
|
|
37537
36784
|
function record3(value, name) {
|
|
37538
|
-
if (!
|
|
36785
|
+
if (!isRecord9(value)) {
|
|
37539
36786
|
throw invalidResponse(`The service returned an invalid ${name}`);
|
|
37540
36787
|
}
|
|
37541
36788
|
return value;
|
|
@@ -37549,7 +36796,7 @@ function stringField(value, field, maximumLength = 85e5) {
|
|
|
37549
36796
|
}
|
|
37550
36797
|
function identifierField(value, field) {
|
|
37551
36798
|
const candidate = stringField(value, field, 128);
|
|
37552
|
-
if (!
|
|
36799
|
+
if (!IDENTIFIER_PATTERN5.test(candidate)) {
|
|
37553
36800
|
throw invalidResponse(`The service returned an invalid ${field}`);
|
|
37554
36801
|
}
|
|
37555
36802
|
return candidate;
|
|
@@ -37720,7 +36967,7 @@ var MobiusRuntimePairingLifecycle = Object.freeze({
|
|
|
37720
36967
|
});
|
|
37721
36968
|
|
|
37722
36969
|
// src/artifacts/runtime-artifact-uploader.ts
|
|
37723
|
-
import { fetch as
|
|
36970
|
+
import { fetch as fetch4 } from "undici";
|
|
37724
36971
|
var UPLOAD_TIMEOUT_MILLISECONDS = 2e4;
|
|
37725
36972
|
var RuntimeArtifactUploadError = class extends Error {
|
|
37726
36973
|
code;
|
|
@@ -37792,7 +37039,7 @@ function sessionArtifactUrl(origin, sessionId, resourcePath) {
|
|
|
37792
37039
|
return new URL(`${origin.pathname}/sessions/${encodeURIComponent(sessionId)}/${resourcePath}`, origin);
|
|
37793
37040
|
}
|
|
37794
37041
|
async function postLease(url2, headers, request, signal) {
|
|
37795
|
-
return await
|
|
37042
|
+
return await fetch4(url2, {
|
|
37796
37043
|
dispatcher: environmentProxyDispatcher,
|
|
37797
37044
|
headers: { ...headers, "content-type": "application/json" },
|
|
37798
37045
|
method: "POST",
|
|
@@ -37801,7 +37048,7 @@ async function postLease(url2, headers, request, signal) {
|
|
|
37801
37048
|
});
|
|
37802
37049
|
}
|
|
37803
37050
|
async function putContent(url2, headers, authorization, bytes, signal) {
|
|
37804
|
-
return await
|
|
37051
|
+
return await fetch4(url2, {
|
|
37805
37052
|
dispatcher: environmentProxyDispatcher,
|
|
37806
37053
|
headers: {
|
|
37807
37054
|
...headers,
|
|
@@ -37887,9 +37134,9 @@ async function uploadRuntimeArtifact(config2, sessionId, artifact, signal) {
|
|
|
37887
37134
|
}
|
|
37888
37135
|
|
|
37889
37136
|
// src/authorization/workspace-directory.ts
|
|
37890
|
-
import { readdir as readdir2, realpath as
|
|
37137
|
+
import { readdir as readdir2, realpath as realpath9, stat as stat8 } from "node:fs/promises";
|
|
37891
37138
|
import { homedir as homedir2 } from "node:os";
|
|
37892
|
-
import { basename as
|
|
37139
|
+
import { basename as basename5, dirname as dirname5, isAbsolute as isAbsolute10, join as join16, normalize as normalize4, relative as relative4 } from "node:path";
|
|
37893
37140
|
var WorkspaceDirectoryListing = class {
|
|
37894
37141
|
directoryId;
|
|
37895
37142
|
directoryLabel;
|
|
@@ -37915,7 +37162,7 @@ function decodePath(value, prefix) {
|
|
|
37915
37162
|
throw new LocalAuthorizationError("The directory identifier is invalid");
|
|
37916
37163
|
}
|
|
37917
37164
|
const decoded = Buffer.from(encoded, "base64url").toString("utf8");
|
|
37918
|
-
if (Buffer.from(decoded, "utf8").toString("base64url") !== encoded || decoded.includes("\0") ||
|
|
37165
|
+
if (Buffer.from(decoded, "utf8").toString("base64url") !== encoded || decoded.includes("\0") || normalize4(decoded) !== decoded) {
|
|
37919
37166
|
throw new LocalAuthorizationError("The directory identifier is invalid");
|
|
37920
37167
|
}
|
|
37921
37168
|
return decoded;
|
|
@@ -37949,15 +37196,15 @@ var WorkspaceDirectoryService = class {
|
|
|
37949
37196
|
};
|
|
37950
37197
|
resolvePath = async (requested, signal) => {
|
|
37951
37198
|
signal.throwIfAborted();
|
|
37952
|
-
if (!isAbsolute10(requested) || requested.includes("\0") ||
|
|
37199
|
+
if (!isAbsolute10(requested) || requested.includes("\0") || normalize4(requested) !== requested) {
|
|
37953
37200
|
throw new LocalAuthorizationError("The local directory path is invalid");
|
|
37954
37201
|
}
|
|
37955
37202
|
try {
|
|
37956
|
-
const target = await
|
|
37203
|
+
const target = await realpath9(requested);
|
|
37957
37204
|
signal.throwIfAborted();
|
|
37958
|
-
const metadata = await
|
|
37205
|
+
const metadata = await stat8(target);
|
|
37959
37206
|
signal.throwIfAborted();
|
|
37960
|
-
if (!isAbsolute10(target) ||
|
|
37207
|
+
if (!isAbsolute10(target) || normalize4(target) !== target || !metadata.isDirectory()) {
|
|
37961
37208
|
throw new LocalAuthorizationError("The selected location is not a directory");
|
|
37962
37209
|
}
|
|
37963
37210
|
return target;
|
|
@@ -37975,13 +37222,13 @@ var WorkspaceDirectoryService = class {
|
|
|
37975
37222
|
const suffix = relative4(homedir2(), path2);
|
|
37976
37223
|
return suffix === "" ? "~" : !isAbsolute10(suffix) && suffix !== ".." && !suffix.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) ? `~/${suffix.replaceAll("\\", "/")}` : path2;
|
|
37977
37224
|
};
|
|
37978
|
-
identify = async (bindingId,
|
|
37225
|
+
identify = async (bindingId, requestedPath2, signal) => {
|
|
37979
37226
|
this.authorizeMachine(bindingId);
|
|
37980
|
-
const path2 = await this.resolvePath(
|
|
37227
|
+
const path2 = await this.resolvePath(requestedPath2, signal);
|
|
37981
37228
|
return {
|
|
37982
37229
|
path: path2,
|
|
37983
37230
|
directoryId: encodePath(path2),
|
|
37984
|
-
name:
|
|
37231
|
+
name: basename5(path2) || path2,
|
|
37985
37232
|
label: this.label(path2)
|
|
37986
37233
|
};
|
|
37987
37234
|
};
|
|
@@ -38013,7 +37260,7 @@ var WorkspaceDirectoryService = class {
|
|
|
38013
37260
|
}
|
|
38014
37261
|
}
|
|
38015
37262
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
38016
|
-
const parent =
|
|
37263
|
+
const parent = dirname5(target);
|
|
38017
37264
|
return new WorkspaceDirectoryListing(
|
|
38018
37265
|
id,
|
|
38019
37266
|
this.label(target),
|
|
@@ -38037,45 +37284,9 @@ var WorkspaceDirectoryService = class {
|
|
|
38037
37284
|
};
|
|
38038
37285
|
};
|
|
38039
37286
|
|
|
38040
|
-
// src/bots/bot-context-applicator.ts
|
|
38041
|
-
var AppliedBotContext = class {
|
|
38042
|
-
resources;
|
|
38043
|
-
constructor(resources) {
|
|
38044
|
-
this.resources = Object.freeze([...resources]);
|
|
38045
|
-
}
|
|
38046
|
-
};
|
|
38047
|
-
var EmbeddedBotContextApplicator = class {
|
|
38048
|
-
apply = async (command, execution, resources, signal) => {
|
|
38049
|
-
signal.throwIfAborted();
|
|
38050
|
-
if (execution.botId !== command.botId || execution.behaviorRevisionId !== command.behaviorRevisionId || execution.behaviorDigest !== command.behaviorDigest) {
|
|
38051
|
-
throw new LocalBotAuthorizationError(
|
|
38052
|
-
"binding_incompatible",
|
|
38053
|
-
"The Bot behavior does not match the execution target"
|
|
38054
|
-
);
|
|
38055
|
-
}
|
|
38056
|
-
if (command.behaviorInstructions.length === 0) {
|
|
38057
|
-
return new AppliedBotContext(resources);
|
|
38058
|
-
}
|
|
38059
|
-
if (!execution.agent.capabilities.embeddedContextPrompt) {
|
|
38060
|
-
throw new LocalBotAuthorizationError(
|
|
38061
|
-
"binding_incompatible",
|
|
38062
|
-
"The local Agent cannot enforce the Bot behavior context"
|
|
38063
|
-
);
|
|
38064
|
-
}
|
|
38065
|
-
const trustedContext = {
|
|
38066
|
-
mimeType: "text/markdown",
|
|
38067
|
-
name: "Mobius Bot behavior",
|
|
38068
|
-
text: command.behaviorInstructions,
|
|
38069
|
-
type: "embedded",
|
|
38070
|
-
uri: `mobius://bots/${encodeURIComponent(command.botId)}/behavior-revisions/${encodeURIComponent(command.behaviorRevisionId)}?sha256=${command.behaviorDigest}`
|
|
38071
|
-
};
|
|
38072
|
-
return new AppliedBotContext([trustedContext, ...resources]);
|
|
38073
|
-
};
|
|
38074
|
-
};
|
|
38075
|
-
|
|
38076
37287
|
// src/native-sessions/service.ts
|
|
38077
|
-
import { randomUUID as
|
|
38078
|
-
import { basename as
|
|
37288
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
37289
|
+
import { basename as basename6 } from "node:path";
|
|
38079
37290
|
|
|
38080
37291
|
// src/native-sessions/codex-history.ts
|
|
38081
37292
|
import { spawn as spawn4 } from "node:child_process";
|
|
@@ -38369,7 +37580,7 @@ var NativeSessionService = class {
|
|
|
38369
37580
|
if (authorized === null) {
|
|
38370
37581
|
return null;
|
|
38371
37582
|
}
|
|
38372
|
-
const entryId =
|
|
37583
|
+
const entryId = randomUUID2();
|
|
38373
37584
|
if (this.#entries.size >= 5e3) {
|
|
38374
37585
|
this.#entries.clear();
|
|
38375
37586
|
}
|
|
@@ -38423,7 +37634,7 @@ var NativeSessionService = class {
|
|
|
38423
37634
|
"invalid_native_session_response"
|
|
38424
37635
|
);
|
|
38425
37636
|
}
|
|
38426
|
-
nextCursor =
|
|
37637
|
+
nextCursor = randomUUID2();
|
|
38427
37638
|
if (this.#cursors.size >= 500) {
|
|
38428
37639
|
this.#cursors.clear();
|
|
38429
37640
|
}
|
|
@@ -38584,7 +37795,7 @@ var NativeSessionService = class {
|
|
|
38584
37795
|
}
|
|
38585
37796
|
resolvedPaths.add(path2);
|
|
38586
37797
|
additionalDirectories.push(path2);
|
|
38587
|
-
additionalEntries.push({ directoryId: directoryId2, name:
|
|
37798
|
+
additionalEntries.push({ directoryId: directoryId2, name: basename6(path2) });
|
|
38588
37799
|
}
|
|
38589
37800
|
const listing = await this.#directories.list(this.#config.bindingId, command.directoryId, signal);
|
|
38590
37801
|
const opened = await this.#sessions.forkSessionAtTurn(
|
|
@@ -38742,12 +37953,12 @@ var NativeSessionService = class {
|
|
|
38742
37953
|
|
|
38743
37954
|
// src/prompt-artifact-resolver.ts
|
|
38744
37955
|
import { createHash as createHash3 } from "node:crypto";
|
|
38745
|
-
import { fetch as
|
|
37956
|
+
import { fetch as fetch5 } from "undici";
|
|
38746
37957
|
var ARTIFACT_SCHEME = "mobius-artifact:";
|
|
38747
37958
|
var ARTIFACT_DOWNLOAD_TIMEOUT_MILLISECONDS = 2e4;
|
|
38748
37959
|
var MAX_AGENT_IMAGE_BASE64_LENGTH = 4e6;
|
|
38749
37960
|
var MAX_AGENT_RESOURCE_BYTE_LENGTH = 1e6;
|
|
38750
|
-
var
|
|
37961
|
+
var IDENTIFIER_PATTERN6 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
38751
37962
|
var PromptArtifactError = class extends Error {
|
|
38752
37963
|
code;
|
|
38753
37964
|
constructor(code, message, options = {}) {
|
|
@@ -38790,7 +38001,7 @@ function parseReference(resource) {
|
|
|
38790
38001
|
const encodedByteLength2 = url2.searchParams.get("byteLength") ?? "";
|
|
38791
38002
|
const sha256 = url2.searchParams.get("sha256") ?? "";
|
|
38792
38003
|
const byteLength = Number(encodedByteLength2);
|
|
38793
|
-
if (url2.protocol !== ARTIFACT_SCHEME || url2.hash.length > 0 || resource.type !== "link" || resource.text.length > 0 || !
|
|
38004
|
+
if (url2.protocol !== ARTIFACT_SCHEME || url2.hash.length > 0 || resource.type !== "link" || resource.text.length > 0 || !IDENTIFIER_PATTERN6.test(artifactId) || keys.length !== 2 || keys[0] !== "byteLength" || keys[1] !== "sha256" || !/^[1-9][0-9]*$/.test(encodedByteLength2) || !Number.isSafeInteger(byteLength) || !/^[a-f0-9]{64}$/.test(sha256)) {
|
|
38794
38005
|
throw new PromptArtifactError("artifact_reference_invalid", "The prompt artifact reference is invalid");
|
|
38795
38006
|
}
|
|
38796
38007
|
return new PromptArtifactReference(artifactId, byteLength, sha256, resource);
|
|
@@ -38856,7 +38067,7 @@ async function download(config2, command, reference, signal) {
|
|
|
38856
38067
|
const requestSignal = AbortSignal.any([signal, timeoutSignal]);
|
|
38857
38068
|
let response;
|
|
38858
38069
|
try {
|
|
38859
|
-
response = await
|
|
38070
|
+
response = await fetch5(downloadUrl(config2, command, reference), {
|
|
38860
38071
|
dispatcher: environmentProxyDispatcher,
|
|
38861
38072
|
headers: {
|
|
38862
38073
|
accept: reference.resource.mimeType,
|
|
@@ -39189,7 +38400,7 @@ var RelayConnectionDiagnostics = class {
|
|
|
39189
38400
|
};
|
|
39190
38401
|
|
|
39191
38402
|
// src/relay-connection/liveness.ts
|
|
39192
|
-
import { randomUUID as
|
|
38403
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
39193
38404
|
var HEARTBEAT_ACK_TIMEOUT_MILLISECONDS = 1e4;
|
|
39194
38405
|
var HEARTBEAT_INTERVAL_MILLISECONDS = 2e4;
|
|
39195
38406
|
var RelayLivenessState = class {
|
|
@@ -39278,7 +38489,7 @@ var RelayConnectionLiveness = class {
|
|
|
39278
38489
|
}
|
|
39279
38490
|
throw new Error("Heartbeat was scheduled in an invalid state");
|
|
39280
38491
|
}
|
|
39281
|
-
const heartbeatId =
|
|
38492
|
+
const heartbeatId = randomUUID3();
|
|
39282
38493
|
this.#state = new AwaitingHeartbeatAckState(
|
|
39283
38494
|
heartbeatId,
|
|
39284
38495
|
this.#timer.schedule(this.#handleTimeout, HEARTBEAT_ACK_TIMEOUT_MILLISECONDS)
|
|
@@ -39294,7 +38505,7 @@ var RelayConnectionLiveness = class {
|
|
|
39294
38505
|
|
|
39295
38506
|
// src/relay-connection/session-event-outbox.ts
|
|
39296
38507
|
import { mkdirSync as mkdirSync3 } from "node:fs";
|
|
39297
|
-
import { dirname as
|
|
38508
|
+
import { dirname as dirname6 } from "node:path";
|
|
39298
38509
|
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
39299
38510
|
var DEFAULT_OUTBOX_LIMITS = {
|
|
39300
38511
|
criticalEventBytes: 136 * 1024 * 1024,
|
|
@@ -39360,7 +38571,7 @@ var SessionEventOutbox = class {
|
|
|
39360
38571
|
constructor(path2, limits = DEFAULT_OUTBOX_LIMITS) {
|
|
39361
38572
|
validateLimits(limits);
|
|
39362
38573
|
this.#limits = limits;
|
|
39363
|
-
mkdirSync3(
|
|
38574
|
+
mkdirSync3(dirname6(path2), { recursive: true });
|
|
39364
38575
|
this.#database = new DatabaseSync3(path2);
|
|
39365
38576
|
this.#database.exec(`
|
|
39366
38577
|
CREATE TABLE IF NOT EXISTS relay_session_event_outbox (
|
|
@@ -39893,12 +39104,6 @@ var RELAY_RECONNECT_DELAY_MILLISECONDS = 500;
|
|
|
39893
39104
|
var AGENT_ACTIVITY_COALESCING_MILLISECONDS = 100;
|
|
39894
39105
|
var ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS = 2e4;
|
|
39895
39106
|
var ACTIVE_TURN_RECONCILIATION_CLOSE_CODE = 4009;
|
|
39896
|
-
function botIpcSocketPath() {
|
|
39897
|
-
if (process.platform === "win32") {
|
|
39898
|
-
return `\\\\.\\pipe\\mobius-bot-${randomUUID5()}`;
|
|
39899
|
-
}
|
|
39900
|
-
return join17("/tmp", `mobius-bot-${randomUUID5()}.sock`);
|
|
39901
|
-
}
|
|
39902
39107
|
var DaemonAcpObserver = class {
|
|
39903
39108
|
#config;
|
|
39904
39109
|
#record;
|
|
@@ -40116,7 +39321,7 @@ async function reconcileActiveTurn(config2, turn, signal) {
|
|
|
40116
39321
|
const requestSignal = AbortSignal.any([signal, timeoutSignal]);
|
|
40117
39322
|
let response;
|
|
40118
39323
|
try {
|
|
40119
|
-
response = await
|
|
39324
|
+
response = await fetch6(activeTurnReconciliationEndpoint(config2, turn), {
|
|
40120
39325
|
body: JSON.stringify({ outcome: { kind: "running" } }),
|
|
40121
39326
|
dispatcher: environmentProxyDispatcher,
|
|
40122
39327
|
headers: { ...runtimeAuthorization(config2.relayUrl), "content-type": "application/json" },
|
|
@@ -40428,13 +39633,13 @@ function reportFailure(publisher, command, code, message, attemptId) {
|
|
|
40428
39633
|
);
|
|
40429
39634
|
}
|
|
40430
39635
|
function operationErrorCode(error62) {
|
|
40431
|
-
if (error62 instanceof AcpExecutionError || error62 instanceof LocalAuthorizationError || error62 instanceof LocalAgentCatalogError || error62 instanceof
|
|
39636
|
+
if (error62 instanceof AcpExecutionError || error62 instanceof LocalAuthorizationError || error62 instanceof LocalAgentCatalogError || error62 instanceof PromptArtifactError) {
|
|
40432
39637
|
return error62.code;
|
|
40433
39638
|
}
|
|
40434
39639
|
return "session_operation_failed";
|
|
40435
39640
|
}
|
|
40436
39641
|
function operationErrorMessage(error62) {
|
|
40437
|
-
if (error62 instanceof AcpExecutionError || error62 instanceof LocalAuthorizationError || error62 instanceof LocalAgentCatalogError || error62 instanceof
|
|
39642
|
+
if (error62 instanceof AcpExecutionError || error62 instanceof LocalAuthorizationError || error62 instanceof LocalAgentCatalogError || error62 instanceof PromptArtifactError) {
|
|
40438
39643
|
return error62.message;
|
|
40439
39644
|
}
|
|
40440
39645
|
return "The local agent operation could not be completed";
|
|
@@ -40469,7 +39674,7 @@ async function resolveSessionDirectories(directories, bindingId, directoryId2, a
|
|
|
40469
39674
|
additionalDirectories.push(directory);
|
|
40470
39675
|
additionalDirectoryEntries.push({
|
|
40471
39676
|
directoryId: additionalDirectoryId,
|
|
40472
|
-
name:
|
|
39677
|
+
name: basename7(directory)
|
|
40473
39678
|
});
|
|
40474
39679
|
}
|
|
40475
39680
|
return new ResolvedSessionDirectories(cwd, additionalDirectories, additionalDirectoryEntries);
|
|
@@ -40699,11 +39904,13 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
40699
39904
|
} else {
|
|
40700
39905
|
await applyCompleteSessionConfiguration(
|
|
40701
39906
|
sessions,
|
|
39907
|
+
audit,
|
|
40702
39908
|
prepared.configOptions,
|
|
40703
39909
|
command.sessionConfigurations,
|
|
40704
39910
|
agent,
|
|
40705
39911
|
resolved.cwd,
|
|
40706
39912
|
resolved.additionalDirectories,
|
|
39913
|
+
command.commandId,
|
|
40707
39914
|
command.sessionId,
|
|
40708
39915
|
signal
|
|
40709
39916
|
);
|
|
@@ -40812,11 +40019,11 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
40812
40019
|
function invalidSessionConfiguration(message) {
|
|
40813
40020
|
return new AcpExecutionError(message, {}, "invalid_session_configuration");
|
|
40814
40021
|
}
|
|
40815
|
-
function validateSessionConfigurationSelection(
|
|
40816
|
-
if (
|
|
40022
|
+
function validateSessionConfigurationSelection(option, selection) {
|
|
40023
|
+
if (option.type !== selection.valueType) {
|
|
40817
40024
|
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} changed type`);
|
|
40818
40025
|
}
|
|
40819
|
-
if (
|
|
40026
|
+
if (option.type === "boolean") {
|
|
40820
40027
|
if (selection.value.length > 0) {
|
|
40821
40028
|
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} has an invalid value`);
|
|
40822
40029
|
}
|
|
@@ -40825,7 +40032,7 @@ function validateSessionConfigurationSelection(option2, selection) {
|
|
|
40825
40032
|
if (selection.booleanValue) {
|
|
40826
40033
|
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} has an invalid value`);
|
|
40827
40034
|
}
|
|
40828
|
-
if (!
|
|
40035
|
+
if (!option.values.some((value) => value.value === selection.value)) {
|
|
40829
40036
|
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} has an unavailable value`);
|
|
40830
40037
|
}
|
|
40831
40038
|
}
|
|
@@ -40837,29 +40044,49 @@ function assertSessionConfigurationSchema(options, selections) {
|
|
|
40837
40044
|
if (selectionsById.size !== selections.length) {
|
|
40838
40045
|
throw invalidSessionConfiguration("The Turn configuration contains duplicate Agent settings");
|
|
40839
40046
|
}
|
|
40840
|
-
for (const
|
|
40841
|
-
const selection = selectionsById.get(
|
|
40842
|
-
if (selection === void 0 || selection.valueType !==
|
|
40843
|
-
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${
|
|
40047
|
+
for (const option of options) {
|
|
40048
|
+
const selection = selectionsById.get(option.id);
|
|
40049
|
+
if (selection === void 0 || selection.valueType !== option.type || option.type === "boolean" && selection.value.length > 0 || option.type === "select" && selection.booleanValue) {
|
|
40050
|
+
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
|
|
40844
40051
|
}
|
|
40845
40052
|
}
|
|
40846
40053
|
}
|
|
40847
|
-
function
|
|
40848
|
-
|
|
40849
|
-
|
|
40054
|
+
function assertSessionConfigurationCoverage(options, selections) {
|
|
40055
|
+
const selectionsById = new Map(selections.map((selection) => [selection.configId, selection]));
|
|
40056
|
+
if (selectionsById.size !== selections.length) {
|
|
40057
|
+
throw invalidSessionConfiguration("The Turn configuration contains duplicate Agent settings");
|
|
40058
|
+
}
|
|
40059
|
+
for (const option of options) {
|
|
40060
|
+
if (!selectionsById.has(option.id)) {
|
|
40061
|
+
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
|
|
40062
|
+
}
|
|
40063
|
+
}
|
|
40064
|
+
}
|
|
40065
|
+
function sessionConfigurationSelectionIsAvailable(option, selection) {
|
|
40066
|
+
if (option.type !== selection.valueType) {
|
|
40067
|
+
return false;
|
|
40068
|
+
}
|
|
40069
|
+
if (option.type === "boolean") {
|
|
40070
|
+
return selection.value.length === 0;
|
|
40071
|
+
}
|
|
40072
|
+
return !selection.booleanValue && option.values.some((value) => value.value === selection.value);
|
|
40073
|
+
}
|
|
40074
|
+
function sessionConfigurationMatches(option, selection) {
|
|
40075
|
+
validateSessionConfigurationSelection(option, selection);
|
|
40076
|
+
return option.type === "boolean" ? option.booleanValue === selection.booleanValue : option.currentValue === selection.value;
|
|
40850
40077
|
}
|
|
40851
40078
|
function sessionConfigurationPriority(selection, options) {
|
|
40852
40079
|
if (selection.configId === "permission_mode") {
|
|
40853
40080
|
return 0;
|
|
40854
40081
|
}
|
|
40855
|
-
const
|
|
40856
|
-
if (selection.configId === "model" ||
|
|
40082
|
+
const option = options.find((candidate) => candidate.id === selection.configId);
|
|
40083
|
+
if (selection.configId === "model" || option?.category === "model") {
|
|
40857
40084
|
return 1;
|
|
40858
40085
|
}
|
|
40859
|
-
if (selection.configId === "reasoning_effort" ||
|
|
40086
|
+
if (selection.configId === "reasoning_effort" || option?.category === "thought_level") {
|
|
40860
40087
|
return 2;
|
|
40861
40088
|
}
|
|
40862
|
-
if (
|
|
40089
|
+
if (option?.category === "model_config") {
|
|
40863
40090
|
return 3;
|
|
40864
40091
|
}
|
|
40865
40092
|
return 4;
|
|
@@ -40867,19 +40094,100 @@ function sessionConfigurationPriority(selection, options) {
|
|
|
40867
40094
|
function assertCompleteSessionConfiguration(options, selections) {
|
|
40868
40095
|
assertSessionConfigurationSchema(options, selections);
|
|
40869
40096
|
const selectionsById = new Map(selections.map((selection) => [selection.configId, selection]));
|
|
40870
|
-
for (const
|
|
40871
|
-
const selection = selectionsById.get(
|
|
40872
|
-
if (selection === void 0 || !sessionConfigurationMatches(
|
|
40873
|
-
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${
|
|
40097
|
+
for (const option of options) {
|
|
40098
|
+
const selection = selectionsById.get(option.id);
|
|
40099
|
+
if (selection === void 0 || !sessionConfigurationMatches(option, selection)) {
|
|
40100
|
+
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
|
|
40101
|
+
}
|
|
40102
|
+
}
|
|
40103
|
+
}
|
|
40104
|
+
function assertAppliedSessionConfiguration(options, selections) {
|
|
40105
|
+
const selectionsById = new Map(selections.map((selection) => [selection.configId, selection]));
|
|
40106
|
+
for (const option of options) {
|
|
40107
|
+
const selection = selectionsById.get(option.id);
|
|
40108
|
+
if (option.id === AGENT_PERMISSION_MODE_CONFIG_ID) {
|
|
40109
|
+
if (selection === void 0 || !sessionConfigurationMatches(option, selection)) {
|
|
40110
|
+
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
|
|
40111
|
+
}
|
|
40112
|
+
continue;
|
|
40113
|
+
}
|
|
40114
|
+
if (selection === void 0 || !sessionConfigurationSelectionIsAvailable(option, selection)) {
|
|
40115
|
+
continue;
|
|
40116
|
+
}
|
|
40117
|
+
if (!sessionConfigurationMatches(option, selection)) {
|
|
40118
|
+
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
|
|
40874
40119
|
}
|
|
40875
40120
|
}
|
|
40876
40121
|
}
|
|
40877
|
-
|
|
40878
|
-
|
|
40879
|
-
|
|
40122
|
+
function unavailableSessionConfigurationCategory(selection) {
|
|
40123
|
+
if (selection.configId === "model") {
|
|
40124
|
+
return "model";
|
|
40125
|
+
}
|
|
40126
|
+
if (selection.configId === "reasoning_effort") {
|
|
40127
|
+
return "thought_level";
|
|
40128
|
+
}
|
|
40129
|
+
return "unknown";
|
|
40130
|
+
}
|
|
40131
|
+
async function applySessionConfigurationSelection(sessions, audit, options, selection, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
|
|
40132
|
+
const option = options.find((candidate) => candidate.id === selection.configId);
|
|
40133
|
+
if (option === void 0) {
|
|
40134
|
+
if (selection.configId !== AGENT_PERMISSION_MODE_CONFIG_ID) {
|
|
40135
|
+
warnIgnoredSetting(
|
|
40136
|
+
audit,
|
|
40137
|
+
"session_configuration_setting_ignored",
|
|
40138
|
+
commandId,
|
|
40139
|
+
sessionId,
|
|
40140
|
+
agent.id,
|
|
40141
|
+
selection,
|
|
40142
|
+
unavailableSessionConfigurationCategory(selection),
|
|
40143
|
+
"setting_unavailable"
|
|
40144
|
+
);
|
|
40145
|
+
return options;
|
|
40146
|
+
}
|
|
40880
40147
|
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} is unavailable`);
|
|
40881
40148
|
}
|
|
40882
|
-
if (
|
|
40149
|
+
if (selection.configId !== AGENT_PERMISSION_MODE_CONFIG_ID) {
|
|
40150
|
+
if (option.type !== selection.valueType) {
|
|
40151
|
+
warnIgnoredSetting(
|
|
40152
|
+
audit,
|
|
40153
|
+
"session_configuration_setting_ignored",
|
|
40154
|
+
commandId,
|
|
40155
|
+
sessionId,
|
|
40156
|
+
agent.id,
|
|
40157
|
+
selection,
|
|
40158
|
+
option.category,
|
|
40159
|
+
"setting_schema_mismatch"
|
|
40160
|
+
);
|
|
40161
|
+
return options;
|
|
40162
|
+
}
|
|
40163
|
+
if (option.type === "boolean" && selection.value.length > 0 || option.type === "select" && selection.booleanValue) {
|
|
40164
|
+
warnIgnoredSetting(
|
|
40165
|
+
audit,
|
|
40166
|
+
"session_configuration_setting_ignored",
|
|
40167
|
+
commandId,
|
|
40168
|
+
sessionId,
|
|
40169
|
+
agent.id,
|
|
40170
|
+
selection,
|
|
40171
|
+
option.category,
|
|
40172
|
+
"selection_schema_mismatch"
|
|
40173
|
+
);
|
|
40174
|
+
return options;
|
|
40175
|
+
}
|
|
40176
|
+
if (option.type === "select" && !option.values.some((value) => value.value === selection.value)) {
|
|
40177
|
+
warnIgnoredSetting(
|
|
40178
|
+
audit,
|
|
40179
|
+
"session_configuration_setting_ignored",
|
|
40180
|
+
commandId,
|
|
40181
|
+
sessionId,
|
|
40182
|
+
agent.id,
|
|
40183
|
+
selection,
|
|
40184
|
+
option.category,
|
|
40185
|
+
"value_unavailable"
|
|
40186
|
+
);
|
|
40187
|
+
return options;
|
|
40188
|
+
}
|
|
40189
|
+
}
|
|
40190
|
+
if (sessionConfigurationMatches(option, selection)) {
|
|
40883
40191
|
return options;
|
|
40884
40192
|
}
|
|
40885
40193
|
return await sessions.configureSession({
|
|
@@ -40888,15 +40196,15 @@ async function applySessionConfigurationSelection(sessions, options, selection,
|
|
|
40888
40196
|
booleanValue: selection.booleanValue,
|
|
40889
40197
|
configId: selection.configId,
|
|
40890
40198
|
cwd,
|
|
40891
|
-
requestId: `cfg_${
|
|
40199
|
+
requestId: `cfg_${randomUUID4()}`,
|
|
40892
40200
|
sessionId,
|
|
40893
40201
|
signal,
|
|
40894
40202
|
value: selection.value,
|
|
40895
40203
|
valueType: selection.valueType
|
|
40896
40204
|
});
|
|
40897
40205
|
}
|
|
40898
|
-
async function applyCompleteSessionConfiguration(sessions, initialOptions, selections, agent, cwd, additionalDirectories, sessionId, signal) {
|
|
40899
|
-
|
|
40206
|
+
async function applyCompleteSessionConfiguration(sessions, audit, initialOptions, selections, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
|
|
40207
|
+
assertSessionConfigurationCoverage(initialOptions, selections);
|
|
40900
40208
|
let options = initialOptions;
|
|
40901
40209
|
const orderedSelections = selections.toSorted((left, right) => {
|
|
40902
40210
|
const priority = sessionConfigurationPriority(left, initialOptions) - sessionConfigurationPriority(right, initialOptions);
|
|
@@ -40905,50 +40213,20 @@ async function applyCompleteSessionConfiguration(sessions, initialOptions, selec
|
|
|
40905
40213
|
for (const selection of orderedSelections) {
|
|
40906
40214
|
options = await applySessionConfigurationSelection(
|
|
40907
40215
|
sessions,
|
|
40216
|
+
audit,
|
|
40908
40217
|
options,
|
|
40909
40218
|
selection,
|
|
40910
40219
|
agent,
|
|
40911
40220
|
cwd,
|
|
40912
40221
|
additionalDirectories,
|
|
40222
|
+
commandId,
|
|
40913
40223
|
sessionId,
|
|
40914
40224
|
signal
|
|
40915
40225
|
);
|
|
40916
40226
|
}
|
|
40917
|
-
|
|
40918
|
-
}
|
|
40919
|
-
function botExecutionAgent(agent, contextHandle, socketPath) {
|
|
40920
|
-
return new LocalAgentDefinition(
|
|
40921
|
-
agent.id,
|
|
40922
|
-
agent.label,
|
|
40923
|
-
agent.command,
|
|
40924
|
-
agent.arguments,
|
|
40925
|
-
{
|
|
40926
|
-
...agent.environment,
|
|
40927
|
-
MOBIUS_BOT_CONTEXT: contextHandle,
|
|
40928
|
-
MOBIUS_BOT_SOCKET: socketPath,
|
|
40929
|
-
MOBIUS_RELAY_TOKEN: "",
|
|
40930
|
-
MOBIUS_RELAY_URL: ""
|
|
40931
|
-
},
|
|
40932
|
-
agent.adapterVersion,
|
|
40933
|
-
agent.agentVersion,
|
|
40934
|
-
agent.adapterIdentity,
|
|
40935
|
-
agent.agentIdentity,
|
|
40936
|
-
agent.promptTimeoutMilliseconds,
|
|
40937
|
-
agent.capabilities,
|
|
40938
|
-
agent.permissionProfile
|
|
40939
|
-
);
|
|
40940
|
-
}
|
|
40941
|
-
function assertPreparedPermission(configOptions, permissionMode) {
|
|
40942
|
-
const permission = configOptions.find((option2) => option2.id === "permission_mode");
|
|
40943
|
-
if (permission === void 0 || permission.type !== "select" || permissionMode !== AGENT_DEFAULT_EXECUTION_SETTING && permission.currentValue !== permissionMode) {
|
|
40944
|
-
throw new AcpExecutionError(
|
|
40945
|
-
"The required Agent permission mode is unavailable",
|
|
40946
|
-
{},
|
|
40947
|
-
"invalid_session_configuration"
|
|
40948
|
-
);
|
|
40949
|
-
}
|
|
40227
|
+
assertAppliedSessionConfiguration(options, selections);
|
|
40950
40228
|
}
|
|
40951
|
-
function
|
|
40229
|
+
function warnIgnoredSetting(audit, event, commandId, sessionId, agentId, selection, category, reason) {
|
|
40952
40230
|
const details = {
|
|
40953
40231
|
agentId,
|
|
40954
40232
|
category,
|
|
@@ -40956,264 +40234,10 @@ function warnIgnoredExecutionSetting(audit, commandId, sessionId, agentId, selec
|
|
|
40956
40234
|
reason,
|
|
40957
40235
|
requestedValue: selection.value
|
|
40958
40236
|
};
|
|
40959
|
-
const event = "bot_execution_setting_ignored";
|
|
40960
40237
|
audit.record({ commandId, details, event, sessionId });
|
|
40961
40238
|
process.stderr.write(`Mobius daemon warning ${JSON.stringify({ commandId, event, sessionId, ...details })}
|
|
40962
40239
|
`);
|
|
40963
40240
|
}
|
|
40964
|
-
async function applySupportedExecutionSelection(sessions, audit, configOptions, selection, category, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
|
|
40965
|
-
if (selection.value === AGENT_DEFAULT_EXECUTION_SETTING) {
|
|
40966
|
-
return configOptions;
|
|
40967
|
-
}
|
|
40968
|
-
const option2 = configOptions.find((candidate) => candidate.id === selection.configId);
|
|
40969
|
-
if (option2 === void 0) {
|
|
40970
|
-
warnIgnoredExecutionSetting(audit, commandId, sessionId, agent.id, selection, category, "setting_unavailable");
|
|
40971
|
-
return configOptions;
|
|
40972
|
-
}
|
|
40973
|
-
if (option2.type !== "select" || option2.category !== category) {
|
|
40974
|
-
warnIgnoredExecutionSetting(
|
|
40975
|
-
audit,
|
|
40976
|
-
commandId,
|
|
40977
|
-
sessionId,
|
|
40978
|
-
agent.id,
|
|
40979
|
-
selection,
|
|
40980
|
-
category,
|
|
40981
|
-
"setting_schema_mismatch"
|
|
40982
|
-
);
|
|
40983
|
-
return configOptions;
|
|
40984
|
-
}
|
|
40985
|
-
if (selection.valueType !== "select" || selection.booleanValue) {
|
|
40986
|
-
warnIgnoredExecutionSetting(
|
|
40987
|
-
audit,
|
|
40988
|
-
commandId,
|
|
40989
|
-
sessionId,
|
|
40990
|
-
agent.id,
|
|
40991
|
-
selection,
|
|
40992
|
-
category,
|
|
40993
|
-
"selection_schema_mismatch"
|
|
40994
|
-
);
|
|
40995
|
-
return configOptions;
|
|
40996
|
-
}
|
|
40997
|
-
if (!option2.values.some((value) => value.value === selection.value)) {
|
|
40998
|
-
warnIgnoredExecutionSetting(audit, commandId, sessionId, agent.id, selection, category, "value_unavailable");
|
|
40999
|
-
return configOptions;
|
|
41000
|
-
}
|
|
41001
|
-
if (option2.currentValue === selection.value) {
|
|
41002
|
-
return configOptions;
|
|
41003
|
-
}
|
|
41004
|
-
return await sessions.configureSession({
|
|
41005
|
-
additionalDirectories,
|
|
41006
|
-
agent,
|
|
41007
|
-
booleanValue: false,
|
|
41008
|
-
configId: selection.configId,
|
|
41009
|
-
cwd,
|
|
41010
|
-
requestId: `cfg_${randomUUID5()}`,
|
|
41011
|
-
sessionId,
|
|
41012
|
-
signal,
|
|
41013
|
-
value: selection.value,
|
|
41014
|
-
valueType: "select"
|
|
41015
|
-
});
|
|
41016
|
-
}
|
|
41017
|
-
async function executeBotPrompt(outbox, publisher, command, config2, directories, audit, sessions, authorizer, contexts, applicator, ipc, attemptId, activateAttempt, timer, signal) {
|
|
41018
|
-
const activities = new CoalescingDaemonActivityPublisher(timer, (activity) => {
|
|
41019
|
-
publisher.recordAttempt(command.sessionId, encodeDaemonActivity(command, activity), attemptId);
|
|
41020
|
-
});
|
|
41021
|
-
try {
|
|
41022
|
-
const deadline = Date.parse(command.executionDeadlineAt);
|
|
41023
|
-
const remaining = deadline - Date.now();
|
|
41024
|
-
if (!Number.isSafeInteger(deadline) || remaining <= 0) {
|
|
41025
|
-
throw new LocalBotAuthorizationError("turn_expired", "The Bot execution deadline has expired");
|
|
41026
|
-
}
|
|
41027
|
-
const execution = await authorizer.authorize(command, config2.catalog, directories, config2.bindingId, signal);
|
|
41028
|
-
const resolved = await resolveSessionDirectories(
|
|
41029
|
-
directories,
|
|
41030
|
-
config2.bindingId,
|
|
41031
|
-
command.directoryId,
|
|
41032
|
-
command.additionalDirectoryIds,
|
|
41033
|
-
signal
|
|
41034
|
-
);
|
|
41035
|
-
const attachments = await resolvePromptArtifacts(config2, command, signal);
|
|
41036
|
-
const applied = await applicator.apply(command, execution, attachments.resources, signal);
|
|
41037
|
-
const deadlineSignal = AbortSignal.timeout(remaining);
|
|
41038
|
-
const executionSignal = AbortSignal.any([signal, deadlineSignal]);
|
|
41039
|
-
const startExecution = () => {
|
|
41040
|
-
audit.record({
|
|
41041
|
-
commandId: command.commandId,
|
|
41042
|
-
details: {
|
|
41043
|
-
behaviorRevisionId: command.behaviorRevisionId,
|
|
41044
|
-
bindingId: command.bindingId,
|
|
41045
|
-
botId: command.botId,
|
|
41046
|
-
executionId: command.executionId
|
|
41047
|
-
},
|
|
41048
|
-
event: "bot_session_authorized",
|
|
41049
|
-
sessionId: command.sessionId
|
|
41050
|
-
});
|
|
41051
|
-
outbox.transitionExecution(command.commandId, "running");
|
|
41052
|
-
publisher.recordAttempt(
|
|
41053
|
-
command.sessionId,
|
|
41054
|
-
encodeSessionStartedEvent({
|
|
41055
|
-
attemptId,
|
|
41056
|
-
commandId: command.commandId,
|
|
41057
|
-
kind: SESSION_STARTED_KIND,
|
|
41058
|
-
sessionId: command.sessionId
|
|
41059
|
-
}),
|
|
41060
|
-
attemptId
|
|
41061
|
-
);
|
|
41062
|
-
activateAttempt();
|
|
41063
|
-
};
|
|
41064
|
-
let stopReason = "steered";
|
|
41065
|
-
if (command.disposition === SessionPromptDisposition.Steer) {
|
|
41066
|
-
startExecution();
|
|
41067
|
-
await sessions.steerPrompt({
|
|
41068
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
41069
|
-
agent: execution.agent,
|
|
41070
|
-
commandId: command.commandId,
|
|
41071
|
-
cwd: resolved.cwd,
|
|
41072
|
-
images: attachments.images,
|
|
41073
|
-
prompt: command.prompt,
|
|
41074
|
-
resources: applied.resources,
|
|
41075
|
-
sessionId: command.sessionId,
|
|
41076
|
-
signal: executionSignal,
|
|
41077
|
-
targetCommandId: command.targetCommandId
|
|
41078
|
-
});
|
|
41079
|
-
} else {
|
|
41080
|
-
if (command.disposition === SessionPromptDisposition.Queue && !outbox.isTerminalExecution(command.targetCommandId, command.sessionId)) {
|
|
41081
|
-
throw new AcpExecutionError(
|
|
41082
|
-
"The queued Bot prompt target is unavailable",
|
|
41083
|
-
{},
|
|
41084
|
-
"prompt_queue_target_unavailable"
|
|
41085
|
-
);
|
|
41086
|
-
}
|
|
41087
|
-
const lease = contexts.activate(command);
|
|
41088
|
-
try {
|
|
41089
|
-
const agent = botExecutionAgent(execution.agent, lease.context.contextHandle, ipc.socketPath);
|
|
41090
|
-
const prepared = await sessions.prepareExecutionSession({
|
|
41091
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
41092
|
-
agent,
|
|
41093
|
-
cwd: resolved.cwd,
|
|
41094
|
-
sessionId: command.sessionId,
|
|
41095
|
-
signal: executionSignal
|
|
41096
|
-
});
|
|
41097
|
-
assertPreparedPermission(prepared.configOptions, execution.executionConfiguration.permissionMode);
|
|
41098
|
-
let configOptions = await applySupportedExecutionSelection(
|
|
41099
|
-
sessions,
|
|
41100
|
-
audit,
|
|
41101
|
-
prepared.configOptions,
|
|
41102
|
-
execution.executionConfiguration.model,
|
|
41103
|
-
"model",
|
|
41104
|
-
agent,
|
|
41105
|
-
resolved.cwd,
|
|
41106
|
-
resolved.additionalDirectories,
|
|
41107
|
-
command.commandId,
|
|
41108
|
-
command.sessionId,
|
|
41109
|
-
executionSignal
|
|
41110
|
-
);
|
|
41111
|
-
configOptions = await applySupportedExecutionSelection(
|
|
41112
|
-
sessions,
|
|
41113
|
-
audit,
|
|
41114
|
-
configOptions,
|
|
41115
|
-
execution.executionConfiguration.reasoningEffort,
|
|
41116
|
-
"thought_level",
|
|
41117
|
-
agent,
|
|
41118
|
-
resolved.cwd,
|
|
41119
|
-
resolved.additionalDirectories,
|
|
41120
|
-
command.commandId,
|
|
41121
|
-
command.sessionId,
|
|
41122
|
-
executionSignal
|
|
41123
|
-
);
|
|
41124
|
-
for (const selection of command.sessionConfigurations) {
|
|
41125
|
-
await sessions.configureSession({
|
|
41126
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
41127
|
-
agent,
|
|
41128
|
-
booleanValue: selection.booleanValue,
|
|
41129
|
-
configId: selection.configId,
|
|
41130
|
-
cwd: resolved.cwd,
|
|
41131
|
-
requestId: `cfg_${randomUUID5()}`,
|
|
41132
|
-
sessionId: command.sessionId,
|
|
41133
|
-
signal: executionSignal,
|
|
41134
|
-
value: selection.value,
|
|
41135
|
-
valueType: selection.valueType
|
|
41136
|
-
});
|
|
41137
|
-
}
|
|
41138
|
-
startExecution();
|
|
41139
|
-
const result = await sessions.runPrompt({
|
|
41140
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
41141
|
-
agent,
|
|
41142
|
-
commandId: command.commandId,
|
|
41143
|
-
cwd: resolved.cwd,
|
|
41144
|
-
disposition: command.disposition,
|
|
41145
|
-
images: attachments.images,
|
|
41146
|
-
onActivity: activities.record,
|
|
41147
|
-
onText: (text3, messageId) => {
|
|
41148
|
-
publisher.recordAttempt(
|
|
41149
|
-
command.sessionId,
|
|
41150
|
-
encodeAgentMessageDeltaEvent({
|
|
41151
|
-
commandId: command.commandId,
|
|
41152
|
-
kind: AGENT_MESSAGE_DELTA_KIND,
|
|
41153
|
-
messageId,
|
|
41154
|
-
sessionId: command.sessionId,
|
|
41155
|
-
text: text3
|
|
41156
|
-
}),
|
|
41157
|
-
attemptId
|
|
41158
|
-
);
|
|
41159
|
-
return Promise.resolve();
|
|
41160
|
-
},
|
|
41161
|
-
prompt: command.prompt,
|
|
41162
|
-
resources: applied.resources,
|
|
41163
|
-
sessionId: command.sessionId,
|
|
41164
|
-
signal: executionSignal,
|
|
41165
|
-
targetCommandId: command.targetCommandId
|
|
41166
|
-
});
|
|
41167
|
-
stopReason = result.stopReason;
|
|
41168
|
-
} finally {
|
|
41169
|
-
lease.release();
|
|
41170
|
-
}
|
|
41171
|
-
}
|
|
41172
|
-
activities.flush();
|
|
41173
|
-
publisher.recordAttempt(
|
|
41174
|
-
command.sessionId,
|
|
41175
|
-
encodeSessionCompletedEvent({
|
|
41176
|
-
commandId: command.commandId,
|
|
41177
|
-
kind: SESSION_COMPLETED_KIND,
|
|
41178
|
-
sessionId: command.sessionId,
|
|
41179
|
-
stopReason
|
|
41180
|
-
}),
|
|
41181
|
-
attemptId
|
|
41182
|
-
);
|
|
41183
|
-
outbox.transitionExecution(command.commandId, stopReason === "cancelled" ? "cancelled" : "succeeded");
|
|
41184
|
-
audit.record({
|
|
41185
|
-
commandId: command.commandId,
|
|
41186
|
-
details: { botId: command.botId, executionId: command.executionId },
|
|
41187
|
-
event: stopReason === "cancelled" ? "bot_session_cancelled" : "bot_session_completed",
|
|
41188
|
-
sessionId: command.sessionId
|
|
41189
|
-
});
|
|
41190
|
-
} catch (error62) {
|
|
41191
|
-
activities.flush();
|
|
41192
|
-
const failure2 = Date.parse(command.executionDeadlineAt) <= Date.now() ? new LocalBotAuthorizationError("turn_expired", "The Bot execution deadline has expired", {
|
|
41193
|
-
cause: error62
|
|
41194
|
-
}) : error62;
|
|
41195
|
-
audit.record({
|
|
41196
|
-
commandId: command.commandId,
|
|
41197
|
-
details: {
|
|
41198
|
-
botId: command.botId,
|
|
41199
|
-
code: operationErrorCode(failure2),
|
|
41200
|
-
executionId: command.executionId
|
|
41201
|
-
},
|
|
41202
|
-
event: "bot_session_failed",
|
|
41203
|
-
sessionId: command.sessionId
|
|
41204
|
-
});
|
|
41205
|
-
const code = operationErrorCode(failure2);
|
|
41206
|
-
reportFailure(
|
|
41207
|
-
publisher,
|
|
41208
|
-
command,
|
|
41209
|
-
code === "session_operation_failed" ? "agent_execution_failed" : code,
|
|
41210
|
-
code === "session_operation_failed" ? "The local agent could not complete the Bot request" : operationErrorMessage(failure2),
|
|
41211
|
-
attemptId
|
|
41212
|
-
);
|
|
41213
|
-
outbox.transitionExecution(command.commandId, "failed");
|
|
41214
|
-
console.error("Mobius daemon Bot command failed", failure2);
|
|
41215
|
-
}
|
|
41216
|
-
}
|
|
41217
40241
|
function waitForRelayRetry(signal, timer) {
|
|
41218
40242
|
if (signal.aborted) {
|
|
41219
40243
|
return Promise.resolve();
|
|
@@ -41260,13 +40284,13 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
|
|
|
41260
40284
|
{
|
|
41261
40285
|
agentId: agent.id,
|
|
41262
40286
|
kind: AGENT_INSTALL_REQUEST_KIND,
|
|
41263
|
-
requestId: `automatic-integration-${
|
|
40287
|
+
requestId: `automatic-integration-${randomUUID4()}`
|
|
41264
40288
|
},
|
|
41265
40289
|
signal
|
|
41266
40290
|
);
|
|
41267
40291
|
}
|
|
41268
40292
|
}
|
|
41269
|
-
async function runRelayConnection(config2, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher,
|
|
40293
|
+
async function runRelayConnection(config2, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher, activeTurns, activeAttemptIds, connectionEpoch, diagnostics, onConnected, signal, timer) {
|
|
41270
40294
|
const relayUrl = new URL(config2.relayUrl);
|
|
41271
40295
|
relayUrl.searchParams.set("deliveryReceipts", "1");
|
|
41272
40296
|
relayUrl.searchParams.set("liveness", "1");
|
|
@@ -41432,32 +40456,6 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
41432
40456
|
}
|
|
41433
40457
|
return;
|
|
41434
40458
|
}
|
|
41435
|
-
if (kind === BOT_SESSION_PROMPT_KIND) {
|
|
41436
|
-
const command = decodeBotSessionPromptCommand(delivery.payload);
|
|
41437
|
-
await processDeliveredPrompt(
|
|
41438
|
-
delivery,
|
|
41439
|
-
command,
|
|
41440
|
-
command.disposition !== SessionPromptDisposition.Steer,
|
|
41441
|
-
(attemptId, activateAttempt, executionSignal) => executeBotPrompt(
|
|
41442
|
-
outbox,
|
|
41443
|
-
publisher,
|
|
41444
|
-
command,
|
|
41445
|
-
config2,
|
|
41446
|
-
directories,
|
|
41447
|
-
audit,
|
|
41448
|
-
sessions,
|
|
41449
|
-
authorizer,
|
|
41450
|
-
contexts,
|
|
41451
|
-
applicator,
|
|
41452
|
-
ipc,
|
|
41453
|
-
attemptId,
|
|
41454
|
-
activateAttempt,
|
|
41455
|
-
timer,
|
|
41456
|
-
executionSignal
|
|
41457
|
-
)
|
|
41458
|
-
);
|
|
41459
|
-
return;
|
|
41460
|
-
}
|
|
41461
40459
|
if (kind === SESSION_PROMPT_KIND) {
|
|
41462
40460
|
const command = decodeSessionPromptCommand(delivery.payload);
|
|
41463
40461
|
await processDeliveredPrompt(
|
|
@@ -41515,8 +40513,6 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
41515
40513
|
payloadSessionId = decodeSessionElicitationRespondCommand(delivery.payload).sessionId;
|
|
41516
40514
|
} else if (payloadKind === SESSION_PROMPT_KIND) {
|
|
41517
40515
|
payloadSessionId = decodeSessionPromptCommand(delivery.payload).sessionId;
|
|
41518
|
-
} else if (payloadKind === BOT_SESSION_PROMPT_KIND) {
|
|
41519
|
-
payloadSessionId = decodeBotSessionPromptCommand(delivery.payload).sessionId;
|
|
41520
40516
|
} else {
|
|
41521
40517
|
throw new Error("Runtime delivery contains an unsupported protocol message");
|
|
41522
40518
|
}
|
|
@@ -41909,6 +40905,29 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
41909
40905
|
connectionLiveness.acknowledge(decodeRuntimeHeartbeatAckEvent(encoded));
|
|
41910
40906
|
return;
|
|
41911
40907
|
}
|
|
40908
|
+
if (kind === FILE_READ_KIND) {
|
|
40909
|
+
const command2 = decodeFileReadCommand(encoded);
|
|
40910
|
+
void streamLocalFile(
|
|
40911
|
+
command2,
|
|
40912
|
+
(message) => send(socket, message),
|
|
40913
|
+
connectionController.signal
|
|
40914
|
+
).catch((error62) => {
|
|
40915
|
+
if (socket.readyState !== WebSocket2.OPEN || connectionController.signal.aborted) {
|
|
40916
|
+
return;
|
|
40917
|
+
}
|
|
40918
|
+
send(
|
|
40919
|
+
socket,
|
|
40920
|
+
encodeFileFailedEvent({
|
|
40921
|
+
code: "file_unavailable",
|
|
40922
|
+
kind: FILE_FAILED_KIND,
|
|
40923
|
+
message: error62 instanceof Error ? error62.message : "The local file is unavailable",
|
|
40924
|
+
requestId: command2.requestId,
|
|
40925
|
+
sessionId: command2.sessionId
|
|
40926
|
+
})
|
|
40927
|
+
);
|
|
40928
|
+
});
|
|
40929
|
+
return;
|
|
40930
|
+
}
|
|
41912
40931
|
if (kind === SESSION_CANCEL_KIND) {
|
|
41913
40932
|
const cancellation = decodeSessionCancelCommand(encoded);
|
|
41914
40933
|
const turn2 = activeTurns.get(cancellation.commandId);
|
|
@@ -42002,48 +41021,6 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
42002
41021
|
});
|
|
42003
41022
|
return;
|
|
42004
41023
|
}
|
|
42005
|
-
if (kind === BOT_SESSION_PROMPT_KIND) {
|
|
42006
|
-
const command2 = decodeBotSessionPromptCommand(encoded);
|
|
42007
|
-
if (activeTurns.has(command2.commandId)) {
|
|
42008
|
-
return;
|
|
42009
|
-
}
|
|
42010
|
-
const receipt2 = outbox.claimExecution(command2.commandId, command2.sessionId, encoded);
|
|
42011
|
-
if (receipt2.kind === "duplicate") {
|
|
42012
|
-
return;
|
|
42013
|
-
}
|
|
42014
|
-
const turn2 = new ActiveDaemonTurn(command2, receipt2.attemptId);
|
|
42015
|
-
activeTurns.set(command2.commandId, turn2);
|
|
42016
|
-
void executeBotPrompt(
|
|
42017
|
-
outbox,
|
|
42018
|
-
publisher,
|
|
42019
|
-
command2,
|
|
42020
|
-
config2,
|
|
42021
|
-
directories,
|
|
42022
|
-
audit,
|
|
42023
|
-
sessions,
|
|
42024
|
-
authorizer,
|
|
42025
|
-
contexts,
|
|
42026
|
-
applicator,
|
|
42027
|
-
ipc,
|
|
42028
|
-
receipt2.attemptId,
|
|
42029
|
-
() => {
|
|
42030
|
-
if (command2.disposition !== SessionPromptDisposition.Steer) {
|
|
42031
|
-
activeAttemptIds.set(command2.sessionId, receipt2.attemptId);
|
|
42032
|
-
}
|
|
42033
|
-
},
|
|
42034
|
-
timer,
|
|
42035
|
-
turn2.signal
|
|
42036
|
-
).catch((error62) => {
|
|
42037
|
-
console.error("Mobius daemon Bot turn failed", error62);
|
|
42038
|
-
}).finally(() => {
|
|
42039
|
-
activeTurns.delete(command2.commandId);
|
|
42040
|
-
if (activeAttemptIds.get(command2.sessionId) === receipt2.attemptId) {
|
|
42041
|
-
activeAttemptIds.delete(command2.sessionId);
|
|
42042
|
-
}
|
|
42043
|
-
turn2.finish();
|
|
42044
|
-
});
|
|
42045
|
-
return;
|
|
42046
|
-
}
|
|
42047
41024
|
if (kind !== SESSION_PROMPT_KIND) {
|
|
42048
41025
|
throw new Error("Unsupported protocol message");
|
|
42049
41026
|
}
|
|
@@ -42147,10 +41124,6 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
42147
41124
|
const sessionStore = new SqliteAcpSessionStore(config2.auditDatabasePath);
|
|
42148
41125
|
const outbox = new SessionEventOutbox(config2.auditDatabasePath);
|
|
42149
41126
|
const publisher = new DaemonSessionEventPublisher(outbox, timer);
|
|
42150
|
-
const authorizer = new LocalBotExecutionAuthorizer();
|
|
42151
|
-
const contexts = new BotExecutionContextRegistry();
|
|
42152
|
-
const applicator = new EmbeddedBotContextApplicator();
|
|
42153
|
-
const ipc = new BotOutboundIpcServer(botIpcSocketPath(), config2.relayUrl, contexts);
|
|
42154
41127
|
const activeTurns = /* @__PURE__ */ new Map();
|
|
42155
41128
|
const activeAttemptIds = /* @__PURE__ */ new Map();
|
|
42156
41129
|
const recordSessionEvent = (sessionId, payload) => {
|
|
@@ -42224,7 +41197,6 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
42224
41197
|
startAutomaticIntegrationProvisioning();
|
|
42225
41198
|
});
|
|
42226
41199
|
try {
|
|
42227
|
-
await ipc.listen(signal);
|
|
42228
41200
|
while (!signal.aborted) {
|
|
42229
41201
|
connectionEpoch += 1;
|
|
42230
41202
|
try {
|
|
@@ -42238,10 +41210,6 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
42238
41210
|
nativeSessions,
|
|
42239
41211
|
outbox,
|
|
42240
41212
|
publisher,
|
|
42241
|
-
authorizer,
|
|
42242
|
-
contexts,
|
|
42243
|
-
applicator,
|
|
42244
|
-
ipc,
|
|
42245
41213
|
activeTurns,
|
|
42246
41214
|
activeAttemptIds,
|
|
42247
41215
|
connectionEpoch,
|
|
@@ -42274,19 +41242,15 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
42274
41242
|
await installations.close();
|
|
42275
41243
|
} finally {
|
|
42276
41244
|
try {
|
|
42277
|
-
await
|
|
41245
|
+
await sessions.close();
|
|
42278
41246
|
} finally {
|
|
42279
41247
|
try {
|
|
42280
|
-
|
|
41248
|
+
sessionStore.close();
|
|
42281
41249
|
} finally {
|
|
42282
41250
|
try {
|
|
42283
|
-
|
|
41251
|
+
publisher.close();
|
|
42284
41252
|
} finally {
|
|
42285
|
-
|
|
42286
|
-
publisher.close();
|
|
42287
|
-
} finally {
|
|
42288
|
-
outbox.close();
|
|
42289
|
-
}
|
|
41253
|
+
outbox.close();
|
|
42290
41254
|
}
|
|
42291
41255
|
}
|
|
42292
41256
|
}
|
|
@@ -42297,9 +41261,9 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
42297
41261
|
}
|
|
42298
41262
|
|
|
42299
41263
|
// src/runtime.ts
|
|
42300
|
-
import { mkdir as
|
|
42301
|
-
import { dirname as
|
|
42302
|
-
var
|
|
41264
|
+
import { mkdir as mkdir4, realpath as realpath10, stat as stat9 } from "node:fs/promises";
|
|
41265
|
+
import { dirname as dirname7, join as join17, resolve as resolve5 } from "node:path";
|
|
41266
|
+
var IDENTIFIER_PATTERN7 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
42303
41267
|
var RUNTIME_CREDENTIAL_PATTERN = /^[a-zA-Z0-9_-]{32,256}$/;
|
|
42304
41268
|
var MobiusRuntimeConfigurationError = class extends Error {
|
|
42305
41269
|
code = "runtime_configuration_invalid";
|
|
@@ -42351,11 +41315,11 @@ function relayUrlFromConnection(connection) {
|
|
|
42351
41315
|
}
|
|
42352
41316
|
function loadMobiusRuntimeConnection(environment = process.env) {
|
|
42353
41317
|
const channelId = requiredEnvironmentValue(environment, "MOBIUS_CHANNEL_ID");
|
|
42354
|
-
if (!
|
|
41318
|
+
if (!IDENTIFIER_PATTERN7.test(channelId)) {
|
|
42355
41319
|
throw new MobiusRuntimeConfigurationError("MOBIUS_CHANNEL_ID is invalid");
|
|
42356
41320
|
}
|
|
42357
41321
|
return Object.freeze({
|
|
42358
|
-
auditDatabasePath: environment["MOBIUS_AUDIT_DATABASE"]?.trim() ||
|
|
41322
|
+
auditDatabasePath: environment["MOBIUS_AUDIT_DATABASE"]?.trim() || join17(readStateDirectory(environment), "audit", `${channelId}.sqlite`),
|
|
42359
41323
|
channelId,
|
|
42360
41324
|
defaultWorkspace: loadDefaultWorkspace(environment),
|
|
42361
41325
|
relayUrl: requiredEnvironmentValue(environment, "MOBIUS_RELAY_URL"),
|
|
@@ -42365,9 +41329,9 @@ function loadMobiusRuntimeConnection(environment = process.env) {
|
|
|
42365
41329
|
async function resolveWorkspace(path2) {
|
|
42366
41330
|
const requested = resolve5(path2);
|
|
42367
41331
|
try {
|
|
42368
|
-
await
|
|
42369
|
-
const resolved = await
|
|
42370
|
-
const metadata = await
|
|
41332
|
+
await mkdir4(requested, { recursive: true, mode: 448 });
|
|
41333
|
+
const resolved = await realpath10(requested);
|
|
41334
|
+
const metadata = await stat9(resolved);
|
|
42371
41335
|
if (!metadata.isDirectory()) {
|
|
42372
41336
|
throw new MobiusRuntimeConfigurationError("The Runtime workspace is not a directory");
|
|
42373
41337
|
}
|
|
@@ -42384,7 +41348,7 @@ async function createMobiusRuntimeEngine(connection, signal, environment = proce
|
|
|
42384
41348
|
const relayUrl = relayUrlFromConnection(connection);
|
|
42385
41349
|
const defaultWorkspace = await resolveWorkspace(connection.defaultWorkspace);
|
|
42386
41350
|
const auditDatabasePath = resolve5(connection.auditDatabasePath);
|
|
42387
|
-
await
|
|
41351
|
+
await mkdir4(dirname7(auditDatabasePath), { recursive: true, mode: 448 });
|
|
42388
41352
|
const inventory = await discoverLocalAgentInventory({
|
|
42389
41353
|
defaultWorkspace,
|
|
42390
41354
|
environment,
|
|
@@ -42431,16 +41395,12 @@ var MobiusRuntimeEngine = class {
|
|
|
42431
41395
|
export {
|
|
42432
41396
|
AcpExecutionError,
|
|
42433
41397
|
AuditStore,
|
|
42434
|
-
BotExecutionContextRegistry,
|
|
42435
|
-
BotMessageCommandError,
|
|
42436
|
-
BotOutboundIpcServer,
|
|
42437
41398
|
LocalAuthorizationError,
|
|
42438
41399
|
MobiusRuntimeConfigurationError,
|
|
42439
41400
|
MobiusRuntimeEngine,
|
|
42440
41401
|
PairingClientError,
|
|
42441
41402
|
createAcpClient,
|
|
42442
41403
|
createMobiusRuntimeEngine,
|
|
42443
|
-
executeBotMessageCommand,
|
|
42444
41404
|
loadDaemonConfig,
|
|
42445
41405
|
loadMobiusRuntimeConnection,
|
|
42446
41406
|
pairLocalMachine,
|