@moxt-ai/mobius 0.0.48 → 0.0.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/acp/session-manager.d.ts +2 -1
- package/dist/acp/session-manager.d.ts.map +1 -1
- package/dist/acp/session-manager.js +34 -11
- package/dist/acp/session-manager.js.map +1 -1
- package/dist/agent-catalog/publish-agent-catalog.d.ts.map +1 -1
- package/dist/agent-catalog/publish-agent-catalog.js +0 -1
- package/dist/agent-catalog/publish-agent-catalog.js.map +1 -1
- package/dist/artifacts/local-file-streamer.d.ts +3 -0
- package/dist/artifacts/local-file-streamer.d.ts.map +1 -0
- package/dist/artifacts/local-file-streamer.js +82 -0
- package/dist/artifacts/local-file-streamer.js.map +1 -0
- package/dist/authorization/local-raster.d.ts +4 -3
- package/dist/authorization/local-raster.d.ts.map +1 -1
- package/dist/authorization/local-raster.js +22 -12
- package/dist/authorization/local-raster.js.map +1 -1
- package/dist/cli.js +529 -1659
- package/dist/cli.js.map +4 -4
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +569 -1690
- package/dist/index.js.map +4 -4
- package/dist/native-sessions/history-images.js +1 -1
- package/dist/native-sessions/history-images.js.map +1 -1
- package/dist/pairing/pair-local-machine.d.ts.map +1 -1
- package/dist/pairing/pair-local-machine.js +0 -1
- package/dist/pairing/pair-local-machine.js.map +1 -1
- package/dist/run-daemon.d.ts.map +1 -1
- package/dist/run-daemon.js +26 -270
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.js +396 -1353
- package/dist/runtime.js.map +4 -4
- package/package.json +1 -1
- package/dist/bots/bot-context-applicator.d.ts +0 -14
- package/dist/bots/bot-context-applicator.d.ts.map +0 -1
- package/dist/bots/bot-context-applicator.js +0 -32
- package/dist/bots/bot-context-applicator.js.map +0 -1
- package/dist/bots/bot-execution-context.d.ts +0 -19
- package/dist/bots/bot-execution-context.d.ts.map +0 -1
- package/dist/bots/bot-execution-context.js +0 -75
- package/dist/bots/bot-execution-context.js.map +0 -1
- package/dist/bots/bot-message-command.d.ts +0 -6
- package/dist/bots/bot-message-command.d.ts.map +0 -1
- package/dist/bots/bot-message-command.js +0 -140
- package/dist/bots/bot-message-command.js.map +0 -1
- package/dist/bots/bot-outbound-ipc.d.ts +0 -12
- package/dist/bots/bot-outbound-ipc.d.ts.map +0 -1
- package/dist/bots/bot-outbound-ipc.js +0 -245
- package/dist/bots/bot-outbound-ipc.js.map +0 -1
- package/dist/bots/local-bot-execution-authorizer.d.ts +0 -23
- package/dist/bots/local-bot-execution-authorizer.d.ts.map +0 -1
- package/dist/bots/local-bot-execution-authorizer.js +0 -62
- package/dist/bots/local-bot-execution-authorizer.js.map +0 -1
package/dist/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
|
}
|
|
@@ -22321,10 +22046,11 @@ import {
|
|
|
22321
22046
|
} from "@agentclientprotocol/sdk";
|
|
22322
22047
|
|
|
22323
22048
|
// src/authorization/local-raster.ts
|
|
22324
|
-
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";
|
|
22325
22050
|
import { basename, isAbsolute, normalize } from "node:path";
|
|
22326
22051
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
22327
|
-
var MAX_LOCAL_RASTER_BYTES =
|
|
22052
|
+
var MAX_LOCAL_RASTER_BYTES = 128 * 1024 * 1024;
|
|
22053
|
+
var MAX_INLINE_RASTER_BYTES = 3e6;
|
|
22328
22054
|
var PNG_SIGNATURE = Uint8Array.of(137, 80, 78, 71);
|
|
22329
22055
|
var JPEG_SIGNATURE = Uint8Array.of(255, 216, 255);
|
|
22330
22056
|
var GIF87_SIGNATURE = new TextEncoder().encode("GIF87a");
|
|
@@ -22335,12 +22061,17 @@ var LocalRasterImage = class {
|
|
|
22335
22061
|
bytes;
|
|
22336
22062
|
mimeType;
|
|
22337
22063
|
name;
|
|
22338
|
-
|
|
22064
|
+
sourceUri;
|
|
22065
|
+
constructor(name, mimeType, bytes, sourceUri = "") {
|
|
22339
22066
|
this.bytes = bytes;
|
|
22340
22067
|
this.mimeType = mimeType;
|
|
22341
22068
|
this.name = name;
|
|
22069
|
+
this.sourceUri = sourceUri;
|
|
22342
22070
|
}
|
|
22343
|
-
base64 = () =>
|
|
22071
|
+
base64 = async () => {
|
|
22072
|
+
const bytes = this.bytes ?? new Uint8Array(await readFile2(this.sourceUri));
|
|
22073
|
+
return Buffer.from(bytes).toString("base64");
|
|
22074
|
+
};
|
|
22344
22075
|
};
|
|
22345
22076
|
function startsWith(bytes, signature, offset = 0) {
|
|
22346
22077
|
if (bytes.byteLength < offset + signature.byteLength) {
|
|
@@ -22364,14 +22095,14 @@ function sniffRasterMime(bytes) {
|
|
|
22364
22095
|
return null;
|
|
22365
22096
|
}
|
|
22366
22097
|
function readInlineRaster(data, name = "Image") {
|
|
22367
|
-
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) {
|
|
22368
22099
|
return null;
|
|
22369
22100
|
}
|
|
22370
22101
|
if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(data)) {
|
|
22371
22102
|
return null;
|
|
22372
22103
|
}
|
|
22373
22104
|
const bytes = new Uint8Array(Buffer.from(data, "base64"));
|
|
22374
|
-
if (bytes.byteLength < 1 || bytes.byteLength >
|
|
22105
|
+
if (bytes.byteLength < 1 || bytes.byteLength > MAX_INLINE_RASTER_BYTES) {
|
|
22375
22106
|
return null;
|
|
22376
22107
|
}
|
|
22377
22108
|
const mimeType = sniffRasterMime(bytes);
|
|
@@ -22439,16 +22170,19 @@ async function readLocalRaster(uri, signal) {
|
|
|
22439
22170
|
if (!targetMetadata.isFile() || targetMetadata.size < 1 || targetMetadata.size > MAX_LOCAL_RASTER_BYTES) {
|
|
22440
22171
|
return null;
|
|
22441
22172
|
}
|
|
22442
|
-
const
|
|
22443
|
-
|
|
22444
|
-
|
|
22445
|
-
|
|
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();
|
|
22446
22179
|
}
|
|
22447
|
-
|
|
22180
|
+
signal.throwIfAborted();
|
|
22181
|
+
const mimeType = sniffRasterMime(header);
|
|
22448
22182
|
if (mimeType === null) {
|
|
22449
22183
|
return null;
|
|
22450
22184
|
}
|
|
22451
|
-
return new LocalRasterImage(basename(target) || "Image", mimeType,
|
|
22185
|
+
return new LocalRasterImage(basename(target) || "Image", mimeType, null, target);
|
|
22452
22186
|
}
|
|
22453
22187
|
|
|
22454
22188
|
// src/authorization/local-video.ts
|
|
@@ -22574,7 +22308,7 @@ async function resolveMessageImages(message, usedCharacters, signal) {
|
|
|
22574
22308
|
if (local === null) {
|
|
22575
22309
|
return "[Image unavailable]";
|
|
22576
22310
|
}
|
|
22577
|
-
const data = local.base64();
|
|
22311
|
+
const data = await local.base64();
|
|
22578
22312
|
if (usedCharacters + imageCharacters + data.length > SESSION_HISTORY_IMAGE_CHARACTER_LIMIT) {
|
|
22579
22313
|
return "[Image unavailable]";
|
|
22580
22314
|
}
|
|
@@ -22610,7 +22344,7 @@ async function replaceImageMarkers(text3, replace) {
|
|
|
22610
22344
|
|
|
22611
22345
|
// src/acp/activity.ts
|
|
22612
22346
|
var TRUNCATION_MARKER = "\n\u2026 output truncated by Mobius";
|
|
22613
|
-
function
|
|
22347
|
+
function isRecord3(value) {
|
|
22614
22348
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22615
22349
|
}
|
|
22616
22350
|
var AcpActivity = class _AcpActivity {
|
|
@@ -22844,16 +22578,16 @@ async function normalizeToolContent(content3, prepareContent) {
|
|
|
22844
22578
|
return normalized;
|
|
22845
22579
|
}
|
|
22846
22580
|
function rawMcpToolContent(rawOutput) {
|
|
22847
|
-
if (!
|
|
22581
|
+
if (!isRecord3(rawOutput)) {
|
|
22848
22582
|
return [];
|
|
22849
22583
|
}
|
|
22850
|
-
const result =
|
|
22584
|
+
const result = isRecord3(rawOutput["result"]) ? rawOutput["result"] : rawOutput;
|
|
22851
22585
|
const content3 = result["content"];
|
|
22852
22586
|
if (!Array.isArray(content3)) {
|
|
22853
22587
|
return [];
|
|
22854
22588
|
}
|
|
22855
22589
|
return content3.flatMap((item) => {
|
|
22856
|
-
if (!
|
|
22590
|
+
if (!isRecord3(item) || item["type"] !== "image" || typeof item["data"] !== "string" || typeof item["mimeType"] !== "string") {
|
|
22857
22591
|
return [];
|
|
22858
22592
|
}
|
|
22859
22593
|
const uri = item["uri"];
|
|
@@ -22930,7 +22664,7 @@ function contentPhase(content3) {
|
|
|
22930
22664
|
return "";
|
|
22931
22665
|
}
|
|
22932
22666
|
const codex = metadata["codex"];
|
|
22933
|
-
if (!
|
|
22667
|
+
if (!isRecord3(codex)) {
|
|
22934
22668
|
return "";
|
|
22935
22669
|
}
|
|
22936
22670
|
const phase = codex["phase"];
|
|
@@ -25734,7 +25468,7 @@ var attention = {
|
|
|
25734
25468
|
};
|
|
25735
25469
|
function resolveAllAttention(events, context) {
|
|
25736
25470
|
let index2 = -1;
|
|
25737
|
-
let
|
|
25471
|
+
let open6;
|
|
25738
25472
|
let group;
|
|
25739
25473
|
let text3;
|
|
25740
25474
|
let openingSequence;
|
|
@@ -25744,16 +25478,16 @@ function resolveAllAttention(events, context) {
|
|
|
25744
25478
|
let offset;
|
|
25745
25479
|
while (++index2 < events.length) {
|
|
25746
25480
|
if (events[index2][0] === "enter" && events[index2][1].type === "attentionSequence" && events[index2][1]._close) {
|
|
25747
|
-
|
|
25748
|
-
while (
|
|
25749
|
-
if (events[
|
|
25750
|
-
context.sliceSerialize(events[
|
|
25751
|
-
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)) {
|
|
25752
25486
|
continue;
|
|
25753
25487
|
}
|
|
25754
|
-
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;
|
|
25755
25489
|
const start = {
|
|
25756
|
-
...events[
|
|
25490
|
+
...events[open6][1].end
|
|
25757
25491
|
};
|
|
25758
25492
|
const end = {
|
|
25759
25493
|
...events[index2][1].start
|
|
@@ -25764,7 +25498,7 @@ function resolveAllAttention(events, context) {
|
|
|
25764
25498
|
type: use > 1 ? "strongSequence" : "emphasisSequence",
|
|
25765
25499
|
start,
|
|
25766
25500
|
end: {
|
|
25767
|
-
...events[
|
|
25501
|
+
...events[open6][1].end
|
|
25768
25502
|
}
|
|
25769
25503
|
};
|
|
25770
25504
|
closingSequence = {
|
|
@@ -25777,7 +25511,7 @@ function resolveAllAttention(events, context) {
|
|
|
25777
25511
|
text3 = {
|
|
25778
25512
|
type: use > 1 ? "strongText" : "emphasisText",
|
|
25779
25513
|
start: {
|
|
25780
|
-
...events[
|
|
25514
|
+
...events[open6][1].end
|
|
25781
25515
|
},
|
|
25782
25516
|
end: {
|
|
25783
25517
|
...events[index2][1].start
|
|
@@ -25792,18 +25526,18 @@ function resolveAllAttention(events, context) {
|
|
|
25792
25526
|
...closingSequence.end
|
|
25793
25527
|
}
|
|
25794
25528
|
};
|
|
25795
|
-
events[
|
|
25529
|
+
events[open6][1].end = {
|
|
25796
25530
|
...openingSequence.start
|
|
25797
25531
|
};
|
|
25798
25532
|
events[index2][1].start = {
|
|
25799
25533
|
...closingSequence.end
|
|
25800
25534
|
};
|
|
25801
25535
|
nextEvents = [];
|
|
25802
|
-
if (events[
|
|
25803
|
-
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]]);
|
|
25804
25538
|
}
|
|
25805
25539
|
nextEvents = push(nextEvents, [["enter", group, context], ["enter", openingSequence, context], ["exit", openingSequence, context], ["enter", text3, context]]);
|
|
25806
|
-
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));
|
|
25807
25541
|
nextEvents = push(nextEvents, [["exit", text3, context], ["enter", closingSequence, context], ["exit", closingSequence, context], ["exit", group, context]]);
|
|
25808
25542
|
if (events[index2][1].end.offset - events[index2][1].start.offset) {
|
|
25809
25543
|
offset = 2;
|
|
@@ -25811,8 +25545,8 @@ function resolveAllAttention(events, context) {
|
|
|
25811
25545
|
} else {
|
|
25812
25546
|
offset = 0;
|
|
25813
25547
|
}
|
|
25814
|
-
splice(events,
|
|
25815
|
-
index2 =
|
|
25548
|
+
splice(events, open6 - 1, index2 - open6 + 3, nextEvents);
|
|
25549
|
+
index2 = open6 + nextEvents.length - offset - 2;
|
|
25816
25550
|
break;
|
|
25817
25551
|
}
|
|
25818
25552
|
}
|
|
@@ -25844,10 +25578,10 @@ function tokenizeAttention(effects, ok2) {
|
|
|
25844
25578
|
}
|
|
25845
25579
|
const token = effects.exit("attentionSequence");
|
|
25846
25580
|
const after = classifyCharacter(code);
|
|
25847
|
-
const
|
|
25581
|
+
const open6 = !after || after === 2 && before || attentionMarkers2.includes(code);
|
|
25848
25582
|
const close = !before || before === 2 && after || attentionMarkers2.includes(previous2);
|
|
25849
|
-
token._open = Boolean(marker === 42 ?
|
|
25850
|
-
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));
|
|
25851
25585
|
return ok2(code);
|
|
25852
25586
|
}
|
|
25853
25587
|
}
|
|
@@ -25871,9 +25605,9 @@ function tokenizeAutolink(effects, ok2, nok) {
|
|
|
25871
25605
|
effects.consume(code);
|
|
25872
25606
|
effects.exit("autolinkMarker");
|
|
25873
25607
|
effects.enter("autolinkProtocol");
|
|
25874
|
-
return
|
|
25608
|
+
return open6;
|
|
25875
25609
|
}
|
|
25876
|
-
function
|
|
25610
|
+
function open6(code) {
|
|
25877
25611
|
if (asciiAlpha(code)) {
|
|
25878
25612
|
effects.consume(code);
|
|
25879
25613
|
return schemeOrEmailAtext;
|
|
@@ -26073,9 +25807,9 @@ function tokenizeCharacterReference(effects, ok2, nok) {
|
|
|
26073
25807
|
effects.enter("characterReferenceMarker");
|
|
26074
25808
|
effects.consume(code);
|
|
26075
25809
|
effects.exit("characterReferenceMarker");
|
|
26076
|
-
return
|
|
25810
|
+
return open6;
|
|
26077
25811
|
}
|
|
26078
|
-
function
|
|
25812
|
+
function open6(code) {
|
|
26079
25813
|
if (code === 35) {
|
|
26080
25814
|
effects.enter("characterReferenceMarkerNumeric");
|
|
26081
25815
|
effects.consume(code);
|
|
@@ -27444,9 +27178,9 @@ function tokenizeHtmlFlow(effects, ok2, nok) {
|
|
|
27444
27178
|
effects.enter("htmlFlow");
|
|
27445
27179
|
effects.enter("htmlFlowData");
|
|
27446
27180
|
effects.consume(code);
|
|
27447
|
-
return
|
|
27181
|
+
return open6;
|
|
27448
27182
|
}
|
|
27449
|
-
function
|
|
27183
|
+
function open6(code) {
|
|
27450
27184
|
if (code === 33) {
|
|
27451
27185
|
effects.consume(code);
|
|
27452
27186
|
return declarationOpen;
|
|
@@ -27794,9 +27528,9 @@ function tokenizeHtmlText(effects, ok2, nok) {
|
|
|
27794
27528
|
effects.enter("htmlText");
|
|
27795
27529
|
effects.enter("htmlTextData");
|
|
27796
27530
|
effects.consume(code);
|
|
27797
|
-
return
|
|
27531
|
+
return open6;
|
|
27798
27532
|
}
|
|
27799
|
-
function
|
|
27533
|
+
function open6(code) {
|
|
27800
27534
|
if (code === 33) {
|
|
27801
27535
|
effects.consume(code);
|
|
27802
27536
|
return declarationOpen;
|
|
@@ -28122,12 +27856,12 @@ function resolveToLabelEnd(events, context) {
|
|
|
28122
27856
|
let index2 = events.length;
|
|
28123
27857
|
let offset = 0;
|
|
28124
27858
|
let token;
|
|
28125
|
-
let
|
|
27859
|
+
let open6;
|
|
28126
27860
|
let close;
|
|
28127
27861
|
let media;
|
|
28128
27862
|
while (index2--) {
|
|
28129
27863
|
token = events[index2][1];
|
|
28130
|
-
if (
|
|
27864
|
+
if (open6) {
|
|
28131
27865
|
if (token.type === "link" || token.type === "labelLink" && token._inactive) {
|
|
28132
27866
|
break;
|
|
28133
27867
|
}
|
|
@@ -28136,7 +27870,7 @@ function resolveToLabelEnd(events, context) {
|
|
|
28136
27870
|
}
|
|
28137
27871
|
} else if (close) {
|
|
28138
27872
|
if (events[index2][0] === "enter" && (token.type === "labelImage" || token.type === "labelLink") && !token._balanced) {
|
|
28139
|
-
|
|
27873
|
+
open6 = index2;
|
|
28140
27874
|
if (token.type !== "labelLink") {
|
|
28141
27875
|
offset = 2;
|
|
28142
27876
|
break;
|
|
@@ -28147,9 +27881,9 @@ function resolveToLabelEnd(events, context) {
|
|
|
28147
27881
|
}
|
|
28148
27882
|
}
|
|
28149
27883
|
const group = {
|
|
28150
|
-
type: events[
|
|
27884
|
+
type: events[open6][1].type === "labelLink" ? "link" : "image",
|
|
28151
27885
|
start: {
|
|
28152
|
-
...events[
|
|
27886
|
+
...events[open6][1].start
|
|
28153
27887
|
},
|
|
28154
27888
|
end: {
|
|
28155
27889
|
...events[events.length - 1][1].end
|
|
@@ -28158,7 +27892,7 @@ function resolveToLabelEnd(events, context) {
|
|
|
28158
27892
|
const label = {
|
|
28159
27893
|
type: "label",
|
|
28160
27894
|
start: {
|
|
28161
|
-
...events[
|
|
27895
|
+
...events[open6][1].start
|
|
28162
27896
|
},
|
|
28163
27897
|
end: {
|
|
28164
27898
|
...events[close][1].end
|
|
@@ -28167,20 +27901,20 @@ function resolveToLabelEnd(events, context) {
|
|
|
28167
27901
|
const text3 = {
|
|
28168
27902
|
type: "labelText",
|
|
28169
27903
|
start: {
|
|
28170
|
-
...events[
|
|
27904
|
+
...events[open6 + offset + 2][1].end
|
|
28171
27905
|
},
|
|
28172
27906
|
end: {
|
|
28173
27907
|
...events[close - 2][1].start
|
|
28174
27908
|
}
|
|
28175
27909
|
};
|
|
28176
27910
|
media = [["enter", group, context], ["enter", label, context]];
|
|
28177
|
-
media = push(media, events.slice(
|
|
27911
|
+
media = push(media, events.slice(open6 + 1, open6 + offset + 3));
|
|
28178
27912
|
media = push(media, [["enter", text3, context]]);
|
|
28179
|
-
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));
|
|
28180
27914
|
media = push(media, [["exit", text3, context], events[close - 2], events[close - 1], ["exit", label, context]]);
|
|
28181
27915
|
media = push(media, events.slice(close + 1));
|
|
28182
27916
|
media = push(media, [["exit", group, context]]);
|
|
28183
|
-
splice(events,
|
|
27917
|
+
splice(events, open6, events.length, media);
|
|
28184
27918
|
return events;
|
|
28185
27919
|
}
|
|
28186
27920
|
function tokenizeLabelEnd(effects, ok2, nok) {
|
|
@@ -28325,9 +28059,9 @@ function tokenizeLabelStartImage(effects, ok2, nok) {
|
|
|
28325
28059
|
effects.enter("labelImageMarker");
|
|
28326
28060
|
effects.consume(code);
|
|
28327
28061
|
effects.exit("labelImageMarker");
|
|
28328
|
-
return
|
|
28062
|
+
return open6;
|
|
28329
28063
|
}
|
|
28330
|
-
function
|
|
28064
|
+
function open6(code) {
|
|
28331
28065
|
if (code === 91) {
|
|
28332
28066
|
effects.enter("labelMarker");
|
|
28333
28067
|
effects.consume(code);
|
|
@@ -29631,8 +29365,8 @@ function compiler(options) {
|
|
|
29631
29365
|
return length;
|
|
29632
29366
|
}
|
|
29633
29367
|
function opener(create, and) {
|
|
29634
|
-
return
|
|
29635
|
-
function
|
|
29368
|
+
return open6;
|
|
29369
|
+
function open6(token) {
|
|
29636
29370
|
enter.call(this, create(token), token);
|
|
29637
29371
|
if (and) and.call(this, token);
|
|
29638
29372
|
}
|
|
@@ -29664,18 +29398,18 @@ function compiler(options) {
|
|
|
29664
29398
|
}
|
|
29665
29399
|
function exit2(token, onExitError) {
|
|
29666
29400
|
const node3 = this.stack.pop();
|
|
29667
|
-
const
|
|
29668
|
-
if (!
|
|
29401
|
+
const open6 = this.tokenStack.pop();
|
|
29402
|
+
if (!open6) {
|
|
29669
29403
|
throw new Error("Cannot close `" + token.type + "` (" + stringifyPosition({
|
|
29670
29404
|
start: token.start,
|
|
29671
29405
|
end: token.end
|
|
29672
29406
|
}) + "): it\u2019s not open");
|
|
29673
|
-
} else if (
|
|
29407
|
+
} else if (open6[0].type !== token.type) {
|
|
29674
29408
|
if (onExitError) {
|
|
29675
|
-
onExitError.call(this, token,
|
|
29409
|
+
onExitError.call(this, token, open6[0]);
|
|
29676
29410
|
} else {
|
|
29677
|
-
const handler =
|
|
29678
|
-
handler.call(this, token,
|
|
29411
|
+
const handler = open6[1] || defaultOnError;
|
|
29412
|
+
handler.call(this, token, open6[0]);
|
|
29679
29413
|
}
|
|
29680
29414
|
}
|
|
29681
29415
|
node3.position.end = point2(token.end);
|
|
@@ -30359,7 +30093,7 @@ var SessionConfigProtocolError = class extends Error {
|
|
|
30359
30093
|
this.name = "SessionConfigProtocolError";
|
|
30360
30094
|
}
|
|
30361
30095
|
};
|
|
30362
|
-
function
|
|
30096
|
+
function isRecord4(value) {
|
|
30363
30097
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
30364
30098
|
}
|
|
30365
30099
|
function readString2(value, fallback = "") {
|
|
@@ -30371,13 +30105,13 @@ function truncate2(value, maximum) {
|
|
|
30371
30105
|
function readBoolean(value, fallback = false) {
|
|
30372
30106
|
return typeof value === "boolean" ? value : fallback;
|
|
30373
30107
|
}
|
|
30374
|
-
function normalizeConfigValue(
|
|
30108
|
+
function normalizeConfigValue(option, groupId = "", groupName = "") {
|
|
30375
30109
|
return {
|
|
30376
|
-
description: truncate2(readString2(
|
|
30110
|
+
description: truncate2(readString2(option["description"]), 500),
|
|
30377
30111
|
groupId: truncate2(groupId, 128),
|
|
30378
30112
|
groupName: truncate2(groupName, 255),
|
|
30379
|
-
name: truncate2(readString2(
|
|
30380
|
-
value: truncate2(readString2(
|
|
30113
|
+
name: truncate2(readString2(option["name"], readString2(option["value"])), 255),
|
|
30114
|
+
value: truncate2(readString2(option["value"]), 500)
|
|
30381
30115
|
};
|
|
30382
30116
|
}
|
|
30383
30117
|
function normalizeConfigValues(value) {
|
|
@@ -30386,7 +30120,7 @@ function normalizeConfigValues(value) {
|
|
|
30386
30120
|
}
|
|
30387
30121
|
const normalized = [];
|
|
30388
30122
|
for (const entry of value) {
|
|
30389
|
-
if (!
|
|
30123
|
+
if (!isRecord4(entry)) {
|
|
30390
30124
|
continue;
|
|
30391
30125
|
}
|
|
30392
30126
|
const groupedOptions = entry["options"];
|
|
@@ -30394,7 +30128,7 @@ function normalizeConfigValues(value) {
|
|
|
30394
30128
|
const groupId = readString2(entry["group"]);
|
|
30395
30129
|
const groupName = readString2(entry["name"]);
|
|
30396
30130
|
for (const groupedOption of groupedOptions) {
|
|
30397
|
-
if (
|
|
30131
|
+
if (isRecord4(groupedOption)) {
|
|
30398
30132
|
normalized.push(normalizeConfigValue(groupedOption, groupId, groupName));
|
|
30399
30133
|
}
|
|
30400
30134
|
}
|
|
@@ -30407,21 +30141,21 @@ function normalizeConfigValues(value) {
|
|
|
30407
30141
|
function normalizeConfigOptions(value, modes) {
|
|
30408
30142
|
const normalized = [];
|
|
30409
30143
|
if (Array.isArray(value)) {
|
|
30410
|
-
for (const
|
|
30411
|
-
if (!
|
|
30144
|
+
for (const option of value) {
|
|
30145
|
+
if (!isRecord4(option)) {
|
|
30412
30146
|
continue;
|
|
30413
30147
|
}
|
|
30414
|
-
const id = truncate2(readString2(
|
|
30415
|
-
const name = truncate2(readString2(
|
|
30148
|
+
const id = truncate2(readString2(option["id"]), 128);
|
|
30149
|
+
const name = truncate2(readString2(option["name"], id), 255);
|
|
30416
30150
|
if (id.length === 0 || name.length === 0) {
|
|
30417
30151
|
continue;
|
|
30418
30152
|
}
|
|
30419
|
-
if (
|
|
30153
|
+
if (option["type"] === "boolean") {
|
|
30420
30154
|
normalized.push({
|
|
30421
|
-
booleanValue: readBoolean(
|
|
30422
|
-
category: truncate2(readString2(
|
|
30155
|
+
booleanValue: readBoolean(option["currentValue"]),
|
|
30156
|
+
category: truncate2(readString2(option["category"]), 128),
|
|
30423
30157
|
currentValue: "",
|
|
30424
|
-
description: truncate2(readString2(
|
|
30158
|
+
description: truncate2(readString2(option["description"]), 500),
|
|
30425
30159
|
id,
|
|
30426
30160
|
name,
|
|
30427
30161
|
type: "boolean",
|
|
@@ -30429,15 +30163,15 @@ function normalizeConfigOptions(value, modes) {
|
|
|
30429
30163
|
});
|
|
30430
30164
|
continue;
|
|
30431
30165
|
}
|
|
30432
|
-
if (
|
|
30433
|
-
const values = normalizeConfigValues(
|
|
30434
|
-
const currentValue = truncate2(readString2(
|
|
30166
|
+
if (option["type"] === "select") {
|
|
30167
|
+
const values = normalizeConfigValues(option["options"]);
|
|
30168
|
+
const currentValue = truncate2(readString2(option["currentValue"]), 500);
|
|
30435
30169
|
if (currentValue.length > 0 && values.some((entry) => entry.value === currentValue)) {
|
|
30436
30170
|
normalized.push({
|
|
30437
30171
|
booleanValue: false,
|
|
30438
|
-
category: truncate2(readString2(
|
|
30172
|
+
category: truncate2(readString2(option["category"]), 128),
|
|
30439
30173
|
currentValue,
|
|
30440
|
-
description: truncate2(readString2(
|
|
30174
|
+
description: truncate2(readString2(option["description"]), 500),
|
|
30441
30175
|
id,
|
|
30442
30176
|
name,
|
|
30443
30177
|
type: "select",
|
|
@@ -30447,12 +30181,12 @@ function normalizeConfigOptions(value, modes) {
|
|
|
30447
30181
|
}
|
|
30448
30182
|
}
|
|
30449
30183
|
}
|
|
30450
|
-
if (
|
|
30184
|
+
if (isRecord4(modes)) {
|
|
30451
30185
|
const values = [];
|
|
30452
30186
|
const availableModes = modes["availableModes"];
|
|
30453
30187
|
if (Array.isArray(availableModes)) {
|
|
30454
30188
|
for (const mode of availableModes) {
|
|
30455
|
-
if (!
|
|
30189
|
+
if (!isRecord4(mode)) {
|
|
30456
30190
|
continue;
|
|
30457
30191
|
}
|
|
30458
30192
|
const id = truncate2(readString2(mode["id"]), 500);
|
|
@@ -30485,14 +30219,14 @@ function normalizeConfigOptions(value, modes) {
|
|
|
30485
30219
|
return normalized.slice(0, 100);
|
|
30486
30220
|
}
|
|
30487
30221
|
function insertRequiredOption(current, required2, afterCategory = "") {
|
|
30488
|
-
if (current.some((
|
|
30222
|
+
if (current.some((option) => option.id === required2.id || option.category === required2.category)) {
|
|
30489
30223
|
return current;
|
|
30490
30224
|
}
|
|
30491
30225
|
if (current.length < MAXIMUM_CONFIG_OPTIONS) {
|
|
30492
30226
|
if (afterCategory.length === 0) {
|
|
30493
30227
|
return [required2, ...current];
|
|
30494
30228
|
}
|
|
30495
|
-
const index3 = current.findIndex((
|
|
30229
|
+
const index3 = current.findIndex((option) => option.category === afterCategory);
|
|
30496
30230
|
if (index3 < 0) {
|
|
30497
30231
|
return [...current, required2];
|
|
30498
30232
|
}
|
|
@@ -30501,7 +30235,7 @@ function insertRequiredOption(current, required2, afterCategory = "") {
|
|
|
30501
30235
|
if (afterCategory.length === 0) {
|
|
30502
30236
|
return [required2, ...current.slice(0, MAXIMUM_CONFIG_OPTIONS - 1)];
|
|
30503
30237
|
}
|
|
30504
|
-
const index2 = current.findIndex((
|
|
30238
|
+
const index2 = current.findIndex((option) => option.category === afterCategory);
|
|
30505
30239
|
if (index2 < 0) {
|
|
30506
30240
|
return [...current.slice(0, MAXIMUM_CONFIG_OPTIONS - 1), required2];
|
|
30507
30241
|
}
|
|
@@ -30514,11 +30248,11 @@ function insertRequiredOption(current, required2, afterCategory = "") {
|
|
|
30514
30248
|
}
|
|
30515
30249
|
return [...current.slice(0, MAXIMUM_CONFIG_OPTIONS - 2), anchor2, required2];
|
|
30516
30250
|
}
|
|
30517
|
-
function validRequiredSelect(
|
|
30518
|
-
return
|
|
30251
|
+
function validRequiredSelect(option) {
|
|
30252
|
+
return option.type === "select" && option.currentValue.length > 0 && option.values.some((value) => value.value === option.currentValue);
|
|
30519
30253
|
}
|
|
30520
30254
|
function ensureModelOption(current) {
|
|
30521
|
-
const existing = current.find((
|
|
30255
|
+
const existing = current.find((option) => option.id === "model" || option.category === "model");
|
|
30522
30256
|
if (existing !== void 0 && validRequiredSelect(existing)) {
|
|
30523
30257
|
return current;
|
|
30524
30258
|
}
|
|
@@ -30541,12 +30275,12 @@ function ensureModelOption(current) {
|
|
|
30541
30275
|
]
|
|
30542
30276
|
};
|
|
30543
30277
|
return insertRequiredOption(
|
|
30544
|
-
current.filter((
|
|
30278
|
+
current.filter((option) => option.id !== "model" && option.category !== "model"),
|
|
30545
30279
|
unavailable
|
|
30546
30280
|
);
|
|
30547
30281
|
}
|
|
30548
30282
|
function ensureReasoningEffortOption(current) {
|
|
30549
|
-
const existing = current.find((
|
|
30283
|
+
const existing = current.find((option) => option.id === "reasoning_effort" || option.category === "thought_level");
|
|
30550
30284
|
if (existing !== void 0 && validRequiredSelect(existing)) {
|
|
30551
30285
|
return current;
|
|
30552
30286
|
}
|
|
@@ -30569,7 +30303,7 @@ function ensureReasoningEffortOption(current) {
|
|
|
30569
30303
|
]
|
|
30570
30304
|
};
|
|
30571
30305
|
return insertRequiredOption(
|
|
30572
|
-
current.filter((
|
|
30306
|
+
current.filter((option) => option.id !== "reasoning_effort" && option.category !== "thought_level"),
|
|
30573
30307
|
unavailable,
|
|
30574
30308
|
"model"
|
|
30575
30309
|
);
|
|
@@ -30577,34 +30311,34 @@ function ensureReasoningEffortOption(current) {
|
|
|
30577
30311
|
function ensureRequiredExecutionOptions(current, permission) {
|
|
30578
30312
|
const normalized = ensureReasoningEffortOption(ensureModelOption(current));
|
|
30579
30313
|
const model = normalized.find(
|
|
30580
|
-
(
|
|
30314
|
+
(option) => (option.id === "model" || option.category === "model") && validRequiredSelect(option)
|
|
30581
30315
|
);
|
|
30582
30316
|
const reasoningEffort = normalized.find(
|
|
30583
|
-
(
|
|
30317
|
+
(option) => (option.id === "reasoning_effort" || option.category === "thought_level") && validRequiredSelect(option)
|
|
30584
30318
|
);
|
|
30585
30319
|
if (model === void 0 || reasoningEffort === void 0) {
|
|
30586
30320
|
throw new SessionConfigProtocolError("The required Agent execution settings are unavailable");
|
|
30587
30321
|
}
|
|
30588
30322
|
const optional2 = normalized.filter(
|
|
30589
|
-
(
|
|
30323
|
+
(option) => option.id !== permission.id && option.category !== permission.category && option.id !== "model" && option.category !== "model" && option.id !== "reasoning_effort" && option.category !== "thought_level"
|
|
30590
30324
|
);
|
|
30591
30325
|
return [permission, model, reasoningEffort, ...optional2].slice(0, MAXIMUM_CONFIG_OPTIONS);
|
|
30592
30326
|
}
|
|
30593
30327
|
function normalizeStandardLifecycle(response) {
|
|
30594
|
-
const lifecycle =
|
|
30328
|
+
const lifecycle = isRecord4(response) ? response : {};
|
|
30595
30329
|
return ensureReasoningEffortOption(normalizeConfigOptions(lifecycle["configOptions"], lifecycle["modes"]));
|
|
30596
30330
|
}
|
|
30597
30331
|
function replaceStandardConfigOptions(current, value) {
|
|
30598
30332
|
const next = normalizeConfigOptions(value, void 0);
|
|
30599
|
-
const withMode = next.some((
|
|
30333
|
+
const withMode = next.some((option) => option.category === "mode") ? next : [...current.filter((option) => option.category === "mode"), ...next].slice(0, 100);
|
|
30600
30334
|
return ensureReasoningEffortOption(withMode);
|
|
30601
30335
|
}
|
|
30602
30336
|
function updateCurrentValue(current, configId, value) {
|
|
30603
|
-
return current.map((
|
|
30337
|
+
return current.map((option) => option.id === configId ? { ...option, currentValue: value } : option);
|
|
30604
30338
|
}
|
|
30605
30339
|
var StandardSessionConfigProtocol = class {
|
|
30606
30340
|
configure = async (current, change, nativeSessionId, transport) => {
|
|
30607
|
-
const existing = current.find((
|
|
30341
|
+
const existing = current.find((option) => option.id === change.configId);
|
|
30608
30342
|
if (existing === void 0) {
|
|
30609
30343
|
return current;
|
|
30610
30344
|
}
|
|
@@ -30633,7 +30367,7 @@ var StandardSessionConfigProtocol = class {
|
|
|
30633
30367
|
"ACP agent exited while changing session configuration",
|
|
30634
30368
|
change.signal
|
|
30635
30369
|
);
|
|
30636
|
-
if (!
|
|
30370
|
+
if (!isRecord4(response) || !Array.isArray(response["configOptions"])) {
|
|
30637
30371
|
throw new SessionConfigProtocolError("The Agent returned an invalid session configuration response");
|
|
30638
30372
|
}
|
|
30639
30373
|
return replaceStandardConfigOptions(current, response["configOptions"]);
|
|
@@ -30647,31 +30381,31 @@ var standardSessionConfigProtocol = new StandardSessionConfigProtocol();
|
|
|
30647
30381
|
var LEGACY_MODEL_CONFIG_ID = "grok_build_legacy_model";
|
|
30648
30382
|
var LEGACY_REASONING_EFFORT_CONFIG_ID = "grok_build_legacy_reasoning_effort";
|
|
30649
30383
|
function legacyOptions(response) {
|
|
30650
|
-
if (!
|
|
30384
|
+
if (!isRecord4(response)) {
|
|
30651
30385
|
return [];
|
|
30652
30386
|
}
|
|
30653
30387
|
const metadata = response["_meta"];
|
|
30654
|
-
if (!
|
|
30388
|
+
if (!isRecord4(metadata)) {
|
|
30655
30389
|
return [];
|
|
30656
30390
|
}
|
|
30657
30391
|
const sessionConfig = metadata["x.ai/sessionConfig"];
|
|
30658
|
-
if (!
|
|
30392
|
+
if (!isRecord4(sessionConfig) || !Array.isArray(sessionConfig["options"])) {
|
|
30659
30393
|
return [];
|
|
30660
30394
|
}
|
|
30661
|
-
return sessionConfig["options"].slice(0, 500).filter(
|
|
30395
|
+
return sessionConfig["options"].slice(0, 500).filter(isRecord4);
|
|
30662
30396
|
}
|
|
30663
|
-
function legacyValue(
|
|
30664
|
-
const value = readString2(
|
|
30397
|
+
function legacyValue(option) {
|
|
30398
|
+
const value = readString2(option["id"]);
|
|
30665
30399
|
return {
|
|
30666
|
-
description: readString2(
|
|
30400
|
+
description: readString2(option["description"]).slice(0, 500),
|
|
30667
30401
|
groupId: "",
|
|
30668
30402
|
groupName: "",
|
|
30669
|
-
name: readString2(
|
|
30403
|
+
name: readString2(option["label"], value).slice(0, 255),
|
|
30670
30404
|
value: value.slice(0, 500)
|
|
30671
30405
|
};
|
|
30672
30406
|
}
|
|
30673
30407
|
function modelsRecord(response) {
|
|
30674
|
-
if (!
|
|
30408
|
+
if (!isRecord4(response) || !isRecord4(response["models"])) {
|
|
30675
30409
|
return {};
|
|
30676
30410
|
}
|
|
30677
30411
|
return response["models"];
|
|
@@ -30680,9 +30414,9 @@ function legacyModelOptions(response) {
|
|
|
30680
30414
|
const options = legacyOptions(response);
|
|
30681
30415
|
const models = modelsRecord(response);
|
|
30682
30416
|
const values = [];
|
|
30683
|
-
for (const
|
|
30684
|
-
if (
|
|
30685
|
-
const value = legacyValue(
|
|
30417
|
+
for (const option of options) {
|
|
30418
|
+
if (option["category"] === "model") {
|
|
30419
|
+
const value = legacyValue(option);
|
|
30686
30420
|
if (value.value.length > 0 && !values.some((existing) => existing.value === value.value)) {
|
|
30687
30421
|
values.push(value);
|
|
30688
30422
|
}
|
|
@@ -30690,7 +30424,7 @@ function legacyModelOptions(response) {
|
|
|
30690
30424
|
}
|
|
30691
30425
|
if (values.length === 0 && Array.isArray(models["availableModels"])) {
|
|
30692
30426
|
for (const model of models["availableModels"]) {
|
|
30693
|
-
if (!
|
|
30427
|
+
if (!isRecord4(model)) {
|
|
30694
30428
|
continue;
|
|
30695
30429
|
}
|
|
30696
30430
|
const value = readString2(model["modelId"]).slice(0, 500);
|
|
@@ -30708,7 +30442,7 @@ function legacyModelOptions(response) {
|
|
|
30708
30442
|
}
|
|
30709
30443
|
}
|
|
30710
30444
|
}
|
|
30711
|
-
const selected = options.find((
|
|
30445
|
+
const selected = options.find((option) => option["category"] === "model" && option["selected"] === true);
|
|
30712
30446
|
const currentValue = readString2(
|
|
30713
30447
|
models["currentModelId"],
|
|
30714
30448
|
selected === void 0 ? "" : readString2(selected["id"])
|
|
@@ -30731,11 +30465,11 @@ function legacyModelOptions(response) {
|
|
|
30731
30465
|
function legacyReasoningEffortOptions(response) {
|
|
30732
30466
|
const options = legacyOptions(response);
|
|
30733
30467
|
const values = [];
|
|
30734
|
-
for (const
|
|
30735
|
-
if (
|
|
30468
|
+
for (const option of options) {
|
|
30469
|
+
if (option["category"] !== "mode") {
|
|
30736
30470
|
continue;
|
|
30737
30471
|
}
|
|
30738
|
-
const value = legacyValue(
|
|
30472
|
+
const value = legacyValue(option);
|
|
30739
30473
|
if (value.value.length > 0 && !values.some((existing) => existing.value === value.value)) {
|
|
30740
30474
|
values.push(value);
|
|
30741
30475
|
}
|
|
@@ -30743,7 +30477,7 @@ function legacyReasoningEffortOptions(response) {
|
|
|
30743
30477
|
if (values.length === 0) {
|
|
30744
30478
|
return [];
|
|
30745
30479
|
}
|
|
30746
|
-
const selected = options.find((
|
|
30480
|
+
const selected = options.find((option) => option["category"] === "mode" && option["selected"] === true);
|
|
30747
30481
|
if (selected === void 0) {
|
|
30748
30482
|
values.unshift({
|
|
30749
30483
|
description: "Use the selected model's default reasoning effort",
|
|
@@ -30770,41 +30504,41 @@ function legacyReasoningEffortOptions(response) {
|
|
|
30770
30504
|
return [result];
|
|
30771
30505
|
}
|
|
30772
30506
|
function normalizeGrokLifecycle(response) {
|
|
30773
|
-
const lifecycle =
|
|
30507
|
+
const lifecycle = isRecord4(response) ? response : {};
|
|
30774
30508
|
const standard = normalizeConfigOptions(lifecycle["configOptions"], lifecycle["modes"]);
|
|
30775
30509
|
const normalized = [...standard];
|
|
30776
|
-
if (!normalized.some((
|
|
30510
|
+
if (!normalized.some((option) => option.category === "model")) {
|
|
30777
30511
|
normalized.push(...legacyModelOptions(response));
|
|
30778
30512
|
}
|
|
30779
|
-
if (!normalized.some((
|
|
30513
|
+
if (!normalized.some((option) => option.category === "thought_level")) {
|
|
30780
30514
|
const efforts = legacyReasoningEffortOptions(response);
|
|
30781
30515
|
if (efforts.length > 0) {
|
|
30782
|
-
const modelIndex = normalized.findIndex((
|
|
30516
|
+
const modelIndex = normalized.findIndex((option) => option.category === "model");
|
|
30783
30517
|
normalized.splice(modelIndex < 0 ? normalized.length : modelIndex + 1, 0, ...efforts);
|
|
30784
30518
|
}
|
|
30785
30519
|
}
|
|
30786
30520
|
return ensureReasoningEffortOption(normalized.slice(0, 100));
|
|
30787
30521
|
}
|
|
30788
30522
|
function updateCurrentValue2(current, category, value) {
|
|
30789
|
-
return current.map((
|
|
30523
|
+
return current.map((option) => option.category === category ? { ...option, currentValue: value } : option);
|
|
30790
30524
|
}
|
|
30791
30525
|
function validateGrokResponse(response, modelId) {
|
|
30792
|
-
if (!
|
|
30526
|
+
if (!isRecord4(response) || !isRecord4(response["_meta"])) {
|
|
30793
30527
|
throw new SessionConfigProtocolError("Grok Build returned an invalid session configuration response");
|
|
30794
30528
|
}
|
|
30795
30529
|
const model = response["_meta"]["model"];
|
|
30796
|
-
const appliedModel =
|
|
30530
|
+
const appliedModel = isRecord4(model) ? model["Ok"] : model;
|
|
30797
30531
|
if (appliedModel !== modelId) {
|
|
30798
30532
|
throw new SessionConfigProtocolError("Grok Build returned an invalid session configuration response");
|
|
30799
30533
|
}
|
|
30800
30534
|
}
|
|
30801
30535
|
var GrokBuildSessionConfigProtocol = class {
|
|
30802
30536
|
configure = async (current, change, nativeSessionId, transport) => {
|
|
30803
|
-
const existing = current.find((
|
|
30537
|
+
const existing = current.find((option) => option.id === change.configId);
|
|
30804
30538
|
if (existing === void 0 || existing.id !== LEGACY_MODEL_CONFIG_ID && existing.id !== LEGACY_REASONING_EFFORT_CONFIG_ID) {
|
|
30805
30539
|
return await standardSessionConfigProtocol.configure(current, change, nativeSessionId, transport);
|
|
30806
30540
|
}
|
|
30807
|
-
const model = current.find((
|
|
30541
|
+
const model = current.find((option) => option.category === "model");
|
|
30808
30542
|
if (model === void 0) {
|
|
30809
30543
|
return current;
|
|
30810
30544
|
}
|
|
@@ -30830,10 +30564,10 @@ var GrokBuildSessionConfigProtocol = class {
|
|
|
30830
30564
|
validateGrokResponse(response, modelId);
|
|
30831
30565
|
const updated = updateCurrentValue2(current, existing.category, change.value);
|
|
30832
30566
|
return existing.category === "thought_level" ? updated.map(
|
|
30833
|
-
(
|
|
30834
|
-
...
|
|
30835
|
-
values:
|
|
30836
|
-
} :
|
|
30567
|
+
(option) => option.category === "thought_level" ? {
|
|
30568
|
+
...option,
|
|
30569
|
+
values: option.values.filter((value) => value.value !== AGENT_DEFAULT_REASONING_EFFORT)
|
|
30570
|
+
} : option
|
|
30837
30571
|
) : updated;
|
|
30838
30572
|
};
|
|
30839
30573
|
normalizeLifecycle = (response) => normalizeGrokLifecycle(response);
|
|
@@ -31326,7 +31060,7 @@ function createWritableAcpStream(output2) {
|
|
|
31326
31060
|
function truncate3(value, maximumLength) {
|
|
31327
31061
|
return value.length <= maximumLength ? value : `${value.slice(0, Math.max(0, maximumLength - 1))}\u2026`;
|
|
31328
31062
|
}
|
|
31329
|
-
function
|
|
31063
|
+
function isRecord5(value) {
|
|
31330
31064
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31331
31065
|
}
|
|
31332
31066
|
function readString4(value, fallback = "") {
|
|
@@ -31359,12 +31093,12 @@ function normalizeElicitationOptions(schema) {
|
|
|
31359
31093
|
const normalized = [];
|
|
31360
31094
|
const oneOf = schema["oneOf"];
|
|
31361
31095
|
if (Array.isArray(oneOf)) {
|
|
31362
|
-
for (const
|
|
31363
|
-
if (
|
|
31096
|
+
for (const option of oneOf) {
|
|
31097
|
+
if (isRecord5(option) && typeof option["const"] === "string") {
|
|
31364
31098
|
normalized.push({
|
|
31365
|
-
description: truncate3(readString4(
|
|
31366
|
-
label: truncate3(readString4(
|
|
31367
|
-
value: truncate3(
|
|
31099
|
+
description: truncate3(readString4(option["description"]), 500),
|
|
31100
|
+
label: truncate3(readString4(option["title"], option["const"]), 255),
|
|
31101
|
+
value: truncate3(option["const"], 500)
|
|
31368
31102
|
});
|
|
31369
31103
|
}
|
|
31370
31104
|
}
|
|
@@ -31380,7 +31114,7 @@ function normalizeElicitationOptions(schema) {
|
|
|
31380
31114
|
return normalized.slice(0, 200);
|
|
31381
31115
|
}
|
|
31382
31116
|
const items = schema["items"];
|
|
31383
|
-
if (!
|
|
31117
|
+
if (!isRecord5(items)) {
|
|
31384
31118
|
return normalized;
|
|
31385
31119
|
}
|
|
31386
31120
|
const anyOf = items["anyOf"];
|
|
@@ -31393,7 +31127,7 @@ function numericString(value) {
|
|
|
31393
31127
|
return typeof value === "number" && Number.isFinite(value) ? value.toString() : "";
|
|
31394
31128
|
}
|
|
31395
31129
|
function normalizeElicitationFields(requestedSchema) {
|
|
31396
|
-
if (!
|
|
31130
|
+
if (!isRecord5(requestedSchema) || !isRecord5(requestedSchema["properties"])) {
|
|
31397
31131
|
return [];
|
|
31398
31132
|
}
|
|
31399
31133
|
const properties2 = requestedSchema["properties"];
|
|
@@ -31403,7 +31137,7 @@ function normalizeElicitationFields(requestedSchema) {
|
|
|
31403
31137
|
);
|
|
31404
31138
|
const normalized = [];
|
|
31405
31139
|
for (const [name, property] of Object.entries(properties2)) {
|
|
31406
|
-
if (!
|
|
31140
|
+
if (!isRecord5(property)) {
|
|
31407
31141
|
continue;
|
|
31408
31142
|
}
|
|
31409
31143
|
const type = elicitationFieldType(property["type"]);
|
|
@@ -31494,7 +31228,7 @@ function validateElicitationContent(encoded, requestedSchema) {
|
|
|
31494
31228
|
"invalid_elicitation_response"
|
|
31495
31229
|
);
|
|
31496
31230
|
}
|
|
31497
|
-
if (!
|
|
31231
|
+
if (!isRecord5(decoded) || !isRecord5(requestedSchema) || !isRecord5(requestedSchema["properties"])) {
|
|
31498
31232
|
throw new AcpExecutionError(
|
|
31499
31233
|
"Elicitation response does not match the requested form",
|
|
31500
31234
|
{},
|
|
@@ -31514,7 +31248,7 @@ function validateElicitationContent(encoded, requestedSchema) {
|
|
|
31514
31248
|
const validated = {};
|
|
31515
31249
|
for (const [name, value] of Object.entries(decoded)) {
|
|
31516
31250
|
const property = properties2[name];
|
|
31517
|
-
if (!
|
|
31251
|
+
if (!isRecord5(property)) {
|
|
31518
31252
|
throw new AcpExecutionError(
|
|
31519
31253
|
`Elicitation field ${name} was not requested`,
|
|
31520
31254
|
{},
|
|
@@ -31551,7 +31285,7 @@ function validateElicitationContent(encoded, requestedSchema) {
|
|
|
31551
31285
|
);
|
|
31552
31286
|
}
|
|
31553
31287
|
const allowed = normalizeElicitationOptions(property);
|
|
31554
|
-
if (allowed.length > 0 && value.some((entry) => !allowed.some((
|
|
31288
|
+
if (allowed.length > 0 && value.some((entry) => !allowed.some((option) => option.value === entry))) {
|
|
31555
31289
|
throw new AcpExecutionError(
|
|
31556
31290
|
`Elicitation field ${name} contains an invalid selection`,
|
|
31557
31291
|
{},
|
|
@@ -31667,6 +31401,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
31667
31401
|
#permissionProfile;
|
|
31668
31402
|
#sessionConfigProtocol;
|
|
31669
31403
|
#store;
|
|
31404
|
+
#emittedToolImages = /* @__PURE__ */ new Set();
|
|
31670
31405
|
#verifiedAgentVersion;
|
|
31671
31406
|
#preSessionUpdateBytes = 0;
|
|
31672
31407
|
#agentName = "";
|
|
@@ -31887,19 +31622,19 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
31887
31622
|
}
|
|
31888
31623
|
};
|
|
31889
31624
|
prepareAgentContent = async (content3) => {
|
|
31890
|
-
if (content3.type === "image" && content3.
|
|
31891
|
-
const raster = readInlineRaster(content3.data, content3.name);
|
|
31892
|
-
if (raster !== null) {
|
|
31893
|
-
return await this.importRaster(raster, AbortSignal.timeout(2e4));
|
|
31894
|
-
}
|
|
31895
|
-
}
|
|
31896
|
-
if (content3.type === "image" && content3.data.length === 0 && content3.uri.length > 0) {
|
|
31625
|
+
if (content3.type === "image" && content3.uri.length > 0) {
|
|
31897
31626
|
const signal = AbortSignal.timeout(2e4);
|
|
31898
31627
|
const raster = await readLocalRaster(content3.uri, signal);
|
|
31899
31628
|
if (raster !== null) {
|
|
31900
31629
|
return await this.importRaster(raster, signal);
|
|
31901
31630
|
}
|
|
31902
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
|
+
}
|
|
31903
31638
|
if (content3.type === "video" && content3.data.length > 0) {
|
|
31904
31639
|
const video = readInlineVideo(content3.data, content3.mimeType, content3.name);
|
|
31905
31640
|
if (video === null) {
|
|
@@ -31920,6 +31655,22 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
31920
31655
|
sessionId: this.#mobiusSessionId
|
|
31921
31656
|
});
|
|
31922
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
|
+
};
|
|
31923
31674
|
emitRaster = async (raster, messageId, signal) => {
|
|
31924
31675
|
const content3 = await this.importRaster(raster, signal);
|
|
31925
31676
|
await this.#getObserver().onContent({
|
|
@@ -31931,14 +31682,14 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
31931
31682
|
sessionId: this.#mobiusSessionId
|
|
31932
31683
|
});
|
|
31933
31684
|
};
|
|
31934
|
-
importRaster = async (raster,
|
|
31935
|
-
|
|
31936
|
-
|
|
31937
|
-
|
|
31938
|
-
|
|
31939
|
-
|
|
31940
|
-
|
|
31941
|
-
);
|
|
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(), "");
|
|
31942
31693
|
};
|
|
31943
31694
|
importVideo = async (video, signal) => {
|
|
31944
31695
|
const artifactId = await this.#getObserver().importLocalArtifact(this.#mobiusSessionId, video, signal);
|
|
@@ -32225,7 +31976,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
32225
31976
|
};
|
|
32226
31977
|
nativeSessionId = () => this.#nativeSessionId;
|
|
32227
31978
|
configure = async (options) => {
|
|
32228
|
-
const existing = this.#configOptions.find((
|
|
31979
|
+
const existing = this.#configOptions.find((option) => option.id === options.configId);
|
|
32229
31980
|
if (existing === void 0 || existing.type !== options.valueType) {
|
|
32230
31981
|
throw new AcpExecutionError(
|
|
32231
31982
|
"The requested ACP configuration option is unavailable",
|
|
@@ -32422,7 +32173,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
32422
32173
|
"ACP agent exited during steering",
|
|
32423
32174
|
options.signal
|
|
32424
32175
|
);
|
|
32425
|
-
if (!
|
|
32176
|
+
if (!isRecord5(response)) {
|
|
32426
32177
|
throw new AcpExecutionError(
|
|
32427
32178
|
"ACP agent returned an invalid steering response",
|
|
32428
32179
|
{},
|
|
@@ -32537,10 +32288,10 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
32537
32288
|
onPermission = async (request, signal) => {
|
|
32538
32289
|
this.assertNativeSession(request.sessionId);
|
|
32539
32290
|
const interactionId = `permission-${crypto.randomUUID()}`;
|
|
32540
|
-
const options = request.options.slice(0, 20).map((
|
|
32541
|
-
kind:
|
|
32542
|
-
name: truncate3(
|
|
32543
|
-
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)
|
|
32544
32295
|
}));
|
|
32545
32296
|
if (options.length === 0) {
|
|
32546
32297
|
throw new AcpExecutionError(
|
|
@@ -32549,7 +32300,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
32549
32300
|
"invalid_agent_permission_request"
|
|
32550
32301
|
);
|
|
32551
32302
|
}
|
|
32552
|
-
const pending = new PendingPermission(interactionId, new Set(options.map((
|
|
32303
|
+
const pending = new PendingPermission(interactionId, new Set(options.map((option) => option.optionId)));
|
|
32553
32304
|
this.#pendingPermissions.set(interactionId, pending);
|
|
32554
32305
|
const abort = () => {
|
|
32555
32306
|
void this.cancelPermission(interactionId);
|
|
@@ -32718,6 +32469,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
32718
32469
|
}
|
|
32719
32470
|
if (update.sessionUpdate === "tool_call_update") {
|
|
32720
32471
|
await this.#turn.activities.recordToolCallUpdate(update);
|
|
32472
|
+
await this.emitToolImages(update);
|
|
32721
32473
|
return;
|
|
32722
32474
|
}
|
|
32723
32475
|
if (update.sessionUpdate === "plan") {
|
|
@@ -32757,7 +32509,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
32757
32509
|
}
|
|
32758
32510
|
if (update.sessionUpdate === "current_mode_update") {
|
|
32759
32511
|
this.#configOptions = this.#configOptions.map(
|
|
32760
|
-
(
|
|
32512
|
+
(option) => option.category === "mode" ? { ...option, currentValue: update.currentModeId } : option
|
|
32761
32513
|
);
|
|
32762
32514
|
this.#configRevision += 1;
|
|
32763
32515
|
await this.emitConfigUpdate();
|
|
@@ -33290,7 +33042,7 @@ var AcpSessionManager = class {
|
|
|
33290
33042
|
if (desired.id === PERMISSION_MODE_CONFIG_ID) {
|
|
33291
33043
|
continue;
|
|
33292
33044
|
}
|
|
33293
|
-
const current = runtime.prepared().configOptions.find((
|
|
33045
|
+
const current = runtime.prepared().configOptions.find((option) => option.id === desired.id);
|
|
33294
33046
|
if (current === void 0 || current.type !== desired.type) {
|
|
33295
33047
|
continue;
|
|
33296
33048
|
}
|
|
@@ -33396,7 +33148,7 @@ var AcpSessionManager = class {
|
|
|
33396
33148
|
async (runtime) => await runtime.close()
|
|
33397
33149
|
);
|
|
33398
33150
|
/**
|
|
33399
|
-
*
|
|
33151
|
+
* Retained for Agents that expose a separate persisted configuration channel.
|
|
33400
33152
|
* Use inspectAgentSettings for Agent-scoped settings discovery.
|
|
33401
33153
|
*/
|
|
33402
33154
|
inspectSession = async (options, metrics = unmeasuredOperationMetrics) => {
|
|
@@ -34016,563 +33768,12 @@ var LocalAuthorizationError = class extends Error {
|
|
|
34016
33768
|
}
|
|
34017
33769
|
};
|
|
34018
33770
|
|
|
34019
|
-
// src/bots/bot-execution-context.ts
|
|
34020
|
-
import { randomBytes } from "node:crypto";
|
|
34021
|
-
|
|
34022
|
-
// src/bots/local-bot-execution-authorizer.ts
|
|
34023
|
-
var LocalBotAuthorizationError = class extends Error {
|
|
34024
|
-
code;
|
|
34025
|
-
constructor(code, message, options = {}) {
|
|
34026
|
-
super(message, options);
|
|
34027
|
-
this.code = code;
|
|
34028
|
-
this.name = "LocalBotAuthorizationError";
|
|
34029
|
-
}
|
|
34030
|
-
};
|
|
34031
|
-
var AuthorizedLocalBotExecution = class {
|
|
34032
|
-
agent;
|
|
34033
|
-
behaviorDigest;
|
|
34034
|
-
behaviorRevisionId;
|
|
34035
|
-
bindingId;
|
|
34036
|
-
bindingRevision;
|
|
34037
|
-
botId;
|
|
34038
|
-
executionConfiguration;
|
|
34039
|
-
workspacePath;
|
|
34040
|
-
workspaceRef;
|
|
34041
|
-
constructor(command, agent, workspacePath) {
|
|
34042
|
-
this.agent = agent;
|
|
34043
|
-
this.behaviorDigest = command.behaviorDigest;
|
|
34044
|
-
this.behaviorRevisionId = command.behaviorRevisionId;
|
|
34045
|
-
this.bindingId = command.bindingId;
|
|
34046
|
-
this.bindingRevision = command.bindingRevision;
|
|
34047
|
-
this.botId = command.botId;
|
|
34048
|
-
this.executionConfiguration = command.executionConfiguration;
|
|
34049
|
-
this.workspacePath = workspacePath;
|
|
34050
|
-
this.workspaceRef = command.directoryId;
|
|
34051
|
-
}
|
|
34052
|
-
};
|
|
34053
|
-
var LocalBotExecutionAuthorizer = class {
|
|
34054
|
-
authorize = async (command, catalog, directories, bindingAuthorityId, signal) => {
|
|
34055
|
-
signal.throwIfAborted();
|
|
34056
|
-
let agent;
|
|
34057
|
-
try {
|
|
34058
|
-
agent = catalog.find(command.agentId).withPermissionMode(command.executionConfiguration.permissionMode);
|
|
34059
|
-
} catch (cause) {
|
|
34060
|
-
if (cause instanceof AgentPermissionConfigurationError) {
|
|
34061
|
-
throw new LocalBotAuthorizationError("binding_incompatible", cause.message, { cause });
|
|
34062
|
-
}
|
|
34063
|
-
throw cause;
|
|
34064
|
-
}
|
|
34065
|
-
const [adapterUnchanged, agentUnchanged] = await Promise.all([
|
|
34066
|
-
revalidateExecutable(agent.adapterIdentity),
|
|
34067
|
-
revalidateExecutable(agent.agentIdentity)
|
|
34068
|
-
]);
|
|
34069
|
-
signal.throwIfAborted();
|
|
34070
|
-
if (!adapterUnchanged || !agentUnchanged) {
|
|
34071
|
-
throw new LocalBotAuthorizationError(
|
|
34072
|
-
"binding_incompatible",
|
|
34073
|
-
"The local Agent executable changed while the Runtime is active; restart the Runtime"
|
|
34074
|
-
);
|
|
34075
|
-
}
|
|
34076
|
-
if (command.behaviorInstructions.length > 0 && !agent.capabilities.embeddedContextPrompt) {
|
|
34077
|
-
throw new LocalBotAuthorizationError(
|
|
34078
|
-
"binding_incompatible",
|
|
34079
|
-
"The local Agent cannot apply the Bot behavior"
|
|
34080
|
-
);
|
|
34081
|
-
}
|
|
34082
|
-
const workspacePath = await directories.resolve(bindingAuthorityId, command.directoryId, signal);
|
|
34083
|
-
signal.throwIfAborted();
|
|
34084
|
-
return new AuthorizedLocalBotExecution(command, agent, workspacePath);
|
|
34085
|
-
};
|
|
34086
|
-
};
|
|
34087
|
-
|
|
34088
|
-
// src/bots/bot-execution-context.ts
|
|
34089
|
-
var ActiveBotExecutionContext = class {
|
|
34090
|
-
command;
|
|
34091
|
-
contextHandle;
|
|
34092
|
-
constructor(contextHandle, command) {
|
|
34093
|
-
this.contextHandle = contextHandle;
|
|
34094
|
-
this.command = command;
|
|
34095
|
-
}
|
|
34096
|
-
resolveTarget = (target) => {
|
|
34097
|
-
if (target === "current") {
|
|
34098
|
-
if (!(this.command.replyRoute instanceof BotConnectionReplyRoute)) {
|
|
34099
|
-
throw new LocalBotAuthorizationError(
|
|
34100
|
-
"delivery_target_not_allowed",
|
|
34101
|
-
"This Bot conversation has no external reply target"
|
|
34102
|
-
);
|
|
34103
|
-
}
|
|
34104
|
-
return this.command.replyRoute.deliveryTargetId;
|
|
34105
|
-
}
|
|
34106
|
-
const resolved = this.command.allowedDeliveryTargets.find((candidate) => candidate.alias === target);
|
|
34107
|
-
if (resolved === void 0) {
|
|
34108
|
-
throw new LocalBotAuthorizationError(
|
|
34109
|
-
"delivery_target_not_allowed",
|
|
34110
|
-
"The named Bot delivery target is not approved"
|
|
34111
|
-
);
|
|
34112
|
-
}
|
|
34113
|
-
return resolved.deliveryTargetId;
|
|
34114
|
-
};
|
|
34115
|
-
};
|
|
34116
|
-
var BotExecutionContextLease = class {
|
|
34117
|
-
context;
|
|
34118
|
-
#release;
|
|
34119
|
-
#released = false;
|
|
34120
|
-
constructor(context, release) {
|
|
34121
|
-
this.context = context;
|
|
34122
|
-
this.#release = release;
|
|
34123
|
-
}
|
|
34124
|
-
release = () => {
|
|
34125
|
-
if (this.#released) {
|
|
34126
|
-
return;
|
|
34127
|
-
}
|
|
34128
|
-
this.#released = true;
|
|
34129
|
-
this.#release();
|
|
34130
|
-
};
|
|
34131
|
-
};
|
|
34132
|
-
var BotExecutionContextRegistry = class {
|
|
34133
|
-
#activeByHandle = /* @__PURE__ */ new Map();
|
|
34134
|
-
#handlesBySession = /* @__PURE__ */ new Map();
|
|
34135
|
-
#inactiveHandles = /* @__PURE__ */ new Set();
|
|
34136
|
-
activate = (command) => {
|
|
34137
|
-
let handle = this.#handlesBySession.get(command.sessionId);
|
|
34138
|
-
if (handle === void 0) {
|
|
34139
|
-
handle = `ctx_${Buffer.from(randomBytes(32)).toString("base64url")}`;
|
|
34140
|
-
this.#handlesBySession.set(command.sessionId, handle);
|
|
34141
|
-
}
|
|
34142
|
-
if (this.#activeByHandle.has(handle)) {
|
|
34143
|
-
throw new LocalBotAuthorizationError("session_busy", "The Bot execution context is already active");
|
|
34144
|
-
}
|
|
34145
|
-
const context = new ActiveBotExecutionContext(handle, command);
|
|
34146
|
-
this.#inactiveHandles.delete(handle);
|
|
34147
|
-
this.#activeByHandle.set(handle, context);
|
|
34148
|
-
return new BotExecutionContextLease(context, () => {
|
|
34149
|
-
if (this.#activeByHandle.get(handle) === context) {
|
|
34150
|
-
this.#activeByHandle.delete(handle);
|
|
34151
|
-
this.#inactiveHandles.add(handle);
|
|
34152
|
-
}
|
|
34153
|
-
});
|
|
34154
|
-
};
|
|
34155
|
-
read = (handle) => {
|
|
34156
|
-
const context = this.#activeByHandle.get(handle);
|
|
34157
|
-
if (context === void 0) {
|
|
34158
|
-
if (this.#inactiveHandles.has(handle)) {
|
|
34159
|
-
throw new LocalBotAuthorizationError(
|
|
34160
|
-
"execution_capability_expired",
|
|
34161
|
-
"The Bot execution capability has expired"
|
|
34162
|
-
);
|
|
34163
|
-
}
|
|
34164
|
-
throw new LocalBotAuthorizationError(
|
|
34165
|
-
"execution_context_required",
|
|
34166
|
-
"An active Bot execution context is required"
|
|
34167
|
-
);
|
|
34168
|
-
}
|
|
34169
|
-
return context;
|
|
34170
|
-
};
|
|
34171
|
-
};
|
|
34172
|
-
|
|
34173
|
-
// src/bots/bot-message-command.ts
|
|
34174
|
-
import { randomUUID } from "node:crypto";
|
|
34175
|
-
import { createConnection } from "node:net";
|
|
34176
|
-
var BOT_IPC_RESPONSE_LIMIT = 64 * 1024;
|
|
34177
|
-
var BOT_IPC_TIMEOUT_MILLISECONDS = 2e4;
|
|
34178
|
-
var BotMessageCommandError = class extends Error {
|
|
34179
|
-
code;
|
|
34180
|
-
constructor(code, message, options = {}) {
|
|
34181
|
-
super(message, options);
|
|
34182
|
-
this.code = code;
|
|
34183
|
-
this.name = "BotMessageCommandError";
|
|
34184
|
-
}
|
|
34185
|
-
};
|
|
34186
|
-
function isRecord7(value) {
|
|
34187
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
34188
|
-
}
|
|
34189
|
-
function requiredEnvironment(environment, name) {
|
|
34190
|
-
const value = environment[name]?.trim();
|
|
34191
|
-
if (value === void 0 || value.length === 0) {
|
|
34192
|
-
throw new BotMessageCommandError(
|
|
34193
|
-
"execution_context_required",
|
|
34194
|
-
"This command is available only inside an active Mobius Bot execution"
|
|
34195
|
-
);
|
|
34196
|
-
}
|
|
34197
|
-
return value;
|
|
34198
|
-
}
|
|
34199
|
-
function option(arguments_, name) {
|
|
34200
|
-
const index2 = arguments_.indexOf(name);
|
|
34201
|
-
if (index2 < 0 || index2 + 1 >= arguments_.length || arguments_[index2 + 1]?.startsWith("--") === true) {
|
|
34202
|
-
throw new BotMessageCommandError(
|
|
34203
|
-
"invalid_request",
|
|
34204
|
-
"Usage: mobius bot message send --target <current|alias> --text <message>"
|
|
34205
|
-
);
|
|
34206
|
-
}
|
|
34207
|
-
const value = arguments_[index2 + 1];
|
|
34208
|
-
if (value === void 0) {
|
|
34209
|
-
throw new BotMessageCommandError("invalid_request", "The Bot message option is missing");
|
|
34210
|
-
}
|
|
34211
|
-
return value;
|
|
34212
|
-
}
|
|
34213
|
-
function validateArguments(arguments_) {
|
|
34214
|
-
if (arguments_.length !== 4) {
|
|
34215
|
-
throw new BotMessageCommandError(
|
|
34216
|
-
"invalid_request",
|
|
34217
|
-
"Usage: mobius bot message send --target <current|alias> --text <message>"
|
|
34218
|
-
);
|
|
34219
|
-
}
|
|
34220
|
-
const names = [arguments_[0], arguments_[2]];
|
|
34221
|
-
if (!names.includes("--target") || !names.includes("--text") || names[0] === names[1]) {
|
|
34222
|
-
throw new BotMessageCommandError(
|
|
34223
|
-
"invalid_request",
|
|
34224
|
-
"Usage: mobius bot message send --target <current|alias> --text <message>"
|
|
34225
|
-
);
|
|
34226
|
-
}
|
|
34227
|
-
}
|
|
34228
|
-
function decodeResponse(encoded) {
|
|
34229
|
-
let value;
|
|
34230
|
-
try {
|
|
34231
|
-
value = JSON.parse(encoded);
|
|
34232
|
-
} catch (cause) {
|
|
34233
|
-
throw new BotMessageCommandError("bot_service_unavailable", "The local Bot service returned invalid data", {
|
|
34234
|
-
cause
|
|
34235
|
-
});
|
|
34236
|
-
}
|
|
34237
|
-
if (!isRecord7(value) || typeof value["ok"] !== "boolean") {
|
|
34238
|
-
throw new BotMessageCommandError("bot_service_unavailable", "The local Bot service returned invalid data");
|
|
34239
|
-
}
|
|
34240
|
-
if (value["ok"] === true && typeof value["outboundMessageId"] === "string") {
|
|
34241
|
-
return value["outboundMessageId"];
|
|
34242
|
-
}
|
|
34243
|
-
const error62 = value["error"];
|
|
34244
|
-
if (value["ok"] === false && isRecord7(error62) && typeof error62["code"] === "string" && typeof error62["message"] === "string") {
|
|
34245
|
-
throw new BotMessageCommandError(error62["code"], error62["message"]);
|
|
34246
|
-
}
|
|
34247
|
-
throw new BotMessageCommandError("bot_service_unavailable", "The local Bot service returned invalid data");
|
|
34248
|
-
}
|
|
34249
|
-
async function requestLocalBotService(socketPath, payload, signal) {
|
|
34250
|
-
signal.throwIfAborted();
|
|
34251
|
-
return await new Promise((resolve6, reject) => {
|
|
34252
|
-
const socket = createConnection(socketPath);
|
|
34253
|
-
const chunks = [];
|
|
34254
|
-
let length = 0;
|
|
34255
|
-
let finished = false;
|
|
34256
|
-
const finish = () => {
|
|
34257
|
-
socket.removeAllListeners();
|
|
34258
|
-
socket.destroy();
|
|
34259
|
-
};
|
|
34260
|
-
const fail = (error62) => {
|
|
34261
|
-
if (finished) {
|
|
34262
|
-
return;
|
|
34263
|
-
}
|
|
34264
|
-
finished = true;
|
|
34265
|
-
finish();
|
|
34266
|
-
if (error62 instanceof BotMessageCommandError) {
|
|
34267
|
-
reject(error62);
|
|
34268
|
-
return;
|
|
34269
|
-
}
|
|
34270
|
-
reject(
|
|
34271
|
-
new BotMessageCommandError(
|
|
34272
|
-
"execution_context_required",
|
|
34273
|
-
"The active Mobius Bot execution is unavailable",
|
|
34274
|
-
{ cause: error62 }
|
|
34275
|
-
)
|
|
34276
|
-
);
|
|
34277
|
-
};
|
|
34278
|
-
const abort = () => fail(signal.reason);
|
|
34279
|
-
socket.setTimeout(BOT_IPC_TIMEOUT_MILLISECONDS, () => {
|
|
34280
|
-
fail(new BotMessageCommandError("bot_service_unavailable", "The local Bot service timed out"));
|
|
34281
|
-
});
|
|
34282
|
-
socket.once("error", fail);
|
|
34283
|
-
socket.once("connect", () => socket.end(`${payload}
|
|
34284
|
-
`));
|
|
34285
|
-
socket.on("data", (chunk) => {
|
|
34286
|
-
length += chunk.byteLength;
|
|
34287
|
-
if (length > BOT_IPC_RESPONSE_LIMIT) {
|
|
34288
|
-
fail(new BotMessageCommandError("bot_service_unavailable", "The local Bot response is too large"));
|
|
34289
|
-
return;
|
|
34290
|
-
}
|
|
34291
|
-
chunks.push(chunk);
|
|
34292
|
-
});
|
|
34293
|
-
socket.once("end", () => {
|
|
34294
|
-
if (finished) {
|
|
34295
|
-
return;
|
|
34296
|
-
}
|
|
34297
|
-
finished = true;
|
|
34298
|
-
signal.removeEventListener("abort", abort);
|
|
34299
|
-
try {
|
|
34300
|
-
resolve6(decodeResponse(Buffer.concat(chunks).toString("utf8")));
|
|
34301
|
-
} catch (error62) {
|
|
34302
|
-
reject(error62);
|
|
34303
|
-
} finally {
|
|
34304
|
-
finish();
|
|
34305
|
-
}
|
|
34306
|
-
});
|
|
34307
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
34308
|
-
});
|
|
34309
|
-
}
|
|
34310
|
-
async function executeBotMessageCommand(arguments_, environment, signal) {
|
|
34311
|
-
validateArguments(arguments_);
|
|
34312
|
-
const contextHandle = requiredEnvironment(environment, "MOBIUS_BOT_CONTEXT");
|
|
34313
|
-
const socketPath = requiredEnvironment(environment, "MOBIUS_BOT_SOCKET");
|
|
34314
|
-
const target = option(arguments_, "--target");
|
|
34315
|
-
const text3 = option(arguments_, "--text");
|
|
34316
|
-
if (!/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/.test(target) || text3.trim().length === 0 || text3.length > 1e4) {
|
|
34317
|
-
throw new BotMessageCommandError("invalid_request", "The Bot outbound message is invalid");
|
|
34318
|
-
}
|
|
34319
|
-
return await requestLocalBotService(
|
|
34320
|
-
socketPath,
|
|
34321
|
-
JSON.stringify({
|
|
34322
|
-
contextHandle,
|
|
34323
|
-
idempotencyKey: `cli_${randomUUID()}`,
|
|
34324
|
-
target,
|
|
34325
|
-
text: text3
|
|
34326
|
-
}),
|
|
34327
|
-
signal
|
|
34328
|
-
);
|
|
34329
|
-
}
|
|
34330
|
-
|
|
34331
|
-
// src/bots/bot-outbound-ipc.ts
|
|
34332
|
-
import { chmod, mkdir, unlink } from "node:fs/promises";
|
|
34333
|
-
import { createServer } from "node:net";
|
|
34334
|
-
import { dirname as dirname3, isAbsolute as isAbsolute2 } from "node:path";
|
|
34335
|
-
import { fetch } from "undici";
|
|
34336
|
-
var BOT_IPC_REQUEST_LIMIT = 32 * 1024;
|
|
34337
|
-
var BOT_IPC_TIMEOUT_MILLISECONDS2 = 2e4;
|
|
34338
|
-
var BOT_RELAY_TIMEOUT_MILLISECONDS = 2e4;
|
|
34339
|
-
var IDENTIFIER_PATTERN5 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
34340
|
-
var WINDOWS_NAMED_PIPE_PREFIX = "\\\\.\\pipe\\";
|
|
34341
|
-
var BotOutboundIpcRequest = class {
|
|
34342
|
-
contextHandle;
|
|
34343
|
-
idempotencyKey;
|
|
34344
|
-
target;
|
|
34345
|
-
text;
|
|
34346
|
-
constructor(contextHandle, idempotencyKey, target, text3) {
|
|
34347
|
-
this.contextHandle = contextHandle;
|
|
34348
|
-
this.idempotencyKey = idempotencyKey;
|
|
34349
|
-
this.target = target;
|
|
34350
|
-
this.text = text3;
|
|
34351
|
-
}
|
|
34352
|
-
};
|
|
34353
|
-
function isRecord8(value) {
|
|
34354
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
34355
|
-
}
|
|
34356
|
-
function decodeRequest(encoded) {
|
|
34357
|
-
let value;
|
|
34358
|
-
try {
|
|
34359
|
-
value = JSON.parse(encoded);
|
|
34360
|
-
} catch (cause) {
|
|
34361
|
-
throw new LocalBotAuthorizationError("invalid_request", "The local Bot request is invalid", { cause });
|
|
34362
|
-
}
|
|
34363
|
-
if (!isRecord8(value)) {
|
|
34364
|
-
throw new LocalBotAuthorizationError("invalid_request", "The local Bot request is invalid");
|
|
34365
|
-
}
|
|
34366
|
-
const keys = Object.keys(value);
|
|
34367
|
-
if (keys.length !== 4 || !keys.every((key) => ["contextHandle", "idempotencyKey", "target", "text"].includes(key))) {
|
|
34368
|
-
throw new LocalBotAuthorizationError("invalid_request", "The local Bot request fields are invalid");
|
|
34369
|
-
}
|
|
34370
|
-
const contextHandle = value["contextHandle"];
|
|
34371
|
-
const idempotencyKey = value["idempotencyKey"];
|
|
34372
|
-
const target = value["target"];
|
|
34373
|
-
const text3 = value["text"];
|
|
34374
|
-
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) {
|
|
34375
|
-
throw new LocalBotAuthorizationError("invalid_request", "The local Bot request is invalid");
|
|
34376
|
-
}
|
|
34377
|
-
return new BotOutboundIpcRequest(contextHandle, idempotencyKey, target, text3);
|
|
34378
|
-
}
|
|
34379
|
-
function relayEndpoint(relayUrl, context, target) {
|
|
34380
|
-
const endpoint = new URL(relayUrl);
|
|
34381
|
-
if (endpoint.protocol !== "ws:" && endpoint.protocol !== "wss:") {
|
|
34382
|
-
throw new LocalBotAuthorizationError("bot_service_unavailable", "The Mobius Relay URL is invalid");
|
|
34383
|
-
}
|
|
34384
|
-
endpoint.protocol = endpoint.protocol === "wss:" ? "https:" : "http:";
|
|
34385
|
-
endpoint.search = "";
|
|
34386
|
-
const execution = encodeURIComponent(context.command.executionId);
|
|
34387
|
-
if (target === "current") {
|
|
34388
|
-
context.resolveTarget(target);
|
|
34389
|
-
endpoint.pathname = `${MOBIUS_API_PREFIX}/v1/bot-executions/${execution}/reply-messages`;
|
|
34390
|
-
return endpoint;
|
|
34391
|
-
}
|
|
34392
|
-
const deliveryTargetId = context.resolveTarget(target);
|
|
34393
|
-
endpoint.pathname = `${MOBIUS_API_PREFIX}/v1/bot-executions/${execution}/delivery-targets/${encodeURIComponent(deliveryTargetId)}/messages`;
|
|
34394
|
-
return endpoint;
|
|
34395
|
-
}
|
|
34396
|
-
function daemonToken(relayUrl) {
|
|
34397
|
-
const token = relayUrl.searchParams.get("token") ?? "";
|
|
34398
|
-
if (!/^[a-zA-Z0-9_-]{32,256}$/.test(token)) {
|
|
34399
|
-
throw new LocalBotAuthorizationError("bot_service_unavailable", "The Runtime credential is unavailable");
|
|
34400
|
-
}
|
|
34401
|
-
return token;
|
|
34402
|
-
}
|
|
34403
|
-
async function decodeRelayResponse(response) {
|
|
34404
|
-
const encoded = await response.text();
|
|
34405
|
-
let value;
|
|
34406
|
-
try {
|
|
34407
|
-
value = JSON.parse(encoded);
|
|
34408
|
-
} catch (cause) {
|
|
34409
|
-
throw new LocalBotAuthorizationError("bot_service_unavailable", "The Mobius Relay returned invalid data", {
|
|
34410
|
-
cause
|
|
34411
|
-
});
|
|
34412
|
-
}
|
|
34413
|
-
if (response.status === 202 && isRecord8(value) && typeof value["outboundMessageId"] === "string") {
|
|
34414
|
-
return value["outboundMessageId"];
|
|
34415
|
-
}
|
|
34416
|
-
if (isRecord8(value) && isRecord8(value["error"])) {
|
|
34417
|
-
const error62 = value["error"];
|
|
34418
|
-
if (typeof error62["code"] === "string" && typeof error62["message"] === "string") {
|
|
34419
|
-
throw new LocalBotAuthorizationError(error62["code"], error62["message"]);
|
|
34420
|
-
}
|
|
34421
|
-
}
|
|
34422
|
-
throw new LocalBotAuthorizationError("bot_service_unavailable", "The Mobius Relay rejected the Bot action");
|
|
34423
|
-
}
|
|
34424
|
-
var BotOutboundIpcServer = class {
|
|
34425
|
-
#registry;
|
|
34426
|
-
#relayUrl;
|
|
34427
|
-
#server;
|
|
34428
|
-
#socketPath;
|
|
34429
|
-
#usesFilesystemSocket;
|
|
34430
|
-
constructor(socketPath, relayUrl, registry2) {
|
|
34431
|
-
const usesFilesystemSocket = !socketPath.startsWith(WINDOWS_NAMED_PIPE_PREFIX);
|
|
34432
|
-
if (usesFilesystemSocket && !isAbsolute2(socketPath)) {
|
|
34433
|
-
throw new Error("The Bot IPC path must be absolute");
|
|
34434
|
-
}
|
|
34435
|
-
this.#registry = registry2;
|
|
34436
|
-
this.#relayUrl = new URL(relayUrl);
|
|
34437
|
-
this.#server = createServer({ allowHalfOpen: true }, (socket) => this.accept(socket));
|
|
34438
|
-
this.#socketPath = socketPath;
|
|
34439
|
-
this.#usesFilesystemSocket = usesFilesystemSocket;
|
|
34440
|
-
}
|
|
34441
|
-
get socketPath() {
|
|
34442
|
-
return this.#socketPath;
|
|
34443
|
-
}
|
|
34444
|
-
listen = async (signal) => {
|
|
34445
|
-
signal.throwIfAborted();
|
|
34446
|
-
if (this.#usesFilesystemSocket) {
|
|
34447
|
-
await mkdir(dirname3(this.#socketPath), { mode: 448, recursive: true });
|
|
34448
|
-
await unlink(this.#socketPath).catch((error62) => {
|
|
34449
|
-
if (!isRecord8(error62) || error62["code"] !== "ENOENT") {
|
|
34450
|
-
throw error62;
|
|
34451
|
-
}
|
|
34452
|
-
});
|
|
34453
|
-
}
|
|
34454
|
-
await new Promise((resolve6, reject) => {
|
|
34455
|
-
const fail = (error62) => reject(error62);
|
|
34456
|
-
this.#server.once("error", fail);
|
|
34457
|
-
this.#server.listen(this.#socketPath, () => {
|
|
34458
|
-
this.#server.removeListener("error", fail);
|
|
34459
|
-
resolve6();
|
|
34460
|
-
});
|
|
34461
|
-
});
|
|
34462
|
-
if (this.#usesFilesystemSocket) {
|
|
34463
|
-
await chmod(this.#socketPath, 384);
|
|
34464
|
-
}
|
|
34465
|
-
signal.addEventListener("abort", this.abort, { once: true });
|
|
34466
|
-
if (signal.aborted) {
|
|
34467
|
-
this.abort();
|
|
34468
|
-
}
|
|
34469
|
-
};
|
|
34470
|
-
close = async () => {
|
|
34471
|
-
if (this.#server.listening) {
|
|
34472
|
-
await new Promise((resolve6, reject) => {
|
|
34473
|
-
this.#server.close((error62) => {
|
|
34474
|
-
if (error62 === void 0) {
|
|
34475
|
-
resolve6();
|
|
34476
|
-
return;
|
|
34477
|
-
}
|
|
34478
|
-
reject(error62);
|
|
34479
|
-
});
|
|
34480
|
-
});
|
|
34481
|
-
}
|
|
34482
|
-
if (this.#usesFilesystemSocket) {
|
|
34483
|
-
await unlink(this.#socketPath).catch((error62) => {
|
|
34484
|
-
if (!isRecord8(error62) || error62["code"] !== "ENOENT") {
|
|
34485
|
-
throw error62;
|
|
34486
|
-
}
|
|
34487
|
-
});
|
|
34488
|
-
}
|
|
34489
|
-
};
|
|
34490
|
-
#abort = () => {
|
|
34491
|
-
this.#server.close();
|
|
34492
|
-
};
|
|
34493
|
-
abort = () => this.#abort();
|
|
34494
|
-
accept = (socket) => {
|
|
34495
|
-
const chunks = [];
|
|
34496
|
-
let length = 0;
|
|
34497
|
-
let rejected = false;
|
|
34498
|
-
const controller = new AbortController();
|
|
34499
|
-
socket.setTimeout(BOT_IPC_TIMEOUT_MILLISECONDS2, () => {
|
|
34500
|
-
controller.abort(new Error("Bot IPC request timed out"));
|
|
34501
|
-
socket.destroy();
|
|
34502
|
-
});
|
|
34503
|
-
socket.on("data", (chunk) => {
|
|
34504
|
-
length += chunk.byteLength;
|
|
34505
|
-
if (length > BOT_IPC_REQUEST_LIMIT) {
|
|
34506
|
-
rejected = true;
|
|
34507
|
-
controller.abort(new Error("Bot IPC request is too large"));
|
|
34508
|
-
socket.end(
|
|
34509
|
-
JSON.stringify({
|
|
34510
|
-
error: { code: "invalid_request", message: "The local Bot request is too large" },
|
|
34511
|
-
ok: false
|
|
34512
|
-
})
|
|
34513
|
-
);
|
|
34514
|
-
return;
|
|
34515
|
-
}
|
|
34516
|
-
chunks.push(chunk);
|
|
34517
|
-
});
|
|
34518
|
-
socket.once("error", () => controller.abort());
|
|
34519
|
-
socket.once("close", () => controller.abort());
|
|
34520
|
-
socket.once("end", () => {
|
|
34521
|
-
if (rejected) {
|
|
34522
|
-
return;
|
|
34523
|
-
}
|
|
34524
|
-
void this.handle(Buffer.concat(chunks).toString("utf8").trim(), controller.signal).then(
|
|
34525
|
-
(outboundMessageId) => {
|
|
34526
|
-
if (!socket.destroyed) {
|
|
34527
|
-
socket.end(JSON.stringify({ ok: true, outboundMessageId }));
|
|
34528
|
-
}
|
|
34529
|
-
},
|
|
34530
|
-
(error62) => {
|
|
34531
|
-
if (socket.destroyed) {
|
|
34532
|
-
return;
|
|
34533
|
-
}
|
|
34534
|
-
const code = error62 instanceof LocalBotAuthorizationError ? error62.code : "bot_service_unavailable";
|
|
34535
|
-
const message = error62 instanceof LocalBotAuthorizationError ? error62.message : "The local Bot action could not be completed";
|
|
34536
|
-
socket.end(JSON.stringify({ error: { code, message }, ok: false }));
|
|
34537
|
-
}
|
|
34538
|
-
);
|
|
34539
|
-
});
|
|
34540
|
-
};
|
|
34541
|
-
handle = async (encoded, signal) => {
|
|
34542
|
-
const request = decodeRequest(encoded);
|
|
34543
|
-
const context = this.#registry.read(request.contextHandle);
|
|
34544
|
-
const timeout = AbortSignal.timeout(BOT_RELAY_TIMEOUT_MILLISECONDS);
|
|
34545
|
-
const requestSignal = AbortSignal.any([signal, timeout]);
|
|
34546
|
-
let response;
|
|
34547
|
-
try {
|
|
34548
|
-
response = await fetch(relayEndpoint(this.#relayUrl, context, request.target), {
|
|
34549
|
-
body: JSON.stringify({ idempotencyKey: request.idempotencyKey, text: request.text }),
|
|
34550
|
-
headers: {
|
|
34551
|
-
authorization: `Bearer ${daemonToken(this.#relayUrl)}`,
|
|
34552
|
-
"content-type": "application/json",
|
|
34553
|
-
"x-mobius-bot-execution-capability": context.command.executionCapabilitySecret
|
|
34554
|
-
},
|
|
34555
|
-
method: "POST",
|
|
34556
|
-
signal: requestSignal
|
|
34557
|
-
});
|
|
34558
|
-
} catch (cause) {
|
|
34559
|
-
signal.throwIfAborted();
|
|
34560
|
-
throw new LocalBotAuthorizationError(
|
|
34561
|
-
timeout.aborted ? "bot_service_timeout" : "bot_service_unavailable",
|
|
34562
|
-
timeout.aborted ? "The Mobius Bot action timed out" : "The Mobius Relay is unavailable",
|
|
34563
|
-
{ cause }
|
|
34564
|
-
);
|
|
34565
|
-
}
|
|
34566
|
-
return await decodeRelayResponse(response);
|
|
34567
|
-
};
|
|
34568
|
-
};
|
|
34569
|
-
|
|
34570
33771
|
// src/pairing/pair-local-machine.ts
|
|
34571
|
-
import { randomUUID
|
|
34572
|
-
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";
|
|
34573
33774
|
import { hostname as hostname3 } from "node:os";
|
|
34574
33775
|
import { basename as basename3, join as join15, resolve as resolve3 } from "node:path";
|
|
34575
|
-
import { fetch as
|
|
33776
|
+
import { fetch as fetch2 } from "undici";
|
|
34576
33777
|
|
|
34577
33778
|
// src/agent-catalog/agent-discovery.ts
|
|
34578
33779
|
var AgentDiscovery = class {
|
|
@@ -34681,8 +33882,8 @@ var LocalAgentInventory = class {
|
|
|
34681
33882
|
};
|
|
34682
33883
|
|
|
34683
33884
|
// src/agent-installation/managed-npm-package.ts
|
|
34684
|
-
import { mkdir
|
|
34685
|
-
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";
|
|
34686
33887
|
var INSTALL_TIMEOUT_MILLISECONDS = 5 * 60 * 1e3;
|
|
34687
33888
|
var PACKAGE_METADATA_LIMIT_BYTES = 64 * 1024;
|
|
34688
33889
|
var PACKAGE_LOCK_LIMIT_BYTES = 8 * 1024 * 1024;
|
|
@@ -34729,7 +33930,7 @@ var ManagedNpmPackageError = class extends Error {
|
|
|
34729
33930
|
this.name = "ManagedNpmPackageError";
|
|
34730
33931
|
}
|
|
34731
33932
|
};
|
|
34732
|
-
function
|
|
33933
|
+
function isRecord6(value) {
|
|
34733
33934
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
34734
33935
|
}
|
|
34735
33936
|
function packagePath(root, packageName) {
|
|
@@ -34737,11 +33938,11 @@ function packagePath(root, packageName) {
|
|
|
34737
33938
|
}
|
|
34738
33939
|
function isContainedPath(root, candidate) {
|
|
34739
33940
|
const difference = relative(root, candidate);
|
|
34740
|
-
return difference.length > 0 && difference !== ".." && !difference.startsWith(`..${sep}`) && !
|
|
33941
|
+
return difference.length > 0 && difference !== ".." && !difference.startsWith(`..${sep}`) && !isAbsolute2(difference);
|
|
34741
33942
|
}
|
|
34742
33943
|
async function readJsonRecord(path2, maximumBytes) {
|
|
34743
33944
|
try {
|
|
34744
|
-
const handle = await
|
|
33945
|
+
const handle = await open3(path2, "r");
|
|
34745
33946
|
try {
|
|
34746
33947
|
const metadata = await handle.stat();
|
|
34747
33948
|
if (!metadata.isFile() || metadata.size > maximumBytes) {
|
|
@@ -34751,7 +33952,7 @@ async function readJsonRecord(path2, maximumBytes) {
|
|
|
34751
33952
|
);
|
|
34752
33953
|
}
|
|
34753
33954
|
const value = JSON.parse(await handle.readFile({ encoding: "utf8" }));
|
|
34754
|
-
if (!
|
|
33955
|
+
if (!isRecord6(value)) {
|
|
34755
33956
|
throw new ManagedNpmPackageError(
|
|
34756
33957
|
"managed_package_verification_failed",
|
|
34757
33958
|
"The managed npm package metadata is invalid"
|
|
@@ -34777,7 +33978,7 @@ function readBinPath(packageMetadata, executableName) {
|
|
|
34777
33978
|
if (typeof bin === "string") {
|
|
34778
33979
|
return bin;
|
|
34779
33980
|
}
|
|
34780
|
-
if (
|
|
33981
|
+
if (isRecord6(bin) && typeof bin[executableName] === "string") {
|
|
34781
33982
|
return bin[executableName];
|
|
34782
33983
|
}
|
|
34783
33984
|
throw new ManagedNpmPackageError(
|
|
@@ -34793,7 +33994,7 @@ function verifyPackageLockEntry(lock, definition2, verifyDependencyClosure) {
|
|
|
34793
33994
|
);
|
|
34794
33995
|
}
|
|
34795
33996
|
const packages = lock["packages"];
|
|
34796
|
-
if (!
|
|
33997
|
+
if (!isRecord6(packages)) {
|
|
34797
33998
|
throw new ManagedNpmPackageError(
|
|
34798
33999
|
"managed_package_verification_failed",
|
|
34799
34000
|
"The managed npm package lockfile is invalid"
|
|
@@ -34807,7 +34008,7 @@ function verifyPackageLockEntry(lock, definition2, verifyDependencyClosure) {
|
|
|
34807
34008
|
if (verifyDependencyClosure && normalizedKey.length > 0) {
|
|
34808
34009
|
let resolved;
|
|
34809
34010
|
try {
|
|
34810
|
-
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") {
|
|
34811
34012
|
throw new Error("Invalid locked dependency");
|
|
34812
34013
|
}
|
|
34813
34014
|
resolved = new URL(candidate["resolved"]);
|
|
@@ -34830,7 +34031,7 @@ function verifyPackageLockEntry(lock, definition2, verifyDependencyClosure) {
|
|
|
34830
34031
|
matches += 1;
|
|
34831
34032
|
}
|
|
34832
34033
|
}
|
|
34833
|
-
if (matches !== 1 || !
|
|
34034
|
+
if (matches !== 1 || !isRecord6(entry) || entry["integrity"] !== definition2.integrity || entry["resolved"] !== definition2.tarballUrl || entry["version"] !== definition2.version) {
|
|
34834
34035
|
throw new ManagedNpmPackageError(
|
|
34835
34036
|
"managed_package_verification_failed",
|
|
34836
34037
|
"The managed npm package lockfile does not match the pinned artifact"
|
|
@@ -34912,8 +34113,8 @@ var ManagedNpmPackageInstaller = class {
|
|
|
34912
34113
|
throw error62;
|
|
34913
34114
|
}
|
|
34914
34115
|
}
|
|
34915
|
-
const parent =
|
|
34916
|
-
await
|
|
34116
|
+
const parent = dirname3(root);
|
|
34117
|
+
await mkdir(parent, { mode: 448, recursive: true });
|
|
34917
34118
|
const staging = await mkdtemp(join4(parent, `.${definition2.version}.staging-`));
|
|
34918
34119
|
try {
|
|
34919
34120
|
const npm = await findExecutableOnPath(process.platform === "win32" ? "npm.cmd" : "npm", environment);
|
|
@@ -34947,7 +34148,7 @@ var ManagedNpmPackageInstaller = class {
|
|
|
34947
34148
|
NPM_CONFIG_IGNORE_SCRIPTS: "true",
|
|
34948
34149
|
NPM_CONFIG_PACKAGE_LOCK: "true",
|
|
34949
34150
|
NPM_CONFIG_REGISTRY: "https://registry.npmjs.org/",
|
|
34950
|
-
PATH: `${
|
|
34151
|
+
PATH: `${dirname3(process.execPath)}${delimiter}/usr/bin${delimiter}/bin`
|
|
34951
34152
|
};
|
|
34952
34153
|
if (definition2.includeOptionalDependencies) {
|
|
34953
34154
|
installEnvironment["NPM_CONFIG_INCLUDE"] = "optional";
|
|
@@ -35130,12 +34331,12 @@ var AgentProbeError = class extends Error {
|
|
|
35130
34331
|
};
|
|
35131
34332
|
|
|
35132
34333
|
// src/agent-catalog/agents/resolve-user-local-executable.ts
|
|
35133
|
-
import { isAbsolute as
|
|
34334
|
+
import { isAbsolute as isAbsolute3, join as join6 } from "node:path";
|
|
35134
34335
|
async function resolveUserLocalExecutable(executableName, context) {
|
|
35135
34336
|
context.signal.throwIfAborted();
|
|
35136
34337
|
const platform = context.platform ?? process.platform;
|
|
35137
34338
|
const homeDirectory = context.environment["HOME"];
|
|
35138
|
-
if (platform === "win32" || homeDirectory === void 0 || !
|
|
34339
|
+
if (platform === "win32" || homeDirectory === void 0 || !isAbsolute3(homeDirectory)) {
|
|
35139
34340
|
return [];
|
|
35140
34341
|
}
|
|
35141
34342
|
const executable = await resolveExecutablePath(join6(homeDirectory, ".local", "bin", executableName), platform);
|
|
@@ -35224,7 +34425,7 @@ var CursorCliAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
35224
34425
|
|
|
35225
34426
|
// src/agent-catalog/agents/deepseek-harness-agent.ts
|
|
35226
34427
|
import { realpath as realpath4, stat as stat4 } from "node:fs/promises";
|
|
35227
|
-
import { isAbsolute as
|
|
34428
|
+
import { isAbsolute as isAbsolute4, join as join7, normalize as normalize2 } from "node:path";
|
|
35228
34429
|
|
|
35229
34430
|
// src/agent-installation/deepseek-managed-package.ts
|
|
35230
34431
|
var DeepSeekHarnessManagedPackage = class extends SriManagedNpmPackageDefinition {
|
|
@@ -35242,7 +34443,7 @@ var DEEPSEEK_HARNESS_PACKAGE = new DeepSeekHarnessManagedPackage(
|
|
|
35242
34443
|
|
|
35243
34444
|
// src/agent-catalog/agents/deepseek-harness-agent.ts
|
|
35244
34445
|
async function validateAgentHome(path2) {
|
|
35245
|
-
if (!
|
|
34446
|
+
if (!isAbsolute4(path2) || normalize2(path2) !== path2) {
|
|
35246
34447
|
throw new AgentProbeError("agent_environment_invalid", "The configured Agent home is invalid");
|
|
35247
34448
|
}
|
|
35248
34449
|
try {
|
|
@@ -35361,7 +34562,7 @@ var GeminiCliAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
35361
34562
|
|
|
35362
34563
|
// src/agent-catalog/agents/grok-build-agent.ts
|
|
35363
34564
|
import { realpath as realpath5 } from "node:fs/promises";
|
|
35364
|
-
import { isAbsolute as
|
|
34565
|
+
import { isAbsolute as isAbsolute5, join as join8, relative as relative2, sep as sep2 } from "node:path";
|
|
35365
34566
|
import {
|
|
35366
34567
|
RequestError as RequestError2
|
|
35367
34568
|
} from "@agentclientprotocol/sdk";
|
|
@@ -35427,7 +34628,7 @@ function grokBuildManagedPackage(platform, architecture) {
|
|
|
35427
34628
|
// src/agent-catalog/agents/grok-build-agent.ts
|
|
35428
34629
|
function isContainedPath2(root, candidate) {
|
|
35429
34630
|
const difference = relative2(root, candidate);
|
|
35430
|
-
return difference.length > 0 && difference !== ".." && !difference.startsWith(`..${sep2}`) && !
|
|
34631
|
+
return difference.length > 0 && difference !== ".." && !difference.startsWith(`..${sep2}`) && !isAbsolute5(difference);
|
|
35431
34632
|
}
|
|
35432
34633
|
var GrokBuildAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
35433
34634
|
adapterVersion = GROK_BUILD_MANAGED_VERSION;
|
|
@@ -35528,11 +34729,11 @@ import { join as join10 } from "node:path";
|
|
|
35528
34729
|
// src/agent-installation/managed-agent-archive.ts
|
|
35529
34730
|
import { createHash } from "node:crypto";
|
|
35530
34731
|
import { createReadStream } from "node:fs";
|
|
35531
|
-
import { chmod
|
|
35532
|
-
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";
|
|
35533
34734
|
|
|
35534
34735
|
// src/agent-installation/verified-download.ts
|
|
35535
|
-
import { fetch
|
|
34736
|
+
import { fetch } from "undici";
|
|
35536
34737
|
|
|
35537
34738
|
// src/network/environment-proxy.ts
|
|
35538
34739
|
import { EnvHttpProxyAgent } from "undici";
|
|
@@ -35630,12 +34831,12 @@ var ManagedAgentArchiveError = class extends Error {
|
|
|
35630
34831
|
this.name = "ManagedAgentArchiveError";
|
|
35631
34832
|
}
|
|
35632
34833
|
};
|
|
35633
|
-
function
|
|
34834
|
+
function isRecord7(value) {
|
|
35634
34835
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
35635
34836
|
}
|
|
35636
34837
|
function isContainedPath3(root, candidate) {
|
|
35637
34838
|
const difference = relative3(root, candidate);
|
|
35638
|
-
return difference.length > 0 && difference !== ".." && !difference.startsWith(`..${sep3}`) && !
|
|
34839
|
+
return difference.length > 0 && difference !== ".." && !difference.startsWith(`..${sep3}`) && !isAbsolute6(difference);
|
|
35639
34840
|
}
|
|
35640
34841
|
async function hashFile(path2, signal) {
|
|
35641
34842
|
signal.throwIfAborted();
|
|
@@ -35670,7 +34871,7 @@ async function hashFile(path2, signal) {
|
|
|
35670
34871
|
async function readManifest(path2) {
|
|
35671
34872
|
let handle;
|
|
35672
34873
|
try {
|
|
35673
|
-
handle = await
|
|
34874
|
+
handle = await open4(path2, "r");
|
|
35674
34875
|
} catch (error62) {
|
|
35675
34876
|
throw new ManagedAgentArchiveError(
|
|
35676
34877
|
"managed_archive_verification_failed",
|
|
@@ -35687,7 +34888,7 @@ async function readManifest(path2) {
|
|
|
35687
34888
|
);
|
|
35688
34889
|
}
|
|
35689
34890
|
const parsed = JSON.parse(await handle.readFile({ encoding: "utf8" }));
|
|
35690
|
-
if (!
|
|
34891
|
+
if (!isRecord7(parsed)) {
|
|
35691
34892
|
throw new ManagedAgentArchiveError(
|
|
35692
34893
|
"managed_archive_verification_failed",
|
|
35693
34894
|
"The managed Agent archive manifest is invalid"
|
|
@@ -35930,7 +35131,7 @@ var PiAgentSpecification = class extends BridgedAcpAgentDefinition {
|
|
|
35930
35131
|
};
|
|
35931
35132
|
|
|
35932
35133
|
// src/agent-catalog/agents/workbuddy-agent.ts
|
|
35933
|
-
import { isAbsolute as
|
|
35134
|
+
import { isAbsolute as isAbsolute7, join as join12 } from "node:path";
|
|
35934
35135
|
|
|
35935
35136
|
// src/agent-installation/workbuddy-managed-package.ts
|
|
35936
35137
|
var WORKBUDDY_MANAGED_VERSION = "2.146.0";
|
|
@@ -35996,12 +35197,12 @@ var WorkBuddyAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
35996
35197
|
}
|
|
35997
35198
|
const requestedPaths = [join12("/Applications", ...WORKBUDDY_MACOS_EXECUTABLE_PATH)];
|
|
35998
35199
|
const homeDirectory = context.environment["HOME"];
|
|
35999
|
-
if (homeDirectory !== void 0 &&
|
|
35200
|
+
if (homeDirectory !== void 0 && isAbsolute7(homeDirectory)) {
|
|
36000
35201
|
requestedPaths.unshift(join12(homeDirectory, "Applications", ...WORKBUDDY_MACOS_EXECUTABLE_PATH));
|
|
36001
35202
|
}
|
|
36002
35203
|
const executables = [];
|
|
36003
|
-
for (const
|
|
36004
|
-
const executable = await resolveExecutablePath(
|
|
35204
|
+
for (const requestedPath2 of requestedPaths) {
|
|
35205
|
+
const executable = await resolveExecutablePath(requestedPath2, "darwin");
|
|
36005
35206
|
context.signal.throwIfAborted();
|
|
36006
35207
|
if (executable !== null) {
|
|
36007
35208
|
executables.push(executable);
|
|
@@ -36060,41 +35261,41 @@ var DiscoveryAcpHandler = class {
|
|
|
36060
35261
|
};
|
|
36061
35262
|
function readableAcpStream(input2) {
|
|
36062
35263
|
let byteLength = 0;
|
|
36063
|
-
let
|
|
35264
|
+
let open6 = true;
|
|
36064
35265
|
return new ReadableStream({
|
|
36065
35266
|
start(controller) {
|
|
36066
35267
|
input2.on("data", (chunk) => {
|
|
36067
|
-
if (!
|
|
35268
|
+
if (!open6) {
|
|
36068
35269
|
return;
|
|
36069
35270
|
}
|
|
36070
35271
|
if (!(chunk instanceof Uint8Array)) {
|
|
36071
|
-
|
|
35272
|
+
open6 = false;
|
|
36072
35273
|
controller.error(new Error("ACP adapter produced invalid output"));
|
|
36073
35274
|
return;
|
|
36074
35275
|
}
|
|
36075
35276
|
byteLength += chunk.byteLength;
|
|
36076
35277
|
if (byteLength > ACP_OUTPUT_LIMIT_BYTES) {
|
|
36077
|
-
|
|
35278
|
+
open6 = false;
|
|
36078
35279
|
controller.error(new Error("ACP adapter output limit exceeded"));
|
|
36079
35280
|
return;
|
|
36080
35281
|
}
|
|
36081
35282
|
controller.enqueue(new Uint8Array(chunk));
|
|
36082
35283
|
});
|
|
36083
35284
|
input2.once("end", () => {
|
|
36084
|
-
if (
|
|
36085
|
-
|
|
35285
|
+
if (open6) {
|
|
35286
|
+
open6 = false;
|
|
36086
35287
|
controller.close();
|
|
36087
35288
|
}
|
|
36088
35289
|
});
|
|
36089
35290
|
input2.once("error", (error62) => {
|
|
36090
|
-
if (
|
|
36091
|
-
|
|
35291
|
+
if (open6) {
|
|
35292
|
+
open6 = false;
|
|
36092
35293
|
controller.error(error62);
|
|
36093
35294
|
}
|
|
36094
35295
|
});
|
|
36095
35296
|
},
|
|
36096
35297
|
cancel() {
|
|
36097
|
-
|
|
35298
|
+
open6 = false;
|
|
36098
35299
|
}
|
|
36099
35300
|
});
|
|
36100
35301
|
}
|
|
@@ -36206,7 +35407,7 @@ async function probeAcpReadiness(specification, agent, environment, defaultWorks
|
|
|
36206
35407
|
}
|
|
36207
35408
|
|
|
36208
35409
|
// src/agent-catalog/executable-discovery.ts
|
|
36209
|
-
import { isAbsolute as
|
|
35410
|
+
import { isAbsolute as isAbsolute8, join as join14 } from "node:path";
|
|
36210
35411
|
|
|
36211
35412
|
// src/agent-installation/managed-adapter-installer.ts
|
|
36212
35413
|
import { join as join13 } from "node:path";
|
|
@@ -36311,7 +35512,7 @@ async function resolveManagedAdapterExecutable(specification, context) {
|
|
|
36311
35512
|
async function resolveSpecificationExecutables(executableName, overrideVariable, resolveInstalled, resolveManaged, context) {
|
|
36312
35513
|
const override = context.environment[overrideVariable];
|
|
36313
35514
|
if (override !== void 0) {
|
|
36314
|
-
if (override.length === 0 || !
|
|
35515
|
+
if (override.length === 0 || !isAbsolute8(override)) {
|
|
36315
35516
|
return [];
|
|
36316
35517
|
}
|
|
36317
35518
|
const executable = await resolveExecutablePath(override, context.platform);
|
|
@@ -36365,7 +35566,7 @@ async function resolveAdapterExecutable(specification, context) {
|
|
|
36365
35566
|
const executables = await resolveAdapterExecutables(specification, context);
|
|
36366
35567
|
return executables[0] ?? null;
|
|
36367
35568
|
}
|
|
36368
|
-
async function probeVersion(executable, arguments_, environment, defaultWorkspace, signal, timeoutMilliseconds,
|
|
35569
|
+
async function probeVersion(executable, arguments_, environment, defaultWorkspace, signal, timeoutMilliseconds, normalize5 = normalizeVersionOutput) {
|
|
36369
35570
|
const result = await runBoundedProcess({
|
|
36370
35571
|
arguments: arguments_,
|
|
36371
35572
|
command: executable.path,
|
|
@@ -36374,7 +35575,7 @@ async function probeVersion(executable, arguments_, environment, defaultWorkspac
|
|
|
36374
35575
|
signal,
|
|
36375
35576
|
timeoutMilliseconds
|
|
36376
35577
|
});
|
|
36377
|
-
const version2 =
|
|
35578
|
+
const version2 = normalize5(result.stdout || result.stderr);
|
|
36378
35579
|
if (version2.length === 0) {
|
|
36379
35580
|
throw new ProcessExecutionError("process_exit_failed", "The executable did not report a version");
|
|
36380
35581
|
}
|
|
@@ -36567,8 +35768,8 @@ async function discoverLocalAgentInventory(options) {
|
|
|
36567
35768
|
// src/pairing/pair-local-machine.ts
|
|
36568
35769
|
var PAIRING_TIMEOUT_MILLISECONDS = 2e4;
|
|
36569
35770
|
var PAIRING_CODE_PATTERN = /^[A-HJ-NP-Z2-9]{4}(?:-[A-HJ-NP-Z2-9]{4}){4}$/;
|
|
36570
|
-
var
|
|
36571
|
-
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}$/;
|
|
36572
35773
|
var MAX_CONNECTION_FILE_LENGTH = 16 * 1024;
|
|
36573
35774
|
var CLAIM_RESPONSE_KEYS = ["channelId", "daemonToken", "runtimeId"];
|
|
36574
35775
|
var REDEEM_RESPONSE_KEYS = ["channelId", "runtimeCredential", "runtimeId"];
|
|
@@ -36582,36 +35783,36 @@ var PairingClientError = class extends Error {
|
|
|
36582
35783
|
this.name = "PairingClientError";
|
|
36583
35784
|
}
|
|
36584
35785
|
};
|
|
36585
|
-
function
|
|
35786
|
+
function isRecord8(value) {
|
|
36586
35787
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
36587
35788
|
}
|
|
36588
35789
|
function hasExactKeys(value, expectedKeys) {
|
|
36589
35790
|
const keys = Object.keys(value);
|
|
36590
35791
|
return keys.length === expectedKeys.length && expectedKeys.every((key) => Object.hasOwn(value, key));
|
|
36591
35792
|
}
|
|
36592
|
-
function readSingleOption(arguments_,
|
|
35793
|
+
function readSingleOption(arguments_, option) {
|
|
36593
35794
|
const values = [];
|
|
36594
35795
|
for (let index2 = 0; index2 < arguments_.length; index2 += 1) {
|
|
36595
|
-
if (arguments_[index2] !==
|
|
35796
|
+
if (arguments_[index2] !== option) {
|
|
36596
35797
|
continue;
|
|
36597
35798
|
}
|
|
36598
35799
|
const value = arguments_[index2 + 1];
|
|
36599
35800
|
if (value === void 0 || value.startsWith("--")) {
|
|
36600
|
-
throw new PairingClientError("invalid_arguments", `${
|
|
35801
|
+
throw new PairingClientError("invalid_arguments", `${option} requires a value`);
|
|
36601
35802
|
}
|
|
36602
35803
|
values.push(value);
|
|
36603
35804
|
index2 += 1;
|
|
36604
35805
|
}
|
|
36605
35806
|
if (values.length !== 1) {
|
|
36606
|
-
throw new PairingClientError("invalid_arguments", `${
|
|
35807
|
+
throw new PairingClientError("invalid_arguments", `${option} must be provided exactly once`);
|
|
36607
35808
|
}
|
|
36608
35809
|
return values[0] ?? "";
|
|
36609
35810
|
}
|
|
36610
35811
|
function assertKnownArguments(arguments_) {
|
|
36611
35812
|
for (let index2 = 0; index2 < arguments_.length; index2 += 2) {
|
|
36612
|
-
const
|
|
36613
|
-
if (
|
|
36614
|
-
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"}`);
|
|
36615
35816
|
}
|
|
36616
35817
|
}
|
|
36617
35818
|
}
|
|
@@ -36656,7 +35857,7 @@ function parsePairCommand(arguments_) {
|
|
|
36656
35857
|
};
|
|
36657
35858
|
}
|
|
36658
35859
|
function validatePairingId(value) {
|
|
36659
|
-
if (!
|
|
35860
|
+
if (!IDENTIFIER_PATTERN4.test(value)) {
|
|
36660
35861
|
throw new PairingClientError("invalid_pairing_id", "The Runtime pairing ID is invalid");
|
|
36661
35862
|
}
|
|
36662
35863
|
return value;
|
|
@@ -36666,7 +35867,7 @@ function parseChannelArgument(arguments_) {
|
|
|
36666
35867
|
throw new PairingClientError("invalid_arguments", "Usage: mobius start --channel <channel-id>");
|
|
36667
35868
|
}
|
|
36668
35869
|
const channelId = arguments_[1] ?? "";
|
|
36669
|
-
if (!
|
|
35870
|
+
if (!IDENTIFIER_PATTERN4.test(channelId)) {
|
|
36670
35871
|
throw new PairingClientError("invalid_channel_id", "The saved channel ID is invalid");
|
|
36671
35872
|
}
|
|
36672
35873
|
return channelId;
|
|
@@ -36674,7 +35875,7 @@ function parseChannelArgument(arguments_) {
|
|
|
36674
35875
|
async function resolveDefaultWorkspace(path2) {
|
|
36675
35876
|
const requestedWorkspace = resolve3(path2);
|
|
36676
35877
|
try {
|
|
36677
|
-
await
|
|
35878
|
+
await mkdir3(requestedWorkspace, { recursive: true, mode: 448 });
|
|
36678
35879
|
const defaultWorkspace = await realpath7(requestedWorkspace);
|
|
36679
35880
|
const metadata = await stat6(defaultWorkspace);
|
|
36680
35881
|
if (!metadata.isDirectory()) {
|
|
@@ -36705,9 +35906,9 @@ async function readJsonResponse(response) {
|
|
|
36705
35906
|
}
|
|
36706
35907
|
}
|
|
36707
35908
|
function readRelayError(value) {
|
|
36708
|
-
if (
|
|
35909
|
+
if (isRecord8(value)) {
|
|
36709
35910
|
const error62 = value["error"];
|
|
36710
|
-
if (
|
|
35911
|
+
if (isRecord8(error62)) {
|
|
36711
35912
|
const code = error62["code"];
|
|
36712
35913
|
const message = error62["message"];
|
|
36713
35914
|
if (typeof code === "string" && typeof message === "string") {
|
|
@@ -36718,13 +35919,13 @@ function readRelayError(value) {
|
|
|
36718
35919
|
return new PairingClientError("pairing_failed", "The relay could not pair this machine");
|
|
36719
35920
|
}
|
|
36720
35921
|
function decodePairingResponse(value, credentialField, expectedKeys) {
|
|
36721
|
-
if (!
|
|
35922
|
+
if (!isRecord8(value) || !hasExactKeys(value, expectedKeys)) {
|
|
36722
35923
|
throw new PairingClientError("invalid_relay_response", "The relay returned an invalid pairing response");
|
|
36723
35924
|
}
|
|
36724
35925
|
const channelId = value["channelId"];
|
|
36725
35926
|
const runtimeCredential2 = value[credentialField];
|
|
36726
35927
|
const runtimeId = value["runtimeId"];
|
|
36727
|
-
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)) {
|
|
36728
35929
|
throw new PairingClientError("invalid_relay_response", "The relay returned an invalid pairing response");
|
|
36729
35930
|
}
|
|
36730
35931
|
return { channelId, runtimeCredential: runtimeCredential2, runtimeId };
|
|
@@ -36734,7 +35935,6 @@ async function claimPairing(options, defaultWorkspace, localAgents, installableA
|
|
|
36734
35935
|
agentPath: agent.agentIdentity.requestedPath,
|
|
36735
35936
|
agentVersion: agent.agentVersion,
|
|
36736
35937
|
agentSettingsDiscovery: true,
|
|
36737
|
-
botSessionConfiguration: true,
|
|
36738
35938
|
capabilities: agent.capabilities,
|
|
36739
35939
|
id: agent.id,
|
|
36740
35940
|
label: agent.label,
|
|
@@ -36743,7 +35943,7 @@ async function claimPairing(options, defaultWorkspace, localAgents, installableA
|
|
|
36743
35943
|
const endpoint = options.pairingId.length > 0 ? mobiusApiUrl(options.relayOrigin, `/v1/runtime-pairings/${encodeURIComponent(options.pairingId)}/redeem`) : mobiusApiUrl(options.relayOrigin, "/pairings/claim");
|
|
36744
35944
|
let response;
|
|
36745
35945
|
try {
|
|
36746
|
-
response = await
|
|
35946
|
+
response = await fetch2(endpoint, {
|
|
36747
35947
|
body: JSON.stringify({
|
|
36748
35948
|
agents,
|
|
36749
35949
|
installableAgents,
|
|
@@ -36767,9 +35967,9 @@ async function claimPairing(options, defaultWorkspace, localAgents, installableA
|
|
|
36767
35967
|
}
|
|
36768
35968
|
async function persistConnection(channelId, relayOrigin, runtimeCredential2, defaultWorkspace, environment) {
|
|
36769
35969
|
const connectionsDirectory = join15(readStateDirectory(environment), "connections");
|
|
36770
|
-
await
|
|
35970
|
+
await mkdir3(connectionsDirectory, { mode: 448, recursive: true });
|
|
36771
35971
|
const connectionPath = join15(connectionsDirectory, `${channelId}.json`);
|
|
36772
|
-
const temporaryPath = join15(connectionsDirectory, `.${channelId}.${
|
|
35972
|
+
const temporaryPath = join15(connectionsDirectory, `.${channelId}.${randomUUID()}.tmp`);
|
|
36773
35973
|
await writeFile2(
|
|
36774
35974
|
temporaryPath,
|
|
36775
35975
|
`${JSON.stringify(
|
|
@@ -36789,14 +35989,14 @@ async function persistConnection(channelId, relayOrigin, runtimeCredential2, def
|
|
|
36789
35989
|
return connectionPath;
|
|
36790
35990
|
}
|
|
36791
35991
|
function decodeSavedConnection(value, expectedChannelId) {
|
|
36792
|
-
if (!
|
|
35992
|
+
if (!isRecord8(value) || !hasExactKeys(value, SAVED_CONNECTION_KEYS) && !hasExactKeys(value, LEGACY_SAVED_CONNECTION_KEYS)) {
|
|
36793
35993
|
throw new PairingClientError("invalid_connection", "The saved connection is invalid");
|
|
36794
35994
|
}
|
|
36795
35995
|
const defaultWorkspace = value["defaultWorkspace"];
|
|
36796
35996
|
const channelId = value["channelId"];
|
|
36797
35997
|
const runtimeCredential2 = value["runtimeCredential"] ?? value["daemonToken"];
|
|
36798
35998
|
const relayOrigin = value["relayOrigin"];
|
|
36799
|
-
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") {
|
|
36800
36000
|
throw new PairingClientError("invalid_connection", "The saved connection is invalid");
|
|
36801
36001
|
}
|
|
36802
36002
|
return {
|
|
@@ -36809,7 +36009,7 @@ function decodeSavedConnection(value, expectedChannelId) {
|
|
|
36809
36009
|
async function readSavedConnection(channelId, environment) {
|
|
36810
36010
|
const connectionPath = join15(readStateDirectory(environment), "connections", `${channelId}.json`);
|
|
36811
36011
|
let encoded = "";
|
|
36812
|
-
const handle = await
|
|
36012
|
+
const handle = await open5(connectionPath, "r");
|
|
36813
36013
|
try {
|
|
36814
36014
|
const metadata = await handle.stat();
|
|
36815
36015
|
if (!metadata.isFile() || metadata.size > MAX_CONNECTION_FILE_LENGTH) {
|
|
@@ -36919,13 +36119,13 @@ async function resumeLocalMachine(arguments_, signal = new AbortController().sig
|
|
|
36919
36119
|
}
|
|
36920
36120
|
|
|
36921
36121
|
// src/run-daemon.ts
|
|
36922
|
-
import { randomUUID as
|
|
36923
|
-
import { basename as
|
|
36122
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
36123
|
+
import { basename as basename7 } from "node:path";
|
|
36924
36124
|
import { styleText } from "node:util";
|
|
36925
|
-
import { fetch as
|
|
36125
|
+
import { fetch as fetch6, WebSocket as WebSocket2 } from "undici";
|
|
36926
36126
|
|
|
36927
36127
|
// src/agent-catalog/publish-agent-catalog.ts
|
|
36928
|
-
import { fetch as
|
|
36128
|
+
import { fetch as fetch3 } from "undici";
|
|
36929
36129
|
|
|
36930
36130
|
// src/relay-connection/runtime-authentication.ts
|
|
36931
36131
|
function runtimeCredential(relayUrl) {
|
|
@@ -36971,13 +36171,12 @@ async function publishAgentCatalog(config2, signal) {
|
|
|
36971
36171
|
let response;
|
|
36972
36172
|
const catalog = config2.catalog.read();
|
|
36973
36173
|
try {
|
|
36974
|
-
response = await
|
|
36174
|
+
response = await fetch3(catalogEndpoint(config2), {
|
|
36975
36175
|
body: JSON.stringify({
|
|
36976
36176
|
agents: catalog.agents.map((agent) => ({
|
|
36977
36177
|
agentPath: agent.agentIdentity.requestedPath,
|
|
36978
36178
|
agentVersion: agent.agentVersion,
|
|
36979
36179
|
agentSettingsDiscovery: true,
|
|
36980
|
-
botSessionConfiguration: true,
|
|
36981
36180
|
capabilities: agent.capabilities,
|
|
36982
36181
|
id: agent.id,
|
|
36983
36182
|
label: agent.label,
|
|
@@ -37464,6 +36663,91 @@ var FixedInstallationExecutor = class {
|
|
|
37464
36663
|
};
|
|
37465
36664
|
};
|
|
37466
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
|
+
|
|
37467
36751
|
// src/artifacts/runtime-artifact-uploader.ts
|
|
37468
36752
|
import { createHash as createHash2 } from "node:crypto";
|
|
37469
36753
|
|
|
@@ -37490,15 +36774,15 @@ var MobiusValidationError = class extends MobiusError {
|
|
|
37490
36774
|
};
|
|
37491
36775
|
|
|
37492
36776
|
// ../mobius-sdk/src/resources.ts
|
|
37493
|
-
var
|
|
36777
|
+
var IDENTIFIER_PATTERN5 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
37494
36778
|
function invalidResponse(message) {
|
|
37495
36779
|
return new MobiusProtocolError(message);
|
|
37496
36780
|
}
|
|
37497
|
-
function
|
|
36781
|
+
function isRecord9(value) {
|
|
37498
36782
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
37499
36783
|
}
|
|
37500
36784
|
function record3(value, name) {
|
|
37501
|
-
if (!
|
|
36785
|
+
if (!isRecord9(value)) {
|
|
37502
36786
|
throw invalidResponse(`The service returned an invalid ${name}`);
|
|
37503
36787
|
}
|
|
37504
36788
|
return value;
|
|
@@ -37512,7 +36796,7 @@ function stringField(value, field, maximumLength = 85e5) {
|
|
|
37512
36796
|
}
|
|
37513
36797
|
function identifierField(value, field) {
|
|
37514
36798
|
const candidate = stringField(value, field, 128);
|
|
37515
|
-
if (!
|
|
36799
|
+
if (!IDENTIFIER_PATTERN5.test(candidate)) {
|
|
37516
36800
|
throw invalidResponse(`The service returned an invalid ${field}`);
|
|
37517
36801
|
}
|
|
37518
36802
|
return candidate;
|
|
@@ -37683,7 +36967,7 @@ var MobiusRuntimePairingLifecycle = Object.freeze({
|
|
|
37683
36967
|
});
|
|
37684
36968
|
|
|
37685
36969
|
// src/artifacts/runtime-artifact-uploader.ts
|
|
37686
|
-
import { fetch as
|
|
36970
|
+
import { fetch as fetch4 } from "undici";
|
|
37687
36971
|
var UPLOAD_TIMEOUT_MILLISECONDS = 2e4;
|
|
37688
36972
|
var RuntimeArtifactUploadError = class extends Error {
|
|
37689
36973
|
code;
|
|
@@ -37755,7 +37039,7 @@ function sessionArtifactUrl(origin, sessionId, resourcePath) {
|
|
|
37755
37039
|
return new URL(`${origin.pathname}/sessions/${encodeURIComponent(sessionId)}/${resourcePath}`, origin);
|
|
37756
37040
|
}
|
|
37757
37041
|
async function postLease(url2, headers, request, signal) {
|
|
37758
|
-
return await
|
|
37042
|
+
return await fetch4(url2, {
|
|
37759
37043
|
dispatcher: environmentProxyDispatcher,
|
|
37760
37044
|
headers: { ...headers, "content-type": "application/json" },
|
|
37761
37045
|
method: "POST",
|
|
@@ -37764,7 +37048,7 @@ async function postLease(url2, headers, request, signal) {
|
|
|
37764
37048
|
});
|
|
37765
37049
|
}
|
|
37766
37050
|
async function putContent(url2, headers, authorization, bytes, signal) {
|
|
37767
|
-
return await
|
|
37051
|
+
return await fetch4(url2, {
|
|
37768
37052
|
dispatcher: environmentProxyDispatcher,
|
|
37769
37053
|
headers: {
|
|
37770
37054
|
...headers,
|
|
@@ -37850,9 +37134,9 @@ async function uploadRuntimeArtifact(config2, sessionId, artifact, signal) {
|
|
|
37850
37134
|
}
|
|
37851
37135
|
|
|
37852
37136
|
// src/authorization/workspace-directory.ts
|
|
37853
|
-
import { readdir as readdir2, realpath as
|
|
37137
|
+
import { readdir as readdir2, realpath as realpath9, stat as stat8 } from "node:fs/promises";
|
|
37854
37138
|
import { homedir as homedir2 } from "node:os";
|
|
37855
|
-
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";
|
|
37856
37140
|
var WorkspaceDirectoryListing = class {
|
|
37857
37141
|
directoryId;
|
|
37858
37142
|
directoryLabel;
|
|
@@ -37878,7 +37162,7 @@ function decodePath(value, prefix) {
|
|
|
37878
37162
|
throw new LocalAuthorizationError("The directory identifier is invalid");
|
|
37879
37163
|
}
|
|
37880
37164
|
const decoded = Buffer.from(encoded, "base64url").toString("utf8");
|
|
37881
|
-
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) {
|
|
37882
37166
|
throw new LocalAuthorizationError("The directory identifier is invalid");
|
|
37883
37167
|
}
|
|
37884
37168
|
return decoded;
|
|
@@ -37912,15 +37196,15 @@ var WorkspaceDirectoryService = class {
|
|
|
37912
37196
|
};
|
|
37913
37197
|
resolvePath = async (requested, signal) => {
|
|
37914
37198
|
signal.throwIfAborted();
|
|
37915
|
-
if (!isAbsolute10(requested) || requested.includes("\0") ||
|
|
37199
|
+
if (!isAbsolute10(requested) || requested.includes("\0") || normalize4(requested) !== requested) {
|
|
37916
37200
|
throw new LocalAuthorizationError("The local directory path is invalid");
|
|
37917
37201
|
}
|
|
37918
37202
|
try {
|
|
37919
|
-
const target = await
|
|
37203
|
+
const target = await realpath9(requested);
|
|
37920
37204
|
signal.throwIfAborted();
|
|
37921
|
-
const metadata = await
|
|
37205
|
+
const metadata = await stat8(target);
|
|
37922
37206
|
signal.throwIfAborted();
|
|
37923
|
-
if (!isAbsolute10(target) ||
|
|
37207
|
+
if (!isAbsolute10(target) || normalize4(target) !== target || !metadata.isDirectory()) {
|
|
37924
37208
|
throw new LocalAuthorizationError("The selected location is not a directory");
|
|
37925
37209
|
}
|
|
37926
37210
|
return target;
|
|
@@ -37938,13 +37222,13 @@ var WorkspaceDirectoryService = class {
|
|
|
37938
37222
|
const suffix = relative4(homedir2(), path2);
|
|
37939
37223
|
return suffix === "" ? "~" : !isAbsolute10(suffix) && suffix !== ".." && !suffix.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) ? `~/${suffix.replaceAll("\\", "/")}` : path2;
|
|
37940
37224
|
};
|
|
37941
|
-
identify = async (bindingId,
|
|
37225
|
+
identify = async (bindingId, requestedPath2, signal) => {
|
|
37942
37226
|
this.authorizeMachine(bindingId);
|
|
37943
|
-
const path2 = await this.resolvePath(
|
|
37227
|
+
const path2 = await this.resolvePath(requestedPath2, signal);
|
|
37944
37228
|
return {
|
|
37945
37229
|
path: path2,
|
|
37946
37230
|
directoryId: encodePath(path2),
|
|
37947
|
-
name:
|
|
37231
|
+
name: basename5(path2) || path2,
|
|
37948
37232
|
label: this.label(path2)
|
|
37949
37233
|
};
|
|
37950
37234
|
};
|
|
@@ -37976,7 +37260,7 @@ var WorkspaceDirectoryService = class {
|
|
|
37976
37260
|
}
|
|
37977
37261
|
}
|
|
37978
37262
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
37979
|
-
const parent =
|
|
37263
|
+
const parent = dirname5(target);
|
|
37980
37264
|
return new WorkspaceDirectoryListing(
|
|
37981
37265
|
id,
|
|
37982
37266
|
this.label(target),
|
|
@@ -38000,45 +37284,9 @@ var WorkspaceDirectoryService = class {
|
|
|
38000
37284
|
};
|
|
38001
37285
|
};
|
|
38002
37286
|
|
|
38003
|
-
// src/bots/bot-context-applicator.ts
|
|
38004
|
-
var AppliedBotContext = class {
|
|
38005
|
-
resources;
|
|
38006
|
-
constructor(resources) {
|
|
38007
|
-
this.resources = Object.freeze([...resources]);
|
|
38008
|
-
}
|
|
38009
|
-
};
|
|
38010
|
-
var EmbeddedBotContextApplicator = class {
|
|
38011
|
-
apply = async (command, execution, resources, signal) => {
|
|
38012
|
-
signal.throwIfAborted();
|
|
38013
|
-
if (execution.botId !== command.botId || execution.behaviorRevisionId !== command.behaviorRevisionId || execution.behaviorDigest !== command.behaviorDigest) {
|
|
38014
|
-
throw new LocalBotAuthorizationError(
|
|
38015
|
-
"binding_incompatible",
|
|
38016
|
-
"The Bot behavior does not match the execution target"
|
|
38017
|
-
);
|
|
38018
|
-
}
|
|
38019
|
-
if (command.behaviorInstructions.length === 0) {
|
|
38020
|
-
return new AppliedBotContext(resources);
|
|
38021
|
-
}
|
|
38022
|
-
if (!execution.agent.capabilities.embeddedContextPrompt) {
|
|
38023
|
-
throw new LocalBotAuthorizationError(
|
|
38024
|
-
"binding_incompatible",
|
|
38025
|
-
"The local Agent cannot enforce the Bot behavior context"
|
|
38026
|
-
);
|
|
38027
|
-
}
|
|
38028
|
-
const trustedContext = {
|
|
38029
|
-
mimeType: "text/markdown",
|
|
38030
|
-
name: "Mobius Bot behavior",
|
|
38031
|
-
text: command.behaviorInstructions,
|
|
38032
|
-
type: "embedded",
|
|
38033
|
-
uri: `mobius://bots/${encodeURIComponent(command.botId)}/behavior-revisions/${encodeURIComponent(command.behaviorRevisionId)}?sha256=${command.behaviorDigest}`
|
|
38034
|
-
};
|
|
38035
|
-
return new AppliedBotContext([trustedContext, ...resources]);
|
|
38036
|
-
};
|
|
38037
|
-
};
|
|
38038
|
-
|
|
38039
37287
|
// src/native-sessions/service.ts
|
|
38040
|
-
import { randomUUID as
|
|
38041
|
-
import { basename as
|
|
37288
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
37289
|
+
import { basename as basename6 } from "node:path";
|
|
38042
37290
|
|
|
38043
37291
|
// src/native-sessions/codex-history.ts
|
|
38044
37292
|
import { spawn as spawn4 } from "node:child_process";
|
|
@@ -38332,7 +37580,7 @@ var NativeSessionService = class {
|
|
|
38332
37580
|
if (authorized === null) {
|
|
38333
37581
|
return null;
|
|
38334
37582
|
}
|
|
38335
|
-
const entryId =
|
|
37583
|
+
const entryId = randomUUID2();
|
|
38336
37584
|
if (this.#entries.size >= 5e3) {
|
|
38337
37585
|
this.#entries.clear();
|
|
38338
37586
|
}
|
|
@@ -38386,7 +37634,7 @@ var NativeSessionService = class {
|
|
|
38386
37634
|
"invalid_native_session_response"
|
|
38387
37635
|
);
|
|
38388
37636
|
}
|
|
38389
|
-
nextCursor =
|
|
37637
|
+
nextCursor = randomUUID2();
|
|
38390
37638
|
if (this.#cursors.size >= 500) {
|
|
38391
37639
|
this.#cursors.clear();
|
|
38392
37640
|
}
|
|
@@ -38547,7 +37795,7 @@ var NativeSessionService = class {
|
|
|
38547
37795
|
}
|
|
38548
37796
|
resolvedPaths.add(path2);
|
|
38549
37797
|
additionalDirectories.push(path2);
|
|
38550
|
-
additionalEntries.push({ directoryId: directoryId2, name:
|
|
37798
|
+
additionalEntries.push({ directoryId: directoryId2, name: basename6(path2) });
|
|
38551
37799
|
}
|
|
38552
37800
|
const listing = await this.#directories.list(this.#config.bindingId, command.directoryId, signal);
|
|
38553
37801
|
const opened = await this.#sessions.forkSessionAtTurn(
|
|
@@ -38705,12 +37953,12 @@ var NativeSessionService = class {
|
|
|
38705
37953
|
|
|
38706
37954
|
// src/prompt-artifact-resolver.ts
|
|
38707
37955
|
import { createHash as createHash3 } from "node:crypto";
|
|
38708
|
-
import { fetch as
|
|
37956
|
+
import { fetch as fetch5 } from "undici";
|
|
38709
37957
|
var ARTIFACT_SCHEME = "mobius-artifact:";
|
|
38710
37958
|
var ARTIFACT_DOWNLOAD_TIMEOUT_MILLISECONDS = 2e4;
|
|
38711
37959
|
var MAX_AGENT_IMAGE_BASE64_LENGTH = 4e6;
|
|
38712
37960
|
var MAX_AGENT_RESOURCE_BYTE_LENGTH = 1e6;
|
|
38713
|
-
var
|
|
37961
|
+
var IDENTIFIER_PATTERN6 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
38714
37962
|
var PromptArtifactError = class extends Error {
|
|
38715
37963
|
code;
|
|
38716
37964
|
constructor(code, message, options = {}) {
|
|
@@ -38753,7 +38001,7 @@ function parseReference(resource) {
|
|
|
38753
38001
|
const encodedByteLength2 = url2.searchParams.get("byteLength") ?? "";
|
|
38754
38002
|
const sha256 = url2.searchParams.get("sha256") ?? "";
|
|
38755
38003
|
const byteLength = Number(encodedByteLength2);
|
|
38756
|
-
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)) {
|
|
38757
38005
|
throw new PromptArtifactError("artifact_reference_invalid", "The prompt artifact reference is invalid");
|
|
38758
38006
|
}
|
|
38759
38007
|
return new PromptArtifactReference(artifactId, byteLength, sha256, resource);
|
|
@@ -38819,7 +38067,7 @@ async function download(config2, command, reference, signal) {
|
|
|
38819
38067
|
const requestSignal = AbortSignal.any([signal, timeoutSignal]);
|
|
38820
38068
|
let response;
|
|
38821
38069
|
try {
|
|
38822
|
-
response = await
|
|
38070
|
+
response = await fetch5(downloadUrl(config2, command, reference), {
|
|
38823
38071
|
dispatcher: environmentProxyDispatcher,
|
|
38824
38072
|
headers: {
|
|
38825
38073
|
accept: reference.resource.mimeType,
|
|
@@ -39152,7 +38400,7 @@ var RelayConnectionDiagnostics = class {
|
|
|
39152
38400
|
};
|
|
39153
38401
|
|
|
39154
38402
|
// src/relay-connection/liveness.ts
|
|
39155
|
-
import { randomUUID as
|
|
38403
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
39156
38404
|
var HEARTBEAT_ACK_TIMEOUT_MILLISECONDS = 1e4;
|
|
39157
38405
|
var HEARTBEAT_INTERVAL_MILLISECONDS = 2e4;
|
|
39158
38406
|
var RelayLivenessState = class {
|
|
@@ -39241,7 +38489,7 @@ var RelayConnectionLiveness = class {
|
|
|
39241
38489
|
}
|
|
39242
38490
|
throw new Error("Heartbeat was scheduled in an invalid state");
|
|
39243
38491
|
}
|
|
39244
|
-
const heartbeatId =
|
|
38492
|
+
const heartbeatId = randomUUID3();
|
|
39245
38493
|
this.#state = new AwaitingHeartbeatAckState(
|
|
39246
38494
|
heartbeatId,
|
|
39247
38495
|
this.#timer.schedule(this.#handleTimeout, HEARTBEAT_ACK_TIMEOUT_MILLISECONDS)
|
|
@@ -39257,7 +38505,7 @@ var RelayConnectionLiveness = class {
|
|
|
39257
38505
|
|
|
39258
38506
|
// src/relay-connection/session-event-outbox.ts
|
|
39259
38507
|
import { mkdirSync as mkdirSync3 } from "node:fs";
|
|
39260
|
-
import { dirname as
|
|
38508
|
+
import { dirname as dirname6 } from "node:path";
|
|
39261
38509
|
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
39262
38510
|
var DEFAULT_OUTBOX_LIMITS = {
|
|
39263
38511
|
criticalEventBytes: 136 * 1024 * 1024,
|
|
@@ -39323,7 +38571,7 @@ var SessionEventOutbox = class {
|
|
|
39323
38571
|
constructor(path2, limits = DEFAULT_OUTBOX_LIMITS) {
|
|
39324
38572
|
validateLimits(limits);
|
|
39325
38573
|
this.#limits = limits;
|
|
39326
|
-
mkdirSync3(
|
|
38574
|
+
mkdirSync3(dirname6(path2), { recursive: true });
|
|
39327
38575
|
this.#database = new DatabaseSync3(path2);
|
|
39328
38576
|
this.#database.exec(`
|
|
39329
38577
|
CREATE TABLE IF NOT EXISTS relay_session_event_outbox (
|
|
@@ -39856,12 +39104,6 @@ var RELAY_RECONNECT_DELAY_MILLISECONDS = 500;
|
|
|
39856
39104
|
var AGENT_ACTIVITY_COALESCING_MILLISECONDS = 100;
|
|
39857
39105
|
var ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS = 2e4;
|
|
39858
39106
|
var ACTIVE_TURN_RECONCILIATION_CLOSE_CODE = 4009;
|
|
39859
|
-
function botIpcSocketPath() {
|
|
39860
|
-
if (process.platform === "win32") {
|
|
39861
|
-
return `\\\\.\\pipe\\mobius-bot-${randomUUID5()}`;
|
|
39862
|
-
}
|
|
39863
|
-
return join17("/tmp", `mobius-bot-${randomUUID5()}.sock`);
|
|
39864
|
-
}
|
|
39865
39107
|
var DaemonAcpObserver = class {
|
|
39866
39108
|
#config;
|
|
39867
39109
|
#record;
|
|
@@ -40079,7 +39321,7 @@ async function reconcileActiveTurn(config2, turn, signal) {
|
|
|
40079
39321
|
const requestSignal = AbortSignal.any([signal, timeoutSignal]);
|
|
40080
39322
|
let response;
|
|
40081
39323
|
try {
|
|
40082
|
-
response = await
|
|
39324
|
+
response = await fetch6(activeTurnReconciliationEndpoint(config2, turn), {
|
|
40083
39325
|
body: JSON.stringify({ outcome: { kind: "running" } }),
|
|
40084
39326
|
dispatcher: environmentProxyDispatcher,
|
|
40085
39327
|
headers: { ...runtimeAuthorization(config2.relayUrl), "content-type": "application/json" },
|
|
@@ -40391,13 +39633,13 @@ function reportFailure(publisher, command, code, message, attemptId) {
|
|
|
40391
39633
|
);
|
|
40392
39634
|
}
|
|
40393
39635
|
function operationErrorCode(error62) {
|
|
40394
|
-
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) {
|
|
40395
39637
|
return error62.code;
|
|
40396
39638
|
}
|
|
40397
39639
|
return "session_operation_failed";
|
|
40398
39640
|
}
|
|
40399
39641
|
function operationErrorMessage(error62) {
|
|
40400
|
-
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) {
|
|
40401
39643
|
return error62.message;
|
|
40402
39644
|
}
|
|
40403
39645
|
return "The local agent operation could not be completed";
|
|
@@ -40432,7 +39674,7 @@ async function resolveSessionDirectories(directories, bindingId, directoryId2, a
|
|
|
40432
39674
|
additionalDirectories.push(directory);
|
|
40433
39675
|
additionalDirectoryEntries.push({
|
|
40434
39676
|
directoryId: additionalDirectoryId,
|
|
40435
|
-
name:
|
|
39677
|
+
name: basename7(directory)
|
|
40436
39678
|
});
|
|
40437
39679
|
}
|
|
40438
39680
|
return new ResolvedSessionDirectories(cwd, additionalDirectories, additionalDirectoryEntries);
|
|
@@ -40777,11 +40019,11 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
40777
40019
|
function invalidSessionConfiguration(message) {
|
|
40778
40020
|
return new AcpExecutionError(message, {}, "invalid_session_configuration");
|
|
40779
40021
|
}
|
|
40780
|
-
function validateSessionConfigurationSelection(
|
|
40781
|
-
if (
|
|
40022
|
+
function validateSessionConfigurationSelection(option, selection) {
|
|
40023
|
+
if (option.type !== selection.valueType) {
|
|
40782
40024
|
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} changed type`);
|
|
40783
40025
|
}
|
|
40784
|
-
if (
|
|
40026
|
+
if (option.type === "boolean") {
|
|
40785
40027
|
if (selection.value.length > 0) {
|
|
40786
40028
|
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} has an invalid value`);
|
|
40787
40029
|
}
|
|
@@ -40790,7 +40032,7 @@ function validateSessionConfigurationSelection(option2, selection) {
|
|
|
40790
40032
|
if (selection.booleanValue) {
|
|
40791
40033
|
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} has an invalid value`);
|
|
40792
40034
|
}
|
|
40793
|
-
if (!
|
|
40035
|
+
if (!option.values.some((value) => value.value === selection.value)) {
|
|
40794
40036
|
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} has an unavailable value`);
|
|
40795
40037
|
}
|
|
40796
40038
|
}
|
|
@@ -40802,10 +40044,10 @@ function assertSessionConfigurationSchema(options, selections) {
|
|
|
40802
40044
|
if (selectionsById.size !== selections.length) {
|
|
40803
40045
|
throw invalidSessionConfiguration("The Turn configuration contains duplicate Agent settings");
|
|
40804
40046
|
}
|
|
40805
|
-
for (const
|
|
40806
|
-
const selection = selectionsById.get(
|
|
40807
|
-
if (selection === void 0 || selection.valueType !==
|
|
40808
|
-
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}`);
|
|
40809
40051
|
}
|
|
40810
40052
|
}
|
|
40811
40053
|
}
|
|
@@ -40814,37 +40056,37 @@ function assertSessionConfigurationCoverage(options, selections) {
|
|
|
40814
40056
|
if (selectionsById.size !== selections.length) {
|
|
40815
40057
|
throw invalidSessionConfiguration("The Turn configuration contains duplicate Agent settings");
|
|
40816
40058
|
}
|
|
40817
|
-
for (const
|
|
40818
|
-
if (!selectionsById.has(
|
|
40819
|
-
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${
|
|
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}`);
|
|
40820
40062
|
}
|
|
40821
40063
|
}
|
|
40822
40064
|
}
|
|
40823
|
-
function sessionConfigurationSelectionIsAvailable(
|
|
40824
|
-
if (
|
|
40065
|
+
function sessionConfigurationSelectionIsAvailable(option, selection) {
|
|
40066
|
+
if (option.type !== selection.valueType) {
|
|
40825
40067
|
return false;
|
|
40826
40068
|
}
|
|
40827
|
-
if (
|
|
40069
|
+
if (option.type === "boolean") {
|
|
40828
40070
|
return selection.value.length === 0;
|
|
40829
40071
|
}
|
|
40830
|
-
return !selection.booleanValue &&
|
|
40072
|
+
return !selection.booleanValue && option.values.some((value) => value.value === selection.value);
|
|
40831
40073
|
}
|
|
40832
|
-
function sessionConfigurationMatches(
|
|
40833
|
-
validateSessionConfigurationSelection(
|
|
40834
|
-
return
|
|
40074
|
+
function sessionConfigurationMatches(option, selection) {
|
|
40075
|
+
validateSessionConfigurationSelection(option, selection);
|
|
40076
|
+
return option.type === "boolean" ? option.booleanValue === selection.booleanValue : option.currentValue === selection.value;
|
|
40835
40077
|
}
|
|
40836
40078
|
function sessionConfigurationPriority(selection, options) {
|
|
40837
40079
|
if (selection.configId === "permission_mode") {
|
|
40838
40080
|
return 0;
|
|
40839
40081
|
}
|
|
40840
|
-
const
|
|
40841
|
-
if (selection.configId === "model" ||
|
|
40082
|
+
const option = options.find((candidate) => candidate.id === selection.configId);
|
|
40083
|
+
if (selection.configId === "model" || option?.category === "model") {
|
|
40842
40084
|
return 1;
|
|
40843
40085
|
}
|
|
40844
|
-
if (selection.configId === "reasoning_effort" ||
|
|
40086
|
+
if (selection.configId === "reasoning_effort" || option?.category === "thought_level") {
|
|
40845
40087
|
return 2;
|
|
40846
40088
|
}
|
|
40847
|
-
if (
|
|
40089
|
+
if (option?.category === "model_config") {
|
|
40848
40090
|
return 3;
|
|
40849
40091
|
}
|
|
40850
40092
|
return 4;
|
|
@@ -40852,28 +40094,28 @@ function sessionConfigurationPriority(selection, options) {
|
|
|
40852
40094
|
function assertCompleteSessionConfiguration(options, selections) {
|
|
40853
40095
|
assertSessionConfigurationSchema(options, selections);
|
|
40854
40096
|
const selectionsById = new Map(selections.map((selection) => [selection.configId, selection]));
|
|
40855
|
-
for (const
|
|
40856
|
-
const selection = selectionsById.get(
|
|
40857
|
-
if (selection === void 0 || !sessionConfigurationMatches(
|
|
40858
|
-
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}`);
|
|
40859
40101
|
}
|
|
40860
40102
|
}
|
|
40861
40103
|
}
|
|
40862
40104
|
function assertAppliedSessionConfiguration(options, selections) {
|
|
40863
40105
|
const selectionsById = new Map(selections.map((selection) => [selection.configId, selection]));
|
|
40864
|
-
for (const
|
|
40865
|
-
const selection = selectionsById.get(
|
|
40866
|
-
if (
|
|
40867
|
-
if (selection === void 0 || !sessionConfigurationMatches(
|
|
40868
|
-
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${
|
|
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}`);
|
|
40869
40111
|
}
|
|
40870
40112
|
continue;
|
|
40871
40113
|
}
|
|
40872
|
-
if (selection === void 0 || !sessionConfigurationSelectionIsAvailable(
|
|
40114
|
+
if (selection === void 0 || !sessionConfigurationSelectionIsAvailable(option, selection)) {
|
|
40873
40115
|
continue;
|
|
40874
40116
|
}
|
|
40875
|
-
if (!sessionConfigurationMatches(
|
|
40876
|
-
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${
|
|
40117
|
+
if (!sessionConfigurationMatches(option, selection)) {
|
|
40118
|
+
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
|
|
40877
40119
|
}
|
|
40878
40120
|
}
|
|
40879
40121
|
}
|
|
@@ -40887,8 +40129,8 @@ function unavailableSessionConfigurationCategory(selection) {
|
|
|
40887
40129
|
return "unknown";
|
|
40888
40130
|
}
|
|
40889
40131
|
async function applySessionConfigurationSelection(sessions, audit, options, selection, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
|
|
40890
|
-
const
|
|
40891
|
-
if (
|
|
40132
|
+
const option = options.find((candidate) => candidate.id === selection.configId);
|
|
40133
|
+
if (option === void 0) {
|
|
40892
40134
|
if (selection.configId !== AGENT_PERMISSION_MODE_CONFIG_ID) {
|
|
40893
40135
|
warnIgnoredSetting(
|
|
40894
40136
|
audit,
|
|
@@ -40905,7 +40147,7 @@ async function applySessionConfigurationSelection(sessions, audit, options, sele
|
|
|
40905
40147
|
throw invalidSessionConfiguration(`The Agent setting ${selection.configId} is unavailable`);
|
|
40906
40148
|
}
|
|
40907
40149
|
if (selection.configId !== AGENT_PERMISSION_MODE_CONFIG_ID) {
|
|
40908
|
-
if (
|
|
40150
|
+
if (option.type !== selection.valueType) {
|
|
40909
40151
|
warnIgnoredSetting(
|
|
40910
40152
|
audit,
|
|
40911
40153
|
"session_configuration_setting_ignored",
|
|
@@ -40913,12 +40155,12 @@ async function applySessionConfigurationSelection(sessions, audit, options, sele
|
|
|
40913
40155
|
sessionId,
|
|
40914
40156
|
agent.id,
|
|
40915
40157
|
selection,
|
|
40916
|
-
|
|
40158
|
+
option.category,
|
|
40917
40159
|
"setting_schema_mismatch"
|
|
40918
40160
|
);
|
|
40919
40161
|
return options;
|
|
40920
40162
|
}
|
|
40921
|
-
if (
|
|
40163
|
+
if (option.type === "boolean" && selection.value.length > 0 || option.type === "select" && selection.booleanValue) {
|
|
40922
40164
|
warnIgnoredSetting(
|
|
40923
40165
|
audit,
|
|
40924
40166
|
"session_configuration_setting_ignored",
|
|
@@ -40926,12 +40168,12 @@ async function applySessionConfigurationSelection(sessions, audit, options, sele
|
|
|
40926
40168
|
sessionId,
|
|
40927
40169
|
agent.id,
|
|
40928
40170
|
selection,
|
|
40929
|
-
|
|
40171
|
+
option.category,
|
|
40930
40172
|
"selection_schema_mismatch"
|
|
40931
40173
|
);
|
|
40932
40174
|
return options;
|
|
40933
40175
|
}
|
|
40934
|
-
if (
|
|
40176
|
+
if (option.type === "select" && !option.values.some((value) => value.value === selection.value)) {
|
|
40935
40177
|
warnIgnoredSetting(
|
|
40936
40178
|
audit,
|
|
40937
40179
|
"session_configuration_setting_ignored",
|
|
@@ -40939,13 +40181,13 @@ async function applySessionConfigurationSelection(sessions, audit, options, sele
|
|
|
40939
40181
|
sessionId,
|
|
40940
40182
|
agent.id,
|
|
40941
40183
|
selection,
|
|
40942
|
-
|
|
40184
|
+
option.category,
|
|
40943
40185
|
"value_unavailable"
|
|
40944
40186
|
);
|
|
40945
40187
|
return options;
|
|
40946
40188
|
}
|
|
40947
40189
|
}
|
|
40948
|
-
if (sessionConfigurationMatches(
|
|
40190
|
+
if (sessionConfigurationMatches(option, selection)) {
|
|
40949
40191
|
return options;
|
|
40950
40192
|
}
|
|
40951
40193
|
return await sessions.configureSession({
|
|
@@ -40954,7 +40196,7 @@ async function applySessionConfigurationSelection(sessions, audit, options, sele
|
|
|
40954
40196
|
booleanValue: selection.booleanValue,
|
|
40955
40197
|
configId: selection.configId,
|
|
40956
40198
|
cwd,
|
|
40957
|
-
requestId: `cfg_${
|
|
40199
|
+
requestId: `cfg_${randomUUID4()}`,
|
|
40958
40200
|
sessionId,
|
|
40959
40201
|
signal,
|
|
40960
40202
|
value: selection.value,
|
|
@@ -40984,37 +40226,6 @@ async function applyCompleteSessionConfiguration(sessions, audit, initialOptions
|
|
|
40984
40226
|
}
|
|
40985
40227
|
assertAppliedSessionConfiguration(options, selections);
|
|
40986
40228
|
}
|
|
40987
|
-
function botExecutionAgent(agent, contextHandle, socketPath) {
|
|
40988
|
-
return new LocalAgentDefinition(
|
|
40989
|
-
agent.id,
|
|
40990
|
-
agent.label,
|
|
40991
|
-
agent.command,
|
|
40992
|
-
agent.arguments,
|
|
40993
|
-
{
|
|
40994
|
-
...agent.environment,
|
|
40995
|
-
MOBIUS_BOT_CONTEXT: contextHandle,
|
|
40996
|
-
MOBIUS_BOT_SOCKET: socketPath,
|
|
40997
|
-
MOBIUS_RELAY_TOKEN: "",
|
|
40998
|
-
MOBIUS_RELAY_URL: ""
|
|
40999
|
-
},
|
|
41000
|
-
agent.adapterVersion,
|
|
41001
|
-
agent.agentVersion,
|
|
41002
|
-
agent.adapterIdentity,
|
|
41003
|
-
agent.agentIdentity,
|
|
41004
|
-
agent.capabilities,
|
|
41005
|
-
agent.permissionProfile
|
|
41006
|
-
);
|
|
41007
|
-
}
|
|
41008
|
-
function assertPreparedPermission(configOptions, permissionMode) {
|
|
41009
|
-
const permission = configOptions.find((option2) => option2.id === "permission_mode");
|
|
41010
|
-
if (permission === void 0 || permission.type !== "select" || permissionMode !== AGENT_DEFAULT_EXECUTION_SETTING && permission.currentValue !== permissionMode) {
|
|
41011
|
-
throw new AcpExecutionError(
|
|
41012
|
-
"The required Agent permission mode is unavailable",
|
|
41013
|
-
{},
|
|
41014
|
-
"invalid_session_configuration"
|
|
41015
|
-
);
|
|
41016
|
-
}
|
|
41017
|
-
}
|
|
41018
40229
|
function warnIgnoredSetting(audit, event, commandId, sessionId, agentId, selection, category, reason) {
|
|
41019
40230
|
const details = {
|
|
41020
40231
|
agentId,
|
|
@@ -41027,274 +40238,6 @@ function warnIgnoredSetting(audit, event, commandId, sessionId, agentId, selecti
|
|
|
41027
40238
|
process.stderr.write(`Mobius daemon warning ${JSON.stringify({ commandId, event, sessionId, ...details })}
|
|
41028
40239
|
`);
|
|
41029
40240
|
}
|
|
41030
|
-
async function applySupportedExecutionSelection(sessions, audit, configOptions, selection, category, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
|
|
41031
|
-
if (selection.value === AGENT_DEFAULT_EXECUTION_SETTING) {
|
|
41032
|
-
return configOptions;
|
|
41033
|
-
}
|
|
41034
|
-
const option2 = configOptions.find((candidate) => candidate.id === selection.configId);
|
|
41035
|
-
if (option2 === void 0) {
|
|
41036
|
-
warnIgnoredSetting(
|
|
41037
|
-
audit,
|
|
41038
|
-
"bot_execution_setting_ignored",
|
|
41039
|
-
commandId,
|
|
41040
|
-
sessionId,
|
|
41041
|
-
agent.id,
|
|
41042
|
-
selection,
|
|
41043
|
-
category,
|
|
41044
|
-
"setting_unavailable"
|
|
41045
|
-
);
|
|
41046
|
-
return configOptions;
|
|
41047
|
-
}
|
|
41048
|
-
if (option2.type !== "select" || option2.category !== category) {
|
|
41049
|
-
warnIgnoredSetting(
|
|
41050
|
-
audit,
|
|
41051
|
-
"bot_execution_setting_ignored",
|
|
41052
|
-
commandId,
|
|
41053
|
-
sessionId,
|
|
41054
|
-
agent.id,
|
|
41055
|
-
selection,
|
|
41056
|
-
category,
|
|
41057
|
-
"setting_schema_mismatch"
|
|
41058
|
-
);
|
|
41059
|
-
return configOptions;
|
|
41060
|
-
}
|
|
41061
|
-
if (selection.valueType !== "select" || selection.booleanValue) {
|
|
41062
|
-
warnIgnoredSetting(
|
|
41063
|
-
audit,
|
|
41064
|
-
"bot_execution_setting_ignored",
|
|
41065
|
-
commandId,
|
|
41066
|
-
sessionId,
|
|
41067
|
-
agent.id,
|
|
41068
|
-
selection,
|
|
41069
|
-
category,
|
|
41070
|
-
"selection_schema_mismatch"
|
|
41071
|
-
);
|
|
41072
|
-
return configOptions;
|
|
41073
|
-
}
|
|
41074
|
-
if (!option2.values.some((value) => value.value === selection.value)) {
|
|
41075
|
-
warnIgnoredSetting(
|
|
41076
|
-
audit,
|
|
41077
|
-
"bot_execution_setting_ignored",
|
|
41078
|
-
commandId,
|
|
41079
|
-
sessionId,
|
|
41080
|
-
agent.id,
|
|
41081
|
-
selection,
|
|
41082
|
-
category,
|
|
41083
|
-
"value_unavailable"
|
|
41084
|
-
);
|
|
41085
|
-
return configOptions;
|
|
41086
|
-
}
|
|
41087
|
-
if (option2.currentValue === selection.value) {
|
|
41088
|
-
return configOptions;
|
|
41089
|
-
}
|
|
41090
|
-
return await sessions.configureSession({
|
|
41091
|
-
additionalDirectories,
|
|
41092
|
-
agent,
|
|
41093
|
-
booleanValue: false,
|
|
41094
|
-
configId: selection.configId,
|
|
41095
|
-
cwd,
|
|
41096
|
-
requestId: `cfg_${randomUUID5()}`,
|
|
41097
|
-
sessionId,
|
|
41098
|
-
signal,
|
|
41099
|
-
value: selection.value,
|
|
41100
|
-
valueType: "select"
|
|
41101
|
-
});
|
|
41102
|
-
}
|
|
41103
|
-
async function executeBotPrompt(outbox, publisher, command, config2, directories, audit, sessions, authorizer, contexts, applicator, ipc, attemptId, activateAttempt, timer, signal) {
|
|
41104
|
-
const activities = new CoalescingDaemonActivityPublisher(timer, (activity) => {
|
|
41105
|
-
publisher.recordAttempt(command.sessionId, encodeDaemonActivity(command, activity), attemptId);
|
|
41106
|
-
});
|
|
41107
|
-
try {
|
|
41108
|
-
const startDeadline = Date.parse(command.executionDeadlineAt);
|
|
41109
|
-
if (!Number.isSafeInteger(startDeadline) || startDeadline <= Date.now()) {
|
|
41110
|
-
throw new LocalBotAuthorizationError("turn_expired", "The Bot execution start deadline has expired");
|
|
41111
|
-
}
|
|
41112
|
-
const execution = await authorizer.authorize(command, config2.catalog, directories, config2.bindingId, signal);
|
|
41113
|
-
const resolved = await resolveSessionDirectories(
|
|
41114
|
-
directories,
|
|
41115
|
-
config2.bindingId,
|
|
41116
|
-
command.directoryId,
|
|
41117
|
-
command.additionalDirectoryIds,
|
|
41118
|
-
signal
|
|
41119
|
-
);
|
|
41120
|
-
const attachments = await resolvePromptArtifacts(config2, command, signal);
|
|
41121
|
-
const applied = await applicator.apply(command, execution, attachments.resources, signal);
|
|
41122
|
-
const startExecution = () => {
|
|
41123
|
-
audit.record({
|
|
41124
|
-
commandId: command.commandId,
|
|
41125
|
-
details: {
|
|
41126
|
-
behaviorRevisionId: command.behaviorRevisionId,
|
|
41127
|
-
bindingId: command.bindingId,
|
|
41128
|
-
botId: command.botId,
|
|
41129
|
-
executionId: command.executionId
|
|
41130
|
-
},
|
|
41131
|
-
event: "bot_session_authorized",
|
|
41132
|
-
sessionId: command.sessionId
|
|
41133
|
-
});
|
|
41134
|
-
outbox.transitionExecution(command.commandId, "running");
|
|
41135
|
-
publisher.recordAttempt(
|
|
41136
|
-
command.sessionId,
|
|
41137
|
-
encodeSessionStartedEvent({
|
|
41138
|
-
attemptId,
|
|
41139
|
-
commandId: command.commandId,
|
|
41140
|
-
kind: SESSION_STARTED_KIND,
|
|
41141
|
-
sessionId: command.sessionId
|
|
41142
|
-
}),
|
|
41143
|
-
attemptId
|
|
41144
|
-
);
|
|
41145
|
-
activateAttempt();
|
|
41146
|
-
};
|
|
41147
|
-
let stopReason = "steered";
|
|
41148
|
-
if (command.disposition === SessionPromptDisposition.Steer) {
|
|
41149
|
-
startExecution();
|
|
41150
|
-
await sessions.steerPrompt({
|
|
41151
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
41152
|
-
agent: execution.agent,
|
|
41153
|
-
commandId: command.commandId,
|
|
41154
|
-
cwd: resolved.cwd,
|
|
41155
|
-
images: attachments.images,
|
|
41156
|
-
prompt: command.prompt,
|
|
41157
|
-
resources: applied.resources,
|
|
41158
|
-
sessionId: command.sessionId,
|
|
41159
|
-
signal,
|
|
41160
|
-
targetCommandId: command.targetCommandId
|
|
41161
|
-
});
|
|
41162
|
-
} else {
|
|
41163
|
-
if (command.disposition === SessionPromptDisposition.Queue && !outbox.isTerminalExecution(command.targetCommandId, command.sessionId)) {
|
|
41164
|
-
throw new AcpExecutionError(
|
|
41165
|
-
"The queued Bot prompt target is unavailable",
|
|
41166
|
-
{},
|
|
41167
|
-
"prompt_queue_target_unavailable"
|
|
41168
|
-
);
|
|
41169
|
-
}
|
|
41170
|
-
const lease = contexts.activate(command);
|
|
41171
|
-
try {
|
|
41172
|
-
const agent = botExecutionAgent(execution.agent, lease.context.contextHandle, ipc.socketPath);
|
|
41173
|
-
const prepared = await sessions.prepareExecutionSession({
|
|
41174
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
41175
|
-
agent,
|
|
41176
|
-
cwd: resolved.cwd,
|
|
41177
|
-
sessionId: command.sessionId,
|
|
41178
|
-
signal
|
|
41179
|
-
});
|
|
41180
|
-
assertPreparedPermission(prepared.configOptions, execution.executionConfiguration.permissionMode);
|
|
41181
|
-
let configOptions = await applySupportedExecutionSelection(
|
|
41182
|
-
sessions,
|
|
41183
|
-
audit,
|
|
41184
|
-
prepared.configOptions,
|
|
41185
|
-
execution.executionConfiguration.model,
|
|
41186
|
-
"model",
|
|
41187
|
-
agent,
|
|
41188
|
-
resolved.cwd,
|
|
41189
|
-
resolved.additionalDirectories,
|
|
41190
|
-
command.commandId,
|
|
41191
|
-
command.sessionId,
|
|
41192
|
-
signal
|
|
41193
|
-
);
|
|
41194
|
-
configOptions = await applySupportedExecutionSelection(
|
|
41195
|
-
sessions,
|
|
41196
|
-
audit,
|
|
41197
|
-
configOptions,
|
|
41198
|
-
execution.executionConfiguration.reasoningEffort,
|
|
41199
|
-
"thought_level",
|
|
41200
|
-
agent,
|
|
41201
|
-
resolved.cwd,
|
|
41202
|
-
resolved.additionalDirectories,
|
|
41203
|
-
command.commandId,
|
|
41204
|
-
command.sessionId,
|
|
41205
|
-
signal
|
|
41206
|
-
);
|
|
41207
|
-
for (const selection of command.sessionConfigurations) {
|
|
41208
|
-
await sessions.configureSession({
|
|
41209
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
41210
|
-
agent,
|
|
41211
|
-
booleanValue: selection.booleanValue,
|
|
41212
|
-
configId: selection.configId,
|
|
41213
|
-
cwd: resolved.cwd,
|
|
41214
|
-
requestId: `cfg_${randomUUID5()}`,
|
|
41215
|
-
sessionId: command.sessionId,
|
|
41216
|
-
signal,
|
|
41217
|
-
value: selection.value,
|
|
41218
|
-
valueType: selection.valueType
|
|
41219
|
-
});
|
|
41220
|
-
}
|
|
41221
|
-
startExecution();
|
|
41222
|
-
const result = await sessions.runPrompt({
|
|
41223
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
41224
|
-
agent,
|
|
41225
|
-
commandId: command.commandId,
|
|
41226
|
-
cwd: resolved.cwd,
|
|
41227
|
-
disposition: command.disposition,
|
|
41228
|
-
images: attachments.images,
|
|
41229
|
-
onActivity: activities.record,
|
|
41230
|
-
onText: (text3, messageId) => {
|
|
41231
|
-
publisher.recordAttempt(
|
|
41232
|
-
command.sessionId,
|
|
41233
|
-
encodeAgentMessageDeltaEvent({
|
|
41234
|
-
commandId: command.commandId,
|
|
41235
|
-
kind: AGENT_MESSAGE_DELTA_KIND,
|
|
41236
|
-
messageId,
|
|
41237
|
-
sessionId: command.sessionId,
|
|
41238
|
-
text: text3
|
|
41239
|
-
}),
|
|
41240
|
-
attemptId
|
|
41241
|
-
);
|
|
41242
|
-
return Promise.resolve();
|
|
41243
|
-
},
|
|
41244
|
-
prompt: command.prompt,
|
|
41245
|
-
resources: applied.resources,
|
|
41246
|
-
sessionId: command.sessionId,
|
|
41247
|
-
signal,
|
|
41248
|
-
targetCommandId: command.targetCommandId
|
|
41249
|
-
});
|
|
41250
|
-
stopReason = result.stopReason;
|
|
41251
|
-
} finally {
|
|
41252
|
-
lease.release();
|
|
41253
|
-
}
|
|
41254
|
-
}
|
|
41255
|
-
activities.flush();
|
|
41256
|
-
publisher.recordAttempt(
|
|
41257
|
-
command.sessionId,
|
|
41258
|
-
encodeSessionCompletedEvent({
|
|
41259
|
-
commandId: command.commandId,
|
|
41260
|
-
kind: SESSION_COMPLETED_KIND,
|
|
41261
|
-
sessionId: command.sessionId,
|
|
41262
|
-
stopReason
|
|
41263
|
-
}),
|
|
41264
|
-
attemptId
|
|
41265
|
-
);
|
|
41266
|
-
outbox.transitionExecution(command.commandId, stopReason === "cancelled" ? "cancelled" : "succeeded");
|
|
41267
|
-
audit.record({
|
|
41268
|
-
commandId: command.commandId,
|
|
41269
|
-
details: { botId: command.botId, executionId: command.executionId },
|
|
41270
|
-
event: stopReason === "cancelled" ? "bot_session_cancelled" : "bot_session_completed",
|
|
41271
|
-
sessionId: command.sessionId
|
|
41272
|
-
});
|
|
41273
|
-
} catch (error62) {
|
|
41274
|
-
activities.flush();
|
|
41275
|
-
const failure2 = error62;
|
|
41276
|
-
audit.record({
|
|
41277
|
-
commandId: command.commandId,
|
|
41278
|
-
details: {
|
|
41279
|
-
botId: command.botId,
|
|
41280
|
-
code: operationErrorCode(failure2),
|
|
41281
|
-
executionId: command.executionId
|
|
41282
|
-
},
|
|
41283
|
-
event: "bot_session_failed",
|
|
41284
|
-
sessionId: command.sessionId
|
|
41285
|
-
});
|
|
41286
|
-
const code = operationErrorCode(failure2);
|
|
41287
|
-
reportFailure(
|
|
41288
|
-
publisher,
|
|
41289
|
-
command,
|
|
41290
|
-
code === "session_operation_failed" ? "agent_execution_failed" : code,
|
|
41291
|
-
code === "session_operation_failed" ? "The local agent could not complete the Bot request" : operationErrorMessage(failure2),
|
|
41292
|
-
attemptId
|
|
41293
|
-
);
|
|
41294
|
-
outbox.transitionExecution(command.commandId, "failed");
|
|
41295
|
-
console.error("Mobius daemon Bot command failed", failure2);
|
|
41296
|
-
}
|
|
41297
|
-
}
|
|
41298
40241
|
function waitForRelayRetry(signal, timer) {
|
|
41299
40242
|
if (signal.aborted) {
|
|
41300
40243
|
return Promise.resolve();
|
|
@@ -41341,13 +40284,13 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
|
|
|
41341
40284
|
{
|
|
41342
40285
|
agentId: agent.id,
|
|
41343
40286
|
kind: AGENT_INSTALL_REQUEST_KIND,
|
|
41344
|
-
requestId: `automatic-integration-${
|
|
40287
|
+
requestId: `automatic-integration-${randomUUID4()}`
|
|
41345
40288
|
},
|
|
41346
40289
|
signal
|
|
41347
40290
|
);
|
|
41348
40291
|
}
|
|
41349
40292
|
}
|
|
41350
|
-
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) {
|
|
41351
40294
|
const relayUrl = new URL(config2.relayUrl);
|
|
41352
40295
|
relayUrl.searchParams.set("deliveryReceipts", "1");
|
|
41353
40296
|
relayUrl.searchParams.set("liveness", "1");
|
|
@@ -41513,32 +40456,6 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
41513
40456
|
}
|
|
41514
40457
|
return;
|
|
41515
40458
|
}
|
|
41516
|
-
if (kind === BOT_SESSION_PROMPT_KIND) {
|
|
41517
|
-
const command = decodeBotSessionPromptCommand(delivery.payload);
|
|
41518
|
-
await processDeliveredPrompt(
|
|
41519
|
-
delivery,
|
|
41520
|
-
command,
|
|
41521
|
-
command.disposition !== SessionPromptDisposition.Steer,
|
|
41522
|
-
(attemptId, activateAttempt, executionSignal) => executeBotPrompt(
|
|
41523
|
-
outbox,
|
|
41524
|
-
publisher,
|
|
41525
|
-
command,
|
|
41526
|
-
config2,
|
|
41527
|
-
directories,
|
|
41528
|
-
audit,
|
|
41529
|
-
sessions,
|
|
41530
|
-
authorizer,
|
|
41531
|
-
contexts,
|
|
41532
|
-
applicator,
|
|
41533
|
-
ipc,
|
|
41534
|
-
attemptId,
|
|
41535
|
-
activateAttempt,
|
|
41536
|
-
timer,
|
|
41537
|
-
executionSignal
|
|
41538
|
-
)
|
|
41539
|
-
);
|
|
41540
|
-
return;
|
|
41541
|
-
}
|
|
41542
40459
|
if (kind === SESSION_PROMPT_KIND) {
|
|
41543
40460
|
const command = decodeSessionPromptCommand(delivery.payload);
|
|
41544
40461
|
await processDeliveredPrompt(
|
|
@@ -41596,8 +40513,6 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
41596
40513
|
payloadSessionId = decodeSessionElicitationRespondCommand(delivery.payload).sessionId;
|
|
41597
40514
|
} else if (payloadKind === SESSION_PROMPT_KIND) {
|
|
41598
40515
|
payloadSessionId = decodeSessionPromptCommand(delivery.payload).sessionId;
|
|
41599
|
-
} else if (payloadKind === BOT_SESSION_PROMPT_KIND) {
|
|
41600
|
-
payloadSessionId = decodeBotSessionPromptCommand(delivery.payload).sessionId;
|
|
41601
40516
|
} else {
|
|
41602
40517
|
throw new Error("Runtime delivery contains an unsupported protocol message");
|
|
41603
40518
|
}
|
|
@@ -41990,6 +40905,29 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
41990
40905
|
connectionLiveness.acknowledge(decodeRuntimeHeartbeatAckEvent(encoded));
|
|
41991
40906
|
return;
|
|
41992
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
|
+
}
|
|
41993
40931
|
if (kind === SESSION_CANCEL_KIND) {
|
|
41994
40932
|
const cancellation = decodeSessionCancelCommand(encoded);
|
|
41995
40933
|
const turn2 = activeTurns.get(cancellation.commandId);
|
|
@@ -42083,48 +41021,6 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
42083
41021
|
});
|
|
42084
41022
|
return;
|
|
42085
41023
|
}
|
|
42086
|
-
if (kind === BOT_SESSION_PROMPT_KIND) {
|
|
42087
|
-
const command2 = decodeBotSessionPromptCommand(encoded);
|
|
42088
|
-
if (activeTurns.has(command2.commandId)) {
|
|
42089
|
-
return;
|
|
42090
|
-
}
|
|
42091
|
-
const receipt2 = outbox.claimExecution(command2.commandId, command2.sessionId, encoded);
|
|
42092
|
-
if (receipt2.kind === "duplicate") {
|
|
42093
|
-
return;
|
|
42094
|
-
}
|
|
42095
|
-
const turn2 = new ActiveDaemonTurn(command2, receipt2.attemptId);
|
|
42096
|
-
activeTurns.set(command2.commandId, turn2);
|
|
42097
|
-
void executeBotPrompt(
|
|
42098
|
-
outbox,
|
|
42099
|
-
publisher,
|
|
42100
|
-
command2,
|
|
42101
|
-
config2,
|
|
42102
|
-
directories,
|
|
42103
|
-
audit,
|
|
42104
|
-
sessions,
|
|
42105
|
-
authorizer,
|
|
42106
|
-
contexts,
|
|
42107
|
-
applicator,
|
|
42108
|
-
ipc,
|
|
42109
|
-
receipt2.attemptId,
|
|
42110
|
-
() => {
|
|
42111
|
-
if (command2.disposition !== SessionPromptDisposition.Steer) {
|
|
42112
|
-
activeAttemptIds.set(command2.sessionId, receipt2.attemptId);
|
|
42113
|
-
}
|
|
42114
|
-
},
|
|
42115
|
-
timer,
|
|
42116
|
-
turn2.signal
|
|
42117
|
-
).catch((error62) => {
|
|
42118
|
-
console.error("Mobius daemon Bot turn failed", error62);
|
|
42119
|
-
}).finally(() => {
|
|
42120
|
-
activeTurns.delete(command2.commandId);
|
|
42121
|
-
if (activeAttemptIds.get(command2.sessionId) === receipt2.attemptId) {
|
|
42122
|
-
activeAttemptIds.delete(command2.sessionId);
|
|
42123
|
-
}
|
|
42124
|
-
turn2.finish();
|
|
42125
|
-
});
|
|
42126
|
-
return;
|
|
42127
|
-
}
|
|
42128
41024
|
if (kind !== SESSION_PROMPT_KIND) {
|
|
42129
41025
|
throw new Error("Unsupported protocol message");
|
|
42130
41026
|
}
|
|
@@ -42228,10 +41124,6 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
42228
41124
|
const sessionStore = new SqliteAcpSessionStore(config2.auditDatabasePath);
|
|
42229
41125
|
const outbox = new SessionEventOutbox(config2.auditDatabasePath);
|
|
42230
41126
|
const publisher = new DaemonSessionEventPublisher(outbox, timer);
|
|
42231
|
-
const authorizer = new LocalBotExecutionAuthorizer();
|
|
42232
|
-
const contexts = new BotExecutionContextRegistry();
|
|
42233
|
-
const applicator = new EmbeddedBotContextApplicator();
|
|
42234
|
-
const ipc = new BotOutboundIpcServer(botIpcSocketPath(), config2.relayUrl, contexts);
|
|
42235
41127
|
const activeTurns = /* @__PURE__ */ new Map();
|
|
42236
41128
|
const activeAttemptIds = /* @__PURE__ */ new Map();
|
|
42237
41129
|
const recordSessionEvent = (sessionId, payload) => {
|
|
@@ -42305,7 +41197,6 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
42305
41197
|
startAutomaticIntegrationProvisioning();
|
|
42306
41198
|
});
|
|
42307
41199
|
try {
|
|
42308
|
-
await ipc.listen(signal);
|
|
42309
41200
|
while (!signal.aborted) {
|
|
42310
41201
|
connectionEpoch += 1;
|
|
42311
41202
|
try {
|
|
@@ -42319,10 +41210,6 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
42319
41210
|
nativeSessions,
|
|
42320
41211
|
outbox,
|
|
42321
41212
|
publisher,
|
|
42322
|
-
authorizer,
|
|
42323
|
-
contexts,
|
|
42324
|
-
applicator,
|
|
42325
|
-
ipc,
|
|
42326
41213
|
activeTurns,
|
|
42327
41214
|
activeAttemptIds,
|
|
42328
41215
|
connectionEpoch,
|
|
@@ -42355,19 +41242,15 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
42355
41242
|
await installations.close();
|
|
42356
41243
|
} finally {
|
|
42357
41244
|
try {
|
|
42358
|
-
await
|
|
41245
|
+
await sessions.close();
|
|
42359
41246
|
} finally {
|
|
42360
41247
|
try {
|
|
42361
|
-
|
|
41248
|
+
sessionStore.close();
|
|
42362
41249
|
} finally {
|
|
42363
41250
|
try {
|
|
42364
|
-
|
|
41251
|
+
publisher.close();
|
|
42365
41252
|
} finally {
|
|
42366
|
-
|
|
42367
|
-
publisher.close();
|
|
42368
|
-
} finally {
|
|
42369
|
-
outbox.close();
|
|
42370
|
-
}
|
|
41253
|
+
outbox.close();
|
|
42371
41254
|
}
|
|
42372
41255
|
}
|
|
42373
41256
|
}
|
|
@@ -42378,9 +41261,9 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
42378
41261
|
}
|
|
42379
41262
|
|
|
42380
41263
|
// src/runtime.ts
|
|
42381
|
-
import { mkdir as
|
|
42382
|
-
import { dirname as
|
|
42383
|
-
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}$/;
|
|
42384
41267
|
var RUNTIME_CREDENTIAL_PATTERN = /^[a-zA-Z0-9_-]{32,256}$/;
|
|
42385
41268
|
var MobiusRuntimeConfigurationError = class extends Error {
|
|
42386
41269
|
code = "runtime_configuration_invalid";
|
|
@@ -42432,11 +41315,11 @@ function relayUrlFromConnection(connection) {
|
|
|
42432
41315
|
}
|
|
42433
41316
|
function loadMobiusRuntimeConnection(environment = process.env) {
|
|
42434
41317
|
const channelId = requiredEnvironmentValue(environment, "MOBIUS_CHANNEL_ID");
|
|
42435
|
-
if (!
|
|
41318
|
+
if (!IDENTIFIER_PATTERN7.test(channelId)) {
|
|
42436
41319
|
throw new MobiusRuntimeConfigurationError("MOBIUS_CHANNEL_ID is invalid");
|
|
42437
41320
|
}
|
|
42438
41321
|
return Object.freeze({
|
|
42439
|
-
auditDatabasePath: environment["MOBIUS_AUDIT_DATABASE"]?.trim() ||
|
|
41322
|
+
auditDatabasePath: environment["MOBIUS_AUDIT_DATABASE"]?.trim() || join17(readStateDirectory(environment), "audit", `${channelId}.sqlite`),
|
|
42440
41323
|
channelId,
|
|
42441
41324
|
defaultWorkspace: loadDefaultWorkspace(environment),
|
|
42442
41325
|
relayUrl: requiredEnvironmentValue(environment, "MOBIUS_RELAY_URL"),
|
|
@@ -42446,9 +41329,9 @@ function loadMobiusRuntimeConnection(environment = process.env) {
|
|
|
42446
41329
|
async function resolveWorkspace(path2) {
|
|
42447
41330
|
const requested = resolve5(path2);
|
|
42448
41331
|
try {
|
|
42449
|
-
await
|
|
42450
|
-
const resolved = await
|
|
42451
|
-
const metadata = await
|
|
41332
|
+
await mkdir4(requested, { recursive: true, mode: 448 });
|
|
41333
|
+
const resolved = await realpath10(requested);
|
|
41334
|
+
const metadata = await stat9(resolved);
|
|
42452
41335
|
if (!metadata.isDirectory()) {
|
|
42453
41336
|
throw new MobiusRuntimeConfigurationError("The Runtime workspace is not a directory");
|
|
42454
41337
|
}
|
|
@@ -42465,7 +41348,7 @@ async function createMobiusRuntimeEngine(connection, signal, environment = proce
|
|
|
42465
41348
|
const relayUrl = relayUrlFromConnection(connection);
|
|
42466
41349
|
const defaultWorkspace = await resolveWorkspace(connection.defaultWorkspace);
|
|
42467
41350
|
const auditDatabasePath = resolve5(connection.auditDatabasePath);
|
|
42468
|
-
await
|
|
41351
|
+
await mkdir4(dirname7(auditDatabasePath), { recursive: true, mode: 448 });
|
|
42469
41352
|
const inventory = await discoverLocalAgentInventory({
|
|
42470
41353
|
defaultWorkspace,
|
|
42471
41354
|
environment,
|
|
@@ -42512,16 +41395,12 @@ var MobiusRuntimeEngine = class {
|
|
|
42512
41395
|
export {
|
|
42513
41396
|
AcpExecutionError,
|
|
42514
41397
|
AuditStore,
|
|
42515
|
-
BotExecutionContextRegistry,
|
|
42516
|
-
BotMessageCommandError,
|
|
42517
|
-
BotOutboundIpcServer,
|
|
42518
41398
|
LocalAuthorizationError,
|
|
42519
41399
|
MobiusRuntimeConfigurationError,
|
|
42520
41400
|
MobiusRuntimeEngine,
|
|
42521
41401
|
PairingClientError,
|
|
42522
41402
|
createAcpClient,
|
|
42523
41403
|
createMobiusRuntimeEngine,
|
|
42524
|
-
executeBotMessageCommand,
|
|
42525
41404
|
loadDaemonConfig,
|
|
42526
41405
|
loadMobiusRuntimeConnection,
|
|
42527
41406
|
pairLocalMachine,
|