@moxt-ai/mobius 0.0.52 → 0.0.54
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/cli.js +133 -40
- package/dist/cli.js.map +4 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +131 -39
- package/dist/index.js.map +4 -4
- package/dist/relay-connection/coalescing-text-publisher.d.ts +27 -0
- package/dist/relay-connection/coalescing-text-publisher.d.ts.map +1 -0
- package/dist/relay-connection/coalescing-text-publisher.js +58 -0
- package/dist/relay-connection/coalescing-text-publisher.js.map +1 -0
- package/dist/relay-connection/connect.d.ts.map +1 -1
- package/dist/relay-connection/connect.js +5 -0
- package/dist/relay-connection/connect.js.map +1 -1
- package/dist/relay-connection/runtime-revocation.d.ts +12 -0
- package/dist/relay-connection/runtime-revocation.d.ts.map +1 -0
- package/dist/relay-connection/runtime-revocation.js +21 -0
- package/dist/relay-connection/runtime-revocation.js.map +1 -0
- package/dist/run-daemon.d.ts.map +1 -1
- package/dist/run-daemon.js +60 -40
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.js +132 -39
- package/dist/runtime.js.map +4 -4
- package/package.json +1 -1
package/dist/runtime.js
CHANGED
|
@@ -37706,8 +37706,72 @@ async function resolvePromptArtifacts(config2, command, signal) {
|
|
|
37706
37706
|
return new ResolvedPromptArtifacts(images, resources);
|
|
37707
37707
|
}
|
|
37708
37708
|
|
|
37709
|
+
// src/relay-connection/coalescing-text-publisher.ts
|
|
37710
|
+
var CoalescingTextPublisher = class {
|
|
37711
|
+
#coalescingMilliseconds;
|
|
37712
|
+
#maximumTextLength;
|
|
37713
|
+
#publish;
|
|
37714
|
+
#timer;
|
|
37715
|
+
#messageId = "";
|
|
37716
|
+
#scheduled = null;
|
|
37717
|
+
#text = "";
|
|
37718
|
+
constructor(timer, publish, coalescingMilliseconds, maximumTextLength) {
|
|
37719
|
+
this.#publish = publish;
|
|
37720
|
+
this.#timer = timer;
|
|
37721
|
+
this.#coalescingMilliseconds = coalescingMilliseconds;
|
|
37722
|
+
this.#maximumTextLength = maximumTextLength;
|
|
37723
|
+
}
|
|
37724
|
+
/** Emit any buffered text now, cancelling the pending flush. */
|
|
37725
|
+
flush = () => {
|
|
37726
|
+
this.#scheduled?.cancel();
|
|
37727
|
+
this.#scheduled = null;
|
|
37728
|
+
const messageId = this.#messageId;
|
|
37729
|
+
const text3 = this.#text;
|
|
37730
|
+
this.#messageId = "";
|
|
37731
|
+
this.#text = "";
|
|
37732
|
+
if (text3.length > 0) {
|
|
37733
|
+
this.#publish(messageId, text3);
|
|
37734
|
+
}
|
|
37735
|
+
};
|
|
37736
|
+
/**
|
|
37737
|
+
* Buffer a chunk, emitting the buffered text when the message changes or the
|
|
37738
|
+
* buffer would exceed the protocol's per-event text limit.
|
|
37739
|
+
*/
|
|
37740
|
+
record = (messageId, text3) => {
|
|
37741
|
+
if (text3.length === 0) {
|
|
37742
|
+
return;
|
|
37743
|
+
}
|
|
37744
|
+
if (this.#text.length > 0 && (this.#messageId !== messageId || this.#text.length + text3.length > this.#maximumTextLength)) {
|
|
37745
|
+
this.flush();
|
|
37746
|
+
}
|
|
37747
|
+
this.#messageId = messageId;
|
|
37748
|
+
this.#text = `${this.#text}${text3}`;
|
|
37749
|
+
this.#scheduled ??= this.#timer.schedule(this.flush, this.#coalescingMilliseconds);
|
|
37750
|
+
};
|
|
37751
|
+
};
|
|
37752
|
+
|
|
37709
37753
|
// src/relay-connection/connect.ts
|
|
37710
37754
|
import { WebSocket } from "undici";
|
|
37755
|
+
|
|
37756
|
+
// src/relay-connection/runtime-revocation.ts
|
|
37757
|
+
var runtimeRevocationCloseCode = 1008;
|
|
37758
|
+
var runtimeRevocationCloseReason = "Runtime revoked";
|
|
37759
|
+
var RuntimeRelayRevokedError = class extends Error {
|
|
37760
|
+
code = "runtime_relay_revoked";
|
|
37761
|
+
closeCode;
|
|
37762
|
+
closeReason;
|
|
37763
|
+
constructor(closeCode, closeReason, options = {}) {
|
|
37764
|
+
super("The Runtime was revoked by the Relay", options);
|
|
37765
|
+
this.closeCode = closeCode;
|
|
37766
|
+
this.closeReason = closeReason;
|
|
37767
|
+
this.name = "RuntimeRelayRevokedError";
|
|
37768
|
+
}
|
|
37769
|
+
};
|
|
37770
|
+
function isRuntimeRelayRevocation(closeCode, closeReason) {
|
|
37771
|
+
return closeCode === runtimeRevocationCloseCode && closeReason === runtimeRevocationCloseReason;
|
|
37772
|
+
}
|
|
37773
|
+
|
|
37774
|
+
// src/relay-connection/connect.ts
|
|
37711
37775
|
var CONNECTION_TIMEOUT_MILLISECONDS = 15e3;
|
|
37712
37776
|
var RelayConnectionError = class extends Error {
|
|
37713
37777
|
code;
|
|
@@ -37760,6 +37824,10 @@ function connectRelay(url2, signal) {
|
|
|
37760
37824
|
);
|
|
37761
37825
|
};
|
|
37762
37826
|
const onClose = (event) => {
|
|
37827
|
+
if (isRuntimeRelayRevocation(event.code, event.reason)) {
|
|
37828
|
+
fail(new RuntimeRelayRevokedError(event.code, event.reason));
|
|
37829
|
+
return;
|
|
37830
|
+
}
|
|
37763
37831
|
fail(
|
|
37764
37832
|
new RelayConnectionError("relay_connection_closed", "Relay connection closed before it was ready", {
|
|
37765
37833
|
closeCode: event.code.toString(),
|
|
@@ -38642,6 +38710,8 @@ var systemDaemonTimer = new SystemDaemonTimer();
|
|
|
38642
38710
|
// src/run-daemon.ts
|
|
38643
38711
|
var RELAY_RECONNECT_DELAY_MILLISECONDS = 500;
|
|
38644
38712
|
var AGENT_ACTIVITY_COALESCING_MILLISECONDS = 100;
|
|
38713
|
+
var AGENT_TEXT_COALESCING_MILLISECONDS = 100;
|
|
38714
|
+
var AGENT_TEXT_MAXIMUM_LENGTH = 1e5;
|
|
38645
38715
|
var ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS = 2e4;
|
|
38646
38716
|
var ACTIVE_TURN_RECONCILIATION_CLOSE_CODE = 4009;
|
|
38647
38717
|
var DaemonAcpObserver = class {
|
|
@@ -39222,32 +39292,41 @@ async function resolveSessionDirectories(directories, bindingId, directoryId2, a
|
|
|
39222
39292
|
async function discoverAgentSettings(command, config2, directories, sessions, signal) {
|
|
39223
39293
|
const agent = config2.catalog.find(command.agentId);
|
|
39224
39294
|
const cwd = await directories.resolve(config2.bindingId, "default", signal);
|
|
39225
|
-
const
|
|
39295
|
+
const baseSnapshot = await sessions.inspectAgentSettings({
|
|
39226
39296
|
additionalDirectories: [],
|
|
39227
39297
|
agent,
|
|
39228
39298
|
cwd,
|
|
39229
39299
|
signal
|
|
39230
39300
|
});
|
|
39301
|
+
const selectedSnapshot = command.model === void 0 ? baseSnapshot : await sessions.inspectAgentSettings({
|
|
39302
|
+
additionalDirectories: [],
|
|
39303
|
+
agent,
|
|
39304
|
+
cwd,
|
|
39305
|
+
model: command.model,
|
|
39306
|
+
signal
|
|
39307
|
+
});
|
|
39231
39308
|
const adapter = agentSettingsAdapterForAgent(agent.id);
|
|
39232
|
-
const
|
|
39309
|
+
const baseSettings = settingsFromSnapshot(agent, baseSnapshot.configOptions);
|
|
39310
|
+
const settings = settingsFromSnapshot(agent, selectedSnapshot.configOptions);
|
|
39233
39311
|
const modelEffort = await discoverModelEffort(
|
|
39234
39312
|
command,
|
|
39235
39313
|
agent,
|
|
39236
39314
|
adapter.modelEffortResolution,
|
|
39237
|
-
|
|
39315
|
+
baseSnapshot.configOptions,
|
|
39316
|
+
selectedSnapshot.configOptions,
|
|
39238
39317
|
cwd,
|
|
39239
39318
|
sessions,
|
|
39240
39319
|
signal
|
|
39241
39320
|
);
|
|
39242
39321
|
return {
|
|
39243
39322
|
agentId: command.agentId,
|
|
39244
|
-
agentName:
|
|
39245
|
-
agentVersion:
|
|
39323
|
+
agentName: selectedSnapshot.agentName,
|
|
39324
|
+
agentVersion: selectedSnapshot.agentVersion,
|
|
39246
39325
|
kind: AGENT_SETTINGS_DISCOVERED_KIND,
|
|
39247
39326
|
modelEffort,
|
|
39248
39327
|
requestId: command.requestId,
|
|
39249
39328
|
settings,
|
|
39250
|
-
settingsRevision: settingsRevision(agent,
|
|
39329
|
+
settingsRevision: settingsRevision(agent, baseSnapshot.agentVersion, baseSettings, modelEffort)
|
|
39251
39330
|
};
|
|
39252
39331
|
}
|
|
39253
39332
|
function settingFromOption(option) {
|
|
@@ -39297,13 +39376,12 @@ function unavailableModelEffort() {
|
|
|
39297
39376
|
valuesByModel: {}
|
|
39298
39377
|
};
|
|
39299
39378
|
}
|
|
39300
|
-
async function discoverModelEffort(command, agent, resolution, initialOptions, cwd, sessions, signal) {
|
|
39379
|
+
async function discoverModelEffort(command, agent, resolution, initialOptions, selectedOptions, cwd, sessions, signal) {
|
|
39301
39380
|
const model = modelOption(initialOptions);
|
|
39302
|
-
const effort = effortOption(initialOptions);
|
|
39303
39381
|
if (resolution !== AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE && resolution !== AGENT_MODEL_EFFORT_RESOLUTION_ON_MODEL_SELECTION) {
|
|
39304
39382
|
return unavailableModelEffort();
|
|
39305
39383
|
}
|
|
39306
|
-
if (model === void 0 || model.type !== "select" || model.values.length === 0
|
|
39384
|
+
if (model === void 0 || model.type !== "select" || model.values.length === 0) {
|
|
39307
39385
|
return unavailableModelEffort();
|
|
39308
39386
|
}
|
|
39309
39387
|
const inspectModel = async (modelValue) => (await sessions.inspectAgentSettings({
|
|
@@ -39315,9 +39393,13 @@ async function discoverModelEffort(command, agent, resolution, initialOptions, c
|
|
|
39315
39393
|
})).configOptions;
|
|
39316
39394
|
const valuesByModel = {};
|
|
39317
39395
|
if (resolution === "complete") {
|
|
39396
|
+
const effort = effortOption(initialOptions);
|
|
39397
|
+
if (effort === void 0 || effort.type !== "select" || effort.values.length < 2) {
|
|
39398
|
+
return unavailableModelEffort();
|
|
39399
|
+
}
|
|
39318
39400
|
for (const value of model.values) {
|
|
39319
|
-
const
|
|
39320
|
-
valuesByModel[value.value] =
|
|
39401
|
+
const selectedEffort2 = effortOption(await inspectModel(value.value));
|
|
39402
|
+
valuesByModel[value.value] = selectedEffort2?.type === "select" ? selectedEffort2.values : [];
|
|
39321
39403
|
}
|
|
39322
39404
|
return {
|
|
39323
39405
|
effortSettingId: effort.id,
|
|
@@ -39330,18 +39412,24 @@ async function discoverModelEffort(command, agent, resolution, initialOptions, c
|
|
|
39330
39412
|
if (!model.values.some((value) => value.value === command.model)) {
|
|
39331
39413
|
throw new AcpExecutionError("The selected Agent model is unavailable", {}, "invalid_session_configuration");
|
|
39332
39414
|
}
|
|
39333
|
-
const
|
|
39334
|
-
valuesByModel[command.model] =
|
|
39415
|
+
const selectedEffort2 = effortOption(selectedOptions);
|
|
39416
|
+
valuesByModel[command.model] = selectedEffort2?.type === "select" ? selectedEffort2.values : [];
|
|
39335
39417
|
}
|
|
39418
|
+
const selectedEffort = effortOption(selectedOptions);
|
|
39336
39419
|
return {
|
|
39337
|
-
effortSettingId:
|
|
39420
|
+
effortSettingId: selectedEffort?.id ?? "",
|
|
39338
39421
|
modelSettingId: model.id,
|
|
39339
39422
|
resolution: "on_model_selection",
|
|
39340
39423
|
valuesByModel
|
|
39341
39424
|
};
|
|
39342
39425
|
}
|
|
39343
39426
|
function settingsRevision(agent, reportedAgentVersion, settings, modelEffort) {
|
|
39344
|
-
const revisionModelEffort = modelEffort.resolution === AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE ? modelEffort : {
|
|
39427
|
+
const revisionModelEffort = modelEffort.resolution === AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE ? modelEffort : {
|
|
39428
|
+
effortSettingId: "",
|
|
39429
|
+
modelSettingId: modelEffort.modelSettingId,
|
|
39430
|
+
resolution: modelEffort.resolution,
|
|
39431
|
+
valuesByModel: {}
|
|
39432
|
+
};
|
|
39345
39433
|
return createHash4("sha256").update(
|
|
39346
39434
|
JSON.stringify({
|
|
39347
39435
|
adapterVersion: agent.adapterVersion,
|
|
@@ -39524,6 +39612,24 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
39524
39612
|
const activities = new CoalescingDaemonActivityPublisher(timer, (activity) => {
|
|
39525
39613
|
publisher.recordAttempt(command.sessionId, encodeDaemonActivity(command, activity), attemptId);
|
|
39526
39614
|
});
|
|
39615
|
+
const text3 = new CoalescingTextPublisher(
|
|
39616
|
+
timer,
|
|
39617
|
+
(messageId, delta) => {
|
|
39618
|
+
publisher.recordAttempt(
|
|
39619
|
+
command.sessionId,
|
|
39620
|
+
encodeAgentMessageDeltaEvent({
|
|
39621
|
+
commandId: command.commandId,
|
|
39622
|
+
kind: AGENT_MESSAGE_DELTA_KIND,
|
|
39623
|
+
messageId,
|
|
39624
|
+
sessionId: command.sessionId,
|
|
39625
|
+
text: delta
|
|
39626
|
+
}),
|
|
39627
|
+
attemptId
|
|
39628
|
+
);
|
|
39629
|
+
},
|
|
39630
|
+
AGENT_TEXT_COALESCING_MILLISECONDS,
|
|
39631
|
+
AGENT_TEXT_MAXIMUM_LENGTH
|
|
39632
|
+
);
|
|
39527
39633
|
try {
|
|
39528
39634
|
const resolved = await resolveSessionDirectories(
|
|
39529
39635
|
directories,
|
|
@@ -39610,18 +39716,8 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
39610
39716
|
disposition: command.disposition,
|
|
39611
39717
|
images: attachments.images,
|
|
39612
39718
|
onActivity: activities.record,
|
|
39613
|
-
onText: (
|
|
39614
|
-
|
|
39615
|
-
command.sessionId,
|
|
39616
|
-
encodeAgentMessageDeltaEvent({
|
|
39617
|
-
commandId: command.commandId,
|
|
39618
|
-
kind: AGENT_MESSAGE_DELTA_KIND,
|
|
39619
|
-
messageId,
|
|
39620
|
-
sessionId: command.sessionId,
|
|
39621
|
-
text: text3
|
|
39622
|
-
}),
|
|
39623
|
-
attemptId
|
|
39624
|
-
);
|
|
39719
|
+
onText: (delta, messageId) => {
|
|
39720
|
+
text3.record(messageId, delta);
|
|
39625
39721
|
return Promise.resolve();
|
|
39626
39722
|
},
|
|
39627
39723
|
prompt: command.prompt,
|
|
@@ -39632,6 +39728,7 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
39632
39728
|
});
|
|
39633
39729
|
stopReason = result.stopReason;
|
|
39634
39730
|
}
|
|
39731
|
+
text3.flush();
|
|
39635
39732
|
activities.flush();
|
|
39636
39733
|
publisher.recordAttempt(
|
|
39637
39734
|
command.sessionId,
|
|
@@ -39650,6 +39747,7 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
39650
39747
|
sessionId: command.sessionId
|
|
39651
39748
|
});
|
|
39652
39749
|
} catch (error62) {
|
|
39750
|
+
text3.flush();
|
|
39653
39751
|
activities.flush();
|
|
39654
39752
|
audit.record({
|
|
39655
39753
|
commandId: command.commandId,
|
|
@@ -39713,17 +39811,6 @@ function assertSessionConfigurationSchema(options, selections) {
|
|
|
39713
39811
|
}
|
|
39714
39812
|
}
|
|
39715
39813
|
}
|
|
39716
|
-
function assertSessionConfigurationCoverage(options, selections) {
|
|
39717
|
-
const selectionsById = new Map(selections.map((selection) => [selection.configId, selection]));
|
|
39718
|
-
if (selectionsById.size !== selections.length) {
|
|
39719
|
-
throw invalidSessionConfiguration("The Turn configuration contains duplicate Agent settings");
|
|
39720
|
-
}
|
|
39721
|
-
for (const option of options) {
|
|
39722
|
-
if (!selectionsById.has(option.id)) {
|
|
39723
|
-
throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
|
|
39724
|
-
}
|
|
39725
|
-
}
|
|
39726
|
-
}
|
|
39727
39814
|
function sessionConfigurationSelectionIsAvailable(option, selection) {
|
|
39728
39815
|
if (option.type !== selection.valueType) {
|
|
39729
39816
|
return false;
|
|
@@ -39852,7 +39939,6 @@ async function applySessionConfigurationSelection(sessions, audit, options, sele
|
|
|
39852
39939
|
});
|
|
39853
39940
|
}
|
|
39854
39941
|
async function applyCompleteSessionConfiguration(sessions, audit, initialOptions, selections, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
|
|
39855
|
-
assertSessionConfigurationCoverage(initialOptions, selections);
|
|
39856
39942
|
let options = initialOptions;
|
|
39857
39943
|
const orderedSelections = selections.toSorted((left, right) => {
|
|
39858
39944
|
const priority = sessionConfigurationPriority(left, initialOptions) - sessionConfigurationPriority(right, initialOptions);
|
|
@@ -40216,6 +40302,10 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
40216
40302
|
signal.addEventListener("abort", stop, { once: true });
|
|
40217
40303
|
const handleClose = (event) => {
|
|
40218
40304
|
diagnostics.connectionClosed(connectionEpoch, event.code, event.reason, "relay");
|
|
40305
|
+
if (isRuntimeRelayRevocation(event.code, event.reason)) {
|
|
40306
|
+
rejectConnection(new RuntimeRelayRevokedError(event.code, event.reason));
|
|
40307
|
+
return;
|
|
40308
|
+
}
|
|
40219
40309
|
resolveConnection();
|
|
40220
40310
|
};
|
|
40221
40311
|
const handleError = (event) => {
|
|
@@ -40870,6 +40960,9 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
|
|
|
40870
40960
|
if (signal.aborted) {
|
|
40871
40961
|
return;
|
|
40872
40962
|
}
|
|
40963
|
+
if (error62 instanceof RuntimeRelayRevokedError) {
|
|
40964
|
+
throw error62;
|
|
40965
|
+
}
|
|
40873
40966
|
diagnostics.connectionFailed(connectionEpoch, error62, "connection");
|
|
40874
40967
|
}
|
|
40875
40968
|
await waitForRelayRetry(signal, timer);
|