@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/runtime.js
CHANGED
|
@@ -3354,11 +3354,11 @@ var $ZodDate = /* @__PURE__ */ $constructor("$ZodDate", (inst, def) => {
|
|
|
3354
3354
|
return payload;
|
|
3355
3355
|
};
|
|
3356
3356
|
});
|
|
3357
|
-
function handleArrayResult(result, final,
|
|
3357
|
+
function handleArrayResult(result, final, index2) {
|
|
3358
3358
|
if (result.issues.length) {
|
|
3359
|
-
final.issues.push(...prefixIssues(
|
|
3359
|
+
final.issues.push(...prefixIssues(index2, result.issues));
|
|
3360
3360
|
}
|
|
3361
|
-
final.value[
|
|
3361
|
+
final.value[index2] = result.value;
|
|
3362
3362
|
}
|
|
3363
3363
|
var $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
|
|
3364
3364
|
$ZodType.init(inst, def);
|
|
@@ -3969,14 +3969,14 @@ function mergeValues(a, b) {
|
|
|
3969
3969
|
return { valid: false, mergeErrorPath: [] };
|
|
3970
3970
|
}
|
|
3971
3971
|
const newArray = [];
|
|
3972
|
-
for (let
|
|
3973
|
-
const itemA = a[
|
|
3974
|
-
const itemB = b[
|
|
3972
|
+
for (let index2 = 0; index2 < a.length; index2++) {
|
|
3973
|
+
const itemA = a[index2];
|
|
3974
|
+
const itemB = b[index2];
|
|
3975
3975
|
const sharedValue = mergeValues(itemA, itemB);
|
|
3976
3976
|
if (!sharedValue.valid) {
|
|
3977
3977
|
return {
|
|
3978
3978
|
valid: false,
|
|
3979
|
-
mergeErrorPath: [
|
|
3979
|
+
mergeErrorPath: [index2, ...sharedValue.mergeErrorPath]
|
|
3980
3980
|
};
|
|
3981
3981
|
}
|
|
3982
3982
|
newArray.push(sharedValue.data);
|
|
@@ -4127,11 +4127,11 @@ function getTupleOptStart(items, key) {
|
|
|
4127
4127
|
}
|
|
4128
4128
|
return 0;
|
|
4129
4129
|
}
|
|
4130
|
-
function handleTupleResult(result, final,
|
|
4130
|
+
function handleTupleResult(result, final, index2) {
|
|
4131
4131
|
if (result.issues.length) {
|
|
4132
|
-
final.issues.push(...prefixIssues(
|
|
4132
|
+
final.issues.push(...prefixIssues(index2, result.issues));
|
|
4133
4133
|
}
|
|
4134
|
-
final.value[
|
|
4134
|
+
final.value[index2] = result.value;
|
|
4135
4135
|
}
|
|
4136
4136
|
function handleTupleResults(itemResults, final, items, input2, optoutStart) {
|
|
4137
4137
|
for (let i = 0; i < items.length; i++) {
|
|
@@ -18812,7 +18812,7 @@ function detectVersion(schema, defaultTarget) {
|
|
|
18812
18812
|
return defaultTarget ?? "draft-2020-12";
|
|
18813
18813
|
}
|
|
18814
18814
|
function applyMinItems(items, minItems) {
|
|
18815
|
-
return items.map((item,
|
|
18815
|
+
return items.map((item, index2) => index2 < minItems ? item : item.optional());
|
|
18816
18816
|
}
|
|
18817
18817
|
function decodeJSONPointerSegment(segment) {
|
|
18818
18818
|
return segment.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
@@ -19997,12 +19997,12 @@ var DEFAULT_AGENT_EXECUTION_CONFIGURATION = Object.freeze({
|
|
|
19997
19997
|
});
|
|
19998
19998
|
var sessionConfigurationSelectionsSchema = external_exports.array(sessionConfigurationSelectionSchema).max(100).superRefine((selections, context) => {
|
|
19999
19999
|
const identifiers = /* @__PURE__ */ new Set();
|
|
20000
|
-
for (const [
|
|
20000
|
+
for (const [index2, selection] of selections.entries()) {
|
|
20001
20001
|
if (identifiers.has(selection.configId)) {
|
|
20002
20002
|
context.addIssue({
|
|
20003
20003
|
code: "custom",
|
|
20004
20004
|
message: "Session configuration identifiers must be unique",
|
|
20005
|
-
path: [
|
|
20005
|
+
path: [index2, "configId"]
|
|
20006
20006
|
});
|
|
20007
20007
|
}
|
|
20008
20008
|
identifiers.add(selection.configId);
|
|
@@ -20342,8 +20342,6 @@ function decodeValue(value, schema) {
|
|
|
20342
20342
|
}
|
|
20343
20343
|
return result.data;
|
|
20344
20344
|
}
|
|
20345
|
-
var decodeAgentDisplayContentValue = (value) => decodeValue(value, displayContentSchema);
|
|
20346
|
-
var decodeRecordedAgentContentValue = (value) => decodeValue(value, recordedDisplayContentSchema);
|
|
20347
20345
|
var decodePromptImagesValue = (value) => decodeValue(value, external_exports.array(promptImageSchema).max(8).readonly());
|
|
20348
20346
|
var decodePromptResourcesValue = (value) => decodeValue(value, external_exports.array(promptResourceSchema).max(16).readonly());
|
|
20349
20347
|
var decodeSessionConfigurationSelections = (value) => decodeValue(value, sessionConfigurationSelectionsSchema);
|
|
@@ -20385,20 +20383,13 @@ var encodeSessionReadyEvent = (message) => encode3(message, sessionReadyEventSch
|
|
|
20385
20383
|
var decodeSessionConfigureCommand = (encoded) => decode3(encoded, sessionConfigureCommandSchema);
|
|
20386
20384
|
var encodeSessionConfigureCommand = (message) => encode3(message, sessionConfigureCommandSchema);
|
|
20387
20385
|
var decodeSessionConfigUpdatedEvent = (encoded) => decode3(encoded, sessionConfigUpdatedEventSchema);
|
|
20388
|
-
var
|
|
20389
|
-
var decodeSessionCommandsUpdatedEvent = (encoded) => decode3(encoded, sessionCommandsUpdatedEventSchema);
|
|
20390
|
-
var decodeSessionInfoUpdatedEvent = (encoded) => decode3(encoded, sessionInfoUpdatedEventSchema);
|
|
20391
|
-
var decodeSessionPermissionRequestedEvent = (encoded) => decode3(encoded, sessionPermissionRequestedEventSchema);
|
|
20386
|
+
var encodeSessionConfigUpdatedEvent = (message) => encode3(message, sessionConfigUpdatedEventSchema);
|
|
20392
20387
|
var decodeSessionPermissionRespondCommand = (encoded) => decode3(encoded, sessionPermissionRespondCommandSchema);
|
|
20393
20388
|
var encodeSessionPermissionRespondCommand = (message) => encode3(message, sessionPermissionRespondCommandSchema);
|
|
20394
|
-
var decodeSessionPermissionResolvedEvent = (encoded) => decode3(encoded, sessionPermissionResolvedEventSchema);
|
|
20395
|
-
var decodeSessionElicitationRequestedEvent = (encoded) => decode3(encoded, sessionElicitationRequestedEventSchema);
|
|
20396
20389
|
var decodeSessionElicitationRespondCommand = (encoded) => decode3(encoded, sessionElicitationRespondCommandSchema);
|
|
20397
20390
|
var encodeSessionElicitationRespondCommand = (message) => encode3(message, sessionElicitationRespondCommandSchema);
|
|
20398
|
-
var decodeSessionElicitationResolvedEvent = (encoded) => decode3(encoded, sessionElicitationResolvedEventSchema);
|
|
20399
20391
|
var decodeSessionOperationFailedEvent = (encoded) => decode3(encoded, sessionOperationFailedEventSchema);
|
|
20400
20392
|
var encodeSessionOperationFailedEvent = (message) => encode3(message, sessionOperationFailedEventSchema);
|
|
20401
|
-
var decodeAgentContentEvent = (encoded) => decode3(encoded, agentContentEventSchema);
|
|
20402
20393
|
var decodeAgentInstallRequestCommand = (encoded) => decode3(encoded, agentInstallRequestCommandSchema);
|
|
20403
20394
|
var encodeAgentInstallRequestCommand = (message) => encode3(message, agentInstallRequestCommandSchema);
|
|
20404
20395
|
var decodeAgentInstallCancelCommand = (encoded) => decode3(encoded, agentInstallCancelCommandSchema);
|
|
@@ -20424,7 +20415,6 @@ var RUNTIME_HEARTBEAT_KIND = "runtime.heartbeat";
|
|
|
20424
20415
|
var RUNTIME_HEARTBEAT_ACK_KIND = "runtime.heartbeat.ack";
|
|
20425
20416
|
var RUNTIME_PING_KIND = "runtime.ping";
|
|
20426
20417
|
var RUNTIME_PONG_KIND = "runtime.pong";
|
|
20427
|
-
var SESSION_STARTED_KIND = "session.started";
|
|
20428
20418
|
var SESSION_QUEUED_KIND = "session.queued";
|
|
20429
20419
|
var AGENT_MESSAGE_DELTA_KIND = "agent.message.delta";
|
|
20430
20420
|
var AGENT_ACTIVITY_KIND = "agent.activity";
|
|
@@ -20434,8 +20424,6 @@ var AGENT_ACTIVITY_RECORDED_FIELD_LIMIT = 4e6;
|
|
|
20434
20424
|
var AGENT_ACTIVITY_RECORDED_DETAIL_LIMIT = 6e6;
|
|
20435
20425
|
var AGENT_ACTIVITY_LOCATION_LIMIT = 12;
|
|
20436
20426
|
var AGENT_ACTIVITY_LOCATION_LENGTH_LIMIT = 1024;
|
|
20437
|
-
var SESSION_COMPLETED_KIND = "session.completed";
|
|
20438
|
-
var SESSION_FAILED_KIND = "session.failed";
|
|
20439
20427
|
var SessionPromptDisposition = Object.freeze({
|
|
20440
20428
|
Queue: "queue",
|
|
20441
20429
|
Reject: "reject",
|
|
@@ -20446,23 +20434,6 @@ var SessionPromptDisposition = Object.freeze({
|
|
|
20446
20434
|
var DIRECTORY_IDENTIFIER_PATTERN2 = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/;
|
|
20447
20435
|
var MAX_PROMPT_LENGTH = 1e4;
|
|
20448
20436
|
var MAX_PROMPT_ATTACHMENT_LENGTH = 6e6;
|
|
20449
|
-
var MAX_EVENT_TEXT_LENGTH = 1e5;
|
|
20450
|
-
var ACTIVITY_TYPES = /* @__PURE__ */ new Set(["notice", "plan", "progress", "reasoning", "tool"]);
|
|
20451
|
-
var NARRATION_ACTIVITY_TYPES = /* @__PURE__ */ new Set(["progress", "reasoning"]);
|
|
20452
|
-
var ACTIVITY_STATUSES = /* @__PURE__ */ new Set(["pending", "running", "completed", "failed"]);
|
|
20453
|
-
var TOOL_KINDS = /* @__PURE__ */ new Set([
|
|
20454
|
-
"",
|
|
20455
|
-
"delete",
|
|
20456
|
-
"edit",
|
|
20457
|
-
"execute",
|
|
20458
|
-
"fetch",
|
|
20459
|
-
"move",
|
|
20460
|
-
"other",
|
|
20461
|
-
"read",
|
|
20462
|
-
"search",
|
|
20463
|
-
"switch_mode",
|
|
20464
|
-
"think"
|
|
20465
|
-
]);
|
|
20466
20437
|
var ProtocolMessageError = class extends Error {
|
|
20467
20438
|
code = "invalid_protocol_message";
|
|
20468
20439
|
constructor(message, options = {}) {
|
|
@@ -20512,13 +20483,6 @@ function readText(value, key, maximumLength) {
|
|
|
20512
20483
|
}
|
|
20513
20484
|
return field;
|
|
20514
20485
|
}
|
|
20515
|
-
function readAllowedString(value, key, allowedValues) {
|
|
20516
|
-
const field = readText(value, key, 64);
|
|
20517
|
-
if (!allowedValues.has(field)) {
|
|
20518
|
-
throw new ProtocolMessageError(`Invalid value field: ${key}`);
|
|
20519
|
-
}
|
|
20520
|
-
return field;
|
|
20521
|
-
}
|
|
20522
20486
|
function readPromptDisposition(value) {
|
|
20523
20487
|
const field = value["disposition"];
|
|
20524
20488
|
if (field === void 0 || field === SessionPromptDisposition.Reject) {
|
|
@@ -20532,32 +20496,6 @@ function readPromptDisposition(value) {
|
|
|
20532
20496
|
}
|
|
20533
20497
|
throw new ProtocolMessageError("Invalid value field: disposition");
|
|
20534
20498
|
}
|
|
20535
|
-
function readSequence(value, key) {
|
|
20536
|
-
const field = value[key];
|
|
20537
|
-
if (typeof field !== "number" || !Number.isSafeInteger(field) || field < 0) {
|
|
20538
|
-
throw new ProtocolMessageError(`Invalid integer field: ${key}`);
|
|
20539
|
-
}
|
|
20540
|
-
return field;
|
|
20541
|
-
}
|
|
20542
|
-
function readLocations(value) {
|
|
20543
|
-
const field = value["locations"];
|
|
20544
|
-
if (!Array.isArray(field) || field.length > AGENT_ACTIVITY_LOCATION_LIMIT) {
|
|
20545
|
-
throw new ProtocolMessageError("Invalid locations field");
|
|
20546
|
-
}
|
|
20547
|
-
const locations = [];
|
|
20548
|
-
const unique = /* @__PURE__ */ new Set();
|
|
20549
|
-
for (const location of field) {
|
|
20550
|
-
if (typeof location !== "string" || location.length === 0 || location.length > AGENT_ACTIVITY_LOCATION_LENGTH_LIMIT) {
|
|
20551
|
-
throw new ProtocolMessageError("Invalid activity location");
|
|
20552
|
-
}
|
|
20553
|
-
if (unique.has(location)) {
|
|
20554
|
-
throw new ProtocolMessageError("Duplicate activity location");
|
|
20555
|
-
}
|
|
20556
|
-
unique.add(location);
|
|
20557
|
-
locations.push(location);
|
|
20558
|
-
}
|
|
20559
|
-
return locations;
|
|
20560
|
-
}
|
|
20561
20499
|
function readDirectoryIdentifiers(value, key, maximumCount) {
|
|
20562
20500
|
const field = value[key];
|
|
20563
20501
|
if (!Array.isArray(field) || field.length > maximumCount) {
|
|
@@ -20574,54 +20512,6 @@ function readDirectoryIdentifiers(value, key, maximumCount) {
|
|
|
20574
20512
|
}
|
|
20575
20513
|
return identifiers;
|
|
20576
20514
|
}
|
|
20577
|
-
function readActivityContent(value) {
|
|
20578
|
-
const field = value["content"];
|
|
20579
|
-
if (!Array.isArray(field) || field.length > 100) {
|
|
20580
|
-
throw new ProtocolMessageError("Invalid activity content field");
|
|
20581
|
-
}
|
|
20582
|
-
return field.map((entry) => decodeAgentDisplayContentValue(entry));
|
|
20583
|
-
}
|
|
20584
|
-
function readActivityDetail(value) {
|
|
20585
|
-
const field = value["detail"];
|
|
20586
|
-
if (!isRecord(field)) {
|
|
20587
|
-
throw new ProtocolMessageError("Invalid activity detail field");
|
|
20588
|
-
}
|
|
20589
|
-
const kind = readString(field, "kind", 32);
|
|
20590
|
-
if (kind === "available") {
|
|
20591
|
-
return {
|
|
20592
|
-
artifactId: readIdentifier(field, "artifactId"),
|
|
20593
|
-
kind
|
|
20594
|
-
};
|
|
20595
|
-
}
|
|
20596
|
-
if (kind === "unrecorded") {
|
|
20597
|
-
return { kind };
|
|
20598
|
-
}
|
|
20599
|
-
if (kind === "truncated") {
|
|
20600
|
-
const capturedBytes = readSequence(field, "capturedBytes");
|
|
20601
|
-
const originalBytes = readSequence(field, "originalBytes");
|
|
20602
|
-
if (capturedBytes > originalBytes) {
|
|
20603
|
-
throw new ProtocolMessageError("Invalid truncated activity detail size");
|
|
20604
|
-
}
|
|
20605
|
-
return { capturedBytes, kind, originalBytes };
|
|
20606
|
-
}
|
|
20607
|
-
if (kind === "recorded") {
|
|
20608
|
-
const contentValue = field["content"];
|
|
20609
|
-
if (!Array.isArray(contentValue) || contentValue.length > 100) {
|
|
20610
|
-
throw new ProtocolMessageError("Invalid recorded activity content");
|
|
20611
|
-
}
|
|
20612
|
-
const detail = {
|
|
20613
|
-
content: contentValue.map((entry) => decodeRecordedAgentContentValue(entry)),
|
|
20614
|
-
input: readText(field, "input", AGENT_ACTIVITY_RECORDED_FIELD_LIMIT),
|
|
20615
|
-
kind,
|
|
20616
|
-
output: readText(field, "output", AGENT_ACTIVITY_RECORDED_FIELD_LIMIT)
|
|
20617
|
-
};
|
|
20618
|
-
if (JSON.stringify(detail).length > AGENT_ACTIVITY_RECORDED_DETAIL_LIMIT) {
|
|
20619
|
-
throw new ProtocolMessageError("Recorded activity detail is too large");
|
|
20620
|
-
}
|
|
20621
|
-
return detail;
|
|
20622
|
-
}
|
|
20623
|
-
throw new ProtocolMessageError("Invalid activity detail availability");
|
|
20624
|
-
}
|
|
20625
20515
|
function readIdentifier(value, key) {
|
|
20626
20516
|
try {
|
|
20627
20517
|
return decodeIdentifier(value[key]);
|
|
@@ -20746,82 +20636,6 @@ function decodeRuntimePongEvent(encoded) {
|
|
|
20746
20636
|
assertKind(value, RUNTIME_PONG_KIND);
|
|
20747
20637
|
return { kind: RUNTIME_PONG_KIND, requestId: readIdentifier(value, "requestId") };
|
|
20748
20638
|
}
|
|
20749
|
-
function decodeSessionStartedEvent(encoded) {
|
|
20750
|
-
const value = parseJson2(encoded);
|
|
20751
|
-
assertKind(value, SESSION_STARTED_KIND);
|
|
20752
|
-
const sequence = readSequence(value, "sequence");
|
|
20753
|
-
if (sequence !== 0) {
|
|
20754
|
-
throw new ProtocolMessageError("Invalid live start sequence");
|
|
20755
|
-
}
|
|
20756
|
-
return {
|
|
20757
|
-
commandId: readIdentifier(value, "commandId"),
|
|
20758
|
-
epoch: readIdentifier(value, "epoch"),
|
|
20759
|
-
kind: SESSION_STARTED_KIND,
|
|
20760
|
-
attemptId: readIdentifier(value, "attemptId"),
|
|
20761
|
-
prompt: readText(value, "prompt", MAX_PROMPT_LENGTH),
|
|
20762
|
-
sequence,
|
|
20763
|
-
sessionId: readIdentifier(value, "sessionId")
|
|
20764
|
-
};
|
|
20765
|
-
}
|
|
20766
|
-
function decodeAgentMessageDeltaEvent(encoded) {
|
|
20767
|
-
const value = parseJson2(encoded);
|
|
20768
|
-
assertKind(value, AGENT_MESSAGE_DELTA_KIND);
|
|
20769
|
-
const sequence = readSequence(value, "sequence");
|
|
20770
|
-
if (sequence === 0) {
|
|
20771
|
-
throw new ProtocolMessageError("Invalid live sequence");
|
|
20772
|
-
}
|
|
20773
|
-
return {
|
|
20774
|
-
commandId: readIdentifier(value, "commandId"),
|
|
20775
|
-
epoch: readIdentifier(value, "epoch"),
|
|
20776
|
-
kind: AGENT_MESSAGE_DELTA_KIND,
|
|
20777
|
-
messageId: value["messageId"] === void 0 ? "" : readText(value, "messageId", 255),
|
|
20778
|
-
sequence,
|
|
20779
|
-
sessionId: readIdentifier(value, "sessionId"),
|
|
20780
|
-
text: readString(value, "text", MAX_EVENT_TEXT_LENGTH)
|
|
20781
|
-
};
|
|
20782
|
-
}
|
|
20783
|
-
function decodeAgentActivityEvent(encoded) {
|
|
20784
|
-
const value = parseJson2(encoded);
|
|
20785
|
-
assertKind(value, AGENT_ACTIVITY_KIND);
|
|
20786
|
-
return {
|
|
20787
|
-
activityId: readIdentifier(value, "activityId"),
|
|
20788
|
-
activityType: readAllowedString(value, "activityType", ACTIVITY_TYPES),
|
|
20789
|
-
commandId: readIdentifier(value, "commandId"),
|
|
20790
|
-
content: readActivityContent(value),
|
|
20791
|
-
detail: readActivityDetail(value),
|
|
20792
|
-
input: readText(value, "input", AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
20793
|
-
kind: AGENT_ACTIVITY_KIND,
|
|
20794
|
-
locations: readLocations(value),
|
|
20795
|
-
name: readText(value, "name", 128),
|
|
20796
|
-
output: readText(value, "output", AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
20797
|
-
sequence: readSequence(value, "sequence"),
|
|
20798
|
-
sessionId: readIdentifier(value, "sessionId"),
|
|
20799
|
-
status: readAllowedString(value, "status", ACTIVITY_STATUSES),
|
|
20800
|
-
title: readString(value, "title", 500),
|
|
20801
|
-
toolKind: readAllowedString(value, "toolKind", TOOL_KINDS)
|
|
20802
|
-
};
|
|
20803
|
-
}
|
|
20804
|
-
function decodeSessionCompletedEvent(encoded) {
|
|
20805
|
-
const value = parseJson2(encoded);
|
|
20806
|
-
assertKind(value, SESSION_COMPLETED_KIND);
|
|
20807
|
-
return {
|
|
20808
|
-
commandId: readIdentifier(value, "commandId"),
|
|
20809
|
-
kind: SESSION_COMPLETED_KIND,
|
|
20810
|
-
sessionId: readIdentifier(value, "sessionId"),
|
|
20811
|
-
stopReason: readString(value, "stopReason", 64)
|
|
20812
|
-
};
|
|
20813
|
-
}
|
|
20814
|
-
function decodeSessionFailedEvent(encoded) {
|
|
20815
|
-
const value = parseJson2(encoded);
|
|
20816
|
-
assertKind(value, SESSION_FAILED_KIND);
|
|
20817
|
-
return {
|
|
20818
|
-
code: readIdentifier(value, "code"),
|
|
20819
|
-
commandId: readIdentifier(value, "commandId"),
|
|
20820
|
-
kind: SESSION_FAILED_KIND,
|
|
20821
|
-
message: readString(value, "message", 500),
|
|
20822
|
-
sessionId: readIdentifier(value, "sessionId")
|
|
20823
|
-
};
|
|
20824
|
-
}
|
|
20825
20639
|
function encodeSessionPromptCommand(message) {
|
|
20826
20640
|
return JSON.stringify(decodeSessionPromptCommand(JSON.stringify(message)));
|
|
20827
20641
|
}
|
|
@@ -20849,19 +20663,6 @@ function encodeRuntimePingCommand(message) {
|
|
|
20849
20663
|
function encodeRuntimePongEvent(message) {
|
|
20850
20664
|
return JSON.stringify(decodeRuntimePongEvent(JSON.stringify(message)));
|
|
20851
20665
|
}
|
|
20852
|
-
function decodeAgentActivityNarrationEvent(encoded) {
|
|
20853
|
-
const value = parseJson2(encoded);
|
|
20854
|
-
assertKind(value, AGENT_ACTIVITY_NARRATION_KIND);
|
|
20855
|
-
return {
|
|
20856
|
-
activityId: readIdentifier(value, "activityId"),
|
|
20857
|
-
activityType: readAllowedString(value, "activityType", NARRATION_ACTIVITY_TYPES),
|
|
20858
|
-
commandId: readIdentifier(value, "commandId"),
|
|
20859
|
-
kind: AGENT_ACTIVITY_NARRATION_KIND,
|
|
20860
|
-
sequence: readSequence(value, "sequence"),
|
|
20861
|
-
sessionId: readIdentifier(value, "sessionId"),
|
|
20862
|
-
text: readText(value, "text", MAX_EVENT_TEXT_LENGTH)
|
|
20863
|
-
};
|
|
20864
|
-
}
|
|
20865
20666
|
|
|
20866
20667
|
// ../protocol/src/session-history.ts
|
|
20867
20668
|
var SESSION_HISTORY_CHARACTER_LIMIT = 256e3;
|
|
@@ -21430,6 +21231,11 @@ var acpSessionUpdateV2Schema = external_exports.discriminatedUnion("sessionUpdat
|
|
|
21430
21231
|
}).readonly()
|
|
21431
21232
|
]);
|
|
21432
21233
|
var lifecycleBase = { commandId: identifierStringSchema };
|
|
21234
|
+
var promptExecutionContextV2Schema = external_exports.object({
|
|
21235
|
+
agentId: identifierStringSchema,
|
|
21236
|
+
directoryId: shortString,
|
|
21237
|
+
additionalDirectoryIds: external_exports.array(identifierStringSchema).max(16).readonly()
|
|
21238
|
+
}).readonly();
|
|
21433
21239
|
var lifecycleMetadataV2Schema = external_exports.discriminatedUnion("kind", [
|
|
21434
21240
|
external_exports.object({ kind: external_exports.literal("session.queue.changed") }).readonly(),
|
|
21435
21241
|
external_exports.object({ event: sessionPermissionRequestedEventSchema, kind: external_exports.literal("session.permission.requested") }).readonly(),
|
|
@@ -21439,7 +21245,8 @@ var lifecycleMetadataV2Schema = external_exports.discriminatedUnion("kind", [
|
|
|
21439
21245
|
external_exports.object({
|
|
21440
21246
|
...lifecycleBase,
|
|
21441
21247
|
content: external_exports.array(contentBlockV2Schema).min(1).max(100).readonly(),
|
|
21442
|
-
kind: external_exports.literal("prompt.requested")
|
|
21248
|
+
kind: external_exports.literal("prompt.requested"),
|
|
21249
|
+
context: promptExecutionContextV2Schema.optional()
|
|
21443
21250
|
}).readonly(),
|
|
21444
21251
|
external_exports.object({ ...lifecycleBase, attemptId: identifierStringSchema, epoch: identifierStringSchema, kind: external_exports.literal("prompt.started") }).readonly(),
|
|
21445
21252
|
external_exports.object({ ...lifecycleBase, kind: external_exports.literal("prompt.completed"), stopReason: shortString }).readonly(),
|
|
@@ -21503,12 +21310,12 @@ var sessionExportV2Schema = external_exports.object({
|
|
|
21503
21310
|
}).readonly().superRefine((session, context) => {
|
|
21504
21311
|
let previousPosition = 0n;
|
|
21505
21312
|
const eventIds = /* @__PURE__ */ new Set();
|
|
21506
|
-
for (const [
|
|
21313
|
+
for (const [index2, event] of session.events.entries()) {
|
|
21507
21314
|
if (event.sessionId !== session.sessionId) {
|
|
21508
21315
|
context.addIssue({
|
|
21509
21316
|
code: "custom",
|
|
21510
21317
|
message: "Exported event belongs to a different Session",
|
|
21511
|
-
path: ["events",
|
|
21318
|
+
path: ["events", index2, "sessionId"]
|
|
21512
21319
|
});
|
|
21513
21320
|
}
|
|
21514
21321
|
const position = BigInt(event.position);
|
|
@@ -21516,14 +21323,14 @@ var sessionExportV2Schema = external_exports.object({
|
|
|
21516
21323
|
context.addIssue({
|
|
21517
21324
|
code: "custom",
|
|
21518
21325
|
message: "Exported events are not in increasing position order",
|
|
21519
|
-
path: ["events",
|
|
21326
|
+
path: ["events", index2, "position"]
|
|
21520
21327
|
});
|
|
21521
21328
|
}
|
|
21522
21329
|
if (eventIds.has(event.eventId)) {
|
|
21523
21330
|
context.addIssue({
|
|
21524
21331
|
code: "custom",
|
|
21525
21332
|
message: "Exported event identities are not unique",
|
|
21526
|
-
path: ["events",
|
|
21333
|
+
path: ["events", index2, "eventId"]
|
|
21527
21334
|
});
|
|
21528
21335
|
}
|
|
21529
21336
|
previousPosition = position;
|
|
@@ -21574,98 +21381,11 @@ function decode5(value, schema) {
|
|
|
21574
21381
|
function encode4(value, schema) {
|
|
21575
21382
|
return JSON.stringify(decode5(value, schema));
|
|
21576
21383
|
}
|
|
21384
|
+
var decodeSessionEventV2 = (value) => decode5(value, sessionEventV2Schema);
|
|
21577
21385
|
var decodeSessionEventEnvelopeV2 = (value) => decode5(value, sessionEventEnvelopeV2Schema);
|
|
21578
21386
|
var encodeSessionEventEnvelopeV2 = (value) => encode4(value, sessionEventEnvelopeV2Schema);
|
|
21579
21387
|
var decodeAcpSessionUpdateV2 = (value) => decode5(value, acpSessionUpdateV2Schema);
|
|
21580
21388
|
|
|
21581
|
-
// ../protocol/src/session-events.ts
|
|
21582
|
-
var SESSION_EVENT_KIND = "session.event";
|
|
21583
|
-
var SESSION_FORKED_KIND = "session.forked";
|
|
21584
|
-
var MAX_RECORDED_EVENT_LENGTH = 8 * 1024 * 1024;
|
|
21585
|
-
var sessionEventEnvelopeSchema = external_exports.object({
|
|
21586
|
-
kind: external_exports.literal(SESSION_EVENT_KIND),
|
|
21587
|
-
payload: external_exports.string().min(2).max(MAX_RECORDED_EVENT_LENGTH),
|
|
21588
|
-
sessionId: identifierStringSchema
|
|
21589
|
-
}).readonly();
|
|
21590
|
-
var SESSION_QUEUE_CHANGED_KIND = "session.queue.changed";
|
|
21591
|
-
var sessionQueueChangedSchema = external_exports.object({ kind: external_exports.literal(SESSION_QUEUE_CHANGED_KIND), sessionId: identifierStringSchema }).readonly();
|
|
21592
|
-
var sessionForkedSchema = external_exports.object({
|
|
21593
|
-
kind: external_exports.literal(SESSION_FORKED_KIND),
|
|
21594
|
-
sessionId: identifierStringSchema,
|
|
21595
|
-
sourceSessionId: identifierStringSchema,
|
|
21596
|
-
throughCommandId: identifierStringSchema
|
|
21597
|
-
}).readonly();
|
|
21598
|
-
function decode6(encoded, schema) {
|
|
21599
|
-
let value;
|
|
21600
|
-
try {
|
|
21601
|
-
value = JSON.parse(encoded);
|
|
21602
|
-
} catch (cause) {
|
|
21603
|
-
throw new ProtocolMessageError("Message is not valid JSON", { cause });
|
|
21604
|
-
}
|
|
21605
|
-
const decoded = schema.safeParse(value);
|
|
21606
|
-
if (!decoded.success) {
|
|
21607
|
-
throw new ProtocolMessageError("Message does not match its schema", {
|
|
21608
|
-
cause: decoded.error
|
|
21609
|
-
});
|
|
21610
|
-
}
|
|
21611
|
-
return decoded.data;
|
|
21612
|
-
}
|
|
21613
|
-
var encode5 = (message, schema) => {
|
|
21614
|
-
const decoded = schema.safeParse(message);
|
|
21615
|
-
if (!decoded.success) {
|
|
21616
|
-
throw new ProtocolMessageError("Message does not match its schema", {
|
|
21617
|
-
cause: decoded.error
|
|
21618
|
-
});
|
|
21619
|
-
}
|
|
21620
|
-
return JSON.stringify(decoded.data);
|
|
21621
|
-
};
|
|
21622
|
-
var decodeSessionEventEnvelope = (encoded) => decode6(encoded, sessionEventEnvelopeSchema);
|
|
21623
|
-
var encodeSessionEventEnvelope = (message) => encode5(message, sessionEventEnvelopeSchema);
|
|
21624
|
-
function decodeRecordedSessionEvent(encoded) {
|
|
21625
|
-
const kind = decodeMessageKind(encoded);
|
|
21626
|
-
switch (kind) {
|
|
21627
|
-
case SESSION_QUEUE_CHANGED_KIND:
|
|
21628
|
-
return decode6(encoded, sessionQueueChangedSchema);
|
|
21629
|
-
case SESSION_FORKED_KIND:
|
|
21630
|
-
return decode6(encoded, sessionForkedSchema);
|
|
21631
|
-
case AGENT_ACTIVITY_KIND:
|
|
21632
|
-
return decodeAgentActivityEvent(encoded);
|
|
21633
|
-
case AGENT_ACTIVITY_NARRATION_KIND:
|
|
21634
|
-
return decodeAgentActivityNarrationEvent(encoded);
|
|
21635
|
-
case AGENT_CONTENT_KIND:
|
|
21636
|
-
return decodeAgentContentEvent(encoded);
|
|
21637
|
-
case AGENT_MESSAGE_DELTA_KIND:
|
|
21638
|
-
return decodeAgentMessageDeltaEvent(encoded);
|
|
21639
|
-
case SESSION_COMMANDS_UPDATED_KIND:
|
|
21640
|
-
return decodeSessionCommandsUpdatedEvent(encoded);
|
|
21641
|
-
case SESSION_COMPLETED_KIND:
|
|
21642
|
-
return decodeSessionCompletedEvent(encoded);
|
|
21643
|
-
case SESSION_CONFIG_UPDATED_KIND:
|
|
21644
|
-
return decodeSessionConfigUpdatedEvent(encoded);
|
|
21645
|
-
case SESSION_ELICITATION_REQUESTED_KIND:
|
|
21646
|
-
return decodeSessionElicitationRequestedEvent(encoded);
|
|
21647
|
-
case SESSION_ELICITATION_RESOLVED_KIND:
|
|
21648
|
-
return decodeSessionElicitationResolvedEvent(encoded);
|
|
21649
|
-
case SESSION_FAILED_KIND:
|
|
21650
|
-
return decodeSessionFailedEvent(encoded);
|
|
21651
|
-
case SESSION_INFO_UPDATED_KIND:
|
|
21652
|
-
return decodeSessionInfoUpdatedEvent(encoded);
|
|
21653
|
-
case SESSION_PERMISSION_REQUESTED_KIND:
|
|
21654
|
-
return decodeSessionPermissionRequestedEvent(encoded);
|
|
21655
|
-
case SESSION_PERMISSION_RESOLVED_KIND:
|
|
21656
|
-
return decodeSessionPermissionResolvedEvent(encoded);
|
|
21657
|
-
case SESSION_READY_KIND:
|
|
21658
|
-
return decodeSessionReadyEvent(encoded);
|
|
21659
|
-
case SESSION_STARTED_KIND:
|
|
21660
|
-
return decodeSessionStartedEvent(encoded);
|
|
21661
|
-
case SESSION_USAGE_UPDATED_KIND:
|
|
21662
|
-
return decodeSessionUsageUpdatedEvent(encoded);
|
|
21663
|
-
default:
|
|
21664
|
-
throw new UnsupportedProtocolMessageKindError("daemon-to-service", kind);
|
|
21665
|
-
}
|
|
21666
|
-
}
|
|
21667
|
-
var encodeRecordedSessionEvent = (event) => JSON.stringify(decodeRecordedSessionEvent(JSON.stringify(event)));
|
|
21668
|
-
|
|
21669
21389
|
// ../protocol/src/session-live-history.ts
|
|
21670
21390
|
var SESSION_LIVE_HISTORY_V2_PAGE_LOAD_KIND = "session.live-history.v2.page.load";
|
|
21671
21391
|
var SESSION_LIVE_HISTORY_V2_PAGE_LOADED_KIND = "session.live-history.v2.page.loaded";
|
|
@@ -21687,7 +21407,7 @@ var sessionLiveHistoryV2PageLoadedSchema = external_exports.object({
|
|
|
21687
21407
|
requestId: identifierStringSchema,
|
|
21688
21408
|
sessionId: identifierStringSchema
|
|
21689
21409
|
}).readonly();
|
|
21690
|
-
function
|
|
21410
|
+
function decode6(schema, encoded) {
|
|
21691
21411
|
try {
|
|
21692
21412
|
const value = JSON.parse(encoded);
|
|
21693
21413
|
return schema.parse(value);
|
|
@@ -21695,8 +21415,8 @@ function decode7(schema, encoded) {
|
|
|
21695
21415
|
throw new ProtocolMessageError("Invalid live Session history message", { cause });
|
|
21696
21416
|
}
|
|
21697
21417
|
}
|
|
21698
|
-
var decodeSessionLiveHistoryV2PageLoad = (encoded) =>
|
|
21699
|
-
var decodeSessionLiveHistoryV2PageLoaded = (encoded) =>
|
|
21418
|
+
var decodeSessionLiveHistoryV2PageLoad = (encoded) => decode6(sessionLiveHistoryV2PageLoadSchema, encoded);
|
|
21419
|
+
var decodeSessionLiveHistoryV2PageLoaded = (encoded) => decode6(sessionLiveHistoryV2PageLoadedSchema, encoded);
|
|
21700
21420
|
var encodeSessionLiveHistoryV2PageLoad = (value) => JSON.stringify(sessionLiveHistoryV2PageLoadSchema.parse(value));
|
|
21701
21421
|
var encodeSessionLiveHistoryV2PageLoaded = (value) => JSON.stringify(sessionLiveHistoryV2PageLoadedSchema.parse(value));
|
|
21702
21422
|
|
|
@@ -21810,6 +21530,11 @@ function decodeServiceToDaemonMessage(encoded) {
|
|
|
21810
21530
|
return signature.decoder(encoded);
|
|
21811
21531
|
}
|
|
21812
21532
|
var daemonToServiceSignatures = {
|
|
21533
|
+
[SESSION_CONFIG_UPDATED_KIND]: defineMessageSignature(
|
|
21534
|
+
SESSION_CONFIG_UPDATED_KIND,
|
|
21535
|
+
encodeSessionConfigUpdatedEvent,
|
|
21536
|
+
decodeSessionConfigUpdatedEvent
|
|
21537
|
+
),
|
|
21813
21538
|
[AGENT_INSTALL_CANCELLED_KIND]: defineMessageSignature(
|
|
21814
21539
|
AGENT_INSTALL_CANCELLED_KIND,
|
|
21815
21540
|
encodeAgentInstallCancelledEvent,
|
|
@@ -21880,11 +21605,6 @@ var daemonToServiceSignatures = {
|
|
|
21880
21605
|
decodeRuntimeHeartbeatEvent
|
|
21881
21606
|
),
|
|
21882
21607
|
[RUNTIME_PONG_KIND]: defineMessageSignature(RUNTIME_PONG_KIND, encodeRuntimePongEvent, decodeRuntimePongEvent),
|
|
21883
|
-
[SESSION_EVENT_KIND]: defineMessageSignature(
|
|
21884
|
-
SESSION_EVENT_KIND,
|
|
21885
|
-
encodeSessionEventEnvelope,
|
|
21886
|
-
decodeSessionEventEnvelope
|
|
21887
|
-
),
|
|
21888
21608
|
[SESSION_EVENT_V2_KIND]: defineMessageSignature(
|
|
21889
21609
|
SESSION_EVENT_V2_KIND,
|
|
21890
21610
|
encodeSessionEventEnvelopeV2,
|
|
@@ -24625,14 +24345,6 @@ var CodexAcpAgent = class {
|
|
|
24625
24345
|
if (isCompactPrompt(context.params.prompt)) {
|
|
24626
24346
|
return await this.#compact(context.signal);
|
|
24627
24347
|
}
|
|
24628
|
-
const messageId = crypto.randomUUID();
|
|
24629
|
-
for (const content of context.params.prompt) {
|
|
24630
|
-
await this.#emit({
|
|
24631
|
-
content,
|
|
24632
|
-
messageId,
|
|
24633
|
-
sessionUpdate: "user_message_chunk"
|
|
24634
|
-
});
|
|
24635
|
-
}
|
|
24636
24348
|
return await this.#runTurn(promptInput(context.params.prompt), context.signal);
|
|
24637
24349
|
}).onRequest(
|
|
24638
24350
|
"_session/steering",
|
|
@@ -25118,10 +24830,6 @@ var CodexAcpAgent = class {
|
|
|
25118
24830
|
if (steering.length === 0) {
|
|
25119
24831
|
throw new AcpExecutionError("Codex received an empty steering request", {}, "invalid_request");
|
|
25120
24832
|
}
|
|
25121
|
-
const messageId = crypto.randomUUID();
|
|
25122
|
-
for (const block of steering) {
|
|
25123
|
-
await this.#emit({ content: block.content, messageId, sessionUpdate: "user_message_chunk" });
|
|
25124
|
-
}
|
|
25125
24833
|
const response = turnSteerResponseSchema.parse(
|
|
25126
24834
|
await this.#appServer.request(
|
|
25127
24835
|
"turn/steer",
|
|
@@ -26565,9 +26273,9 @@ function comparePrerelease(left, right) {
|
|
|
26565
26273
|
if (left.length === 0 || right.length === 0) {
|
|
26566
26274
|
return left.length === right.length ? 0 : left.length === 0 ? 1 : -1;
|
|
26567
26275
|
}
|
|
26568
|
-
for (let
|
|
26569
|
-
const leftPart = left[
|
|
26570
|
-
const rightPart = right[
|
|
26276
|
+
for (let index2 = 0; index2 < Math.max(left.length, right.length); index2 += 1) {
|
|
26277
|
+
const leftPart = left[index2];
|
|
26278
|
+
const rightPart = right[index2];
|
|
26571
26279
|
if (leftPart === void 0 || rightPart === void 0) {
|
|
26572
26280
|
return leftPart === rightPart ? 0 : leftPart === void 0 ? -1 : 1;
|
|
26573
26281
|
}
|
|
@@ -26592,8 +26300,8 @@ function compareAgentVersions(left, right) {
|
|
|
26592
26300
|
if (parsedLeft === null || parsedRight === null) {
|
|
26593
26301
|
return null;
|
|
26594
26302
|
}
|
|
26595
|
-
for (let
|
|
26596
|
-
const difference = (parsedLeft.core[
|
|
26303
|
+
for (let index2 = 0; index2 < Math.max(parsedLeft.core.length, parsedRight.core.length); index2 += 1) {
|
|
26304
|
+
const difference = (parsedLeft.core[index2] ?? 0) - (parsedRight.core[index2] ?? 0);
|
|
26597
26305
|
if (difference !== 0) {
|
|
26598
26306
|
return Math.sign(difference);
|
|
26599
26307
|
}
|
|
@@ -27080,7 +26788,7 @@ function createDaemonConfig(connection, agents = [], installableAgents = [], loc
|
|
|
27080
26788
|
}
|
|
27081
26789
|
|
|
27082
26790
|
// src/run-daemon.ts
|
|
27083
|
-
import { createHash as createHash7, randomUUID as
|
|
26791
|
+
import { createHash as createHash7, randomUUID as randomUUID9 } from "node:crypto";
|
|
27084
26792
|
import { join as join18 } from "node:path";
|
|
27085
26793
|
import { styleText } from "node:util";
|
|
27086
26794
|
|
|
@@ -27203,7 +26911,7 @@ function startsWith(bytes, signature, offset = 0) {
|
|
|
27203
26911
|
if (bytes.byteLength < offset + signature.byteLength) {
|
|
27204
26912
|
return false;
|
|
27205
26913
|
}
|
|
27206
|
-
return signature.every((value,
|
|
26914
|
+
return signature.every((value, index2) => bytes[offset + index2] === value);
|
|
27207
26915
|
}
|
|
27208
26916
|
function sniffRasterMime(bytes) {
|
|
27209
26917
|
if (startsWith(bytes, PNG_SIGNATURE)) {
|
|
@@ -27331,7 +27039,7 @@ function startsWith2(bytes, signature, offset = 0) {
|
|
|
27331
27039
|
if (bytes.byteLength < offset + signature.byteLength) {
|
|
27332
27040
|
return false;
|
|
27333
27041
|
}
|
|
27334
|
-
return signature.every((value,
|
|
27042
|
+
return signature.every((value, index2) => bytes[offset + index2] === value);
|
|
27335
27043
|
}
|
|
27336
27044
|
function sniffVideoMime(bytes) {
|
|
27337
27045
|
if (startsWith2(bytes, MP4_FILE_TYPE, 4)) {
|
|
@@ -27460,10 +27168,10 @@ async function replaceImageMarkers(text2, replace) {
|
|
|
27460
27168
|
let cursor = 0;
|
|
27461
27169
|
let rewritten = "";
|
|
27462
27170
|
for (const match of matches) {
|
|
27463
|
-
const
|
|
27464
|
-
rewritten += text2.slice(cursor,
|
|
27171
|
+
const index2 = match.index ?? 0;
|
|
27172
|
+
rewritten += text2.slice(cursor, index2);
|
|
27465
27173
|
rewritten += await replace(match[1] ?? "");
|
|
27466
|
-
cursor =
|
|
27174
|
+
cursor = index2 + match[0].length;
|
|
27467
27175
|
}
|
|
27468
27176
|
return `${rewritten}${text2.slice(cursor)}`;
|
|
27469
27177
|
}
|
|
@@ -28697,9 +28405,9 @@ function historyContentCharacters(messages) {
|
|
|
28697
28405
|
var AcpHistoryReplay = class {
|
|
28698
28406
|
#activities = /* @__PURE__ */ new Map();
|
|
28699
28407
|
#messages = [];
|
|
28700
|
-
#events
|
|
28701
|
-
#records = [];
|
|
28408
|
+
#events;
|
|
28702
28409
|
#turnActivityIds = /* @__PURE__ */ new Set();
|
|
28410
|
+
#sessionId;
|
|
28703
28411
|
#activityTracker = new AcpActivityTracker(
|
|
28704
28412
|
async (activity2) => {
|
|
28705
28413
|
this.#activities.set(activity2.activityId, activity2);
|
|
@@ -28720,10 +28428,16 @@ var AcpHistoryReplay = class {
|
|
|
28720
28428
|
#firstMessageIndex = 0;
|
|
28721
28429
|
#characters = 0;
|
|
28722
28430
|
#truncated = false;
|
|
28431
|
+
constructor(events, sessionId) {
|
|
28432
|
+
this.#events = events;
|
|
28433
|
+
this.#sessionId = sessionId;
|
|
28434
|
+
}
|
|
28723
28435
|
record = async (update, rawUpdate, onRecorded = () => Promise.resolve()) => {
|
|
28724
|
-
this.#
|
|
28725
|
-
|
|
28726
|
-
await
|
|
28436
|
+
const position = this.#events.append(this.#sessionId, { payload: rawUpdate, type: "acp" });
|
|
28437
|
+
await onRecorded(position);
|
|
28438
|
+
return await this.#applyUpdate(update, position);
|
|
28439
|
+
};
|
|
28440
|
+
#applyUpdate = async (update, position) => {
|
|
28727
28441
|
if (update.sessionUpdate === "agent_thought_chunk") {
|
|
28728
28442
|
if (update.content.type === "text") {
|
|
28729
28443
|
await this.#activityTracker.recordNarrative(
|
|
@@ -28732,30 +28446,30 @@ var AcpHistoryReplay = class {
|
|
|
28732
28446
|
update.content.text
|
|
28733
28447
|
);
|
|
28734
28448
|
}
|
|
28735
|
-
return
|
|
28449
|
+
return position;
|
|
28736
28450
|
}
|
|
28737
28451
|
if (update.sessionUpdate === "tool_call") {
|
|
28738
28452
|
await this.#activityTracker.recordToolCall(update);
|
|
28739
|
-
return
|
|
28453
|
+
return position;
|
|
28740
28454
|
}
|
|
28741
28455
|
if (update.sessionUpdate === "tool_call_update") {
|
|
28742
28456
|
await this.#activityTracker.recordToolCallUpdate(update);
|
|
28743
|
-
return
|
|
28457
|
+
return position;
|
|
28744
28458
|
}
|
|
28745
28459
|
if (update.sessionUpdate === "plan") {
|
|
28746
28460
|
await this.#activityTracker.recordPlan(update);
|
|
28747
|
-
return
|
|
28461
|
+
return position;
|
|
28748
28462
|
}
|
|
28749
28463
|
if (update.sessionUpdate === "plan_update") {
|
|
28750
28464
|
await this.#activityTracker.recordPlanUpdate(update);
|
|
28751
|
-
return
|
|
28465
|
+
return position;
|
|
28752
28466
|
}
|
|
28753
28467
|
if (update.sessionUpdate === "plan_removed") {
|
|
28754
28468
|
await this.#activityTracker.removePlan(update);
|
|
28755
|
-
return
|
|
28469
|
+
return position;
|
|
28756
28470
|
}
|
|
28757
28471
|
if (update.sessionUpdate !== "user_message_chunk" && update.sessionUpdate !== "agent_message_chunk") {
|
|
28758
|
-
return
|
|
28472
|
+
return position;
|
|
28759
28473
|
}
|
|
28760
28474
|
if (update.sessionUpdate === "agent_message_chunk" && isProgressMessage(update)) {
|
|
28761
28475
|
if (update.content.type === "text") {
|
|
@@ -28765,18 +28479,18 @@ var AcpHistoryReplay = class {
|
|
|
28765
28479
|
update.content.text
|
|
28766
28480
|
);
|
|
28767
28481
|
}
|
|
28768
|
-
return
|
|
28482
|
+
return position;
|
|
28769
28483
|
}
|
|
28770
28484
|
const role = update.sessionUpdate === "user_message_chunk" ? "user" : "assistant";
|
|
28771
28485
|
const content = update.content;
|
|
28772
28486
|
if (role === "assistant" && content.type !== "text") {
|
|
28773
28487
|
await this.#activityTracker.finishNarrative();
|
|
28774
28488
|
this.recordAssistantContent(update.messageId ?? null, normalizeContentBlock(content));
|
|
28775
|
-
return
|
|
28489
|
+
return position;
|
|
28776
28490
|
}
|
|
28777
28491
|
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]`;
|
|
28778
28492
|
if (text2.length === 0) {
|
|
28779
|
-
return
|
|
28493
|
+
return position;
|
|
28780
28494
|
}
|
|
28781
28495
|
const previous = this.#messages.at(-1);
|
|
28782
28496
|
const id = update.messageId ?? null;
|
|
@@ -28803,41 +28517,32 @@ var AcpHistoryReplay = class {
|
|
|
28803
28517
|
this.#characters += bounded2.length;
|
|
28804
28518
|
this.#lastMessageId = id;
|
|
28805
28519
|
this.trimMessages();
|
|
28806
|
-
return
|
|
28520
|
+
return position;
|
|
28807
28521
|
};
|
|
28808
28522
|
recordLifecycle = (event) => {
|
|
28809
28523
|
if (event.type !== "lifecycle-metadata") {
|
|
28810
28524
|
throw new Error("Lifecycle history only accepts lifecycle metadata");
|
|
28811
28525
|
}
|
|
28812
|
-
this.#
|
|
28813
|
-
this.#events.push(event);
|
|
28814
|
-
return this.#events.length;
|
|
28526
|
+
return this.#events.append(this.#sessionId, event);
|
|
28815
28527
|
};
|
|
28816
|
-
eventCount = () => this.#events.length;
|
|
28817
28528
|
append = async (replay) => {
|
|
28818
|
-
|
|
28819
|
-
|
|
28820
|
-
|
|
28821
|
-
} else {
|
|
28822
|
-
this.recordLifecycle(record2.event);
|
|
28823
|
-
}
|
|
28529
|
+
await replay.#activityTracker.finish();
|
|
28530
|
+
for (const [activityId, activity2] of replay.#activities) {
|
|
28531
|
+
this.#activities.set(activityId, activity2);
|
|
28824
28532
|
}
|
|
28825
|
-
|
|
28826
|
-
|
|
28827
|
-
|
|
28828
|
-
const parsedCursor = cursor === null ? events.length : Number(cursor);
|
|
28829
|
-
if (!Number.isSafeInteger(parsedCursor) || parsedCursor < 0 || parsedCursor > events.length) {
|
|
28830
|
-
throw new Error("The native event cursor is invalid");
|
|
28533
|
+
for (const message of replay.#messages.slice(replay.#firstMessageIndex)) {
|
|
28534
|
+
this.#messages.push(message);
|
|
28535
|
+
this.#characters += message.text.length;
|
|
28831
28536
|
}
|
|
28832
|
-
|
|
28833
|
-
|
|
28834
|
-
|
|
28835
|
-
|
|
28836
|
-
|
|
28837
|
-
|
|
28838
|
-
|
|
28839
|
-
};
|
|
28537
|
+
this.#turnActivityIds.clear();
|
|
28538
|
+
for (const activityId of replay.#turnActivityIds) {
|
|
28539
|
+
this.#turnActivityIds.add(activityId);
|
|
28540
|
+
}
|
|
28541
|
+
this.#lastMessageId = replay.#lastMessageId;
|
|
28542
|
+
this.#truncated ||= replay.#truncated;
|
|
28543
|
+
this.trimMessages();
|
|
28840
28544
|
};
|
|
28545
|
+
eventPage = (eventLimit, cursor) => this.#events.page(this.#sessionId, eventLimit, cursor);
|
|
28841
28546
|
snapshot = async () => {
|
|
28842
28547
|
await this.#activityTracker.finish();
|
|
28843
28548
|
const messages = this.#messages.slice(this.#firstMessageIndex).map((message) => {
|
|
@@ -29470,9 +29175,7 @@ var AcpSessionInteractions = class {
|
|
|
29470
29175
|
};
|
|
29471
29176
|
|
|
29472
29177
|
// src/acp/session-store.ts
|
|
29473
|
-
import {
|
|
29474
|
-
import { dirname as dirname3 } from "node:path";
|
|
29475
|
-
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
29178
|
+
import { randomUUID } from "node:crypto";
|
|
29476
29179
|
|
|
29477
29180
|
// ../../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
|
|
29478
29181
|
var entityKind = /* @__PURE__ */ Symbol.for("drizzle:entityKind");
|
|
@@ -30588,7 +30291,7 @@ function haveSameKeys(left, right) {
|
|
|
30588
30291
|
const leftKeys = Object.keys(left);
|
|
30589
30292
|
const rightKeys = Object.keys(right);
|
|
30590
30293
|
if (leftKeys.length !== rightKeys.length) return false;
|
|
30591
|
-
for (const [
|
|
30294
|
+
for (const [index2, key] of leftKeys.entries()) if (key !== rightKeys[index2]) return false;
|
|
30592
30295
|
return true;
|
|
30593
30296
|
}
|
|
30594
30297
|
function mapUpdateSet(table, values) {
|
|
@@ -31341,195 +31044,6 @@ var NoopLogger = class {
|
|
|
31341
31044
|
}
|
|
31342
31045
|
};
|
|
31343
31046
|
|
|
31344
|
-
// ../../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
|
|
31345
|
-
var SQLiteCountBuilder = class SQLiteCountBuilder2 extends SQL {
|
|
31346
|
-
static [entityKind] = "SQLiteCountBuilder";
|
|
31347
|
-
dialect;
|
|
31348
|
-
session;
|
|
31349
|
-
static buildCount(source, filters, parens) {
|
|
31350
|
-
const query = sql`select count(*) from ${source}${sql` where ${filters}`.if(filters)}`;
|
|
31351
|
-
return parens ? sql`(${query})` : query;
|
|
31352
|
-
}
|
|
31353
|
-
constructor(countConfig) {
|
|
31354
|
-
super(SQLiteCountBuilder2.buildCount(countConfig.source, countConfig.filters, true).queryChunks);
|
|
31355
|
-
this.countConfig = countConfig;
|
|
31356
|
-
this.dialect = countConfig.dialect;
|
|
31357
|
-
this.session = countConfig.session;
|
|
31358
|
-
this.mapWith((e) => {
|
|
31359
|
-
if (typeof e === "number") return e;
|
|
31360
|
-
return Number(e ?? 0);
|
|
31361
|
-
});
|
|
31362
|
-
}
|
|
31363
|
-
executableSql;
|
|
31364
|
-
build() {
|
|
31365
|
-
if (!this.executableSql) {
|
|
31366
|
-
const { source, filters } = this.countConfig;
|
|
31367
|
-
this.executableSql = SQLiteCountBuilder2.buildCount(source, filters);
|
|
31368
|
-
}
|
|
31369
|
-
return this.dialect.sqlToQuery(this.executableSql);
|
|
31370
|
-
}
|
|
31371
|
-
};
|
|
31372
|
-
|
|
31373
|
-
// ../../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
|
|
31374
|
-
var SQLiteAsyncCountBuilder = class extends SQLiteCountBuilder {
|
|
31375
|
-
static [entityKind] = "SQLiteAsyncCountBuilder";
|
|
31376
|
-
constructor(countConfig) {
|
|
31377
|
-
super(countConfig);
|
|
31378
|
-
}
|
|
31379
|
-
/** @internal */
|
|
31380
|
-
executeRaw(placeholderValues) {
|
|
31381
|
-
return this.session.prepareQuery(this.build(), "arrays", false, "all", (rows) => {
|
|
31382
|
-
const v = rows[0]?.[0];
|
|
31383
|
-
if (typeof v === "number") return v;
|
|
31384
|
-
return v ? Number(v) : 0;
|
|
31385
|
-
}).execute(placeholderValues);
|
|
31386
|
-
}
|
|
31387
|
-
async execute(placeholderValues) {
|
|
31388
|
-
return await this.executeRaw(placeholderValues);
|
|
31389
|
-
}
|
|
31390
|
-
};
|
|
31391
|
-
applyMixins(SQLiteAsyncCountBuilder, [QueryPromise]);
|
|
31392
|
-
var SQLiteSyncCountBuilder = class extends SQLiteAsyncCountBuilder {
|
|
31393
|
-
static [entityKind] = "SQLiteSyncCountBuilder";
|
|
31394
|
-
sync(placeholderValues) {
|
|
31395
|
-
return this.executeRaw(placeholderValues).sync();
|
|
31396
|
-
}
|
|
31397
|
-
};
|
|
31398
|
-
|
|
31399
|
-
// ../../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
|
|
31400
|
-
var RelationalQueryBuilder = class {
|
|
31401
|
-
static [entityKind] = "SQLiteRelationalQueryBuilderV2";
|
|
31402
|
-
constructor(mode, schema, table, tableConfig, dialect, session, forbidJsonb, builder = SQLiteRelationalQuery) {
|
|
31403
|
-
this.mode = mode;
|
|
31404
|
-
this.schema = schema;
|
|
31405
|
-
this.table = table;
|
|
31406
|
-
this.tableConfig = tableConfig;
|
|
31407
|
-
this.dialect = dialect;
|
|
31408
|
-
this.session = session;
|
|
31409
|
-
this.forbidJsonb = forbidJsonb;
|
|
31410
|
-
this.builder = builder;
|
|
31411
|
-
}
|
|
31412
|
-
findMany(config2) {
|
|
31413
|
-
return new this.builder(this.mode, this.schema, this.table, this.tableConfig, this.dialect, this.session, config2 ?? true, "many", this.forbidJsonb);
|
|
31414
|
-
}
|
|
31415
|
-
findFirst(config2) {
|
|
31416
|
-
return new this.builder(this.mode, this.schema, this.table, this.tableConfig, this.dialect, this.session, config2 ?? true, "first", this.forbidJsonb);
|
|
31417
|
-
}
|
|
31418
|
-
};
|
|
31419
|
-
var SQLiteRelationalQuery = class {
|
|
31420
|
-
static [entityKind] = "SQLiteRelationalQueryV2";
|
|
31421
|
-
/** @internal */
|
|
31422
|
-
mode;
|
|
31423
|
-
/** @internal */
|
|
31424
|
-
table;
|
|
31425
|
-
/** @internal */
|
|
31426
|
-
resultKind;
|
|
31427
|
-
constructor(resultKind, schema, table, tableConfig, dialect, session, config2, mode, forbidJsonb) {
|
|
31428
|
-
this.schema = schema;
|
|
31429
|
-
this.tableConfig = tableConfig;
|
|
31430
|
-
this.dialect = dialect;
|
|
31431
|
-
this.session = session;
|
|
31432
|
-
this.config = config2;
|
|
31433
|
-
this.forbidJsonb = forbidJsonb;
|
|
31434
|
-
this.resultKind = resultKind;
|
|
31435
|
-
this.mode = mode;
|
|
31436
|
-
this.table = table;
|
|
31437
|
-
}
|
|
31438
|
-
getSQL() {
|
|
31439
|
-
return this._getQuery().sql;
|
|
31440
|
-
}
|
|
31441
|
-
_getQuery() {
|
|
31442
|
-
const jsonb = this.forbidJsonb ? sql`json` : sql`jsonb`;
|
|
31443
|
-
return this.dialect.buildRelationalQuery({
|
|
31444
|
-
schema: this.schema,
|
|
31445
|
-
table: this.table,
|
|
31446
|
-
tableConfig: this.tableConfig,
|
|
31447
|
-
queryConfig: this.config,
|
|
31448
|
-
mode: this.mode,
|
|
31449
|
-
jsonb
|
|
31450
|
-
});
|
|
31451
|
-
}
|
|
31452
|
-
_toSQL() {
|
|
31453
|
-
const query = this._getQuery();
|
|
31454
|
-
return {
|
|
31455
|
-
query,
|
|
31456
|
-
builtQuery: this.dialect.sqlToQuery(query.sql)
|
|
31457
|
-
};
|
|
31458
|
-
}
|
|
31459
|
-
toSQL() {
|
|
31460
|
-
return this._toSQL().builtQuery;
|
|
31461
|
-
}
|
|
31462
|
-
};
|
|
31463
|
-
|
|
31464
|
-
// ../../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
|
|
31465
|
-
var SQLiteAsyncRelationalQuery = class extends SQLiteRelationalQuery {
|
|
31466
|
-
static [entityKind] = "SQLiteAsyncRelationalQueryV2";
|
|
31467
|
-
/** @internal */
|
|
31468
|
-
_prepare(prepare = false) {
|
|
31469
|
-
const { query, builtQuery } = this._toSQL();
|
|
31470
|
-
const mapper = this.dialect.mapperGenerators.relationalRows({
|
|
31471
|
-
isFirst: this.mode === "first",
|
|
31472
|
-
parseJson: true,
|
|
31473
|
-
parseJsonIfString: false,
|
|
31474
|
-
rootJsonMappers: false,
|
|
31475
|
-
selection: query.selection,
|
|
31476
|
-
arrayModeRoot: true
|
|
31477
|
-
});
|
|
31478
|
-
return this.session.prepareQuery(builtQuery, "arrays", prepare, "all", mapper);
|
|
31479
|
-
}
|
|
31480
|
-
prepare() {
|
|
31481
|
-
return this._prepare(true);
|
|
31482
|
-
}
|
|
31483
|
-
async execute(placeholderValues) {
|
|
31484
|
-
return this._prepare().execute(placeholderValues);
|
|
31485
|
-
}
|
|
31486
|
-
};
|
|
31487
|
-
var SQLiteSyncRelationalQuery = class extends SQLiteAsyncRelationalQuery {
|
|
31488
|
-
static [entityKind] = "SQLiteSyncRelationalQueryV2";
|
|
31489
|
-
sync(placeholderValues) {
|
|
31490
|
-
return this._prepare().execute(placeholderValues).sync();
|
|
31491
|
-
}
|
|
31492
|
-
};
|
|
31493
|
-
applyMixins(SQLiteAsyncRelationalQuery, [QueryPromise]);
|
|
31494
|
-
|
|
31495
|
-
// ../../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
|
|
31496
|
-
var SelectionProxyHandler = class SelectionProxyHandler2 {
|
|
31497
|
-
static [entityKind] = "SelectionProxyHandler";
|
|
31498
|
-
config;
|
|
31499
|
-
constructor(config2) {
|
|
31500
|
-
this.config = { ...config2 };
|
|
31501
|
-
}
|
|
31502
|
-
get(subquery, prop) {
|
|
31503
|
-
if (prop === "_") return {
|
|
31504
|
-
...subquery["_"],
|
|
31505
|
-
selectedFields: new Proxy(subquery._.selectedFields, this)
|
|
31506
|
-
};
|
|
31507
|
-
if (prop === ViewBaseConfig) return {
|
|
31508
|
-
...subquery[ViewBaseConfig],
|
|
31509
|
-
selectedFields: new Proxy(subquery[ViewBaseConfig].selectedFields, this)
|
|
31510
|
-
};
|
|
31511
|
-
if (typeof prop === "symbol") return subquery[prop];
|
|
31512
|
-
const value = (is(subquery, Subquery) ? subquery._.selectedFields : is(subquery, View) ? subquery[ViewBaseConfig].selectedFields : subquery)[prop];
|
|
31513
|
-
if (is(value, SQL.Aliased)) {
|
|
31514
|
-
if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) return value.sql;
|
|
31515
|
-
const newValue = value.clone();
|
|
31516
|
-
newValue.isSelectionField = true;
|
|
31517
|
-
newValue.origin = this.config.alias;
|
|
31518
|
-
return newValue;
|
|
31519
|
-
}
|
|
31520
|
-
if (is(value, SQL)) {
|
|
31521
|
-
if (this.config.sqlBehavior === "sql") return value;
|
|
31522
|
-
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.`);
|
|
31523
|
-
}
|
|
31524
|
-
if (is(value, Column)) {
|
|
31525
|
-
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));
|
|
31526
|
-
return value;
|
|
31527
|
-
}
|
|
31528
|
-
if (typeof value !== "object" || value === null) return value;
|
|
31529
|
-
return new Proxy(value, new SelectionProxyHandler2(this.config));
|
|
31530
|
-
}
|
|
31531
|
-
};
|
|
31532
|
-
|
|
31533
31047
|
// ../../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
|
|
31534
31048
|
var ForeignKeyBuilder = class {
|
|
31535
31049
|
static [entityKind] = "SQLiteForeignKeyBuilder";
|
|
@@ -32094,130 +31608,144 @@ function sqliteTableWithCasing(casing) {
|
|
|
32094
31608
|
}
|
|
32095
31609
|
var sqliteTable = sqliteTableWithCasing(void 0);
|
|
32096
31610
|
|
|
32097
|
-
// ../../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/
|
|
32098
|
-
|
|
32099
|
-
|
|
32100
|
-
|
|
32101
|
-
|
|
32102
|
-
|
|
32103
|
-
}
|
|
32104
|
-
|
|
32105
|
-
|
|
32106
|
-
|
|
32107
|
-
|
|
31611
|
+
// ../../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
|
|
31612
|
+
var IndexBuilderOn = class {
|
|
31613
|
+
static [entityKind] = "SQLiteIndexBuilderOn";
|
|
31614
|
+
constructor(name2, unique) {
|
|
31615
|
+
this.name = name2;
|
|
31616
|
+
this.unique = unique;
|
|
31617
|
+
}
|
|
31618
|
+
on(...columns) {
|
|
31619
|
+
return new IndexBuilder(this.name, columns, this.unique);
|
|
31620
|
+
}
|
|
31621
|
+
};
|
|
31622
|
+
var IndexBuilder = class {
|
|
31623
|
+
static [entityKind] = "SQLiteIndexBuilder";
|
|
32108
31624
|
/** @internal */
|
|
32109
31625
|
config;
|
|
32110
|
-
constructor(
|
|
32111
|
-
this.table = table;
|
|
32112
|
-
this.session = session;
|
|
32113
|
-
this.dialect = dialect;
|
|
31626
|
+
constructor(name2, columns, unique) {
|
|
32114
31627
|
this.config = {
|
|
32115
|
-
|
|
32116
|
-
|
|
31628
|
+
name: name2,
|
|
31629
|
+
columns,
|
|
31630
|
+
unique,
|
|
31631
|
+
where: void 0
|
|
32117
31632
|
};
|
|
32118
31633
|
}
|
|
32119
31634
|
/**
|
|
32120
|
-
*
|
|
32121
|
-
*
|
|
32122
|
-
* Calling this method will delete only those rows that fulfill a specified condition.
|
|
32123
|
-
*
|
|
32124
|
-
* See docs: {@link https://orm.drizzle.team/docs/delete}
|
|
32125
|
-
*
|
|
32126
|
-
* @param where the `where` clause.
|
|
32127
|
-
*
|
|
32128
|
-
* @example
|
|
32129
|
-
* You can use conditional operators and `sql function` to filter the rows to be deleted.
|
|
32130
|
-
*
|
|
32131
|
-
* ```ts
|
|
32132
|
-
* // Delete all cars with green color
|
|
32133
|
-
* db.delete(cars).where(eq(cars.color, 'green'));
|
|
32134
|
-
* // or
|
|
32135
|
-
* db.delete(cars).where(sql`${cars.color} = 'green'`)
|
|
32136
|
-
* ```
|
|
32137
|
-
*
|
|
32138
|
-
* You can logically combine conditional operators with `and()` and `or()` operators:
|
|
32139
|
-
*
|
|
32140
|
-
* ```ts
|
|
32141
|
-
* // Delete all BMW cars with a green color
|
|
32142
|
-
* db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
|
32143
|
-
*
|
|
32144
|
-
* // Delete all cars with the green or blue color
|
|
32145
|
-
* db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
32146
|
-
* ```
|
|
31635
|
+
* Condition for partial index.
|
|
32147
31636
|
*/
|
|
32148
|
-
where(
|
|
32149
|
-
this.config.where =
|
|
32150
|
-
return this;
|
|
32151
|
-
}
|
|
32152
|
-
orderBy(...columns) {
|
|
32153
|
-
if (typeof columns[0] === "function") {
|
|
32154
|
-
const orderBy = columns[0](new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
|
|
32155
|
-
sqlAliasedBehavior: "alias",
|
|
32156
|
-
sqlBehavior: "sql"
|
|
32157
|
-
})));
|
|
32158
|
-
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
32159
|
-
this.config.orderBy = orderByArray;
|
|
32160
|
-
} else {
|
|
32161
|
-
const orderByArray = columns;
|
|
32162
|
-
this.config.orderBy = orderByArray;
|
|
32163
|
-
}
|
|
32164
|
-
return this;
|
|
32165
|
-
}
|
|
32166
|
-
limit(limit) {
|
|
32167
|
-
this.config.limit = limit;
|
|
32168
|
-
return this;
|
|
32169
|
-
}
|
|
32170
|
-
returning(fields = this.table[SQLiteTable.Symbol.Columns]) {
|
|
32171
|
-
this.config.returning = orderSelectedFields(fields);
|
|
31637
|
+
where(condition) {
|
|
31638
|
+
this.config.where = condition;
|
|
32172
31639
|
return this;
|
|
32173
31640
|
}
|
|
32174
|
-
|
|
32175
|
-
|
|
32176
|
-
|
|
32177
|
-
toSQL() {
|
|
32178
|
-
return this.dialect.sqlToQuery(this.getSQL());
|
|
31641
|
+
/** @internal */
|
|
31642
|
+
build(table) {
|
|
31643
|
+
return new Index(this.config, table);
|
|
32179
31644
|
}
|
|
32180
|
-
|
|
32181
|
-
|
|
31645
|
+
};
|
|
31646
|
+
var Index = class {
|
|
31647
|
+
static [entityKind] = "SQLiteIndex";
|
|
31648
|
+
config;
|
|
31649
|
+
isNameExplicit;
|
|
31650
|
+
constructor(config2, table) {
|
|
31651
|
+
this.config = {
|
|
31652
|
+
...config2,
|
|
31653
|
+
table
|
|
31654
|
+
};
|
|
31655
|
+
this.isNameExplicit = !!config2.name;
|
|
32182
31656
|
}
|
|
32183
31657
|
};
|
|
31658
|
+
function index(name2) {
|
|
31659
|
+
return new IndexBuilderOn(name2, false);
|
|
31660
|
+
}
|
|
32184
31661
|
|
|
32185
|
-
// ../../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/
|
|
32186
|
-
|
|
32187
|
-
|
|
31662
|
+
// ../../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
|
|
31663
|
+
function primaryKey(...config2) {
|
|
31664
|
+
if (config2[0].columns) return new PrimaryKeyBuilder(config2[0].columns, config2[0].name);
|
|
31665
|
+
return new PrimaryKeyBuilder(config2);
|
|
31666
|
+
}
|
|
31667
|
+
var PrimaryKeyBuilder = class {
|
|
31668
|
+
static [entityKind] = "SQLitePrimaryKeyBuilder";
|
|
32188
31669
|
/** @internal */
|
|
32189
|
-
|
|
32190
|
-
|
|
32191
|
-
|
|
32192
|
-
|
|
32193
|
-
|
|
31670
|
+
columns;
|
|
31671
|
+
/** @internal */
|
|
31672
|
+
name;
|
|
31673
|
+
constructor(columns, name2) {
|
|
31674
|
+
this.columns = columns;
|
|
31675
|
+
this.name = name2;
|
|
32194
31676
|
}
|
|
32195
|
-
|
|
32196
|
-
|
|
31677
|
+
/** @internal */
|
|
31678
|
+
build(table) {
|
|
31679
|
+
return new PrimaryKey(table, this.columns, this.name);
|
|
32197
31680
|
}
|
|
32198
|
-
|
|
32199
|
-
|
|
32200
|
-
|
|
32201
|
-
|
|
32202
|
-
|
|
32203
|
-
|
|
32204
|
-
|
|
32205
|
-
|
|
32206
|
-
|
|
32207
|
-
|
|
32208
|
-
|
|
32209
|
-
}
|
|
32210
|
-
|
|
32211
|
-
return this.
|
|
31681
|
+
};
|
|
31682
|
+
var PrimaryKey = class {
|
|
31683
|
+
static [entityKind] = "SQLitePrimaryKey";
|
|
31684
|
+
columns;
|
|
31685
|
+
name;
|
|
31686
|
+
isNameExplicit;
|
|
31687
|
+
constructor(table, columns, name2) {
|
|
31688
|
+
this.table = table;
|
|
31689
|
+
this.columns = columns;
|
|
31690
|
+
this.name = name2;
|
|
31691
|
+
this.isNameExplicit = !!name2;
|
|
31692
|
+
}
|
|
31693
|
+
getName() {
|
|
31694
|
+
return this.name ?? `${this.table[SQLiteTable.Symbol.Name]}_${this.columns.map((column) => column.name).join("_")}_pk`;
|
|
32212
31695
|
}
|
|
32213
31696
|
};
|
|
32214
|
-
|
|
31697
|
+
|
|
31698
|
+
// ../../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
|
|
31699
|
+
function extractUsedTable(table) {
|
|
31700
|
+
if (is(table, SQLiteTable)) return [`${table[Table.Symbol.BaseName]}`];
|
|
31701
|
+
if (is(table, Subquery)) return table._.usedTables ?? [];
|
|
31702
|
+
if (is(table, SQL)) return table.usedTables ?? [];
|
|
31703
|
+
return [];
|
|
31704
|
+
}
|
|
32215
31705
|
|
|
32216
31706
|
// ../../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
|
|
32217
31707
|
var SQLiteViewBase = class extends View {
|
|
32218
31708
|
static [entityKind] = "SQLiteViewBase";
|
|
32219
31709
|
};
|
|
32220
31710
|
|
|
31711
|
+
// ../../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
|
|
31712
|
+
var SelectionProxyHandler = class SelectionProxyHandler2 {
|
|
31713
|
+
static [entityKind] = "SelectionProxyHandler";
|
|
31714
|
+
config;
|
|
31715
|
+
constructor(config2) {
|
|
31716
|
+
this.config = { ...config2 };
|
|
31717
|
+
}
|
|
31718
|
+
get(subquery, prop) {
|
|
31719
|
+
if (prop === "_") return {
|
|
31720
|
+
...subquery["_"],
|
|
31721
|
+
selectedFields: new Proxy(subquery._.selectedFields, this)
|
|
31722
|
+
};
|
|
31723
|
+
if (prop === ViewBaseConfig) return {
|
|
31724
|
+
...subquery[ViewBaseConfig],
|
|
31725
|
+
selectedFields: new Proxy(subquery[ViewBaseConfig].selectedFields, this)
|
|
31726
|
+
};
|
|
31727
|
+
if (typeof prop === "symbol") return subquery[prop];
|
|
31728
|
+
const value = (is(subquery, Subquery) ? subquery._.selectedFields : is(subquery, View) ? subquery[ViewBaseConfig].selectedFields : subquery)[prop];
|
|
31729
|
+
if (is(value, SQL.Aliased)) {
|
|
31730
|
+
if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) return value.sql;
|
|
31731
|
+
const newValue = value.clone();
|
|
31732
|
+
newValue.isSelectionField = true;
|
|
31733
|
+
newValue.origin = this.config.alias;
|
|
31734
|
+
return newValue;
|
|
31735
|
+
}
|
|
31736
|
+
if (is(value, SQL)) {
|
|
31737
|
+
if (this.config.sqlBehavior === "sql") return value;
|
|
31738
|
+
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.`);
|
|
31739
|
+
}
|
|
31740
|
+
if (is(value, Column)) {
|
|
31741
|
+
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));
|
|
31742
|
+
return value;
|
|
31743
|
+
}
|
|
31744
|
+
if (typeof value !== "object" || value === null) return value;
|
|
31745
|
+
return new Proxy(value, new SelectionProxyHandler2(this.config));
|
|
31746
|
+
}
|
|
31747
|
+
};
|
|
31748
|
+
|
|
32221
31749
|
// ../../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
|
|
32222
31750
|
var TypedQueryBuilder = class {
|
|
32223
31751
|
static [entityKind] = "TypedQueryBuilder";
|
|
@@ -32918,8 +32446,8 @@ var SQLiteDialect = class {
|
|
|
32918
32446
|
buildJoins(joins) {
|
|
32919
32447
|
if (!joins || joins.length === 0) return;
|
|
32920
32448
|
const joinsArray = [];
|
|
32921
|
-
if (joins) for (const [
|
|
32922
|
-
if (
|
|
32449
|
+
if (joins) for (const [index2, joinMeta] of joins.entries()) {
|
|
32450
|
+
if (index2 === 0) joinsArray.push(sql` `);
|
|
32923
32451
|
const table = joinMeta.table;
|
|
32924
32452
|
const onSql = joinMeta.on ? sql` on ${joinMeta.on}` : void 0;
|
|
32925
32453
|
if (is(table, SQLiteTable)) {
|
|
@@ -32929,7 +32457,7 @@ var SQLiteDialect = class {
|
|
|
32929
32457
|
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
|
32930
32458
|
joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`}${onSql}`);
|
|
32931
32459
|
} else joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join ${table}${onSql}`);
|
|
32932
|
-
if (
|
|
32460
|
+
if (index2 < joins.length - 1) joinsArray.push(sql` `);
|
|
32933
32461
|
}
|
|
32934
32462
|
return sql.join(joinsArray);
|
|
32935
32463
|
}
|
|
@@ -32938,9 +32466,9 @@ var SQLiteDialect = class {
|
|
|
32938
32466
|
}
|
|
32939
32467
|
buildOrderBy(orderBy) {
|
|
32940
32468
|
const orderByList = [];
|
|
32941
|
-
if (orderBy) for (const [
|
|
32469
|
+
if (orderBy) for (const [index2, orderByValue] of orderBy.entries()) {
|
|
32942
32470
|
orderByList.push(orderByValue);
|
|
32943
|
-
if (
|
|
32471
|
+
if (index2 < orderBy.length - 1) orderByList.push(sql`, `);
|
|
32944
32472
|
}
|
|
32945
32473
|
return orderByList.length > 0 ? sql` order by ${sql.join(orderByList)}` : void 0;
|
|
32946
32474
|
}
|
|
@@ -32968,9 +32496,9 @@ var SQLiteDialect = class {
|
|
|
32968
32496
|
const whereSql = where ? sql` where ${where}` : void 0;
|
|
32969
32497
|
const havingSql = having ? sql` having ${having}` : void 0;
|
|
32970
32498
|
const groupByList = [];
|
|
32971
|
-
if (groupBy) for (const [
|
|
32499
|
+
if (groupBy) for (const [index2, groupByValue] of groupBy.entries()) {
|
|
32972
32500
|
groupByList.push(groupByValue);
|
|
32973
|
-
if (
|
|
32501
|
+
if (index2 < groupBy.length - 1) groupByList.push(sql`, `);
|
|
32974
32502
|
}
|
|
32975
32503
|
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}`;
|
|
32976
32504
|
if (setOperators.length > 0) return this.buildSetOperations(finalQuery, setOperators);
|
|
@@ -33259,6 +32787,268 @@ var QueryBuilder = class {
|
|
|
33259
32787
|
}
|
|
33260
32788
|
};
|
|
33261
32789
|
|
|
32790
|
+
// ../../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
|
|
32791
|
+
var SQLiteCountBuilder = class SQLiteCountBuilder2 extends SQL {
|
|
32792
|
+
static [entityKind] = "SQLiteCountBuilder";
|
|
32793
|
+
dialect;
|
|
32794
|
+
session;
|
|
32795
|
+
static buildCount(source, filters, parens) {
|
|
32796
|
+
const query = sql`select count(*) from ${source}${sql` where ${filters}`.if(filters)}`;
|
|
32797
|
+
return parens ? sql`(${query})` : query;
|
|
32798
|
+
}
|
|
32799
|
+
constructor(countConfig) {
|
|
32800
|
+
super(SQLiteCountBuilder2.buildCount(countConfig.source, countConfig.filters, true).queryChunks);
|
|
32801
|
+
this.countConfig = countConfig;
|
|
32802
|
+
this.dialect = countConfig.dialect;
|
|
32803
|
+
this.session = countConfig.session;
|
|
32804
|
+
this.mapWith((e) => {
|
|
32805
|
+
if (typeof e === "number") return e;
|
|
32806
|
+
return Number(e ?? 0);
|
|
32807
|
+
});
|
|
32808
|
+
}
|
|
32809
|
+
executableSql;
|
|
32810
|
+
build() {
|
|
32811
|
+
if (!this.executableSql) {
|
|
32812
|
+
const { source, filters } = this.countConfig;
|
|
32813
|
+
this.executableSql = SQLiteCountBuilder2.buildCount(source, filters);
|
|
32814
|
+
}
|
|
32815
|
+
return this.dialect.sqlToQuery(this.executableSql);
|
|
32816
|
+
}
|
|
32817
|
+
};
|
|
32818
|
+
|
|
32819
|
+
// ../../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
|
|
32820
|
+
var SQLiteAsyncCountBuilder = class extends SQLiteCountBuilder {
|
|
32821
|
+
static [entityKind] = "SQLiteAsyncCountBuilder";
|
|
32822
|
+
constructor(countConfig) {
|
|
32823
|
+
super(countConfig);
|
|
32824
|
+
}
|
|
32825
|
+
/** @internal */
|
|
32826
|
+
executeRaw(placeholderValues) {
|
|
32827
|
+
return this.session.prepareQuery(this.build(), "arrays", false, "all", (rows) => {
|
|
32828
|
+
const v = rows[0]?.[0];
|
|
32829
|
+
if (typeof v === "number") return v;
|
|
32830
|
+
return v ? Number(v) : 0;
|
|
32831
|
+
}).execute(placeholderValues);
|
|
32832
|
+
}
|
|
32833
|
+
async execute(placeholderValues) {
|
|
32834
|
+
return await this.executeRaw(placeholderValues);
|
|
32835
|
+
}
|
|
32836
|
+
};
|
|
32837
|
+
applyMixins(SQLiteAsyncCountBuilder, [QueryPromise]);
|
|
32838
|
+
var SQLiteSyncCountBuilder = class extends SQLiteAsyncCountBuilder {
|
|
32839
|
+
static [entityKind] = "SQLiteSyncCountBuilder";
|
|
32840
|
+
sync(placeholderValues) {
|
|
32841
|
+
return this.executeRaw(placeholderValues).sync();
|
|
32842
|
+
}
|
|
32843
|
+
};
|
|
32844
|
+
|
|
32845
|
+
// ../../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
|
|
32846
|
+
var RelationalQueryBuilder = class {
|
|
32847
|
+
static [entityKind] = "SQLiteRelationalQueryBuilderV2";
|
|
32848
|
+
constructor(mode, schema, table, tableConfig, dialect, session, forbidJsonb, builder = SQLiteRelationalQuery) {
|
|
32849
|
+
this.mode = mode;
|
|
32850
|
+
this.schema = schema;
|
|
32851
|
+
this.table = table;
|
|
32852
|
+
this.tableConfig = tableConfig;
|
|
32853
|
+
this.dialect = dialect;
|
|
32854
|
+
this.session = session;
|
|
32855
|
+
this.forbidJsonb = forbidJsonb;
|
|
32856
|
+
this.builder = builder;
|
|
32857
|
+
}
|
|
32858
|
+
findMany(config2) {
|
|
32859
|
+
return new this.builder(this.mode, this.schema, this.table, this.tableConfig, this.dialect, this.session, config2 ?? true, "many", this.forbidJsonb);
|
|
32860
|
+
}
|
|
32861
|
+
findFirst(config2) {
|
|
32862
|
+
return new this.builder(this.mode, this.schema, this.table, this.tableConfig, this.dialect, this.session, config2 ?? true, "first", this.forbidJsonb);
|
|
32863
|
+
}
|
|
32864
|
+
};
|
|
32865
|
+
var SQLiteRelationalQuery = class {
|
|
32866
|
+
static [entityKind] = "SQLiteRelationalQueryV2";
|
|
32867
|
+
/** @internal */
|
|
32868
|
+
mode;
|
|
32869
|
+
/** @internal */
|
|
32870
|
+
table;
|
|
32871
|
+
/** @internal */
|
|
32872
|
+
resultKind;
|
|
32873
|
+
constructor(resultKind, schema, table, tableConfig, dialect, session, config2, mode, forbidJsonb) {
|
|
32874
|
+
this.schema = schema;
|
|
32875
|
+
this.tableConfig = tableConfig;
|
|
32876
|
+
this.dialect = dialect;
|
|
32877
|
+
this.session = session;
|
|
32878
|
+
this.config = config2;
|
|
32879
|
+
this.forbidJsonb = forbidJsonb;
|
|
32880
|
+
this.resultKind = resultKind;
|
|
32881
|
+
this.mode = mode;
|
|
32882
|
+
this.table = table;
|
|
32883
|
+
}
|
|
32884
|
+
getSQL() {
|
|
32885
|
+
return this._getQuery().sql;
|
|
32886
|
+
}
|
|
32887
|
+
_getQuery() {
|
|
32888
|
+
const jsonb = this.forbidJsonb ? sql`json` : sql`jsonb`;
|
|
32889
|
+
return this.dialect.buildRelationalQuery({
|
|
32890
|
+
schema: this.schema,
|
|
32891
|
+
table: this.table,
|
|
32892
|
+
tableConfig: this.tableConfig,
|
|
32893
|
+
queryConfig: this.config,
|
|
32894
|
+
mode: this.mode,
|
|
32895
|
+
jsonb
|
|
32896
|
+
});
|
|
32897
|
+
}
|
|
32898
|
+
_toSQL() {
|
|
32899
|
+
const query = this._getQuery();
|
|
32900
|
+
return {
|
|
32901
|
+
query,
|
|
32902
|
+
builtQuery: this.dialect.sqlToQuery(query.sql)
|
|
32903
|
+
};
|
|
32904
|
+
}
|
|
32905
|
+
toSQL() {
|
|
32906
|
+
return this._toSQL().builtQuery;
|
|
32907
|
+
}
|
|
32908
|
+
};
|
|
32909
|
+
|
|
32910
|
+
// ../../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
|
|
32911
|
+
var SQLiteAsyncRelationalQuery = class extends SQLiteRelationalQuery {
|
|
32912
|
+
static [entityKind] = "SQLiteAsyncRelationalQueryV2";
|
|
32913
|
+
/** @internal */
|
|
32914
|
+
_prepare(prepare = false) {
|
|
32915
|
+
const { query, builtQuery } = this._toSQL();
|
|
32916
|
+
const mapper = this.dialect.mapperGenerators.relationalRows({
|
|
32917
|
+
isFirst: this.mode === "first",
|
|
32918
|
+
parseJson: true,
|
|
32919
|
+
parseJsonIfString: false,
|
|
32920
|
+
rootJsonMappers: false,
|
|
32921
|
+
selection: query.selection,
|
|
32922
|
+
arrayModeRoot: true
|
|
32923
|
+
});
|
|
32924
|
+
return this.session.prepareQuery(builtQuery, "arrays", prepare, "all", mapper);
|
|
32925
|
+
}
|
|
32926
|
+
prepare() {
|
|
32927
|
+
return this._prepare(true);
|
|
32928
|
+
}
|
|
32929
|
+
async execute(placeholderValues) {
|
|
32930
|
+
return this._prepare().execute(placeholderValues);
|
|
32931
|
+
}
|
|
32932
|
+
};
|
|
32933
|
+
var SQLiteSyncRelationalQuery = class extends SQLiteAsyncRelationalQuery {
|
|
32934
|
+
static [entityKind] = "SQLiteSyncRelationalQueryV2";
|
|
32935
|
+
sync(placeholderValues) {
|
|
32936
|
+
return this._prepare().execute(placeholderValues).sync();
|
|
32937
|
+
}
|
|
32938
|
+
};
|
|
32939
|
+
applyMixins(SQLiteAsyncRelationalQuery, [QueryPromise]);
|
|
32940
|
+
|
|
32941
|
+
// ../../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
|
|
32942
|
+
var SQLiteDeleteBase = class {
|
|
32943
|
+
static [entityKind] = "SQLiteDelete";
|
|
32944
|
+
/** @internal */
|
|
32945
|
+
config;
|
|
32946
|
+
constructor(table, session, dialect, withList) {
|
|
32947
|
+
this.table = table;
|
|
32948
|
+
this.session = session;
|
|
32949
|
+
this.dialect = dialect;
|
|
32950
|
+
this.config = {
|
|
32951
|
+
table,
|
|
32952
|
+
withList
|
|
32953
|
+
};
|
|
32954
|
+
}
|
|
32955
|
+
/**
|
|
32956
|
+
* Adds a `where` clause to the query.
|
|
32957
|
+
*
|
|
32958
|
+
* Calling this method will delete only those rows that fulfill a specified condition.
|
|
32959
|
+
*
|
|
32960
|
+
* See docs: {@link https://orm.drizzle.team/docs/delete}
|
|
32961
|
+
*
|
|
32962
|
+
* @param where the `where` clause.
|
|
32963
|
+
*
|
|
32964
|
+
* @example
|
|
32965
|
+
* You can use conditional operators and `sql function` to filter the rows to be deleted.
|
|
32966
|
+
*
|
|
32967
|
+
* ```ts
|
|
32968
|
+
* // Delete all cars with green color
|
|
32969
|
+
* db.delete(cars).where(eq(cars.color, 'green'));
|
|
32970
|
+
* // or
|
|
32971
|
+
* db.delete(cars).where(sql`${cars.color} = 'green'`)
|
|
32972
|
+
* ```
|
|
32973
|
+
*
|
|
32974
|
+
* You can logically combine conditional operators with `and()` and `or()` operators:
|
|
32975
|
+
*
|
|
32976
|
+
* ```ts
|
|
32977
|
+
* // Delete all BMW cars with a green color
|
|
32978
|
+
* db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
|
32979
|
+
*
|
|
32980
|
+
* // Delete all cars with the green or blue color
|
|
32981
|
+
* db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
32982
|
+
* ```
|
|
32983
|
+
*/
|
|
32984
|
+
where(where) {
|
|
32985
|
+
this.config.where = where;
|
|
32986
|
+
return this;
|
|
32987
|
+
}
|
|
32988
|
+
orderBy(...columns) {
|
|
32989
|
+
if (typeof columns[0] === "function") {
|
|
32990
|
+
const orderBy = columns[0](new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
|
|
32991
|
+
sqlAliasedBehavior: "alias",
|
|
32992
|
+
sqlBehavior: "sql"
|
|
32993
|
+
})));
|
|
32994
|
+
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
32995
|
+
this.config.orderBy = orderByArray;
|
|
32996
|
+
} else {
|
|
32997
|
+
const orderByArray = columns;
|
|
32998
|
+
this.config.orderBy = orderByArray;
|
|
32999
|
+
}
|
|
33000
|
+
return this;
|
|
33001
|
+
}
|
|
33002
|
+
limit(limit) {
|
|
33003
|
+
this.config.limit = limit;
|
|
33004
|
+
return this;
|
|
33005
|
+
}
|
|
33006
|
+
returning(fields = this.table[SQLiteTable.Symbol.Columns]) {
|
|
33007
|
+
this.config.returning = orderSelectedFields(fields);
|
|
33008
|
+
return this;
|
|
33009
|
+
}
|
|
33010
|
+
getSQL() {
|
|
33011
|
+
return this.dialect.buildDeleteQuery(this.config);
|
|
33012
|
+
}
|
|
33013
|
+
toSQL() {
|
|
33014
|
+
return this.dialect.sqlToQuery(this.getSQL());
|
|
33015
|
+
}
|
|
33016
|
+
$dynamic() {
|
|
33017
|
+
return this;
|
|
33018
|
+
}
|
|
33019
|
+
};
|
|
33020
|
+
|
|
33021
|
+
// ../../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
|
|
33022
|
+
var SQLiteAsyncDeleteBase = class extends SQLiteDeleteBase {
|
|
33023
|
+
static [entityKind] = "SQLiteAsyncDelete";
|
|
33024
|
+
/** @internal */
|
|
33025
|
+
_prepare(prepare = false) {
|
|
33026
|
+
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, {
|
|
33027
|
+
type: "delete",
|
|
33028
|
+
tables: extractUsedTable(this.config.table)
|
|
33029
|
+
});
|
|
33030
|
+
}
|
|
33031
|
+
prepare() {
|
|
33032
|
+
return this._prepare(true);
|
|
33033
|
+
}
|
|
33034
|
+
run = (placeholderValues) => {
|
|
33035
|
+
return this._prepare().run(placeholderValues);
|
|
33036
|
+
};
|
|
33037
|
+
all = (placeholderValues) => {
|
|
33038
|
+
return this._prepare().all(placeholderValues);
|
|
33039
|
+
};
|
|
33040
|
+
get = (placeholderValues) => {
|
|
33041
|
+
return this._prepare().get(placeholderValues);
|
|
33042
|
+
};
|
|
33043
|
+
values = (placeholderValues) => {
|
|
33044
|
+
return this._prepare().values(placeholderValues);
|
|
33045
|
+
};
|
|
33046
|
+
async execute(placeholderValues) {
|
|
33047
|
+
return this._prepare().execute(placeholderValues);
|
|
33048
|
+
}
|
|
33049
|
+
};
|
|
33050
|
+
applyMixins(SQLiteAsyncDeleteBase, [QueryPromise]);
|
|
33051
|
+
|
|
33262
33052
|
// ../../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
|
|
33263
33053
|
var SQLiteInsertBuilder = class {
|
|
33264
33054
|
static [entityKind] = "SQLiteInsertBuilder";
|
|
@@ -34146,133 +33936,6 @@ var SQLiteAsyncTransaction = class extends SQLiteAsyncDatabase {
|
|
|
34146
33936
|
}
|
|
34147
33937
|
};
|
|
34148
33938
|
|
|
34149
|
-
// ../../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
|
|
34150
|
-
var NodeSQLiteSession = class extends SQLiteAsyncSession {
|
|
34151
|
-
static [entityKind] = "SQLJsSession";
|
|
34152
|
-
logger;
|
|
34153
|
-
constructor(client2, dialect, relations, options = {}) {
|
|
34154
|
-
super(dialect, "sync");
|
|
34155
|
-
this.client = client2;
|
|
34156
|
-
this.relations = relations;
|
|
34157
|
-
this.options = options;
|
|
34158
|
-
this.logger = options.logger ?? new NoopLogger();
|
|
34159
|
-
}
|
|
34160
|
-
prepareQuery(query, mode, _prepare, executeMethod, mapper, queryMetadata) {
|
|
34161
|
-
let stmt;
|
|
34162
|
-
try {
|
|
34163
|
-
stmt = this.client.prepare(query.sql);
|
|
34164
|
-
} catch (e) {
|
|
34165
|
-
throw new DrizzleQueryError(query.sql, query.params, e);
|
|
34166
|
-
}
|
|
34167
|
-
return new SQLiteAsyncPreparedQuery("sync", executeMethod, {
|
|
34168
|
-
all: (params) => {
|
|
34169
|
-
stmt.setReturnArrays(mode === "arrays");
|
|
34170
|
-
const res = stmt.all(...params);
|
|
34171
|
-
if (mode === "objects") return res.map((row) => ({ ...row }));
|
|
34172
|
-
return res;
|
|
34173
|
-
},
|
|
34174
|
-
get: (params) => {
|
|
34175
|
-
stmt.setReturnArrays(mode === "arrays");
|
|
34176
|
-
const res = stmt.get(...params);
|
|
34177
|
-
if (res && mode === "objects") return { ...res };
|
|
34178
|
-
return res;
|
|
34179
|
-
},
|
|
34180
|
-
run: (params) => {
|
|
34181
|
-
stmt.setReturnArrays(false);
|
|
34182
|
-
return stmt.run(...params);
|
|
34183
|
-
},
|
|
34184
|
-
values: (params) => {
|
|
34185
|
-
stmt.setReturnArrays(true);
|
|
34186
|
-
return stmt.all(...params);
|
|
34187
|
-
}
|
|
34188
|
-
}, query, mapper, mode, this.logger, void 0, queryMetadata, void 0);
|
|
34189
|
-
}
|
|
34190
|
-
transaction(transaction, config2 = {}) {
|
|
34191
|
-
const tx = new NodeSQLiteTransaction("sync", this.dialect, this, this.relations);
|
|
34192
|
-
this.run(sql.raw(`begin${config2.behavior ? ` ${config2.behavior}` : ""}`));
|
|
34193
|
-
try {
|
|
34194
|
-
const result = transaction(tx);
|
|
34195
|
-
this.run(sql`commit`);
|
|
34196
|
-
return result;
|
|
34197
|
-
} catch (err) {
|
|
34198
|
-
this.run(sql`rollback`);
|
|
34199
|
-
throw err;
|
|
34200
|
-
}
|
|
34201
|
-
}
|
|
34202
|
-
};
|
|
34203
|
-
var NodeSQLiteTransaction = class NodeSQLiteTransaction2 extends SQLiteAsyncTransaction {
|
|
34204
|
-
static [entityKind] = "SQLJsTransaction";
|
|
34205
|
-
transaction(transaction) {
|
|
34206
|
-
const savepointName = `sp${this.nestedIndex + 1}`;
|
|
34207
|
-
const tx = new NodeSQLiteTransaction2("sync", this.dialect, this.session, this._.relations, this.nestedIndex + 1);
|
|
34208
|
-
tx.run(sql.raw(`savepoint ${savepointName}`));
|
|
34209
|
-
try {
|
|
34210
|
-
const result = transaction(tx);
|
|
34211
|
-
tx.run(sql.raw(`release savepoint ${savepointName}`));
|
|
34212
|
-
return result;
|
|
34213
|
-
} catch (err) {
|
|
34214
|
-
tx.run(sql.raw(`rollback to savepoint ${savepointName}`));
|
|
34215
|
-
throw err;
|
|
34216
|
-
}
|
|
34217
|
-
}
|
|
34218
|
-
};
|
|
34219
|
-
|
|
34220
|
-
// ../../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
|
|
34221
|
-
import { DatabaseSync } from "node:sqlite";
|
|
34222
|
-
var NodeSQLiteDatabase = class extends SQLiteAsyncDatabase {
|
|
34223
|
-
static [entityKind] = "NodeSQLiteDatabase";
|
|
34224
|
-
};
|
|
34225
|
-
function construct(client2, config2 = {}) {
|
|
34226
|
-
const dialect = new SQLiteDialect({ useJitMappers: jitCompatCheck(config2.jit) });
|
|
34227
|
-
let logger;
|
|
34228
|
-
if (config2.logger === true) logger = new DefaultLogger();
|
|
34229
|
-
else if (config2.logger !== false) logger = config2.logger;
|
|
34230
|
-
const relations = config2.relations ?? {};
|
|
34231
|
-
const db = new NodeSQLiteDatabase("sync", dialect, new NodeSQLiteSession(client2, dialect, relations, { logger }), relations);
|
|
34232
|
-
db.$client = client2;
|
|
34233
|
-
return db;
|
|
34234
|
-
}
|
|
34235
|
-
function drizzle(...params) {
|
|
34236
|
-
if (params[0] === void 0 || typeof params[0] === "string") return construct(params[0] === void 0 ? new DatabaseSync(":memory:") : new DatabaseSync(params[0]), params[1]);
|
|
34237
|
-
const { connection, client: client2, ...config2 } = params[0];
|
|
34238
|
-
if (client2) return construct(client2, config2);
|
|
34239
|
-
if (typeof connection === "object") {
|
|
34240
|
-
const { path: path2, ...options } = connection;
|
|
34241
|
-
return construct(new DatabaseSync(path2 ?? ":memory:", options), config2);
|
|
34242
|
-
}
|
|
34243
|
-
return construct(new DatabaseSync(connection ?? ":memory:"), config2);
|
|
34244
|
-
}
|
|
34245
|
-
(function(_drizzle) {
|
|
34246
|
-
function mock(config2) {
|
|
34247
|
-
return construct({}, config2);
|
|
34248
|
-
}
|
|
34249
|
-
_drizzle.mock = mock;
|
|
34250
|
-
})(drizzle || (drizzle = {}));
|
|
34251
|
-
|
|
34252
|
-
// src/generated/acp-session-store-migrations.ts
|
|
34253
|
-
var acpSessionStoreMigrations = [
|
|
34254
|
-
{
|
|
34255
|
-
"name": "0000_slimy_captain_midlands.sql",
|
|
34256
|
-
"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"
|
|
34257
|
-
},
|
|
34258
|
-
{
|
|
34259
|
-
"name": "0001_regular_ultimates.sql",
|
|
34260
|
-
"sql": "ALTER TABLE `acp_session` ADD `last_terminal_command_id` text;"
|
|
34261
|
-
},
|
|
34262
|
-
{
|
|
34263
|
-
"name": "0002_equal_black_queen.sql",
|
|
34264
|
-
"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`);"
|
|
34265
|
-
},
|
|
34266
|
-
{
|
|
34267
|
-
"name": "0003_silky_ravenous.sql",
|
|
34268
|
-
"sql": "DROP TABLE `session_event_v2`;"
|
|
34269
|
-
},
|
|
34270
|
-
{
|
|
34271
|
-
"name": "0004_special_mathemanic.sql",
|
|
34272
|
-
"sql": "DROP TABLE `deleted_acp_session`;--> statement-breakpoint\nALTER TABLE `acp_session` DROP COLUMN `last_terminal_command_id`;"
|
|
34273
|
-
}
|
|
34274
|
-
];
|
|
34275
|
-
|
|
34276
33939
|
// src/schema/acp-session-store/acp-session.ts
|
|
34277
33940
|
var acpSession = sqliteTable("acp_session", {
|
|
34278
33941
|
sessionId: text("session_id").primaryKey(),
|
|
@@ -34285,6 +33948,216 @@ var acpSession = sqliteTable("acp_session", {
|
|
|
34285
33948
|
updatedAt: text("updated_at").notNull()
|
|
34286
33949
|
});
|
|
34287
33950
|
|
|
33951
|
+
// src/schema/session-event-cache/session-event-v2.ts
|
|
33952
|
+
var sessionEventV2 = sqliteTable(
|
|
33953
|
+
"session_event_v2",
|
|
33954
|
+
{
|
|
33955
|
+
eventJson: text("event_json").notNull(),
|
|
33956
|
+
generationId: text("generation_id").notNull(),
|
|
33957
|
+
position: integer2("position").notNull(),
|
|
33958
|
+
sessionId: text("session_id").notNull()
|
|
33959
|
+
},
|
|
33960
|
+
(table) => [
|
|
33961
|
+
primaryKey({ columns: [table.generationId, table.sessionId, table.position] }),
|
|
33962
|
+
index("session_event_v2_generation_session_position_index").on(
|
|
33963
|
+
table.generationId,
|
|
33964
|
+
table.sessionId,
|
|
33965
|
+
table.position
|
|
33966
|
+
)
|
|
33967
|
+
]
|
|
33968
|
+
);
|
|
33969
|
+
|
|
33970
|
+
// src/acp/session-event-store-v2.ts
|
|
33971
|
+
var HOT_EVENT_HIGH_WATER_MARK = 256;
|
|
33972
|
+
var HOT_EVENT_RETENTION = 128;
|
|
33973
|
+
function eventPage(eventCount, eventLimit, cursor, read) {
|
|
33974
|
+
const parsedCursor = cursor === null ? eventCount : Number(cursor);
|
|
33975
|
+
if (!Number.isSafeInteger(parsedCursor) || parsedCursor < 0 || parsedCursor > eventCount) {
|
|
33976
|
+
throw new Error("The native event cursor is invalid");
|
|
33977
|
+
}
|
|
33978
|
+
const endPosition = parsedCursor;
|
|
33979
|
+
const startPosition = Math.max(0, endPosition - eventLimit);
|
|
33980
|
+
return {
|
|
33981
|
+
events: read(startPosition + 1, endPosition),
|
|
33982
|
+
nextCursor: startPosition === 0 ? null : startPosition.toString(),
|
|
33983
|
+
startPosition: startPosition + 1,
|
|
33984
|
+
truncated: startPosition > 0
|
|
33985
|
+
};
|
|
33986
|
+
}
|
|
33987
|
+
var MemoryAcpSessionEventStoreV2 = class {
|
|
33988
|
+
generationId;
|
|
33989
|
+
#events = /* @__PURE__ */ new Map();
|
|
33990
|
+
constructor(generationId) {
|
|
33991
|
+
this.generationId = generationId;
|
|
33992
|
+
}
|
|
33993
|
+
append = (sessionId, event) => {
|
|
33994
|
+
const events = this.#events.get(sessionId) ?? [];
|
|
33995
|
+
events.push(event);
|
|
33996
|
+
this.#events.set(sessionId, events);
|
|
33997
|
+
return events.length;
|
|
33998
|
+
};
|
|
33999
|
+
close = () => this.#events.clear();
|
|
34000
|
+
page = (sessionId, eventLimit, cursor) => {
|
|
34001
|
+
const events = this.#events.get(sessionId) ?? [];
|
|
34002
|
+
return eventPage(
|
|
34003
|
+
events.length,
|
|
34004
|
+
eventLimit,
|
|
34005
|
+
cursor,
|
|
34006
|
+
(startPosition, endPosition) => events.slice(startPosition - 1, endPosition)
|
|
34007
|
+
);
|
|
34008
|
+
};
|
|
34009
|
+
remove = (sessionId) => {
|
|
34010
|
+
this.#events.delete(sessionId);
|
|
34011
|
+
};
|
|
34012
|
+
reset = this.remove;
|
|
34013
|
+
};
|
|
34014
|
+
var cachedEventRowSchema = external_exports.object({ eventJson: external_exports.string(), position: external_exports.number().int().positive() });
|
|
34015
|
+
function decodeCachedEvent(value) {
|
|
34016
|
+
const payload = external_exports.record(external_exports.string(), external_exports.unknown()).parse(value);
|
|
34017
|
+
const event = decodeSessionEventV2({
|
|
34018
|
+
...payload,
|
|
34019
|
+
eventId: "cached-event",
|
|
34020
|
+
position: "1",
|
|
34021
|
+
provenance: { kind: "original" },
|
|
34022
|
+
recordedAt: "1970-01-01T00:00:00.000Z",
|
|
34023
|
+
sessionId: "cached-session"
|
|
34024
|
+
});
|
|
34025
|
+
return event.type === "acp" ? { payload: event.payload, type: event.type } : { payload: event.payload, type: event.type };
|
|
34026
|
+
}
|
|
34027
|
+
var CachedAcpSessionEventStoreV2 = class {
|
|
34028
|
+
generationId;
|
|
34029
|
+
#database;
|
|
34030
|
+
#ignoredPersistedSessions = /* @__PURE__ */ new Set();
|
|
34031
|
+
#localDatabase;
|
|
34032
|
+
#sessions = /* @__PURE__ */ new Map();
|
|
34033
|
+
#flushSchedule = { kind: "idle" };
|
|
34034
|
+
#isLocalDBAvailable = true;
|
|
34035
|
+
constructor(localDatabase, generationId) {
|
|
34036
|
+
this.generationId = generationId;
|
|
34037
|
+
this.#localDatabase = localDatabase;
|
|
34038
|
+
this.#database = localDatabase.orm;
|
|
34039
|
+
try {
|
|
34040
|
+
this.#localDatabase.transaction(() => this.#database.delete(sessionEventV2).run());
|
|
34041
|
+
} catch (error62) {
|
|
34042
|
+
this.#localDatabase.close();
|
|
34043
|
+
throw error62;
|
|
34044
|
+
}
|
|
34045
|
+
}
|
|
34046
|
+
append = (sessionId, event) => {
|
|
34047
|
+
if (this.#flushSchedule.kind === "closed") {
|
|
34048
|
+
throw new Error("The V2 Session event store is closed");
|
|
34049
|
+
}
|
|
34050
|
+
const session = this.#sessions.get(sessionId) ?? { hot: [], nextPosition: 1 };
|
|
34051
|
+
const position = session.nextPosition;
|
|
34052
|
+
session.hot.push({ event, position });
|
|
34053
|
+
session.nextPosition += 1;
|
|
34054
|
+
this.#sessions.set(sessionId, session);
|
|
34055
|
+
if (session.hot.length > HOT_EVENT_HIGH_WATER_MARK) {
|
|
34056
|
+
this.#scheduleFlush();
|
|
34057
|
+
}
|
|
34058
|
+
return position;
|
|
34059
|
+
};
|
|
34060
|
+
#scheduleFlush = () => {
|
|
34061
|
+
if (!this.#isLocalDBAvailable || this.#flushSchedule.kind !== "idle") {
|
|
34062
|
+
return;
|
|
34063
|
+
}
|
|
34064
|
+
const handle = setImmediate(() => {
|
|
34065
|
+
if (this.#flushSchedule.kind !== "scheduled" || this.#flushSchedule.handle !== handle) {
|
|
34066
|
+
return;
|
|
34067
|
+
}
|
|
34068
|
+
this.#flushSchedule = { kind: "idle" };
|
|
34069
|
+
this.#flush(false);
|
|
34070
|
+
});
|
|
34071
|
+
this.#flushSchedule = { handle, kind: "scheduled" };
|
|
34072
|
+
};
|
|
34073
|
+
#flush = (includeHotTail) => {
|
|
34074
|
+
if (!this.#isLocalDBAvailable || this.#flushSchedule.kind === "closed") {
|
|
34075
|
+
return;
|
|
34076
|
+
}
|
|
34077
|
+
const batches = [...this.#sessions.entries()].flatMap(([sessionId, session]) => {
|
|
34078
|
+
const count = includeHotTail ? session.hot.length : Math.max(0, session.hot.length - HOT_EVENT_RETENTION);
|
|
34079
|
+
return count === 0 ? [] : [{ count, events: session.hot.slice(0, count), sessionId }];
|
|
34080
|
+
});
|
|
34081
|
+
const values = batches.flatMap(
|
|
34082
|
+
(batch) => batch.events.map(({ event, position }) => ({
|
|
34083
|
+
eventJson: JSON.stringify(event),
|
|
34084
|
+
generationId: this.generationId,
|
|
34085
|
+
position,
|
|
34086
|
+
sessionId: batch.sessionId
|
|
34087
|
+
}))
|
|
34088
|
+
);
|
|
34089
|
+
if (values.length === 0) {
|
|
34090
|
+
return;
|
|
34091
|
+
}
|
|
34092
|
+
try {
|
|
34093
|
+
this.#localDatabase.transaction(() => {
|
|
34094
|
+
for (let offset = 0; offset < values.length; offset += 200) {
|
|
34095
|
+
this.#database.insert(sessionEventV2).values(values.slice(offset, offset + 200)).run();
|
|
34096
|
+
}
|
|
34097
|
+
});
|
|
34098
|
+
for (const batch of batches) {
|
|
34099
|
+
this.#sessions.get(batch.sessionId)?.hot.splice(0, batch.count);
|
|
34100
|
+
}
|
|
34101
|
+
} catch (cause) {
|
|
34102
|
+
this.#isLocalDBAvailable = false;
|
|
34103
|
+
console.warn("Mobius V2 Session event cache writes are unavailable; retaining events in memory", cause);
|
|
34104
|
+
}
|
|
34105
|
+
};
|
|
34106
|
+
page = (sessionId, eventLimit, cursor) => {
|
|
34107
|
+
const session = this.#sessions.get(sessionId);
|
|
34108
|
+
const eventCount = (session?.nextPosition ?? 1) - 1;
|
|
34109
|
+
return eventPage(eventCount, eventLimit, cursor, (startPosition, endPosition) => {
|
|
34110
|
+
const persisted = this.#ignoredPersistedSessions.has(sessionId) ? [] : this.#database.select({ eventJson: sessionEventV2.eventJson, position: sessionEventV2.position }).from(sessionEventV2).where(
|
|
34111
|
+
and(
|
|
34112
|
+
eq(sessionEventV2.generationId, this.generationId),
|
|
34113
|
+
eq(sessionEventV2.sessionId, sessionId),
|
|
34114
|
+
gte(sessionEventV2.position, startPosition),
|
|
34115
|
+
lte(sessionEventV2.position, endPosition)
|
|
34116
|
+
)
|
|
34117
|
+
).orderBy(asc(sessionEventV2.position)).all().map((value) => {
|
|
34118
|
+
const row = cachedEventRowSchema.parse(value);
|
|
34119
|
+
return { event: decodeCachedEvent(JSON.parse(row.eventJson)), position: row.position };
|
|
34120
|
+
});
|
|
34121
|
+
const hot = (session?.hot ?? []).filter(
|
|
34122
|
+
({ position }) => position >= startPosition && position <= endPosition
|
|
34123
|
+
);
|
|
34124
|
+
return [...persisted, ...hot].toSorted((left, right) => left.position - right.position).map(({ event }) => event);
|
|
34125
|
+
});
|
|
34126
|
+
};
|
|
34127
|
+
#deletePersisted = (sessionId) => {
|
|
34128
|
+
if (!this.#isLocalDBAvailable) {
|
|
34129
|
+
this.#ignoredPersistedSessions.add(sessionId);
|
|
34130
|
+
return;
|
|
34131
|
+
}
|
|
34132
|
+
try {
|
|
34133
|
+
this.#database.delete(sessionEventV2).where(and(eq(sessionEventV2.generationId, this.generationId), eq(sessionEventV2.sessionId, sessionId))).run();
|
|
34134
|
+
this.#ignoredPersistedSessions.delete(sessionId);
|
|
34135
|
+
} catch (cause) {
|
|
34136
|
+
this.#isLocalDBAvailable = false;
|
|
34137
|
+
this.#ignoredPersistedSessions.add(sessionId);
|
|
34138
|
+
console.warn("Mobius V2 Session event cache writes are unavailable; retaining events in memory", cause);
|
|
34139
|
+
}
|
|
34140
|
+
};
|
|
34141
|
+
remove = (sessionId) => {
|
|
34142
|
+
this.#deletePersisted(sessionId);
|
|
34143
|
+
this.#sessions.delete(sessionId);
|
|
34144
|
+
};
|
|
34145
|
+
reset = this.remove;
|
|
34146
|
+
close = () => {
|
|
34147
|
+
if (this.#flushSchedule.kind === "closed") {
|
|
34148
|
+
return;
|
|
34149
|
+
}
|
|
34150
|
+
if (this.#flushSchedule.kind === "scheduled") {
|
|
34151
|
+
clearImmediate(this.#flushSchedule.handle);
|
|
34152
|
+
}
|
|
34153
|
+
this.#flushSchedule = { kind: "idle" };
|
|
34154
|
+
this.#flush(true);
|
|
34155
|
+
this.#flushSchedule = { kind: "closed" };
|
|
34156
|
+
this.#localDatabase.close();
|
|
34157
|
+
this.#sessions.clear();
|
|
34158
|
+
};
|
|
34159
|
+
};
|
|
34160
|
+
|
|
34288
34161
|
// src/acp/session-store.ts
|
|
34289
34162
|
var AcpStoredSession = class {
|
|
34290
34163
|
additionalDirectories;
|
|
@@ -34320,9 +34193,14 @@ var FoundAcpStoredSession = class extends AcpStoredSessionLookup {
|
|
|
34320
34193
|
}
|
|
34321
34194
|
};
|
|
34322
34195
|
var MemoryAcpSessionStore = class {
|
|
34196
|
+
eventsV2;
|
|
34323
34197
|
#sessions = /* @__PURE__ */ new Map();
|
|
34198
|
+
constructor(eventsV2 = new MemoryAcpSessionEventStoreV2(randomUUID())) {
|
|
34199
|
+
this.eventsV2 = eventsV2;
|
|
34200
|
+
}
|
|
34324
34201
|
close = () => {
|
|
34325
34202
|
this.#sessions.clear();
|
|
34203
|
+
this.eventsV2.close();
|
|
34326
34204
|
};
|
|
34327
34205
|
findNative = (agentId, nativeSessionId) => [...this.#sessions.values()].filter(
|
|
34328
34206
|
(session) => session.agentId === agentId && session.nativeSessionId === nativeSessionId
|
|
@@ -34334,6 +34212,7 @@ var MemoryAcpSessionStore = class {
|
|
|
34334
34212
|
};
|
|
34335
34213
|
remove = (sessionId) => {
|
|
34336
34214
|
this.#sessions.delete(sessionId);
|
|
34215
|
+
this.eventsV2.remove(sessionId);
|
|
34337
34216
|
};
|
|
34338
34217
|
write = (session) => {
|
|
34339
34218
|
this.#sessions.set(session.sessionId, session);
|
|
@@ -34365,39 +34244,20 @@ function decodeStoredSession(value) {
|
|
|
34365
34244
|
);
|
|
34366
34245
|
}
|
|
34367
34246
|
var SqliteAcpSessionStore = class {
|
|
34247
|
+
eventsV2;
|
|
34368
34248
|
#database;
|
|
34369
|
-
#
|
|
34370
|
-
constructor(
|
|
34371
|
-
|
|
34372
|
-
this.#
|
|
34373
|
-
|
|
34374
|
-
this.#migrate();
|
|
34375
|
-
this.#database = drizzle({ client: this.#sqliteDatabase });
|
|
34249
|
+
#localDatabase;
|
|
34250
|
+
constructor(localDatabase, eventsV2 = new MemoryAcpSessionEventStoreV2(randomUUID())) {
|
|
34251
|
+
this.eventsV2 = eventsV2;
|
|
34252
|
+
this.#localDatabase = localDatabase;
|
|
34253
|
+
this.#database = localDatabase.orm;
|
|
34376
34254
|
}
|
|
34377
|
-
#migrate = () => {
|
|
34378
|
-
const version2 = external_exports.object({ user_version: external_exports.number().int().nonnegative() }).parse(this.#sqliteDatabase.prepare("PRAGMA user_version").get()).user_version;
|
|
34379
|
-
if (version2 > acpSessionStoreMigrations.length) {
|
|
34380
|
-
this.#sqliteDatabase.close();
|
|
34381
|
-
throw new Error("The ACP Session database was created by a newer Mobius version");
|
|
34382
|
-
}
|
|
34383
|
-
for (let index = version2; index < acpSessionStoreMigrations.length; index += 1) {
|
|
34384
|
-
const migration = acpSessionStoreMigrations[index];
|
|
34385
|
-
if (migration === void 0) {
|
|
34386
|
-
throw new Error("The ACP Session migration is unavailable");
|
|
34387
|
-
}
|
|
34388
|
-
this.#sqliteDatabase.exec("BEGIN IMMEDIATE");
|
|
34389
|
-
try {
|
|
34390
|
-
this.#sqliteDatabase.exec(migration.sql);
|
|
34391
|
-
this.#sqliteDatabase.exec(`PRAGMA user_version = ${index + 1}`);
|
|
34392
|
-
this.#sqliteDatabase.exec("COMMIT");
|
|
34393
|
-
} catch (error62) {
|
|
34394
|
-
this.#sqliteDatabase.exec("ROLLBACK");
|
|
34395
|
-
throw error62;
|
|
34396
|
-
}
|
|
34397
|
-
}
|
|
34398
|
-
};
|
|
34399
34255
|
close = () => {
|
|
34400
|
-
|
|
34256
|
+
try {
|
|
34257
|
+
this.#localDatabase.close();
|
|
34258
|
+
} finally {
|
|
34259
|
+
this.eventsV2.close();
|
|
34260
|
+
}
|
|
34401
34261
|
};
|
|
34402
34262
|
findNative = (agentId, nativeSessionId) => this.#database.select().from(acpSession).where(and(eq(acpSession.agentId, agentId), eq(acpSession.nativeSessionId, nativeSessionId))).all().map(decodeStoredSession);
|
|
34403
34263
|
list = () => this.#database.select().from(acpSession).orderBy(desc(acpSession.updatedAt)).all().map(decodeStoredSession);
|
|
@@ -34407,6 +34267,7 @@ var SqliteAcpSessionStore = class {
|
|
|
34407
34267
|
};
|
|
34408
34268
|
remove = (sessionId) => {
|
|
34409
34269
|
this.#database.delete(acpSession).where(eq(acpSession.sessionId, sessionId)).run();
|
|
34270
|
+
this.eventsV2.remove(sessionId);
|
|
34410
34271
|
};
|
|
34411
34272
|
write = (session) => {
|
|
34412
34273
|
const value = {
|
|
@@ -34432,7 +34293,7 @@ var RetryableAcpInitializationError = class extends AcpExecutionError {
|
|
|
34432
34293
|
}
|
|
34433
34294
|
};
|
|
34434
34295
|
function arraysEqual(left, right) {
|
|
34435
|
-
return left.length === right.length && left.every((value,
|
|
34296
|
+
return left.length === right.length && left.every((value, index2) => value === right[index2]);
|
|
34436
34297
|
}
|
|
34437
34298
|
function recordsEqual(left, right) {
|
|
34438
34299
|
const leftEntries = Object.entries(left);
|
|
@@ -34487,7 +34348,7 @@ var AgentSession = class _AgentSession {
|
|
|
34487
34348
|
commandId: () => this.#turn.commandId,
|
|
34488
34349
|
assertNativeSession: (sessionId) => this.assertNativeSession(sessionId),
|
|
34489
34350
|
observer: getObserver,
|
|
34490
|
-
recordSessionEventV2: this
|
|
34351
|
+
recordSessionEventV2: this.recordLifecycleEventV2
|
|
34491
34352
|
});
|
|
34492
34353
|
this.#connection = new AgentConnection(agent, cwd, this);
|
|
34493
34354
|
this.#contentExternalizer = contentExternalizer;
|
|
@@ -34595,12 +34456,17 @@ var AgentSession = class _AgentSession {
|
|
|
34595
34456
|
);
|
|
34596
34457
|
}
|
|
34597
34458
|
const history = await this.#completedHistory(signal, "ACP agent exited while loading history");
|
|
34598
|
-
return history.eventPage(eventLimit, cursor
|
|
34459
|
+
return history.eventPage(eventLimit, cursor);
|
|
34599
34460
|
};
|
|
34600
34461
|
async #completedHistory(signal, exitMessage) {
|
|
34601
34462
|
if (!this.#prompted && this.#nativeHistoryOwnership.kind === "fresh-session") {
|
|
34602
34463
|
if (this.#sessionLoad.kind === "not-requested") {
|
|
34603
|
-
this.#
|
|
34464
|
+
this.#store.eventsV2.reset(this.#mobiusSessionId);
|
|
34465
|
+
this.#sessionLoad = {
|
|
34466
|
+
history: new AcpHistoryReplay(this.#store.eventsV2, this.#mobiusSessionId),
|
|
34467
|
+
kind: "loaded",
|
|
34468
|
+
response: {}
|
|
34469
|
+
};
|
|
34604
34470
|
}
|
|
34605
34471
|
if (this.#sessionLoad.kind === "loaded") {
|
|
34606
34472
|
return this.#sessionLoad.history;
|
|
@@ -34615,7 +34481,8 @@ var AgentSession = class _AgentSession {
|
|
|
34615
34481
|
if (this.#sessionLoad.kind === "capturing") {
|
|
34616
34482
|
return await waitForSharedOperation(this.#sessionLoad.completion, signal);
|
|
34617
34483
|
}
|
|
34618
|
-
|
|
34484
|
+
this.#store.eventsV2.reset(this.#mobiusSessionId);
|
|
34485
|
+
const history = new AcpHistoryReplay(this.#store.eventsV2, this.#mobiusSessionId);
|
|
34619
34486
|
const completion = Promise.resolve().then(async () => {
|
|
34620
34487
|
try {
|
|
34621
34488
|
const response = await this.race(
|
|
@@ -35064,7 +34931,14 @@ var AgentSession = class _AgentSession {
|
|
|
35064
34931
|
if (this.#turn.running) {
|
|
35065
34932
|
throw new AcpExecutionError("Another prompt is already running in this conversation", {}, "session_busy");
|
|
35066
34933
|
}
|
|
35067
|
-
|
|
34934
|
+
if (!this.#capabilities.loadSession && this.#sessionLoad.kind === "not-requested") {
|
|
34935
|
+
this.#sessionLoad = {
|
|
34936
|
+
kind: "loaded",
|
|
34937
|
+
history: new AcpHistoryReplay(this.#store.eventsV2, this.#mobiusSessionId),
|
|
34938
|
+
response: {}
|
|
34939
|
+
};
|
|
34940
|
+
}
|
|
34941
|
+
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;
|
|
35068
34942
|
const prompt = this.buildPrompt(options);
|
|
35069
34943
|
if (this.#sessionTitle === null || this.#sessionTitle.length === 0) {
|
|
35070
34944
|
this.#sessionTitle = truncate(options.prompt, 500);
|
|
@@ -35090,14 +34964,19 @@ var AgentSession = class _AgentSession {
|
|
|
35090
34964
|
this.prepareAgentContent
|
|
35091
34965
|
);
|
|
35092
34966
|
this.#turn = running;
|
|
35093
|
-
this.#turnHistory = completedHistory === null ? null : new AcpHistoryReplay();
|
|
34967
|
+
this.#turnHistory = completedHistory === null ? null : new AcpHistoryReplay(this.#store.eventsV2, this.#mobiusSessionId);
|
|
35094
34968
|
const lifecycleV2 = options.lifecycleV2;
|
|
35095
34969
|
if (lifecycleV2 !== void 0) {
|
|
35096
|
-
await this
|
|
35097
|
-
payload: {
|
|
34970
|
+
await this.recordLifecycleEventV2({
|
|
34971
|
+
payload: {
|
|
34972
|
+
commandId: options.commandId,
|
|
34973
|
+
content: lifecycleV2.content,
|
|
34974
|
+
kind: "prompt.requested",
|
|
34975
|
+
...lifecycleV2.context === void 0 ? {} : { context: lifecycleV2.context }
|
|
34976
|
+
},
|
|
35098
34977
|
type: "lifecycle-metadata"
|
|
35099
34978
|
});
|
|
35100
|
-
await this
|
|
34979
|
+
await this.recordLifecycleEventV2({
|
|
35101
34980
|
payload: {
|
|
35102
34981
|
attemptId: lifecycleV2.attemptId,
|
|
35103
34982
|
commandId: options.commandId,
|
|
@@ -35160,7 +35039,7 @@ var AgentSession = class _AgentSession {
|
|
|
35160
35039
|
)
|
|
35161
35040
|
);
|
|
35162
35041
|
if (lifecycleV2 !== void 0) {
|
|
35163
|
-
await this
|
|
35042
|
+
await this.recordLifecycleEventV2({
|
|
35164
35043
|
payload: { commandId: options.commandId, kind: "prompt.completed", stopReason: result.stopReason },
|
|
35165
35044
|
type: "lifecycle-metadata"
|
|
35166
35045
|
});
|
|
@@ -35170,8 +35049,8 @@ var AgentSession = class _AgentSession {
|
|
|
35170
35049
|
await running.activities.finish();
|
|
35171
35050
|
const failure2 = error62 instanceof AcpExecutionError ? error62 : new AcpExecutionError("ACP agent execution failed", { cause: error62 });
|
|
35172
35051
|
if (lifecycleV2 !== void 0) {
|
|
35173
|
-
await this
|
|
35174
|
-
payload: {
|
|
35052
|
+
await this.recordLifecycleEventV2({
|
|
35053
|
+
payload: options.cancellationRequested?.() === true ? { commandId: options.commandId, kind: "prompt.completed", stopReason: "cancelled" } : {
|
|
35175
35054
|
attemptId: lifecycleV2.attemptId,
|
|
35176
35055
|
code: failure2.code,
|
|
35177
35056
|
commandId: options.commandId,
|
|
@@ -35207,11 +35086,16 @@ var AgentSession = class _AgentSession {
|
|
|
35207
35086
|
const prompt = this.buildPrompt(options);
|
|
35208
35087
|
const lifecycleV2 = options.lifecycleV2;
|
|
35209
35088
|
if (lifecycleV2 !== void 0) {
|
|
35210
|
-
await this
|
|
35211
|
-
payload: {
|
|
35089
|
+
await this.recordLifecycleEventV2({
|
|
35090
|
+
payload: {
|
|
35091
|
+
commandId: options.commandId,
|
|
35092
|
+
content: lifecycleV2.content,
|
|
35093
|
+
kind: "prompt.requested",
|
|
35094
|
+
...lifecycleV2.context === void 0 ? {} : { context: lifecycleV2.context }
|
|
35095
|
+
},
|
|
35212
35096
|
type: "lifecycle-metadata"
|
|
35213
35097
|
});
|
|
35214
|
-
await this
|
|
35098
|
+
await this.recordLifecycleEventV2({
|
|
35215
35099
|
payload: {
|
|
35216
35100
|
attemptId: lifecycleV2.attemptId,
|
|
35217
35101
|
commandId: options.commandId,
|
|
@@ -35241,7 +35125,7 @@ var AgentSession = class _AgentSession {
|
|
|
35241
35125
|
const outcome = response["outcome"];
|
|
35242
35126
|
if (outcome === "injected" || outcome === "startedNewTurn") {
|
|
35243
35127
|
if (lifecycleV2 !== void 0) {
|
|
35244
|
-
await this
|
|
35128
|
+
await this.recordLifecycleEventV2({
|
|
35245
35129
|
payload: { commandId: options.commandId, kind: "prompt.completed", stopReason: "steered" },
|
|
35246
35130
|
type: "lifecycle-metadata"
|
|
35247
35131
|
});
|
|
@@ -35266,7 +35150,7 @@ var AgentSession = class _AgentSession {
|
|
|
35266
35150
|
} catch (error62) {
|
|
35267
35151
|
const failure2 = error62 instanceof AcpExecutionError ? error62 : new AcpExecutionError("ACP agent execution failed", { cause: error62 });
|
|
35268
35152
|
if (lifecycleV2 !== void 0) {
|
|
35269
|
-
await this
|
|
35153
|
+
await this.recordLifecycleEventV2({
|
|
35270
35154
|
payload: {
|
|
35271
35155
|
attemptId: lifecycleV2.attemptId,
|
|
35272
35156
|
code: failure2.code,
|
|
@@ -35299,11 +35183,18 @@ var AgentSession = class _AgentSession {
|
|
|
35299
35183
|
onElicitation = (request, signal) => this.#interactions.onElicitation(request, signal);
|
|
35300
35184
|
onElicitationComplete = (notification) => this.#interactions.onElicitationComplete(notification);
|
|
35301
35185
|
onUpdate = (notification) => this.#updates.receive(notification);
|
|
35302
|
-
|
|
35186
|
+
recordControlEventV2 = async (event) => {
|
|
35187
|
+
if (this.#sessionLoad.kind !== "loaded") {
|
|
35188
|
+
return false;
|
|
35189
|
+
}
|
|
35190
|
+
await this.recordLifecycleEventV2(event);
|
|
35191
|
+
return true;
|
|
35192
|
+
};
|
|
35193
|
+
recordLifecycleEventV2 = async (event) => {
|
|
35303
35194
|
if (event.type !== "lifecycle-metadata" || this.#sessionLoad.kind !== "loaded") {
|
|
35304
35195
|
return;
|
|
35305
35196
|
}
|
|
35306
|
-
const position = this.#turnHistory === null ? this.#sessionLoad.history.recordLifecycle(event) : this.#
|
|
35197
|
+
const position = this.#turnHistory === null ? this.#sessionLoad.history.recordLifecycle(event) : this.#turnHistory.recordLifecycle(event);
|
|
35307
35198
|
await this.#getObserver().onSessionEventV2?.(this.#mobiusSessionId, event, position);
|
|
35308
35199
|
};
|
|
35309
35200
|
selectNativeSession = (sessionId) => {
|
|
@@ -35324,13 +35215,8 @@ var AgentSession = class _AgentSession {
|
|
|
35324
35215
|
} else {
|
|
35325
35216
|
const onSessionEventV2 = this.#getObserver().onSessionEventV2;
|
|
35326
35217
|
if (this.#turnHistory !== null) {
|
|
35327
|
-
|
|
35328
|
-
|
|
35329
|
-
await onSessionEventV2?.(
|
|
35330
|
-
this.#mobiusSessionId,
|
|
35331
|
-
{ payload: rawUpdate, type: "acp" },
|
|
35332
|
-
completedEventCount + turnPosition
|
|
35333
|
-
);
|
|
35218
|
+
await this.#turnHistory.record(update, rawUpdate, async (position) => {
|
|
35219
|
+
await onSessionEventV2?.(this.#mobiusSessionId, { payload: rawUpdate, type: "acp" }, position);
|
|
35334
35220
|
});
|
|
35335
35221
|
} else if (this.#sessionLoad.kind === "loaded") {
|
|
35336
35222
|
await this.#sessionLoad.history.record(update, rawUpdate, async (position) => {
|
|
@@ -35973,9 +35859,9 @@ var AcpContentExternalizer = class {
|
|
|
35973
35859
|
};
|
|
35974
35860
|
|
|
35975
35861
|
// src/external-content/local-external-content-store.ts
|
|
35976
|
-
import { createHash as createHash2, randomUUID } from "node:crypto";
|
|
35862
|
+
import { createHash as createHash2, randomUUID as randomUUID2 } from "node:crypto";
|
|
35977
35863
|
import { lstat, mkdir as mkdir4, readdir as readdir2, realpath as realpath7, rename as rename3, rm as rm3, stat as stat6, utimes, writeFile as writeFile3 } from "node:fs/promises";
|
|
35978
|
-
import { dirname as
|
|
35864
|
+
import { dirname as dirname3, join as join15 } from "node:path";
|
|
35979
35865
|
var contentRequest = /^mobius-content:(image|audio|resource):([a-f0-9]{64})$/u;
|
|
35980
35866
|
var CONTENT_LIFETIME_MILLISECONDS = 24 * 60 * 60 * 1e3;
|
|
35981
35867
|
var metadataSchema2 = external_exports.strictObject({
|
|
@@ -35994,7 +35880,7 @@ var UnretainedExternalContentStore = class {
|
|
|
35994
35880
|
};
|
|
35995
35881
|
};
|
|
35996
35882
|
async function atomicWrite(path2, bytes, signal) {
|
|
35997
|
-
const temporary = `${path2}.${
|
|
35883
|
+
const temporary = `${path2}.${randomUUID2()}.tmp`;
|
|
35998
35884
|
try {
|
|
35999
35885
|
await writeFile3(temporary, bytes, { mode: 384, signal });
|
|
36000
35886
|
signal.throwIfAborted();
|
|
@@ -36011,7 +35897,7 @@ var LocalExternalContentStore = class {
|
|
|
36011
35897
|
#expirationTimer;
|
|
36012
35898
|
#cleanup = Promise.resolve();
|
|
36013
35899
|
constructor(stateDirectory) {
|
|
36014
|
-
this.#root = join15(stateDirectory, "tmp", "session-content",
|
|
35900
|
+
this.#root = join15(stateDirectory, "tmp", "session-content", randomUUID2());
|
|
36015
35901
|
this.#expirationTimer = setInterval(() => {
|
|
36016
35902
|
void this.#expire().catch(() => void 0);
|
|
36017
35903
|
}, 6e4);
|
|
@@ -36022,11 +35908,11 @@ var LocalExternalContentStore = class {
|
|
|
36022
35908
|
await mkdir4(this.#root, { mode: 448, recursive: true });
|
|
36023
35909
|
const now = /* @__PURE__ */ new Date();
|
|
36024
35910
|
await utimes(this.#root, now, now);
|
|
36025
|
-
for (const directory of await readdir2(
|
|
35911
|
+
for (const directory of await readdir2(dirname3(this.#root), { withFileTypes: true })) {
|
|
36026
35912
|
if (!directory.isDirectory() || !/^[a-f0-9-]{36}$/u.test(directory.name)) {
|
|
36027
35913
|
continue;
|
|
36028
35914
|
}
|
|
36029
|
-
const path2 = join15(
|
|
35915
|
+
const path2 = join15(dirname3(this.#root), directory.name);
|
|
36030
35916
|
if (path2 === this.#root) {
|
|
36031
35917
|
continue;
|
|
36032
35918
|
}
|
|
@@ -36112,12 +35998,12 @@ var LocalExternalContentStore = class {
|
|
|
36112
35998
|
}
|
|
36113
35999
|
try {
|
|
36114
36000
|
const [resolvedDirectory, resolvedPath, file2] = await Promise.all([
|
|
36115
|
-
realpath7(
|
|
36001
|
+
realpath7(dirname3(entry.path)),
|
|
36116
36002
|
realpath7(entry.path),
|
|
36117
36003
|
lstat(entry.path)
|
|
36118
36004
|
]);
|
|
36119
36005
|
signal.throwIfAborted();
|
|
36120
|
-
if (!file2.isFile() || file2.isSymbolicLink() ||
|
|
36006
|
+
if (!file2.isFile() || file2.isSymbolicLink() || dirname3(resolvedPath) !== resolvedDirectory) {
|
|
36121
36007
|
return null;
|
|
36122
36008
|
}
|
|
36123
36009
|
return { mediaType: entry.mediaType, name: entry.name, path: resolvedPath };
|
|
@@ -36194,9 +36080,9 @@ var AcpProcessCapacityLock = class {
|
|
|
36194
36080
|
return await waiter.completion.promise;
|
|
36195
36081
|
} finally {
|
|
36196
36082
|
signal.removeEventListener("abort", waiter.cancel);
|
|
36197
|
-
const
|
|
36198
|
-
if (
|
|
36199
|
-
this.#waiters.splice(
|
|
36083
|
+
const index2 = this.#waiters.indexOf(waiter);
|
|
36084
|
+
if (index2 >= 0) {
|
|
36085
|
+
this.#waiters.splice(index2, 1);
|
|
36200
36086
|
}
|
|
36201
36087
|
}
|
|
36202
36088
|
};
|
|
@@ -36367,6 +36253,13 @@ var AgentRuntimeManager = class {
|
|
|
36367
36253
|
this.#contentExternalizer = contentExternalizer;
|
|
36368
36254
|
this.#queryProcesses = new AgentQueryProcesses(this.#processes, contentExternalizer);
|
|
36369
36255
|
}
|
|
36256
|
+
recordLifecycleEventV2 = async (sessionId, event) => {
|
|
36257
|
+
const runtime = this.#executionProcesses.get(sessionId);
|
|
36258
|
+
if (runtime === void 0) {
|
|
36259
|
+
return false;
|
|
36260
|
+
}
|
|
36261
|
+
return await runtime.recordControlEventV2(event);
|
|
36262
|
+
};
|
|
36370
36263
|
setObserver = (observer) => {
|
|
36371
36264
|
this.#observer = observer;
|
|
36372
36265
|
};
|
|
@@ -36696,7 +36589,10 @@ var AgentRuntimeManager = class {
|
|
|
36696
36589
|
return { stopReason: "cancelled" };
|
|
36697
36590
|
}
|
|
36698
36591
|
try {
|
|
36699
|
-
const result = await runtime.prompt(
|
|
36592
|
+
const result = await runtime.prompt({
|
|
36593
|
+
...options2,
|
|
36594
|
+
cancellationRequested: () => this.#executions.cancellation(options2.sessionId) !== void 0
|
|
36595
|
+
});
|
|
36700
36596
|
return this.#executions.cancellation(options2.sessionId) !== void 0 ? { stopReason: "cancelled" } : result;
|
|
36701
36597
|
} catch (error62) {
|
|
36702
36598
|
if (this.#executions.cancellation(options2.sessionId) !== void 0) {
|
|
@@ -37556,7 +37452,7 @@ var FixedInstallationExecutor = class {
|
|
|
37556
37452
|
// src/authorization/workspace-directory.ts
|
|
37557
37453
|
import { readdir as readdir3, realpath as realpath8, stat as stat7 } from "node:fs/promises";
|
|
37558
37454
|
import { homedir as homedir2 } from "node:os";
|
|
37559
|
-
import { basename as basename3, dirname as
|
|
37455
|
+
import { basename as basename3, dirname as dirname4, isAbsolute as isAbsolute9, join as join16, normalize as normalize3, relative as relative4 } from "node:path";
|
|
37560
37456
|
|
|
37561
37457
|
// src/authorization/local-authorization-error.ts
|
|
37562
37458
|
var LocalAuthorizationError = class extends Error {
|
|
@@ -37695,7 +37591,7 @@ var WorkspaceDirectoryService = class {
|
|
|
37695
37591
|
}
|
|
37696
37592
|
}
|
|
37697
37593
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
37698
|
-
const parent =
|
|
37594
|
+
const parent = dirname4(target);
|
|
37699
37595
|
return new WorkspaceDirectoryListing(
|
|
37700
37596
|
id,
|
|
37701
37597
|
this.label(target),
|
|
@@ -37720,7 +37616,7 @@ var WorkspaceDirectoryService = class {
|
|
|
37720
37616
|
};
|
|
37721
37617
|
|
|
37722
37618
|
// src/daemon-diagnostic-log.ts
|
|
37723
|
-
import { appendFileSync, mkdirSync
|
|
37619
|
+
import { appendFileSync, mkdirSync, readFileSync as readFileSync2, renameSync, statSync as statSync3, writeFileSync } from "node:fs";
|
|
37724
37620
|
import { join as join17 } from "node:path";
|
|
37725
37621
|
var MAXIMUM_DAEMON_LOG_BYTES = 1 * 1024 * 1024;
|
|
37726
37622
|
var DaemonDiagnosticLog = class {
|
|
@@ -37736,7 +37632,7 @@ var DaemonDiagnosticLog = class {
|
|
|
37736
37632
|
const encoded = `${diagnostic.replace(/[\r\n]+/gu, " ").trim()}
|
|
37737
37633
|
`;
|
|
37738
37634
|
const encodedBytes = Buffer.byteLength(encoded);
|
|
37739
|
-
|
|
37635
|
+
mkdirSync(this.#directory, { mode: 448, recursive: true });
|
|
37740
37636
|
let existingBytes = 0;
|
|
37741
37637
|
try {
|
|
37742
37638
|
existingBytes = statSync3(this.#path).size;
|
|
@@ -37994,16 +37890,7 @@ function send(socket, message) {
|
|
|
37994
37890
|
}
|
|
37995
37891
|
socket.send(encodeDaemonToServiceMessage(message));
|
|
37996
37892
|
}
|
|
37997
|
-
function
|
|
37998
|
-
publisher.publish(command.sessionId, {
|
|
37999
|
-
code,
|
|
38000
|
-
commandId: command.commandId,
|
|
38001
|
-
kind: SESSION_FAILED_KIND,
|
|
38002
|
-
message,
|
|
38003
|
-
sessionId: command.sessionId
|
|
38004
|
-
});
|
|
38005
|
-
}
|
|
38006
|
-
function settleAbandonedTurn(publisher, operations, audit, cancellation) {
|
|
37893
|
+
async function settleAbandonedTurn(eventLog, operations, audit, cancellation) {
|
|
38007
37894
|
const attemptId = operations.findUnsettledAttemptId(cancellation.commandId, cancellation.sessionId);
|
|
38008
37895
|
if (attemptId === null) {
|
|
38009
37896
|
console.warn("Mobius daemon ignored cancellation for an inactive turn");
|
|
@@ -38014,13 +37901,14 @@ function settleAbandonedTurn(publisher, operations, audit, cancellation) {
|
|
|
38014
37901
|
event: "session_abandoned_turn_settled",
|
|
38015
37902
|
sessionId: cancellation.sessionId
|
|
38016
37903
|
});
|
|
38017
|
-
|
|
38018
|
-
|
|
38019
|
-
cancellation,
|
|
37904
|
+
await eventLog.failed(
|
|
37905
|
+
cancellation.sessionId,
|
|
37906
|
+
cancellation.commandId,
|
|
38020
37907
|
"agent_execution_abandoned",
|
|
38021
37908
|
"The local Agent execution was abandoned before it completed"
|
|
38022
37909
|
);
|
|
38023
37910
|
operations.transitionExecution(cancellation.commandId, "failed");
|
|
37911
|
+
eventLog.publishTerminal(cancellation.sessionId, cancellation.commandId);
|
|
38024
37912
|
}
|
|
38025
37913
|
function operationErrorCode(error62) {
|
|
38026
37914
|
if (error62 instanceof AcpExecutionError || error62 instanceof LocalAuthorizationError || error62 instanceof LocalAgentCatalogError || error62 instanceof PromptArtifactError) {
|
|
@@ -38201,7 +38089,7 @@ var DaemonInstallationObserver = class {
|
|
|
38201
38089
|
};
|
|
38202
38090
|
|
|
38203
38091
|
// src/daemon-active-turn.ts
|
|
38204
|
-
import { randomUUID as
|
|
38092
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
38205
38093
|
function activeMessageCharacters(message) {
|
|
38206
38094
|
return message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0);
|
|
38207
38095
|
}
|
|
@@ -38209,8 +38097,8 @@ var ACTIVE_TURN_TEXT_CHUNK_LIMIT = Math.floor(SESSION_HISTORY_CHARACTER_LIMIT /
|
|
|
38209
38097
|
function boundedRecoveryMessages(messages) {
|
|
38210
38098
|
const selected = [];
|
|
38211
38099
|
let remainingCharacters = SESSION_HISTORY_CHARACTER_LIMIT;
|
|
38212
|
-
for (let
|
|
38213
|
-
const message = messages[
|
|
38100
|
+
for (let index2 = messages.length - 1; index2 >= 0 && selected.length < SESSION_HISTORY_MESSAGE_LIMIT; index2 -= 1) {
|
|
38101
|
+
const message = messages[index2];
|
|
38214
38102
|
if (message === void 0) {
|
|
38215
38103
|
break;
|
|
38216
38104
|
}
|
|
@@ -38235,7 +38123,7 @@ var ActiveDaemonTurn = class {
|
|
|
38235
38123
|
#timeline;
|
|
38236
38124
|
#sequence = 0;
|
|
38237
38125
|
#interaction = null;
|
|
38238
|
-
#epoch = decodeIdentifier(
|
|
38126
|
+
#epoch = decodeIdentifier(randomUUID3());
|
|
38239
38127
|
constructor(command, attemptId) {
|
|
38240
38128
|
this.attemptId = attemptId;
|
|
38241
38129
|
this.command = command;
|
|
@@ -38297,7 +38185,7 @@ var ActiveDaemonTurn = class {
|
|
|
38297
38185
|
if (!this.#activities.has(event.activityId)) {
|
|
38298
38186
|
this.#timeline = [
|
|
38299
38187
|
...this.#timeline,
|
|
38300
|
-
{ activityId: event.activityId, id: decodeIdentifier(
|
|
38188
|
+
{ activityId: event.activityId, id: decodeIdentifier(randomUUID3()), kind: "activity" }
|
|
38301
38189
|
];
|
|
38302
38190
|
}
|
|
38303
38191
|
this.#activities.set(event.activityId, {
|
|
@@ -38318,7 +38206,7 @@ var ActiveDaemonTurn = class {
|
|
|
38318
38206
|
if (previous === void 0) {
|
|
38319
38207
|
this.#timeline = [
|
|
38320
38208
|
...this.#timeline,
|
|
38321
|
-
{ activityId: event.activityId, id: decodeIdentifier(
|
|
38209
|
+
{ activityId: event.activityId, id: decodeIdentifier(randomUUID3()), kind: "activity" }
|
|
38322
38210
|
];
|
|
38323
38211
|
}
|
|
38324
38212
|
this.#activities.set(event.activityId, {
|
|
@@ -38343,7 +38231,7 @@ var ActiveDaemonTurn = class {
|
|
|
38343
38231
|
...this.#timeline,
|
|
38344
38232
|
{
|
|
38345
38233
|
content: /* @__PURE__ */ new Map([[event.contentId, event.content]]),
|
|
38346
|
-
id: decodeIdentifier(
|
|
38234
|
+
id: decodeIdentifier(randomUUID3()),
|
|
38347
38235
|
kind: "message",
|
|
38348
38236
|
sourceMessageId: event.messageId,
|
|
38349
38237
|
text: ""
|
|
@@ -38351,7 +38239,7 @@ var ActiveDaemonTurn = class {
|
|
|
38351
38239
|
];
|
|
38352
38240
|
} else {
|
|
38353
38241
|
this.#timeline = this.#timeline.map(
|
|
38354
|
-
(entry,
|
|
38242
|
+
(entry, index2) => index2 === target && entry.kind === "message" ? { ...entry, content: new Map([...entry.content, [event.contentId, event.content]]) } : entry
|
|
38355
38243
|
);
|
|
38356
38244
|
}
|
|
38357
38245
|
} else if (event.kind === SESSION_PERMISSION_REQUESTED_KIND || event.kind === SESSION_ELICITATION_REQUESTED_KIND) {
|
|
@@ -38383,7 +38271,7 @@ var ActiveDaemonTurn = class {
|
|
|
38383
38271
|
...this.#timeline,
|
|
38384
38272
|
{
|
|
38385
38273
|
content: /* @__PURE__ */ new Map(),
|
|
38386
|
-
id: decodeIdentifier(
|
|
38274
|
+
id: decodeIdentifier(randomUUID3()),
|
|
38387
38275
|
kind: "message",
|
|
38388
38276
|
sourceMessageId: messageId,
|
|
38389
38277
|
text: remaining.slice(0, ACTIVE_TURN_TEXT_CHUNK_LIMIT)
|
|
@@ -38654,6 +38542,202 @@ var DaemonTurnRegistry = class {
|
|
|
38654
38542
|
};
|
|
38655
38543
|
};
|
|
38656
38544
|
|
|
38545
|
+
// src/generated/acp-session-store-migrations.ts
|
|
38546
|
+
var acpSessionStoreMigrations = [
|
|
38547
|
+
{
|
|
38548
|
+
"name": "0000_slimy_captain_midlands.sql",
|
|
38549
|
+
"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"
|
|
38550
|
+
},
|
|
38551
|
+
{
|
|
38552
|
+
"name": "0001_regular_ultimates.sql",
|
|
38553
|
+
"sql": "ALTER TABLE `acp_session` ADD `last_terminal_command_id` text;"
|
|
38554
|
+
},
|
|
38555
|
+
{
|
|
38556
|
+
"name": "0002_equal_black_queen.sql",
|
|
38557
|
+
"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`);"
|
|
38558
|
+
},
|
|
38559
|
+
{
|
|
38560
|
+
"name": "0003_silky_ravenous.sql",
|
|
38561
|
+
"sql": "DROP TABLE `session_event_v2`;"
|
|
38562
|
+
},
|
|
38563
|
+
{
|
|
38564
|
+
"name": "0004_special_mathemanic.sql",
|
|
38565
|
+
"sql": "DROP TABLE `deleted_acp_session`;--> statement-breakpoint\nALTER TABLE `acp_session` DROP COLUMN `last_terminal_command_id`;"
|
|
38566
|
+
}
|
|
38567
|
+
];
|
|
38568
|
+
|
|
38569
|
+
// src/generated/session-event-cache-migrations.ts
|
|
38570
|
+
var sessionEventCacheMigrations = [
|
|
38571
|
+
{
|
|
38572
|
+
"name": "migration.sql",
|
|
38573
|
+
"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`);"
|
|
38574
|
+
}
|
|
38575
|
+
];
|
|
38576
|
+
|
|
38577
|
+
// src/infra/local-sqlite-database.ts
|
|
38578
|
+
import { chmodSync, mkdirSync as mkdirSync2 } from "node:fs";
|
|
38579
|
+
import { dirname as dirname5 } from "node:path";
|
|
38580
|
+
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
38581
|
+
|
|
38582
|
+
// ../../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
|
|
38583
|
+
var NodeSQLiteSession = class extends SQLiteAsyncSession {
|
|
38584
|
+
static [entityKind] = "SQLJsSession";
|
|
38585
|
+
logger;
|
|
38586
|
+
constructor(client2, dialect, relations, options = {}) {
|
|
38587
|
+
super(dialect, "sync");
|
|
38588
|
+
this.client = client2;
|
|
38589
|
+
this.relations = relations;
|
|
38590
|
+
this.options = options;
|
|
38591
|
+
this.logger = options.logger ?? new NoopLogger();
|
|
38592
|
+
}
|
|
38593
|
+
prepareQuery(query, mode, _prepare, executeMethod, mapper, queryMetadata) {
|
|
38594
|
+
let stmt;
|
|
38595
|
+
try {
|
|
38596
|
+
stmt = this.client.prepare(query.sql);
|
|
38597
|
+
} catch (e) {
|
|
38598
|
+
throw new DrizzleQueryError(query.sql, query.params, e);
|
|
38599
|
+
}
|
|
38600
|
+
return new SQLiteAsyncPreparedQuery("sync", executeMethod, {
|
|
38601
|
+
all: (params) => {
|
|
38602
|
+
stmt.setReturnArrays(mode === "arrays");
|
|
38603
|
+
const res = stmt.all(...params);
|
|
38604
|
+
if (mode === "objects") return res.map((row) => ({ ...row }));
|
|
38605
|
+
return res;
|
|
38606
|
+
},
|
|
38607
|
+
get: (params) => {
|
|
38608
|
+
stmt.setReturnArrays(mode === "arrays");
|
|
38609
|
+
const res = stmt.get(...params);
|
|
38610
|
+
if (res && mode === "objects") return { ...res };
|
|
38611
|
+
return res;
|
|
38612
|
+
},
|
|
38613
|
+
run: (params) => {
|
|
38614
|
+
stmt.setReturnArrays(false);
|
|
38615
|
+
return stmt.run(...params);
|
|
38616
|
+
},
|
|
38617
|
+
values: (params) => {
|
|
38618
|
+
stmt.setReturnArrays(true);
|
|
38619
|
+
return stmt.all(...params);
|
|
38620
|
+
}
|
|
38621
|
+
}, query, mapper, mode, this.logger, void 0, queryMetadata, void 0);
|
|
38622
|
+
}
|
|
38623
|
+
transaction(transaction, config2 = {}) {
|
|
38624
|
+
const tx = new NodeSQLiteTransaction("sync", this.dialect, this, this.relations);
|
|
38625
|
+
this.run(sql.raw(`begin${config2.behavior ? ` ${config2.behavior}` : ""}`));
|
|
38626
|
+
try {
|
|
38627
|
+
const result = transaction(tx);
|
|
38628
|
+
this.run(sql`commit`);
|
|
38629
|
+
return result;
|
|
38630
|
+
} catch (err) {
|
|
38631
|
+
this.run(sql`rollback`);
|
|
38632
|
+
throw err;
|
|
38633
|
+
}
|
|
38634
|
+
}
|
|
38635
|
+
};
|
|
38636
|
+
var NodeSQLiteTransaction = class NodeSQLiteTransaction2 extends SQLiteAsyncTransaction {
|
|
38637
|
+
static [entityKind] = "SQLJsTransaction";
|
|
38638
|
+
transaction(transaction) {
|
|
38639
|
+
const savepointName = `sp${this.nestedIndex + 1}`;
|
|
38640
|
+
const tx = new NodeSQLiteTransaction2("sync", this.dialect, this.session, this._.relations, this.nestedIndex + 1);
|
|
38641
|
+
tx.run(sql.raw(`savepoint ${savepointName}`));
|
|
38642
|
+
try {
|
|
38643
|
+
const result = transaction(tx);
|
|
38644
|
+
tx.run(sql.raw(`release savepoint ${savepointName}`));
|
|
38645
|
+
return result;
|
|
38646
|
+
} catch (err) {
|
|
38647
|
+
tx.run(sql.raw(`rollback to savepoint ${savepointName}`));
|
|
38648
|
+
throw err;
|
|
38649
|
+
}
|
|
38650
|
+
}
|
|
38651
|
+
};
|
|
38652
|
+
|
|
38653
|
+
// ../../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
|
|
38654
|
+
import { DatabaseSync } from "node:sqlite";
|
|
38655
|
+
var NodeSQLiteDatabase = class extends SQLiteAsyncDatabase {
|
|
38656
|
+
static [entityKind] = "NodeSQLiteDatabase";
|
|
38657
|
+
};
|
|
38658
|
+
function construct(client2, config2 = {}) {
|
|
38659
|
+
const dialect = new SQLiteDialect({ useJitMappers: jitCompatCheck(config2.jit) });
|
|
38660
|
+
let logger;
|
|
38661
|
+
if (config2.logger === true) logger = new DefaultLogger();
|
|
38662
|
+
else if (config2.logger !== false) logger = config2.logger;
|
|
38663
|
+
const relations = config2.relations ?? {};
|
|
38664
|
+
const db = new NodeSQLiteDatabase("sync", dialect, new NodeSQLiteSession(client2, dialect, relations, { logger }), relations);
|
|
38665
|
+
db.$client = client2;
|
|
38666
|
+
return db;
|
|
38667
|
+
}
|
|
38668
|
+
function drizzle(...params) {
|
|
38669
|
+
if (params[0] === void 0 || typeof params[0] === "string") return construct(params[0] === void 0 ? new DatabaseSync(":memory:") : new DatabaseSync(params[0]), params[1]);
|
|
38670
|
+
const { connection, client: client2, ...config2 } = params[0];
|
|
38671
|
+
if (client2) return construct(client2, config2);
|
|
38672
|
+
if (typeof connection === "object") {
|
|
38673
|
+
const { path: path2, ...options } = connection;
|
|
38674
|
+
return construct(new DatabaseSync(path2 ?? ":memory:", options), config2);
|
|
38675
|
+
}
|
|
38676
|
+
return construct(new DatabaseSync(connection ?? ":memory:"), config2);
|
|
38677
|
+
}
|
|
38678
|
+
(function(_drizzle) {
|
|
38679
|
+
function mock(config2) {
|
|
38680
|
+
return construct({}, config2);
|
|
38681
|
+
}
|
|
38682
|
+
_drizzle.mock = mock;
|
|
38683
|
+
})(drizzle || (drizzle = {}));
|
|
38684
|
+
|
|
38685
|
+
// src/infra/local-sqlite-database.ts
|
|
38686
|
+
var LocalSqliteDatabase = class {
|
|
38687
|
+
orm;
|
|
38688
|
+
#sqlite;
|
|
38689
|
+
constructor(path2, label, migrations, pragmas = []) {
|
|
38690
|
+
mkdirSync2(dirname5(path2), { mode: 448, recursive: true });
|
|
38691
|
+
this.#sqlite = new DatabaseSync2(path2);
|
|
38692
|
+
chmodSync(path2, 384);
|
|
38693
|
+
try {
|
|
38694
|
+
for (const pragma of pragmas) {
|
|
38695
|
+
this.#sqlite.exec(pragma);
|
|
38696
|
+
}
|
|
38697
|
+
this.#migrate(label, migrations);
|
|
38698
|
+
this.orm = drizzle({ client: this.#sqlite });
|
|
38699
|
+
} catch (error62) {
|
|
38700
|
+
this.#sqlite.close();
|
|
38701
|
+
throw error62;
|
|
38702
|
+
}
|
|
38703
|
+
}
|
|
38704
|
+
#migrate = (label, migrations) => {
|
|
38705
|
+
const version2 = external_exports.object({ user_version: external_exports.number().int().nonnegative() }).parse(this.#sqlite.prepare("PRAGMA user_version").get()).user_version;
|
|
38706
|
+
if (version2 > migrations.length) {
|
|
38707
|
+
throw new Error(`The ${label} was created by a newer Mobius version`);
|
|
38708
|
+
}
|
|
38709
|
+
for (let index2 = version2; index2 < migrations.length; index2 += 1) {
|
|
38710
|
+
const migration = migrations[index2];
|
|
38711
|
+
if (migration === void 0) {
|
|
38712
|
+
throw new Error(`The ${label} migration is unavailable`);
|
|
38713
|
+
}
|
|
38714
|
+
this.transaction(() => {
|
|
38715
|
+
this.#sqlite.exec(migration.sql);
|
|
38716
|
+
this.#sqlite.exec(`PRAGMA user_version = ${index2 + 1}`);
|
|
38717
|
+
});
|
|
38718
|
+
}
|
|
38719
|
+
};
|
|
38720
|
+
transaction = (operation) => {
|
|
38721
|
+
this.#sqlite.exec("BEGIN IMMEDIATE");
|
|
38722
|
+
try {
|
|
38723
|
+
const result = operation();
|
|
38724
|
+
this.#sqlite.exec("COMMIT");
|
|
38725
|
+
return result;
|
|
38726
|
+
} catch (error62) {
|
|
38727
|
+
this.#sqlite.exec("ROLLBACK");
|
|
38728
|
+
throw error62;
|
|
38729
|
+
}
|
|
38730
|
+
};
|
|
38731
|
+
close = () => this.#sqlite.close();
|
|
38732
|
+
};
|
|
38733
|
+
|
|
38734
|
+
// src/local-databases.ts
|
|
38735
|
+
var openAcpSessionDatabase = (path2) => new LocalSqliteDatabase(path2, "ACP Session database", acpSessionStoreMigrations);
|
|
38736
|
+
var openSessionEventCacheV2Database = (path2) => new LocalSqliteDatabase(path2, "V2 Session event cache", sessionEventCacheMigrations, [
|
|
38737
|
+
"PRAGMA journal_mode = WAL",
|
|
38738
|
+
"PRAGMA synchronous = OFF"
|
|
38739
|
+
]);
|
|
38740
|
+
|
|
38657
38741
|
// src/native-sessions/codex-history.ts
|
|
38658
38742
|
import { spawn as spawn5 } from "node:child_process";
|
|
38659
38743
|
var responseSchema = external_exports.union([
|
|
@@ -39358,7 +39442,7 @@ var readCodexFullHistory = async (agent, cwd, nativeSessionId, signal, nativeTur
|
|
|
39358
39442
|
});
|
|
39359
39443
|
|
|
39360
39444
|
// src/native-sessions/service.ts
|
|
39361
|
-
import { randomUUID as
|
|
39445
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
39362
39446
|
var NativeSessionService = class {
|
|
39363
39447
|
#entries = /* @__PURE__ */ new Map();
|
|
39364
39448
|
#cursors = /* @__PURE__ */ new Map();
|
|
@@ -39417,7 +39501,7 @@ var NativeSessionService = class {
|
|
|
39417
39501
|
if (authorized === null) {
|
|
39418
39502
|
return null;
|
|
39419
39503
|
}
|
|
39420
|
-
const entryId = decodeIdentifier(
|
|
39504
|
+
const entryId = decodeIdentifier(randomUUID4());
|
|
39421
39505
|
if (this.#entries.size >= 5e3) {
|
|
39422
39506
|
this.#entries.clear();
|
|
39423
39507
|
}
|
|
@@ -39473,7 +39557,7 @@ var NativeSessionService = class {
|
|
|
39473
39557
|
"invalid_native_session_response"
|
|
39474
39558
|
);
|
|
39475
39559
|
}
|
|
39476
|
-
nextCursor = decodeIdentifier(
|
|
39560
|
+
nextCursor = decodeIdentifier(randomUUID4());
|
|
39477
39561
|
if (this.#cursors.size >= 500) {
|
|
39478
39562
|
this.#cursors.clear();
|
|
39479
39563
|
}
|
|
@@ -39651,7 +39735,7 @@ var NativeSessionService = class {
|
|
|
39651
39735
|
resolveTarget = async (command, options, selected) => {
|
|
39652
39736
|
let cursor = null;
|
|
39653
39737
|
const visited = /* @__PURE__ */ new Set();
|
|
39654
|
-
for (let
|
|
39738
|
+
for (let index2 = 0; index2 < 100; index2 += 1) {
|
|
39655
39739
|
const page = await this.#sessions.listNativeSessions(options, cursor);
|
|
39656
39740
|
const info = page.sessions.find((entry) => entry.sessionId === selected.nativeSessionId);
|
|
39657
39741
|
if (info !== void 0) {
|
|
@@ -39659,7 +39743,7 @@ var NativeSessionService = class {
|
|
|
39659
39743
|
if (target === null) {
|
|
39660
39744
|
throw new LocalAuthorizationError("The selected native session is not authorized");
|
|
39661
39745
|
}
|
|
39662
|
-
if (target.cwd !== selected.cwd || target.additionalDirectories.length !== selected.additionalDirectories.length || target.additionalDirectories.some((path2,
|
|
39746
|
+
if (target.cwd !== selected.cwd || target.additionalDirectories.length !== selected.additionalDirectories.length || target.additionalDirectories.some((path2, index3) => path2 !== selected.additionalDirectories[index3])) {
|
|
39663
39747
|
throw new AcpExecutionError(
|
|
39664
39748
|
"This session's directory changed. Refresh the list before continuing.",
|
|
39665
39749
|
{},
|
|
@@ -39698,7 +39782,7 @@ var NativeSessionService = class {
|
|
|
39698
39782
|
};
|
|
39699
39783
|
|
|
39700
39784
|
// src/relay-connection/daemon-operation-state.ts
|
|
39701
|
-
import { createHash as createHash4, randomUUID as
|
|
39785
|
+
import { createHash as createHash4, randomUUID as randomUUID5 } from "node:crypto";
|
|
39702
39786
|
var MAX_TERMINAL_RECEIPTS = 1024;
|
|
39703
39787
|
function isTerminal(state) {
|
|
39704
39788
|
return state === "succeeded" || state === "failed" || state === "cancelled";
|
|
@@ -39715,7 +39799,7 @@ var DaemonOperationState = class {
|
|
|
39715
39799
|
}
|
|
39716
39800
|
return { attemptId: existing.attemptId, commandId, kind: "duplicate", state: existing.state };
|
|
39717
39801
|
}
|
|
39718
|
-
const attemptId =
|
|
39802
|
+
const attemptId = randomUUID5();
|
|
39719
39803
|
this.#executions.set(commandId, { attemptId, commandHash, sessionId, state: "dispatching" });
|
|
39720
39804
|
return { attemptId, commandId, kind: "accepted", state: "dispatching" };
|
|
39721
39805
|
};
|
|
@@ -40679,7 +40763,7 @@ async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, dir
|
|
|
40679
40763
|
const replay = await sessions.loadSessionEventsV2(loadOptions, command.eventLimit, command.cursor);
|
|
40680
40764
|
signal.throwIfAborted();
|
|
40681
40765
|
const events = replay.events.map(
|
|
40682
|
-
(event,
|
|
40766
|
+
(event, index2) => eventLogV2.event(command.sessionId, replay.startPosition + index2, event, "1970-01-01T00:00:00.000Z")
|
|
40683
40767
|
);
|
|
40684
40768
|
const tailCursor = events.at(-1)?.eventId ?? "";
|
|
40685
40769
|
audit.record({
|
|
@@ -40730,7 +40814,7 @@ async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, dir
|
|
|
40730
40814
|
}
|
|
40731
40815
|
|
|
40732
40816
|
// src/acp/session-config/apply-session-configuration.ts
|
|
40733
|
-
import { randomUUID as
|
|
40817
|
+
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
40734
40818
|
function invalidSessionConfiguration(message) {
|
|
40735
40819
|
return new AcpExecutionError(message, {}, "invalid_session_configuration");
|
|
40736
40820
|
}
|
|
@@ -40871,7 +40955,7 @@ async function applySessionConfigurationSelection(sessions, audit, options, sele
|
|
|
40871
40955
|
booleanValue: selection.booleanValue,
|
|
40872
40956
|
configId: selection.configId,
|
|
40873
40957
|
cwd,
|
|
40874
|
-
requestId: `cfg_${
|
|
40958
|
+
requestId: `cfg_${randomUUID6()}`,
|
|
40875
40959
|
sessionId,
|
|
40876
40960
|
signal,
|
|
40877
40961
|
value: selection.value,
|
|
@@ -40913,112 +40997,6 @@ function warnIgnoredSetting(audit, event, commandId, sessionId, agentId, selecti
|
|
|
40913
40997
|
`);
|
|
40914
40998
|
}
|
|
40915
40999
|
|
|
40916
|
-
// src/relay-connection/coalescing-agent-event-publisher.ts
|
|
40917
|
-
var AGENT_EVENT_COALESCING_MILLISECONDS = 100;
|
|
40918
|
-
var AGENT_EVENT_TEXT_MAXIMUM_LENGTH = 1e5;
|
|
40919
|
-
var CoalescingAgentEventPublisher = class {
|
|
40920
|
-
#entries = [];
|
|
40921
|
-
#publish;
|
|
40922
|
-
#publishedActivityIds = /* @__PURE__ */ new Set();
|
|
40923
|
-
#scheduled = null;
|
|
40924
|
-
#timer;
|
|
40925
|
-
constructor(timer, publish) {
|
|
40926
|
-
this.#publish = publish;
|
|
40927
|
-
this.#timer = timer;
|
|
40928
|
-
}
|
|
40929
|
-
flush = () => {
|
|
40930
|
-
this.#scheduled?.cancel();
|
|
40931
|
-
this.#scheduled = null;
|
|
40932
|
-
const entries = this.#entries;
|
|
40933
|
-
this.#entries = [];
|
|
40934
|
-
for (const entry of entries) {
|
|
40935
|
-
this.#publish(entry);
|
|
40936
|
-
}
|
|
40937
|
-
};
|
|
40938
|
-
recordActivity = (activity2) => {
|
|
40939
|
-
const latest = this.#entries.at(-1);
|
|
40940
|
-
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" }];
|
|
40941
|
-
const first = !this.#publishedActivityIds.has(activity2.activityId);
|
|
40942
|
-
this.#publishedActivityIds.add(activity2.activityId);
|
|
40943
|
-
if (first || activity2.status !== "pending" && activity2.status !== "running") {
|
|
40944
|
-
this.flush();
|
|
40945
|
-
} else {
|
|
40946
|
-
this.schedule();
|
|
40947
|
-
}
|
|
40948
|
-
return Promise.resolve();
|
|
40949
|
-
};
|
|
40950
|
-
recordNarration = (increment) => {
|
|
40951
|
-
if (increment.text.length === 0) {
|
|
40952
|
-
return Promise.resolve();
|
|
40953
|
-
}
|
|
40954
|
-
let remaining = increment.text;
|
|
40955
|
-
while (remaining.length > 0) {
|
|
40956
|
-
const latest = this.#entries.at(-1);
|
|
40957
|
-
if (latest?.kind === "narration" && latest.increment.activityId === increment.activityId) {
|
|
40958
|
-
const available = AGENT_EVENT_TEXT_MAXIMUM_LENGTH - latest.increment.text.length;
|
|
40959
|
-
if (available > 0) {
|
|
40960
|
-
this.#entries = [
|
|
40961
|
-
...this.#entries.slice(0, -1),
|
|
40962
|
-
{
|
|
40963
|
-
increment: {
|
|
40964
|
-
...increment,
|
|
40965
|
-
text: `${latest.increment.text}${remaining.slice(0, available)}`
|
|
40966
|
-
},
|
|
40967
|
-
kind: "narration"
|
|
40968
|
-
}
|
|
40969
|
-
];
|
|
40970
|
-
remaining = remaining.slice(available);
|
|
40971
|
-
continue;
|
|
40972
|
-
}
|
|
40973
|
-
}
|
|
40974
|
-
this.#entries = [
|
|
40975
|
-
...this.#entries,
|
|
40976
|
-
{
|
|
40977
|
-
increment: { ...increment, text: remaining.slice(0, AGENT_EVENT_TEXT_MAXIMUM_LENGTH) },
|
|
40978
|
-
kind: "narration"
|
|
40979
|
-
}
|
|
40980
|
-
];
|
|
40981
|
-
remaining = remaining.slice(AGENT_EVENT_TEXT_MAXIMUM_LENGTH);
|
|
40982
|
-
}
|
|
40983
|
-
this.schedule();
|
|
40984
|
-
return Promise.resolve();
|
|
40985
|
-
};
|
|
40986
|
-
recordText = (text2, messageId) => {
|
|
40987
|
-
if (text2.length === 0) {
|
|
40988
|
-
return Promise.resolve();
|
|
40989
|
-
}
|
|
40990
|
-
let remaining = text2;
|
|
40991
|
-
while (remaining.length > 0) {
|
|
40992
|
-
const latest = this.#entries.at(-1);
|
|
40993
|
-
if (latest?.kind === "text" && latest.messageId === messageId) {
|
|
40994
|
-
const available = AGENT_EVENT_TEXT_MAXIMUM_LENGTH - latest.text.length;
|
|
40995
|
-
if (available > 0) {
|
|
40996
|
-
this.#entries = [
|
|
40997
|
-
...this.#entries.slice(0, -1),
|
|
40998
|
-
{ ...latest, text: `${latest.text}${remaining.slice(0, available)}` }
|
|
40999
|
-
];
|
|
41000
|
-
remaining = remaining.slice(available);
|
|
41001
|
-
continue;
|
|
41002
|
-
}
|
|
41003
|
-
}
|
|
41004
|
-
this.#entries = [
|
|
41005
|
-
...this.#entries,
|
|
41006
|
-
{
|
|
41007
|
-
kind: "text",
|
|
41008
|
-
messageId,
|
|
41009
|
-
text: remaining.slice(0, AGENT_EVENT_TEXT_MAXIMUM_LENGTH)
|
|
41010
|
-
}
|
|
41011
|
-
];
|
|
41012
|
-
remaining = remaining.slice(AGENT_EVENT_TEXT_MAXIMUM_LENGTH);
|
|
41013
|
-
}
|
|
41014
|
-
this.schedule();
|
|
41015
|
-
return Promise.resolve();
|
|
41016
|
-
};
|
|
41017
|
-
schedule() {
|
|
41018
|
-
this.#scheduled ??= this.#timer.schedule(this.flush, AGENT_EVENT_COALESCING_MILLISECONDS);
|
|
41019
|
-
}
|
|
41020
|
-
};
|
|
41021
|
-
|
|
41022
41000
|
// src/daemon-prompt-executor.ts
|
|
41023
41001
|
function daemonActivity(command, activity2) {
|
|
41024
41002
|
return {
|
|
@@ -41041,7 +41019,6 @@ function daemonActivity(command, activity2) {
|
|
|
41041
41019
|
}
|
|
41042
41020
|
async function executePrompt({
|
|
41043
41021
|
operations,
|
|
41044
|
-
publisher,
|
|
41045
41022
|
eventLogV2,
|
|
41046
41023
|
command,
|
|
41047
41024
|
config: config2,
|
|
@@ -41051,36 +41028,11 @@ async function executePrompt({
|
|
|
41051
41028
|
attemptId,
|
|
41052
41029
|
activateAttempt,
|
|
41053
41030
|
waitForSessionAvailability,
|
|
41054
|
-
timer,
|
|
41055
41031
|
signal,
|
|
41056
|
-
|
|
41032
|
+
recordTurnEvent,
|
|
41057
41033
|
recordSteeringPrompt,
|
|
41058
41034
|
cancellationRequested
|
|
41059
41035
|
}) {
|
|
41060
|
-
const events = new CoalescingAgentEventPublisher(timer, (event) => {
|
|
41061
|
-
if (event.kind === "text") {
|
|
41062
|
-
publisher.publish(
|
|
41063
|
-
command.sessionId,
|
|
41064
|
-
recordLiveEvent({ kind: AGENT_MESSAGE_DELTA_KIND, messageId: event.messageId, text: event.text })
|
|
41065
|
-
);
|
|
41066
|
-
return;
|
|
41067
|
-
}
|
|
41068
|
-
if (event.kind === "narration") {
|
|
41069
|
-
const recorded = {
|
|
41070
|
-
activityId: event.increment.activityId,
|
|
41071
|
-
activityType: event.increment.activityType,
|
|
41072
|
-
commandId: command.commandId,
|
|
41073
|
-
kind: AGENT_ACTIVITY_NARRATION_KIND,
|
|
41074
|
-
sequence: event.increment.sequence,
|
|
41075
|
-
sessionId: command.sessionId,
|
|
41076
|
-
text: event.increment.text
|
|
41077
|
-
};
|
|
41078
|
-
publisher.publish(command.sessionId, recordLiveEvent(recorded));
|
|
41079
|
-
return;
|
|
41080
|
-
}
|
|
41081
|
-
const activity2 = daemonActivity(command, event.activity);
|
|
41082
|
-
publisher.publish(command.sessionId, recordLiveEvent(activity2));
|
|
41083
|
-
});
|
|
41084
41036
|
try {
|
|
41085
41037
|
const resolved = await resolveSessionDirectories(
|
|
41086
41038
|
directories,
|
|
@@ -41148,33 +41100,6 @@ async function executePrompt({
|
|
|
41148
41100
|
}
|
|
41149
41101
|
const stream = activateAttempt();
|
|
41150
41102
|
const lifecycleV2 = eventLogV2.started(command.sessionId, command.commandId, attemptId, stream.epoch);
|
|
41151
|
-
if (!prepared.prompted) {
|
|
41152
|
-
const listing = await directories.list(config2.bindingId, command.directoryId, signal);
|
|
41153
|
-
publisher.publish(command.sessionId, {
|
|
41154
|
-
additionalDirectories: resolved.additionalDirectoryEntries,
|
|
41155
|
-
agentId: command.agentId,
|
|
41156
|
-
agentName: prepared.agentName,
|
|
41157
|
-
agentVersion: prepared.agentVersion,
|
|
41158
|
-
capabilities: prepared.capabilities,
|
|
41159
|
-
commands: prepared.commands,
|
|
41160
|
-
configOptions: prepared.configOptions,
|
|
41161
|
-
directoryId: command.directoryId,
|
|
41162
|
-
directoryLabel: listing.directoryLabel,
|
|
41163
|
-
kind: SESSION_READY_KIND,
|
|
41164
|
-
requestId: command.commandId,
|
|
41165
|
-
restored: prepared.restored,
|
|
41166
|
-
sessionId: command.sessionId
|
|
41167
|
-
});
|
|
41168
|
-
}
|
|
41169
|
-
publisher.publish(command.sessionId, {
|
|
41170
|
-
commandId: command.commandId,
|
|
41171
|
-
epoch: stream.epoch,
|
|
41172
|
-
kind: SESSION_STARTED_KIND,
|
|
41173
|
-
attemptId,
|
|
41174
|
-
prompt: command.prompt,
|
|
41175
|
-
sequence: stream.sequence,
|
|
41176
|
-
sessionId: command.sessionId
|
|
41177
|
-
});
|
|
41178
41103
|
const attachments = await resolvePromptArtifacts(config2, command, signal);
|
|
41179
41104
|
let stopReason;
|
|
41180
41105
|
if (availability.disposition === SessionPromptDisposition.Steer) {
|
|
@@ -41201,9 +41126,20 @@ async function executePrompt({
|
|
|
41201
41126
|
disposition: availability.disposition,
|
|
41202
41127
|
images: attachments.images,
|
|
41203
41128
|
lifecycleV2,
|
|
41204
|
-
onActivity:
|
|
41205
|
-
|
|
41206
|
-
|
|
41129
|
+
onActivity: async (activity2) => {
|
|
41130
|
+
recordTurnEvent(daemonActivity(command, activity2));
|
|
41131
|
+
},
|
|
41132
|
+
onNarration: async (increment) => {
|
|
41133
|
+
recordTurnEvent({
|
|
41134
|
+
...increment,
|
|
41135
|
+
commandId: command.commandId,
|
|
41136
|
+
sessionId: command.sessionId,
|
|
41137
|
+
kind: AGENT_ACTIVITY_NARRATION_KIND
|
|
41138
|
+
});
|
|
41139
|
+
},
|
|
41140
|
+
onText: async (text2, messageId) => {
|
|
41141
|
+
recordTurnEvent({ kind: AGENT_MESSAGE_DELTA_KIND, text: text2, messageId });
|
|
41142
|
+
},
|
|
41207
41143
|
prompt: command.prompt,
|
|
41208
41144
|
resources: attachments.resources,
|
|
41209
41145
|
sessionId: command.sessionId,
|
|
@@ -41212,14 +41148,7 @@ async function executePrompt({
|
|
|
41212
41148
|
});
|
|
41213
41149
|
stopReason = result.stopReason;
|
|
41214
41150
|
}
|
|
41215
|
-
|
|
41216
|
-
publisher.publish(command.sessionId, {
|
|
41217
|
-
commandId: command.commandId,
|
|
41218
|
-
kind: SESSION_COMPLETED_KIND,
|
|
41219
|
-
sessionId: command.sessionId,
|
|
41220
|
-
stopReason
|
|
41221
|
-
});
|
|
41222
|
-
eventLogV2.completed(command.sessionId, command.commandId, stopReason);
|
|
41151
|
+
await eventLogV2.completed(command.sessionId, command.commandId, stopReason);
|
|
41223
41152
|
operations.transitionExecution(command.commandId, stopReason === "cancelled" ? "cancelled" : "succeeded");
|
|
41224
41153
|
audit.record({
|
|
41225
41154
|
commandId: command.commandId,
|
|
@@ -41227,15 +41156,8 @@ async function executePrompt({
|
|
|
41227
41156
|
sessionId: command.sessionId
|
|
41228
41157
|
});
|
|
41229
41158
|
} catch (error62) {
|
|
41230
|
-
events.flush();
|
|
41231
41159
|
if (signal.aborted && cancellationRequested()) {
|
|
41232
|
-
|
|
41233
|
-
commandId: command.commandId,
|
|
41234
|
-
kind: SESSION_COMPLETED_KIND,
|
|
41235
|
-
sessionId: command.sessionId,
|
|
41236
|
-
stopReason: "cancelled"
|
|
41237
|
-
});
|
|
41238
|
-
eventLogV2.completed(command.sessionId, command.commandId, "cancelled");
|
|
41160
|
+
await eventLogV2.completed(command.sessionId, command.commandId, "cancelled");
|
|
41239
41161
|
operations.transitionExecution(command.commandId, "cancelled");
|
|
41240
41162
|
audit.record({
|
|
41241
41163
|
commandId: command.commandId,
|
|
@@ -41252,8 +41174,7 @@ async function executePrompt({
|
|
|
41252
41174
|
const code = operationErrorCode(error62);
|
|
41253
41175
|
const failureCode = code === "session_operation_failed" ? "agent_execution_failed" : code;
|
|
41254
41176
|
const failureMessage = code === "session_operation_failed" ? "The local agent could not complete the request" : operationErrorMessage(error62);
|
|
41255
|
-
eventLogV2.failed(command.sessionId, command.commandId, failureCode, failureMessage);
|
|
41256
|
-
reportFailure(publisher, command, failureCode, failureMessage);
|
|
41177
|
+
await eventLogV2.failed(command.sessionId, command.commandId, failureCode, failureMessage);
|
|
41257
41178
|
operations.transitionExecution(command.commandId, "failed");
|
|
41258
41179
|
console.error("Mobius daemon command failed", error62);
|
|
41259
41180
|
}
|
|
@@ -41281,7 +41202,7 @@ async function executeWorkspaceList(socket, command, directories, audit, signal)
|
|
|
41281
41202
|
reportOperationFailure(socket, command.requestId, "", error62);
|
|
41282
41203
|
}
|
|
41283
41204
|
}
|
|
41284
|
-
async function executeSessionPrepare(
|
|
41205
|
+
async function executeSessionPrepare(socket, command, config2, directories, audit, sessions, diagnostics, signal) {
|
|
41285
41206
|
const metrics = new AccumulatingOperationMetrics();
|
|
41286
41207
|
try {
|
|
41287
41208
|
const readyEvent = await metrics.measure("prepare-total", async () => {
|
|
@@ -41331,12 +41252,6 @@ async function executeSessionPrepare(publisher, socket, command, config2, direct
|
|
|
41331
41252
|
event: "session_configured",
|
|
41332
41253
|
sessionId: command.sessionId
|
|
41333
41254
|
});
|
|
41334
|
-
publisher.publish(command.sessionId, {
|
|
41335
|
-
configOptions,
|
|
41336
|
-
kind: "session.config.updated",
|
|
41337
|
-
requestId: command.requestId,
|
|
41338
|
-
sessionId: command.sessionId
|
|
41339
|
-
});
|
|
41340
41255
|
}
|
|
41341
41256
|
const event = {
|
|
41342
41257
|
additionalDirectories: resolved.additionalDirectoryEntries,
|
|
@@ -41354,11 +41269,6 @@ async function executeSessionPrepare(publisher, socket, command, config2, direct
|
|
|
41354
41269
|
sessionId: command.sessionId,
|
|
41355
41270
|
runtimeTimings: metrics.snapshot()
|
|
41356
41271
|
};
|
|
41357
|
-
if (command.transient !== true) {
|
|
41358
|
-
metrics.measureSync("readiness-commit", () => {
|
|
41359
|
-
publisher.publish(command.sessionId, event);
|
|
41360
|
-
});
|
|
41361
|
-
}
|
|
41362
41272
|
return event;
|
|
41363
41273
|
});
|
|
41364
41274
|
send(socket, {
|
|
@@ -41388,7 +41298,7 @@ async function executeSessionPrepare(publisher, socket, command, config2, direct
|
|
|
41388
41298
|
reportOperationFailure(socket, command.requestId, command.sessionId, error62, metrics.snapshot());
|
|
41389
41299
|
}
|
|
41390
41300
|
}
|
|
41391
|
-
async function executeSessionConfigure(
|
|
41301
|
+
async function executeSessionConfigure(socket, command, config2, directories, audit, sessions, signal) {
|
|
41392
41302
|
try {
|
|
41393
41303
|
const resolved = await resolveSessionDirectories(
|
|
41394
41304
|
directories,
|
|
@@ -41414,7 +41324,7 @@ async function executeSessionConfigure(publisher, socket, command, config2, dire
|
|
|
41414
41324
|
event: "session_configured",
|
|
41415
41325
|
sessionId: command.sessionId
|
|
41416
41326
|
});
|
|
41417
|
-
|
|
41327
|
+
send(socket, {
|
|
41418
41328
|
configOptions,
|
|
41419
41329
|
kind: "session.config.updated",
|
|
41420
41330
|
requestId: command.requestId,
|
|
@@ -41534,7 +41444,6 @@ function createDaemonCommandHandler({
|
|
|
41534
41444
|
installations,
|
|
41535
41445
|
nativeSessions,
|
|
41536
41446
|
operations,
|
|
41537
|
-
publisher,
|
|
41538
41447
|
eventLogV2,
|
|
41539
41448
|
externalContent,
|
|
41540
41449
|
activeTurns,
|
|
@@ -41555,8 +41464,9 @@ function createDaemonCommandHandler({
|
|
|
41555
41464
|
timer
|
|
41556
41465
|
});
|
|
41557
41466
|
const queueChanged = (sessionId) => {
|
|
41558
|
-
|
|
41559
|
-
|
|
41467
|
+
void eventLogV2.queueChanged(sessionId).catch((error62) => {
|
|
41468
|
+
console.error("Could not record queue change", error62);
|
|
41469
|
+
});
|
|
41560
41470
|
};
|
|
41561
41471
|
const nativeRequestHandler = createNativeSessionRequestHandler({
|
|
41562
41472
|
audit,
|
|
@@ -41625,7 +41535,9 @@ function createDaemonCommandHandler({
|
|
|
41625
41535
|
const cancellation = message;
|
|
41626
41536
|
const turn2 = activeTurns.get(cancellation.commandId);
|
|
41627
41537
|
if (turn2 === void 0 || !turn2.matches(cancellation)) {
|
|
41628
|
-
settleAbandonedTurn(
|
|
41538
|
+
void settleAbandonedTurn(eventLogV2, operations, audit, cancellation).catch((error62) => {
|
|
41539
|
+
console.error("Could not settle abandoned turn", error62);
|
|
41540
|
+
});
|
|
41629
41541
|
return;
|
|
41630
41542
|
}
|
|
41631
41543
|
const cancellationState = turn2.requestCancellation();
|
|
@@ -41665,22 +41577,12 @@ function createDaemonCommandHandler({
|
|
|
41665
41577
|
}
|
|
41666
41578
|
if (kind === SESSION_PREPARE_KIND) {
|
|
41667
41579
|
const command2 = message;
|
|
41668
|
-
void executeSessionPrepare(
|
|
41669
|
-
publisher,
|
|
41670
|
-
socket,
|
|
41671
|
-
command2,
|
|
41672
|
-
config2,
|
|
41673
|
-
directories,
|
|
41674
|
-
audit,
|
|
41675
|
-
sessions,
|
|
41676
|
-
diagnostics,
|
|
41677
|
-
signal
|
|
41678
|
-
);
|
|
41580
|
+
void executeSessionPrepare(socket, command2, config2, directories, audit, sessions, diagnostics, signal);
|
|
41679
41581
|
return;
|
|
41680
41582
|
}
|
|
41681
41583
|
if (kind === SESSION_CONFIGURE_KIND) {
|
|
41682
41584
|
const command2 = message;
|
|
41683
|
-
void executeSessionConfigure(
|
|
41585
|
+
void executeSessionConfigure(socket, command2, config2, directories, audit, sessions, signal);
|
|
41684
41586
|
return;
|
|
41685
41587
|
}
|
|
41686
41588
|
if (kind === SESSION_LIST_KIND) {
|
|
@@ -41782,7 +41684,6 @@ function createDaemonCommandHandler({
|
|
|
41782
41684
|
eventLogV2.requested(command);
|
|
41783
41685
|
void executePrompt({
|
|
41784
41686
|
operations,
|
|
41785
|
-
publisher,
|
|
41786
41687
|
eventLogV2,
|
|
41787
41688
|
command,
|
|
41788
41689
|
config: config2,
|
|
@@ -41799,15 +41700,15 @@ function createDaemonCommandHandler({
|
|
|
41799
41700
|
sessionId: command.sessionId
|
|
41800
41701
|
});
|
|
41801
41702
|
}),
|
|
41802
|
-
timer,
|
|
41803
41703
|
signal: turn.signal,
|
|
41804
|
-
|
|
41704
|
+
recordTurnEvent: turn.recordEvent,
|
|
41805
41705
|
recordSteeringPrompt: () => activeTurns.recordSteeringPrompt(command),
|
|
41806
41706
|
cancellationRequested: turn.cancellationRequested
|
|
41807
41707
|
}).catch((error62) => {
|
|
41808
41708
|
console.error("Mobius daemon turn failed", error62);
|
|
41809
41709
|
}).finally(() => {
|
|
41810
41710
|
activeTurns.finish(turn);
|
|
41711
|
+
eventLogV2.publishTerminal(command.sessionId, command.commandId);
|
|
41811
41712
|
if (command.disposition === SessionPromptDisposition.Queue) {
|
|
41812
41713
|
queueChanged(command.sessionId);
|
|
41813
41714
|
}
|
|
@@ -41941,7 +41842,7 @@ function connectRelay(url2, signal) {
|
|
|
41941
41842
|
}
|
|
41942
41843
|
|
|
41943
41844
|
// src/relay-connection/liveness.ts
|
|
41944
|
-
import { randomUUID as
|
|
41845
|
+
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
41945
41846
|
var HEARTBEAT_ACK_TIMEOUT_MILLISECONDS = 1e4;
|
|
41946
41847
|
var HEARTBEAT_INTERVAL_MILLISECONDS = 2e4;
|
|
41947
41848
|
var RelayLivenessState = class {
|
|
@@ -42030,7 +41931,7 @@ var RelayConnectionLiveness = class {
|
|
|
42030
41931
|
}
|
|
42031
41932
|
throw new Error("Heartbeat was scheduled in an invalid state");
|
|
42032
41933
|
}
|
|
42033
|
-
const heartbeatId =
|
|
41934
|
+
const heartbeatId = randomUUID7();
|
|
42034
41935
|
this.#state = new AwaitingHeartbeatAckState(
|
|
42035
41936
|
heartbeatId,
|
|
42036
41937
|
this.#timer.schedule(this.#handleTimeout, HEARTBEAT_ACK_TIMEOUT_MILLISECONDS)
|
|
@@ -42091,7 +41992,6 @@ async function runRelayConnection({
|
|
|
42091
41992
|
installations,
|
|
42092
41993
|
nativeSessions,
|
|
42093
41994
|
operations,
|
|
42094
|
-
publisher,
|
|
42095
41995
|
eventLogV2,
|
|
42096
41996
|
externalContent,
|
|
42097
41997
|
activeTurns,
|
|
@@ -42256,51 +42156,17 @@ var DaemonSessionEventPublisher = class {
|
|
|
42256
42156
|
close = () => {
|
|
42257
42157
|
this.#socket = null;
|
|
42258
42158
|
};
|
|
42259
|
-
|
|
42260
|
-
|
|
42261
|
-
if (socket === null || socket.readyState !== WebSocket8.OPEN) {
|
|
42262
|
-
return;
|
|
42263
|
-
}
|
|
42264
|
-
const encoded = encodeDaemonToServiceMessage({
|
|
42265
|
-
kind: SESSION_EVENT_KIND,
|
|
42266
|
-
payload: encodeRecordedSessionEvent(event),
|
|
42267
|
-
sessionId
|
|
42268
|
-
});
|
|
42269
|
-
if (socket.bufferedAmount + Buffer.byteLength(encoded, "utf8") > MAX_BUFFERED_BYTES) {
|
|
42270
|
-
socket.close(1013, "Live event transport overloaded");
|
|
42271
|
-
return;
|
|
42272
|
-
}
|
|
42273
|
-
try {
|
|
42274
|
-
socket.send(encoded);
|
|
42275
|
-
} catch {
|
|
42276
|
-
}
|
|
42277
|
-
};
|
|
42278
|
-
publishBatch = (sessionId, events) => {
|
|
42279
|
-
for (const event of events) {
|
|
42280
|
-
this.publish(sessionId, event);
|
|
42281
|
-
}
|
|
42282
|
-
};
|
|
42283
|
-
publishStatus = (event) => {
|
|
42284
|
-
const socket = this.#socket;
|
|
42285
|
-
if (socket === null || socket.readyState !== WebSocket8.OPEN) {
|
|
42286
|
-
return;
|
|
42287
|
-
}
|
|
42288
|
-
const encoded = encodeDaemonToServiceMessage(event);
|
|
42289
|
-
if (socket.bufferedAmount + Buffer.byteLength(encoded, "utf8") > MAX_BUFFERED_BYTES) {
|
|
42290
|
-
socket.close(1013, "Live event transport overloaded");
|
|
42291
|
-
return;
|
|
42292
|
-
}
|
|
42293
|
-
try {
|
|
42294
|
-
socket.send(encoded);
|
|
42295
|
-
} catch {
|
|
42296
|
-
}
|
|
42159
|
+
publishOperationFailure = (sessionId, requestId, code, message) => {
|
|
42160
|
+
this.#send({ kind: "session.operation.failed", sessionId, requestId, code, message });
|
|
42297
42161
|
};
|
|
42298
|
-
|
|
42162
|
+
publishStatus = (event) => this.#send(event);
|
|
42163
|
+
publishV2 = (event) => this.#send({ event, kind: SESSION_EVENT_V2_KIND });
|
|
42164
|
+
#send = (message) => {
|
|
42299
42165
|
const socket = this.#socket;
|
|
42300
42166
|
if (socket === null || socket.readyState !== WebSocket8.OPEN) {
|
|
42301
42167
|
return;
|
|
42302
42168
|
}
|
|
42303
|
-
const encoded = encodeDaemonToServiceMessage(
|
|
42169
|
+
const encoded = encodeDaemonToServiceMessage(message);
|
|
42304
42170
|
if (socket.bufferedAmount + Buffer.byteLength(encoded, "utf8") > MAX_BUFFERED_BYTES) {
|
|
42305
42171
|
socket.close(1013, "Live event transport overloaded");
|
|
42306
42172
|
return;
|
|
@@ -42322,7 +42188,7 @@ var SystemDaemonTimer = class {
|
|
|
42322
42188
|
var systemDaemonTimer = new SystemDaemonTimer();
|
|
42323
42189
|
|
|
42324
42190
|
// src/session-event-log-v2.ts
|
|
42325
|
-
import { createHash as createHash6, randomUUID as
|
|
42191
|
+
import { createHash as createHash6, randomUUID as randomUUID8 } from "node:crypto";
|
|
42326
42192
|
function promptContent(command) {
|
|
42327
42193
|
const content = [];
|
|
42328
42194
|
if (command.prompt.length > 0) {
|
|
@@ -42346,7 +42212,7 @@ function promptContent(command) {
|
|
|
42346
42212
|
}
|
|
42347
42213
|
return content;
|
|
42348
42214
|
}
|
|
42349
|
-
function
|
|
42215
|
+
function sessionEventV22(daemonGenerationId, sessionId, position, event, recordedAt) {
|
|
42350
42216
|
const sessionPrefix = createHash6("sha256").update(sessionId).digest("hex").slice(0, 16);
|
|
42351
42217
|
return {
|
|
42352
42218
|
eventId: `event-${daemonGenerationId}-${sessionPrefix}-${position.toString().padStart(16, "0")}`,
|
|
@@ -42358,46 +42224,116 @@ function sessionEventV2(daemonGenerationId, sessionId, position, event, recorded
|
|
|
42358
42224
|
};
|
|
42359
42225
|
}
|
|
42360
42226
|
var DaemonSessionEventLogV2 = class {
|
|
42361
|
-
daemonGenerationId
|
|
42227
|
+
daemonGenerationId;
|
|
42362
42228
|
#publisher;
|
|
42229
|
+
#terminal = /* @__PURE__ */ new Map();
|
|
42230
|
+
#publications = /* @__PURE__ */ new Map();
|
|
42363
42231
|
#queued = /* @__PURE__ */ new Map();
|
|
42364
|
-
|
|
42232
|
+
#recordLifecycle;
|
|
42233
|
+
constructor(publisher, recordLifecycle, daemonGenerationId = randomUUID8()) {
|
|
42234
|
+
this.#recordLifecycle = recordLifecycle;
|
|
42365
42235
|
this.#publisher = publisher;
|
|
42236
|
+
this.daemonGenerationId = daemonGenerationId;
|
|
42366
42237
|
}
|
|
42367
42238
|
requested = (command) => {
|
|
42368
42239
|
this.#queued.set(command.commandId, {
|
|
42369
42240
|
commandId: command.commandId,
|
|
42370
42241
|
content: promptContent(command),
|
|
42242
|
+
context: {
|
|
42243
|
+
agentId: command.agentId,
|
|
42244
|
+
directoryId: command.directoryId,
|
|
42245
|
+
additionalDirectoryIds: command.additionalDirectoryIds
|
|
42246
|
+
},
|
|
42247
|
+
phase: "queued",
|
|
42371
42248
|
sessionId: command.sessionId
|
|
42372
42249
|
});
|
|
42373
42250
|
};
|
|
42374
42251
|
started = (sessionId, commandId, attemptId, epoch) => {
|
|
42375
42252
|
const request = this.#queued.get(commandId);
|
|
42376
42253
|
if (request?.sessionId === sessionId) {
|
|
42377
|
-
this.#queued.
|
|
42378
|
-
return { attemptId, content: request.content, epoch };
|
|
42254
|
+
this.#queued.set(commandId, { ...request, phase: "running" });
|
|
42255
|
+
return { attemptId, content: request.content, epoch, context: request.context };
|
|
42379
42256
|
}
|
|
42380
42257
|
throw new Error("The executing prompt was not registered in the V2 queue");
|
|
42381
42258
|
};
|
|
42382
42259
|
record = (sessionId, event, position) => {
|
|
42383
|
-
this
|
|
42260
|
+
const recorded = this.event(sessionId, position, event, (/* @__PURE__ */ new Date()).toISOString());
|
|
42261
|
+
if (event.type === "lifecycle-metadata" && (event.payload.kind === "prompt.completed" || event.payload.kind === "prompt.failed" || event.payload.kind === "prompt.failed-before-start")) {
|
|
42262
|
+
this.#terminal.set(event.payload.commandId, recorded);
|
|
42263
|
+
const pending2 = this.#publications.get(sessionId) ?? [];
|
|
42264
|
+
pending2.push(recorded);
|
|
42265
|
+
this.#publications.set(sessionId, pending2);
|
|
42266
|
+
return;
|
|
42267
|
+
}
|
|
42268
|
+
const pending = this.#publications.get(sessionId);
|
|
42269
|
+
if (pending !== void 0) {
|
|
42270
|
+
pending.push(recorded);
|
|
42271
|
+
} else {
|
|
42272
|
+
this.#publisher.publishV2(recorded);
|
|
42273
|
+
}
|
|
42274
|
+
};
|
|
42275
|
+
publishTerminal = (sessionId, commandId) => {
|
|
42276
|
+
const event = this.#terminal.get(commandId);
|
|
42277
|
+
if (event?.sessionId === sessionId) {
|
|
42278
|
+
this.#terminal.delete(commandId);
|
|
42279
|
+
const pending = this.#publications.get(sessionId) ?? [];
|
|
42280
|
+
while (pending.length > 0) {
|
|
42281
|
+
const next = pending[0];
|
|
42282
|
+
if (next === void 0) {
|
|
42283
|
+
break;
|
|
42284
|
+
}
|
|
42285
|
+
if (next.type === "lifecycle-metadata" && "commandId" in next.payload && this.#terminal.has(next.payload.commandId)) {
|
|
42286
|
+
break;
|
|
42287
|
+
}
|
|
42288
|
+
pending.shift();
|
|
42289
|
+
this.#publisher.publishV2(next);
|
|
42290
|
+
}
|
|
42291
|
+
if (pending.length === 0) {
|
|
42292
|
+
this.#publications.delete(sessionId);
|
|
42293
|
+
}
|
|
42294
|
+
}
|
|
42295
|
+
this.#queued.delete(commandId);
|
|
42384
42296
|
};
|
|
42385
|
-
event = (sessionId, position, event, recordedAt) =>
|
|
42386
|
-
queueChanged = (
|
|
42387
|
-
|
|
42297
|
+
event = (sessionId, position, event, recordedAt) => sessionEventV22(this.daemonGenerationId, sessionId, position, event, recordedAt);
|
|
42298
|
+
queueChanged = async (sessionId) => {
|
|
42299
|
+
await this.#recordLifecycle(sessionId, {
|
|
42300
|
+
type: "lifecycle-metadata",
|
|
42301
|
+
payload: { kind: "session.queue.changed" }
|
|
42302
|
+
});
|
|
42303
|
+
};
|
|
42304
|
+
completed = async (sessionId, commandId, stopReason) => {
|
|
42388
42305
|
const request = this.#queued.get(commandId);
|
|
42389
|
-
if (request?.sessionId
|
|
42390
|
-
|
|
42306
|
+
if (request?.sessionId !== sessionId || this.#terminal.has(commandId)) {
|
|
42307
|
+
return;
|
|
42308
|
+
}
|
|
42309
|
+
const recorded = await this.#recordLifecycle(sessionId, {
|
|
42310
|
+
type: "lifecycle-metadata",
|
|
42311
|
+
payload: { kind: "prompt.completed", commandId, stopReason }
|
|
42312
|
+
});
|
|
42313
|
+
if (!recorded) {
|
|
42314
|
+
this.#publisher.publishOperationFailure(
|
|
42315
|
+
sessionId,
|
|
42316
|
+
commandId,
|
|
42317
|
+
"cancelled",
|
|
42318
|
+
"The prompt was cancelled before execution"
|
|
42319
|
+
);
|
|
42391
42320
|
}
|
|
42392
42321
|
};
|
|
42393
|
-
failed = (sessionId, commandId,
|
|
42322
|
+
failed = async (sessionId, commandId, code, message) => {
|
|
42394
42323
|
const request = this.#queued.get(commandId);
|
|
42395
|
-
if (request?.sessionId
|
|
42396
|
-
|
|
42324
|
+
if (request?.sessionId !== sessionId || this.#terminal.has(commandId)) {
|
|
42325
|
+
return;
|
|
42326
|
+
}
|
|
42327
|
+
const recorded = await this.#recordLifecycle(sessionId, {
|
|
42328
|
+
type: "lifecycle-metadata",
|
|
42329
|
+
payload: { kind: "prompt.failed-before-start", commandId, code, message }
|
|
42330
|
+
});
|
|
42331
|
+
if (!recorded) {
|
|
42332
|
+
this.#publisher.publishOperationFailure(sessionId, commandId, code, message);
|
|
42397
42333
|
}
|
|
42398
42334
|
};
|
|
42399
42335
|
promptRequestRecovery = (sessionId) => ({
|
|
42400
|
-
queuedPromptRequests: [...this.#queued.values()].filter((request) => request.sessionId === sessionId).map(({ commandId, content }) => ({ commandId, content }))
|
|
42336
|
+
queuedPromptRequests: [...this.#queued.values()].filter((request) => request.sessionId === sessionId && request.phase === "queued").map(({ commandId, content }) => ({ commandId, content }))
|
|
42401
42337
|
});
|
|
42402
42338
|
};
|
|
42403
42339
|
|
|
@@ -42449,7 +42385,7 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
|
|
|
42449
42385
|
{
|
|
42450
42386
|
agentId: agent.id,
|
|
42451
42387
|
kind: AGENT_INSTALL_REQUEST_KIND,
|
|
42452
|
-
requestId: `automatic-integration-${
|
|
42388
|
+
requestId: `automatic-integration-${randomUUID9()}`
|
|
42453
42389
|
},
|
|
42454
42390
|
signal
|
|
42455
42391
|
);
|
|
@@ -42467,19 +42403,33 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
42467
42403
|
publishCatalog: async (installationSignal) => await publishAgentCatalog(config2, installationSignal),
|
|
42468
42404
|
stateDirectory
|
|
42469
42405
|
});
|
|
42470
|
-
const
|
|
42471
|
-
|
|
42472
|
-
);
|
|
42406
|
+
const channelHash = createHash7("sha256").update(config2.channelId).digest("hex");
|
|
42407
|
+
const daemonGenerationId = randomUUID9();
|
|
42408
|
+
const sessionDatabase = openAcpSessionDatabase(join18(stateDirectory, "sessions", `${channelHash}.sqlite`));
|
|
42409
|
+
let eventsV2;
|
|
42410
|
+
try {
|
|
42411
|
+
eventsV2 = new CachedAcpSessionEventStoreV2(
|
|
42412
|
+
openSessionEventCacheV2Database(join18(stateDirectory, "sessions", `${channelHash}.events.sqlite`)),
|
|
42413
|
+
daemonGenerationId
|
|
42414
|
+
);
|
|
42415
|
+
} catch (error62) {
|
|
42416
|
+
sessionDatabase.close();
|
|
42417
|
+
throw error62;
|
|
42418
|
+
}
|
|
42419
|
+
const sessionStore = new SqliteAcpSessionStore(sessionDatabase, eventsV2);
|
|
42473
42420
|
await using externalContent = new LocalExternalContentStore(stateDirectory);
|
|
42474
42421
|
const operations = new DaemonOperationState();
|
|
42475
42422
|
const publisher = new DaemonSessionEventPublisher();
|
|
42476
|
-
const eventLogV2 = new DaemonSessionEventLogV2(
|
|
42423
|
+
const eventLogV2 = new DaemonSessionEventLogV2(
|
|
42424
|
+
publisher,
|
|
42425
|
+
(sessionId, event) => agentRuntime.recordLifecycleEventV2(sessionId, event),
|
|
42426
|
+
daemonGenerationId
|
|
42427
|
+
);
|
|
42477
42428
|
const activeTurns = new DaemonTurnRegistry(operations);
|
|
42478
|
-
const recordSessionEvent = (sessionId, event) => {
|
|
42479
|
-
publisher.publish(sessionId, activeTurns.recordEvent(event));
|
|
42480
|
-
};
|
|
42481
42429
|
const agentRuntime = new AgentRuntimeManager(
|
|
42482
|
-
new DaemonAcpObserver(
|
|
42430
|
+
new DaemonAcpObserver((_sessionId, event) => {
|
|
42431
|
+
activeTurns.recordEvent(event);
|
|
42432
|
+
}, eventLogV2.record),
|
|
42483
42433
|
sessionStore,
|
|
42484
42434
|
{
|
|
42485
42435
|
read: async (options2, nativeSessionId, nativeTurn) => options2.agent.id === "codex" ? (await readCodexFullHistory(
|
|
@@ -42519,7 +42469,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
42519
42469
|
options2.signal
|
|
42520
42470
|
);
|
|
42521
42471
|
return cwd === options2.cwd && additionalDirectories.length === options2.additionalDirectories.length && additionalDirectories.every(
|
|
42522
|
-
(directory,
|
|
42472
|
+
(directory, index2) => directory === options2.additionalDirectories[index2]
|
|
42523
42473
|
);
|
|
42524
42474
|
});
|
|
42525
42475
|
}
|
|
@@ -42664,7 +42614,7 @@ import { basename as basename6, resolve as resolve7 } from "node:path";
|
|
|
42664
42614
|
import { fetch as fetch4 } from "undici";
|
|
42665
42615
|
|
|
42666
42616
|
// src/storage/runtime-installation-store.ts
|
|
42667
|
-
import { createHash as createHash8, randomUUID as
|
|
42617
|
+
import { createHash as createHash8, randomUUID as randomUUID10 } from "node:crypto";
|
|
42668
42618
|
import { mkdir as mkdir5, open as open5, readdir as readdir4, rename as rename4, unlink, writeFile as writeFile4 } from "node:fs/promises";
|
|
42669
42619
|
import { dirname as dirname6, join as join19, resolve as resolve6 } from "node:path";
|
|
42670
42620
|
var APPLICATION_ID_PATTERN = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+){1,31}$/;
|
|
@@ -42794,10 +42744,10 @@ function parseRelayOrigin(value) {
|
|
|
42794
42744
|
return origin;
|
|
42795
42745
|
}
|
|
42796
42746
|
function connectionId() {
|
|
42797
|
-
return `mcn_${
|
|
42747
|
+
return `mcn_${randomUUID10().replaceAll("-", "")}`;
|
|
42798
42748
|
}
|
|
42799
42749
|
function installationId() {
|
|
42800
|
-
return `min_${
|
|
42750
|
+
return `min_${randomUUID10().replaceAll("-", "")}`;
|
|
42801
42751
|
}
|
|
42802
42752
|
function channelIndexFileName(channelId) {
|
|
42803
42753
|
return `mci_${createHash8("sha256").update(channelId).digest("hex")}.json`;
|
|
@@ -42909,7 +42859,7 @@ async function readJsonFile(path2, signal, missingCode) {
|
|
|
42909
42859
|
async function writeJsonAtomically(path2, value, signal) {
|
|
42910
42860
|
signal.throwIfAborted();
|
|
42911
42861
|
const directory = dirname6(path2);
|
|
42912
|
-
const temporaryPath = join19(directory, `.${
|
|
42862
|
+
const temporaryPath = join19(directory, `.${randomUUID10()}.tmp`);
|
|
42913
42863
|
try {
|
|
42914
42864
|
await mkdir5(directory, { mode: 448, recursive: true });
|
|
42915
42865
|
signal.throwIfAborted();
|
|
@@ -42986,16 +42936,16 @@ var RuntimeInstallationStore = class _RuntimeInstallationStore {
|
|
|
42986
42936
|
};
|
|
42987
42937
|
#readConnectionForChannel = async (channelId, signal) => {
|
|
42988
42938
|
const normalizedChannelId = validateIdentifier(channelId, "invalid_channel_id");
|
|
42989
|
-
const
|
|
42939
|
+
const index2 = decodeChannelIndex(
|
|
42990
42940
|
await readJsonFile(this.channelIndexPath(normalizedChannelId), signal, "connection_not_found")
|
|
42991
42941
|
);
|
|
42992
|
-
if (
|
|
42942
|
+
if (index2.applicationId !== this.applicationId || index2.installationId !== this.installationId || index2.channelId !== normalizedChannelId) {
|
|
42993
42943
|
throw new RuntimeInstallationStoreError(
|
|
42994
42944
|
"connection_owner_mismatch",
|
|
42995
42945
|
"The saved Runtime connection belongs to another installation"
|
|
42996
42946
|
);
|
|
42997
42947
|
}
|
|
42998
|
-
return await this.readConnection(
|
|
42948
|
+
return await this.readConnection(index2.connectionId, signal);
|
|
42999
42949
|
};
|
|
43000
42950
|
saveConnection = async (input2, signal) => {
|
|
43001
42951
|
const stored = new VerifiedRuntimeConnection(
|