@moxt-ai/mobius 0.0.460 → 0.0.462
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/{chunk-APGZM3B3.js → chunk-2KU5227F.js} +449 -57
- package/dist/{chunk-APGZM3B3.js.map → chunk-2KU5227F.js.map} +3 -3
- package/dist/{chunk-WOA2UFZO.js → chunk-O56TVV5C.js} +2 -2
- package/dist/{chunk-WOA2UFZO.js.map → chunk-O56TVV5C.js.map} +1 -1
- package/dist/{cli-AYXN6EC5.js → cli-4SSU3XE7.js} +3 -3
- package/dist/cli.js +2 -2
- package/dist/engine/acp/adapter/antigravity/adapter.d.ts.map +1 -1
- package/dist/engine/acp/adapter/antigravity/adapter.js +14 -0
- package/dist/engine/acp/adapter/antigravity/adapter.js.map +1 -1
- package/dist/engine/acp/harness/antigravity/usage-quota.d.ts +1 -0
- package/dist/engine/acp/harness/antigravity/usage-quota.d.ts.map +1 -1
- package/dist/engine/acp/harness/antigravity/usage-quota.js +74 -13
- package/dist/engine/acp/harness/antigravity/usage-quota.js.map +1 -1
- package/dist/engine/runtime/relay/run-relay-connection.d.ts.map +1 -1
- package/dist/engine/runtime/relay/run-relay-connection.js +6 -2
- package/dist/engine/runtime/relay/run-relay-connection.js.map +1 -1
- package/dist/engine/runtime/relay/session-event-publisher.d.ts +15 -3
- package/dist/engine/runtime/relay/session-event-publisher.d.ts.map +1 -1
- package/dist/engine/runtime/relay/session-event-publisher.js +327 -47
- package/dist/engine/runtime/relay/session-event-publisher.js.map +1 -1
- package/dist/engine/storage/antigravity-usage-credentials.d.ts +1 -1
- package/dist/engine/storage/antigravity-usage-credentials.d.ts.map +1 -1
- package/dist/engine/storage/antigravity-usage-credentials.js +2 -2
- package/dist/engine/storage/antigravity-usage-credentials.js.map +1 -1
- package/dist/engine.js +2 -2
- package/package.json +2 -2
- /package/dist/{cli-AYXN6EC5.js.map → cli-4SSU3XE7.js.map} +0 -0
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
__toESM,
|
|
6
6
|
__using,
|
|
7
7
|
package_default
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-O56TVV5C.js";
|
|
9
9
|
|
|
10
10
|
// ../../node_modules/.pnpm/ignore@7.0.9/node_modules/ignore/index.js
|
|
11
11
|
var require_ignore = __commonJS({
|
|
@@ -20779,7 +20779,10 @@ var RUNTIME_HEARTBEAT_ACK_MESSAGE = `{"kind":"${RUNTIME_HEARTBEAT_ACK_KIND}"}`;
|
|
|
20779
20779
|
function decodeRuntimeLivenessReadyEvent(encoded) {
|
|
20780
20780
|
const value = parseJson(encoded);
|
|
20781
20781
|
assertKind(value, RUNTIME_LIVENESS_READY_KIND);
|
|
20782
|
-
return {
|
|
20782
|
+
return {
|
|
20783
|
+
kind: RUNTIME_LIVENESS_READY_KIND,
|
|
20784
|
+
...Reflect.get(value, "sessionEventAcknowledgement") === true ? { sessionEventAcknowledgement: true } : {}
|
|
20785
|
+
};
|
|
20783
20786
|
}
|
|
20784
20787
|
function decodeRuntimeHeartbeatEvent(encoded) {
|
|
20785
20788
|
const value = parseJson(encoded);
|
|
@@ -21800,6 +21803,45 @@ var sessionLiveEventSchema = external_exports.discriminatedUnion("type", [
|
|
|
21800
21803
|
type: external_exports.literal("lifecycle-metadata")
|
|
21801
21804
|
}).readonly()
|
|
21802
21805
|
]);
|
|
21806
|
+
var sessionEventDeliverySchema = external_exports.object({ sessionId: identifierStringSchema, after: positionSchema.nullable(), resumed: external_exports.literal(true).optional() }).readonly();
|
|
21807
|
+
var sessionEventDeliveriesSchema = external_exports.array(sessionEventDeliverySchema).min(1).max(SESSION_EVENT_BATCH_MAX_SIZE).readonly();
|
|
21808
|
+
function checkDeliveryOrder(envelope2, context) {
|
|
21809
|
+
if (envelope2.delivery === void 0) {
|
|
21810
|
+
return;
|
|
21811
|
+
}
|
|
21812
|
+
const previous = /* @__PURE__ */ new Map();
|
|
21813
|
+
for (const delivery of envelope2.delivery) {
|
|
21814
|
+
if (previous.has(delivery.sessionId)) {
|
|
21815
|
+
context.addIssue({ code: "custom", message: "A Session's delivery order is stated twice" });
|
|
21816
|
+
return;
|
|
21817
|
+
}
|
|
21818
|
+
previous.set(delivery.sessionId, delivery.after === null ? null : BigInt(delivery.after));
|
|
21819
|
+
}
|
|
21820
|
+
const named = /* @__PURE__ */ new Set();
|
|
21821
|
+
for (const event of envelope2.events) {
|
|
21822
|
+
if (!previous.has(event.sessionId)) {
|
|
21823
|
+
context.addIssue({ code: "custom", message: "An event's Session has no delivery order" });
|
|
21824
|
+
return;
|
|
21825
|
+
}
|
|
21826
|
+
named.add(event.sessionId);
|
|
21827
|
+
const position = BigInt(event.position);
|
|
21828
|
+
const before = previous.get(event.sessionId);
|
|
21829
|
+
if (before !== null && before !== void 0 && position <= before) {
|
|
21830
|
+
context.addIssue({ code: "custom", message: "A Session's events are not in delivery order" });
|
|
21831
|
+
return;
|
|
21832
|
+
}
|
|
21833
|
+
previous.set(event.sessionId, position);
|
|
21834
|
+
}
|
|
21835
|
+
if (named.size !== previous.size) {
|
|
21836
|
+
context.addIssue({ code: "custom", message: "A delivery order names a Session without events" });
|
|
21837
|
+
}
|
|
21838
|
+
}
|
|
21839
|
+
var SESSION_EVENTS_ACKNOWLEDGED_KIND = "session.events.acknowledged";
|
|
21840
|
+
var sessionEventsAcknowledgedSchema = external_exports.object({
|
|
21841
|
+
kind: external_exports.literal(SESSION_EVENTS_ACKNOWLEDGED_KIND),
|
|
21842
|
+
// Each Session's events through this position were recorded or need no Recording; none is sent again.
|
|
21843
|
+
sessions: external_exports.array(external_exports.object({ sessionId: identifierStringSchema, through: positionSchema }).readonly()).min(1).max(SESSION_EVENT_BATCH_MAX_SIZE).readonly()
|
|
21844
|
+
}).readonly();
|
|
21803
21845
|
var wireLifecyclePayloadSchema = external_exports.object({
|
|
21804
21846
|
kind: identifierStringSchema,
|
|
21805
21847
|
commandId: identifierStringSchema.optional(),
|
|
@@ -21829,14 +21871,19 @@ var sessionWireEventSchema = external_exports.union([
|
|
|
21829
21871
|
]);
|
|
21830
21872
|
var sessionWireEnvelopeSchema = external_exports.object({
|
|
21831
21873
|
kind: external_exports.literal(SESSION_EVENT_KIND),
|
|
21832
|
-
events: external_exports.array(sessionWireEventSchema).min(1).max(SESSION_EVENT_BATCH_MAX_SIZE).readonly()
|
|
21833
|
-
|
|
21874
|
+
events: external_exports.array(sessionWireEventSchema).min(1).max(SESSION_EVENT_BATCH_MAX_SIZE).readonly(),
|
|
21875
|
+
delivery: sessionEventDeliveriesSchema.optional()
|
|
21876
|
+
}).passthrough().superRefine(checkDeliveryOrder).readonly();
|
|
21834
21877
|
function isRecord2(value) {
|
|
21835
21878
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21836
21879
|
}
|
|
21837
21880
|
var sessionEventBatchSchema = external_exports.array(sessionEventSchema).min(1).max(SESSION_EVENT_BATCH_MAX_SIZE).readonly();
|
|
21838
21881
|
var sessionLiveEventBatchSchema = external_exports.array(sessionLiveEventSchema).min(1).max(SESSION_EVENT_BATCH_MAX_SIZE).readonly();
|
|
21839
|
-
var sessionEventEnvelopeSchema = external_exports.object({
|
|
21882
|
+
var sessionEventEnvelopeSchema = external_exports.object({
|
|
21883
|
+
events: sessionLiveEventBatchSchema,
|
|
21884
|
+
kind: external_exports.literal(SESSION_EVENT_KIND),
|
|
21885
|
+
delivery: sessionEventDeliveriesSchema.optional()
|
|
21886
|
+
}).superRefine(checkDeliveryOrder).readonly();
|
|
21840
21887
|
var promptMessageOutcomeSchema = external_exports.object({
|
|
21841
21888
|
payload: external_exports.discriminatedUnion("kind", [promptCompletedSchema, promptFailedSchema]),
|
|
21842
21889
|
recordedAt: external_exports.iso.datetime({ offset: true })
|
|
@@ -21930,6 +21977,8 @@ var decodeKnownSessionEventPayload = (value) => {
|
|
|
21930
21977
|
};
|
|
21931
21978
|
var decodeSessionEventEnvelope = (value) => decode3(value, sessionEventEnvelopeSchema);
|
|
21932
21979
|
var encodeSessionEventEnvelope = (value) => encode3(value, sessionEventEnvelopeSchema);
|
|
21980
|
+
var decodeSessionEventsAcknowledgedEvent = (value) => decode3(value, sessionEventsAcknowledgedSchema);
|
|
21981
|
+
var encodeSessionEventsAcknowledgedEvent = (value) => encode3(value, sessionEventsAcknowledgedSchema);
|
|
21933
21982
|
var decodeAcpSessionUpdate = (value) => decode3(value, acpSessionUpdateSchema);
|
|
21934
21983
|
var decodeKnownNativeSessionEvents = (value) => decode3(sanitizeConsumableNativeSessionEvents(value), nativeSessionEventsSchema);
|
|
21935
21984
|
|
|
@@ -22948,6 +22997,11 @@ var serviceToDaemonSignatures = {
|
|
|
22948
22997
|
encodeRuntimeLivenessReadyEvent,
|
|
22949
22998
|
decodeRuntimeLivenessReadyEvent
|
|
22950
22999
|
),
|
|
23000
|
+
[SESSION_EVENTS_ACKNOWLEDGED_KIND]: defineMessageSignature(
|
|
23001
|
+
SESSION_EVENTS_ACKNOWLEDGED_KIND,
|
|
23002
|
+
encodeSessionEventsAcknowledgedEvent,
|
|
23003
|
+
decodeSessionEventsAcknowledgedEvent
|
|
23004
|
+
),
|
|
22951
23005
|
"runtime.diagnostics.read": defineMessageSignature(
|
|
22952
23006
|
"runtime.diagnostics.read",
|
|
22953
23007
|
encodeRuntimeDiagnosticsRequest,
|
|
@@ -85788,7 +85842,7 @@ async function readAntigravityStoredCredentials(environment) {
|
|
|
85788
85842
|
} catch {
|
|
85789
85843
|
}
|
|
85790
85844
|
}
|
|
85791
|
-
return { kind: "
|
|
85845
|
+
return { kind: "no_file_credentials" };
|
|
85792
85846
|
}
|
|
85793
85847
|
|
|
85794
85848
|
// src/engine/util/network/environment-proxy.ts
|
|
@@ -85846,7 +85900,7 @@ var DAILY_ENDPOINT = "https://daily-cloudcode-pa.googleapis.com";
|
|
|
85846
85900
|
var PROD_ENDPOINT = "https://cloudcode-pa.googleapis.com";
|
|
85847
85901
|
var OAUTH_TOKEN_URL = "https://oauth2.googleapis.com/token";
|
|
85848
85902
|
var HTTP_TIMEOUT_MILLISECONDS = 1e4;
|
|
85849
|
-
var
|
|
85903
|
+
var AGY_CLI_TIMEOUT_MILLISECONDS = 15e3;
|
|
85850
85904
|
var TOKEN_EXPIRY_MARGIN_MILLISECONDS = 6e4;
|
|
85851
85905
|
var SESSION_WINDOW_MINUTES3 = 5 * 60;
|
|
85852
85906
|
var WEEKLY_WINDOW_MINUTES3 = 7 * 24 * 60;
|
|
@@ -85875,6 +85929,30 @@ var summarySchema = external_exports.object({
|
|
|
85875
85929
|
).optional(),
|
|
85876
85930
|
buckets: external_exports.array(bucketSchema).optional()
|
|
85877
85931
|
});
|
|
85932
|
+
var cliUsageSchema = external_exports.object({
|
|
85933
|
+
status: external_exports.literal("SUCCESS"),
|
|
85934
|
+
command: external_exports.object({
|
|
85935
|
+
name: external_exports.literal("usage"),
|
|
85936
|
+
data: external_exports.object({
|
|
85937
|
+
groups: external_exports.array(
|
|
85938
|
+
external_exports.object({
|
|
85939
|
+
name: external_exports.string().optional(),
|
|
85940
|
+
buckets: external_exports.array(
|
|
85941
|
+
external_exports.object({
|
|
85942
|
+
id: external_exports.string().min(1),
|
|
85943
|
+
name: external_exports.string().optional(),
|
|
85944
|
+
window: external_exports.string().optional(),
|
|
85945
|
+
description: external_exports.string().optional(),
|
|
85946
|
+
disabled: external_exports.boolean().optional(),
|
|
85947
|
+
remaining_fraction: external_exports.number().optional(),
|
|
85948
|
+
reset_time: external_exports.string().optional()
|
|
85949
|
+
})
|
|
85950
|
+
)
|
|
85951
|
+
})
|
|
85952
|
+
)
|
|
85953
|
+
})
|
|
85954
|
+
})
|
|
85955
|
+
});
|
|
85878
85956
|
var availableModelsSchema = external_exports.object({
|
|
85879
85957
|
models: external_exports.record(
|
|
85880
85958
|
external_exports.string(),
|
|
@@ -86045,10 +86123,7 @@ async function refreshAgyOAuthViaCli(options) {
|
|
|
86045
86123
|
stdio: ["ignore", "ignore", "ignore"]
|
|
86046
86124
|
});
|
|
86047
86125
|
const processTreePromise = captureProcessTree(child).catch(() => []);
|
|
86048
|
-
const timeoutSignal = AbortSignal.any([
|
|
86049
|
-
options.signal,
|
|
86050
|
-
AbortSignal.timeout(TOKEN_REFRESH_CLI_TIMEOUT_MILLISECONDS)
|
|
86051
|
-
]);
|
|
86126
|
+
const timeoutSignal = AbortSignal.any([options.signal, AbortSignal.timeout(AGY_CLI_TIMEOUT_MILLISECONDS)]);
|
|
86052
86127
|
await new Promise((resolve21, reject2) => {
|
|
86053
86128
|
let settled = false;
|
|
86054
86129
|
const finish = (outcome) => {
|
|
@@ -86141,6 +86216,50 @@ async function fetchMergedWindows(params) {
|
|
|
86141
86216
|
}
|
|
86142
86217
|
return { windows: [...merged.values()], unauthorized: unauthorized && merged.size === 0 };
|
|
86143
86218
|
}
|
|
86219
|
+
async function readCliManagedUsage(options, checkedAt) {
|
|
86220
|
+
const base = { agentId: "antigravity", checkedAt };
|
|
86221
|
+
try {
|
|
86222
|
+
const { stdout } = await runBoundedProcess({
|
|
86223
|
+
...options,
|
|
86224
|
+
arguments: ["-p", "/usage", "--output-format", "json"],
|
|
86225
|
+
environment: { ...process.env, ...options.environment },
|
|
86226
|
+
outputLimitBytes: 256 * 1024,
|
|
86227
|
+
timeoutMilliseconds: AGY_CLI_TIMEOUT_MILLISECONDS
|
|
86228
|
+
});
|
|
86229
|
+
const { command } = cliUsageSchema.parse(JSON.parse(stdout));
|
|
86230
|
+
const groups = command.data.groups.map((group) => ({
|
|
86231
|
+
displayName: group.name,
|
|
86232
|
+
buckets: group.buckets.map((bucket) => ({
|
|
86233
|
+
bucketId: bucket.id,
|
|
86234
|
+
displayName: bucket.name,
|
|
86235
|
+
window: bucket.window,
|
|
86236
|
+
description: bucket.description,
|
|
86237
|
+
disabled: bucket.disabled,
|
|
86238
|
+
remainingFraction: bucket.remaining_fraction,
|
|
86239
|
+
resetTime: bucket.reset_time
|
|
86240
|
+
}))
|
|
86241
|
+
}));
|
|
86242
|
+
const windows = parseSummaryWindows({ groups }, Date.parse(checkedAt));
|
|
86243
|
+
if (windows.length > 0) {
|
|
86244
|
+
return { ...base, status: "available", windows };
|
|
86245
|
+
}
|
|
86246
|
+
} catch (error62) {
|
|
86247
|
+
options.signal.throwIfAborted();
|
|
86248
|
+
if (error62 instanceof ProcessExecutionError && error62.code === "process_exit_failed" && await options.requiresAuthentication()) {
|
|
86249
|
+
return {
|
|
86250
|
+
...base,
|
|
86251
|
+
status: "unauthenticated",
|
|
86252
|
+
message: "Sign in to Antigravity on this computer to view subscription quotas."
|
|
86253
|
+
};
|
|
86254
|
+
}
|
|
86255
|
+
}
|
|
86256
|
+
return {
|
|
86257
|
+
...base,
|
|
86258
|
+
status: "unavailable",
|
|
86259
|
+
errorCode: "antigravity_usage_probe_failed",
|
|
86260
|
+
errorMessage: "Could not read Antigravity usage quotas."
|
|
86261
|
+
};
|
|
86262
|
+
}
|
|
86144
86263
|
async function readAntigravityUsageQuota(options) {
|
|
86145
86264
|
options.signal.throwIfAborted();
|
|
86146
86265
|
const checkedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -86154,13 +86273,8 @@ async function readAntigravityUsageQuota(options) {
|
|
|
86154
86273
|
message: credentials.message
|
|
86155
86274
|
};
|
|
86156
86275
|
}
|
|
86157
|
-
if (credentials.kind === "
|
|
86158
|
-
return
|
|
86159
|
-
agentId: "antigravity",
|
|
86160
|
-
status: "unauthenticated",
|
|
86161
|
-
checkedAt,
|
|
86162
|
-
message: "Sign in to Antigravity on this computer to view subscription quotas."
|
|
86163
|
-
};
|
|
86276
|
+
if (credentials.kind === "no_file_credentials") {
|
|
86277
|
+
return await readCliManagedUsage(options, checkedAt);
|
|
86164
86278
|
}
|
|
86165
86279
|
let accessToken = null;
|
|
86166
86280
|
let accountLabel;
|
|
@@ -88012,6 +88126,22 @@ var AntigravityAdapter = class {
|
|
|
88012
88126
|
return { kind: "unsupported" };
|
|
88013
88127
|
};
|
|
88014
88128
|
readUsageQuota = async (params) => await readAntigravityUsageQuota({
|
|
88129
|
+
// Print mode uses the same exit code for a missing login and an upstream outage.
|
|
88130
|
+
requiresAuthentication: async () => {
|
|
88131
|
+
try {
|
|
88132
|
+
await probeAcpReadiness(
|
|
88133
|
+
new AntigravityAgentSpecification(),
|
|
88134
|
+
params.agent,
|
|
88135
|
+
process.env,
|
|
88136
|
+
params.cwd,
|
|
88137
|
+
params.signal
|
|
88138
|
+
);
|
|
88139
|
+
return false;
|
|
88140
|
+
} catch (error62) {
|
|
88141
|
+
params.signal.throwIfAborted();
|
|
88142
|
+
return error62 instanceof AgentProbeError && error62.code === "authentication_required";
|
|
88143
|
+
}
|
|
88144
|
+
},
|
|
88015
88145
|
command: params.agent.command,
|
|
88016
88146
|
cwd: params.cwd,
|
|
88017
88147
|
environment: params.agent.environment,
|
|
@@ -104803,7 +104933,7 @@ async function runRelayConnection({
|
|
|
104803
104933
|
return;
|
|
104804
104934
|
}
|
|
104805
104935
|
ready = true;
|
|
104806
|
-
publisher.connect(socket);
|
|
104936
|
+
publisher.connect(socket, message.sessionEventAcknowledgement === true);
|
|
104807
104937
|
connectionLiveness.start();
|
|
104808
104938
|
onConnected();
|
|
104809
104939
|
return;
|
|
@@ -104813,6 +104943,10 @@ async function runRelayConnection({
|
|
|
104813
104943
|
return;
|
|
104814
104944
|
}
|
|
104815
104945
|
connectionLiveness.recordInboundActivity();
|
|
104946
|
+
if (kind === SESSION_EVENTS_ACKNOWLEDGED_KIND) {
|
|
104947
|
+
publisher.acknowledge(socket, message);
|
|
104948
|
+
return;
|
|
104949
|
+
}
|
|
104816
104950
|
commands.dispatch(message);
|
|
104817
104951
|
} catch (error62) {
|
|
104818
104952
|
console.error("Mobius daemon rejected a message", error62);
|
|
@@ -104841,41 +104975,62 @@ async function runRelayConnection({
|
|
|
104841
104975
|
// src/engine/runtime/relay/session-event-publisher.ts
|
|
104842
104976
|
import { WebSocket as WebSocket11 } from "undici";
|
|
104843
104977
|
var MAX_BUFFERED_BYTES = 32 * 1024 * 1024;
|
|
104844
|
-
var
|
|
104978
|
+
var MAX_RETAINED_BYTES = 32 * 1024 * 1024;
|
|
104845
104979
|
var MAX_EVENT_BATCH_BYTES = 1024 * 1024;
|
|
104846
104980
|
var MAX_FRAME_BYTES = 8 * 1024 * 1024;
|
|
104847
104981
|
var LOCAL_BACKPRESSURE_CLOSE_CODE = 4009;
|
|
104848
104982
|
var EMPTY_ENVELOPE_BYTES = Buffer.byteLength(JSON.stringify({ events: [], kind: SESSION_EVENT_KIND }));
|
|
104983
|
+
var EMPTY_DELIVERY_BYTES = Buffer.byteLength(',"delivery":[]');
|
|
104849
104984
|
var SESSION_EVENT_BATCH_WINDOW_MILLISECONDS = 100;
|
|
104985
|
+
var SESSION_EVENT_RESEND_INTERVAL_MILLISECONDS = 3e4;
|
|
104986
|
+
var MAX_SESSION_EVENT_RESENDS = 5;
|
|
104850
104987
|
var RuntimeSessionEventPublisher = class {
|
|
104851
|
-
#
|
|
104988
|
+
#retained = [];
|
|
104989
|
+
#sessions = /* @__PURE__ */ new Map();
|
|
104852
104990
|
#awaitingFirstAnswer = /* @__PURE__ */ new Map();
|
|
104853
|
-
#
|
|
104991
|
+
#retainedBytes = 0;
|
|
104992
|
+
#unsentCount = 0;
|
|
104993
|
+
#unsentBytes = 0;
|
|
104854
104994
|
#overflowReported = false;
|
|
104855
104995
|
#pendingTask = null;
|
|
104996
|
+
#resendTask = null;
|
|
104997
|
+
#tick = 0;
|
|
104856
104998
|
#connection = { kind: "disconnected" };
|
|
104857
104999
|
#timer;
|
|
104858
105000
|
constructor(timer) {
|
|
104859
105001
|
this.#timer = timer;
|
|
104860
105002
|
}
|
|
104861
|
-
connect = (socket) => {
|
|
105003
|
+
connect = (socket, acknowledged) => {
|
|
104862
105004
|
if (this.#connection.kind === "closed") {
|
|
104863
105005
|
return;
|
|
104864
105006
|
}
|
|
104865
|
-
this.#connection = { kind: "connected", socket };
|
|
105007
|
+
this.#connection = { kind: "connected", socket, acknowledged };
|
|
105008
|
+
for (const retained of this.#retained) {
|
|
105009
|
+
if (retained.handoff.kind === "sent") {
|
|
105010
|
+
this.#markUnsent(retained);
|
|
105011
|
+
}
|
|
105012
|
+
}
|
|
105013
|
+
for (const delivery of this.#sessions.values()) {
|
|
105014
|
+
delivery.lastSent = null;
|
|
105015
|
+
}
|
|
104866
105016
|
this.flushEvents(socket);
|
|
104867
105017
|
};
|
|
104868
105018
|
disconnect = (socket) => {
|
|
104869
105019
|
if (this.#connection.kind === "connected" && this.#connection.socket === socket) {
|
|
104870
105020
|
this.#connection = { kind: "disconnected" };
|
|
104871
105021
|
this.cancelFlush();
|
|
105022
|
+
this.cancelResend();
|
|
104872
105023
|
}
|
|
104873
105024
|
};
|
|
104874
105025
|
close = () => {
|
|
104875
105026
|
this.#connection = { kind: "closed" };
|
|
104876
105027
|
this.cancelFlush();
|
|
104877
|
-
this
|
|
104878
|
-
this.#
|
|
105028
|
+
this.cancelResend();
|
|
105029
|
+
this.#retained.length = 0;
|
|
105030
|
+
this.#retainedBytes = 0;
|
|
105031
|
+
this.#unsentCount = 0;
|
|
105032
|
+
this.#unsentBytes = 0;
|
|
105033
|
+
this.#sessions.clear();
|
|
104879
105034
|
this.#awaitingFirstAnswer.clear();
|
|
104880
105035
|
};
|
|
104881
105036
|
flush = () => {
|
|
@@ -104883,6 +105038,30 @@ var RuntimeSessionEventPublisher = class {
|
|
|
104883
105038
|
this.flushEvents(this.#connection.socket);
|
|
104884
105039
|
}
|
|
104885
105040
|
};
|
|
105041
|
+
/** Releases the acknowledged events of each Session, which are never sent again. */
|
|
105042
|
+
acknowledge = (socket, message) => {
|
|
105043
|
+
const connection = this.#connection;
|
|
105044
|
+
if (connection.kind !== "connected" || connection.socket !== socket || !connection.acknowledged) {
|
|
105045
|
+
return;
|
|
105046
|
+
}
|
|
105047
|
+
for (const { sessionId, through } of message.sessions) {
|
|
105048
|
+
const position = Number(through);
|
|
105049
|
+
const delivery = this.#sessions.get(sessionId);
|
|
105050
|
+
const named = this.#retained.some(
|
|
105051
|
+
(retained) => retained.event.sessionId === sessionId && retained.position === position && (retained.handoff.kind === "sent" || retained.handoff.sentBefore)
|
|
105052
|
+
);
|
|
105053
|
+
if (delivery === void 0 || !named) {
|
|
105054
|
+
continue;
|
|
105055
|
+
}
|
|
105056
|
+
this.#release((retained) => retained.event.sessionId === sessionId && retained.position <= position);
|
|
105057
|
+
delivery.acknowledged = position;
|
|
105058
|
+
delivery.resends = 0;
|
|
105059
|
+
if (delivery.lastSent !== null && delivery.lastSent <= position) {
|
|
105060
|
+
delivery.lastSent = null;
|
|
105061
|
+
}
|
|
105062
|
+
this.#forgetSettled(sessionId);
|
|
105063
|
+
}
|
|
105064
|
+
};
|
|
104886
105065
|
publishOperationFailure = (sessionId, requestId, code, message) => {
|
|
104887
105066
|
this.#send({ kind: "session.operation.failed", sessionId, requestId, code, message });
|
|
104888
105067
|
};
|
|
@@ -104913,6 +105092,7 @@ var RuntimeSessionEventPublisher = class {
|
|
|
104913
105092
|
return;
|
|
104914
105093
|
}
|
|
104915
105094
|
const bytes = Buffer.byteLength(JSON.stringify(event), "utf8") + 1;
|
|
105095
|
+
const delivery = this.#delivery(event.sessionId);
|
|
104916
105096
|
if (bytes + EMPTY_ENVELOPE_BYTES > MAX_FRAME_BYTES) {
|
|
104917
105097
|
console.warn("Live Session event exceeds the Relay frame limit", {
|
|
104918
105098
|
code: "live_event_too_large",
|
|
@@ -104920,47 +105100,49 @@ var RuntimeSessionEventPublisher = class {
|
|
|
104920
105100
|
eventId: event.eventId,
|
|
104921
105101
|
bytes
|
|
104922
105102
|
});
|
|
105103
|
+
delivery.lost = true;
|
|
104923
105104
|
return;
|
|
104924
105105
|
}
|
|
104925
|
-
|
|
104926
|
-
|
|
104927
|
-
|
|
104928
|
-
if (this.#
|
|
105106
|
+
if (this.#retainedBytes + bytes > MAX_RETAINED_BYTES) {
|
|
105107
|
+
this.#evictSent(this.#retainedBytes + bytes - MAX_RETAINED_BYTES);
|
|
105108
|
+
}
|
|
105109
|
+
if (this.#retainedBytes + bytes > MAX_RETAINED_BYTES) {
|
|
104929
105110
|
if (!this.#overflowReported) {
|
|
104930
105111
|
this.#overflowReported = true;
|
|
104931
105112
|
console.warn("Live Session output exceeded the pending buffer limit", {
|
|
104932
105113
|
code: "live_event_buffer_full",
|
|
104933
105114
|
sessionId: event.sessionId,
|
|
104934
105115
|
eventId: event.eventId,
|
|
104935
|
-
maximumBytes:
|
|
105116
|
+
maximumBytes: MAX_RETAINED_BYTES
|
|
104936
105117
|
});
|
|
104937
105118
|
}
|
|
105119
|
+
delivery.lost = true;
|
|
104938
105120
|
return;
|
|
104939
105121
|
}
|
|
104940
|
-
if (batch === void 0 || newBatch) {
|
|
104941
|
-
batch = { events: [], firstAnswers: [], bytes: EMPTY_ENVELOPE_BYTES };
|
|
104942
|
-
this.#pending.push(batch);
|
|
104943
|
-
}
|
|
104944
|
-
batch.events.push(event);
|
|
104945
|
-
batch.bytes += bytes;
|
|
104946
|
-
this.#pendingBytes += additionalBytes;
|
|
104947
105122
|
const awaiting = this.#awaitingFirstAnswer.get(event.sessionId);
|
|
104948
105123
|
const firstAnswer = this.#consumeFirstAnswer(event);
|
|
104949
|
-
|
|
104950
|
-
|
|
105124
|
+
this.#retained.push({
|
|
105125
|
+
event,
|
|
105126
|
+
position: Number(event.position),
|
|
105127
|
+
bytes,
|
|
105128
|
+
handoff: { kind: "unsent", sentBefore: false },
|
|
105129
|
+
firstAnswer: firstAnswer && awaiting !== void 0 ? {
|
|
104951
105130
|
sessionId: event.sessionId,
|
|
104952
105131
|
commandId: awaiting.commandId,
|
|
104953
105132
|
eventId: event.eventId,
|
|
104954
105133
|
observedAt: Date.now(),
|
|
104955
105134
|
publishedAt: performance.now()
|
|
104956
|
-
}
|
|
104957
|
-
}
|
|
105135
|
+
} : null
|
|
105136
|
+
});
|
|
105137
|
+
this.#retainedBytes += bytes;
|
|
105138
|
+
this.#unsentCount += 1;
|
|
105139
|
+
this.#unsentBytes += bytes;
|
|
104958
105140
|
const connection = this.#connection;
|
|
104959
105141
|
if (connection.kind !== "connected" || connection.socket.readyState !== WebSocket11.OPEN) {
|
|
104960
105142
|
return;
|
|
104961
105143
|
}
|
|
104962
105144
|
const socket = connection.socket;
|
|
104963
|
-
if (firstAnswer || this.#
|
|
105145
|
+
if (firstAnswer || this.#unsentCount >= SESSION_EVENT_BATCH_MAX_SIZE || EMPTY_ENVELOPE_BYTES + this.#unsentBytes >= MAX_EVENT_BATCH_BYTES) {
|
|
104964
105146
|
this.flushEvents(socket);
|
|
104965
105147
|
return;
|
|
104966
105148
|
}
|
|
@@ -104969,6 +105151,86 @@ var RuntimeSessionEventPublisher = class {
|
|
|
104969
105151
|
SESSION_EVENT_BATCH_WINDOW_MILLISECONDS
|
|
104970
105152
|
);
|
|
104971
105153
|
};
|
|
105154
|
+
#delivery = (sessionId) => {
|
|
105155
|
+
const existing = this.#sessions.get(sessionId);
|
|
105156
|
+
if (existing !== void 0) {
|
|
105157
|
+
return existing;
|
|
105158
|
+
}
|
|
105159
|
+
const created = { acknowledged: null, lastSent: null, lost: false, resends: 0 };
|
|
105160
|
+
this.#sessions.set(sessionId, created);
|
|
105161
|
+
return created;
|
|
105162
|
+
};
|
|
105163
|
+
/** A Session with nothing retained or owed needs no delivery state; its next events start a new order. */
|
|
105164
|
+
#forgetSettled = (sessionId) => {
|
|
105165
|
+
const delivery = this.#sessions.get(sessionId);
|
|
105166
|
+
if (delivery !== void 0 && !delivery.lost && !this.#retained.some((retained) => retained.event.sessionId === sessionId)) {
|
|
105167
|
+
this.#sessions.delete(sessionId);
|
|
105168
|
+
}
|
|
105169
|
+
};
|
|
105170
|
+
#markUnsent = (retained) => {
|
|
105171
|
+
retained.handoff = { kind: "unsent", sentBefore: true };
|
|
105172
|
+
this.#unsentCount += 1;
|
|
105173
|
+
this.#unsentBytes += retained.bytes;
|
|
105174
|
+
};
|
|
105175
|
+
#release = (released) => {
|
|
105176
|
+
let kept = 0;
|
|
105177
|
+
for (const retained of this.#retained) {
|
|
105178
|
+
if (released(retained)) {
|
|
105179
|
+
this.#retainedBytes -= retained.bytes;
|
|
105180
|
+
if (retained.handoff.kind === "unsent") {
|
|
105181
|
+
this.#unsentCount -= 1;
|
|
105182
|
+
this.#unsentBytes -= retained.bytes;
|
|
105183
|
+
}
|
|
105184
|
+
} else {
|
|
105185
|
+
this.#retained[kept] = retained;
|
|
105186
|
+
kept += 1;
|
|
105187
|
+
}
|
|
105188
|
+
}
|
|
105189
|
+
this.#retained.length = kept;
|
|
105190
|
+
if (this.#retained.length === 0) {
|
|
105191
|
+
this.#overflowReported = false;
|
|
105192
|
+
}
|
|
105193
|
+
};
|
|
105194
|
+
/** Gives up the oldest Sessions' sent events to make room; those Sessions continue with a new, omitted order. */
|
|
105195
|
+
#evictSent = (needed) => {
|
|
105196
|
+
let freed = 0;
|
|
105197
|
+
const sessions = /* @__PURE__ */ new Set();
|
|
105198
|
+
for (const retained of this.#retained) {
|
|
105199
|
+
if (freed >= needed) {
|
|
105200
|
+
break;
|
|
105201
|
+
}
|
|
105202
|
+
if (retained.handoff.kind === "unsent" && !retained.handoff.sentBefore) {
|
|
105203
|
+
continue;
|
|
105204
|
+
}
|
|
105205
|
+
if (!sessions.has(retained.event.sessionId)) {
|
|
105206
|
+
sessions.add(retained.event.sessionId);
|
|
105207
|
+
for (const candidate of this.#retained) {
|
|
105208
|
+
if (candidate.event.sessionId === retained.event.sessionId && (candidate.handoff.kind === "sent" || candidate.handoff.sentBefore)) {
|
|
105209
|
+
freed += candidate.bytes;
|
|
105210
|
+
}
|
|
105211
|
+
}
|
|
105212
|
+
}
|
|
105213
|
+
}
|
|
105214
|
+
if (sessions.size === 0) {
|
|
105215
|
+
return;
|
|
105216
|
+
}
|
|
105217
|
+
this.#giveUp(sessions);
|
|
105218
|
+
console.warn("Unacknowledged live Session output was given up to make room", {
|
|
105219
|
+
code: "live_event_unacknowledged_evicted",
|
|
105220
|
+
sessions: sessions.size
|
|
105221
|
+
});
|
|
105222
|
+
};
|
|
105223
|
+
#giveUp = (sessions) => {
|
|
105224
|
+
this.#release(
|
|
105225
|
+
(retained) => sessions.has(retained.event.sessionId) && (retained.handoff.kind === "sent" || retained.handoff.sentBefore)
|
|
105226
|
+
);
|
|
105227
|
+
for (const sessionId of sessions) {
|
|
105228
|
+
const delivery = this.#delivery(sessionId);
|
|
105229
|
+
delivery.lost = true;
|
|
105230
|
+
delivery.lastSent = null;
|
|
105231
|
+
delivery.resends = 0;
|
|
105232
|
+
}
|
|
105233
|
+
};
|
|
104972
105234
|
#consumeFirstAnswer = (event) => {
|
|
104973
105235
|
if (event.type === "lifecycle-metadata") {
|
|
104974
105236
|
const payload = event.payload;
|
|
@@ -104992,24 +105254,100 @@ var RuntimeSessionEventPublisher = class {
|
|
|
104992
105254
|
this.#pendingTask?.cancel();
|
|
104993
105255
|
this.#pendingTask = null;
|
|
104994
105256
|
};
|
|
105257
|
+
cancelResend = () => {
|
|
105258
|
+
this.#resendTask?.cancel();
|
|
105259
|
+
this.#resendTask = null;
|
|
105260
|
+
};
|
|
105261
|
+
/** Checks for unacknowledged events while this connection holds any it sent. */
|
|
105262
|
+
scheduleResend = (socket) => {
|
|
105263
|
+
if (this.#resendTask !== null || !this.#retained.some((retained) => retained.handoff.kind === "sent")) {
|
|
105264
|
+
return;
|
|
105265
|
+
}
|
|
105266
|
+
this.#resendTask = this.#timer.schedule(() => {
|
|
105267
|
+
this.#resendTask = null;
|
|
105268
|
+
this.resendUnacknowledged(socket);
|
|
105269
|
+
}, SESSION_EVENT_RESEND_INTERVAL_MILLISECONDS);
|
|
105270
|
+
};
|
|
105271
|
+
resendUnacknowledged = (socket) => {
|
|
105272
|
+
const connection = this.#connection;
|
|
105273
|
+
if (connection.kind !== "connected" || connection.socket !== socket || !connection.acknowledged) {
|
|
105274
|
+
return;
|
|
105275
|
+
}
|
|
105276
|
+
this.#tick += 1;
|
|
105277
|
+
const oldest = /* @__PURE__ */ new Map();
|
|
105278
|
+
for (const retained of this.#retained) {
|
|
105279
|
+
if (retained.handoff.kind === "sent" && !oldest.has(retained.event.sessionId)) {
|
|
105280
|
+
oldest.set(retained.event.sessionId, retained.handoff.tick);
|
|
105281
|
+
}
|
|
105282
|
+
}
|
|
105283
|
+
const abandoned = /* @__PURE__ */ new Set();
|
|
105284
|
+
const resent = /* @__PURE__ */ new Set();
|
|
105285
|
+
for (const [sessionId, tick] of oldest) {
|
|
105286
|
+
const delivery = this.#delivery(sessionId);
|
|
105287
|
+
if (this.#tick - tick <= 2 ** delivery.resends) {
|
|
105288
|
+
continue;
|
|
105289
|
+
}
|
|
105290
|
+
if (delivery.resends >= MAX_SESSION_EVENT_RESENDS) {
|
|
105291
|
+
abandoned.add(sessionId);
|
|
105292
|
+
} else {
|
|
105293
|
+
delivery.resends += 1;
|
|
105294
|
+
resent.add(sessionId);
|
|
105295
|
+
}
|
|
105296
|
+
}
|
|
105297
|
+
if (abandoned.size > 0) {
|
|
105298
|
+
this.#giveUp(abandoned);
|
|
105299
|
+
console.warn("Live Session output the Relay never acknowledged was given up", {
|
|
105300
|
+
code: "live_event_unacknowledged_abandoned",
|
|
105301
|
+
sessions: abandoned.size
|
|
105302
|
+
});
|
|
105303
|
+
}
|
|
105304
|
+
for (const retained of this.#retained) {
|
|
105305
|
+
if (resent.has(retained.event.sessionId) && retained.handoff.kind === "sent") {
|
|
105306
|
+
this.#markUnsent(retained);
|
|
105307
|
+
}
|
|
105308
|
+
}
|
|
105309
|
+
for (const sessionId of resent) {
|
|
105310
|
+
const delivery = this.#delivery(sessionId);
|
|
105311
|
+
delivery.lastSent = null;
|
|
105312
|
+
}
|
|
105313
|
+
this.flushEvents(socket);
|
|
105314
|
+
this.scheduleResend(socket);
|
|
105315
|
+
};
|
|
104995
105316
|
flushEvents = (socket) => {
|
|
104996
105317
|
this.cancelFlush();
|
|
104997
105318
|
const connection = this.#connection;
|
|
104998
105319
|
if (connection.kind !== "connected" || connection.socket !== socket || socket.readyState !== WebSocket11.OPEN) {
|
|
104999
105320
|
return;
|
|
105000
105321
|
}
|
|
105001
|
-
|
|
105002
|
-
|
|
105003
|
-
|
|
105322
|
+
for (; ; ) {
|
|
105323
|
+
const batch = this.#nextBatch(connection.acknowledged);
|
|
105324
|
+
if (batch.length === 0) {
|
|
105325
|
+
break;
|
|
105326
|
+
}
|
|
105327
|
+
const delivery = connection.acknowledged ? this.#deliveryOrder(batch) : void 0;
|
|
105328
|
+
const encoded = encodeDaemonToServiceMessage({
|
|
105329
|
+
events: batch.map((retained) => retained.event),
|
|
105330
|
+
kind: SESSION_EVENT_KIND,
|
|
105331
|
+
...delivery === void 0 ? {} : { delivery }
|
|
105332
|
+
});
|
|
105004
105333
|
if (socket.bufferedAmount + Buffer.byteLength(encoded, "utf8") > MAX_BUFFERED_BYTES) {
|
|
105005
105334
|
socket.close(LOCAL_BACKPRESSURE_CLOSE_CODE, "Live event transport overloaded");
|
|
105006
105335
|
break;
|
|
105007
105336
|
}
|
|
105008
105337
|
try {
|
|
105009
105338
|
socket.send(encoded);
|
|
105010
|
-
|
|
105011
|
-
|
|
105012
|
-
|
|
105339
|
+
} catch {
|
|
105340
|
+
console.warn("Live Session output could not be sent", { code: "live_event_send_failed" });
|
|
105341
|
+
socket.close(LOCAL_BACKPRESSURE_CLOSE_CODE, "Live event handoff failed");
|
|
105342
|
+
break;
|
|
105343
|
+
}
|
|
105344
|
+
for (const retained of batch) {
|
|
105345
|
+
retained.handoff = { kind: "sent", tick: this.#tick };
|
|
105346
|
+
this.#unsentCount -= 1;
|
|
105347
|
+
this.#unsentBytes -= retained.bytes;
|
|
105348
|
+
const answer = retained.firstAnswer;
|
|
105349
|
+
retained.firstAnswer = null;
|
|
105350
|
+
if (answer !== null) {
|
|
105013
105351
|
console.info(
|
|
105014
105352
|
JSON.stringify({
|
|
105015
105353
|
event: "runtime-first-answer-handoff-timing",
|
|
@@ -105022,16 +105360,70 @@ var RuntimeSessionEventPublisher = class {
|
|
|
105022
105360
|
})
|
|
105023
105361
|
);
|
|
105024
105362
|
}
|
|
105025
|
-
}
|
|
105026
|
-
|
|
105027
|
-
|
|
105028
|
-
|
|
105363
|
+
}
|
|
105364
|
+
if (!connection.acknowledged) {
|
|
105365
|
+
const sent = new Set(batch);
|
|
105366
|
+
this.#release((retained) => sent.has(retained));
|
|
105367
|
+
for (const sessionId of new Set(batch.map((retained) => retained.event.sessionId))) {
|
|
105368
|
+
const delivery2 = this.#sessions.get(sessionId);
|
|
105369
|
+
if (delivery2 !== void 0) {
|
|
105370
|
+
delivery2.lost = false;
|
|
105371
|
+
}
|
|
105372
|
+
this.#forgetSettled(sessionId);
|
|
105373
|
+
}
|
|
105029
105374
|
}
|
|
105030
105375
|
}
|
|
105031
|
-
|
|
105032
|
-
|
|
105033
|
-
|
|
105376
|
+
if (connection.acknowledged) {
|
|
105377
|
+
this.scheduleResend(socket);
|
|
105378
|
+
}
|
|
105379
|
+
};
|
|
105380
|
+
/** The oldest unsent events that fit one envelope, in the order they were published. */
|
|
105381
|
+
#nextBatch = (acknowledged) => {
|
|
105382
|
+
const batch = [];
|
|
105383
|
+
const sessions = /* @__PURE__ */ new Set();
|
|
105384
|
+
let bytes = EMPTY_ENVELOPE_BYTES + (acknowledged ? EMPTY_DELIVERY_BYTES : 0);
|
|
105385
|
+
for (const retained of this.#retained) {
|
|
105386
|
+
if (retained.handoff.kind !== "unsent") {
|
|
105387
|
+
continue;
|
|
105388
|
+
}
|
|
105389
|
+
const sessionId = retained.event.sessionId;
|
|
105390
|
+
const orderBytes = acknowledged && !sessions.has(sessionId) ? Buffer.byteLength(
|
|
105391
|
+
`${JSON.stringify({ sessionId, after: String(Number.MAX_SAFE_INTEGER), resumed: true })},`
|
|
105392
|
+
) : 0;
|
|
105393
|
+
if (batch.length >= SESSION_EVENT_BATCH_MAX_SIZE || batch.length > 0 && bytes + retained.bytes + orderBytes > MAX_EVENT_BATCH_BYTES) {
|
|
105394
|
+
break;
|
|
105395
|
+
}
|
|
105396
|
+
batch.push(retained);
|
|
105397
|
+
sessions.add(sessionId);
|
|
105398
|
+
bytes += retained.bytes + orderBytes;
|
|
105399
|
+
}
|
|
105400
|
+
return batch;
|
|
105401
|
+
};
|
|
105402
|
+
/** States where each Session's events in the batch continue its delivery, and records them as its newest sent. */
|
|
105403
|
+
#deliveryOrder = (batch) => {
|
|
105404
|
+
const order = [];
|
|
105405
|
+
for (const retained of batch) {
|
|
105406
|
+
const sessionId = retained.event.sessionId;
|
|
105407
|
+
const delivery = this.#delivery(sessionId);
|
|
105408
|
+
if (!order.some((entry) => entry.sessionId === sessionId)) {
|
|
105409
|
+
const after = delivery.lost ? null : delivery.lastSent ?? delivery.acknowledged;
|
|
105410
|
+
if (delivery.lost) {
|
|
105411
|
+
retained.event = {
|
|
105412
|
+
...retained.event,
|
|
105413
|
+
mobiusMetadata: { ...retained.event.mobiusMetadata, omitted: true }
|
|
105414
|
+
};
|
|
105415
|
+
delivery.lost = false;
|
|
105416
|
+
}
|
|
105417
|
+
const resumed = after !== null && delivery.lastSent === null;
|
|
105418
|
+
order.push({
|
|
105419
|
+
sessionId,
|
|
105420
|
+
after: after === null ? null : String(after),
|
|
105421
|
+
...resumed ? { resumed: true } : {}
|
|
105422
|
+
});
|
|
105423
|
+
}
|
|
105424
|
+
delivery.lastSent = retained.position;
|
|
105034
105425
|
}
|
|
105426
|
+
return order;
|
|
105035
105427
|
};
|
|
105036
105428
|
};
|
|
105037
105429
|
|
|
@@ -105507,4 +105899,4 @@ export {
|
|
|
105507
105899
|
* MIT Licensed
|
|
105508
105900
|
*)
|
|
105509
105901
|
*/
|
|
105510
|
-
//# sourceMappingURL=chunk-
|
|
105902
|
+
//# sourceMappingURL=chunk-2KU5227F.js.map
|