@moxt-ai/mobius 0.0.174 → 0.0.176
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/acp/agent-runtime-manager.d.ts +0 -1
- package/dist/acp/agent-runtime-manager.d.ts.map +1 -1
- package/dist/acp/agent-runtime-manager.js +2 -37
- package/dist/acp/agent-runtime-manager.js.map +1 -1
- package/dist/acp/agent-session.d.ts +0 -1
- package/dist/acp/agent-session.d.ts.map +1 -1
- package/dist/acp/agent-session.js +19 -25
- package/dist/acp/agent-session.js.map +1 -1
- package/dist/acp/session-event-store-v2.d.ts +37 -0
- package/dist/acp/session-event-store-v2.d.ts.map +1 -0
- package/dist/acp/session-event-store-v2.js +199 -0
- package/dist/acp/session-event-store-v2.js.map +1 -0
- package/dist/acp/session-history.d.ts +3 -2
- package/dist/acp/session-history.d.ts.map +1 -1
- package/dist/acp/session-history.js +37 -41
- package/dist/acp/session-history.js.map +1 -1
- package/dist/acp/session-store.d.ts +8 -9
- package/dist/acp/session-store.d.ts.map +1 -1
- package/dist/acp/session-store.js +27 -109
- package/dist/acp/session-store.js.map +1 -1
- package/dist/cli.js +985 -867
- package/dist/cli.js.map +4 -4
- package/dist/daemon-command-handler.d.ts.map +1 -1
- package/dist/daemon-command-handler.js +0 -1
- package/dist/daemon-command-handler.js.map +1 -1
- package/dist/daemon-turn-registry.d.ts +13 -13
- package/dist/generated/acp-session-store-migrations.d.ts +3 -0
- package/dist/generated/acp-session-store-migrations.d.ts.map +1 -1
- package/dist/generated/acp-session-store-migrations.js +5 -1
- package/dist/generated/acp-session-store-migrations.js.map +1 -1
- package/dist/generated/session-event-cache-migrations.d.ts +5 -0
- package/dist/generated/session-event-cache-migrations.d.ts.map +1 -0
- package/dist/generated/session-event-cache-migrations.js +9 -0
- package/dist/generated/session-event-cache-migrations.js.map +1 -0
- package/dist/index.js +979 -862
- package/dist/index.js.map +4 -4
- package/dist/infra/local-sqlite-database.d.ts +13 -0
- package/dist/infra/local-sqlite-database.d.ts.map +1 -0
- package/dist/infra/local-sqlite-database.js +57 -0
- package/dist/infra/local-sqlite-database.js.map +1 -0
- package/dist/local-databases.d.ts +4 -0
- package/dist/local-databases.d.ts.map +1 -0
- package/dist/local-databases.js +9 -0
- package/dist/local-databases.js.map +1 -0
- package/dist/native-sessions/handle-native-requests.d.ts +0 -2
- package/dist/native-sessions/handle-native-requests.d.ts.map +1 -1
- package/dist/native-sessions/handle-native-requests.js +1 -12
- package/dist/native-sessions/handle-native-requests.js.map +1 -1
- package/dist/native-sessions/service.d.ts.map +1 -1
- package/dist/native-sessions/service.js +0 -62
- package/dist/native-sessions/service.js.map +1 -1
- package/dist/run-daemon.d.ts.map +1 -1
- package/dist/run-daemon.js +15 -2
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.js +969 -852
- package/dist/runtime.js.map +4 -4
- package/dist/schema/acp-session-store/acp-session.d.ts +0 -16
- package/dist/schema/acp-session-store/acp-session.d.ts.map +1 -1
- package/dist/schema/acp-session-store/acp-session.js +0 -1
- package/dist/schema/acp-session-store/acp-session.js.map +1 -1
- package/dist/schema/acp-session-store/index.d.ts +0 -1
- package/dist/schema/acp-session-store/index.d.ts.map +1 -1
- package/dist/schema/acp-session-store/index.js +0 -1
- package/dist/schema/acp-session-store/index.js.map +1 -1
- package/dist/schema/session-event-cache/index.d.ts +2 -0
- package/dist/schema/session-event-cache/index.d.ts.map +1 -0
- package/dist/schema/session-event-cache/index.js +2 -0
- package/dist/schema/session-event-cache/index.js.map +1 -0
- package/dist/schema/session-event-cache/session-event-v2.d.ts +72 -0
- package/dist/schema/session-event-cache/session-event-v2.d.ts.map +1 -0
- package/dist/schema/session-event-cache/session-event-v2.js +11 -0
- package/dist/schema/session-event-cache/session-event-v2.js.map +1 -0
- package/dist/session-event-log-v2.d.ts +2 -2
- package/dist/session-event-log-v2.d.ts.map +1 -1
- package/dist/session-event-log-v2.js +3 -2
- package/dist/session-event-log-v2.js.map +1 -1
- package/package.json +2 -1
- package/dist/schema/acp-session-store/deleted-acp-session.d.ts +0 -24
- package/dist/schema/acp-session-store/deleted-acp-session.d.ts.map +0 -1
- package/dist/schema/acp-session-store/deleted-acp-session.js +0 -5
- package/dist/schema/acp-session-store/deleted-acp-session.js.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -2340,11 +2340,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2340
2340
|
};
|
|
2341
2341
|
this._checkNumberOfArguments();
|
|
2342
2342
|
const processedArgs = [];
|
|
2343
|
-
this.registeredArguments.forEach((declaredArg,
|
|
2343
|
+
this.registeredArguments.forEach((declaredArg, index2) => {
|
|
2344
2344
|
let value = declaredArg.defaultValue;
|
|
2345
2345
|
if (declaredArg.variadic) {
|
|
2346
|
-
if (
|
|
2347
|
-
value = this.args.slice(
|
|
2346
|
+
if (index2 < this.args.length) {
|
|
2347
|
+
value = this.args.slice(index2);
|
|
2348
2348
|
if (declaredArg.parseArg) {
|
|
2349
2349
|
value = value.reduce((processed, v) => {
|
|
2350
2350
|
return myParseArg(declaredArg, v, processed);
|
|
@@ -2353,13 +2353,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2353
2353
|
} else if (value === void 0) {
|
|
2354
2354
|
value = [];
|
|
2355
2355
|
}
|
|
2356
|
-
} else if (
|
|
2357
|
-
value = this.args[
|
|
2356
|
+
} else if (index2 < this.args.length) {
|
|
2357
|
+
value = this.args[index2];
|
|
2358
2358
|
if (declaredArg.parseArg) {
|
|
2359
2359
|
value = myParseArg(declaredArg, value, declaredArg.defaultValue);
|
|
2360
2360
|
}
|
|
2361
2361
|
}
|
|
2362
|
-
processedArgs[
|
|
2362
|
+
processedArgs[index2] = value;
|
|
2363
2363
|
});
|
|
2364
2364
|
this.processedArgs = processedArgs;
|
|
2365
2365
|
}
|
|
@@ -2653,10 +2653,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2653
2653
|
}
|
|
2654
2654
|
}
|
|
2655
2655
|
if (/^--[^=]+=/.test(arg)) {
|
|
2656
|
-
const
|
|
2657
|
-
const option = this._findOption(arg.slice(0,
|
|
2656
|
+
const index2 = arg.indexOf("=");
|
|
2657
|
+
const option = this._findOption(arg.slice(0, index2));
|
|
2658
2658
|
if (option && (option.required || option.optional)) {
|
|
2659
|
-
this.emit(`option:${option.name()}`, arg.slice(
|
|
2659
|
+
this.emit(`option:${option.name()}`, arg.slice(index2 + 1));
|
|
2660
2660
|
continue;
|
|
2661
2661
|
}
|
|
2662
2662
|
}
|
|
@@ -3381,7 +3381,7 @@ var program = new Command();
|
|
|
3381
3381
|
// package.json
|
|
3382
3382
|
var package_default = {
|
|
3383
3383
|
name: "@moxt-ai/mobius",
|
|
3384
|
-
version: "0.0.
|
|
3384
|
+
version: "0.0.176",
|
|
3385
3385
|
description: "Mobius CLI for pairing and running local AI agent services.",
|
|
3386
3386
|
type: "module",
|
|
3387
3387
|
bin: {
|
|
@@ -3435,6 +3435,7 @@ var package_default = {
|
|
|
3435
3435
|
devDependencies: {
|
|
3436
3436
|
"@moxt-ai/mobius-protocol": "workspace:*",
|
|
3437
3437
|
"@types/node": "^24.13.5",
|
|
3438
|
+
"drizzle-kit": "1.0.0-rc.4",
|
|
3438
3439
|
"drizzle-orm": "1.0.0-rc.4",
|
|
3439
3440
|
esbuild: "0.28.2",
|
|
3440
3441
|
"@moxt-ai/mobius-sdk": "workspace:*",
|
|
@@ -8320,11 +8321,11 @@ var $ZodDate = /* @__PURE__ */ $constructor("$ZodDate", (inst, def) => {
|
|
|
8320
8321
|
return payload;
|
|
8321
8322
|
};
|
|
8322
8323
|
});
|
|
8323
|
-
function handleArrayResult(result, final,
|
|
8324
|
+
function handleArrayResult(result, final, index2) {
|
|
8324
8325
|
if (result.issues.length) {
|
|
8325
|
-
final.issues.push(...prefixIssues(
|
|
8326
|
+
final.issues.push(...prefixIssues(index2, result.issues));
|
|
8326
8327
|
}
|
|
8327
|
-
final.value[
|
|
8328
|
+
final.value[index2] = result.value;
|
|
8328
8329
|
}
|
|
8329
8330
|
var $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
|
|
8330
8331
|
$ZodType.init(inst, def);
|
|
@@ -8935,14 +8936,14 @@ function mergeValues(a, b) {
|
|
|
8935
8936
|
return { valid: false, mergeErrorPath: [] };
|
|
8936
8937
|
}
|
|
8937
8938
|
const newArray = [];
|
|
8938
|
-
for (let
|
|
8939
|
-
const itemA = a[
|
|
8940
|
-
const itemB = b[
|
|
8939
|
+
for (let index2 = 0; index2 < a.length; index2++) {
|
|
8940
|
+
const itemA = a[index2];
|
|
8941
|
+
const itemB = b[index2];
|
|
8941
8942
|
const sharedValue = mergeValues(itemA, itemB);
|
|
8942
8943
|
if (!sharedValue.valid) {
|
|
8943
8944
|
return {
|
|
8944
8945
|
valid: false,
|
|
8945
|
-
mergeErrorPath: [
|
|
8946
|
+
mergeErrorPath: [index2, ...sharedValue.mergeErrorPath]
|
|
8946
8947
|
};
|
|
8947
8948
|
}
|
|
8948
8949
|
newArray.push(sharedValue.data);
|
|
@@ -9093,11 +9094,11 @@ function getTupleOptStart(items, key) {
|
|
|
9093
9094
|
}
|
|
9094
9095
|
return 0;
|
|
9095
9096
|
}
|
|
9096
|
-
function handleTupleResult(result, final,
|
|
9097
|
+
function handleTupleResult(result, final, index2) {
|
|
9097
9098
|
if (result.issues.length) {
|
|
9098
|
-
final.issues.push(...prefixIssues(
|
|
9099
|
+
final.issues.push(...prefixIssues(index2, result.issues));
|
|
9099
9100
|
}
|
|
9100
|
-
final.value[
|
|
9101
|
+
final.value[index2] = result.value;
|
|
9101
9102
|
}
|
|
9102
9103
|
function handleTupleResults(itemResults, final, items, input2, optoutStart) {
|
|
9103
9104
|
for (let i = 0; i < items.length; i++) {
|
|
@@ -23778,7 +23779,7 @@ function detectVersion(schema, defaultTarget) {
|
|
|
23778
23779
|
return defaultTarget ?? "draft-2020-12";
|
|
23779
23780
|
}
|
|
23780
23781
|
function applyMinItems(items, minItems) {
|
|
23781
|
-
return items.map((item,
|
|
23782
|
+
return items.map((item, index2) => index2 < minItems ? item : item.optional());
|
|
23782
23783
|
}
|
|
23783
23784
|
function decodeJSONPointerSegment(segment) {
|
|
23784
23785
|
return segment.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
@@ -27852,9 +27853,9 @@ function comparePrerelease(left, right) {
|
|
|
27852
27853
|
if (left.length === 0 || right.length === 0) {
|
|
27853
27854
|
return left.length === right.length ? 0 : left.length === 0 ? 1 : -1;
|
|
27854
27855
|
}
|
|
27855
|
-
for (let
|
|
27856
|
-
const leftPart = left[
|
|
27857
|
-
const rightPart = right[
|
|
27856
|
+
for (let index2 = 0; index2 < Math.max(left.length, right.length); index2 += 1) {
|
|
27857
|
+
const leftPart = left[index2];
|
|
27858
|
+
const rightPart = right[index2];
|
|
27858
27859
|
if (leftPart === void 0 || rightPart === void 0) {
|
|
27859
27860
|
return leftPart === rightPart ? 0 : leftPart === void 0 ? -1 : 1;
|
|
27860
27861
|
}
|
|
@@ -27879,8 +27880,8 @@ function compareAgentVersions(left, right) {
|
|
|
27879
27880
|
if (parsedLeft === null || parsedRight === null) {
|
|
27880
27881
|
return null;
|
|
27881
27882
|
}
|
|
27882
|
-
for (let
|
|
27883
|
-
const difference = (parsedLeft.core[
|
|
27883
|
+
for (let index2 = 0; index2 < Math.max(parsedLeft.core.length, parsedRight.core.length); index2 += 1) {
|
|
27884
|
+
const difference = (parsedLeft.core[index2] ?? 0) - (parsedRight.core[index2] ?? 0);
|
|
27884
27885
|
if (difference !== 0) {
|
|
27885
27886
|
return Math.sign(difference);
|
|
27886
27887
|
}
|
|
@@ -28624,12 +28625,12 @@ var DEFAULT_AGENT_EXECUTION_CONFIGURATION = Object.freeze({
|
|
|
28624
28625
|
});
|
|
28625
28626
|
var sessionConfigurationSelectionsSchema = external_exports.array(sessionConfigurationSelectionSchema).max(100).superRefine((selections, context) => {
|
|
28626
28627
|
const identifiers = /* @__PURE__ */ new Set();
|
|
28627
|
-
for (const [
|
|
28628
|
+
for (const [index2, selection] of selections.entries()) {
|
|
28628
28629
|
if (identifiers.has(selection.configId)) {
|
|
28629
28630
|
context.addIssue({
|
|
28630
28631
|
code: "custom",
|
|
28631
28632
|
message: "Session configuration identifiers must be unique",
|
|
28632
|
-
path: [
|
|
28633
|
+
path: [index2, "configId"]
|
|
28633
28634
|
});
|
|
28634
28635
|
}
|
|
28635
28636
|
identifiers.add(selection.configId);
|
|
@@ -29666,17 +29667,6 @@ var nativeSessionRequestSchema = external_exports.discriminatedUnion("action", [
|
|
|
29666
29667
|
action: external_exports.enum(["import", "fork"]),
|
|
29667
29668
|
entryId: identifierStringSchema,
|
|
29668
29669
|
targetSessionId: identifierStringSchema
|
|
29669
|
-
}).readonly(),
|
|
29670
|
-
external_exports.object({
|
|
29671
|
-
...identity,
|
|
29672
|
-
action: external_exports.literal("fork-recorded"),
|
|
29673
|
-
targetSessionId: identifierStringSchema,
|
|
29674
|
-
throughCommandId: identifierStringSchema
|
|
29675
|
-
}).readonly(),
|
|
29676
|
-
external_exports.object({
|
|
29677
|
-
...identity,
|
|
29678
|
-
action: external_exports.literal("delete"),
|
|
29679
|
-
entryId: identifierStringSchema
|
|
29680
29670
|
}).readonly()
|
|
29681
29671
|
]);
|
|
29682
29672
|
var nativeSessionCommandSchema = external_exports.discriminatedUnion("action", [
|
|
@@ -29692,17 +29682,6 @@ var nativeSessionCommandSchema = external_exports.discriminatedUnion("action", [
|
|
|
29692
29682
|
action: external_exports.enum(["import", "fork"]),
|
|
29693
29683
|
entryId: identifierStringSchema,
|
|
29694
29684
|
targetSessionId: identifierStringSchema
|
|
29695
|
-
}).readonly(),
|
|
29696
|
-
external_exports.object({
|
|
29697
|
-
...identity,
|
|
29698
|
-
action: external_exports.literal("fork-recorded"),
|
|
29699
|
-
targetSessionId: identifierStringSchema,
|
|
29700
|
-
throughCommandId: identifierStringSchema
|
|
29701
|
-
}).readonly(),
|
|
29702
|
-
external_exports.object({
|
|
29703
|
-
...identity,
|
|
29704
|
-
action: external_exports.literal("delete"),
|
|
29705
|
-
entryId: identifierStringSchema
|
|
29706
29685
|
}).readonly()
|
|
29707
29686
|
]);
|
|
29708
29687
|
var nativeSessionEntrySchema = external_exports.object({
|
|
@@ -29747,16 +29726,10 @@ var nativeSessionResultSchema = external_exports.discriminatedUnion("action", [
|
|
|
29747
29726
|
}).readonly(),
|
|
29748
29727
|
external_exports.object({
|
|
29749
29728
|
...resultEnvelope,
|
|
29750
|
-
action: external_exports.enum(["import", "fork"
|
|
29729
|
+
action: external_exports.enum(["import", "fork"]),
|
|
29751
29730
|
targetSessionId: identifierStringSchema,
|
|
29752
29731
|
ready: sessionReadyEventSchema,
|
|
29753
29732
|
title: external_exports.string().max(500)
|
|
29754
|
-
}).readonly(),
|
|
29755
|
-
external_exports.object({
|
|
29756
|
-
...resultEnvelope,
|
|
29757
|
-
action: external_exports.literal("delete"),
|
|
29758
|
-
entryId: identifierStringSchema,
|
|
29759
|
-
deletedSessionIds: external_exports.array(identifierStringSchema).max(500).readonly()
|
|
29760
29733
|
}).readonly()
|
|
29761
29734
|
]);
|
|
29762
29735
|
var nativeSessionCancelSchema = external_exports.object({ ...envelope, kind: external_exports.literal(NATIVE_SESSION_CANCEL_KIND) }).readonly();
|
|
@@ -30158,12 +30131,12 @@ var sessionExportV2Schema = external_exports.object({
|
|
|
30158
30131
|
}).readonly().superRefine((session, context) => {
|
|
30159
30132
|
let previousPosition = 0n;
|
|
30160
30133
|
const eventIds = /* @__PURE__ */ new Set();
|
|
30161
|
-
for (const [
|
|
30134
|
+
for (const [index2, event] of session.events.entries()) {
|
|
30162
30135
|
if (event.sessionId !== session.sessionId) {
|
|
30163
30136
|
context.addIssue({
|
|
30164
30137
|
code: "custom",
|
|
30165
30138
|
message: "Exported event belongs to a different Session",
|
|
30166
|
-
path: ["events",
|
|
30139
|
+
path: ["events", index2, "sessionId"]
|
|
30167
30140
|
});
|
|
30168
30141
|
}
|
|
30169
30142
|
const position = BigInt(event.position);
|
|
@@ -30171,14 +30144,14 @@ var sessionExportV2Schema = external_exports.object({
|
|
|
30171
30144
|
context.addIssue({
|
|
30172
30145
|
code: "custom",
|
|
30173
30146
|
message: "Exported events are not in increasing position order",
|
|
30174
|
-
path: ["events",
|
|
30147
|
+
path: ["events", index2, "position"]
|
|
30175
30148
|
});
|
|
30176
30149
|
}
|
|
30177
30150
|
if (eventIds.has(event.eventId)) {
|
|
30178
30151
|
context.addIssue({
|
|
30179
30152
|
code: "custom",
|
|
30180
30153
|
message: "Exported event identities are not unique",
|
|
30181
|
-
path: ["events",
|
|
30154
|
+
path: ["events", index2, "eventId"]
|
|
30182
30155
|
});
|
|
30183
30156
|
}
|
|
30184
30157
|
previousPosition = position;
|
|
@@ -30229,6 +30202,7 @@ function decode5(value, schema) {
|
|
|
30229
30202
|
function encode4(value, schema) {
|
|
30230
30203
|
return JSON.stringify(decode5(value, schema));
|
|
30231
30204
|
}
|
|
30205
|
+
var decodeSessionEventV2 = (value) => decode5(value, sessionEventV2Schema);
|
|
30232
30206
|
var decodeSessionEventEnvelopeV2 = (value) => decode5(value, sessionEventEnvelopeV2Schema);
|
|
30233
30207
|
var encodeSessionEventEnvelopeV2 = (value) => encode4(value, sessionEventEnvelopeV2Schema);
|
|
30234
30208
|
var decodeAcpSessionUpdateV2 = (value) => decode5(value, acpSessionUpdateV2Schema);
|
|
@@ -30974,16 +30948,16 @@ var RuntimeInstallationStore = class _RuntimeInstallationStore {
|
|
|
30974
30948
|
};
|
|
30975
30949
|
#readConnectionForChannel = async (channelId, signal) => {
|
|
30976
30950
|
const normalizedChannelId = validateIdentifier(channelId, "invalid_channel_id");
|
|
30977
|
-
const
|
|
30951
|
+
const index2 = decodeChannelIndex(
|
|
30978
30952
|
await readJsonFile(this.channelIndexPath(normalizedChannelId), signal, "connection_not_found")
|
|
30979
30953
|
);
|
|
30980
|
-
if (
|
|
30954
|
+
if (index2.applicationId !== this.applicationId || index2.installationId !== this.installationId || index2.channelId !== normalizedChannelId) {
|
|
30981
30955
|
throw new RuntimeInstallationStoreError(
|
|
30982
30956
|
"connection_owner_mismatch",
|
|
30983
30957
|
"The saved Runtime connection belongs to another installation"
|
|
30984
30958
|
);
|
|
30985
30959
|
}
|
|
30986
|
-
return await this.readConnection(
|
|
30960
|
+
return await this.readConnection(index2.connectionId, signal);
|
|
30987
30961
|
};
|
|
30988
30962
|
saveConnection = async (input2, signal) => {
|
|
30989
30963
|
const stored = new VerifiedRuntimeConnection(
|
|
@@ -31178,16 +31152,16 @@ function hasExactKeys2(value, expectedKeys) {
|
|
|
31178
31152
|
}
|
|
31179
31153
|
function readSingleOption(arguments_, option) {
|
|
31180
31154
|
const values = [];
|
|
31181
|
-
for (let
|
|
31182
|
-
if (arguments_[
|
|
31155
|
+
for (let index2 = 0; index2 < arguments_.length; index2 += 1) {
|
|
31156
|
+
if (arguments_[index2] !== option) {
|
|
31183
31157
|
continue;
|
|
31184
31158
|
}
|
|
31185
|
-
const value = arguments_[
|
|
31159
|
+
const value = arguments_[index2 + 1];
|
|
31186
31160
|
if (value === void 0 || value.startsWith("--")) {
|
|
31187
31161
|
throw new PairingClientError("invalid_arguments", `${option} requires a value`);
|
|
31188
31162
|
}
|
|
31189
31163
|
values.push(value);
|
|
31190
|
-
|
|
31164
|
+
index2 += 1;
|
|
31191
31165
|
}
|
|
31192
31166
|
if (values.length !== 1) {
|
|
31193
31167
|
throw new PairingClientError("invalid_arguments", `${option} must be provided exactly once`);
|
|
@@ -31195,8 +31169,8 @@ function readSingleOption(arguments_, option) {
|
|
|
31195
31169
|
return values[0] ?? "";
|
|
31196
31170
|
}
|
|
31197
31171
|
function assertKnownArguments(arguments_) {
|
|
31198
|
-
for (let
|
|
31199
|
-
const option = arguments_[
|
|
31172
|
+
for (let index2 = 0; index2 < arguments_.length; index2 += 2) {
|
|
31173
|
+
const option = arguments_[index2];
|
|
31200
31174
|
if (option !== "--url" && option !== "--code" && option !== "--pairing" && option !== "--workspace") {
|
|
31201
31175
|
throw new PairingClientError("invalid_arguments", `Unknown pairing option: ${option ?? "missing option"}`);
|
|
31202
31176
|
}
|
|
@@ -31473,7 +31447,7 @@ var AuditStore = class {
|
|
|
31473
31447
|
};
|
|
31474
31448
|
|
|
31475
31449
|
// src/run-daemon.ts
|
|
31476
|
-
import { createHash as createHash8, randomUUID as
|
|
31450
|
+
import { createHash as createHash8, randomUUID as randomUUID10 } from "node:crypto";
|
|
31477
31451
|
import { join as join19 } from "node:path";
|
|
31478
31452
|
import { styleText } from "node:util";
|
|
31479
31453
|
|
|
@@ -31596,7 +31570,7 @@ function startsWith(bytes, signature, offset = 0) {
|
|
|
31596
31570
|
if (bytes.byteLength < offset + signature.byteLength) {
|
|
31597
31571
|
return false;
|
|
31598
31572
|
}
|
|
31599
|
-
return signature.every((value,
|
|
31573
|
+
return signature.every((value, index2) => bytes[offset + index2] === value);
|
|
31600
31574
|
}
|
|
31601
31575
|
function sniffRasterMime(bytes) {
|
|
31602
31576
|
if (startsWith(bytes, PNG_SIGNATURE)) {
|
|
@@ -31724,7 +31698,7 @@ function startsWith2(bytes, signature, offset = 0) {
|
|
|
31724
31698
|
if (bytes.byteLength < offset + signature.byteLength) {
|
|
31725
31699
|
return false;
|
|
31726
31700
|
}
|
|
31727
|
-
return signature.every((value,
|
|
31701
|
+
return signature.every((value, index2) => bytes[offset + index2] === value);
|
|
31728
31702
|
}
|
|
31729
31703
|
function sniffVideoMime(bytes) {
|
|
31730
31704
|
if (startsWith2(bytes, MP4_FILE_TYPE, 4)) {
|
|
@@ -31853,10 +31827,10 @@ async function replaceImageMarkers(text2, replace) {
|
|
|
31853
31827
|
let cursor = 0;
|
|
31854
31828
|
let rewritten = "";
|
|
31855
31829
|
for (const match of matches) {
|
|
31856
|
-
const
|
|
31857
|
-
rewritten += text2.slice(cursor,
|
|
31830
|
+
const index2 = match.index ?? 0;
|
|
31831
|
+
rewritten += text2.slice(cursor, index2);
|
|
31858
31832
|
rewritten += await replace(match[1] ?? "");
|
|
31859
|
-
cursor =
|
|
31833
|
+
cursor = index2 + match[0].length;
|
|
31860
31834
|
}
|
|
31861
31835
|
return `${rewritten}${text2.slice(cursor)}`;
|
|
31862
31836
|
}
|
|
@@ -33090,9 +33064,9 @@ function historyContentCharacters(messages) {
|
|
|
33090
33064
|
var AcpHistoryReplay = class {
|
|
33091
33065
|
#activities = /* @__PURE__ */ new Map();
|
|
33092
33066
|
#messages = [];
|
|
33093
|
-
#events
|
|
33094
|
-
#records = [];
|
|
33067
|
+
#events;
|
|
33095
33068
|
#turnActivityIds = /* @__PURE__ */ new Set();
|
|
33069
|
+
#sessionId;
|
|
33096
33070
|
#activityTracker = new AcpActivityTracker(
|
|
33097
33071
|
async (activity2) => {
|
|
33098
33072
|
this.#activities.set(activity2.activityId, activity2);
|
|
@@ -33113,10 +33087,16 @@ var AcpHistoryReplay = class {
|
|
|
33113
33087
|
#firstMessageIndex = 0;
|
|
33114
33088
|
#characters = 0;
|
|
33115
33089
|
#truncated = false;
|
|
33090
|
+
constructor(events, sessionId) {
|
|
33091
|
+
this.#events = events;
|
|
33092
|
+
this.#sessionId = sessionId;
|
|
33093
|
+
}
|
|
33116
33094
|
record = async (update, rawUpdate, onRecorded = () => Promise.resolve()) => {
|
|
33117
|
-
this.#
|
|
33118
|
-
|
|
33119
|
-
await
|
|
33095
|
+
const position = this.#events.append(this.#sessionId, { payload: rawUpdate, type: "acp" });
|
|
33096
|
+
await onRecorded(position);
|
|
33097
|
+
return await this.#applyUpdate(update, position);
|
|
33098
|
+
};
|
|
33099
|
+
#applyUpdate = async (update, position) => {
|
|
33120
33100
|
if (update.sessionUpdate === "agent_thought_chunk") {
|
|
33121
33101
|
if (update.content.type === "text") {
|
|
33122
33102
|
await this.#activityTracker.recordNarrative(
|
|
@@ -33125,30 +33105,30 @@ var AcpHistoryReplay = class {
|
|
|
33125
33105
|
update.content.text
|
|
33126
33106
|
);
|
|
33127
33107
|
}
|
|
33128
|
-
return
|
|
33108
|
+
return position;
|
|
33129
33109
|
}
|
|
33130
33110
|
if (update.sessionUpdate === "tool_call") {
|
|
33131
33111
|
await this.#activityTracker.recordToolCall(update);
|
|
33132
|
-
return
|
|
33112
|
+
return position;
|
|
33133
33113
|
}
|
|
33134
33114
|
if (update.sessionUpdate === "tool_call_update") {
|
|
33135
33115
|
await this.#activityTracker.recordToolCallUpdate(update);
|
|
33136
|
-
return
|
|
33116
|
+
return position;
|
|
33137
33117
|
}
|
|
33138
33118
|
if (update.sessionUpdate === "plan") {
|
|
33139
33119
|
await this.#activityTracker.recordPlan(update);
|
|
33140
|
-
return
|
|
33120
|
+
return position;
|
|
33141
33121
|
}
|
|
33142
33122
|
if (update.sessionUpdate === "plan_update") {
|
|
33143
33123
|
await this.#activityTracker.recordPlanUpdate(update);
|
|
33144
|
-
return
|
|
33124
|
+
return position;
|
|
33145
33125
|
}
|
|
33146
33126
|
if (update.sessionUpdate === "plan_removed") {
|
|
33147
33127
|
await this.#activityTracker.removePlan(update);
|
|
33148
|
-
return
|
|
33128
|
+
return position;
|
|
33149
33129
|
}
|
|
33150
33130
|
if (update.sessionUpdate !== "user_message_chunk" && update.sessionUpdate !== "agent_message_chunk") {
|
|
33151
|
-
return
|
|
33131
|
+
return position;
|
|
33152
33132
|
}
|
|
33153
33133
|
if (update.sessionUpdate === "agent_message_chunk" && isProgressMessage(update)) {
|
|
33154
33134
|
if (update.content.type === "text") {
|
|
@@ -33158,18 +33138,18 @@ var AcpHistoryReplay = class {
|
|
|
33158
33138
|
update.content.text
|
|
33159
33139
|
);
|
|
33160
33140
|
}
|
|
33161
|
-
return
|
|
33141
|
+
return position;
|
|
33162
33142
|
}
|
|
33163
33143
|
const role = update.sessionUpdate === "user_message_chunk" ? "user" : "assistant";
|
|
33164
33144
|
const content = update.content;
|
|
33165
33145
|
if (role === "assistant" && content.type !== "text") {
|
|
33166
33146
|
await this.#activityTracker.finishNarrative();
|
|
33167
33147
|
this.recordAssistantContent(update.messageId ?? null, normalizeContentBlock(content));
|
|
33168
|
-
return
|
|
33148
|
+
return position;
|
|
33169
33149
|
}
|
|
33170
33150
|
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]`;
|
|
33171
33151
|
if (text2.length === 0) {
|
|
33172
|
-
return
|
|
33152
|
+
return position;
|
|
33173
33153
|
}
|
|
33174
33154
|
const previous = this.#messages.at(-1);
|
|
33175
33155
|
const id = update.messageId ?? null;
|
|
@@ -33196,41 +33176,32 @@ var AcpHistoryReplay = class {
|
|
|
33196
33176
|
this.#characters += bounded2.length;
|
|
33197
33177
|
this.#lastMessageId = id;
|
|
33198
33178
|
this.trimMessages();
|
|
33199
|
-
return
|
|
33179
|
+
return position;
|
|
33200
33180
|
};
|
|
33201
33181
|
recordLifecycle = (event) => {
|
|
33202
33182
|
if (event.type !== "lifecycle-metadata") {
|
|
33203
33183
|
throw new Error("Lifecycle history only accepts lifecycle metadata");
|
|
33204
33184
|
}
|
|
33205
|
-
this.#
|
|
33206
|
-
this.#events.push(event);
|
|
33207
|
-
return this.#events.length;
|
|
33185
|
+
return this.#events.append(this.#sessionId, event);
|
|
33208
33186
|
};
|
|
33209
|
-
eventCount = () => this.#events.length;
|
|
33210
33187
|
append = async (replay) => {
|
|
33211
|
-
|
|
33212
|
-
|
|
33213
|
-
|
|
33214
|
-
} else {
|
|
33215
|
-
this.recordLifecycle(record2.event);
|
|
33216
|
-
}
|
|
33188
|
+
await replay.#activityTracker.finish();
|
|
33189
|
+
for (const [activityId, activity2] of replay.#activities) {
|
|
33190
|
+
this.#activities.set(activityId, activity2);
|
|
33217
33191
|
}
|
|
33218
|
-
|
|
33219
|
-
|
|
33220
|
-
|
|
33221
|
-
const parsedCursor = cursor === null ? events.length : Number(cursor);
|
|
33222
|
-
if (!Number.isSafeInteger(parsedCursor) || parsedCursor < 0 || parsedCursor > events.length) {
|
|
33223
|
-
throw new Error("The native event cursor is invalid");
|
|
33192
|
+
for (const message of replay.#messages.slice(replay.#firstMessageIndex)) {
|
|
33193
|
+
this.#messages.push(message);
|
|
33194
|
+
this.#characters += message.text.length;
|
|
33224
33195
|
}
|
|
33225
|
-
|
|
33226
|
-
|
|
33227
|
-
|
|
33228
|
-
|
|
33229
|
-
|
|
33230
|
-
|
|
33231
|
-
|
|
33232
|
-
};
|
|
33196
|
+
this.#turnActivityIds.clear();
|
|
33197
|
+
for (const activityId of replay.#turnActivityIds) {
|
|
33198
|
+
this.#turnActivityIds.add(activityId);
|
|
33199
|
+
}
|
|
33200
|
+
this.#lastMessageId = replay.#lastMessageId;
|
|
33201
|
+
this.#truncated ||= replay.#truncated;
|
|
33202
|
+
this.trimMessages();
|
|
33233
33203
|
};
|
|
33204
|
+
eventPage = (eventLimit, cursor) => this.#events.page(this.#sessionId, eventLimit, cursor);
|
|
33234
33205
|
snapshot = async () => {
|
|
33235
33206
|
await this.#activityTracker.finish();
|
|
33236
33207
|
const messages = this.#messages.slice(this.#firstMessageIndex).map((message) => {
|
|
@@ -33863,9 +33834,7 @@ var AcpSessionInteractions = class {
|
|
|
33863
33834
|
};
|
|
33864
33835
|
|
|
33865
33836
|
// src/acp/session-store.ts
|
|
33866
|
-
import {
|
|
33867
|
-
import { dirname as dirname4 } from "node:path";
|
|
33868
|
-
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
33837
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
33869
33838
|
|
|
33870
33839
|
// ../../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
|
|
33871
33840
|
var entityKind = /* @__PURE__ */ Symbol.for("drizzle:entityKind");
|
|
@@ -34981,7 +34950,7 @@ function haveSameKeys(left, right) {
|
|
|
34981
34950
|
const leftKeys = Object.keys(left);
|
|
34982
34951
|
const rightKeys = Object.keys(right);
|
|
34983
34952
|
if (leftKeys.length !== rightKeys.length) return false;
|
|
34984
|
-
for (const [
|
|
34953
|
+
for (const [index2, key] of leftKeys.entries()) if (key !== rightKeys[index2]) return false;
|
|
34985
34954
|
return true;
|
|
34986
34955
|
}
|
|
34987
34956
|
function mapUpdateSet(table, values) {
|
|
@@ -35734,195 +35703,6 @@ var NoopLogger = class {
|
|
|
35734
35703
|
}
|
|
35735
35704
|
};
|
|
35736
35705
|
|
|
35737
|
-
// ../../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
|
|
35738
|
-
var SQLiteCountBuilder = class SQLiteCountBuilder2 extends SQL {
|
|
35739
|
-
static [entityKind] = "SQLiteCountBuilder";
|
|
35740
|
-
dialect;
|
|
35741
|
-
session;
|
|
35742
|
-
static buildCount(source, filters, parens) {
|
|
35743
|
-
const query = sql`select count(*) from ${source}${sql` where ${filters}`.if(filters)}`;
|
|
35744
|
-
return parens ? sql`(${query})` : query;
|
|
35745
|
-
}
|
|
35746
|
-
constructor(countConfig) {
|
|
35747
|
-
super(SQLiteCountBuilder2.buildCount(countConfig.source, countConfig.filters, true).queryChunks);
|
|
35748
|
-
this.countConfig = countConfig;
|
|
35749
|
-
this.dialect = countConfig.dialect;
|
|
35750
|
-
this.session = countConfig.session;
|
|
35751
|
-
this.mapWith((e) => {
|
|
35752
|
-
if (typeof e === "number") return e;
|
|
35753
|
-
return Number(e ?? 0);
|
|
35754
|
-
});
|
|
35755
|
-
}
|
|
35756
|
-
executableSql;
|
|
35757
|
-
build() {
|
|
35758
|
-
if (!this.executableSql) {
|
|
35759
|
-
const { source, filters } = this.countConfig;
|
|
35760
|
-
this.executableSql = SQLiteCountBuilder2.buildCount(source, filters);
|
|
35761
|
-
}
|
|
35762
|
-
return this.dialect.sqlToQuery(this.executableSql);
|
|
35763
|
-
}
|
|
35764
|
-
};
|
|
35765
|
-
|
|
35766
|
-
// ../../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
|
|
35767
|
-
var SQLiteAsyncCountBuilder = class extends SQLiteCountBuilder {
|
|
35768
|
-
static [entityKind] = "SQLiteAsyncCountBuilder";
|
|
35769
|
-
constructor(countConfig) {
|
|
35770
|
-
super(countConfig);
|
|
35771
|
-
}
|
|
35772
|
-
/** @internal */
|
|
35773
|
-
executeRaw(placeholderValues) {
|
|
35774
|
-
return this.session.prepareQuery(this.build(), "arrays", false, "all", (rows) => {
|
|
35775
|
-
const v = rows[0]?.[0];
|
|
35776
|
-
if (typeof v === "number") return v;
|
|
35777
|
-
return v ? Number(v) : 0;
|
|
35778
|
-
}).execute(placeholderValues);
|
|
35779
|
-
}
|
|
35780
|
-
async execute(placeholderValues) {
|
|
35781
|
-
return await this.executeRaw(placeholderValues);
|
|
35782
|
-
}
|
|
35783
|
-
};
|
|
35784
|
-
applyMixins(SQLiteAsyncCountBuilder, [QueryPromise]);
|
|
35785
|
-
var SQLiteSyncCountBuilder = class extends SQLiteAsyncCountBuilder {
|
|
35786
|
-
static [entityKind] = "SQLiteSyncCountBuilder";
|
|
35787
|
-
sync(placeholderValues) {
|
|
35788
|
-
return this.executeRaw(placeholderValues).sync();
|
|
35789
|
-
}
|
|
35790
|
-
};
|
|
35791
|
-
|
|
35792
|
-
// ../../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
|
|
35793
|
-
var RelationalQueryBuilder = class {
|
|
35794
|
-
static [entityKind] = "SQLiteRelationalQueryBuilderV2";
|
|
35795
|
-
constructor(mode, schema, table, tableConfig, dialect, session, forbidJsonb, builder = SQLiteRelationalQuery) {
|
|
35796
|
-
this.mode = mode;
|
|
35797
|
-
this.schema = schema;
|
|
35798
|
-
this.table = table;
|
|
35799
|
-
this.tableConfig = tableConfig;
|
|
35800
|
-
this.dialect = dialect;
|
|
35801
|
-
this.session = session;
|
|
35802
|
-
this.forbidJsonb = forbidJsonb;
|
|
35803
|
-
this.builder = builder;
|
|
35804
|
-
}
|
|
35805
|
-
findMany(config2) {
|
|
35806
|
-
return new this.builder(this.mode, this.schema, this.table, this.tableConfig, this.dialect, this.session, config2 ?? true, "many", this.forbidJsonb);
|
|
35807
|
-
}
|
|
35808
|
-
findFirst(config2) {
|
|
35809
|
-
return new this.builder(this.mode, this.schema, this.table, this.tableConfig, this.dialect, this.session, config2 ?? true, "first", this.forbidJsonb);
|
|
35810
|
-
}
|
|
35811
|
-
};
|
|
35812
|
-
var SQLiteRelationalQuery = class {
|
|
35813
|
-
static [entityKind] = "SQLiteRelationalQueryV2";
|
|
35814
|
-
/** @internal */
|
|
35815
|
-
mode;
|
|
35816
|
-
/** @internal */
|
|
35817
|
-
table;
|
|
35818
|
-
/** @internal */
|
|
35819
|
-
resultKind;
|
|
35820
|
-
constructor(resultKind, schema, table, tableConfig, dialect, session, config2, mode, forbidJsonb) {
|
|
35821
|
-
this.schema = schema;
|
|
35822
|
-
this.tableConfig = tableConfig;
|
|
35823
|
-
this.dialect = dialect;
|
|
35824
|
-
this.session = session;
|
|
35825
|
-
this.config = config2;
|
|
35826
|
-
this.forbidJsonb = forbidJsonb;
|
|
35827
|
-
this.resultKind = resultKind;
|
|
35828
|
-
this.mode = mode;
|
|
35829
|
-
this.table = table;
|
|
35830
|
-
}
|
|
35831
|
-
getSQL() {
|
|
35832
|
-
return this._getQuery().sql;
|
|
35833
|
-
}
|
|
35834
|
-
_getQuery() {
|
|
35835
|
-
const jsonb = this.forbidJsonb ? sql`json` : sql`jsonb`;
|
|
35836
|
-
return this.dialect.buildRelationalQuery({
|
|
35837
|
-
schema: this.schema,
|
|
35838
|
-
table: this.table,
|
|
35839
|
-
tableConfig: this.tableConfig,
|
|
35840
|
-
queryConfig: this.config,
|
|
35841
|
-
mode: this.mode,
|
|
35842
|
-
jsonb
|
|
35843
|
-
});
|
|
35844
|
-
}
|
|
35845
|
-
_toSQL() {
|
|
35846
|
-
const query = this._getQuery();
|
|
35847
|
-
return {
|
|
35848
|
-
query,
|
|
35849
|
-
builtQuery: this.dialect.sqlToQuery(query.sql)
|
|
35850
|
-
};
|
|
35851
|
-
}
|
|
35852
|
-
toSQL() {
|
|
35853
|
-
return this._toSQL().builtQuery;
|
|
35854
|
-
}
|
|
35855
|
-
};
|
|
35856
|
-
|
|
35857
|
-
// ../../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
|
|
35858
|
-
var SQLiteAsyncRelationalQuery = class extends SQLiteRelationalQuery {
|
|
35859
|
-
static [entityKind] = "SQLiteAsyncRelationalQueryV2";
|
|
35860
|
-
/** @internal */
|
|
35861
|
-
_prepare(prepare = false) {
|
|
35862
|
-
const { query, builtQuery } = this._toSQL();
|
|
35863
|
-
const mapper = this.dialect.mapperGenerators.relationalRows({
|
|
35864
|
-
isFirst: this.mode === "first",
|
|
35865
|
-
parseJson: true,
|
|
35866
|
-
parseJsonIfString: false,
|
|
35867
|
-
rootJsonMappers: false,
|
|
35868
|
-
selection: query.selection,
|
|
35869
|
-
arrayModeRoot: true
|
|
35870
|
-
});
|
|
35871
|
-
return this.session.prepareQuery(builtQuery, "arrays", prepare, "all", mapper);
|
|
35872
|
-
}
|
|
35873
|
-
prepare() {
|
|
35874
|
-
return this._prepare(true);
|
|
35875
|
-
}
|
|
35876
|
-
async execute(placeholderValues) {
|
|
35877
|
-
return this._prepare().execute(placeholderValues);
|
|
35878
|
-
}
|
|
35879
|
-
};
|
|
35880
|
-
var SQLiteSyncRelationalQuery = class extends SQLiteAsyncRelationalQuery {
|
|
35881
|
-
static [entityKind] = "SQLiteSyncRelationalQueryV2";
|
|
35882
|
-
sync(placeholderValues) {
|
|
35883
|
-
return this._prepare().execute(placeholderValues).sync();
|
|
35884
|
-
}
|
|
35885
|
-
};
|
|
35886
|
-
applyMixins(SQLiteAsyncRelationalQuery, [QueryPromise]);
|
|
35887
|
-
|
|
35888
|
-
// ../../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
|
|
35889
|
-
var SelectionProxyHandler = class SelectionProxyHandler2 {
|
|
35890
|
-
static [entityKind] = "SelectionProxyHandler";
|
|
35891
|
-
config;
|
|
35892
|
-
constructor(config2) {
|
|
35893
|
-
this.config = { ...config2 };
|
|
35894
|
-
}
|
|
35895
|
-
get(subquery, prop) {
|
|
35896
|
-
if (prop === "_") return {
|
|
35897
|
-
...subquery["_"],
|
|
35898
|
-
selectedFields: new Proxy(subquery._.selectedFields, this)
|
|
35899
|
-
};
|
|
35900
|
-
if (prop === ViewBaseConfig) return {
|
|
35901
|
-
...subquery[ViewBaseConfig],
|
|
35902
|
-
selectedFields: new Proxy(subquery[ViewBaseConfig].selectedFields, this)
|
|
35903
|
-
};
|
|
35904
|
-
if (typeof prop === "symbol") return subquery[prop];
|
|
35905
|
-
const value = (is(subquery, Subquery) ? subquery._.selectedFields : is(subquery, View) ? subquery[ViewBaseConfig].selectedFields : subquery)[prop];
|
|
35906
|
-
if (is(value, SQL.Aliased)) {
|
|
35907
|
-
if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) return value.sql;
|
|
35908
|
-
const newValue = value.clone();
|
|
35909
|
-
newValue.isSelectionField = true;
|
|
35910
|
-
newValue.origin = this.config.alias;
|
|
35911
|
-
return newValue;
|
|
35912
|
-
}
|
|
35913
|
-
if (is(value, SQL)) {
|
|
35914
|
-
if (this.config.sqlBehavior === "sql") return value;
|
|
35915
|
-
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.`);
|
|
35916
|
-
}
|
|
35917
|
-
if (is(value, Column)) {
|
|
35918
|
-
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));
|
|
35919
|
-
return value;
|
|
35920
|
-
}
|
|
35921
|
-
if (typeof value !== "object" || value === null) return value;
|
|
35922
|
-
return new Proxy(value, new SelectionProxyHandler2(this.config));
|
|
35923
|
-
}
|
|
35924
|
-
};
|
|
35925
|
-
|
|
35926
35706
|
// ../../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
|
|
35927
35707
|
var ForeignKeyBuilder = class {
|
|
35928
35708
|
static [entityKind] = "SQLiteForeignKeyBuilder";
|
|
@@ -36487,130 +36267,144 @@ function sqliteTableWithCasing(casing) {
|
|
|
36487
36267
|
}
|
|
36488
36268
|
var sqliteTable = sqliteTableWithCasing(void 0);
|
|
36489
36269
|
|
|
36490
|
-
// ../../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/
|
|
36491
|
-
|
|
36492
|
-
|
|
36493
|
-
|
|
36494
|
-
|
|
36495
|
-
|
|
36496
|
-
}
|
|
36497
|
-
|
|
36498
|
-
|
|
36499
|
-
|
|
36500
|
-
|
|
36270
|
+
// ../../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
|
|
36271
|
+
var IndexBuilderOn = class {
|
|
36272
|
+
static [entityKind] = "SQLiteIndexBuilderOn";
|
|
36273
|
+
constructor(name2, unique) {
|
|
36274
|
+
this.name = name2;
|
|
36275
|
+
this.unique = unique;
|
|
36276
|
+
}
|
|
36277
|
+
on(...columns) {
|
|
36278
|
+
return new IndexBuilder(this.name, columns, this.unique);
|
|
36279
|
+
}
|
|
36280
|
+
};
|
|
36281
|
+
var IndexBuilder = class {
|
|
36282
|
+
static [entityKind] = "SQLiteIndexBuilder";
|
|
36501
36283
|
/** @internal */
|
|
36502
36284
|
config;
|
|
36503
|
-
constructor(
|
|
36504
|
-
this.table = table;
|
|
36505
|
-
this.session = session;
|
|
36506
|
-
this.dialect = dialect;
|
|
36285
|
+
constructor(name2, columns, unique) {
|
|
36507
36286
|
this.config = {
|
|
36508
|
-
|
|
36509
|
-
|
|
36287
|
+
name: name2,
|
|
36288
|
+
columns,
|
|
36289
|
+
unique,
|
|
36290
|
+
where: void 0
|
|
36510
36291
|
};
|
|
36511
36292
|
}
|
|
36512
36293
|
/**
|
|
36513
|
-
*
|
|
36514
|
-
*
|
|
36515
|
-
* Calling this method will delete only those rows that fulfill a specified condition.
|
|
36516
|
-
*
|
|
36517
|
-
* See docs: {@link https://orm.drizzle.team/docs/delete}
|
|
36518
|
-
*
|
|
36519
|
-
* @param where the `where` clause.
|
|
36520
|
-
*
|
|
36521
|
-
* @example
|
|
36522
|
-
* You can use conditional operators and `sql function` to filter the rows to be deleted.
|
|
36523
|
-
*
|
|
36524
|
-
* ```ts
|
|
36525
|
-
* // Delete all cars with green color
|
|
36526
|
-
* db.delete(cars).where(eq(cars.color, 'green'));
|
|
36527
|
-
* // or
|
|
36528
|
-
* db.delete(cars).where(sql`${cars.color} = 'green'`)
|
|
36529
|
-
* ```
|
|
36530
|
-
*
|
|
36531
|
-
* You can logically combine conditional operators with `and()` and `or()` operators:
|
|
36532
|
-
*
|
|
36533
|
-
* ```ts
|
|
36534
|
-
* // Delete all BMW cars with a green color
|
|
36535
|
-
* db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
|
36536
|
-
*
|
|
36537
|
-
* // Delete all cars with the green or blue color
|
|
36538
|
-
* db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
36539
|
-
* ```
|
|
36294
|
+
* Condition for partial index.
|
|
36540
36295
|
*/
|
|
36541
|
-
where(
|
|
36542
|
-
this.config.where =
|
|
36543
|
-
return this;
|
|
36544
|
-
}
|
|
36545
|
-
orderBy(...columns) {
|
|
36546
|
-
if (typeof columns[0] === "function") {
|
|
36547
|
-
const orderBy = columns[0](new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
|
|
36548
|
-
sqlAliasedBehavior: "alias",
|
|
36549
|
-
sqlBehavior: "sql"
|
|
36550
|
-
})));
|
|
36551
|
-
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
36552
|
-
this.config.orderBy = orderByArray;
|
|
36553
|
-
} else {
|
|
36554
|
-
const orderByArray = columns;
|
|
36555
|
-
this.config.orderBy = orderByArray;
|
|
36556
|
-
}
|
|
36557
|
-
return this;
|
|
36558
|
-
}
|
|
36559
|
-
limit(limit) {
|
|
36560
|
-
this.config.limit = limit;
|
|
36561
|
-
return this;
|
|
36562
|
-
}
|
|
36563
|
-
returning(fields = this.table[SQLiteTable.Symbol.Columns]) {
|
|
36564
|
-
this.config.returning = orderSelectedFields(fields);
|
|
36296
|
+
where(condition) {
|
|
36297
|
+
this.config.where = condition;
|
|
36565
36298
|
return this;
|
|
36566
36299
|
}
|
|
36567
|
-
|
|
36568
|
-
|
|
36569
|
-
|
|
36570
|
-
toSQL() {
|
|
36571
|
-
return this.dialect.sqlToQuery(this.getSQL());
|
|
36300
|
+
/** @internal */
|
|
36301
|
+
build(table) {
|
|
36302
|
+
return new Index(this.config, table);
|
|
36572
36303
|
}
|
|
36573
|
-
|
|
36574
|
-
|
|
36304
|
+
};
|
|
36305
|
+
var Index = class {
|
|
36306
|
+
static [entityKind] = "SQLiteIndex";
|
|
36307
|
+
config;
|
|
36308
|
+
isNameExplicit;
|
|
36309
|
+
constructor(config2, table) {
|
|
36310
|
+
this.config = {
|
|
36311
|
+
...config2,
|
|
36312
|
+
table
|
|
36313
|
+
};
|
|
36314
|
+
this.isNameExplicit = !!config2.name;
|
|
36575
36315
|
}
|
|
36576
36316
|
};
|
|
36317
|
+
function index(name2) {
|
|
36318
|
+
return new IndexBuilderOn(name2, false);
|
|
36319
|
+
}
|
|
36577
36320
|
|
|
36578
|
-
// ../../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/
|
|
36579
|
-
|
|
36580
|
-
|
|
36321
|
+
// ../../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
|
|
36322
|
+
function primaryKey(...config2) {
|
|
36323
|
+
if (config2[0].columns) return new PrimaryKeyBuilder(config2[0].columns, config2[0].name);
|
|
36324
|
+
return new PrimaryKeyBuilder(config2);
|
|
36325
|
+
}
|
|
36326
|
+
var PrimaryKeyBuilder = class {
|
|
36327
|
+
static [entityKind] = "SQLitePrimaryKeyBuilder";
|
|
36581
36328
|
/** @internal */
|
|
36582
|
-
|
|
36583
|
-
|
|
36584
|
-
|
|
36585
|
-
|
|
36586
|
-
|
|
36329
|
+
columns;
|
|
36330
|
+
/** @internal */
|
|
36331
|
+
name;
|
|
36332
|
+
constructor(columns, name2) {
|
|
36333
|
+
this.columns = columns;
|
|
36334
|
+
this.name = name2;
|
|
36587
36335
|
}
|
|
36588
|
-
|
|
36589
|
-
|
|
36336
|
+
/** @internal */
|
|
36337
|
+
build(table) {
|
|
36338
|
+
return new PrimaryKey(table, this.columns, this.name);
|
|
36590
36339
|
}
|
|
36591
|
-
|
|
36592
|
-
|
|
36593
|
-
|
|
36594
|
-
|
|
36595
|
-
|
|
36596
|
-
|
|
36597
|
-
|
|
36598
|
-
|
|
36599
|
-
|
|
36600
|
-
|
|
36601
|
-
|
|
36602
|
-
}
|
|
36603
|
-
|
|
36604
|
-
return this.
|
|
36340
|
+
};
|
|
36341
|
+
var PrimaryKey = class {
|
|
36342
|
+
static [entityKind] = "SQLitePrimaryKey";
|
|
36343
|
+
columns;
|
|
36344
|
+
name;
|
|
36345
|
+
isNameExplicit;
|
|
36346
|
+
constructor(table, columns, name2) {
|
|
36347
|
+
this.table = table;
|
|
36348
|
+
this.columns = columns;
|
|
36349
|
+
this.name = name2;
|
|
36350
|
+
this.isNameExplicit = !!name2;
|
|
36351
|
+
}
|
|
36352
|
+
getName() {
|
|
36353
|
+
return this.name ?? `${this.table[SQLiteTable.Symbol.Name]}_${this.columns.map((column) => column.name).join("_")}_pk`;
|
|
36605
36354
|
}
|
|
36606
36355
|
};
|
|
36607
|
-
|
|
36356
|
+
|
|
36357
|
+
// ../../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
|
|
36358
|
+
function extractUsedTable(table) {
|
|
36359
|
+
if (is(table, SQLiteTable)) return [`${table[Table.Symbol.BaseName]}`];
|
|
36360
|
+
if (is(table, Subquery)) return table._.usedTables ?? [];
|
|
36361
|
+
if (is(table, SQL)) return table.usedTables ?? [];
|
|
36362
|
+
return [];
|
|
36363
|
+
}
|
|
36608
36364
|
|
|
36609
36365
|
// ../../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
|
|
36610
36366
|
var SQLiteViewBase = class extends View {
|
|
36611
36367
|
static [entityKind] = "SQLiteViewBase";
|
|
36612
36368
|
};
|
|
36613
36369
|
|
|
36370
|
+
// ../../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
|
|
36371
|
+
var SelectionProxyHandler = class SelectionProxyHandler2 {
|
|
36372
|
+
static [entityKind] = "SelectionProxyHandler";
|
|
36373
|
+
config;
|
|
36374
|
+
constructor(config2) {
|
|
36375
|
+
this.config = { ...config2 };
|
|
36376
|
+
}
|
|
36377
|
+
get(subquery, prop) {
|
|
36378
|
+
if (prop === "_") return {
|
|
36379
|
+
...subquery["_"],
|
|
36380
|
+
selectedFields: new Proxy(subquery._.selectedFields, this)
|
|
36381
|
+
};
|
|
36382
|
+
if (prop === ViewBaseConfig) return {
|
|
36383
|
+
...subquery[ViewBaseConfig],
|
|
36384
|
+
selectedFields: new Proxy(subquery[ViewBaseConfig].selectedFields, this)
|
|
36385
|
+
};
|
|
36386
|
+
if (typeof prop === "symbol") return subquery[prop];
|
|
36387
|
+
const value = (is(subquery, Subquery) ? subquery._.selectedFields : is(subquery, View) ? subquery[ViewBaseConfig].selectedFields : subquery)[prop];
|
|
36388
|
+
if (is(value, SQL.Aliased)) {
|
|
36389
|
+
if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) return value.sql;
|
|
36390
|
+
const newValue = value.clone();
|
|
36391
|
+
newValue.isSelectionField = true;
|
|
36392
|
+
newValue.origin = this.config.alias;
|
|
36393
|
+
return newValue;
|
|
36394
|
+
}
|
|
36395
|
+
if (is(value, SQL)) {
|
|
36396
|
+
if (this.config.sqlBehavior === "sql") return value;
|
|
36397
|
+
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.`);
|
|
36398
|
+
}
|
|
36399
|
+
if (is(value, Column)) {
|
|
36400
|
+
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));
|
|
36401
|
+
return value;
|
|
36402
|
+
}
|
|
36403
|
+
if (typeof value !== "object" || value === null) return value;
|
|
36404
|
+
return new Proxy(value, new SelectionProxyHandler2(this.config));
|
|
36405
|
+
}
|
|
36406
|
+
};
|
|
36407
|
+
|
|
36614
36408
|
// ../../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
|
|
36615
36409
|
var TypedQueryBuilder = class {
|
|
36616
36410
|
static [entityKind] = "TypedQueryBuilder";
|
|
@@ -37311,8 +37105,8 @@ var SQLiteDialect = class {
|
|
|
37311
37105
|
buildJoins(joins) {
|
|
37312
37106
|
if (!joins || joins.length === 0) return;
|
|
37313
37107
|
const joinsArray = [];
|
|
37314
|
-
if (joins) for (const [
|
|
37315
|
-
if (
|
|
37108
|
+
if (joins) for (const [index2, joinMeta] of joins.entries()) {
|
|
37109
|
+
if (index2 === 0) joinsArray.push(sql` `);
|
|
37316
37110
|
const table = joinMeta.table;
|
|
37317
37111
|
const onSql = joinMeta.on ? sql` on ${joinMeta.on}` : void 0;
|
|
37318
37112
|
if (is(table, SQLiteTable)) {
|
|
@@ -37322,7 +37116,7 @@ var SQLiteDialect = class {
|
|
|
37322
37116
|
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
|
37323
37117
|
joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`}${onSql}`);
|
|
37324
37118
|
} else joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join ${table}${onSql}`);
|
|
37325
|
-
if (
|
|
37119
|
+
if (index2 < joins.length - 1) joinsArray.push(sql` `);
|
|
37326
37120
|
}
|
|
37327
37121
|
return sql.join(joinsArray);
|
|
37328
37122
|
}
|
|
@@ -37331,9 +37125,9 @@ var SQLiteDialect = class {
|
|
|
37331
37125
|
}
|
|
37332
37126
|
buildOrderBy(orderBy) {
|
|
37333
37127
|
const orderByList = [];
|
|
37334
|
-
if (orderBy) for (const [
|
|
37128
|
+
if (orderBy) for (const [index2, orderByValue] of orderBy.entries()) {
|
|
37335
37129
|
orderByList.push(orderByValue);
|
|
37336
|
-
if (
|
|
37130
|
+
if (index2 < orderBy.length - 1) orderByList.push(sql`, `);
|
|
37337
37131
|
}
|
|
37338
37132
|
return orderByList.length > 0 ? sql` order by ${sql.join(orderByList)}` : void 0;
|
|
37339
37133
|
}
|
|
@@ -37361,9 +37155,9 @@ var SQLiteDialect = class {
|
|
|
37361
37155
|
const whereSql = where ? sql` where ${where}` : void 0;
|
|
37362
37156
|
const havingSql = having ? sql` having ${having}` : void 0;
|
|
37363
37157
|
const groupByList = [];
|
|
37364
|
-
if (groupBy) for (const [
|
|
37158
|
+
if (groupBy) for (const [index2, groupByValue] of groupBy.entries()) {
|
|
37365
37159
|
groupByList.push(groupByValue);
|
|
37366
|
-
if (
|
|
37160
|
+
if (index2 < groupBy.length - 1) groupByList.push(sql`, `);
|
|
37367
37161
|
}
|
|
37368
37162
|
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}`;
|
|
37369
37163
|
if (setOperators.length > 0) return this.buildSetOperations(finalQuery, setOperators);
|
|
@@ -37652,6 +37446,268 @@ var QueryBuilder = class {
|
|
|
37652
37446
|
}
|
|
37653
37447
|
};
|
|
37654
37448
|
|
|
37449
|
+
// ../../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
|
|
37450
|
+
var SQLiteCountBuilder = class SQLiteCountBuilder2 extends SQL {
|
|
37451
|
+
static [entityKind] = "SQLiteCountBuilder";
|
|
37452
|
+
dialect;
|
|
37453
|
+
session;
|
|
37454
|
+
static buildCount(source, filters, parens) {
|
|
37455
|
+
const query = sql`select count(*) from ${source}${sql` where ${filters}`.if(filters)}`;
|
|
37456
|
+
return parens ? sql`(${query})` : query;
|
|
37457
|
+
}
|
|
37458
|
+
constructor(countConfig) {
|
|
37459
|
+
super(SQLiteCountBuilder2.buildCount(countConfig.source, countConfig.filters, true).queryChunks);
|
|
37460
|
+
this.countConfig = countConfig;
|
|
37461
|
+
this.dialect = countConfig.dialect;
|
|
37462
|
+
this.session = countConfig.session;
|
|
37463
|
+
this.mapWith((e) => {
|
|
37464
|
+
if (typeof e === "number") return e;
|
|
37465
|
+
return Number(e ?? 0);
|
|
37466
|
+
});
|
|
37467
|
+
}
|
|
37468
|
+
executableSql;
|
|
37469
|
+
build() {
|
|
37470
|
+
if (!this.executableSql) {
|
|
37471
|
+
const { source, filters } = this.countConfig;
|
|
37472
|
+
this.executableSql = SQLiteCountBuilder2.buildCount(source, filters);
|
|
37473
|
+
}
|
|
37474
|
+
return this.dialect.sqlToQuery(this.executableSql);
|
|
37475
|
+
}
|
|
37476
|
+
};
|
|
37477
|
+
|
|
37478
|
+
// ../../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
|
|
37479
|
+
var SQLiteAsyncCountBuilder = class extends SQLiteCountBuilder {
|
|
37480
|
+
static [entityKind] = "SQLiteAsyncCountBuilder";
|
|
37481
|
+
constructor(countConfig) {
|
|
37482
|
+
super(countConfig);
|
|
37483
|
+
}
|
|
37484
|
+
/** @internal */
|
|
37485
|
+
executeRaw(placeholderValues) {
|
|
37486
|
+
return this.session.prepareQuery(this.build(), "arrays", false, "all", (rows) => {
|
|
37487
|
+
const v = rows[0]?.[0];
|
|
37488
|
+
if (typeof v === "number") return v;
|
|
37489
|
+
return v ? Number(v) : 0;
|
|
37490
|
+
}).execute(placeholderValues);
|
|
37491
|
+
}
|
|
37492
|
+
async execute(placeholderValues) {
|
|
37493
|
+
return await this.executeRaw(placeholderValues);
|
|
37494
|
+
}
|
|
37495
|
+
};
|
|
37496
|
+
applyMixins(SQLiteAsyncCountBuilder, [QueryPromise]);
|
|
37497
|
+
var SQLiteSyncCountBuilder = class extends SQLiteAsyncCountBuilder {
|
|
37498
|
+
static [entityKind] = "SQLiteSyncCountBuilder";
|
|
37499
|
+
sync(placeholderValues) {
|
|
37500
|
+
return this.executeRaw(placeholderValues).sync();
|
|
37501
|
+
}
|
|
37502
|
+
};
|
|
37503
|
+
|
|
37504
|
+
// ../../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
|
|
37505
|
+
var RelationalQueryBuilder = class {
|
|
37506
|
+
static [entityKind] = "SQLiteRelationalQueryBuilderV2";
|
|
37507
|
+
constructor(mode, schema, table, tableConfig, dialect, session, forbidJsonb, builder = SQLiteRelationalQuery) {
|
|
37508
|
+
this.mode = mode;
|
|
37509
|
+
this.schema = schema;
|
|
37510
|
+
this.table = table;
|
|
37511
|
+
this.tableConfig = tableConfig;
|
|
37512
|
+
this.dialect = dialect;
|
|
37513
|
+
this.session = session;
|
|
37514
|
+
this.forbidJsonb = forbidJsonb;
|
|
37515
|
+
this.builder = builder;
|
|
37516
|
+
}
|
|
37517
|
+
findMany(config2) {
|
|
37518
|
+
return new this.builder(this.mode, this.schema, this.table, this.tableConfig, this.dialect, this.session, config2 ?? true, "many", this.forbidJsonb);
|
|
37519
|
+
}
|
|
37520
|
+
findFirst(config2) {
|
|
37521
|
+
return new this.builder(this.mode, this.schema, this.table, this.tableConfig, this.dialect, this.session, config2 ?? true, "first", this.forbidJsonb);
|
|
37522
|
+
}
|
|
37523
|
+
};
|
|
37524
|
+
var SQLiteRelationalQuery = class {
|
|
37525
|
+
static [entityKind] = "SQLiteRelationalQueryV2";
|
|
37526
|
+
/** @internal */
|
|
37527
|
+
mode;
|
|
37528
|
+
/** @internal */
|
|
37529
|
+
table;
|
|
37530
|
+
/** @internal */
|
|
37531
|
+
resultKind;
|
|
37532
|
+
constructor(resultKind, schema, table, tableConfig, dialect, session, config2, mode, forbidJsonb) {
|
|
37533
|
+
this.schema = schema;
|
|
37534
|
+
this.tableConfig = tableConfig;
|
|
37535
|
+
this.dialect = dialect;
|
|
37536
|
+
this.session = session;
|
|
37537
|
+
this.config = config2;
|
|
37538
|
+
this.forbidJsonb = forbidJsonb;
|
|
37539
|
+
this.resultKind = resultKind;
|
|
37540
|
+
this.mode = mode;
|
|
37541
|
+
this.table = table;
|
|
37542
|
+
}
|
|
37543
|
+
getSQL() {
|
|
37544
|
+
return this._getQuery().sql;
|
|
37545
|
+
}
|
|
37546
|
+
_getQuery() {
|
|
37547
|
+
const jsonb = this.forbidJsonb ? sql`json` : sql`jsonb`;
|
|
37548
|
+
return this.dialect.buildRelationalQuery({
|
|
37549
|
+
schema: this.schema,
|
|
37550
|
+
table: this.table,
|
|
37551
|
+
tableConfig: this.tableConfig,
|
|
37552
|
+
queryConfig: this.config,
|
|
37553
|
+
mode: this.mode,
|
|
37554
|
+
jsonb
|
|
37555
|
+
});
|
|
37556
|
+
}
|
|
37557
|
+
_toSQL() {
|
|
37558
|
+
const query = this._getQuery();
|
|
37559
|
+
return {
|
|
37560
|
+
query,
|
|
37561
|
+
builtQuery: this.dialect.sqlToQuery(query.sql)
|
|
37562
|
+
};
|
|
37563
|
+
}
|
|
37564
|
+
toSQL() {
|
|
37565
|
+
return this._toSQL().builtQuery;
|
|
37566
|
+
}
|
|
37567
|
+
};
|
|
37568
|
+
|
|
37569
|
+
// ../../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
|
|
37570
|
+
var SQLiteAsyncRelationalQuery = class extends SQLiteRelationalQuery {
|
|
37571
|
+
static [entityKind] = "SQLiteAsyncRelationalQueryV2";
|
|
37572
|
+
/** @internal */
|
|
37573
|
+
_prepare(prepare = false) {
|
|
37574
|
+
const { query, builtQuery } = this._toSQL();
|
|
37575
|
+
const mapper = this.dialect.mapperGenerators.relationalRows({
|
|
37576
|
+
isFirst: this.mode === "first",
|
|
37577
|
+
parseJson: true,
|
|
37578
|
+
parseJsonIfString: false,
|
|
37579
|
+
rootJsonMappers: false,
|
|
37580
|
+
selection: query.selection,
|
|
37581
|
+
arrayModeRoot: true
|
|
37582
|
+
});
|
|
37583
|
+
return this.session.prepareQuery(builtQuery, "arrays", prepare, "all", mapper);
|
|
37584
|
+
}
|
|
37585
|
+
prepare() {
|
|
37586
|
+
return this._prepare(true);
|
|
37587
|
+
}
|
|
37588
|
+
async execute(placeholderValues) {
|
|
37589
|
+
return this._prepare().execute(placeholderValues);
|
|
37590
|
+
}
|
|
37591
|
+
};
|
|
37592
|
+
var SQLiteSyncRelationalQuery = class extends SQLiteAsyncRelationalQuery {
|
|
37593
|
+
static [entityKind] = "SQLiteSyncRelationalQueryV2";
|
|
37594
|
+
sync(placeholderValues) {
|
|
37595
|
+
return this._prepare().execute(placeholderValues).sync();
|
|
37596
|
+
}
|
|
37597
|
+
};
|
|
37598
|
+
applyMixins(SQLiteAsyncRelationalQuery, [QueryPromise]);
|
|
37599
|
+
|
|
37600
|
+
// ../../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
|
|
37601
|
+
var SQLiteDeleteBase = class {
|
|
37602
|
+
static [entityKind] = "SQLiteDelete";
|
|
37603
|
+
/** @internal */
|
|
37604
|
+
config;
|
|
37605
|
+
constructor(table, session, dialect, withList) {
|
|
37606
|
+
this.table = table;
|
|
37607
|
+
this.session = session;
|
|
37608
|
+
this.dialect = dialect;
|
|
37609
|
+
this.config = {
|
|
37610
|
+
table,
|
|
37611
|
+
withList
|
|
37612
|
+
};
|
|
37613
|
+
}
|
|
37614
|
+
/**
|
|
37615
|
+
* Adds a `where` clause to the query.
|
|
37616
|
+
*
|
|
37617
|
+
* Calling this method will delete only those rows that fulfill a specified condition.
|
|
37618
|
+
*
|
|
37619
|
+
* See docs: {@link https://orm.drizzle.team/docs/delete}
|
|
37620
|
+
*
|
|
37621
|
+
* @param where the `where` clause.
|
|
37622
|
+
*
|
|
37623
|
+
* @example
|
|
37624
|
+
* You can use conditional operators and `sql function` to filter the rows to be deleted.
|
|
37625
|
+
*
|
|
37626
|
+
* ```ts
|
|
37627
|
+
* // Delete all cars with green color
|
|
37628
|
+
* db.delete(cars).where(eq(cars.color, 'green'));
|
|
37629
|
+
* // or
|
|
37630
|
+
* db.delete(cars).where(sql`${cars.color} = 'green'`)
|
|
37631
|
+
* ```
|
|
37632
|
+
*
|
|
37633
|
+
* You can logically combine conditional operators with `and()` and `or()` operators:
|
|
37634
|
+
*
|
|
37635
|
+
* ```ts
|
|
37636
|
+
* // Delete all BMW cars with a green color
|
|
37637
|
+
* db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
|
37638
|
+
*
|
|
37639
|
+
* // Delete all cars with the green or blue color
|
|
37640
|
+
* db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
37641
|
+
* ```
|
|
37642
|
+
*/
|
|
37643
|
+
where(where) {
|
|
37644
|
+
this.config.where = where;
|
|
37645
|
+
return this;
|
|
37646
|
+
}
|
|
37647
|
+
orderBy(...columns) {
|
|
37648
|
+
if (typeof columns[0] === "function") {
|
|
37649
|
+
const orderBy = columns[0](new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
|
|
37650
|
+
sqlAliasedBehavior: "alias",
|
|
37651
|
+
sqlBehavior: "sql"
|
|
37652
|
+
})));
|
|
37653
|
+
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
37654
|
+
this.config.orderBy = orderByArray;
|
|
37655
|
+
} else {
|
|
37656
|
+
const orderByArray = columns;
|
|
37657
|
+
this.config.orderBy = orderByArray;
|
|
37658
|
+
}
|
|
37659
|
+
return this;
|
|
37660
|
+
}
|
|
37661
|
+
limit(limit) {
|
|
37662
|
+
this.config.limit = limit;
|
|
37663
|
+
return this;
|
|
37664
|
+
}
|
|
37665
|
+
returning(fields = this.table[SQLiteTable.Symbol.Columns]) {
|
|
37666
|
+
this.config.returning = orderSelectedFields(fields);
|
|
37667
|
+
return this;
|
|
37668
|
+
}
|
|
37669
|
+
getSQL() {
|
|
37670
|
+
return this.dialect.buildDeleteQuery(this.config);
|
|
37671
|
+
}
|
|
37672
|
+
toSQL() {
|
|
37673
|
+
return this.dialect.sqlToQuery(this.getSQL());
|
|
37674
|
+
}
|
|
37675
|
+
$dynamic() {
|
|
37676
|
+
return this;
|
|
37677
|
+
}
|
|
37678
|
+
};
|
|
37679
|
+
|
|
37680
|
+
// ../../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
|
|
37681
|
+
var SQLiteAsyncDeleteBase = class extends SQLiteDeleteBase {
|
|
37682
|
+
static [entityKind] = "SQLiteAsyncDelete";
|
|
37683
|
+
/** @internal */
|
|
37684
|
+
_prepare(prepare = false) {
|
|
37685
|
+
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, {
|
|
37686
|
+
type: "delete",
|
|
37687
|
+
tables: extractUsedTable(this.config.table)
|
|
37688
|
+
});
|
|
37689
|
+
}
|
|
37690
|
+
prepare() {
|
|
37691
|
+
return this._prepare(true);
|
|
37692
|
+
}
|
|
37693
|
+
run = (placeholderValues) => {
|
|
37694
|
+
return this._prepare().run(placeholderValues);
|
|
37695
|
+
};
|
|
37696
|
+
all = (placeholderValues) => {
|
|
37697
|
+
return this._prepare().all(placeholderValues);
|
|
37698
|
+
};
|
|
37699
|
+
get = (placeholderValues) => {
|
|
37700
|
+
return this._prepare().get(placeholderValues);
|
|
37701
|
+
};
|
|
37702
|
+
values = (placeholderValues) => {
|
|
37703
|
+
return this._prepare().values(placeholderValues);
|
|
37704
|
+
};
|
|
37705
|
+
async execute(placeholderValues) {
|
|
37706
|
+
return this._prepare().execute(placeholderValues);
|
|
37707
|
+
}
|
|
37708
|
+
};
|
|
37709
|
+
applyMixins(SQLiteAsyncDeleteBase, [QueryPromise]);
|
|
37710
|
+
|
|
37655
37711
|
// ../../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
|
|
37656
37712
|
var SQLiteInsertBuilder = class {
|
|
37657
37713
|
static [entityKind] = "SQLiteInsertBuilder";
|
|
@@ -38539,129 +38595,6 @@ var SQLiteAsyncTransaction = class extends SQLiteAsyncDatabase {
|
|
|
38539
38595
|
}
|
|
38540
38596
|
};
|
|
38541
38597
|
|
|
38542
|
-
// ../../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
|
|
38543
|
-
var NodeSQLiteSession = class extends SQLiteAsyncSession {
|
|
38544
|
-
static [entityKind] = "SQLJsSession";
|
|
38545
|
-
logger;
|
|
38546
|
-
constructor(client2, dialect, relations, options = {}) {
|
|
38547
|
-
super(dialect, "sync");
|
|
38548
|
-
this.client = client2;
|
|
38549
|
-
this.relations = relations;
|
|
38550
|
-
this.options = options;
|
|
38551
|
-
this.logger = options.logger ?? new NoopLogger();
|
|
38552
|
-
}
|
|
38553
|
-
prepareQuery(query, mode, _prepare, executeMethod, mapper, queryMetadata) {
|
|
38554
|
-
let stmt;
|
|
38555
|
-
try {
|
|
38556
|
-
stmt = this.client.prepare(query.sql);
|
|
38557
|
-
} catch (e) {
|
|
38558
|
-
throw new DrizzleQueryError(query.sql, query.params, e);
|
|
38559
|
-
}
|
|
38560
|
-
return new SQLiteAsyncPreparedQuery("sync", executeMethod, {
|
|
38561
|
-
all: (params) => {
|
|
38562
|
-
stmt.setReturnArrays(mode === "arrays");
|
|
38563
|
-
const res = stmt.all(...params);
|
|
38564
|
-
if (mode === "objects") return res.map((row) => ({ ...row }));
|
|
38565
|
-
return res;
|
|
38566
|
-
},
|
|
38567
|
-
get: (params) => {
|
|
38568
|
-
stmt.setReturnArrays(mode === "arrays");
|
|
38569
|
-
const res = stmt.get(...params);
|
|
38570
|
-
if (res && mode === "objects") return { ...res };
|
|
38571
|
-
return res;
|
|
38572
|
-
},
|
|
38573
|
-
run: (params) => {
|
|
38574
|
-
stmt.setReturnArrays(false);
|
|
38575
|
-
return stmt.run(...params);
|
|
38576
|
-
},
|
|
38577
|
-
values: (params) => {
|
|
38578
|
-
stmt.setReturnArrays(true);
|
|
38579
|
-
return stmt.all(...params);
|
|
38580
|
-
}
|
|
38581
|
-
}, query, mapper, mode, this.logger, void 0, queryMetadata, void 0);
|
|
38582
|
-
}
|
|
38583
|
-
transaction(transaction, config2 = {}) {
|
|
38584
|
-
const tx = new NodeSQLiteTransaction("sync", this.dialect, this, this.relations);
|
|
38585
|
-
this.run(sql.raw(`begin${config2.behavior ? ` ${config2.behavior}` : ""}`));
|
|
38586
|
-
try {
|
|
38587
|
-
const result = transaction(tx);
|
|
38588
|
-
this.run(sql`commit`);
|
|
38589
|
-
return result;
|
|
38590
|
-
} catch (err) {
|
|
38591
|
-
this.run(sql`rollback`);
|
|
38592
|
-
throw err;
|
|
38593
|
-
}
|
|
38594
|
-
}
|
|
38595
|
-
};
|
|
38596
|
-
var NodeSQLiteTransaction = class NodeSQLiteTransaction2 extends SQLiteAsyncTransaction {
|
|
38597
|
-
static [entityKind] = "SQLJsTransaction";
|
|
38598
|
-
transaction(transaction) {
|
|
38599
|
-
const savepointName = `sp${this.nestedIndex + 1}`;
|
|
38600
|
-
const tx = new NodeSQLiteTransaction2("sync", this.dialect, this.session, this._.relations, this.nestedIndex + 1);
|
|
38601
|
-
tx.run(sql.raw(`savepoint ${savepointName}`));
|
|
38602
|
-
try {
|
|
38603
|
-
const result = transaction(tx);
|
|
38604
|
-
tx.run(sql.raw(`release savepoint ${savepointName}`));
|
|
38605
|
-
return result;
|
|
38606
|
-
} catch (err) {
|
|
38607
|
-
tx.run(sql.raw(`rollback to savepoint ${savepointName}`));
|
|
38608
|
-
throw err;
|
|
38609
|
-
}
|
|
38610
|
-
}
|
|
38611
|
-
};
|
|
38612
|
-
|
|
38613
|
-
// ../../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
|
|
38614
|
-
import { DatabaseSync } from "node:sqlite";
|
|
38615
|
-
var NodeSQLiteDatabase = class extends SQLiteAsyncDatabase {
|
|
38616
|
-
static [entityKind] = "NodeSQLiteDatabase";
|
|
38617
|
-
};
|
|
38618
|
-
function construct(client2, config2 = {}) {
|
|
38619
|
-
const dialect = new SQLiteDialect({ useJitMappers: jitCompatCheck(config2.jit) });
|
|
38620
|
-
let logger;
|
|
38621
|
-
if (config2.logger === true) logger = new DefaultLogger();
|
|
38622
|
-
else if (config2.logger !== false) logger = config2.logger;
|
|
38623
|
-
const relations = config2.relations ?? {};
|
|
38624
|
-
const db = new NodeSQLiteDatabase("sync", dialect, new NodeSQLiteSession(client2, dialect, relations, { logger }), relations);
|
|
38625
|
-
db.$client = client2;
|
|
38626
|
-
return db;
|
|
38627
|
-
}
|
|
38628
|
-
function drizzle(...params) {
|
|
38629
|
-
if (params[0] === void 0 || typeof params[0] === "string") return construct(params[0] === void 0 ? new DatabaseSync(":memory:") : new DatabaseSync(params[0]), params[1]);
|
|
38630
|
-
const { connection, client: client2, ...config2 } = params[0];
|
|
38631
|
-
if (client2) return construct(client2, config2);
|
|
38632
|
-
if (typeof connection === "object") {
|
|
38633
|
-
const { path: path3, ...options } = connection;
|
|
38634
|
-
return construct(new DatabaseSync(path3 ?? ":memory:", options), config2);
|
|
38635
|
-
}
|
|
38636
|
-
return construct(new DatabaseSync(connection ?? ":memory:"), config2);
|
|
38637
|
-
}
|
|
38638
|
-
(function(_drizzle) {
|
|
38639
|
-
function mock(config2) {
|
|
38640
|
-
return construct({}, config2);
|
|
38641
|
-
}
|
|
38642
|
-
_drizzle.mock = mock;
|
|
38643
|
-
})(drizzle || (drizzle = {}));
|
|
38644
|
-
|
|
38645
|
-
// src/generated/acp-session-store-migrations.ts
|
|
38646
|
-
var acpSessionStoreMigrations = [
|
|
38647
|
-
{
|
|
38648
|
-
"name": "0000_slimy_captain_midlands.sql",
|
|
38649
|
-
"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"
|
|
38650
|
-
},
|
|
38651
|
-
{
|
|
38652
|
-
"name": "0001_regular_ultimates.sql",
|
|
38653
|
-
"sql": "ALTER TABLE `acp_session` ADD `last_terminal_command_id` text;"
|
|
38654
|
-
},
|
|
38655
|
-
{
|
|
38656
|
-
"name": "0002_equal_black_queen.sql",
|
|
38657
|
-
"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`);"
|
|
38658
|
-
},
|
|
38659
|
-
{
|
|
38660
|
-
"name": "0003_silky_ravenous.sql",
|
|
38661
|
-
"sql": "DROP TABLE `session_event_v2`;"
|
|
38662
|
-
}
|
|
38663
|
-
];
|
|
38664
|
-
|
|
38665
38598
|
// src/schema/acp-session-store/acp-session.ts
|
|
38666
38599
|
var acpSession = sqliteTable("acp_session", {
|
|
38667
38600
|
sessionId: text("session_id").primaryKey(),
|
|
@@ -38669,33 +38602,235 @@ var acpSession = sqliteTable("acp_session", {
|
|
|
38669
38602
|
nativeSessionId: text("native_session_id").notNull(),
|
|
38670
38603
|
cwd: text("cwd").notNull(),
|
|
38671
38604
|
additionalDirectories: text("additional_directories").notNull(),
|
|
38672
|
-
lastTerminalCommandId: text("last_terminal_command_id"),
|
|
38673
38605
|
prompted: integer2("prompted", { mode: "boolean" }).notNull(),
|
|
38674
38606
|
title: text("title").notNull(),
|
|
38675
38607
|
updatedAt: text("updated_at").notNull()
|
|
38676
38608
|
});
|
|
38677
38609
|
|
|
38678
|
-
// src/schema/
|
|
38679
|
-
var
|
|
38680
|
-
|
|
38681
|
-
|
|
38610
|
+
// src/schema/session-event-cache/session-event-v2.ts
|
|
38611
|
+
var sessionEventV2 = sqliteTable(
|
|
38612
|
+
"session_event_v2",
|
|
38613
|
+
{
|
|
38614
|
+
eventJson: text("event_json").notNull(),
|
|
38615
|
+
generationId: text("generation_id").notNull(),
|
|
38616
|
+
position: integer2("position").notNull(),
|
|
38617
|
+
sessionId: text("session_id").notNull()
|
|
38618
|
+
},
|
|
38619
|
+
(table) => [
|
|
38620
|
+
primaryKey({ columns: [table.generationId, table.sessionId, table.position] }),
|
|
38621
|
+
index("session_event_v2_generation_session_position_index").on(
|
|
38622
|
+
table.generationId,
|
|
38623
|
+
table.sessionId,
|
|
38624
|
+
table.position
|
|
38625
|
+
)
|
|
38626
|
+
]
|
|
38627
|
+
);
|
|
38628
|
+
|
|
38629
|
+
// src/acp/session-event-store-v2.ts
|
|
38630
|
+
var HOT_EVENT_HIGH_WATER_MARK = 256;
|
|
38631
|
+
var HOT_EVENT_RETENTION = 128;
|
|
38632
|
+
function eventPage(eventCount, eventLimit, cursor, read) {
|
|
38633
|
+
const parsedCursor = cursor === null ? eventCount : Number(cursor);
|
|
38634
|
+
if (!Number.isSafeInteger(parsedCursor) || parsedCursor < 0 || parsedCursor > eventCount) {
|
|
38635
|
+
throw new Error("The native event cursor is invalid");
|
|
38636
|
+
}
|
|
38637
|
+
const endPosition = parsedCursor;
|
|
38638
|
+
const startPosition = Math.max(0, endPosition - eventLimit);
|
|
38639
|
+
return {
|
|
38640
|
+
events: read(startPosition + 1, endPosition),
|
|
38641
|
+
nextCursor: startPosition === 0 ? null : startPosition.toString(),
|
|
38642
|
+
startPosition: startPosition + 1,
|
|
38643
|
+
truncated: startPosition > 0
|
|
38644
|
+
};
|
|
38645
|
+
}
|
|
38646
|
+
var MemoryAcpSessionEventStoreV2 = class {
|
|
38647
|
+
generationId;
|
|
38648
|
+
#events = /* @__PURE__ */ new Map();
|
|
38649
|
+
constructor(generationId) {
|
|
38650
|
+
this.generationId = generationId;
|
|
38651
|
+
}
|
|
38652
|
+
append = (sessionId, event) => {
|
|
38653
|
+
const events = this.#events.get(sessionId) ?? [];
|
|
38654
|
+
events.push(event);
|
|
38655
|
+
this.#events.set(sessionId, events);
|
|
38656
|
+
return events.length;
|
|
38657
|
+
};
|
|
38658
|
+
close = () => this.#events.clear();
|
|
38659
|
+
page = (sessionId, eventLimit, cursor) => {
|
|
38660
|
+
const events = this.#events.get(sessionId) ?? [];
|
|
38661
|
+
return eventPage(
|
|
38662
|
+
events.length,
|
|
38663
|
+
eventLimit,
|
|
38664
|
+
cursor,
|
|
38665
|
+
(startPosition, endPosition) => events.slice(startPosition - 1, endPosition)
|
|
38666
|
+
);
|
|
38667
|
+
};
|
|
38668
|
+
remove = (sessionId) => {
|
|
38669
|
+
this.#events.delete(sessionId);
|
|
38670
|
+
};
|
|
38671
|
+
reset = this.remove;
|
|
38672
|
+
};
|
|
38673
|
+
var cachedEventRowSchema = external_exports.object({ eventJson: external_exports.string(), position: external_exports.number().int().positive() });
|
|
38674
|
+
function decodeCachedEvent(value) {
|
|
38675
|
+
const payload = external_exports.record(external_exports.string(), external_exports.unknown()).parse(value);
|
|
38676
|
+
const event = decodeSessionEventV2({
|
|
38677
|
+
...payload,
|
|
38678
|
+
eventId: "cached-event",
|
|
38679
|
+
position: "1",
|
|
38680
|
+
provenance: { kind: "original" },
|
|
38681
|
+
recordedAt: "1970-01-01T00:00:00.000Z",
|
|
38682
|
+
sessionId: "cached-session"
|
|
38683
|
+
});
|
|
38684
|
+
return event.type === "acp" ? { payload: event.payload, type: event.type } : { payload: event.payload, type: event.type };
|
|
38685
|
+
}
|
|
38686
|
+
var CachedAcpSessionEventStoreV2 = class {
|
|
38687
|
+
generationId;
|
|
38688
|
+
#database;
|
|
38689
|
+
#ignoredPersistedSessions = /* @__PURE__ */ new Set();
|
|
38690
|
+
#localDatabase;
|
|
38691
|
+
#sessions = /* @__PURE__ */ new Map();
|
|
38692
|
+
#flushSchedule = { kind: "idle" };
|
|
38693
|
+
#isLocalDBAvailable = true;
|
|
38694
|
+
constructor(localDatabase, generationId) {
|
|
38695
|
+
this.generationId = generationId;
|
|
38696
|
+
this.#localDatabase = localDatabase;
|
|
38697
|
+
this.#database = localDatabase.orm;
|
|
38698
|
+
try {
|
|
38699
|
+
this.#localDatabase.transaction(() => this.#database.delete(sessionEventV2).run());
|
|
38700
|
+
} catch (error62) {
|
|
38701
|
+
this.#localDatabase.close();
|
|
38702
|
+
throw error62;
|
|
38703
|
+
}
|
|
38704
|
+
}
|
|
38705
|
+
append = (sessionId, event) => {
|
|
38706
|
+
if (this.#flushSchedule.kind === "closed") {
|
|
38707
|
+
throw new Error("The V2 Session event store is closed");
|
|
38708
|
+
}
|
|
38709
|
+
const session = this.#sessions.get(sessionId) ?? { hot: [], nextPosition: 1 };
|
|
38710
|
+
const position = session.nextPosition;
|
|
38711
|
+
session.hot.push({ event, position });
|
|
38712
|
+
session.nextPosition += 1;
|
|
38713
|
+
this.#sessions.set(sessionId, session);
|
|
38714
|
+
if (session.hot.length > HOT_EVENT_HIGH_WATER_MARK) {
|
|
38715
|
+
this.#scheduleFlush();
|
|
38716
|
+
}
|
|
38717
|
+
return position;
|
|
38718
|
+
};
|
|
38719
|
+
#scheduleFlush = () => {
|
|
38720
|
+
if (!this.#isLocalDBAvailable || this.#flushSchedule.kind !== "idle") {
|
|
38721
|
+
return;
|
|
38722
|
+
}
|
|
38723
|
+
const handle = setImmediate(() => {
|
|
38724
|
+
if (this.#flushSchedule.kind !== "scheduled" || this.#flushSchedule.handle !== handle) {
|
|
38725
|
+
return;
|
|
38726
|
+
}
|
|
38727
|
+
this.#flushSchedule = { kind: "idle" };
|
|
38728
|
+
this.#flush(false);
|
|
38729
|
+
});
|
|
38730
|
+
this.#flushSchedule = { handle, kind: "scheduled" };
|
|
38731
|
+
};
|
|
38732
|
+
#flush = (includeHotTail) => {
|
|
38733
|
+
if (!this.#isLocalDBAvailable || this.#flushSchedule.kind === "closed") {
|
|
38734
|
+
return;
|
|
38735
|
+
}
|
|
38736
|
+
const batches = [...this.#sessions.entries()].flatMap(([sessionId, session]) => {
|
|
38737
|
+
const count = includeHotTail ? session.hot.length : Math.max(0, session.hot.length - HOT_EVENT_RETENTION);
|
|
38738
|
+
return count === 0 ? [] : [{ count, events: session.hot.slice(0, count), sessionId }];
|
|
38739
|
+
});
|
|
38740
|
+
const values = batches.flatMap(
|
|
38741
|
+
(batch) => batch.events.map(({ event, position }) => ({
|
|
38742
|
+
eventJson: JSON.stringify(event),
|
|
38743
|
+
generationId: this.generationId,
|
|
38744
|
+
position,
|
|
38745
|
+
sessionId: batch.sessionId
|
|
38746
|
+
}))
|
|
38747
|
+
);
|
|
38748
|
+
if (values.length === 0) {
|
|
38749
|
+
return;
|
|
38750
|
+
}
|
|
38751
|
+
try {
|
|
38752
|
+
this.#localDatabase.transaction(() => {
|
|
38753
|
+
for (let offset = 0; offset < values.length; offset += 200) {
|
|
38754
|
+
this.#database.insert(sessionEventV2).values(values.slice(offset, offset + 200)).run();
|
|
38755
|
+
}
|
|
38756
|
+
});
|
|
38757
|
+
for (const batch of batches) {
|
|
38758
|
+
this.#sessions.get(batch.sessionId)?.hot.splice(0, batch.count);
|
|
38759
|
+
}
|
|
38760
|
+
} catch (cause) {
|
|
38761
|
+
this.#isLocalDBAvailable = false;
|
|
38762
|
+
console.warn("Mobius V2 Session event cache writes are unavailable; retaining events in memory", cause);
|
|
38763
|
+
}
|
|
38764
|
+
};
|
|
38765
|
+
page = (sessionId, eventLimit, cursor) => {
|
|
38766
|
+
const session = this.#sessions.get(sessionId);
|
|
38767
|
+
const eventCount = (session?.nextPosition ?? 1) - 1;
|
|
38768
|
+
return eventPage(eventCount, eventLimit, cursor, (startPosition, endPosition) => {
|
|
38769
|
+
const persisted = this.#ignoredPersistedSessions.has(sessionId) ? [] : this.#database.select({ eventJson: sessionEventV2.eventJson, position: sessionEventV2.position }).from(sessionEventV2).where(
|
|
38770
|
+
and(
|
|
38771
|
+
eq(sessionEventV2.generationId, this.generationId),
|
|
38772
|
+
eq(sessionEventV2.sessionId, sessionId),
|
|
38773
|
+
gte(sessionEventV2.position, startPosition),
|
|
38774
|
+
lte(sessionEventV2.position, endPosition)
|
|
38775
|
+
)
|
|
38776
|
+
).orderBy(asc(sessionEventV2.position)).all().map((value) => {
|
|
38777
|
+
const row = cachedEventRowSchema.parse(value);
|
|
38778
|
+
return { event: decodeCachedEvent(JSON.parse(row.eventJson)), position: row.position };
|
|
38779
|
+
});
|
|
38780
|
+
const hot = (session?.hot ?? []).filter(
|
|
38781
|
+
({ position }) => position >= startPosition && position <= endPosition
|
|
38782
|
+
);
|
|
38783
|
+
return [...persisted, ...hot].toSorted((left, right) => left.position - right.position).map(({ event }) => event);
|
|
38784
|
+
});
|
|
38785
|
+
};
|
|
38786
|
+
#deletePersisted = (sessionId) => {
|
|
38787
|
+
if (!this.#isLocalDBAvailable) {
|
|
38788
|
+
this.#ignoredPersistedSessions.add(sessionId);
|
|
38789
|
+
return;
|
|
38790
|
+
}
|
|
38791
|
+
try {
|
|
38792
|
+
this.#database.delete(sessionEventV2).where(and(eq(sessionEventV2.generationId, this.generationId), eq(sessionEventV2.sessionId, sessionId))).run();
|
|
38793
|
+
this.#ignoredPersistedSessions.delete(sessionId);
|
|
38794
|
+
} catch (cause) {
|
|
38795
|
+
this.#isLocalDBAvailable = false;
|
|
38796
|
+
this.#ignoredPersistedSessions.add(sessionId);
|
|
38797
|
+
console.warn("Mobius V2 Session event cache writes are unavailable; retaining events in memory", cause);
|
|
38798
|
+
}
|
|
38799
|
+
};
|
|
38800
|
+
remove = (sessionId) => {
|
|
38801
|
+
this.#deletePersisted(sessionId);
|
|
38802
|
+
this.#sessions.delete(sessionId);
|
|
38803
|
+
};
|
|
38804
|
+
reset = this.remove;
|
|
38805
|
+
close = () => {
|
|
38806
|
+
if (this.#flushSchedule.kind === "closed") {
|
|
38807
|
+
return;
|
|
38808
|
+
}
|
|
38809
|
+
if (this.#flushSchedule.kind === "scheduled") {
|
|
38810
|
+
clearImmediate(this.#flushSchedule.handle);
|
|
38811
|
+
}
|
|
38812
|
+
this.#flushSchedule = { kind: "idle" };
|
|
38813
|
+
this.#flush(true);
|
|
38814
|
+
this.#flushSchedule = { kind: "closed" };
|
|
38815
|
+
this.#localDatabase.close();
|
|
38816
|
+
this.#sessions.clear();
|
|
38817
|
+
};
|
|
38818
|
+
};
|
|
38682
38819
|
|
|
38683
38820
|
// src/acp/session-store.ts
|
|
38684
38821
|
var AcpStoredSession = class {
|
|
38685
38822
|
additionalDirectories;
|
|
38686
38823
|
agentId;
|
|
38687
38824
|
cwd;
|
|
38688
|
-
lastTerminalCommandId;
|
|
38689
38825
|
nativeSessionId;
|
|
38690
38826
|
prompted;
|
|
38691
38827
|
sessionId;
|
|
38692
38828
|
title;
|
|
38693
38829
|
updatedAt;
|
|
38694
|
-
constructor(sessionId, agentId, nativeSessionId, cwd, additionalDirectories, prompted, title2, updatedAt = (/* @__PURE__ */ new Date()).toISOString()
|
|
38830
|
+
constructor(sessionId, agentId, nativeSessionId, cwd, additionalDirectories, prompted, title2, updatedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
38695
38831
|
this.additionalDirectories = [...additionalDirectories];
|
|
38696
38832
|
this.agentId = agentId;
|
|
38697
38833
|
this.cwd = cwd;
|
|
38698
|
-
this.lastTerminalCommandId = lastTerminalCommandId;
|
|
38699
38834
|
this.nativeSessionId = nativeSessionId;
|
|
38700
38835
|
this.prompted = prompted;
|
|
38701
38836
|
this.sessionId = sessionId;
|
|
@@ -38716,37 +38851,27 @@ var FoundAcpStoredSession = class extends AcpStoredSessionLookup {
|
|
|
38716
38851
|
this.session = session;
|
|
38717
38852
|
}
|
|
38718
38853
|
};
|
|
38719
|
-
var DeletedAcpStoredSession = class extends AcpStoredSessionLookup {
|
|
38720
|
-
found = false;
|
|
38721
|
-
};
|
|
38722
38854
|
var MemoryAcpSessionStore = class {
|
|
38855
|
+
eventsV2;
|
|
38723
38856
|
#sessions = /* @__PURE__ */ new Map();
|
|
38724
|
-
|
|
38857
|
+
constructor(eventsV2 = new MemoryAcpSessionEventStoreV2(randomUUID2())) {
|
|
38858
|
+
this.eventsV2 = eventsV2;
|
|
38859
|
+
}
|
|
38725
38860
|
close = () => {
|
|
38726
38861
|
this.#sessions.clear();
|
|
38727
|
-
this
|
|
38862
|
+
this.eventsV2.close();
|
|
38728
38863
|
};
|
|
38729
38864
|
findNative = (agentId, nativeSessionId) => [...this.#sessions.values()].filter(
|
|
38730
38865
|
(session) => session.agentId === agentId && session.nativeSessionId === nativeSessionId
|
|
38731
38866
|
);
|
|
38732
38867
|
list = () => [...this.#sessions.values()].toSorted((left, right) => right.updatedAt.localeCompare(left.updatedAt));
|
|
38733
|
-
markDeleted = (agentId, nativeSessionId) => {
|
|
38734
|
-
const ids = this.findNative(agentId, nativeSessionId).map((session) => session.sessionId);
|
|
38735
|
-
for (const id of ids) {
|
|
38736
|
-
this.#sessions.delete(id);
|
|
38737
|
-
this.#deleted.add(id);
|
|
38738
|
-
}
|
|
38739
|
-
return ids;
|
|
38740
|
-
};
|
|
38741
38868
|
read = (sessionId) => {
|
|
38742
|
-
if (this.#deleted.has(sessionId)) {
|
|
38743
|
-
return new DeletedAcpStoredSession();
|
|
38744
|
-
}
|
|
38745
38869
|
const session = this.#sessions.get(sessionId);
|
|
38746
38870
|
return session === void 0 ? new MissingAcpStoredSession() : new FoundAcpStoredSession(session);
|
|
38747
38871
|
};
|
|
38748
38872
|
remove = (sessionId) => {
|
|
38749
38873
|
this.#sessions.delete(sessionId);
|
|
38874
|
+
this.eventsV2.remove(sessionId);
|
|
38750
38875
|
};
|
|
38751
38876
|
write = (session) => {
|
|
38752
38877
|
this.#sessions.set(session.sessionId, session);
|
|
@@ -38756,14 +38881,12 @@ var storedSessionRowSchema = external_exports.object({
|
|
|
38756
38881
|
additionalDirectories: external_exports.string(),
|
|
38757
38882
|
agentId: external_exports.string(),
|
|
38758
38883
|
cwd: external_exports.string(),
|
|
38759
|
-
lastTerminalCommandId: external_exports.string().nullable(),
|
|
38760
38884
|
nativeSessionId: external_exports.string(),
|
|
38761
38885
|
prompted: external_exports.boolean(),
|
|
38762
38886
|
sessionId: external_exports.string(),
|
|
38763
38887
|
title: external_exports.string(),
|
|
38764
38888
|
updatedAt: external_exports.string()
|
|
38765
38889
|
});
|
|
38766
|
-
var sessionIdRowSchema = external_exports.object({ sessionId: external_exports.string() });
|
|
38767
38890
|
function decodeStoredSession(value) {
|
|
38768
38891
|
const row = storedSessionRowSchema.parse(value);
|
|
38769
38892
|
const decodedAdditionalDirectories = JSON.parse(row.additionalDirectories);
|
|
@@ -38776,98 +38899,47 @@ function decodeStoredSession(value) {
|
|
|
38776
38899
|
additionalDirectories,
|
|
38777
38900
|
row.prompted,
|
|
38778
38901
|
row.title,
|
|
38779
|
-
row.updatedAt
|
|
38780
|
-
row.lastTerminalCommandId
|
|
38902
|
+
row.updatedAt
|
|
38781
38903
|
);
|
|
38782
38904
|
}
|
|
38783
38905
|
var SqliteAcpSessionStore = class {
|
|
38906
|
+
eventsV2;
|
|
38784
38907
|
#database;
|
|
38785
|
-
#
|
|
38786
|
-
constructor(
|
|
38787
|
-
|
|
38788
|
-
this.#
|
|
38789
|
-
|
|
38790
|
-
this.#migrate();
|
|
38791
|
-
this.#database = drizzle({ client: this.#sqliteDatabase });
|
|
38908
|
+
#localDatabase;
|
|
38909
|
+
constructor(localDatabase, eventsV2 = new MemoryAcpSessionEventStoreV2(randomUUID2())) {
|
|
38910
|
+
this.eventsV2 = eventsV2;
|
|
38911
|
+
this.#localDatabase = localDatabase;
|
|
38912
|
+
this.#database = localDatabase.orm;
|
|
38792
38913
|
}
|
|
38793
|
-
|
|
38794
|
-
const version2 = external_exports.object({ user_version: external_exports.number().int().nonnegative() }).parse(this.#sqliteDatabase.prepare("PRAGMA user_version").get()).user_version;
|
|
38795
|
-
if (version2 > acpSessionStoreMigrations.length) {
|
|
38796
|
-
this.#sqliteDatabase.close();
|
|
38797
|
-
throw new Error("The ACP Session database was created by a newer Mobius version");
|
|
38798
|
-
}
|
|
38799
|
-
for (let index = version2; index < acpSessionStoreMigrations.length; index += 1) {
|
|
38800
|
-
const migration = acpSessionStoreMigrations[index];
|
|
38801
|
-
if (migration === void 0) {
|
|
38802
|
-
throw new Error("The ACP Session migration is unavailable");
|
|
38803
|
-
}
|
|
38804
|
-
this.#sqliteDatabase.exec("BEGIN IMMEDIATE");
|
|
38805
|
-
try {
|
|
38806
|
-
this.#sqliteDatabase.exec(migration.sql);
|
|
38807
|
-
this.#sqliteDatabase.exec(`PRAGMA user_version = ${index + 1}`);
|
|
38808
|
-
this.#sqliteDatabase.exec("COMMIT");
|
|
38809
|
-
} catch (error62) {
|
|
38810
|
-
this.#sqliteDatabase.exec("ROLLBACK");
|
|
38811
|
-
throw error62;
|
|
38812
|
-
}
|
|
38813
|
-
}
|
|
38814
|
-
};
|
|
38815
|
-
#transaction = (operation) => {
|
|
38816
|
-
this.#sqliteDatabase.exec("BEGIN IMMEDIATE");
|
|
38914
|
+
close = () => {
|
|
38817
38915
|
try {
|
|
38818
|
-
|
|
38819
|
-
|
|
38820
|
-
|
|
38821
|
-
this.#sqliteDatabase.exec("ROLLBACK");
|
|
38822
|
-
throw error62;
|
|
38916
|
+
this.#localDatabase.close();
|
|
38917
|
+
} finally {
|
|
38918
|
+
this.eventsV2.close();
|
|
38823
38919
|
}
|
|
38824
38920
|
};
|
|
38825
|
-
close = () => {
|
|
38826
|
-
this.#sqliteDatabase.close();
|
|
38827
|
-
};
|
|
38828
38921
|
findNative = (agentId, nativeSessionId) => this.#database.select().from(acpSession).where(and(eq(acpSession.agentId, agentId), eq(acpSession.nativeSessionId, nativeSessionId))).all().map(decodeStoredSession);
|
|
38829
38922
|
list = () => this.#database.select().from(acpSession).orderBy(desc(acpSession.updatedAt)).all().map(decodeStoredSession);
|
|
38830
|
-
markDeleted = (agentId, nativeSessionId) => {
|
|
38831
|
-
const ids = this.#database.select({ sessionId: acpSession.sessionId }).from(acpSession).where(and(eq(acpSession.agentId, agentId), eq(acpSession.nativeSessionId, nativeSessionId))).all().map((row) => sessionIdRowSchema.parse(row).sessionId);
|
|
38832
|
-
this.#transaction(() => {
|
|
38833
|
-
this.#database.delete(acpSession).where(and(eq(acpSession.agentId, agentId), eq(acpSession.nativeSessionId, nativeSessionId))).run();
|
|
38834
|
-
for (const id of ids) {
|
|
38835
|
-
this.#database.insert(deletedAcpSession).values({ sessionId: id }).onConflictDoNothing().run();
|
|
38836
|
-
}
|
|
38837
|
-
});
|
|
38838
|
-
return ids;
|
|
38839
|
-
};
|
|
38840
38923
|
read = (sessionId) => {
|
|
38841
|
-
const deleted = this.#database.select({ sessionId: deletedAcpSession.sessionId }).from(deletedAcpSession).where(eq(deletedAcpSession.sessionId, sessionId)).get();
|
|
38842
|
-
if (deleted !== void 0) {
|
|
38843
|
-
sessionIdRowSchema.parse(deleted);
|
|
38844
|
-
return new DeletedAcpStoredSession();
|
|
38845
|
-
}
|
|
38846
38924
|
const row = this.#database.select().from(acpSession).where(eq(acpSession.sessionId, sessionId)).get();
|
|
38847
38925
|
return row === void 0 ? new MissingAcpStoredSession() : new FoundAcpStoredSession(decodeStoredSession(row));
|
|
38848
38926
|
};
|
|
38849
38927
|
remove = (sessionId) => {
|
|
38850
38928
|
this.#database.delete(acpSession).where(eq(acpSession.sessionId, sessionId)).run();
|
|
38929
|
+
this.eventsV2.remove(sessionId);
|
|
38851
38930
|
};
|
|
38852
38931
|
write = (session) => {
|
|
38853
38932
|
const value = {
|
|
38854
38933
|
additionalDirectories: JSON.stringify(session.additionalDirectories),
|
|
38855
38934
|
agentId: session.agentId,
|
|
38856
38935
|
cwd: session.cwd,
|
|
38857
|
-
lastTerminalCommandId: session.lastTerminalCommandId,
|
|
38858
38936
|
nativeSessionId: session.nativeSessionId,
|
|
38859
38937
|
prompted: session.prompted,
|
|
38860
38938
|
sessionId: session.sessionId,
|
|
38861
38939
|
title: session.title,
|
|
38862
38940
|
updatedAt: session.updatedAt
|
|
38863
38941
|
};
|
|
38864
|
-
this.#
|
|
38865
|
-
this.#database.delete(deletedAcpSession).where(eq(deletedAcpSession.sessionId, session.sessionId)).run();
|
|
38866
|
-
this.#database.insert(acpSession).values(value).onConflictDoUpdate({
|
|
38867
|
-
target: acpSession.sessionId,
|
|
38868
|
-
set: value
|
|
38869
|
-
}).run();
|
|
38870
|
-
});
|
|
38942
|
+
this.#database.insert(acpSession).values(value).onConflictDoUpdate({ target: acpSession.sessionId, set: value }).run();
|
|
38871
38943
|
};
|
|
38872
38944
|
};
|
|
38873
38945
|
|
|
@@ -38880,7 +38952,7 @@ var RetryableAcpInitializationError = class extends AcpExecutionError {
|
|
|
38880
38952
|
}
|
|
38881
38953
|
};
|
|
38882
38954
|
function arraysEqual(left, right) {
|
|
38883
|
-
return left.length === right.length && left.every((value,
|
|
38955
|
+
return left.length === right.length && left.every((value, index2) => value === right[index2]);
|
|
38884
38956
|
}
|
|
38885
38957
|
function recordsEqual(left, right) {
|
|
38886
38958
|
const leftEntries = Object.entries(left);
|
|
@@ -38908,7 +38980,6 @@ var AgentSession = class _AgentSession {
|
|
|
38908
38980
|
#commands = [];
|
|
38909
38981
|
#configRevision = 0;
|
|
38910
38982
|
#configOptions = [];
|
|
38911
|
-
#lastTerminalCommandId = null;
|
|
38912
38983
|
#nativeHistoryOwnership = { kind: "unbound" };
|
|
38913
38984
|
#prompted = false;
|
|
38914
38985
|
#nativePrompt = null;
|
|
@@ -39044,12 +39115,17 @@ var AgentSession = class _AgentSession {
|
|
|
39044
39115
|
);
|
|
39045
39116
|
}
|
|
39046
39117
|
const history = await this.#completedHistory(signal, "ACP agent exited while loading history");
|
|
39047
|
-
return history.eventPage(eventLimit, cursor
|
|
39118
|
+
return history.eventPage(eventLimit, cursor);
|
|
39048
39119
|
};
|
|
39049
39120
|
async #completedHistory(signal, exitMessage) {
|
|
39050
39121
|
if (!this.#prompted && this.#nativeHistoryOwnership.kind === "fresh-session") {
|
|
39051
39122
|
if (this.#sessionLoad.kind === "not-requested") {
|
|
39052
|
-
this.#
|
|
39123
|
+
this.#store.eventsV2.reset(this.#mobiusSessionId);
|
|
39124
|
+
this.#sessionLoad = {
|
|
39125
|
+
history: new AcpHistoryReplay(this.#store.eventsV2, this.#mobiusSessionId),
|
|
39126
|
+
kind: "loaded",
|
|
39127
|
+
response: {}
|
|
39128
|
+
};
|
|
39053
39129
|
}
|
|
39054
39130
|
if (this.#sessionLoad.kind === "loaded") {
|
|
39055
39131
|
return this.#sessionLoad.history;
|
|
@@ -39064,7 +39140,8 @@ var AgentSession = class _AgentSession {
|
|
|
39064
39140
|
if (this.#sessionLoad.kind === "capturing") {
|
|
39065
39141
|
return await waitForSharedOperation(this.#sessionLoad.completion, signal);
|
|
39066
39142
|
}
|
|
39067
|
-
|
|
39143
|
+
this.#store.eventsV2.reset(this.#mobiusSessionId);
|
|
39144
|
+
const history = new AcpHistoryReplay(this.#store.eventsV2, this.#mobiusSessionId);
|
|
39068
39145
|
const completion = Promise.resolve().then(async () => {
|
|
39069
39146
|
try {
|
|
39070
39147
|
const response = await this.race(
|
|
@@ -39221,13 +39298,6 @@ var AgentSession = class _AgentSession {
|
|
|
39221
39298
|
this.#store.remove(this.#mobiusSessionId);
|
|
39222
39299
|
stored = this.#metrics.measureSync("session-state-read", () => this.#store.read(this.#mobiusSessionId));
|
|
39223
39300
|
}
|
|
39224
|
-
if (stored instanceof DeletedAcpStoredSession) {
|
|
39225
|
-
throw new AcpExecutionError(
|
|
39226
|
-
"The native Agent session was deleted. Start a new chat.",
|
|
39227
|
-
{},
|
|
39228
|
-
"native_session_deleted"
|
|
39229
|
-
);
|
|
39230
|
-
}
|
|
39231
39301
|
let lifecycleResponse;
|
|
39232
39302
|
if (origin?.kind === "fork") {
|
|
39233
39303
|
if (!this.#capabilities.unstableForkSession) {
|
|
@@ -39275,7 +39345,6 @@ var AgentSession = class _AgentSession {
|
|
|
39275
39345
|
} else if (stored instanceof FoundAcpStoredSession && stored.session.agentId === this.#agentId && stored.session.cwd === this.#cwd && arraysEqual(stored.session.additionalDirectories, this.#additionalDirectories)) {
|
|
39276
39346
|
this.selectNativeSession(stored.session.nativeSessionId);
|
|
39277
39347
|
this.#prompted = stored.session.prompted;
|
|
39278
|
-
this.#lastTerminalCommandId = stored.session.lastTerminalCommandId;
|
|
39279
39348
|
this.#sessionTitle = stored.session.title;
|
|
39280
39349
|
this.#restored = true;
|
|
39281
39350
|
if (this.#capabilities.resumeSession) {
|
|
@@ -39351,8 +39420,7 @@ var AgentSession = class _AgentSession {
|
|
|
39351
39420
|
this.#additionalDirectories,
|
|
39352
39421
|
this.#prompted,
|
|
39353
39422
|
this.#sessionTitle ?? "",
|
|
39354
|
-
(/* @__PURE__ */ new Date()).toISOString()
|
|
39355
|
-
this.#lastTerminalCommandId
|
|
39423
|
+
(/* @__PURE__ */ new Date()).toISOString()
|
|
39356
39424
|
)
|
|
39357
39425
|
);
|
|
39358
39426
|
};
|
|
@@ -39381,24 +39449,6 @@ var AgentSession = class _AgentSession {
|
|
|
39381
39449
|
}
|
|
39382
39450
|
return decoded.data;
|
|
39383
39451
|
};
|
|
39384
|
-
deleteNativeSession = async (nativeSessionId, signal) => {
|
|
39385
|
-
if (!this.#capabilities.deleteSession || !this.#capabilities.listSessions) {
|
|
39386
|
-
throw new AcpExecutionError(
|
|
39387
|
-
"This Agent does not support native session deletion",
|
|
39388
|
-
{},
|
|
39389
|
-
"native_session_unsupported"
|
|
39390
|
-
);
|
|
39391
|
-
}
|
|
39392
|
-
await this.race(
|
|
39393
|
-
this.#connection.connection.agent.request(
|
|
39394
|
-
methods8.agent.session.delete,
|
|
39395
|
-
{ sessionId: nativeSessionIdSchema.parse(nativeSessionId) },
|
|
39396
|
-
{ cancellationSignal: signal }
|
|
39397
|
-
),
|
|
39398
|
-
"ACP agent exited while deleting a session",
|
|
39399
|
-
signal
|
|
39400
|
-
);
|
|
39401
|
-
};
|
|
39402
39452
|
nativeSessionId = () => this.#updates.sessionId();
|
|
39403
39453
|
adoptNativeSessionId = (sessionId) => {
|
|
39404
39454
|
if (this.#prompted || this.#updates.sessionId() !== sessionId) {
|
|
@@ -39554,8 +39604,7 @@ var AgentSession = class _AgentSession {
|
|
|
39554
39604
|
this.#additionalDirectories,
|
|
39555
39605
|
true,
|
|
39556
39606
|
this.#sessionTitle,
|
|
39557
|
-
(/* @__PURE__ */ new Date()).toISOString()
|
|
39558
|
-
this.#lastTerminalCommandId
|
|
39607
|
+
(/* @__PURE__ */ new Date()).toISOString()
|
|
39559
39608
|
)
|
|
39560
39609
|
);
|
|
39561
39610
|
this.#prompted = true;
|
|
@@ -39567,7 +39616,7 @@ var AgentSession = class _AgentSession {
|
|
|
39567
39616
|
this.prepareAgentContent
|
|
39568
39617
|
);
|
|
39569
39618
|
this.#turn = running;
|
|
39570
|
-
this.#turnHistory = completedHistory === null ? null : new AcpHistoryReplay();
|
|
39619
|
+
this.#turnHistory = completedHistory === null ? null : new AcpHistoryReplay(this.#store.eventsV2, this.#mobiusSessionId);
|
|
39571
39620
|
const lifecycleV2 = options.lifecycleV2;
|
|
39572
39621
|
if (lifecycleV2 !== void 0) {
|
|
39573
39622
|
await this.#recordLifecycleEventV2({
|
|
@@ -39624,7 +39673,6 @@ var AgentSession = class _AgentSession {
|
|
|
39624
39673
|
usage: result.usage ?? null
|
|
39625
39674
|
});
|
|
39626
39675
|
}
|
|
39627
|
-
this.#lastTerminalCommandId = options.commandId;
|
|
39628
39676
|
this.#store.write(
|
|
39629
39677
|
new AcpStoredSession(
|
|
39630
39678
|
this.#mobiusSessionId,
|
|
@@ -39634,8 +39682,7 @@ var AgentSession = class _AgentSession {
|
|
|
39634
39682
|
this.#additionalDirectories,
|
|
39635
39683
|
true,
|
|
39636
39684
|
this.#sessionTitle ?? "",
|
|
39637
|
-
(/* @__PURE__ */ new Date()).toISOString()
|
|
39638
|
-
this.#lastTerminalCommandId
|
|
39685
|
+
(/* @__PURE__ */ new Date()).toISOString()
|
|
39639
39686
|
)
|
|
39640
39687
|
);
|
|
39641
39688
|
if (lifecycleV2 !== void 0) {
|
|
@@ -39782,7 +39829,7 @@ var AgentSession = class _AgentSession {
|
|
|
39782
39829
|
if (event.type !== "lifecycle-metadata" || this.#sessionLoad.kind !== "loaded") {
|
|
39783
39830
|
return;
|
|
39784
39831
|
}
|
|
39785
|
-
const position = this.#turnHistory === null ? this.#sessionLoad.history.recordLifecycle(event) : this.#
|
|
39832
|
+
const position = this.#turnHistory === null ? this.#sessionLoad.history.recordLifecycle(event) : this.#turnHistory.recordLifecycle(event);
|
|
39786
39833
|
await this.#getObserver().onSessionEventV2?.(this.#mobiusSessionId, event, position);
|
|
39787
39834
|
};
|
|
39788
39835
|
selectNativeSession = (sessionId) => {
|
|
@@ -39803,13 +39850,8 @@ var AgentSession = class _AgentSession {
|
|
|
39803
39850
|
} else {
|
|
39804
39851
|
const onSessionEventV2 = this.#getObserver().onSessionEventV2;
|
|
39805
39852
|
if (this.#turnHistory !== null) {
|
|
39806
|
-
|
|
39807
|
-
|
|
39808
|
-
await onSessionEventV2?.(
|
|
39809
|
-
this.#mobiusSessionId,
|
|
39810
|
-
{ payload: rawUpdate, type: "acp" },
|
|
39811
|
-
completedEventCount + turnPosition
|
|
39812
|
-
);
|
|
39853
|
+
await this.#turnHistory.record(update, rawUpdate, async (position) => {
|
|
39854
|
+
await onSessionEventV2?.(this.#mobiusSessionId, { payload: rawUpdate, type: "acp" }, position);
|
|
39813
39855
|
});
|
|
39814
39856
|
} else if (this.#sessionLoad.kind === "loaded") {
|
|
39815
39857
|
await this.#sessionLoad.history.record(update, rawUpdate, async (position) => {
|
|
@@ -39923,8 +39965,7 @@ var AgentSession = class _AgentSession {
|
|
|
39923
39965
|
this.#additionalDirectories,
|
|
39924
39966
|
this.#prompted,
|
|
39925
39967
|
this.#sessionTitle ?? "",
|
|
39926
|
-
(/* @__PURE__ */ new Date()).toISOString()
|
|
39927
|
-
this.#lastTerminalCommandId
|
|
39968
|
+
(/* @__PURE__ */ new Date()).toISOString()
|
|
39928
39969
|
)
|
|
39929
39970
|
);
|
|
39930
39971
|
}
|
|
@@ -40453,9 +40494,9 @@ var AcpContentExternalizer = class {
|
|
|
40453
40494
|
};
|
|
40454
40495
|
|
|
40455
40496
|
// src/external-content/local-external-content-store.ts
|
|
40456
|
-
import { createHash as createHash3, randomUUID as
|
|
40497
|
+
import { createHash as createHash3, randomUUID as randomUUID3 } from "node:crypto";
|
|
40457
40498
|
import { lstat, mkdir as mkdir6, readdir as readdir3, realpath as realpath8, rename as rename4, rm as rm3, stat as stat7, utimes, writeFile as writeFile4 } from "node:fs/promises";
|
|
40458
|
-
import { dirname as
|
|
40499
|
+
import { dirname as dirname4, join as join16 } from "node:path";
|
|
40459
40500
|
var contentRequest = /^mobius-content:(image|audio|resource):([a-f0-9]{64})$/u;
|
|
40460
40501
|
var CONTENT_LIFETIME_MILLISECONDS = 24 * 60 * 60 * 1e3;
|
|
40461
40502
|
var metadataSchema2 = external_exports.strictObject({
|
|
@@ -40474,7 +40515,7 @@ var UnretainedExternalContentStore = class {
|
|
|
40474
40515
|
};
|
|
40475
40516
|
};
|
|
40476
40517
|
async function atomicWrite(path3, bytes, signal) {
|
|
40477
|
-
const temporary = `${path3}.${
|
|
40518
|
+
const temporary = `${path3}.${randomUUID3()}.tmp`;
|
|
40478
40519
|
try {
|
|
40479
40520
|
await writeFile4(temporary, bytes, { mode: 384, signal });
|
|
40480
40521
|
signal.throwIfAborted();
|
|
@@ -40491,7 +40532,7 @@ var LocalExternalContentStore = class {
|
|
|
40491
40532
|
#expirationTimer;
|
|
40492
40533
|
#cleanup = Promise.resolve();
|
|
40493
40534
|
constructor(stateDirectory) {
|
|
40494
|
-
this.#root = join16(stateDirectory, "tmp", "session-content",
|
|
40535
|
+
this.#root = join16(stateDirectory, "tmp", "session-content", randomUUID3());
|
|
40495
40536
|
this.#expirationTimer = setInterval(() => {
|
|
40496
40537
|
void this.#expire().catch(() => void 0);
|
|
40497
40538
|
}, 6e4);
|
|
@@ -40502,11 +40543,11 @@ var LocalExternalContentStore = class {
|
|
|
40502
40543
|
await mkdir6(this.#root, { mode: 448, recursive: true });
|
|
40503
40544
|
const now = /* @__PURE__ */ new Date();
|
|
40504
40545
|
await utimes(this.#root, now, now);
|
|
40505
|
-
for (const directory of await readdir3(
|
|
40546
|
+
for (const directory of await readdir3(dirname4(this.#root), { withFileTypes: true })) {
|
|
40506
40547
|
if (!directory.isDirectory() || !/^[a-f0-9-]{36}$/u.test(directory.name)) {
|
|
40507
40548
|
continue;
|
|
40508
40549
|
}
|
|
40509
|
-
const path3 = join16(
|
|
40550
|
+
const path3 = join16(dirname4(this.#root), directory.name);
|
|
40510
40551
|
if (path3 === this.#root) {
|
|
40511
40552
|
continue;
|
|
40512
40553
|
}
|
|
@@ -40592,12 +40633,12 @@ var LocalExternalContentStore = class {
|
|
|
40592
40633
|
}
|
|
40593
40634
|
try {
|
|
40594
40635
|
const [resolvedDirectory, resolvedPath, file2] = await Promise.all([
|
|
40595
|
-
realpath8(
|
|
40636
|
+
realpath8(dirname4(entry.path)),
|
|
40596
40637
|
realpath8(entry.path),
|
|
40597
40638
|
lstat(entry.path)
|
|
40598
40639
|
]);
|
|
40599
40640
|
signal.throwIfAborted();
|
|
40600
|
-
if (!file2.isFile() || file2.isSymbolicLink() ||
|
|
40641
|
+
if (!file2.isFile() || file2.isSymbolicLink() || dirname4(resolvedPath) !== resolvedDirectory) {
|
|
40601
40642
|
return null;
|
|
40602
40643
|
}
|
|
40603
40644
|
return { mediaType: entry.mediaType, name: entry.name, path: resolvedPath };
|
|
@@ -40674,9 +40715,9 @@ var AcpProcessCapacityLock = class {
|
|
|
40674
40715
|
return await waiter.completion.promise;
|
|
40675
40716
|
} finally {
|
|
40676
40717
|
signal.removeEventListener("abort", waiter.cancel);
|
|
40677
|
-
const
|
|
40678
|
-
if (
|
|
40679
|
-
this.#waiters.splice(
|
|
40718
|
+
const index2 = this.#waiters.indexOf(waiter);
|
|
40719
|
+
if (index2 >= 0) {
|
|
40720
|
+
this.#waiters.splice(index2, 1);
|
|
40680
40721
|
}
|
|
40681
40722
|
}
|
|
40682
40723
|
};
|
|
@@ -40965,13 +41006,6 @@ var AgentRuntimeManager = class {
|
|
|
40965
41006
|
}
|
|
40966
41007
|
prepareSession = async (options, metrics = unmeasuredOperationMetrics) => this.#operations.run(options, async (options2) => {
|
|
40967
41008
|
const stored = metrics.measureSync("session-state-read", () => this.#store.read(options2.sessionId));
|
|
40968
|
-
if (stored instanceof DeletedAcpStoredSession) {
|
|
40969
|
-
throw new AcpExecutionError(
|
|
40970
|
-
"The native Agent session was deleted. Start a new chat.",
|
|
40971
|
-
{},
|
|
40972
|
-
"native_session_deleted"
|
|
40973
|
-
);
|
|
40974
|
-
}
|
|
40975
41009
|
if (stored instanceof FoundAcpStoredSession && this.#nativeOperations.has(`${stored.session.agentId}:${stored.session.nativeSessionId}`)) {
|
|
40976
41010
|
throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
|
|
40977
41011
|
}
|
|
@@ -41420,7 +41454,7 @@ var AgentRuntimeManager = class {
|
|
|
41420
41454
|
}
|
|
41421
41455
|
});
|
|
41422
41456
|
}
|
|
41423
|
-
if (this.#executionProcesses.get(options2.sessionId) !== void 0 || this.#executionProcesses.pending(options2.sessionId) !== void 0 || this.#store.read(options2.sessionId) instanceof FoundAcpStoredSession
|
|
41457
|
+
if (this.#executionProcesses.get(options2.sessionId) !== void 0 || this.#executionProcesses.pending(options2.sessionId) !== void 0 || this.#store.read(options2.sessionId) instanceof FoundAcpStoredSession) {
|
|
41424
41458
|
throw new AcpExecutionError(
|
|
41425
41459
|
"The destination conversation already exists",
|
|
41426
41460
|
{},
|
|
@@ -41466,40 +41500,6 @@ var AgentRuntimeManager = class {
|
|
|
41466
41500
|
}
|
|
41467
41501
|
});
|
|
41468
41502
|
});
|
|
41469
|
-
deleteNativeSession = async (options, nativeSessionId) => this.#operations.run(options, async (options2) => {
|
|
41470
|
-
return await this.#queryProcesses.use(options2, async (runtime) => {
|
|
41471
|
-
const key = `${options2.agent.id}:${nativeSessionId}`;
|
|
41472
|
-
const linked = this.#store.findNative(options2.agent.id, nativeSessionId);
|
|
41473
|
-
if (this.#nativeOperations.has(key) || linked.some(
|
|
41474
|
-
(entry) => this.#executions.command(entry.sessionId) !== void 0 || this.#executionProcesses.pending(entry.sessionId) !== void 0
|
|
41475
|
-
)) {
|
|
41476
|
-
throw new AcpExecutionError(
|
|
41477
|
-
"Wait for the native session's running operation to finish",
|
|
41478
|
-
{},
|
|
41479
|
-
"session_busy"
|
|
41480
|
-
);
|
|
41481
|
-
}
|
|
41482
|
-
this.#nativeOperations.add(key);
|
|
41483
|
-
try {
|
|
41484
|
-
for (const entry of linked) {
|
|
41485
|
-
const active = this.#executionProcesses.get(entry.sessionId);
|
|
41486
|
-
if (active !== void 0 && active !== runtime) {
|
|
41487
|
-
await this.#retireSessionProcess(entry.sessionId, active, async () => await active.close());
|
|
41488
|
-
}
|
|
41489
|
-
}
|
|
41490
|
-
options2.signal.throwIfAborted();
|
|
41491
|
-
await runtime.deleteNativeSession(nativeSessionId, options2.signal);
|
|
41492
|
-
const deleted = this.#store.markDeleted(options2.agent.id, nativeSessionId);
|
|
41493
|
-
if (runtime.nativeSessionId() === nativeSessionId) {
|
|
41494
|
-
await this.#queryProcesses.retire(options2.sessionId, runtime);
|
|
41495
|
-
}
|
|
41496
|
-
return deleted;
|
|
41497
|
-
} finally {
|
|
41498
|
-
this.#nativeOperations.delete(key);
|
|
41499
|
-
this.#processes.notifyChanged();
|
|
41500
|
-
}
|
|
41501
|
-
});
|
|
41502
|
-
});
|
|
41503
41503
|
};
|
|
41504
41504
|
|
|
41505
41505
|
// src/agent-catalog/publish-agent-catalog.ts
|
|
@@ -42077,7 +42077,7 @@ var FixedInstallationExecutor = class {
|
|
|
42077
42077
|
// src/authorization/workspace-directory.ts
|
|
42078
42078
|
import { readdir as readdir4, realpath as realpath9, stat as stat8 } from "node:fs/promises";
|
|
42079
42079
|
import { homedir as homedir2 } from "node:os";
|
|
42080
|
-
import { basename as basename4, dirname as
|
|
42080
|
+
import { basename as basename4, dirname as dirname5, isAbsolute as isAbsolute9, join as join17, normalize as normalize3, relative as relative4 } from "node:path";
|
|
42081
42081
|
|
|
42082
42082
|
// src/authorization/local-authorization-error.ts
|
|
42083
42083
|
var LocalAuthorizationError = class extends Error {
|
|
@@ -42216,7 +42216,7 @@ var WorkspaceDirectoryService = class {
|
|
|
42216
42216
|
}
|
|
42217
42217
|
}
|
|
42218
42218
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
42219
|
-
const parent =
|
|
42219
|
+
const parent = dirname5(target);
|
|
42220
42220
|
return new WorkspaceDirectoryListing(
|
|
42221
42221
|
id,
|
|
42222
42222
|
this.label(target),
|
|
@@ -42241,7 +42241,7 @@ var WorkspaceDirectoryService = class {
|
|
|
42241
42241
|
};
|
|
42242
42242
|
|
|
42243
42243
|
// src/daemon-diagnostic-log.ts
|
|
42244
|
-
import { appendFileSync, mkdirSync
|
|
42244
|
+
import { appendFileSync, mkdirSync, readFileSync as readFileSync2, renameSync, statSync as statSync3, writeFileSync } from "node:fs";
|
|
42245
42245
|
import { join as join18 } from "node:path";
|
|
42246
42246
|
var MAXIMUM_DAEMON_LOG_BYTES = 1 * 1024 * 1024;
|
|
42247
42247
|
var DaemonDiagnosticLog = class {
|
|
@@ -42257,7 +42257,7 @@ var DaemonDiagnosticLog = class {
|
|
|
42257
42257
|
const encoded = `${diagnostic.replace(/[\r\n]+/gu, " ").trim()}
|
|
42258
42258
|
`;
|
|
42259
42259
|
const encodedBytes = Buffer.byteLength(encoded);
|
|
42260
|
-
|
|
42260
|
+
mkdirSync(this.#directory, { mode: 448, recursive: true });
|
|
42261
42261
|
let existingBytes = 0;
|
|
42262
42262
|
try {
|
|
42263
42263
|
existingBytes = statSync3(this.#path).size;
|
|
@@ -42722,7 +42722,7 @@ var DaemonInstallationObserver = class {
|
|
|
42722
42722
|
};
|
|
42723
42723
|
|
|
42724
42724
|
// src/daemon-active-turn.ts
|
|
42725
|
-
import { randomUUID as
|
|
42725
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
42726
42726
|
function activeMessageCharacters(message) {
|
|
42727
42727
|
return message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0);
|
|
42728
42728
|
}
|
|
@@ -42730,8 +42730,8 @@ var ACTIVE_TURN_TEXT_CHUNK_LIMIT = Math.floor(SESSION_HISTORY_CHARACTER_LIMIT /
|
|
|
42730
42730
|
function boundedRecoveryMessages(messages) {
|
|
42731
42731
|
const selected = [];
|
|
42732
42732
|
let remainingCharacters = SESSION_HISTORY_CHARACTER_LIMIT;
|
|
42733
|
-
for (let
|
|
42734
|
-
const message = messages[
|
|
42733
|
+
for (let index2 = messages.length - 1; index2 >= 0 && selected.length < SESSION_HISTORY_MESSAGE_LIMIT; index2 -= 1) {
|
|
42734
|
+
const message = messages[index2];
|
|
42735
42735
|
if (message === void 0) {
|
|
42736
42736
|
break;
|
|
42737
42737
|
}
|
|
@@ -42756,7 +42756,7 @@ var ActiveDaemonTurn = class {
|
|
|
42756
42756
|
#timeline;
|
|
42757
42757
|
#sequence = 0;
|
|
42758
42758
|
#interaction = null;
|
|
42759
|
-
#epoch = decodeIdentifier(
|
|
42759
|
+
#epoch = decodeIdentifier(randomUUID4());
|
|
42760
42760
|
constructor(command, attemptId) {
|
|
42761
42761
|
this.attemptId = attemptId;
|
|
42762
42762
|
this.command = command;
|
|
@@ -42818,7 +42818,7 @@ var ActiveDaemonTurn = class {
|
|
|
42818
42818
|
if (!this.#activities.has(event.activityId)) {
|
|
42819
42819
|
this.#timeline = [
|
|
42820
42820
|
...this.#timeline,
|
|
42821
|
-
{ activityId: event.activityId, id: decodeIdentifier(
|
|
42821
|
+
{ activityId: event.activityId, id: decodeIdentifier(randomUUID4()), kind: "activity" }
|
|
42822
42822
|
];
|
|
42823
42823
|
}
|
|
42824
42824
|
this.#activities.set(event.activityId, {
|
|
@@ -42839,7 +42839,7 @@ var ActiveDaemonTurn = class {
|
|
|
42839
42839
|
if (previous === void 0) {
|
|
42840
42840
|
this.#timeline = [
|
|
42841
42841
|
...this.#timeline,
|
|
42842
|
-
{ activityId: event.activityId, id: decodeIdentifier(
|
|
42842
|
+
{ activityId: event.activityId, id: decodeIdentifier(randomUUID4()), kind: "activity" }
|
|
42843
42843
|
];
|
|
42844
42844
|
}
|
|
42845
42845
|
this.#activities.set(event.activityId, {
|
|
@@ -42864,7 +42864,7 @@ var ActiveDaemonTurn = class {
|
|
|
42864
42864
|
...this.#timeline,
|
|
42865
42865
|
{
|
|
42866
42866
|
content: /* @__PURE__ */ new Map([[event.contentId, event.content]]),
|
|
42867
|
-
id: decodeIdentifier(
|
|
42867
|
+
id: decodeIdentifier(randomUUID4()),
|
|
42868
42868
|
kind: "message",
|
|
42869
42869
|
sourceMessageId: event.messageId,
|
|
42870
42870
|
text: ""
|
|
@@ -42872,7 +42872,7 @@ var ActiveDaemonTurn = class {
|
|
|
42872
42872
|
];
|
|
42873
42873
|
} else {
|
|
42874
42874
|
this.#timeline = this.#timeline.map(
|
|
42875
|
-
(entry,
|
|
42875
|
+
(entry, index2) => index2 === target && entry.kind === "message" ? { ...entry, content: new Map([...entry.content, [event.contentId, event.content]]) } : entry
|
|
42876
42876
|
);
|
|
42877
42877
|
}
|
|
42878
42878
|
} else if (event.kind === SESSION_PERMISSION_REQUESTED_KIND || event.kind === SESSION_ELICITATION_REQUESTED_KIND) {
|
|
@@ -42904,7 +42904,7 @@ var ActiveDaemonTurn = class {
|
|
|
42904
42904
|
...this.#timeline,
|
|
42905
42905
|
{
|
|
42906
42906
|
content: /* @__PURE__ */ new Map(),
|
|
42907
|
-
id: decodeIdentifier(
|
|
42907
|
+
id: decodeIdentifier(randomUUID4()),
|
|
42908
42908
|
kind: "message",
|
|
42909
42909
|
sourceMessageId: messageId,
|
|
42910
42910
|
text: remaining.slice(0, ACTIVE_TURN_TEXT_CHUNK_LIMIT)
|
|
@@ -43175,6 +43175,202 @@ var DaemonTurnRegistry = class {
|
|
|
43175
43175
|
};
|
|
43176
43176
|
};
|
|
43177
43177
|
|
|
43178
|
+
// src/generated/acp-session-store-migrations.ts
|
|
43179
|
+
var acpSessionStoreMigrations = [
|
|
43180
|
+
{
|
|
43181
|
+
"name": "0000_slimy_captain_midlands.sql",
|
|
43182
|
+
"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"
|
|
43183
|
+
},
|
|
43184
|
+
{
|
|
43185
|
+
"name": "0001_regular_ultimates.sql",
|
|
43186
|
+
"sql": "ALTER TABLE `acp_session` ADD `last_terminal_command_id` text;"
|
|
43187
|
+
},
|
|
43188
|
+
{
|
|
43189
|
+
"name": "0002_equal_black_queen.sql",
|
|
43190
|
+
"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`);"
|
|
43191
|
+
},
|
|
43192
|
+
{
|
|
43193
|
+
"name": "0003_silky_ravenous.sql",
|
|
43194
|
+
"sql": "DROP TABLE `session_event_v2`;"
|
|
43195
|
+
},
|
|
43196
|
+
{
|
|
43197
|
+
"name": "0004_special_mathemanic.sql",
|
|
43198
|
+
"sql": "DROP TABLE `deleted_acp_session`;--> statement-breakpoint\nALTER TABLE `acp_session` DROP COLUMN `last_terminal_command_id`;"
|
|
43199
|
+
}
|
|
43200
|
+
];
|
|
43201
|
+
|
|
43202
|
+
// src/generated/session-event-cache-migrations.ts
|
|
43203
|
+
var sessionEventCacheMigrations = [
|
|
43204
|
+
{
|
|
43205
|
+
"name": "migration.sql",
|
|
43206
|
+
"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`);"
|
|
43207
|
+
}
|
|
43208
|
+
];
|
|
43209
|
+
|
|
43210
|
+
// src/infra/local-sqlite-database.ts
|
|
43211
|
+
import { chmodSync, mkdirSync as mkdirSync2 } from "node:fs";
|
|
43212
|
+
import { dirname as dirname6 } from "node:path";
|
|
43213
|
+
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
43214
|
+
|
|
43215
|
+
// ../../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
|
|
43216
|
+
var NodeSQLiteSession = class extends SQLiteAsyncSession {
|
|
43217
|
+
static [entityKind] = "SQLJsSession";
|
|
43218
|
+
logger;
|
|
43219
|
+
constructor(client2, dialect, relations, options = {}) {
|
|
43220
|
+
super(dialect, "sync");
|
|
43221
|
+
this.client = client2;
|
|
43222
|
+
this.relations = relations;
|
|
43223
|
+
this.options = options;
|
|
43224
|
+
this.logger = options.logger ?? new NoopLogger();
|
|
43225
|
+
}
|
|
43226
|
+
prepareQuery(query, mode, _prepare, executeMethod, mapper, queryMetadata) {
|
|
43227
|
+
let stmt;
|
|
43228
|
+
try {
|
|
43229
|
+
stmt = this.client.prepare(query.sql);
|
|
43230
|
+
} catch (e) {
|
|
43231
|
+
throw new DrizzleQueryError(query.sql, query.params, e);
|
|
43232
|
+
}
|
|
43233
|
+
return new SQLiteAsyncPreparedQuery("sync", executeMethod, {
|
|
43234
|
+
all: (params) => {
|
|
43235
|
+
stmt.setReturnArrays(mode === "arrays");
|
|
43236
|
+
const res = stmt.all(...params);
|
|
43237
|
+
if (mode === "objects") return res.map((row) => ({ ...row }));
|
|
43238
|
+
return res;
|
|
43239
|
+
},
|
|
43240
|
+
get: (params) => {
|
|
43241
|
+
stmt.setReturnArrays(mode === "arrays");
|
|
43242
|
+
const res = stmt.get(...params);
|
|
43243
|
+
if (res && mode === "objects") return { ...res };
|
|
43244
|
+
return res;
|
|
43245
|
+
},
|
|
43246
|
+
run: (params) => {
|
|
43247
|
+
stmt.setReturnArrays(false);
|
|
43248
|
+
return stmt.run(...params);
|
|
43249
|
+
},
|
|
43250
|
+
values: (params) => {
|
|
43251
|
+
stmt.setReturnArrays(true);
|
|
43252
|
+
return stmt.all(...params);
|
|
43253
|
+
}
|
|
43254
|
+
}, query, mapper, mode, this.logger, void 0, queryMetadata, void 0);
|
|
43255
|
+
}
|
|
43256
|
+
transaction(transaction, config2 = {}) {
|
|
43257
|
+
const tx = new NodeSQLiteTransaction("sync", this.dialect, this, this.relations);
|
|
43258
|
+
this.run(sql.raw(`begin${config2.behavior ? ` ${config2.behavior}` : ""}`));
|
|
43259
|
+
try {
|
|
43260
|
+
const result = transaction(tx);
|
|
43261
|
+
this.run(sql`commit`);
|
|
43262
|
+
return result;
|
|
43263
|
+
} catch (err) {
|
|
43264
|
+
this.run(sql`rollback`);
|
|
43265
|
+
throw err;
|
|
43266
|
+
}
|
|
43267
|
+
}
|
|
43268
|
+
};
|
|
43269
|
+
var NodeSQLiteTransaction = class NodeSQLiteTransaction2 extends SQLiteAsyncTransaction {
|
|
43270
|
+
static [entityKind] = "SQLJsTransaction";
|
|
43271
|
+
transaction(transaction) {
|
|
43272
|
+
const savepointName = `sp${this.nestedIndex + 1}`;
|
|
43273
|
+
const tx = new NodeSQLiteTransaction2("sync", this.dialect, this.session, this._.relations, this.nestedIndex + 1);
|
|
43274
|
+
tx.run(sql.raw(`savepoint ${savepointName}`));
|
|
43275
|
+
try {
|
|
43276
|
+
const result = transaction(tx);
|
|
43277
|
+
tx.run(sql.raw(`release savepoint ${savepointName}`));
|
|
43278
|
+
return result;
|
|
43279
|
+
} catch (err) {
|
|
43280
|
+
tx.run(sql.raw(`rollback to savepoint ${savepointName}`));
|
|
43281
|
+
throw err;
|
|
43282
|
+
}
|
|
43283
|
+
}
|
|
43284
|
+
};
|
|
43285
|
+
|
|
43286
|
+
// ../../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
|
|
43287
|
+
import { DatabaseSync } from "node:sqlite";
|
|
43288
|
+
var NodeSQLiteDatabase = class extends SQLiteAsyncDatabase {
|
|
43289
|
+
static [entityKind] = "NodeSQLiteDatabase";
|
|
43290
|
+
};
|
|
43291
|
+
function construct(client2, config2 = {}) {
|
|
43292
|
+
const dialect = new SQLiteDialect({ useJitMappers: jitCompatCheck(config2.jit) });
|
|
43293
|
+
let logger;
|
|
43294
|
+
if (config2.logger === true) logger = new DefaultLogger();
|
|
43295
|
+
else if (config2.logger !== false) logger = config2.logger;
|
|
43296
|
+
const relations = config2.relations ?? {};
|
|
43297
|
+
const db = new NodeSQLiteDatabase("sync", dialect, new NodeSQLiteSession(client2, dialect, relations, { logger }), relations);
|
|
43298
|
+
db.$client = client2;
|
|
43299
|
+
return db;
|
|
43300
|
+
}
|
|
43301
|
+
function drizzle(...params) {
|
|
43302
|
+
if (params[0] === void 0 || typeof params[0] === "string") return construct(params[0] === void 0 ? new DatabaseSync(":memory:") : new DatabaseSync(params[0]), params[1]);
|
|
43303
|
+
const { connection, client: client2, ...config2 } = params[0];
|
|
43304
|
+
if (client2) return construct(client2, config2);
|
|
43305
|
+
if (typeof connection === "object") {
|
|
43306
|
+
const { path: path3, ...options } = connection;
|
|
43307
|
+
return construct(new DatabaseSync(path3 ?? ":memory:", options), config2);
|
|
43308
|
+
}
|
|
43309
|
+
return construct(new DatabaseSync(connection ?? ":memory:"), config2);
|
|
43310
|
+
}
|
|
43311
|
+
(function(_drizzle) {
|
|
43312
|
+
function mock(config2) {
|
|
43313
|
+
return construct({}, config2);
|
|
43314
|
+
}
|
|
43315
|
+
_drizzle.mock = mock;
|
|
43316
|
+
})(drizzle || (drizzle = {}));
|
|
43317
|
+
|
|
43318
|
+
// src/infra/local-sqlite-database.ts
|
|
43319
|
+
var LocalSqliteDatabase = class {
|
|
43320
|
+
orm;
|
|
43321
|
+
#sqlite;
|
|
43322
|
+
constructor(path3, label, migrations, pragmas = []) {
|
|
43323
|
+
mkdirSync2(dirname6(path3), { mode: 448, recursive: true });
|
|
43324
|
+
this.#sqlite = new DatabaseSync2(path3);
|
|
43325
|
+
chmodSync(path3, 384);
|
|
43326
|
+
try {
|
|
43327
|
+
for (const pragma of pragmas) {
|
|
43328
|
+
this.#sqlite.exec(pragma);
|
|
43329
|
+
}
|
|
43330
|
+
this.#migrate(label, migrations);
|
|
43331
|
+
this.orm = drizzle({ client: this.#sqlite });
|
|
43332
|
+
} catch (error62) {
|
|
43333
|
+
this.#sqlite.close();
|
|
43334
|
+
throw error62;
|
|
43335
|
+
}
|
|
43336
|
+
}
|
|
43337
|
+
#migrate = (label, migrations) => {
|
|
43338
|
+
const version2 = external_exports.object({ user_version: external_exports.number().int().nonnegative() }).parse(this.#sqlite.prepare("PRAGMA user_version").get()).user_version;
|
|
43339
|
+
if (version2 > migrations.length) {
|
|
43340
|
+
throw new Error(`The ${label} was created by a newer Mobius version`);
|
|
43341
|
+
}
|
|
43342
|
+
for (let index2 = version2; index2 < migrations.length; index2 += 1) {
|
|
43343
|
+
const migration = migrations[index2];
|
|
43344
|
+
if (migration === void 0) {
|
|
43345
|
+
throw new Error(`The ${label} migration is unavailable`);
|
|
43346
|
+
}
|
|
43347
|
+
this.transaction(() => {
|
|
43348
|
+
this.#sqlite.exec(migration.sql);
|
|
43349
|
+
this.#sqlite.exec(`PRAGMA user_version = ${index2 + 1}`);
|
|
43350
|
+
});
|
|
43351
|
+
}
|
|
43352
|
+
};
|
|
43353
|
+
transaction = (operation) => {
|
|
43354
|
+
this.#sqlite.exec("BEGIN IMMEDIATE");
|
|
43355
|
+
try {
|
|
43356
|
+
const result = operation();
|
|
43357
|
+
this.#sqlite.exec("COMMIT");
|
|
43358
|
+
return result;
|
|
43359
|
+
} catch (error62) {
|
|
43360
|
+
this.#sqlite.exec("ROLLBACK");
|
|
43361
|
+
throw error62;
|
|
43362
|
+
}
|
|
43363
|
+
};
|
|
43364
|
+
close = () => this.#sqlite.close();
|
|
43365
|
+
};
|
|
43366
|
+
|
|
43367
|
+
// src/local-databases.ts
|
|
43368
|
+
var openAcpSessionDatabase = (path3) => new LocalSqliteDatabase(path3, "ACP Session database", acpSessionStoreMigrations);
|
|
43369
|
+
var openSessionEventCacheV2Database = (path3) => new LocalSqliteDatabase(path3, "V2 Session event cache", sessionEventCacheMigrations, [
|
|
43370
|
+
"PRAGMA journal_mode = WAL",
|
|
43371
|
+
"PRAGMA synchronous = OFF"
|
|
43372
|
+
]);
|
|
43373
|
+
|
|
43178
43374
|
// src/native-sessions/codex-history.ts
|
|
43179
43375
|
import { spawn as spawn5 } from "node:child_process";
|
|
43180
43376
|
var responseSchema = external_exports.union([
|
|
@@ -43879,8 +44075,7 @@ var readCodexFullHistory = async (agent, cwd, nativeSessionId, signal, nativeTur
|
|
|
43879
44075
|
});
|
|
43880
44076
|
|
|
43881
44077
|
// src/native-sessions/service.ts
|
|
43882
|
-
import { randomUUID as
|
|
43883
|
-
import { basename as basename5 } from "node:path";
|
|
44078
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
43884
44079
|
var NativeSessionService = class {
|
|
43885
44080
|
#entries = /* @__PURE__ */ new Map();
|
|
43886
44081
|
#cursors = /* @__PURE__ */ new Map();
|
|
@@ -43924,64 +44119,6 @@ var NativeSessionService = class {
|
|
|
43924
44119
|
...await this.#activeTurn(command, options)
|
|
43925
44120
|
};
|
|
43926
44121
|
}
|
|
43927
|
-
if (command.action === "fork-recorded") {
|
|
43928
|
-
const source = this.#sessions.findSessions([command.sessionId])[0];
|
|
43929
|
-
if (source === void 0 || !source.prompted) {
|
|
43930
|
-
throw new AcpExecutionError(
|
|
43931
|
-
"The source conversation has no resumable native Agent session",
|
|
43932
|
-
{},
|
|
43933
|
-
"native_session_not_found"
|
|
43934
|
-
);
|
|
43935
|
-
}
|
|
43936
|
-
if (source.agentId !== command.agentId || source.cwd !== cwd || source.additionalDirectories.length !== additionalDirectories.length || source.additionalDirectories.some((path3, index) => path3 !== additionalDirectories[index])) {
|
|
43937
|
-
throw new AcpExecutionError(
|
|
43938
|
-
"The source conversation execution target does not match the fork request",
|
|
43939
|
-
{},
|
|
43940
|
-
"native_session_target_changed"
|
|
43941
|
-
);
|
|
43942
|
-
}
|
|
43943
|
-
if (source.lastTerminalCommandId !== command.throughCommandId) {
|
|
43944
|
-
throw new AcpExecutionError(
|
|
43945
|
-
"The selected Turn is no longer the source conversation head",
|
|
43946
|
-
{},
|
|
43947
|
-
"fork_point_stale"
|
|
43948
|
-
);
|
|
43949
|
-
}
|
|
43950
|
-
const opened2 = await this.#sessions.openNativeSession(
|
|
43951
|
-
{ ...options, sessionId: command.targetSessionId },
|
|
43952
|
-
{ kind: "fork", nativeSessionId: source.nativeSessionId }
|
|
43953
|
-
);
|
|
43954
|
-
signal.throwIfAborted();
|
|
43955
|
-
const directory = await this.#directories.list(this.#config.bindingId, command.directoryId, signal);
|
|
43956
|
-
const ready2 = {
|
|
43957
|
-
additionalDirectories: additionalDirectories.map((path3, index) => ({
|
|
43958
|
-
directoryId: command.additionalDirectoryIds[index] ?? command.directoryId,
|
|
43959
|
-
name: basename5(path3) || path3
|
|
43960
|
-
})),
|
|
43961
|
-
agentId: command.agentId,
|
|
43962
|
-
agentName: opened2.prepared.agentName,
|
|
43963
|
-
agentVersion: opened2.prepared.agentVersion,
|
|
43964
|
-
capabilities: opened2.prepared.capabilities,
|
|
43965
|
-
commands: opened2.prepared.commands,
|
|
43966
|
-
configOptions: opened2.prepared.configOptions,
|
|
43967
|
-
directoryId: command.directoryId,
|
|
43968
|
-
directoryLabel: directory.directoryLabel,
|
|
43969
|
-
kind: "session.ready",
|
|
43970
|
-
requestId: command.requestId,
|
|
43971
|
-
restored: true,
|
|
43972
|
-
sessionId: opened2.sessionId
|
|
43973
|
-
};
|
|
43974
|
-
this.record(command, "native_recorded_session_forked");
|
|
43975
|
-
return {
|
|
43976
|
-
action: "fork-recorded",
|
|
43977
|
-
kind: "native.session.result",
|
|
43978
|
-
ready: ready2,
|
|
43979
|
-
requestId: command.requestId,
|
|
43980
|
-
sessionId: command.sessionId,
|
|
43981
|
-
targetSessionId: command.targetSessionId,
|
|
43982
|
-
title: source.title || "Untitled session"
|
|
43983
|
-
};
|
|
43984
|
-
}
|
|
43985
44122
|
const prepared = await this.#sessions.prepareNativeSessionBrowser(options);
|
|
43986
44123
|
if (!prepared.capabilities.listSessions) {
|
|
43987
44124
|
throw new AcpExecutionError(
|
|
@@ -43997,7 +44134,7 @@ var NativeSessionService = class {
|
|
|
43997
44134
|
if (authorized === null) {
|
|
43998
44135
|
return null;
|
|
43999
44136
|
}
|
|
44000
|
-
const entryId = decodeIdentifier(
|
|
44137
|
+
const entryId = decodeIdentifier(randomUUID5());
|
|
44001
44138
|
if (this.#entries.size >= 5e3) {
|
|
44002
44139
|
this.#entries.clear();
|
|
44003
44140
|
}
|
|
@@ -44053,7 +44190,7 @@ var NativeSessionService = class {
|
|
|
44053
44190
|
"invalid_native_session_response"
|
|
44054
44191
|
);
|
|
44055
44192
|
}
|
|
44056
|
-
nextCursor = decodeIdentifier(
|
|
44193
|
+
nextCursor = decodeIdentifier(randomUUID5());
|
|
44057
44194
|
if (this.#cursors.size >= 500) {
|
|
44058
44195
|
this.#cursors.clear();
|
|
44059
44196
|
}
|
|
@@ -44116,25 +44253,6 @@ var NativeSessionService = class {
|
|
|
44116
44253
|
);
|
|
44117
44254
|
}
|
|
44118
44255
|
const target = await this.resolveTarget(command, options, selected);
|
|
44119
|
-
if (command.action === "delete") {
|
|
44120
|
-
if (!prepared.capabilities.deleteSession) {
|
|
44121
|
-
throw new AcpExecutionError(
|
|
44122
|
-
"This Agent does not support native session deletion",
|
|
44123
|
-
{},
|
|
44124
|
-
"native_session_unsupported"
|
|
44125
|
-
);
|
|
44126
|
-
}
|
|
44127
|
-
signal.throwIfAborted();
|
|
44128
|
-
this.record(command, "native_session_delete_authorized");
|
|
44129
|
-
const deletedSessionIds = await this.#sessions.deleteNativeSession(options, target.info.sessionId);
|
|
44130
|
-
this.record(command, "native_session_deleted");
|
|
44131
|
-
return {
|
|
44132
|
-
...envelope2,
|
|
44133
|
-
action: "delete",
|
|
44134
|
-
entryId: command.entryId,
|
|
44135
|
-
deletedSessionIds: deletedSessionIds.map(decodeIdentifier)
|
|
44136
|
-
};
|
|
44137
|
-
}
|
|
44138
44256
|
const action = command.action;
|
|
44139
44257
|
if (action === "import" && !prepared.capabilities.loadSession && !prepared.capabilities.resumeSession) {
|
|
44140
44258
|
throw new AcpExecutionError("This Agent cannot import native sessions", {}, "native_session_unsupported");
|
|
@@ -44250,7 +44368,7 @@ var NativeSessionService = class {
|
|
|
44250
44368
|
resolveTarget = async (command, options, selected) => {
|
|
44251
44369
|
let cursor = null;
|
|
44252
44370
|
const visited = /* @__PURE__ */ new Set();
|
|
44253
|
-
for (let
|
|
44371
|
+
for (let index2 = 0; index2 < 100; index2 += 1) {
|
|
44254
44372
|
const page = await this.#sessions.listNativeSessions(options, cursor);
|
|
44255
44373
|
const info = page.sessions.find((entry) => entry.sessionId === selected.nativeSessionId);
|
|
44256
44374
|
if (info !== void 0) {
|
|
@@ -44258,7 +44376,7 @@ var NativeSessionService = class {
|
|
|
44258
44376
|
if (target === null) {
|
|
44259
44377
|
throw new LocalAuthorizationError("The selected native session is not authorized");
|
|
44260
44378
|
}
|
|
44261
|
-
if (target.cwd !== selected.cwd || target.additionalDirectories.length !== selected.additionalDirectories.length || target.additionalDirectories.some((path3,
|
|
44379
|
+
if (target.cwd !== selected.cwd || target.additionalDirectories.length !== selected.additionalDirectories.length || target.additionalDirectories.some((path3, index3) => path3 !== selected.additionalDirectories[index3])) {
|
|
44262
44380
|
throw new AcpExecutionError(
|
|
44263
44381
|
"This session's directory changed. Refresh the list before continuing.",
|
|
44264
44382
|
{},
|
|
@@ -44297,7 +44415,7 @@ var NativeSessionService = class {
|
|
|
44297
44415
|
};
|
|
44298
44416
|
|
|
44299
44417
|
// src/relay-connection/daemon-operation-state.ts
|
|
44300
|
-
import { createHash as createHash5, randomUUID as
|
|
44418
|
+
import { createHash as createHash5, randomUUID as randomUUID6 } from "node:crypto";
|
|
44301
44419
|
var MAX_TERMINAL_RECEIPTS = 1024;
|
|
44302
44420
|
function isTerminal(state) {
|
|
44303
44421
|
return state === "succeeded" || state === "failed" || state === "cancelled";
|
|
@@ -44314,7 +44432,7 @@ var DaemonOperationState = class {
|
|
|
44314
44432
|
}
|
|
44315
44433
|
return { attemptId: existing.attemptId, commandId, kind: "duplicate", state: existing.state };
|
|
44316
44434
|
}
|
|
44317
|
-
const attemptId =
|
|
44435
|
+
const attemptId = randomUUID6();
|
|
44318
44436
|
this.#executions.set(commandId, { attemptId, commandHash, sessionId, state: "dispatching" });
|
|
44319
44437
|
return { attemptId, commandId, kind: "accepted", state: "dispatching" };
|
|
44320
44438
|
};
|
|
@@ -45144,7 +45262,7 @@ function createAgentSettingsDiscoveryHandler(dependencies) {
|
|
|
45144
45262
|
// src/artifacts/local-file-streamer.ts
|
|
45145
45263
|
import { createReadStream as createReadStream2 } from "node:fs";
|
|
45146
45264
|
import { realpath as realpath10, stat as stat9 } from "node:fs/promises";
|
|
45147
|
-
import { basename as
|
|
45265
|
+
import { basename as basename5, isAbsolute as isAbsolute10, normalize as normalize4, resolve as resolve7 } from "node:path";
|
|
45148
45266
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
45149
45267
|
var CHUNK_BYTES = 192 * 1024;
|
|
45150
45268
|
function requestedPath(value) {
|
|
@@ -45196,7 +45314,7 @@ async function streamLocalFile(command, send2, signal, workingDirectory, externa
|
|
|
45196
45314
|
kind: FILE_BEGIN_KIND,
|
|
45197
45315
|
mediaType: external?.mediaType ?? raster?.mimeType ?? "application/octet-stream",
|
|
45198
45316
|
modifiedAt: before.mtime.toISOString(),
|
|
45199
|
-
name: external?.name ?? (
|
|
45317
|
+
name: external?.name ?? (basename5(target) || "file"),
|
|
45200
45318
|
requestId: command.requestId,
|
|
45201
45319
|
sessionId: command.sessionId
|
|
45202
45320
|
});
|
|
@@ -45226,7 +45344,7 @@ async function streamLocalFile(command, send2, signal, workingDirectory, externa
|
|
|
45226
45344
|
}
|
|
45227
45345
|
|
|
45228
45346
|
// src/authorization/resolve-session-directories.ts
|
|
45229
|
-
import { basename as
|
|
45347
|
+
import { basename as basename6 } from "node:path";
|
|
45230
45348
|
var ResolvedSessionDirectories = class {
|
|
45231
45349
|
additionalDirectories;
|
|
45232
45350
|
additionalDirectoryEntries;
|
|
@@ -45251,7 +45369,7 @@ async function resolveSessionDirectories(directories, bindingId, directoryId2, a
|
|
|
45251
45369
|
additionalDirectories.push(directory);
|
|
45252
45370
|
additionalDirectoryEntries.push({
|
|
45253
45371
|
directoryId: additionalDirectoryId,
|
|
45254
|
-
name:
|
|
45372
|
+
name: basename6(directory)
|
|
45255
45373
|
});
|
|
45256
45374
|
}
|
|
45257
45375
|
return new ResolvedSessionDirectories(cwd, additionalDirectories, additionalDirectoryEntries);
|
|
@@ -45278,7 +45396,7 @@ async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, dir
|
|
|
45278
45396
|
const replay = await sessions.loadSessionEventsV2(loadOptions, command.eventLimit, command.cursor);
|
|
45279
45397
|
signal.throwIfAborted();
|
|
45280
45398
|
const events = replay.events.map(
|
|
45281
|
-
(event,
|
|
45399
|
+
(event, index2) => eventLogV2.event(command.sessionId, replay.startPosition + index2, event, "1970-01-01T00:00:00.000Z")
|
|
45282
45400
|
);
|
|
45283
45401
|
const tailCursor = events.at(-1)?.eventId ?? "";
|
|
45284
45402
|
audit.record({
|
|
@@ -45329,7 +45447,7 @@ async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, dir
|
|
|
45329
45447
|
}
|
|
45330
45448
|
|
|
45331
45449
|
// src/acp/session-config/apply-session-configuration.ts
|
|
45332
|
-
import { randomUUID as
|
|
45450
|
+
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
45333
45451
|
function invalidSessionConfiguration(message) {
|
|
45334
45452
|
return new AcpExecutionError(message, {}, "invalid_session_configuration");
|
|
45335
45453
|
}
|
|
@@ -45470,7 +45588,7 @@ async function applySessionConfigurationSelection(sessions, audit, options, sele
|
|
|
45470
45588
|
booleanValue: selection.booleanValue,
|
|
45471
45589
|
configId: selection.configId,
|
|
45472
45590
|
cwd,
|
|
45473
|
-
requestId: `cfg_${
|
|
45591
|
+
requestId: `cfg_${randomUUID7()}`,
|
|
45474
45592
|
sessionId,
|
|
45475
45593
|
signal,
|
|
45476
45594
|
value: selection.value,
|
|
@@ -46030,7 +46148,7 @@ async function executeSessionConfigure(publisher, socket, command, config2, dire
|
|
|
46030
46148
|
// src/native-sessions/handle-native-requests.ts
|
|
46031
46149
|
import { WebSocket as WebSocket4 } from "undici";
|
|
46032
46150
|
function createNativeSessionRequestHandler(dependencies) {
|
|
46033
|
-
const { audit, diagnostics, nativeSessions,
|
|
46151
|
+
const { audit, diagnostics, nativeSessions, signal, socket, timer } = dependencies;
|
|
46034
46152
|
const pending = /* @__PURE__ */ new Map();
|
|
46035
46153
|
const cancel = (command) => {
|
|
46036
46154
|
const request = pending.get(command.requestId);
|
|
@@ -46082,17 +46200,6 @@ function createNativeSessionRequestHandler(dependencies) {
|
|
|
46082
46200
|
}
|
|
46083
46201
|
operationSignal.throwIfAborted();
|
|
46084
46202
|
const result = await nativeSessions.execute(command, operationSignal);
|
|
46085
|
-
if (command.action === "fork-recorded" && result.action === "fork-recorded") {
|
|
46086
|
-
publisher.publishBatch(result.ready.sessionId, [
|
|
46087
|
-
result.ready,
|
|
46088
|
-
{
|
|
46089
|
-
kind: "session.forked",
|
|
46090
|
-
sessionId: result.ready.sessionId,
|
|
46091
|
-
sourceSessionId: command.sessionId,
|
|
46092
|
-
throughCommandId: command.throughCommandId
|
|
46093
|
-
}
|
|
46094
|
-
]);
|
|
46095
|
-
}
|
|
46096
46203
|
if (socket.readyState === WebSocket4.OPEN) {
|
|
46097
46204
|
send(socket, result);
|
|
46098
46205
|
}
|
|
@@ -46172,7 +46279,6 @@ function createDaemonCommandHandler({
|
|
|
46172
46279
|
audit,
|
|
46173
46280
|
diagnostics,
|
|
46174
46281
|
nativeSessions,
|
|
46175
|
-
publisher,
|
|
46176
46282
|
signal,
|
|
46177
46283
|
socket,
|
|
46178
46284
|
timer
|
|
@@ -46552,7 +46658,7 @@ function connectRelay(url2, signal) {
|
|
|
46552
46658
|
}
|
|
46553
46659
|
|
|
46554
46660
|
// src/relay-connection/liveness.ts
|
|
46555
|
-
import { randomUUID as
|
|
46661
|
+
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
46556
46662
|
var HEARTBEAT_ACK_TIMEOUT_MILLISECONDS = 1e4;
|
|
46557
46663
|
var HEARTBEAT_INTERVAL_MILLISECONDS = 2e4;
|
|
46558
46664
|
var RelayLivenessState = class {
|
|
@@ -46641,7 +46747,7 @@ var RelayConnectionLiveness = class {
|
|
|
46641
46747
|
}
|
|
46642
46748
|
throw new Error("Heartbeat was scheduled in an invalid state");
|
|
46643
46749
|
}
|
|
46644
|
-
const heartbeatId =
|
|
46750
|
+
const heartbeatId = randomUUID8();
|
|
46645
46751
|
this.#state = new AwaitingHeartbeatAckState(
|
|
46646
46752
|
heartbeatId,
|
|
46647
46753
|
this.#timer.schedule(this.#handleTimeout, HEARTBEAT_ACK_TIMEOUT_MILLISECONDS)
|
|
@@ -46933,7 +47039,7 @@ var SystemDaemonTimer = class {
|
|
|
46933
47039
|
var systemDaemonTimer = new SystemDaemonTimer();
|
|
46934
47040
|
|
|
46935
47041
|
// src/session-event-log-v2.ts
|
|
46936
|
-
import { createHash as createHash7, randomUUID as
|
|
47042
|
+
import { createHash as createHash7, randomUUID as randomUUID9 } from "node:crypto";
|
|
46937
47043
|
function promptContent(command) {
|
|
46938
47044
|
const content = [];
|
|
46939
47045
|
if (command.prompt.length > 0) {
|
|
@@ -46957,7 +47063,7 @@ function promptContent(command) {
|
|
|
46957
47063
|
}
|
|
46958
47064
|
return content;
|
|
46959
47065
|
}
|
|
46960
|
-
function
|
|
47066
|
+
function sessionEventV22(daemonGenerationId, sessionId, position, event, recordedAt) {
|
|
46961
47067
|
const sessionPrefix = createHash7("sha256").update(sessionId).digest("hex").slice(0, 16);
|
|
46962
47068
|
return {
|
|
46963
47069
|
eventId: `event-${daemonGenerationId}-${sessionPrefix}-${position.toString().padStart(16, "0")}`,
|
|
@@ -46969,11 +47075,12 @@ function sessionEventV2(daemonGenerationId, sessionId, position, event, recorded
|
|
|
46969
47075
|
};
|
|
46970
47076
|
}
|
|
46971
47077
|
var DaemonSessionEventLogV2 = class {
|
|
46972
|
-
daemonGenerationId
|
|
47078
|
+
daemonGenerationId;
|
|
46973
47079
|
#publisher;
|
|
46974
47080
|
#queued = /* @__PURE__ */ new Map();
|
|
46975
|
-
constructor(publisher) {
|
|
47081
|
+
constructor(publisher, daemonGenerationId = randomUUID9()) {
|
|
46976
47082
|
this.#publisher = publisher;
|
|
47083
|
+
this.daemonGenerationId = daemonGenerationId;
|
|
46977
47084
|
}
|
|
46978
47085
|
requested = (command) => {
|
|
46979
47086
|
this.#queued.set(command.commandId, {
|
|
@@ -46993,7 +47100,7 @@ var DaemonSessionEventLogV2 = class {
|
|
|
46993
47100
|
record = (sessionId, event, position) => {
|
|
46994
47101
|
this.#publisher.publishV2(this.event(sessionId, position, event, (/* @__PURE__ */ new Date()).toISOString()));
|
|
46995
47102
|
};
|
|
46996
|
-
event = (sessionId, position, event, recordedAt) =>
|
|
47103
|
+
event = (sessionId, position, event, recordedAt) => sessionEventV22(this.daemonGenerationId, sessionId, position, event, recordedAt);
|
|
46997
47104
|
queueChanged = (_sessionId) => void 0;
|
|
46998
47105
|
completed = (sessionId, commandId, _stopReason) => {
|
|
46999
47106
|
const request = this.#queued.get(commandId);
|
|
@@ -47060,7 +47167,7 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
|
|
|
47060
47167
|
{
|
|
47061
47168
|
agentId: agent.id,
|
|
47062
47169
|
kind: AGENT_INSTALL_REQUEST_KIND,
|
|
47063
|
-
requestId: `automatic-integration-${
|
|
47170
|
+
requestId: `automatic-integration-${randomUUID10()}`
|
|
47064
47171
|
},
|
|
47065
47172
|
signal
|
|
47066
47173
|
);
|
|
@@ -47078,13 +47185,24 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
47078
47185
|
publishCatalog: async (installationSignal) => await publishAgentCatalog(config2, installationSignal),
|
|
47079
47186
|
stateDirectory
|
|
47080
47187
|
});
|
|
47081
|
-
const
|
|
47082
|
-
|
|
47083
|
-
);
|
|
47188
|
+
const channelHash = createHash8("sha256").update(config2.channelId).digest("hex");
|
|
47189
|
+
const daemonGenerationId = randomUUID10();
|
|
47190
|
+
const sessionDatabase = openAcpSessionDatabase(join19(stateDirectory, "sessions", `${channelHash}.sqlite`));
|
|
47191
|
+
let eventsV2;
|
|
47192
|
+
try {
|
|
47193
|
+
eventsV2 = new CachedAcpSessionEventStoreV2(
|
|
47194
|
+
openSessionEventCacheV2Database(join19(stateDirectory, "sessions", `${channelHash}.events.sqlite`)),
|
|
47195
|
+
daemonGenerationId
|
|
47196
|
+
);
|
|
47197
|
+
} catch (error62) {
|
|
47198
|
+
sessionDatabase.close();
|
|
47199
|
+
throw error62;
|
|
47200
|
+
}
|
|
47201
|
+
const sessionStore = new SqliteAcpSessionStore(sessionDatabase, eventsV2);
|
|
47084
47202
|
await using externalContent = new LocalExternalContentStore(stateDirectory);
|
|
47085
47203
|
const operations = new DaemonOperationState();
|
|
47086
47204
|
const publisher = new DaemonSessionEventPublisher();
|
|
47087
|
-
const eventLogV2 = new DaemonSessionEventLogV2(publisher);
|
|
47205
|
+
const eventLogV2 = new DaemonSessionEventLogV2(publisher, daemonGenerationId);
|
|
47088
47206
|
const activeTurns = new DaemonTurnRegistry(operations);
|
|
47089
47207
|
const recordSessionEvent = (sessionId, event) => {
|
|
47090
47208
|
publisher.publish(sessionId, activeTurns.recordEvent(event));
|
|
@@ -47130,7 +47248,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
47130
47248
|
options2.signal
|
|
47131
47249
|
);
|
|
47132
47250
|
return cwd === options2.cwd && additionalDirectories.length === options2.additionalDirectories.length && additionalDirectories.every(
|
|
47133
|
-
(directory,
|
|
47251
|
+
(directory, index2) => directory === options2.additionalDirectories[index2]
|
|
47134
47252
|
);
|
|
47135
47253
|
});
|
|
47136
47254
|
}
|
|
@@ -47595,12 +47713,12 @@ var RuntimeSupervisor = class {
|
|
|
47595
47713
|
}
|
|
47596
47714
|
};
|
|
47597
47715
|
function pairingIdentifier(arguments_) {
|
|
47598
|
-
const indexes = arguments_.flatMap((argument,
|
|
47716
|
+
const indexes = arguments_.flatMap((argument, index3) => argument === "--pairing" ? [index3] : []);
|
|
47599
47717
|
if (indexes.length !== 1) {
|
|
47600
47718
|
return null;
|
|
47601
47719
|
}
|
|
47602
|
-
const
|
|
47603
|
-
return
|
|
47720
|
+
const index2 = indexes[0];
|
|
47721
|
+
return index2 === void 0 ? null : arguments_[index2 + 1] ?? null;
|
|
47604
47722
|
}
|
|
47605
47723
|
async function waitForReady(active, signal) {
|
|
47606
47724
|
if (active.status === "online") {
|
|
@@ -47895,9 +48013,9 @@ function formatPairTable(pairs) {
|
|
|
47895
48013
|
const headers = ["connection_id", "app_id", "runtime_id", "workspace", "status"];
|
|
47896
48014
|
const rows = pairs.map((pair) => [pair.connectionId, pair.appId, pair.runtimeId, pair.workspace, pair.status]);
|
|
47897
48015
|
const widths = headers.map(
|
|
47898
|
-
(header,
|
|
48016
|
+
(header, index2) => Math.max(header.length, ...rows.map((row) => row[index2]?.length ?? 0))
|
|
47899
48017
|
);
|
|
47900
|
-
const line = (row) => `| ${row.map((value,
|
|
48018
|
+
const line = (row) => `| ${row.map((value, index2) => value.padEnd(widths[index2] ?? value.length)).join(" | ")} |`;
|
|
47901
48019
|
const divider = `|-${widths.map((width) => "-".repeat(width)).join("-|-")}-|`;
|
|
47902
48020
|
return `${line(headers)}
|
|
47903
48021
|
${divider}
|