@moxt-ai/mobius 0.0.175 → 0.0.177
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/agent-runtime-manager.d.ts +2 -1
- package/dist/acp/agent-runtime-manager.d.ts.map +1 -1
- package/dist/acp/agent-runtime-manager.js +11 -1
- package/dist/acp/agent-runtime-manager.js.map +1 -1
- package/dist/acp/agent-session.d.ts +3 -1
- package/dist/acp/agent-session.d.ts.map +1 -1
- package/dist/acp/agent-session.js +62 -28
- package/dist/acp/agent-session.js.map +1 -1
- package/dist/acp/codex/agent.d.ts.map +1 -1
- package/dist/acp/codex/agent.js +0 -12
- package/dist/acp/codex/agent.js.map +1 -1
- package/dist/acp/session-contracts.d.ts +3 -1
- package/dist/acp/session-contracts.d.ts.map +1 -1
- package/dist/acp/session-contracts.js.map +1 -1
- package/dist/acp/session-event-store-v2.d.ts +37 -0
- package/dist/acp/session-event-store-v2.d.ts.map +1 -0
- package/dist/acp/session-event-store-v2.js +199 -0
- package/dist/acp/session-event-store-v2.js.map +1 -0
- package/dist/acp/session-history.d.ts +3 -2
- package/dist/acp/session-history.d.ts.map +1 -1
- package/dist/acp/session-history.js +37 -41
- package/dist/acp/session-history.js.map +1 -1
- package/dist/acp/session-store.d.ts +7 -1
- package/dist/acp/session-store.d.ts.map +1 -1
- package/dist/acp/session-store.js +20 -37
- package/dist/acp/session-store.js.map +1 -1
- package/dist/cli.js +1167 -1216
- package/dist/cli.js.map +4 -4
- package/dist/daemon-command-handler.d.ts +1 -3
- package/dist/daemon-command-handler.d.ts.map +1 -1
- package/dist/daemon-command-handler.js +11 -9
- package/dist/daemon-command-handler.js.map +1 -1
- package/dist/daemon-command-results.d.ts +2 -3
- package/dist/daemon-command-results.d.ts.map +1 -1
- package/dist/daemon-command-results.js +4 -12
- package/dist/daemon-command-results.js.map +1 -1
- package/dist/daemon-prompt-executor.d.ts +2 -6
- package/dist/daemon-prompt-executor.d.ts.map +1 -1
- package/dist/daemon-prompt-executor.js +20 -73
- package/dist/daemon-prompt-executor.js.map +1 -1
- package/dist/daemon-session-commands.d.ts +2 -3
- package/dist/daemon-session-commands.d.ts.map +1 -1
- package/dist/daemon-session-commands.js +3 -15
- package/dist/daemon-session-commands.js.map +1 -1
- package/dist/generated/session-event-cache-migrations.d.ts +5 -0
- package/dist/generated/session-event-cache-migrations.d.ts.map +1 -0
- package/dist/generated/session-event-cache-migrations.js +9 -0
- package/dist/generated/session-event-cache-migrations.js.map +1 -0
- package/dist/index.js +1161 -1211
- package/dist/index.js.map +4 -4
- package/dist/infra/local-sqlite-database.d.ts +13 -0
- package/dist/infra/local-sqlite-database.d.ts.map +1 -0
- package/dist/infra/local-sqlite-database.js +57 -0
- package/dist/infra/local-sqlite-database.js.map +1 -0
- package/dist/local-databases.d.ts +4 -0
- package/dist/local-databases.d.ts.map +1 -0
- package/dist/local-databases.js +9 -0
- package/dist/local-databases.js.map +1 -0
- package/dist/relay-connection/run-relay-connection.d.ts.map +1 -1
- package/dist/relay-connection/run-relay-connection.js +0 -1
- package/dist/relay-connection/run-relay-connection.js.map +1 -1
- package/dist/relay-connection/session-event-publisher.d.ts +2 -3
- package/dist/relay-connection/session-event-publisher.d.ts.map +1 -1
- package/dist/relay-connection/session-event-publisher.js +8 -46
- package/dist/relay-connection/session-event-publisher.js.map +1 -1
- package/dist/run-daemon.d.ts.map +1 -1
- package/dist/run-daemon.js +18 -6
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.js +1149 -1199
- package/dist/runtime.js.map +4 -4
- package/dist/schema/session-event-cache/index.d.ts +2 -0
- package/dist/schema/session-event-cache/index.d.ts.map +1 -0
- package/dist/schema/session-event-cache/index.js +2 -0
- package/dist/schema/session-event-cache/index.js.map +1 -0
- package/dist/schema/session-event-cache/session-event-v2.d.ts +72 -0
- package/dist/schema/session-event-cache/session-event-v2.d.ts.map +1 -0
- package/dist/schema/session-event-cache/session-event-v2.js +11 -0
- package/dist/schema/session-event-cache/session-event-v2.js.map +1 -0
- package/dist/session-event-log-v2.d.ts +8 -6
- package/dist/session-event-log-v2.d.ts.map +1 -1
- package/dist/session-event-log-v2.js +85 -13
- package/dist/session-event-log-v2.js.map +1 -1
- package/package.json +2 -1
- package/dist/relay-connection/coalescing-agent-event-publisher.d.ts +0 -32
- package/dist/relay-connection/coalescing-agent-event-publisher.d.ts.map +0 -1
- package/dist/relay-connection/coalescing-agent-event-publisher.js +0 -116
- package/dist/relay-connection/coalescing-agent-event-publisher.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -3380,11 +3380,11 @@ var $ZodDate = /* @__PURE__ */ $constructor("$ZodDate", (inst, def) => {
|
|
|
3380
3380
|
return payload;
|
|
3381
3381
|
};
|
|
3382
3382
|
});
|
|
3383
|
-
function handleArrayResult(result, final,
|
|
3383
|
+
function handleArrayResult(result, final, index2) {
|
|
3384
3384
|
if (result.issues.length) {
|
|
3385
|
-
final.issues.push(...prefixIssues(
|
|
3385
|
+
final.issues.push(...prefixIssues(index2, result.issues));
|
|
3386
3386
|
}
|
|
3387
|
-
final.value[
|
|
3387
|
+
final.value[index2] = result.value;
|
|
3388
3388
|
}
|
|
3389
3389
|
var $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
|
|
3390
3390
|
$ZodType.init(inst, def);
|
|
@@ -3995,14 +3995,14 @@ function mergeValues(a, b) {
|
|
|
3995
3995
|
return { valid: false, mergeErrorPath: [] };
|
|
3996
3996
|
}
|
|
3997
3997
|
const newArray = [];
|
|
3998
|
-
for (let
|
|
3999
|
-
const itemA = a[
|
|
4000
|
-
const itemB = b[
|
|
3998
|
+
for (let index2 = 0; index2 < a.length; index2++) {
|
|
3999
|
+
const itemA = a[index2];
|
|
4000
|
+
const itemB = b[index2];
|
|
4001
4001
|
const sharedValue = mergeValues(itemA, itemB);
|
|
4002
4002
|
if (!sharedValue.valid) {
|
|
4003
4003
|
return {
|
|
4004
4004
|
valid: false,
|
|
4005
|
-
mergeErrorPath: [
|
|
4005
|
+
mergeErrorPath: [index2, ...sharedValue.mergeErrorPath]
|
|
4006
4006
|
};
|
|
4007
4007
|
}
|
|
4008
4008
|
newArray.push(sharedValue.data);
|
|
@@ -4153,11 +4153,11 @@ function getTupleOptStart(items, key) {
|
|
|
4153
4153
|
}
|
|
4154
4154
|
return 0;
|
|
4155
4155
|
}
|
|
4156
|
-
function handleTupleResult(result, final,
|
|
4156
|
+
function handleTupleResult(result, final, index2) {
|
|
4157
4157
|
if (result.issues.length) {
|
|
4158
|
-
final.issues.push(...prefixIssues(
|
|
4158
|
+
final.issues.push(...prefixIssues(index2, result.issues));
|
|
4159
4159
|
}
|
|
4160
|
-
final.value[
|
|
4160
|
+
final.value[index2] = result.value;
|
|
4161
4161
|
}
|
|
4162
4162
|
function handleTupleResults(itemResults, final, items, input2, optoutStart) {
|
|
4163
4163
|
for (let i = 0; i < items.length; i++) {
|
|
@@ -18838,7 +18838,7 @@ function detectVersion(schema, defaultTarget) {
|
|
|
18838
18838
|
return defaultTarget ?? "draft-2020-12";
|
|
18839
18839
|
}
|
|
18840
18840
|
function applyMinItems(items, minItems) {
|
|
18841
|
-
return items.map((item,
|
|
18841
|
+
return items.map((item, index2) => index2 < minItems ? item : item.optional());
|
|
18842
18842
|
}
|
|
18843
18843
|
function decodeJSONPointerSegment(segment) {
|
|
18844
18844
|
return segment.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
@@ -20023,12 +20023,12 @@ var DEFAULT_AGENT_EXECUTION_CONFIGURATION = Object.freeze({
|
|
|
20023
20023
|
});
|
|
20024
20024
|
var sessionConfigurationSelectionsSchema = external_exports.array(sessionConfigurationSelectionSchema).max(100).superRefine((selections, context) => {
|
|
20025
20025
|
const identifiers = /* @__PURE__ */ new Set();
|
|
20026
|
-
for (const [
|
|
20026
|
+
for (const [index2, selection] of selections.entries()) {
|
|
20027
20027
|
if (identifiers.has(selection.configId)) {
|
|
20028
20028
|
context.addIssue({
|
|
20029
20029
|
code: "custom",
|
|
20030
20030
|
message: "Session configuration identifiers must be unique",
|
|
20031
|
-
path: [
|
|
20031
|
+
path: [index2, "configId"]
|
|
20032
20032
|
});
|
|
20033
20033
|
}
|
|
20034
20034
|
identifiers.add(selection.configId);
|
|
@@ -20368,8 +20368,6 @@ function decodeValue(value, schema) {
|
|
|
20368
20368
|
}
|
|
20369
20369
|
return result.data;
|
|
20370
20370
|
}
|
|
20371
|
-
var decodeAgentDisplayContentValue = (value) => decodeValue(value, displayContentSchema);
|
|
20372
|
-
var decodeRecordedAgentContentValue = (value) => decodeValue(value, recordedDisplayContentSchema);
|
|
20373
20371
|
var decodePromptImagesValue = (value) => decodeValue(value, external_exports.array(promptImageSchema).max(8).readonly());
|
|
20374
20372
|
var decodePromptResourcesValue = (value) => decodeValue(value, external_exports.array(promptResourceSchema).max(16).readonly());
|
|
20375
20373
|
var decodeSessionConfigurationSelections = (value) => decodeValue(value, sessionConfigurationSelectionsSchema);
|
|
@@ -20411,20 +20409,13 @@ var encodeSessionReadyEvent = (message) => encode3(message, sessionReadyEventSch
|
|
|
20411
20409
|
var decodeSessionConfigureCommand = (encoded) => decode3(encoded, sessionConfigureCommandSchema);
|
|
20412
20410
|
var encodeSessionConfigureCommand = (message) => encode3(message, sessionConfigureCommandSchema);
|
|
20413
20411
|
var decodeSessionConfigUpdatedEvent = (encoded) => decode3(encoded, sessionConfigUpdatedEventSchema);
|
|
20414
|
-
var
|
|
20415
|
-
var decodeSessionCommandsUpdatedEvent = (encoded) => decode3(encoded, sessionCommandsUpdatedEventSchema);
|
|
20416
|
-
var decodeSessionInfoUpdatedEvent = (encoded) => decode3(encoded, sessionInfoUpdatedEventSchema);
|
|
20417
|
-
var decodeSessionPermissionRequestedEvent = (encoded) => decode3(encoded, sessionPermissionRequestedEventSchema);
|
|
20412
|
+
var encodeSessionConfigUpdatedEvent = (message) => encode3(message, sessionConfigUpdatedEventSchema);
|
|
20418
20413
|
var decodeSessionPermissionRespondCommand = (encoded) => decode3(encoded, sessionPermissionRespondCommandSchema);
|
|
20419
20414
|
var encodeSessionPermissionRespondCommand = (message) => encode3(message, sessionPermissionRespondCommandSchema);
|
|
20420
|
-
var decodeSessionPermissionResolvedEvent = (encoded) => decode3(encoded, sessionPermissionResolvedEventSchema);
|
|
20421
|
-
var decodeSessionElicitationRequestedEvent = (encoded) => decode3(encoded, sessionElicitationRequestedEventSchema);
|
|
20422
20415
|
var decodeSessionElicitationRespondCommand = (encoded) => decode3(encoded, sessionElicitationRespondCommandSchema);
|
|
20423
20416
|
var encodeSessionElicitationRespondCommand = (message) => encode3(message, sessionElicitationRespondCommandSchema);
|
|
20424
|
-
var decodeSessionElicitationResolvedEvent = (encoded) => decode3(encoded, sessionElicitationResolvedEventSchema);
|
|
20425
20417
|
var decodeSessionOperationFailedEvent = (encoded) => decode3(encoded, sessionOperationFailedEventSchema);
|
|
20426
20418
|
var encodeSessionOperationFailedEvent = (message) => encode3(message, sessionOperationFailedEventSchema);
|
|
20427
|
-
var decodeAgentContentEvent = (encoded) => decode3(encoded, agentContentEventSchema);
|
|
20428
20419
|
var decodeAgentInstallRequestCommand = (encoded) => decode3(encoded, agentInstallRequestCommandSchema);
|
|
20429
20420
|
var encodeAgentInstallRequestCommand = (message) => encode3(message, agentInstallRequestCommandSchema);
|
|
20430
20421
|
var decodeAgentInstallCancelCommand = (encoded) => decode3(encoded, agentInstallCancelCommandSchema);
|
|
@@ -20450,7 +20441,6 @@ var RUNTIME_HEARTBEAT_KIND = "runtime.heartbeat";
|
|
|
20450
20441
|
var RUNTIME_HEARTBEAT_ACK_KIND = "runtime.heartbeat.ack";
|
|
20451
20442
|
var RUNTIME_PING_KIND = "runtime.ping";
|
|
20452
20443
|
var RUNTIME_PONG_KIND = "runtime.pong";
|
|
20453
|
-
var SESSION_STARTED_KIND = "session.started";
|
|
20454
20444
|
var SESSION_QUEUED_KIND = "session.queued";
|
|
20455
20445
|
var AGENT_MESSAGE_DELTA_KIND = "agent.message.delta";
|
|
20456
20446
|
var AGENT_ACTIVITY_KIND = "agent.activity";
|
|
@@ -20460,8 +20450,6 @@ var AGENT_ACTIVITY_RECORDED_FIELD_LIMIT = 4e6;
|
|
|
20460
20450
|
var AGENT_ACTIVITY_RECORDED_DETAIL_LIMIT = 6e6;
|
|
20461
20451
|
var AGENT_ACTIVITY_LOCATION_LIMIT = 12;
|
|
20462
20452
|
var AGENT_ACTIVITY_LOCATION_LENGTH_LIMIT = 1024;
|
|
20463
|
-
var SESSION_COMPLETED_KIND = "session.completed";
|
|
20464
|
-
var SESSION_FAILED_KIND = "session.failed";
|
|
20465
20453
|
var SessionPromptDisposition = Object.freeze({
|
|
20466
20454
|
Queue: "queue",
|
|
20467
20455
|
Reject: "reject",
|
|
@@ -20472,23 +20460,6 @@ var SessionPromptDisposition = Object.freeze({
|
|
|
20472
20460
|
var DIRECTORY_IDENTIFIER_PATTERN2 = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/;
|
|
20473
20461
|
var MAX_PROMPT_LENGTH = 1e4;
|
|
20474
20462
|
var MAX_PROMPT_ATTACHMENT_LENGTH = 6e6;
|
|
20475
|
-
var MAX_EVENT_TEXT_LENGTH = 1e5;
|
|
20476
|
-
var ACTIVITY_TYPES = /* @__PURE__ */ new Set(["notice", "plan", "progress", "reasoning", "tool"]);
|
|
20477
|
-
var NARRATION_ACTIVITY_TYPES = /* @__PURE__ */ new Set(["progress", "reasoning"]);
|
|
20478
|
-
var ACTIVITY_STATUSES = /* @__PURE__ */ new Set(["pending", "running", "completed", "failed"]);
|
|
20479
|
-
var TOOL_KINDS = /* @__PURE__ */ new Set([
|
|
20480
|
-
"",
|
|
20481
|
-
"delete",
|
|
20482
|
-
"edit",
|
|
20483
|
-
"execute",
|
|
20484
|
-
"fetch",
|
|
20485
|
-
"move",
|
|
20486
|
-
"other",
|
|
20487
|
-
"read",
|
|
20488
|
-
"search",
|
|
20489
|
-
"switch_mode",
|
|
20490
|
-
"think"
|
|
20491
|
-
]);
|
|
20492
20463
|
var ProtocolMessageError = class extends Error {
|
|
20493
20464
|
code = "invalid_protocol_message";
|
|
20494
20465
|
constructor(message, options = {}) {
|
|
@@ -20538,13 +20509,6 @@ function readText(value, key, maximumLength) {
|
|
|
20538
20509
|
}
|
|
20539
20510
|
return field;
|
|
20540
20511
|
}
|
|
20541
|
-
function readAllowedString(value, key, allowedValues) {
|
|
20542
|
-
const field = readText(value, key, 64);
|
|
20543
|
-
if (!allowedValues.has(field)) {
|
|
20544
|
-
throw new ProtocolMessageError(`Invalid value field: ${key}`);
|
|
20545
|
-
}
|
|
20546
|
-
return field;
|
|
20547
|
-
}
|
|
20548
20512
|
function readPromptDisposition(value) {
|
|
20549
20513
|
const field = value["disposition"];
|
|
20550
20514
|
if (field === void 0 || field === SessionPromptDisposition.Reject) {
|
|
@@ -20558,32 +20522,6 @@ function readPromptDisposition(value) {
|
|
|
20558
20522
|
}
|
|
20559
20523
|
throw new ProtocolMessageError("Invalid value field: disposition");
|
|
20560
20524
|
}
|
|
20561
|
-
function readSequence(value, key) {
|
|
20562
|
-
const field = value[key];
|
|
20563
|
-
if (typeof field !== "number" || !Number.isSafeInteger(field) || field < 0) {
|
|
20564
|
-
throw new ProtocolMessageError(`Invalid integer field: ${key}`);
|
|
20565
|
-
}
|
|
20566
|
-
return field;
|
|
20567
|
-
}
|
|
20568
|
-
function readLocations(value) {
|
|
20569
|
-
const field = value["locations"];
|
|
20570
|
-
if (!Array.isArray(field) || field.length > AGENT_ACTIVITY_LOCATION_LIMIT) {
|
|
20571
|
-
throw new ProtocolMessageError("Invalid locations field");
|
|
20572
|
-
}
|
|
20573
|
-
const locations = [];
|
|
20574
|
-
const unique = /* @__PURE__ */ new Set();
|
|
20575
|
-
for (const location of field) {
|
|
20576
|
-
if (typeof location !== "string" || location.length === 0 || location.length > AGENT_ACTIVITY_LOCATION_LENGTH_LIMIT) {
|
|
20577
|
-
throw new ProtocolMessageError("Invalid activity location");
|
|
20578
|
-
}
|
|
20579
|
-
if (unique.has(location)) {
|
|
20580
|
-
throw new ProtocolMessageError("Duplicate activity location");
|
|
20581
|
-
}
|
|
20582
|
-
unique.add(location);
|
|
20583
|
-
locations.push(location);
|
|
20584
|
-
}
|
|
20585
|
-
return locations;
|
|
20586
|
-
}
|
|
20587
20525
|
function readDirectoryIdentifiers(value, key, maximumCount) {
|
|
20588
20526
|
const field = value[key];
|
|
20589
20527
|
if (!Array.isArray(field) || field.length > maximumCount) {
|
|
@@ -20600,54 +20538,6 @@ function readDirectoryIdentifiers(value, key, maximumCount) {
|
|
|
20600
20538
|
}
|
|
20601
20539
|
return identifiers;
|
|
20602
20540
|
}
|
|
20603
|
-
function readActivityContent(value) {
|
|
20604
|
-
const field = value["content"];
|
|
20605
|
-
if (!Array.isArray(field) || field.length > 100) {
|
|
20606
|
-
throw new ProtocolMessageError("Invalid activity content field");
|
|
20607
|
-
}
|
|
20608
|
-
return field.map((entry) => decodeAgentDisplayContentValue(entry));
|
|
20609
|
-
}
|
|
20610
|
-
function readActivityDetail(value) {
|
|
20611
|
-
const field = value["detail"];
|
|
20612
|
-
if (!isRecord(field)) {
|
|
20613
|
-
throw new ProtocolMessageError("Invalid activity detail field");
|
|
20614
|
-
}
|
|
20615
|
-
const kind = readString(field, "kind", 32);
|
|
20616
|
-
if (kind === "available") {
|
|
20617
|
-
return {
|
|
20618
|
-
artifactId: readIdentifier(field, "artifactId"),
|
|
20619
|
-
kind
|
|
20620
|
-
};
|
|
20621
|
-
}
|
|
20622
|
-
if (kind === "unrecorded") {
|
|
20623
|
-
return { kind };
|
|
20624
|
-
}
|
|
20625
|
-
if (kind === "truncated") {
|
|
20626
|
-
const capturedBytes = readSequence(field, "capturedBytes");
|
|
20627
|
-
const originalBytes = readSequence(field, "originalBytes");
|
|
20628
|
-
if (capturedBytes > originalBytes) {
|
|
20629
|
-
throw new ProtocolMessageError("Invalid truncated activity detail size");
|
|
20630
|
-
}
|
|
20631
|
-
return { capturedBytes, kind, originalBytes };
|
|
20632
|
-
}
|
|
20633
|
-
if (kind === "recorded") {
|
|
20634
|
-
const contentValue = field["content"];
|
|
20635
|
-
if (!Array.isArray(contentValue) || contentValue.length > 100) {
|
|
20636
|
-
throw new ProtocolMessageError("Invalid recorded activity content");
|
|
20637
|
-
}
|
|
20638
|
-
const detail = {
|
|
20639
|
-
content: contentValue.map((entry) => decodeRecordedAgentContentValue(entry)),
|
|
20640
|
-
input: readText(field, "input", AGENT_ACTIVITY_RECORDED_FIELD_LIMIT),
|
|
20641
|
-
kind,
|
|
20642
|
-
output: readText(field, "output", AGENT_ACTIVITY_RECORDED_FIELD_LIMIT)
|
|
20643
|
-
};
|
|
20644
|
-
if (JSON.stringify(detail).length > AGENT_ACTIVITY_RECORDED_DETAIL_LIMIT) {
|
|
20645
|
-
throw new ProtocolMessageError("Recorded activity detail is too large");
|
|
20646
|
-
}
|
|
20647
|
-
return detail;
|
|
20648
|
-
}
|
|
20649
|
-
throw new ProtocolMessageError("Invalid activity detail availability");
|
|
20650
|
-
}
|
|
20651
20541
|
function readIdentifier(value, key) {
|
|
20652
20542
|
try {
|
|
20653
20543
|
return decodeIdentifier(value[key]);
|
|
@@ -20772,82 +20662,6 @@ function decodeRuntimePongEvent(encoded) {
|
|
|
20772
20662
|
assertKind(value, RUNTIME_PONG_KIND);
|
|
20773
20663
|
return { kind: RUNTIME_PONG_KIND, requestId: readIdentifier(value, "requestId") };
|
|
20774
20664
|
}
|
|
20775
|
-
function decodeSessionStartedEvent(encoded) {
|
|
20776
|
-
const value = parseJson2(encoded);
|
|
20777
|
-
assertKind(value, SESSION_STARTED_KIND);
|
|
20778
|
-
const sequence = readSequence(value, "sequence");
|
|
20779
|
-
if (sequence !== 0) {
|
|
20780
|
-
throw new ProtocolMessageError("Invalid live start sequence");
|
|
20781
|
-
}
|
|
20782
|
-
return {
|
|
20783
|
-
commandId: readIdentifier(value, "commandId"),
|
|
20784
|
-
epoch: readIdentifier(value, "epoch"),
|
|
20785
|
-
kind: SESSION_STARTED_KIND,
|
|
20786
|
-
attemptId: readIdentifier(value, "attemptId"),
|
|
20787
|
-
prompt: readText(value, "prompt", MAX_PROMPT_LENGTH),
|
|
20788
|
-
sequence,
|
|
20789
|
-
sessionId: readIdentifier(value, "sessionId")
|
|
20790
|
-
};
|
|
20791
|
-
}
|
|
20792
|
-
function decodeAgentMessageDeltaEvent(encoded) {
|
|
20793
|
-
const value = parseJson2(encoded);
|
|
20794
|
-
assertKind(value, AGENT_MESSAGE_DELTA_KIND);
|
|
20795
|
-
const sequence = readSequence(value, "sequence");
|
|
20796
|
-
if (sequence === 0) {
|
|
20797
|
-
throw new ProtocolMessageError("Invalid live sequence");
|
|
20798
|
-
}
|
|
20799
|
-
return {
|
|
20800
|
-
commandId: readIdentifier(value, "commandId"),
|
|
20801
|
-
epoch: readIdentifier(value, "epoch"),
|
|
20802
|
-
kind: AGENT_MESSAGE_DELTA_KIND,
|
|
20803
|
-
messageId: value["messageId"] === void 0 ? "" : readText(value, "messageId", 255),
|
|
20804
|
-
sequence,
|
|
20805
|
-
sessionId: readIdentifier(value, "sessionId"),
|
|
20806
|
-
text: readString(value, "text", MAX_EVENT_TEXT_LENGTH)
|
|
20807
|
-
};
|
|
20808
|
-
}
|
|
20809
|
-
function decodeAgentActivityEvent(encoded) {
|
|
20810
|
-
const value = parseJson2(encoded);
|
|
20811
|
-
assertKind(value, AGENT_ACTIVITY_KIND);
|
|
20812
|
-
return {
|
|
20813
|
-
activityId: readIdentifier(value, "activityId"),
|
|
20814
|
-
activityType: readAllowedString(value, "activityType", ACTIVITY_TYPES),
|
|
20815
|
-
commandId: readIdentifier(value, "commandId"),
|
|
20816
|
-
content: readActivityContent(value),
|
|
20817
|
-
detail: readActivityDetail(value),
|
|
20818
|
-
input: readText(value, "input", AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
20819
|
-
kind: AGENT_ACTIVITY_KIND,
|
|
20820
|
-
locations: readLocations(value),
|
|
20821
|
-
name: readText(value, "name", 128),
|
|
20822
|
-
output: readText(value, "output", AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
20823
|
-
sequence: readSequence(value, "sequence"),
|
|
20824
|
-
sessionId: readIdentifier(value, "sessionId"),
|
|
20825
|
-
status: readAllowedString(value, "status", ACTIVITY_STATUSES),
|
|
20826
|
-
title: readString(value, "title", 500),
|
|
20827
|
-
toolKind: readAllowedString(value, "toolKind", TOOL_KINDS)
|
|
20828
|
-
};
|
|
20829
|
-
}
|
|
20830
|
-
function decodeSessionCompletedEvent(encoded) {
|
|
20831
|
-
const value = parseJson2(encoded);
|
|
20832
|
-
assertKind(value, SESSION_COMPLETED_KIND);
|
|
20833
|
-
return {
|
|
20834
|
-
commandId: readIdentifier(value, "commandId"),
|
|
20835
|
-
kind: SESSION_COMPLETED_KIND,
|
|
20836
|
-
sessionId: readIdentifier(value, "sessionId"),
|
|
20837
|
-
stopReason: readString(value, "stopReason", 64)
|
|
20838
|
-
};
|
|
20839
|
-
}
|
|
20840
|
-
function decodeSessionFailedEvent(encoded) {
|
|
20841
|
-
const value = parseJson2(encoded);
|
|
20842
|
-
assertKind(value, SESSION_FAILED_KIND);
|
|
20843
|
-
return {
|
|
20844
|
-
code: readIdentifier(value, "code"),
|
|
20845
|
-
commandId: readIdentifier(value, "commandId"),
|
|
20846
|
-
kind: SESSION_FAILED_KIND,
|
|
20847
|
-
message: readString(value, "message", 500),
|
|
20848
|
-
sessionId: readIdentifier(value, "sessionId")
|
|
20849
|
-
};
|
|
20850
|
-
}
|
|
20851
20665
|
function encodeSessionPromptCommand(message) {
|
|
20852
20666
|
return JSON.stringify(decodeSessionPromptCommand(JSON.stringify(message)));
|
|
20853
20667
|
}
|
|
@@ -20875,19 +20689,6 @@ function encodeRuntimePingCommand(message) {
|
|
|
20875
20689
|
function encodeRuntimePongEvent(message) {
|
|
20876
20690
|
return JSON.stringify(decodeRuntimePongEvent(JSON.stringify(message)));
|
|
20877
20691
|
}
|
|
20878
|
-
function decodeAgentActivityNarrationEvent(encoded) {
|
|
20879
|
-
const value = parseJson2(encoded);
|
|
20880
|
-
assertKind(value, AGENT_ACTIVITY_NARRATION_KIND);
|
|
20881
|
-
return {
|
|
20882
|
-
activityId: readIdentifier(value, "activityId"),
|
|
20883
|
-
activityType: readAllowedString(value, "activityType", NARRATION_ACTIVITY_TYPES),
|
|
20884
|
-
commandId: readIdentifier(value, "commandId"),
|
|
20885
|
-
kind: AGENT_ACTIVITY_NARRATION_KIND,
|
|
20886
|
-
sequence: readSequence(value, "sequence"),
|
|
20887
|
-
sessionId: readIdentifier(value, "sessionId"),
|
|
20888
|
-
text: readText(value, "text", MAX_EVENT_TEXT_LENGTH)
|
|
20889
|
-
};
|
|
20890
|
-
}
|
|
20891
20692
|
|
|
20892
20693
|
// ../protocol/src/session-history.ts
|
|
20893
20694
|
var SESSION_HISTORY_CHARACTER_LIMIT = 256e3;
|
|
@@ -21456,6 +21257,11 @@ var acpSessionUpdateV2Schema = external_exports.discriminatedUnion("sessionUpdat
|
|
|
21456
21257
|
}).readonly()
|
|
21457
21258
|
]);
|
|
21458
21259
|
var lifecycleBase = { commandId: identifierStringSchema };
|
|
21260
|
+
var promptExecutionContextV2Schema = external_exports.object({
|
|
21261
|
+
agentId: identifierStringSchema,
|
|
21262
|
+
directoryId: shortString,
|
|
21263
|
+
additionalDirectoryIds: external_exports.array(identifierStringSchema).max(16).readonly()
|
|
21264
|
+
}).readonly();
|
|
21459
21265
|
var lifecycleMetadataV2Schema = external_exports.discriminatedUnion("kind", [
|
|
21460
21266
|
external_exports.object({ kind: external_exports.literal("session.queue.changed") }).readonly(),
|
|
21461
21267
|
external_exports.object({ event: sessionPermissionRequestedEventSchema, kind: external_exports.literal("session.permission.requested") }).readonly(),
|
|
@@ -21465,7 +21271,8 @@ var lifecycleMetadataV2Schema = external_exports.discriminatedUnion("kind", [
|
|
|
21465
21271
|
external_exports.object({
|
|
21466
21272
|
...lifecycleBase,
|
|
21467
21273
|
content: external_exports.array(contentBlockV2Schema).min(1).max(100).readonly(),
|
|
21468
|
-
kind: external_exports.literal("prompt.requested")
|
|
21274
|
+
kind: external_exports.literal("prompt.requested"),
|
|
21275
|
+
context: promptExecutionContextV2Schema.optional()
|
|
21469
21276
|
}).readonly(),
|
|
21470
21277
|
external_exports.object({ ...lifecycleBase, attemptId: identifierStringSchema, epoch: identifierStringSchema, kind: external_exports.literal("prompt.started") }).readonly(),
|
|
21471
21278
|
external_exports.object({ ...lifecycleBase, kind: external_exports.literal("prompt.completed"), stopReason: shortString }).readonly(),
|
|
@@ -21529,12 +21336,12 @@ var sessionExportV2Schema = external_exports.object({
|
|
|
21529
21336
|
}).readonly().superRefine((session, context) => {
|
|
21530
21337
|
let previousPosition = 0n;
|
|
21531
21338
|
const eventIds = /* @__PURE__ */ new Set();
|
|
21532
|
-
for (const [
|
|
21339
|
+
for (const [index2, event] of session.events.entries()) {
|
|
21533
21340
|
if (event.sessionId !== session.sessionId) {
|
|
21534
21341
|
context.addIssue({
|
|
21535
21342
|
code: "custom",
|
|
21536
21343
|
message: "Exported event belongs to a different Session",
|
|
21537
|
-
path: ["events",
|
|
21344
|
+
path: ["events", index2, "sessionId"]
|
|
21538
21345
|
});
|
|
21539
21346
|
}
|
|
21540
21347
|
const position = BigInt(event.position);
|
|
@@ -21542,14 +21349,14 @@ var sessionExportV2Schema = external_exports.object({
|
|
|
21542
21349
|
context.addIssue({
|
|
21543
21350
|
code: "custom",
|
|
21544
21351
|
message: "Exported events are not in increasing position order",
|
|
21545
|
-
path: ["events",
|
|
21352
|
+
path: ["events", index2, "position"]
|
|
21546
21353
|
});
|
|
21547
21354
|
}
|
|
21548
21355
|
if (eventIds.has(event.eventId)) {
|
|
21549
21356
|
context.addIssue({
|
|
21550
21357
|
code: "custom",
|
|
21551
21358
|
message: "Exported event identities are not unique",
|
|
21552
|
-
path: ["events",
|
|
21359
|
+
path: ["events", index2, "eventId"]
|
|
21553
21360
|
});
|
|
21554
21361
|
}
|
|
21555
21362
|
previousPosition = position;
|
|
@@ -21600,98 +21407,11 @@ function decode5(value, schema) {
|
|
|
21600
21407
|
function encode4(value, schema) {
|
|
21601
21408
|
return JSON.stringify(decode5(value, schema));
|
|
21602
21409
|
}
|
|
21410
|
+
var decodeSessionEventV2 = (value) => decode5(value, sessionEventV2Schema);
|
|
21603
21411
|
var decodeSessionEventEnvelopeV2 = (value) => decode5(value, sessionEventEnvelopeV2Schema);
|
|
21604
21412
|
var encodeSessionEventEnvelopeV2 = (value) => encode4(value, sessionEventEnvelopeV2Schema);
|
|
21605
21413
|
var decodeAcpSessionUpdateV2 = (value) => decode5(value, acpSessionUpdateV2Schema);
|
|
21606
21414
|
|
|
21607
|
-
// ../protocol/src/session-events.ts
|
|
21608
|
-
var SESSION_EVENT_KIND = "session.event";
|
|
21609
|
-
var SESSION_FORKED_KIND = "session.forked";
|
|
21610
|
-
var MAX_RECORDED_EVENT_LENGTH = 8 * 1024 * 1024;
|
|
21611
|
-
var sessionEventEnvelopeSchema = external_exports.object({
|
|
21612
|
-
kind: external_exports.literal(SESSION_EVENT_KIND),
|
|
21613
|
-
payload: external_exports.string().min(2).max(MAX_RECORDED_EVENT_LENGTH),
|
|
21614
|
-
sessionId: identifierStringSchema
|
|
21615
|
-
}).readonly();
|
|
21616
|
-
var SESSION_QUEUE_CHANGED_KIND = "session.queue.changed";
|
|
21617
|
-
var sessionQueueChangedSchema = external_exports.object({ kind: external_exports.literal(SESSION_QUEUE_CHANGED_KIND), sessionId: identifierStringSchema }).readonly();
|
|
21618
|
-
var sessionForkedSchema = external_exports.object({
|
|
21619
|
-
kind: external_exports.literal(SESSION_FORKED_KIND),
|
|
21620
|
-
sessionId: identifierStringSchema,
|
|
21621
|
-
sourceSessionId: identifierStringSchema,
|
|
21622
|
-
throughCommandId: identifierStringSchema
|
|
21623
|
-
}).readonly();
|
|
21624
|
-
function decode6(encoded, schema) {
|
|
21625
|
-
let value;
|
|
21626
|
-
try {
|
|
21627
|
-
value = JSON.parse(encoded);
|
|
21628
|
-
} catch (cause) {
|
|
21629
|
-
throw new ProtocolMessageError("Message is not valid JSON", { cause });
|
|
21630
|
-
}
|
|
21631
|
-
const decoded = schema.safeParse(value);
|
|
21632
|
-
if (!decoded.success) {
|
|
21633
|
-
throw new ProtocolMessageError("Message does not match its schema", {
|
|
21634
|
-
cause: decoded.error
|
|
21635
|
-
});
|
|
21636
|
-
}
|
|
21637
|
-
return decoded.data;
|
|
21638
|
-
}
|
|
21639
|
-
var encode5 = (message, schema) => {
|
|
21640
|
-
const decoded = schema.safeParse(message);
|
|
21641
|
-
if (!decoded.success) {
|
|
21642
|
-
throw new ProtocolMessageError("Message does not match its schema", {
|
|
21643
|
-
cause: decoded.error
|
|
21644
|
-
});
|
|
21645
|
-
}
|
|
21646
|
-
return JSON.stringify(decoded.data);
|
|
21647
|
-
};
|
|
21648
|
-
var decodeSessionEventEnvelope = (encoded) => decode6(encoded, sessionEventEnvelopeSchema);
|
|
21649
|
-
var encodeSessionEventEnvelope = (message) => encode5(message, sessionEventEnvelopeSchema);
|
|
21650
|
-
function decodeRecordedSessionEvent(encoded) {
|
|
21651
|
-
const kind = decodeMessageKind(encoded);
|
|
21652
|
-
switch (kind) {
|
|
21653
|
-
case SESSION_QUEUE_CHANGED_KIND:
|
|
21654
|
-
return decode6(encoded, sessionQueueChangedSchema);
|
|
21655
|
-
case SESSION_FORKED_KIND:
|
|
21656
|
-
return decode6(encoded, sessionForkedSchema);
|
|
21657
|
-
case AGENT_ACTIVITY_KIND:
|
|
21658
|
-
return decodeAgentActivityEvent(encoded);
|
|
21659
|
-
case AGENT_ACTIVITY_NARRATION_KIND:
|
|
21660
|
-
return decodeAgentActivityNarrationEvent(encoded);
|
|
21661
|
-
case AGENT_CONTENT_KIND:
|
|
21662
|
-
return decodeAgentContentEvent(encoded);
|
|
21663
|
-
case AGENT_MESSAGE_DELTA_KIND:
|
|
21664
|
-
return decodeAgentMessageDeltaEvent(encoded);
|
|
21665
|
-
case SESSION_COMMANDS_UPDATED_KIND:
|
|
21666
|
-
return decodeSessionCommandsUpdatedEvent(encoded);
|
|
21667
|
-
case SESSION_COMPLETED_KIND:
|
|
21668
|
-
return decodeSessionCompletedEvent(encoded);
|
|
21669
|
-
case SESSION_CONFIG_UPDATED_KIND:
|
|
21670
|
-
return decodeSessionConfigUpdatedEvent(encoded);
|
|
21671
|
-
case SESSION_ELICITATION_REQUESTED_KIND:
|
|
21672
|
-
return decodeSessionElicitationRequestedEvent(encoded);
|
|
21673
|
-
case SESSION_ELICITATION_RESOLVED_KIND:
|
|
21674
|
-
return decodeSessionElicitationResolvedEvent(encoded);
|
|
21675
|
-
case SESSION_FAILED_KIND:
|
|
21676
|
-
return decodeSessionFailedEvent(encoded);
|
|
21677
|
-
case SESSION_INFO_UPDATED_KIND:
|
|
21678
|
-
return decodeSessionInfoUpdatedEvent(encoded);
|
|
21679
|
-
case SESSION_PERMISSION_REQUESTED_KIND:
|
|
21680
|
-
return decodeSessionPermissionRequestedEvent(encoded);
|
|
21681
|
-
case SESSION_PERMISSION_RESOLVED_KIND:
|
|
21682
|
-
return decodeSessionPermissionResolvedEvent(encoded);
|
|
21683
|
-
case SESSION_READY_KIND:
|
|
21684
|
-
return decodeSessionReadyEvent(encoded);
|
|
21685
|
-
case SESSION_STARTED_KIND:
|
|
21686
|
-
return decodeSessionStartedEvent(encoded);
|
|
21687
|
-
case SESSION_USAGE_UPDATED_KIND:
|
|
21688
|
-
return decodeSessionUsageUpdatedEvent(encoded);
|
|
21689
|
-
default:
|
|
21690
|
-
throw new UnsupportedProtocolMessageKindError("daemon-to-service", kind);
|
|
21691
|
-
}
|
|
21692
|
-
}
|
|
21693
|
-
var encodeRecordedSessionEvent = (event) => JSON.stringify(decodeRecordedSessionEvent(JSON.stringify(event)));
|
|
21694
|
-
|
|
21695
21415
|
// ../protocol/src/session-live-history.ts
|
|
21696
21416
|
var SESSION_LIVE_HISTORY_V2_PAGE_LOAD_KIND = "session.live-history.v2.page.load";
|
|
21697
21417
|
var SESSION_LIVE_HISTORY_V2_PAGE_LOADED_KIND = "session.live-history.v2.page.loaded";
|
|
@@ -21713,7 +21433,7 @@ var sessionLiveHistoryV2PageLoadedSchema = external_exports.object({
|
|
|
21713
21433
|
requestId: identifierStringSchema,
|
|
21714
21434
|
sessionId: identifierStringSchema
|
|
21715
21435
|
}).readonly();
|
|
21716
|
-
function
|
|
21436
|
+
function decode6(schema, encoded) {
|
|
21717
21437
|
try {
|
|
21718
21438
|
const value = JSON.parse(encoded);
|
|
21719
21439
|
return schema.parse(value);
|
|
@@ -21721,8 +21441,8 @@ function decode7(schema, encoded) {
|
|
|
21721
21441
|
throw new ProtocolMessageError("Invalid live Session history message", { cause });
|
|
21722
21442
|
}
|
|
21723
21443
|
}
|
|
21724
|
-
var decodeSessionLiveHistoryV2PageLoad = (encoded) =>
|
|
21725
|
-
var decodeSessionLiveHistoryV2PageLoaded = (encoded) =>
|
|
21444
|
+
var decodeSessionLiveHistoryV2PageLoad = (encoded) => decode6(sessionLiveHistoryV2PageLoadSchema, encoded);
|
|
21445
|
+
var decodeSessionLiveHistoryV2PageLoaded = (encoded) => decode6(sessionLiveHistoryV2PageLoadedSchema, encoded);
|
|
21726
21446
|
var encodeSessionLiveHistoryV2PageLoad = (value) => JSON.stringify(sessionLiveHistoryV2PageLoadSchema.parse(value));
|
|
21727
21447
|
var encodeSessionLiveHistoryV2PageLoaded = (value) => JSON.stringify(sessionLiveHistoryV2PageLoadedSchema.parse(value));
|
|
21728
21448
|
|
|
@@ -21836,6 +21556,11 @@ function decodeServiceToDaemonMessage(encoded) {
|
|
|
21836
21556
|
return signature.decoder(encoded);
|
|
21837
21557
|
}
|
|
21838
21558
|
var daemonToServiceSignatures = {
|
|
21559
|
+
[SESSION_CONFIG_UPDATED_KIND]: defineMessageSignature(
|
|
21560
|
+
SESSION_CONFIG_UPDATED_KIND,
|
|
21561
|
+
encodeSessionConfigUpdatedEvent,
|
|
21562
|
+
decodeSessionConfigUpdatedEvent
|
|
21563
|
+
),
|
|
21839
21564
|
[AGENT_INSTALL_CANCELLED_KIND]: defineMessageSignature(
|
|
21840
21565
|
AGENT_INSTALL_CANCELLED_KIND,
|
|
21841
21566
|
encodeAgentInstallCancelledEvent,
|
|
@@ -21906,11 +21631,6 @@ var daemonToServiceSignatures = {
|
|
|
21906
21631
|
decodeRuntimeHeartbeatEvent
|
|
21907
21632
|
),
|
|
21908
21633
|
[RUNTIME_PONG_KIND]: defineMessageSignature(RUNTIME_PONG_KIND, encodeRuntimePongEvent, decodeRuntimePongEvent),
|
|
21909
|
-
[SESSION_EVENT_KIND]: defineMessageSignature(
|
|
21910
|
-
SESSION_EVENT_KIND,
|
|
21911
|
-
encodeSessionEventEnvelope,
|
|
21912
|
-
decodeSessionEventEnvelope
|
|
21913
|
-
),
|
|
21914
21634
|
[SESSION_EVENT_V2_KIND]: defineMessageSignature(
|
|
21915
21635
|
SESSION_EVENT_V2_KIND,
|
|
21916
21636
|
encodeSessionEventEnvelopeV2,
|
|
@@ -22915,7 +22635,7 @@ function startsWith(bytes, signature, offset = 0) {
|
|
|
22915
22635
|
if (bytes.byteLength < offset + signature.byteLength) {
|
|
22916
22636
|
return false;
|
|
22917
22637
|
}
|
|
22918
|
-
return signature.every((value,
|
|
22638
|
+
return signature.every((value, index2) => bytes[offset + index2] === value);
|
|
22919
22639
|
}
|
|
22920
22640
|
function sniffRasterMime(bytes) {
|
|
22921
22641
|
if (startsWith(bytes, PNG_SIGNATURE)) {
|
|
@@ -23043,7 +22763,7 @@ function startsWith2(bytes, signature, offset = 0) {
|
|
|
23043
22763
|
if (bytes.byteLength < offset + signature.byteLength) {
|
|
23044
22764
|
return false;
|
|
23045
22765
|
}
|
|
23046
|
-
return signature.every((value,
|
|
22766
|
+
return signature.every((value, index2) => bytes[offset + index2] === value);
|
|
23047
22767
|
}
|
|
23048
22768
|
function sniffVideoMime(bytes) {
|
|
23049
22769
|
if (startsWith2(bytes, MP4_FILE_TYPE, 4)) {
|
|
@@ -23172,10 +22892,10 @@ async function replaceImageMarkers(text2, replace) {
|
|
|
23172
22892
|
let cursor = 0;
|
|
23173
22893
|
let rewritten = "";
|
|
23174
22894
|
for (const match of matches) {
|
|
23175
|
-
const
|
|
23176
|
-
rewritten += text2.slice(cursor,
|
|
22895
|
+
const index2 = match.index ?? 0;
|
|
22896
|
+
rewritten += text2.slice(cursor, index2);
|
|
23177
22897
|
rewritten += await replace(match[1] ?? "");
|
|
23178
|
-
cursor =
|
|
22898
|
+
cursor = index2 + match[0].length;
|
|
23179
22899
|
}
|
|
23180
22900
|
return `${rewritten}${text2.slice(cursor)}`;
|
|
23181
22901
|
}
|
|
@@ -24493,9 +24213,9 @@ function historyContentCharacters(messages) {
|
|
|
24493
24213
|
var AcpHistoryReplay = class {
|
|
24494
24214
|
#activities = /* @__PURE__ */ new Map();
|
|
24495
24215
|
#messages = [];
|
|
24496
|
-
#events
|
|
24497
|
-
#records = [];
|
|
24216
|
+
#events;
|
|
24498
24217
|
#turnActivityIds = /* @__PURE__ */ new Set();
|
|
24218
|
+
#sessionId;
|
|
24499
24219
|
#activityTracker = new AcpActivityTracker(
|
|
24500
24220
|
async (activity2) => {
|
|
24501
24221
|
this.#activities.set(activity2.activityId, activity2);
|
|
@@ -24516,10 +24236,16 @@ var AcpHistoryReplay = class {
|
|
|
24516
24236
|
#firstMessageIndex = 0;
|
|
24517
24237
|
#characters = 0;
|
|
24518
24238
|
#truncated = false;
|
|
24239
|
+
constructor(events, sessionId) {
|
|
24240
|
+
this.#events = events;
|
|
24241
|
+
this.#sessionId = sessionId;
|
|
24242
|
+
}
|
|
24519
24243
|
record = async (update, rawUpdate, onRecorded = () => Promise.resolve()) => {
|
|
24520
|
-
this.#
|
|
24521
|
-
|
|
24522
|
-
await
|
|
24244
|
+
const position = this.#events.append(this.#sessionId, { payload: rawUpdate, type: "acp" });
|
|
24245
|
+
await onRecorded(position);
|
|
24246
|
+
return await this.#applyUpdate(update, position);
|
|
24247
|
+
};
|
|
24248
|
+
#applyUpdate = async (update, position) => {
|
|
24523
24249
|
if (update.sessionUpdate === "agent_thought_chunk") {
|
|
24524
24250
|
if (update.content.type === "text") {
|
|
24525
24251
|
await this.#activityTracker.recordNarrative(
|
|
@@ -24528,30 +24254,30 @@ var AcpHistoryReplay = class {
|
|
|
24528
24254
|
update.content.text
|
|
24529
24255
|
);
|
|
24530
24256
|
}
|
|
24531
|
-
return
|
|
24257
|
+
return position;
|
|
24532
24258
|
}
|
|
24533
24259
|
if (update.sessionUpdate === "tool_call") {
|
|
24534
24260
|
await this.#activityTracker.recordToolCall(update);
|
|
24535
|
-
return
|
|
24261
|
+
return position;
|
|
24536
24262
|
}
|
|
24537
24263
|
if (update.sessionUpdate === "tool_call_update") {
|
|
24538
24264
|
await this.#activityTracker.recordToolCallUpdate(update);
|
|
24539
|
-
return
|
|
24265
|
+
return position;
|
|
24540
24266
|
}
|
|
24541
24267
|
if (update.sessionUpdate === "plan") {
|
|
24542
24268
|
await this.#activityTracker.recordPlan(update);
|
|
24543
|
-
return
|
|
24269
|
+
return position;
|
|
24544
24270
|
}
|
|
24545
24271
|
if (update.sessionUpdate === "plan_update") {
|
|
24546
24272
|
await this.#activityTracker.recordPlanUpdate(update);
|
|
24547
|
-
return
|
|
24273
|
+
return position;
|
|
24548
24274
|
}
|
|
24549
24275
|
if (update.sessionUpdate === "plan_removed") {
|
|
24550
24276
|
await this.#activityTracker.removePlan(update);
|
|
24551
|
-
return
|
|
24277
|
+
return position;
|
|
24552
24278
|
}
|
|
24553
24279
|
if (update.sessionUpdate !== "user_message_chunk" && update.sessionUpdate !== "agent_message_chunk") {
|
|
24554
|
-
return
|
|
24280
|
+
return position;
|
|
24555
24281
|
}
|
|
24556
24282
|
if (update.sessionUpdate === "agent_message_chunk" && isProgressMessage(update)) {
|
|
24557
24283
|
if (update.content.type === "text") {
|
|
@@ -24561,18 +24287,18 @@ var AcpHistoryReplay = class {
|
|
|
24561
24287
|
update.content.text
|
|
24562
24288
|
);
|
|
24563
24289
|
}
|
|
24564
|
-
return
|
|
24290
|
+
return position;
|
|
24565
24291
|
}
|
|
24566
24292
|
const role = update.sessionUpdate === "user_message_chunk" ? "user" : "assistant";
|
|
24567
24293
|
const content = update.content;
|
|
24568
24294
|
if (role === "assistant" && content.type !== "text") {
|
|
24569
24295
|
await this.#activityTracker.finishNarrative();
|
|
24570
24296
|
this.recordAssistantContent(update.messageId ?? null, normalizeContentBlock(content));
|
|
24571
|
-
return
|
|
24297
|
+
return position;
|
|
24572
24298
|
}
|
|
24573
24299
|
const text2 = content.type === "text" ? content.text : content.type === "image" ? content.data.length > 0 ? `[@image](data:${content.mimeType};base64,${content.data})` : content.uri != null && content.uri.length > 0 ? `[@image](${content.uri})` : "[image attachment]" : `[${content.type} attachment]`;
|
|
24574
24300
|
if (text2.length === 0) {
|
|
24575
|
-
return
|
|
24301
|
+
return position;
|
|
24576
24302
|
}
|
|
24577
24303
|
const previous = this.#messages.at(-1);
|
|
24578
24304
|
const id = update.messageId ?? null;
|
|
@@ -24599,41 +24325,32 @@ var AcpHistoryReplay = class {
|
|
|
24599
24325
|
this.#characters += bounded2.length;
|
|
24600
24326
|
this.#lastMessageId = id;
|
|
24601
24327
|
this.trimMessages();
|
|
24602
|
-
return
|
|
24328
|
+
return position;
|
|
24603
24329
|
};
|
|
24604
24330
|
recordLifecycle = (event) => {
|
|
24605
24331
|
if (event.type !== "lifecycle-metadata") {
|
|
24606
24332
|
throw new Error("Lifecycle history only accepts lifecycle metadata");
|
|
24607
24333
|
}
|
|
24608
|
-
this.#
|
|
24609
|
-
this.#events.push(event);
|
|
24610
|
-
return this.#events.length;
|
|
24334
|
+
return this.#events.append(this.#sessionId, event);
|
|
24611
24335
|
};
|
|
24612
|
-
eventCount = () => this.#events.length;
|
|
24613
24336
|
append = async (replay) => {
|
|
24614
|
-
|
|
24615
|
-
|
|
24616
|
-
|
|
24617
|
-
} else {
|
|
24618
|
-
this.recordLifecycle(record2.event);
|
|
24619
|
-
}
|
|
24337
|
+
await replay.#activityTracker.finish();
|
|
24338
|
+
for (const [activityId, activity2] of replay.#activities) {
|
|
24339
|
+
this.#activities.set(activityId, activity2);
|
|
24620
24340
|
}
|
|
24621
|
-
|
|
24622
|
-
|
|
24623
|
-
|
|
24624
|
-
const parsedCursor = cursor === null ? events.length : Number(cursor);
|
|
24625
|
-
if (!Number.isSafeInteger(parsedCursor) || parsedCursor < 0 || parsedCursor > events.length) {
|
|
24626
|
-
throw new Error("The native event cursor is invalid");
|
|
24341
|
+
for (const message of replay.#messages.slice(replay.#firstMessageIndex)) {
|
|
24342
|
+
this.#messages.push(message);
|
|
24343
|
+
this.#characters += message.text.length;
|
|
24627
24344
|
}
|
|
24628
|
-
|
|
24629
|
-
|
|
24630
|
-
|
|
24631
|
-
|
|
24632
|
-
|
|
24633
|
-
|
|
24634
|
-
|
|
24635
|
-
};
|
|
24345
|
+
this.#turnActivityIds.clear();
|
|
24346
|
+
for (const activityId of replay.#turnActivityIds) {
|
|
24347
|
+
this.#turnActivityIds.add(activityId);
|
|
24348
|
+
}
|
|
24349
|
+
this.#lastMessageId = replay.#lastMessageId;
|
|
24350
|
+
this.#truncated ||= replay.#truncated;
|
|
24351
|
+
this.trimMessages();
|
|
24636
24352
|
};
|
|
24353
|
+
eventPage = (eventLimit, cursor) => this.#events.page(this.#sessionId, eventLimit, cursor);
|
|
24637
24354
|
snapshot = async () => {
|
|
24638
24355
|
await this.#activityTracker.finish();
|
|
24639
24356
|
const messages = this.#messages.slice(this.#firstMessageIndex).map((message) => {
|
|
@@ -25266,9 +24983,7 @@ var AcpSessionInteractions = class {
|
|
|
25266
24983
|
};
|
|
25267
24984
|
|
|
25268
24985
|
// src/acp/session-store.ts
|
|
25269
|
-
import {
|
|
25270
|
-
import { dirname } from "node:path";
|
|
25271
|
-
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
24986
|
+
import { randomUUID } from "node:crypto";
|
|
25272
24987
|
|
|
25273
24988
|
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/entity.js
|
|
25274
24989
|
var entityKind = /* @__PURE__ */ Symbol.for("drizzle:entityKind");
|
|
@@ -26384,7 +26099,7 @@ function haveSameKeys(left, right) {
|
|
|
26384
26099
|
const leftKeys = Object.keys(left);
|
|
26385
26100
|
const rightKeys = Object.keys(right);
|
|
26386
26101
|
if (leftKeys.length !== rightKeys.length) return false;
|
|
26387
|
-
for (const [
|
|
26102
|
+
for (const [index2, key] of leftKeys.entries()) if (key !== rightKeys[index2]) return false;
|
|
26388
26103
|
return true;
|
|
26389
26104
|
}
|
|
26390
26105
|
function mapUpdateSet(table, values) {
|
|
@@ -27137,195 +26852,6 @@ var NoopLogger = class {
|
|
|
27137
26852
|
}
|
|
27138
26853
|
};
|
|
27139
26854
|
|
|
27140
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/query-builders/count.js
|
|
27141
|
-
var SQLiteCountBuilder = class SQLiteCountBuilder2 extends SQL {
|
|
27142
|
-
static [entityKind] = "SQLiteCountBuilder";
|
|
27143
|
-
dialect;
|
|
27144
|
-
session;
|
|
27145
|
-
static buildCount(source, filters, parens) {
|
|
27146
|
-
const query = sql`select count(*) from ${source}${sql` where ${filters}`.if(filters)}`;
|
|
27147
|
-
return parens ? sql`(${query})` : query;
|
|
27148
|
-
}
|
|
27149
|
-
constructor(countConfig) {
|
|
27150
|
-
super(SQLiteCountBuilder2.buildCount(countConfig.source, countConfig.filters, true).queryChunks);
|
|
27151
|
-
this.countConfig = countConfig;
|
|
27152
|
-
this.dialect = countConfig.dialect;
|
|
27153
|
-
this.session = countConfig.session;
|
|
27154
|
-
this.mapWith((e) => {
|
|
27155
|
-
if (typeof e === "number") return e;
|
|
27156
|
-
return Number(e ?? 0);
|
|
27157
|
-
});
|
|
27158
|
-
}
|
|
27159
|
-
executableSql;
|
|
27160
|
-
build() {
|
|
27161
|
-
if (!this.executableSql) {
|
|
27162
|
-
const { source, filters } = this.countConfig;
|
|
27163
|
-
this.executableSql = SQLiteCountBuilder2.buildCount(source, filters);
|
|
27164
|
-
}
|
|
27165
|
-
return this.dialect.sqlToQuery(this.executableSql);
|
|
27166
|
-
}
|
|
27167
|
-
};
|
|
27168
|
-
|
|
27169
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/async/count.js
|
|
27170
|
-
var SQLiteAsyncCountBuilder = class extends SQLiteCountBuilder {
|
|
27171
|
-
static [entityKind] = "SQLiteAsyncCountBuilder";
|
|
27172
|
-
constructor(countConfig) {
|
|
27173
|
-
super(countConfig);
|
|
27174
|
-
}
|
|
27175
|
-
/** @internal */
|
|
27176
|
-
executeRaw(placeholderValues) {
|
|
27177
|
-
return this.session.prepareQuery(this.build(), "arrays", false, "all", (rows) => {
|
|
27178
|
-
const v = rows[0]?.[0];
|
|
27179
|
-
if (typeof v === "number") return v;
|
|
27180
|
-
return v ? Number(v) : 0;
|
|
27181
|
-
}).execute(placeholderValues);
|
|
27182
|
-
}
|
|
27183
|
-
async execute(placeholderValues) {
|
|
27184
|
-
return await this.executeRaw(placeholderValues);
|
|
27185
|
-
}
|
|
27186
|
-
};
|
|
27187
|
-
applyMixins(SQLiteAsyncCountBuilder, [QueryPromise]);
|
|
27188
|
-
var SQLiteSyncCountBuilder = class extends SQLiteAsyncCountBuilder {
|
|
27189
|
-
static [entityKind] = "SQLiteSyncCountBuilder";
|
|
27190
|
-
sync(placeholderValues) {
|
|
27191
|
-
return this.executeRaw(placeholderValues).sync();
|
|
27192
|
-
}
|
|
27193
|
-
};
|
|
27194
|
-
|
|
27195
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/query-builders/query.js
|
|
27196
|
-
var RelationalQueryBuilder = class {
|
|
27197
|
-
static [entityKind] = "SQLiteRelationalQueryBuilderV2";
|
|
27198
|
-
constructor(mode, schema, table, tableConfig, dialect, session, forbidJsonb, builder = SQLiteRelationalQuery) {
|
|
27199
|
-
this.mode = mode;
|
|
27200
|
-
this.schema = schema;
|
|
27201
|
-
this.table = table;
|
|
27202
|
-
this.tableConfig = tableConfig;
|
|
27203
|
-
this.dialect = dialect;
|
|
27204
|
-
this.session = session;
|
|
27205
|
-
this.forbidJsonb = forbidJsonb;
|
|
27206
|
-
this.builder = builder;
|
|
27207
|
-
}
|
|
27208
|
-
findMany(config2) {
|
|
27209
|
-
return new this.builder(this.mode, this.schema, this.table, this.tableConfig, this.dialect, this.session, config2 ?? true, "many", this.forbidJsonb);
|
|
27210
|
-
}
|
|
27211
|
-
findFirst(config2) {
|
|
27212
|
-
return new this.builder(this.mode, this.schema, this.table, this.tableConfig, this.dialect, this.session, config2 ?? true, "first", this.forbidJsonb);
|
|
27213
|
-
}
|
|
27214
|
-
};
|
|
27215
|
-
var SQLiteRelationalQuery = class {
|
|
27216
|
-
static [entityKind] = "SQLiteRelationalQueryV2";
|
|
27217
|
-
/** @internal */
|
|
27218
|
-
mode;
|
|
27219
|
-
/** @internal */
|
|
27220
|
-
table;
|
|
27221
|
-
/** @internal */
|
|
27222
|
-
resultKind;
|
|
27223
|
-
constructor(resultKind, schema, table, tableConfig, dialect, session, config2, mode, forbidJsonb) {
|
|
27224
|
-
this.schema = schema;
|
|
27225
|
-
this.tableConfig = tableConfig;
|
|
27226
|
-
this.dialect = dialect;
|
|
27227
|
-
this.session = session;
|
|
27228
|
-
this.config = config2;
|
|
27229
|
-
this.forbidJsonb = forbidJsonb;
|
|
27230
|
-
this.resultKind = resultKind;
|
|
27231
|
-
this.mode = mode;
|
|
27232
|
-
this.table = table;
|
|
27233
|
-
}
|
|
27234
|
-
getSQL() {
|
|
27235
|
-
return this._getQuery().sql;
|
|
27236
|
-
}
|
|
27237
|
-
_getQuery() {
|
|
27238
|
-
const jsonb = this.forbidJsonb ? sql`json` : sql`jsonb`;
|
|
27239
|
-
return this.dialect.buildRelationalQuery({
|
|
27240
|
-
schema: this.schema,
|
|
27241
|
-
table: this.table,
|
|
27242
|
-
tableConfig: this.tableConfig,
|
|
27243
|
-
queryConfig: this.config,
|
|
27244
|
-
mode: this.mode,
|
|
27245
|
-
jsonb
|
|
27246
|
-
});
|
|
27247
|
-
}
|
|
27248
|
-
_toSQL() {
|
|
27249
|
-
const query = this._getQuery();
|
|
27250
|
-
return {
|
|
27251
|
-
query,
|
|
27252
|
-
builtQuery: this.dialect.sqlToQuery(query.sql)
|
|
27253
|
-
};
|
|
27254
|
-
}
|
|
27255
|
-
toSQL() {
|
|
27256
|
-
return this._toSQL().builtQuery;
|
|
27257
|
-
}
|
|
27258
|
-
};
|
|
27259
|
-
|
|
27260
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/async/query.js
|
|
27261
|
-
var SQLiteAsyncRelationalQuery = class extends SQLiteRelationalQuery {
|
|
27262
|
-
static [entityKind] = "SQLiteAsyncRelationalQueryV2";
|
|
27263
|
-
/** @internal */
|
|
27264
|
-
_prepare(prepare = false) {
|
|
27265
|
-
const { query, builtQuery } = this._toSQL();
|
|
27266
|
-
const mapper = this.dialect.mapperGenerators.relationalRows({
|
|
27267
|
-
isFirst: this.mode === "first",
|
|
27268
|
-
parseJson: true,
|
|
27269
|
-
parseJsonIfString: false,
|
|
27270
|
-
rootJsonMappers: false,
|
|
27271
|
-
selection: query.selection,
|
|
27272
|
-
arrayModeRoot: true
|
|
27273
|
-
});
|
|
27274
|
-
return this.session.prepareQuery(builtQuery, "arrays", prepare, "all", mapper);
|
|
27275
|
-
}
|
|
27276
|
-
prepare() {
|
|
27277
|
-
return this._prepare(true);
|
|
27278
|
-
}
|
|
27279
|
-
async execute(placeholderValues) {
|
|
27280
|
-
return this._prepare().execute(placeholderValues);
|
|
27281
|
-
}
|
|
27282
|
-
};
|
|
27283
|
-
var SQLiteSyncRelationalQuery = class extends SQLiteAsyncRelationalQuery {
|
|
27284
|
-
static [entityKind] = "SQLiteSyncRelationalQueryV2";
|
|
27285
|
-
sync(placeholderValues) {
|
|
27286
|
-
return this._prepare().execute(placeholderValues).sync();
|
|
27287
|
-
}
|
|
27288
|
-
};
|
|
27289
|
-
applyMixins(SQLiteAsyncRelationalQuery, [QueryPromise]);
|
|
27290
|
-
|
|
27291
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/selection-proxy.js
|
|
27292
|
-
var SelectionProxyHandler = class SelectionProxyHandler2 {
|
|
27293
|
-
static [entityKind] = "SelectionProxyHandler";
|
|
27294
|
-
config;
|
|
27295
|
-
constructor(config2) {
|
|
27296
|
-
this.config = { ...config2 };
|
|
27297
|
-
}
|
|
27298
|
-
get(subquery, prop) {
|
|
27299
|
-
if (prop === "_") return {
|
|
27300
|
-
...subquery["_"],
|
|
27301
|
-
selectedFields: new Proxy(subquery._.selectedFields, this)
|
|
27302
|
-
};
|
|
27303
|
-
if (prop === ViewBaseConfig) return {
|
|
27304
|
-
...subquery[ViewBaseConfig],
|
|
27305
|
-
selectedFields: new Proxy(subquery[ViewBaseConfig].selectedFields, this)
|
|
27306
|
-
};
|
|
27307
|
-
if (typeof prop === "symbol") return subquery[prop];
|
|
27308
|
-
const value = (is(subquery, Subquery) ? subquery._.selectedFields : is(subquery, View) ? subquery[ViewBaseConfig].selectedFields : subquery)[prop];
|
|
27309
|
-
if (is(value, SQL.Aliased)) {
|
|
27310
|
-
if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) return value.sql;
|
|
27311
|
-
const newValue = value.clone();
|
|
27312
|
-
newValue.isSelectionField = true;
|
|
27313
|
-
newValue.origin = this.config.alias;
|
|
27314
|
-
return newValue;
|
|
27315
|
-
}
|
|
27316
|
-
if (is(value, SQL)) {
|
|
27317
|
-
if (this.config.sqlBehavior === "sql") return value;
|
|
27318
|
-
throw new Error(`You tried to reference "${prop}" field from a subquery, which is a raw SQL field, but it doesn't have an alias declared. Please add an alias to the field using ".as('alias')" method.`);
|
|
27319
|
-
}
|
|
27320
|
-
if (is(value, Column)) {
|
|
27321
|
-
if (this.config.alias) return new Proxy(value, new ColumnTableAliasProxyHandler(new Proxy(value.table, new TableAliasProxyHandler(this.config.alias, this.config.replaceOriginalName ?? false, true)), true));
|
|
27322
|
-
return value;
|
|
27323
|
-
}
|
|
27324
|
-
if (typeof value !== "object" || value === null) return value;
|
|
27325
|
-
return new Proxy(value, new SelectionProxyHandler2(this.config));
|
|
27326
|
-
}
|
|
27327
|
-
};
|
|
27328
|
-
|
|
27329
26855
|
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/foreign-keys.js
|
|
27330
26856
|
var ForeignKeyBuilder = class {
|
|
27331
26857
|
static [entityKind] = "SQLiteForeignKeyBuilder";
|
|
@@ -27890,130 +27416,144 @@ function sqliteTableWithCasing(casing) {
|
|
|
27890
27416
|
}
|
|
27891
27417
|
var sqliteTable = sqliteTableWithCasing(void 0);
|
|
27892
27418
|
|
|
27893
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/
|
|
27894
|
-
|
|
27895
|
-
|
|
27896
|
-
|
|
27897
|
-
|
|
27898
|
-
|
|
27899
|
-
}
|
|
27900
|
-
|
|
27901
|
-
|
|
27902
|
-
|
|
27903
|
-
|
|
27419
|
+
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/indexes.js
|
|
27420
|
+
var IndexBuilderOn = class {
|
|
27421
|
+
static [entityKind] = "SQLiteIndexBuilderOn";
|
|
27422
|
+
constructor(name2, unique) {
|
|
27423
|
+
this.name = name2;
|
|
27424
|
+
this.unique = unique;
|
|
27425
|
+
}
|
|
27426
|
+
on(...columns) {
|
|
27427
|
+
return new IndexBuilder(this.name, columns, this.unique);
|
|
27428
|
+
}
|
|
27429
|
+
};
|
|
27430
|
+
var IndexBuilder = class {
|
|
27431
|
+
static [entityKind] = "SQLiteIndexBuilder";
|
|
27904
27432
|
/** @internal */
|
|
27905
27433
|
config;
|
|
27906
|
-
constructor(
|
|
27907
|
-
this.table = table;
|
|
27908
|
-
this.session = session;
|
|
27909
|
-
this.dialect = dialect;
|
|
27434
|
+
constructor(name2, columns, unique) {
|
|
27910
27435
|
this.config = {
|
|
27911
|
-
|
|
27912
|
-
|
|
27436
|
+
name: name2,
|
|
27437
|
+
columns,
|
|
27438
|
+
unique,
|
|
27439
|
+
where: void 0
|
|
27913
27440
|
};
|
|
27914
27441
|
}
|
|
27915
27442
|
/**
|
|
27916
|
-
*
|
|
27917
|
-
*
|
|
27918
|
-
* Calling this method will delete only those rows that fulfill a specified condition.
|
|
27919
|
-
*
|
|
27920
|
-
* See docs: {@link https://orm.drizzle.team/docs/delete}
|
|
27921
|
-
*
|
|
27922
|
-
* @param where the `where` clause.
|
|
27923
|
-
*
|
|
27924
|
-
* @example
|
|
27925
|
-
* You can use conditional operators and `sql function` to filter the rows to be deleted.
|
|
27926
|
-
*
|
|
27927
|
-
* ```ts
|
|
27928
|
-
* // Delete all cars with green color
|
|
27929
|
-
* db.delete(cars).where(eq(cars.color, 'green'));
|
|
27930
|
-
* // or
|
|
27931
|
-
* db.delete(cars).where(sql`${cars.color} = 'green'`)
|
|
27932
|
-
* ```
|
|
27933
|
-
*
|
|
27934
|
-
* You can logically combine conditional operators with `and()` and `or()` operators:
|
|
27935
|
-
*
|
|
27936
|
-
* ```ts
|
|
27937
|
-
* // Delete all BMW cars with a green color
|
|
27938
|
-
* db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
|
27939
|
-
*
|
|
27940
|
-
* // Delete all cars with the green or blue color
|
|
27941
|
-
* db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
27942
|
-
* ```
|
|
27443
|
+
* Condition for partial index.
|
|
27943
27444
|
*/
|
|
27944
|
-
where(
|
|
27945
|
-
this.config.where =
|
|
27946
|
-
return this;
|
|
27947
|
-
}
|
|
27948
|
-
orderBy(...columns) {
|
|
27949
|
-
if (typeof columns[0] === "function") {
|
|
27950
|
-
const orderBy = columns[0](new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
|
|
27951
|
-
sqlAliasedBehavior: "alias",
|
|
27952
|
-
sqlBehavior: "sql"
|
|
27953
|
-
})));
|
|
27954
|
-
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
27955
|
-
this.config.orderBy = orderByArray;
|
|
27956
|
-
} else {
|
|
27957
|
-
const orderByArray = columns;
|
|
27958
|
-
this.config.orderBy = orderByArray;
|
|
27959
|
-
}
|
|
27960
|
-
return this;
|
|
27961
|
-
}
|
|
27962
|
-
limit(limit) {
|
|
27963
|
-
this.config.limit = limit;
|
|
27445
|
+
where(condition) {
|
|
27446
|
+
this.config.where = condition;
|
|
27964
27447
|
return this;
|
|
27965
27448
|
}
|
|
27966
|
-
|
|
27967
|
-
|
|
27968
|
-
return this;
|
|
27969
|
-
}
|
|
27970
|
-
getSQL() {
|
|
27971
|
-
return this.dialect.buildDeleteQuery(this.config);
|
|
27972
|
-
}
|
|
27973
|
-
toSQL() {
|
|
27974
|
-
return this.dialect.sqlToQuery(this.getSQL());
|
|
27449
|
+
/** @internal */
|
|
27450
|
+
build(table) {
|
|
27451
|
+
return new Index(this.config, table);
|
|
27975
27452
|
}
|
|
27976
|
-
|
|
27977
|
-
|
|
27453
|
+
};
|
|
27454
|
+
var Index = class {
|
|
27455
|
+
static [entityKind] = "SQLiteIndex";
|
|
27456
|
+
config;
|
|
27457
|
+
isNameExplicit;
|
|
27458
|
+
constructor(config2, table) {
|
|
27459
|
+
this.config = {
|
|
27460
|
+
...config2,
|
|
27461
|
+
table
|
|
27462
|
+
};
|
|
27463
|
+
this.isNameExplicit = !!config2.name;
|
|
27978
27464
|
}
|
|
27979
27465
|
};
|
|
27466
|
+
function index(name2) {
|
|
27467
|
+
return new IndexBuilderOn(name2, false);
|
|
27468
|
+
}
|
|
27980
27469
|
|
|
27981
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/
|
|
27982
|
-
|
|
27983
|
-
|
|
27470
|
+
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/primary-keys.js
|
|
27471
|
+
function primaryKey(...config2) {
|
|
27472
|
+
if (config2[0].columns) return new PrimaryKeyBuilder(config2[0].columns, config2[0].name);
|
|
27473
|
+
return new PrimaryKeyBuilder(config2);
|
|
27474
|
+
}
|
|
27475
|
+
var PrimaryKeyBuilder = class {
|
|
27476
|
+
static [entityKind] = "SQLitePrimaryKeyBuilder";
|
|
27984
27477
|
/** @internal */
|
|
27985
|
-
|
|
27986
|
-
|
|
27987
|
-
|
|
27988
|
-
|
|
27989
|
-
|
|
27478
|
+
columns;
|
|
27479
|
+
/** @internal */
|
|
27480
|
+
name;
|
|
27481
|
+
constructor(columns, name2) {
|
|
27482
|
+
this.columns = columns;
|
|
27483
|
+
this.name = name2;
|
|
27990
27484
|
}
|
|
27991
|
-
|
|
27992
|
-
|
|
27485
|
+
/** @internal */
|
|
27486
|
+
build(table) {
|
|
27487
|
+
return new PrimaryKey(table, this.columns, this.name);
|
|
27993
27488
|
}
|
|
27994
|
-
|
|
27995
|
-
|
|
27996
|
-
|
|
27997
|
-
|
|
27998
|
-
|
|
27999
|
-
|
|
28000
|
-
|
|
28001
|
-
|
|
28002
|
-
|
|
28003
|
-
|
|
28004
|
-
|
|
28005
|
-
}
|
|
28006
|
-
|
|
28007
|
-
return this.
|
|
27489
|
+
};
|
|
27490
|
+
var PrimaryKey = class {
|
|
27491
|
+
static [entityKind] = "SQLitePrimaryKey";
|
|
27492
|
+
columns;
|
|
27493
|
+
name;
|
|
27494
|
+
isNameExplicit;
|
|
27495
|
+
constructor(table, columns, name2) {
|
|
27496
|
+
this.table = table;
|
|
27497
|
+
this.columns = columns;
|
|
27498
|
+
this.name = name2;
|
|
27499
|
+
this.isNameExplicit = !!name2;
|
|
27500
|
+
}
|
|
27501
|
+
getName() {
|
|
27502
|
+
return this.name ?? `${this.table[SQLiteTable.Symbol.Name]}_${this.columns.map((column) => column.name).join("_")}_pk`;
|
|
28008
27503
|
}
|
|
28009
27504
|
};
|
|
28010
|
-
|
|
27505
|
+
|
|
27506
|
+
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/utils.js
|
|
27507
|
+
function extractUsedTable(table) {
|
|
27508
|
+
if (is(table, SQLiteTable)) return [`${table[Table.Symbol.BaseName]}`];
|
|
27509
|
+
if (is(table, Subquery)) return table._.usedTables ?? [];
|
|
27510
|
+
if (is(table, SQL)) return table.usedTables ?? [];
|
|
27511
|
+
return [];
|
|
27512
|
+
}
|
|
28011
27513
|
|
|
28012
27514
|
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/view-base.js
|
|
28013
27515
|
var SQLiteViewBase = class extends View {
|
|
28014
27516
|
static [entityKind] = "SQLiteViewBase";
|
|
28015
27517
|
};
|
|
28016
27518
|
|
|
27519
|
+
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/selection-proxy.js
|
|
27520
|
+
var SelectionProxyHandler = class SelectionProxyHandler2 {
|
|
27521
|
+
static [entityKind] = "SelectionProxyHandler";
|
|
27522
|
+
config;
|
|
27523
|
+
constructor(config2) {
|
|
27524
|
+
this.config = { ...config2 };
|
|
27525
|
+
}
|
|
27526
|
+
get(subquery, prop) {
|
|
27527
|
+
if (prop === "_") return {
|
|
27528
|
+
...subquery["_"],
|
|
27529
|
+
selectedFields: new Proxy(subquery._.selectedFields, this)
|
|
27530
|
+
};
|
|
27531
|
+
if (prop === ViewBaseConfig) return {
|
|
27532
|
+
...subquery[ViewBaseConfig],
|
|
27533
|
+
selectedFields: new Proxy(subquery[ViewBaseConfig].selectedFields, this)
|
|
27534
|
+
};
|
|
27535
|
+
if (typeof prop === "symbol") return subquery[prop];
|
|
27536
|
+
const value = (is(subquery, Subquery) ? subquery._.selectedFields : is(subquery, View) ? subquery[ViewBaseConfig].selectedFields : subquery)[prop];
|
|
27537
|
+
if (is(value, SQL.Aliased)) {
|
|
27538
|
+
if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) return value.sql;
|
|
27539
|
+
const newValue = value.clone();
|
|
27540
|
+
newValue.isSelectionField = true;
|
|
27541
|
+
newValue.origin = this.config.alias;
|
|
27542
|
+
return newValue;
|
|
27543
|
+
}
|
|
27544
|
+
if (is(value, SQL)) {
|
|
27545
|
+
if (this.config.sqlBehavior === "sql") return value;
|
|
27546
|
+
throw new Error(`You tried to reference "${prop}" field from a subquery, which is a raw SQL field, but it doesn't have an alias declared. Please add an alias to the field using ".as('alias')" method.`);
|
|
27547
|
+
}
|
|
27548
|
+
if (is(value, Column)) {
|
|
27549
|
+
if (this.config.alias) return new Proxy(value, new ColumnTableAliasProxyHandler(new Proxy(value.table, new TableAliasProxyHandler(this.config.alias, this.config.replaceOriginalName ?? false, true)), true));
|
|
27550
|
+
return value;
|
|
27551
|
+
}
|
|
27552
|
+
if (typeof value !== "object" || value === null) return value;
|
|
27553
|
+
return new Proxy(value, new SelectionProxyHandler2(this.config));
|
|
27554
|
+
}
|
|
27555
|
+
};
|
|
27556
|
+
|
|
28017
27557
|
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/query-builders/query-builder.js
|
|
28018
27558
|
var TypedQueryBuilder = class {
|
|
28019
27559
|
static [entityKind] = "TypedQueryBuilder";
|
|
@@ -28714,8 +28254,8 @@ var SQLiteDialect = class {
|
|
|
28714
28254
|
buildJoins(joins) {
|
|
28715
28255
|
if (!joins || joins.length === 0) return;
|
|
28716
28256
|
const joinsArray = [];
|
|
28717
|
-
if (joins) for (const [
|
|
28718
|
-
if (
|
|
28257
|
+
if (joins) for (const [index2, joinMeta] of joins.entries()) {
|
|
28258
|
+
if (index2 === 0) joinsArray.push(sql` `);
|
|
28719
28259
|
const table = joinMeta.table;
|
|
28720
28260
|
const onSql = joinMeta.on ? sql` on ${joinMeta.on}` : void 0;
|
|
28721
28261
|
if (is(table, SQLiteTable)) {
|
|
@@ -28725,7 +28265,7 @@ var SQLiteDialect = class {
|
|
|
28725
28265
|
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
|
28726
28266
|
joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`}${onSql}`);
|
|
28727
28267
|
} else joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join ${table}${onSql}`);
|
|
28728
|
-
if (
|
|
28268
|
+
if (index2 < joins.length - 1) joinsArray.push(sql` `);
|
|
28729
28269
|
}
|
|
28730
28270
|
return sql.join(joinsArray);
|
|
28731
28271
|
}
|
|
@@ -28734,9 +28274,9 @@ var SQLiteDialect = class {
|
|
|
28734
28274
|
}
|
|
28735
28275
|
buildOrderBy(orderBy) {
|
|
28736
28276
|
const orderByList = [];
|
|
28737
|
-
if (orderBy) for (const [
|
|
28277
|
+
if (orderBy) for (const [index2, orderByValue] of orderBy.entries()) {
|
|
28738
28278
|
orderByList.push(orderByValue);
|
|
28739
|
-
if (
|
|
28279
|
+
if (index2 < orderBy.length - 1) orderByList.push(sql`, `);
|
|
28740
28280
|
}
|
|
28741
28281
|
return orderByList.length > 0 ? sql` order by ${sql.join(orderByList)}` : void 0;
|
|
28742
28282
|
}
|
|
@@ -28764,9 +28304,9 @@ var SQLiteDialect = class {
|
|
|
28764
28304
|
const whereSql = where ? sql` where ${where}` : void 0;
|
|
28765
28305
|
const havingSql = having ? sql` having ${having}` : void 0;
|
|
28766
28306
|
const groupByList = [];
|
|
28767
|
-
if (groupBy) for (const [
|
|
28307
|
+
if (groupBy) for (const [index2, groupByValue] of groupBy.entries()) {
|
|
28768
28308
|
groupByList.push(groupByValue);
|
|
28769
|
-
if (
|
|
28309
|
+
if (index2 < groupBy.length - 1) groupByList.push(sql`, `);
|
|
28770
28310
|
}
|
|
28771
28311
|
const finalQuery = sql`${withSql}select${distinctSql} ${selection} from ${tableSql}${joinsSql}${whereSql}${groupByList.length > 0 ? sql` group by ${sql.join(groupByList)}` : void 0}${havingSql}${this.buildOrderBy(orderBy)}${this.buildLimit(limit)}${offset ? sql` offset ${offset}` : void 0}`;
|
|
28772
28312
|
if (setOperators.length > 0) return this.buildSetOperations(finalQuery, setOperators);
|
|
@@ -29055,6 +28595,268 @@ var QueryBuilder = class {
|
|
|
29055
28595
|
}
|
|
29056
28596
|
};
|
|
29057
28597
|
|
|
28598
|
+
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/query-builders/count.js
|
|
28599
|
+
var SQLiteCountBuilder = class SQLiteCountBuilder2 extends SQL {
|
|
28600
|
+
static [entityKind] = "SQLiteCountBuilder";
|
|
28601
|
+
dialect;
|
|
28602
|
+
session;
|
|
28603
|
+
static buildCount(source, filters, parens) {
|
|
28604
|
+
const query = sql`select count(*) from ${source}${sql` where ${filters}`.if(filters)}`;
|
|
28605
|
+
return parens ? sql`(${query})` : query;
|
|
28606
|
+
}
|
|
28607
|
+
constructor(countConfig) {
|
|
28608
|
+
super(SQLiteCountBuilder2.buildCount(countConfig.source, countConfig.filters, true).queryChunks);
|
|
28609
|
+
this.countConfig = countConfig;
|
|
28610
|
+
this.dialect = countConfig.dialect;
|
|
28611
|
+
this.session = countConfig.session;
|
|
28612
|
+
this.mapWith((e) => {
|
|
28613
|
+
if (typeof e === "number") return e;
|
|
28614
|
+
return Number(e ?? 0);
|
|
28615
|
+
});
|
|
28616
|
+
}
|
|
28617
|
+
executableSql;
|
|
28618
|
+
build() {
|
|
28619
|
+
if (!this.executableSql) {
|
|
28620
|
+
const { source, filters } = this.countConfig;
|
|
28621
|
+
this.executableSql = SQLiteCountBuilder2.buildCount(source, filters);
|
|
28622
|
+
}
|
|
28623
|
+
return this.dialect.sqlToQuery(this.executableSql);
|
|
28624
|
+
}
|
|
28625
|
+
};
|
|
28626
|
+
|
|
28627
|
+
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/async/count.js
|
|
28628
|
+
var SQLiteAsyncCountBuilder = class extends SQLiteCountBuilder {
|
|
28629
|
+
static [entityKind] = "SQLiteAsyncCountBuilder";
|
|
28630
|
+
constructor(countConfig) {
|
|
28631
|
+
super(countConfig);
|
|
28632
|
+
}
|
|
28633
|
+
/** @internal */
|
|
28634
|
+
executeRaw(placeholderValues) {
|
|
28635
|
+
return this.session.prepareQuery(this.build(), "arrays", false, "all", (rows) => {
|
|
28636
|
+
const v = rows[0]?.[0];
|
|
28637
|
+
if (typeof v === "number") return v;
|
|
28638
|
+
return v ? Number(v) : 0;
|
|
28639
|
+
}).execute(placeholderValues);
|
|
28640
|
+
}
|
|
28641
|
+
async execute(placeholderValues) {
|
|
28642
|
+
return await this.executeRaw(placeholderValues);
|
|
28643
|
+
}
|
|
28644
|
+
};
|
|
28645
|
+
applyMixins(SQLiteAsyncCountBuilder, [QueryPromise]);
|
|
28646
|
+
var SQLiteSyncCountBuilder = class extends SQLiteAsyncCountBuilder {
|
|
28647
|
+
static [entityKind] = "SQLiteSyncCountBuilder";
|
|
28648
|
+
sync(placeholderValues) {
|
|
28649
|
+
return this.executeRaw(placeholderValues).sync();
|
|
28650
|
+
}
|
|
28651
|
+
};
|
|
28652
|
+
|
|
28653
|
+
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/query-builders/query.js
|
|
28654
|
+
var RelationalQueryBuilder = class {
|
|
28655
|
+
static [entityKind] = "SQLiteRelationalQueryBuilderV2";
|
|
28656
|
+
constructor(mode, schema, table, tableConfig, dialect, session, forbidJsonb, builder = SQLiteRelationalQuery) {
|
|
28657
|
+
this.mode = mode;
|
|
28658
|
+
this.schema = schema;
|
|
28659
|
+
this.table = table;
|
|
28660
|
+
this.tableConfig = tableConfig;
|
|
28661
|
+
this.dialect = dialect;
|
|
28662
|
+
this.session = session;
|
|
28663
|
+
this.forbidJsonb = forbidJsonb;
|
|
28664
|
+
this.builder = builder;
|
|
28665
|
+
}
|
|
28666
|
+
findMany(config2) {
|
|
28667
|
+
return new this.builder(this.mode, this.schema, this.table, this.tableConfig, this.dialect, this.session, config2 ?? true, "many", this.forbidJsonb);
|
|
28668
|
+
}
|
|
28669
|
+
findFirst(config2) {
|
|
28670
|
+
return new this.builder(this.mode, this.schema, this.table, this.tableConfig, this.dialect, this.session, config2 ?? true, "first", this.forbidJsonb);
|
|
28671
|
+
}
|
|
28672
|
+
};
|
|
28673
|
+
var SQLiteRelationalQuery = class {
|
|
28674
|
+
static [entityKind] = "SQLiteRelationalQueryV2";
|
|
28675
|
+
/** @internal */
|
|
28676
|
+
mode;
|
|
28677
|
+
/** @internal */
|
|
28678
|
+
table;
|
|
28679
|
+
/** @internal */
|
|
28680
|
+
resultKind;
|
|
28681
|
+
constructor(resultKind, schema, table, tableConfig, dialect, session, config2, mode, forbidJsonb) {
|
|
28682
|
+
this.schema = schema;
|
|
28683
|
+
this.tableConfig = tableConfig;
|
|
28684
|
+
this.dialect = dialect;
|
|
28685
|
+
this.session = session;
|
|
28686
|
+
this.config = config2;
|
|
28687
|
+
this.forbidJsonb = forbidJsonb;
|
|
28688
|
+
this.resultKind = resultKind;
|
|
28689
|
+
this.mode = mode;
|
|
28690
|
+
this.table = table;
|
|
28691
|
+
}
|
|
28692
|
+
getSQL() {
|
|
28693
|
+
return this._getQuery().sql;
|
|
28694
|
+
}
|
|
28695
|
+
_getQuery() {
|
|
28696
|
+
const jsonb = this.forbidJsonb ? sql`json` : sql`jsonb`;
|
|
28697
|
+
return this.dialect.buildRelationalQuery({
|
|
28698
|
+
schema: this.schema,
|
|
28699
|
+
table: this.table,
|
|
28700
|
+
tableConfig: this.tableConfig,
|
|
28701
|
+
queryConfig: this.config,
|
|
28702
|
+
mode: this.mode,
|
|
28703
|
+
jsonb
|
|
28704
|
+
});
|
|
28705
|
+
}
|
|
28706
|
+
_toSQL() {
|
|
28707
|
+
const query = this._getQuery();
|
|
28708
|
+
return {
|
|
28709
|
+
query,
|
|
28710
|
+
builtQuery: this.dialect.sqlToQuery(query.sql)
|
|
28711
|
+
};
|
|
28712
|
+
}
|
|
28713
|
+
toSQL() {
|
|
28714
|
+
return this._toSQL().builtQuery;
|
|
28715
|
+
}
|
|
28716
|
+
};
|
|
28717
|
+
|
|
28718
|
+
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/async/query.js
|
|
28719
|
+
var SQLiteAsyncRelationalQuery = class extends SQLiteRelationalQuery {
|
|
28720
|
+
static [entityKind] = "SQLiteAsyncRelationalQueryV2";
|
|
28721
|
+
/** @internal */
|
|
28722
|
+
_prepare(prepare = false) {
|
|
28723
|
+
const { query, builtQuery } = this._toSQL();
|
|
28724
|
+
const mapper = this.dialect.mapperGenerators.relationalRows({
|
|
28725
|
+
isFirst: this.mode === "first",
|
|
28726
|
+
parseJson: true,
|
|
28727
|
+
parseJsonIfString: false,
|
|
28728
|
+
rootJsonMappers: false,
|
|
28729
|
+
selection: query.selection,
|
|
28730
|
+
arrayModeRoot: true
|
|
28731
|
+
});
|
|
28732
|
+
return this.session.prepareQuery(builtQuery, "arrays", prepare, "all", mapper);
|
|
28733
|
+
}
|
|
28734
|
+
prepare() {
|
|
28735
|
+
return this._prepare(true);
|
|
28736
|
+
}
|
|
28737
|
+
async execute(placeholderValues) {
|
|
28738
|
+
return this._prepare().execute(placeholderValues);
|
|
28739
|
+
}
|
|
28740
|
+
};
|
|
28741
|
+
var SQLiteSyncRelationalQuery = class extends SQLiteAsyncRelationalQuery {
|
|
28742
|
+
static [entityKind] = "SQLiteSyncRelationalQueryV2";
|
|
28743
|
+
sync(placeholderValues) {
|
|
28744
|
+
return this._prepare().execute(placeholderValues).sync();
|
|
28745
|
+
}
|
|
28746
|
+
};
|
|
28747
|
+
applyMixins(SQLiteAsyncRelationalQuery, [QueryPromise]);
|
|
28748
|
+
|
|
28749
|
+
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/query-builders/delete.js
|
|
28750
|
+
var SQLiteDeleteBase = class {
|
|
28751
|
+
static [entityKind] = "SQLiteDelete";
|
|
28752
|
+
/** @internal */
|
|
28753
|
+
config;
|
|
28754
|
+
constructor(table, session, dialect, withList) {
|
|
28755
|
+
this.table = table;
|
|
28756
|
+
this.session = session;
|
|
28757
|
+
this.dialect = dialect;
|
|
28758
|
+
this.config = {
|
|
28759
|
+
table,
|
|
28760
|
+
withList
|
|
28761
|
+
};
|
|
28762
|
+
}
|
|
28763
|
+
/**
|
|
28764
|
+
* Adds a `where` clause to the query.
|
|
28765
|
+
*
|
|
28766
|
+
* Calling this method will delete only those rows that fulfill a specified condition.
|
|
28767
|
+
*
|
|
28768
|
+
* See docs: {@link https://orm.drizzle.team/docs/delete}
|
|
28769
|
+
*
|
|
28770
|
+
* @param where the `where` clause.
|
|
28771
|
+
*
|
|
28772
|
+
* @example
|
|
28773
|
+
* You can use conditional operators and `sql function` to filter the rows to be deleted.
|
|
28774
|
+
*
|
|
28775
|
+
* ```ts
|
|
28776
|
+
* // Delete all cars with green color
|
|
28777
|
+
* db.delete(cars).where(eq(cars.color, 'green'));
|
|
28778
|
+
* // or
|
|
28779
|
+
* db.delete(cars).where(sql`${cars.color} = 'green'`)
|
|
28780
|
+
* ```
|
|
28781
|
+
*
|
|
28782
|
+
* You can logically combine conditional operators with `and()` and `or()` operators:
|
|
28783
|
+
*
|
|
28784
|
+
* ```ts
|
|
28785
|
+
* // Delete all BMW cars with a green color
|
|
28786
|
+
* db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
|
28787
|
+
*
|
|
28788
|
+
* // Delete all cars with the green or blue color
|
|
28789
|
+
* db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
28790
|
+
* ```
|
|
28791
|
+
*/
|
|
28792
|
+
where(where) {
|
|
28793
|
+
this.config.where = where;
|
|
28794
|
+
return this;
|
|
28795
|
+
}
|
|
28796
|
+
orderBy(...columns) {
|
|
28797
|
+
if (typeof columns[0] === "function") {
|
|
28798
|
+
const orderBy = columns[0](new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
|
|
28799
|
+
sqlAliasedBehavior: "alias",
|
|
28800
|
+
sqlBehavior: "sql"
|
|
28801
|
+
})));
|
|
28802
|
+
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
28803
|
+
this.config.orderBy = orderByArray;
|
|
28804
|
+
} else {
|
|
28805
|
+
const orderByArray = columns;
|
|
28806
|
+
this.config.orderBy = orderByArray;
|
|
28807
|
+
}
|
|
28808
|
+
return this;
|
|
28809
|
+
}
|
|
28810
|
+
limit(limit) {
|
|
28811
|
+
this.config.limit = limit;
|
|
28812
|
+
return this;
|
|
28813
|
+
}
|
|
28814
|
+
returning(fields = this.table[SQLiteTable.Symbol.Columns]) {
|
|
28815
|
+
this.config.returning = orderSelectedFields(fields);
|
|
28816
|
+
return this;
|
|
28817
|
+
}
|
|
28818
|
+
getSQL() {
|
|
28819
|
+
return this.dialect.buildDeleteQuery(this.config);
|
|
28820
|
+
}
|
|
28821
|
+
toSQL() {
|
|
28822
|
+
return this.dialect.sqlToQuery(this.getSQL());
|
|
28823
|
+
}
|
|
28824
|
+
$dynamic() {
|
|
28825
|
+
return this;
|
|
28826
|
+
}
|
|
28827
|
+
};
|
|
28828
|
+
|
|
28829
|
+
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/async/delete.js
|
|
28830
|
+
var SQLiteAsyncDeleteBase = class extends SQLiteDeleteBase {
|
|
28831
|
+
static [entityKind] = "SQLiteAsyncDelete";
|
|
28832
|
+
/** @internal */
|
|
28833
|
+
_prepare(prepare = false) {
|
|
28834
|
+
return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), "arrays", prepare, this.config.returning ? "all" : "run", this.config.returning ? this.dialect.mapperGenerators.rows(this.config.returning, void 0) : void 0, {
|
|
28835
|
+
type: "delete",
|
|
28836
|
+
tables: extractUsedTable(this.config.table)
|
|
28837
|
+
});
|
|
28838
|
+
}
|
|
28839
|
+
prepare() {
|
|
28840
|
+
return this._prepare(true);
|
|
28841
|
+
}
|
|
28842
|
+
run = (placeholderValues) => {
|
|
28843
|
+
return this._prepare().run(placeholderValues);
|
|
28844
|
+
};
|
|
28845
|
+
all = (placeholderValues) => {
|
|
28846
|
+
return this._prepare().all(placeholderValues);
|
|
28847
|
+
};
|
|
28848
|
+
get = (placeholderValues) => {
|
|
28849
|
+
return this._prepare().get(placeholderValues);
|
|
28850
|
+
};
|
|
28851
|
+
values = (placeholderValues) => {
|
|
28852
|
+
return this._prepare().values(placeholderValues);
|
|
28853
|
+
};
|
|
28854
|
+
async execute(placeholderValues) {
|
|
28855
|
+
return this._prepare().execute(placeholderValues);
|
|
28856
|
+
}
|
|
28857
|
+
};
|
|
28858
|
+
applyMixins(SQLiteAsyncDeleteBase, [QueryPromise]);
|
|
28859
|
+
|
|
29058
28860
|
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/query-builders/insert.js
|
|
29059
28861
|
var SQLiteInsertBuilder = class {
|
|
29060
28862
|
static [entityKind] = "SQLiteInsertBuilder";
|
|
@@ -29942,133 +29744,6 @@ var SQLiteAsyncTransaction = class extends SQLiteAsyncDatabase {
|
|
|
29942
29744
|
}
|
|
29943
29745
|
};
|
|
29944
29746
|
|
|
29945
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/node-sqlite/session.js
|
|
29946
|
-
var NodeSQLiteSession = class extends SQLiteAsyncSession {
|
|
29947
|
-
static [entityKind] = "SQLJsSession";
|
|
29948
|
-
logger;
|
|
29949
|
-
constructor(client2, dialect, relations, options = {}) {
|
|
29950
|
-
super(dialect, "sync");
|
|
29951
|
-
this.client = client2;
|
|
29952
|
-
this.relations = relations;
|
|
29953
|
-
this.options = options;
|
|
29954
|
-
this.logger = options.logger ?? new NoopLogger();
|
|
29955
|
-
}
|
|
29956
|
-
prepareQuery(query, mode, _prepare, executeMethod, mapper, queryMetadata) {
|
|
29957
|
-
let stmt;
|
|
29958
|
-
try {
|
|
29959
|
-
stmt = this.client.prepare(query.sql);
|
|
29960
|
-
} catch (e) {
|
|
29961
|
-
throw new DrizzleQueryError(query.sql, query.params, e);
|
|
29962
|
-
}
|
|
29963
|
-
return new SQLiteAsyncPreparedQuery("sync", executeMethod, {
|
|
29964
|
-
all: (params) => {
|
|
29965
|
-
stmt.setReturnArrays(mode === "arrays");
|
|
29966
|
-
const res = stmt.all(...params);
|
|
29967
|
-
if (mode === "objects") return res.map((row) => ({ ...row }));
|
|
29968
|
-
return res;
|
|
29969
|
-
},
|
|
29970
|
-
get: (params) => {
|
|
29971
|
-
stmt.setReturnArrays(mode === "arrays");
|
|
29972
|
-
const res = stmt.get(...params);
|
|
29973
|
-
if (res && mode === "objects") return { ...res };
|
|
29974
|
-
return res;
|
|
29975
|
-
},
|
|
29976
|
-
run: (params) => {
|
|
29977
|
-
stmt.setReturnArrays(false);
|
|
29978
|
-
return stmt.run(...params);
|
|
29979
|
-
},
|
|
29980
|
-
values: (params) => {
|
|
29981
|
-
stmt.setReturnArrays(true);
|
|
29982
|
-
return stmt.all(...params);
|
|
29983
|
-
}
|
|
29984
|
-
}, query, mapper, mode, this.logger, void 0, queryMetadata, void 0);
|
|
29985
|
-
}
|
|
29986
|
-
transaction(transaction, config2 = {}) {
|
|
29987
|
-
const tx = new NodeSQLiteTransaction("sync", this.dialect, this, this.relations);
|
|
29988
|
-
this.run(sql.raw(`begin${config2.behavior ? ` ${config2.behavior}` : ""}`));
|
|
29989
|
-
try {
|
|
29990
|
-
const result = transaction(tx);
|
|
29991
|
-
this.run(sql`commit`);
|
|
29992
|
-
return result;
|
|
29993
|
-
} catch (err) {
|
|
29994
|
-
this.run(sql`rollback`);
|
|
29995
|
-
throw err;
|
|
29996
|
-
}
|
|
29997
|
-
}
|
|
29998
|
-
};
|
|
29999
|
-
var NodeSQLiteTransaction = class NodeSQLiteTransaction2 extends SQLiteAsyncTransaction {
|
|
30000
|
-
static [entityKind] = "SQLJsTransaction";
|
|
30001
|
-
transaction(transaction) {
|
|
30002
|
-
const savepointName = `sp${this.nestedIndex + 1}`;
|
|
30003
|
-
const tx = new NodeSQLiteTransaction2("sync", this.dialect, this.session, this._.relations, this.nestedIndex + 1);
|
|
30004
|
-
tx.run(sql.raw(`savepoint ${savepointName}`));
|
|
30005
|
-
try {
|
|
30006
|
-
const result = transaction(tx);
|
|
30007
|
-
tx.run(sql.raw(`release savepoint ${savepointName}`));
|
|
30008
|
-
return result;
|
|
30009
|
-
} catch (err) {
|
|
30010
|
-
tx.run(sql.raw(`rollback to savepoint ${savepointName}`));
|
|
30011
|
-
throw err;
|
|
30012
|
-
}
|
|
30013
|
-
}
|
|
30014
|
-
};
|
|
30015
|
-
|
|
30016
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/node-sqlite/driver.js
|
|
30017
|
-
import { DatabaseSync } from "node:sqlite";
|
|
30018
|
-
var NodeSQLiteDatabase = class extends SQLiteAsyncDatabase {
|
|
30019
|
-
static [entityKind] = "NodeSQLiteDatabase";
|
|
30020
|
-
};
|
|
30021
|
-
function construct(client2, config2 = {}) {
|
|
30022
|
-
const dialect = new SQLiteDialect({ useJitMappers: jitCompatCheck(config2.jit) });
|
|
30023
|
-
let logger;
|
|
30024
|
-
if (config2.logger === true) logger = new DefaultLogger();
|
|
30025
|
-
else if (config2.logger !== false) logger = config2.logger;
|
|
30026
|
-
const relations = config2.relations ?? {};
|
|
30027
|
-
const db = new NodeSQLiteDatabase("sync", dialect, new NodeSQLiteSession(client2, dialect, relations, { logger }), relations);
|
|
30028
|
-
db.$client = client2;
|
|
30029
|
-
return db;
|
|
30030
|
-
}
|
|
30031
|
-
function drizzle(...params) {
|
|
30032
|
-
if (params[0] === void 0 || typeof params[0] === "string") return construct(params[0] === void 0 ? new DatabaseSync(":memory:") : new DatabaseSync(params[0]), params[1]);
|
|
30033
|
-
const { connection, client: client2, ...config2 } = params[0];
|
|
30034
|
-
if (client2) return construct(client2, config2);
|
|
30035
|
-
if (typeof connection === "object") {
|
|
30036
|
-
const { path: path2, ...options } = connection;
|
|
30037
|
-
return construct(new DatabaseSync(path2 ?? ":memory:", options), config2);
|
|
30038
|
-
}
|
|
30039
|
-
return construct(new DatabaseSync(connection ?? ":memory:"), config2);
|
|
30040
|
-
}
|
|
30041
|
-
(function(_drizzle) {
|
|
30042
|
-
function mock(config2) {
|
|
30043
|
-
return construct({}, config2);
|
|
30044
|
-
}
|
|
30045
|
-
_drizzle.mock = mock;
|
|
30046
|
-
})(drizzle || (drizzle = {}));
|
|
30047
|
-
|
|
30048
|
-
// src/generated/acp-session-store-migrations.ts
|
|
30049
|
-
var acpSessionStoreMigrations = [
|
|
30050
|
-
{
|
|
30051
|
-
"name": "0000_slimy_captain_midlands.sql",
|
|
30052
|
-
"sql": "CREATE TABLE `acp_session` (\n `session_id` text PRIMARY KEY NOT NULL,\n `agent_id` text NOT NULL,\n `native_session_id` text NOT NULL,\n `cwd` text NOT NULL,\n `additional_directories` text NOT NULL,\n `prompted` integer NOT NULL,\n `title` text NOT NULL,\n `updated_at` text NOT NULL\n);\n--> statement-breakpoint\nCREATE TABLE `deleted_acp_session` (\n `session_id` text PRIMARY KEY NOT NULL\n);\n"
|
|
30053
|
-
},
|
|
30054
|
-
{
|
|
30055
|
-
"name": "0001_regular_ultimates.sql",
|
|
30056
|
-
"sql": "ALTER TABLE `acp_session` ADD `last_terminal_command_id` text;"
|
|
30057
|
-
},
|
|
30058
|
-
{
|
|
30059
|
-
"name": "0002_equal_black_queen.sql",
|
|
30060
|
-
"sql": "CREATE TABLE `session_event_v2` (\n `event_id` text PRIMARY KEY NOT NULL,\n `event_json` text NOT NULL,\n `position` integer NOT NULL,\n `session_id` text NOT NULL\n);\n--> statement-breakpoint\nCREATE UNIQUE INDEX `session_event_v2_session_position_unique` ON `session_event_v2` (`session_id`,`position`);--> statement-breakpoint\nCREATE INDEX `session_event_v2_session_position_index` ON `session_event_v2` (`session_id`,`position`);"
|
|
30061
|
-
},
|
|
30062
|
-
{
|
|
30063
|
-
"name": "0003_silky_ravenous.sql",
|
|
30064
|
-
"sql": "DROP TABLE `session_event_v2`;"
|
|
30065
|
-
},
|
|
30066
|
-
{
|
|
30067
|
-
"name": "0004_special_mathemanic.sql",
|
|
30068
|
-
"sql": "DROP TABLE `deleted_acp_session`;--> statement-breakpoint\nALTER TABLE `acp_session` DROP COLUMN `last_terminal_command_id`;"
|
|
30069
|
-
}
|
|
30070
|
-
];
|
|
30071
|
-
|
|
30072
29747
|
// src/schema/acp-session-store/acp-session.ts
|
|
30073
29748
|
var acpSession = sqliteTable("acp_session", {
|
|
30074
29749
|
sessionId: text("session_id").primaryKey(),
|
|
@@ -30081,6 +29756,216 @@ var acpSession = sqliteTable("acp_session", {
|
|
|
30081
29756
|
updatedAt: text("updated_at").notNull()
|
|
30082
29757
|
});
|
|
30083
29758
|
|
|
29759
|
+
// src/schema/session-event-cache/session-event-v2.ts
|
|
29760
|
+
var sessionEventV2 = sqliteTable(
|
|
29761
|
+
"session_event_v2",
|
|
29762
|
+
{
|
|
29763
|
+
eventJson: text("event_json").notNull(),
|
|
29764
|
+
generationId: text("generation_id").notNull(),
|
|
29765
|
+
position: integer2("position").notNull(),
|
|
29766
|
+
sessionId: text("session_id").notNull()
|
|
29767
|
+
},
|
|
29768
|
+
(table) => [
|
|
29769
|
+
primaryKey({ columns: [table.generationId, table.sessionId, table.position] }),
|
|
29770
|
+
index("session_event_v2_generation_session_position_index").on(
|
|
29771
|
+
table.generationId,
|
|
29772
|
+
table.sessionId,
|
|
29773
|
+
table.position
|
|
29774
|
+
)
|
|
29775
|
+
]
|
|
29776
|
+
);
|
|
29777
|
+
|
|
29778
|
+
// src/acp/session-event-store-v2.ts
|
|
29779
|
+
var HOT_EVENT_HIGH_WATER_MARK = 256;
|
|
29780
|
+
var HOT_EVENT_RETENTION = 128;
|
|
29781
|
+
function eventPage(eventCount, eventLimit, cursor, read) {
|
|
29782
|
+
const parsedCursor = cursor === null ? eventCount : Number(cursor);
|
|
29783
|
+
if (!Number.isSafeInteger(parsedCursor) || parsedCursor < 0 || parsedCursor > eventCount) {
|
|
29784
|
+
throw new Error("The native event cursor is invalid");
|
|
29785
|
+
}
|
|
29786
|
+
const endPosition = parsedCursor;
|
|
29787
|
+
const startPosition = Math.max(0, endPosition - eventLimit);
|
|
29788
|
+
return {
|
|
29789
|
+
events: read(startPosition + 1, endPosition),
|
|
29790
|
+
nextCursor: startPosition === 0 ? null : startPosition.toString(),
|
|
29791
|
+
startPosition: startPosition + 1,
|
|
29792
|
+
truncated: startPosition > 0
|
|
29793
|
+
};
|
|
29794
|
+
}
|
|
29795
|
+
var MemoryAcpSessionEventStoreV2 = class {
|
|
29796
|
+
generationId;
|
|
29797
|
+
#events = /* @__PURE__ */ new Map();
|
|
29798
|
+
constructor(generationId) {
|
|
29799
|
+
this.generationId = generationId;
|
|
29800
|
+
}
|
|
29801
|
+
append = (sessionId, event) => {
|
|
29802
|
+
const events = this.#events.get(sessionId) ?? [];
|
|
29803
|
+
events.push(event);
|
|
29804
|
+
this.#events.set(sessionId, events);
|
|
29805
|
+
return events.length;
|
|
29806
|
+
};
|
|
29807
|
+
close = () => this.#events.clear();
|
|
29808
|
+
page = (sessionId, eventLimit, cursor) => {
|
|
29809
|
+
const events = this.#events.get(sessionId) ?? [];
|
|
29810
|
+
return eventPage(
|
|
29811
|
+
events.length,
|
|
29812
|
+
eventLimit,
|
|
29813
|
+
cursor,
|
|
29814
|
+
(startPosition, endPosition) => events.slice(startPosition - 1, endPosition)
|
|
29815
|
+
);
|
|
29816
|
+
};
|
|
29817
|
+
remove = (sessionId) => {
|
|
29818
|
+
this.#events.delete(sessionId);
|
|
29819
|
+
};
|
|
29820
|
+
reset = this.remove;
|
|
29821
|
+
};
|
|
29822
|
+
var cachedEventRowSchema = external_exports.object({ eventJson: external_exports.string(), position: external_exports.number().int().positive() });
|
|
29823
|
+
function decodeCachedEvent(value) {
|
|
29824
|
+
const payload = external_exports.record(external_exports.string(), external_exports.unknown()).parse(value);
|
|
29825
|
+
const event = decodeSessionEventV2({
|
|
29826
|
+
...payload,
|
|
29827
|
+
eventId: "cached-event",
|
|
29828
|
+
position: "1",
|
|
29829
|
+
provenance: { kind: "original" },
|
|
29830
|
+
recordedAt: "1970-01-01T00:00:00.000Z",
|
|
29831
|
+
sessionId: "cached-session"
|
|
29832
|
+
});
|
|
29833
|
+
return event.type === "acp" ? { payload: event.payload, type: event.type } : { payload: event.payload, type: event.type };
|
|
29834
|
+
}
|
|
29835
|
+
var CachedAcpSessionEventStoreV2 = class {
|
|
29836
|
+
generationId;
|
|
29837
|
+
#database;
|
|
29838
|
+
#ignoredPersistedSessions = /* @__PURE__ */ new Set();
|
|
29839
|
+
#localDatabase;
|
|
29840
|
+
#sessions = /* @__PURE__ */ new Map();
|
|
29841
|
+
#flushSchedule = { kind: "idle" };
|
|
29842
|
+
#isLocalDBAvailable = true;
|
|
29843
|
+
constructor(localDatabase, generationId) {
|
|
29844
|
+
this.generationId = generationId;
|
|
29845
|
+
this.#localDatabase = localDatabase;
|
|
29846
|
+
this.#database = localDatabase.orm;
|
|
29847
|
+
try {
|
|
29848
|
+
this.#localDatabase.transaction(() => this.#database.delete(sessionEventV2).run());
|
|
29849
|
+
} catch (error62) {
|
|
29850
|
+
this.#localDatabase.close();
|
|
29851
|
+
throw error62;
|
|
29852
|
+
}
|
|
29853
|
+
}
|
|
29854
|
+
append = (sessionId, event) => {
|
|
29855
|
+
if (this.#flushSchedule.kind === "closed") {
|
|
29856
|
+
throw new Error("The V2 Session event store is closed");
|
|
29857
|
+
}
|
|
29858
|
+
const session = this.#sessions.get(sessionId) ?? { hot: [], nextPosition: 1 };
|
|
29859
|
+
const position = session.nextPosition;
|
|
29860
|
+
session.hot.push({ event, position });
|
|
29861
|
+
session.nextPosition += 1;
|
|
29862
|
+
this.#sessions.set(sessionId, session);
|
|
29863
|
+
if (session.hot.length > HOT_EVENT_HIGH_WATER_MARK) {
|
|
29864
|
+
this.#scheduleFlush();
|
|
29865
|
+
}
|
|
29866
|
+
return position;
|
|
29867
|
+
};
|
|
29868
|
+
#scheduleFlush = () => {
|
|
29869
|
+
if (!this.#isLocalDBAvailable || this.#flushSchedule.kind !== "idle") {
|
|
29870
|
+
return;
|
|
29871
|
+
}
|
|
29872
|
+
const handle = setImmediate(() => {
|
|
29873
|
+
if (this.#flushSchedule.kind !== "scheduled" || this.#flushSchedule.handle !== handle) {
|
|
29874
|
+
return;
|
|
29875
|
+
}
|
|
29876
|
+
this.#flushSchedule = { kind: "idle" };
|
|
29877
|
+
this.#flush(false);
|
|
29878
|
+
});
|
|
29879
|
+
this.#flushSchedule = { handle, kind: "scheduled" };
|
|
29880
|
+
};
|
|
29881
|
+
#flush = (includeHotTail) => {
|
|
29882
|
+
if (!this.#isLocalDBAvailable || this.#flushSchedule.kind === "closed") {
|
|
29883
|
+
return;
|
|
29884
|
+
}
|
|
29885
|
+
const batches = [...this.#sessions.entries()].flatMap(([sessionId, session]) => {
|
|
29886
|
+
const count = includeHotTail ? session.hot.length : Math.max(0, session.hot.length - HOT_EVENT_RETENTION);
|
|
29887
|
+
return count === 0 ? [] : [{ count, events: session.hot.slice(0, count), sessionId }];
|
|
29888
|
+
});
|
|
29889
|
+
const values = batches.flatMap(
|
|
29890
|
+
(batch) => batch.events.map(({ event, position }) => ({
|
|
29891
|
+
eventJson: JSON.stringify(event),
|
|
29892
|
+
generationId: this.generationId,
|
|
29893
|
+
position,
|
|
29894
|
+
sessionId: batch.sessionId
|
|
29895
|
+
}))
|
|
29896
|
+
);
|
|
29897
|
+
if (values.length === 0) {
|
|
29898
|
+
return;
|
|
29899
|
+
}
|
|
29900
|
+
try {
|
|
29901
|
+
this.#localDatabase.transaction(() => {
|
|
29902
|
+
for (let offset = 0; offset < values.length; offset += 200) {
|
|
29903
|
+
this.#database.insert(sessionEventV2).values(values.slice(offset, offset + 200)).run();
|
|
29904
|
+
}
|
|
29905
|
+
});
|
|
29906
|
+
for (const batch of batches) {
|
|
29907
|
+
this.#sessions.get(batch.sessionId)?.hot.splice(0, batch.count);
|
|
29908
|
+
}
|
|
29909
|
+
} catch (cause) {
|
|
29910
|
+
this.#isLocalDBAvailable = false;
|
|
29911
|
+
console.warn("Mobius V2 Session event cache writes are unavailable; retaining events in memory", cause);
|
|
29912
|
+
}
|
|
29913
|
+
};
|
|
29914
|
+
page = (sessionId, eventLimit, cursor) => {
|
|
29915
|
+
const session = this.#sessions.get(sessionId);
|
|
29916
|
+
const eventCount = (session?.nextPosition ?? 1) - 1;
|
|
29917
|
+
return eventPage(eventCount, eventLimit, cursor, (startPosition, endPosition) => {
|
|
29918
|
+
const persisted = this.#ignoredPersistedSessions.has(sessionId) ? [] : this.#database.select({ eventJson: sessionEventV2.eventJson, position: sessionEventV2.position }).from(sessionEventV2).where(
|
|
29919
|
+
and(
|
|
29920
|
+
eq(sessionEventV2.generationId, this.generationId),
|
|
29921
|
+
eq(sessionEventV2.sessionId, sessionId),
|
|
29922
|
+
gte(sessionEventV2.position, startPosition),
|
|
29923
|
+
lte(sessionEventV2.position, endPosition)
|
|
29924
|
+
)
|
|
29925
|
+
).orderBy(asc(sessionEventV2.position)).all().map((value) => {
|
|
29926
|
+
const row = cachedEventRowSchema.parse(value);
|
|
29927
|
+
return { event: decodeCachedEvent(JSON.parse(row.eventJson)), position: row.position };
|
|
29928
|
+
});
|
|
29929
|
+
const hot = (session?.hot ?? []).filter(
|
|
29930
|
+
({ position }) => position >= startPosition && position <= endPosition
|
|
29931
|
+
);
|
|
29932
|
+
return [...persisted, ...hot].toSorted((left, right) => left.position - right.position).map(({ event }) => event);
|
|
29933
|
+
});
|
|
29934
|
+
};
|
|
29935
|
+
#deletePersisted = (sessionId) => {
|
|
29936
|
+
if (!this.#isLocalDBAvailable) {
|
|
29937
|
+
this.#ignoredPersistedSessions.add(sessionId);
|
|
29938
|
+
return;
|
|
29939
|
+
}
|
|
29940
|
+
try {
|
|
29941
|
+
this.#database.delete(sessionEventV2).where(and(eq(sessionEventV2.generationId, this.generationId), eq(sessionEventV2.sessionId, sessionId))).run();
|
|
29942
|
+
this.#ignoredPersistedSessions.delete(sessionId);
|
|
29943
|
+
} catch (cause) {
|
|
29944
|
+
this.#isLocalDBAvailable = false;
|
|
29945
|
+
this.#ignoredPersistedSessions.add(sessionId);
|
|
29946
|
+
console.warn("Mobius V2 Session event cache writes are unavailable; retaining events in memory", cause);
|
|
29947
|
+
}
|
|
29948
|
+
};
|
|
29949
|
+
remove = (sessionId) => {
|
|
29950
|
+
this.#deletePersisted(sessionId);
|
|
29951
|
+
this.#sessions.delete(sessionId);
|
|
29952
|
+
};
|
|
29953
|
+
reset = this.remove;
|
|
29954
|
+
close = () => {
|
|
29955
|
+
if (this.#flushSchedule.kind === "closed") {
|
|
29956
|
+
return;
|
|
29957
|
+
}
|
|
29958
|
+
if (this.#flushSchedule.kind === "scheduled") {
|
|
29959
|
+
clearImmediate(this.#flushSchedule.handle);
|
|
29960
|
+
}
|
|
29961
|
+
this.#flushSchedule = { kind: "idle" };
|
|
29962
|
+
this.#flush(true);
|
|
29963
|
+
this.#flushSchedule = { kind: "closed" };
|
|
29964
|
+
this.#localDatabase.close();
|
|
29965
|
+
this.#sessions.clear();
|
|
29966
|
+
};
|
|
29967
|
+
};
|
|
29968
|
+
|
|
30084
29969
|
// src/acp/session-store.ts
|
|
30085
29970
|
var AcpStoredSession = class {
|
|
30086
29971
|
additionalDirectories;
|
|
@@ -30116,9 +30001,14 @@ var FoundAcpStoredSession = class extends AcpStoredSessionLookup {
|
|
|
30116
30001
|
}
|
|
30117
30002
|
};
|
|
30118
30003
|
var MemoryAcpSessionStore = class {
|
|
30004
|
+
eventsV2;
|
|
30119
30005
|
#sessions = /* @__PURE__ */ new Map();
|
|
30006
|
+
constructor(eventsV2 = new MemoryAcpSessionEventStoreV2(randomUUID())) {
|
|
30007
|
+
this.eventsV2 = eventsV2;
|
|
30008
|
+
}
|
|
30120
30009
|
close = () => {
|
|
30121
30010
|
this.#sessions.clear();
|
|
30011
|
+
this.eventsV2.close();
|
|
30122
30012
|
};
|
|
30123
30013
|
findNative = (agentId, nativeSessionId) => [...this.#sessions.values()].filter(
|
|
30124
30014
|
(session) => session.agentId === agentId && session.nativeSessionId === nativeSessionId
|
|
@@ -30130,6 +30020,7 @@ var MemoryAcpSessionStore = class {
|
|
|
30130
30020
|
};
|
|
30131
30021
|
remove = (sessionId) => {
|
|
30132
30022
|
this.#sessions.delete(sessionId);
|
|
30023
|
+
this.eventsV2.remove(sessionId);
|
|
30133
30024
|
};
|
|
30134
30025
|
write = (session) => {
|
|
30135
30026
|
this.#sessions.set(session.sessionId, session);
|
|
@@ -30161,39 +30052,20 @@ function decodeStoredSession(value) {
|
|
|
30161
30052
|
);
|
|
30162
30053
|
}
|
|
30163
30054
|
var SqliteAcpSessionStore = class {
|
|
30055
|
+
eventsV2;
|
|
30164
30056
|
#database;
|
|
30165
|
-
#
|
|
30166
|
-
constructor(
|
|
30167
|
-
|
|
30168
|
-
this.#
|
|
30169
|
-
|
|
30170
|
-
this.#migrate();
|
|
30171
|
-
this.#database = drizzle({ client: this.#sqliteDatabase });
|
|
30057
|
+
#localDatabase;
|
|
30058
|
+
constructor(localDatabase, eventsV2 = new MemoryAcpSessionEventStoreV2(randomUUID())) {
|
|
30059
|
+
this.eventsV2 = eventsV2;
|
|
30060
|
+
this.#localDatabase = localDatabase;
|
|
30061
|
+
this.#database = localDatabase.orm;
|
|
30172
30062
|
}
|
|
30173
|
-
#migrate = () => {
|
|
30174
|
-
const version2 = external_exports.object({ user_version: external_exports.number().int().nonnegative() }).parse(this.#sqliteDatabase.prepare("PRAGMA user_version").get()).user_version;
|
|
30175
|
-
if (version2 > acpSessionStoreMigrations.length) {
|
|
30176
|
-
this.#sqliteDatabase.close();
|
|
30177
|
-
throw new Error("The ACP Session database was created by a newer Mobius version");
|
|
30178
|
-
}
|
|
30179
|
-
for (let index = version2; index < acpSessionStoreMigrations.length; index += 1) {
|
|
30180
|
-
const migration = acpSessionStoreMigrations[index];
|
|
30181
|
-
if (migration === void 0) {
|
|
30182
|
-
throw new Error("The ACP Session migration is unavailable");
|
|
30183
|
-
}
|
|
30184
|
-
this.#sqliteDatabase.exec("BEGIN IMMEDIATE");
|
|
30185
|
-
try {
|
|
30186
|
-
this.#sqliteDatabase.exec(migration.sql);
|
|
30187
|
-
this.#sqliteDatabase.exec(`PRAGMA user_version = ${index + 1}`);
|
|
30188
|
-
this.#sqliteDatabase.exec("COMMIT");
|
|
30189
|
-
} catch (error62) {
|
|
30190
|
-
this.#sqliteDatabase.exec("ROLLBACK");
|
|
30191
|
-
throw error62;
|
|
30192
|
-
}
|
|
30193
|
-
}
|
|
30194
|
-
};
|
|
30195
30063
|
close = () => {
|
|
30196
|
-
|
|
30064
|
+
try {
|
|
30065
|
+
this.#localDatabase.close();
|
|
30066
|
+
} finally {
|
|
30067
|
+
this.eventsV2.close();
|
|
30068
|
+
}
|
|
30197
30069
|
};
|
|
30198
30070
|
findNative = (agentId, nativeSessionId) => this.#database.select().from(acpSession).where(and(eq(acpSession.agentId, agentId), eq(acpSession.nativeSessionId, nativeSessionId))).all().map(decodeStoredSession);
|
|
30199
30071
|
list = () => this.#database.select().from(acpSession).orderBy(desc(acpSession.updatedAt)).all().map(decodeStoredSession);
|
|
@@ -30203,6 +30075,7 @@ var SqliteAcpSessionStore = class {
|
|
|
30203
30075
|
};
|
|
30204
30076
|
remove = (sessionId) => {
|
|
30205
30077
|
this.#database.delete(acpSession).where(eq(acpSession.sessionId, sessionId)).run();
|
|
30078
|
+
this.eventsV2.remove(sessionId);
|
|
30206
30079
|
};
|
|
30207
30080
|
write = (session) => {
|
|
30208
30081
|
const value = {
|
|
@@ -30228,7 +30101,7 @@ var RetryableAcpInitializationError = class extends AcpExecutionError {
|
|
|
30228
30101
|
}
|
|
30229
30102
|
};
|
|
30230
30103
|
function arraysEqual(left, right) {
|
|
30231
|
-
return left.length === right.length && left.every((value,
|
|
30104
|
+
return left.length === right.length && left.every((value, index2) => value === right[index2]);
|
|
30232
30105
|
}
|
|
30233
30106
|
function recordsEqual(left, right) {
|
|
30234
30107
|
const leftEntries = Object.entries(left);
|
|
@@ -30283,7 +30156,7 @@ var AgentSession = class _AgentSession {
|
|
|
30283
30156
|
commandId: () => this.#turn.commandId,
|
|
30284
30157
|
assertNativeSession: (sessionId) => this.assertNativeSession(sessionId),
|
|
30285
30158
|
observer: getObserver,
|
|
30286
|
-
recordSessionEventV2: this
|
|
30159
|
+
recordSessionEventV2: this.recordLifecycleEventV2
|
|
30287
30160
|
});
|
|
30288
30161
|
this.#connection = new AgentConnection(agent, cwd, this);
|
|
30289
30162
|
this.#contentExternalizer = contentExternalizer;
|
|
@@ -30391,12 +30264,17 @@ var AgentSession = class _AgentSession {
|
|
|
30391
30264
|
);
|
|
30392
30265
|
}
|
|
30393
30266
|
const history = await this.#completedHistory(signal, "ACP agent exited while loading history");
|
|
30394
|
-
return history.eventPage(eventLimit, cursor
|
|
30267
|
+
return history.eventPage(eventLimit, cursor);
|
|
30395
30268
|
};
|
|
30396
30269
|
async #completedHistory(signal, exitMessage) {
|
|
30397
30270
|
if (!this.#prompted && this.#nativeHistoryOwnership.kind === "fresh-session") {
|
|
30398
30271
|
if (this.#sessionLoad.kind === "not-requested") {
|
|
30399
|
-
this.#
|
|
30272
|
+
this.#store.eventsV2.reset(this.#mobiusSessionId);
|
|
30273
|
+
this.#sessionLoad = {
|
|
30274
|
+
history: new AcpHistoryReplay(this.#store.eventsV2, this.#mobiusSessionId),
|
|
30275
|
+
kind: "loaded",
|
|
30276
|
+
response: {}
|
|
30277
|
+
};
|
|
30400
30278
|
}
|
|
30401
30279
|
if (this.#sessionLoad.kind === "loaded") {
|
|
30402
30280
|
return this.#sessionLoad.history;
|
|
@@ -30411,7 +30289,8 @@ var AgentSession = class _AgentSession {
|
|
|
30411
30289
|
if (this.#sessionLoad.kind === "capturing") {
|
|
30412
30290
|
return await waitForSharedOperation(this.#sessionLoad.completion, signal);
|
|
30413
30291
|
}
|
|
30414
|
-
|
|
30292
|
+
this.#store.eventsV2.reset(this.#mobiusSessionId);
|
|
30293
|
+
const history = new AcpHistoryReplay(this.#store.eventsV2, this.#mobiusSessionId);
|
|
30415
30294
|
const completion = Promise.resolve().then(async () => {
|
|
30416
30295
|
try {
|
|
30417
30296
|
const response = await this.race(
|
|
@@ -30860,7 +30739,14 @@ var AgentSession = class _AgentSession {
|
|
|
30860
30739
|
if (this.#turn.running) {
|
|
30861
30740
|
throw new AcpExecutionError("Another prompt is already running in this conversation", {}, "session_busy");
|
|
30862
30741
|
}
|
|
30863
|
-
|
|
30742
|
+
if (!this.#capabilities.loadSession && this.#sessionLoad.kind === "not-requested") {
|
|
30743
|
+
this.#sessionLoad = {
|
|
30744
|
+
kind: "loaded",
|
|
30745
|
+
history: new AcpHistoryReplay(this.#store.eventsV2, this.#mobiusSessionId),
|
|
30746
|
+
response: {}
|
|
30747
|
+
};
|
|
30748
|
+
}
|
|
30749
|
+
const completedHistory = this.#capabilities.loadSession ? await this.#completedHistory(options.signal, "ACP agent exited while loading history before a prompt") : this.#sessionLoad.kind === "loaded" ? this.#sessionLoad.history : null;
|
|
30864
30750
|
const prompt = this.buildPrompt(options);
|
|
30865
30751
|
if (this.#sessionTitle === null || this.#sessionTitle.length === 0) {
|
|
30866
30752
|
this.#sessionTitle = truncate2(options.prompt, 500);
|
|
@@ -30886,14 +30772,19 @@ var AgentSession = class _AgentSession {
|
|
|
30886
30772
|
this.prepareAgentContent
|
|
30887
30773
|
);
|
|
30888
30774
|
this.#turn = running;
|
|
30889
|
-
this.#turnHistory = completedHistory === null ? null : new AcpHistoryReplay();
|
|
30775
|
+
this.#turnHistory = completedHistory === null ? null : new AcpHistoryReplay(this.#store.eventsV2, this.#mobiusSessionId);
|
|
30890
30776
|
const lifecycleV2 = options.lifecycleV2;
|
|
30891
30777
|
if (lifecycleV2 !== void 0) {
|
|
30892
|
-
await this
|
|
30893
|
-
payload: {
|
|
30778
|
+
await this.recordLifecycleEventV2({
|
|
30779
|
+
payload: {
|
|
30780
|
+
commandId: options.commandId,
|
|
30781
|
+
content: lifecycleV2.content,
|
|
30782
|
+
kind: "prompt.requested",
|
|
30783
|
+
...lifecycleV2.context === void 0 ? {} : { context: lifecycleV2.context }
|
|
30784
|
+
},
|
|
30894
30785
|
type: "lifecycle-metadata"
|
|
30895
30786
|
});
|
|
30896
|
-
await this
|
|
30787
|
+
await this.recordLifecycleEventV2({
|
|
30897
30788
|
payload: {
|
|
30898
30789
|
attemptId: lifecycleV2.attemptId,
|
|
30899
30790
|
commandId: options.commandId,
|
|
@@ -30956,7 +30847,7 @@ var AgentSession = class _AgentSession {
|
|
|
30956
30847
|
)
|
|
30957
30848
|
);
|
|
30958
30849
|
if (lifecycleV2 !== void 0) {
|
|
30959
|
-
await this
|
|
30850
|
+
await this.recordLifecycleEventV2({
|
|
30960
30851
|
payload: { commandId: options.commandId, kind: "prompt.completed", stopReason: result.stopReason },
|
|
30961
30852
|
type: "lifecycle-metadata"
|
|
30962
30853
|
});
|
|
@@ -30966,8 +30857,8 @@ var AgentSession = class _AgentSession {
|
|
|
30966
30857
|
await running.activities.finish();
|
|
30967
30858
|
const failure2 = error62 instanceof AcpExecutionError ? error62 : new AcpExecutionError("ACP agent execution failed", { cause: error62 });
|
|
30968
30859
|
if (lifecycleV2 !== void 0) {
|
|
30969
|
-
await this
|
|
30970
|
-
payload: {
|
|
30860
|
+
await this.recordLifecycleEventV2({
|
|
30861
|
+
payload: options.cancellationRequested?.() === true ? { commandId: options.commandId, kind: "prompt.completed", stopReason: "cancelled" } : {
|
|
30971
30862
|
attemptId: lifecycleV2.attemptId,
|
|
30972
30863
|
code: failure2.code,
|
|
30973
30864
|
commandId: options.commandId,
|
|
@@ -31003,11 +30894,16 @@ var AgentSession = class _AgentSession {
|
|
|
31003
30894
|
const prompt = this.buildPrompt(options);
|
|
31004
30895
|
const lifecycleV2 = options.lifecycleV2;
|
|
31005
30896
|
if (lifecycleV2 !== void 0) {
|
|
31006
|
-
await this
|
|
31007
|
-
payload: {
|
|
30897
|
+
await this.recordLifecycleEventV2({
|
|
30898
|
+
payload: {
|
|
30899
|
+
commandId: options.commandId,
|
|
30900
|
+
content: lifecycleV2.content,
|
|
30901
|
+
kind: "prompt.requested",
|
|
30902
|
+
...lifecycleV2.context === void 0 ? {} : { context: lifecycleV2.context }
|
|
30903
|
+
},
|
|
31008
30904
|
type: "lifecycle-metadata"
|
|
31009
30905
|
});
|
|
31010
|
-
await this
|
|
30906
|
+
await this.recordLifecycleEventV2({
|
|
31011
30907
|
payload: {
|
|
31012
30908
|
attemptId: lifecycleV2.attemptId,
|
|
31013
30909
|
commandId: options.commandId,
|
|
@@ -31037,7 +30933,7 @@ var AgentSession = class _AgentSession {
|
|
|
31037
30933
|
const outcome = response["outcome"];
|
|
31038
30934
|
if (outcome === "injected" || outcome === "startedNewTurn") {
|
|
31039
30935
|
if (lifecycleV2 !== void 0) {
|
|
31040
|
-
await this
|
|
30936
|
+
await this.recordLifecycleEventV2({
|
|
31041
30937
|
payload: { commandId: options.commandId, kind: "prompt.completed", stopReason: "steered" },
|
|
31042
30938
|
type: "lifecycle-metadata"
|
|
31043
30939
|
});
|
|
@@ -31062,7 +30958,7 @@ var AgentSession = class _AgentSession {
|
|
|
31062
30958
|
} catch (error62) {
|
|
31063
30959
|
const failure2 = error62 instanceof AcpExecutionError ? error62 : new AcpExecutionError("ACP agent execution failed", { cause: error62 });
|
|
31064
30960
|
if (lifecycleV2 !== void 0) {
|
|
31065
|
-
await this
|
|
30961
|
+
await this.recordLifecycleEventV2({
|
|
31066
30962
|
payload: {
|
|
31067
30963
|
attemptId: lifecycleV2.attemptId,
|
|
31068
30964
|
code: failure2.code,
|
|
@@ -31095,11 +30991,18 @@ var AgentSession = class _AgentSession {
|
|
|
31095
30991
|
onElicitation = (request, signal) => this.#interactions.onElicitation(request, signal);
|
|
31096
30992
|
onElicitationComplete = (notification) => this.#interactions.onElicitationComplete(notification);
|
|
31097
30993
|
onUpdate = (notification) => this.#updates.receive(notification);
|
|
31098
|
-
|
|
30994
|
+
recordControlEventV2 = async (event) => {
|
|
30995
|
+
if (this.#sessionLoad.kind !== "loaded") {
|
|
30996
|
+
return false;
|
|
30997
|
+
}
|
|
30998
|
+
await this.recordLifecycleEventV2(event);
|
|
30999
|
+
return true;
|
|
31000
|
+
};
|
|
31001
|
+
recordLifecycleEventV2 = async (event) => {
|
|
31099
31002
|
if (event.type !== "lifecycle-metadata" || this.#sessionLoad.kind !== "loaded") {
|
|
31100
31003
|
return;
|
|
31101
31004
|
}
|
|
31102
|
-
const position = this.#turnHistory === null ? this.#sessionLoad.history.recordLifecycle(event) : this.#
|
|
31005
|
+
const position = this.#turnHistory === null ? this.#sessionLoad.history.recordLifecycle(event) : this.#turnHistory.recordLifecycle(event);
|
|
31103
31006
|
await this.#getObserver().onSessionEventV2?.(this.#mobiusSessionId, event, position);
|
|
31104
31007
|
};
|
|
31105
31008
|
selectNativeSession = (sessionId) => {
|
|
@@ -31120,13 +31023,8 @@ var AgentSession = class _AgentSession {
|
|
|
31120
31023
|
} else {
|
|
31121
31024
|
const onSessionEventV2 = this.#getObserver().onSessionEventV2;
|
|
31122
31025
|
if (this.#turnHistory !== null) {
|
|
31123
|
-
|
|
31124
|
-
|
|
31125
|
-
await onSessionEventV2?.(
|
|
31126
|
-
this.#mobiusSessionId,
|
|
31127
|
-
{ payload: rawUpdate, type: "acp" },
|
|
31128
|
-
completedEventCount + turnPosition
|
|
31129
|
-
);
|
|
31026
|
+
await this.#turnHistory.record(update, rawUpdate, async (position) => {
|
|
31027
|
+
await onSessionEventV2?.(this.#mobiusSessionId, { payload: rawUpdate, type: "acp" }, position);
|
|
31130
31028
|
});
|
|
31131
31029
|
} else if (this.#sessionLoad.kind === "loaded") {
|
|
31132
31030
|
await this.#sessionLoad.history.record(update, rawUpdate, async (position) => {
|
|
@@ -31769,9 +31667,9 @@ var AcpContentExternalizer = class {
|
|
|
31769
31667
|
};
|
|
31770
31668
|
|
|
31771
31669
|
// src/external-content/local-external-content-store.ts
|
|
31772
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
31670
|
+
import { createHash, randomUUID as randomUUID2 } from "node:crypto";
|
|
31773
31671
|
import { lstat, mkdir, readdir as readdir2, realpath as realpath3, rename, rm, stat as stat3, utimes, writeFile } from "node:fs/promises";
|
|
31774
|
-
import { dirname
|
|
31672
|
+
import { dirname, join as join4 } from "node:path";
|
|
31775
31673
|
var contentRequest = /^mobius-content:(image|audio|resource):([a-f0-9]{64})$/u;
|
|
31776
31674
|
var CONTENT_LIFETIME_MILLISECONDS = 24 * 60 * 60 * 1e3;
|
|
31777
31675
|
var metadataSchema2 = external_exports.strictObject({
|
|
@@ -31790,7 +31688,7 @@ var UnretainedExternalContentStore = class {
|
|
|
31790
31688
|
};
|
|
31791
31689
|
};
|
|
31792
31690
|
async function atomicWrite(path2, bytes, signal) {
|
|
31793
|
-
const temporary = `${path2}.${
|
|
31691
|
+
const temporary = `${path2}.${randomUUID2()}.tmp`;
|
|
31794
31692
|
try {
|
|
31795
31693
|
await writeFile(temporary, bytes, { mode: 384, signal });
|
|
31796
31694
|
signal.throwIfAborted();
|
|
@@ -31807,7 +31705,7 @@ var LocalExternalContentStore = class {
|
|
|
31807
31705
|
#expirationTimer;
|
|
31808
31706
|
#cleanup = Promise.resolve();
|
|
31809
31707
|
constructor(stateDirectory) {
|
|
31810
|
-
this.#root = join4(stateDirectory, "tmp", "session-content",
|
|
31708
|
+
this.#root = join4(stateDirectory, "tmp", "session-content", randomUUID2());
|
|
31811
31709
|
this.#expirationTimer = setInterval(() => {
|
|
31812
31710
|
void this.#expire().catch(() => void 0);
|
|
31813
31711
|
}, 6e4);
|
|
@@ -31818,11 +31716,11 @@ var LocalExternalContentStore = class {
|
|
|
31818
31716
|
await mkdir(this.#root, { mode: 448, recursive: true });
|
|
31819
31717
|
const now = /* @__PURE__ */ new Date();
|
|
31820
31718
|
await utimes(this.#root, now, now);
|
|
31821
|
-
for (const directory of await readdir2(
|
|
31719
|
+
for (const directory of await readdir2(dirname(this.#root), { withFileTypes: true })) {
|
|
31822
31720
|
if (!directory.isDirectory() || !/^[a-f0-9-]{36}$/u.test(directory.name)) {
|
|
31823
31721
|
continue;
|
|
31824
31722
|
}
|
|
31825
|
-
const path2 = join4(
|
|
31723
|
+
const path2 = join4(dirname(this.#root), directory.name);
|
|
31826
31724
|
if (path2 === this.#root) {
|
|
31827
31725
|
continue;
|
|
31828
31726
|
}
|
|
@@ -31908,12 +31806,12 @@ var LocalExternalContentStore = class {
|
|
|
31908
31806
|
}
|
|
31909
31807
|
try {
|
|
31910
31808
|
const [resolvedDirectory, resolvedPath, file2] = await Promise.all([
|
|
31911
|
-
realpath3(
|
|
31809
|
+
realpath3(dirname(entry.path)),
|
|
31912
31810
|
realpath3(entry.path),
|
|
31913
31811
|
lstat(entry.path)
|
|
31914
31812
|
]);
|
|
31915
31813
|
signal.throwIfAborted();
|
|
31916
|
-
if (!file2.isFile() || file2.isSymbolicLink() ||
|
|
31814
|
+
if (!file2.isFile() || file2.isSymbolicLink() || dirname(resolvedPath) !== resolvedDirectory) {
|
|
31917
31815
|
return null;
|
|
31918
31816
|
}
|
|
31919
31817
|
return { mediaType: entry.mediaType, name: entry.name, path: resolvedPath };
|
|
@@ -31990,9 +31888,9 @@ var AcpProcessCapacityLock = class {
|
|
|
31990
31888
|
return await waiter.completion.promise;
|
|
31991
31889
|
} finally {
|
|
31992
31890
|
signal.removeEventListener("abort", waiter.cancel);
|
|
31993
|
-
const
|
|
31994
|
-
if (
|
|
31995
|
-
this.#waiters.splice(
|
|
31891
|
+
const index2 = this.#waiters.indexOf(waiter);
|
|
31892
|
+
if (index2 >= 0) {
|
|
31893
|
+
this.#waiters.splice(index2, 1);
|
|
31996
31894
|
}
|
|
31997
31895
|
}
|
|
31998
31896
|
};
|
|
@@ -32163,6 +32061,13 @@ var AgentRuntimeManager = class {
|
|
|
32163
32061
|
this.#contentExternalizer = contentExternalizer;
|
|
32164
32062
|
this.#queryProcesses = new AgentQueryProcesses(this.#processes, contentExternalizer);
|
|
32165
32063
|
}
|
|
32064
|
+
recordLifecycleEventV2 = async (sessionId, event) => {
|
|
32065
|
+
const runtime = this.#executionProcesses.get(sessionId);
|
|
32066
|
+
if (runtime === void 0) {
|
|
32067
|
+
return false;
|
|
32068
|
+
}
|
|
32069
|
+
return await runtime.recordControlEventV2(event);
|
|
32070
|
+
};
|
|
32166
32071
|
setObserver = (observer) => {
|
|
32167
32072
|
this.#observer = observer;
|
|
32168
32073
|
};
|
|
@@ -32492,7 +32397,10 @@ var AgentRuntimeManager = class {
|
|
|
32492
32397
|
return { stopReason: "cancelled" };
|
|
32493
32398
|
}
|
|
32494
32399
|
try {
|
|
32495
|
-
const result = await runtime.prompt(
|
|
32400
|
+
const result = await runtime.prompt({
|
|
32401
|
+
...options2,
|
|
32402
|
+
cancellationRequested: () => this.#executions.cancellation(options2.sessionId) !== void 0
|
|
32403
|
+
});
|
|
32496
32404
|
return this.#executions.cancellation(options2.sessionId) !== void 0 ? { stopReason: "cancelled" } : result;
|
|
32497
32405
|
} catch (error62) {
|
|
32498
32406
|
if (this.#executions.cancellation(options2.sessionId) !== void 0) {
|
|
@@ -32979,7 +32887,7 @@ var LocalAgentInventory = class {
|
|
|
32979
32887
|
|
|
32980
32888
|
// src/agent-installation/managed-npm-package.ts
|
|
32981
32889
|
import { mkdir as mkdir2, mkdtemp, open as open3, realpath as realpath4, rename as rename2, rm as rm2, stat as stat4 } from "node:fs/promises";
|
|
32982
|
-
import { delimiter, dirname as
|
|
32890
|
+
import { delimiter, dirname as dirname2, isAbsolute as isAbsolute2, join as join5, relative, sep } from "node:path";
|
|
32983
32891
|
var INSTALL_TIMEOUT_MILLISECONDS = 5 * 60 * 1e3;
|
|
32984
32892
|
var PACKAGE_METADATA_LIMIT_BYTES = 64 * 1024;
|
|
32985
32893
|
var PACKAGE_LOCK_LIMIT_BYTES = 8 * 1024 * 1024;
|
|
@@ -33209,7 +33117,7 @@ var ManagedNpmPackageInstaller = class {
|
|
|
33209
33117
|
throw error62;
|
|
33210
33118
|
}
|
|
33211
33119
|
}
|
|
33212
|
-
const parent =
|
|
33120
|
+
const parent = dirname2(root);
|
|
33213
33121
|
await mkdir2(parent, { mode: 448, recursive: true });
|
|
33214
33122
|
const staging = await mkdtemp(join5(parent, `.${definition.version}.staging-`));
|
|
33215
33123
|
try {
|
|
@@ -33244,7 +33152,7 @@ var ManagedNpmPackageInstaller = class {
|
|
|
33244
33152
|
NPM_CONFIG_IGNORE_SCRIPTS: "true",
|
|
33245
33153
|
NPM_CONFIG_PACKAGE_LOCK: "true",
|
|
33246
33154
|
NPM_CONFIG_REGISTRY: "https://registry.npmjs.org/",
|
|
33247
|
-
PATH: `${
|
|
33155
|
+
PATH: `${dirname2(process.execPath)}${delimiter}/usr/bin${delimiter}/bin`
|
|
33248
33156
|
};
|
|
33249
33157
|
if (definition.includeOptionalDependencies) {
|
|
33250
33158
|
installEnvironment["NPM_CONFIG_INCLUDE"] = "optional";
|
|
@@ -34688,14 +34596,6 @@ var CodexAcpAgent = class {
|
|
|
34688
34596
|
if (isCompactPrompt(context.params.prompt)) {
|
|
34689
34597
|
return await this.#compact(context.signal);
|
|
34690
34598
|
}
|
|
34691
|
-
const messageId = crypto.randomUUID();
|
|
34692
|
-
for (const content of context.params.prompt) {
|
|
34693
|
-
await this.#emit({
|
|
34694
|
-
content,
|
|
34695
|
-
messageId,
|
|
34696
|
-
sessionUpdate: "user_message_chunk"
|
|
34697
|
-
});
|
|
34698
|
-
}
|
|
34699
34599
|
return await this.#runTurn(promptInput(context.params.prompt), context.signal);
|
|
34700
34600
|
}).onRequest(
|
|
34701
34601
|
"_session/steering",
|
|
@@ -35181,10 +35081,6 @@ var CodexAcpAgent = class {
|
|
|
35181
35081
|
if (steering.length === 0) {
|
|
35182
35082
|
throw new AcpExecutionError("Codex received an empty steering request", {}, "invalid_request");
|
|
35183
35083
|
}
|
|
35184
|
-
const messageId = crypto.randomUUID();
|
|
35185
|
-
for (const block of steering) {
|
|
35186
|
-
await this.#emit({ content: block.content, messageId, sessionUpdate: "user_message_chunk" });
|
|
35187
|
-
}
|
|
35188
35084
|
const response = turnSteerResponseSchema.parse(
|
|
35189
35085
|
await this.#appServer.request(
|
|
35190
35086
|
"turn/steer",
|
|
@@ -35729,7 +35625,7 @@ import { join as join11 } from "node:path";
|
|
|
35729
35625
|
import { createHash as createHash2 } from "node:crypto";
|
|
35730
35626
|
import { createReadStream } from "node:fs";
|
|
35731
35627
|
import { chmod, copyFile, mkdir as mkdir4, mkdtemp as mkdtemp2, open as open4, realpath as realpath7, rename as rename3, rm as rm3, stat as stat6, writeFile as writeFile3 } from "node:fs/promises";
|
|
35732
|
-
import { delimiter as delimiter2, dirname as
|
|
35628
|
+
import { delimiter as delimiter2, dirname as dirname3, isAbsolute as isAbsolute6, join as join10, relative as relative3, sep as sep3 } from "node:path";
|
|
35733
35629
|
|
|
35734
35630
|
// src/agent-installation/verified-download.ts
|
|
35735
35631
|
import { fetch } from "undici";
|
|
@@ -36588,9 +36484,9 @@ function comparePrerelease(left, right) {
|
|
|
36588
36484
|
if (left.length === 0 || right.length === 0) {
|
|
36589
36485
|
return left.length === right.length ? 0 : left.length === 0 ? 1 : -1;
|
|
36590
36486
|
}
|
|
36591
|
-
for (let
|
|
36592
|
-
const leftPart = left[
|
|
36593
|
-
const rightPart = right[
|
|
36487
|
+
for (let index2 = 0; index2 < Math.max(left.length, right.length); index2 += 1) {
|
|
36488
|
+
const leftPart = left[index2];
|
|
36489
|
+
const rightPart = right[index2];
|
|
36594
36490
|
if (leftPart === void 0 || rightPart === void 0) {
|
|
36595
36491
|
return leftPart === rightPart ? 0 : leftPart === void 0 ? -1 : 1;
|
|
36596
36492
|
}
|
|
@@ -36615,8 +36511,8 @@ function compareAgentVersions(left, right) {
|
|
|
36615
36511
|
if (parsedLeft === null || parsedRight === null) {
|
|
36616
36512
|
return null;
|
|
36617
36513
|
}
|
|
36618
|
-
for (let
|
|
36619
|
-
const difference = (parsedLeft.core[
|
|
36514
|
+
for (let index2 = 0; index2 < Math.max(parsedLeft.core.length, parsedRight.core.length); index2 += 1) {
|
|
36515
|
+
const difference = (parsedLeft.core[index2] ?? 0) - (parsedRight.core[index2] ?? 0);
|
|
36620
36516
|
if (difference !== 0) {
|
|
36621
36517
|
return Math.sign(difference);
|
|
36622
36518
|
}
|
|
@@ -37037,9 +36933,9 @@ async function discoverLocalAgentInventory(options) {
|
|
|
37037
36933
|
}
|
|
37038
36934
|
|
|
37039
36935
|
// src/storage/runtime-installation-store.ts
|
|
37040
|
-
import { createHash as createHash3, randomUUID as
|
|
36936
|
+
import { createHash as createHash3, randomUUID as randomUUID3 } from "node:crypto";
|
|
37041
36937
|
import { mkdir as mkdir5, open as open5, readdir as readdir3, rename as rename4, unlink, writeFile as writeFile4 } from "node:fs/promises";
|
|
37042
|
-
import { dirname as
|
|
36938
|
+
import { dirname as dirname4, join as join16, resolve as resolve4 } from "node:path";
|
|
37043
36939
|
var APPLICATION_ID_PATTERN = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+){1,31}$/;
|
|
37044
36940
|
var CONNECTION_ID_PATTERN = /^mcn_[a-f0-9]{32}$/;
|
|
37045
36941
|
var INSTALLATION_ID_PATTERN = /^min_[a-f0-9]{32}$/;
|
|
@@ -37167,10 +37063,10 @@ function parseRelayOrigin(value) {
|
|
|
37167
37063
|
return origin;
|
|
37168
37064
|
}
|
|
37169
37065
|
function connectionId() {
|
|
37170
|
-
return `mcn_${
|
|
37066
|
+
return `mcn_${randomUUID3().replaceAll("-", "")}`;
|
|
37171
37067
|
}
|
|
37172
37068
|
function installationId() {
|
|
37173
|
-
return `min_${
|
|
37069
|
+
return `min_${randomUUID3().replaceAll("-", "")}`;
|
|
37174
37070
|
}
|
|
37175
37071
|
function channelIndexFileName(channelId) {
|
|
37176
37072
|
return `mci_${createHash3("sha256").update(channelId).digest("hex")}.json`;
|
|
@@ -37281,8 +37177,8 @@ async function readJsonFile(path2, signal, missingCode) {
|
|
|
37281
37177
|
}
|
|
37282
37178
|
async function writeJsonAtomically(path2, value, signal) {
|
|
37283
37179
|
signal.throwIfAborted();
|
|
37284
|
-
const directory =
|
|
37285
|
-
const temporaryPath = join16(directory, `.${
|
|
37180
|
+
const directory = dirname4(path2);
|
|
37181
|
+
const temporaryPath = join16(directory, `.${randomUUID3()}.tmp`);
|
|
37286
37182
|
try {
|
|
37287
37183
|
await mkdir5(directory, { mode: 448, recursive: true });
|
|
37288
37184
|
signal.throwIfAborted();
|
|
@@ -37359,16 +37255,16 @@ var RuntimeInstallationStore = class _RuntimeInstallationStore {
|
|
|
37359
37255
|
};
|
|
37360
37256
|
#readConnectionForChannel = async (channelId, signal) => {
|
|
37361
37257
|
const normalizedChannelId = validateIdentifier(channelId, "invalid_channel_id");
|
|
37362
|
-
const
|
|
37258
|
+
const index2 = decodeChannelIndex(
|
|
37363
37259
|
await readJsonFile(this.channelIndexPath(normalizedChannelId), signal, "connection_not_found")
|
|
37364
37260
|
);
|
|
37365
|
-
if (
|
|
37261
|
+
if (index2.applicationId !== this.applicationId || index2.installationId !== this.installationId || index2.channelId !== normalizedChannelId) {
|
|
37366
37262
|
throw new RuntimeInstallationStoreError(
|
|
37367
37263
|
"connection_owner_mismatch",
|
|
37368
37264
|
"The saved Runtime connection belongs to another installation"
|
|
37369
37265
|
);
|
|
37370
37266
|
}
|
|
37371
|
-
return await this.readConnection(
|
|
37267
|
+
return await this.readConnection(index2.connectionId, signal);
|
|
37372
37268
|
};
|
|
37373
37269
|
saveConnection = async (input2, signal) => {
|
|
37374
37270
|
const stored = new VerifiedRuntimeConnection(
|
|
@@ -37563,16 +37459,16 @@ function hasExactKeys2(value, expectedKeys) {
|
|
|
37563
37459
|
}
|
|
37564
37460
|
function readSingleOption(arguments_, option) {
|
|
37565
37461
|
const values = [];
|
|
37566
|
-
for (let
|
|
37567
|
-
if (arguments_[
|
|
37462
|
+
for (let index2 = 0; index2 < arguments_.length; index2 += 1) {
|
|
37463
|
+
if (arguments_[index2] !== option) {
|
|
37568
37464
|
continue;
|
|
37569
37465
|
}
|
|
37570
|
-
const value = arguments_[
|
|
37466
|
+
const value = arguments_[index2 + 1];
|
|
37571
37467
|
if (value === void 0 || value.startsWith("--")) {
|
|
37572
37468
|
throw new PairingClientError("invalid_arguments", `${option} requires a value`);
|
|
37573
37469
|
}
|
|
37574
37470
|
values.push(value);
|
|
37575
|
-
|
|
37471
|
+
index2 += 1;
|
|
37576
37472
|
}
|
|
37577
37473
|
if (values.length !== 1) {
|
|
37578
37474
|
throw new PairingClientError("invalid_arguments", `${option} must be provided exactly once`);
|
|
@@ -37580,8 +37476,8 @@ function readSingleOption(arguments_, option) {
|
|
|
37580
37476
|
return values[0] ?? "";
|
|
37581
37477
|
}
|
|
37582
37478
|
function assertKnownArguments(arguments_) {
|
|
37583
|
-
for (let
|
|
37584
|
-
const option = arguments_[
|
|
37479
|
+
for (let index2 = 0; index2 < arguments_.length; index2 += 2) {
|
|
37480
|
+
const option = arguments_[index2];
|
|
37585
37481
|
if (option !== "--url" && option !== "--code" && option !== "--pairing" && option !== "--workspace") {
|
|
37586
37482
|
throw new PairingClientError("invalid_arguments", `Unknown pairing option: ${option ?? "missing option"}`);
|
|
37587
37483
|
}
|
|
@@ -37872,7 +37768,7 @@ function isRuntimeRelayRevocation(closeCode, closeReason) {
|
|
|
37872
37768
|
}
|
|
37873
37769
|
|
|
37874
37770
|
// src/run-daemon.ts
|
|
37875
|
-
import { createHash as createHash8, randomUUID as
|
|
37771
|
+
import { createHash as createHash8, randomUUID as randomUUID10 } from "node:crypto";
|
|
37876
37772
|
import { join as join19 } from "node:path";
|
|
37877
37773
|
import { styleText } from "node:util";
|
|
37878
37774
|
|
|
@@ -38451,7 +38347,7 @@ var FixedInstallationExecutor = class {
|
|
|
38451
38347
|
// src/authorization/workspace-directory.ts
|
|
38452
38348
|
import { readdir as readdir4, realpath as realpath9, stat as stat8 } from "node:fs/promises";
|
|
38453
38349
|
import { homedir as homedir2 } from "node:os";
|
|
38454
|
-
import { basename as basename4, dirname as
|
|
38350
|
+
import { basename as basename4, dirname as dirname5, isAbsolute as isAbsolute9, join as join17, normalize as normalize3, relative as relative4 } from "node:path";
|
|
38455
38351
|
var WorkspaceDirectoryListing = class {
|
|
38456
38352
|
directoryId;
|
|
38457
38353
|
directoryLabel;
|
|
@@ -38579,7 +38475,7 @@ var WorkspaceDirectoryService = class {
|
|
|
38579
38475
|
}
|
|
38580
38476
|
}
|
|
38581
38477
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
38582
|
-
const parent =
|
|
38478
|
+
const parent = dirname5(target);
|
|
38583
38479
|
return new WorkspaceDirectoryListing(
|
|
38584
38480
|
id,
|
|
38585
38481
|
this.label(target),
|
|
@@ -38604,7 +38500,7 @@ var WorkspaceDirectoryService = class {
|
|
|
38604
38500
|
};
|
|
38605
38501
|
|
|
38606
38502
|
// src/daemon-diagnostic-log.ts
|
|
38607
|
-
import { appendFileSync, mkdirSync
|
|
38503
|
+
import { appendFileSync, mkdirSync, readFileSync as readFileSync2, renameSync, statSync as statSync3, writeFileSync } from "node:fs";
|
|
38608
38504
|
import { join as join18 } from "node:path";
|
|
38609
38505
|
var MAXIMUM_DAEMON_LOG_BYTES = 1 * 1024 * 1024;
|
|
38610
38506
|
var DaemonDiagnosticLog = class {
|
|
@@ -38620,7 +38516,7 @@ var DaemonDiagnosticLog = class {
|
|
|
38620
38516
|
const encoded = `${diagnostic.replace(/[\r\n]+/gu, " ").trim()}
|
|
38621
38517
|
`;
|
|
38622
38518
|
const encodedBytes = Buffer.byteLength(encoded);
|
|
38623
|
-
|
|
38519
|
+
mkdirSync(this.#directory, { mode: 448, recursive: true });
|
|
38624
38520
|
let existingBytes = 0;
|
|
38625
38521
|
try {
|
|
38626
38522
|
existingBytes = statSync3(this.#path).size;
|
|
@@ -38878,16 +38774,7 @@ function send(socket, message) {
|
|
|
38878
38774
|
}
|
|
38879
38775
|
socket.send(encodeDaemonToServiceMessage(message));
|
|
38880
38776
|
}
|
|
38881
|
-
function
|
|
38882
|
-
publisher.publish(command.sessionId, {
|
|
38883
|
-
code,
|
|
38884
|
-
commandId: command.commandId,
|
|
38885
|
-
kind: SESSION_FAILED_KIND,
|
|
38886
|
-
message,
|
|
38887
|
-
sessionId: command.sessionId
|
|
38888
|
-
});
|
|
38889
|
-
}
|
|
38890
|
-
function settleAbandonedTurn(publisher, operations, audit, cancellation) {
|
|
38777
|
+
async function settleAbandonedTurn(eventLog, operations, audit, cancellation) {
|
|
38891
38778
|
const attemptId = operations.findUnsettledAttemptId(cancellation.commandId, cancellation.sessionId);
|
|
38892
38779
|
if (attemptId === null) {
|
|
38893
38780
|
console.warn("Mobius daemon ignored cancellation for an inactive turn");
|
|
@@ -38898,13 +38785,14 @@ function settleAbandonedTurn(publisher, operations, audit, cancellation) {
|
|
|
38898
38785
|
event: "session_abandoned_turn_settled",
|
|
38899
38786
|
sessionId: cancellation.sessionId
|
|
38900
38787
|
});
|
|
38901
|
-
|
|
38902
|
-
|
|
38903
|
-
cancellation,
|
|
38788
|
+
await eventLog.failed(
|
|
38789
|
+
cancellation.sessionId,
|
|
38790
|
+
cancellation.commandId,
|
|
38904
38791
|
"agent_execution_abandoned",
|
|
38905
38792
|
"The local Agent execution was abandoned before it completed"
|
|
38906
38793
|
);
|
|
38907
38794
|
operations.transitionExecution(cancellation.commandId, "failed");
|
|
38795
|
+
eventLog.publishTerminal(cancellation.sessionId, cancellation.commandId);
|
|
38908
38796
|
}
|
|
38909
38797
|
function operationErrorCode(error62) {
|
|
38910
38798
|
if (error62 instanceof AcpExecutionError || error62 instanceof LocalAuthorizationError || error62 instanceof LocalAgentCatalogError || error62 instanceof PromptArtifactError) {
|
|
@@ -39085,7 +38973,7 @@ var DaemonInstallationObserver = class {
|
|
|
39085
38973
|
};
|
|
39086
38974
|
|
|
39087
38975
|
// src/daemon-active-turn.ts
|
|
39088
|
-
import { randomUUID as
|
|
38976
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
39089
38977
|
function activeMessageCharacters(message) {
|
|
39090
38978
|
return message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0);
|
|
39091
38979
|
}
|
|
@@ -39093,8 +38981,8 @@ var ACTIVE_TURN_TEXT_CHUNK_LIMIT = Math.floor(SESSION_HISTORY_CHARACTER_LIMIT /
|
|
|
39093
38981
|
function boundedRecoveryMessages(messages) {
|
|
39094
38982
|
const selected = [];
|
|
39095
38983
|
let remainingCharacters = SESSION_HISTORY_CHARACTER_LIMIT;
|
|
39096
|
-
for (let
|
|
39097
|
-
const message = messages[
|
|
38984
|
+
for (let index2 = messages.length - 1; index2 >= 0 && selected.length < SESSION_HISTORY_MESSAGE_LIMIT; index2 -= 1) {
|
|
38985
|
+
const message = messages[index2];
|
|
39098
38986
|
if (message === void 0) {
|
|
39099
38987
|
break;
|
|
39100
38988
|
}
|
|
@@ -39119,7 +39007,7 @@ var ActiveDaemonTurn = class {
|
|
|
39119
39007
|
#timeline;
|
|
39120
39008
|
#sequence = 0;
|
|
39121
39009
|
#interaction = null;
|
|
39122
|
-
#epoch = decodeIdentifier(
|
|
39010
|
+
#epoch = decodeIdentifier(randomUUID4());
|
|
39123
39011
|
constructor(command, attemptId) {
|
|
39124
39012
|
this.attemptId = attemptId;
|
|
39125
39013
|
this.command = command;
|
|
@@ -39181,7 +39069,7 @@ var ActiveDaemonTurn = class {
|
|
|
39181
39069
|
if (!this.#activities.has(event.activityId)) {
|
|
39182
39070
|
this.#timeline = [
|
|
39183
39071
|
...this.#timeline,
|
|
39184
|
-
{ activityId: event.activityId, id: decodeIdentifier(
|
|
39072
|
+
{ activityId: event.activityId, id: decodeIdentifier(randomUUID4()), kind: "activity" }
|
|
39185
39073
|
];
|
|
39186
39074
|
}
|
|
39187
39075
|
this.#activities.set(event.activityId, {
|
|
@@ -39202,7 +39090,7 @@ var ActiveDaemonTurn = class {
|
|
|
39202
39090
|
if (previous === void 0) {
|
|
39203
39091
|
this.#timeline = [
|
|
39204
39092
|
...this.#timeline,
|
|
39205
|
-
{ activityId: event.activityId, id: decodeIdentifier(
|
|
39093
|
+
{ activityId: event.activityId, id: decodeIdentifier(randomUUID4()), kind: "activity" }
|
|
39206
39094
|
];
|
|
39207
39095
|
}
|
|
39208
39096
|
this.#activities.set(event.activityId, {
|
|
@@ -39227,7 +39115,7 @@ var ActiveDaemonTurn = class {
|
|
|
39227
39115
|
...this.#timeline,
|
|
39228
39116
|
{
|
|
39229
39117
|
content: /* @__PURE__ */ new Map([[event.contentId, event.content]]),
|
|
39230
|
-
id: decodeIdentifier(
|
|
39118
|
+
id: decodeIdentifier(randomUUID4()),
|
|
39231
39119
|
kind: "message",
|
|
39232
39120
|
sourceMessageId: event.messageId,
|
|
39233
39121
|
text: ""
|
|
@@ -39235,7 +39123,7 @@ var ActiveDaemonTurn = class {
|
|
|
39235
39123
|
];
|
|
39236
39124
|
} else {
|
|
39237
39125
|
this.#timeline = this.#timeline.map(
|
|
39238
|
-
(entry,
|
|
39126
|
+
(entry, index2) => index2 === target && entry.kind === "message" ? { ...entry, content: new Map([...entry.content, [event.contentId, event.content]]) } : entry
|
|
39239
39127
|
);
|
|
39240
39128
|
}
|
|
39241
39129
|
} else if (event.kind === SESSION_PERMISSION_REQUESTED_KIND || event.kind === SESSION_ELICITATION_REQUESTED_KIND) {
|
|
@@ -39267,7 +39155,7 @@ var ActiveDaemonTurn = class {
|
|
|
39267
39155
|
...this.#timeline,
|
|
39268
39156
|
{
|
|
39269
39157
|
content: /* @__PURE__ */ new Map(),
|
|
39270
|
-
id: decodeIdentifier(
|
|
39158
|
+
id: decodeIdentifier(randomUUID4()),
|
|
39271
39159
|
kind: "message",
|
|
39272
39160
|
sourceMessageId: messageId,
|
|
39273
39161
|
text: remaining.slice(0, ACTIVE_TURN_TEXT_CHUNK_LIMIT)
|
|
@@ -39538,6 +39426,202 @@ var DaemonTurnRegistry = class {
|
|
|
39538
39426
|
};
|
|
39539
39427
|
};
|
|
39540
39428
|
|
|
39429
|
+
// src/generated/acp-session-store-migrations.ts
|
|
39430
|
+
var acpSessionStoreMigrations = [
|
|
39431
|
+
{
|
|
39432
|
+
"name": "0000_slimy_captain_midlands.sql",
|
|
39433
|
+
"sql": "CREATE TABLE `acp_session` (\n `session_id` text PRIMARY KEY NOT NULL,\n `agent_id` text NOT NULL,\n `native_session_id` text NOT NULL,\n `cwd` text NOT NULL,\n `additional_directories` text NOT NULL,\n `prompted` integer NOT NULL,\n `title` text NOT NULL,\n `updated_at` text NOT NULL\n);\n--> statement-breakpoint\nCREATE TABLE `deleted_acp_session` (\n `session_id` text PRIMARY KEY NOT NULL\n);\n"
|
|
39434
|
+
},
|
|
39435
|
+
{
|
|
39436
|
+
"name": "0001_regular_ultimates.sql",
|
|
39437
|
+
"sql": "ALTER TABLE `acp_session` ADD `last_terminal_command_id` text;"
|
|
39438
|
+
},
|
|
39439
|
+
{
|
|
39440
|
+
"name": "0002_equal_black_queen.sql",
|
|
39441
|
+
"sql": "CREATE TABLE `session_event_v2` (\n `event_id` text PRIMARY KEY NOT NULL,\n `event_json` text NOT NULL,\n `position` integer NOT NULL,\n `session_id` text NOT NULL\n);\n--> statement-breakpoint\nCREATE UNIQUE INDEX `session_event_v2_session_position_unique` ON `session_event_v2` (`session_id`,`position`);--> statement-breakpoint\nCREATE INDEX `session_event_v2_session_position_index` ON `session_event_v2` (`session_id`,`position`);"
|
|
39442
|
+
},
|
|
39443
|
+
{
|
|
39444
|
+
"name": "0003_silky_ravenous.sql",
|
|
39445
|
+
"sql": "DROP TABLE `session_event_v2`;"
|
|
39446
|
+
},
|
|
39447
|
+
{
|
|
39448
|
+
"name": "0004_special_mathemanic.sql",
|
|
39449
|
+
"sql": "DROP TABLE `deleted_acp_session`;--> statement-breakpoint\nALTER TABLE `acp_session` DROP COLUMN `last_terminal_command_id`;"
|
|
39450
|
+
}
|
|
39451
|
+
];
|
|
39452
|
+
|
|
39453
|
+
// src/generated/session-event-cache-migrations.ts
|
|
39454
|
+
var sessionEventCacheMigrations = [
|
|
39455
|
+
{
|
|
39456
|
+
"name": "migration.sql",
|
|
39457
|
+
"sql": "CREATE TABLE `session_event_v2` (\n `event_json` text NOT NULL,\n `generation_id` text NOT NULL,\n `position` integer NOT NULL,\n `session_id` text NOT NULL,\n CONSTRAINT `session_event_v2_pk` PRIMARY KEY(`generation_id`, `session_id`, `position`)\n);\n--> statement-breakpoint\nCREATE INDEX `session_event_v2_generation_session_position_index` ON `session_event_v2` (`generation_id`,`session_id`,`position`);"
|
|
39458
|
+
}
|
|
39459
|
+
];
|
|
39460
|
+
|
|
39461
|
+
// src/infra/local-sqlite-database.ts
|
|
39462
|
+
import { chmodSync, mkdirSync as mkdirSync2 } from "node:fs";
|
|
39463
|
+
import { dirname as dirname6 } from "node:path";
|
|
39464
|
+
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
39465
|
+
|
|
39466
|
+
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/node-sqlite/session.js
|
|
39467
|
+
var NodeSQLiteSession = class extends SQLiteAsyncSession {
|
|
39468
|
+
static [entityKind] = "SQLJsSession";
|
|
39469
|
+
logger;
|
|
39470
|
+
constructor(client2, dialect, relations, options = {}) {
|
|
39471
|
+
super(dialect, "sync");
|
|
39472
|
+
this.client = client2;
|
|
39473
|
+
this.relations = relations;
|
|
39474
|
+
this.options = options;
|
|
39475
|
+
this.logger = options.logger ?? new NoopLogger();
|
|
39476
|
+
}
|
|
39477
|
+
prepareQuery(query, mode, _prepare, executeMethod, mapper, queryMetadata) {
|
|
39478
|
+
let stmt;
|
|
39479
|
+
try {
|
|
39480
|
+
stmt = this.client.prepare(query.sql);
|
|
39481
|
+
} catch (e) {
|
|
39482
|
+
throw new DrizzleQueryError(query.sql, query.params, e);
|
|
39483
|
+
}
|
|
39484
|
+
return new SQLiteAsyncPreparedQuery("sync", executeMethod, {
|
|
39485
|
+
all: (params) => {
|
|
39486
|
+
stmt.setReturnArrays(mode === "arrays");
|
|
39487
|
+
const res = stmt.all(...params);
|
|
39488
|
+
if (mode === "objects") return res.map((row) => ({ ...row }));
|
|
39489
|
+
return res;
|
|
39490
|
+
},
|
|
39491
|
+
get: (params) => {
|
|
39492
|
+
stmt.setReturnArrays(mode === "arrays");
|
|
39493
|
+
const res = stmt.get(...params);
|
|
39494
|
+
if (res && mode === "objects") return { ...res };
|
|
39495
|
+
return res;
|
|
39496
|
+
},
|
|
39497
|
+
run: (params) => {
|
|
39498
|
+
stmt.setReturnArrays(false);
|
|
39499
|
+
return stmt.run(...params);
|
|
39500
|
+
},
|
|
39501
|
+
values: (params) => {
|
|
39502
|
+
stmt.setReturnArrays(true);
|
|
39503
|
+
return stmt.all(...params);
|
|
39504
|
+
}
|
|
39505
|
+
}, query, mapper, mode, this.logger, void 0, queryMetadata, void 0);
|
|
39506
|
+
}
|
|
39507
|
+
transaction(transaction, config2 = {}) {
|
|
39508
|
+
const tx = new NodeSQLiteTransaction("sync", this.dialect, this, this.relations);
|
|
39509
|
+
this.run(sql.raw(`begin${config2.behavior ? ` ${config2.behavior}` : ""}`));
|
|
39510
|
+
try {
|
|
39511
|
+
const result = transaction(tx);
|
|
39512
|
+
this.run(sql`commit`);
|
|
39513
|
+
return result;
|
|
39514
|
+
} catch (err) {
|
|
39515
|
+
this.run(sql`rollback`);
|
|
39516
|
+
throw err;
|
|
39517
|
+
}
|
|
39518
|
+
}
|
|
39519
|
+
};
|
|
39520
|
+
var NodeSQLiteTransaction = class NodeSQLiteTransaction2 extends SQLiteAsyncTransaction {
|
|
39521
|
+
static [entityKind] = "SQLJsTransaction";
|
|
39522
|
+
transaction(transaction) {
|
|
39523
|
+
const savepointName = `sp${this.nestedIndex + 1}`;
|
|
39524
|
+
const tx = new NodeSQLiteTransaction2("sync", this.dialect, this.session, this._.relations, this.nestedIndex + 1);
|
|
39525
|
+
tx.run(sql.raw(`savepoint ${savepointName}`));
|
|
39526
|
+
try {
|
|
39527
|
+
const result = transaction(tx);
|
|
39528
|
+
tx.run(sql.raw(`release savepoint ${savepointName}`));
|
|
39529
|
+
return result;
|
|
39530
|
+
} catch (err) {
|
|
39531
|
+
tx.run(sql.raw(`rollback to savepoint ${savepointName}`));
|
|
39532
|
+
throw err;
|
|
39533
|
+
}
|
|
39534
|
+
}
|
|
39535
|
+
};
|
|
39536
|
+
|
|
39537
|
+
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/node-sqlite/driver.js
|
|
39538
|
+
import { DatabaseSync } from "node:sqlite";
|
|
39539
|
+
var NodeSQLiteDatabase = class extends SQLiteAsyncDatabase {
|
|
39540
|
+
static [entityKind] = "NodeSQLiteDatabase";
|
|
39541
|
+
};
|
|
39542
|
+
function construct(client2, config2 = {}) {
|
|
39543
|
+
const dialect = new SQLiteDialect({ useJitMappers: jitCompatCheck(config2.jit) });
|
|
39544
|
+
let logger;
|
|
39545
|
+
if (config2.logger === true) logger = new DefaultLogger();
|
|
39546
|
+
else if (config2.logger !== false) logger = config2.logger;
|
|
39547
|
+
const relations = config2.relations ?? {};
|
|
39548
|
+
const db = new NodeSQLiteDatabase("sync", dialect, new NodeSQLiteSession(client2, dialect, relations, { logger }), relations);
|
|
39549
|
+
db.$client = client2;
|
|
39550
|
+
return db;
|
|
39551
|
+
}
|
|
39552
|
+
function drizzle(...params) {
|
|
39553
|
+
if (params[0] === void 0 || typeof params[0] === "string") return construct(params[0] === void 0 ? new DatabaseSync(":memory:") : new DatabaseSync(params[0]), params[1]);
|
|
39554
|
+
const { connection, client: client2, ...config2 } = params[0];
|
|
39555
|
+
if (client2) return construct(client2, config2);
|
|
39556
|
+
if (typeof connection === "object") {
|
|
39557
|
+
const { path: path2, ...options } = connection;
|
|
39558
|
+
return construct(new DatabaseSync(path2 ?? ":memory:", options), config2);
|
|
39559
|
+
}
|
|
39560
|
+
return construct(new DatabaseSync(connection ?? ":memory:"), config2);
|
|
39561
|
+
}
|
|
39562
|
+
(function(_drizzle) {
|
|
39563
|
+
function mock(config2) {
|
|
39564
|
+
return construct({}, config2);
|
|
39565
|
+
}
|
|
39566
|
+
_drizzle.mock = mock;
|
|
39567
|
+
})(drizzle || (drizzle = {}));
|
|
39568
|
+
|
|
39569
|
+
// src/infra/local-sqlite-database.ts
|
|
39570
|
+
var LocalSqliteDatabase = class {
|
|
39571
|
+
orm;
|
|
39572
|
+
#sqlite;
|
|
39573
|
+
constructor(path2, label, migrations, pragmas = []) {
|
|
39574
|
+
mkdirSync2(dirname6(path2), { mode: 448, recursive: true });
|
|
39575
|
+
this.#sqlite = new DatabaseSync2(path2);
|
|
39576
|
+
chmodSync(path2, 384);
|
|
39577
|
+
try {
|
|
39578
|
+
for (const pragma of pragmas) {
|
|
39579
|
+
this.#sqlite.exec(pragma);
|
|
39580
|
+
}
|
|
39581
|
+
this.#migrate(label, migrations);
|
|
39582
|
+
this.orm = drizzle({ client: this.#sqlite });
|
|
39583
|
+
} catch (error62) {
|
|
39584
|
+
this.#sqlite.close();
|
|
39585
|
+
throw error62;
|
|
39586
|
+
}
|
|
39587
|
+
}
|
|
39588
|
+
#migrate = (label, migrations) => {
|
|
39589
|
+
const version2 = external_exports.object({ user_version: external_exports.number().int().nonnegative() }).parse(this.#sqlite.prepare("PRAGMA user_version").get()).user_version;
|
|
39590
|
+
if (version2 > migrations.length) {
|
|
39591
|
+
throw new Error(`The ${label} was created by a newer Mobius version`);
|
|
39592
|
+
}
|
|
39593
|
+
for (let index2 = version2; index2 < migrations.length; index2 += 1) {
|
|
39594
|
+
const migration = migrations[index2];
|
|
39595
|
+
if (migration === void 0) {
|
|
39596
|
+
throw new Error(`The ${label} migration is unavailable`);
|
|
39597
|
+
}
|
|
39598
|
+
this.transaction(() => {
|
|
39599
|
+
this.#sqlite.exec(migration.sql);
|
|
39600
|
+
this.#sqlite.exec(`PRAGMA user_version = ${index2 + 1}`);
|
|
39601
|
+
});
|
|
39602
|
+
}
|
|
39603
|
+
};
|
|
39604
|
+
transaction = (operation) => {
|
|
39605
|
+
this.#sqlite.exec("BEGIN IMMEDIATE");
|
|
39606
|
+
try {
|
|
39607
|
+
const result = operation();
|
|
39608
|
+
this.#sqlite.exec("COMMIT");
|
|
39609
|
+
return result;
|
|
39610
|
+
} catch (error62) {
|
|
39611
|
+
this.#sqlite.exec("ROLLBACK");
|
|
39612
|
+
throw error62;
|
|
39613
|
+
}
|
|
39614
|
+
};
|
|
39615
|
+
close = () => this.#sqlite.close();
|
|
39616
|
+
};
|
|
39617
|
+
|
|
39618
|
+
// src/local-databases.ts
|
|
39619
|
+
var openAcpSessionDatabase = (path2) => new LocalSqliteDatabase(path2, "ACP Session database", acpSessionStoreMigrations);
|
|
39620
|
+
var openSessionEventCacheV2Database = (path2) => new LocalSqliteDatabase(path2, "V2 Session event cache", sessionEventCacheMigrations, [
|
|
39621
|
+
"PRAGMA journal_mode = WAL",
|
|
39622
|
+
"PRAGMA synchronous = OFF"
|
|
39623
|
+
]);
|
|
39624
|
+
|
|
39541
39625
|
// src/native-sessions/codex-history.ts
|
|
39542
39626
|
import { spawn as spawn5 } from "node:child_process";
|
|
39543
39627
|
var responseSchema = external_exports.union([
|
|
@@ -40242,7 +40326,7 @@ var readCodexFullHistory = async (agent, cwd, nativeSessionId, signal, nativeTur
|
|
|
40242
40326
|
});
|
|
40243
40327
|
|
|
40244
40328
|
// src/native-sessions/service.ts
|
|
40245
|
-
import { randomUUID as
|
|
40329
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
40246
40330
|
var NativeSessionService = class {
|
|
40247
40331
|
#entries = /* @__PURE__ */ new Map();
|
|
40248
40332
|
#cursors = /* @__PURE__ */ new Map();
|
|
@@ -40301,7 +40385,7 @@ var NativeSessionService = class {
|
|
|
40301
40385
|
if (authorized === null) {
|
|
40302
40386
|
return null;
|
|
40303
40387
|
}
|
|
40304
|
-
const entryId = decodeIdentifier(
|
|
40388
|
+
const entryId = decodeIdentifier(randomUUID5());
|
|
40305
40389
|
if (this.#entries.size >= 5e3) {
|
|
40306
40390
|
this.#entries.clear();
|
|
40307
40391
|
}
|
|
@@ -40357,7 +40441,7 @@ var NativeSessionService = class {
|
|
|
40357
40441
|
"invalid_native_session_response"
|
|
40358
40442
|
);
|
|
40359
40443
|
}
|
|
40360
|
-
nextCursor = decodeIdentifier(
|
|
40444
|
+
nextCursor = decodeIdentifier(randomUUID5());
|
|
40361
40445
|
if (this.#cursors.size >= 500) {
|
|
40362
40446
|
this.#cursors.clear();
|
|
40363
40447
|
}
|
|
@@ -40535,7 +40619,7 @@ var NativeSessionService = class {
|
|
|
40535
40619
|
resolveTarget = async (command, options, selected) => {
|
|
40536
40620
|
let cursor = null;
|
|
40537
40621
|
const visited = /* @__PURE__ */ new Set();
|
|
40538
|
-
for (let
|
|
40622
|
+
for (let index2 = 0; index2 < 100; index2 += 1) {
|
|
40539
40623
|
const page = await this.#sessions.listNativeSessions(options, cursor);
|
|
40540
40624
|
const info = page.sessions.find((entry) => entry.sessionId === selected.nativeSessionId);
|
|
40541
40625
|
if (info !== void 0) {
|
|
@@ -40543,7 +40627,7 @@ var NativeSessionService = class {
|
|
|
40543
40627
|
if (target === null) {
|
|
40544
40628
|
throw new LocalAuthorizationError("The selected native session is not authorized");
|
|
40545
40629
|
}
|
|
40546
|
-
if (target.cwd !== selected.cwd || target.additionalDirectories.length !== selected.additionalDirectories.length || target.additionalDirectories.some((path2,
|
|
40630
|
+
if (target.cwd !== selected.cwd || target.additionalDirectories.length !== selected.additionalDirectories.length || target.additionalDirectories.some((path2, index3) => path2 !== selected.additionalDirectories[index3])) {
|
|
40547
40631
|
throw new AcpExecutionError(
|
|
40548
40632
|
"This session's directory changed. Refresh the list before continuing.",
|
|
40549
40633
|
{},
|
|
@@ -40582,7 +40666,7 @@ var NativeSessionService = class {
|
|
|
40582
40666
|
};
|
|
40583
40667
|
|
|
40584
40668
|
// src/relay-connection/daemon-operation-state.ts
|
|
40585
|
-
import { createHash as createHash5, randomUUID as
|
|
40669
|
+
import { createHash as createHash5, randomUUID as randomUUID6 } from "node:crypto";
|
|
40586
40670
|
var MAX_TERMINAL_RECEIPTS = 1024;
|
|
40587
40671
|
function isTerminal(state) {
|
|
40588
40672
|
return state === "succeeded" || state === "failed" || state === "cancelled";
|
|
@@ -40599,7 +40683,7 @@ var DaemonOperationState = class {
|
|
|
40599
40683
|
}
|
|
40600
40684
|
return { attemptId: existing.attemptId, commandId, kind: "duplicate", state: existing.state };
|
|
40601
40685
|
}
|
|
40602
|
-
const attemptId =
|
|
40686
|
+
const attemptId = randomUUID6();
|
|
40603
40687
|
this.#executions.set(commandId, { attemptId, commandHash, sessionId, state: "dispatching" });
|
|
40604
40688
|
return { attemptId, commandId, kind: "accepted", state: "dispatching" };
|
|
40605
40689
|
};
|
|
@@ -41563,7 +41647,7 @@ async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, dir
|
|
|
41563
41647
|
const replay = await sessions.loadSessionEventsV2(loadOptions, command.eventLimit, command.cursor);
|
|
41564
41648
|
signal.throwIfAborted();
|
|
41565
41649
|
const events = replay.events.map(
|
|
41566
|
-
(event,
|
|
41650
|
+
(event, index2) => eventLogV2.event(command.sessionId, replay.startPosition + index2, event, "1970-01-01T00:00:00.000Z")
|
|
41567
41651
|
);
|
|
41568
41652
|
const tailCursor = events.at(-1)?.eventId ?? "";
|
|
41569
41653
|
audit.record({
|
|
@@ -41614,7 +41698,7 @@ async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, dir
|
|
|
41614
41698
|
}
|
|
41615
41699
|
|
|
41616
41700
|
// src/acp/session-config/apply-session-configuration.ts
|
|
41617
|
-
import { randomUUID as
|
|
41701
|
+
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
41618
41702
|
function invalidSessionConfiguration(message) {
|
|
41619
41703
|
return new AcpExecutionError(message, {}, "invalid_session_configuration");
|
|
41620
41704
|
}
|
|
@@ -41755,7 +41839,7 @@ async function applySessionConfigurationSelection(sessions, audit, options, sele
|
|
|
41755
41839
|
booleanValue: selection.booleanValue,
|
|
41756
41840
|
configId: selection.configId,
|
|
41757
41841
|
cwd,
|
|
41758
|
-
requestId: `cfg_${
|
|
41842
|
+
requestId: `cfg_${randomUUID7()}`,
|
|
41759
41843
|
sessionId,
|
|
41760
41844
|
signal,
|
|
41761
41845
|
value: selection.value,
|
|
@@ -41797,112 +41881,6 @@ function warnIgnoredSetting(audit, event, commandId, sessionId, agentId, selecti
|
|
|
41797
41881
|
`);
|
|
41798
41882
|
}
|
|
41799
41883
|
|
|
41800
|
-
// src/relay-connection/coalescing-agent-event-publisher.ts
|
|
41801
|
-
var AGENT_EVENT_COALESCING_MILLISECONDS = 100;
|
|
41802
|
-
var AGENT_EVENT_TEXT_MAXIMUM_LENGTH = 1e5;
|
|
41803
|
-
var CoalescingAgentEventPublisher = class {
|
|
41804
|
-
#entries = [];
|
|
41805
|
-
#publish;
|
|
41806
|
-
#publishedActivityIds = /* @__PURE__ */ new Set();
|
|
41807
|
-
#scheduled = null;
|
|
41808
|
-
#timer;
|
|
41809
|
-
constructor(timer, publish) {
|
|
41810
|
-
this.#publish = publish;
|
|
41811
|
-
this.#timer = timer;
|
|
41812
|
-
}
|
|
41813
|
-
flush = () => {
|
|
41814
|
-
this.#scheduled?.cancel();
|
|
41815
|
-
this.#scheduled = null;
|
|
41816
|
-
const entries = this.#entries;
|
|
41817
|
-
this.#entries = [];
|
|
41818
|
-
for (const entry of entries) {
|
|
41819
|
-
this.#publish(entry);
|
|
41820
|
-
}
|
|
41821
|
-
};
|
|
41822
|
-
recordActivity = (activity2) => {
|
|
41823
|
-
const latest = this.#entries.at(-1);
|
|
41824
|
-
this.#entries = latest?.kind === "activity" && latest.activity.activityId === activity2.activityId ? [...this.#entries.slice(0, -1), { activity: activity2, kind: "activity" }] : [...this.#entries, { activity: activity2, kind: "activity" }];
|
|
41825
|
-
const first = !this.#publishedActivityIds.has(activity2.activityId);
|
|
41826
|
-
this.#publishedActivityIds.add(activity2.activityId);
|
|
41827
|
-
if (first || activity2.status !== "pending" && activity2.status !== "running") {
|
|
41828
|
-
this.flush();
|
|
41829
|
-
} else {
|
|
41830
|
-
this.schedule();
|
|
41831
|
-
}
|
|
41832
|
-
return Promise.resolve();
|
|
41833
|
-
};
|
|
41834
|
-
recordNarration = (increment) => {
|
|
41835
|
-
if (increment.text.length === 0) {
|
|
41836
|
-
return Promise.resolve();
|
|
41837
|
-
}
|
|
41838
|
-
let remaining = increment.text;
|
|
41839
|
-
while (remaining.length > 0) {
|
|
41840
|
-
const latest = this.#entries.at(-1);
|
|
41841
|
-
if (latest?.kind === "narration" && latest.increment.activityId === increment.activityId) {
|
|
41842
|
-
const available = AGENT_EVENT_TEXT_MAXIMUM_LENGTH - latest.increment.text.length;
|
|
41843
|
-
if (available > 0) {
|
|
41844
|
-
this.#entries = [
|
|
41845
|
-
...this.#entries.slice(0, -1),
|
|
41846
|
-
{
|
|
41847
|
-
increment: {
|
|
41848
|
-
...increment,
|
|
41849
|
-
text: `${latest.increment.text}${remaining.slice(0, available)}`
|
|
41850
|
-
},
|
|
41851
|
-
kind: "narration"
|
|
41852
|
-
}
|
|
41853
|
-
];
|
|
41854
|
-
remaining = remaining.slice(available);
|
|
41855
|
-
continue;
|
|
41856
|
-
}
|
|
41857
|
-
}
|
|
41858
|
-
this.#entries = [
|
|
41859
|
-
...this.#entries,
|
|
41860
|
-
{
|
|
41861
|
-
increment: { ...increment, text: remaining.slice(0, AGENT_EVENT_TEXT_MAXIMUM_LENGTH) },
|
|
41862
|
-
kind: "narration"
|
|
41863
|
-
}
|
|
41864
|
-
];
|
|
41865
|
-
remaining = remaining.slice(AGENT_EVENT_TEXT_MAXIMUM_LENGTH);
|
|
41866
|
-
}
|
|
41867
|
-
this.schedule();
|
|
41868
|
-
return Promise.resolve();
|
|
41869
|
-
};
|
|
41870
|
-
recordText = (text2, messageId) => {
|
|
41871
|
-
if (text2.length === 0) {
|
|
41872
|
-
return Promise.resolve();
|
|
41873
|
-
}
|
|
41874
|
-
let remaining = text2;
|
|
41875
|
-
while (remaining.length > 0) {
|
|
41876
|
-
const latest = this.#entries.at(-1);
|
|
41877
|
-
if (latest?.kind === "text" && latest.messageId === messageId) {
|
|
41878
|
-
const available = AGENT_EVENT_TEXT_MAXIMUM_LENGTH - latest.text.length;
|
|
41879
|
-
if (available > 0) {
|
|
41880
|
-
this.#entries = [
|
|
41881
|
-
...this.#entries.slice(0, -1),
|
|
41882
|
-
{ ...latest, text: `${latest.text}${remaining.slice(0, available)}` }
|
|
41883
|
-
];
|
|
41884
|
-
remaining = remaining.slice(available);
|
|
41885
|
-
continue;
|
|
41886
|
-
}
|
|
41887
|
-
}
|
|
41888
|
-
this.#entries = [
|
|
41889
|
-
...this.#entries,
|
|
41890
|
-
{
|
|
41891
|
-
kind: "text",
|
|
41892
|
-
messageId,
|
|
41893
|
-
text: remaining.slice(0, AGENT_EVENT_TEXT_MAXIMUM_LENGTH)
|
|
41894
|
-
}
|
|
41895
|
-
];
|
|
41896
|
-
remaining = remaining.slice(AGENT_EVENT_TEXT_MAXIMUM_LENGTH);
|
|
41897
|
-
}
|
|
41898
|
-
this.schedule();
|
|
41899
|
-
return Promise.resolve();
|
|
41900
|
-
};
|
|
41901
|
-
schedule() {
|
|
41902
|
-
this.#scheduled ??= this.#timer.schedule(this.flush, AGENT_EVENT_COALESCING_MILLISECONDS);
|
|
41903
|
-
}
|
|
41904
|
-
};
|
|
41905
|
-
|
|
41906
41884
|
// src/daemon-prompt-executor.ts
|
|
41907
41885
|
function daemonActivity(command, activity2) {
|
|
41908
41886
|
return {
|
|
@@ -41925,7 +41903,6 @@ function daemonActivity(command, activity2) {
|
|
|
41925
41903
|
}
|
|
41926
41904
|
async function executePrompt({
|
|
41927
41905
|
operations,
|
|
41928
|
-
publisher,
|
|
41929
41906
|
eventLogV2,
|
|
41930
41907
|
command,
|
|
41931
41908
|
config: config2,
|
|
@@ -41935,36 +41912,11 @@ async function executePrompt({
|
|
|
41935
41912
|
attemptId,
|
|
41936
41913
|
activateAttempt,
|
|
41937
41914
|
waitForSessionAvailability,
|
|
41938
|
-
timer,
|
|
41939
41915
|
signal,
|
|
41940
|
-
|
|
41916
|
+
recordTurnEvent,
|
|
41941
41917
|
recordSteeringPrompt,
|
|
41942
41918
|
cancellationRequested
|
|
41943
41919
|
}) {
|
|
41944
|
-
const events = new CoalescingAgentEventPublisher(timer, (event) => {
|
|
41945
|
-
if (event.kind === "text") {
|
|
41946
|
-
publisher.publish(
|
|
41947
|
-
command.sessionId,
|
|
41948
|
-
recordLiveEvent({ kind: AGENT_MESSAGE_DELTA_KIND, messageId: event.messageId, text: event.text })
|
|
41949
|
-
);
|
|
41950
|
-
return;
|
|
41951
|
-
}
|
|
41952
|
-
if (event.kind === "narration") {
|
|
41953
|
-
const recorded = {
|
|
41954
|
-
activityId: event.increment.activityId,
|
|
41955
|
-
activityType: event.increment.activityType,
|
|
41956
|
-
commandId: command.commandId,
|
|
41957
|
-
kind: AGENT_ACTIVITY_NARRATION_KIND,
|
|
41958
|
-
sequence: event.increment.sequence,
|
|
41959
|
-
sessionId: command.sessionId,
|
|
41960
|
-
text: event.increment.text
|
|
41961
|
-
};
|
|
41962
|
-
publisher.publish(command.sessionId, recordLiveEvent(recorded));
|
|
41963
|
-
return;
|
|
41964
|
-
}
|
|
41965
|
-
const activity2 = daemonActivity(command, event.activity);
|
|
41966
|
-
publisher.publish(command.sessionId, recordLiveEvent(activity2));
|
|
41967
|
-
});
|
|
41968
41920
|
try {
|
|
41969
41921
|
const resolved = await resolveSessionDirectories(
|
|
41970
41922
|
directories,
|
|
@@ -42032,33 +41984,6 @@ async function executePrompt({
|
|
|
42032
41984
|
}
|
|
42033
41985
|
const stream = activateAttempt();
|
|
42034
41986
|
const lifecycleV2 = eventLogV2.started(command.sessionId, command.commandId, attemptId, stream.epoch);
|
|
42035
|
-
if (!prepared.prompted) {
|
|
42036
|
-
const listing = await directories.list(config2.bindingId, command.directoryId, signal);
|
|
42037
|
-
publisher.publish(command.sessionId, {
|
|
42038
|
-
additionalDirectories: resolved.additionalDirectoryEntries,
|
|
42039
|
-
agentId: command.agentId,
|
|
42040
|
-
agentName: prepared.agentName,
|
|
42041
|
-
agentVersion: prepared.agentVersion,
|
|
42042
|
-
capabilities: prepared.capabilities,
|
|
42043
|
-
commands: prepared.commands,
|
|
42044
|
-
configOptions: prepared.configOptions,
|
|
42045
|
-
directoryId: command.directoryId,
|
|
42046
|
-
directoryLabel: listing.directoryLabel,
|
|
42047
|
-
kind: SESSION_READY_KIND,
|
|
42048
|
-
requestId: command.commandId,
|
|
42049
|
-
restored: prepared.restored,
|
|
42050
|
-
sessionId: command.sessionId
|
|
42051
|
-
});
|
|
42052
|
-
}
|
|
42053
|
-
publisher.publish(command.sessionId, {
|
|
42054
|
-
commandId: command.commandId,
|
|
42055
|
-
epoch: stream.epoch,
|
|
42056
|
-
kind: SESSION_STARTED_KIND,
|
|
42057
|
-
attemptId,
|
|
42058
|
-
prompt: command.prompt,
|
|
42059
|
-
sequence: stream.sequence,
|
|
42060
|
-
sessionId: command.sessionId
|
|
42061
|
-
});
|
|
42062
41987
|
const attachments = await resolvePromptArtifacts(config2, command, signal);
|
|
42063
41988
|
let stopReason;
|
|
42064
41989
|
if (availability.disposition === SessionPromptDisposition.Steer) {
|
|
@@ -42085,9 +42010,20 @@ async function executePrompt({
|
|
|
42085
42010
|
disposition: availability.disposition,
|
|
42086
42011
|
images: attachments.images,
|
|
42087
42012
|
lifecycleV2,
|
|
42088
|
-
onActivity:
|
|
42089
|
-
|
|
42090
|
-
|
|
42013
|
+
onActivity: async (activity2) => {
|
|
42014
|
+
recordTurnEvent(daemonActivity(command, activity2));
|
|
42015
|
+
},
|
|
42016
|
+
onNarration: async (increment) => {
|
|
42017
|
+
recordTurnEvent({
|
|
42018
|
+
...increment,
|
|
42019
|
+
commandId: command.commandId,
|
|
42020
|
+
sessionId: command.sessionId,
|
|
42021
|
+
kind: AGENT_ACTIVITY_NARRATION_KIND
|
|
42022
|
+
});
|
|
42023
|
+
},
|
|
42024
|
+
onText: async (text2, messageId) => {
|
|
42025
|
+
recordTurnEvent({ kind: AGENT_MESSAGE_DELTA_KIND, text: text2, messageId });
|
|
42026
|
+
},
|
|
42091
42027
|
prompt: command.prompt,
|
|
42092
42028
|
resources: attachments.resources,
|
|
42093
42029
|
sessionId: command.sessionId,
|
|
@@ -42096,14 +42032,7 @@ async function executePrompt({
|
|
|
42096
42032
|
});
|
|
42097
42033
|
stopReason = result.stopReason;
|
|
42098
42034
|
}
|
|
42099
|
-
|
|
42100
|
-
publisher.publish(command.sessionId, {
|
|
42101
|
-
commandId: command.commandId,
|
|
42102
|
-
kind: SESSION_COMPLETED_KIND,
|
|
42103
|
-
sessionId: command.sessionId,
|
|
42104
|
-
stopReason
|
|
42105
|
-
});
|
|
42106
|
-
eventLogV2.completed(command.sessionId, command.commandId, stopReason);
|
|
42035
|
+
await eventLogV2.completed(command.sessionId, command.commandId, stopReason);
|
|
42107
42036
|
operations.transitionExecution(command.commandId, stopReason === "cancelled" ? "cancelled" : "succeeded");
|
|
42108
42037
|
audit.record({
|
|
42109
42038
|
commandId: command.commandId,
|
|
@@ -42111,15 +42040,8 @@ async function executePrompt({
|
|
|
42111
42040
|
sessionId: command.sessionId
|
|
42112
42041
|
});
|
|
42113
42042
|
} catch (error62) {
|
|
42114
|
-
events.flush();
|
|
42115
42043
|
if (signal.aborted && cancellationRequested()) {
|
|
42116
|
-
|
|
42117
|
-
commandId: command.commandId,
|
|
42118
|
-
kind: SESSION_COMPLETED_KIND,
|
|
42119
|
-
sessionId: command.sessionId,
|
|
42120
|
-
stopReason: "cancelled"
|
|
42121
|
-
});
|
|
42122
|
-
eventLogV2.completed(command.sessionId, command.commandId, "cancelled");
|
|
42044
|
+
await eventLogV2.completed(command.sessionId, command.commandId, "cancelled");
|
|
42123
42045
|
operations.transitionExecution(command.commandId, "cancelled");
|
|
42124
42046
|
audit.record({
|
|
42125
42047
|
commandId: command.commandId,
|
|
@@ -42136,8 +42058,7 @@ async function executePrompt({
|
|
|
42136
42058
|
const code = operationErrorCode(error62);
|
|
42137
42059
|
const failureCode = code === "session_operation_failed" ? "agent_execution_failed" : code;
|
|
42138
42060
|
const failureMessage = code === "session_operation_failed" ? "The local agent could not complete the request" : operationErrorMessage(error62);
|
|
42139
|
-
eventLogV2.failed(command.sessionId, command.commandId, failureCode, failureMessage);
|
|
42140
|
-
reportFailure(publisher, command, failureCode, failureMessage);
|
|
42061
|
+
await eventLogV2.failed(command.sessionId, command.commandId, failureCode, failureMessage);
|
|
42141
42062
|
operations.transitionExecution(command.commandId, "failed");
|
|
42142
42063
|
console.error("Mobius daemon command failed", error62);
|
|
42143
42064
|
}
|
|
@@ -42165,7 +42086,7 @@ async function executeWorkspaceList(socket, command, directories, audit, signal)
|
|
|
42165
42086
|
reportOperationFailure(socket, command.requestId, "", error62);
|
|
42166
42087
|
}
|
|
42167
42088
|
}
|
|
42168
|
-
async function executeSessionPrepare(
|
|
42089
|
+
async function executeSessionPrepare(socket, command, config2, directories, audit, sessions, diagnostics, signal) {
|
|
42169
42090
|
const metrics = new AccumulatingOperationMetrics();
|
|
42170
42091
|
try {
|
|
42171
42092
|
const readyEvent = await metrics.measure("prepare-total", async () => {
|
|
@@ -42215,12 +42136,6 @@ async function executeSessionPrepare(publisher, socket, command, config2, direct
|
|
|
42215
42136
|
event: "session_configured",
|
|
42216
42137
|
sessionId: command.sessionId
|
|
42217
42138
|
});
|
|
42218
|
-
publisher.publish(command.sessionId, {
|
|
42219
|
-
configOptions,
|
|
42220
|
-
kind: "session.config.updated",
|
|
42221
|
-
requestId: command.requestId,
|
|
42222
|
-
sessionId: command.sessionId
|
|
42223
|
-
});
|
|
42224
42139
|
}
|
|
42225
42140
|
const event = {
|
|
42226
42141
|
additionalDirectories: resolved.additionalDirectoryEntries,
|
|
@@ -42238,11 +42153,6 @@ async function executeSessionPrepare(publisher, socket, command, config2, direct
|
|
|
42238
42153
|
sessionId: command.sessionId,
|
|
42239
42154
|
runtimeTimings: metrics.snapshot()
|
|
42240
42155
|
};
|
|
42241
|
-
if (command.transient !== true) {
|
|
42242
|
-
metrics.measureSync("readiness-commit", () => {
|
|
42243
|
-
publisher.publish(command.sessionId, event);
|
|
42244
|
-
});
|
|
42245
|
-
}
|
|
42246
42156
|
return event;
|
|
42247
42157
|
});
|
|
42248
42158
|
send(socket, {
|
|
@@ -42272,7 +42182,7 @@ async function executeSessionPrepare(publisher, socket, command, config2, direct
|
|
|
42272
42182
|
reportOperationFailure(socket, command.requestId, command.sessionId, error62, metrics.snapshot());
|
|
42273
42183
|
}
|
|
42274
42184
|
}
|
|
42275
|
-
async function executeSessionConfigure(
|
|
42185
|
+
async function executeSessionConfigure(socket, command, config2, directories, audit, sessions, signal) {
|
|
42276
42186
|
try {
|
|
42277
42187
|
const resolved = await resolveSessionDirectories(
|
|
42278
42188
|
directories,
|
|
@@ -42298,7 +42208,7 @@ async function executeSessionConfigure(publisher, socket, command, config2, dire
|
|
|
42298
42208
|
event: "session_configured",
|
|
42299
42209
|
sessionId: command.sessionId
|
|
42300
42210
|
});
|
|
42301
|
-
|
|
42211
|
+
send(socket, {
|
|
42302
42212
|
configOptions,
|
|
42303
42213
|
kind: "session.config.updated",
|
|
42304
42214
|
requestId: command.requestId,
|
|
@@ -42418,7 +42328,6 @@ function createDaemonCommandHandler({
|
|
|
42418
42328
|
installations,
|
|
42419
42329
|
nativeSessions,
|
|
42420
42330
|
operations,
|
|
42421
|
-
publisher,
|
|
42422
42331
|
eventLogV2,
|
|
42423
42332
|
externalContent,
|
|
42424
42333
|
activeTurns,
|
|
@@ -42439,8 +42348,9 @@ function createDaemonCommandHandler({
|
|
|
42439
42348
|
timer
|
|
42440
42349
|
});
|
|
42441
42350
|
const queueChanged = (sessionId) => {
|
|
42442
|
-
|
|
42443
|
-
|
|
42351
|
+
void eventLogV2.queueChanged(sessionId).catch((error62) => {
|
|
42352
|
+
console.error("Could not record queue change", error62);
|
|
42353
|
+
});
|
|
42444
42354
|
};
|
|
42445
42355
|
const nativeRequestHandler = createNativeSessionRequestHandler({
|
|
42446
42356
|
audit,
|
|
@@ -42509,7 +42419,9 @@ function createDaemonCommandHandler({
|
|
|
42509
42419
|
const cancellation = message;
|
|
42510
42420
|
const turn2 = activeTurns.get(cancellation.commandId);
|
|
42511
42421
|
if (turn2 === void 0 || !turn2.matches(cancellation)) {
|
|
42512
|
-
settleAbandonedTurn(
|
|
42422
|
+
void settleAbandonedTurn(eventLogV2, operations, audit, cancellation).catch((error62) => {
|
|
42423
|
+
console.error("Could not settle abandoned turn", error62);
|
|
42424
|
+
});
|
|
42513
42425
|
return;
|
|
42514
42426
|
}
|
|
42515
42427
|
const cancellationState = turn2.requestCancellation();
|
|
@@ -42549,22 +42461,12 @@ function createDaemonCommandHandler({
|
|
|
42549
42461
|
}
|
|
42550
42462
|
if (kind === SESSION_PREPARE_KIND) {
|
|
42551
42463
|
const command2 = message;
|
|
42552
|
-
void executeSessionPrepare(
|
|
42553
|
-
publisher,
|
|
42554
|
-
socket,
|
|
42555
|
-
command2,
|
|
42556
|
-
config2,
|
|
42557
|
-
directories,
|
|
42558
|
-
audit,
|
|
42559
|
-
sessions,
|
|
42560
|
-
diagnostics,
|
|
42561
|
-
signal
|
|
42562
|
-
);
|
|
42464
|
+
void executeSessionPrepare(socket, command2, config2, directories, audit, sessions, diagnostics, signal);
|
|
42563
42465
|
return;
|
|
42564
42466
|
}
|
|
42565
42467
|
if (kind === SESSION_CONFIGURE_KIND) {
|
|
42566
42468
|
const command2 = message;
|
|
42567
|
-
void executeSessionConfigure(
|
|
42469
|
+
void executeSessionConfigure(socket, command2, config2, directories, audit, sessions, signal);
|
|
42568
42470
|
return;
|
|
42569
42471
|
}
|
|
42570
42472
|
if (kind === SESSION_LIST_KIND) {
|
|
@@ -42666,7 +42568,6 @@ function createDaemonCommandHandler({
|
|
|
42666
42568
|
eventLogV2.requested(command);
|
|
42667
42569
|
void executePrompt({
|
|
42668
42570
|
operations,
|
|
42669
|
-
publisher,
|
|
42670
42571
|
eventLogV2,
|
|
42671
42572
|
command,
|
|
42672
42573
|
config: config2,
|
|
@@ -42683,15 +42584,15 @@ function createDaemonCommandHandler({
|
|
|
42683
42584
|
sessionId: command.sessionId
|
|
42684
42585
|
});
|
|
42685
42586
|
}),
|
|
42686
|
-
timer,
|
|
42687
42587
|
signal: turn.signal,
|
|
42688
|
-
|
|
42588
|
+
recordTurnEvent: turn.recordEvent,
|
|
42689
42589
|
recordSteeringPrompt: () => activeTurns.recordSteeringPrompt(command),
|
|
42690
42590
|
cancellationRequested: turn.cancellationRequested
|
|
42691
42591
|
}).catch((error62) => {
|
|
42692
42592
|
console.error("Mobius daemon turn failed", error62);
|
|
42693
42593
|
}).finally(() => {
|
|
42694
42594
|
activeTurns.finish(turn);
|
|
42595
|
+
eventLogV2.publishTerminal(command.sessionId, command.commandId);
|
|
42695
42596
|
if (command.disposition === SessionPromptDisposition.Queue) {
|
|
42696
42597
|
queueChanged(command.sessionId);
|
|
42697
42598
|
}
|
|
@@ -42805,7 +42706,7 @@ function connectRelay(url2, signal) {
|
|
|
42805
42706
|
}
|
|
42806
42707
|
|
|
42807
42708
|
// src/relay-connection/liveness.ts
|
|
42808
|
-
import { randomUUID as
|
|
42709
|
+
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
42809
42710
|
var HEARTBEAT_ACK_TIMEOUT_MILLISECONDS = 1e4;
|
|
42810
42711
|
var HEARTBEAT_INTERVAL_MILLISECONDS = 2e4;
|
|
42811
42712
|
var RelayLivenessState = class {
|
|
@@ -42894,7 +42795,7 @@ var RelayConnectionLiveness = class {
|
|
|
42894
42795
|
}
|
|
42895
42796
|
throw new Error("Heartbeat was scheduled in an invalid state");
|
|
42896
42797
|
}
|
|
42897
|
-
const heartbeatId =
|
|
42798
|
+
const heartbeatId = randomUUID8();
|
|
42898
42799
|
this.#state = new AwaitingHeartbeatAckState(
|
|
42899
42800
|
heartbeatId,
|
|
42900
42801
|
this.#timer.schedule(this.#handleTimeout, HEARTBEAT_ACK_TIMEOUT_MILLISECONDS)
|
|
@@ -42955,7 +42856,6 @@ async function runRelayConnection({
|
|
|
42955
42856
|
installations,
|
|
42956
42857
|
nativeSessions,
|
|
42957
42858
|
operations,
|
|
42958
|
-
publisher,
|
|
42959
42859
|
eventLogV2,
|
|
42960
42860
|
externalContent,
|
|
42961
42861
|
activeTurns,
|
|
@@ -43120,51 +43020,17 @@ var DaemonSessionEventPublisher = class {
|
|
|
43120
43020
|
close = () => {
|
|
43121
43021
|
this.#socket = null;
|
|
43122
43022
|
};
|
|
43123
|
-
|
|
43124
|
-
|
|
43125
|
-
if (socket === null || socket.readyState !== WebSocket8.OPEN) {
|
|
43126
|
-
return;
|
|
43127
|
-
}
|
|
43128
|
-
const encoded = encodeDaemonToServiceMessage({
|
|
43129
|
-
kind: SESSION_EVENT_KIND,
|
|
43130
|
-
payload: encodeRecordedSessionEvent(event),
|
|
43131
|
-
sessionId
|
|
43132
|
-
});
|
|
43133
|
-
if (socket.bufferedAmount + Buffer.byteLength(encoded, "utf8") > MAX_BUFFERED_BYTES) {
|
|
43134
|
-
socket.close(1013, "Live event transport overloaded");
|
|
43135
|
-
return;
|
|
43136
|
-
}
|
|
43137
|
-
try {
|
|
43138
|
-
socket.send(encoded);
|
|
43139
|
-
} catch {
|
|
43140
|
-
}
|
|
43141
|
-
};
|
|
43142
|
-
publishBatch = (sessionId, events) => {
|
|
43143
|
-
for (const event of events) {
|
|
43144
|
-
this.publish(sessionId, event);
|
|
43145
|
-
}
|
|
43146
|
-
};
|
|
43147
|
-
publishStatus = (event) => {
|
|
43148
|
-
const socket = this.#socket;
|
|
43149
|
-
if (socket === null || socket.readyState !== WebSocket8.OPEN) {
|
|
43150
|
-
return;
|
|
43151
|
-
}
|
|
43152
|
-
const encoded = encodeDaemonToServiceMessage(event);
|
|
43153
|
-
if (socket.bufferedAmount + Buffer.byteLength(encoded, "utf8") > MAX_BUFFERED_BYTES) {
|
|
43154
|
-
socket.close(1013, "Live event transport overloaded");
|
|
43155
|
-
return;
|
|
43156
|
-
}
|
|
43157
|
-
try {
|
|
43158
|
-
socket.send(encoded);
|
|
43159
|
-
} catch {
|
|
43160
|
-
}
|
|
43023
|
+
publishOperationFailure = (sessionId, requestId, code, message) => {
|
|
43024
|
+
this.#send({ kind: "session.operation.failed", sessionId, requestId, code, message });
|
|
43161
43025
|
};
|
|
43162
|
-
|
|
43026
|
+
publishStatus = (event) => this.#send(event);
|
|
43027
|
+
publishV2 = (event) => this.#send({ event, kind: SESSION_EVENT_V2_KIND });
|
|
43028
|
+
#send = (message) => {
|
|
43163
43029
|
const socket = this.#socket;
|
|
43164
43030
|
if (socket === null || socket.readyState !== WebSocket8.OPEN) {
|
|
43165
43031
|
return;
|
|
43166
43032
|
}
|
|
43167
|
-
const encoded = encodeDaemonToServiceMessage(
|
|
43033
|
+
const encoded = encodeDaemonToServiceMessage(message);
|
|
43168
43034
|
if (socket.bufferedAmount + Buffer.byteLength(encoded, "utf8") > MAX_BUFFERED_BYTES) {
|
|
43169
43035
|
socket.close(1013, "Live event transport overloaded");
|
|
43170
43036
|
return;
|
|
@@ -43186,7 +43052,7 @@ var SystemDaemonTimer = class {
|
|
|
43186
43052
|
var systemDaemonTimer = new SystemDaemonTimer();
|
|
43187
43053
|
|
|
43188
43054
|
// src/session-event-log-v2.ts
|
|
43189
|
-
import { createHash as createHash7, randomUUID as
|
|
43055
|
+
import { createHash as createHash7, randomUUID as randomUUID9 } from "node:crypto";
|
|
43190
43056
|
function promptContent(command) {
|
|
43191
43057
|
const content = [];
|
|
43192
43058
|
if (command.prompt.length > 0) {
|
|
@@ -43210,7 +43076,7 @@ function promptContent(command) {
|
|
|
43210
43076
|
}
|
|
43211
43077
|
return content;
|
|
43212
43078
|
}
|
|
43213
|
-
function
|
|
43079
|
+
function sessionEventV22(daemonGenerationId, sessionId, position, event, recordedAt) {
|
|
43214
43080
|
const sessionPrefix = createHash7("sha256").update(sessionId).digest("hex").slice(0, 16);
|
|
43215
43081
|
return {
|
|
43216
43082
|
eventId: `event-${daemonGenerationId}-${sessionPrefix}-${position.toString().padStart(16, "0")}`,
|
|
@@ -43222,46 +43088,116 @@ function sessionEventV2(daemonGenerationId, sessionId, position, event, recorded
|
|
|
43222
43088
|
};
|
|
43223
43089
|
}
|
|
43224
43090
|
var DaemonSessionEventLogV2 = class {
|
|
43225
|
-
daemonGenerationId
|
|
43091
|
+
daemonGenerationId;
|
|
43226
43092
|
#publisher;
|
|
43093
|
+
#terminal = /* @__PURE__ */ new Map();
|
|
43094
|
+
#publications = /* @__PURE__ */ new Map();
|
|
43227
43095
|
#queued = /* @__PURE__ */ new Map();
|
|
43228
|
-
|
|
43096
|
+
#recordLifecycle;
|
|
43097
|
+
constructor(publisher, recordLifecycle, daemonGenerationId = randomUUID9()) {
|
|
43098
|
+
this.#recordLifecycle = recordLifecycle;
|
|
43229
43099
|
this.#publisher = publisher;
|
|
43100
|
+
this.daemonGenerationId = daemonGenerationId;
|
|
43230
43101
|
}
|
|
43231
43102
|
requested = (command) => {
|
|
43232
43103
|
this.#queued.set(command.commandId, {
|
|
43233
43104
|
commandId: command.commandId,
|
|
43234
43105
|
content: promptContent(command),
|
|
43106
|
+
context: {
|
|
43107
|
+
agentId: command.agentId,
|
|
43108
|
+
directoryId: command.directoryId,
|
|
43109
|
+
additionalDirectoryIds: command.additionalDirectoryIds
|
|
43110
|
+
},
|
|
43111
|
+
phase: "queued",
|
|
43235
43112
|
sessionId: command.sessionId
|
|
43236
43113
|
});
|
|
43237
43114
|
};
|
|
43238
43115
|
started = (sessionId, commandId, attemptId, epoch) => {
|
|
43239
43116
|
const request = this.#queued.get(commandId);
|
|
43240
43117
|
if (request?.sessionId === sessionId) {
|
|
43241
|
-
this.#queued.
|
|
43242
|
-
return { attemptId, content: request.content, epoch };
|
|
43118
|
+
this.#queued.set(commandId, { ...request, phase: "running" });
|
|
43119
|
+
return { attemptId, content: request.content, epoch, context: request.context };
|
|
43243
43120
|
}
|
|
43244
43121
|
throw new Error("The executing prompt was not registered in the V2 queue");
|
|
43245
43122
|
};
|
|
43246
43123
|
record = (sessionId, event, position) => {
|
|
43247
|
-
this
|
|
43124
|
+
const recorded = this.event(sessionId, position, event, (/* @__PURE__ */ new Date()).toISOString());
|
|
43125
|
+
if (event.type === "lifecycle-metadata" && (event.payload.kind === "prompt.completed" || event.payload.kind === "prompt.failed" || event.payload.kind === "prompt.failed-before-start")) {
|
|
43126
|
+
this.#terminal.set(event.payload.commandId, recorded);
|
|
43127
|
+
const pending2 = this.#publications.get(sessionId) ?? [];
|
|
43128
|
+
pending2.push(recorded);
|
|
43129
|
+
this.#publications.set(sessionId, pending2);
|
|
43130
|
+
return;
|
|
43131
|
+
}
|
|
43132
|
+
const pending = this.#publications.get(sessionId);
|
|
43133
|
+
if (pending !== void 0) {
|
|
43134
|
+
pending.push(recorded);
|
|
43135
|
+
} else {
|
|
43136
|
+
this.#publisher.publishV2(recorded);
|
|
43137
|
+
}
|
|
43138
|
+
};
|
|
43139
|
+
publishTerminal = (sessionId, commandId) => {
|
|
43140
|
+
const event = this.#terminal.get(commandId);
|
|
43141
|
+
if (event?.sessionId === sessionId) {
|
|
43142
|
+
this.#terminal.delete(commandId);
|
|
43143
|
+
const pending = this.#publications.get(sessionId) ?? [];
|
|
43144
|
+
while (pending.length > 0) {
|
|
43145
|
+
const next = pending[0];
|
|
43146
|
+
if (next === void 0) {
|
|
43147
|
+
break;
|
|
43148
|
+
}
|
|
43149
|
+
if (next.type === "lifecycle-metadata" && "commandId" in next.payload && this.#terminal.has(next.payload.commandId)) {
|
|
43150
|
+
break;
|
|
43151
|
+
}
|
|
43152
|
+
pending.shift();
|
|
43153
|
+
this.#publisher.publishV2(next);
|
|
43154
|
+
}
|
|
43155
|
+
if (pending.length === 0) {
|
|
43156
|
+
this.#publications.delete(sessionId);
|
|
43157
|
+
}
|
|
43158
|
+
}
|
|
43159
|
+
this.#queued.delete(commandId);
|
|
43248
43160
|
};
|
|
43249
|
-
event = (sessionId, position, event, recordedAt) =>
|
|
43250
|
-
queueChanged = (
|
|
43251
|
-
|
|
43161
|
+
event = (sessionId, position, event, recordedAt) => sessionEventV22(this.daemonGenerationId, sessionId, position, event, recordedAt);
|
|
43162
|
+
queueChanged = async (sessionId) => {
|
|
43163
|
+
await this.#recordLifecycle(sessionId, {
|
|
43164
|
+
type: "lifecycle-metadata",
|
|
43165
|
+
payload: { kind: "session.queue.changed" }
|
|
43166
|
+
});
|
|
43167
|
+
};
|
|
43168
|
+
completed = async (sessionId, commandId, stopReason) => {
|
|
43252
43169
|
const request = this.#queued.get(commandId);
|
|
43253
|
-
if (request?.sessionId
|
|
43254
|
-
|
|
43170
|
+
if (request?.sessionId !== sessionId || this.#terminal.has(commandId)) {
|
|
43171
|
+
return;
|
|
43172
|
+
}
|
|
43173
|
+
const recorded = await this.#recordLifecycle(sessionId, {
|
|
43174
|
+
type: "lifecycle-metadata",
|
|
43175
|
+
payload: { kind: "prompt.completed", commandId, stopReason }
|
|
43176
|
+
});
|
|
43177
|
+
if (!recorded) {
|
|
43178
|
+
this.#publisher.publishOperationFailure(
|
|
43179
|
+
sessionId,
|
|
43180
|
+
commandId,
|
|
43181
|
+
"cancelled",
|
|
43182
|
+
"The prompt was cancelled before execution"
|
|
43183
|
+
);
|
|
43255
43184
|
}
|
|
43256
43185
|
};
|
|
43257
|
-
failed = (sessionId, commandId,
|
|
43186
|
+
failed = async (sessionId, commandId, code, message) => {
|
|
43258
43187
|
const request = this.#queued.get(commandId);
|
|
43259
|
-
if (request?.sessionId
|
|
43260
|
-
|
|
43188
|
+
if (request?.sessionId !== sessionId || this.#terminal.has(commandId)) {
|
|
43189
|
+
return;
|
|
43190
|
+
}
|
|
43191
|
+
const recorded = await this.#recordLifecycle(sessionId, {
|
|
43192
|
+
type: "lifecycle-metadata",
|
|
43193
|
+
payload: { kind: "prompt.failed-before-start", commandId, code, message }
|
|
43194
|
+
});
|
|
43195
|
+
if (!recorded) {
|
|
43196
|
+
this.#publisher.publishOperationFailure(sessionId, commandId, code, message);
|
|
43261
43197
|
}
|
|
43262
43198
|
};
|
|
43263
43199
|
promptRequestRecovery = (sessionId) => ({
|
|
43264
|
-
queuedPromptRequests: [...this.#queued.values()].filter((request) => request.sessionId === sessionId).map(({ commandId, content }) => ({ commandId, content }))
|
|
43200
|
+
queuedPromptRequests: [...this.#queued.values()].filter((request) => request.sessionId === sessionId && request.phase === "queued").map(({ commandId, content }) => ({ commandId, content }))
|
|
43265
43201
|
});
|
|
43266
43202
|
};
|
|
43267
43203
|
|
|
@@ -43313,7 +43249,7 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
|
|
|
43313
43249
|
{
|
|
43314
43250
|
agentId: agent.id,
|
|
43315
43251
|
kind: AGENT_INSTALL_REQUEST_KIND,
|
|
43316
|
-
requestId: `automatic-integration-${
|
|
43252
|
+
requestId: `automatic-integration-${randomUUID10()}`
|
|
43317
43253
|
},
|
|
43318
43254
|
signal
|
|
43319
43255
|
);
|
|
@@ -43331,19 +43267,33 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
43331
43267
|
publishCatalog: async (installationSignal) => await publishAgentCatalog(config2, installationSignal),
|
|
43332
43268
|
stateDirectory
|
|
43333
43269
|
});
|
|
43334
|
-
const
|
|
43335
|
-
|
|
43336
|
-
);
|
|
43270
|
+
const channelHash = createHash8("sha256").update(config2.channelId).digest("hex");
|
|
43271
|
+
const daemonGenerationId = randomUUID10();
|
|
43272
|
+
const sessionDatabase = openAcpSessionDatabase(join19(stateDirectory, "sessions", `${channelHash}.sqlite`));
|
|
43273
|
+
let eventsV2;
|
|
43274
|
+
try {
|
|
43275
|
+
eventsV2 = new CachedAcpSessionEventStoreV2(
|
|
43276
|
+
openSessionEventCacheV2Database(join19(stateDirectory, "sessions", `${channelHash}.events.sqlite`)),
|
|
43277
|
+
daemonGenerationId
|
|
43278
|
+
);
|
|
43279
|
+
} catch (error62) {
|
|
43280
|
+
sessionDatabase.close();
|
|
43281
|
+
throw error62;
|
|
43282
|
+
}
|
|
43283
|
+
const sessionStore = new SqliteAcpSessionStore(sessionDatabase, eventsV2);
|
|
43337
43284
|
await using externalContent = new LocalExternalContentStore(stateDirectory);
|
|
43338
43285
|
const operations = new DaemonOperationState();
|
|
43339
43286
|
const publisher = new DaemonSessionEventPublisher();
|
|
43340
|
-
const eventLogV2 = new DaemonSessionEventLogV2(
|
|
43287
|
+
const eventLogV2 = new DaemonSessionEventLogV2(
|
|
43288
|
+
publisher,
|
|
43289
|
+
(sessionId, event) => agentRuntime.recordLifecycleEventV2(sessionId, event),
|
|
43290
|
+
daemonGenerationId
|
|
43291
|
+
);
|
|
43341
43292
|
const activeTurns = new DaemonTurnRegistry(operations);
|
|
43342
|
-
const recordSessionEvent = (sessionId, event) => {
|
|
43343
|
-
publisher.publish(sessionId, activeTurns.recordEvent(event));
|
|
43344
|
-
};
|
|
43345
43293
|
const agentRuntime = new AgentRuntimeManager(
|
|
43346
|
-
new DaemonAcpObserver(
|
|
43294
|
+
new DaemonAcpObserver((_sessionId, event) => {
|
|
43295
|
+
activeTurns.recordEvent(event);
|
|
43296
|
+
}, eventLogV2.record),
|
|
43347
43297
|
sessionStore,
|
|
43348
43298
|
{
|
|
43349
43299
|
read: async (options2, nativeSessionId, nativeTurn) => options2.agent.id === "codex" ? (await readCodexFullHistory(
|
|
@@ -43383,7 +43333,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
43383
43333
|
options2.signal
|
|
43384
43334
|
);
|
|
43385
43335
|
return cwd === options2.cwd && additionalDirectories.length === options2.additionalDirectories.length && additionalDirectories.every(
|
|
43386
|
-
(directory,
|
|
43336
|
+
(directory, index2) => directory === options2.additionalDirectories[index2]
|
|
43387
43337
|
);
|
|
43388
43338
|
});
|
|
43389
43339
|
}
|