@moxt-ai/mobius 0.0.154 → 0.0.155
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 +34 -317
- package/dist/cli.js.map +4 -4
- package/dist/daemon-turn-registry.d.ts +13 -13
- package/dist/index.js +33 -316
- package/dist/index.js.map +4 -4
- package/dist/relay-connection/run-relay-connection.d.ts.map +1 -1
- package/dist/relay-connection/run-relay-connection.js +2 -15
- package/dist/relay-connection/run-relay-connection.js.map +1 -1
- package/dist/relay-connection/session-event-publisher.d.ts +4 -9
- package/dist/relay-connection/session-event-publisher.d.ts.map +1 -1
- package/dist/relay-connection/session-event-publisher.js +26 -140
- package/dist/relay-connection/session-event-publisher.js.map +1 -1
- package/dist/run-daemon.js +1 -1
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.js +37 -320
- package/dist/runtime.js.map +4 -4
- package/package.json +1 -1
- package/dist/relay-connection/session-event-queue.d.ts +0 -14
- package/dist/relay-connection/session-event-queue.d.ts.map +0 -1
- package/dist/relay-connection/session-event-queue.js +0 -75
- package/dist/relay-connection/session-event-queue.js.map +0 -1
|
@@ -20,19 +20,6 @@ export declare class DaemonTurnRegistry {
|
|
|
20
20
|
epoch: string;
|
|
21
21
|
hasOlder: boolean;
|
|
22
22
|
interaction: Readonly<{
|
|
23
|
-
commandId: string;
|
|
24
|
-
interactionId: string;
|
|
25
|
-
kind: "session.permission.requested";
|
|
26
|
-
options: readonly Readonly<{
|
|
27
|
-
kind: "allow_always" | "allow_once" | "reject_always" | "reject_once";
|
|
28
|
-
name: string;
|
|
29
|
-
optionId: string;
|
|
30
|
-
}>[];
|
|
31
|
-
sessionId: string;
|
|
32
|
-
title: string;
|
|
33
|
-
toolCallId: string;
|
|
34
|
-
toolKind: string;
|
|
35
|
-
}> | Readonly<{
|
|
36
23
|
accepted: boolean;
|
|
37
24
|
commandId: string;
|
|
38
25
|
elicitationId: string;
|
|
@@ -64,6 +51,19 @@ export declare class DaemonTurnRegistry {
|
|
|
64
51
|
mode: "form" | "url";
|
|
65
52
|
sessionId: string;
|
|
66
53
|
url: string;
|
|
54
|
+
}> | Readonly<{
|
|
55
|
+
commandId: string;
|
|
56
|
+
interactionId: string;
|
|
57
|
+
kind: "session.permission.requested";
|
|
58
|
+
options: readonly Readonly<{
|
|
59
|
+
kind: "allow_always" | "allow_once" | "reject_always" | "reject_once";
|
|
60
|
+
name: string;
|
|
61
|
+
optionId: string;
|
|
62
|
+
}>[];
|
|
63
|
+
sessionId: string;
|
|
64
|
+
title: string;
|
|
65
|
+
toolCallId: string;
|
|
66
|
+
toolKind: string;
|
|
67
67
|
}> | null;
|
|
68
68
|
messages: readonly (Readonly<{
|
|
69
69
|
id: string;
|
package/dist/index.js
CHANGED
|
@@ -20767,16 +20767,8 @@ function decodeSessionQueuedEvent(encoded) {
|
|
|
20767
20767
|
function decodeRuntimeLivenessReadyEvent(encoded) {
|
|
20768
20768
|
const value = parseJson2(encoded);
|
|
20769
20769
|
assertKind(value, RUNTIME_LIVENESS_READY_KIND);
|
|
20770
|
-
|
|
20771
|
-
|
|
20772
|
-
return { kind: RUNTIME_LIVENESS_READY_KIND };
|
|
20773
|
-
}
|
|
20774
|
-
assertExactKeys(value, ["kind", "sessionEventDelivery"]);
|
|
20775
|
-
const sessionEventDelivery = readString(value, "sessionEventDelivery", 32);
|
|
20776
|
-
if (sessionEventDelivery !== "reliable-v1") {
|
|
20777
|
-
throw new ProtocolMessageError("Unsupported Session event delivery mode");
|
|
20778
|
-
}
|
|
20779
|
-
return { kind: RUNTIME_LIVENESS_READY_KIND, sessionEventDelivery };
|
|
20770
|
+
assertExactKeys(value, ["kind"]);
|
|
20771
|
+
return { kind: RUNTIME_LIVENESS_READY_KIND };
|
|
20780
20772
|
}
|
|
20781
20773
|
function decodeRuntimeHeartbeatEvent(encoded) {
|
|
20782
20774
|
const value = parseJson2(encoded);
|
|
@@ -21243,60 +21235,13 @@ var encodeNativeSessionCancel = (value) => JSON.stringify(nativeSessionCancelSch
|
|
|
21243
21235
|
|
|
21244
21236
|
// ../protocol/src/session-events.ts
|
|
21245
21237
|
var SESSION_EVENT_KIND = "session.event";
|
|
21246
|
-
var SESSION_EVENT_ACK_KIND = "session.event.ack";
|
|
21247
|
-
var SESSION_EVENT_DEFERRED_KIND = "session.event.deferred";
|
|
21248
|
-
var SESSION_EVENT_REJECTED_KIND = "session.event.rejected";
|
|
21249
21238
|
var SESSION_FORKED_KIND = "session.forked";
|
|
21250
|
-
var SessionEventRejectionCode = {
|
|
21251
|
-
IdempotencyConflict: "idempotency_conflict",
|
|
21252
|
-
InvalidEvent: "invalid_event",
|
|
21253
|
-
RecordingRejected: "recording_rejected"
|
|
21254
|
-
};
|
|
21255
21239
|
var MAX_RECORDED_EVENT_LENGTH = 8 * 1024 * 1024;
|
|
21256
|
-
var
|
|
21257
|
-
kind: external_exports.literal(SESSION_EVENT_KIND),
|
|
21258
|
-
payload: external_exports.string().min(2).max(MAX_RECORDED_EVENT_LENGTH),
|
|
21259
|
-
sessionId: identifierStringSchema
|
|
21260
|
-
}).readonly();
|
|
21261
|
-
var reliableDeliverySchema = external_exports.strictObject({
|
|
21262
|
-
eventId: identifierStringSchema,
|
|
21263
|
-
kind: external_exports.literal("reliable"),
|
|
21264
|
-
sourceSeq: external_exports.string().regex(/^(?:0|[1-9][0-9]*)$/u).max(40),
|
|
21265
|
-
streamId: identifierStringSchema
|
|
21266
|
-
}).readonly();
|
|
21267
|
-
var reliableSessionEventEnvelopeSchema = external_exports.strictObject({
|
|
21268
|
-
delivery: reliableDeliverySchema,
|
|
21240
|
+
var sessionEventEnvelopeSchema = external_exports.strictObject({
|
|
21269
21241
|
kind: external_exports.literal(SESSION_EVENT_KIND),
|
|
21270
21242
|
payload: external_exports.string().min(2).max(MAX_RECORDED_EVENT_LENGTH),
|
|
21271
21243
|
sessionId: identifierStringSchema
|
|
21272
21244
|
}).readonly();
|
|
21273
|
-
var eventEnvelopeSchema = external_exports.union([ephemeralEventEnvelopeSchema, reliableSessionEventEnvelopeSchema]).readonly();
|
|
21274
|
-
var acknowledgementOutcomeSchema = external_exports.discriminatedUnion("kind", [
|
|
21275
|
-
external_exports.strictObject({ kind: external_exports.literal("relayed") }).readonly(),
|
|
21276
|
-
external_exports.strictObject({
|
|
21277
|
-
kind: external_exports.literal("recorded"),
|
|
21278
|
-
providerId: identifierStringSchema,
|
|
21279
|
-
recordingEpoch: identifierStringSchema
|
|
21280
|
-
}).readonly()
|
|
21281
|
-
]);
|
|
21282
|
-
var eventAcknowledgementSchema = external_exports.strictObject({
|
|
21283
|
-
eventId: identifierStringSchema,
|
|
21284
|
-
kind: external_exports.literal(SESSION_EVENT_ACK_KIND),
|
|
21285
|
-
outcome: acknowledgementOutcomeSchema,
|
|
21286
|
-
sessionId: identifierStringSchema
|
|
21287
|
-
}).readonly();
|
|
21288
|
-
var eventDeferredSchema = external_exports.strictObject({
|
|
21289
|
-
eventId: identifierStringSchema,
|
|
21290
|
-
kind: external_exports.literal(SESSION_EVENT_DEFERRED_KIND),
|
|
21291
|
-
retryAfterMilliseconds: external_exports.number().int().min(100).max(6e4),
|
|
21292
|
-
sessionId: identifierStringSchema
|
|
21293
|
-
}).readonly();
|
|
21294
|
-
var eventRejectedSchema = external_exports.strictObject({
|
|
21295
|
-
code: external_exports.enum(SessionEventRejectionCode),
|
|
21296
|
-
eventId: identifierStringSchema,
|
|
21297
|
-
kind: external_exports.literal(SESSION_EVENT_REJECTED_KIND),
|
|
21298
|
-
sessionId: identifierStringSchema
|
|
21299
|
-
}).readonly();
|
|
21300
21245
|
var SESSION_QUEUE_CHANGED_KIND = "session.queue.changed";
|
|
21301
21246
|
var sessionQueueChangedSchema = external_exports.strictObject({ kind: external_exports.literal(SESSION_QUEUE_CHANGED_KIND), sessionId: identifierStringSchema }).readonly();
|
|
21302
21247
|
var sessionForkedSchema = external_exports.strictObject({
|
|
@@ -21329,14 +21274,8 @@ var encode4 = (message, schema) => {
|
|
|
21329
21274
|
}
|
|
21330
21275
|
return JSON.stringify(decoded.data);
|
|
21331
21276
|
};
|
|
21332
|
-
var decodeSessionEventEnvelope = (encoded) => decode5(encoded,
|
|
21333
|
-
var encodeSessionEventEnvelope = (message) => encode4(message,
|
|
21334
|
-
var decodeSessionEventAcknowledgement = (encoded) => decode5(encoded, eventAcknowledgementSchema);
|
|
21335
|
-
var encodeSessionEventAcknowledgement = (message) => encode4(message, eventAcknowledgementSchema);
|
|
21336
|
-
var decodeSessionEventDeferred = (encoded) => decode5(encoded, eventDeferredSchema);
|
|
21337
|
-
var encodeSessionEventDeferred = (message) => encode4(message, eventDeferredSchema);
|
|
21338
|
-
var decodeSessionEventRejected = (encoded) => decode5(encoded, eventRejectedSchema);
|
|
21339
|
-
var encodeSessionEventRejected = (message) => encode4(message, eventRejectedSchema);
|
|
21277
|
+
var decodeSessionEventEnvelope = (encoded) => decode5(encoded, sessionEventEnvelopeSchema);
|
|
21278
|
+
var encodeSessionEventEnvelope = (message) => encode4(message, sessionEventEnvelopeSchema);
|
|
21340
21279
|
function decodeRecordedSessionEvent(encoded) {
|
|
21341
21280
|
const kind = decodeMessageKind(encoded);
|
|
21342
21281
|
switch (kind) {
|
|
@@ -21510,21 +21449,6 @@ var serviceToDaemonSignatures = {
|
|
|
21510
21449
|
encodeSessionElicitationRespondCommand,
|
|
21511
21450
|
decodeSessionElicitationRespondCommand
|
|
21512
21451
|
),
|
|
21513
|
-
[SESSION_EVENT_ACK_KIND]: defineMessageSignature(
|
|
21514
|
-
SESSION_EVENT_ACK_KIND,
|
|
21515
|
-
encodeSessionEventAcknowledgement,
|
|
21516
|
-
decodeSessionEventAcknowledgement
|
|
21517
|
-
),
|
|
21518
|
-
[SESSION_EVENT_DEFERRED_KIND]: defineMessageSignature(
|
|
21519
|
-
SESSION_EVENT_DEFERRED_KIND,
|
|
21520
|
-
encodeSessionEventDeferred,
|
|
21521
|
-
decodeSessionEventDeferred
|
|
21522
|
-
),
|
|
21523
|
-
[SESSION_EVENT_REJECTED_KIND]: defineMessageSignature(
|
|
21524
|
-
SESSION_EVENT_REJECTED_KIND,
|
|
21525
|
-
encodeSessionEventRejected,
|
|
21526
|
-
decodeSessionEventRejected
|
|
21527
|
-
),
|
|
21528
21452
|
[SESSION_LIVE_HISTORY_LOAD_KIND]: defineMessageSignature(
|
|
21529
21453
|
SESSION_LIVE_HISTORY_LOAD_KIND,
|
|
21530
21454
|
encodeSessionLiveHistoryLoad,
|
|
@@ -37660,7 +37584,7 @@ function isRuntimeRelayRevocation(closeCode, closeReason) {
|
|
|
37660
37584
|
}
|
|
37661
37585
|
|
|
37662
37586
|
// src/run-daemon.ts
|
|
37663
|
-
import { createHash as createHash6, randomUUID as
|
|
37587
|
+
import { createHash as createHash6, randomUUID as randomUUID7 } from "node:crypto";
|
|
37664
37588
|
import { join as join18 } from "node:path";
|
|
37665
37589
|
import { styleText } from "node:util";
|
|
37666
37590
|
|
|
@@ -43337,7 +43261,6 @@ async function runRelayConnection({
|
|
|
43337
43261
|
}) {
|
|
43338
43262
|
const relayUrl = new URL(config2.relayUrl);
|
|
43339
43263
|
relayUrl.searchParams.set("liveness", "1");
|
|
43340
|
-
relayUrl.searchParams.set("sessionEventDelivery", "reliable-v1");
|
|
43341
43264
|
const socket = await connectRelay(relayUrl, signal);
|
|
43342
43265
|
diagnostics.connectionOpened(connectionEpoch);
|
|
43343
43266
|
const connectionController = new AbortController();
|
|
@@ -43457,10 +43380,7 @@ async function runRelayConnection({
|
|
|
43457
43380
|
const message = decodeServiceToDaemonMessage(encoded);
|
|
43458
43381
|
const kind = message.kind;
|
|
43459
43382
|
if (kind === RUNTIME_LIVENESS_READY_KIND) {
|
|
43460
|
-
publisher.connect(
|
|
43461
|
-
socket,
|
|
43462
|
-
message.sessionEventDelivery === "reliable-v1" ? "reliable" : "ephemeral"
|
|
43463
|
-
);
|
|
43383
|
+
publisher.connect(socket);
|
|
43464
43384
|
connectionLiveness.start();
|
|
43465
43385
|
return;
|
|
43466
43386
|
}
|
|
@@ -43468,18 +43388,6 @@ async function runRelayConnection({
|
|
|
43468
43388
|
connectionLiveness.acknowledge(message);
|
|
43469
43389
|
return;
|
|
43470
43390
|
}
|
|
43471
|
-
if (kind === SESSION_EVENT_ACK_KIND) {
|
|
43472
|
-
publisher.acknowledge(message);
|
|
43473
|
-
return;
|
|
43474
|
-
}
|
|
43475
|
-
if (kind === SESSION_EVENT_DEFERRED_KIND) {
|
|
43476
|
-
publisher.defer(message);
|
|
43477
|
-
return;
|
|
43478
|
-
}
|
|
43479
|
-
if (kind === SESSION_EVENT_REJECTED_KIND) {
|
|
43480
|
-
publisher.reject(message);
|
|
43481
|
-
return;
|
|
43482
|
-
}
|
|
43483
43391
|
commands.handle(message);
|
|
43484
43392
|
} catch (error62) {
|
|
43485
43393
|
console.error("Mobius daemon rejected a message", error62);
|
|
@@ -43506,233 +43414,42 @@ async function runRelayConnection({
|
|
|
43506
43414
|
|
|
43507
43415
|
// src/relay-connection/session-event-publisher.ts
|
|
43508
43416
|
import { WebSocket as WebSocket9 } from "undici";
|
|
43509
|
-
|
|
43510
|
-
// src/relay-connection/session-event-queue.ts
|
|
43511
|
-
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
43512
|
-
var STANDARD_EVENT_BYTES = 96 * 1024 * 1024;
|
|
43513
|
-
var CRITICAL_EVENT_BYTES = 128 * 1024 * 1024;
|
|
43514
|
-
var SessionEventQueueCapacityError = class extends Error {
|
|
43515
|
-
code = "session_event_queue_full";
|
|
43516
|
-
constructor() {
|
|
43517
|
-
super("The in-memory Session event queue is full");
|
|
43518
|
-
this.name = "SessionEventQueueCapacityError";
|
|
43519
|
-
}
|
|
43520
|
-
};
|
|
43521
|
-
var SessionEventQueue = class {
|
|
43522
|
-
#streamId = randomUUID7();
|
|
43523
|
-
#events = /* @__PURE__ */ new Map();
|
|
43524
|
-
#nextSourceSeq = 1;
|
|
43525
|
-
#totalBytes = 0;
|
|
43526
|
-
enqueueBatch = (sessionId, payloads, critical) => {
|
|
43527
|
-
if (payloads.length < 1 || payloads.length > 32) {
|
|
43528
|
-
throw new Error("A Session event batch must contain between 1 and 32 events");
|
|
43529
|
-
}
|
|
43530
|
-
if (!Number.isSafeInteger(this.#nextSourceSeq + payloads.length)) {
|
|
43531
|
-
throw new Error("The Session event source sequence is exhausted");
|
|
43532
|
-
}
|
|
43533
|
-
const entries = payloads.map((payload, index) => {
|
|
43534
|
-
const envelope2 = {
|
|
43535
|
-
delivery: {
|
|
43536
|
-
eventId: randomUUID7(),
|
|
43537
|
-
kind: "reliable",
|
|
43538
|
-
sourceSeq: (this.#nextSourceSeq + index).toString(),
|
|
43539
|
-
streamId: this.#streamId
|
|
43540
|
-
},
|
|
43541
|
-
kind: SESSION_EVENT_KIND,
|
|
43542
|
-
payload,
|
|
43543
|
-
sessionId
|
|
43544
|
-
};
|
|
43545
|
-
return { envelope: envelope2, byteLength: Buffer.byteLength(encodeSessionEventEnvelope(envelope2), "utf8") };
|
|
43546
|
-
});
|
|
43547
|
-
const byteLength = entries.reduce((total, entry) => total + entry.byteLength, 0);
|
|
43548
|
-
if (this.#totalBytes + byteLength > (critical ? CRITICAL_EVENT_BYTES : STANDARD_EVENT_BYTES)) {
|
|
43549
|
-
throw new SessionEventQueueCapacityError();
|
|
43550
|
-
}
|
|
43551
|
-
for (const entry of entries) {
|
|
43552
|
-
this.#events.set(entry.envelope.delivery.eventId, entry);
|
|
43553
|
-
}
|
|
43554
|
-
this.#nextSourceSeq += entries.length;
|
|
43555
|
-
this.#totalBytes += byteLength;
|
|
43556
|
-
};
|
|
43557
|
-
pending = (limit, excludedEventIds) => {
|
|
43558
|
-
const result = [];
|
|
43559
|
-
for (const [eventId, entry] of this.#events) {
|
|
43560
|
-
if (!excludedEventIds.has(eventId)) {
|
|
43561
|
-
result.push(entry.envelope);
|
|
43562
|
-
if (result.length === limit) {
|
|
43563
|
-
break;
|
|
43564
|
-
}
|
|
43565
|
-
}
|
|
43566
|
-
}
|
|
43567
|
-
return result;
|
|
43568
|
-
};
|
|
43569
|
-
remove = (eventId, sessionId) => {
|
|
43570
|
-
const entry = this.#events.get(eventId);
|
|
43571
|
-
if (entry === void 0 || entry.envelope.sessionId !== sessionId) {
|
|
43572
|
-
return false;
|
|
43573
|
-
}
|
|
43574
|
-
this.#events.delete(eventId);
|
|
43575
|
-
this.#totalBytes -= entry.byteLength;
|
|
43576
|
-
return true;
|
|
43577
|
-
};
|
|
43578
|
-
clear = () => {
|
|
43579
|
-
this.#events.clear();
|
|
43580
|
-
this.#totalBytes = 0;
|
|
43581
|
-
};
|
|
43582
|
-
};
|
|
43583
|
-
|
|
43584
|
-
// src/relay-connection/session-event-publisher.ts
|
|
43585
|
-
var SESSION_EVENT_REPLAY_WINDOW = 16;
|
|
43586
|
-
var SESSION_EVENT_REPLAY_BYTE_LIMIT = 32 * 1024 * 1024;
|
|
43587
|
-
function reservesSessionEventCapacity(event) {
|
|
43588
|
-
if (event.kind === SESSION_COMPLETED_KIND || event.kind === SESSION_FAILED_KIND || event.kind === SESSION_FORKED_KIND || event.kind === SESSION_READY_KIND) {
|
|
43589
|
-
return true;
|
|
43590
|
-
}
|
|
43591
|
-
return event.kind === AGENT_ACTIVITY_KIND && (event.activityType === "progress" || event.activityType === "reasoning") && (event.status === "completed" || event.status === "failed");
|
|
43592
|
-
}
|
|
43417
|
+
var MAX_BUFFERED_BYTES = 32 * 1024 * 1024;
|
|
43593
43418
|
var DaemonSessionEventPublisher = class {
|
|
43594
|
-
#
|
|
43595
|
-
|
|
43596
|
-
|
|
43597
|
-
#timer;
|
|
43598
|
-
#connection = { kind: "disconnected" };
|
|
43599
|
-
#deferredReplay = null;
|
|
43600
|
-
#inFlightBytes = 0;
|
|
43601
|
-
constructor(timer) {
|
|
43602
|
-
this.#timer = timer;
|
|
43603
|
-
}
|
|
43604
|
-
acknowledge = (acknowledgement) => {
|
|
43605
|
-
if (!this.#queue.remove(acknowledgement.eventId, acknowledgement.sessionId)) {
|
|
43606
|
-
return;
|
|
43607
|
-
}
|
|
43608
|
-
this.#removeInFlight(acknowledgement.eventId);
|
|
43609
|
-
this.#publishNextBatch();
|
|
43610
|
-
};
|
|
43611
|
-
close = () => {
|
|
43612
|
-
this.#deferredReplay?.cancel();
|
|
43613
|
-
this.#deferredReplay = null;
|
|
43614
|
-
this.#connection = { kind: "disconnected" };
|
|
43615
|
-
this.#clearInFlight();
|
|
43616
|
-
this.#queue.clear();
|
|
43617
|
-
};
|
|
43618
|
-
connect = (socket, delivery) => {
|
|
43619
|
-
this.#connection = { delivery, kind: "connected", socket };
|
|
43620
|
-
this.#clearInFlight();
|
|
43621
|
-
this.#publishNextBatch();
|
|
43622
|
-
};
|
|
43623
|
-
defer = (deferred) => {
|
|
43624
|
-
if (!this.#inFlight.has(deferred.eventId)) {
|
|
43625
|
-
return;
|
|
43626
|
-
}
|
|
43627
|
-
this.#clearInFlight();
|
|
43628
|
-
if (this.#deferredReplay !== null) {
|
|
43629
|
-
return;
|
|
43630
|
-
}
|
|
43631
|
-
this.#deferredReplay = this.#timer.schedule(() => {
|
|
43632
|
-
this.#deferredReplay = null;
|
|
43633
|
-
this.#publishNextBatch();
|
|
43634
|
-
}, deferred.retryAfterMilliseconds);
|
|
43419
|
+
#socket = null;
|
|
43420
|
+
connect = (socket) => {
|
|
43421
|
+
this.#socket = socket;
|
|
43635
43422
|
};
|
|
43636
43423
|
disconnect = (socket) => {
|
|
43637
|
-
if (this.#
|
|
43638
|
-
|
|
43639
|
-
}
|
|
43640
|
-
this.#connection = { kind: "disconnected" };
|
|
43641
|
-
this.#clearInFlight();
|
|
43642
|
-
};
|
|
43643
|
-
publish = (sessionId, event) => {
|
|
43644
|
-
try {
|
|
43645
|
-
this.#queue.enqueueBatch(
|
|
43646
|
-
sessionId,
|
|
43647
|
-
[encodeRecordedSessionEvent(event)],
|
|
43648
|
-
reservesSessionEventCapacity(event)
|
|
43649
|
-
);
|
|
43650
|
-
} catch (error62) {
|
|
43651
|
-
if (!(error62 instanceof SessionEventQueueCapacityError)) {
|
|
43652
|
-
throw error62;
|
|
43653
|
-
}
|
|
43654
|
-
if (!this.#reportedCapacityKinds.has(event.kind)) {
|
|
43655
|
-
this.#reportedCapacityKinds.add(event.kind);
|
|
43656
|
-
console.warn(`Mobius daemon could not buffer "${event.kind}" because the Session event queue is full`);
|
|
43657
|
-
}
|
|
43658
|
-
return;
|
|
43659
|
-
}
|
|
43660
|
-
this.#publishNextBatch();
|
|
43661
|
-
};
|
|
43662
|
-
publishBatch = (sessionId, events) => {
|
|
43663
|
-
const critical = events.some(reservesSessionEventCapacity);
|
|
43664
|
-
this.#queue.enqueueBatch(sessionId, events.map(encodeRecordedSessionEvent), critical);
|
|
43665
|
-
this.#publishNextBatch();
|
|
43666
|
-
};
|
|
43667
|
-
reject = (rejection) => {
|
|
43668
|
-
if (!this.#queue.remove(rejection.eventId, rejection.sessionId)) {
|
|
43669
|
-
return;
|
|
43424
|
+
if (this.#socket === socket) {
|
|
43425
|
+
this.#socket = null;
|
|
43670
43426
|
}
|
|
43671
|
-
this.#removeInFlight(rejection.eventId);
|
|
43672
|
-
console.error(`Mobius Relay rejected Session event ${rejection.eventId} with code ${rejection.code}`);
|
|
43673
|
-
this.#publishNextBatch();
|
|
43674
43427
|
};
|
|
43675
|
-
|
|
43676
|
-
this.#
|
|
43677
|
-
this.#inFlightBytes = 0;
|
|
43428
|
+
close = () => {
|
|
43429
|
+
this.#socket = null;
|
|
43678
43430
|
};
|
|
43679
|
-
|
|
43680
|
-
|
|
43431
|
+
publish = (sessionId, event) => {
|
|
43432
|
+
const socket = this.#socket;
|
|
43433
|
+
if (socket === null || socket.readyState !== WebSocket9.OPEN) {
|
|
43681
43434
|
return;
|
|
43682
43435
|
}
|
|
43683
|
-
|
|
43684
|
-
|
|
43685
|
-
|
|
43686
|
-
|
|
43687
|
-
|
|
43688
|
-
|
|
43689
|
-
|
|
43690
|
-
const encoded = encodeDaemonToServiceMessage(
|
|
43691
|
-
this.#connection.delivery === "reliable" ? envelope2 : {
|
|
43692
|
-
kind: envelope2.kind,
|
|
43693
|
-
payload: envelope2.payload,
|
|
43694
|
-
sessionId: envelope2.sessionId
|
|
43695
|
-
}
|
|
43696
|
-
);
|
|
43697
|
-
const byteLength = Buffer.byteLength(encoded, "utf8");
|
|
43698
|
-
if (this.#inFlightBytes + byteLength > SESSION_EVENT_REPLAY_BYTE_LIMIT) {
|
|
43699
|
-
return;
|
|
43700
|
-
}
|
|
43701
|
-
if (!this.#send(encoded)) {
|
|
43702
|
-
this.#clearInFlight();
|
|
43703
|
-
return;
|
|
43704
|
-
}
|
|
43705
|
-
if (this.#connection.delivery === "ephemeral") {
|
|
43706
|
-
this.#queue.remove(envelope2.delivery.eventId, envelope2.sessionId);
|
|
43707
|
-
sent += 1;
|
|
43708
|
-
continue;
|
|
43709
|
-
}
|
|
43710
|
-
this.#inFlight.set(envelope2.delivery.eventId, { byteLength });
|
|
43711
|
-
this.#inFlightBytes += byteLength;
|
|
43712
|
-
sent += 1;
|
|
43713
|
-
}
|
|
43714
|
-
if (sent === 0) {
|
|
43715
|
-
return;
|
|
43716
|
-
}
|
|
43717
|
-
}
|
|
43718
|
-
};
|
|
43719
|
-
#removeInFlight = (eventId) => {
|
|
43720
|
-
const inFlight = this.#inFlight.get(eventId);
|
|
43721
|
-
if (inFlight === void 0) {
|
|
43436
|
+
const encoded = encodeDaemonToServiceMessage({
|
|
43437
|
+
kind: SESSION_EVENT_KIND,
|
|
43438
|
+
payload: encodeRecordedSessionEvent(event),
|
|
43439
|
+
sessionId
|
|
43440
|
+
});
|
|
43441
|
+
if (socket.bufferedAmount + Buffer.byteLength(encoded, "utf8") > MAX_BUFFERED_BYTES) {
|
|
43442
|
+
socket.close(1013, "Live event transport overloaded");
|
|
43722
43443
|
return;
|
|
43723
43444
|
}
|
|
43724
|
-
this.#inFlight.delete(eventId);
|
|
43725
|
-
this.#inFlightBytes -= inFlight.byteLength;
|
|
43726
|
-
};
|
|
43727
|
-
#send = (encoded) => {
|
|
43728
|
-
if (this.#connection.kind !== "connected" || this.#connection.socket.readyState !== WebSocket9.OPEN) {
|
|
43729
|
-
return false;
|
|
43730
|
-
}
|
|
43731
43445
|
try {
|
|
43732
|
-
|
|
43733
|
-
return true;
|
|
43446
|
+
socket.send(encoded);
|
|
43734
43447
|
} catch {
|
|
43735
|
-
|
|
43448
|
+
}
|
|
43449
|
+
};
|
|
43450
|
+
publishBatch = (sessionId, events) => {
|
|
43451
|
+
for (const event of events) {
|
|
43452
|
+
this.publish(sessionId, event);
|
|
43736
43453
|
}
|
|
43737
43454
|
};
|
|
43738
43455
|
};
|
|
@@ -43794,7 +43511,7 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
|
|
|
43794
43511
|
{
|
|
43795
43512
|
agentId: agent.id,
|
|
43796
43513
|
kind: AGENT_INSTALL_REQUEST_KIND,
|
|
43797
|
-
requestId: `automatic-integration-${
|
|
43514
|
+
requestId: `automatic-integration-${randomUUID7()}`
|
|
43798
43515
|
},
|
|
43799
43516
|
signal
|
|
43800
43517
|
);
|
|
@@ -43816,7 +43533,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
43816
43533
|
join18(stateDirectory, "sessions", `${createHash6("sha256").update(config2.channelId).digest("hex")}.sqlite`)
|
|
43817
43534
|
);
|
|
43818
43535
|
const operations = new DaemonOperationState();
|
|
43819
|
-
const publisher = new DaemonSessionEventPublisher(
|
|
43536
|
+
const publisher = new DaemonSessionEventPublisher();
|
|
43820
43537
|
const activeTurns = new DaemonTurnRegistry(operations);
|
|
43821
43538
|
const recordSessionEvent = (sessionId, event) => {
|
|
43822
43539
|
publisher.publish(sessionId, activeTurns.recordEvent(event));
|