@moxt-ai/mobius 0.0.295 → 0.0.296
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 +72 -40
- package/dist/cli.js.map +3 -3
- package/dist/runtime/relay/session-event-publisher.d.ts +2 -2
- package/dist/runtime/relay/session-event-publisher.d.ts.map +1 -1
- package/dist/runtime/relay/session-event-publisher.js +79 -42
- package/dist/runtime/relay/session-event-publisher.js.map +1 -1
- package/dist/runtime.js +72 -40
- package/dist/runtime.js.map +3 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -5398,7 +5398,7 @@ var program = new Command();
|
|
|
5398
5398
|
// package.json
|
|
5399
5399
|
var package_default = {
|
|
5400
5400
|
name: "@moxt-ai/mobius",
|
|
5401
|
-
version: "0.0.
|
|
5401
|
+
version: "0.0.296",
|
|
5402
5402
|
description: "Mobius CLI for pairing and running local AI agent services.",
|
|
5403
5403
|
type: "module",
|
|
5404
5404
|
bin: {
|
|
@@ -96846,37 +96846,44 @@ async function runRelayConnection({
|
|
|
96846
96846
|
// src/runtime/relay/session-event-publisher.ts
|
|
96847
96847
|
import { WebSocket as WebSocket8 } from "undici";
|
|
96848
96848
|
var MAX_BUFFERED_BYTES = 32 * 1024 * 1024;
|
|
96849
|
+
var MAX_PENDING_BYTES2 = 32 * 1024 * 1024;
|
|
96849
96850
|
var MAX_EVENT_BATCH_BYTES = 1024 * 1024;
|
|
96850
96851
|
var MAX_FRAME_BYTES = 8 * 1024 * 1024;
|
|
96851
96852
|
var LOCAL_BACKPRESSURE_CLOSE_CODE = 4009;
|
|
96852
96853
|
var EMPTY_ENVELOPE_BYTES = Buffer.byteLength(JSON.stringify({ events: [], kind: SESSION_EVENT_KIND }));
|
|
96853
96854
|
var SESSION_EVENT_BATCH_WINDOW_MILLISECONDS = 100;
|
|
96854
96855
|
var RuntimeSessionEventPublisher = class {
|
|
96855
|
-
#
|
|
96856
|
-
#pendingBytes =
|
|
96856
|
+
#pending = [];
|
|
96857
|
+
#pendingBytes = 0;
|
|
96858
|
+
#overflowReported = false;
|
|
96857
96859
|
#pendingTask = null;
|
|
96858
|
-
#
|
|
96860
|
+
#connection = { kind: "disconnected" };
|
|
96859
96861
|
#timer;
|
|
96860
96862
|
constructor(timer) {
|
|
96861
96863
|
this.#timer = timer;
|
|
96862
96864
|
}
|
|
96863
96865
|
connect = (socket) => {
|
|
96864
|
-
this.
|
|
96865
|
-
|
|
96866
|
+
if (this.#connection.kind === "closed") {
|
|
96867
|
+
return;
|
|
96868
|
+
}
|
|
96869
|
+
this.#connection = { kind: "connected", socket };
|
|
96870
|
+
this.flushEvents(socket);
|
|
96866
96871
|
};
|
|
96867
96872
|
disconnect = (socket) => {
|
|
96868
|
-
if (this.#socket === socket) {
|
|
96869
|
-
this.#
|
|
96870
|
-
this.
|
|
96873
|
+
if (this.#connection.kind === "connected" && this.#connection.socket === socket) {
|
|
96874
|
+
this.#connection = { kind: "disconnected" };
|
|
96875
|
+
this.cancelFlush();
|
|
96871
96876
|
}
|
|
96872
96877
|
};
|
|
96873
96878
|
close = () => {
|
|
96874
|
-
this.#
|
|
96875
|
-
this.
|
|
96879
|
+
this.#connection = { kind: "closed" };
|
|
96880
|
+
this.cancelFlush();
|
|
96881
|
+
this.#pending.length = 0;
|
|
96882
|
+
this.#pendingBytes = 0;
|
|
96876
96883
|
};
|
|
96877
96884
|
flush = () => {
|
|
96878
|
-
if (this.#
|
|
96879
|
-
this.flushEvents(this.#socket);
|
|
96885
|
+
if (this.#connection.kind === "connected") {
|
|
96886
|
+
this.flushEvents(this.#connection.socket);
|
|
96880
96887
|
}
|
|
96881
96888
|
};
|
|
96882
96889
|
publishOperationFailure = (sessionId, requestId, code, message) => {
|
|
@@ -96886,10 +96893,11 @@ var RuntimeSessionEventPublisher = class {
|
|
|
96886
96893
|
publishInfo = (event) => this.#send(event);
|
|
96887
96894
|
publishClosed = (event) => this.#send(event);
|
|
96888
96895
|
#send = (message) => {
|
|
96889
|
-
const
|
|
96890
|
-
if (
|
|
96896
|
+
const connection = this.#connection;
|
|
96897
|
+
if (connection.kind !== "connected" || connection.socket.readyState !== WebSocket8.OPEN) {
|
|
96891
96898
|
return;
|
|
96892
96899
|
}
|
|
96900
|
+
const socket = connection.socket;
|
|
96893
96901
|
const encoded = encodeDaemonToServiceMessage(message);
|
|
96894
96902
|
if (socket.bufferedAmount + Buffer.byteLength(encoded, "utf8") > MAX_BUFFERED_BYTES) {
|
|
96895
96903
|
socket.close(LOCAL_BACKPRESSURE_CLOSE_CODE, "Live event transport overloaded");
|
|
@@ -96901,8 +96909,7 @@ var RuntimeSessionEventPublisher = class {
|
|
|
96901
96909
|
}
|
|
96902
96910
|
};
|
|
96903
96911
|
publish = (event) => {
|
|
96904
|
-
|
|
96905
|
-
if (socket === null || socket.readyState !== WebSocket8.OPEN) {
|
|
96912
|
+
if (this.#connection.kind === "closed") {
|
|
96906
96913
|
return;
|
|
96907
96914
|
}
|
|
96908
96915
|
const bytes = Buffer.byteLength(JSON.stringify(event), "utf8") + 1;
|
|
@@ -96915,15 +96922,34 @@ var RuntimeSessionEventPublisher = class {
|
|
|
96915
96922
|
});
|
|
96916
96923
|
return;
|
|
96917
96924
|
}
|
|
96918
|
-
|
|
96919
|
-
|
|
96920
|
-
|
|
96921
|
-
|
|
96925
|
+
let batch = this.#pending.at(-1);
|
|
96926
|
+
const newBatch = batch === void 0 || batch.events.length >= SESSION_EVENT_BATCH_MAX_SIZE || batch.bytes + bytes > MAX_EVENT_BATCH_BYTES;
|
|
96927
|
+
const additionalBytes = bytes + (newBatch ? EMPTY_ENVELOPE_BYTES : 0);
|
|
96928
|
+
if (this.#pendingBytes + additionalBytes > MAX_PENDING_BYTES2) {
|
|
96929
|
+
if (!this.#overflowReported) {
|
|
96930
|
+
this.#overflowReported = true;
|
|
96931
|
+
console.warn("Live Session output exceeded the pending buffer limit", {
|
|
96932
|
+
code: "live_event_buffer_full",
|
|
96933
|
+
sessionId: event.sessionId,
|
|
96934
|
+
eventId: event.eventId,
|
|
96935
|
+
maximumBytes: MAX_PENDING_BYTES2
|
|
96936
|
+
});
|
|
96922
96937
|
}
|
|
96938
|
+
return;
|
|
96923
96939
|
}
|
|
96924
|
-
|
|
96925
|
-
|
|
96926
|
-
|
|
96940
|
+
if (batch === void 0 || newBatch) {
|
|
96941
|
+
batch = { events: [], bytes: EMPTY_ENVELOPE_BYTES };
|
|
96942
|
+
this.#pending.push(batch);
|
|
96943
|
+
}
|
|
96944
|
+
batch.events.push(event);
|
|
96945
|
+
batch.bytes += bytes;
|
|
96946
|
+
this.#pendingBytes += additionalBytes;
|
|
96947
|
+
const connection = this.#connection;
|
|
96948
|
+
if (connection.kind !== "connected" || connection.socket.readyState !== WebSocket8.OPEN) {
|
|
96949
|
+
return;
|
|
96950
|
+
}
|
|
96951
|
+
const socket = connection.socket;
|
|
96952
|
+
if (this.#pending.length > 1 || batch.events.length >= SESSION_EVENT_BATCH_MAX_SIZE || batch.bytes >= MAX_EVENT_BATCH_BYTES) {
|
|
96927
96953
|
this.flushEvents(socket);
|
|
96928
96954
|
return;
|
|
96929
96955
|
}
|
|
@@ -96932,29 +96958,35 @@ var RuntimeSessionEventPublisher = class {
|
|
|
96932
96958
|
SESSION_EVENT_BATCH_WINDOW_MILLISECONDS
|
|
96933
96959
|
);
|
|
96934
96960
|
};
|
|
96935
|
-
|
|
96961
|
+
cancelFlush = () => {
|
|
96936
96962
|
this.#pendingTask?.cancel();
|
|
96937
96963
|
this.#pendingTask = null;
|
|
96938
|
-
this.#pendingEvents = [];
|
|
96939
|
-
this.#pendingBytes = EMPTY_ENVELOPE_BYTES;
|
|
96940
96964
|
};
|
|
96941
96965
|
flushEvents = (socket) => {
|
|
96942
|
-
this
|
|
96943
|
-
|
|
96944
|
-
|
|
96945
|
-
this.#pendingEvents = [];
|
|
96946
|
-
this.#pendingBytes = EMPTY_ENVELOPE_BYTES;
|
|
96947
|
-
if (events.length === 0 || this.#socket !== socket || socket.readyState !== WebSocket8.OPEN) {
|
|
96966
|
+
this.cancelFlush();
|
|
96967
|
+
const connection = this.#connection;
|
|
96968
|
+
if (connection.kind !== "connected" || connection.socket !== socket || socket.readyState !== WebSocket8.OPEN) {
|
|
96948
96969
|
return;
|
|
96949
96970
|
}
|
|
96950
|
-
|
|
96951
|
-
|
|
96952
|
-
|
|
96953
|
-
|
|
96971
|
+
let attempted = 0;
|
|
96972
|
+
for (const batch of this.#pending) {
|
|
96973
|
+
const encoded = encodeDaemonToServiceMessage({ events: batch.events, kind: SESSION_EVENT_KIND });
|
|
96974
|
+
if (socket.bufferedAmount + Buffer.byteLength(encoded, "utf8") > MAX_BUFFERED_BYTES) {
|
|
96975
|
+
socket.close(LOCAL_BACKPRESSURE_CLOSE_CODE, "Live event transport overloaded");
|
|
96976
|
+
break;
|
|
96977
|
+
}
|
|
96978
|
+
attempted += 1;
|
|
96979
|
+
this.#pendingBytes -= batch.bytes;
|
|
96980
|
+
try {
|
|
96981
|
+
socket.send(encoded);
|
|
96982
|
+
} catch {
|
|
96983
|
+
console.warn("Live Session output could not be sent", { code: "live_event_send_failed" });
|
|
96984
|
+
break;
|
|
96985
|
+
}
|
|
96954
96986
|
}
|
|
96955
|
-
|
|
96956
|
-
|
|
96957
|
-
|
|
96987
|
+
this.#pending.splice(0, attempted);
|
|
96988
|
+
if (this.#pending.length === 0) {
|
|
96989
|
+
this.#overflowReported = false;
|
|
96958
96990
|
}
|
|
96959
96991
|
};
|
|
96960
96992
|
};
|