@moxt-ai/mobius 0.0.175 → 0.0.177
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/acp/agent-runtime-manager.d.ts +2 -1
- package/dist/acp/agent-runtime-manager.d.ts.map +1 -1
- package/dist/acp/agent-runtime-manager.js +11 -1
- package/dist/acp/agent-runtime-manager.js.map +1 -1
- package/dist/acp/agent-session.d.ts +3 -1
- package/dist/acp/agent-session.d.ts.map +1 -1
- package/dist/acp/agent-session.js +62 -28
- package/dist/acp/agent-session.js.map +1 -1
- package/dist/acp/codex/agent.d.ts.map +1 -1
- package/dist/acp/codex/agent.js +0 -12
- package/dist/acp/codex/agent.js.map +1 -1
- package/dist/acp/session-contracts.d.ts +3 -1
- package/dist/acp/session-contracts.d.ts.map +1 -1
- package/dist/acp/session-contracts.js.map +1 -1
- package/dist/acp/session-event-store-v2.d.ts +37 -0
- package/dist/acp/session-event-store-v2.d.ts.map +1 -0
- package/dist/acp/session-event-store-v2.js +199 -0
- package/dist/acp/session-event-store-v2.js.map +1 -0
- package/dist/acp/session-history.d.ts +3 -2
- package/dist/acp/session-history.d.ts.map +1 -1
- package/dist/acp/session-history.js +37 -41
- package/dist/acp/session-history.js.map +1 -1
- package/dist/acp/session-store.d.ts +7 -1
- package/dist/acp/session-store.d.ts.map +1 -1
- package/dist/acp/session-store.js +20 -37
- package/dist/acp/session-store.js.map +1 -1
- package/dist/cli.js +1167 -1216
- package/dist/cli.js.map +4 -4
- package/dist/daemon-command-handler.d.ts +1 -3
- package/dist/daemon-command-handler.d.ts.map +1 -1
- package/dist/daemon-command-handler.js +11 -9
- package/dist/daemon-command-handler.js.map +1 -1
- package/dist/daemon-command-results.d.ts +2 -3
- package/dist/daemon-command-results.d.ts.map +1 -1
- package/dist/daemon-command-results.js +4 -12
- package/dist/daemon-command-results.js.map +1 -1
- package/dist/daemon-prompt-executor.d.ts +2 -6
- package/dist/daemon-prompt-executor.d.ts.map +1 -1
- package/dist/daemon-prompt-executor.js +20 -73
- package/dist/daemon-prompt-executor.js.map +1 -1
- package/dist/daemon-session-commands.d.ts +2 -3
- package/dist/daemon-session-commands.d.ts.map +1 -1
- package/dist/daemon-session-commands.js +3 -15
- package/dist/daemon-session-commands.js.map +1 -1
- package/dist/generated/session-event-cache-migrations.d.ts +5 -0
- package/dist/generated/session-event-cache-migrations.d.ts.map +1 -0
- package/dist/generated/session-event-cache-migrations.js +9 -0
- package/dist/generated/session-event-cache-migrations.js.map +1 -0
- package/dist/index.js +1161 -1211
- package/dist/index.js.map +4 -4
- package/dist/infra/local-sqlite-database.d.ts +13 -0
- package/dist/infra/local-sqlite-database.d.ts.map +1 -0
- package/dist/infra/local-sqlite-database.js +57 -0
- package/dist/infra/local-sqlite-database.js.map +1 -0
- package/dist/local-databases.d.ts +4 -0
- package/dist/local-databases.d.ts.map +1 -0
- package/dist/local-databases.js +9 -0
- package/dist/local-databases.js.map +1 -0
- package/dist/relay-connection/run-relay-connection.d.ts.map +1 -1
- package/dist/relay-connection/run-relay-connection.js +0 -1
- package/dist/relay-connection/run-relay-connection.js.map +1 -1
- package/dist/relay-connection/session-event-publisher.d.ts +2 -3
- package/dist/relay-connection/session-event-publisher.d.ts.map +1 -1
- package/dist/relay-connection/session-event-publisher.js +8 -46
- package/dist/relay-connection/session-event-publisher.js.map +1 -1
- package/dist/run-daemon.d.ts.map +1 -1
- package/dist/run-daemon.js +18 -6
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.js +1149 -1199
- package/dist/runtime.js.map +4 -4
- package/dist/schema/session-event-cache/index.d.ts +2 -0
- package/dist/schema/session-event-cache/index.d.ts.map +1 -0
- package/dist/schema/session-event-cache/index.js +2 -0
- package/dist/schema/session-event-cache/index.js.map +1 -0
- package/dist/schema/session-event-cache/session-event-v2.d.ts +72 -0
- package/dist/schema/session-event-cache/session-event-v2.d.ts.map +1 -0
- package/dist/schema/session-event-cache/session-event-v2.js +11 -0
- package/dist/schema/session-event-cache/session-event-v2.js.map +1 -0
- package/dist/session-event-log-v2.d.ts +8 -6
- package/dist/session-event-log-v2.d.ts.map +1 -1
- package/dist/session-event-log-v2.js +85 -13
- package/dist/session-event-log-v2.js.map +1 -1
- package/package.json +2 -1
- package/dist/relay-connection/coalescing-agent-event-publisher.d.ts +0 -32
- package/dist/relay-connection/coalescing-agent-event-publisher.d.ts.map +0 -1
- package/dist/relay-connection/coalescing-agent-event-publisher.js +0 -116
- package/dist/relay-connection/coalescing-agent-event-publisher.js.map +0 -1
package/dist/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.177",
|
|
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, "~");
|
|
@@ -25912,14 +25913,6 @@ var CodexAcpAgent = class {
|
|
|
25912
25913
|
if (isCompactPrompt(context.params.prompt)) {
|
|
25913
25914
|
return await this.#compact(context.signal);
|
|
25914
25915
|
}
|
|
25915
|
-
const messageId = crypto.randomUUID();
|
|
25916
|
-
for (const content of context.params.prompt) {
|
|
25917
|
-
await this.#emit({
|
|
25918
|
-
content,
|
|
25919
|
-
messageId,
|
|
25920
|
-
sessionUpdate: "user_message_chunk"
|
|
25921
|
-
});
|
|
25922
|
-
}
|
|
25923
25916
|
return await this.#runTurn(promptInput(context.params.prompt), context.signal);
|
|
25924
25917
|
}).onRequest(
|
|
25925
25918
|
"_session/steering",
|
|
@@ -26405,10 +26398,6 @@ var CodexAcpAgent = class {
|
|
|
26405
26398
|
if (steering.length === 0) {
|
|
26406
26399
|
throw new AcpExecutionError("Codex received an empty steering request", {}, "invalid_request");
|
|
26407
26400
|
}
|
|
26408
|
-
const messageId = crypto.randomUUID();
|
|
26409
|
-
for (const block of steering) {
|
|
26410
|
-
await this.#emit({ content: block.content, messageId, sessionUpdate: "user_message_chunk" });
|
|
26411
|
-
}
|
|
26412
26401
|
const response = turnSteerResponseSchema.parse(
|
|
26413
26402
|
await this.#appServer.request(
|
|
26414
26403
|
"turn/steer",
|
|
@@ -27852,9 +27841,9 @@ function comparePrerelease(left, right) {
|
|
|
27852
27841
|
if (left.length === 0 || right.length === 0) {
|
|
27853
27842
|
return left.length === right.length ? 0 : left.length === 0 ? 1 : -1;
|
|
27854
27843
|
}
|
|
27855
|
-
for (let
|
|
27856
|
-
const leftPart = left[
|
|
27857
|
-
const rightPart = right[
|
|
27844
|
+
for (let index2 = 0; index2 < Math.max(left.length, right.length); index2 += 1) {
|
|
27845
|
+
const leftPart = left[index2];
|
|
27846
|
+
const rightPart = right[index2];
|
|
27858
27847
|
if (leftPart === void 0 || rightPart === void 0) {
|
|
27859
27848
|
return leftPart === rightPart ? 0 : leftPart === void 0 ? -1 : 1;
|
|
27860
27849
|
}
|
|
@@ -27879,8 +27868,8 @@ function compareAgentVersions(left, right) {
|
|
|
27879
27868
|
if (parsedLeft === null || parsedRight === null) {
|
|
27880
27869
|
return null;
|
|
27881
27870
|
}
|
|
27882
|
-
for (let
|
|
27883
|
-
const difference = (parsedLeft.core[
|
|
27871
|
+
for (let index2 = 0; index2 < Math.max(parsedLeft.core.length, parsedRight.core.length); index2 += 1) {
|
|
27872
|
+
const difference = (parsedLeft.core[index2] ?? 0) - (parsedRight.core[index2] ?? 0);
|
|
27884
27873
|
if (difference !== 0) {
|
|
27885
27874
|
return Math.sign(difference);
|
|
27886
27875
|
}
|
|
@@ -28624,12 +28613,12 @@ var DEFAULT_AGENT_EXECUTION_CONFIGURATION = Object.freeze({
|
|
|
28624
28613
|
});
|
|
28625
28614
|
var sessionConfigurationSelectionsSchema = external_exports.array(sessionConfigurationSelectionSchema).max(100).superRefine((selections, context) => {
|
|
28626
28615
|
const identifiers = /* @__PURE__ */ new Set();
|
|
28627
|
-
for (const [
|
|
28616
|
+
for (const [index2, selection] of selections.entries()) {
|
|
28628
28617
|
if (identifiers.has(selection.configId)) {
|
|
28629
28618
|
context.addIssue({
|
|
28630
28619
|
code: "custom",
|
|
28631
28620
|
message: "Session configuration identifiers must be unique",
|
|
28632
|
-
path: [
|
|
28621
|
+
path: [index2, "configId"]
|
|
28633
28622
|
});
|
|
28634
28623
|
}
|
|
28635
28624
|
identifiers.add(selection.configId);
|
|
@@ -28969,8 +28958,6 @@ function decodeValue(value, schema) {
|
|
|
28969
28958
|
}
|
|
28970
28959
|
return result.data;
|
|
28971
28960
|
}
|
|
28972
|
-
var decodeAgentDisplayContentValue = (value) => decodeValue(value, displayContentSchema);
|
|
28973
|
-
var decodeRecordedAgentContentValue = (value) => decodeValue(value, recordedDisplayContentSchema);
|
|
28974
28961
|
var decodePromptImagesValue = (value) => decodeValue(value, external_exports.array(promptImageSchema).max(8).readonly());
|
|
28975
28962
|
var decodePromptResourcesValue = (value) => decodeValue(value, external_exports.array(promptResourceSchema).max(16).readonly());
|
|
28976
28963
|
var decodeSessionConfigurationSelections = (value) => decodeValue(value, sessionConfigurationSelectionsSchema);
|
|
@@ -29012,20 +28999,13 @@ var encodeSessionReadyEvent = (message) => encode3(message, sessionReadyEventSch
|
|
|
29012
28999
|
var decodeSessionConfigureCommand = (encoded) => decode3(encoded, sessionConfigureCommandSchema);
|
|
29013
29000
|
var encodeSessionConfigureCommand = (message) => encode3(message, sessionConfigureCommandSchema);
|
|
29014
29001
|
var decodeSessionConfigUpdatedEvent = (encoded) => decode3(encoded, sessionConfigUpdatedEventSchema);
|
|
29015
|
-
var
|
|
29016
|
-
var decodeSessionCommandsUpdatedEvent = (encoded) => decode3(encoded, sessionCommandsUpdatedEventSchema);
|
|
29017
|
-
var decodeSessionInfoUpdatedEvent = (encoded) => decode3(encoded, sessionInfoUpdatedEventSchema);
|
|
29018
|
-
var decodeSessionPermissionRequestedEvent = (encoded) => decode3(encoded, sessionPermissionRequestedEventSchema);
|
|
29002
|
+
var encodeSessionConfigUpdatedEvent = (message) => encode3(message, sessionConfigUpdatedEventSchema);
|
|
29019
29003
|
var decodeSessionPermissionRespondCommand = (encoded) => decode3(encoded, sessionPermissionRespondCommandSchema);
|
|
29020
29004
|
var encodeSessionPermissionRespondCommand = (message) => encode3(message, sessionPermissionRespondCommandSchema);
|
|
29021
|
-
var decodeSessionPermissionResolvedEvent = (encoded) => decode3(encoded, sessionPermissionResolvedEventSchema);
|
|
29022
|
-
var decodeSessionElicitationRequestedEvent = (encoded) => decode3(encoded, sessionElicitationRequestedEventSchema);
|
|
29023
29005
|
var decodeSessionElicitationRespondCommand = (encoded) => decode3(encoded, sessionElicitationRespondCommandSchema);
|
|
29024
29006
|
var encodeSessionElicitationRespondCommand = (message) => encode3(message, sessionElicitationRespondCommandSchema);
|
|
29025
|
-
var decodeSessionElicitationResolvedEvent = (encoded) => decode3(encoded, sessionElicitationResolvedEventSchema);
|
|
29026
29007
|
var decodeSessionOperationFailedEvent = (encoded) => decode3(encoded, sessionOperationFailedEventSchema);
|
|
29027
29008
|
var encodeSessionOperationFailedEvent = (message) => encode3(message, sessionOperationFailedEventSchema);
|
|
29028
|
-
var decodeAgentContentEvent = (encoded) => decode3(encoded, agentContentEventSchema);
|
|
29029
29009
|
var decodeAgentInstallRequestCommand = (encoded) => decode3(encoded, agentInstallRequestCommandSchema);
|
|
29030
29010
|
var encodeAgentInstallRequestCommand = (message) => encode3(message, agentInstallRequestCommandSchema);
|
|
29031
29011
|
var decodeAgentInstallCancelCommand = (encoded) => decode3(encoded, agentInstallCancelCommandSchema);
|
|
@@ -29051,7 +29031,6 @@ var RUNTIME_HEARTBEAT_KIND = "runtime.heartbeat";
|
|
|
29051
29031
|
var RUNTIME_HEARTBEAT_ACK_KIND = "runtime.heartbeat.ack";
|
|
29052
29032
|
var RUNTIME_PING_KIND = "runtime.ping";
|
|
29053
29033
|
var RUNTIME_PONG_KIND = "runtime.pong";
|
|
29054
|
-
var SESSION_STARTED_KIND = "session.started";
|
|
29055
29034
|
var SESSION_QUEUED_KIND = "session.queued";
|
|
29056
29035
|
var AGENT_MESSAGE_DELTA_KIND = "agent.message.delta";
|
|
29057
29036
|
var AGENT_ACTIVITY_KIND = "agent.activity";
|
|
@@ -29061,8 +29040,6 @@ var AGENT_ACTIVITY_RECORDED_FIELD_LIMIT = 4e6;
|
|
|
29061
29040
|
var AGENT_ACTIVITY_RECORDED_DETAIL_LIMIT = 6e6;
|
|
29062
29041
|
var AGENT_ACTIVITY_LOCATION_LIMIT = 12;
|
|
29063
29042
|
var AGENT_ACTIVITY_LOCATION_LENGTH_LIMIT = 1024;
|
|
29064
|
-
var SESSION_COMPLETED_KIND = "session.completed";
|
|
29065
|
-
var SESSION_FAILED_KIND = "session.failed";
|
|
29066
29043
|
var SessionPromptDisposition = Object.freeze({
|
|
29067
29044
|
Queue: "queue",
|
|
29068
29045
|
Reject: "reject",
|
|
@@ -29073,23 +29050,6 @@ var SessionPromptDisposition = Object.freeze({
|
|
|
29073
29050
|
var DIRECTORY_IDENTIFIER_PATTERN2 = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/;
|
|
29074
29051
|
var MAX_PROMPT_LENGTH = 1e4;
|
|
29075
29052
|
var MAX_PROMPT_ATTACHMENT_LENGTH = 6e6;
|
|
29076
|
-
var MAX_EVENT_TEXT_LENGTH = 1e5;
|
|
29077
|
-
var ACTIVITY_TYPES = /* @__PURE__ */ new Set(["notice", "plan", "progress", "reasoning", "tool"]);
|
|
29078
|
-
var NARRATION_ACTIVITY_TYPES = /* @__PURE__ */ new Set(["progress", "reasoning"]);
|
|
29079
|
-
var ACTIVITY_STATUSES = /* @__PURE__ */ new Set(["pending", "running", "completed", "failed"]);
|
|
29080
|
-
var TOOL_KINDS = /* @__PURE__ */ new Set([
|
|
29081
|
-
"",
|
|
29082
|
-
"delete",
|
|
29083
|
-
"edit",
|
|
29084
|
-
"execute",
|
|
29085
|
-
"fetch",
|
|
29086
|
-
"move",
|
|
29087
|
-
"other",
|
|
29088
|
-
"read",
|
|
29089
|
-
"search",
|
|
29090
|
-
"switch_mode",
|
|
29091
|
-
"think"
|
|
29092
|
-
]);
|
|
29093
29053
|
var ProtocolMessageError = class extends Error {
|
|
29094
29054
|
code = "invalid_protocol_message";
|
|
29095
29055
|
constructor(message, options = {}) {
|
|
@@ -29139,13 +29099,6 @@ function readText(value, key, maximumLength) {
|
|
|
29139
29099
|
}
|
|
29140
29100
|
return field;
|
|
29141
29101
|
}
|
|
29142
|
-
function readAllowedString(value, key, allowedValues) {
|
|
29143
|
-
const field = readText(value, key, 64);
|
|
29144
|
-
if (!allowedValues.has(field)) {
|
|
29145
|
-
throw new ProtocolMessageError(`Invalid value field: ${key}`);
|
|
29146
|
-
}
|
|
29147
|
-
return field;
|
|
29148
|
-
}
|
|
29149
29102
|
function readPromptDisposition(value) {
|
|
29150
29103
|
const field = value["disposition"];
|
|
29151
29104
|
if (field === void 0 || field === SessionPromptDisposition.Reject) {
|
|
@@ -29159,32 +29112,6 @@ function readPromptDisposition(value) {
|
|
|
29159
29112
|
}
|
|
29160
29113
|
throw new ProtocolMessageError("Invalid value field: disposition");
|
|
29161
29114
|
}
|
|
29162
|
-
function readSequence(value, key) {
|
|
29163
|
-
const field = value[key];
|
|
29164
|
-
if (typeof field !== "number" || !Number.isSafeInteger(field) || field < 0) {
|
|
29165
|
-
throw new ProtocolMessageError(`Invalid integer field: ${key}`);
|
|
29166
|
-
}
|
|
29167
|
-
return field;
|
|
29168
|
-
}
|
|
29169
|
-
function readLocations(value) {
|
|
29170
|
-
const field = value["locations"];
|
|
29171
|
-
if (!Array.isArray(field) || field.length > AGENT_ACTIVITY_LOCATION_LIMIT) {
|
|
29172
|
-
throw new ProtocolMessageError("Invalid locations field");
|
|
29173
|
-
}
|
|
29174
|
-
const locations = [];
|
|
29175
|
-
const unique = /* @__PURE__ */ new Set();
|
|
29176
|
-
for (const location of field) {
|
|
29177
|
-
if (typeof location !== "string" || location.length === 0 || location.length > AGENT_ACTIVITY_LOCATION_LENGTH_LIMIT) {
|
|
29178
|
-
throw new ProtocolMessageError("Invalid activity location");
|
|
29179
|
-
}
|
|
29180
|
-
if (unique.has(location)) {
|
|
29181
|
-
throw new ProtocolMessageError("Duplicate activity location");
|
|
29182
|
-
}
|
|
29183
|
-
unique.add(location);
|
|
29184
|
-
locations.push(location);
|
|
29185
|
-
}
|
|
29186
|
-
return locations;
|
|
29187
|
-
}
|
|
29188
29115
|
function readDirectoryIdentifiers(value, key, maximumCount) {
|
|
29189
29116
|
const field = value[key];
|
|
29190
29117
|
if (!Array.isArray(field) || field.length > maximumCount) {
|
|
@@ -29201,54 +29128,6 @@ function readDirectoryIdentifiers(value, key, maximumCount) {
|
|
|
29201
29128
|
}
|
|
29202
29129
|
return identifiers;
|
|
29203
29130
|
}
|
|
29204
|
-
function readActivityContent(value) {
|
|
29205
|
-
const field = value["content"];
|
|
29206
|
-
if (!Array.isArray(field) || field.length > 100) {
|
|
29207
|
-
throw new ProtocolMessageError("Invalid activity content field");
|
|
29208
|
-
}
|
|
29209
|
-
return field.map((entry) => decodeAgentDisplayContentValue(entry));
|
|
29210
|
-
}
|
|
29211
|
-
function readActivityDetail(value) {
|
|
29212
|
-
const field = value["detail"];
|
|
29213
|
-
if (!isRecord5(field)) {
|
|
29214
|
-
throw new ProtocolMessageError("Invalid activity detail field");
|
|
29215
|
-
}
|
|
29216
|
-
const kind = readString2(field, "kind", 32);
|
|
29217
|
-
if (kind === "available") {
|
|
29218
|
-
return {
|
|
29219
|
-
artifactId: readIdentifier(field, "artifactId"),
|
|
29220
|
-
kind
|
|
29221
|
-
};
|
|
29222
|
-
}
|
|
29223
|
-
if (kind === "unrecorded") {
|
|
29224
|
-
return { kind };
|
|
29225
|
-
}
|
|
29226
|
-
if (kind === "truncated") {
|
|
29227
|
-
const capturedBytes = readSequence(field, "capturedBytes");
|
|
29228
|
-
const originalBytes = readSequence(field, "originalBytes");
|
|
29229
|
-
if (capturedBytes > originalBytes) {
|
|
29230
|
-
throw new ProtocolMessageError("Invalid truncated activity detail size");
|
|
29231
|
-
}
|
|
29232
|
-
return { capturedBytes, kind, originalBytes };
|
|
29233
|
-
}
|
|
29234
|
-
if (kind === "recorded") {
|
|
29235
|
-
const contentValue = field["content"];
|
|
29236
|
-
if (!Array.isArray(contentValue) || contentValue.length > 100) {
|
|
29237
|
-
throw new ProtocolMessageError("Invalid recorded activity content");
|
|
29238
|
-
}
|
|
29239
|
-
const detail = {
|
|
29240
|
-
content: contentValue.map((entry) => decodeRecordedAgentContentValue(entry)),
|
|
29241
|
-
input: readText(field, "input", AGENT_ACTIVITY_RECORDED_FIELD_LIMIT),
|
|
29242
|
-
kind,
|
|
29243
|
-
output: readText(field, "output", AGENT_ACTIVITY_RECORDED_FIELD_LIMIT)
|
|
29244
|
-
};
|
|
29245
|
-
if (JSON.stringify(detail).length > AGENT_ACTIVITY_RECORDED_DETAIL_LIMIT) {
|
|
29246
|
-
throw new ProtocolMessageError("Recorded activity detail is too large");
|
|
29247
|
-
}
|
|
29248
|
-
return detail;
|
|
29249
|
-
}
|
|
29250
|
-
throw new ProtocolMessageError("Invalid activity detail availability");
|
|
29251
|
-
}
|
|
29252
29131
|
function readIdentifier(value, key) {
|
|
29253
29132
|
try {
|
|
29254
29133
|
return decodeIdentifier(value[key]);
|
|
@@ -29373,82 +29252,6 @@ function decodeRuntimePongEvent(encoded) {
|
|
|
29373
29252
|
assertKind(value, RUNTIME_PONG_KIND);
|
|
29374
29253
|
return { kind: RUNTIME_PONG_KIND, requestId: readIdentifier(value, "requestId") };
|
|
29375
29254
|
}
|
|
29376
|
-
function decodeSessionStartedEvent(encoded) {
|
|
29377
|
-
const value = parseJson2(encoded);
|
|
29378
|
-
assertKind(value, SESSION_STARTED_KIND);
|
|
29379
|
-
const sequence = readSequence(value, "sequence");
|
|
29380
|
-
if (sequence !== 0) {
|
|
29381
|
-
throw new ProtocolMessageError("Invalid live start sequence");
|
|
29382
|
-
}
|
|
29383
|
-
return {
|
|
29384
|
-
commandId: readIdentifier(value, "commandId"),
|
|
29385
|
-
epoch: readIdentifier(value, "epoch"),
|
|
29386
|
-
kind: SESSION_STARTED_KIND,
|
|
29387
|
-
attemptId: readIdentifier(value, "attemptId"),
|
|
29388
|
-
prompt: readText(value, "prompt", MAX_PROMPT_LENGTH),
|
|
29389
|
-
sequence,
|
|
29390
|
-
sessionId: readIdentifier(value, "sessionId")
|
|
29391
|
-
};
|
|
29392
|
-
}
|
|
29393
|
-
function decodeAgentMessageDeltaEvent(encoded) {
|
|
29394
|
-
const value = parseJson2(encoded);
|
|
29395
|
-
assertKind(value, AGENT_MESSAGE_DELTA_KIND);
|
|
29396
|
-
const sequence = readSequence(value, "sequence");
|
|
29397
|
-
if (sequence === 0) {
|
|
29398
|
-
throw new ProtocolMessageError("Invalid live sequence");
|
|
29399
|
-
}
|
|
29400
|
-
return {
|
|
29401
|
-
commandId: readIdentifier(value, "commandId"),
|
|
29402
|
-
epoch: readIdentifier(value, "epoch"),
|
|
29403
|
-
kind: AGENT_MESSAGE_DELTA_KIND,
|
|
29404
|
-
messageId: value["messageId"] === void 0 ? "" : readText(value, "messageId", 255),
|
|
29405
|
-
sequence,
|
|
29406
|
-
sessionId: readIdentifier(value, "sessionId"),
|
|
29407
|
-
text: readString2(value, "text", MAX_EVENT_TEXT_LENGTH)
|
|
29408
|
-
};
|
|
29409
|
-
}
|
|
29410
|
-
function decodeAgentActivityEvent(encoded) {
|
|
29411
|
-
const value = parseJson2(encoded);
|
|
29412
|
-
assertKind(value, AGENT_ACTIVITY_KIND);
|
|
29413
|
-
return {
|
|
29414
|
-
activityId: readIdentifier(value, "activityId"),
|
|
29415
|
-
activityType: readAllowedString(value, "activityType", ACTIVITY_TYPES),
|
|
29416
|
-
commandId: readIdentifier(value, "commandId"),
|
|
29417
|
-
content: readActivityContent(value),
|
|
29418
|
-
detail: readActivityDetail(value),
|
|
29419
|
-
input: readText(value, "input", AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
29420
|
-
kind: AGENT_ACTIVITY_KIND,
|
|
29421
|
-
locations: readLocations(value),
|
|
29422
|
-
name: readText(value, "name", 128),
|
|
29423
|
-
output: readText(value, "output", AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
29424
|
-
sequence: readSequence(value, "sequence"),
|
|
29425
|
-
sessionId: readIdentifier(value, "sessionId"),
|
|
29426
|
-
status: readAllowedString(value, "status", ACTIVITY_STATUSES),
|
|
29427
|
-
title: readString2(value, "title", 500),
|
|
29428
|
-
toolKind: readAllowedString(value, "toolKind", TOOL_KINDS)
|
|
29429
|
-
};
|
|
29430
|
-
}
|
|
29431
|
-
function decodeSessionCompletedEvent(encoded) {
|
|
29432
|
-
const value = parseJson2(encoded);
|
|
29433
|
-
assertKind(value, SESSION_COMPLETED_KIND);
|
|
29434
|
-
return {
|
|
29435
|
-
commandId: readIdentifier(value, "commandId"),
|
|
29436
|
-
kind: SESSION_COMPLETED_KIND,
|
|
29437
|
-
sessionId: readIdentifier(value, "sessionId"),
|
|
29438
|
-
stopReason: readString2(value, "stopReason", 64)
|
|
29439
|
-
};
|
|
29440
|
-
}
|
|
29441
|
-
function decodeSessionFailedEvent(encoded) {
|
|
29442
|
-
const value = parseJson2(encoded);
|
|
29443
|
-
assertKind(value, SESSION_FAILED_KIND);
|
|
29444
|
-
return {
|
|
29445
|
-
code: readIdentifier(value, "code"),
|
|
29446
|
-
commandId: readIdentifier(value, "commandId"),
|
|
29447
|
-
kind: SESSION_FAILED_KIND,
|
|
29448
|
-
message: readString2(value, "message", 500),
|
|
29449
|
-
sessionId: readIdentifier(value, "sessionId")
|
|
29450
|
-
};
|
|
29451
|
-
}
|
|
29452
29255
|
function encodeSessionPromptCommand(message) {
|
|
29453
29256
|
return JSON.stringify(decodeSessionPromptCommand(JSON.stringify(message)));
|
|
29454
29257
|
}
|
|
@@ -29476,19 +29279,6 @@ function encodeRuntimePingCommand(message) {
|
|
|
29476
29279
|
function encodeRuntimePongEvent(message) {
|
|
29477
29280
|
return JSON.stringify(decodeRuntimePongEvent(JSON.stringify(message)));
|
|
29478
29281
|
}
|
|
29479
|
-
function decodeAgentActivityNarrationEvent(encoded) {
|
|
29480
|
-
const value = parseJson2(encoded);
|
|
29481
|
-
assertKind(value, AGENT_ACTIVITY_NARRATION_KIND);
|
|
29482
|
-
return {
|
|
29483
|
-
activityId: readIdentifier(value, "activityId"),
|
|
29484
|
-
activityType: readAllowedString(value, "activityType", NARRATION_ACTIVITY_TYPES),
|
|
29485
|
-
commandId: readIdentifier(value, "commandId"),
|
|
29486
|
-
kind: AGENT_ACTIVITY_NARRATION_KIND,
|
|
29487
|
-
sequence: readSequence(value, "sequence"),
|
|
29488
|
-
sessionId: readIdentifier(value, "sessionId"),
|
|
29489
|
-
text: readText(value, "text", MAX_EVENT_TEXT_LENGTH)
|
|
29490
|
-
};
|
|
29491
|
-
}
|
|
29492
29282
|
|
|
29493
29283
|
// ../protocol/src/session-history.ts
|
|
29494
29284
|
var SESSION_HISTORY_CHARACTER_LIMIT = 256e3;
|
|
@@ -30057,6 +29847,11 @@ var acpSessionUpdateV2Schema = external_exports.discriminatedUnion("sessionUpdat
|
|
|
30057
29847
|
}).readonly()
|
|
30058
29848
|
]);
|
|
30059
29849
|
var lifecycleBase = { commandId: identifierStringSchema };
|
|
29850
|
+
var promptExecutionContextV2Schema = external_exports.object({
|
|
29851
|
+
agentId: identifierStringSchema,
|
|
29852
|
+
directoryId: shortString,
|
|
29853
|
+
additionalDirectoryIds: external_exports.array(identifierStringSchema).max(16).readonly()
|
|
29854
|
+
}).readonly();
|
|
30060
29855
|
var lifecycleMetadataV2Schema = external_exports.discriminatedUnion("kind", [
|
|
30061
29856
|
external_exports.object({ kind: external_exports.literal("session.queue.changed") }).readonly(),
|
|
30062
29857
|
external_exports.object({ event: sessionPermissionRequestedEventSchema, kind: external_exports.literal("session.permission.requested") }).readonly(),
|
|
@@ -30066,7 +29861,8 @@ var lifecycleMetadataV2Schema = external_exports.discriminatedUnion("kind", [
|
|
|
30066
29861
|
external_exports.object({
|
|
30067
29862
|
...lifecycleBase,
|
|
30068
29863
|
content: external_exports.array(contentBlockV2Schema).min(1).max(100).readonly(),
|
|
30069
|
-
kind: external_exports.literal("prompt.requested")
|
|
29864
|
+
kind: external_exports.literal("prompt.requested"),
|
|
29865
|
+
context: promptExecutionContextV2Schema.optional()
|
|
30070
29866
|
}).readonly(),
|
|
30071
29867
|
external_exports.object({ ...lifecycleBase, attemptId: identifierStringSchema, epoch: identifierStringSchema, kind: external_exports.literal("prompt.started") }).readonly(),
|
|
30072
29868
|
external_exports.object({ ...lifecycleBase, kind: external_exports.literal("prompt.completed"), stopReason: shortString }).readonly(),
|
|
@@ -30130,12 +29926,12 @@ var sessionExportV2Schema = external_exports.object({
|
|
|
30130
29926
|
}).readonly().superRefine((session, context) => {
|
|
30131
29927
|
let previousPosition = 0n;
|
|
30132
29928
|
const eventIds = /* @__PURE__ */ new Set();
|
|
30133
|
-
for (const [
|
|
29929
|
+
for (const [index2, event] of session.events.entries()) {
|
|
30134
29930
|
if (event.sessionId !== session.sessionId) {
|
|
30135
29931
|
context.addIssue({
|
|
30136
29932
|
code: "custom",
|
|
30137
29933
|
message: "Exported event belongs to a different Session",
|
|
30138
|
-
path: ["events",
|
|
29934
|
+
path: ["events", index2, "sessionId"]
|
|
30139
29935
|
});
|
|
30140
29936
|
}
|
|
30141
29937
|
const position = BigInt(event.position);
|
|
@@ -30143,14 +29939,14 @@ var sessionExportV2Schema = external_exports.object({
|
|
|
30143
29939
|
context.addIssue({
|
|
30144
29940
|
code: "custom",
|
|
30145
29941
|
message: "Exported events are not in increasing position order",
|
|
30146
|
-
path: ["events",
|
|
29942
|
+
path: ["events", index2, "position"]
|
|
30147
29943
|
});
|
|
30148
29944
|
}
|
|
30149
29945
|
if (eventIds.has(event.eventId)) {
|
|
30150
29946
|
context.addIssue({
|
|
30151
29947
|
code: "custom",
|
|
30152
29948
|
message: "Exported event identities are not unique",
|
|
30153
|
-
path: ["events",
|
|
29949
|
+
path: ["events", index2, "eventId"]
|
|
30154
29950
|
});
|
|
30155
29951
|
}
|
|
30156
29952
|
previousPosition = position;
|
|
@@ -30201,98 +29997,11 @@ function decode5(value, schema) {
|
|
|
30201
29997
|
function encode4(value, schema) {
|
|
30202
29998
|
return JSON.stringify(decode5(value, schema));
|
|
30203
29999
|
}
|
|
30000
|
+
var decodeSessionEventV2 = (value) => decode5(value, sessionEventV2Schema);
|
|
30204
30001
|
var decodeSessionEventEnvelopeV2 = (value) => decode5(value, sessionEventEnvelopeV2Schema);
|
|
30205
30002
|
var encodeSessionEventEnvelopeV2 = (value) => encode4(value, sessionEventEnvelopeV2Schema);
|
|
30206
30003
|
var decodeAcpSessionUpdateV2 = (value) => decode5(value, acpSessionUpdateV2Schema);
|
|
30207
30004
|
|
|
30208
|
-
// ../protocol/src/session-events.ts
|
|
30209
|
-
var SESSION_EVENT_KIND = "session.event";
|
|
30210
|
-
var SESSION_FORKED_KIND = "session.forked";
|
|
30211
|
-
var MAX_RECORDED_EVENT_LENGTH = 8 * 1024 * 1024;
|
|
30212
|
-
var sessionEventEnvelopeSchema = external_exports.object({
|
|
30213
|
-
kind: external_exports.literal(SESSION_EVENT_KIND),
|
|
30214
|
-
payload: external_exports.string().min(2).max(MAX_RECORDED_EVENT_LENGTH),
|
|
30215
|
-
sessionId: identifierStringSchema
|
|
30216
|
-
}).readonly();
|
|
30217
|
-
var SESSION_QUEUE_CHANGED_KIND = "session.queue.changed";
|
|
30218
|
-
var sessionQueueChangedSchema = external_exports.object({ kind: external_exports.literal(SESSION_QUEUE_CHANGED_KIND), sessionId: identifierStringSchema }).readonly();
|
|
30219
|
-
var sessionForkedSchema = external_exports.object({
|
|
30220
|
-
kind: external_exports.literal(SESSION_FORKED_KIND),
|
|
30221
|
-
sessionId: identifierStringSchema,
|
|
30222
|
-
sourceSessionId: identifierStringSchema,
|
|
30223
|
-
throughCommandId: identifierStringSchema
|
|
30224
|
-
}).readonly();
|
|
30225
|
-
function decode6(encoded, schema) {
|
|
30226
|
-
let value;
|
|
30227
|
-
try {
|
|
30228
|
-
value = JSON.parse(encoded);
|
|
30229
|
-
} catch (cause) {
|
|
30230
|
-
throw new ProtocolMessageError("Message is not valid JSON", { cause });
|
|
30231
|
-
}
|
|
30232
|
-
const decoded = schema.safeParse(value);
|
|
30233
|
-
if (!decoded.success) {
|
|
30234
|
-
throw new ProtocolMessageError("Message does not match its schema", {
|
|
30235
|
-
cause: decoded.error
|
|
30236
|
-
});
|
|
30237
|
-
}
|
|
30238
|
-
return decoded.data;
|
|
30239
|
-
}
|
|
30240
|
-
var encode5 = (message, schema) => {
|
|
30241
|
-
const decoded = schema.safeParse(message);
|
|
30242
|
-
if (!decoded.success) {
|
|
30243
|
-
throw new ProtocolMessageError("Message does not match its schema", {
|
|
30244
|
-
cause: decoded.error
|
|
30245
|
-
});
|
|
30246
|
-
}
|
|
30247
|
-
return JSON.stringify(decoded.data);
|
|
30248
|
-
};
|
|
30249
|
-
var decodeSessionEventEnvelope = (encoded) => decode6(encoded, sessionEventEnvelopeSchema);
|
|
30250
|
-
var encodeSessionEventEnvelope = (message) => encode5(message, sessionEventEnvelopeSchema);
|
|
30251
|
-
function decodeRecordedSessionEvent(encoded) {
|
|
30252
|
-
const kind = decodeMessageKind(encoded);
|
|
30253
|
-
switch (kind) {
|
|
30254
|
-
case SESSION_QUEUE_CHANGED_KIND:
|
|
30255
|
-
return decode6(encoded, sessionQueueChangedSchema);
|
|
30256
|
-
case SESSION_FORKED_KIND:
|
|
30257
|
-
return decode6(encoded, sessionForkedSchema);
|
|
30258
|
-
case AGENT_ACTIVITY_KIND:
|
|
30259
|
-
return decodeAgentActivityEvent(encoded);
|
|
30260
|
-
case AGENT_ACTIVITY_NARRATION_KIND:
|
|
30261
|
-
return decodeAgentActivityNarrationEvent(encoded);
|
|
30262
|
-
case AGENT_CONTENT_KIND:
|
|
30263
|
-
return decodeAgentContentEvent(encoded);
|
|
30264
|
-
case AGENT_MESSAGE_DELTA_KIND:
|
|
30265
|
-
return decodeAgentMessageDeltaEvent(encoded);
|
|
30266
|
-
case SESSION_COMMANDS_UPDATED_KIND:
|
|
30267
|
-
return decodeSessionCommandsUpdatedEvent(encoded);
|
|
30268
|
-
case SESSION_COMPLETED_KIND:
|
|
30269
|
-
return decodeSessionCompletedEvent(encoded);
|
|
30270
|
-
case SESSION_CONFIG_UPDATED_KIND:
|
|
30271
|
-
return decodeSessionConfigUpdatedEvent(encoded);
|
|
30272
|
-
case SESSION_ELICITATION_REQUESTED_KIND:
|
|
30273
|
-
return decodeSessionElicitationRequestedEvent(encoded);
|
|
30274
|
-
case SESSION_ELICITATION_RESOLVED_KIND:
|
|
30275
|
-
return decodeSessionElicitationResolvedEvent(encoded);
|
|
30276
|
-
case SESSION_FAILED_KIND:
|
|
30277
|
-
return decodeSessionFailedEvent(encoded);
|
|
30278
|
-
case SESSION_INFO_UPDATED_KIND:
|
|
30279
|
-
return decodeSessionInfoUpdatedEvent(encoded);
|
|
30280
|
-
case SESSION_PERMISSION_REQUESTED_KIND:
|
|
30281
|
-
return decodeSessionPermissionRequestedEvent(encoded);
|
|
30282
|
-
case SESSION_PERMISSION_RESOLVED_KIND:
|
|
30283
|
-
return decodeSessionPermissionResolvedEvent(encoded);
|
|
30284
|
-
case SESSION_READY_KIND:
|
|
30285
|
-
return decodeSessionReadyEvent(encoded);
|
|
30286
|
-
case SESSION_STARTED_KIND:
|
|
30287
|
-
return decodeSessionStartedEvent(encoded);
|
|
30288
|
-
case SESSION_USAGE_UPDATED_KIND:
|
|
30289
|
-
return decodeSessionUsageUpdatedEvent(encoded);
|
|
30290
|
-
default:
|
|
30291
|
-
throw new UnsupportedProtocolMessageKindError("daemon-to-service", kind);
|
|
30292
|
-
}
|
|
30293
|
-
}
|
|
30294
|
-
var encodeRecordedSessionEvent = (event) => JSON.stringify(decodeRecordedSessionEvent(JSON.stringify(event)));
|
|
30295
|
-
|
|
30296
30005
|
// ../protocol/src/session-live-history.ts
|
|
30297
30006
|
var SESSION_LIVE_HISTORY_V2_PAGE_LOAD_KIND = "session.live-history.v2.page.load";
|
|
30298
30007
|
var SESSION_LIVE_HISTORY_V2_PAGE_LOADED_KIND = "session.live-history.v2.page.loaded";
|
|
@@ -30314,7 +30023,7 @@ var sessionLiveHistoryV2PageLoadedSchema = external_exports.object({
|
|
|
30314
30023
|
requestId: identifierStringSchema,
|
|
30315
30024
|
sessionId: identifierStringSchema
|
|
30316
30025
|
}).readonly();
|
|
30317
|
-
function
|
|
30026
|
+
function decode6(schema, encoded) {
|
|
30318
30027
|
try {
|
|
30319
30028
|
const value = JSON.parse(encoded);
|
|
30320
30029
|
return schema.parse(value);
|
|
@@ -30322,8 +30031,8 @@ function decode7(schema, encoded) {
|
|
|
30322
30031
|
throw new ProtocolMessageError("Invalid live Session history message", { cause });
|
|
30323
30032
|
}
|
|
30324
30033
|
}
|
|
30325
|
-
var decodeSessionLiveHistoryV2PageLoad = (encoded) =>
|
|
30326
|
-
var decodeSessionLiveHistoryV2PageLoaded = (encoded) =>
|
|
30034
|
+
var decodeSessionLiveHistoryV2PageLoad = (encoded) => decode6(sessionLiveHistoryV2PageLoadSchema, encoded);
|
|
30035
|
+
var decodeSessionLiveHistoryV2PageLoaded = (encoded) => decode6(sessionLiveHistoryV2PageLoadedSchema, encoded);
|
|
30327
30036
|
var encodeSessionLiveHistoryV2PageLoad = (value) => JSON.stringify(sessionLiveHistoryV2PageLoadSchema.parse(value));
|
|
30328
30037
|
var encodeSessionLiveHistoryV2PageLoaded = (value) => JSON.stringify(sessionLiveHistoryV2PageLoadedSchema.parse(value));
|
|
30329
30038
|
|
|
@@ -30437,6 +30146,11 @@ function decodeServiceToDaemonMessage(encoded) {
|
|
|
30437
30146
|
return signature.decoder(encoded);
|
|
30438
30147
|
}
|
|
30439
30148
|
var daemonToServiceSignatures = {
|
|
30149
|
+
[SESSION_CONFIG_UPDATED_KIND]: defineMessageSignature(
|
|
30150
|
+
SESSION_CONFIG_UPDATED_KIND,
|
|
30151
|
+
encodeSessionConfigUpdatedEvent,
|
|
30152
|
+
decodeSessionConfigUpdatedEvent
|
|
30153
|
+
),
|
|
30440
30154
|
[AGENT_INSTALL_CANCELLED_KIND]: defineMessageSignature(
|
|
30441
30155
|
AGENT_INSTALL_CANCELLED_KIND,
|
|
30442
30156
|
encodeAgentInstallCancelledEvent,
|
|
@@ -30507,11 +30221,6 @@ var daemonToServiceSignatures = {
|
|
|
30507
30221
|
decodeRuntimeHeartbeatEvent
|
|
30508
30222
|
),
|
|
30509
30223
|
[RUNTIME_PONG_KIND]: defineMessageSignature(RUNTIME_PONG_KIND, encodeRuntimePongEvent, decodeRuntimePongEvent),
|
|
30510
|
-
[SESSION_EVENT_KIND]: defineMessageSignature(
|
|
30511
|
-
SESSION_EVENT_KIND,
|
|
30512
|
-
encodeSessionEventEnvelope,
|
|
30513
|
-
decodeSessionEventEnvelope
|
|
30514
|
-
),
|
|
30515
30224
|
[SESSION_EVENT_V2_KIND]: defineMessageSignature(
|
|
30516
30225
|
SESSION_EVENT_V2_KIND,
|
|
30517
30226
|
encodeSessionEventEnvelopeV2,
|
|
@@ -30946,16 +30655,16 @@ var RuntimeInstallationStore = class _RuntimeInstallationStore {
|
|
|
30946
30655
|
};
|
|
30947
30656
|
#readConnectionForChannel = async (channelId, signal) => {
|
|
30948
30657
|
const normalizedChannelId = validateIdentifier(channelId, "invalid_channel_id");
|
|
30949
|
-
const
|
|
30658
|
+
const index2 = decodeChannelIndex(
|
|
30950
30659
|
await readJsonFile(this.channelIndexPath(normalizedChannelId), signal, "connection_not_found")
|
|
30951
30660
|
);
|
|
30952
|
-
if (
|
|
30661
|
+
if (index2.applicationId !== this.applicationId || index2.installationId !== this.installationId || index2.channelId !== normalizedChannelId) {
|
|
30953
30662
|
throw new RuntimeInstallationStoreError(
|
|
30954
30663
|
"connection_owner_mismatch",
|
|
30955
30664
|
"The saved Runtime connection belongs to another installation"
|
|
30956
30665
|
);
|
|
30957
30666
|
}
|
|
30958
|
-
return await this.readConnection(
|
|
30667
|
+
return await this.readConnection(index2.connectionId, signal);
|
|
30959
30668
|
};
|
|
30960
30669
|
saveConnection = async (input2, signal) => {
|
|
30961
30670
|
const stored = new VerifiedRuntimeConnection(
|
|
@@ -31150,16 +30859,16 @@ function hasExactKeys2(value, expectedKeys) {
|
|
|
31150
30859
|
}
|
|
31151
30860
|
function readSingleOption(arguments_, option) {
|
|
31152
30861
|
const values = [];
|
|
31153
|
-
for (let
|
|
31154
|
-
if (arguments_[
|
|
30862
|
+
for (let index2 = 0; index2 < arguments_.length; index2 += 1) {
|
|
30863
|
+
if (arguments_[index2] !== option) {
|
|
31155
30864
|
continue;
|
|
31156
30865
|
}
|
|
31157
|
-
const value = arguments_[
|
|
30866
|
+
const value = arguments_[index2 + 1];
|
|
31158
30867
|
if (value === void 0 || value.startsWith("--")) {
|
|
31159
30868
|
throw new PairingClientError("invalid_arguments", `${option} requires a value`);
|
|
31160
30869
|
}
|
|
31161
30870
|
values.push(value);
|
|
31162
|
-
|
|
30871
|
+
index2 += 1;
|
|
31163
30872
|
}
|
|
31164
30873
|
if (values.length !== 1) {
|
|
31165
30874
|
throw new PairingClientError("invalid_arguments", `${option} must be provided exactly once`);
|
|
@@ -31167,8 +30876,8 @@ function readSingleOption(arguments_, option) {
|
|
|
31167
30876
|
return values[0] ?? "";
|
|
31168
30877
|
}
|
|
31169
30878
|
function assertKnownArguments(arguments_) {
|
|
31170
|
-
for (let
|
|
31171
|
-
const option = arguments_[
|
|
30879
|
+
for (let index2 = 0; index2 < arguments_.length; index2 += 2) {
|
|
30880
|
+
const option = arguments_[index2];
|
|
31172
30881
|
if (option !== "--url" && option !== "--code" && option !== "--pairing" && option !== "--workspace") {
|
|
31173
30882
|
throw new PairingClientError("invalid_arguments", `Unknown pairing option: ${option ?? "missing option"}`);
|
|
31174
30883
|
}
|
|
@@ -31445,7 +31154,7 @@ var AuditStore = class {
|
|
|
31445
31154
|
};
|
|
31446
31155
|
|
|
31447
31156
|
// src/run-daemon.ts
|
|
31448
|
-
import { createHash as createHash8, randomUUID as
|
|
31157
|
+
import { createHash as createHash8, randomUUID as randomUUID10 } from "node:crypto";
|
|
31449
31158
|
import { join as join19 } from "node:path";
|
|
31450
31159
|
import { styleText } from "node:util";
|
|
31451
31160
|
|
|
@@ -31568,7 +31277,7 @@ function startsWith(bytes, signature, offset = 0) {
|
|
|
31568
31277
|
if (bytes.byteLength < offset + signature.byteLength) {
|
|
31569
31278
|
return false;
|
|
31570
31279
|
}
|
|
31571
|
-
return signature.every((value,
|
|
31280
|
+
return signature.every((value, index2) => bytes[offset + index2] === value);
|
|
31572
31281
|
}
|
|
31573
31282
|
function sniffRasterMime(bytes) {
|
|
31574
31283
|
if (startsWith(bytes, PNG_SIGNATURE)) {
|
|
@@ -31696,7 +31405,7 @@ function startsWith2(bytes, signature, offset = 0) {
|
|
|
31696
31405
|
if (bytes.byteLength < offset + signature.byteLength) {
|
|
31697
31406
|
return false;
|
|
31698
31407
|
}
|
|
31699
|
-
return signature.every((value,
|
|
31408
|
+
return signature.every((value, index2) => bytes[offset + index2] === value);
|
|
31700
31409
|
}
|
|
31701
31410
|
function sniffVideoMime(bytes) {
|
|
31702
31411
|
if (startsWith2(bytes, MP4_FILE_TYPE, 4)) {
|
|
@@ -31825,10 +31534,10 @@ async function replaceImageMarkers(text2, replace) {
|
|
|
31825
31534
|
let cursor = 0;
|
|
31826
31535
|
let rewritten = "";
|
|
31827
31536
|
for (const match of matches) {
|
|
31828
|
-
const
|
|
31829
|
-
rewritten += text2.slice(cursor,
|
|
31537
|
+
const index2 = match.index ?? 0;
|
|
31538
|
+
rewritten += text2.slice(cursor, index2);
|
|
31830
31539
|
rewritten += await replace(match[1] ?? "");
|
|
31831
|
-
cursor =
|
|
31540
|
+
cursor = index2 + match[0].length;
|
|
31832
31541
|
}
|
|
31833
31542
|
return `${rewritten}${text2.slice(cursor)}`;
|
|
31834
31543
|
}
|
|
@@ -33062,9 +32771,9 @@ function historyContentCharacters(messages) {
|
|
|
33062
32771
|
var AcpHistoryReplay = class {
|
|
33063
32772
|
#activities = /* @__PURE__ */ new Map();
|
|
33064
32773
|
#messages = [];
|
|
33065
|
-
#events
|
|
33066
|
-
#records = [];
|
|
32774
|
+
#events;
|
|
33067
32775
|
#turnActivityIds = /* @__PURE__ */ new Set();
|
|
32776
|
+
#sessionId;
|
|
33068
32777
|
#activityTracker = new AcpActivityTracker(
|
|
33069
32778
|
async (activity2) => {
|
|
33070
32779
|
this.#activities.set(activity2.activityId, activity2);
|
|
@@ -33085,10 +32794,16 @@ var AcpHistoryReplay = class {
|
|
|
33085
32794
|
#firstMessageIndex = 0;
|
|
33086
32795
|
#characters = 0;
|
|
33087
32796
|
#truncated = false;
|
|
32797
|
+
constructor(events, sessionId) {
|
|
32798
|
+
this.#events = events;
|
|
32799
|
+
this.#sessionId = sessionId;
|
|
32800
|
+
}
|
|
33088
32801
|
record = async (update, rawUpdate, onRecorded = () => Promise.resolve()) => {
|
|
33089
|
-
this.#
|
|
33090
|
-
|
|
33091
|
-
await
|
|
32802
|
+
const position = this.#events.append(this.#sessionId, { payload: rawUpdate, type: "acp" });
|
|
32803
|
+
await onRecorded(position);
|
|
32804
|
+
return await this.#applyUpdate(update, position);
|
|
32805
|
+
};
|
|
32806
|
+
#applyUpdate = async (update, position) => {
|
|
33092
32807
|
if (update.sessionUpdate === "agent_thought_chunk") {
|
|
33093
32808
|
if (update.content.type === "text") {
|
|
33094
32809
|
await this.#activityTracker.recordNarrative(
|
|
@@ -33097,30 +32812,30 @@ var AcpHistoryReplay = class {
|
|
|
33097
32812
|
update.content.text
|
|
33098
32813
|
);
|
|
33099
32814
|
}
|
|
33100
|
-
return
|
|
32815
|
+
return position;
|
|
33101
32816
|
}
|
|
33102
32817
|
if (update.sessionUpdate === "tool_call") {
|
|
33103
32818
|
await this.#activityTracker.recordToolCall(update);
|
|
33104
|
-
return
|
|
32819
|
+
return position;
|
|
33105
32820
|
}
|
|
33106
32821
|
if (update.sessionUpdate === "tool_call_update") {
|
|
33107
32822
|
await this.#activityTracker.recordToolCallUpdate(update);
|
|
33108
|
-
return
|
|
32823
|
+
return position;
|
|
33109
32824
|
}
|
|
33110
32825
|
if (update.sessionUpdate === "plan") {
|
|
33111
32826
|
await this.#activityTracker.recordPlan(update);
|
|
33112
|
-
return
|
|
32827
|
+
return position;
|
|
33113
32828
|
}
|
|
33114
32829
|
if (update.sessionUpdate === "plan_update") {
|
|
33115
32830
|
await this.#activityTracker.recordPlanUpdate(update);
|
|
33116
|
-
return
|
|
32831
|
+
return position;
|
|
33117
32832
|
}
|
|
33118
32833
|
if (update.sessionUpdate === "plan_removed") {
|
|
33119
32834
|
await this.#activityTracker.removePlan(update);
|
|
33120
|
-
return
|
|
32835
|
+
return position;
|
|
33121
32836
|
}
|
|
33122
32837
|
if (update.sessionUpdate !== "user_message_chunk" && update.sessionUpdate !== "agent_message_chunk") {
|
|
33123
|
-
return
|
|
32838
|
+
return position;
|
|
33124
32839
|
}
|
|
33125
32840
|
if (update.sessionUpdate === "agent_message_chunk" && isProgressMessage(update)) {
|
|
33126
32841
|
if (update.content.type === "text") {
|
|
@@ -33130,18 +32845,18 @@ var AcpHistoryReplay = class {
|
|
|
33130
32845
|
update.content.text
|
|
33131
32846
|
);
|
|
33132
32847
|
}
|
|
33133
|
-
return
|
|
32848
|
+
return position;
|
|
33134
32849
|
}
|
|
33135
32850
|
const role = update.sessionUpdate === "user_message_chunk" ? "user" : "assistant";
|
|
33136
32851
|
const content = update.content;
|
|
33137
32852
|
if (role === "assistant" && content.type !== "text") {
|
|
33138
32853
|
await this.#activityTracker.finishNarrative();
|
|
33139
32854
|
this.recordAssistantContent(update.messageId ?? null, normalizeContentBlock(content));
|
|
33140
|
-
return
|
|
32855
|
+
return position;
|
|
33141
32856
|
}
|
|
33142
32857
|
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]`;
|
|
33143
32858
|
if (text2.length === 0) {
|
|
33144
|
-
return
|
|
32859
|
+
return position;
|
|
33145
32860
|
}
|
|
33146
32861
|
const previous = this.#messages.at(-1);
|
|
33147
32862
|
const id = update.messageId ?? null;
|
|
@@ -33168,41 +32883,32 @@ var AcpHistoryReplay = class {
|
|
|
33168
32883
|
this.#characters += bounded2.length;
|
|
33169
32884
|
this.#lastMessageId = id;
|
|
33170
32885
|
this.trimMessages();
|
|
33171
|
-
return
|
|
32886
|
+
return position;
|
|
33172
32887
|
};
|
|
33173
32888
|
recordLifecycle = (event) => {
|
|
33174
32889
|
if (event.type !== "lifecycle-metadata") {
|
|
33175
32890
|
throw new Error("Lifecycle history only accepts lifecycle metadata");
|
|
33176
32891
|
}
|
|
33177
|
-
this.#
|
|
33178
|
-
this.#events.push(event);
|
|
33179
|
-
return this.#events.length;
|
|
32892
|
+
return this.#events.append(this.#sessionId, event);
|
|
33180
32893
|
};
|
|
33181
|
-
eventCount = () => this.#events.length;
|
|
33182
32894
|
append = async (replay) => {
|
|
33183
|
-
|
|
33184
|
-
|
|
33185
|
-
|
|
33186
|
-
} else {
|
|
33187
|
-
this.recordLifecycle(record2.event);
|
|
33188
|
-
}
|
|
32895
|
+
await replay.#activityTracker.finish();
|
|
32896
|
+
for (const [activityId, activity2] of replay.#activities) {
|
|
32897
|
+
this.#activities.set(activityId, activity2);
|
|
33189
32898
|
}
|
|
33190
|
-
|
|
33191
|
-
|
|
33192
|
-
|
|
33193
|
-
const parsedCursor = cursor === null ? events.length : Number(cursor);
|
|
33194
|
-
if (!Number.isSafeInteger(parsedCursor) || parsedCursor < 0 || parsedCursor > events.length) {
|
|
33195
|
-
throw new Error("The native event cursor is invalid");
|
|
32899
|
+
for (const message of replay.#messages.slice(replay.#firstMessageIndex)) {
|
|
32900
|
+
this.#messages.push(message);
|
|
32901
|
+
this.#characters += message.text.length;
|
|
33196
32902
|
}
|
|
33197
|
-
|
|
33198
|
-
|
|
33199
|
-
|
|
33200
|
-
|
|
33201
|
-
|
|
33202
|
-
|
|
33203
|
-
|
|
33204
|
-
};
|
|
32903
|
+
this.#turnActivityIds.clear();
|
|
32904
|
+
for (const activityId of replay.#turnActivityIds) {
|
|
32905
|
+
this.#turnActivityIds.add(activityId);
|
|
32906
|
+
}
|
|
32907
|
+
this.#lastMessageId = replay.#lastMessageId;
|
|
32908
|
+
this.#truncated ||= replay.#truncated;
|
|
32909
|
+
this.trimMessages();
|
|
33205
32910
|
};
|
|
32911
|
+
eventPage = (eventLimit, cursor) => this.#events.page(this.#sessionId, eventLimit, cursor);
|
|
33206
32912
|
snapshot = async () => {
|
|
33207
32913
|
await this.#activityTracker.finish();
|
|
33208
32914
|
const messages = this.#messages.slice(this.#firstMessageIndex).map((message) => {
|
|
@@ -33835,9 +33541,7 @@ var AcpSessionInteractions = class {
|
|
|
33835
33541
|
};
|
|
33836
33542
|
|
|
33837
33543
|
// src/acp/session-store.ts
|
|
33838
|
-
import {
|
|
33839
|
-
import { dirname as dirname4 } from "node:path";
|
|
33840
|
-
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
33544
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
33841
33545
|
|
|
33842
33546
|
// ../../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
|
|
33843
33547
|
var entityKind = /* @__PURE__ */ Symbol.for("drizzle:entityKind");
|
|
@@ -34953,7 +34657,7 @@ function haveSameKeys(left, right) {
|
|
|
34953
34657
|
const leftKeys = Object.keys(left);
|
|
34954
34658
|
const rightKeys = Object.keys(right);
|
|
34955
34659
|
if (leftKeys.length !== rightKeys.length) return false;
|
|
34956
|
-
for (const [
|
|
34660
|
+
for (const [index2, key] of leftKeys.entries()) if (key !== rightKeys[index2]) return false;
|
|
34957
34661
|
return true;
|
|
34958
34662
|
}
|
|
34959
34663
|
function mapUpdateSet(table, values) {
|
|
@@ -35706,195 +35410,6 @@ var NoopLogger = class {
|
|
|
35706
35410
|
}
|
|
35707
35411
|
};
|
|
35708
35412
|
|
|
35709
|
-
// ../../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
|
|
35710
|
-
var SQLiteCountBuilder = class SQLiteCountBuilder2 extends SQL {
|
|
35711
|
-
static [entityKind] = "SQLiteCountBuilder";
|
|
35712
|
-
dialect;
|
|
35713
|
-
session;
|
|
35714
|
-
static buildCount(source, filters, parens) {
|
|
35715
|
-
const query = sql`select count(*) from ${source}${sql` where ${filters}`.if(filters)}`;
|
|
35716
|
-
return parens ? sql`(${query})` : query;
|
|
35717
|
-
}
|
|
35718
|
-
constructor(countConfig) {
|
|
35719
|
-
super(SQLiteCountBuilder2.buildCount(countConfig.source, countConfig.filters, true).queryChunks);
|
|
35720
|
-
this.countConfig = countConfig;
|
|
35721
|
-
this.dialect = countConfig.dialect;
|
|
35722
|
-
this.session = countConfig.session;
|
|
35723
|
-
this.mapWith((e) => {
|
|
35724
|
-
if (typeof e === "number") return e;
|
|
35725
|
-
return Number(e ?? 0);
|
|
35726
|
-
});
|
|
35727
|
-
}
|
|
35728
|
-
executableSql;
|
|
35729
|
-
build() {
|
|
35730
|
-
if (!this.executableSql) {
|
|
35731
|
-
const { source, filters } = this.countConfig;
|
|
35732
|
-
this.executableSql = SQLiteCountBuilder2.buildCount(source, filters);
|
|
35733
|
-
}
|
|
35734
|
-
return this.dialect.sqlToQuery(this.executableSql);
|
|
35735
|
-
}
|
|
35736
|
-
};
|
|
35737
|
-
|
|
35738
|
-
// ../../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
|
|
35739
|
-
var SQLiteAsyncCountBuilder = class extends SQLiteCountBuilder {
|
|
35740
|
-
static [entityKind] = "SQLiteAsyncCountBuilder";
|
|
35741
|
-
constructor(countConfig) {
|
|
35742
|
-
super(countConfig);
|
|
35743
|
-
}
|
|
35744
|
-
/** @internal */
|
|
35745
|
-
executeRaw(placeholderValues) {
|
|
35746
|
-
return this.session.prepareQuery(this.build(), "arrays", false, "all", (rows) => {
|
|
35747
|
-
const v = rows[0]?.[0];
|
|
35748
|
-
if (typeof v === "number") return v;
|
|
35749
|
-
return v ? Number(v) : 0;
|
|
35750
|
-
}).execute(placeholderValues);
|
|
35751
|
-
}
|
|
35752
|
-
async execute(placeholderValues) {
|
|
35753
|
-
return await this.executeRaw(placeholderValues);
|
|
35754
|
-
}
|
|
35755
|
-
};
|
|
35756
|
-
applyMixins(SQLiteAsyncCountBuilder, [QueryPromise]);
|
|
35757
|
-
var SQLiteSyncCountBuilder = class extends SQLiteAsyncCountBuilder {
|
|
35758
|
-
static [entityKind] = "SQLiteSyncCountBuilder";
|
|
35759
|
-
sync(placeholderValues) {
|
|
35760
|
-
return this.executeRaw(placeholderValues).sync();
|
|
35761
|
-
}
|
|
35762
|
-
};
|
|
35763
|
-
|
|
35764
|
-
// ../../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
|
|
35765
|
-
var RelationalQueryBuilder = class {
|
|
35766
|
-
static [entityKind] = "SQLiteRelationalQueryBuilderV2";
|
|
35767
|
-
constructor(mode, schema, table, tableConfig, dialect, session, forbidJsonb, builder = SQLiteRelationalQuery) {
|
|
35768
|
-
this.mode = mode;
|
|
35769
|
-
this.schema = schema;
|
|
35770
|
-
this.table = table;
|
|
35771
|
-
this.tableConfig = tableConfig;
|
|
35772
|
-
this.dialect = dialect;
|
|
35773
|
-
this.session = session;
|
|
35774
|
-
this.forbidJsonb = forbidJsonb;
|
|
35775
|
-
this.builder = builder;
|
|
35776
|
-
}
|
|
35777
|
-
findMany(config2) {
|
|
35778
|
-
return new this.builder(this.mode, this.schema, this.table, this.tableConfig, this.dialect, this.session, config2 ?? true, "many", this.forbidJsonb);
|
|
35779
|
-
}
|
|
35780
|
-
findFirst(config2) {
|
|
35781
|
-
return new this.builder(this.mode, this.schema, this.table, this.tableConfig, this.dialect, this.session, config2 ?? true, "first", this.forbidJsonb);
|
|
35782
|
-
}
|
|
35783
|
-
};
|
|
35784
|
-
var SQLiteRelationalQuery = class {
|
|
35785
|
-
static [entityKind] = "SQLiteRelationalQueryV2";
|
|
35786
|
-
/** @internal */
|
|
35787
|
-
mode;
|
|
35788
|
-
/** @internal */
|
|
35789
|
-
table;
|
|
35790
|
-
/** @internal */
|
|
35791
|
-
resultKind;
|
|
35792
|
-
constructor(resultKind, schema, table, tableConfig, dialect, session, config2, mode, forbidJsonb) {
|
|
35793
|
-
this.schema = schema;
|
|
35794
|
-
this.tableConfig = tableConfig;
|
|
35795
|
-
this.dialect = dialect;
|
|
35796
|
-
this.session = session;
|
|
35797
|
-
this.config = config2;
|
|
35798
|
-
this.forbidJsonb = forbidJsonb;
|
|
35799
|
-
this.resultKind = resultKind;
|
|
35800
|
-
this.mode = mode;
|
|
35801
|
-
this.table = table;
|
|
35802
|
-
}
|
|
35803
|
-
getSQL() {
|
|
35804
|
-
return this._getQuery().sql;
|
|
35805
|
-
}
|
|
35806
|
-
_getQuery() {
|
|
35807
|
-
const jsonb = this.forbidJsonb ? sql`json` : sql`jsonb`;
|
|
35808
|
-
return this.dialect.buildRelationalQuery({
|
|
35809
|
-
schema: this.schema,
|
|
35810
|
-
table: this.table,
|
|
35811
|
-
tableConfig: this.tableConfig,
|
|
35812
|
-
queryConfig: this.config,
|
|
35813
|
-
mode: this.mode,
|
|
35814
|
-
jsonb
|
|
35815
|
-
});
|
|
35816
|
-
}
|
|
35817
|
-
_toSQL() {
|
|
35818
|
-
const query = this._getQuery();
|
|
35819
|
-
return {
|
|
35820
|
-
query,
|
|
35821
|
-
builtQuery: this.dialect.sqlToQuery(query.sql)
|
|
35822
|
-
};
|
|
35823
|
-
}
|
|
35824
|
-
toSQL() {
|
|
35825
|
-
return this._toSQL().builtQuery;
|
|
35826
|
-
}
|
|
35827
|
-
};
|
|
35828
|
-
|
|
35829
|
-
// ../../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
|
|
35830
|
-
var SQLiteAsyncRelationalQuery = class extends SQLiteRelationalQuery {
|
|
35831
|
-
static [entityKind] = "SQLiteAsyncRelationalQueryV2";
|
|
35832
|
-
/** @internal */
|
|
35833
|
-
_prepare(prepare = false) {
|
|
35834
|
-
const { query, builtQuery } = this._toSQL();
|
|
35835
|
-
const mapper = this.dialect.mapperGenerators.relationalRows({
|
|
35836
|
-
isFirst: this.mode === "first",
|
|
35837
|
-
parseJson: true,
|
|
35838
|
-
parseJsonIfString: false,
|
|
35839
|
-
rootJsonMappers: false,
|
|
35840
|
-
selection: query.selection,
|
|
35841
|
-
arrayModeRoot: true
|
|
35842
|
-
});
|
|
35843
|
-
return this.session.prepareQuery(builtQuery, "arrays", prepare, "all", mapper);
|
|
35844
|
-
}
|
|
35845
|
-
prepare() {
|
|
35846
|
-
return this._prepare(true);
|
|
35847
|
-
}
|
|
35848
|
-
async execute(placeholderValues) {
|
|
35849
|
-
return this._prepare().execute(placeholderValues);
|
|
35850
|
-
}
|
|
35851
|
-
};
|
|
35852
|
-
var SQLiteSyncRelationalQuery = class extends SQLiteAsyncRelationalQuery {
|
|
35853
|
-
static [entityKind] = "SQLiteSyncRelationalQueryV2";
|
|
35854
|
-
sync(placeholderValues) {
|
|
35855
|
-
return this._prepare().execute(placeholderValues).sync();
|
|
35856
|
-
}
|
|
35857
|
-
};
|
|
35858
|
-
applyMixins(SQLiteAsyncRelationalQuery, [QueryPromise]);
|
|
35859
|
-
|
|
35860
|
-
// ../../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
|
|
35861
|
-
var SelectionProxyHandler = class SelectionProxyHandler2 {
|
|
35862
|
-
static [entityKind] = "SelectionProxyHandler";
|
|
35863
|
-
config;
|
|
35864
|
-
constructor(config2) {
|
|
35865
|
-
this.config = { ...config2 };
|
|
35866
|
-
}
|
|
35867
|
-
get(subquery, prop) {
|
|
35868
|
-
if (prop === "_") return {
|
|
35869
|
-
...subquery["_"],
|
|
35870
|
-
selectedFields: new Proxy(subquery._.selectedFields, this)
|
|
35871
|
-
};
|
|
35872
|
-
if (prop === ViewBaseConfig) return {
|
|
35873
|
-
...subquery[ViewBaseConfig],
|
|
35874
|
-
selectedFields: new Proxy(subquery[ViewBaseConfig].selectedFields, this)
|
|
35875
|
-
};
|
|
35876
|
-
if (typeof prop === "symbol") return subquery[prop];
|
|
35877
|
-
const value = (is(subquery, Subquery) ? subquery._.selectedFields : is(subquery, View) ? subquery[ViewBaseConfig].selectedFields : subquery)[prop];
|
|
35878
|
-
if (is(value, SQL.Aliased)) {
|
|
35879
|
-
if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) return value.sql;
|
|
35880
|
-
const newValue = value.clone();
|
|
35881
|
-
newValue.isSelectionField = true;
|
|
35882
|
-
newValue.origin = this.config.alias;
|
|
35883
|
-
return newValue;
|
|
35884
|
-
}
|
|
35885
|
-
if (is(value, SQL)) {
|
|
35886
|
-
if (this.config.sqlBehavior === "sql") return value;
|
|
35887
|
-
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.`);
|
|
35888
|
-
}
|
|
35889
|
-
if (is(value, Column)) {
|
|
35890
|
-
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));
|
|
35891
|
-
return value;
|
|
35892
|
-
}
|
|
35893
|
-
if (typeof value !== "object" || value === null) return value;
|
|
35894
|
-
return new Proxy(value, new SelectionProxyHandler2(this.config));
|
|
35895
|
-
}
|
|
35896
|
-
};
|
|
35897
|
-
|
|
35898
35413
|
// ../../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
|
|
35899
35414
|
var ForeignKeyBuilder = class {
|
|
35900
35415
|
static [entityKind] = "SQLiteForeignKeyBuilder";
|
|
@@ -36459,130 +35974,144 @@ function sqliteTableWithCasing(casing) {
|
|
|
36459
35974
|
}
|
|
36460
35975
|
var sqliteTable = sqliteTableWithCasing(void 0);
|
|
36461
35976
|
|
|
36462
|
-
// ../../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/
|
|
36463
|
-
|
|
36464
|
-
|
|
36465
|
-
|
|
36466
|
-
|
|
36467
|
-
|
|
36468
|
-
}
|
|
36469
|
-
|
|
36470
|
-
|
|
36471
|
-
|
|
36472
|
-
|
|
35977
|
+
// ../../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
|
|
35978
|
+
var IndexBuilderOn = class {
|
|
35979
|
+
static [entityKind] = "SQLiteIndexBuilderOn";
|
|
35980
|
+
constructor(name2, unique) {
|
|
35981
|
+
this.name = name2;
|
|
35982
|
+
this.unique = unique;
|
|
35983
|
+
}
|
|
35984
|
+
on(...columns) {
|
|
35985
|
+
return new IndexBuilder(this.name, columns, this.unique);
|
|
35986
|
+
}
|
|
35987
|
+
};
|
|
35988
|
+
var IndexBuilder = class {
|
|
35989
|
+
static [entityKind] = "SQLiteIndexBuilder";
|
|
36473
35990
|
/** @internal */
|
|
36474
35991
|
config;
|
|
36475
|
-
constructor(
|
|
36476
|
-
this.table = table;
|
|
36477
|
-
this.session = session;
|
|
36478
|
-
this.dialect = dialect;
|
|
35992
|
+
constructor(name2, columns, unique) {
|
|
36479
35993
|
this.config = {
|
|
36480
|
-
|
|
36481
|
-
|
|
35994
|
+
name: name2,
|
|
35995
|
+
columns,
|
|
35996
|
+
unique,
|
|
35997
|
+
where: void 0
|
|
36482
35998
|
};
|
|
36483
35999
|
}
|
|
36484
36000
|
/**
|
|
36485
|
-
*
|
|
36486
|
-
*
|
|
36487
|
-
* Calling this method will delete only those rows that fulfill a specified condition.
|
|
36488
|
-
*
|
|
36489
|
-
* See docs: {@link https://orm.drizzle.team/docs/delete}
|
|
36490
|
-
*
|
|
36491
|
-
* @param where the `where` clause.
|
|
36492
|
-
*
|
|
36493
|
-
* @example
|
|
36494
|
-
* You can use conditional operators and `sql function` to filter the rows to be deleted.
|
|
36495
|
-
*
|
|
36496
|
-
* ```ts
|
|
36497
|
-
* // Delete all cars with green color
|
|
36498
|
-
* db.delete(cars).where(eq(cars.color, 'green'));
|
|
36499
|
-
* // or
|
|
36500
|
-
* db.delete(cars).where(sql`${cars.color} = 'green'`)
|
|
36501
|
-
* ```
|
|
36502
|
-
*
|
|
36503
|
-
* You can logically combine conditional operators with `and()` and `or()` operators:
|
|
36504
|
-
*
|
|
36505
|
-
* ```ts
|
|
36506
|
-
* // Delete all BMW cars with a green color
|
|
36507
|
-
* db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
|
36508
|
-
*
|
|
36509
|
-
* // Delete all cars with the green or blue color
|
|
36510
|
-
* db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
36511
|
-
* ```
|
|
36001
|
+
* Condition for partial index.
|
|
36512
36002
|
*/
|
|
36513
|
-
where(
|
|
36514
|
-
this.config.where =
|
|
36515
|
-
return this;
|
|
36516
|
-
}
|
|
36517
|
-
orderBy(...columns) {
|
|
36518
|
-
if (typeof columns[0] === "function") {
|
|
36519
|
-
const orderBy = columns[0](new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
|
|
36520
|
-
sqlAliasedBehavior: "alias",
|
|
36521
|
-
sqlBehavior: "sql"
|
|
36522
|
-
})));
|
|
36523
|
-
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
36524
|
-
this.config.orderBy = orderByArray;
|
|
36525
|
-
} else {
|
|
36526
|
-
const orderByArray = columns;
|
|
36527
|
-
this.config.orderBy = orderByArray;
|
|
36528
|
-
}
|
|
36529
|
-
return this;
|
|
36530
|
-
}
|
|
36531
|
-
limit(limit) {
|
|
36532
|
-
this.config.limit = limit;
|
|
36533
|
-
return this;
|
|
36534
|
-
}
|
|
36535
|
-
returning(fields = this.table[SQLiteTable.Symbol.Columns]) {
|
|
36536
|
-
this.config.returning = orderSelectedFields(fields);
|
|
36003
|
+
where(condition) {
|
|
36004
|
+
this.config.where = condition;
|
|
36537
36005
|
return this;
|
|
36538
36006
|
}
|
|
36539
|
-
|
|
36540
|
-
|
|
36541
|
-
|
|
36542
|
-
toSQL() {
|
|
36543
|
-
return this.dialect.sqlToQuery(this.getSQL());
|
|
36007
|
+
/** @internal */
|
|
36008
|
+
build(table) {
|
|
36009
|
+
return new Index(this.config, table);
|
|
36544
36010
|
}
|
|
36545
|
-
|
|
36546
|
-
|
|
36011
|
+
};
|
|
36012
|
+
var Index = class {
|
|
36013
|
+
static [entityKind] = "SQLiteIndex";
|
|
36014
|
+
config;
|
|
36015
|
+
isNameExplicit;
|
|
36016
|
+
constructor(config2, table) {
|
|
36017
|
+
this.config = {
|
|
36018
|
+
...config2,
|
|
36019
|
+
table
|
|
36020
|
+
};
|
|
36021
|
+
this.isNameExplicit = !!config2.name;
|
|
36547
36022
|
}
|
|
36548
36023
|
};
|
|
36024
|
+
function index(name2) {
|
|
36025
|
+
return new IndexBuilderOn(name2, false);
|
|
36026
|
+
}
|
|
36549
36027
|
|
|
36550
|
-
// ../../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/
|
|
36551
|
-
|
|
36552
|
-
|
|
36028
|
+
// ../../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
|
|
36029
|
+
function primaryKey(...config2) {
|
|
36030
|
+
if (config2[0].columns) return new PrimaryKeyBuilder(config2[0].columns, config2[0].name);
|
|
36031
|
+
return new PrimaryKeyBuilder(config2);
|
|
36032
|
+
}
|
|
36033
|
+
var PrimaryKeyBuilder = class {
|
|
36034
|
+
static [entityKind] = "SQLitePrimaryKeyBuilder";
|
|
36553
36035
|
/** @internal */
|
|
36554
|
-
|
|
36555
|
-
|
|
36556
|
-
|
|
36557
|
-
|
|
36558
|
-
|
|
36036
|
+
columns;
|
|
36037
|
+
/** @internal */
|
|
36038
|
+
name;
|
|
36039
|
+
constructor(columns, name2) {
|
|
36040
|
+
this.columns = columns;
|
|
36041
|
+
this.name = name2;
|
|
36559
36042
|
}
|
|
36560
|
-
|
|
36561
|
-
|
|
36043
|
+
/** @internal */
|
|
36044
|
+
build(table) {
|
|
36045
|
+
return new PrimaryKey(table, this.columns, this.name);
|
|
36562
36046
|
}
|
|
36563
|
-
|
|
36564
|
-
|
|
36565
|
-
|
|
36566
|
-
|
|
36567
|
-
|
|
36568
|
-
|
|
36569
|
-
|
|
36570
|
-
|
|
36571
|
-
|
|
36572
|
-
|
|
36573
|
-
|
|
36574
|
-
}
|
|
36575
|
-
|
|
36576
|
-
return this.
|
|
36047
|
+
};
|
|
36048
|
+
var PrimaryKey = class {
|
|
36049
|
+
static [entityKind] = "SQLitePrimaryKey";
|
|
36050
|
+
columns;
|
|
36051
|
+
name;
|
|
36052
|
+
isNameExplicit;
|
|
36053
|
+
constructor(table, columns, name2) {
|
|
36054
|
+
this.table = table;
|
|
36055
|
+
this.columns = columns;
|
|
36056
|
+
this.name = name2;
|
|
36057
|
+
this.isNameExplicit = !!name2;
|
|
36058
|
+
}
|
|
36059
|
+
getName() {
|
|
36060
|
+
return this.name ?? `${this.table[SQLiteTable.Symbol.Name]}_${this.columns.map((column) => column.name).join("_")}_pk`;
|
|
36577
36061
|
}
|
|
36578
36062
|
};
|
|
36579
|
-
|
|
36063
|
+
|
|
36064
|
+
// ../../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
|
|
36065
|
+
function extractUsedTable(table) {
|
|
36066
|
+
if (is(table, SQLiteTable)) return [`${table[Table.Symbol.BaseName]}`];
|
|
36067
|
+
if (is(table, Subquery)) return table._.usedTables ?? [];
|
|
36068
|
+
if (is(table, SQL)) return table.usedTables ?? [];
|
|
36069
|
+
return [];
|
|
36070
|
+
}
|
|
36580
36071
|
|
|
36581
36072
|
// ../../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
|
|
36582
36073
|
var SQLiteViewBase = class extends View {
|
|
36583
36074
|
static [entityKind] = "SQLiteViewBase";
|
|
36584
36075
|
};
|
|
36585
36076
|
|
|
36077
|
+
// ../../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
|
|
36078
|
+
var SelectionProxyHandler = class SelectionProxyHandler2 {
|
|
36079
|
+
static [entityKind] = "SelectionProxyHandler";
|
|
36080
|
+
config;
|
|
36081
|
+
constructor(config2) {
|
|
36082
|
+
this.config = { ...config2 };
|
|
36083
|
+
}
|
|
36084
|
+
get(subquery, prop) {
|
|
36085
|
+
if (prop === "_") return {
|
|
36086
|
+
...subquery["_"],
|
|
36087
|
+
selectedFields: new Proxy(subquery._.selectedFields, this)
|
|
36088
|
+
};
|
|
36089
|
+
if (prop === ViewBaseConfig) return {
|
|
36090
|
+
...subquery[ViewBaseConfig],
|
|
36091
|
+
selectedFields: new Proxy(subquery[ViewBaseConfig].selectedFields, this)
|
|
36092
|
+
};
|
|
36093
|
+
if (typeof prop === "symbol") return subquery[prop];
|
|
36094
|
+
const value = (is(subquery, Subquery) ? subquery._.selectedFields : is(subquery, View) ? subquery[ViewBaseConfig].selectedFields : subquery)[prop];
|
|
36095
|
+
if (is(value, SQL.Aliased)) {
|
|
36096
|
+
if (this.config.sqlAliasedBehavior === "sql" && !value.isSelectionField) return value.sql;
|
|
36097
|
+
const newValue = value.clone();
|
|
36098
|
+
newValue.isSelectionField = true;
|
|
36099
|
+
newValue.origin = this.config.alias;
|
|
36100
|
+
return newValue;
|
|
36101
|
+
}
|
|
36102
|
+
if (is(value, SQL)) {
|
|
36103
|
+
if (this.config.sqlBehavior === "sql") return value;
|
|
36104
|
+
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.`);
|
|
36105
|
+
}
|
|
36106
|
+
if (is(value, Column)) {
|
|
36107
|
+
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));
|
|
36108
|
+
return value;
|
|
36109
|
+
}
|
|
36110
|
+
if (typeof value !== "object" || value === null) return value;
|
|
36111
|
+
return new Proxy(value, new SelectionProxyHandler2(this.config));
|
|
36112
|
+
}
|
|
36113
|
+
};
|
|
36114
|
+
|
|
36586
36115
|
// ../../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
|
|
36587
36116
|
var TypedQueryBuilder = class {
|
|
36588
36117
|
static [entityKind] = "TypedQueryBuilder";
|
|
@@ -37283,8 +36812,8 @@ var SQLiteDialect = class {
|
|
|
37283
36812
|
buildJoins(joins) {
|
|
37284
36813
|
if (!joins || joins.length === 0) return;
|
|
37285
36814
|
const joinsArray = [];
|
|
37286
|
-
if (joins) for (const [
|
|
37287
|
-
if (
|
|
36815
|
+
if (joins) for (const [index2, joinMeta] of joins.entries()) {
|
|
36816
|
+
if (index2 === 0) joinsArray.push(sql` `);
|
|
37288
36817
|
const table = joinMeta.table;
|
|
37289
36818
|
const onSql = joinMeta.on ? sql` on ${joinMeta.on}` : void 0;
|
|
37290
36819
|
if (is(table, SQLiteTable)) {
|
|
@@ -37294,7 +36823,7 @@ var SQLiteDialect = class {
|
|
|
37294
36823
|
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
|
37295
36824
|
joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`}${onSql}`);
|
|
37296
36825
|
} else joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join ${table}${onSql}`);
|
|
37297
|
-
if (
|
|
36826
|
+
if (index2 < joins.length - 1) joinsArray.push(sql` `);
|
|
37298
36827
|
}
|
|
37299
36828
|
return sql.join(joinsArray);
|
|
37300
36829
|
}
|
|
@@ -37303,9 +36832,9 @@ var SQLiteDialect = class {
|
|
|
37303
36832
|
}
|
|
37304
36833
|
buildOrderBy(orderBy) {
|
|
37305
36834
|
const orderByList = [];
|
|
37306
|
-
if (orderBy) for (const [
|
|
36835
|
+
if (orderBy) for (const [index2, orderByValue] of orderBy.entries()) {
|
|
37307
36836
|
orderByList.push(orderByValue);
|
|
37308
|
-
if (
|
|
36837
|
+
if (index2 < orderBy.length - 1) orderByList.push(sql`, `);
|
|
37309
36838
|
}
|
|
37310
36839
|
return orderByList.length > 0 ? sql` order by ${sql.join(orderByList)}` : void 0;
|
|
37311
36840
|
}
|
|
@@ -37333,9 +36862,9 @@ var SQLiteDialect = class {
|
|
|
37333
36862
|
const whereSql = where ? sql` where ${where}` : void 0;
|
|
37334
36863
|
const havingSql = having ? sql` having ${having}` : void 0;
|
|
37335
36864
|
const groupByList = [];
|
|
37336
|
-
if (groupBy) for (const [
|
|
36865
|
+
if (groupBy) for (const [index2, groupByValue] of groupBy.entries()) {
|
|
37337
36866
|
groupByList.push(groupByValue);
|
|
37338
|
-
if (
|
|
36867
|
+
if (index2 < groupBy.length - 1) groupByList.push(sql`, `);
|
|
37339
36868
|
}
|
|
37340
36869
|
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}`;
|
|
37341
36870
|
if (setOperators.length > 0) return this.buildSetOperations(finalQuery, setOperators);
|
|
@@ -37624,6 +37153,268 @@ var QueryBuilder = class {
|
|
|
37624
37153
|
}
|
|
37625
37154
|
};
|
|
37626
37155
|
|
|
37156
|
+
// ../../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
|
|
37157
|
+
var SQLiteCountBuilder = class SQLiteCountBuilder2 extends SQL {
|
|
37158
|
+
static [entityKind] = "SQLiteCountBuilder";
|
|
37159
|
+
dialect;
|
|
37160
|
+
session;
|
|
37161
|
+
static buildCount(source, filters, parens) {
|
|
37162
|
+
const query = sql`select count(*) from ${source}${sql` where ${filters}`.if(filters)}`;
|
|
37163
|
+
return parens ? sql`(${query})` : query;
|
|
37164
|
+
}
|
|
37165
|
+
constructor(countConfig) {
|
|
37166
|
+
super(SQLiteCountBuilder2.buildCount(countConfig.source, countConfig.filters, true).queryChunks);
|
|
37167
|
+
this.countConfig = countConfig;
|
|
37168
|
+
this.dialect = countConfig.dialect;
|
|
37169
|
+
this.session = countConfig.session;
|
|
37170
|
+
this.mapWith((e) => {
|
|
37171
|
+
if (typeof e === "number") return e;
|
|
37172
|
+
return Number(e ?? 0);
|
|
37173
|
+
});
|
|
37174
|
+
}
|
|
37175
|
+
executableSql;
|
|
37176
|
+
build() {
|
|
37177
|
+
if (!this.executableSql) {
|
|
37178
|
+
const { source, filters } = this.countConfig;
|
|
37179
|
+
this.executableSql = SQLiteCountBuilder2.buildCount(source, filters);
|
|
37180
|
+
}
|
|
37181
|
+
return this.dialect.sqlToQuery(this.executableSql);
|
|
37182
|
+
}
|
|
37183
|
+
};
|
|
37184
|
+
|
|
37185
|
+
// ../../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
|
|
37186
|
+
var SQLiteAsyncCountBuilder = class extends SQLiteCountBuilder {
|
|
37187
|
+
static [entityKind] = "SQLiteAsyncCountBuilder";
|
|
37188
|
+
constructor(countConfig) {
|
|
37189
|
+
super(countConfig);
|
|
37190
|
+
}
|
|
37191
|
+
/** @internal */
|
|
37192
|
+
executeRaw(placeholderValues) {
|
|
37193
|
+
return this.session.prepareQuery(this.build(), "arrays", false, "all", (rows) => {
|
|
37194
|
+
const v = rows[0]?.[0];
|
|
37195
|
+
if (typeof v === "number") return v;
|
|
37196
|
+
return v ? Number(v) : 0;
|
|
37197
|
+
}).execute(placeholderValues);
|
|
37198
|
+
}
|
|
37199
|
+
async execute(placeholderValues) {
|
|
37200
|
+
return await this.executeRaw(placeholderValues);
|
|
37201
|
+
}
|
|
37202
|
+
};
|
|
37203
|
+
applyMixins(SQLiteAsyncCountBuilder, [QueryPromise]);
|
|
37204
|
+
var SQLiteSyncCountBuilder = class extends SQLiteAsyncCountBuilder {
|
|
37205
|
+
static [entityKind] = "SQLiteSyncCountBuilder";
|
|
37206
|
+
sync(placeholderValues) {
|
|
37207
|
+
return this.executeRaw(placeholderValues).sync();
|
|
37208
|
+
}
|
|
37209
|
+
};
|
|
37210
|
+
|
|
37211
|
+
// ../../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
|
|
37212
|
+
var RelationalQueryBuilder = class {
|
|
37213
|
+
static [entityKind] = "SQLiteRelationalQueryBuilderV2";
|
|
37214
|
+
constructor(mode, schema, table, tableConfig, dialect, session, forbidJsonb, builder = SQLiteRelationalQuery) {
|
|
37215
|
+
this.mode = mode;
|
|
37216
|
+
this.schema = schema;
|
|
37217
|
+
this.table = table;
|
|
37218
|
+
this.tableConfig = tableConfig;
|
|
37219
|
+
this.dialect = dialect;
|
|
37220
|
+
this.session = session;
|
|
37221
|
+
this.forbidJsonb = forbidJsonb;
|
|
37222
|
+
this.builder = builder;
|
|
37223
|
+
}
|
|
37224
|
+
findMany(config2) {
|
|
37225
|
+
return new this.builder(this.mode, this.schema, this.table, this.tableConfig, this.dialect, this.session, config2 ?? true, "many", this.forbidJsonb);
|
|
37226
|
+
}
|
|
37227
|
+
findFirst(config2) {
|
|
37228
|
+
return new this.builder(this.mode, this.schema, this.table, this.tableConfig, this.dialect, this.session, config2 ?? true, "first", this.forbidJsonb);
|
|
37229
|
+
}
|
|
37230
|
+
};
|
|
37231
|
+
var SQLiteRelationalQuery = class {
|
|
37232
|
+
static [entityKind] = "SQLiteRelationalQueryV2";
|
|
37233
|
+
/** @internal */
|
|
37234
|
+
mode;
|
|
37235
|
+
/** @internal */
|
|
37236
|
+
table;
|
|
37237
|
+
/** @internal */
|
|
37238
|
+
resultKind;
|
|
37239
|
+
constructor(resultKind, schema, table, tableConfig, dialect, session, config2, mode, forbidJsonb) {
|
|
37240
|
+
this.schema = schema;
|
|
37241
|
+
this.tableConfig = tableConfig;
|
|
37242
|
+
this.dialect = dialect;
|
|
37243
|
+
this.session = session;
|
|
37244
|
+
this.config = config2;
|
|
37245
|
+
this.forbidJsonb = forbidJsonb;
|
|
37246
|
+
this.resultKind = resultKind;
|
|
37247
|
+
this.mode = mode;
|
|
37248
|
+
this.table = table;
|
|
37249
|
+
}
|
|
37250
|
+
getSQL() {
|
|
37251
|
+
return this._getQuery().sql;
|
|
37252
|
+
}
|
|
37253
|
+
_getQuery() {
|
|
37254
|
+
const jsonb = this.forbidJsonb ? sql`json` : sql`jsonb`;
|
|
37255
|
+
return this.dialect.buildRelationalQuery({
|
|
37256
|
+
schema: this.schema,
|
|
37257
|
+
table: this.table,
|
|
37258
|
+
tableConfig: this.tableConfig,
|
|
37259
|
+
queryConfig: this.config,
|
|
37260
|
+
mode: this.mode,
|
|
37261
|
+
jsonb
|
|
37262
|
+
});
|
|
37263
|
+
}
|
|
37264
|
+
_toSQL() {
|
|
37265
|
+
const query = this._getQuery();
|
|
37266
|
+
return {
|
|
37267
|
+
query,
|
|
37268
|
+
builtQuery: this.dialect.sqlToQuery(query.sql)
|
|
37269
|
+
};
|
|
37270
|
+
}
|
|
37271
|
+
toSQL() {
|
|
37272
|
+
return this._toSQL().builtQuery;
|
|
37273
|
+
}
|
|
37274
|
+
};
|
|
37275
|
+
|
|
37276
|
+
// ../../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
|
|
37277
|
+
var SQLiteAsyncRelationalQuery = class extends SQLiteRelationalQuery {
|
|
37278
|
+
static [entityKind] = "SQLiteAsyncRelationalQueryV2";
|
|
37279
|
+
/** @internal */
|
|
37280
|
+
_prepare(prepare = false) {
|
|
37281
|
+
const { query, builtQuery } = this._toSQL();
|
|
37282
|
+
const mapper = this.dialect.mapperGenerators.relationalRows({
|
|
37283
|
+
isFirst: this.mode === "first",
|
|
37284
|
+
parseJson: true,
|
|
37285
|
+
parseJsonIfString: false,
|
|
37286
|
+
rootJsonMappers: false,
|
|
37287
|
+
selection: query.selection,
|
|
37288
|
+
arrayModeRoot: true
|
|
37289
|
+
});
|
|
37290
|
+
return this.session.prepareQuery(builtQuery, "arrays", prepare, "all", mapper);
|
|
37291
|
+
}
|
|
37292
|
+
prepare() {
|
|
37293
|
+
return this._prepare(true);
|
|
37294
|
+
}
|
|
37295
|
+
async execute(placeholderValues) {
|
|
37296
|
+
return this._prepare().execute(placeholderValues);
|
|
37297
|
+
}
|
|
37298
|
+
};
|
|
37299
|
+
var SQLiteSyncRelationalQuery = class extends SQLiteAsyncRelationalQuery {
|
|
37300
|
+
static [entityKind] = "SQLiteSyncRelationalQueryV2";
|
|
37301
|
+
sync(placeholderValues) {
|
|
37302
|
+
return this._prepare().execute(placeholderValues).sync();
|
|
37303
|
+
}
|
|
37304
|
+
};
|
|
37305
|
+
applyMixins(SQLiteAsyncRelationalQuery, [QueryPromise]);
|
|
37306
|
+
|
|
37307
|
+
// ../../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
|
|
37308
|
+
var SQLiteDeleteBase = class {
|
|
37309
|
+
static [entityKind] = "SQLiteDelete";
|
|
37310
|
+
/** @internal */
|
|
37311
|
+
config;
|
|
37312
|
+
constructor(table, session, dialect, withList) {
|
|
37313
|
+
this.table = table;
|
|
37314
|
+
this.session = session;
|
|
37315
|
+
this.dialect = dialect;
|
|
37316
|
+
this.config = {
|
|
37317
|
+
table,
|
|
37318
|
+
withList
|
|
37319
|
+
};
|
|
37320
|
+
}
|
|
37321
|
+
/**
|
|
37322
|
+
* Adds a `where` clause to the query.
|
|
37323
|
+
*
|
|
37324
|
+
* Calling this method will delete only those rows that fulfill a specified condition.
|
|
37325
|
+
*
|
|
37326
|
+
* See docs: {@link https://orm.drizzle.team/docs/delete}
|
|
37327
|
+
*
|
|
37328
|
+
* @param where the `where` clause.
|
|
37329
|
+
*
|
|
37330
|
+
* @example
|
|
37331
|
+
* You can use conditional operators and `sql function` to filter the rows to be deleted.
|
|
37332
|
+
*
|
|
37333
|
+
* ```ts
|
|
37334
|
+
* // Delete all cars with green color
|
|
37335
|
+
* db.delete(cars).where(eq(cars.color, 'green'));
|
|
37336
|
+
* // or
|
|
37337
|
+
* db.delete(cars).where(sql`${cars.color} = 'green'`)
|
|
37338
|
+
* ```
|
|
37339
|
+
*
|
|
37340
|
+
* You can logically combine conditional operators with `and()` and `or()` operators:
|
|
37341
|
+
*
|
|
37342
|
+
* ```ts
|
|
37343
|
+
* // Delete all BMW cars with a green color
|
|
37344
|
+
* db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
|
37345
|
+
*
|
|
37346
|
+
* // Delete all cars with the green or blue color
|
|
37347
|
+
* db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
37348
|
+
* ```
|
|
37349
|
+
*/
|
|
37350
|
+
where(where) {
|
|
37351
|
+
this.config.where = where;
|
|
37352
|
+
return this;
|
|
37353
|
+
}
|
|
37354
|
+
orderBy(...columns) {
|
|
37355
|
+
if (typeof columns[0] === "function") {
|
|
37356
|
+
const orderBy = columns[0](new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
|
|
37357
|
+
sqlAliasedBehavior: "alias",
|
|
37358
|
+
sqlBehavior: "sql"
|
|
37359
|
+
})));
|
|
37360
|
+
const orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
37361
|
+
this.config.orderBy = orderByArray;
|
|
37362
|
+
} else {
|
|
37363
|
+
const orderByArray = columns;
|
|
37364
|
+
this.config.orderBy = orderByArray;
|
|
37365
|
+
}
|
|
37366
|
+
return this;
|
|
37367
|
+
}
|
|
37368
|
+
limit(limit) {
|
|
37369
|
+
this.config.limit = limit;
|
|
37370
|
+
return this;
|
|
37371
|
+
}
|
|
37372
|
+
returning(fields = this.table[SQLiteTable.Symbol.Columns]) {
|
|
37373
|
+
this.config.returning = orderSelectedFields(fields);
|
|
37374
|
+
return this;
|
|
37375
|
+
}
|
|
37376
|
+
getSQL() {
|
|
37377
|
+
return this.dialect.buildDeleteQuery(this.config);
|
|
37378
|
+
}
|
|
37379
|
+
toSQL() {
|
|
37380
|
+
return this.dialect.sqlToQuery(this.getSQL());
|
|
37381
|
+
}
|
|
37382
|
+
$dynamic() {
|
|
37383
|
+
return this;
|
|
37384
|
+
}
|
|
37385
|
+
};
|
|
37386
|
+
|
|
37387
|
+
// ../../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
|
|
37388
|
+
var SQLiteAsyncDeleteBase = class extends SQLiteDeleteBase {
|
|
37389
|
+
static [entityKind] = "SQLiteAsyncDelete";
|
|
37390
|
+
/** @internal */
|
|
37391
|
+
_prepare(prepare = false) {
|
|
37392
|
+
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, {
|
|
37393
|
+
type: "delete",
|
|
37394
|
+
tables: extractUsedTable(this.config.table)
|
|
37395
|
+
});
|
|
37396
|
+
}
|
|
37397
|
+
prepare() {
|
|
37398
|
+
return this._prepare(true);
|
|
37399
|
+
}
|
|
37400
|
+
run = (placeholderValues) => {
|
|
37401
|
+
return this._prepare().run(placeholderValues);
|
|
37402
|
+
};
|
|
37403
|
+
all = (placeholderValues) => {
|
|
37404
|
+
return this._prepare().all(placeholderValues);
|
|
37405
|
+
};
|
|
37406
|
+
get = (placeholderValues) => {
|
|
37407
|
+
return this._prepare().get(placeholderValues);
|
|
37408
|
+
};
|
|
37409
|
+
values = (placeholderValues) => {
|
|
37410
|
+
return this._prepare().values(placeholderValues);
|
|
37411
|
+
};
|
|
37412
|
+
async execute(placeholderValues) {
|
|
37413
|
+
return this._prepare().execute(placeholderValues);
|
|
37414
|
+
}
|
|
37415
|
+
};
|
|
37416
|
+
applyMixins(SQLiteAsyncDeleteBase, [QueryPromise]);
|
|
37417
|
+
|
|
37627
37418
|
// ../../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
|
|
37628
37419
|
var SQLiteInsertBuilder = class {
|
|
37629
37420
|
static [entityKind] = "SQLiteInsertBuilder";
|
|
@@ -38511,133 +38302,6 @@ var SQLiteAsyncTransaction = class extends SQLiteAsyncDatabase {
|
|
|
38511
38302
|
}
|
|
38512
38303
|
};
|
|
38513
38304
|
|
|
38514
|
-
// ../../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
|
|
38515
|
-
var NodeSQLiteSession = class extends SQLiteAsyncSession {
|
|
38516
|
-
static [entityKind] = "SQLJsSession";
|
|
38517
|
-
logger;
|
|
38518
|
-
constructor(client2, dialect, relations, options = {}) {
|
|
38519
|
-
super(dialect, "sync");
|
|
38520
|
-
this.client = client2;
|
|
38521
|
-
this.relations = relations;
|
|
38522
|
-
this.options = options;
|
|
38523
|
-
this.logger = options.logger ?? new NoopLogger();
|
|
38524
|
-
}
|
|
38525
|
-
prepareQuery(query, mode, _prepare, executeMethod, mapper, queryMetadata) {
|
|
38526
|
-
let stmt;
|
|
38527
|
-
try {
|
|
38528
|
-
stmt = this.client.prepare(query.sql);
|
|
38529
|
-
} catch (e) {
|
|
38530
|
-
throw new DrizzleQueryError(query.sql, query.params, e);
|
|
38531
|
-
}
|
|
38532
|
-
return new SQLiteAsyncPreparedQuery("sync", executeMethod, {
|
|
38533
|
-
all: (params) => {
|
|
38534
|
-
stmt.setReturnArrays(mode === "arrays");
|
|
38535
|
-
const res = stmt.all(...params);
|
|
38536
|
-
if (mode === "objects") return res.map((row) => ({ ...row }));
|
|
38537
|
-
return res;
|
|
38538
|
-
},
|
|
38539
|
-
get: (params) => {
|
|
38540
|
-
stmt.setReturnArrays(mode === "arrays");
|
|
38541
|
-
const res = stmt.get(...params);
|
|
38542
|
-
if (res && mode === "objects") return { ...res };
|
|
38543
|
-
return res;
|
|
38544
|
-
},
|
|
38545
|
-
run: (params) => {
|
|
38546
|
-
stmt.setReturnArrays(false);
|
|
38547
|
-
return stmt.run(...params);
|
|
38548
|
-
},
|
|
38549
|
-
values: (params) => {
|
|
38550
|
-
stmt.setReturnArrays(true);
|
|
38551
|
-
return stmt.all(...params);
|
|
38552
|
-
}
|
|
38553
|
-
}, query, mapper, mode, this.logger, void 0, queryMetadata, void 0);
|
|
38554
|
-
}
|
|
38555
|
-
transaction(transaction, config2 = {}) {
|
|
38556
|
-
const tx = new NodeSQLiteTransaction("sync", this.dialect, this, this.relations);
|
|
38557
|
-
this.run(sql.raw(`begin${config2.behavior ? ` ${config2.behavior}` : ""}`));
|
|
38558
|
-
try {
|
|
38559
|
-
const result = transaction(tx);
|
|
38560
|
-
this.run(sql`commit`);
|
|
38561
|
-
return result;
|
|
38562
|
-
} catch (err) {
|
|
38563
|
-
this.run(sql`rollback`);
|
|
38564
|
-
throw err;
|
|
38565
|
-
}
|
|
38566
|
-
}
|
|
38567
|
-
};
|
|
38568
|
-
var NodeSQLiteTransaction = class NodeSQLiteTransaction2 extends SQLiteAsyncTransaction {
|
|
38569
|
-
static [entityKind] = "SQLJsTransaction";
|
|
38570
|
-
transaction(transaction) {
|
|
38571
|
-
const savepointName = `sp${this.nestedIndex + 1}`;
|
|
38572
|
-
const tx = new NodeSQLiteTransaction2("sync", this.dialect, this.session, this._.relations, this.nestedIndex + 1);
|
|
38573
|
-
tx.run(sql.raw(`savepoint ${savepointName}`));
|
|
38574
|
-
try {
|
|
38575
|
-
const result = transaction(tx);
|
|
38576
|
-
tx.run(sql.raw(`release savepoint ${savepointName}`));
|
|
38577
|
-
return result;
|
|
38578
|
-
} catch (err) {
|
|
38579
|
-
tx.run(sql.raw(`rollback to savepoint ${savepointName}`));
|
|
38580
|
-
throw err;
|
|
38581
|
-
}
|
|
38582
|
-
}
|
|
38583
|
-
};
|
|
38584
|
-
|
|
38585
|
-
// ../../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
|
|
38586
|
-
import { DatabaseSync } from "node:sqlite";
|
|
38587
|
-
var NodeSQLiteDatabase = class extends SQLiteAsyncDatabase {
|
|
38588
|
-
static [entityKind] = "NodeSQLiteDatabase";
|
|
38589
|
-
};
|
|
38590
|
-
function construct(client2, config2 = {}) {
|
|
38591
|
-
const dialect = new SQLiteDialect({ useJitMappers: jitCompatCheck(config2.jit) });
|
|
38592
|
-
let logger;
|
|
38593
|
-
if (config2.logger === true) logger = new DefaultLogger();
|
|
38594
|
-
else if (config2.logger !== false) logger = config2.logger;
|
|
38595
|
-
const relations = config2.relations ?? {};
|
|
38596
|
-
const db = new NodeSQLiteDatabase("sync", dialect, new NodeSQLiteSession(client2, dialect, relations, { logger }), relations);
|
|
38597
|
-
db.$client = client2;
|
|
38598
|
-
return db;
|
|
38599
|
-
}
|
|
38600
|
-
function drizzle(...params) {
|
|
38601
|
-
if (params[0] === void 0 || typeof params[0] === "string") return construct(params[0] === void 0 ? new DatabaseSync(":memory:") : new DatabaseSync(params[0]), params[1]);
|
|
38602
|
-
const { connection, client: client2, ...config2 } = params[0];
|
|
38603
|
-
if (client2) return construct(client2, config2);
|
|
38604
|
-
if (typeof connection === "object") {
|
|
38605
|
-
const { path: path3, ...options } = connection;
|
|
38606
|
-
return construct(new DatabaseSync(path3 ?? ":memory:", options), config2);
|
|
38607
|
-
}
|
|
38608
|
-
return construct(new DatabaseSync(connection ?? ":memory:"), config2);
|
|
38609
|
-
}
|
|
38610
|
-
(function(_drizzle) {
|
|
38611
|
-
function mock(config2) {
|
|
38612
|
-
return construct({}, config2);
|
|
38613
|
-
}
|
|
38614
|
-
_drizzle.mock = mock;
|
|
38615
|
-
})(drizzle || (drizzle = {}));
|
|
38616
|
-
|
|
38617
|
-
// src/generated/acp-session-store-migrations.ts
|
|
38618
|
-
var acpSessionStoreMigrations = [
|
|
38619
|
-
{
|
|
38620
|
-
"name": "0000_slimy_captain_midlands.sql",
|
|
38621
|
-
"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"
|
|
38622
|
-
},
|
|
38623
|
-
{
|
|
38624
|
-
"name": "0001_regular_ultimates.sql",
|
|
38625
|
-
"sql": "ALTER TABLE `acp_session` ADD `last_terminal_command_id` text;"
|
|
38626
|
-
},
|
|
38627
|
-
{
|
|
38628
|
-
"name": "0002_equal_black_queen.sql",
|
|
38629
|
-
"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`);"
|
|
38630
|
-
},
|
|
38631
|
-
{
|
|
38632
|
-
"name": "0003_silky_ravenous.sql",
|
|
38633
|
-
"sql": "DROP TABLE `session_event_v2`;"
|
|
38634
|
-
},
|
|
38635
|
-
{
|
|
38636
|
-
"name": "0004_special_mathemanic.sql",
|
|
38637
|
-
"sql": "DROP TABLE `deleted_acp_session`;--> statement-breakpoint\nALTER TABLE `acp_session` DROP COLUMN `last_terminal_command_id`;"
|
|
38638
|
-
}
|
|
38639
|
-
];
|
|
38640
|
-
|
|
38641
38305
|
// src/schema/acp-session-store/acp-session.ts
|
|
38642
38306
|
var acpSession = sqliteTable("acp_session", {
|
|
38643
38307
|
sessionId: text("session_id").primaryKey(),
|
|
@@ -38650,6 +38314,216 @@ var acpSession = sqliteTable("acp_session", {
|
|
|
38650
38314
|
updatedAt: text("updated_at").notNull()
|
|
38651
38315
|
});
|
|
38652
38316
|
|
|
38317
|
+
// src/schema/session-event-cache/session-event-v2.ts
|
|
38318
|
+
var sessionEventV2 = sqliteTable(
|
|
38319
|
+
"session_event_v2",
|
|
38320
|
+
{
|
|
38321
|
+
eventJson: text("event_json").notNull(),
|
|
38322
|
+
generationId: text("generation_id").notNull(),
|
|
38323
|
+
position: integer2("position").notNull(),
|
|
38324
|
+
sessionId: text("session_id").notNull()
|
|
38325
|
+
},
|
|
38326
|
+
(table) => [
|
|
38327
|
+
primaryKey({ columns: [table.generationId, table.sessionId, table.position] }),
|
|
38328
|
+
index("session_event_v2_generation_session_position_index").on(
|
|
38329
|
+
table.generationId,
|
|
38330
|
+
table.sessionId,
|
|
38331
|
+
table.position
|
|
38332
|
+
)
|
|
38333
|
+
]
|
|
38334
|
+
);
|
|
38335
|
+
|
|
38336
|
+
// src/acp/session-event-store-v2.ts
|
|
38337
|
+
var HOT_EVENT_HIGH_WATER_MARK = 256;
|
|
38338
|
+
var HOT_EVENT_RETENTION = 128;
|
|
38339
|
+
function eventPage(eventCount, eventLimit, cursor, read) {
|
|
38340
|
+
const parsedCursor = cursor === null ? eventCount : Number(cursor);
|
|
38341
|
+
if (!Number.isSafeInteger(parsedCursor) || parsedCursor < 0 || parsedCursor > eventCount) {
|
|
38342
|
+
throw new Error("The native event cursor is invalid");
|
|
38343
|
+
}
|
|
38344
|
+
const endPosition = parsedCursor;
|
|
38345
|
+
const startPosition = Math.max(0, endPosition - eventLimit);
|
|
38346
|
+
return {
|
|
38347
|
+
events: read(startPosition + 1, endPosition),
|
|
38348
|
+
nextCursor: startPosition === 0 ? null : startPosition.toString(),
|
|
38349
|
+
startPosition: startPosition + 1,
|
|
38350
|
+
truncated: startPosition > 0
|
|
38351
|
+
};
|
|
38352
|
+
}
|
|
38353
|
+
var MemoryAcpSessionEventStoreV2 = class {
|
|
38354
|
+
generationId;
|
|
38355
|
+
#events = /* @__PURE__ */ new Map();
|
|
38356
|
+
constructor(generationId) {
|
|
38357
|
+
this.generationId = generationId;
|
|
38358
|
+
}
|
|
38359
|
+
append = (sessionId, event) => {
|
|
38360
|
+
const events = this.#events.get(sessionId) ?? [];
|
|
38361
|
+
events.push(event);
|
|
38362
|
+
this.#events.set(sessionId, events);
|
|
38363
|
+
return events.length;
|
|
38364
|
+
};
|
|
38365
|
+
close = () => this.#events.clear();
|
|
38366
|
+
page = (sessionId, eventLimit, cursor) => {
|
|
38367
|
+
const events = this.#events.get(sessionId) ?? [];
|
|
38368
|
+
return eventPage(
|
|
38369
|
+
events.length,
|
|
38370
|
+
eventLimit,
|
|
38371
|
+
cursor,
|
|
38372
|
+
(startPosition, endPosition) => events.slice(startPosition - 1, endPosition)
|
|
38373
|
+
);
|
|
38374
|
+
};
|
|
38375
|
+
remove = (sessionId) => {
|
|
38376
|
+
this.#events.delete(sessionId);
|
|
38377
|
+
};
|
|
38378
|
+
reset = this.remove;
|
|
38379
|
+
};
|
|
38380
|
+
var cachedEventRowSchema = external_exports.object({ eventJson: external_exports.string(), position: external_exports.number().int().positive() });
|
|
38381
|
+
function decodeCachedEvent(value) {
|
|
38382
|
+
const payload = external_exports.record(external_exports.string(), external_exports.unknown()).parse(value);
|
|
38383
|
+
const event = decodeSessionEventV2({
|
|
38384
|
+
...payload,
|
|
38385
|
+
eventId: "cached-event",
|
|
38386
|
+
position: "1",
|
|
38387
|
+
provenance: { kind: "original" },
|
|
38388
|
+
recordedAt: "1970-01-01T00:00:00.000Z",
|
|
38389
|
+
sessionId: "cached-session"
|
|
38390
|
+
});
|
|
38391
|
+
return event.type === "acp" ? { payload: event.payload, type: event.type } : { payload: event.payload, type: event.type };
|
|
38392
|
+
}
|
|
38393
|
+
var CachedAcpSessionEventStoreV2 = class {
|
|
38394
|
+
generationId;
|
|
38395
|
+
#database;
|
|
38396
|
+
#ignoredPersistedSessions = /* @__PURE__ */ new Set();
|
|
38397
|
+
#localDatabase;
|
|
38398
|
+
#sessions = /* @__PURE__ */ new Map();
|
|
38399
|
+
#flushSchedule = { kind: "idle" };
|
|
38400
|
+
#isLocalDBAvailable = true;
|
|
38401
|
+
constructor(localDatabase, generationId) {
|
|
38402
|
+
this.generationId = generationId;
|
|
38403
|
+
this.#localDatabase = localDatabase;
|
|
38404
|
+
this.#database = localDatabase.orm;
|
|
38405
|
+
try {
|
|
38406
|
+
this.#localDatabase.transaction(() => this.#database.delete(sessionEventV2).run());
|
|
38407
|
+
} catch (error62) {
|
|
38408
|
+
this.#localDatabase.close();
|
|
38409
|
+
throw error62;
|
|
38410
|
+
}
|
|
38411
|
+
}
|
|
38412
|
+
append = (sessionId, event) => {
|
|
38413
|
+
if (this.#flushSchedule.kind === "closed") {
|
|
38414
|
+
throw new Error("The V2 Session event store is closed");
|
|
38415
|
+
}
|
|
38416
|
+
const session = this.#sessions.get(sessionId) ?? { hot: [], nextPosition: 1 };
|
|
38417
|
+
const position = session.nextPosition;
|
|
38418
|
+
session.hot.push({ event, position });
|
|
38419
|
+
session.nextPosition += 1;
|
|
38420
|
+
this.#sessions.set(sessionId, session);
|
|
38421
|
+
if (session.hot.length > HOT_EVENT_HIGH_WATER_MARK) {
|
|
38422
|
+
this.#scheduleFlush();
|
|
38423
|
+
}
|
|
38424
|
+
return position;
|
|
38425
|
+
};
|
|
38426
|
+
#scheduleFlush = () => {
|
|
38427
|
+
if (!this.#isLocalDBAvailable || this.#flushSchedule.kind !== "idle") {
|
|
38428
|
+
return;
|
|
38429
|
+
}
|
|
38430
|
+
const handle = setImmediate(() => {
|
|
38431
|
+
if (this.#flushSchedule.kind !== "scheduled" || this.#flushSchedule.handle !== handle) {
|
|
38432
|
+
return;
|
|
38433
|
+
}
|
|
38434
|
+
this.#flushSchedule = { kind: "idle" };
|
|
38435
|
+
this.#flush(false);
|
|
38436
|
+
});
|
|
38437
|
+
this.#flushSchedule = { handle, kind: "scheduled" };
|
|
38438
|
+
};
|
|
38439
|
+
#flush = (includeHotTail) => {
|
|
38440
|
+
if (!this.#isLocalDBAvailable || this.#flushSchedule.kind === "closed") {
|
|
38441
|
+
return;
|
|
38442
|
+
}
|
|
38443
|
+
const batches = [...this.#sessions.entries()].flatMap(([sessionId, session]) => {
|
|
38444
|
+
const count = includeHotTail ? session.hot.length : Math.max(0, session.hot.length - HOT_EVENT_RETENTION);
|
|
38445
|
+
return count === 0 ? [] : [{ count, events: session.hot.slice(0, count), sessionId }];
|
|
38446
|
+
});
|
|
38447
|
+
const values = batches.flatMap(
|
|
38448
|
+
(batch) => batch.events.map(({ event, position }) => ({
|
|
38449
|
+
eventJson: JSON.stringify(event),
|
|
38450
|
+
generationId: this.generationId,
|
|
38451
|
+
position,
|
|
38452
|
+
sessionId: batch.sessionId
|
|
38453
|
+
}))
|
|
38454
|
+
);
|
|
38455
|
+
if (values.length === 0) {
|
|
38456
|
+
return;
|
|
38457
|
+
}
|
|
38458
|
+
try {
|
|
38459
|
+
this.#localDatabase.transaction(() => {
|
|
38460
|
+
for (let offset = 0; offset < values.length; offset += 200) {
|
|
38461
|
+
this.#database.insert(sessionEventV2).values(values.slice(offset, offset + 200)).run();
|
|
38462
|
+
}
|
|
38463
|
+
});
|
|
38464
|
+
for (const batch of batches) {
|
|
38465
|
+
this.#sessions.get(batch.sessionId)?.hot.splice(0, batch.count);
|
|
38466
|
+
}
|
|
38467
|
+
} catch (cause) {
|
|
38468
|
+
this.#isLocalDBAvailable = false;
|
|
38469
|
+
console.warn("Mobius V2 Session event cache writes are unavailable; retaining events in memory", cause);
|
|
38470
|
+
}
|
|
38471
|
+
};
|
|
38472
|
+
page = (sessionId, eventLimit, cursor) => {
|
|
38473
|
+
const session = this.#sessions.get(sessionId);
|
|
38474
|
+
const eventCount = (session?.nextPosition ?? 1) - 1;
|
|
38475
|
+
return eventPage(eventCount, eventLimit, cursor, (startPosition, endPosition) => {
|
|
38476
|
+
const persisted = this.#ignoredPersistedSessions.has(sessionId) ? [] : this.#database.select({ eventJson: sessionEventV2.eventJson, position: sessionEventV2.position }).from(sessionEventV2).where(
|
|
38477
|
+
and(
|
|
38478
|
+
eq(sessionEventV2.generationId, this.generationId),
|
|
38479
|
+
eq(sessionEventV2.sessionId, sessionId),
|
|
38480
|
+
gte(sessionEventV2.position, startPosition),
|
|
38481
|
+
lte(sessionEventV2.position, endPosition)
|
|
38482
|
+
)
|
|
38483
|
+
).orderBy(asc(sessionEventV2.position)).all().map((value) => {
|
|
38484
|
+
const row = cachedEventRowSchema.parse(value);
|
|
38485
|
+
return { event: decodeCachedEvent(JSON.parse(row.eventJson)), position: row.position };
|
|
38486
|
+
});
|
|
38487
|
+
const hot = (session?.hot ?? []).filter(
|
|
38488
|
+
({ position }) => position >= startPosition && position <= endPosition
|
|
38489
|
+
);
|
|
38490
|
+
return [...persisted, ...hot].toSorted((left, right) => left.position - right.position).map(({ event }) => event);
|
|
38491
|
+
});
|
|
38492
|
+
};
|
|
38493
|
+
#deletePersisted = (sessionId) => {
|
|
38494
|
+
if (!this.#isLocalDBAvailable) {
|
|
38495
|
+
this.#ignoredPersistedSessions.add(sessionId);
|
|
38496
|
+
return;
|
|
38497
|
+
}
|
|
38498
|
+
try {
|
|
38499
|
+
this.#database.delete(sessionEventV2).where(and(eq(sessionEventV2.generationId, this.generationId), eq(sessionEventV2.sessionId, sessionId))).run();
|
|
38500
|
+
this.#ignoredPersistedSessions.delete(sessionId);
|
|
38501
|
+
} catch (cause) {
|
|
38502
|
+
this.#isLocalDBAvailable = false;
|
|
38503
|
+
this.#ignoredPersistedSessions.add(sessionId);
|
|
38504
|
+
console.warn("Mobius V2 Session event cache writes are unavailable; retaining events in memory", cause);
|
|
38505
|
+
}
|
|
38506
|
+
};
|
|
38507
|
+
remove = (sessionId) => {
|
|
38508
|
+
this.#deletePersisted(sessionId);
|
|
38509
|
+
this.#sessions.delete(sessionId);
|
|
38510
|
+
};
|
|
38511
|
+
reset = this.remove;
|
|
38512
|
+
close = () => {
|
|
38513
|
+
if (this.#flushSchedule.kind === "closed") {
|
|
38514
|
+
return;
|
|
38515
|
+
}
|
|
38516
|
+
if (this.#flushSchedule.kind === "scheduled") {
|
|
38517
|
+
clearImmediate(this.#flushSchedule.handle);
|
|
38518
|
+
}
|
|
38519
|
+
this.#flushSchedule = { kind: "idle" };
|
|
38520
|
+
this.#flush(true);
|
|
38521
|
+
this.#flushSchedule = { kind: "closed" };
|
|
38522
|
+
this.#localDatabase.close();
|
|
38523
|
+
this.#sessions.clear();
|
|
38524
|
+
};
|
|
38525
|
+
};
|
|
38526
|
+
|
|
38653
38527
|
// src/acp/session-store.ts
|
|
38654
38528
|
var AcpStoredSession = class {
|
|
38655
38529
|
additionalDirectories;
|
|
@@ -38685,9 +38559,14 @@ var FoundAcpStoredSession = class extends AcpStoredSessionLookup {
|
|
|
38685
38559
|
}
|
|
38686
38560
|
};
|
|
38687
38561
|
var MemoryAcpSessionStore = class {
|
|
38562
|
+
eventsV2;
|
|
38688
38563
|
#sessions = /* @__PURE__ */ new Map();
|
|
38564
|
+
constructor(eventsV2 = new MemoryAcpSessionEventStoreV2(randomUUID2())) {
|
|
38565
|
+
this.eventsV2 = eventsV2;
|
|
38566
|
+
}
|
|
38689
38567
|
close = () => {
|
|
38690
38568
|
this.#sessions.clear();
|
|
38569
|
+
this.eventsV2.close();
|
|
38691
38570
|
};
|
|
38692
38571
|
findNative = (agentId, nativeSessionId) => [...this.#sessions.values()].filter(
|
|
38693
38572
|
(session) => session.agentId === agentId && session.nativeSessionId === nativeSessionId
|
|
@@ -38699,6 +38578,7 @@ var MemoryAcpSessionStore = class {
|
|
|
38699
38578
|
};
|
|
38700
38579
|
remove = (sessionId) => {
|
|
38701
38580
|
this.#sessions.delete(sessionId);
|
|
38581
|
+
this.eventsV2.remove(sessionId);
|
|
38702
38582
|
};
|
|
38703
38583
|
write = (session) => {
|
|
38704
38584
|
this.#sessions.set(session.sessionId, session);
|
|
@@ -38730,39 +38610,20 @@ function decodeStoredSession(value) {
|
|
|
38730
38610
|
);
|
|
38731
38611
|
}
|
|
38732
38612
|
var SqliteAcpSessionStore = class {
|
|
38613
|
+
eventsV2;
|
|
38733
38614
|
#database;
|
|
38734
|
-
#
|
|
38735
|
-
constructor(
|
|
38736
|
-
|
|
38737
|
-
this.#
|
|
38738
|
-
|
|
38739
|
-
this.#migrate();
|
|
38740
|
-
this.#database = drizzle({ client: this.#sqliteDatabase });
|
|
38615
|
+
#localDatabase;
|
|
38616
|
+
constructor(localDatabase, eventsV2 = new MemoryAcpSessionEventStoreV2(randomUUID2())) {
|
|
38617
|
+
this.eventsV2 = eventsV2;
|
|
38618
|
+
this.#localDatabase = localDatabase;
|
|
38619
|
+
this.#database = localDatabase.orm;
|
|
38741
38620
|
}
|
|
38742
|
-
#migrate = () => {
|
|
38743
|
-
const version2 = external_exports.object({ user_version: external_exports.number().int().nonnegative() }).parse(this.#sqliteDatabase.prepare("PRAGMA user_version").get()).user_version;
|
|
38744
|
-
if (version2 > acpSessionStoreMigrations.length) {
|
|
38745
|
-
this.#sqliteDatabase.close();
|
|
38746
|
-
throw new Error("The ACP Session database was created by a newer Mobius version");
|
|
38747
|
-
}
|
|
38748
|
-
for (let index = version2; index < acpSessionStoreMigrations.length; index += 1) {
|
|
38749
|
-
const migration = acpSessionStoreMigrations[index];
|
|
38750
|
-
if (migration === void 0) {
|
|
38751
|
-
throw new Error("The ACP Session migration is unavailable");
|
|
38752
|
-
}
|
|
38753
|
-
this.#sqliteDatabase.exec("BEGIN IMMEDIATE");
|
|
38754
|
-
try {
|
|
38755
|
-
this.#sqliteDatabase.exec(migration.sql);
|
|
38756
|
-
this.#sqliteDatabase.exec(`PRAGMA user_version = ${index + 1}`);
|
|
38757
|
-
this.#sqliteDatabase.exec("COMMIT");
|
|
38758
|
-
} catch (error62) {
|
|
38759
|
-
this.#sqliteDatabase.exec("ROLLBACK");
|
|
38760
|
-
throw error62;
|
|
38761
|
-
}
|
|
38762
|
-
}
|
|
38763
|
-
};
|
|
38764
38621
|
close = () => {
|
|
38765
|
-
|
|
38622
|
+
try {
|
|
38623
|
+
this.#localDatabase.close();
|
|
38624
|
+
} finally {
|
|
38625
|
+
this.eventsV2.close();
|
|
38626
|
+
}
|
|
38766
38627
|
};
|
|
38767
38628
|
findNative = (agentId, nativeSessionId) => this.#database.select().from(acpSession).where(and(eq(acpSession.agentId, agentId), eq(acpSession.nativeSessionId, nativeSessionId))).all().map(decodeStoredSession);
|
|
38768
38629
|
list = () => this.#database.select().from(acpSession).orderBy(desc(acpSession.updatedAt)).all().map(decodeStoredSession);
|
|
@@ -38772,6 +38633,7 @@ var SqliteAcpSessionStore = class {
|
|
|
38772
38633
|
};
|
|
38773
38634
|
remove = (sessionId) => {
|
|
38774
38635
|
this.#database.delete(acpSession).where(eq(acpSession.sessionId, sessionId)).run();
|
|
38636
|
+
this.eventsV2.remove(sessionId);
|
|
38775
38637
|
};
|
|
38776
38638
|
write = (session) => {
|
|
38777
38639
|
const value = {
|
|
@@ -38797,7 +38659,7 @@ var RetryableAcpInitializationError = class extends AcpExecutionError {
|
|
|
38797
38659
|
}
|
|
38798
38660
|
};
|
|
38799
38661
|
function arraysEqual(left, right) {
|
|
38800
|
-
return left.length === right.length && left.every((value,
|
|
38662
|
+
return left.length === right.length && left.every((value, index2) => value === right[index2]);
|
|
38801
38663
|
}
|
|
38802
38664
|
function recordsEqual(left, right) {
|
|
38803
38665
|
const leftEntries = Object.entries(left);
|
|
@@ -38852,7 +38714,7 @@ var AgentSession = class _AgentSession {
|
|
|
38852
38714
|
commandId: () => this.#turn.commandId,
|
|
38853
38715
|
assertNativeSession: (sessionId) => this.assertNativeSession(sessionId),
|
|
38854
38716
|
observer: getObserver,
|
|
38855
|
-
recordSessionEventV2: this
|
|
38717
|
+
recordSessionEventV2: this.recordLifecycleEventV2
|
|
38856
38718
|
});
|
|
38857
38719
|
this.#connection = new AgentConnection(agent, cwd, this);
|
|
38858
38720
|
this.#contentExternalizer = contentExternalizer;
|
|
@@ -38960,12 +38822,17 @@ var AgentSession = class _AgentSession {
|
|
|
38960
38822
|
);
|
|
38961
38823
|
}
|
|
38962
38824
|
const history = await this.#completedHistory(signal, "ACP agent exited while loading history");
|
|
38963
|
-
return history.eventPage(eventLimit, cursor
|
|
38825
|
+
return history.eventPage(eventLimit, cursor);
|
|
38964
38826
|
};
|
|
38965
38827
|
async #completedHistory(signal, exitMessage) {
|
|
38966
38828
|
if (!this.#prompted && this.#nativeHistoryOwnership.kind === "fresh-session") {
|
|
38967
38829
|
if (this.#sessionLoad.kind === "not-requested") {
|
|
38968
|
-
this.#
|
|
38830
|
+
this.#store.eventsV2.reset(this.#mobiusSessionId);
|
|
38831
|
+
this.#sessionLoad = {
|
|
38832
|
+
history: new AcpHistoryReplay(this.#store.eventsV2, this.#mobiusSessionId),
|
|
38833
|
+
kind: "loaded",
|
|
38834
|
+
response: {}
|
|
38835
|
+
};
|
|
38969
38836
|
}
|
|
38970
38837
|
if (this.#sessionLoad.kind === "loaded") {
|
|
38971
38838
|
return this.#sessionLoad.history;
|
|
@@ -38980,7 +38847,8 @@ var AgentSession = class _AgentSession {
|
|
|
38980
38847
|
if (this.#sessionLoad.kind === "capturing") {
|
|
38981
38848
|
return await waitForSharedOperation(this.#sessionLoad.completion, signal);
|
|
38982
38849
|
}
|
|
38983
|
-
|
|
38850
|
+
this.#store.eventsV2.reset(this.#mobiusSessionId);
|
|
38851
|
+
const history = new AcpHistoryReplay(this.#store.eventsV2, this.#mobiusSessionId);
|
|
38984
38852
|
const completion = Promise.resolve().then(async () => {
|
|
38985
38853
|
try {
|
|
38986
38854
|
const response = await this.race(
|
|
@@ -39429,7 +39297,14 @@ var AgentSession = class _AgentSession {
|
|
|
39429
39297
|
if (this.#turn.running) {
|
|
39430
39298
|
throw new AcpExecutionError("Another prompt is already running in this conversation", {}, "session_busy");
|
|
39431
39299
|
}
|
|
39432
|
-
|
|
39300
|
+
if (!this.#capabilities.loadSession && this.#sessionLoad.kind === "not-requested") {
|
|
39301
|
+
this.#sessionLoad = {
|
|
39302
|
+
kind: "loaded",
|
|
39303
|
+
history: new AcpHistoryReplay(this.#store.eventsV2, this.#mobiusSessionId),
|
|
39304
|
+
response: {}
|
|
39305
|
+
};
|
|
39306
|
+
}
|
|
39307
|
+
const completedHistory = this.#capabilities.loadSession ? await this.#completedHistory(options.signal, "ACP agent exited while loading history before a prompt") : this.#sessionLoad.kind === "loaded" ? this.#sessionLoad.history : null;
|
|
39433
39308
|
const prompt = this.buildPrompt(options);
|
|
39434
39309
|
if (this.#sessionTitle === null || this.#sessionTitle.length === 0) {
|
|
39435
39310
|
this.#sessionTitle = truncate(options.prompt, 500);
|
|
@@ -39455,14 +39330,19 @@ var AgentSession = class _AgentSession {
|
|
|
39455
39330
|
this.prepareAgentContent
|
|
39456
39331
|
);
|
|
39457
39332
|
this.#turn = running;
|
|
39458
|
-
this.#turnHistory = completedHistory === null ? null : new AcpHistoryReplay();
|
|
39333
|
+
this.#turnHistory = completedHistory === null ? null : new AcpHistoryReplay(this.#store.eventsV2, this.#mobiusSessionId);
|
|
39459
39334
|
const lifecycleV2 = options.lifecycleV2;
|
|
39460
39335
|
if (lifecycleV2 !== void 0) {
|
|
39461
|
-
await this
|
|
39462
|
-
payload: {
|
|
39336
|
+
await this.recordLifecycleEventV2({
|
|
39337
|
+
payload: {
|
|
39338
|
+
commandId: options.commandId,
|
|
39339
|
+
content: lifecycleV2.content,
|
|
39340
|
+
kind: "prompt.requested",
|
|
39341
|
+
...lifecycleV2.context === void 0 ? {} : { context: lifecycleV2.context }
|
|
39342
|
+
},
|
|
39463
39343
|
type: "lifecycle-metadata"
|
|
39464
39344
|
});
|
|
39465
|
-
await this
|
|
39345
|
+
await this.recordLifecycleEventV2({
|
|
39466
39346
|
payload: {
|
|
39467
39347
|
attemptId: lifecycleV2.attemptId,
|
|
39468
39348
|
commandId: options.commandId,
|
|
@@ -39525,7 +39405,7 @@ var AgentSession = class _AgentSession {
|
|
|
39525
39405
|
)
|
|
39526
39406
|
);
|
|
39527
39407
|
if (lifecycleV2 !== void 0) {
|
|
39528
|
-
await this
|
|
39408
|
+
await this.recordLifecycleEventV2({
|
|
39529
39409
|
payload: { commandId: options.commandId, kind: "prompt.completed", stopReason: result.stopReason },
|
|
39530
39410
|
type: "lifecycle-metadata"
|
|
39531
39411
|
});
|
|
@@ -39535,8 +39415,8 @@ var AgentSession = class _AgentSession {
|
|
|
39535
39415
|
await running.activities.finish();
|
|
39536
39416
|
const failure2 = error62 instanceof AcpExecutionError ? error62 : new AcpExecutionError("ACP agent execution failed", { cause: error62 });
|
|
39537
39417
|
if (lifecycleV2 !== void 0) {
|
|
39538
|
-
await this
|
|
39539
|
-
payload: {
|
|
39418
|
+
await this.recordLifecycleEventV2({
|
|
39419
|
+
payload: options.cancellationRequested?.() === true ? { commandId: options.commandId, kind: "prompt.completed", stopReason: "cancelled" } : {
|
|
39540
39420
|
attemptId: lifecycleV2.attemptId,
|
|
39541
39421
|
code: failure2.code,
|
|
39542
39422
|
commandId: options.commandId,
|
|
@@ -39572,11 +39452,16 @@ var AgentSession = class _AgentSession {
|
|
|
39572
39452
|
const prompt = this.buildPrompt(options);
|
|
39573
39453
|
const lifecycleV2 = options.lifecycleV2;
|
|
39574
39454
|
if (lifecycleV2 !== void 0) {
|
|
39575
|
-
await this
|
|
39576
|
-
payload: {
|
|
39455
|
+
await this.recordLifecycleEventV2({
|
|
39456
|
+
payload: {
|
|
39457
|
+
commandId: options.commandId,
|
|
39458
|
+
content: lifecycleV2.content,
|
|
39459
|
+
kind: "prompt.requested",
|
|
39460
|
+
...lifecycleV2.context === void 0 ? {} : { context: lifecycleV2.context }
|
|
39461
|
+
},
|
|
39577
39462
|
type: "lifecycle-metadata"
|
|
39578
39463
|
});
|
|
39579
|
-
await this
|
|
39464
|
+
await this.recordLifecycleEventV2({
|
|
39580
39465
|
payload: {
|
|
39581
39466
|
attemptId: lifecycleV2.attemptId,
|
|
39582
39467
|
commandId: options.commandId,
|
|
@@ -39606,7 +39491,7 @@ var AgentSession = class _AgentSession {
|
|
|
39606
39491
|
const outcome = response["outcome"];
|
|
39607
39492
|
if (outcome === "injected" || outcome === "startedNewTurn") {
|
|
39608
39493
|
if (lifecycleV2 !== void 0) {
|
|
39609
|
-
await this
|
|
39494
|
+
await this.recordLifecycleEventV2({
|
|
39610
39495
|
payload: { commandId: options.commandId, kind: "prompt.completed", stopReason: "steered" },
|
|
39611
39496
|
type: "lifecycle-metadata"
|
|
39612
39497
|
});
|
|
@@ -39631,7 +39516,7 @@ var AgentSession = class _AgentSession {
|
|
|
39631
39516
|
} catch (error62) {
|
|
39632
39517
|
const failure2 = error62 instanceof AcpExecutionError ? error62 : new AcpExecutionError("ACP agent execution failed", { cause: error62 });
|
|
39633
39518
|
if (lifecycleV2 !== void 0) {
|
|
39634
|
-
await this
|
|
39519
|
+
await this.recordLifecycleEventV2({
|
|
39635
39520
|
payload: {
|
|
39636
39521
|
attemptId: lifecycleV2.attemptId,
|
|
39637
39522
|
code: failure2.code,
|
|
@@ -39664,11 +39549,18 @@ var AgentSession = class _AgentSession {
|
|
|
39664
39549
|
onElicitation = (request, signal) => this.#interactions.onElicitation(request, signal);
|
|
39665
39550
|
onElicitationComplete = (notification) => this.#interactions.onElicitationComplete(notification);
|
|
39666
39551
|
onUpdate = (notification) => this.#updates.receive(notification);
|
|
39667
|
-
|
|
39552
|
+
recordControlEventV2 = async (event) => {
|
|
39553
|
+
if (this.#sessionLoad.kind !== "loaded") {
|
|
39554
|
+
return false;
|
|
39555
|
+
}
|
|
39556
|
+
await this.recordLifecycleEventV2(event);
|
|
39557
|
+
return true;
|
|
39558
|
+
};
|
|
39559
|
+
recordLifecycleEventV2 = async (event) => {
|
|
39668
39560
|
if (event.type !== "lifecycle-metadata" || this.#sessionLoad.kind !== "loaded") {
|
|
39669
39561
|
return;
|
|
39670
39562
|
}
|
|
39671
|
-
const position = this.#turnHistory === null ? this.#sessionLoad.history.recordLifecycle(event) : this.#
|
|
39563
|
+
const position = this.#turnHistory === null ? this.#sessionLoad.history.recordLifecycle(event) : this.#turnHistory.recordLifecycle(event);
|
|
39672
39564
|
await this.#getObserver().onSessionEventV2?.(this.#mobiusSessionId, event, position);
|
|
39673
39565
|
};
|
|
39674
39566
|
selectNativeSession = (sessionId) => {
|
|
@@ -39689,13 +39581,8 @@ var AgentSession = class _AgentSession {
|
|
|
39689
39581
|
} else {
|
|
39690
39582
|
const onSessionEventV2 = this.#getObserver().onSessionEventV2;
|
|
39691
39583
|
if (this.#turnHistory !== null) {
|
|
39692
|
-
|
|
39693
|
-
|
|
39694
|
-
await onSessionEventV2?.(
|
|
39695
|
-
this.#mobiusSessionId,
|
|
39696
|
-
{ payload: rawUpdate, type: "acp" },
|
|
39697
|
-
completedEventCount + turnPosition
|
|
39698
|
-
);
|
|
39584
|
+
await this.#turnHistory.record(update, rawUpdate, async (position) => {
|
|
39585
|
+
await onSessionEventV2?.(this.#mobiusSessionId, { payload: rawUpdate, type: "acp" }, position);
|
|
39699
39586
|
});
|
|
39700
39587
|
} else if (this.#sessionLoad.kind === "loaded") {
|
|
39701
39588
|
await this.#sessionLoad.history.record(update, rawUpdate, async (position) => {
|
|
@@ -40338,9 +40225,9 @@ var AcpContentExternalizer = class {
|
|
|
40338
40225
|
};
|
|
40339
40226
|
|
|
40340
40227
|
// src/external-content/local-external-content-store.ts
|
|
40341
|
-
import { createHash as createHash3, randomUUID as
|
|
40228
|
+
import { createHash as createHash3, randomUUID as randomUUID3 } from "node:crypto";
|
|
40342
40229
|
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";
|
|
40343
|
-
import { dirname as
|
|
40230
|
+
import { dirname as dirname4, join as join16 } from "node:path";
|
|
40344
40231
|
var contentRequest = /^mobius-content:(image|audio|resource):([a-f0-9]{64})$/u;
|
|
40345
40232
|
var CONTENT_LIFETIME_MILLISECONDS = 24 * 60 * 60 * 1e3;
|
|
40346
40233
|
var metadataSchema2 = external_exports.strictObject({
|
|
@@ -40359,7 +40246,7 @@ var UnretainedExternalContentStore = class {
|
|
|
40359
40246
|
};
|
|
40360
40247
|
};
|
|
40361
40248
|
async function atomicWrite(path3, bytes, signal) {
|
|
40362
|
-
const temporary = `${path3}.${
|
|
40249
|
+
const temporary = `${path3}.${randomUUID3()}.tmp`;
|
|
40363
40250
|
try {
|
|
40364
40251
|
await writeFile4(temporary, bytes, { mode: 384, signal });
|
|
40365
40252
|
signal.throwIfAborted();
|
|
@@ -40376,7 +40263,7 @@ var LocalExternalContentStore = class {
|
|
|
40376
40263
|
#expirationTimer;
|
|
40377
40264
|
#cleanup = Promise.resolve();
|
|
40378
40265
|
constructor(stateDirectory) {
|
|
40379
|
-
this.#root = join16(stateDirectory, "tmp", "session-content",
|
|
40266
|
+
this.#root = join16(stateDirectory, "tmp", "session-content", randomUUID3());
|
|
40380
40267
|
this.#expirationTimer = setInterval(() => {
|
|
40381
40268
|
void this.#expire().catch(() => void 0);
|
|
40382
40269
|
}, 6e4);
|
|
@@ -40387,11 +40274,11 @@ var LocalExternalContentStore = class {
|
|
|
40387
40274
|
await mkdir6(this.#root, { mode: 448, recursive: true });
|
|
40388
40275
|
const now = /* @__PURE__ */ new Date();
|
|
40389
40276
|
await utimes(this.#root, now, now);
|
|
40390
|
-
for (const directory of await readdir3(
|
|
40277
|
+
for (const directory of await readdir3(dirname4(this.#root), { withFileTypes: true })) {
|
|
40391
40278
|
if (!directory.isDirectory() || !/^[a-f0-9-]{36}$/u.test(directory.name)) {
|
|
40392
40279
|
continue;
|
|
40393
40280
|
}
|
|
40394
|
-
const path3 = join16(
|
|
40281
|
+
const path3 = join16(dirname4(this.#root), directory.name);
|
|
40395
40282
|
if (path3 === this.#root) {
|
|
40396
40283
|
continue;
|
|
40397
40284
|
}
|
|
@@ -40477,12 +40364,12 @@ var LocalExternalContentStore = class {
|
|
|
40477
40364
|
}
|
|
40478
40365
|
try {
|
|
40479
40366
|
const [resolvedDirectory, resolvedPath, file2] = await Promise.all([
|
|
40480
|
-
realpath8(
|
|
40367
|
+
realpath8(dirname4(entry.path)),
|
|
40481
40368
|
realpath8(entry.path),
|
|
40482
40369
|
lstat(entry.path)
|
|
40483
40370
|
]);
|
|
40484
40371
|
signal.throwIfAborted();
|
|
40485
|
-
if (!file2.isFile() || file2.isSymbolicLink() ||
|
|
40372
|
+
if (!file2.isFile() || file2.isSymbolicLink() || dirname4(resolvedPath) !== resolvedDirectory) {
|
|
40486
40373
|
return null;
|
|
40487
40374
|
}
|
|
40488
40375
|
return { mediaType: entry.mediaType, name: entry.name, path: resolvedPath };
|
|
@@ -40559,9 +40446,9 @@ var AcpProcessCapacityLock = class {
|
|
|
40559
40446
|
return await waiter.completion.promise;
|
|
40560
40447
|
} finally {
|
|
40561
40448
|
signal.removeEventListener("abort", waiter.cancel);
|
|
40562
|
-
const
|
|
40563
|
-
if (
|
|
40564
|
-
this.#waiters.splice(
|
|
40449
|
+
const index2 = this.#waiters.indexOf(waiter);
|
|
40450
|
+
if (index2 >= 0) {
|
|
40451
|
+
this.#waiters.splice(index2, 1);
|
|
40565
40452
|
}
|
|
40566
40453
|
}
|
|
40567
40454
|
};
|
|
@@ -40732,6 +40619,13 @@ var AgentRuntimeManager = class {
|
|
|
40732
40619
|
this.#contentExternalizer = contentExternalizer;
|
|
40733
40620
|
this.#queryProcesses = new AgentQueryProcesses(this.#processes, contentExternalizer);
|
|
40734
40621
|
}
|
|
40622
|
+
recordLifecycleEventV2 = async (sessionId, event) => {
|
|
40623
|
+
const runtime = this.#executionProcesses.get(sessionId);
|
|
40624
|
+
if (runtime === void 0) {
|
|
40625
|
+
return false;
|
|
40626
|
+
}
|
|
40627
|
+
return await runtime.recordControlEventV2(event);
|
|
40628
|
+
};
|
|
40735
40629
|
setObserver = (observer) => {
|
|
40736
40630
|
this.#observer = observer;
|
|
40737
40631
|
};
|
|
@@ -41061,7 +40955,10 @@ var AgentRuntimeManager = class {
|
|
|
41061
40955
|
return { stopReason: "cancelled" };
|
|
41062
40956
|
}
|
|
41063
40957
|
try {
|
|
41064
|
-
const result = await runtime.prompt(
|
|
40958
|
+
const result = await runtime.prompt({
|
|
40959
|
+
...options2,
|
|
40960
|
+
cancellationRequested: () => this.#executions.cancellation(options2.sessionId) !== void 0
|
|
40961
|
+
});
|
|
41065
40962
|
return this.#executions.cancellation(options2.sessionId) !== void 0 ? { stopReason: "cancelled" } : result;
|
|
41066
40963
|
} catch (error62) {
|
|
41067
40964
|
if (this.#executions.cancellation(options2.sessionId) !== void 0) {
|
|
@@ -41921,7 +41818,7 @@ var FixedInstallationExecutor = class {
|
|
|
41921
41818
|
// src/authorization/workspace-directory.ts
|
|
41922
41819
|
import { readdir as readdir4, realpath as realpath9, stat as stat8 } from "node:fs/promises";
|
|
41923
41820
|
import { homedir as homedir2 } from "node:os";
|
|
41924
|
-
import { basename as basename4, dirname as
|
|
41821
|
+
import { basename as basename4, dirname as dirname5, isAbsolute as isAbsolute9, join as join17, normalize as normalize3, relative as relative4 } from "node:path";
|
|
41925
41822
|
|
|
41926
41823
|
// src/authorization/local-authorization-error.ts
|
|
41927
41824
|
var LocalAuthorizationError = class extends Error {
|
|
@@ -42060,7 +41957,7 @@ var WorkspaceDirectoryService = class {
|
|
|
42060
41957
|
}
|
|
42061
41958
|
}
|
|
42062
41959
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
42063
|
-
const parent =
|
|
41960
|
+
const parent = dirname5(target);
|
|
42064
41961
|
return new WorkspaceDirectoryListing(
|
|
42065
41962
|
id,
|
|
42066
41963
|
this.label(target),
|
|
@@ -42085,7 +41982,7 @@ var WorkspaceDirectoryService = class {
|
|
|
42085
41982
|
};
|
|
42086
41983
|
|
|
42087
41984
|
// src/daemon-diagnostic-log.ts
|
|
42088
|
-
import { appendFileSync, mkdirSync
|
|
41985
|
+
import { appendFileSync, mkdirSync, readFileSync as readFileSync2, renameSync, statSync as statSync3, writeFileSync } from "node:fs";
|
|
42089
41986
|
import { join as join18 } from "node:path";
|
|
42090
41987
|
var MAXIMUM_DAEMON_LOG_BYTES = 1 * 1024 * 1024;
|
|
42091
41988
|
var DaemonDiagnosticLog = class {
|
|
@@ -42101,7 +41998,7 @@ var DaemonDiagnosticLog = class {
|
|
|
42101
41998
|
const encoded = `${diagnostic.replace(/[\r\n]+/gu, " ").trim()}
|
|
42102
41999
|
`;
|
|
42103
42000
|
const encodedBytes = Buffer.byteLength(encoded);
|
|
42104
|
-
|
|
42001
|
+
mkdirSync(this.#directory, { mode: 448, recursive: true });
|
|
42105
42002
|
let existingBytes = 0;
|
|
42106
42003
|
try {
|
|
42107
42004
|
existingBytes = statSync3(this.#path).size;
|
|
@@ -42359,16 +42256,7 @@ function send(socket, message) {
|
|
|
42359
42256
|
}
|
|
42360
42257
|
socket.send(encodeDaemonToServiceMessage(message));
|
|
42361
42258
|
}
|
|
42362
|
-
function
|
|
42363
|
-
publisher.publish(command.sessionId, {
|
|
42364
|
-
code,
|
|
42365
|
-
commandId: command.commandId,
|
|
42366
|
-
kind: SESSION_FAILED_KIND,
|
|
42367
|
-
message,
|
|
42368
|
-
sessionId: command.sessionId
|
|
42369
|
-
});
|
|
42370
|
-
}
|
|
42371
|
-
function settleAbandonedTurn(publisher, operations, audit, cancellation) {
|
|
42259
|
+
async function settleAbandonedTurn(eventLog, operations, audit, cancellation) {
|
|
42372
42260
|
const attemptId = operations.findUnsettledAttemptId(cancellation.commandId, cancellation.sessionId);
|
|
42373
42261
|
if (attemptId === null) {
|
|
42374
42262
|
console.warn("Mobius daemon ignored cancellation for an inactive turn");
|
|
@@ -42379,13 +42267,14 @@ function settleAbandonedTurn(publisher, operations, audit, cancellation) {
|
|
|
42379
42267
|
event: "session_abandoned_turn_settled",
|
|
42380
42268
|
sessionId: cancellation.sessionId
|
|
42381
42269
|
});
|
|
42382
|
-
|
|
42383
|
-
|
|
42384
|
-
cancellation,
|
|
42270
|
+
await eventLog.failed(
|
|
42271
|
+
cancellation.sessionId,
|
|
42272
|
+
cancellation.commandId,
|
|
42385
42273
|
"agent_execution_abandoned",
|
|
42386
42274
|
"The local Agent execution was abandoned before it completed"
|
|
42387
42275
|
);
|
|
42388
42276
|
operations.transitionExecution(cancellation.commandId, "failed");
|
|
42277
|
+
eventLog.publishTerminal(cancellation.sessionId, cancellation.commandId);
|
|
42389
42278
|
}
|
|
42390
42279
|
function operationErrorCode(error62) {
|
|
42391
42280
|
if (error62 instanceof AcpExecutionError || error62 instanceof LocalAuthorizationError || error62 instanceof LocalAgentCatalogError || error62 instanceof PromptArtifactError) {
|
|
@@ -42566,7 +42455,7 @@ var DaemonInstallationObserver = class {
|
|
|
42566
42455
|
};
|
|
42567
42456
|
|
|
42568
42457
|
// src/daemon-active-turn.ts
|
|
42569
|
-
import { randomUUID as
|
|
42458
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
42570
42459
|
function activeMessageCharacters(message) {
|
|
42571
42460
|
return message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0);
|
|
42572
42461
|
}
|
|
@@ -42574,8 +42463,8 @@ var ACTIVE_TURN_TEXT_CHUNK_LIMIT = Math.floor(SESSION_HISTORY_CHARACTER_LIMIT /
|
|
|
42574
42463
|
function boundedRecoveryMessages(messages) {
|
|
42575
42464
|
const selected = [];
|
|
42576
42465
|
let remainingCharacters = SESSION_HISTORY_CHARACTER_LIMIT;
|
|
42577
|
-
for (let
|
|
42578
|
-
const message = messages[
|
|
42466
|
+
for (let index2 = messages.length - 1; index2 >= 0 && selected.length < SESSION_HISTORY_MESSAGE_LIMIT; index2 -= 1) {
|
|
42467
|
+
const message = messages[index2];
|
|
42579
42468
|
if (message === void 0) {
|
|
42580
42469
|
break;
|
|
42581
42470
|
}
|
|
@@ -42600,7 +42489,7 @@ var ActiveDaemonTurn = class {
|
|
|
42600
42489
|
#timeline;
|
|
42601
42490
|
#sequence = 0;
|
|
42602
42491
|
#interaction = null;
|
|
42603
|
-
#epoch = decodeIdentifier(
|
|
42492
|
+
#epoch = decodeIdentifier(randomUUID4());
|
|
42604
42493
|
constructor(command, attemptId) {
|
|
42605
42494
|
this.attemptId = attemptId;
|
|
42606
42495
|
this.command = command;
|
|
@@ -42662,7 +42551,7 @@ var ActiveDaemonTurn = class {
|
|
|
42662
42551
|
if (!this.#activities.has(event.activityId)) {
|
|
42663
42552
|
this.#timeline = [
|
|
42664
42553
|
...this.#timeline,
|
|
42665
|
-
{ activityId: event.activityId, id: decodeIdentifier(
|
|
42554
|
+
{ activityId: event.activityId, id: decodeIdentifier(randomUUID4()), kind: "activity" }
|
|
42666
42555
|
];
|
|
42667
42556
|
}
|
|
42668
42557
|
this.#activities.set(event.activityId, {
|
|
@@ -42683,7 +42572,7 @@ var ActiveDaemonTurn = class {
|
|
|
42683
42572
|
if (previous === void 0) {
|
|
42684
42573
|
this.#timeline = [
|
|
42685
42574
|
...this.#timeline,
|
|
42686
|
-
{ activityId: event.activityId, id: decodeIdentifier(
|
|
42575
|
+
{ activityId: event.activityId, id: decodeIdentifier(randomUUID4()), kind: "activity" }
|
|
42687
42576
|
];
|
|
42688
42577
|
}
|
|
42689
42578
|
this.#activities.set(event.activityId, {
|
|
@@ -42708,7 +42597,7 @@ var ActiveDaemonTurn = class {
|
|
|
42708
42597
|
...this.#timeline,
|
|
42709
42598
|
{
|
|
42710
42599
|
content: /* @__PURE__ */ new Map([[event.contentId, event.content]]),
|
|
42711
|
-
id: decodeIdentifier(
|
|
42600
|
+
id: decodeIdentifier(randomUUID4()),
|
|
42712
42601
|
kind: "message",
|
|
42713
42602
|
sourceMessageId: event.messageId,
|
|
42714
42603
|
text: ""
|
|
@@ -42716,7 +42605,7 @@ var ActiveDaemonTurn = class {
|
|
|
42716
42605
|
];
|
|
42717
42606
|
} else {
|
|
42718
42607
|
this.#timeline = this.#timeline.map(
|
|
42719
|
-
(entry,
|
|
42608
|
+
(entry, index2) => index2 === target && entry.kind === "message" ? { ...entry, content: new Map([...entry.content, [event.contentId, event.content]]) } : entry
|
|
42720
42609
|
);
|
|
42721
42610
|
}
|
|
42722
42611
|
} else if (event.kind === SESSION_PERMISSION_REQUESTED_KIND || event.kind === SESSION_ELICITATION_REQUESTED_KIND) {
|
|
@@ -42748,7 +42637,7 @@ var ActiveDaemonTurn = class {
|
|
|
42748
42637
|
...this.#timeline,
|
|
42749
42638
|
{
|
|
42750
42639
|
content: /* @__PURE__ */ new Map(),
|
|
42751
|
-
id: decodeIdentifier(
|
|
42640
|
+
id: decodeIdentifier(randomUUID4()),
|
|
42752
42641
|
kind: "message",
|
|
42753
42642
|
sourceMessageId: messageId,
|
|
42754
42643
|
text: remaining.slice(0, ACTIVE_TURN_TEXT_CHUNK_LIMIT)
|
|
@@ -43019,6 +42908,202 @@ var DaemonTurnRegistry = class {
|
|
|
43019
42908
|
};
|
|
43020
42909
|
};
|
|
43021
42910
|
|
|
42911
|
+
// src/generated/acp-session-store-migrations.ts
|
|
42912
|
+
var acpSessionStoreMigrations = [
|
|
42913
|
+
{
|
|
42914
|
+
"name": "0000_slimy_captain_midlands.sql",
|
|
42915
|
+
"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"
|
|
42916
|
+
},
|
|
42917
|
+
{
|
|
42918
|
+
"name": "0001_regular_ultimates.sql",
|
|
42919
|
+
"sql": "ALTER TABLE `acp_session` ADD `last_terminal_command_id` text;"
|
|
42920
|
+
},
|
|
42921
|
+
{
|
|
42922
|
+
"name": "0002_equal_black_queen.sql",
|
|
42923
|
+
"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`);"
|
|
42924
|
+
},
|
|
42925
|
+
{
|
|
42926
|
+
"name": "0003_silky_ravenous.sql",
|
|
42927
|
+
"sql": "DROP TABLE `session_event_v2`;"
|
|
42928
|
+
},
|
|
42929
|
+
{
|
|
42930
|
+
"name": "0004_special_mathemanic.sql",
|
|
42931
|
+
"sql": "DROP TABLE `deleted_acp_session`;--> statement-breakpoint\nALTER TABLE `acp_session` DROP COLUMN `last_terminal_command_id`;"
|
|
42932
|
+
}
|
|
42933
|
+
];
|
|
42934
|
+
|
|
42935
|
+
// src/generated/session-event-cache-migrations.ts
|
|
42936
|
+
var sessionEventCacheMigrations = [
|
|
42937
|
+
{
|
|
42938
|
+
"name": "migration.sql",
|
|
42939
|
+
"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`);"
|
|
42940
|
+
}
|
|
42941
|
+
];
|
|
42942
|
+
|
|
42943
|
+
// src/infra/local-sqlite-database.ts
|
|
42944
|
+
import { chmodSync, mkdirSync as mkdirSync2 } from "node:fs";
|
|
42945
|
+
import { dirname as dirname6 } from "node:path";
|
|
42946
|
+
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
42947
|
+
|
|
42948
|
+
// ../../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
|
|
42949
|
+
var NodeSQLiteSession = class extends SQLiteAsyncSession {
|
|
42950
|
+
static [entityKind] = "SQLJsSession";
|
|
42951
|
+
logger;
|
|
42952
|
+
constructor(client2, dialect, relations, options = {}) {
|
|
42953
|
+
super(dialect, "sync");
|
|
42954
|
+
this.client = client2;
|
|
42955
|
+
this.relations = relations;
|
|
42956
|
+
this.options = options;
|
|
42957
|
+
this.logger = options.logger ?? new NoopLogger();
|
|
42958
|
+
}
|
|
42959
|
+
prepareQuery(query, mode, _prepare, executeMethod, mapper, queryMetadata) {
|
|
42960
|
+
let stmt;
|
|
42961
|
+
try {
|
|
42962
|
+
stmt = this.client.prepare(query.sql);
|
|
42963
|
+
} catch (e) {
|
|
42964
|
+
throw new DrizzleQueryError(query.sql, query.params, e);
|
|
42965
|
+
}
|
|
42966
|
+
return new SQLiteAsyncPreparedQuery("sync", executeMethod, {
|
|
42967
|
+
all: (params) => {
|
|
42968
|
+
stmt.setReturnArrays(mode === "arrays");
|
|
42969
|
+
const res = stmt.all(...params);
|
|
42970
|
+
if (mode === "objects") return res.map((row) => ({ ...row }));
|
|
42971
|
+
return res;
|
|
42972
|
+
},
|
|
42973
|
+
get: (params) => {
|
|
42974
|
+
stmt.setReturnArrays(mode === "arrays");
|
|
42975
|
+
const res = stmt.get(...params);
|
|
42976
|
+
if (res && mode === "objects") return { ...res };
|
|
42977
|
+
return res;
|
|
42978
|
+
},
|
|
42979
|
+
run: (params) => {
|
|
42980
|
+
stmt.setReturnArrays(false);
|
|
42981
|
+
return stmt.run(...params);
|
|
42982
|
+
},
|
|
42983
|
+
values: (params) => {
|
|
42984
|
+
stmt.setReturnArrays(true);
|
|
42985
|
+
return stmt.all(...params);
|
|
42986
|
+
}
|
|
42987
|
+
}, query, mapper, mode, this.logger, void 0, queryMetadata, void 0);
|
|
42988
|
+
}
|
|
42989
|
+
transaction(transaction, config2 = {}) {
|
|
42990
|
+
const tx = new NodeSQLiteTransaction("sync", this.dialect, this, this.relations);
|
|
42991
|
+
this.run(sql.raw(`begin${config2.behavior ? ` ${config2.behavior}` : ""}`));
|
|
42992
|
+
try {
|
|
42993
|
+
const result = transaction(tx);
|
|
42994
|
+
this.run(sql`commit`);
|
|
42995
|
+
return result;
|
|
42996
|
+
} catch (err) {
|
|
42997
|
+
this.run(sql`rollback`);
|
|
42998
|
+
throw err;
|
|
42999
|
+
}
|
|
43000
|
+
}
|
|
43001
|
+
};
|
|
43002
|
+
var NodeSQLiteTransaction = class NodeSQLiteTransaction2 extends SQLiteAsyncTransaction {
|
|
43003
|
+
static [entityKind] = "SQLJsTransaction";
|
|
43004
|
+
transaction(transaction) {
|
|
43005
|
+
const savepointName = `sp${this.nestedIndex + 1}`;
|
|
43006
|
+
const tx = new NodeSQLiteTransaction2("sync", this.dialect, this.session, this._.relations, this.nestedIndex + 1);
|
|
43007
|
+
tx.run(sql.raw(`savepoint ${savepointName}`));
|
|
43008
|
+
try {
|
|
43009
|
+
const result = transaction(tx);
|
|
43010
|
+
tx.run(sql.raw(`release savepoint ${savepointName}`));
|
|
43011
|
+
return result;
|
|
43012
|
+
} catch (err) {
|
|
43013
|
+
tx.run(sql.raw(`rollback to savepoint ${savepointName}`));
|
|
43014
|
+
throw err;
|
|
43015
|
+
}
|
|
43016
|
+
}
|
|
43017
|
+
};
|
|
43018
|
+
|
|
43019
|
+
// ../../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
|
|
43020
|
+
import { DatabaseSync } from "node:sqlite";
|
|
43021
|
+
var NodeSQLiteDatabase = class extends SQLiteAsyncDatabase {
|
|
43022
|
+
static [entityKind] = "NodeSQLiteDatabase";
|
|
43023
|
+
};
|
|
43024
|
+
function construct(client2, config2 = {}) {
|
|
43025
|
+
const dialect = new SQLiteDialect({ useJitMappers: jitCompatCheck(config2.jit) });
|
|
43026
|
+
let logger;
|
|
43027
|
+
if (config2.logger === true) logger = new DefaultLogger();
|
|
43028
|
+
else if (config2.logger !== false) logger = config2.logger;
|
|
43029
|
+
const relations = config2.relations ?? {};
|
|
43030
|
+
const db = new NodeSQLiteDatabase("sync", dialect, new NodeSQLiteSession(client2, dialect, relations, { logger }), relations);
|
|
43031
|
+
db.$client = client2;
|
|
43032
|
+
return db;
|
|
43033
|
+
}
|
|
43034
|
+
function drizzle(...params) {
|
|
43035
|
+
if (params[0] === void 0 || typeof params[0] === "string") return construct(params[0] === void 0 ? new DatabaseSync(":memory:") : new DatabaseSync(params[0]), params[1]);
|
|
43036
|
+
const { connection, client: client2, ...config2 } = params[0];
|
|
43037
|
+
if (client2) return construct(client2, config2);
|
|
43038
|
+
if (typeof connection === "object") {
|
|
43039
|
+
const { path: path3, ...options } = connection;
|
|
43040
|
+
return construct(new DatabaseSync(path3 ?? ":memory:", options), config2);
|
|
43041
|
+
}
|
|
43042
|
+
return construct(new DatabaseSync(connection ?? ":memory:"), config2);
|
|
43043
|
+
}
|
|
43044
|
+
(function(_drizzle) {
|
|
43045
|
+
function mock(config2) {
|
|
43046
|
+
return construct({}, config2);
|
|
43047
|
+
}
|
|
43048
|
+
_drizzle.mock = mock;
|
|
43049
|
+
})(drizzle || (drizzle = {}));
|
|
43050
|
+
|
|
43051
|
+
// src/infra/local-sqlite-database.ts
|
|
43052
|
+
var LocalSqliteDatabase = class {
|
|
43053
|
+
orm;
|
|
43054
|
+
#sqlite;
|
|
43055
|
+
constructor(path3, label, migrations, pragmas = []) {
|
|
43056
|
+
mkdirSync2(dirname6(path3), { mode: 448, recursive: true });
|
|
43057
|
+
this.#sqlite = new DatabaseSync2(path3);
|
|
43058
|
+
chmodSync(path3, 384);
|
|
43059
|
+
try {
|
|
43060
|
+
for (const pragma of pragmas) {
|
|
43061
|
+
this.#sqlite.exec(pragma);
|
|
43062
|
+
}
|
|
43063
|
+
this.#migrate(label, migrations);
|
|
43064
|
+
this.orm = drizzle({ client: this.#sqlite });
|
|
43065
|
+
} catch (error62) {
|
|
43066
|
+
this.#sqlite.close();
|
|
43067
|
+
throw error62;
|
|
43068
|
+
}
|
|
43069
|
+
}
|
|
43070
|
+
#migrate = (label, migrations) => {
|
|
43071
|
+
const version2 = external_exports.object({ user_version: external_exports.number().int().nonnegative() }).parse(this.#sqlite.prepare("PRAGMA user_version").get()).user_version;
|
|
43072
|
+
if (version2 > migrations.length) {
|
|
43073
|
+
throw new Error(`The ${label} was created by a newer Mobius version`);
|
|
43074
|
+
}
|
|
43075
|
+
for (let index2 = version2; index2 < migrations.length; index2 += 1) {
|
|
43076
|
+
const migration = migrations[index2];
|
|
43077
|
+
if (migration === void 0) {
|
|
43078
|
+
throw new Error(`The ${label} migration is unavailable`);
|
|
43079
|
+
}
|
|
43080
|
+
this.transaction(() => {
|
|
43081
|
+
this.#sqlite.exec(migration.sql);
|
|
43082
|
+
this.#sqlite.exec(`PRAGMA user_version = ${index2 + 1}`);
|
|
43083
|
+
});
|
|
43084
|
+
}
|
|
43085
|
+
};
|
|
43086
|
+
transaction = (operation) => {
|
|
43087
|
+
this.#sqlite.exec("BEGIN IMMEDIATE");
|
|
43088
|
+
try {
|
|
43089
|
+
const result = operation();
|
|
43090
|
+
this.#sqlite.exec("COMMIT");
|
|
43091
|
+
return result;
|
|
43092
|
+
} catch (error62) {
|
|
43093
|
+
this.#sqlite.exec("ROLLBACK");
|
|
43094
|
+
throw error62;
|
|
43095
|
+
}
|
|
43096
|
+
};
|
|
43097
|
+
close = () => this.#sqlite.close();
|
|
43098
|
+
};
|
|
43099
|
+
|
|
43100
|
+
// src/local-databases.ts
|
|
43101
|
+
var openAcpSessionDatabase = (path3) => new LocalSqliteDatabase(path3, "ACP Session database", acpSessionStoreMigrations);
|
|
43102
|
+
var openSessionEventCacheV2Database = (path3) => new LocalSqliteDatabase(path3, "V2 Session event cache", sessionEventCacheMigrations, [
|
|
43103
|
+
"PRAGMA journal_mode = WAL",
|
|
43104
|
+
"PRAGMA synchronous = OFF"
|
|
43105
|
+
]);
|
|
43106
|
+
|
|
43022
43107
|
// src/native-sessions/codex-history.ts
|
|
43023
43108
|
import { spawn as spawn5 } from "node:child_process";
|
|
43024
43109
|
var responseSchema = external_exports.union([
|
|
@@ -43723,7 +43808,7 @@ var readCodexFullHistory = async (agent, cwd, nativeSessionId, signal, nativeTur
|
|
|
43723
43808
|
});
|
|
43724
43809
|
|
|
43725
43810
|
// src/native-sessions/service.ts
|
|
43726
|
-
import { randomUUID as
|
|
43811
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
43727
43812
|
var NativeSessionService = class {
|
|
43728
43813
|
#entries = /* @__PURE__ */ new Map();
|
|
43729
43814
|
#cursors = /* @__PURE__ */ new Map();
|
|
@@ -43782,7 +43867,7 @@ var NativeSessionService = class {
|
|
|
43782
43867
|
if (authorized === null) {
|
|
43783
43868
|
return null;
|
|
43784
43869
|
}
|
|
43785
|
-
const entryId = decodeIdentifier(
|
|
43870
|
+
const entryId = decodeIdentifier(randomUUID5());
|
|
43786
43871
|
if (this.#entries.size >= 5e3) {
|
|
43787
43872
|
this.#entries.clear();
|
|
43788
43873
|
}
|
|
@@ -43838,7 +43923,7 @@ var NativeSessionService = class {
|
|
|
43838
43923
|
"invalid_native_session_response"
|
|
43839
43924
|
);
|
|
43840
43925
|
}
|
|
43841
|
-
nextCursor = decodeIdentifier(
|
|
43926
|
+
nextCursor = decodeIdentifier(randomUUID5());
|
|
43842
43927
|
if (this.#cursors.size >= 500) {
|
|
43843
43928
|
this.#cursors.clear();
|
|
43844
43929
|
}
|
|
@@ -44016,7 +44101,7 @@ var NativeSessionService = class {
|
|
|
44016
44101
|
resolveTarget = async (command, options, selected) => {
|
|
44017
44102
|
let cursor = null;
|
|
44018
44103
|
const visited = /* @__PURE__ */ new Set();
|
|
44019
|
-
for (let
|
|
44104
|
+
for (let index2 = 0; index2 < 100; index2 += 1) {
|
|
44020
44105
|
const page = await this.#sessions.listNativeSessions(options, cursor);
|
|
44021
44106
|
const info = page.sessions.find((entry) => entry.sessionId === selected.nativeSessionId);
|
|
44022
44107
|
if (info !== void 0) {
|
|
@@ -44024,7 +44109,7 @@ var NativeSessionService = class {
|
|
|
44024
44109
|
if (target === null) {
|
|
44025
44110
|
throw new LocalAuthorizationError("The selected native session is not authorized");
|
|
44026
44111
|
}
|
|
44027
|
-
if (target.cwd !== selected.cwd || target.additionalDirectories.length !== selected.additionalDirectories.length || target.additionalDirectories.some((path3,
|
|
44112
|
+
if (target.cwd !== selected.cwd || target.additionalDirectories.length !== selected.additionalDirectories.length || target.additionalDirectories.some((path3, index3) => path3 !== selected.additionalDirectories[index3])) {
|
|
44028
44113
|
throw new AcpExecutionError(
|
|
44029
44114
|
"This session's directory changed. Refresh the list before continuing.",
|
|
44030
44115
|
{},
|
|
@@ -44063,7 +44148,7 @@ var NativeSessionService = class {
|
|
|
44063
44148
|
};
|
|
44064
44149
|
|
|
44065
44150
|
// src/relay-connection/daemon-operation-state.ts
|
|
44066
|
-
import { createHash as createHash5, randomUUID as
|
|
44151
|
+
import { createHash as createHash5, randomUUID as randomUUID6 } from "node:crypto";
|
|
44067
44152
|
var MAX_TERMINAL_RECEIPTS = 1024;
|
|
44068
44153
|
function isTerminal(state) {
|
|
44069
44154
|
return state === "succeeded" || state === "failed" || state === "cancelled";
|
|
@@ -44080,7 +44165,7 @@ var DaemonOperationState = class {
|
|
|
44080
44165
|
}
|
|
44081
44166
|
return { attemptId: existing.attemptId, commandId, kind: "duplicate", state: existing.state };
|
|
44082
44167
|
}
|
|
44083
|
-
const attemptId =
|
|
44168
|
+
const attemptId = randomUUID6();
|
|
44084
44169
|
this.#executions.set(commandId, { attemptId, commandHash, sessionId, state: "dispatching" });
|
|
44085
44170
|
return { attemptId, commandId, kind: "accepted", state: "dispatching" };
|
|
44086
44171
|
};
|
|
@@ -45044,7 +45129,7 @@ async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, dir
|
|
|
45044
45129
|
const replay = await sessions.loadSessionEventsV2(loadOptions, command.eventLimit, command.cursor);
|
|
45045
45130
|
signal.throwIfAborted();
|
|
45046
45131
|
const events = replay.events.map(
|
|
45047
|
-
(event,
|
|
45132
|
+
(event, index2) => eventLogV2.event(command.sessionId, replay.startPosition + index2, event, "1970-01-01T00:00:00.000Z")
|
|
45048
45133
|
);
|
|
45049
45134
|
const tailCursor = events.at(-1)?.eventId ?? "";
|
|
45050
45135
|
audit.record({
|
|
@@ -45095,7 +45180,7 @@ async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, dir
|
|
|
45095
45180
|
}
|
|
45096
45181
|
|
|
45097
45182
|
// src/acp/session-config/apply-session-configuration.ts
|
|
45098
|
-
import { randomUUID as
|
|
45183
|
+
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
45099
45184
|
function invalidSessionConfiguration(message) {
|
|
45100
45185
|
return new AcpExecutionError(message, {}, "invalid_session_configuration");
|
|
45101
45186
|
}
|
|
@@ -45236,7 +45321,7 @@ async function applySessionConfigurationSelection(sessions, audit, options, sele
|
|
|
45236
45321
|
booleanValue: selection.booleanValue,
|
|
45237
45322
|
configId: selection.configId,
|
|
45238
45323
|
cwd,
|
|
45239
|
-
requestId: `cfg_${
|
|
45324
|
+
requestId: `cfg_${randomUUID7()}`,
|
|
45240
45325
|
sessionId,
|
|
45241
45326
|
signal,
|
|
45242
45327
|
value: selection.value,
|
|
@@ -45278,112 +45363,6 @@ function warnIgnoredSetting(audit, event, commandId, sessionId, agentId, selecti
|
|
|
45278
45363
|
`);
|
|
45279
45364
|
}
|
|
45280
45365
|
|
|
45281
|
-
// src/relay-connection/coalescing-agent-event-publisher.ts
|
|
45282
|
-
var AGENT_EVENT_COALESCING_MILLISECONDS = 100;
|
|
45283
|
-
var AGENT_EVENT_TEXT_MAXIMUM_LENGTH = 1e5;
|
|
45284
|
-
var CoalescingAgentEventPublisher = class {
|
|
45285
|
-
#entries = [];
|
|
45286
|
-
#publish;
|
|
45287
|
-
#publishedActivityIds = /* @__PURE__ */ new Set();
|
|
45288
|
-
#scheduled = null;
|
|
45289
|
-
#timer;
|
|
45290
|
-
constructor(timer, publish) {
|
|
45291
|
-
this.#publish = publish;
|
|
45292
|
-
this.#timer = timer;
|
|
45293
|
-
}
|
|
45294
|
-
flush = () => {
|
|
45295
|
-
this.#scheduled?.cancel();
|
|
45296
|
-
this.#scheduled = null;
|
|
45297
|
-
const entries = this.#entries;
|
|
45298
|
-
this.#entries = [];
|
|
45299
|
-
for (const entry of entries) {
|
|
45300
|
-
this.#publish(entry);
|
|
45301
|
-
}
|
|
45302
|
-
};
|
|
45303
|
-
recordActivity = (activity2) => {
|
|
45304
|
-
const latest = this.#entries.at(-1);
|
|
45305
|
-
this.#entries = latest?.kind === "activity" && latest.activity.activityId === activity2.activityId ? [...this.#entries.slice(0, -1), { activity: activity2, kind: "activity" }] : [...this.#entries, { activity: activity2, kind: "activity" }];
|
|
45306
|
-
const first = !this.#publishedActivityIds.has(activity2.activityId);
|
|
45307
|
-
this.#publishedActivityIds.add(activity2.activityId);
|
|
45308
|
-
if (first || activity2.status !== "pending" && activity2.status !== "running") {
|
|
45309
|
-
this.flush();
|
|
45310
|
-
} else {
|
|
45311
|
-
this.schedule();
|
|
45312
|
-
}
|
|
45313
|
-
return Promise.resolve();
|
|
45314
|
-
};
|
|
45315
|
-
recordNarration = (increment) => {
|
|
45316
|
-
if (increment.text.length === 0) {
|
|
45317
|
-
return Promise.resolve();
|
|
45318
|
-
}
|
|
45319
|
-
let remaining = increment.text;
|
|
45320
|
-
while (remaining.length > 0) {
|
|
45321
|
-
const latest = this.#entries.at(-1);
|
|
45322
|
-
if (latest?.kind === "narration" && latest.increment.activityId === increment.activityId) {
|
|
45323
|
-
const available = AGENT_EVENT_TEXT_MAXIMUM_LENGTH - latest.increment.text.length;
|
|
45324
|
-
if (available > 0) {
|
|
45325
|
-
this.#entries = [
|
|
45326
|
-
...this.#entries.slice(0, -1),
|
|
45327
|
-
{
|
|
45328
|
-
increment: {
|
|
45329
|
-
...increment,
|
|
45330
|
-
text: `${latest.increment.text}${remaining.slice(0, available)}`
|
|
45331
|
-
},
|
|
45332
|
-
kind: "narration"
|
|
45333
|
-
}
|
|
45334
|
-
];
|
|
45335
|
-
remaining = remaining.slice(available);
|
|
45336
|
-
continue;
|
|
45337
|
-
}
|
|
45338
|
-
}
|
|
45339
|
-
this.#entries = [
|
|
45340
|
-
...this.#entries,
|
|
45341
|
-
{
|
|
45342
|
-
increment: { ...increment, text: remaining.slice(0, AGENT_EVENT_TEXT_MAXIMUM_LENGTH) },
|
|
45343
|
-
kind: "narration"
|
|
45344
|
-
}
|
|
45345
|
-
];
|
|
45346
|
-
remaining = remaining.slice(AGENT_EVENT_TEXT_MAXIMUM_LENGTH);
|
|
45347
|
-
}
|
|
45348
|
-
this.schedule();
|
|
45349
|
-
return Promise.resolve();
|
|
45350
|
-
};
|
|
45351
|
-
recordText = (text2, messageId) => {
|
|
45352
|
-
if (text2.length === 0) {
|
|
45353
|
-
return Promise.resolve();
|
|
45354
|
-
}
|
|
45355
|
-
let remaining = text2;
|
|
45356
|
-
while (remaining.length > 0) {
|
|
45357
|
-
const latest = this.#entries.at(-1);
|
|
45358
|
-
if (latest?.kind === "text" && latest.messageId === messageId) {
|
|
45359
|
-
const available = AGENT_EVENT_TEXT_MAXIMUM_LENGTH - latest.text.length;
|
|
45360
|
-
if (available > 0) {
|
|
45361
|
-
this.#entries = [
|
|
45362
|
-
...this.#entries.slice(0, -1),
|
|
45363
|
-
{ ...latest, text: `${latest.text}${remaining.slice(0, available)}` }
|
|
45364
|
-
];
|
|
45365
|
-
remaining = remaining.slice(available);
|
|
45366
|
-
continue;
|
|
45367
|
-
}
|
|
45368
|
-
}
|
|
45369
|
-
this.#entries = [
|
|
45370
|
-
...this.#entries,
|
|
45371
|
-
{
|
|
45372
|
-
kind: "text",
|
|
45373
|
-
messageId,
|
|
45374
|
-
text: remaining.slice(0, AGENT_EVENT_TEXT_MAXIMUM_LENGTH)
|
|
45375
|
-
}
|
|
45376
|
-
];
|
|
45377
|
-
remaining = remaining.slice(AGENT_EVENT_TEXT_MAXIMUM_LENGTH);
|
|
45378
|
-
}
|
|
45379
|
-
this.schedule();
|
|
45380
|
-
return Promise.resolve();
|
|
45381
|
-
};
|
|
45382
|
-
schedule() {
|
|
45383
|
-
this.#scheduled ??= this.#timer.schedule(this.flush, AGENT_EVENT_COALESCING_MILLISECONDS);
|
|
45384
|
-
}
|
|
45385
|
-
};
|
|
45386
|
-
|
|
45387
45366
|
// src/daemon-prompt-executor.ts
|
|
45388
45367
|
function daemonActivity(command, activity2) {
|
|
45389
45368
|
return {
|
|
@@ -45406,7 +45385,6 @@ function daemonActivity(command, activity2) {
|
|
|
45406
45385
|
}
|
|
45407
45386
|
async function executePrompt({
|
|
45408
45387
|
operations,
|
|
45409
|
-
publisher,
|
|
45410
45388
|
eventLogV2,
|
|
45411
45389
|
command,
|
|
45412
45390
|
config: config2,
|
|
@@ -45416,36 +45394,11 @@ async function executePrompt({
|
|
|
45416
45394
|
attemptId,
|
|
45417
45395
|
activateAttempt,
|
|
45418
45396
|
waitForSessionAvailability,
|
|
45419
|
-
timer,
|
|
45420
45397
|
signal,
|
|
45421
|
-
|
|
45398
|
+
recordTurnEvent,
|
|
45422
45399
|
recordSteeringPrompt,
|
|
45423
45400
|
cancellationRequested
|
|
45424
45401
|
}) {
|
|
45425
|
-
const events = new CoalescingAgentEventPublisher(timer, (event) => {
|
|
45426
|
-
if (event.kind === "text") {
|
|
45427
|
-
publisher.publish(
|
|
45428
|
-
command.sessionId,
|
|
45429
|
-
recordLiveEvent({ kind: AGENT_MESSAGE_DELTA_KIND, messageId: event.messageId, text: event.text })
|
|
45430
|
-
);
|
|
45431
|
-
return;
|
|
45432
|
-
}
|
|
45433
|
-
if (event.kind === "narration") {
|
|
45434
|
-
const recorded = {
|
|
45435
|
-
activityId: event.increment.activityId,
|
|
45436
|
-
activityType: event.increment.activityType,
|
|
45437
|
-
commandId: command.commandId,
|
|
45438
|
-
kind: AGENT_ACTIVITY_NARRATION_KIND,
|
|
45439
|
-
sequence: event.increment.sequence,
|
|
45440
|
-
sessionId: command.sessionId,
|
|
45441
|
-
text: event.increment.text
|
|
45442
|
-
};
|
|
45443
|
-
publisher.publish(command.sessionId, recordLiveEvent(recorded));
|
|
45444
|
-
return;
|
|
45445
|
-
}
|
|
45446
|
-
const activity2 = daemonActivity(command, event.activity);
|
|
45447
|
-
publisher.publish(command.sessionId, recordLiveEvent(activity2));
|
|
45448
|
-
});
|
|
45449
45402
|
try {
|
|
45450
45403
|
const resolved = await resolveSessionDirectories(
|
|
45451
45404
|
directories,
|
|
@@ -45513,33 +45466,6 @@ async function executePrompt({
|
|
|
45513
45466
|
}
|
|
45514
45467
|
const stream = activateAttempt();
|
|
45515
45468
|
const lifecycleV2 = eventLogV2.started(command.sessionId, command.commandId, attemptId, stream.epoch);
|
|
45516
|
-
if (!prepared.prompted) {
|
|
45517
|
-
const listing = await directories.list(config2.bindingId, command.directoryId, signal);
|
|
45518
|
-
publisher.publish(command.sessionId, {
|
|
45519
|
-
additionalDirectories: resolved.additionalDirectoryEntries,
|
|
45520
|
-
agentId: command.agentId,
|
|
45521
|
-
agentName: prepared.agentName,
|
|
45522
|
-
agentVersion: prepared.agentVersion,
|
|
45523
|
-
capabilities: prepared.capabilities,
|
|
45524
|
-
commands: prepared.commands,
|
|
45525
|
-
configOptions: prepared.configOptions,
|
|
45526
|
-
directoryId: command.directoryId,
|
|
45527
|
-
directoryLabel: listing.directoryLabel,
|
|
45528
|
-
kind: SESSION_READY_KIND,
|
|
45529
|
-
requestId: command.commandId,
|
|
45530
|
-
restored: prepared.restored,
|
|
45531
|
-
sessionId: command.sessionId
|
|
45532
|
-
});
|
|
45533
|
-
}
|
|
45534
|
-
publisher.publish(command.sessionId, {
|
|
45535
|
-
commandId: command.commandId,
|
|
45536
|
-
epoch: stream.epoch,
|
|
45537
|
-
kind: SESSION_STARTED_KIND,
|
|
45538
|
-
attemptId,
|
|
45539
|
-
prompt: command.prompt,
|
|
45540
|
-
sequence: stream.sequence,
|
|
45541
|
-
sessionId: command.sessionId
|
|
45542
|
-
});
|
|
45543
45469
|
const attachments = await resolvePromptArtifacts(config2, command, signal);
|
|
45544
45470
|
let stopReason;
|
|
45545
45471
|
if (availability.disposition === SessionPromptDisposition.Steer) {
|
|
@@ -45566,9 +45492,20 @@ async function executePrompt({
|
|
|
45566
45492
|
disposition: availability.disposition,
|
|
45567
45493
|
images: attachments.images,
|
|
45568
45494
|
lifecycleV2,
|
|
45569
|
-
onActivity:
|
|
45570
|
-
|
|
45571
|
-
|
|
45495
|
+
onActivity: async (activity2) => {
|
|
45496
|
+
recordTurnEvent(daemonActivity(command, activity2));
|
|
45497
|
+
},
|
|
45498
|
+
onNarration: async (increment) => {
|
|
45499
|
+
recordTurnEvent({
|
|
45500
|
+
...increment,
|
|
45501
|
+
commandId: command.commandId,
|
|
45502
|
+
sessionId: command.sessionId,
|
|
45503
|
+
kind: AGENT_ACTIVITY_NARRATION_KIND
|
|
45504
|
+
});
|
|
45505
|
+
},
|
|
45506
|
+
onText: async (text2, messageId) => {
|
|
45507
|
+
recordTurnEvent({ kind: AGENT_MESSAGE_DELTA_KIND, text: text2, messageId });
|
|
45508
|
+
},
|
|
45572
45509
|
prompt: command.prompt,
|
|
45573
45510
|
resources: attachments.resources,
|
|
45574
45511
|
sessionId: command.sessionId,
|
|
@@ -45577,14 +45514,7 @@ async function executePrompt({
|
|
|
45577
45514
|
});
|
|
45578
45515
|
stopReason = result.stopReason;
|
|
45579
45516
|
}
|
|
45580
|
-
|
|
45581
|
-
publisher.publish(command.sessionId, {
|
|
45582
|
-
commandId: command.commandId,
|
|
45583
|
-
kind: SESSION_COMPLETED_KIND,
|
|
45584
|
-
sessionId: command.sessionId,
|
|
45585
|
-
stopReason
|
|
45586
|
-
});
|
|
45587
|
-
eventLogV2.completed(command.sessionId, command.commandId, stopReason);
|
|
45517
|
+
await eventLogV2.completed(command.sessionId, command.commandId, stopReason);
|
|
45588
45518
|
operations.transitionExecution(command.commandId, stopReason === "cancelled" ? "cancelled" : "succeeded");
|
|
45589
45519
|
audit.record({
|
|
45590
45520
|
commandId: command.commandId,
|
|
@@ -45592,15 +45522,8 @@ async function executePrompt({
|
|
|
45592
45522
|
sessionId: command.sessionId
|
|
45593
45523
|
});
|
|
45594
45524
|
} catch (error62) {
|
|
45595
|
-
events.flush();
|
|
45596
45525
|
if (signal.aborted && cancellationRequested()) {
|
|
45597
|
-
|
|
45598
|
-
commandId: command.commandId,
|
|
45599
|
-
kind: SESSION_COMPLETED_KIND,
|
|
45600
|
-
sessionId: command.sessionId,
|
|
45601
|
-
stopReason: "cancelled"
|
|
45602
|
-
});
|
|
45603
|
-
eventLogV2.completed(command.sessionId, command.commandId, "cancelled");
|
|
45526
|
+
await eventLogV2.completed(command.sessionId, command.commandId, "cancelled");
|
|
45604
45527
|
operations.transitionExecution(command.commandId, "cancelled");
|
|
45605
45528
|
audit.record({
|
|
45606
45529
|
commandId: command.commandId,
|
|
@@ -45617,8 +45540,7 @@ async function executePrompt({
|
|
|
45617
45540
|
const code = operationErrorCode(error62);
|
|
45618
45541
|
const failureCode = code === "session_operation_failed" ? "agent_execution_failed" : code;
|
|
45619
45542
|
const failureMessage = code === "session_operation_failed" ? "The local agent could not complete the request" : operationErrorMessage(error62);
|
|
45620
|
-
eventLogV2.failed(command.sessionId, command.commandId, failureCode, failureMessage);
|
|
45621
|
-
reportFailure(publisher, command, failureCode, failureMessage);
|
|
45543
|
+
await eventLogV2.failed(command.sessionId, command.commandId, failureCode, failureMessage);
|
|
45622
45544
|
operations.transitionExecution(command.commandId, "failed");
|
|
45623
45545
|
console.error("Mobius daemon command failed", error62);
|
|
45624
45546
|
}
|
|
@@ -45646,7 +45568,7 @@ async function executeWorkspaceList(socket, command, directories, audit, signal)
|
|
|
45646
45568
|
reportOperationFailure(socket, command.requestId, "", error62);
|
|
45647
45569
|
}
|
|
45648
45570
|
}
|
|
45649
|
-
async function executeSessionPrepare(
|
|
45571
|
+
async function executeSessionPrepare(socket, command, config2, directories, audit, sessions, diagnostics, signal) {
|
|
45650
45572
|
const metrics = new AccumulatingOperationMetrics();
|
|
45651
45573
|
try {
|
|
45652
45574
|
const readyEvent = await metrics.measure("prepare-total", async () => {
|
|
@@ -45696,12 +45618,6 @@ async function executeSessionPrepare(publisher, socket, command, config2, direct
|
|
|
45696
45618
|
event: "session_configured",
|
|
45697
45619
|
sessionId: command.sessionId
|
|
45698
45620
|
});
|
|
45699
|
-
publisher.publish(command.sessionId, {
|
|
45700
|
-
configOptions,
|
|
45701
|
-
kind: "session.config.updated",
|
|
45702
|
-
requestId: command.requestId,
|
|
45703
|
-
sessionId: command.sessionId
|
|
45704
|
-
});
|
|
45705
45621
|
}
|
|
45706
45622
|
const event = {
|
|
45707
45623
|
additionalDirectories: resolved.additionalDirectoryEntries,
|
|
@@ -45719,11 +45635,6 @@ async function executeSessionPrepare(publisher, socket, command, config2, direct
|
|
|
45719
45635
|
sessionId: command.sessionId,
|
|
45720
45636
|
runtimeTimings: metrics.snapshot()
|
|
45721
45637
|
};
|
|
45722
|
-
if (command.transient !== true) {
|
|
45723
|
-
metrics.measureSync("readiness-commit", () => {
|
|
45724
|
-
publisher.publish(command.sessionId, event);
|
|
45725
|
-
});
|
|
45726
|
-
}
|
|
45727
45638
|
return event;
|
|
45728
45639
|
});
|
|
45729
45640
|
send(socket, {
|
|
@@ -45753,7 +45664,7 @@ async function executeSessionPrepare(publisher, socket, command, config2, direct
|
|
|
45753
45664
|
reportOperationFailure(socket, command.requestId, command.sessionId, error62, metrics.snapshot());
|
|
45754
45665
|
}
|
|
45755
45666
|
}
|
|
45756
|
-
async function executeSessionConfigure(
|
|
45667
|
+
async function executeSessionConfigure(socket, command, config2, directories, audit, sessions, signal) {
|
|
45757
45668
|
try {
|
|
45758
45669
|
const resolved = await resolveSessionDirectories(
|
|
45759
45670
|
directories,
|
|
@@ -45779,7 +45690,7 @@ async function executeSessionConfigure(publisher, socket, command, config2, dire
|
|
|
45779
45690
|
event: "session_configured",
|
|
45780
45691
|
sessionId: command.sessionId
|
|
45781
45692
|
});
|
|
45782
|
-
|
|
45693
|
+
send(socket, {
|
|
45783
45694
|
configOptions,
|
|
45784
45695
|
kind: "session.config.updated",
|
|
45785
45696
|
requestId: command.requestId,
|
|
@@ -45899,7 +45810,6 @@ function createDaemonCommandHandler({
|
|
|
45899
45810
|
installations,
|
|
45900
45811
|
nativeSessions,
|
|
45901
45812
|
operations,
|
|
45902
|
-
publisher,
|
|
45903
45813
|
eventLogV2,
|
|
45904
45814
|
externalContent,
|
|
45905
45815
|
activeTurns,
|
|
@@ -45920,8 +45830,9 @@ function createDaemonCommandHandler({
|
|
|
45920
45830
|
timer
|
|
45921
45831
|
});
|
|
45922
45832
|
const queueChanged = (sessionId) => {
|
|
45923
|
-
|
|
45924
|
-
|
|
45833
|
+
void eventLogV2.queueChanged(sessionId).catch((error62) => {
|
|
45834
|
+
console.error("Could not record queue change", error62);
|
|
45835
|
+
});
|
|
45925
45836
|
};
|
|
45926
45837
|
const nativeRequestHandler = createNativeSessionRequestHandler({
|
|
45927
45838
|
audit,
|
|
@@ -45990,7 +45901,9 @@ function createDaemonCommandHandler({
|
|
|
45990
45901
|
const cancellation = message;
|
|
45991
45902
|
const turn2 = activeTurns.get(cancellation.commandId);
|
|
45992
45903
|
if (turn2 === void 0 || !turn2.matches(cancellation)) {
|
|
45993
|
-
settleAbandonedTurn(
|
|
45904
|
+
void settleAbandonedTurn(eventLogV2, operations, audit, cancellation).catch((error62) => {
|
|
45905
|
+
console.error("Could not settle abandoned turn", error62);
|
|
45906
|
+
});
|
|
45994
45907
|
return;
|
|
45995
45908
|
}
|
|
45996
45909
|
const cancellationState = turn2.requestCancellation();
|
|
@@ -46030,22 +45943,12 @@ function createDaemonCommandHandler({
|
|
|
46030
45943
|
}
|
|
46031
45944
|
if (kind === SESSION_PREPARE_KIND) {
|
|
46032
45945
|
const command2 = message;
|
|
46033
|
-
void executeSessionPrepare(
|
|
46034
|
-
publisher,
|
|
46035
|
-
socket,
|
|
46036
|
-
command2,
|
|
46037
|
-
config2,
|
|
46038
|
-
directories,
|
|
46039
|
-
audit,
|
|
46040
|
-
sessions,
|
|
46041
|
-
diagnostics,
|
|
46042
|
-
signal
|
|
46043
|
-
);
|
|
45946
|
+
void executeSessionPrepare(socket, command2, config2, directories, audit, sessions, diagnostics, signal);
|
|
46044
45947
|
return;
|
|
46045
45948
|
}
|
|
46046
45949
|
if (kind === SESSION_CONFIGURE_KIND) {
|
|
46047
45950
|
const command2 = message;
|
|
46048
|
-
void executeSessionConfigure(
|
|
45951
|
+
void executeSessionConfigure(socket, command2, config2, directories, audit, sessions, signal);
|
|
46049
45952
|
return;
|
|
46050
45953
|
}
|
|
46051
45954
|
if (kind === SESSION_LIST_KIND) {
|
|
@@ -46147,7 +46050,6 @@ function createDaemonCommandHandler({
|
|
|
46147
46050
|
eventLogV2.requested(command);
|
|
46148
46051
|
void executePrompt({
|
|
46149
46052
|
operations,
|
|
46150
|
-
publisher,
|
|
46151
46053
|
eventLogV2,
|
|
46152
46054
|
command,
|
|
46153
46055
|
config: config2,
|
|
@@ -46164,15 +46066,15 @@ function createDaemonCommandHandler({
|
|
|
46164
46066
|
sessionId: command.sessionId
|
|
46165
46067
|
});
|
|
46166
46068
|
}),
|
|
46167
|
-
timer,
|
|
46168
46069
|
signal: turn.signal,
|
|
46169
|
-
|
|
46070
|
+
recordTurnEvent: turn.recordEvent,
|
|
46170
46071
|
recordSteeringPrompt: () => activeTurns.recordSteeringPrompt(command),
|
|
46171
46072
|
cancellationRequested: turn.cancellationRequested
|
|
46172
46073
|
}).catch((error62) => {
|
|
46173
46074
|
console.error("Mobius daemon turn failed", error62);
|
|
46174
46075
|
}).finally(() => {
|
|
46175
46076
|
activeTurns.finish(turn);
|
|
46077
|
+
eventLogV2.publishTerminal(command.sessionId, command.commandId);
|
|
46176
46078
|
if (command.disposition === SessionPromptDisposition.Queue) {
|
|
46177
46079
|
queueChanged(command.sessionId);
|
|
46178
46080
|
}
|
|
@@ -46306,7 +46208,7 @@ function connectRelay(url2, signal) {
|
|
|
46306
46208
|
}
|
|
46307
46209
|
|
|
46308
46210
|
// src/relay-connection/liveness.ts
|
|
46309
|
-
import { randomUUID as
|
|
46211
|
+
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
46310
46212
|
var HEARTBEAT_ACK_TIMEOUT_MILLISECONDS = 1e4;
|
|
46311
46213
|
var HEARTBEAT_INTERVAL_MILLISECONDS = 2e4;
|
|
46312
46214
|
var RelayLivenessState = class {
|
|
@@ -46395,7 +46297,7 @@ var RelayConnectionLiveness = class {
|
|
|
46395
46297
|
}
|
|
46396
46298
|
throw new Error("Heartbeat was scheduled in an invalid state");
|
|
46397
46299
|
}
|
|
46398
|
-
const heartbeatId =
|
|
46300
|
+
const heartbeatId = randomUUID8();
|
|
46399
46301
|
this.#state = new AwaitingHeartbeatAckState(
|
|
46400
46302
|
heartbeatId,
|
|
46401
46303
|
this.#timer.schedule(this.#handleTimeout, HEARTBEAT_ACK_TIMEOUT_MILLISECONDS)
|
|
@@ -46456,7 +46358,6 @@ async function runRelayConnection({
|
|
|
46456
46358
|
installations,
|
|
46457
46359
|
nativeSessions,
|
|
46458
46360
|
operations,
|
|
46459
|
-
publisher,
|
|
46460
46361
|
eventLogV2,
|
|
46461
46362
|
externalContent,
|
|
46462
46363
|
activeTurns,
|
|
@@ -46621,51 +46522,17 @@ var DaemonSessionEventPublisher = class {
|
|
|
46621
46522
|
close = () => {
|
|
46622
46523
|
this.#socket = null;
|
|
46623
46524
|
};
|
|
46624
|
-
|
|
46625
|
-
|
|
46626
|
-
if (socket === null || socket.readyState !== WebSocket8.OPEN) {
|
|
46627
|
-
return;
|
|
46628
|
-
}
|
|
46629
|
-
const encoded = encodeDaemonToServiceMessage({
|
|
46630
|
-
kind: SESSION_EVENT_KIND,
|
|
46631
|
-
payload: encodeRecordedSessionEvent(event),
|
|
46632
|
-
sessionId
|
|
46633
|
-
});
|
|
46634
|
-
if (socket.bufferedAmount + Buffer.byteLength(encoded, "utf8") > MAX_BUFFERED_BYTES) {
|
|
46635
|
-
socket.close(1013, "Live event transport overloaded");
|
|
46636
|
-
return;
|
|
46637
|
-
}
|
|
46638
|
-
try {
|
|
46639
|
-
socket.send(encoded);
|
|
46640
|
-
} catch {
|
|
46641
|
-
}
|
|
46642
|
-
};
|
|
46643
|
-
publishBatch = (sessionId, events) => {
|
|
46644
|
-
for (const event of events) {
|
|
46645
|
-
this.publish(sessionId, event);
|
|
46646
|
-
}
|
|
46647
|
-
};
|
|
46648
|
-
publishStatus = (event) => {
|
|
46649
|
-
const socket = this.#socket;
|
|
46650
|
-
if (socket === null || socket.readyState !== WebSocket8.OPEN) {
|
|
46651
|
-
return;
|
|
46652
|
-
}
|
|
46653
|
-
const encoded = encodeDaemonToServiceMessage(event);
|
|
46654
|
-
if (socket.bufferedAmount + Buffer.byteLength(encoded, "utf8") > MAX_BUFFERED_BYTES) {
|
|
46655
|
-
socket.close(1013, "Live event transport overloaded");
|
|
46656
|
-
return;
|
|
46657
|
-
}
|
|
46658
|
-
try {
|
|
46659
|
-
socket.send(encoded);
|
|
46660
|
-
} catch {
|
|
46661
|
-
}
|
|
46525
|
+
publishOperationFailure = (sessionId, requestId, code, message) => {
|
|
46526
|
+
this.#send({ kind: "session.operation.failed", sessionId, requestId, code, message });
|
|
46662
46527
|
};
|
|
46663
|
-
|
|
46528
|
+
publishStatus = (event) => this.#send(event);
|
|
46529
|
+
publishV2 = (event) => this.#send({ event, kind: SESSION_EVENT_V2_KIND });
|
|
46530
|
+
#send = (message) => {
|
|
46664
46531
|
const socket = this.#socket;
|
|
46665
46532
|
if (socket === null || socket.readyState !== WebSocket8.OPEN) {
|
|
46666
46533
|
return;
|
|
46667
46534
|
}
|
|
46668
|
-
const encoded = encodeDaemonToServiceMessage(
|
|
46535
|
+
const encoded = encodeDaemonToServiceMessage(message);
|
|
46669
46536
|
if (socket.bufferedAmount + Buffer.byteLength(encoded, "utf8") > MAX_BUFFERED_BYTES) {
|
|
46670
46537
|
socket.close(1013, "Live event transport overloaded");
|
|
46671
46538
|
return;
|
|
@@ -46687,7 +46554,7 @@ var SystemDaemonTimer = class {
|
|
|
46687
46554
|
var systemDaemonTimer = new SystemDaemonTimer();
|
|
46688
46555
|
|
|
46689
46556
|
// src/session-event-log-v2.ts
|
|
46690
|
-
import { createHash as createHash7, randomUUID as
|
|
46557
|
+
import { createHash as createHash7, randomUUID as randomUUID9 } from "node:crypto";
|
|
46691
46558
|
function promptContent(command) {
|
|
46692
46559
|
const content = [];
|
|
46693
46560
|
if (command.prompt.length > 0) {
|
|
@@ -46711,7 +46578,7 @@ function promptContent(command) {
|
|
|
46711
46578
|
}
|
|
46712
46579
|
return content;
|
|
46713
46580
|
}
|
|
46714
|
-
function
|
|
46581
|
+
function sessionEventV22(daemonGenerationId, sessionId, position, event, recordedAt) {
|
|
46715
46582
|
const sessionPrefix = createHash7("sha256").update(sessionId).digest("hex").slice(0, 16);
|
|
46716
46583
|
return {
|
|
46717
46584
|
eventId: `event-${daemonGenerationId}-${sessionPrefix}-${position.toString().padStart(16, "0")}`,
|
|
@@ -46723,46 +46590,116 @@ function sessionEventV2(daemonGenerationId, sessionId, position, event, recorded
|
|
|
46723
46590
|
};
|
|
46724
46591
|
}
|
|
46725
46592
|
var DaemonSessionEventLogV2 = class {
|
|
46726
|
-
daemonGenerationId
|
|
46593
|
+
daemonGenerationId;
|
|
46727
46594
|
#publisher;
|
|
46595
|
+
#terminal = /* @__PURE__ */ new Map();
|
|
46596
|
+
#publications = /* @__PURE__ */ new Map();
|
|
46728
46597
|
#queued = /* @__PURE__ */ new Map();
|
|
46729
|
-
|
|
46598
|
+
#recordLifecycle;
|
|
46599
|
+
constructor(publisher, recordLifecycle, daemonGenerationId = randomUUID9()) {
|
|
46600
|
+
this.#recordLifecycle = recordLifecycle;
|
|
46730
46601
|
this.#publisher = publisher;
|
|
46602
|
+
this.daemonGenerationId = daemonGenerationId;
|
|
46731
46603
|
}
|
|
46732
46604
|
requested = (command) => {
|
|
46733
46605
|
this.#queued.set(command.commandId, {
|
|
46734
46606
|
commandId: command.commandId,
|
|
46735
46607
|
content: promptContent(command),
|
|
46608
|
+
context: {
|
|
46609
|
+
agentId: command.agentId,
|
|
46610
|
+
directoryId: command.directoryId,
|
|
46611
|
+
additionalDirectoryIds: command.additionalDirectoryIds
|
|
46612
|
+
},
|
|
46613
|
+
phase: "queued",
|
|
46736
46614
|
sessionId: command.sessionId
|
|
46737
46615
|
});
|
|
46738
46616
|
};
|
|
46739
46617
|
started = (sessionId, commandId, attemptId, epoch) => {
|
|
46740
46618
|
const request = this.#queued.get(commandId);
|
|
46741
46619
|
if (request?.sessionId === sessionId) {
|
|
46742
|
-
this.#queued.
|
|
46743
|
-
return { attemptId, content: request.content, epoch };
|
|
46620
|
+
this.#queued.set(commandId, { ...request, phase: "running" });
|
|
46621
|
+
return { attemptId, content: request.content, epoch, context: request.context };
|
|
46744
46622
|
}
|
|
46745
46623
|
throw new Error("The executing prompt was not registered in the V2 queue");
|
|
46746
46624
|
};
|
|
46747
46625
|
record = (sessionId, event, position) => {
|
|
46748
|
-
this
|
|
46626
|
+
const recorded = this.event(sessionId, position, event, (/* @__PURE__ */ new Date()).toISOString());
|
|
46627
|
+
if (event.type === "lifecycle-metadata" && (event.payload.kind === "prompt.completed" || event.payload.kind === "prompt.failed" || event.payload.kind === "prompt.failed-before-start")) {
|
|
46628
|
+
this.#terminal.set(event.payload.commandId, recorded);
|
|
46629
|
+
const pending2 = this.#publications.get(sessionId) ?? [];
|
|
46630
|
+
pending2.push(recorded);
|
|
46631
|
+
this.#publications.set(sessionId, pending2);
|
|
46632
|
+
return;
|
|
46633
|
+
}
|
|
46634
|
+
const pending = this.#publications.get(sessionId);
|
|
46635
|
+
if (pending !== void 0) {
|
|
46636
|
+
pending.push(recorded);
|
|
46637
|
+
} else {
|
|
46638
|
+
this.#publisher.publishV2(recorded);
|
|
46639
|
+
}
|
|
46640
|
+
};
|
|
46641
|
+
publishTerminal = (sessionId, commandId) => {
|
|
46642
|
+
const event = this.#terminal.get(commandId);
|
|
46643
|
+
if (event?.sessionId === sessionId) {
|
|
46644
|
+
this.#terminal.delete(commandId);
|
|
46645
|
+
const pending = this.#publications.get(sessionId) ?? [];
|
|
46646
|
+
while (pending.length > 0) {
|
|
46647
|
+
const next = pending[0];
|
|
46648
|
+
if (next === void 0) {
|
|
46649
|
+
break;
|
|
46650
|
+
}
|
|
46651
|
+
if (next.type === "lifecycle-metadata" && "commandId" in next.payload && this.#terminal.has(next.payload.commandId)) {
|
|
46652
|
+
break;
|
|
46653
|
+
}
|
|
46654
|
+
pending.shift();
|
|
46655
|
+
this.#publisher.publishV2(next);
|
|
46656
|
+
}
|
|
46657
|
+
if (pending.length === 0) {
|
|
46658
|
+
this.#publications.delete(sessionId);
|
|
46659
|
+
}
|
|
46660
|
+
}
|
|
46661
|
+
this.#queued.delete(commandId);
|
|
46749
46662
|
};
|
|
46750
|
-
event = (sessionId, position, event, recordedAt) =>
|
|
46751
|
-
queueChanged = (
|
|
46752
|
-
|
|
46663
|
+
event = (sessionId, position, event, recordedAt) => sessionEventV22(this.daemonGenerationId, sessionId, position, event, recordedAt);
|
|
46664
|
+
queueChanged = async (sessionId) => {
|
|
46665
|
+
await this.#recordLifecycle(sessionId, {
|
|
46666
|
+
type: "lifecycle-metadata",
|
|
46667
|
+
payload: { kind: "session.queue.changed" }
|
|
46668
|
+
});
|
|
46669
|
+
};
|
|
46670
|
+
completed = async (sessionId, commandId, stopReason) => {
|
|
46753
46671
|
const request = this.#queued.get(commandId);
|
|
46754
|
-
if (request?.sessionId
|
|
46755
|
-
|
|
46672
|
+
if (request?.sessionId !== sessionId || this.#terminal.has(commandId)) {
|
|
46673
|
+
return;
|
|
46674
|
+
}
|
|
46675
|
+
const recorded = await this.#recordLifecycle(sessionId, {
|
|
46676
|
+
type: "lifecycle-metadata",
|
|
46677
|
+
payload: { kind: "prompt.completed", commandId, stopReason }
|
|
46678
|
+
});
|
|
46679
|
+
if (!recorded) {
|
|
46680
|
+
this.#publisher.publishOperationFailure(
|
|
46681
|
+
sessionId,
|
|
46682
|
+
commandId,
|
|
46683
|
+
"cancelled",
|
|
46684
|
+
"The prompt was cancelled before execution"
|
|
46685
|
+
);
|
|
46756
46686
|
}
|
|
46757
46687
|
};
|
|
46758
|
-
failed = (sessionId, commandId,
|
|
46688
|
+
failed = async (sessionId, commandId, code, message) => {
|
|
46759
46689
|
const request = this.#queued.get(commandId);
|
|
46760
|
-
if (request?.sessionId
|
|
46761
|
-
|
|
46690
|
+
if (request?.sessionId !== sessionId || this.#terminal.has(commandId)) {
|
|
46691
|
+
return;
|
|
46692
|
+
}
|
|
46693
|
+
const recorded = await this.#recordLifecycle(sessionId, {
|
|
46694
|
+
type: "lifecycle-metadata",
|
|
46695
|
+
payload: { kind: "prompt.failed-before-start", commandId, code, message }
|
|
46696
|
+
});
|
|
46697
|
+
if (!recorded) {
|
|
46698
|
+
this.#publisher.publishOperationFailure(sessionId, commandId, code, message);
|
|
46762
46699
|
}
|
|
46763
46700
|
};
|
|
46764
46701
|
promptRequestRecovery = (sessionId) => ({
|
|
46765
|
-
queuedPromptRequests: [...this.#queued.values()].filter((request) => request.sessionId === sessionId).map(({ commandId, content }) => ({ commandId, content }))
|
|
46702
|
+
queuedPromptRequests: [...this.#queued.values()].filter((request) => request.sessionId === sessionId && request.phase === "queued").map(({ commandId, content }) => ({ commandId, content }))
|
|
46766
46703
|
});
|
|
46767
46704
|
};
|
|
46768
46705
|
|
|
@@ -46814,7 +46751,7 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
|
|
|
46814
46751
|
{
|
|
46815
46752
|
agentId: agent.id,
|
|
46816
46753
|
kind: AGENT_INSTALL_REQUEST_KIND,
|
|
46817
|
-
requestId: `automatic-integration-${
|
|
46754
|
+
requestId: `automatic-integration-${randomUUID10()}`
|
|
46818
46755
|
},
|
|
46819
46756
|
signal
|
|
46820
46757
|
);
|
|
@@ -46832,19 +46769,33 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
46832
46769
|
publishCatalog: async (installationSignal) => await publishAgentCatalog(config2, installationSignal),
|
|
46833
46770
|
stateDirectory
|
|
46834
46771
|
});
|
|
46835
|
-
const
|
|
46836
|
-
|
|
46837
|
-
);
|
|
46772
|
+
const channelHash = createHash8("sha256").update(config2.channelId).digest("hex");
|
|
46773
|
+
const daemonGenerationId = randomUUID10();
|
|
46774
|
+
const sessionDatabase = openAcpSessionDatabase(join19(stateDirectory, "sessions", `${channelHash}.sqlite`));
|
|
46775
|
+
let eventsV2;
|
|
46776
|
+
try {
|
|
46777
|
+
eventsV2 = new CachedAcpSessionEventStoreV2(
|
|
46778
|
+
openSessionEventCacheV2Database(join19(stateDirectory, "sessions", `${channelHash}.events.sqlite`)),
|
|
46779
|
+
daemonGenerationId
|
|
46780
|
+
);
|
|
46781
|
+
} catch (error62) {
|
|
46782
|
+
sessionDatabase.close();
|
|
46783
|
+
throw error62;
|
|
46784
|
+
}
|
|
46785
|
+
const sessionStore = new SqliteAcpSessionStore(sessionDatabase, eventsV2);
|
|
46838
46786
|
await using externalContent = new LocalExternalContentStore(stateDirectory);
|
|
46839
46787
|
const operations = new DaemonOperationState();
|
|
46840
46788
|
const publisher = new DaemonSessionEventPublisher();
|
|
46841
|
-
const eventLogV2 = new DaemonSessionEventLogV2(
|
|
46789
|
+
const eventLogV2 = new DaemonSessionEventLogV2(
|
|
46790
|
+
publisher,
|
|
46791
|
+
(sessionId, event) => agentRuntime.recordLifecycleEventV2(sessionId, event),
|
|
46792
|
+
daemonGenerationId
|
|
46793
|
+
);
|
|
46842
46794
|
const activeTurns = new DaemonTurnRegistry(operations);
|
|
46843
|
-
const recordSessionEvent = (sessionId, event) => {
|
|
46844
|
-
publisher.publish(sessionId, activeTurns.recordEvent(event));
|
|
46845
|
-
};
|
|
46846
46795
|
const agentRuntime = new AgentRuntimeManager(
|
|
46847
|
-
new DaemonAcpObserver(
|
|
46796
|
+
new DaemonAcpObserver((_sessionId, event) => {
|
|
46797
|
+
activeTurns.recordEvent(event);
|
|
46798
|
+
}, eventLogV2.record),
|
|
46848
46799
|
sessionStore,
|
|
46849
46800
|
{
|
|
46850
46801
|
read: async (options2, nativeSessionId, nativeTurn) => options2.agent.id === "codex" ? (await readCodexFullHistory(
|
|
@@ -46884,7 +46835,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
46884
46835
|
options2.signal
|
|
46885
46836
|
);
|
|
46886
46837
|
return cwd === options2.cwd && additionalDirectories.length === options2.additionalDirectories.length && additionalDirectories.every(
|
|
46887
|
-
(directory,
|
|
46838
|
+
(directory, index2) => directory === options2.additionalDirectories[index2]
|
|
46888
46839
|
);
|
|
46889
46840
|
});
|
|
46890
46841
|
}
|
|
@@ -47349,12 +47300,12 @@ var RuntimeSupervisor = class {
|
|
|
47349
47300
|
}
|
|
47350
47301
|
};
|
|
47351
47302
|
function pairingIdentifier(arguments_) {
|
|
47352
|
-
const indexes = arguments_.flatMap((argument,
|
|
47303
|
+
const indexes = arguments_.flatMap((argument, index3) => argument === "--pairing" ? [index3] : []);
|
|
47353
47304
|
if (indexes.length !== 1) {
|
|
47354
47305
|
return null;
|
|
47355
47306
|
}
|
|
47356
|
-
const
|
|
47357
|
-
return
|
|
47307
|
+
const index2 = indexes[0];
|
|
47308
|
+
return index2 === void 0 ? null : arguments_[index2 + 1] ?? null;
|
|
47358
47309
|
}
|
|
47359
47310
|
async function waitForReady(active, signal) {
|
|
47360
47311
|
if (active.status === "online") {
|
|
@@ -47649,9 +47600,9 @@ function formatPairTable(pairs) {
|
|
|
47649
47600
|
const headers = ["connection_id", "app_id", "runtime_id", "workspace", "status"];
|
|
47650
47601
|
const rows = pairs.map((pair) => [pair.connectionId, pair.appId, pair.runtimeId, pair.workspace, pair.status]);
|
|
47651
47602
|
const widths = headers.map(
|
|
47652
|
-
(header,
|
|
47603
|
+
(header, index2) => Math.max(header.length, ...rows.map((row) => row[index2]?.length ?? 0))
|
|
47653
47604
|
);
|
|
47654
|
-
const line = (row) => `| ${row.map((value,
|
|
47605
|
+
const line = (row) => `| ${row.map((value, index2) => value.padEnd(widths[index2] ?? value.length)).join(" | ")} |`;
|
|
47655
47606
|
const divider = `|-${widths.map((width) => "-".repeat(width)).join("-|-")}-|`;
|
|
47656
47607
|
return `${line(headers)}
|
|
47657
47608
|
${divider}
|