@moxt-ai/mobius 0.0.175 → 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-session.d.ts.map +1 -1
- package/dist/acp/agent-session.js +14 -8
- 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 +7 -1
- package/dist/acp/session-store.d.ts.map +1 -1
- package/dist/acp/session-store.js +20 -37
- package/dist/acp/session-store.js.map +1 -1
- package/dist/cli.js +973 -609
- package/dist/cli.js.map +4 -4
- 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 +967 -604
- 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/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 +955 -592
- package/dist/runtime.js.map +4 -4
- package/dist/schema/session-event-cache/index.d.ts +2 -0
- package/dist/schema/session-event-cache/index.d.ts.map +1 -0
- package/dist/schema/session-event-cache/index.js +2 -0
- package/dist/schema/session-event-cache/index.js.map +1 -0
- package/dist/schema/session-event-cache/session-event-v2.d.ts +72 -0
- package/dist/schema/session-event-cache/session-event-v2.d.ts.map +1 -0
- package/dist/schema/session-event-cache/session-event-v2.js +11 -0
- package/dist/schema/session-event-cache/session-event-v2.js.map +1 -0
- package/dist/session-event-log-v2.d.ts +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/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);
|
|
@@ -21503,12 +21503,12 @@ var sessionExportV2Schema = external_exports.object({
|
|
|
21503
21503
|
}).readonly().superRefine((session, context) => {
|
|
21504
21504
|
let previousPosition = 0n;
|
|
21505
21505
|
const eventIds = /* @__PURE__ */ new Set();
|
|
21506
|
-
for (const [
|
|
21506
|
+
for (const [index2, event] of session.events.entries()) {
|
|
21507
21507
|
if (event.sessionId !== session.sessionId) {
|
|
21508
21508
|
context.addIssue({
|
|
21509
21509
|
code: "custom",
|
|
21510
21510
|
message: "Exported event belongs to a different Session",
|
|
21511
|
-
path: ["events",
|
|
21511
|
+
path: ["events", index2, "sessionId"]
|
|
21512
21512
|
});
|
|
21513
21513
|
}
|
|
21514
21514
|
const position = BigInt(event.position);
|
|
@@ -21516,14 +21516,14 @@ var sessionExportV2Schema = external_exports.object({
|
|
|
21516
21516
|
context.addIssue({
|
|
21517
21517
|
code: "custom",
|
|
21518
21518
|
message: "Exported events are not in increasing position order",
|
|
21519
|
-
path: ["events",
|
|
21519
|
+
path: ["events", index2, "position"]
|
|
21520
21520
|
});
|
|
21521
21521
|
}
|
|
21522
21522
|
if (eventIds.has(event.eventId)) {
|
|
21523
21523
|
context.addIssue({
|
|
21524
21524
|
code: "custom",
|
|
21525
21525
|
message: "Exported event identities are not unique",
|
|
21526
|
-
path: ["events",
|
|
21526
|
+
path: ["events", index2, "eventId"]
|
|
21527
21527
|
});
|
|
21528
21528
|
}
|
|
21529
21529
|
previousPosition = position;
|
|
@@ -21574,6 +21574,7 @@ function decode5(value, schema) {
|
|
|
21574
21574
|
function encode4(value, schema) {
|
|
21575
21575
|
return JSON.stringify(decode5(value, schema));
|
|
21576
21576
|
}
|
|
21577
|
+
var decodeSessionEventV2 = (value) => decode5(value, sessionEventV2Schema);
|
|
21577
21578
|
var decodeSessionEventEnvelopeV2 = (value) => decode5(value, sessionEventEnvelopeV2Schema);
|
|
21578
21579
|
var encodeSessionEventEnvelopeV2 = (value) => encode4(value, sessionEventEnvelopeV2Schema);
|
|
21579
21580
|
var decodeAcpSessionUpdateV2 = (value) => decode5(value, acpSessionUpdateV2Schema);
|
|
@@ -26565,9 +26566,9 @@ function comparePrerelease(left, right) {
|
|
|
26565
26566
|
if (left.length === 0 || right.length === 0) {
|
|
26566
26567
|
return left.length === right.length ? 0 : left.length === 0 ? 1 : -1;
|
|
26567
26568
|
}
|
|
26568
|
-
for (let
|
|
26569
|
-
const leftPart = left[
|
|
26570
|
-
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];
|
|
26571
26572
|
if (leftPart === void 0 || rightPart === void 0) {
|
|
26572
26573
|
return leftPart === rightPart ? 0 : leftPart === void 0 ? -1 : 1;
|
|
26573
26574
|
}
|
|
@@ -26592,8 +26593,8 @@ function compareAgentVersions(left, right) {
|
|
|
26592
26593
|
if (parsedLeft === null || parsedRight === null) {
|
|
26593
26594
|
return null;
|
|
26594
26595
|
}
|
|
26595
|
-
for (let
|
|
26596
|
-
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);
|
|
26597
26598
|
if (difference !== 0) {
|
|
26598
26599
|
return Math.sign(difference);
|
|
26599
26600
|
}
|
|
@@ -27080,7 +27081,7 @@ function createDaemonConfig(connection, agents = [], installableAgents = [], loc
|
|
|
27080
27081
|
}
|
|
27081
27082
|
|
|
27082
27083
|
// src/run-daemon.ts
|
|
27083
|
-
import { createHash as createHash7, randomUUID as
|
|
27084
|
+
import { createHash as createHash7, randomUUID as randomUUID9 } from "node:crypto";
|
|
27084
27085
|
import { join as join18 } from "node:path";
|
|
27085
27086
|
import { styleText } from "node:util";
|
|
27086
27087
|
|
|
@@ -27203,7 +27204,7 @@ function startsWith(bytes, signature, offset = 0) {
|
|
|
27203
27204
|
if (bytes.byteLength < offset + signature.byteLength) {
|
|
27204
27205
|
return false;
|
|
27205
27206
|
}
|
|
27206
|
-
return signature.every((value,
|
|
27207
|
+
return signature.every((value, index2) => bytes[offset + index2] === value);
|
|
27207
27208
|
}
|
|
27208
27209
|
function sniffRasterMime(bytes) {
|
|
27209
27210
|
if (startsWith(bytes, PNG_SIGNATURE)) {
|
|
@@ -27331,7 +27332,7 @@ function startsWith2(bytes, signature, offset = 0) {
|
|
|
27331
27332
|
if (bytes.byteLength < offset + signature.byteLength) {
|
|
27332
27333
|
return false;
|
|
27333
27334
|
}
|
|
27334
|
-
return signature.every((value,
|
|
27335
|
+
return signature.every((value, index2) => bytes[offset + index2] === value);
|
|
27335
27336
|
}
|
|
27336
27337
|
function sniffVideoMime(bytes) {
|
|
27337
27338
|
if (startsWith2(bytes, MP4_FILE_TYPE, 4)) {
|
|
@@ -27460,10 +27461,10 @@ async function replaceImageMarkers(text2, replace) {
|
|
|
27460
27461
|
let cursor = 0;
|
|
27461
27462
|
let rewritten = "";
|
|
27462
27463
|
for (const match of matches) {
|
|
27463
|
-
const
|
|
27464
|
-
rewritten += text2.slice(cursor,
|
|
27464
|
+
const index2 = match.index ?? 0;
|
|
27465
|
+
rewritten += text2.slice(cursor, index2);
|
|
27465
27466
|
rewritten += await replace(match[1] ?? "");
|
|
27466
|
-
cursor =
|
|
27467
|
+
cursor = index2 + match[0].length;
|
|
27467
27468
|
}
|
|
27468
27469
|
return `${rewritten}${text2.slice(cursor)}`;
|
|
27469
27470
|
}
|
|
@@ -28697,9 +28698,9 @@ function historyContentCharacters(messages) {
|
|
|
28697
28698
|
var AcpHistoryReplay = class {
|
|
28698
28699
|
#activities = /* @__PURE__ */ new Map();
|
|
28699
28700
|
#messages = [];
|
|
28700
|
-
#events
|
|
28701
|
-
#records = [];
|
|
28701
|
+
#events;
|
|
28702
28702
|
#turnActivityIds = /* @__PURE__ */ new Set();
|
|
28703
|
+
#sessionId;
|
|
28703
28704
|
#activityTracker = new AcpActivityTracker(
|
|
28704
28705
|
async (activity2) => {
|
|
28705
28706
|
this.#activities.set(activity2.activityId, activity2);
|
|
@@ -28720,10 +28721,16 @@ var AcpHistoryReplay = class {
|
|
|
28720
28721
|
#firstMessageIndex = 0;
|
|
28721
28722
|
#characters = 0;
|
|
28722
28723
|
#truncated = false;
|
|
28724
|
+
constructor(events, sessionId) {
|
|
28725
|
+
this.#events = events;
|
|
28726
|
+
this.#sessionId = sessionId;
|
|
28727
|
+
}
|
|
28723
28728
|
record = async (update, rawUpdate, onRecorded = () => Promise.resolve()) => {
|
|
28724
|
-
this.#
|
|
28725
|
-
|
|
28726
|
-
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) => {
|
|
28727
28734
|
if (update.sessionUpdate === "agent_thought_chunk") {
|
|
28728
28735
|
if (update.content.type === "text") {
|
|
28729
28736
|
await this.#activityTracker.recordNarrative(
|
|
@@ -28732,30 +28739,30 @@ var AcpHistoryReplay = class {
|
|
|
28732
28739
|
update.content.text
|
|
28733
28740
|
);
|
|
28734
28741
|
}
|
|
28735
|
-
return
|
|
28742
|
+
return position;
|
|
28736
28743
|
}
|
|
28737
28744
|
if (update.sessionUpdate === "tool_call") {
|
|
28738
28745
|
await this.#activityTracker.recordToolCall(update);
|
|
28739
|
-
return
|
|
28746
|
+
return position;
|
|
28740
28747
|
}
|
|
28741
28748
|
if (update.sessionUpdate === "tool_call_update") {
|
|
28742
28749
|
await this.#activityTracker.recordToolCallUpdate(update);
|
|
28743
|
-
return
|
|
28750
|
+
return position;
|
|
28744
28751
|
}
|
|
28745
28752
|
if (update.sessionUpdate === "plan") {
|
|
28746
28753
|
await this.#activityTracker.recordPlan(update);
|
|
28747
|
-
return
|
|
28754
|
+
return position;
|
|
28748
28755
|
}
|
|
28749
28756
|
if (update.sessionUpdate === "plan_update") {
|
|
28750
28757
|
await this.#activityTracker.recordPlanUpdate(update);
|
|
28751
|
-
return
|
|
28758
|
+
return position;
|
|
28752
28759
|
}
|
|
28753
28760
|
if (update.sessionUpdate === "plan_removed") {
|
|
28754
28761
|
await this.#activityTracker.removePlan(update);
|
|
28755
|
-
return
|
|
28762
|
+
return position;
|
|
28756
28763
|
}
|
|
28757
28764
|
if (update.sessionUpdate !== "user_message_chunk" && update.sessionUpdate !== "agent_message_chunk") {
|
|
28758
|
-
return
|
|
28765
|
+
return position;
|
|
28759
28766
|
}
|
|
28760
28767
|
if (update.sessionUpdate === "agent_message_chunk" && isProgressMessage(update)) {
|
|
28761
28768
|
if (update.content.type === "text") {
|
|
@@ -28765,18 +28772,18 @@ var AcpHistoryReplay = class {
|
|
|
28765
28772
|
update.content.text
|
|
28766
28773
|
);
|
|
28767
28774
|
}
|
|
28768
|
-
return
|
|
28775
|
+
return position;
|
|
28769
28776
|
}
|
|
28770
28777
|
const role = update.sessionUpdate === "user_message_chunk" ? "user" : "assistant";
|
|
28771
28778
|
const content = update.content;
|
|
28772
28779
|
if (role === "assistant" && content.type !== "text") {
|
|
28773
28780
|
await this.#activityTracker.finishNarrative();
|
|
28774
28781
|
this.recordAssistantContent(update.messageId ?? null, normalizeContentBlock(content));
|
|
28775
|
-
return
|
|
28782
|
+
return position;
|
|
28776
28783
|
}
|
|
28777
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]`;
|
|
28778
28785
|
if (text2.length === 0) {
|
|
28779
|
-
return
|
|
28786
|
+
return position;
|
|
28780
28787
|
}
|
|
28781
28788
|
const previous = this.#messages.at(-1);
|
|
28782
28789
|
const id = update.messageId ?? null;
|
|
@@ -28803,41 +28810,32 @@ var AcpHistoryReplay = class {
|
|
|
28803
28810
|
this.#characters += bounded2.length;
|
|
28804
28811
|
this.#lastMessageId = id;
|
|
28805
28812
|
this.trimMessages();
|
|
28806
|
-
return
|
|
28813
|
+
return position;
|
|
28807
28814
|
};
|
|
28808
28815
|
recordLifecycle = (event) => {
|
|
28809
28816
|
if (event.type !== "lifecycle-metadata") {
|
|
28810
28817
|
throw new Error("Lifecycle history only accepts lifecycle metadata");
|
|
28811
28818
|
}
|
|
28812
|
-
this.#
|
|
28813
|
-
this.#events.push(event);
|
|
28814
|
-
return this.#events.length;
|
|
28819
|
+
return this.#events.append(this.#sessionId, event);
|
|
28815
28820
|
};
|
|
28816
|
-
eventCount = () => this.#events.length;
|
|
28817
28821
|
append = async (replay) => {
|
|
28818
|
-
|
|
28819
|
-
|
|
28820
|
-
|
|
28821
|
-
} else {
|
|
28822
|
-
this.recordLifecycle(record2.event);
|
|
28823
|
-
}
|
|
28822
|
+
await replay.#activityTracker.finish();
|
|
28823
|
+
for (const [activityId, activity2] of replay.#activities) {
|
|
28824
|
+
this.#activities.set(activityId, activity2);
|
|
28824
28825
|
}
|
|
28825
|
-
|
|
28826
|
-
|
|
28827
|
-
|
|
28828
|
-
const parsedCursor = cursor === null ? events.length : Number(cursor);
|
|
28829
|
-
if (!Number.isSafeInteger(parsedCursor) || parsedCursor < 0 || parsedCursor > events.length) {
|
|
28830
|
-
throw new Error("The native event cursor is invalid");
|
|
28826
|
+
for (const message of replay.#messages.slice(replay.#firstMessageIndex)) {
|
|
28827
|
+
this.#messages.push(message);
|
|
28828
|
+
this.#characters += message.text.length;
|
|
28831
28829
|
}
|
|
28832
|
-
|
|
28833
|
-
|
|
28834
|
-
|
|
28835
|
-
|
|
28836
|
-
|
|
28837
|
-
|
|
28838
|
-
|
|
28839
|
-
};
|
|
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();
|
|
28840
28837
|
};
|
|
28838
|
+
eventPage = (eventLimit, cursor) => this.#events.page(this.#sessionId, eventLimit, cursor);
|
|
28841
28839
|
snapshot = async () => {
|
|
28842
28840
|
await this.#activityTracker.finish();
|
|
28843
28841
|
const messages = this.#messages.slice(this.#firstMessageIndex).map((message) => {
|
|
@@ -29470,9 +29468,7 @@ var AcpSessionInteractions = class {
|
|
|
29470
29468
|
};
|
|
29471
29469
|
|
|
29472
29470
|
// src/acp/session-store.ts
|
|
29473
|
-
import {
|
|
29474
|
-
import { dirname as dirname3 } from "node:path";
|
|
29475
|
-
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
29471
|
+
import { randomUUID } from "node:crypto";
|
|
29476
29472
|
|
|
29477
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
|
|
29478
29474
|
var entityKind = /* @__PURE__ */ Symbol.for("drizzle:entityKind");
|
|
@@ -30588,7 +30584,7 @@ function haveSameKeys(left, right) {
|
|
|
30588
30584
|
const leftKeys = Object.keys(left);
|
|
30589
30585
|
const rightKeys = Object.keys(right);
|
|
30590
30586
|
if (leftKeys.length !== rightKeys.length) return false;
|
|
30591
|
-
for (const [
|
|
30587
|
+
for (const [index2, key] of leftKeys.entries()) if (key !== rightKeys[index2]) return false;
|
|
30592
30588
|
return true;
|
|
30593
30589
|
}
|
|
30594
30590
|
function mapUpdateSet(table, values) {
|
|
@@ -31341,195 +31337,6 @@ var NoopLogger = class {
|
|
|
31341
31337
|
}
|
|
31342
31338
|
};
|
|
31343
31339
|
|
|
31344
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/query-builders/count.js
|
|
31345
|
-
var SQLiteCountBuilder = class SQLiteCountBuilder2 extends SQL {
|
|
31346
|
-
static [entityKind] = "SQLiteCountBuilder";
|
|
31347
|
-
dialect;
|
|
31348
|
-
session;
|
|
31349
|
-
static buildCount(source, filters, parens) {
|
|
31350
|
-
const query = sql`select count(*) from ${source}${sql` where ${filters}`.if(filters)}`;
|
|
31351
|
-
return parens ? sql`(${query})` : query;
|
|
31352
|
-
}
|
|
31353
|
-
constructor(countConfig) {
|
|
31354
|
-
super(SQLiteCountBuilder2.buildCount(countConfig.source, countConfig.filters, true).queryChunks);
|
|
31355
|
-
this.countConfig = countConfig;
|
|
31356
|
-
this.dialect = countConfig.dialect;
|
|
31357
|
-
this.session = countConfig.session;
|
|
31358
|
-
this.mapWith((e) => {
|
|
31359
|
-
if (typeof e === "number") return e;
|
|
31360
|
-
return Number(e ?? 0);
|
|
31361
|
-
});
|
|
31362
|
-
}
|
|
31363
|
-
executableSql;
|
|
31364
|
-
build() {
|
|
31365
|
-
if (!this.executableSql) {
|
|
31366
|
-
const { source, filters } = this.countConfig;
|
|
31367
|
-
this.executableSql = SQLiteCountBuilder2.buildCount(source, filters);
|
|
31368
|
-
}
|
|
31369
|
-
return this.dialect.sqlToQuery(this.executableSql);
|
|
31370
|
-
}
|
|
31371
|
-
};
|
|
31372
|
-
|
|
31373
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/async/count.js
|
|
31374
|
-
var SQLiteAsyncCountBuilder = class extends SQLiteCountBuilder {
|
|
31375
|
-
static [entityKind] = "SQLiteAsyncCountBuilder";
|
|
31376
|
-
constructor(countConfig) {
|
|
31377
|
-
super(countConfig);
|
|
31378
|
-
}
|
|
31379
|
-
/** @internal */
|
|
31380
|
-
executeRaw(placeholderValues) {
|
|
31381
|
-
return this.session.prepareQuery(this.build(), "arrays", false, "all", (rows) => {
|
|
31382
|
-
const v = rows[0]?.[0];
|
|
31383
|
-
if (typeof v === "number") return v;
|
|
31384
|
-
return v ? Number(v) : 0;
|
|
31385
|
-
}).execute(placeholderValues);
|
|
31386
|
-
}
|
|
31387
|
-
async execute(placeholderValues) {
|
|
31388
|
-
return await this.executeRaw(placeholderValues);
|
|
31389
|
-
}
|
|
31390
|
-
};
|
|
31391
|
-
applyMixins(SQLiteAsyncCountBuilder, [QueryPromise]);
|
|
31392
|
-
var SQLiteSyncCountBuilder = class extends SQLiteAsyncCountBuilder {
|
|
31393
|
-
static [entityKind] = "SQLiteSyncCountBuilder";
|
|
31394
|
-
sync(placeholderValues) {
|
|
31395
|
-
return this.executeRaw(placeholderValues).sync();
|
|
31396
|
-
}
|
|
31397
|
-
};
|
|
31398
|
-
|
|
31399
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/query-builders/query.js
|
|
31400
|
-
var RelationalQueryBuilder = class {
|
|
31401
|
-
static [entityKind] = "SQLiteRelationalQueryBuilderV2";
|
|
31402
|
-
constructor(mode, schema, table, tableConfig, dialect, session, forbidJsonb, builder = SQLiteRelationalQuery) {
|
|
31403
|
-
this.mode = mode;
|
|
31404
|
-
this.schema = schema;
|
|
31405
|
-
this.table = table;
|
|
31406
|
-
this.tableConfig = tableConfig;
|
|
31407
|
-
this.dialect = dialect;
|
|
31408
|
-
this.session = session;
|
|
31409
|
-
this.forbidJsonb = forbidJsonb;
|
|
31410
|
-
this.builder = builder;
|
|
31411
|
-
}
|
|
31412
|
-
findMany(config2) {
|
|
31413
|
-
return new this.builder(this.mode, this.schema, this.table, this.tableConfig, this.dialect, this.session, config2 ?? true, "many", this.forbidJsonb);
|
|
31414
|
-
}
|
|
31415
|
-
findFirst(config2) {
|
|
31416
|
-
return new this.builder(this.mode, this.schema, this.table, this.tableConfig, this.dialect, this.session, config2 ?? true, "first", this.forbidJsonb);
|
|
31417
|
-
}
|
|
31418
|
-
};
|
|
31419
|
-
var SQLiteRelationalQuery = class {
|
|
31420
|
-
static [entityKind] = "SQLiteRelationalQueryV2";
|
|
31421
|
-
/** @internal */
|
|
31422
|
-
mode;
|
|
31423
|
-
/** @internal */
|
|
31424
|
-
table;
|
|
31425
|
-
/** @internal */
|
|
31426
|
-
resultKind;
|
|
31427
|
-
constructor(resultKind, schema, table, tableConfig, dialect, session, config2, mode, forbidJsonb) {
|
|
31428
|
-
this.schema = schema;
|
|
31429
|
-
this.tableConfig = tableConfig;
|
|
31430
|
-
this.dialect = dialect;
|
|
31431
|
-
this.session = session;
|
|
31432
|
-
this.config = config2;
|
|
31433
|
-
this.forbidJsonb = forbidJsonb;
|
|
31434
|
-
this.resultKind = resultKind;
|
|
31435
|
-
this.mode = mode;
|
|
31436
|
-
this.table = table;
|
|
31437
|
-
}
|
|
31438
|
-
getSQL() {
|
|
31439
|
-
return this._getQuery().sql;
|
|
31440
|
-
}
|
|
31441
|
-
_getQuery() {
|
|
31442
|
-
const jsonb = this.forbidJsonb ? sql`json` : sql`jsonb`;
|
|
31443
|
-
return this.dialect.buildRelationalQuery({
|
|
31444
|
-
schema: this.schema,
|
|
31445
|
-
table: this.table,
|
|
31446
|
-
tableConfig: this.tableConfig,
|
|
31447
|
-
queryConfig: this.config,
|
|
31448
|
-
mode: this.mode,
|
|
31449
|
-
jsonb
|
|
31450
|
-
});
|
|
31451
|
-
}
|
|
31452
|
-
_toSQL() {
|
|
31453
|
-
const query = this._getQuery();
|
|
31454
|
-
return {
|
|
31455
|
-
query,
|
|
31456
|
-
builtQuery: this.dialect.sqlToQuery(query.sql)
|
|
31457
|
-
};
|
|
31458
|
-
}
|
|
31459
|
-
toSQL() {
|
|
31460
|
-
return this._toSQL().builtQuery;
|
|
31461
|
-
}
|
|
31462
|
-
};
|
|
31463
|
-
|
|
31464
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/async/query.js
|
|
31465
|
-
var SQLiteAsyncRelationalQuery = class extends SQLiteRelationalQuery {
|
|
31466
|
-
static [entityKind] = "SQLiteAsyncRelationalQueryV2";
|
|
31467
|
-
/** @internal */
|
|
31468
|
-
_prepare(prepare = false) {
|
|
31469
|
-
const { query, builtQuery } = this._toSQL();
|
|
31470
|
-
const mapper = this.dialect.mapperGenerators.relationalRows({
|
|
31471
|
-
isFirst: this.mode === "first",
|
|
31472
|
-
parseJson: true,
|
|
31473
|
-
parseJsonIfString: false,
|
|
31474
|
-
rootJsonMappers: false,
|
|
31475
|
-
selection: query.selection,
|
|
31476
|
-
arrayModeRoot: true
|
|
31477
|
-
});
|
|
31478
|
-
return this.session.prepareQuery(builtQuery, "arrays", prepare, "all", mapper);
|
|
31479
|
-
}
|
|
31480
|
-
prepare() {
|
|
31481
|
-
return this._prepare(true);
|
|
31482
|
-
}
|
|
31483
|
-
async execute(placeholderValues) {
|
|
31484
|
-
return this._prepare().execute(placeholderValues);
|
|
31485
|
-
}
|
|
31486
|
-
};
|
|
31487
|
-
var SQLiteSyncRelationalQuery = class extends SQLiteAsyncRelationalQuery {
|
|
31488
|
-
static [entityKind] = "SQLiteSyncRelationalQueryV2";
|
|
31489
|
-
sync(placeholderValues) {
|
|
31490
|
-
return this._prepare().execute(placeholderValues).sync();
|
|
31491
|
-
}
|
|
31492
|
-
};
|
|
31493
|
-
applyMixins(SQLiteAsyncRelationalQuery, [QueryPromise]);
|
|
31494
|
-
|
|
31495
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/selection-proxy.js
|
|
31496
|
-
var SelectionProxyHandler = class SelectionProxyHandler2 {
|
|
31497
|
-
static [entityKind] = "SelectionProxyHandler";
|
|
31498
|
-
config;
|
|
31499
|
-
constructor(config2) {
|
|
31500
|
-
this.config = { ...config2 };
|
|
31501
|
-
}
|
|
31502
|
-
get(subquery, prop) {
|
|
31503
|
-
if (prop === "_") return {
|
|
31504
|
-
...subquery["_"],
|
|
31505
|
-
selectedFields: new Proxy(subquery._.selectedFields, this)
|
|
31506
|
-
};
|
|
31507
|
-
if (prop === ViewBaseConfig) return {
|
|
31508
|
-
...subquery[ViewBaseConfig],
|
|
31509
|
-
selectedFields: new Proxy(subquery[ViewBaseConfig].selectedFields, this)
|
|
31510
|
-
};
|
|
31511
|
-
if (typeof prop === "symbol") return subquery[prop];
|
|
31512
|
-
const value = (is(subquery, Subquery) ? subquery._.selectedFields : is(subquery, View) ? subquery[ViewBaseConfig].selectedFields : subquery)[prop];
|
|
31513
|
-
if (is(value, SQL.Aliased)) {
|
|
31514
|
-
if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) return value.sql;
|
|
31515
|
-
const newValue = value.clone();
|
|
31516
|
-
newValue.isSelectionField = true;
|
|
31517
|
-
newValue.origin = this.config.alias;
|
|
31518
|
-
return newValue;
|
|
31519
|
-
}
|
|
31520
|
-
if (is(value, SQL)) {
|
|
31521
|
-
if (this.config.sqlBehavior === "sql") return value;
|
|
31522
|
-
throw new Error(`You tried to reference "${prop}" field from a subquery, which is a raw SQL field, but it doesn't have an alias declared. Please add an alias to the field using ".as('alias')" method.`);
|
|
31523
|
-
}
|
|
31524
|
-
if (is(value, Column)) {
|
|
31525
|
-
if (this.config.alias) return new Proxy(value, new ColumnTableAliasProxyHandler(new Proxy(value.table, new TableAliasProxyHandler(this.config.alias, this.config.replaceOriginalName ?? false, true)), true));
|
|
31526
|
-
return value;
|
|
31527
|
-
}
|
|
31528
|
-
if (typeof value !== "object" || value === null) return value;
|
|
31529
|
-
return new Proxy(value, new SelectionProxyHandler2(this.config));
|
|
31530
|
-
}
|
|
31531
|
-
};
|
|
31532
|
-
|
|
31533
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
|
|
31534
31341
|
var ForeignKeyBuilder = class {
|
|
31535
31342
|
static [entityKind] = "SQLiteForeignKeyBuilder";
|
|
@@ -32094,130 +31901,144 @@ function sqliteTableWithCasing(casing) {
|
|
|
32094
31901
|
}
|
|
32095
31902
|
var sqliteTable = sqliteTableWithCasing(void 0);
|
|
32096
31903
|
|
|
32097
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/
|
|
32098
|
-
|
|
32099
|
-
|
|
32100
|
-
|
|
32101
|
-
|
|
32102
|
-
|
|
32103
|
-
}
|
|
32104
|
-
|
|
32105
|
-
|
|
32106
|
-
|
|
32107
|
-
|
|
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";
|
|
32108
31917
|
/** @internal */
|
|
32109
31918
|
config;
|
|
32110
|
-
constructor(
|
|
32111
|
-
this.table = table;
|
|
32112
|
-
this.session = session;
|
|
32113
|
-
this.dialect = dialect;
|
|
31919
|
+
constructor(name2, columns, unique) {
|
|
32114
31920
|
this.config = {
|
|
32115
|
-
|
|
32116
|
-
|
|
31921
|
+
name: name2,
|
|
31922
|
+
columns,
|
|
31923
|
+
unique,
|
|
31924
|
+
where: void 0
|
|
32117
31925
|
};
|
|
32118
31926
|
}
|
|
32119
31927
|
/**
|
|
32120
|
-
*
|
|
32121
|
-
*
|
|
32122
|
-
* Calling this method will delete only those rows that fulfill a specified condition.
|
|
32123
|
-
*
|
|
32124
|
-
* See docs: {@link https://orm.drizzle.team/docs/delete}
|
|
32125
|
-
*
|
|
32126
|
-
* @param where the `where` clause.
|
|
32127
|
-
*
|
|
32128
|
-
* @example
|
|
32129
|
-
* You can use conditional operators and `sql function` to filter the rows to be deleted.
|
|
32130
|
-
*
|
|
32131
|
-
* ```ts
|
|
32132
|
-
* // Delete all cars with green color
|
|
32133
|
-
* db.delete(cars).where(eq(cars.color, 'green'));
|
|
32134
|
-
* // or
|
|
32135
|
-
* db.delete(cars).where(sql`${cars.color} = 'green'`)
|
|
32136
|
-
* ```
|
|
32137
|
-
*
|
|
32138
|
-
* You can logically combine conditional operators with `and()` and `or()` operators:
|
|
32139
|
-
*
|
|
32140
|
-
* ```ts
|
|
32141
|
-
* // Delete all BMW cars with a green color
|
|
32142
|
-
* db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
|
32143
|
-
*
|
|
32144
|
-
* // Delete all cars with the green or blue color
|
|
32145
|
-
* db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
32146
|
-
* ```
|
|
31928
|
+
* Condition for partial index.
|
|
32147
31929
|
*/
|
|
32148
|
-
where(
|
|
32149
|
-
this.config.where =
|
|
31930
|
+
where(condition) {
|
|
31931
|
+
this.config.where = condition;
|
|
32150
31932
|
return this;
|
|
32151
31933
|
}
|
|
32152
|
-
|
|
32153
|
-
|
|
32154
|
-
|
|
32155
|
-
sqlAliasedBehavior: "alias",
|
|
32156
|
-
sqlBehavior: "sql"
|
|
32157
|
-
})));
|
|
32158
|
-
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
32159
|
-
this.config.orderBy = orderByArray;
|
|
32160
|
-
} else {
|
|
32161
|
-
const orderByArray = columns;
|
|
32162
|
-
this.config.orderBy = orderByArray;
|
|
32163
|
-
}
|
|
32164
|
-
return this;
|
|
32165
|
-
}
|
|
32166
|
-
limit(limit) {
|
|
32167
|
-
this.config.limit = limit;
|
|
32168
|
-
return this;
|
|
32169
|
-
}
|
|
32170
|
-
returning(fields = this.table[SQLiteTable.Symbol.Columns]) {
|
|
32171
|
-
this.config.returning = orderSelectedFields(fields);
|
|
32172
|
-
return this;
|
|
32173
|
-
}
|
|
32174
|
-
getSQL() {
|
|
32175
|
-
return this.dialect.buildDeleteQuery(this.config);
|
|
32176
|
-
}
|
|
32177
|
-
toSQL() {
|
|
32178
|
-
return this.dialect.sqlToQuery(this.getSQL());
|
|
31934
|
+
/** @internal */
|
|
31935
|
+
build(table) {
|
|
31936
|
+
return new Index(this.config, table);
|
|
32179
31937
|
}
|
|
32180
|
-
|
|
32181
|
-
|
|
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;
|
|
32182
31949
|
}
|
|
32183
31950
|
};
|
|
31951
|
+
function index(name2) {
|
|
31952
|
+
return new IndexBuilderOn(name2, false);
|
|
31953
|
+
}
|
|
32184
31954
|
|
|
32185
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/
|
|
32186
|
-
|
|
32187
|
-
|
|
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";
|
|
32188
31962
|
/** @internal */
|
|
32189
|
-
|
|
32190
|
-
|
|
32191
|
-
|
|
32192
|
-
|
|
32193
|
-
|
|
31963
|
+
columns;
|
|
31964
|
+
/** @internal */
|
|
31965
|
+
name;
|
|
31966
|
+
constructor(columns, name2) {
|
|
31967
|
+
this.columns = columns;
|
|
31968
|
+
this.name = name2;
|
|
32194
31969
|
}
|
|
32195
|
-
|
|
32196
|
-
|
|
31970
|
+
/** @internal */
|
|
31971
|
+
build(table) {
|
|
31972
|
+
return new PrimaryKey(table, this.columns, this.name);
|
|
32197
31973
|
}
|
|
32198
|
-
|
|
32199
|
-
|
|
32200
|
-
|
|
32201
|
-
|
|
32202
|
-
|
|
32203
|
-
|
|
32204
|
-
|
|
32205
|
-
|
|
32206
|
-
|
|
32207
|
-
|
|
32208
|
-
|
|
32209
|
-
}
|
|
32210
|
-
|
|
32211
|
-
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`;
|
|
32212
31988
|
}
|
|
32213
31989
|
};
|
|
32214
|
-
|
|
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
|
+
}
|
|
32215
31998
|
|
|
32216
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
|
|
32217
32000
|
var SQLiteViewBase = class extends View {
|
|
32218
32001
|
static [entityKind] = "SQLiteViewBase";
|
|
32219
32002
|
};
|
|
32220
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
|
+
|
|
32221
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
|
|
32222
32043
|
var TypedQueryBuilder = class {
|
|
32223
32044
|
static [entityKind] = "TypedQueryBuilder";
|
|
@@ -32918,8 +32739,8 @@ var SQLiteDialect = class {
|
|
|
32918
32739
|
buildJoins(joins) {
|
|
32919
32740
|
if (!joins || joins.length === 0) return;
|
|
32920
32741
|
const joinsArray = [];
|
|
32921
|
-
if (joins) for (const [
|
|
32922
|
-
if (
|
|
32742
|
+
if (joins) for (const [index2, joinMeta] of joins.entries()) {
|
|
32743
|
+
if (index2 === 0) joinsArray.push(sql` `);
|
|
32923
32744
|
const table = joinMeta.table;
|
|
32924
32745
|
const onSql = joinMeta.on ? sql` on ${joinMeta.on}` : void 0;
|
|
32925
32746
|
if (is(table, SQLiteTable)) {
|
|
@@ -32929,7 +32750,7 @@ var SQLiteDialect = class {
|
|
|
32929
32750
|
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
|
32930
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}`);
|
|
32931
32752
|
} else joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join ${table}${onSql}`);
|
|
32932
|
-
if (
|
|
32753
|
+
if (index2 < joins.length - 1) joinsArray.push(sql` `);
|
|
32933
32754
|
}
|
|
32934
32755
|
return sql.join(joinsArray);
|
|
32935
32756
|
}
|
|
@@ -32938,9 +32759,9 @@ var SQLiteDialect = class {
|
|
|
32938
32759
|
}
|
|
32939
32760
|
buildOrderBy(orderBy) {
|
|
32940
32761
|
const orderByList = [];
|
|
32941
|
-
if (orderBy) for (const [
|
|
32762
|
+
if (orderBy) for (const [index2, orderByValue] of orderBy.entries()) {
|
|
32942
32763
|
orderByList.push(orderByValue);
|
|
32943
|
-
if (
|
|
32764
|
+
if (index2 < orderBy.length - 1) orderByList.push(sql`, `);
|
|
32944
32765
|
}
|
|
32945
32766
|
return orderByList.length > 0 ? sql` order by ${sql.join(orderByList)}` : void 0;
|
|
32946
32767
|
}
|
|
@@ -32968,9 +32789,9 @@ var SQLiteDialect = class {
|
|
|
32968
32789
|
const whereSql = where ? sql` where ${where}` : void 0;
|
|
32969
32790
|
const havingSql = having ? sql` having ${having}` : void 0;
|
|
32970
32791
|
const groupByList = [];
|
|
32971
|
-
if (groupBy) for (const [
|
|
32792
|
+
if (groupBy) for (const [index2, groupByValue] of groupBy.entries()) {
|
|
32972
32793
|
groupByList.push(groupByValue);
|
|
32973
|
-
if (
|
|
32794
|
+
if (index2 < groupBy.length - 1) groupByList.push(sql`, `);
|
|
32974
32795
|
}
|
|
32975
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}`;
|
|
32976
32797
|
if (setOperators.length > 0) return this.buildSetOperations(finalQuery, setOperators);
|
|
@@ -33259,6 +33080,268 @@ var QueryBuilder = class {
|
|
|
33259
33080
|
}
|
|
33260
33081
|
};
|
|
33261
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
|
+
|
|
33262
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
|
|
33263
33346
|
var SQLiteInsertBuilder = class {
|
|
33264
33347
|
static [entityKind] = "SQLiteInsertBuilder";
|
|
@@ -34146,133 +34229,6 @@ var SQLiteAsyncTransaction = class extends SQLiteAsyncDatabase {
|
|
|
34146
34229
|
}
|
|
34147
34230
|
};
|
|
34148
34231
|
|
|
34149
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/node-sqlite/session.js
|
|
34150
|
-
var NodeSQLiteSession = class extends SQLiteAsyncSession {
|
|
34151
|
-
static [entityKind] = "SQLJsSession";
|
|
34152
|
-
logger;
|
|
34153
|
-
constructor(client2, dialect, relations, options = {}) {
|
|
34154
|
-
super(dialect, "sync");
|
|
34155
|
-
this.client = client2;
|
|
34156
|
-
this.relations = relations;
|
|
34157
|
-
this.options = options;
|
|
34158
|
-
this.logger = options.logger ?? new NoopLogger();
|
|
34159
|
-
}
|
|
34160
|
-
prepareQuery(query, mode, _prepare, executeMethod, mapper, queryMetadata) {
|
|
34161
|
-
let stmt;
|
|
34162
|
-
try {
|
|
34163
|
-
stmt = this.client.prepare(query.sql);
|
|
34164
|
-
} catch (e) {
|
|
34165
|
-
throw new DrizzleQueryError(query.sql, query.params, e);
|
|
34166
|
-
}
|
|
34167
|
-
return new SQLiteAsyncPreparedQuery("sync", executeMethod, {
|
|
34168
|
-
all: (params) => {
|
|
34169
|
-
stmt.setReturnArrays(mode === "arrays");
|
|
34170
|
-
const res = stmt.all(...params);
|
|
34171
|
-
if (mode === "objects") return res.map((row) => ({ ...row }));
|
|
34172
|
-
return res;
|
|
34173
|
-
},
|
|
34174
|
-
get: (params) => {
|
|
34175
|
-
stmt.setReturnArrays(mode === "arrays");
|
|
34176
|
-
const res = stmt.get(...params);
|
|
34177
|
-
if (res && mode === "objects") return { ...res };
|
|
34178
|
-
return res;
|
|
34179
|
-
},
|
|
34180
|
-
run: (params) => {
|
|
34181
|
-
stmt.setReturnArrays(false);
|
|
34182
|
-
return stmt.run(...params);
|
|
34183
|
-
},
|
|
34184
|
-
values: (params) => {
|
|
34185
|
-
stmt.setReturnArrays(true);
|
|
34186
|
-
return stmt.all(...params);
|
|
34187
|
-
}
|
|
34188
|
-
}, query, mapper, mode, this.logger, void 0, queryMetadata, void 0);
|
|
34189
|
-
}
|
|
34190
|
-
transaction(transaction, config2 = {}) {
|
|
34191
|
-
const tx = new NodeSQLiteTransaction("sync", this.dialect, this, this.relations);
|
|
34192
|
-
this.run(sql.raw(`begin${config2.behavior ? ` ${config2.behavior}` : ""}`));
|
|
34193
|
-
try {
|
|
34194
|
-
const result = transaction(tx);
|
|
34195
|
-
this.run(sql`commit`);
|
|
34196
|
-
return result;
|
|
34197
|
-
} catch (err) {
|
|
34198
|
-
this.run(sql`rollback`);
|
|
34199
|
-
throw err;
|
|
34200
|
-
}
|
|
34201
|
-
}
|
|
34202
|
-
};
|
|
34203
|
-
var NodeSQLiteTransaction = class NodeSQLiteTransaction2 extends SQLiteAsyncTransaction {
|
|
34204
|
-
static [entityKind] = "SQLJsTransaction";
|
|
34205
|
-
transaction(transaction) {
|
|
34206
|
-
const savepointName = `sp${this.nestedIndex + 1}`;
|
|
34207
|
-
const tx = new NodeSQLiteTransaction2("sync", this.dialect, this.session, this._.relations, this.nestedIndex + 1);
|
|
34208
|
-
tx.run(sql.raw(`savepoint ${savepointName}`));
|
|
34209
|
-
try {
|
|
34210
|
-
const result = transaction(tx);
|
|
34211
|
-
tx.run(sql.raw(`release savepoint ${savepointName}`));
|
|
34212
|
-
return result;
|
|
34213
|
-
} catch (err) {
|
|
34214
|
-
tx.run(sql.raw(`rollback to savepoint ${savepointName}`));
|
|
34215
|
-
throw err;
|
|
34216
|
-
}
|
|
34217
|
-
}
|
|
34218
|
-
};
|
|
34219
|
-
|
|
34220
|
-
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/node-sqlite/driver.js
|
|
34221
|
-
import { DatabaseSync } from "node:sqlite";
|
|
34222
|
-
var NodeSQLiteDatabase = class extends SQLiteAsyncDatabase {
|
|
34223
|
-
static [entityKind] = "NodeSQLiteDatabase";
|
|
34224
|
-
};
|
|
34225
|
-
function construct(client2, config2 = {}) {
|
|
34226
|
-
const dialect = new SQLiteDialect({ useJitMappers: jitCompatCheck(config2.jit) });
|
|
34227
|
-
let logger;
|
|
34228
|
-
if (config2.logger === true) logger = new DefaultLogger();
|
|
34229
|
-
else if (config2.logger !== false) logger = config2.logger;
|
|
34230
|
-
const relations = config2.relations ?? {};
|
|
34231
|
-
const db = new NodeSQLiteDatabase("sync", dialect, new NodeSQLiteSession(client2, dialect, relations, { logger }), relations);
|
|
34232
|
-
db.$client = client2;
|
|
34233
|
-
return db;
|
|
34234
|
-
}
|
|
34235
|
-
function drizzle(...params) {
|
|
34236
|
-
if (params[0] === void 0 || typeof params[0] === "string") return construct(params[0] === void 0 ? new DatabaseSync(":memory:") : new DatabaseSync(params[0]), params[1]);
|
|
34237
|
-
const { connection, client: client2, ...config2 } = params[0];
|
|
34238
|
-
if (client2) return construct(client2, config2);
|
|
34239
|
-
if (typeof connection === "object") {
|
|
34240
|
-
const { path: path2, ...options } = connection;
|
|
34241
|
-
return construct(new DatabaseSync(path2 ?? ":memory:", options), config2);
|
|
34242
|
-
}
|
|
34243
|
-
return construct(new DatabaseSync(connection ?? ":memory:"), config2);
|
|
34244
|
-
}
|
|
34245
|
-
(function(_drizzle) {
|
|
34246
|
-
function mock(config2) {
|
|
34247
|
-
return construct({}, config2);
|
|
34248
|
-
}
|
|
34249
|
-
_drizzle.mock = mock;
|
|
34250
|
-
})(drizzle || (drizzle = {}));
|
|
34251
|
-
|
|
34252
|
-
// src/generated/acp-session-store-migrations.ts
|
|
34253
|
-
var acpSessionStoreMigrations = [
|
|
34254
|
-
{
|
|
34255
|
-
"name": "0000_slimy_captain_midlands.sql",
|
|
34256
|
-
"sql": "CREATE TABLE `acp_session` (\n `session_id` text PRIMARY KEY NOT NULL,\n `agent_id` text NOT NULL,\n `native_session_id` text NOT NULL,\n `cwd` text NOT NULL,\n `additional_directories` text NOT NULL,\n `prompted` integer NOT NULL,\n `title` text NOT NULL,\n `updated_at` text NOT NULL\n);\n--> statement-breakpoint\nCREATE TABLE `deleted_acp_session` (\n `session_id` text PRIMARY KEY NOT NULL\n);\n"
|
|
34257
|
-
},
|
|
34258
|
-
{
|
|
34259
|
-
"name": "0001_regular_ultimates.sql",
|
|
34260
|
-
"sql": "ALTER TABLE `acp_session` ADD `last_terminal_command_id` text;"
|
|
34261
|
-
},
|
|
34262
|
-
{
|
|
34263
|
-
"name": "0002_equal_black_queen.sql",
|
|
34264
|
-
"sql": "CREATE TABLE `session_event_v2` (\n `event_id` text PRIMARY KEY NOT NULL,\n `event_json` text NOT NULL,\n `position` integer NOT NULL,\n `session_id` text NOT NULL\n);\n--> statement-breakpoint\nCREATE UNIQUE INDEX `session_event_v2_session_position_unique` ON `session_event_v2` (`session_id`,`position`);--> statement-breakpoint\nCREATE INDEX `session_event_v2_session_position_index` ON `session_event_v2` (`session_id`,`position`);"
|
|
34265
|
-
},
|
|
34266
|
-
{
|
|
34267
|
-
"name": "0003_silky_ravenous.sql",
|
|
34268
|
-
"sql": "DROP TABLE `session_event_v2`;"
|
|
34269
|
-
},
|
|
34270
|
-
{
|
|
34271
|
-
"name": "0004_special_mathemanic.sql",
|
|
34272
|
-
"sql": "DROP TABLE `deleted_acp_session`;--> statement-breakpoint\nALTER TABLE `acp_session` DROP COLUMN `last_terminal_command_id`;"
|
|
34273
|
-
}
|
|
34274
|
-
];
|
|
34275
|
-
|
|
34276
34232
|
// src/schema/acp-session-store/acp-session.ts
|
|
34277
34233
|
var acpSession = sqliteTable("acp_session", {
|
|
34278
34234
|
sessionId: text("session_id").primaryKey(),
|
|
@@ -34285,6 +34241,216 @@ var acpSession = sqliteTable("acp_session", {
|
|
|
34285
34241
|
updatedAt: text("updated_at").notNull()
|
|
34286
34242
|
});
|
|
34287
34243
|
|
|
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
|
+
};
|
|
34453
|
+
|
|
34288
34454
|
// src/acp/session-store.ts
|
|
34289
34455
|
var AcpStoredSession = class {
|
|
34290
34456
|
additionalDirectories;
|
|
@@ -34320,9 +34486,14 @@ var FoundAcpStoredSession = class extends AcpStoredSessionLookup {
|
|
|
34320
34486
|
}
|
|
34321
34487
|
};
|
|
34322
34488
|
var MemoryAcpSessionStore = class {
|
|
34489
|
+
eventsV2;
|
|
34323
34490
|
#sessions = /* @__PURE__ */ new Map();
|
|
34491
|
+
constructor(eventsV2 = new MemoryAcpSessionEventStoreV2(randomUUID())) {
|
|
34492
|
+
this.eventsV2 = eventsV2;
|
|
34493
|
+
}
|
|
34324
34494
|
close = () => {
|
|
34325
34495
|
this.#sessions.clear();
|
|
34496
|
+
this.eventsV2.close();
|
|
34326
34497
|
};
|
|
34327
34498
|
findNative = (agentId, nativeSessionId) => [...this.#sessions.values()].filter(
|
|
34328
34499
|
(session) => session.agentId === agentId && session.nativeSessionId === nativeSessionId
|
|
@@ -34334,6 +34505,7 @@ var MemoryAcpSessionStore = class {
|
|
|
34334
34505
|
};
|
|
34335
34506
|
remove = (sessionId) => {
|
|
34336
34507
|
this.#sessions.delete(sessionId);
|
|
34508
|
+
this.eventsV2.remove(sessionId);
|
|
34337
34509
|
};
|
|
34338
34510
|
write = (session) => {
|
|
34339
34511
|
this.#sessions.set(session.sessionId, session);
|
|
@@ -34365,39 +34537,20 @@ function decodeStoredSession(value) {
|
|
|
34365
34537
|
);
|
|
34366
34538
|
}
|
|
34367
34539
|
var SqliteAcpSessionStore = class {
|
|
34540
|
+
eventsV2;
|
|
34368
34541
|
#database;
|
|
34369
|
-
#
|
|
34370
|
-
constructor(
|
|
34371
|
-
|
|
34372
|
-
this.#
|
|
34373
|
-
|
|
34374
|
-
this.#migrate();
|
|
34375
|
-
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;
|
|
34376
34547
|
}
|
|
34377
|
-
#migrate = () => {
|
|
34378
|
-
const version2 = external_exports.object({ user_version: external_exports.number().int().nonnegative() }).parse(this.#sqliteDatabase.prepare("PRAGMA user_version").get()).user_version;
|
|
34379
|
-
if (version2 > acpSessionStoreMigrations.length) {
|
|
34380
|
-
this.#sqliteDatabase.close();
|
|
34381
|
-
throw new Error("The ACP Session database was created by a newer Mobius version");
|
|
34382
|
-
}
|
|
34383
|
-
for (let index = version2; index < acpSessionStoreMigrations.length; index += 1) {
|
|
34384
|
-
const migration = acpSessionStoreMigrations[index];
|
|
34385
|
-
if (migration === void 0) {
|
|
34386
|
-
throw new Error("The ACP Session migration is unavailable");
|
|
34387
|
-
}
|
|
34388
|
-
this.#sqliteDatabase.exec("BEGIN IMMEDIATE");
|
|
34389
|
-
try {
|
|
34390
|
-
this.#sqliteDatabase.exec(migration.sql);
|
|
34391
|
-
this.#sqliteDatabase.exec(`PRAGMA user_version = ${index + 1}`);
|
|
34392
|
-
this.#sqliteDatabase.exec("COMMIT");
|
|
34393
|
-
} catch (error62) {
|
|
34394
|
-
this.#sqliteDatabase.exec("ROLLBACK");
|
|
34395
|
-
throw error62;
|
|
34396
|
-
}
|
|
34397
|
-
}
|
|
34398
|
-
};
|
|
34399
34548
|
close = () => {
|
|
34400
|
-
|
|
34549
|
+
try {
|
|
34550
|
+
this.#localDatabase.close();
|
|
34551
|
+
} finally {
|
|
34552
|
+
this.eventsV2.close();
|
|
34553
|
+
}
|
|
34401
34554
|
};
|
|
34402
34555
|
findNative = (agentId, nativeSessionId) => this.#database.select().from(acpSession).where(and(eq(acpSession.agentId, agentId), eq(acpSession.nativeSessionId, nativeSessionId))).all().map(decodeStoredSession);
|
|
34403
34556
|
list = () => this.#database.select().from(acpSession).orderBy(desc(acpSession.updatedAt)).all().map(decodeStoredSession);
|
|
@@ -34407,6 +34560,7 @@ var SqliteAcpSessionStore = class {
|
|
|
34407
34560
|
};
|
|
34408
34561
|
remove = (sessionId) => {
|
|
34409
34562
|
this.#database.delete(acpSession).where(eq(acpSession.sessionId, sessionId)).run();
|
|
34563
|
+
this.eventsV2.remove(sessionId);
|
|
34410
34564
|
};
|
|
34411
34565
|
write = (session) => {
|
|
34412
34566
|
const value = {
|
|
@@ -34432,7 +34586,7 @@ var RetryableAcpInitializationError = class extends AcpExecutionError {
|
|
|
34432
34586
|
}
|
|
34433
34587
|
};
|
|
34434
34588
|
function arraysEqual(left, right) {
|
|
34435
|
-
return left.length === right.length && left.every((value,
|
|
34589
|
+
return left.length === right.length && left.every((value, index2) => value === right[index2]);
|
|
34436
34590
|
}
|
|
34437
34591
|
function recordsEqual(left, right) {
|
|
34438
34592
|
const leftEntries = Object.entries(left);
|
|
@@ -34595,12 +34749,17 @@ var AgentSession = class _AgentSession {
|
|
|
34595
34749
|
);
|
|
34596
34750
|
}
|
|
34597
34751
|
const history = await this.#completedHistory(signal, "ACP agent exited while loading history");
|
|
34598
|
-
return history.eventPage(eventLimit, cursor
|
|
34752
|
+
return history.eventPage(eventLimit, cursor);
|
|
34599
34753
|
};
|
|
34600
34754
|
async #completedHistory(signal, exitMessage) {
|
|
34601
34755
|
if (!this.#prompted && this.#nativeHistoryOwnership.kind === "fresh-session") {
|
|
34602
34756
|
if (this.#sessionLoad.kind === "not-requested") {
|
|
34603
|
-
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
|
+
};
|
|
34604
34763
|
}
|
|
34605
34764
|
if (this.#sessionLoad.kind === "loaded") {
|
|
34606
34765
|
return this.#sessionLoad.history;
|
|
@@ -34615,7 +34774,8 @@ var AgentSession = class _AgentSession {
|
|
|
34615
34774
|
if (this.#sessionLoad.kind === "capturing") {
|
|
34616
34775
|
return await waitForSharedOperation(this.#sessionLoad.completion, signal);
|
|
34617
34776
|
}
|
|
34618
|
-
|
|
34777
|
+
this.#store.eventsV2.reset(this.#mobiusSessionId);
|
|
34778
|
+
const history = new AcpHistoryReplay(this.#store.eventsV2, this.#mobiusSessionId);
|
|
34619
34779
|
const completion = Promise.resolve().then(async () => {
|
|
34620
34780
|
try {
|
|
34621
34781
|
const response = await this.race(
|
|
@@ -35090,7 +35250,7 @@ var AgentSession = class _AgentSession {
|
|
|
35090
35250
|
this.prepareAgentContent
|
|
35091
35251
|
);
|
|
35092
35252
|
this.#turn = running;
|
|
35093
|
-
this.#turnHistory = completedHistory === null ? null : new AcpHistoryReplay();
|
|
35253
|
+
this.#turnHistory = completedHistory === null ? null : new AcpHistoryReplay(this.#store.eventsV2, this.#mobiusSessionId);
|
|
35094
35254
|
const lifecycleV2 = options.lifecycleV2;
|
|
35095
35255
|
if (lifecycleV2 !== void 0) {
|
|
35096
35256
|
await this.#recordLifecycleEventV2({
|
|
@@ -35303,7 +35463,7 @@ var AgentSession = class _AgentSession {
|
|
|
35303
35463
|
if (event.type !== "lifecycle-metadata" || this.#sessionLoad.kind !== "loaded") {
|
|
35304
35464
|
return;
|
|
35305
35465
|
}
|
|
35306
|
-
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);
|
|
35307
35467
|
await this.#getObserver().onSessionEventV2?.(this.#mobiusSessionId, event, position);
|
|
35308
35468
|
};
|
|
35309
35469
|
selectNativeSession = (sessionId) => {
|
|
@@ -35324,13 +35484,8 @@ var AgentSession = class _AgentSession {
|
|
|
35324
35484
|
} else {
|
|
35325
35485
|
const onSessionEventV2 = this.#getObserver().onSessionEventV2;
|
|
35326
35486
|
if (this.#turnHistory !== null) {
|
|
35327
|
-
|
|
35328
|
-
|
|
35329
|
-
await onSessionEventV2?.(
|
|
35330
|
-
this.#mobiusSessionId,
|
|
35331
|
-
{ payload: rawUpdate, type: "acp" },
|
|
35332
|
-
completedEventCount + turnPosition
|
|
35333
|
-
);
|
|
35487
|
+
await this.#turnHistory.record(update, rawUpdate, async (position) => {
|
|
35488
|
+
await onSessionEventV2?.(this.#mobiusSessionId, { payload: rawUpdate, type: "acp" }, position);
|
|
35334
35489
|
});
|
|
35335
35490
|
} else if (this.#sessionLoad.kind === "loaded") {
|
|
35336
35491
|
await this.#sessionLoad.history.record(update, rawUpdate, async (position) => {
|
|
@@ -35973,9 +36128,9 @@ var AcpContentExternalizer = class {
|
|
|
35973
36128
|
};
|
|
35974
36129
|
|
|
35975
36130
|
// src/external-content/local-external-content-store.ts
|
|
35976
|
-
import { createHash as createHash2, randomUUID } from "node:crypto";
|
|
36131
|
+
import { createHash as createHash2, randomUUID as randomUUID2 } from "node:crypto";
|
|
35977
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";
|
|
35978
|
-
import { dirname as
|
|
36133
|
+
import { dirname as dirname3, join as join15 } from "node:path";
|
|
35979
36134
|
var contentRequest = /^mobius-content:(image|audio|resource):([a-f0-9]{64})$/u;
|
|
35980
36135
|
var CONTENT_LIFETIME_MILLISECONDS = 24 * 60 * 60 * 1e3;
|
|
35981
36136
|
var metadataSchema2 = external_exports.strictObject({
|
|
@@ -35994,7 +36149,7 @@ var UnretainedExternalContentStore = class {
|
|
|
35994
36149
|
};
|
|
35995
36150
|
};
|
|
35996
36151
|
async function atomicWrite(path2, bytes, signal) {
|
|
35997
|
-
const temporary = `${path2}.${
|
|
36152
|
+
const temporary = `${path2}.${randomUUID2()}.tmp`;
|
|
35998
36153
|
try {
|
|
35999
36154
|
await writeFile3(temporary, bytes, { mode: 384, signal });
|
|
36000
36155
|
signal.throwIfAborted();
|
|
@@ -36011,7 +36166,7 @@ var LocalExternalContentStore = class {
|
|
|
36011
36166
|
#expirationTimer;
|
|
36012
36167
|
#cleanup = Promise.resolve();
|
|
36013
36168
|
constructor(stateDirectory) {
|
|
36014
|
-
this.#root = join15(stateDirectory, "tmp", "session-content",
|
|
36169
|
+
this.#root = join15(stateDirectory, "tmp", "session-content", randomUUID2());
|
|
36015
36170
|
this.#expirationTimer = setInterval(() => {
|
|
36016
36171
|
void this.#expire().catch(() => void 0);
|
|
36017
36172
|
}, 6e4);
|
|
@@ -36022,11 +36177,11 @@ var LocalExternalContentStore = class {
|
|
|
36022
36177
|
await mkdir4(this.#root, { mode: 448, recursive: true });
|
|
36023
36178
|
const now = /* @__PURE__ */ new Date();
|
|
36024
36179
|
await utimes(this.#root, now, now);
|
|
36025
|
-
for (const directory of await readdir2(
|
|
36180
|
+
for (const directory of await readdir2(dirname3(this.#root), { withFileTypes: true })) {
|
|
36026
36181
|
if (!directory.isDirectory() || !/^[a-f0-9-]{36}$/u.test(directory.name)) {
|
|
36027
36182
|
continue;
|
|
36028
36183
|
}
|
|
36029
|
-
const path2 = join15(
|
|
36184
|
+
const path2 = join15(dirname3(this.#root), directory.name);
|
|
36030
36185
|
if (path2 === this.#root) {
|
|
36031
36186
|
continue;
|
|
36032
36187
|
}
|
|
@@ -36112,12 +36267,12 @@ var LocalExternalContentStore = class {
|
|
|
36112
36267
|
}
|
|
36113
36268
|
try {
|
|
36114
36269
|
const [resolvedDirectory, resolvedPath, file2] = await Promise.all([
|
|
36115
|
-
realpath7(
|
|
36270
|
+
realpath7(dirname3(entry.path)),
|
|
36116
36271
|
realpath7(entry.path),
|
|
36117
36272
|
lstat(entry.path)
|
|
36118
36273
|
]);
|
|
36119
36274
|
signal.throwIfAborted();
|
|
36120
|
-
if (!file2.isFile() || file2.isSymbolicLink() ||
|
|
36275
|
+
if (!file2.isFile() || file2.isSymbolicLink() || dirname3(resolvedPath) !== resolvedDirectory) {
|
|
36121
36276
|
return null;
|
|
36122
36277
|
}
|
|
36123
36278
|
return { mediaType: entry.mediaType, name: entry.name, path: resolvedPath };
|
|
@@ -36194,9 +36349,9 @@ var AcpProcessCapacityLock = class {
|
|
|
36194
36349
|
return await waiter.completion.promise;
|
|
36195
36350
|
} finally {
|
|
36196
36351
|
signal.removeEventListener("abort", waiter.cancel);
|
|
36197
|
-
const
|
|
36198
|
-
if (
|
|
36199
|
-
this.#waiters.splice(
|
|
36352
|
+
const index2 = this.#waiters.indexOf(waiter);
|
|
36353
|
+
if (index2 >= 0) {
|
|
36354
|
+
this.#waiters.splice(index2, 1);
|
|
36200
36355
|
}
|
|
36201
36356
|
}
|
|
36202
36357
|
};
|
|
@@ -37556,7 +37711,7 @@ var FixedInstallationExecutor = class {
|
|
|
37556
37711
|
// src/authorization/workspace-directory.ts
|
|
37557
37712
|
import { readdir as readdir3, realpath as realpath8, stat as stat7 } from "node:fs/promises";
|
|
37558
37713
|
import { homedir as homedir2 } from "node:os";
|
|
37559
|
-
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";
|
|
37560
37715
|
|
|
37561
37716
|
// src/authorization/local-authorization-error.ts
|
|
37562
37717
|
var LocalAuthorizationError = class extends Error {
|
|
@@ -37695,7 +37850,7 @@ var WorkspaceDirectoryService = class {
|
|
|
37695
37850
|
}
|
|
37696
37851
|
}
|
|
37697
37852
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
37698
|
-
const parent =
|
|
37853
|
+
const parent = dirname4(target);
|
|
37699
37854
|
return new WorkspaceDirectoryListing(
|
|
37700
37855
|
id,
|
|
37701
37856
|
this.label(target),
|
|
@@ -37720,7 +37875,7 @@ var WorkspaceDirectoryService = class {
|
|
|
37720
37875
|
};
|
|
37721
37876
|
|
|
37722
37877
|
// src/daemon-diagnostic-log.ts
|
|
37723
|
-
import { appendFileSync, mkdirSync
|
|
37878
|
+
import { appendFileSync, mkdirSync, readFileSync as readFileSync2, renameSync, statSync as statSync3, writeFileSync } from "node:fs";
|
|
37724
37879
|
import { join as join17 } from "node:path";
|
|
37725
37880
|
var MAXIMUM_DAEMON_LOG_BYTES = 1 * 1024 * 1024;
|
|
37726
37881
|
var DaemonDiagnosticLog = class {
|
|
@@ -37736,7 +37891,7 @@ var DaemonDiagnosticLog = class {
|
|
|
37736
37891
|
const encoded = `${diagnostic.replace(/[\r\n]+/gu, " ").trim()}
|
|
37737
37892
|
`;
|
|
37738
37893
|
const encodedBytes = Buffer.byteLength(encoded);
|
|
37739
|
-
|
|
37894
|
+
mkdirSync(this.#directory, { mode: 448, recursive: true });
|
|
37740
37895
|
let existingBytes = 0;
|
|
37741
37896
|
try {
|
|
37742
37897
|
existingBytes = statSync3(this.#path).size;
|
|
@@ -38201,7 +38356,7 @@ var DaemonInstallationObserver = class {
|
|
|
38201
38356
|
};
|
|
38202
38357
|
|
|
38203
38358
|
// src/daemon-active-turn.ts
|
|
38204
|
-
import { randomUUID as
|
|
38359
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
38205
38360
|
function activeMessageCharacters(message) {
|
|
38206
38361
|
return message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0);
|
|
38207
38362
|
}
|
|
@@ -38209,8 +38364,8 @@ var ACTIVE_TURN_TEXT_CHUNK_LIMIT = Math.floor(SESSION_HISTORY_CHARACTER_LIMIT /
|
|
|
38209
38364
|
function boundedRecoveryMessages(messages) {
|
|
38210
38365
|
const selected = [];
|
|
38211
38366
|
let remainingCharacters = SESSION_HISTORY_CHARACTER_LIMIT;
|
|
38212
|
-
for (let
|
|
38213
|
-
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];
|
|
38214
38369
|
if (message === void 0) {
|
|
38215
38370
|
break;
|
|
38216
38371
|
}
|
|
@@ -38235,7 +38390,7 @@ var ActiveDaemonTurn = class {
|
|
|
38235
38390
|
#timeline;
|
|
38236
38391
|
#sequence = 0;
|
|
38237
38392
|
#interaction = null;
|
|
38238
|
-
#epoch = decodeIdentifier(
|
|
38393
|
+
#epoch = decodeIdentifier(randomUUID3());
|
|
38239
38394
|
constructor(command, attemptId) {
|
|
38240
38395
|
this.attemptId = attemptId;
|
|
38241
38396
|
this.command = command;
|
|
@@ -38297,7 +38452,7 @@ var ActiveDaemonTurn = class {
|
|
|
38297
38452
|
if (!this.#activities.has(event.activityId)) {
|
|
38298
38453
|
this.#timeline = [
|
|
38299
38454
|
...this.#timeline,
|
|
38300
|
-
{ activityId: event.activityId, id: decodeIdentifier(
|
|
38455
|
+
{ activityId: event.activityId, id: decodeIdentifier(randomUUID3()), kind: "activity" }
|
|
38301
38456
|
];
|
|
38302
38457
|
}
|
|
38303
38458
|
this.#activities.set(event.activityId, {
|
|
@@ -38318,7 +38473,7 @@ var ActiveDaemonTurn = class {
|
|
|
38318
38473
|
if (previous === void 0) {
|
|
38319
38474
|
this.#timeline = [
|
|
38320
38475
|
...this.#timeline,
|
|
38321
|
-
{ activityId: event.activityId, id: decodeIdentifier(
|
|
38476
|
+
{ activityId: event.activityId, id: decodeIdentifier(randomUUID3()), kind: "activity" }
|
|
38322
38477
|
];
|
|
38323
38478
|
}
|
|
38324
38479
|
this.#activities.set(event.activityId, {
|
|
@@ -38343,7 +38498,7 @@ var ActiveDaemonTurn = class {
|
|
|
38343
38498
|
...this.#timeline,
|
|
38344
38499
|
{
|
|
38345
38500
|
content: /* @__PURE__ */ new Map([[event.contentId, event.content]]),
|
|
38346
|
-
id: decodeIdentifier(
|
|
38501
|
+
id: decodeIdentifier(randomUUID3()),
|
|
38347
38502
|
kind: "message",
|
|
38348
38503
|
sourceMessageId: event.messageId,
|
|
38349
38504
|
text: ""
|
|
@@ -38351,7 +38506,7 @@ var ActiveDaemonTurn = class {
|
|
|
38351
38506
|
];
|
|
38352
38507
|
} else {
|
|
38353
38508
|
this.#timeline = this.#timeline.map(
|
|
38354
|
-
(entry,
|
|
38509
|
+
(entry, index2) => index2 === target && entry.kind === "message" ? { ...entry, content: new Map([...entry.content, [event.contentId, event.content]]) } : entry
|
|
38355
38510
|
);
|
|
38356
38511
|
}
|
|
38357
38512
|
} else if (event.kind === SESSION_PERMISSION_REQUESTED_KIND || event.kind === SESSION_ELICITATION_REQUESTED_KIND) {
|
|
@@ -38383,7 +38538,7 @@ var ActiveDaemonTurn = class {
|
|
|
38383
38538
|
...this.#timeline,
|
|
38384
38539
|
{
|
|
38385
38540
|
content: /* @__PURE__ */ new Map(),
|
|
38386
|
-
id: decodeIdentifier(
|
|
38541
|
+
id: decodeIdentifier(randomUUID3()),
|
|
38387
38542
|
kind: "message",
|
|
38388
38543
|
sourceMessageId: messageId,
|
|
38389
38544
|
text: remaining.slice(0, ACTIVE_TURN_TEXT_CHUNK_LIMIT)
|
|
@@ -38654,6 +38809,202 @@ var DaemonTurnRegistry = class {
|
|
|
38654
38809
|
};
|
|
38655
38810
|
};
|
|
38656
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
|
+
|
|
38657
39008
|
// src/native-sessions/codex-history.ts
|
|
38658
39009
|
import { spawn as spawn5 } from "node:child_process";
|
|
38659
39010
|
var responseSchema = external_exports.union([
|
|
@@ -39358,7 +39709,7 @@ var readCodexFullHistory = async (agent, cwd, nativeSessionId, signal, nativeTur
|
|
|
39358
39709
|
});
|
|
39359
39710
|
|
|
39360
39711
|
// src/native-sessions/service.ts
|
|
39361
|
-
import { randomUUID as
|
|
39712
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
39362
39713
|
var NativeSessionService = class {
|
|
39363
39714
|
#entries = /* @__PURE__ */ new Map();
|
|
39364
39715
|
#cursors = /* @__PURE__ */ new Map();
|
|
@@ -39417,7 +39768,7 @@ var NativeSessionService = class {
|
|
|
39417
39768
|
if (authorized === null) {
|
|
39418
39769
|
return null;
|
|
39419
39770
|
}
|
|
39420
|
-
const entryId = decodeIdentifier(
|
|
39771
|
+
const entryId = decodeIdentifier(randomUUID4());
|
|
39421
39772
|
if (this.#entries.size >= 5e3) {
|
|
39422
39773
|
this.#entries.clear();
|
|
39423
39774
|
}
|
|
@@ -39473,7 +39824,7 @@ var NativeSessionService = class {
|
|
|
39473
39824
|
"invalid_native_session_response"
|
|
39474
39825
|
);
|
|
39475
39826
|
}
|
|
39476
|
-
nextCursor = decodeIdentifier(
|
|
39827
|
+
nextCursor = decodeIdentifier(randomUUID4());
|
|
39477
39828
|
if (this.#cursors.size >= 500) {
|
|
39478
39829
|
this.#cursors.clear();
|
|
39479
39830
|
}
|
|
@@ -39651,7 +40002,7 @@ var NativeSessionService = class {
|
|
|
39651
40002
|
resolveTarget = async (command, options, selected) => {
|
|
39652
40003
|
let cursor = null;
|
|
39653
40004
|
const visited = /* @__PURE__ */ new Set();
|
|
39654
|
-
for (let
|
|
40005
|
+
for (let index2 = 0; index2 < 100; index2 += 1) {
|
|
39655
40006
|
const page = await this.#sessions.listNativeSessions(options, cursor);
|
|
39656
40007
|
const info = page.sessions.find((entry) => entry.sessionId === selected.nativeSessionId);
|
|
39657
40008
|
if (info !== void 0) {
|
|
@@ -39659,7 +40010,7 @@ var NativeSessionService = class {
|
|
|
39659
40010
|
if (target === null) {
|
|
39660
40011
|
throw new LocalAuthorizationError("The selected native session is not authorized");
|
|
39661
40012
|
}
|
|
39662
|
-
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])) {
|
|
39663
40014
|
throw new AcpExecutionError(
|
|
39664
40015
|
"This session's directory changed. Refresh the list before continuing.",
|
|
39665
40016
|
{},
|
|
@@ -39698,7 +40049,7 @@ var NativeSessionService = class {
|
|
|
39698
40049
|
};
|
|
39699
40050
|
|
|
39700
40051
|
// src/relay-connection/daemon-operation-state.ts
|
|
39701
|
-
import { createHash as createHash4, randomUUID as
|
|
40052
|
+
import { createHash as createHash4, randomUUID as randomUUID5 } from "node:crypto";
|
|
39702
40053
|
var MAX_TERMINAL_RECEIPTS = 1024;
|
|
39703
40054
|
function isTerminal(state) {
|
|
39704
40055
|
return state === "succeeded" || state === "failed" || state === "cancelled";
|
|
@@ -39715,7 +40066,7 @@ var DaemonOperationState = class {
|
|
|
39715
40066
|
}
|
|
39716
40067
|
return { attemptId: existing.attemptId, commandId, kind: "duplicate", state: existing.state };
|
|
39717
40068
|
}
|
|
39718
|
-
const attemptId =
|
|
40069
|
+
const attemptId = randomUUID5();
|
|
39719
40070
|
this.#executions.set(commandId, { attemptId, commandHash, sessionId, state: "dispatching" });
|
|
39720
40071
|
return { attemptId, commandId, kind: "accepted", state: "dispatching" };
|
|
39721
40072
|
};
|
|
@@ -40679,7 +41030,7 @@ async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, dir
|
|
|
40679
41030
|
const replay = await sessions.loadSessionEventsV2(loadOptions, command.eventLimit, command.cursor);
|
|
40680
41031
|
signal.throwIfAborted();
|
|
40681
41032
|
const events = replay.events.map(
|
|
40682
|
-
(event,
|
|
41033
|
+
(event, index2) => eventLogV2.event(command.sessionId, replay.startPosition + index2, event, "1970-01-01T00:00:00.000Z")
|
|
40683
41034
|
);
|
|
40684
41035
|
const tailCursor = events.at(-1)?.eventId ?? "";
|
|
40685
41036
|
audit.record({
|
|
@@ -40730,7 +41081,7 @@ async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, dir
|
|
|
40730
41081
|
}
|
|
40731
41082
|
|
|
40732
41083
|
// src/acp/session-config/apply-session-configuration.ts
|
|
40733
|
-
import { randomUUID as
|
|
41084
|
+
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
40734
41085
|
function invalidSessionConfiguration(message) {
|
|
40735
41086
|
return new AcpExecutionError(message, {}, "invalid_session_configuration");
|
|
40736
41087
|
}
|
|
@@ -40871,7 +41222,7 @@ async function applySessionConfigurationSelection(sessions, audit, options, sele
|
|
|
40871
41222
|
booleanValue: selection.booleanValue,
|
|
40872
41223
|
configId: selection.configId,
|
|
40873
41224
|
cwd,
|
|
40874
|
-
requestId: `cfg_${
|
|
41225
|
+
requestId: `cfg_${randomUUID6()}`,
|
|
40875
41226
|
sessionId,
|
|
40876
41227
|
signal,
|
|
40877
41228
|
value: selection.value,
|
|
@@ -41941,7 +42292,7 @@ function connectRelay(url2, signal) {
|
|
|
41941
42292
|
}
|
|
41942
42293
|
|
|
41943
42294
|
// src/relay-connection/liveness.ts
|
|
41944
|
-
import { randomUUID as
|
|
42295
|
+
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
41945
42296
|
var HEARTBEAT_ACK_TIMEOUT_MILLISECONDS = 1e4;
|
|
41946
42297
|
var HEARTBEAT_INTERVAL_MILLISECONDS = 2e4;
|
|
41947
42298
|
var RelayLivenessState = class {
|
|
@@ -42030,7 +42381,7 @@ var RelayConnectionLiveness = class {
|
|
|
42030
42381
|
}
|
|
42031
42382
|
throw new Error("Heartbeat was scheduled in an invalid state");
|
|
42032
42383
|
}
|
|
42033
|
-
const heartbeatId =
|
|
42384
|
+
const heartbeatId = randomUUID7();
|
|
42034
42385
|
this.#state = new AwaitingHeartbeatAckState(
|
|
42035
42386
|
heartbeatId,
|
|
42036
42387
|
this.#timer.schedule(this.#handleTimeout, HEARTBEAT_ACK_TIMEOUT_MILLISECONDS)
|
|
@@ -42322,7 +42673,7 @@ var SystemDaemonTimer = class {
|
|
|
42322
42673
|
var systemDaemonTimer = new SystemDaemonTimer();
|
|
42323
42674
|
|
|
42324
42675
|
// src/session-event-log-v2.ts
|
|
42325
|
-
import { createHash as createHash6, randomUUID as
|
|
42676
|
+
import { createHash as createHash6, randomUUID as randomUUID8 } from "node:crypto";
|
|
42326
42677
|
function promptContent(command) {
|
|
42327
42678
|
const content = [];
|
|
42328
42679
|
if (command.prompt.length > 0) {
|
|
@@ -42346,7 +42697,7 @@ function promptContent(command) {
|
|
|
42346
42697
|
}
|
|
42347
42698
|
return content;
|
|
42348
42699
|
}
|
|
42349
|
-
function
|
|
42700
|
+
function sessionEventV22(daemonGenerationId, sessionId, position, event, recordedAt) {
|
|
42350
42701
|
const sessionPrefix = createHash6("sha256").update(sessionId).digest("hex").slice(0, 16);
|
|
42351
42702
|
return {
|
|
42352
42703
|
eventId: `event-${daemonGenerationId}-${sessionPrefix}-${position.toString().padStart(16, "0")}`,
|
|
@@ -42358,11 +42709,12 @@ function sessionEventV2(daemonGenerationId, sessionId, position, event, recorded
|
|
|
42358
42709
|
};
|
|
42359
42710
|
}
|
|
42360
42711
|
var DaemonSessionEventLogV2 = class {
|
|
42361
|
-
daemonGenerationId
|
|
42712
|
+
daemonGenerationId;
|
|
42362
42713
|
#publisher;
|
|
42363
42714
|
#queued = /* @__PURE__ */ new Map();
|
|
42364
|
-
constructor(publisher) {
|
|
42715
|
+
constructor(publisher, daemonGenerationId = randomUUID8()) {
|
|
42365
42716
|
this.#publisher = publisher;
|
|
42717
|
+
this.daemonGenerationId = daemonGenerationId;
|
|
42366
42718
|
}
|
|
42367
42719
|
requested = (command) => {
|
|
42368
42720
|
this.#queued.set(command.commandId, {
|
|
@@ -42382,7 +42734,7 @@ var DaemonSessionEventLogV2 = class {
|
|
|
42382
42734
|
record = (sessionId, event, position) => {
|
|
42383
42735
|
this.#publisher.publishV2(this.event(sessionId, position, event, (/* @__PURE__ */ new Date()).toISOString()));
|
|
42384
42736
|
};
|
|
42385
|
-
event = (sessionId, position, event, recordedAt) =>
|
|
42737
|
+
event = (sessionId, position, event, recordedAt) => sessionEventV22(this.daemonGenerationId, sessionId, position, event, recordedAt);
|
|
42386
42738
|
queueChanged = (_sessionId) => void 0;
|
|
42387
42739
|
completed = (sessionId, commandId, _stopReason) => {
|
|
42388
42740
|
const request = this.#queued.get(commandId);
|
|
@@ -42449,7 +42801,7 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
|
|
|
42449
42801
|
{
|
|
42450
42802
|
agentId: agent.id,
|
|
42451
42803
|
kind: AGENT_INSTALL_REQUEST_KIND,
|
|
42452
|
-
requestId: `automatic-integration-${
|
|
42804
|
+
requestId: `automatic-integration-${randomUUID9()}`
|
|
42453
42805
|
},
|
|
42454
42806
|
signal
|
|
42455
42807
|
);
|
|
@@ -42467,13 +42819,24 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
42467
42819
|
publishCatalog: async (installationSignal) => await publishAgentCatalog(config2, installationSignal),
|
|
42468
42820
|
stateDirectory
|
|
42469
42821
|
});
|
|
42470
|
-
const
|
|
42471
|
-
|
|
42472
|
-
);
|
|
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);
|
|
42473
42836
|
await using externalContent = new LocalExternalContentStore(stateDirectory);
|
|
42474
42837
|
const operations = new DaemonOperationState();
|
|
42475
42838
|
const publisher = new DaemonSessionEventPublisher();
|
|
42476
|
-
const eventLogV2 = new DaemonSessionEventLogV2(publisher);
|
|
42839
|
+
const eventLogV2 = new DaemonSessionEventLogV2(publisher, daemonGenerationId);
|
|
42477
42840
|
const activeTurns = new DaemonTurnRegistry(operations);
|
|
42478
42841
|
const recordSessionEvent = (sessionId, event) => {
|
|
42479
42842
|
publisher.publish(sessionId, activeTurns.recordEvent(event));
|
|
@@ -42519,7 +42882,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
42519
42882
|
options2.signal
|
|
42520
42883
|
);
|
|
42521
42884
|
return cwd === options2.cwd && additionalDirectories.length === options2.additionalDirectories.length && additionalDirectories.every(
|
|
42522
|
-
(directory,
|
|
42885
|
+
(directory, index2) => directory === options2.additionalDirectories[index2]
|
|
42523
42886
|
);
|
|
42524
42887
|
});
|
|
42525
42888
|
}
|
|
@@ -42664,7 +43027,7 @@ import { basename as basename6, resolve as resolve7 } from "node:path";
|
|
|
42664
43027
|
import { fetch as fetch4 } from "undici";
|
|
42665
43028
|
|
|
42666
43029
|
// src/storage/runtime-installation-store.ts
|
|
42667
|
-
import { createHash as createHash8, randomUUID as
|
|
43030
|
+
import { createHash as createHash8, randomUUID as randomUUID10 } from "node:crypto";
|
|
42668
43031
|
import { mkdir as mkdir5, open as open5, readdir as readdir4, rename as rename4, unlink, writeFile as writeFile4 } from "node:fs/promises";
|
|
42669
43032
|
import { dirname as dirname6, join as join19, resolve as resolve6 } from "node:path";
|
|
42670
43033
|
var APPLICATION_ID_PATTERN = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+){1,31}$/;
|
|
@@ -42794,10 +43157,10 @@ function parseRelayOrigin(value) {
|
|
|
42794
43157
|
return origin;
|
|
42795
43158
|
}
|
|
42796
43159
|
function connectionId() {
|
|
42797
|
-
return `mcn_${
|
|
43160
|
+
return `mcn_${randomUUID10().replaceAll("-", "")}`;
|
|
42798
43161
|
}
|
|
42799
43162
|
function installationId() {
|
|
42800
|
-
return `min_${
|
|
43163
|
+
return `min_${randomUUID10().replaceAll("-", "")}`;
|
|
42801
43164
|
}
|
|
42802
43165
|
function channelIndexFileName(channelId) {
|
|
42803
43166
|
return `mci_${createHash8("sha256").update(channelId).digest("hex")}.json`;
|
|
@@ -42909,7 +43272,7 @@ async function readJsonFile(path2, signal, missingCode) {
|
|
|
42909
43272
|
async function writeJsonAtomically(path2, value, signal) {
|
|
42910
43273
|
signal.throwIfAborted();
|
|
42911
43274
|
const directory = dirname6(path2);
|
|
42912
|
-
const temporaryPath = join19(directory, `.${
|
|
43275
|
+
const temporaryPath = join19(directory, `.${randomUUID10()}.tmp`);
|
|
42913
43276
|
try {
|
|
42914
43277
|
await mkdir5(directory, { mode: 448, recursive: true });
|
|
42915
43278
|
signal.throwIfAborted();
|
|
@@ -42986,16 +43349,16 @@ var RuntimeInstallationStore = class _RuntimeInstallationStore {
|
|
|
42986
43349
|
};
|
|
42987
43350
|
#readConnectionForChannel = async (channelId, signal) => {
|
|
42988
43351
|
const normalizedChannelId = validateIdentifier(channelId, "invalid_channel_id");
|
|
42989
|
-
const
|
|
43352
|
+
const index2 = decodeChannelIndex(
|
|
42990
43353
|
await readJsonFile(this.channelIndexPath(normalizedChannelId), signal, "connection_not_found")
|
|
42991
43354
|
);
|
|
42992
|
-
if (
|
|
43355
|
+
if (index2.applicationId !== this.applicationId || index2.installationId !== this.installationId || index2.channelId !== normalizedChannelId) {
|
|
42993
43356
|
throw new RuntimeInstallationStoreError(
|
|
42994
43357
|
"connection_owner_mismatch",
|
|
42995
43358
|
"The saved Runtime connection belongs to another installation"
|
|
42996
43359
|
);
|
|
42997
43360
|
}
|
|
42998
|
-
return await this.readConnection(
|
|
43361
|
+
return await this.readConnection(index2.connectionId, signal);
|
|
42999
43362
|
};
|
|
43000
43363
|
saveConnection = async (input2, signal) => {
|
|
43001
43364
|
const stored = new VerifiedRuntimeConnection(
|