@moxt-ai/mobius 0.0.174 → 0.0.176
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 +0 -1
- package/dist/acp/agent-runtime-manager.d.ts.map +1 -1
- package/dist/acp/agent-runtime-manager.js +2 -37
- package/dist/acp/agent-runtime-manager.js.map +1 -1
- package/dist/acp/agent-session.d.ts +0 -1
- package/dist/acp/agent-session.d.ts.map +1 -1
- package/dist/acp/agent-session.js +19 -25
- package/dist/acp/agent-session.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 +8 -9
- package/dist/acp/session-store.d.ts.map +1 -1
- package/dist/acp/session-store.js +27 -109
- package/dist/acp/session-store.js.map +1 -1
- package/dist/cli.js +985 -867
- package/dist/cli.js.map +4 -4
- package/dist/daemon-command-handler.d.ts.map +1 -1
- package/dist/daemon-command-handler.js +0 -1
- package/dist/daemon-command-handler.js.map +1 -1
- package/dist/daemon-turn-registry.d.ts +13 -13
- package/dist/generated/acp-session-store-migrations.d.ts +3 -0
- package/dist/generated/acp-session-store-migrations.d.ts.map +1 -1
- package/dist/generated/acp-session-store-migrations.js +5 -1
- package/dist/generated/acp-session-store-migrations.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 +979 -862
- 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/native-sessions/handle-native-requests.d.ts +0 -2
- package/dist/native-sessions/handle-native-requests.d.ts.map +1 -1
- package/dist/native-sessions/handle-native-requests.js +1 -12
- package/dist/native-sessions/handle-native-requests.js.map +1 -1
- package/dist/native-sessions/service.d.ts.map +1 -1
- package/dist/native-sessions/service.js +0 -62
- package/dist/native-sessions/service.js.map +1 -1
- package/dist/run-daemon.d.ts.map +1 -1
- package/dist/run-daemon.js +15 -2
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.js +969 -852
- package/dist/runtime.js.map +4 -4
- package/dist/schema/acp-session-store/acp-session.d.ts +0 -16
- package/dist/schema/acp-session-store/acp-session.d.ts.map +1 -1
- package/dist/schema/acp-session-store/acp-session.js +0 -1
- package/dist/schema/acp-session-store/acp-session.js.map +1 -1
- package/dist/schema/acp-session-store/index.d.ts +0 -1
- package/dist/schema/acp-session-store/index.d.ts.map +1 -1
- package/dist/schema/acp-session-store/index.js +0 -1
- package/dist/schema/acp-session-store/index.js.map +1 -1
- 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 +2 -2
- package/dist/session-event-log-v2.d.ts.map +1 -1
- package/dist/session-event-log-v2.js +3 -2
- package/dist/session-event-log-v2.js.map +1 -1
- package/package.json +2 -1
- package/dist/schema/acp-session-store/deleted-acp-session.d.ts +0 -24
- package/dist/schema/acp-session-store/deleted-acp-session.d.ts.map +0 -1
- package/dist/schema/acp-session-store/deleted-acp-session.js +0 -5
- package/dist/schema/acp-session-store/deleted-acp-session.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);
|
|
@@ -21039,17 +21039,6 @@ var nativeSessionRequestSchema = external_exports.discriminatedUnion("action", [
|
|
|
21039
21039
|
action: external_exports.enum(["import", "fork"]),
|
|
21040
21040
|
entryId: identifierStringSchema,
|
|
21041
21041
|
targetSessionId: identifierStringSchema
|
|
21042
|
-
}).readonly(),
|
|
21043
|
-
external_exports.object({
|
|
21044
|
-
...identity,
|
|
21045
|
-
action: external_exports.literal("fork-recorded"),
|
|
21046
|
-
targetSessionId: identifierStringSchema,
|
|
21047
|
-
throughCommandId: identifierStringSchema
|
|
21048
|
-
}).readonly(),
|
|
21049
|
-
external_exports.object({
|
|
21050
|
-
...identity,
|
|
21051
|
-
action: external_exports.literal("delete"),
|
|
21052
|
-
entryId: identifierStringSchema
|
|
21053
21042
|
}).readonly()
|
|
21054
21043
|
]);
|
|
21055
21044
|
var nativeSessionCommandSchema = external_exports.discriminatedUnion("action", [
|
|
@@ -21065,17 +21054,6 @@ var nativeSessionCommandSchema = external_exports.discriminatedUnion("action", [
|
|
|
21065
21054
|
action: external_exports.enum(["import", "fork"]),
|
|
21066
21055
|
entryId: identifierStringSchema,
|
|
21067
21056
|
targetSessionId: identifierStringSchema
|
|
21068
|
-
}).readonly(),
|
|
21069
|
-
external_exports.object({
|
|
21070
|
-
...identity,
|
|
21071
|
-
action: external_exports.literal("fork-recorded"),
|
|
21072
|
-
targetSessionId: identifierStringSchema,
|
|
21073
|
-
throughCommandId: identifierStringSchema
|
|
21074
|
-
}).readonly(),
|
|
21075
|
-
external_exports.object({
|
|
21076
|
-
...identity,
|
|
21077
|
-
action: external_exports.literal("delete"),
|
|
21078
|
-
entryId: identifierStringSchema
|
|
21079
21057
|
}).readonly()
|
|
21080
21058
|
]);
|
|
21081
21059
|
var nativeSessionEntrySchema = external_exports.object({
|
|
@@ -21120,16 +21098,10 @@ var nativeSessionResultSchema = external_exports.discriminatedUnion("action", [
|
|
|
21120
21098
|
}).readonly(),
|
|
21121
21099
|
external_exports.object({
|
|
21122
21100
|
...resultEnvelope,
|
|
21123
|
-
action: external_exports.enum(["import", "fork"
|
|
21101
|
+
action: external_exports.enum(["import", "fork"]),
|
|
21124
21102
|
targetSessionId: identifierStringSchema,
|
|
21125
21103
|
ready: sessionReadyEventSchema,
|
|
21126
21104
|
title: external_exports.string().max(500)
|
|
21127
|
-
}).readonly(),
|
|
21128
|
-
external_exports.object({
|
|
21129
|
-
...resultEnvelope,
|
|
21130
|
-
action: external_exports.literal("delete"),
|
|
21131
|
-
entryId: identifierStringSchema,
|
|
21132
|
-
deletedSessionIds: external_exports.array(identifierStringSchema).max(500).readonly()
|
|
21133
21105
|
}).readonly()
|
|
21134
21106
|
]);
|
|
21135
21107
|
var nativeSessionCancelSchema = external_exports.object({ ...envelope, kind: external_exports.literal(NATIVE_SESSION_CANCEL_KIND) }).readonly();
|
|
@@ -21531,12 +21503,12 @@ var sessionExportV2Schema = external_exports.object({
|
|
|
21531
21503
|
}).readonly().superRefine((session, context) => {
|
|
21532
21504
|
let previousPosition = 0n;
|
|
21533
21505
|
const eventIds = /* @__PURE__ */ new Set();
|
|
21534
|
-
for (const [
|
|
21506
|
+
for (const [index2, event] of session.events.entries()) {
|
|
21535
21507
|
if (event.sessionId !== session.sessionId) {
|
|
21536
21508
|
context.addIssue({
|
|
21537
21509
|
code: "custom",
|
|
21538
21510
|
message: "Exported event belongs to a different Session",
|
|
21539
|
-
path: ["events",
|
|
21511
|
+
path: ["events", index2, "sessionId"]
|
|
21540
21512
|
});
|
|
21541
21513
|
}
|
|
21542
21514
|
const position = BigInt(event.position);
|
|
@@ -21544,14 +21516,14 @@ var sessionExportV2Schema = external_exports.object({
|
|
|
21544
21516
|
context.addIssue({
|
|
21545
21517
|
code: "custom",
|
|
21546
21518
|
message: "Exported events are not in increasing position order",
|
|
21547
|
-
path: ["events",
|
|
21519
|
+
path: ["events", index2, "position"]
|
|
21548
21520
|
});
|
|
21549
21521
|
}
|
|
21550
21522
|
if (eventIds.has(event.eventId)) {
|
|
21551
21523
|
context.addIssue({
|
|
21552
21524
|
code: "custom",
|
|
21553
21525
|
message: "Exported event identities are not unique",
|
|
21554
|
-
path: ["events",
|
|
21526
|
+
path: ["events", index2, "eventId"]
|
|
21555
21527
|
});
|
|
21556
21528
|
}
|
|
21557
21529
|
previousPosition = position;
|
|
@@ -21602,6 +21574,7 @@ function decode5(value, schema) {
|
|
|
21602
21574
|
function encode4(value, schema) {
|
|
21603
21575
|
return JSON.stringify(decode5(value, schema));
|
|
21604
21576
|
}
|
|
21577
|
+
var decodeSessionEventV2 = (value) => decode5(value, sessionEventV2Schema);
|
|
21605
21578
|
var decodeSessionEventEnvelopeV2 = (value) => decode5(value, sessionEventEnvelopeV2Schema);
|
|
21606
21579
|
var encodeSessionEventEnvelopeV2 = (value) => encode4(value, sessionEventEnvelopeV2Schema);
|
|
21607
21580
|
var decodeAcpSessionUpdateV2 = (value) => decode5(value, acpSessionUpdateV2Schema);
|
|
@@ -26593,9 +26566,9 @@ function comparePrerelease(left, right) {
|
|
|
26593
26566
|
if (left.length === 0 || right.length === 0) {
|
|
26594
26567
|
return left.length === right.length ? 0 : left.length === 0 ? 1 : -1;
|
|
26595
26568
|
}
|
|
26596
|
-
for (let
|
|
26597
|
-
const leftPart = left[
|
|
26598
|
-
const rightPart = right[
|
|
26569
|
+
for (let index2 = 0; index2 < Math.max(left.length, right.length); index2 += 1) {
|
|
26570
|
+
const leftPart = left[index2];
|
|
26571
|
+
const rightPart = right[index2];
|
|
26599
26572
|
if (leftPart === void 0 || rightPart === void 0) {
|
|
26600
26573
|
return leftPart === rightPart ? 0 : leftPart === void 0 ? -1 : 1;
|
|
26601
26574
|
}
|
|
@@ -26620,8 +26593,8 @@ function compareAgentVersions(left, right) {
|
|
|
26620
26593
|
if (parsedLeft === null || parsedRight === null) {
|
|
26621
26594
|
return null;
|
|
26622
26595
|
}
|
|
26623
|
-
for (let
|
|
26624
|
-
const difference = (parsedLeft.core[
|
|
26596
|
+
for (let index2 = 0; index2 < Math.max(parsedLeft.core.length, parsedRight.core.length); index2 += 1) {
|
|
26597
|
+
const difference = (parsedLeft.core[index2] ?? 0) - (parsedRight.core[index2] ?? 0);
|
|
26625
26598
|
if (difference !== 0) {
|
|
26626
26599
|
return Math.sign(difference);
|
|
26627
26600
|
}
|
|
@@ -27108,7 +27081,7 @@ function createDaemonConfig(connection, agents = [], installableAgents = [], loc
|
|
|
27108
27081
|
}
|
|
27109
27082
|
|
|
27110
27083
|
// src/run-daemon.ts
|
|
27111
|
-
import { createHash as createHash7, randomUUID as
|
|
27084
|
+
import { createHash as createHash7, randomUUID as randomUUID9 } from "node:crypto";
|
|
27112
27085
|
import { join as join18 } from "node:path";
|
|
27113
27086
|
import { styleText } from "node:util";
|
|
27114
27087
|
|
|
@@ -27231,7 +27204,7 @@ function startsWith(bytes, signature, offset = 0) {
|
|
|
27231
27204
|
if (bytes.byteLength < offset + signature.byteLength) {
|
|
27232
27205
|
return false;
|
|
27233
27206
|
}
|
|
27234
|
-
return signature.every((value,
|
|
27207
|
+
return signature.every((value, index2) => bytes[offset + index2] === value);
|
|
27235
27208
|
}
|
|
27236
27209
|
function sniffRasterMime(bytes) {
|
|
27237
27210
|
if (startsWith(bytes, PNG_SIGNATURE)) {
|
|
@@ -27359,7 +27332,7 @@ function startsWith2(bytes, signature, offset = 0) {
|
|
|
27359
27332
|
if (bytes.byteLength < offset + signature.byteLength) {
|
|
27360
27333
|
return false;
|
|
27361
27334
|
}
|
|
27362
|
-
return signature.every((value,
|
|
27335
|
+
return signature.every((value, index2) => bytes[offset + index2] === value);
|
|
27363
27336
|
}
|
|
27364
27337
|
function sniffVideoMime(bytes) {
|
|
27365
27338
|
if (startsWith2(bytes, MP4_FILE_TYPE, 4)) {
|
|
@@ -27488,10 +27461,10 @@ async function replaceImageMarkers(text2, replace) {
|
|
|
27488
27461
|
let cursor = 0;
|
|
27489
27462
|
let rewritten = "";
|
|
27490
27463
|
for (const match of matches) {
|
|
27491
|
-
const
|
|
27492
|
-
rewritten += text2.slice(cursor,
|
|
27464
|
+
const index2 = match.index ?? 0;
|
|
27465
|
+
rewritten += text2.slice(cursor, index2);
|
|
27493
27466
|
rewritten += await replace(match[1] ?? "");
|
|
27494
|
-
cursor =
|
|
27467
|
+
cursor = index2 + match[0].length;
|
|
27495
27468
|
}
|
|
27496
27469
|
return `${rewritten}${text2.slice(cursor)}`;
|
|
27497
27470
|
}
|
|
@@ -28725,9 +28698,9 @@ function historyContentCharacters(messages) {
|
|
|
28725
28698
|
var AcpHistoryReplay = class {
|
|
28726
28699
|
#activities = /* @__PURE__ */ new Map();
|
|
28727
28700
|
#messages = [];
|
|
28728
|
-
#events
|
|
28729
|
-
#records = [];
|
|
28701
|
+
#events;
|
|
28730
28702
|
#turnActivityIds = /* @__PURE__ */ new Set();
|
|
28703
|
+
#sessionId;
|
|
28731
28704
|
#activityTracker = new AcpActivityTracker(
|
|
28732
28705
|
async (activity2) => {
|
|
28733
28706
|
this.#activities.set(activity2.activityId, activity2);
|
|
@@ -28748,10 +28721,16 @@ var AcpHistoryReplay = class {
|
|
|
28748
28721
|
#firstMessageIndex = 0;
|
|
28749
28722
|
#characters = 0;
|
|
28750
28723
|
#truncated = false;
|
|
28724
|
+
constructor(events, sessionId) {
|
|
28725
|
+
this.#events = events;
|
|
28726
|
+
this.#sessionId = sessionId;
|
|
28727
|
+
}
|
|
28751
28728
|
record = async (update, rawUpdate, onRecorded = () => Promise.resolve()) => {
|
|
28752
|
-
this.#
|
|
28753
|
-
|
|
28754
|
-
await
|
|
28729
|
+
const position = this.#events.append(this.#sessionId, { payload: rawUpdate, type: "acp" });
|
|
28730
|
+
await onRecorded(position);
|
|
28731
|
+
return await this.#applyUpdate(update, position);
|
|
28732
|
+
};
|
|
28733
|
+
#applyUpdate = async (update, position) => {
|
|
28755
28734
|
if (update.sessionUpdate === "agent_thought_chunk") {
|
|
28756
28735
|
if (update.content.type === "text") {
|
|
28757
28736
|
await this.#activityTracker.recordNarrative(
|
|
@@ -28760,30 +28739,30 @@ var AcpHistoryReplay = class {
|
|
|
28760
28739
|
update.content.text
|
|
28761
28740
|
);
|
|
28762
28741
|
}
|
|
28763
|
-
return
|
|
28742
|
+
return position;
|
|
28764
28743
|
}
|
|
28765
28744
|
if (update.sessionUpdate === "tool_call") {
|
|
28766
28745
|
await this.#activityTracker.recordToolCall(update);
|
|
28767
|
-
return
|
|
28746
|
+
return position;
|
|
28768
28747
|
}
|
|
28769
28748
|
if (update.sessionUpdate === "tool_call_update") {
|
|
28770
28749
|
await this.#activityTracker.recordToolCallUpdate(update);
|
|
28771
|
-
return
|
|
28750
|
+
return position;
|
|
28772
28751
|
}
|
|
28773
28752
|
if (update.sessionUpdate === "plan") {
|
|
28774
28753
|
await this.#activityTracker.recordPlan(update);
|
|
28775
|
-
return
|
|
28754
|
+
return position;
|
|
28776
28755
|
}
|
|
28777
28756
|
if (update.sessionUpdate === "plan_update") {
|
|
28778
28757
|
await this.#activityTracker.recordPlanUpdate(update);
|
|
28779
|
-
return
|
|
28758
|
+
return position;
|
|
28780
28759
|
}
|
|
28781
28760
|
if (update.sessionUpdate === "plan_removed") {
|
|
28782
28761
|
await this.#activityTracker.removePlan(update);
|
|
28783
|
-
return
|
|
28762
|
+
return position;
|
|
28784
28763
|
}
|
|
28785
28764
|
if (update.sessionUpdate !== "user_message_chunk" && update.sessionUpdate !== "agent_message_chunk") {
|
|
28786
|
-
return
|
|
28765
|
+
return position;
|
|
28787
28766
|
}
|
|
28788
28767
|
if (update.sessionUpdate === "agent_message_chunk" && isProgressMessage(update)) {
|
|
28789
28768
|
if (update.content.type === "text") {
|
|
@@ -28793,18 +28772,18 @@ var AcpHistoryReplay = class {
|
|
|
28793
28772
|
update.content.text
|
|
28794
28773
|
);
|
|
28795
28774
|
}
|
|
28796
|
-
return
|
|
28775
|
+
return position;
|
|
28797
28776
|
}
|
|
28798
28777
|
const role = update.sessionUpdate === "user_message_chunk" ? "user" : "assistant";
|
|
28799
28778
|
const content = update.content;
|
|
28800
28779
|
if (role === "assistant" && content.type !== "text") {
|
|
28801
28780
|
await this.#activityTracker.finishNarrative();
|
|
28802
28781
|
this.recordAssistantContent(update.messageId ?? null, normalizeContentBlock(content));
|
|
28803
|
-
return
|
|
28782
|
+
return position;
|
|
28804
28783
|
}
|
|
28805
28784
|
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]`;
|
|
28806
28785
|
if (text2.length === 0) {
|
|
28807
|
-
return
|
|
28786
|
+
return position;
|
|
28808
28787
|
}
|
|
28809
28788
|
const previous = this.#messages.at(-1);
|
|
28810
28789
|
const id = update.messageId ?? null;
|
|
@@ -28831,41 +28810,32 @@ var AcpHistoryReplay = class {
|
|
|
28831
28810
|
this.#characters += bounded2.length;
|
|
28832
28811
|
this.#lastMessageId = id;
|
|
28833
28812
|
this.trimMessages();
|
|
28834
|
-
return
|
|
28813
|
+
return position;
|
|
28835
28814
|
};
|
|
28836
28815
|
recordLifecycle = (event) => {
|
|
28837
28816
|
if (event.type !== "lifecycle-metadata") {
|
|
28838
28817
|
throw new Error("Lifecycle history only accepts lifecycle metadata");
|
|
28839
28818
|
}
|
|
28840
|
-
this.#
|
|
28841
|
-
this.#events.push(event);
|
|
28842
|
-
return this.#events.length;
|
|
28819
|
+
return this.#events.append(this.#sessionId, event);
|
|
28843
28820
|
};
|
|
28844
|
-
eventCount = () => this.#events.length;
|
|
28845
28821
|
append = async (replay) => {
|
|
28846
|
-
|
|
28847
|
-
|
|
28848
|
-
|
|
28849
|
-
} else {
|
|
28850
|
-
this.recordLifecycle(record2.event);
|
|
28851
|
-
}
|
|
28822
|
+
await replay.#activityTracker.finish();
|
|
28823
|
+
for (const [activityId, activity2] of replay.#activities) {
|
|
28824
|
+
this.#activities.set(activityId, activity2);
|
|
28852
28825
|
}
|
|
28853
|
-
|
|
28854
|
-
|
|
28855
|
-
|
|
28856
|
-
const parsedCursor = cursor === null ? events.length : Number(cursor);
|
|
28857
|
-
if (!Number.isSafeInteger(parsedCursor) || parsedCursor < 0 || parsedCursor > events.length) {
|
|
28858
|
-
throw new Error("The native event cursor is invalid");
|
|
28826
|
+
for (const message of replay.#messages.slice(replay.#firstMessageIndex)) {
|
|
28827
|
+
this.#messages.push(message);
|
|
28828
|
+
this.#characters += message.text.length;
|
|
28859
28829
|
}
|
|
28860
|
-
|
|
28861
|
-
|
|
28862
|
-
|
|
28863
|
-
|
|
28864
|
-
|
|
28865
|
-
|
|
28866
|
-
|
|
28867
|
-
};
|
|
28830
|
+
this.#turnActivityIds.clear();
|
|
28831
|
+
for (const activityId of replay.#turnActivityIds) {
|
|
28832
|
+
this.#turnActivityIds.add(activityId);
|
|
28833
|
+
}
|
|
28834
|
+
this.#lastMessageId = replay.#lastMessageId;
|
|
28835
|
+
this.#truncated ||= replay.#truncated;
|
|
28836
|
+
this.trimMessages();
|
|
28868
28837
|
};
|
|
28838
|
+
eventPage = (eventLimit, cursor) => this.#events.page(this.#sessionId, eventLimit, cursor);
|
|
28869
28839
|
snapshot = async () => {
|
|
28870
28840
|
await this.#activityTracker.finish();
|
|
28871
28841
|
const messages = this.#messages.slice(this.#firstMessageIndex).map((message) => {
|
|
@@ -29498,9 +29468,7 @@ var AcpSessionInteractions = class {
|
|
|
29498
29468
|
};
|
|
29499
29469
|
|
|
29500
29470
|
// src/acp/session-store.ts
|
|
29501
|
-
import {
|
|
29502
|
-
import { dirname as dirname3 } from "node:path";
|
|
29503
|
-
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
29471
|
+
import { randomUUID } from "node:crypto";
|
|
29504
29472
|
|
|
29505
29473
|
// ../../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
|
|
29506
29474
|
var entityKind = /* @__PURE__ */ Symbol.for("drizzle:entityKind");
|
|
@@ -30616,7 +30584,7 @@ function haveSameKeys(left, right) {
|
|
|
30616
30584
|
const leftKeys = Object.keys(left);
|
|
30617
30585
|
const rightKeys = Object.keys(right);
|
|
30618
30586
|
if (leftKeys.length !== rightKeys.length) return false;
|
|
30619
|
-
for (const [
|
|
30587
|
+
for (const [index2, key] of leftKeys.entries()) if (key !== rightKeys[index2]) return false;
|
|
30620
30588
|
return true;
|
|
30621
30589
|
}
|
|
30622
30590
|
function mapUpdateSet(table, values) {
|
|
@@ -31369,195 +31337,6 @@ var NoopLogger = class {
|
|
|
31369
31337
|
}
|
|
31370
31338
|
};
|
|
31371
31339
|
|
|
31372
|
-
// ../../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
|
|
31373
|
-
var SQLiteCountBuilder = class SQLiteCountBuilder2 extends SQL {
|
|
31374
|
-
static [entityKind] = "SQLiteCountBuilder";
|
|
31375
|
-
dialect;
|
|
31376
|
-
session;
|
|
31377
|
-
static buildCount(source, filters, parens) {
|
|
31378
|
-
const query = sql`select count(*) from ${source}${sql` where ${filters}`.if(filters)}`;
|
|
31379
|
-
return parens ? sql`(${query})` : query;
|
|
31380
|
-
}
|
|
31381
|
-
constructor(countConfig) {
|
|
31382
|
-
super(SQLiteCountBuilder2.buildCount(countConfig.source, countConfig.filters, true).queryChunks);
|
|
31383
|
-
this.countConfig = countConfig;
|
|
31384
|
-
this.dialect = countConfig.dialect;
|
|
31385
|
-
this.session = countConfig.session;
|
|
31386
|
-
this.mapWith((e) => {
|
|
31387
|
-
if (typeof e === "number") return e;
|
|
31388
|
-
return Number(e ?? 0);
|
|
31389
|
-
});
|
|
31390
|
-
}
|
|
31391
|
-
executableSql;
|
|
31392
|
-
build() {
|
|
31393
|
-
if (!this.executableSql) {
|
|
31394
|
-
const { source, filters } = this.countConfig;
|
|
31395
|
-
this.executableSql = SQLiteCountBuilder2.buildCount(source, filters);
|
|
31396
|
-
}
|
|
31397
|
-
return this.dialect.sqlToQuery(this.executableSql);
|
|
31398
|
-
}
|
|
31399
|
-
};
|
|
31400
|
-
|
|
31401
|
-
// ../../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
|
|
31402
|
-
var SQLiteAsyncCountBuilder = class extends SQLiteCountBuilder {
|
|
31403
|
-
static [entityKind] = "SQLiteAsyncCountBuilder";
|
|
31404
|
-
constructor(countConfig) {
|
|
31405
|
-
super(countConfig);
|
|
31406
|
-
}
|
|
31407
|
-
/** @internal */
|
|
31408
|
-
executeRaw(placeholderValues) {
|
|
31409
|
-
return this.session.prepareQuery(this.build(), "arrays", false, "all", (rows) => {
|
|
31410
|
-
const v = rows[0]?.[0];
|
|
31411
|
-
if (typeof v === "number") return v;
|
|
31412
|
-
return v ? Number(v) : 0;
|
|
31413
|
-
}).execute(placeholderValues);
|
|
31414
|
-
}
|
|
31415
|
-
async execute(placeholderValues) {
|
|
31416
|
-
return await this.executeRaw(placeholderValues);
|
|
31417
|
-
}
|
|
31418
|
-
};
|
|
31419
|
-
applyMixins(SQLiteAsyncCountBuilder, [QueryPromise]);
|
|
31420
|
-
var SQLiteSyncCountBuilder = class extends SQLiteAsyncCountBuilder {
|
|
31421
|
-
static [entityKind] = "SQLiteSyncCountBuilder";
|
|
31422
|
-
sync(placeholderValues) {
|
|
31423
|
-
return this.executeRaw(placeholderValues).sync();
|
|
31424
|
-
}
|
|
31425
|
-
};
|
|
31426
|
-
|
|
31427
|
-
// ../../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
|
|
31428
|
-
var RelationalQueryBuilder = class {
|
|
31429
|
-
static [entityKind] = "SQLiteRelationalQueryBuilderV2";
|
|
31430
|
-
constructor(mode, schema, table, tableConfig, dialect, session, forbidJsonb, builder = SQLiteRelationalQuery) {
|
|
31431
|
-
this.mode = mode;
|
|
31432
|
-
this.schema = schema;
|
|
31433
|
-
this.table = table;
|
|
31434
|
-
this.tableConfig = tableConfig;
|
|
31435
|
-
this.dialect = dialect;
|
|
31436
|
-
this.session = session;
|
|
31437
|
-
this.forbidJsonb = forbidJsonb;
|
|
31438
|
-
this.builder = builder;
|
|
31439
|
-
}
|
|
31440
|
-
findMany(config2) {
|
|
31441
|
-
return new this.builder(this.mode, this.schema, this.table, this.tableConfig, this.dialect, this.session, config2 ?? true, "many", this.forbidJsonb);
|
|
31442
|
-
}
|
|
31443
|
-
findFirst(config2) {
|
|
31444
|
-
return new this.builder(this.mode, this.schema, this.table, this.tableConfig, this.dialect, this.session, config2 ?? true, "first", this.forbidJsonb);
|
|
31445
|
-
}
|
|
31446
|
-
};
|
|
31447
|
-
var SQLiteRelationalQuery = class {
|
|
31448
|
-
static [entityKind] = "SQLiteRelationalQueryV2";
|
|
31449
|
-
/** @internal */
|
|
31450
|
-
mode;
|
|
31451
|
-
/** @internal */
|
|
31452
|
-
table;
|
|
31453
|
-
/** @internal */
|
|
31454
|
-
resultKind;
|
|
31455
|
-
constructor(resultKind, schema, table, tableConfig, dialect, session, config2, mode, forbidJsonb) {
|
|
31456
|
-
this.schema = schema;
|
|
31457
|
-
this.tableConfig = tableConfig;
|
|
31458
|
-
this.dialect = dialect;
|
|
31459
|
-
this.session = session;
|
|
31460
|
-
this.config = config2;
|
|
31461
|
-
this.forbidJsonb = forbidJsonb;
|
|
31462
|
-
this.resultKind = resultKind;
|
|
31463
|
-
this.mode = mode;
|
|
31464
|
-
this.table = table;
|
|
31465
|
-
}
|
|
31466
|
-
getSQL() {
|
|
31467
|
-
return this._getQuery().sql;
|
|
31468
|
-
}
|
|
31469
|
-
_getQuery() {
|
|
31470
|
-
const jsonb = this.forbidJsonb ? sql`json` : sql`jsonb`;
|
|
31471
|
-
return this.dialect.buildRelationalQuery({
|
|
31472
|
-
schema: this.schema,
|
|
31473
|
-
table: this.table,
|
|
31474
|
-
tableConfig: this.tableConfig,
|
|
31475
|
-
queryConfig: this.config,
|
|
31476
|
-
mode: this.mode,
|
|
31477
|
-
jsonb
|
|
31478
|
-
});
|
|
31479
|
-
}
|
|
31480
|
-
_toSQL() {
|
|
31481
|
-
const query = this._getQuery();
|
|
31482
|
-
return {
|
|
31483
|
-
query,
|
|
31484
|
-
builtQuery: this.dialect.sqlToQuery(query.sql)
|
|
31485
|
-
};
|
|
31486
|
-
}
|
|
31487
|
-
toSQL() {
|
|
31488
|
-
return this._toSQL().builtQuery;
|
|
31489
|
-
}
|
|
31490
|
-
};
|
|
31491
|
-
|
|
31492
|
-
// ../../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
|
|
31493
|
-
var SQLiteAsyncRelationalQuery = class extends SQLiteRelationalQuery {
|
|
31494
|
-
static [entityKind] = "SQLiteAsyncRelationalQueryV2";
|
|
31495
|
-
/** @internal */
|
|
31496
|
-
_prepare(prepare = false) {
|
|
31497
|
-
const { query, builtQuery } = this._toSQL();
|
|
31498
|
-
const mapper = this.dialect.mapperGenerators.relationalRows({
|
|
31499
|
-
isFirst: this.mode === "first",
|
|
31500
|
-
parseJson: true,
|
|
31501
|
-
parseJsonIfString: false,
|
|
31502
|
-
rootJsonMappers: false,
|
|
31503
|
-
selection: query.selection,
|
|
31504
|
-
arrayModeRoot: true
|
|
31505
|
-
});
|
|
31506
|
-
return this.session.prepareQuery(builtQuery, "arrays", prepare, "all", mapper);
|
|
31507
|
-
}
|
|
31508
|
-
prepare() {
|
|
31509
|
-
return this._prepare(true);
|
|
31510
|
-
}
|
|
31511
|
-
async execute(placeholderValues) {
|
|
31512
|
-
return this._prepare().execute(placeholderValues);
|
|
31513
|
-
}
|
|
31514
|
-
};
|
|
31515
|
-
var SQLiteSyncRelationalQuery = class extends SQLiteAsyncRelationalQuery {
|
|
31516
|
-
static [entityKind] = "SQLiteSyncRelationalQueryV2";
|
|
31517
|
-
sync(placeholderValues) {
|
|
31518
|
-
return this._prepare().execute(placeholderValues).sync();
|
|
31519
|
-
}
|
|
31520
|
-
};
|
|
31521
|
-
applyMixins(SQLiteAsyncRelationalQuery, [QueryPromise]);
|
|
31522
|
-
|
|
31523
|
-
// ../../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
|
|
31524
|
-
var SelectionProxyHandler = class SelectionProxyHandler2 {
|
|
31525
|
-
static [entityKind] = "SelectionProxyHandler";
|
|
31526
|
-
config;
|
|
31527
|
-
constructor(config2) {
|
|
31528
|
-
this.config = { ...config2 };
|
|
31529
|
-
}
|
|
31530
|
-
get(subquery, prop) {
|
|
31531
|
-
if (prop === "_") return {
|
|
31532
|
-
...subquery["_"],
|
|
31533
|
-
selectedFields: new Proxy(subquery._.selectedFields, this)
|
|
31534
|
-
};
|
|
31535
|
-
if (prop === ViewBaseConfig) return {
|
|
31536
|
-
...subquery[ViewBaseConfig],
|
|
31537
|
-
selectedFields: new Proxy(subquery[ViewBaseConfig].selectedFields, this)
|
|
31538
|
-
};
|
|
31539
|
-
if (typeof prop === "symbol") return subquery[prop];
|
|
31540
|
-
const value = (is(subquery, Subquery) ? subquery._.selectedFields : is(subquery, View) ? subquery[ViewBaseConfig].selectedFields : subquery)[prop];
|
|
31541
|
-
if (is(value, SQL.Aliased)) {
|
|
31542
|
-
if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) return value.sql;
|
|
31543
|
-
const newValue = value.clone();
|
|
31544
|
-
newValue.isSelectionField = true;
|
|
31545
|
-
newValue.origin = this.config.alias;
|
|
31546
|
-
return newValue;
|
|
31547
|
-
}
|
|
31548
|
-
if (is(value, SQL)) {
|
|
31549
|
-
if (this.config.sqlBehavior === "sql") return value;
|
|
31550
|
-
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.`);
|
|
31551
|
-
}
|
|
31552
|
-
if (is(value, Column)) {
|
|
31553
|
-
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));
|
|
31554
|
-
return value;
|
|
31555
|
-
}
|
|
31556
|
-
if (typeof value !== "object" || value === null) return value;
|
|
31557
|
-
return new Proxy(value, new SelectionProxyHandler2(this.config));
|
|
31558
|
-
}
|
|
31559
|
-
};
|
|
31560
|
-
|
|
31561
31340
|
// ../../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
|
|
31562
31341
|
var ForeignKeyBuilder = class {
|
|
31563
31342
|
static [entityKind] = "SQLiteForeignKeyBuilder";
|
|
@@ -32122,130 +31901,144 @@ function sqliteTableWithCasing(casing) {
|
|
|
32122
31901
|
}
|
|
32123
31902
|
var sqliteTable = sqliteTableWithCasing(void 0);
|
|
32124
31903
|
|
|
32125
|
-
// ../../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/
|
|
32126
|
-
|
|
32127
|
-
|
|
32128
|
-
|
|
32129
|
-
|
|
32130
|
-
|
|
32131
|
-
}
|
|
32132
|
-
|
|
32133
|
-
|
|
32134
|
-
|
|
32135
|
-
|
|
31904
|
+
// ../../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
|
|
31905
|
+
var IndexBuilderOn = class {
|
|
31906
|
+
static [entityKind] = "SQLiteIndexBuilderOn";
|
|
31907
|
+
constructor(name2, unique) {
|
|
31908
|
+
this.name = name2;
|
|
31909
|
+
this.unique = unique;
|
|
31910
|
+
}
|
|
31911
|
+
on(...columns) {
|
|
31912
|
+
return new IndexBuilder(this.name, columns, this.unique);
|
|
31913
|
+
}
|
|
31914
|
+
};
|
|
31915
|
+
var IndexBuilder = class {
|
|
31916
|
+
static [entityKind] = "SQLiteIndexBuilder";
|
|
32136
31917
|
/** @internal */
|
|
32137
31918
|
config;
|
|
32138
|
-
constructor(
|
|
32139
|
-
this.table = table;
|
|
32140
|
-
this.session = session;
|
|
32141
|
-
this.dialect = dialect;
|
|
31919
|
+
constructor(name2, columns, unique) {
|
|
32142
31920
|
this.config = {
|
|
32143
|
-
|
|
32144
|
-
|
|
31921
|
+
name: name2,
|
|
31922
|
+
columns,
|
|
31923
|
+
unique,
|
|
31924
|
+
where: void 0
|
|
32145
31925
|
};
|
|
32146
31926
|
}
|
|
32147
31927
|
/**
|
|
32148
|
-
*
|
|
32149
|
-
*
|
|
32150
|
-
* Calling this method will delete only those rows that fulfill a specified condition.
|
|
32151
|
-
*
|
|
32152
|
-
* See docs: {@link https://orm.drizzle.team/docs/delete}
|
|
32153
|
-
*
|
|
32154
|
-
* @param where the `where` clause.
|
|
32155
|
-
*
|
|
32156
|
-
* @example
|
|
32157
|
-
* You can use conditional operators and `sql function` to filter the rows to be deleted.
|
|
32158
|
-
*
|
|
32159
|
-
* ```ts
|
|
32160
|
-
* // Delete all cars with green color
|
|
32161
|
-
* db.delete(cars).where(eq(cars.color, 'green'));
|
|
32162
|
-
* // or
|
|
32163
|
-
* db.delete(cars).where(sql`${cars.color} = 'green'`)
|
|
32164
|
-
* ```
|
|
32165
|
-
*
|
|
32166
|
-
* You can logically combine conditional operators with `and()` and `or()` operators:
|
|
32167
|
-
*
|
|
32168
|
-
* ```ts
|
|
32169
|
-
* // Delete all BMW cars with a green color
|
|
32170
|
-
* db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
|
32171
|
-
*
|
|
32172
|
-
* // Delete all cars with the green or blue color
|
|
32173
|
-
* db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
32174
|
-
* ```
|
|
31928
|
+
* Condition for partial index.
|
|
32175
31929
|
*/
|
|
32176
|
-
where(
|
|
32177
|
-
this.config.where =
|
|
32178
|
-
return this;
|
|
32179
|
-
}
|
|
32180
|
-
orderBy(...columns) {
|
|
32181
|
-
if (typeof columns[0] === "function") {
|
|
32182
|
-
const orderBy = columns[0](new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
|
|
32183
|
-
sqlAliasedBehavior: "alias",
|
|
32184
|
-
sqlBehavior: "sql"
|
|
32185
|
-
})));
|
|
32186
|
-
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
32187
|
-
this.config.orderBy = orderByArray;
|
|
32188
|
-
} else {
|
|
32189
|
-
const orderByArray = columns;
|
|
32190
|
-
this.config.orderBy = orderByArray;
|
|
32191
|
-
}
|
|
32192
|
-
return this;
|
|
32193
|
-
}
|
|
32194
|
-
limit(limit) {
|
|
32195
|
-
this.config.limit = limit;
|
|
32196
|
-
return this;
|
|
32197
|
-
}
|
|
32198
|
-
returning(fields = this.table[SQLiteTable.Symbol.Columns]) {
|
|
32199
|
-
this.config.returning = orderSelectedFields(fields);
|
|
31930
|
+
where(condition) {
|
|
31931
|
+
this.config.where = condition;
|
|
32200
31932
|
return this;
|
|
32201
31933
|
}
|
|
32202
|
-
|
|
32203
|
-
|
|
32204
|
-
|
|
32205
|
-
toSQL() {
|
|
32206
|
-
return this.dialect.sqlToQuery(this.getSQL());
|
|
31934
|
+
/** @internal */
|
|
31935
|
+
build(table) {
|
|
31936
|
+
return new Index(this.config, table);
|
|
32207
31937
|
}
|
|
32208
|
-
|
|
32209
|
-
|
|
31938
|
+
};
|
|
31939
|
+
var Index = class {
|
|
31940
|
+
static [entityKind] = "SQLiteIndex";
|
|
31941
|
+
config;
|
|
31942
|
+
isNameExplicit;
|
|
31943
|
+
constructor(config2, table) {
|
|
31944
|
+
this.config = {
|
|
31945
|
+
...config2,
|
|
31946
|
+
table
|
|
31947
|
+
};
|
|
31948
|
+
this.isNameExplicit = !!config2.name;
|
|
32210
31949
|
}
|
|
32211
31950
|
};
|
|
31951
|
+
function index(name2) {
|
|
31952
|
+
return new IndexBuilderOn(name2, false);
|
|
31953
|
+
}
|
|
32212
31954
|
|
|
32213
|
-
// ../../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/
|
|
32214
|
-
|
|
32215
|
-
|
|
31955
|
+
// ../../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
|
|
31956
|
+
function primaryKey(...config2) {
|
|
31957
|
+
if (config2[0].columns) return new PrimaryKeyBuilder(config2[0].columns, config2[0].name);
|
|
31958
|
+
return new PrimaryKeyBuilder(config2);
|
|
31959
|
+
}
|
|
31960
|
+
var PrimaryKeyBuilder = class {
|
|
31961
|
+
static [entityKind] = "SQLitePrimaryKeyBuilder";
|
|
32216
31962
|
/** @internal */
|
|
32217
|
-
|
|
32218
|
-
|
|
32219
|
-
|
|
32220
|
-
|
|
32221
|
-
|
|
31963
|
+
columns;
|
|
31964
|
+
/** @internal */
|
|
31965
|
+
name;
|
|
31966
|
+
constructor(columns, name2) {
|
|
31967
|
+
this.columns = columns;
|
|
31968
|
+
this.name = name2;
|
|
32222
31969
|
}
|
|
32223
|
-
|
|
32224
|
-
|
|
31970
|
+
/** @internal */
|
|
31971
|
+
build(table) {
|
|
31972
|
+
return new PrimaryKey(table, this.columns, this.name);
|
|
32225
31973
|
}
|
|
32226
|
-
|
|
32227
|
-
|
|
32228
|
-
|
|
32229
|
-
|
|
32230
|
-
|
|
32231
|
-
|
|
32232
|
-
|
|
32233
|
-
|
|
32234
|
-
|
|
32235
|
-
|
|
32236
|
-
|
|
32237
|
-
}
|
|
32238
|
-
|
|
32239
|
-
return this.
|
|
31974
|
+
};
|
|
31975
|
+
var PrimaryKey = class {
|
|
31976
|
+
static [entityKind] = "SQLitePrimaryKey";
|
|
31977
|
+
columns;
|
|
31978
|
+
name;
|
|
31979
|
+
isNameExplicit;
|
|
31980
|
+
constructor(table, columns, name2) {
|
|
31981
|
+
this.table = table;
|
|
31982
|
+
this.columns = columns;
|
|
31983
|
+
this.name = name2;
|
|
31984
|
+
this.isNameExplicit = !!name2;
|
|
31985
|
+
}
|
|
31986
|
+
getName() {
|
|
31987
|
+
return this.name ?? `${this.table[SQLiteTable.Symbol.Name]}_${this.columns.map((column) => column.name).join("_")}_pk`;
|
|
32240
31988
|
}
|
|
32241
31989
|
};
|
|
32242
|
-
|
|
31990
|
+
|
|
31991
|
+
// ../../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
|
|
31992
|
+
function extractUsedTable(table) {
|
|
31993
|
+
if (is(table, SQLiteTable)) return [`${table[Table.Symbol.BaseName]}`];
|
|
31994
|
+
if (is(table, Subquery)) return table._.usedTables ?? [];
|
|
31995
|
+
if (is(table, SQL)) return table.usedTables ?? [];
|
|
31996
|
+
return [];
|
|
31997
|
+
}
|
|
32243
31998
|
|
|
32244
31999
|
// ../../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
|
|
32245
32000
|
var SQLiteViewBase = class extends View {
|
|
32246
32001
|
static [entityKind] = "SQLiteViewBase";
|
|
32247
32002
|
};
|
|
32248
32003
|
|
|
32004
|
+
// ../../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
|
|
32005
|
+
var SelectionProxyHandler = class SelectionProxyHandler2 {
|
|
32006
|
+
static [entityKind] = "SelectionProxyHandler";
|
|
32007
|
+
config;
|
|
32008
|
+
constructor(config2) {
|
|
32009
|
+
this.config = { ...config2 };
|
|
32010
|
+
}
|
|
32011
|
+
get(subquery, prop) {
|
|
32012
|
+
if (prop === "_") return {
|
|
32013
|
+
...subquery["_"],
|
|
32014
|
+
selectedFields: new Proxy(subquery._.selectedFields, this)
|
|
32015
|
+
};
|
|
32016
|
+
if (prop === ViewBaseConfig) return {
|
|
32017
|
+
...subquery[ViewBaseConfig],
|
|
32018
|
+
selectedFields: new Proxy(subquery[ViewBaseConfig].selectedFields, this)
|
|
32019
|
+
};
|
|
32020
|
+
if (typeof prop === "symbol") return subquery[prop];
|
|
32021
|
+
const value = (is(subquery, Subquery) ? subquery._.selectedFields : is(subquery, View) ? subquery[ViewBaseConfig].selectedFields : subquery)[prop];
|
|
32022
|
+
if (is(value, SQL.Aliased)) {
|
|
32023
|
+
if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) return value.sql;
|
|
32024
|
+
const newValue = value.clone();
|
|
32025
|
+
newValue.isSelectionField = true;
|
|
32026
|
+
newValue.origin = this.config.alias;
|
|
32027
|
+
return newValue;
|
|
32028
|
+
}
|
|
32029
|
+
if (is(value, SQL)) {
|
|
32030
|
+
if (this.config.sqlBehavior === "sql") return value;
|
|
32031
|
+
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.`);
|
|
32032
|
+
}
|
|
32033
|
+
if (is(value, Column)) {
|
|
32034
|
+
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));
|
|
32035
|
+
return value;
|
|
32036
|
+
}
|
|
32037
|
+
if (typeof value !== "object" || value === null) return value;
|
|
32038
|
+
return new Proxy(value, new SelectionProxyHandler2(this.config));
|
|
32039
|
+
}
|
|
32040
|
+
};
|
|
32041
|
+
|
|
32249
32042
|
// ../../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
|
|
32250
32043
|
var TypedQueryBuilder = class {
|
|
32251
32044
|
static [entityKind] = "TypedQueryBuilder";
|
|
@@ -32946,8 +32739,8 @@ var SQLiteDialect = class {
|
|
|
32946
32739
|
buildJoins(joins) {
|
|
32947
32740
|
if (!joins || joins.length === 0) return;
|
|
32948
32741
|
const joinsArray = [];
|
|
32949
|
-
if (joins) for (const [
|
|
32950
|
-
if (
|
|
32742
|
+
if (joins) for (const [index2, joinMeta] of joins.entries()) {
|
|
32743
|
+
if (index2 === 0) joinsArray.push(sql` `);
|
|
32951
32744
|
const table = joinMeta.table;
|
|
32952
32745
|
const onSql = joinMeta.on ? sql` on ${joinMeta.on}` : void 0;
|
|
32953
32746
|
if (is(table, SQLiteTable)) {
|
|
@@ -32957,7 +32750,7 @@ var SQLiteDialect = class {
|
|
|
32957
32750
|
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
|
32958
32751
|
joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`}${onSql}`);
|
|
32959
32752
|
} else joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join ${table}${onSql}`);
|
|
32960
|
-
if (
|
|
32753
|
+
if (index2 < joins.length - 1) joinsArray.push(sql` `);
|
|
32961
32754
|
}
|
|
32962
32755
|
return sql.join(joinsArray);
|
|
32963
32756
|
}
|
|
@@ -32966,9 +32759,9 @@ var SQLiteDialect = class {
|
|
|
32966
32759
|
}
|
|
32967
32760
|
buildOrderBy(orderBy) {
|
|
32968
32761
|
const orderByList = [];
|
|
32969
|
-
if (orderBy) for (const [
|
|
32762
|
+
if (orderBy) for (const [index2, orderByValue] of orderBy.entries()) {
|
|
32970
32763
|
orderByList.push(orderByValue);
|
|
32971
|
-
if (
|
|
32764
|
+
if (index2 < orderBy.length - 1) orderByList.push(sql`, `);
|
|
32972
32765
|
}
|
|
32973
32766
|
return orderByList.length > 0 ? sql` order by ${sql.join(orderByList)}` : void 0;
|
|
32974
32767
|
}
|
|
@@ -32996,9 +32789,9 @@ var SQLiteDialect = class {
|
|
|
32996
32789
|
const whereSql = where ? sql` where ${where}` : void 0;
|
|
32997
32790
|
const havingSql = having ? sql` having ${having}` : void 0;
|
|
32998
32791
|
const groupByList = [];
|
|
32999
|
-
if (groupBy) for (const [
|
|
32792
|
+
if (groupBy) for (const [index2, groupByValue] of groupBy.entries()) {
|
|
33000
32793
|
groupByList.push(groupByValue);
|
|
33001
|
-
if (
|
|
32794
|
+
if (index2 < groupBy.length - 1) groupByList.push(sql`, `);
|
|
33002
32795
|
}
|
|
33003
32796
|
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}`;
|
|
33004
32797
|
if (setOperators.length > 0) return this.buildSetOperations(finalQuery, setOperators);
|
|
@@ -33287,6 +33080,268 @@ var QueryBuilder = class {
|
|
|
33287
33080
|
}
|
|
33288
33081
|
};
|
|
33289
33082
|
|
|
33083
|
+
// ../../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
|
|
33084
|
+
var SQLiteCountBuilder = class SQLiteCountBuilder2 extends SQL {
|
|
33085
|
+
static [entityKind] = "SQLiteCountBuilder";
|
|
33086
|
+
dialect;
|
|
33087
|
+
session;
|
|
33088
|
+
static buildCount(source, filters, parens) {
|
|
33089
|
+
const query = sql`select count(*) from ${source}${sql` where ${filters}`.if(filters)}`;
|
|
33090
|
+
return parens ? sql`(${query})` : query;
|
|
33091
|
+
}
|
|
33092
|
+
constructor(countConfig) {
|
|
33093
|
+
super(SQLiteCountBuilder2.buildCount(countConfig.source, countConfig.filters, true).queryChunks);
|
|
33094
|
+
this.countConfig = countConfig;
|
|
33095
|
+
this.dialect = countConfig.dialect;
|
|
33096
|
+
this.session = countConfig.session;
|
|
33097
|
+
this.mapWith((e) => {
|
|
33098
|
+
if (typeof e === "number") return e;
|
|
33099
|
+
return Number(e ?? 0);
|
|
33100
|
+
});
|
|
33101
|
+
}
|
|
33102
|
+
executableSql;
|
|
33103
|
+
build() {
|
|
33104
|
+
if (!this.executableSql) {
|
|
33105
|
+
const { source, filters } = this.countConfig;
|
|
33106
|
+
this.executableSql = SQLiteCountBuilder2.buildCount(source, filters);
|
|
33107
|
+
}
|
|
33108
|
+
return this.dialect.sqlToQuery(this.executableSql);
|
|
33109
|
+
}
|
|
33110
|
+
};
|
|
33111
|
+
|
|
33112
|
+
// ../../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
|
|
33113
|
+
var SQLiteAsyncCountBuilder = class extends SQLiteCountBuilder {
|
|
33114
|
+
static [entityKind] = "SQLiteAsyncCountBuilder";
|
|
33115
|
+
constructor(countConfig) {
|
|
33116
|
+
super(countConfig);
|
|
33117
|
+
}
|
|
33118
|
+
/** @internal */
|
|
33119
|
+
executeRaw(placeholderValues) {
|
|
33120
|
+
return this.session.prepareQuery(this.build(), "arrays", false, "all", (rows) => {
|
|
33121
|
+
const v = rows[0]?.[0];
|
|
33122
|
+
if (typeof v === "number") return v;
|
|
33123
|
+
return v ? Number(v) : 0;
|
|
33124
|
+
}).execute(placeholderValues);
|
|
33125
|
+
}
|
|
33126
|
+
async execute(placeholderValues) {
|
|
33127
|
+
return await this.executeRaw(placeholderValues);
|
|
33128
|
+
}
|
|
33129
|
+
};
|
|
33130
|
+
applyMixins(SQLiteAsyncCountBuilder, [QueryPromise]);
|
|
33131
|
+
var SQLiteSyncCountBuilder = class extends SQLiteAsyncCountBuilder {
|
|
33132
|
+
static [entityKind] = "SQLiteSyncCountBuilder";
|
|
33133
|
+
sync(placeholderValues) {
|
|
33134
|
+
return this.executeRaw(placeholderValues).sync();
|
|
33135
|
+
}
|
|
33136
|
+
};
|
|
33137
|
+
|
|
33138
|
+
// ../../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
|
|
33139
|
+
var RelationalQueryBuilder = class {
|
|
33140
|
+
static [entityKind] = "SQLiteRelationalQueryBuilderV2";
|
|
33141
|
+
constructor(mode, schema, table, tableConfig, dialect, session, forbidJsonb, builder = SQLiteRelationalQuery) {
|
|
33142
|
+
this.mode = mode;
|
|
33143
|
+
this.schema = schema;
|
|
33144
|
+
this.table = table;
|
|
33145
|
+
this.tableConfig = tableConfig;
|
|
33146
|
+
this.dialect = dialect;
|
|
33147
|
+
this.session = session;
|
|
33148
|
+
this.forbidJsonb = forbidJsonb;
|
|
33149
|
+
this.builder = builder;
|
|
33150
|
+
}
|
|
33151
|
+
findMany(config2) {
|
|
33152
|
+
return new this.builder(this.mode, this.schema, this.table, this.tableConfig, this.dialect, this.session, config2 ?? true, "many", this.forbidJsonb);
|
|
33153
|
+
}
|
|
33154
|
+
findFirst(config2) {
|
|
33155
|
+
return new this.builder(this.mode, this.schema, this.table, this.tableConfig, this.dialect, this.session, config2 ?? true, "first", this.forbidJsonb);
|
|
33156
|
+
}
|
|
33157
|
+
};
|
|
33158
|
+
var SQLiteRelationalQuery = class {
|
|
33159
|
+
static [entityKind] = "SQLiteRelationalQueryV2";
|
|
33160
|
+
/** @internal */
|
|
33161
|
+
mode;
|
|
33162
|
+
/** @internal */
|
|
33163
|
+
table;
|
|
33164
|
+
/** @internal */
|
|
33165
|
+
resultKind;
|
|
33166
|
+
constructor(resultKind, schema, table, tableConfig, dialect, session, config2, mode, forbidJsonb) {
|
|
33167
|
+
this.schema = schema;
|
|
33168
|
+
this.tableConfig = tableConfig;
|
|
33169
|
+
this.dialect = dialect;
|
|
33170
|
+
this.session = session;
|
|
33171
|
+
this.config = config2;
|
|
33172
|
+
this.forbidJsonb = forbidJsonb;
|
|
33173
|
+
this.resultKind = resultKind;
|
|
33174
|
+
this.mode = mode;
|
|
33175
|
+
this.table = table;
|
|
33176
|
+
}
|
|
33177
|
+
getSQL() {
|
|
33178
|
+
return this._getQuery().sql;
|
|
33179
|
+
}
|
|
33180
|
+
_getQuery() {
|
|
33181
|
+
const jsonb = this.forbidJsonb ? sql`json` : sql`jsonb`;
|
|
33182
|
+
return this.dialect.buildRelationalQuery({
|
|
33183
|
+
schema: this.schema,
|
|
33184
|
+
table: this.table,
|
|
33185
|
+
tableConfig: this.tableConfig,
|
|
33186
|
+
queryConfig: this.config,
|
|
33187
|
+
mode: this.mode,
|
|
33188
|
+
jsonb
|
|
33189
|
+
});
|
|
33190
|
+
}
|
|
33191
|
+
_toSQL() {
|
|
33192
|
+
const query = this._getQuery();
|
|
33193
|
+
return {
|
|
33194
|
+
query,
|
|
33195
|
+
builtQuery: this.dialect.sqlToQuery(query.sql)
|
|
33196
|
+
};
|
|
33197
|
+
}
|
|
33198
|
+
toSQL() {
|
|
33199
|
+
return this._toSQL().builtQuery;
|
|
33200
|
+
}
|
|
33201
|
+
};
|
|
33202
|
+
|
|
33203
|
+
// ../../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
|
|
33204
|
+
var SQLiteAsyncRelationalQuery = class extends SQLiteRelationalQuery {
|
|
33205
|
+
static [entityKind] = "SQLiteAsyncRelationalQueryV2";
|
|
33206
|
+
/** @internal */
|
|
33207
|
+
_prepare(prepare = false) {
|
|
33208
|
+
const { query, builtQuery } = this._toSQL();
|
|
33209
|
+
const mapper = this.dialect.mapperGenerators.relationalRows({
|
|
33210
|
+
isFirst: this.mode === "first",
|
|
33211
|
+
parseJson: true,
|
|
33212
|
+
parseJsonIfString: false,
|
|
33213
|
+
rootJsonMappers: false,
|
|
33214
|
+
selection: query.selection,
|
|
33215
|
+
arrayModeRoot: true
|
|
33216
|
+
});
|
|
33217
|
+
return this.session.prepareQuery(builtQuery, "arrays", prepare, "all", mapper);
|
|
33218
|
+
}
|
|
33219
|
+
prepare() {
|
|
33220
|
+
return this._prepare(true);
|
|
33221
|
+
}
|
|
33222
|
+
async execute(placeholderValues) {
|
|
33223
|
+
return this._prepare().execute(placeholderValues);
|
|
33224
|
+
}
|
|
33225
|
+
};
|
|
33226
|
+
var SQLiteSyncRelationalQuery = class extends SQLiteAsyncRelationalQuery {
|
|
33227
|
+
static [entityKind] = "SQLiteSyncRelationalQueryV2";
|
|
33228
|
+
sync(placeholderValues) {
|
|
33229
|
+
return this._prepare().execute(placeholderValues).sync();
|
|
33230
|
+
}
|
|
33231
|
+
};
|
|
33232
|
+
applyMixins(SQLiteAsyncRelationalQuery, [QueryPromise]);
|
|
33233
|
+
|
|
33234
|
+
// ../../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
|
|
33235
|
+
var SQLiteDeleteBase = class {
|
|
33236
|
+
static [entityKind] = "SQLiteDelete";
|
|
33237
|
+
/** @internal */
|
|
33238
|
+
config;
|
|
33239
|
+
constructor(table, session, dialect, withList) {
|
|
33240
|
+
this.table = table;
|
|
33241
|
+
this.session = session;
|
|
33242
|
+
this.dialect = dialect;
|
|
33243
|
+
this.config = {
|
|
33244
|
+
table,
|
|
33245
|
+
withList
|
|
33246
|
+
};
|
|
33247
|
+
}
|
|
33248
|
+
/**
|
|
33249
|
+
* Adds a `where` clause to the query.
|
|
33250
|
+
*
|
|
33251
|
+
* Calling this method will delete only those rows that fulfill a specified condition.
|
|
33252
|
+
*
|
|
33253
|
+
* See docs: {@link https://orm.drizzle.team/docs/delete}
|
|
33254
|
+
*
|
|
33255
|
+
* @param where the `where` clause.
|
|
33256
|
+
*
|
|
33257
|
+
* @example
|
|
33258
|
+
* You can use conditional operators and `sql function` to filter the rows to be deleted.
|
|
33259
|
+
*
|
|
33260
|
+
* ```ts
|
|
33261
|
+
* // Delete all cars with green color
|
|
33262
|
+
* db.delete(cars).where(eq(cars.color, 'green'));
|
|
33263
|
+
* // or
|
|
33264
|
+
* db.delete(cars).where(sql`${cars.color} = 'green'`)
|
|
33265
|
+
* ```
|
|
33266
|
+
*
|
|
33267
|
+
* You can logically combine conditional operators with `and()` and `or()` operators:
|
|
33268
|
+
*
|
|
33269
|
+
* ```ts
|
|
33270
|
+
* // Delete all BMW cars with a green color
|
|
33271
|
+
* db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
|
33272
|
+
*
|
|
33273
|
+
* // Delete all cars with the green or blue color
|
|
33274
|
+
* db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
33275
|
+
* ```
|
|
33276
|
+
*/
|
|
33277
|
+
where(where) {
|
|
33278
|
+
this.config.where = where;
|
|
33279
|
+
return this;
|
|
33280
|
+
}
|
|
33281
|
+
orderBy(...columns) {
|
|
33282
|
+
if (typeof columns[0] === "function") {
|
|
33283
|
+
const orderBy = columns[0](new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
|
|
33284
|
+
sqlAliasedBehavior: "alias",
|
|
33285
|
+
sqlBehavior: "sql"
|
|
33286
|
+
})));
|
|
33287
|
+
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
33288
|
+
this.config.orderBy = orderByArray;
|
|
33289
|
+
} else {
|
|
33290
|
+
const orderByArray = columns;
|
|
33291
|
+
this.config.orderBy = orderByArray;
|
|
33292
|
+
}
|
|
33293
|
+
return this;
|
|
33294
|
+
}
|
|
33295
|
+
limit(limit) {
|
|
33296
|
+
this.config.limit = limit;
|
|
33297
|
+
return this;
|
|
33298
|
+
}
|
|
33299
|
+
returning(fields = this.table[SQLiteTable.Symbol.Columns]) {
|
|
33300
|
+
this.config.returning = orderSelectedFields(fields);
|
|
33301
|
+
return this;
|
|
33302
|
+
}
|
|
33303
|
+
getSQL() {
|
|
33304
|
+
return this.dialect.buildDeleteQuery(this.config);
|
|
33305
|
+
}
|
|
33306
|
+
toSQL() {
|
|
33307
|
+
return this.dialect.sqlToQuery(this.getSQL());
|
|
33308
|
+
}
|
|
33309
|
+
$dynamic() {
|
|
33310
|
+
return this;
|
|
33311
|
+
}
|
|
33312
|
+
};
|
|
33313
|
+
|
|
33314
|
+
// ../../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
|
|
33315
|
+
var SQLiteAsyncDeleteBase = class extends SQLiteDeleteBase {
|
|
33316
|
+
static [entityKind] = "SQLiteAsyncDelete";
|
|
33317
|
+
/** @internal */
|
|
33318
|
+
_prepare(prepare = false) {
|
|
33319
|
+
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, {
|
|
33320
|
+
type: "delete",
|
|
33321
|
+
tables: extractUsedTable(this.config.table)
|
|
33322
|
+
});
|
|
33323
|
+
}
|
|
33324
|
+
prepare() {
|
|
33325
|
+
return this._prepare(true);
|
|
33326
|
+
}
|
|
33327
|
+
run = (placeholderValues) => {
|
|
33328
|
+
return this._prepare().run(placeholderValues);
|
|
33329
|
+
};
|
|
33330
|
+
all = (placeholderValues) => {
|
|
33331
|
+
return this._prepare().all(placeholderValues);
|
|
33332
|
+
};
|
|
33333
|
+
get = (placeholderValues) => {
|
|
33334
|
+
return this._prepare().get(placeholderValues);
|
|
33335
|
+
};
|
|
33336
|
+
values = (placeholderValues) => {
|
|
33337
|
+
return this._prepare().values(placeholderValues);
|
|
33338
|
+
};
|
|
33339
|
+
async execute(placeholderValues) {
|
|
33340
|
+
return this._prepare().execute(placeholderValues);
|
|
33341
|
+
}
|
|
33342
|
+
};
|
|
33343
|
+
applyMixins(SQLiteAsyncDeleteBase, [QueryPromise]);
|
|
33344
|
+
|
|
33290
33345
|
// ../../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
|
|
33291
33346
|
var SQLiteInsertBuilder = class {
|
|
33292
33347
|
static [entityKind] = "SQLiteInsertBuilder";
|
|
@@ -34174,129 +34229,6 @@ var SQLiteAsyncTransaction = class extends SQLiteAsyncDatabase {
|
|
|
34174
34229
|
}
|
|
34175
34230
|
};
|
|
34176
34231
|
|
|
34177
|
-
// ../../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
|
|
34178
|
-
var NodeSQLiteSession = class extends SQLiteAsyncSession {
|
|
34179
|
-
static [entityKind] = "SQLJsSession";
|
|
34180
|
-
logger;
|
|
34181
|
-
constructor(client2, dialect, relations, options = {}) {
|
|
34182
|
-
super(dialect, "sync");
|
|
34183
|
-
this.client = client2;
|
|
34184
|
-
this.relations = relations;
|
|
34185
|
-
this.options = options;
|
|
34186
|
-
this.logger = options.logger ?? new NoopLogger();
|
|
34187
|
-
}
|
|
34188
|
-
prepareQuery(query, mode, _prepare, executeMethod, mapper, queryMetadata) {
|
|
34189
|
-
let stmt;
|
|
34190
|
-
try {
|
|
34191
|
-
stmt = this.client.prepare(query.sql);
|
|
34192
|
-
} catch (e) {
|
|
34193
|
-
throw new DrizzleQueryError(query.sql, query.params, e);
|
|
34194
|
-
}
|
|
34195
|
-
return new SQLiteAsyncPreparedQuery("sync", executeMethod, {
|
|
34196
|
-
all: (params) => {
|
|
34197
|
-
stmt.setReturnArrays(mode === "arrays");
|
|
34198
|
-
const res = stmt.all(...params);
|
|
34199
|
-
if (mode === "objects") return res.map((row) => ({ ...row }));
|
|
34200
|
-
return res;
|
|
34201
|
-
},
|
|
34202
|
-
get: (params) => {
|
|
34203
|
-
stmt.setReturnArrays(mode === "arrays");
|
|
34204
|
-
const res = stmt.get(...params);
|
|
34205
|
-
if (res && mode === "objects") return { ...res };
|
|
34206
|
-
return res;
|
|
34207
|
-
},
|
|
34208
|
-
run: (params) => {
|
|
34209
|
-
stmt.setReturnArrays(false);
|
|
34210
|
-
return stmt.run(...params);
|
|
34211
|
-
},
|
|
34212
|
-
values: (params) => {
|
|
34213
|
-
stmt.setReturnArrays(true);
|
|
34214
|
-
return stmt.all(...params);
|
|
34215
|
-
}
|
|
34216
|
-
}, query, mapper, mode, this.logger, void 0, queryMetadata, void 0);
|
|
34217
|
-
}
|
|
34218
|
-
transaction(transaction, config2 = {}) {
|
|
34219
|
-
const tx = new NodeSQLiteTransaction("sync", this.dialect, this, this.relations);
|
|
34220
|
-
this.run(sql.raw(`begin${config2.behavior ? ` ${config2.behavior}` : ""}`));
|
|
34221
|
-
try {
|
|
34222
|
-
const result = transaction(tx);
|
|
34223
|
-
this.run(sql`commit`);
|
|
34224
|
-
return result;
|
|
34225
|
-
} catch (err) {
|
|
34226
|
-
this.run(sql`rollback`);
|
|
34227
|
-
throw err;
|
|
34228
|
-
}
|
|
34229
|
-
}
|
|
34230
|
-
};
|
|
34231
|
-
var NodeSQLiteTransaction = class NodeSQLiteTransaction2 extends SQLiteAsyncTransaction {
|
|
34232
|
-
static [entityKind] = "SQLJsTransaction";
|
|
34233
|
-
transaction(transaction) {
|
|
34234
|
-
const savepointName = `sp${this.nestedIndex + 1}`;
|
|
34235
|
-
const tx = new NodeSQLiteTransaction2("sync", this.dialect, this.session, this._.relations, this.nestedIndex + 1);
|
|
34236
|
-
tx.run(sql.raw(`savepoint ${savepointName}`));
|
|
34237
|
-
try {
|
|
34238
|
-
const result = transaction(tx);
|
|
34239
|
-
tx.run(sql.raw(`release savepoint ${savepointName}`));
|
|
34240
|
-
return result;
|
|
34241
|
-
} catch (err) {
|
|
34242
|
-
tx.run(sql.raw(`rollback to savepoint ${savepointName}`));
|
|
34243
|
-
throw err;
|
|
34244
|
-
}
|
|
34245
|
-
}
|
|
34246
|
-
};
|
|
34247
|
-
|
|
34248
|
-
// ../../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
|
|
34249
|
-
import { DatabaseSync } from "node:sqlite";
|
|
34250
|
-
var NodeSQLiteDatabase = class extends SQLiteAsyncDatabase {
|
|
34251
|
-
static [entityKind] = "NodeSQLiteDatabase";
|
|
34252
|
-
};
|
|
34253
|
-
function construct(client2, config2 = {}) {
|
|
34254
|
-
const dialect = new SQLiteDialect({ useJitMappers: jitCompatCheck(config2.jit) });
|
|
34255
|
-
let logger;
|
|
34256
|
-
if (config2.logger === true) logger = new DefaultLogger();
|
|
34257
|
-
else if (config2.logger !== false) logger = config2.logger;
|
|
34258
|
-
const relations = config2.relations ?? {};
|
|
34259
|
-
const db = new NodeSQLiteDatabase("sync", dialect, new NodeSQLiteSession(client2, dialect, relations, { logger }), relations);
|
|
34260
|
-
db.$client = client2;
|
|
34261
|
-
return db;
|
|
34262
|
-
}
|
|
34263
|
-
function drizzle(...params) {
|
|
34264
|
-
if (params[0] === void 0 || typeof params[0] === "string") return construct(params[0] === void 0 ? new DatabaseSync(":memory:") : new DatabaseSync(params[0]), params[1]);
|
|
34265
|
-
const { connection, client: client2, ...config2 } = params[0];
|
|
34266
|
-
if (client2) return construct(client2, config2);
|
|
34267
|
-
if (typeof connection === "object") {
|
|
34268
|
-
const { path: path2, ...options } = connection;
|
|
34269
|
-
return construct(new DatabaseSync(path2 ?? ":memory:", options), config2);
|
|
34270
|
-
}
|
|
34271
|
-
return construct(new DatabaseSync(connection ?? ":memory:"), config2);
|
|
34272
|
-
}
|
|
34273
|
-
(function(_drizzle) {
|
|
34274
|
-
function mock(config2) {
|
|
34275
|
-
return construct({}, config2);
|
|
34276
|
-
}
|
|
34277
|
-
_drizzle.mock = mock;
|
|
34278
|
-
})(drizzle || (drizzle = {}));
|
|
34279
|
-
|
|
34280
|
-
// src/generated/acp-session-store-migrations.ts
|
|
34281
|
-
var acpSessionStoreMigrations = [
|
|
34282
|
-
{
|
|
34283
|
-
"name": "0000_slimy_captain_midlands.sql",
|
|
34284
|
-
"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"
|
|
34285
|
-
},
|
|
34286
|
-
{
|
|
34287
|
-
"name": "0001_regular_ultimates.sql",
|
|
34288
|
-
"sql": "ALTER TABLE `acp_session` ADD `last_terminal_command_id` text;"
|
|
34289
|
-
},
|
|
34290
|
-
{
|
|
34291
|
-
"name": "0002_equal_black_queen.sql",
|
|
34292
|
-
"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`);"
|
|
34293
|
-
},
|
|
34294
|
-
{
|
|
34295
|
-
"name": "0003_silky_ravenous.sql",
|
|
34296
|
-
"sql": "DROP TABLE `session_event_v2`;"
|
|
34297
|
-
}
|
|
34298
|
-
];
|
|
34299
|
-
|
|
34300
34232
|
// src/schema/acp-session-store/acp-session.ts
|
|
34301
34233
|
var acpSession = sqliteTable("acp_session", {
|
|
34302
34234
|
sessionId: text("session_id").primaryKey(),
|
|
@@ -34304,33 +34236,235 @@ var acpSession = sqliteTable("acp_session", {
|
|
|
34304
34236
|
nativeSessionId: text("native_session_id").notNull(),
|
|
34305
34237
|
cwd: text("cwd").notNull(),
|
|
34306
34238
|
additionalDirectories: text("additional_directories").notNull(),
|
|
34307
|
-
lastTerminalCommandId: text("last_terminal_command_id"),
|
|
34308
34239
|
prompted: integer2("prompted", { mode: "boolean" }).notNull(),
|
|
34309
34240
|
title: text("title").notNull(),
|
|
34310
34241
|
updatedAt: text("updated_at").notNull()
|
|
34311
34242
|
});
|
|
34312
34243
|
|
|
34313
|
-
// src/schema/
|
|
34314
|
-
var
|
|
34315
|
-
|
|
34316
|
-
|
|
34244
|
+
// src/schema/session-event-cache/session-event-v2.ts
|
|
34245
|
+
var sessionEventV2 = sqliteTable(
|
|
34246
|
+
"session_event_v2",
|
|
34247
|
+
{
|
|
34248
|
+
eventJson: text("event_json").notNull(),
|
|
34249
|
+
generationId: text("generation_id").notNull(),
|
|
34250
|
+
position: integer2("position").notNull(),
|
|
34251
|
+
sessionId: text("session_id").notNull()
|
|
34252
|
+
},
|
|
34253
|
+
(table) => [
|
|
34254
|
+
primaryKey({ columns: [table.generationId, table.sessionId, table.position] }),
|
|
34255
|
+
index("session_event_v2_generation_session_position_index").on(
|
|
34256
|
+
table.generationId,
|
|
34257
|
+
table.sessionId,
|
|
34258
|
+
table.position
|
|
34259
|
+
)
|
|
34260
|
+
]
|
|
34261
|
+
);
|
|
34262
|
+
|
|
34263
|
+
// src/acp/session-event-store-v2.ts
|
|
34264
|
+
var HOT_EVENT_HIGH_WATER_MARK = 256;
|
|
34265
|
+
var HOT_EVENT_RETENTION = 128;
|
|
34266
|
+
function eventPage(eventCount, eventLimit, cursor, read) {
|
|
34267
|
+
const parsedCursor = cursor === null ? eventCount : Number(cursor);
|
|
34268
|
+
if (!Number.isSafeInteger(parsedCursor) || parsedCursor < 0 || parsedCursor > eventCount) {
|
|
34269
|
+
throw new Error("The native event cursor is invalid");
|
|
34270
|
+
}
|
|
34271
|
+
const endPosition = parsedCursor;
|
|
34272
|
+
const startPosition = Math.max(0, endPosition - eventLimit);
|
|
34273
|
+
return {
|
|
34274
|
+
events: read(startPosition + 1, endPosition),
|
|
34275
|
+
nextCursor: startPosition === 0 ? null : startPosition.toString(),
|
|
34276
|
+
startPosition: startPosition + 1,
|
|
34277
|
+
truncated: startPosition > 0
|
|
34278
|
+
};
|
|
34279
|
+
}
|
|
34280
|
+
var MemoryAcpSessionEventStoreV2 = class {
|
|
34281
|
+
generationId;
|
|
34282
|
+
#events = /* @__PURE__ */ new Map();
|
|
34283
|
+
constructor(generationId) {
|
|
34284
|
+
this.generationId = generationId;
|
|
34285
|
+
}
|
|
34286
|
+
append = (sessionId, event) => {
|
|
34287
|
+
const events = this.#events.get(sessionId) ?? [];
|
|
34288
|
+
events.push(event);
|
|
34289
|
+
this.#events.set(sessionId, events);
|
|
34290
|
+
return events.length;
|
|
34291
|
+
};
|
|
34292
|
+
close = () => this.#events.clear();
|
|
34293
|
+
page = (sessionId, eventLimit, cursor) => {
|
|
34294
|
+
const events = this.#events.get(sessionId) ?? [];
|
|
34295
|
+
return eventPage(
|
|
34296
|
+
events.length,
|
|
34297
|
+
eventLimit,
|
|
34298
|
+
cursor,
|
|
34299
|
+
(startPosition, endPosition) => events.slice(startPosition - 1, endPosition)
|
|
34300
|
+
);
|
|
34301
|
+
};
|
|
34302
|
+
remove = (sessionId) => {
|
|
34303
|
+
this.#events.delete(sessionId);
|
|
34304
|
+
};
|
|
34305
|
+
reset = this.remove;
|
|
34306
|
+
};
|
|
34307
|
+
var cachedEventRowSchema = external_exports.object({ eventJson: external_exports.string(), position: external_exports.number().int().positive() });
|
|
34308
|
+
function decodeCachedEvent(value) {
|
|
34309
|
+
const payload = external_exports.record(external_exports.string(), external_exports.unknown()).parse(value);
|
|
34310
|
+
const event = decodeSessionEventV2({
|
|
34311
|
+
...payload,
|
|
34312
|
+
eventId: "cached-event",
|
|
34313
|
+
position: "1",
|
|
34314
|
+
provenance: { kind: "original" },
|
|
34315
|
+
recordedAt: "1970-01-01T00:00:00.000Z",
|
|
34316
|
+
sessionId: "cached-session"
|
|
34317
|
+
});
|
|
34318
|
+
return event.type === "acp" ? { payload: event.payload, type: event.type } : { payload: event.payload, type: event.type };
|
|
34319
|
+
}
|
|
34320
|
+
var CachedAcpSessionEventStoreV2 = class {
|
|
34321
|
+
generationId;
|
|
34322
|
+
#database;
|
|
34323
|
+
#ignoredPersistedSessions = /* @__PURE__ */ new Set();
|
|
34324
|
+
#localDatabase;
|
|
34325
|
+
#sessions = /* @__PURE__ */ new Map();
|
|
34326
|
+
#flushSchedule = { kind: "idle" };
|
|
34327
|
+
#isLocalDBAvailable = true;
|
|
34328
|
+
constructor(localDatabase, generationId) {
|
|
34329
|
+
this.generationId = generationId;
|
|
34330
|
+
this.#localDatabase = localDatabase;
|
|
34331
|
+
this.#database = localDatabase.orm;
|
|
34332
|
+
try {
|
|
34333
|
+
this.#localDatabase.transaction(() => this.#database.delete(sessionEventV2).run());
|
|
34334
|
+
} catch (error62) {
|
|
34335
|
+
this.#localDatabase.close();
|
|
34336
|
+
throw error62;
|
|
34337
|
+
}
|
|
34338
|
+
}
|
|
34339
|
+
append = (sessionId, event) => {
|
|
34340
|
+
if (this.#flushSchedule.kind === "closed") {
|
|
34341
|
+
throw new Error("The V2 Session event store is closed");
|
|
34342
|
+
}
|
|
34343
|
+
const session = this.#sessions.get(sessionId) ?? { hot: [], nextPosition: 1 };
|
|
34344
|
+
const position = session.nextPosition;
|
|
34345
|
+
session.hot.push({ event, position });
|
|
34346
|
+
session.nextPosition += 1;
|
|
34347
|
+
this.#sessions.set(sessionId, session);
|
|
34348
|
+
if (session.hot.length > HOT_EVENT_HIGH_WATER_MARK) {
|
|
34349
|
+
this.#scheduleFlush();
|
|
34350
|
+
}
|
|
34351
|
+
return position;
|
|
34352
|
+
};
|
|
34353
|
+
#scheduleFlush = () => {
|
|
34354
|
+
if (!this.#isLocalDBAvailable || this.#flushSchedule.kind !== "idle") {
|
|
34355
|
+
return;
|
|
34356
|
+
}
|
|
34357
|
+
const handle = setImmediate(() => {
|
|
34358
|
+
if (this.#flushSchedule.kind !== "scheduled" || this.#flushSchedule.handle !== handle) {
|
|
34359
|
+
return;
|
|
34360
|
+
}
|
|
34361
|
+
this.#flushSchedule = { kind: "idle" };
|
|
34362
|
+
this.#flush(false);
|
|
34363
|
+
});
|
|
34364
|
+
this.#flushSchedule = { handle, kind: "scheduled" };
|
|
34365
|
+
};
|
|
34366
|
+
#flush = (includeHotTail) => {
|
|
34367
|
+
if (!this.#isLocalDBAvailable || this.#flushSchedule.kind === "closed") {
|
|
34368
|
+
return;
|
|
34369
|
+
}
|
|
34370
|
+
const batches = [...this.#sessions.entries()].flatMap(([sessionId, session]) => {
|
|
34371
|
+
const count = includeHotTail ? session.hot.length : Math.max(0, session.hot.length - HOT_EVENT_RETENTION);
|
|
34372
|
+
return count === 0 ? [] : [{ count, events: session.hot.slice(0, count), sessionId }];
|
|
34373
|
+
});
|
|
34374
|
+
const values = batches.flatMap(
|
|
34375
|
+
(batch) => batch.events.map(({ event, position }) => ({
|
|
34376
|
+
eventJson: JSON.stringify(event),
|
|
34377
|
+
generationId: this.generationId,
|
|
34378
|
+
position,
|
|
34379
|
+
sessionId: batch.sessionId
|
|
34380
|
+
}))
|
|
34381
|
+
);
|
|
34382
|
+
if (values.length === 0) {
|
|
34383
|
+
return;
|
|
34384
|
+
}
|
|
34385
|
+
try {
|
|
34386
|
+
this.#localDatabase.transaction(() => {
|
|
34387
|
+
for (let offset = 0; offset < values.length; offset += 200) {
|
|
34388
|
+
this.#database.insert(sessionEventV2).values(values.slice(offset, offset + 200)).run();
|
|
34389
|
+
}
|
|
34390
|
+
});
|
|
34391
|
+
for (const batch of batches) {
|
|
34392
|
+
this.#sessions.get(batch.sessionId)?.hot.splice(0, batch.count);
|
|
34393
|
+
}
|
|
34394
|
+
} catch (cause) {
|
|
34395
|
+
this.#isLocalDBAvailable = false;
|
|
34396
|
+
console.warn("Mobius V2 Session event cache writes are unavailable; retaining events in memory", cause);
|
|
34397
|
+
}
|
|
34398
|
+
};
|
|
34399
|
+
page = (sessionId, eventLimit, cursor) => {
|
|
34400
|
+
const session = this.#sessions.get(sessionId);
|
|
34401
|
+
const eventCount = (session?.nextPosition ?? 1) - 1;
|
|
34402
|
+
return eventPage(eventCount, eventLimit, cursor, (startPosition, endPosition) => {
|
|
34403
|
+
const persisted = this.#ignoredPersistedSessions.has(sessionId) ? [] : this.#database.select({ eventJson: sessionEventV2.eventJson, position: sessionEventV2.position }).from(sessionEventV2).where(
|
|
34404
|
+
and(
|
|
34405
|
+
eq(sessionEventV2.generationId, this.generationId),
|
|
34406
|
+
eq(sessionEventV2.sessionId, sessionId),
|
|
34407
|
+
gte(sessionEventV2.position, startPosition),
|
|
34408
|
+
lte(sessionEventV2.position, endPosition)
|
|
34409
|
+
)
|
|
34410
|
+
).orderBy(asc(sessionEventV2.position)).all().map((value) => {
|
|
34411
|
+
const row = cachedEventRowSchema.parse(value);
|
|
34412
|
+
return { event: decodeCachedEvent(JSON.parse(row.eventJson)), position: row.position };
|
|
34413
|
+
});
|
|
34414
|
+
const hot = (session?.hot ?? []).filter(
|
|
34415
|
+
({ position }) => position >= startPosition && position <= endPosition
|
|
34416
|
+
);
|
|
34417
|
+
return [...persisted, ...hot].toSorted((left, right) => left.position - right.position).map(({ event }) => event);
|
|
34418
|
+
});
|
|
34419
|
+
};
|
|
34420
|
+
#deletePersisted = (sessionId) => {
|
|
34421
|
+
if (!this.#isLocalDBAvailable) {
|
|
34422
|
+
this.#ignoredPersistedSessions.add(sessionId);
|
|
34423
|
+
return;
|
|
34424
|
+
}
|
|
34425
|
+
try {
|
|
34426
|
+
this.#database.delete(sessionEventV2).where(and(eq(sessionEventV2.generationId, this.generationId), eq(sessionEventV2.sessionId, sessionId))).run();
|
|
34427
|
+
this.#ignoredPersistedSessions.delete(sessionId);
|
|
34428
|
+
} catch (cause) {
|
|
34429
|
+
this.#isLocalDBAvailable = false;
|
|
34430
|
+
this.#ignoredPersistedSessions.add(sessionId);
|
|
34431
|
+
console.warn("Mobius V2 Session event cache writes are unavailable; retaining events in memory", cause);
|
|
34432
|
+
}
|
|
34433
|
+
};
|
|
34434
|
+
remove = (sessionId) => {
|
|
34435
|
+
this.#deletePersisted(sessionId);
|
|
34436
|
+
this.#sessions.delete(sessionId);
|
|
34437
|
+
};
|
|
34438
|
+
reset = this.remove;
|
|
34439
|
+
close = () => {
|
|
34440
|
+
if (this.#flushSchedule.kind === "closed") {
|
|
34441
|
+
return;
|
|
34442
|
+
}
|
|
34443
|
+
if (this.#flushSchedule.kind === "scheduled") {
|
|
34444
|
+
clearImmediate(this.#flushSchedule.handle);
|
|
34445
|
+
}
|
|
34446
|
+
this.#flushSchedule = { kind: "idle" };
|
|
34447
|
+
this.#flush(true);
|
|
34448
|
+
this.#flushSchedule = { kind: "closed" };
|
|
34449
|
+
this.#localDatabase.close();
|
|
34450
|
+
this.#sessions.clear();
|
|
34451
|
+
};
|
|
34452
|
+
};
|
|
34317
34453
|
|
|
34318
34454
|
// src/acp/session-store.ts
|
|
34319
34455
|
var AcpStoredSession = class {
|
|
34320
34456
|
additionalDirectories;
|
|
34321
34457
|
agentId;
|
|
34322
34458
|
cwd;
|
|
34323
|
-
lastTerminalCommandId;
|
|
34324
34459
|
nativeSessionId;
|
|
34325
34460
|
prompted;
|
|
34326
34461
|
sessionId;
|
|
34327
34462
|
title;
|
|
34328
34463
|
updatedAt;
|
|
34329
|
-
constructor(sessionId, agentId, nativeSessionId, cwd, additionalDirectories, prompted, title2, updatedAt = (/* @__PURE__ */ new Date()).toISOString()
|
|
34464
|
+
constructor(sessionId, agentId, nativeSessionId, cwd, additionalDirectories, prompted, title2, updatedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
34330
34465
|
this.additionalDirectories = [...additionalDirectories];
|
|
34331
34466
|
this.agentId = agentId;
|
|
34332
34467
|
this.cwd = cwd;
|
|
34333
|
-
this.lastTerminalCommandId = lastTerminalCommandId;
|
|
34334
34468
|
this.nativeSessionId = nativeSessionId;
|
|
34335
34469
|
this.prompted = prompted;
|
|
34336
34470
|
this.sessionId = sessionId;
|
|
@@ -34351,37 +34485,27 @@ var FoundAcpStoredSession = class extends AcpStoredSessionLookup {
|
|
|
34351
34485
|
this.session = session;
|
|
34352
34486
|
}
|
|
34353
34487
|
};
|
|
34354
|
-
var DeletedAcpStoredSession = class extends AcpStoredSessionLookup {
|
|
34355
|
-
found = false;
|
|
34356
|
-
};
|
|
34357
34488
|
var MemoryAcpSessionStore = class {
|
|
34489
|
+
eventsV2;
|
|
34358
34490
|
#sessions = /* @__PURE__ */ new Map();
|
|
34359
|
-
|
|
34491
|
+
constructor(eventsV2 = new MemoryAcpSessionEventStoreV2(randomUUID())) {
|
|
34492
|
+
this.eventsV2 = eventsV2;
|
|
34493
|
+
}
|
|
34360
34494
|
close = () => {
|
|
34361
34495
|
this.#sessions.clear();
|
|
34362
|
-
this
|
|
34496
|
+
this.eventsV2.close();
|
|
34363
34497
|
};
|
|
34364
34498
|
findNative = (agentId, nativeSessionId) => [...this.#sessions.values()].filter(
|
|
34365
34499
|
(session) => session.agentId === agentId && session.nativeSessionId === nativeSessionId
|
|
34366
34500
|
);
|
|
34367
34501
|
list = () => [...this.#sessions.values()].toSorted((left, right) => right.updatedAt.localeCompare(left.updatedAt));
|
|
34368
|
-
markDeleted = (agentId, nativeSessionId) => {
|
|
34369
|
-
const ids = this.findNative(agentId, nativeSessionId).map((session) => session.sessionId);
|
|
34370
|
-
for (const id of ids) {
|
|
34371
|
-
this.#sessions.delete(id);
|
|
34372
|
-
this.#deleted.add(id);
|
|
34373
|
-
}
|
|
34374
|
-
return ids;
|
|
34375
|
-
};
|
|
34376
34502
|
read = (sessionId) => {
|
|
34377
|
-
if (this.#deleted.has(sessionId)) {
|
|
34378
|
-
return new DeletedAcpStoredSession();
|
|
34379
|
-
}
|
|
34380
34503
|
const session = this.#sessions.get(sessionId);
|
|
34381
34504
|
return session === void 0 ? new MissingAcpStoredSession() : new FoundAcpStoredSession(session);
|
|
34382
34505
|
};
|
|
34383
34506
|
remove = (sessionId) => {
|
|
34384
34507
|
this.#sessions.delete(sessionId);
|
|
34508
|
+
this.eventsV2.remove(sessionId);
|
|
34385
34509
|
};
|
|
34386
34510
|
write = (session) => {
|
|
34387
34511
|
this.#sessions.set(session.sessionId, session);
|
|
@@ -34391,14 +34515,12 @@ var storedSessionRowSchema = external_exports.object({
|
|
|
34391
34515
|
additionalDirectories: external_exports.string(),
|
|
34392
34516
|
agentId: external_exports.string(),
|
|
34393
34517
|
cwd: external_exports.string(),
|
|
34394
|
-
lastTerminalCommandId: external_exports.string().nullable(),
|
|
34395
34518
|
nativeSessionId: external_exports.string(),
|
|
34396
34519
|
prompted: external_exports.boolean(),
|
|
34397
34520
|
sessionId: external_exports.string(),
|
|
34398
34521
|
title: external_exports.string(),
|
|
34399
34522
|
updatedAt: external_exports.string()
|
|
34400
34523
|
});
|
|
34401
|
-
var sessionIdRowSchema = external_exports.object({ sessionId: external_exports.string() });
|
|
34402
34524
|
function decodeStoredSession(value) {
|
|
34403
34525
|
const row = storedSessionRowSchema.parse(value);
|
|
34404
34526
|
const decodedAdditionalDirectories = JSON.parse(row.additionalDirectories);
|
|
@@ -34411,98 +34533,47 @@ function decodeStoredSession(value) {
|
|
|
34411
34533
|
additionalDirectories,
|
|
34412
34534
|
row.prompted,
|
|
34413
34535
|
row.title,
|
|
34414
|
-
row.updatedAt
|
|
34415
|
-
row.lastTerminalCommandId
|
|
34536
|
+
row.updatedAt
|
|
34416
34537
|
);
|
|
34417
34538
|
}
|
|
34418
34539
|
var SqliteAcpSessionStore = class {
|
|
34540
|
+
eventsV2;
|
|
34419
34541
|
#database;
|
|
34420
|
-
#
|
|
34421
|
-
constructor(
|
|
34422
|
-
|
|
34423
|
-
this.#
|
|
34424
|
-
|
|
34425
|
-
this.#migrate();
|
|
34426
|
-
this.#database = drizzle({ client: this.#sqliteDatabase });
|
|
34542
|
+
#localDatabase;
|
|
34543
|
+
constructor(localDatabase, eventsV2 = new MemoryAcpSessionEventStoreV2(randomUUID())) {
|
|
34544
|
+
this.eventsV2 = eventsV2;
|
|
34545
|
+
this.#localDatabase = localDatabase;
|
|
34546
|
+
this.#database = localDatabase.orm;
|
|
34427
34547
|
}
|
|
34428
|
-
|
|
34429
|
-
const version2 = external_exports.object({ user_version: external_exports.number().int().nonnegative() }).parse(this.#sqliteDatabase.prepare("PRAGMA user_version").get()).user_version;
|
|
34430
|
-
if (version2 > acpSessionStoreMigrations.length) {
|
|
34431
|
-
this.#sqliteDatabase.close();
|
|
34432
|
-
throw new Error("The ACP Session database was created by a newer Mobius version");
|
|
34433
|
-
}
|
|
34434
|
-
for (let index = version2; index < acpSessionStoreMigrations.length; index += 1) {
|
|
34435
|
-
const migration = acpSessionStoreMigrations[index];
|
|
34436
|
-
if (migration === void 0) {
|
|
34437
|
-
throw new Error("The ACP Session migration is unavailable");
|
|
34438
|
-
}
|
|
34439
|
-
this.#sqliteDatabase.exec("BEGIN IMMEDIATE");
|
|
34440
|
-
try {
|
|
34441
|
-
this.#sqliteDatabase.exec(migration.sql);
|
|
34442
|
-
this.#sqliteDatabase.exec(`PRAGMA user_version = ${index + 1}`);
|
|
34443
|
-
this.#sqliteDatabase.exec("COMMIT");
|
|
34444
|
-
} catch (error62) {
|
|
34445
|
-
this.#sqliteDatabase.exec("ROLLBACK");
|
|
34446
|
-
throw error62;
|
|
34447
|
-
}
|
|
34448
|
-
}
|
|
34449
|
-
};
|
|
34450
|
-
#transaction = (operation) => {
|
|
34451
|
-
this.#sqliteDatabase.exec("BEGIN IMMEDIATE");
|
|
34548
|
+
close = () => {
|
|
34452
34549
|
try {
|
|
34453
|
-
|
|
34454
|
-
|
|
34455
|
-
|
|
34456
|
-
this.#sqliteDatabase.exec("ROLLBACK");
|
|
34457
|
-
throw error62;
|
|
34550
|
+
this.#localDatabase.close();
|
|
34551
|
+
} finally {
|
|
34552
|
+
this.eventsV2.close();
|
|
34458
34553
|
}
|
|
34459
34554
|
};
|
|
34460
|
-
close = () => {
|
|
34461
|
-
this.#sqliteDatabase.close();
|
|
34462
|
-
};
|
|
34463
34555
|
findNative = (agentId, nativeSessionId) => this.#database.select().from(acpSession).where(and(eq(acpSession.agentId, agentId), eq(acpSession.nativeSessionId, nativeSessionId))).all().map(decodeStoredSession);
|
|
34464
34556
|
list = () => this.#database.select().from(acpSession).orderBy(desc(acpSession.updatedAt)).all().map(decodeStoredSession);
|
|
34465
|
-
markDeleted = (agentId, nativeSessionId) => {
|
|
34466
|
-
const ids = this.#database.select({ sessionId: acpSession.sessionId }).from(acpSession).where(and(eq(acpSession.agentId, agentId), eq(acpSession.nativeSessionId, nativeSessionId))).all().map((row) => sessionIdRowSchema.parse(row).sessionId);
|
|
34467
|
-
this.#transaction(() => {
|
|
34468
|
-
this.#database.delete(acpSession).where(and(eq(acpSession.agentId, agentId), eq(acpSession.nativeSessionId, nativeSessionId))).run();
|
|
34469
|
-
for (const id of ids) {
|
|
34470
|
-
this.#database.insert(deletedAcpSession).values({ sessionId: id }).onConflictDoNothing().run();
|
|
34471
|
-
}
|
|
34472
|
-
});
|
|
34473
|
-
return ids;
|
|
34474
|
-
};
|
|
34475
34557
|
read = (sessionId) => {
|
|
34476
|
-
const deleted = this.#database.select({ sessionId: deletedAcpSession.sessionId }).from(deletedAcpSession).where(eq(deletedAcpSession.sessionId, sessionId)).get();
|
|
34477
|
-
if (deleted !== void 0) {
|
|
34478
|
-
sessionIdRowSchema.parse(deleted);
|
|
34479
|
-
return new DeletedAcpStoredSession();
|
|
34480
|
-
}
|
|
34481
34558
|
const row = this.#database.select().from(acpSession).where(eq(acpSession.sessionId, sessionId)).get();
|
|
34482
34559
|
return row === void 0 ? new MissingAcpStoredSession() : new FoundAcpStoredSession(decodeStoredSession(row));
|
|
34483
34560
|
};
|
|
34484
34561
|
remove = (sessionId) => {
|
|
34485
34562
|
this.#database.delete(acpSession).where(eq(acpSession.sessionId, sessionId)).run();
|
|
34563
|
+
this.eventsV2.remove(sessionId);
|
|
34486
34564
|
};
|
|
34487
34565
|
write = (session) => {
|
|
34488
34566
|
const value = {
|
|
34489
34567
|
additionalDirectories: JSON.stringify(session.additionalDirectories),
|
|
34490
34568
|
agentId: session.agentId,
|
|
34491
34569
|
cwd: session.cwd,
|
|
34492
|
-
lastTerminalCommandId: session.lastTerminalCommandId,
|
|
34493
34570
|
nativeSessionId: session.nativeSessionId,
|
|
34494
34571
|
prompted: session.prompted,
|
|
34495
34572
|
sessionId: session.sessionId,
|
|
34496
34573
|
title: session.title,
|
|
34497
34574
|
updatedAt: session.updatedAt
|
|
34498
34575
|
};
|
|
34499
|
-
this.#
|
|
34500
|
-
this.#database.delete(deletedAcpSession).where(eq(deletedAcpSession.sessionId, session.sessionId)).run();
|
|
34501
|
-
this.#database.insert(acpSession).values(value).onConflictDoUpdate({
|
|
34502
|
-
target: acpSession.sessionId,
|
|
34503
|
-
set: value
|
|
34504
|
-
}).run();
|
|
34505
|
-
});
|
|
34576
|
+
this.#database.insert(acpSession).values(value).onConflictDoUpdate({ target: acpSession.sessionId, set: value }).run();
|
|
34506
34577
|
};
|
|
34507
34578
|
};
|
|
34508
34579
|
|
|
@@ -34515,7 +34586,7 @@ var RetryableAcpInitializationError = class extends AcpExecutionError {
|
|
|
34515
34586
|
}
|
|
34516
34587
|
};
|
|
34517
34588
|
function arraysEqual(left, right) {
|
|
34518
|
-
return left.length === right.length && left.every((value,
|
|
34589
|
+
return left.length === right.length && left.every((value, index2) => value === right[index2]);
|
|
34519
34590
|
}
|
|
34520
34591
|
function recordsEqual(left, right) {
|
|
34521
34592
|
const leftEntries = Object.entries(left);
|
|
@@ -34543,7 +34614,6 @@ var AgentSession = class _AgentSession {
|
|
|
34543
34614
|
#commands = [];
|
|
34544
34615
|
#configRevision = 0;
|
|
34545
34616
|
#configOptions = [];
|
|
34546
|
-
#lastTerminalCommandId = null;
|
|
34547
34617
|
#nativeHistoryOwnership = { kind: "unbound" };
|
|
34548
34618
|
#prompted = false;
|
|
34549
34619
|
#nativePrompt = null;
|
|
@@ -34679,12 +34749,17 @@ var AgentSession = class _AgentSession {
|
|
|
34679
34749
|
);
|
|
34680
34750
|
}
|
|
34681
34751
|
const history = await this.#completedHistory(signal, "ACP agent exited while loading history");
|
|
34682
|
-
return history.eventPage(eventLimit, cursor
|
|
34752
|
+
return history.eventPage(eventLimit, cursor);
|
|
34683
34753
|
};
|
|
34684
34754
|
async #completedHistory(signal, exitMessage) {
|
|
34685
34755
|
if (!this.#prompted && this.#nativeHistoryOwnership.kind === "fresh-session") {
|
|
34686
34756
|
if (this.#sessionLoad.kind === "not-requested") {
|
|
34687
|
-
this.#
|
|
34757
|
+
this.#store.eventsV2.reset(this.#mobiusSessionId);
|
|
34758
|
+
this.#sessionLoad = {
|
|
34759
|
+
history: new AcpHistoryReplay(this.#store.eventsV2, this.#mobiusSessionId),
|
|
34760
|
+
kind: "loaded",
|
|
34761
|
+
response: {}
|
|
34762
|
+
};
|
|
34688
34763
|
}
|
|
34689
34764
|
if (this.#sessionLoad.kind === "loaded") {
|
|
34690
34765
|
return this.#sessionLoad.history;
|
|
@@ -34699,7 +34774,8 @@ var AgentSession = class _AgentSession {
|
|
|
34699
34774
|
if (this.#sessionLoad.kind === "capturing") {
|
|
34700
34775
|
return await waitForSharedOperation(this.#sessionLoad.completion, signal);
|
|
34701
34776
|
}
|
|
34702
|
-
|
|
34777
|
+
this.#store.eventsV2.reset(this.#mobiusSessionId);
|
|
34778
|
+
const history = new AcpHistoryReplay(this.#store.eventsV2, this.#mobiusSessionId);
|
|
34703
34779
|
const completion = Promise.resolve().then(async () => {
|
|
34704
34780
|
try {
|
|
34705
34781
|
const response = await this.race(
|
|
@@ -34856,13 +34932,6 @@ var AgentSession = class _AgentSession {
|
|
|
34856
34932
|
this.#store.remove(this.#mobiusSessionId);
|
|
34857
34933
|
stored = this.#metrics.measureSync("session-state-read", () => this.#store.read(this.#mobiusSessionId));
|
|
34858
34934
|
}
|
|
34859
|
-
if (stored instanceof DeletedAcpStoredSession) {
|
|
34860
|
-
throw new AcpExecutionError(
|
|
34861
|
-
"The native Agent session was deleted. Start a new chat.",
|
|
34862
|
-
{},
|
|
34863
|
-
"native_session_deleted"
|
|
34864
|
-
);
|
|
34865
|
-
}
|
|
34866
34935
|
let lifecycleResponse;
|
|
34867
34936
|
if (origin?.kind === "fork") {
|
|
34868
34937
|
if (!this.#capabilities.unstableForkSession) {
|
|
@@ -34910,7 +34979,6 @@ var AgentSession = class _AgentSession {
|
|
|
34910
34979
|
} else if (stored instanceof FoundAcpStoredSession && stored.session.agentId === this.#agentId && stored.session.cwd === this.#cwd && arraysEqual(stored.session.additionalDirectories, this.#additionalDirectories)) {
|
|
34911
34980
|
this.selectNativeSession(stored.session.nativeSessionId);
|
|
34912
34981
|
this.#prompted = stored.session.prompted;
|
|
34913
|
-
this.#lastTerminalCommandId = stored.session.lastTerminalCommandId;
|
|
34914
34982
|
this.#sessionTitle = stored.session.title;
|
|
34915
34983
|
this.#restored = true;
|
|
34916
34984
|
if (this.#capabilities.resumeSession) {
|
|
@@ -34986,8 +35054,7 @@ var AgentSession = class _AgentSession {
|
|
|
34986
35054
|
this.#additionalDirectories,
|
|
34987
35055
|
this.#prompted,
|
|
34988
35056
|
this.#sessionTitle ?? "",
|
|
34989
|
-
(/* @__PURE__ */ new Date()).toISOString()
|
|
34990
|
-
this.#lastTerminalCommandId
|
|
35057
|
+
(/* @__PURE__ */ new Date()).toISOString()
|
|
34991
35058
|
)
|
|
34992
35059
|
);
|
|
34993
35060
|
};
|
|
@@ -35016,24 +35083,6 @@ var AgentSession = class _AgentSession {
|
|
|
35016
35083
|
}
|
|
35017
35084
|
return decoded.data;
|
|
35018
35085
|
};
|
|
35019
|
-
deleteNativeSession = async (nativeSessionId, signal) => {
|
|
35020
|
-
if (!this.#capabilities.deleteSession || !this.#capabilities.listSessions) {
|
|
35021
|
-
throw new AcpExecutionError(
|
|
35022
|
-
"This Agent does not support native session deletion",
|
|
35023
|
-
{},
|
|
35024
|
-
"native_session_unsupported"
|
|
35025
|
-
);
|
|
35026
|
-
}
|
|
35027
|
-
await this.race(
|
|
35028
|
-
this.#connection.connection.agent.request(
|
|
35029
|
-
methods8.agent.session.delete,
|
|
35030
|
-
{ sessionId: nativeSessionIdSchema.parse(nativeSessionId) },
|
|
35031
|
-
{ cancellationSignal: signal }
|
|
35032
|
-
),
|
|
35033
|
-
"ACP agent exited while deleting a session",
|
|
35034
|
-
signal
|
|
35035
|
-
);
|
|
35036
|
-
};
|
|
35037
35086
|
nativeSessionId = () => this.#updates.sessionId();
|
|
35038
35087
|
adoptNativeSessionId = (sessionId) => {
|
|
35039
35088
|
if (this.#prompted || this.#updates.sessionId() !== sessionId) {
|
|
@@ -35189,8 +35238,7 @@ var AgentSession = class _AgentSession {
|
|
|
35189
35238
|
this.#additionalDirectories,
|
|
35190
35239
|
true,
|
|
35191
35240
|
this.#sessionTitle,
|
|
35192
|
-
(/* @__PURE__ */ new Date()).toISOString()
|
|
35193
|
-
this.#lastTerminalCommandId
|
|
35241
|
+
(/* @__PURE__ */ new Date()).toISOString()
|
|
35194
35242
|
)
|
|
35195
35243
|
);
|
|
35196
35244
|
this.#prompted = true;
|
|
@@ -35202,7 +35250,7 @@ var AgentSession = class _AgentSession {
|
|
|
35202
35250
|
this.prepareAgentContent
|
|
35203
35251
|
);
|
|
35204
35252
|
this.#turn = running;
|
|
35205
|
-
this.#turnHistory = completedHistory === null ? null : new AcpHistoryReplay();
|
|
35253
|
+
this.#turnHistory = completedHistory === null ? null : new AcpHistoryReplay(this.#store.eventsV2, this.#mobiusSessionId);
|
|
35206
35254
|
const lifecycleV2 = options.lifecycleV2;
|
|
35207
35255
|
if (lifecycleV2 !== void 0) {
|
|
35208
35256
|
await this.#recordLifecycleEventV2({
|
|
@@ -35259,7 +35307,6 @@ var AgentSession = class _AgentSession {
|
|
|
35259
35307
|
usage: result.usage ?? null
|
|
35260
35308
|
});
|
|
35261
35309
|
}
|
|
35262
|
-
this.#lastTerminalCommandId = options.commandId;
|
|
35263
35310
|
this.#store.write(
|
|
35264
35311
|
new AcpStoredSession(
|
|
35265
35312
|
this.#mobiusSessionId,
|
|
@@ -35269,8 +35316,7 @@ var AgentSession = class _AgentSession {
|
|
|
35269
35316
|
this.#additionalDirectories,
|
|
35270
35317
|
true,
|
|
35271
35318
|
this.#sessionTitle ?? "",
|
|
35272
|
-
(/* @__PURE__ */ new Date()).toISOString()
|
|
35273
|
-
this.#lastTerminalCommandId
|
|
35319
|
+
(/* @__PURE__ */ new Date()).toISOString()
|
|
35274
35320
|
)
|
|
35275
35321
|
);
|
|
35276
35322
|
if (lifecycleV2 !== void 0) {
|
|
@@ -35417,7 +35463,7 @@ var AgentSession = class _AgentSession {
|
|
|
35417
35463
|
if (event.type !== "lifecycle-metadata" || this.#sessionLoad.kind !== "loaded") {
|
|
35418
35464
|
return;
|
|
35419
35465
|
}
|
|
35420
|
-
const position = this.#turnHistory === null ? this.#sessionLoad.history.recordLifecycle(event) : this.#
|
|
35466
|
+
const position = this.#turnHistory === null ? this.#sessionLoad.history.recordLifecycle(event) : this.#turnHistory.recordLifecycle(event);
|
|
35421
35467
|
await this.#getObserver().onSessionEventV2?.(this.#mobiusSessionId, event, position);
|
|
35422
35468
|
};
|
|
35423
35469
|
selectNativeSession = (sessionId) => {
|
|
@@ -35438,13 +35484,8 @@ var AgentSession = class _AgentSession {
|
|
|
35438
35484
|
} else {
|
|
35439
35485
|
const onSessionEventV2 = this.#getObserver().onSessionEventV2;
|
|
35440
35486
|
if (this.#turnHistory !== null) {
|
|
35441
|
-
|
|
35442
|
-
|
|
35443
|
-
await onSessionEventV2?.(
|
|
35444
|
-
this.#mobiusSessionId,
|
|
35445
|
-
{ payload: rawUpdate, type: "acp" },
|
|
35446
|
-
completedEventCount + turnPosition
|
|
35447
|
-
);
|
|
35487
|
+
await this.#turnHistory.record(update, rawUpdate, async (position) => {
|
|
35488
|
+
await onSessionEventV2?.(this.#mobiusSessionId, { payload: rawUpdate, type: "acp" }, position);
|
|
35448
35489
|
});
|
|
35449
35490
|
} else if (this.#sessionLoad.kind === "loaded") {
|
|
35450
35491
|
await this.#sessionLoad.history.record(update, rawUpdate, async (position) => {
|
|
@@ -35558,8 +35599,7 @@ var AgentSession = class _AgentSession {
|
|
|
35558
35599
|
this.#additionalDirectories,
|
|
35559
35600
|
this.#prompted,
|
|
35560
35601
|
this.#sessionTitle ?? "",
|
|
35561
|
-
(/* @__PURE__ */ new Date()).toISOString()
|
|
35562
|
-
this.#lastTerminalCommandId
|
|
35602
|
+
(/* @__PURE__ */ new Date()).toISOString()
|
|
35563
35603
|
)
|
|
35564
35604
|
);
|
|
35565
35605
|
}
|
|
@@ -36088,9 +36128,9 @@ var AcpContentExternalizer = class {
|
|
|
36088
36128
|
};
|
|
36089
36129
|
|
|
36090
36130
|
// src/external-content/local-external-content-store.ts
|
|
36091
|
-
import { createHash as createHash2, randomUUID } from "node:crypto";
|
|
36131
|
+
import { createHash as createHash2, randomUUID as randomUUID2 } from "node:crypto";
|
|
36092
36132
|
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";
|
|
36093
|
-
import { dirname as
|
|
36133
|
+
import { dirname as dirname3, join as join15 } from "node:path";
|
|
36094
36134
|
var contentRequest = /^mobius-content:(image|audio|resource):([a-f0-9]{64})$/u;
|
|
36095
36135
|
var CONTENT_LIFETIME_MILLISECONDS = 24 * 60 * 60 * 1e3;
|
|
36096
36136
|
var metadataSchema2 = external_exports.strictObject({
|
|
@@ -36109,7 +36149,7 @@ var UnretainedExternalContentStore = class {
|
|
|
36109
36149
|
};
|
|
36110
36150
|
};
|
|
36111
36151
|
async function atomicWrite(path2, bytes, signal) {
|
|
36112
|
-
const temporary = `${path2}.${
|
|
36152
|
+
const temporary = `${path2}.${randomUUID2()}.tmp`;
|
|
36113
36153
|
try {
|
|
36114
36154
|
await writeFile3(temporary, bytes, { mode: 384, signal });
|
|
36115
36155
|
signal.throwIfAborted();
|
|
@@ -36126,7 +36166,7 @@ var LocalExternalContentStore = class {
|
|
|
36126
36166
|
#expirationTimer;
|
|
36127
36167
|
#cleanup = Promise.resolve();
|
|
36128
36168
|
constructor(stateDirectory) {
|
|
36129
|
-
this.#root = join15(stateDirectory, "tmp", "session-content",
|
|
36169
|
+
this.#root = join15(stateDirectory, "tmp", "session-content", randomUUID2());
|
|
36130
36170
|
this.#expirationTimer = setInterval(() => {
|
|
36131
36171
|
void this.#expire().catch(() => void 0);
|
|
36132
36172
|
}, 6e4);
|
|
@@ -36137,11 +36177,11 @@ var LocalExternalContentStore = class {
|
|
|
36137
36177
|
await mkdir4(this.#root, { mode: 448, recursive: true });
|
|
36138
36178
|
const now = /* @__PURE__ */ new Date();
|
|
36139
36179
|
await utimes(this.#root, now, now);
|
|
36140
|
-
for (const directory of await readdir2(
|
|
36180
|
+
for (const directory of await readdir2(dirname3(this.#root), { withFileTypes: true })) {
|
|
36141
36181
|
if (!directory.isDirectory() || !/^[a-f0-9-]{36}$/u.test(directory.name)) {
|
|
36142
36182
|
continue;
|
|
36143
36183
|
}
|
|
36144
|
-
const path2 = join15(
|
|
36184
|
+
const path2 = join15(dirname3(this.#root), directory.name);
|
|
36145
36185
|
if (path2 === this.#root) {
|
|
36146
36186
|
continue;
|
|
36147
36187
|
}
|
|
@@ -36227,12 +36267,12 @@ var LocalExternalContentStore = class {
|
|
|
36227
36267
|
}
|
|
36228
36268
|
try {
|
|
36229
36269
|
const [resolvedDirectory, resolvedPath, file2] = await Promise.all([
|
|
36230
|
-
realpath7(
|
|
36270
|
+
realpath7(dirname3(entry.path)),
|
|
36231
36271
|
realpath7(entry.path),
|
|
36232
36272
|
lstat(entry.path)
|
|
36233
36273
|
]);
|
|
36234
36274
|
signal.throwIfAborted();
|
|
36235
|
-
if (!file2.isFile() || file2.isSymbolicLink() ||
|
|
36275
|
+
if (!file2.isFile() || file2.isSymbolicLink() || dirname3(resolvedPath) !== resolvedDirectory) {
|
|
36236
36276
|
return null;
|
|
36237
36277
|
}
|
|
36238
36278
|
return { mediaType: entry.mediaType, name: entry.name, path: resolvedPath };
|
|
@@ -36309,9 +36349,9 @@ var AcpProcessCapacityLock = class {
|
|
|
36309
36349
|
return await waiter.completion.promise;
|
|
36310
36350
|
} finally {
|
|
36311
36351
|
signal.removeEventListener("abort", waiter.cancel);
|
|
36312
|
-
const
|
|
36313
|
-
if (
|
|
36314
|
-
this.#waiters.splice(
|
|
36352
|
+
const index2 = this.#waiters.indexOf(waiter);
|
|
36353
|
+
if (index2 >= 0) {
|
|
36354
|
+
this.#waiters.splice(index2, 1);
|
|
36315
36355
|
}
|
|
36316
36356
|
}
|
|
36317
36357
|
};
|
|
@@ -36600,13 +36640,6 @@ var AgentRuntimeManager = class {
|
|
|
36600
36640
|
}
|
|
36601
36641
|
prepareSession = async (options, metrics = unmeasuredOperationMetrics) => this.#operations.run(options, async (options2) => {
|
|
36602
36642
|
const stored = metrics.measureSync("session-state-read", () => this.#store.read(options2.sessionId));
|
|
36603
|
-
if (stored instanceof DeletedAcpStoredSession) {
|
|
36604
|
-
throw new AcpExecutionError(
|
|
36605
|
-
"The native Agent session was deleted. Start a new chat.",
|
|
36606
|
-
{},
|
|
36607
|
-
"native_session_deleted"
|
|
36608
|
-
);
|
|
36609
|
-
}
|
|
36610
36643
|
if (stored instanceof FoundAcpStoredSession && this.#nativeOperations.has(`${stored.session.agentId}:${stored.session.nativeSessionId}`)) {
|
|
36611
36644
|
throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
|
|
36612
36645
|
}
|
|
@@ -37055,7 +37088,7 @@ var AgentRuntimeManager = class {
|
|
|
37055
37088
|
}
|
|
37056
37089
|
});
|
|
37057
37090
|
}
|
|
37058
|
-
if (this.#executionProcesses.get(options2.sessionId) !== void 0 || this.#executionProcesses.pending(options2.sessionId) !== void 0 || this.#store.read(options2.sessionId) instanceof FoundAcpStoredSession
|
|
37091
|
+
if (this.#executionProcesses.get(options2.sessionId) !== void 0 || this.#executionProcesses.pending(options2.sessionId) !== void 0 || this.#store.read(options2.sessionId) instanceof FoundAcpStoredSession) {
|
|
37059
37092
|
throw new AcpExecutionError(
|
|
37060
37093
|
"The destination conversation already exists",
|
|
37061
37094
|
{},
|
|
@@ -37101,40 +37134,6 @@ var AgentRuntimeManager = class {
|
|
|
37101
37134
|
}
|
|
37102
37135
|
});
|
|
37103
37136
|
});
|
|
37104
|
-
deleteNativeSession = async (options, nativeSessionId) => this.#operations.run(options, async (options2) => {
|
|
37105
|
-
return await this.#queryProcesses.use(options2, async (runtime) => {
|
|
37106
|
-
const key = `${options2.agent.id}:${nativeSessionId}`;
|
|
37107
|
-
const linked = this.#store.findNative(options2.agent.id, nativeSessionId);
|
|
37108
|
-
if (this.#nativeOperations.has(key) || linked.some(
|
|
37109
|
-
(entry) => this.#executions.command(entry.sessionId) !== void 0 || this.#executionProcesses.pending(entry.sessionId) !== void 0
|
|
37110
|
-
)) {
|
|
37111
|
-
throw new AcpExecutionError(
|
|
37112
|
-
"Wait for the native session's running operation to finish",
|
|
37113
|
-
{},
|
|
37114
|
-
"session_busy"
|
|
37115
|
-
);
|
|
37116
|
-
}
|
|
37117
|
-
this.#nativeOperations.add(key);
|
|
37118
|
-
try {
|
|
37119
|
-
for (const entry of linked) {
|
|
37120
|
-
const active = this.#executionProcesses.get(entry.sessionId);
|
|
37121
|
-
if (active !== void 0 && active !== runtime) {
|
|
37122
|
-
await this.#retireSessionProcess(entry.sessionId, active, async () => await active.close());
|
|
37123
|
-
}
|
|
37124
|
-
}
|
|
37125
|
-
options2.signal.throwIfAborted();
|
|
37126
|
-
await runtime.deleteNativeSession(nativeSessionId, options2.signal);
|
|
37127
|
-
const deleted = this.#store.markDeleted(options2.agent.id, nativeSessionId);
|
|
37128
|
-
if (runtime.nativeSessionId() === nativeSessionId) {
|
|
37129
|
-
await this.#queryProcesses.retire(options2.sessionId, runtime);
|
|
37130
|
-
}
|
|
37131
|
-
return deleted;
|
|
37132
|
-
} finally {
|
|
37133
|
-
this.#nativeOperations.delete(key);
|
|
37134
|
-
this.#processes.notifyChanged();
|
|
37135
|
-
}
|
|
37136
|
-
});
|
|
37137
|
-
});
|
|
37138
37137
|
};
|
|
37139
37138
|
|
|
37140
37139
|
// src/agent-catalog/publish-agent-catalog.ts
|
|
@@ -37712,7 +37711,7 @@ var FixedInstallationExecutor = class {
|
|
|
37712
37711
|
// src/authorization/workspace-directory.ts
|
|
37713
37712
|
import { readdir as readdir3, realpath as realpath8, stat as stat7 } from "node:fs/promises";
|
|
37714
37713
|
import { homedir as homedir2 } from "node:os";
|
|
37715
|
-
import { basename as basename3, dirname as
|
|
37714
|
+
import { basename as basename3, dirname as dirname4, isAbsolute as isAbsolute9, join as join16, normalize as normalize3, relative as relative4 } from "node:path";
|
|
37716
37715
|
|
|
37717
37716
|
// src/authorization/local-authorization-error.ts
|
|
37718
37717
|
var LocalAuthorizationError = class extends Error {
|
|
@@ -37851,7 +37850,7 @@ var WorkspaceDirectoryService = class {
|
|
|
37851
37850
|
}
|
|
37852
37851
|
}
|
|
37853
37852
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
37854
|
-
const parent =
|
|
37853
|
+
const parent = dirname4(target);
|
|
37855
37854
|
return new WorkspaceDirectoryListing(
|
|
37856
37855
|
id,
|
|
37857
37856
|
this.label(target),
|
|
@@ -37876,7 +37875,7 @@ var WorkspaceDirectoryService = class {
|
|
|
37876
37875
|
};
|
|
37877
37876
|
|
|
37878
37877
|
// src/daemon-diagnostic-log.ts
|
|
37879
|
-
import { appendFileSync, mkdirSync
|
|
37878
|
+
import { appendFileSync, mkdirSync, readFileSync as readFileSync2, renameSync, statSync as statSync3, writeFileSync } from "node:fs";
|
|
37880
37879
|
import { join as join17 } from "node:path";
|
|
37881
37880
|
var MAXIMUM_DAEMON_LOG_BYTES = 1 * 1024 * 1024;
|
|
37882
37881
|
var DaemonDiagnosticLog = class {
|
|
@@ -37892,7 +37891,7 @@ var DaemonDiagnosticLog = class {
|
|
|
37892
37891
|
const encoded = `${diagnostic.replace(/[\r\n]+/gu, " ").trim()}
|
|
37893
37892
|
`;
|
|
37894
37893
|
const encodedBytes = Buffer.byteLength(encoded);
|
|
37895
|
-
|
|
37894
|
+
mkdirSync(this.#directory, { mode: 448, recursive: true });
|
|
37896
37895
|
let existingBytes = 0;
|
|
37897
37896
|
try {
|
|
37898
37897
|
existingBytes = statSync3(this.#path).size;
|
|
@@ -38357,7 +38356,7 @@ var DaemonInstallationObserver = class {
|
|
|
38357
38356
|
};
|
|
38358
38357
|
|
|
38359
38358
|
// src/daemon-active-turn.ts
|
|
38360
|
-
import { randomUUID as
|
|
38359
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
38361
38360
|
function activeMessageCharacters(message) {
|
|
38362
38361
|
return message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0);
|
|
38363
38362
|
}
|
|
@@ -38365,8 +38364,8 @@ var ACTIVE_TURN_TEXT_CHUNK_LIMIT = Math.floor(SESSION_HISTORY_CHARACTER_LIMIT /
|
|
|
38365
38364
|
function boundedRecoveryMessages(messages) {
|
|
38366
38365
|
const selected = [];
|
|
38367
38366
|
let remainingCharacters = SESSION_HISTORY_CHARACTER_LIMIT;
|
|
38368
|
-
for (let
|
|
38369
|
-
const message = messages[
|
|
38367
|
+
for (let index2 = messages.length - 1; index2 >= 0 && selected.length < SESSION_HISTORY_MESSAGE_LIMIT; index2 -= 1) {
|
|
38368
|
+
const message = messages[index2];
|
|
38370
38369
|
if (message === void 0) {
|
|
38371
38370
|
break;
|
|
38372
38371
|
}
|
|
@@ -38391,7 +38390,7 @@ var ActiveDaemonTurn = class {
|
|
|
38391
38390
|
#timeline;
|
|
38392
38391
|
#sequence = 0;
|
|
38393
38392
|
#interaction = null;
|
|
38394
|
-
#epoch = decodeIdentifier(
|
|
38393
|
+
#epoch = decodeIdentifier(randomUUID3());
|
|
38395
38394
|
constructor(command, attemptId) {
|
|
38396
38395
|
this.attemptId = attemptId;
|
|
38397
38396
|
this.command = command;
|
|
@@ -38453,7 +38452,7 @@ var ActiveDaemonTurn = class {
|
|
|
38453
38452
|
if (!this.#activities.has(event.activityId)) {
|
|
38454
38453
|
this.#timeline = [
|
|
38455
38454
|
...this.#timeline,
|
|
38456
|
-
{ activityId: event.activityId, id: decodeIdentifier(
|
|
38455
|
+
{ activityId: event.activityId, id: decodeIdentifier(randomUUID3()), kind: "activity" }
|
|
38457
38456
|
];
|
|
38458
38457
|
}
|
|
38459
38458
|
this.#activities.set(event.activityId, {
|
|
@@ -38474,7 +38473,7 @@ var ActiveDaemonTurn = class {
|
|
|
38474
38473
|
if (previous === void 0) {
|
|
38475
38474
|
this.#timeline = [
|
|
38476
38475
|
...this.#timeline,
|
|
38477
|
-
{ activityId: event.activityId, id: decodeIdentifier(
|
|
38476
|
+
{ activityId: event.activityId, id: decodeIdentifier(randomUUID3()), kind: "activity" }
|
|
38478
38477
|
];
|
|
38479
38478
|
}
|
|
38480
38479
|
this.#activities.set(event.activityId, {
|
|
@@ -38499,7 +38498,7 @@ var ActiveDaemonTurn = class {
|
|
|
38499
38498
|
...this.#timeline,
|
|
38500
38499
|
{
|
|
38501
38500
|
content: /* @__PURE__ */ new Map([[event.contentId, event.content]]),
|
|
38502
|
-
id: decodeIdentifier(
|
|
38501
|
+
id: decodeIdentifier(randomUUID3()),
|
|
38503
38502
|
kind: "message",
|
|
38504
38503
|
sourceMessageId: event.messageId,
|
|
38505
38504
|
text: ""
|
|
@@ -38507,7 +38506,7 @@ var ActiveDaemonTurn = class {
|
|
|
38507
38506
|
];
|
|
38508
38507
|
} else {
|
|
38509
38508
|
this.#timeline = this.#timeline.map(
|
|
38510
|
-
(entry,
|
|
38509
|
+
(entry, index2) => index2 === target && entry.kind === "message" ? { ...entry, content: new Map([...entry.content, [event.contentId, event.content]]) } : entry
|
|
38511
38510
|
);
|
|
38512
38511
|
}
|
|
38513
38512
|
} else if (event.kind === SESSION_PERMISSION_REQUESTED_KIND || event.kind === SESSION_ELICITATION_REQUESTED_KIND) {
|
|
@@ -38539,7 +38538,7 @@ var ActiveDaemonTurn = class {
|
|
|
38539
38538
|
...this.#timeline,
|
|
38540
38539
|
{
|
|
38541
38540
|
content: /* @__PURE__ */ new Map(),
|
|
38542
|
-
id: decodeIdentifier(
|
|
38541
|
+
id: decodeIdentifier(randomUUID3()),
|
|
38543
38542
|
kind: "message",
|
|
38544
38543
|
sourceMessageId: messageId,
|
|
38545
38544
|
text: remaining.slice(0, ACTIVE_TURN_TEXT_CHUNK_LIMIT)
|
|
@@ -38810,6 +38809,202 @@ var DaemonTurnRegistry = class {
|
|
|
38810
38809
|
};
|
|
38811
38810
|
};
|
|
38812
38811
|
|
|
38812
|
+
// src/generated/acp-session-store-migrations.ts
|
|
38813
|
+
var acpSessionStoreMigrations = [
|
|
38814
|
+
{
|
|
38815
|
+
"name": "0000_slimy_captain_midlands.sql",
|
|
38816
|
+
"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"
|
|
38817
|
+
},
|
|
38818
|
+
{
|
|
38819
|
+
"name": "0001_regular_ultimates.sql",
|
|
38820
|
+
"sql": "ALTER TABLE `acp_session` ADD `last_terminal_command_id` text;"
|
|
38821
|
+
},
|
|
38822
|
+
{
|
|
38823
|
+
"name": "0002_equal_black_queen.sql",
|
|
38824
|
+
"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`);"
|
|
38825
|
+
},
|
|
38826
|
+
{
|
|
38827
|
+
"name": "0003_silky_ravenous.sql",
|
|
38828
|
+
"sql": "DROP TABLE `session_event_v2`;"
|
|
38829
|
+
},
|
|
38830
|
+
{
|
|
38831
|
+
"name": "0004_special_mathemanic.sql",
|
|
38832
|
+
"sql": "DROP TABLE `deleted_acp_session`;--> statement-breakpoint\nALTER TABLE `acp_session` DROP COLUMN `last_terminal_command_id`;"
|
|
38833
|
+
}
|
|
38834
|
+
];
|
|
38835
|
+
|
|
38836
|
+
// src/generated/session-event-cache-migrations.ts
|
|
38837
|
+
var sessionEventCacheMigrations = [
|
|
38838
|
+
{
|
|
38839
|
+
"name": "migration.sql",
|
|
38840
|
+
"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`);"
|
|
38841
|
+
}
|
|
38842
|
+
];
|
|
38843
|
+
|
|
38844
|
+
// src/infra/local-sqlite-database.ts
|
|
38845
|
+
import { chmodSync, mkdirSync as mkdirSync2 } from "node:fs";
|
|
38846
|
+
import { dirname as dirname5 } from "node:path";
|
|
38847
|
+
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
38848
|
+
|
|
38849
|
+
// ../../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
|
|
38850
|
+
var NodeSQLiteSession = class extends SQLiteAsyncSession {
|
|
38851
|
+
static [entityKind] = "SQLJsSession";
|
|
38852
|
+
logger;
|
|
38853
|
+
constructor(client2, dialect, relations, options = {}) {
|
|
38854
|
+
super(dialect, "sync");
|
|
38855
|
+
this.client = client2;
|
|
38856
|
+
this.relations = relations;
|
|
38857
|
+
this.options = options;
|
|
38858
|
+
this.logger = options.logger ?? new NoopLogger();
|
|
38859
|
+
}
|
|
38860
|
+
prepareQuery(query, mode, _prepare, executeMethod, mapper, queryMetadata) {
|
|
38861
|
+
let stmt;
|
|
38862
|
+
try {
|
|
38863
|
+
stmt = this.client.prepare(query.sql);
|
|
38864
|
+
} catch (e) {
|
|
38865
|
+
throw new DrizzleQueryError(query.sql, query.params, e);
|
|
38866
|
+
}
|
|
38867
|
+
return new SQLiteAsyncPreparedQuery("sync", executeMethod, {
|
|
38868
|
+
all: (params) => {
|
|
38869
|
+
stmt.setReturnArrays(mode === "arrays");
|
|
38870
|
+
const res = stmt.all(...params);
|
|
38871
|
+
if (mode === "objects") return res.map((row) => ({ ...row }));
|
|
38872
|
+
return res;
|
|
38873
|
+
},
|
|
38874
|
+
get: (params) => {
|
|
38875
|
+
stmt.setReturnArrays(mode === "arrays");
|
|
38876
|
+
const res = stmt.get(...params);
|
|
38877
|
+
if (res && mode === "objects") return { ...res };
|
|
38878
|
+
return res;
|
|
38879
|
+
},
|
|
38880
|
+
run: (params) => {
|
|
38881
|
+
stmt.setReturnArrays(false);
|
|
38882
|
+
return stmt.run(...params);
|
|
38883
|
+
},
|
|
38884
|
+
values: (params) => {
|
|
38885
|
+
stmt.setReturnArrays(true);
|
|
38886
|
+
return stmt.all(...params);
|
|
38887
|
+
}
|
|
38888
|
+
}, query, mapper, mode, this.logger, void 0, queryMetadata, void 0);
|
|
38889
|
+
}
|
|
38890
|
+
transaction(transaction, config2 = {}) {
|
|
38891
|
+
const tx = new NodeSQLiteTransaction("sync", this.dialect, this, this.relations);
|
|
38892
|
+
this.run(sql.raw(`begin${config2.behavior ? ` ${config2.behavior}` : ""}`));
|
|
38893
|
+
try {
|
|
38894
|
+
const result = transaction(tx);
|
|
38895
|
+
this.run(sql`commit`);
|
|
38896
|
+
return result;
|
|
38897
|
+
} catch (err) {
|
|
38898
|
+
this.run(sql`rollback`);
|
|
38899
|
+
throw err;
|
|
38900
|
+
}
|
|
38901
|
+
}
|
|
38902
|
+
};
|
|
38903
|
+
var NodeSQLiteTransaction = class NodeSQLiteTransaction2 extends SQLiteAsyncTransaction {
|
|
38904
|
+
static [entityKind] = "SQLJsTransaction";
|
|
38905
|
+
transaction(transaction) {
|
|
38906
|
+
const savepointName = `sp${this.nestedIndex + 1}`;
|
|
38907
|
+
const tx = new NodeSQLiteTransaction2("sync", this.dialect, this.session, this._.relations, this.nestedIndex + 1);
|
|
38908
|
+
tx.run(sql.raw(`savepoint ${savepointName}`));
|
|
38909
|
+
try {
|
|
38910
|
+
const result = transaction(tx);
|
|
38911
|
+
tx.run(sql.raw(`release savepoint ${savepointName}`));
|
|
38912
|
+
return result;
|
|
38913
|
+
} catch (err) {
|
|
38914
|
+
tx.run(sql.raw(`rollback to savepoint ${savepointName}`));
|
|
38915
|
+
throw err;
|
|
38916
|
+
}
|
|
38917
|
+
}
|
|
38918
|
+
};
|
|
38919
|
+
|
|
38920
|
+
// ../../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
|
|
38921
|
+
import { DatabaseSync } from "node:sqlite";
|
|
38922
|
+
var NodeSQLiteDatabase = class extends SQLiteAsyncDatabase {
|
|
38923
|
+
static [entityKind] = "NodeSQLiteDatabase";
|
|
38924
|
+
};
|
|
38925
|
+
function construct(client2, config2 = {}) {
|
|
38926
|
+
const dialect = new SQLiteDialect({ useJitMappers: jitCompatCheck(config2.jit) });
|
|
38927
|
+
let logger;
|
|
38928
|
+
if (config2.logger === true) logger = new DefaultLogger();
|
|
38929
|
+
else if (config2.logger !== false) logger = config2.logger;
|
|
38930
|
+
const relations = config2.relations ?? {};
|
|
38931
|
+
const db = new NodeSQLiteDatabase("sync", dialect, new NodeSQLiteSession(client2, dialect, relations, { logger }), relations);
|
|
38932
|
+
db.$client = client2;
|
|
38933
|
+
return db;
|
|
38934
|
+
}
|
|
38935
|
+
function drizzle(...params) {
|
|
38936
|
+
if (params[0] === void 0 || typeof params[0] === "string") return construct(params[0] === void 0 ? new DatabaseSync(":memory:") : new DatabaseSync(params[0]), params[1]);
|
|
38937
|
+
const { connection, client: client2, ...config2 } = params[0];
|
|
38938
|
+
if (client2) return construct(client2, config2);
|
|
38939
|
+
if (typeof connection === "object") {
|
|
38940
|
+
const { path: path2, ...options } = connection;
|
|
38941
|
+
return construct(new DatabaseSync(path2 ?? ":memory:", options), config2);
|
|
38942
|
+
}
|
|
38943
|
+
return construct(new DatabaseSync(connection ?? ":memory:"), config2);
|
|
38944
|
+
}
|
|
38945
|
+
(function(_drizzle) {
|
|
38946
|
+
function mock(config2) {
|
|
38947
|
+
return construct({}, config2);
|
|
38948
|
+
}
|
|
38949
|
+
_drizzle.mock = mock;
|
|
38950
|
+
})(drizzle || (drizzle = {}));
|
|
38951
|
+
|
|
38952
|
+
// src/infra/local-sqlite-database.ts
|
|
38953
|
+
var LocalSqliteDatabase = class {
|
|
38954
|
+
orm;
|
|
38955
|
+
#sqlite;
|
|
38956
|
+
constructor(path2, label, migrations, pragmas = []) {
|
|
38957
|
+
mkdirSync2(dirname5(path2), { mode: 448, recursive: true });
|
|
38958
|
+
this.#sqlite = new DatabaseSync2(path2);
|
|
38959
|
+
chmodSync(path2, 384);
|
|
38960
|
+
try {
|
|
38961
|
+
for (const pragma of pragmas) {
|
|
38962
|
+
this.#sqlite.exec(pragma);
|
|
38963
|
+
}
|
|
38964
|
+
this.#migrate(label, migrations);
|
|
38965
|
+
this.orm = drizzle({ client: this.#sqlite });
|
|
38966
|
+
} catch (error62) {
|
|
38967
|
+
this.#sqlite.close();
|
|
38968
|
+
throw error62;
|
|
38969
|
+
}
|
|
38970
|
+
}
|
|
38971
|
+
#migrate = (label, migrations) => {
|
|
38972
|
+
const version2 = external_exports.object({ user_version: external_exports.number().int().nonnegative() }).parse(this.#sqlite.prepare("PRAGMA user_version").get()).user_version;
|
|
38973
|
+
if (version2 > migrations.length) {
|
|
38974
|
+
throw new Error(`The ${label} was created by a newer Mobius version`);
|
|
38975
|
+
}
|
|
38976
|
+
for (let index2 = version2; index2 < migrations.length; index2 += 1) {
|
|
38977
|
+
const migration = migrations[index2];
|
|
38978
|
+
if (migration === void 0) {
|
|
38979
|
+
throw new Error(`The ${label} migration is unavailable`);
|
|
38980
|
+
}
|
|
38981
|
+
this.transaction(() => {
|
|
38982
|
+
this.#sqlite.exec(migration.sql);
|
|
38983
|
+
this.#sqlite.exec(`PRAGMA user_version = ${index2 + 1}`);
|
|
38984
|
+
});
|
|
38985
|
+
}
|
|
38986
|
+
};
|
|
38987
|
+
transaction = (operation) => {
|
|
38988
|
+
this.#sqlite.exec("BEGIN IMMEDIATE");
|
|
38989
|
+
try {
|
|
38990
|
+
const result = operation();
|
|
38991
|
+
this.#sqlite.exec("COMMIT");
|
|
38992
|
+
return result;
|
|
38993
|
+
} catch (error62) {
|
|
38994
|
+
this.#sqlite.exec("ROLLBACK");
|
|
38995
|
+
throw error62;
|
|
38996
|
+
}
|
|
38997
|
+
};
|
|
38998
|
+
close = () => this.#sqlite.close();
|
|
38999
|
+
};
|
|
39000
|
+
|
|
39001
|
+
// src/local-databases.ts
|
|
39002
|
+
var openAcpSessionDatabase = (path2) => new LocalSqliteDatabase(path2, "ACP Session database", acpSessionStoreMigrations);
|
|
39003
|
+
var openSessionEventCacheV2Database = (path2) => new LocalSqliteDatabase(path2, "V2 Session event cache", sessionEventCacheMigrations, [
|
|
39004
|
+
"PRAGMA journal_mode = WAL",
|
|
39005
|
+
"PRAGMA synchronous = OFF"
|
|
39006
|
+
]);
|
|
39007
|
+
|
|
38813
39008
|
// src/native-sessions/codex-history.ts
|
|
38814
39009
|
import { spawn as spawn5 } from "node:child_process";
|
|
38815
39010
|
var responseSchema = external_exports.union([
|
|
@@ -39514,8 +39709,7 @@ var readCodexFullHistory = async (agent, cwd, nativeSessionId, signal, nativeTur
|
|
|
39514
39709
|
});
|
|
39515
39710
|
|
|
39516
39711
|
// src/native-sessions/service.ts
|
|
39517
|
-
import { randomUUID as
|
|
39518
|
-
import { basename as basename4 } from "node:path";
|
|
39712
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
39519
39713
|
var NativeSessionService = class {
|
|
39520
39714
|
#entries = /* @__PURE__ */ new Map();
|
|
39521
39715
|
#cursors = /* @__PURE__ */ new Map();
|
|
@@ -39559,64 +39753,6 @@ var NativeSessionService = class {
|
|
|
39559
39753
|
...await this.#activeTurn(command, options)
|
|
39560
39754
|
};
|
|
39561
39755
|
}
|
|
39562
|
-
if (command.action === "fork-recorded") {
|
|
39563
|
-
const source = this.#sessions.findSessions([command.sessionId])[0];
|
|
39564
|
-
if (source === void 0 || !source.prompted) {
|
|
39565
|
-
throw new AcpExecutionError(
|
|
39566
|
-
"The source conversation has no resumable native Agent session",
|
|
39567
|
-
{},
|
|
39568
|
-
"native_session_not_found"
|
|
39569
|
-
);
|
|
39570
|
-
}
|
|
39571
|
-
if (source.agentId !== command.agentId || source.cwd !== cwd || source.additionalDirectories.length !== additionalDirectories.length || source.additionalDirectories.some((path2, index) => path2 !== additionalDirectories[index])) {
|
|
39572
|
-
throw new AcpExecutionError(
|
|
39573
|
-
"The source conversation execution target does not match the fork request",
|
|
39574
|
-
{},
|
|
39575
|
-
"native_session_target_changed"
|
|
39576
|
-
);
|
|
39577
|
-
}
|
|
39578
|
-
if (source.lastTerminalCommandId !== command.throughCommandId) {
|
|
39579
|
-
throw new AcpExecutionError(
|
|
39580
|
-
"The selected Turn is no longer the source conversation head",
|
|
39581
|
-
{},
|
|
39582
|
-
"fork_point_stale"
|
|
39583
|
-
);
|
|
39584
|
-
}
|
|
39585
|
-
const opened2 = await this.#sessions.openNativeSession(
|
|
39586
|
-
{ ...options, sessionId: command.targetSessionId },
|
|
39587
|
-
{ kind: "fork", nativeSessionId: source.nativeSessionId }
|
|
39588
|
-
);
|
|
39589
|
-
signal.throwIfAborted();
|
|
39590
|
-
const directory = await this.#directories.list(this.#config.bindingId, command.directoryId, signal);
|
|
39591
|
-
const ready2 = {
|
|
39592
|
-
additionalDirectories: additionalDirectories.map((path2, index) => ({
|
|
39593
|
-
directoryId: command.additionalDirectoryIds[index] ?? command.directoryId,
|
|
39594
|
-
name: basename4(path2) || path2
|
|
39595
|
-
})),
|
|
39596
|
-
agentId: command.agentId,
|
|
39597
|
-
agentName: opened2.prepared.agentName,
|
|
39598
|
-
agentVersion: opened2.prepared.agentVersion,
|
|
39599
|
-
capabilities: opened2.prepared.capabilities,
|
|
39600
|
-
commands: opened2.prepared.commands,
|
|
39601
|
-
configOptions: opened2.prepared.configOptions,
|
|
39602
|
-
directoryId: command.directoryId,
|
|
39603
|
-
directoryLabel: directory.directoryLabel,
|
|
39604
|
-
kind: "session.ready",
|
|
39605
|
-
requestId: command.requestId,
|
|
39606
|
-
restored: true,
|
|
39607
|
-
sessionId: opened2.sessionId
|
|
39608
|
-
};
|
|
39609
|
-
this.record(command, "native_recorded_session_forked");
|
|
39610
|
-
return {
|
|
39611
|
-
action: "fork-recorded",
|
|
39612
|
-
kind: "native.session.result",
|
|
39613
|
-
ready: ready2,
|
|
39614
|
-
requestId: command.requestId,
|
|
39615
|
-
sessionId: command.sessionId,
|
|
39616
|
-
targetSessionId: command.targetSessionId,
|
|
39617
|
-
title: source.title || "Untitled session"
|
|
39618
|
-
};
|
|
39619
|
-
}
|
|
39620
39756
|
const prepared = await this.#sessions.prepareNativeSessionBrowser(options);
|
|
39621
39757
|
if (!prepared.capabilities.listSessions) {
|
|
39622
39758
|
throw new AcpExecutionError(
|
|
@@ -39632,7 +39768,7 @@ var NativeSessionService = class {
|
|
|
39632
39768
|
if (authorized === null) {
|
|
39633
39769
|
return null;
|
|
39634
39770
|
}
|
|
39635
|
-
const entryId = decodeIdentifier(
|
|
39771
|
+
const entryId = decodeIdentifier(randomUUID4());
|
|
39636
39772
|
if (this.#entries.size >= 5e3) {
|
|
39637
39773
|
this.#entries.clear();
|
|
39638
39774
|
}
|
|
@@ -39688,7 +39824,7 @@ var NativeSessionService = class {
|
|
|
39688
39824
|
"invalid_native_session_response"
|
|
39689
39825
|
);
|
|
39690
39826
|
}
|
|
39691
|
-
nextCursor = decodeIdentifier(
|
|
39827
|
+
nextCursor = decodeIdentifier(randomUUID4());
|
|
39692
39828
|
if (this.#cursors.size >= 500) {
|
|
39693
39829
|
this.#cursors.clear();
|
|
39694
39830
|
}
|
|
@@ -39751,25 +39887,6 @@ var NativeSessionService = class {
|
|
|
39751
39887
|
);
|
|
39752
39888
|
}
|
|
39753
39889
|
const target = await this.resolveTarget(command, options, selected);
|
|
39754
|
-
if (command.action === "delete") {
|
|
39755
|
-
if (!prepared.capabilities.deleteSession) {
|
|
39756
|
-
throw new AcpExecutionError(
|
|
39757
|
-
"This Agent does not support native session deletion",
|
|
39758
|
-
{},
|
|
39759
|
-
"native_session_unsupported"
|
|
39760
|
-
);
|
|
39761
|
-
}
|
|
39762
|
-
signal.throwIfAborted();
|
|
39763
|
-
this.record(command, "native_session_delete_authorized");
|
|
39764
|
-
const deletedSessionIds = await this.#sessions.deleteNativeSession(options, target.info.sessionId);
|
|
39765
|
-
this.record(command, "native_session_deleted");
|
|
39766
|
-
return {
|
|
39767
|
-
...envelope2,
|
|
39768
|
-
action: "delete",
|
|
39769
|
-
entryId: command.entryId,
|
|
39770
|
-
deletedSessionIds: deletedSessionIds.map(decodeIdentifier)
|
|
39771
|
-
};
|
|
39772
|
-
}
|
|
39773
39890
|
const action = command.action;
|
|
39774
39891
|
if (action === "import" && !prepared.capabilities.loadSession && !prepared.capabilities.resumeSession) {
|
|
39775
39892
|
throw new AcpExecutionError("This Agent cannot import native sessions", {}, "native_session_unsupported");
|
|
@@ -39885,7 +40002,7 @@ var NativeSessionService = class {
|
|
|
39885
40002
|
resolveTarget = async (command, options, selected) => {
|
|
39886
40003
|
let cursor = null;
|
|
39887
40004
|
const visited = /* @__PURE__ */ new Set();
|
|
39888
|
-
for (let
|
|
40005
|
+
for (let index2 = 0; index2 < 100; index2 += 1) {
|
|
39889
40006
|
const page = await this.#sessions.listNativeSessions(options, cursor);
|
|
39890
40007
|
const info = page.sessions.find((entry) => entry.sessionId === selected.nativeSessionId);
|
|
39891
40008
|
if (info !== void 0) {
|
|
@@ -39893,7 +40010,7 @@ var NativeSessionService = class {
|
|
|
39893
40010
|
if (target === null) {
|
|
39894
40011
|
throw new LocalAuthorizationError("The selected native session is not authorized");
|
|
39895
40012
|
}
|
|
39896
|
-
if (target.cwd !== selected.cwd || target.additionalDirectories.length !== selected.additionalDirectories.length || target.additionalDirectories.some((path2,
|
|
40013
|
+
if (target.cwd !== selected.cwd || target.additionalDirectories.length !== selected.additionalDirectories.length || target.additionalDirectories.some((path2, index3) => path2 !== selected.additionalDirectories[index3])) {
|
|
39897
40014
|
throw new AcpExecutionError(
|
|
39898
40015
|
"This session's directory changed. Refresh the list before continuing.",
|
|
39899
40016
|
{},
|
|
@@ -39932,7 +40049,7 @@ var NativeSessionService = class {
|
|
|
39932
40049
|
};
|
|
39933
40050
|
|
|
39934
40051
|
// src/relay-connection/daemon-operation-state.ts
|
|
39935
|
-
import { createHash as createHash4, randomUUID as
|
|
40052
|
+
import { createHash as createHash4, randomUUID as randomUUID5 } from "node:crypto";
|
|
39936
40053
|
var MAX_TERMINAL_RECEIPTS = 1024;
|
|
39937
40054
|
function isTerminal(state) {
|
|
39938
40055
|
return state === "succeeded" || state === "failed" || state === "cancelled";
|
|
@@ -39949,7 +40066,7 @@ var DaemonOperationState = class {
|
|
|
39949
40066
|
}
|
|
39950
40067
|
return { attemptId: existing.attemptId, commandId, kind: "duplicate", state: existing.state };
|
|
39951
40068
|
}
|
|
39952
|
-
const attemptId =
|
|
40069
|
+
const attemptId = randomUUID5();
|
|
39953
40070
|
this.#executions.set(commandId, { attemptId, commandHash, sessionId, state: "dispatching" });
|
|
39954
40071
|
return { attemptId, commandId, kind: "accepted", state: "dispatching" };
|
|
39955
40072
|
};
|
|
@@ -40779,7 +40896,7 @@ function createAgentSettingsDiscoveryHandler(dependencies) {
|
|
|
40779
40896
|
// src/artifacts/local-file-streamer.ts
|
|
40780
40897
|
import { createReadStream as createReadStream2 } from "node:fs";
|
|
40781
40898
|
import { realpath as realpath9, stat as stat8 } from "node:fs/promises";
|
|
40782
|
-
import { basename as
|
|
40899
|
+
import { basename as basename4, isAbsolute as isAbsolute10, normalize as normalize4, resolve as resolve5 } from "node:path";
|
|
40783
40900
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
40784
40901
|
var CHUNK_BYTES = 192 * 1024;
|
|
40785
40902
|
function requestedPath(value) {
|
|
@@ -40831,7 +40948,7 @@ async function streamLocalFile(command, send2, signal, workingDirectory, externa
|
|
|
40831
40948
|
kind: FILE_BEGIN_KIND,
|
|
40832
40949
|
mediaType: external?.mediaType ?? raster?.mimeType ?? "application/octet-stream",
|
|
40833
40950
|
modifiedAt: before.mtime.toISOString(),
|
|
40834
|
-
name: external?.name ?? (
|
|
40951
|
+
name: external?.name ?? (basename4(target) || "file"),
|
|
40835
40952
|
requestId: command.requestId,
|
|
40836
40953
|
sessionId: command.sessionId
|
|
40837
40954
|
});
|
|
@@ -40861,7 +40978,7 @@ async function streamLocalFile(command, send2, signal, workingDirectory, externa
|
|
|
40861
40978
|
}
|
|
40862
40979
|
|
|
40863
40980
|
// src/authorization/resolve-session-directories.ts
|
|
40864
|
-
import { basename as
|
|
40981
|
+
import { basename as basename5 } from "node:path";
|
|
40865
40982
|
var ResolvedSessionDirectories = class {
|
|
40866
40983
|
additionalDirectories;
|
|
40867
40984
|
additionalDirectoryEntries;
|
|
@@ -40886,7 +41003,7 @@ async function resolveSessionDirectories(directories, bindingId, directoryId2, a
|
|
|
40886
41003
|
additionalDirectories.push(directory);
|
|
40887
41004
|
additionalDirectoryEntries.push({
|
|
40888
41005
|
directoryId: additionalDirectoryId,
|
|
40889
|
-
name:
|
|
41006
|
+
name: basename5(directory)
|
|
40890
41007
|
});
|
|
40891
41008
|
}
|
|
40892
41009
|
return new ResolvedSessionDirectories(cwd, additionalDirectories, additionalDirectoryEntries);
|
|
@@ -40913,7 +41030,7 @@ async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, dir
|
|
|
40913
41030
|
const replay = await sessions.loadSessionEventsV2(loadOptions, command.eventLimit, command.cursor);
|
|
40914
41031
|
signal.throwIfAborted();
|
|
40915
41032
|
const events = replay.events.map(
|
|
40916
|
-
(event,
|
|
41033
|
+
(event, index2) => eventLogV2.event(command.sessionId, replay.startPosition + index2, event, "1970-01-01T00:00:00.000Z")
|
|
40917
41034
|
);
|
|
40918
41035
|
const tailCursor = events.at(-1)?.eventId ?? "";
|
|
40919
41036
|
audit.record({
|
|
@@ -40964,7 +41081,7 @@ async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, dir
|
|
|
40964
41081
|
}
|
|
40965
41082
|
|
|
40966
41083
|
// src/acp/session-config/apply-session-configuration.ts
|
|
40967
|
-
import { randomUUID as
|
|
41084
|
+
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
40968
41085
|
function invalidSessionConfiguration(message) {
|
|
40969
41086
|
return new AcpExecutionError(message, {}, "invalid_session_configuration");
|
|
40970
41087
|
}
|
|
@@ -41105,7 +41222,7 @@ async function applySessionConfigurationSelection(sessions, audit, options, sele
|
|
|
41105
41222
|
booleanValue: selection.booleanValue,
|
|
41106
41223
|
configId: selection.configId,
|
|
41107
41224
|
cwd,
|
|
41108
|
-
requestId: `cfg_${
|
|
41225
|
+
requestId: `cfg_${randomUUID6()}`,
|
|
41109
41226
|
sessionId,
|
|
41110
41227
|
signal,
|
|
41111
41228
|
value: selection.value,
|
|
@@ -41665,7 +41782,7 @@ async function executeSessionConfigure(publisher, socket, command, config2, dire
|
|
|
41665
41782
|
// src/native-sessions/handle-native-requests.ts
|
|
41666
41783
|
import { WebSocket as WebSocket4 } from "undici";
|
|
41667
41784
|
function createNativeSessionRequestHandler(dependencies) {
|
|
41668
|
-
const { audit, diagnostics, nativeSessions,
|
|
41785
|
+
const { audit, diagnostics, nativeSessions, signal, socket, timer } = dependencies;
|
|
41669
41786
|
const pending = /* @__PURE__ */ new Map();
|
|
41670
41787
|
const cancel = (command) => {
|
|
41671
41788
|
const request = pending.get(command.requestId);
|
|
@@ -41717,17 +41834,6 @@ function createNativeSessionRequestHandler(dependencies) {
|
|
|
41717
41834
|
}
|
|
41718
41835
|
operationSignal.throwIfAborted();
|
|
41719
41836
|
const result = await nativeSessions.execute(command, operationSignal);
|
|
41720
|
-
if (command.action === "fork-recorded" && result.action === "fork-recorded") {
|
|
41721
|
-
publisher.publishBatch(result.ready.sessionId, [
|
|
41722
|
-
result.ready,
|
|
41723
|
-
{
|
|
41724
|
-
kind: "session.forked",
|
|
41725
|
-
sessionId: result.ready.sessionId,
|
|
41726
|
-
sourceSessionId: command.sessionId,
|
|
41727
|
-
throughCommandId: command.throughCommandId
|
|
41728
|
-
}
|
|
41729
|
-
]);
|
|
41730
|
-
}
|
|
41731
41837
|
if (socket.readyState === WebSocket4.OPEN) {
|
|
41732
41838
|
send(socket, result);
|
|
41733
41839
|
}
|
|
@@ -41807,7 +41913,6 @@ function createDaemonCommandHandler({
|
|
|
41807
41913
|
audit,
|
|
41808
41914
|
diagnostics,
|
|
41809
41915
|
nativeSessions,
|
|
41810
|
-
publisher,
|
|
41811
41916
|
signal,
|
|
41812
41917
|
socket,
|
|
41813
41918
|
timer
|
|
@@ -42187,7 +42292,7 @@ function connectRelay(url2, signal) {
|
|
|
42187
42292
|
}
|
|
42188
42293
|
|
|
42189
42294
|
// src/relay-connection/liveness.ts
|
|
42190
|
-
import { randomUUID as
|
|
42295
|
+
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
42191
42296
|
var HEARTBEAT_ACK_TIMEOUT_MILLISECONDS = 1e4;
|
|
42192
42297
|
var HEARTBEAT_INTERVAL_MILLISECONDS = 2e4;
|
|
42193
42298
|
var RelayLivenessState = class {
|
|
@@ -42276,7 +42381,7 @@ var RelayConnectionLiveness = class {
|
|
|
42276
42381
|
}
|
|
42277
42382
|
throw new Error("Heartbeat was scheduled in an invalid state");
|
|
42278
42383
|
}
|
|
42279
|
-
const heartbeatId =
|
|
42384
|
+
const heartbeatId = randomUUID7();
|
|
42280
42385
|
this.#state = new AwaitingHeartbeatAckState(
|
|
42281
42386
|
heartbeatId,
|
|
42282
42387
|
this.#timer.schedule(this.#handleTimeout, HEARTBEAT_ACK_TIMEOUT_MILLISECONDS)
|
|
@@ -42568,7 +42673,7 @@ var SystemDaemonTimer = class {
|
|
|
42568
42673
|
var systemDaemonTimer = new SystemDaemonTimer();
|
|
42569
42674
|
|
|
42570
42675
|
// src/session-event-log-v2.ts
|
|
42571
|
-
import { createHash as createHash6, randomUUID as
|
|
42676
|
+
import { createHash as createHash6, randomUUID as randomUUID8 } from "node:crypto";
|
|
42572
42677
|
function promptContent(command) {
|
|
42573
42678
|
const content = [];
|
|
42574
42679
|
if (command.prompt.length > 0) {
|
|
@@ -42592,7 +42697,7 @@ function promptContent(command) {
|
|
|
42592
42697
|
}
|
|
42593
42698
|
return content;
|
|
42594
42699
|
}
|
|
42595
|
-
function
|
|
42700
|
+
function sessionEventV22(daemonGenerationId, sessionId, position, event, recordedAt) {
|
|
42596
42701
|
const sessionPrefix = createHash6("sha256").update(sessionId).digest("hex").slice(0, 16);
|
|
42597
42702
|
return {
|
|
42598
42703
|
eventId: `event-${daemonGenerationId}-${sessionPrefix}-${position.toString().padStart(16, "0")}`,
|
|
@@ -42604,11 +42709,12 @@ function sessionEventV2(daemonGenerationId, sessionId, position, event, recorded
|
|
|
42604
42709
|
};
|
|
42605
42710
|
}
|
|
42606
42711
|
var DaemonSessionEventLogV2 = class {
|
|
42607
|
-
daemonGenerationId
|
|
42712
|
+
daemonGenerationId;
|
|
42608
42713
|
#publisher;
|
|
42609
42714
|
#queued = /* @__PURE__ */ new Map();
|
|
42610
|
-
constructor(publisher) {
|
|
42715
|
+
constructor(publisher, daemonGenerationId = randomUUID8()) {
|
|
42611
42716
|
this.#publisher = publisher;
|
|
42717
|
+
this.daemonGenerationId = daemonGenerationId;
|
|
42612
42718
|
}
|
|
42613
42719
|
requested = (command) => {
|
|
42614
42720
|
this.#queued.set(command.commandId, {
|
|
@@ -42628,7 +42734,7 @@ var DaemonSessionEventLogV2 = class {
|
|
|
42628
42734
|
record = (sessionId, event, position) => {
|
|
42629
42735
|
this.#publisher.publishV2(this.event(sessionId, position, event, (/* @__PURE__ */ new Date()).toISOString()));
|
|
42630
42736
|
};
|
|
42631
|
-
event = (sessionId, position, event, recordedAt) =>
|
|
42737
|
+
event = (sessionId, position, event, recordedAt) => sessionEventV22(this.daemonGenerationId, sessionId, position, event, recordedAt);
|
|
42632
42738
|
queueChanged = (_sessionId) => void 0;
|
|
42633
42739
|
completed = (sessionId, commandId, _stopReason) => {
|
|
42634
42740
|
const request = this.#queued.get(commandId);
|
|
@@ -42695,7 +42801,7 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
|
|
|
42695
42801
|
{
|
|
42696
42802
|
agentId: agent.id,
|
|
42697
42803
|
kind: AGENT_INSTALL_REQUEST_KIND,
|
|
42698
|
-
requestId: `automatic-integration-${
|
|
42804
|
+
requestId: `automatic-integration-${randomUUID9()}`
|
|
42699
42805
|
},
|
|
42700
42806
|
signal
|
|
42701
42807
|
);
|
|
@@ -42713,13 +42819,24 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
42713
42819
|
publishCatalog: async (installationSignal) => await publishAgentCatalog(config2, installationSignal),
|
|
42714
42820
|
stateDirectory
|
|
42715
42821
|
});
|
|
42716
|
-
const
|
|
42717
|
-
|
|
42718
|
-
);
|
|
42822
|
+
const channelHash = createHash7("sha256").update(config2.channelId).digest("hex");
|
|
42823
|
+
const daemonGenerationId = randomUUID9();
|
|
42824
|
+
const sessionDatabase = openAcpSessionDatabase(join18(stateDirectory, "sessions", `${channelHash}.sqlite`));
|
|
42825
|
+
let eventsV2;
|
|
42826
|
+
try {
|
|
42827
|
+
eventsV2 = new CachedAcpSessionEventStoreV2(
|
|
42828
|
+
openSessionEventCacheV2Database(join18(stateDirectory, "sessions", `${channelHash}.events.sqlite`)),
|
|
42829
|
+
daemonGenerationId
|
|
42830
|
+
);
|
|
42831
|
+
} catch (error62) {
|
|
42832
|
+
sessionDatabase.close();
|
|
42833
|
+
throw error62;
|
|
42834
|
+
}
|
|
42835
|
+
const sessionStore = new SqliteAcpSessionStore(sessionDatabase, eventsV2);
|
|
42719
42836
|
await using externalContent = new LocalExternalContentStore(stateDirectory);
|
|
42720
42837
|
const operations = new DaemonOperationState();
|
|
42721
42838
|
const publisher = new DaemonSessionEventPublisher();
|
|
42722
|
-
const eventLogV2 = new DaemonSessionEventLogV2(publisher);
|
|
42839
|
+
const eventLogV2 = new DaemonSessionEventLogV2(publisher, daemonGenerationId);
|
|
42723
42840
|
const activeTurns = new DaemonTurnRegistry(operations);
|
|
42724
42841
|
const recordSessionEvent = (sessionId, event) => {
|
|
42725
42842
|
publisher.publish(sessionId, activeTurns.recordEvent(event));
|
|
@@ -42765,7 +42882,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
42765
42882
|
options2.signal
|
|
42766
42883
|
);
|
|
42767
42884
|
return cwd === options2.cwd && additionalDirectories.length === options2.additionalDirectories.length && additionalDirectories.every(
|
|
42768
|
-
(directory,
|
|
42885
|
+
(directory, index2) => directory === options2.additionalDirectories[index2]
|
|
42769
42886
|
);
|
|
42770
42887
|
});
|
|
42771
42888
|
}
|
|
@@ -42906,11 +43023,11 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
42906
43023
|
// src/pairing/pair-local-machine.ts
|
|
42907
43024
|
import { mkdir as mkdir6, realpath as realpath10, stat as stat9 } from "node:fs/promises";
|
|
42908
43025
|
import { hostname as hostname3 } from "node:os";
|
|
42909
|
-
import { basename as
|
|
43026
|
+
import { basename as basename6, resolve as resolve7 } from "node:path";
|
|
42910
43027
|
import { fetch as fetch4 } from "undici";
|
|
42911
43028
|
|
|
42912
43029
|
// src/storage/runtime-installation-store.ts
|
|
42913
|
-
import { createHash as createHash8, randomUUID as
|
|
43030
|
+
import { createHash as createHash8, randomUUID as randomUUID10 } from "node:crypto";
|
|
42914
43031
|
import { mkdir as mkdir5, open as open5, readdir as readdir4, rename as rename4, unlink, writeFile as writeFile4 } from "node:fs/promises";
|
|
42915
43032
|
import { dirname as dirname6, join as join19, resolve as resolve6 } from "node:path";
|
|
42916
43033
|
var APPLICATION_ID_PATTERN = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+){1,31}$/;
|
|
@@ -43040,10 +43157,10 @@ function parseRelayOrigin(value) {
|
|
|
43040
43157
|
return origin;
|
|
43041
43158
|
}
|
|
43042
43159
|
function connectionId() {
|
|
43043
|
-
return `mcn_${
|
|
43160
|
+
return `mcn_${randomUUID10().replaceAll("-", "")}`;
|
|
43044
43161
|
}
|
|
43045
43162
|
function installationId() {
|
|
43046
|
-
return `min_${
|
|
43163
|
+
return `min_${randomUUID10().replaceAll("-", "")}`;
|
|
43047
43164
|
}
|
|
43048
43165
|
function channelIndexFileName(channelId) {
|
|
43049
43166
|
return `mci_${createHash8("sha256").update(channelId).digest("hex")}.json`;
|
|
@@ -43155,7 +43272,7 @@ async function readJsonFile(path2, signal, missingCode) {
|
|
|
43155
43272
|
async function writeJsonAtomically(path2, value, signal) {
|
|
43156
43273
|
signal.throwIfAborted();
|
|
43157
43274
|
const directory = dirname6(path2);
|
|
43158
|
-
const temporaryPath = join19(directory, `.${
|
|
43275
|
+
const temporaryPath = join19(directory, `.${randomUUID10()}.tmp`);
|
|
43159
43276
|
try {
|
|
43160
43277
|
await mkdir5(directory, { mode: 448, recursive: true });
|
|
43161
43278
|
signal.throwIfAborted();
|
|
@@ -43232,16 +43349,16 @@ var RuntimeInstallationStore = class _RuntimeInstallationStore {
|
|
|
43232
43349
|
};
|
|
43233
43350
|
#readConnectionForChannel = async (channelId, signal) => {
|
|
43234
43351
|
const normalizedChannelId = validateIdentifier(channelId, "invalid_channel_id");
|
|
43235
|
-
const
|
|
43352
|
+
const index2 = decodeChannelIndex(
|
|
43236
43353
|
await readJsonFile(this.channelIndexPath(normalizedChannelId), signal, "connection_not_found")
|
|
43237
43354
|
);
|
|
43238
|
-
if (
|
|
43355
|
+
if (index2.applicationId !== this.applicationId || index2.installationId !== this.installationId || index2.channelId !== normalizedChannelId) {
|
|
43239
43356
|
throw new RuntimeInstallationStoreError(
|
|
43240
43357
|
"connection_owner_mismatch",
|
|
43241
43358
|
"The saved Runtime connection belongs to another installation"
|
|
43242
43359
|
);
|
|
43243
43360
|
}
|
|
43244
|
-
return await this.readConnection(
|
|
43361
|
+
return await this.readConnection(index2.connectionId, signal);
|
|
43245
43362
|
};
|
|
43246
43363
|
saveConnection = async (input2, signal) => {
|
|
43247
43364
|
const stored = new VerifiedRuntimeConnection(
|
|
@@ -43548,7 +43665,7 @@ async function claimPairing(options, defaultWorkspace, localAgents, installableA
|
|
|
43548
43665
|
installableAgents,
|
|
43549
43666
|
machineName: hostname3(),
|
|
43550
43667
|
pairingCode: options.code,
|
|
43551
|
-
workspaceName:
|
|
43668
|
+
workspaceName: basename6(defaultWorkspace) || "Local workspace"
|
|
43552
43669
|
}),
|
|
43553
43670
|
dispatcher: environmentProxyDispatcher,
|
|
43554
43671
|
headers: { "content-type": "application/json" },
|