@moxt-ai/mobius 0.0.155 → 0.0.156
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-query-processes.d.ts +2 -1
- package/dist/acp/agent-query-processes.d.ts.map +1 -1
- package/dist/acp/agent-query-processes.js +7 -1
- package/dist/acp/agent-query-processes.js.map +1 -1
- package/dist/acp/agent-runtime-manager.d.ts +4 -2
- package/dist/acp/agent-runtime-manager.d.ts.map +1 -1
- package/dist/acp/agent-runtime-manager.js +19 -0
- package/dist/acp/agent-runtime-manager.js.map +1 -1
- package/dist/acp/agent-session.d.ts +2 -1
- package/dist/acp/agent-session.d.ts.map +1 -1
- package/dist/acp/agent-session.js +16 -2
- package/dist/acp/agent-session.js.map +1 -1
- package/dist/acp/session-contracts.d.ts +9 -1
- package/dist/acp/session-contracts.d.ts.map +1 -1
- package/dist/acp/session-contracts.js +1 -0
- package/dist/acp/session-contracts.js.map +1 -1
- 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 +17 -1
- package/dist/acp/session-history.js.map +1 -1
- package/dist/acp/session-store.d.ts +7 -0
- package/dist/acp/session-store.d.ts.map +1 -1
- package/dist/acp/session-store.js +34 -3
- package/dist/acp/session-store.js.map +1 -1
- package/dist/cli.js +1034 -103
- package/dist/cli.js.map +4 -4
- package/dist/daemon-command-handler.d.ts +3 -1
- package/dist/daemon-command-handler.d.ts.map +1 -1
- package/dist/daemon-command-handler.js +9 -3
- package/dist/daemon-command-handler.js.map +1 -1
- package/dist/daemon-history-commands.d.ts +2 -1
- package/dist/daemon-history-commands.d.ts.map +1 -1
- package/dist/daemon-history-commands.js +64 -1
- package/dist/daemon-history-commands.js.map +1 -1
- package/dist/daemon-observers.d.ts +3 -2
- package/dist/daemon-observers.d.ts.map +1 -1
- package/dist/daemon-observers.js +7 -1
- package/dist/daemon-observers.js.map +1 -1
- package/dist/daemon-prompt-executor.d.ts +3 -1
- package/dist/daemon-prompt-executor.d.ts.map +1 -1
- package/dist/daemon-prompt-executor.js +9 -3
- package/dist/daemon-prompt-executor.js.map +1 -1
- package/dist/daemon-turn-registry.d.ts +13 -13
- package/dist/generated/acp-session-store-migrations.d.ts +3 -0
- package/dist/generated/acp-session-store-migrations.d.ts.map +1 -1
- package/dist/generated/acp-session-store-migrations.js +5 -1
- package/dist/generated/acp-session-store-migrations.js.map +1 -1
- package/dist/index.js +1017 -86
- package/dist/index.js.map +4 -4
- package/dist/relay-connection/run-relay-connection.d.ts +3 -1
- package/dist/relay-connection/run-relay-connection.d.ts.map +1 -1
- package/dist/relay-connection/run-relay-connection.js +2 -1
- package/dist/relay-connection/run-relay-connection.js.map +1 -1
- package/dist/relay-connection/session-event-publisher.d.ts +2 -1
- package/dist/relay-connection/session-event-publisher.d.ts.map +1 -1
- package/dist/relay-connection/session-event-publisher.js +18 -1
- 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 +4 -1
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.js +1013 -82
- package/dist/runtime.js.map +4 -4
- package/dist/schema/acp-session-store/index.d.ts +1 -0
- package/dist/schema/acp-session-store/index.d.ts.map +1 -1
- package/dist/schema/acp-session-store/index.js +1 -0
- package/dist/schema/acp-session-store/index.js.map +1 -1
- package/dist/schema/acp-session-store/session-event-v2.d.ts +82 -0
- package/dist/schema/acp-session-store/session-event-v2.d.ts.map +1 -0
- package/dist/schema/acp-session-store/session-event-v2.js +11 -0
- package/dist/schema/acp-session-store/session-event-v2.js.map +1 -0
- package/dist/session-event-log-v2.d.ts +15 -0
- package/dist/session-event-log-v2.d.ts.map +1 -0
- package/dist/session-event-log-v2.js +238 -0
- package/dist/session-event-log-v2.js.map +1 -0
- package/package.json +1 -1
package/dist/runtime.js
CHANGED
|
@@ -3354,11 +3354,11 @@ var $ZodDate = /* @__PURE__ */ $constructor("$ZodDate", (inst, def) => {
|
|
|
3354
3354
|
return payload;
|
|
3355
3355
|
};
|
|
3356
3356
|
});
|
|
3357
|
-
function handleArrayResult(result, final,
|
|
3357
|
+
function handleArrayResult(result, final, index2) {
|
|
3358
3358
|
if (result.issues.length) {
|
|
3359
|
-
final.issues.push(...prefixIssues(
|
|
3359
|
+
final.issues.push(...prefixIssues(index2, result.issues));
|
|
3360
3360
|
}
|
|
3361
|
-
final.value[
|
|
3361
|
+
final.value[index2] = result.value;
|
|
3362
3362
|
}
|
|
3363
3363
|
var $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
|
|
3364
3364
|
$ZodType.init(inst, def);
|
|
@@ -3969,14 +3969,14 @@ function mergeValues(a, b) {
|
|
|
3969
3969
|
return { valid: false, mergeErrorPath: [] };
|
|
3970
3970
|
}
|
|
3971
3971
|
const newArray = [];
|
|
3972
|
-
for (let
|
|
3973
|
-
const itemA = a[
|
|
3974
|
-
const itemB = b[
|
|
3972
|
+
for (let index2 = 0; index2 < a.length; index2++) {
|
|
3973
|
+
const itemA = a[index2];
|
|
3974
|
+
const itemB = b[index2];
|
|
3975
3975
|
const sharedValue = mergeValues(itemA, itemB);
|
|
3976
3976
|
if (!sharedValue.valid) {
|
|
3977
3977
|
return {
|
|
3978
3978
|
valid: false,
|
|
3979
|
-
mergeErrorPath: [
|
|
3979
|
+
mergeErrorPath: [index2, ...sharedValue.mergeErrorPath]
|
|
3980
3980
|
};
|
|
3981
3981
|
}
|
|
3982
3982
|
newArray.push(sharedValue.data);
|
|
@@ -4127,11 +4127,11 @@ function getTupleOptStart(items, key) {
|
|
|
4127
4127
|
}
|
|
4128
4128
|
return 0;
|
|
4129
4129
|
}
|
|
4130
|
-
function handleTupleResult(result, final,
|
|
4130
|
+
function handleTupleResult(result, final, index2) {
|
|
4131
4131
|
if (result.issues.length) {
|
|
4132
|
-
final.issues.push(...prefixIssues(
|
|
4132
|
+
final.issues.push(...prefixIssues(index2, result.issues));
|
|
4133
4133
|
}
|
|
4134
|
-
final.value[
|
|
4134
|
+
final.value[index2] = result.value;
|
|
4135
4135
|
}
|
|
4136
4136
|
function handleTupleResults(itemResults, final, items, input2, optoutStart) {
|
|
4137
4137
|
for (let i = 0; i < items.length; i++) {
|
|
@@ -18812,7 +18812,7 @@ function detectVersion(schema, defaultTarget) {
|
|
|
18812
18812
|
return defaultTarget ?? "draft-2020-12";
|
|
18813
18813
|
}
|
|
18814
18814
|
function applyMinItems(items, minItems) {
|
|
18815
|
-
return items.map((item,
|
|
18815
|
+
return items.map((item, index2) => index2 < minItems ? item : item.optional());
|
|
18816
18816
|
}
|
|
18817
18817
|
function decodeJSONPointerSegment(segment) {
|
|
18818
18818
|
return segment.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
@@ -20000,12 +20000,12 @@ var DEFAULT_AGENT_EXECUTION_CONFIGURATION = Object.freeze({
|
|
|
20000
20000
|
});
|
|
20001
20001
|
var sessionConfigurationSelectionsSchema = external_exports.array(sessionConfigurationSelectionSchema).max(100).superRefine((selections, context) => {
|
|
20002
20002
|
const identifiers = /* @__PURE__ */ new Set();
|
|
20003
|
-
for (const [
|
|
20003
|
+
for (const [index2, selection] of selections.entries()) {
|
|
20004
20004
|
if (identifiers.has(selection.configId)) {
|
|
20005
20005
|
context.addIssue({
|
|
20006
20006
|
code: "custom",
|
|
20007
20007
|
message: "Session configuration identifiers must be unique",
|
|
20008
|
-
path: [
|
|
20008
|
+
path: [index2, "configId"]
|
|
20009
20009
|
});
|
|
20010
20010
|
}
|
|
20011
20011
|
identifiers.add(selection.configId);
|
|
@@ -21207,6 +21207,383 @@ var encodeNativeSessionResult = (value) => JSON.stringify(nativeSessionResultSch
|
|
|
21207
21207
|
var decodeNativeSessionCancel = (encoded) => decode4(nativeSessionCancelSchema, encoded);
|
|
21208
21208
|
var encodeNativeSessionCancel = (value) => JSON.stringify(nativeSessionCancelSchema.parse(value));
|
|
21209
21209
|
|
|
21210
|
+
// ../protocol/src/session-event-log-v2.ts
|
|
21211
|
+
var MAX_EVENT_COUNT = 1e4;
|
|
21212
|
+
var MAX_COLLECTION_SIZE = 1e3;
|
|
21213
|
+
var MAX_CONTENT_LENGTH = 1e6;
|
|
21214
|
+
var MAX_JSON_DEPTH = 16;
|
|
21215
|
+
var MAX_JSON_KEYS = 1e3;
|
|
21216
|
+
var SESSION_EVENT_V2_KIND = "session.event.v2";
|
|
21217
|
+
var boundedString = external_exports.string().max(MAX_CONTENT_LENGTH);
|
|
21218
|
+
var shortString = external_exports.string().max(2048);
|
|
21219
|
+
function boundedJsonIssue(value, depth = 0) {
|
|
21220
|
+
if (depth > MAX_JSON_DEPTH) {
|
|
21221
|
+
return "JSON nesting exceeds the maximum depth";
|
|
21222
|
+
}
|
|
21223
|
+
if (typeof value === "string") {
|
|
21224
|
+
return value.length <= MAX_CONTENT_LENGTH ? null : "JSON string exceeds the maximum length";
|
|
21225
|
+
}
|
|
21226
|
+
if (typeof value === "number") {
|
|
21227
|
+
return Number.isFinite(value) ? null : "JSON number must be finite";
|
|
21228
|
+
}
|
|
21229
|
+
if (typeof value === "boolean" || value === null) {
|
|
21230
|
+
return null;
|
|
21231
|
+
}
|
|
21232
|
+
if (Array.isArray(value)) {
|
|
21233
|
+
if (value.length > MAX_COLLECTION_SIZE) {
|
|
21234
|
+
return "JSON array exceeds the maximum length";
|
|
21235
|
+
}
|
|
21236
|
+
for (const item of value) {
|
|
21237
|
+
const issue2 = boundedJsonIssue(item, depth + 1);
|
|
21238
|
+
if (issue2 !== null) {
|
|
21239
|
+
return issue2;
|
|
21240
|
+
}
|
|
21241
|
+
}
|
|
21242
|
+
return null;
|
|
21243
|
+
}
|
|
21244
|
+
if (typeof value === "object" && value !== void 0) {
|
|
21245
|
+
const entries = Object.entries(value);
|
|
21246
|
+
if (entries.length > MAX_JSON_KEYS) {
|
|
21247
|
+
return "JSON object exceeds the maximum key count";
|
|
21248
|
+
}
|
|
21249
|
+
for (const [key, item] of entries) {
|
|
21250
|
+
if (key.length > 255) {
|
|
21251
|
+
return "JSON key exceeds the maximum length";
|
|
21252
|
+
}
|
|
21253
|
+
const issue2 = boundedJsonIssue(item, depth + 1);
|
|
21254
|
+
if (issue2 !== null) {
|
|
21255
|
+
return issue2;
|
|
21256
|
+
}
|
|
21257
|
+
}
|
|
21258
|
+
return null;
|
|
21259
|
+
}
|
|
21260
|
+
return "Value is not bounded JSON";
|
|
21261
|
+
}
|
|
21262
|
+
var boundedJsonSchema = external_exports.unknown().superRefine((value, context) => {
|
|
21263
|
+
const issue2 = boundedJsonIssue(value);
|
|
21264
|
+
if (issue2 !== null) {
|
|
21265
|
+
context.addIssue({ code: "custom", message: issue2 });
|
|
21266
|
+
}
|
|
21267
|
+
});
|
|
21268
|
+
var metadataSchema = external_exports.record(external_exports.string().max(255), boundedJsonSchema).readonly();
|
|
21269
|
+
var optionalMetadata = metadataSchema.nullable().optional();
|
|
21270
|
+
var annotationsSchema = external_exports.strictObject({
|
|
21271
|
+
_meta: optionalMetadata,
|
|
21272
|
+
audience: external_exports.array(external_exports.enum(["assistant", "user"])).max(2).readonly().nullable().optional(),
|
|
21273
|
+
lastModified: shortString.nullable().optional(),
|
|
21274
|
+
priority: external_exports.number().finite().nullable().optional()
|
|
21275
|
+
}).readonly();
|
|
21276
|
+
var contentFields = { _meta: optionalMetadata, annotations: annotationsSchema.nullable().optional() };
|
|
21277
|
+
var textContentSchema = external_exports.strictObject({ ...contentFields, text: boundedString, type: external_exports.literal("text") }).readonly();
|
|
21278
|
+
var imageContentSchema = external_exports.strictObject({
|
|
21279
|
+
...contentFields,
|
|
21280
|
+
data: boundedString,
|
|
21281
|
+
mimeType: shortString,
|
|
21282
|
+
type: external_exports.literal("image"),
|
|
21283
|
+
uri: boundedString.nullable().optional()
|
|
21284
|
+
}).readonly();
|
|
21285
|
+
var audioContentSchema = external_exports.strictObject({ ...contentFields, data: boundedString, mimeType: shortString, type: external_exports.literal("audio") }).readonly();
|
|
21286
|
+
var resourceLinkSchema = external_exports.strictObject({
|
|
21287
|
+
...contentFields,
|
|
21288
|
+
description: boundedString.nullable().optional(),
|
|
21289
|
+
mimeType: shortString.nullable().optional(),
|
|
21290
|
+
name: shortString,
|
|
21291
|
+
size: external_exports.number().int().nonnegative().safe().nullable().optional(),
|
|
21292
|
+
title: shortString.nullable().optional(),
|
|
21293
|
+
type: external_exports.literal("resource_link"),
|
|
21294
|
+
uri: boundedString
|
|
21295
|
+
}).readonly();
|
|
21296
|
+
var textResourceSchema = external_exports.strictObject({
|
|
21297
|
+
_meta: optionalMetadata,
|
|
21298
|
+
mimeType: shortString.nullable().optional(),
|
|
21299
|
+
text: boundedString,
|
|
21300
|
+
uri: boundedString
|
|
21301
|
+
}).readonly();
|
|
21302
|
+
var blobResourceSchema = external_exports.strictObject({
|
|
21303
|
+
_meta: optionalMetadata,
|
|
21304
|
+
blob: boundedString,
|
|
21305
|
+
mimeType: shortString.nullable().optional(),
|
|
21306
|
+
uri: boundedString
|
|
21307
|
+
}).readonly();
|
|
21308
|
+
var embeddedResourceSchema = external_exports.strictObject({
|
|
21309
|
+
...contentFields,
|
|
21310
|
+
resource: external_exports.union([textResourceSchema, blobResourceSchema]),
|
|
21311
|
+
type: external_exports.literal("resource")
|
|
21312
|
+
}).readonly();
|
|
21313
|
+
var contentBlockV2Schema = external_exports.discriminatedUnion("type", [
|
|
21314
|
+
textContentSchema,
|
|
21315
|
+
imageContentSchema,
|
|
21316
|
+
audioContentSchema,
|
|
21317
|
+
resourceLinkSchema,
|
|
21318
|
+
embeddedResourceSchema
|
|
21319
|
+
]);
|
|
21320
|
+
var toolCallContentSchema = external_exports.discriminatedUnion("type", [
|
|
21321
|
+
external_exports.strictObject({ _meta: optionalMetadata, content: contentBlockV2Schema, type: external_exports.literal("content") }).readonly(),
|
|
21322
|
+
external_exports.strictObject({
|
|
21323
|
+
_meta: optionalMetadata,
|
|
21324
|
+
newText: boundedString,
|
|
21325
|
+
oldText: boundedString.nullable().optional(),
|
|
21326
|
+
path: boundedString,
|
|
21327
|
+
type: external_exports.literal("diff")
|
|
21328
|
+
}).readonly(),
|
|
21329
|
+
external_exports.strictObject({ _meta: optionalMetadata, terminalId: shortString, type: external_exports.literal("terminal") }).readonly()
|
|
21330
|
+
]);
|
|
21331
|
+
var toolCallLocationSchema = external_exports.strictObject({
|
|
21332
|
+
_meta: optionalMetadata,
|
|
21333
|
+
line: external_exports.number().int().nonnegative().safe().nullable().optional(),
|
|
21334
|
+
path: boundedString
|
|
21335
|
+
}).readonly();
|
|
21336
|
+
var toolKindSchema = external_exports.enum([
|
|
21337
|
+
"read",
|
|
21338
|
+
"edit",
|
|
21339
|
+
"delete",
|
|
21340
|
+
"move",
|
|
21341
|
+
"search",
|
|
21342
|
+
"execute",
|
|
21343
|
+
"think",
|
|
21344
|
+
"fetch",
|
|
21345
|
+
"switch_mode",
|
|
21346
|
+
"other"
|
|
21347
|
+
]);
|
|
21348
|
+
var toolStatusSchema = external_exports.enum(["pending", "in_progress", "completed", "failed"]);
|
|
21349
|
+
var toolPatchFields = {
|
|
21350
|
+
_meta: optionalMetadata,
|
|
21351
|
+
content: external_exports.array(toolCallContentSchema).max(MAX_COLLECTION_SIZE).readonly().nullable().optional(),
|
|
21352
|
+
kind: toolKindSchema.nullable().optional(),
|
|
21353
|
+
locations: external_exports.array(toolCallLocationSchema).max(MAX_COLLECTION_SIZE).readonly().nullable().optional(),
|
|
21354
|
+
name: shortString.nullable().optional(),
|
|
21355
|
+
rawInput: boundedJsonSchema.optional(),
|
|
21356
|
+
rawOutput: boundedJsonSchema.optional(),
|
|
21357
|
+
status: toolStatusSchema.nullable().optional(),
|
|
21358
|
+
title: boundedString.nullable().optional()
|
|
21359
|
+
};
|
|
21360
|
+
var planEntrySchema = external_exports.strictObject({
|
|
21361
|
+
_meta: optionalMetadata,
|
|
21362
|
+
content: boundedString,
|
|
21363
|
+
priority: external_exports.enum(["high", "medium", "low"]),
|
|
21364
|
+
status: external_exports.enum(["pending", "in_progress", "completed"])
|
|
21365
|
+
}).readonly();
|
|
21366
|
+
var planContentSchema = external_exports.discriminatedUnion("type", [
|
|
21367
|
+
external_exports.strictObject({
|
|
21368
|
+
_meta: optionalMetadata,
|
|
21369
|
+
entries: external_exports.array(planEntrySchema).max(MAX_COLLECTION_SIZE).readonly(),
|
|
21370
|
+
planId: shortString,
|
|
21371
|
+
type: external_exports.literal("items")
|
|
21372
|
+
}).readonly(),
|
|
21373
|
+
external_exports.strictObject({ _meta: optionalMetadata, planId: shortString, type: external_exports.literal("file"), uri: boundedString }).readonly(),
|
|
21374
|
+
external_exports.strictObject({
|
|
21375
|
+
_meta: optionalMetadata,
|
|
21376
|
+
content: boundedString,
|
|
21377
|
+
planId: shortString,
|
|
21378
|
+
type: external_exports.literal("markdown")
|
|
21379
|
+
}).readonly()
|
|
21380
|
+
]);
|
|
21381
|
+
var commandSchema = external_exports.strictObject({
|
|
21382
|
+
_meta: optionalMetadata,
|
|
21383
|
+
description: boundedString,
|
|
21384
|
+
input: external_exports.strictObject({ _meta: optionalMetadata, hint: boundedString }).readonly().nullable().optional(),
|
|
21385
|
+
name: shortString
|
|
21386
|
+
}).readonly();
|
|
21387
|
+
var configSelectOptionSchema = external_exports.strictObject({
|
|
21388
|
+
_meta: optionalMetadata,
|
|
21389
|
+
description: boundedString.nullable().optional(),
|
|
21390
|
+
name: shortString,
|
|
21391
|
+
value: shortString
|
|
21392
|
+
}).readonly();
|
|
21393
|
+
var configSelectGroupSchema = external_exports.strictObject({
|
|
21394
|
+
_meta: optionalMetadata,
|
|
21395
|
+
group: shortString,
|
|
21396
|
+
name: shortString,
|
|
21397
|
+
options: external_exports.array(configSelectOptionSchema).max(MAX_COLLECTION_SIZE).readonly()
|
|
21398
|
+
}).readonly();
|
|
21399
|
+
var configBaseFields = {
|
|
21400
|
+
_meta: optionalMetadata,
|
|
21401
|
+
category: shortString.nullable().optional(),
|
|
21402
|
+
description: boundedString.nullable().optional(),
|
|
21403
|
+
id: shortString,
|
|
21404
|
+
name: shortString
|
|
21405
|
+
};
|
|
21406
|
+
var sessionConfigOptionSchema2 = external_exports.discriminatedUnion("type", [
|
|
21407
|
+
external_exports.strictObject({
|
|
21408
|
+
...configBaseFields,
|
|
21409
|
+
currentValue: shortString,
|
|
21410
|
+
options: external_exports.union([
|
|
21411
|
+
external_exports.array(configSelectOptionSchema).max(MAX_COLLECTION_SIZE).readonly(),
|
|
21412
|
+
external_exports.array(configSelectGroupSchema).max(MAX_COLLECTION_SIZE).readonly()
|
|
21413
|
+
]),
|
|
21414
|
+
type: external_exports.literal("select")
|
|
21415
|
+
}).readonly(),
|
|
21416
|
+
external_exports.strictObject({ ...configBaseFields, currentValue: external_exports.boolean(), type: external_exports.literal("boolean") }).readonly()
|
|
21417
|
+
]);
|
|
21418
|
+
var contentChunkFields = {
|
|
21419
|
+
_meta: optionalMetadata,
|
|
21420
|
+
content: contentBlockV2Schema,
|
|
21421
|
+
messageId: shortString.nullable().optional()
|
|
21422
|
+
};
|
|
21423
|
+
var acpSessionUpdateV2Schema = external_exports.discriminatedUnion("sessionUpdate", [
|
|
21424
|
+
external_exports.strictObject({ ...contentChunkFields, sessionUpdate: external_exports.literal("user_message_chunk") }).readonly(),
|
|
21425
|
+
external_exports.strictObject({ ...contentChunkFields, sessionUpdate: external_exports.literal("agent_message_chunk") }).readonly(),
|
|
21426
|
+
external_exports.strictObject({ ...contentChunkFields, sessionUpdate: external_exports.literal("agent_thought_chunk") }).readonly(),
|
|
21427
|
+
external_exports.strictObject({
|
|
21428
|
+
_meta: optionalMetadata,
|
|
21429
|
+
content: external_exports.array(toolCallContentSchema).max(MAX_COLLECTION_SIZE).readonly().optional(),
|
|
21430
|
+
kind: toolKindSchema.optional(),
|
|
21431
|
+
locations: external_exports.array(toolCallLocationSchema).max(MAX_COLLECTION_SIZE).readonly().optional(),
|
|
21432
|
+
name: shortString.nullable().optional(),
|
|
21433
|
+
rawInput: boundedJsonSchema.optional(),
|
|
21434
|
+
rawOutput: boundedJsonSchema.optional(),
|
|
21435
|
+
sessionUpdate: external_exports.literal("tool_call"),
|
|
21436
|
+
status: toolStatusSchema.optional(),
|
|
21437
|
+
title: boundedString,
|
|
21438
|
+
toolCallId: shortString
|
|
21439
|
+
}).readonly(),
|
|
21440
|
+
external_exports.strictObject({ ...toolPatchFields, sessionUpdate: external_exports.literal("tool_call_update"), toolCallId: shortString }).readonly(),
|
|
21441
|
+
external_exports.strictObject({
|
|
21442
|
+
_meta: optionalMetadata,
|
|
21443
|
+
entries: external_exports.array(planEntrySchema).max(MAX_COLLECTION_SIZE).readonly(),
|
|
21444
|
+
sessionUpdate: external_exports.literal("plan")
|
|
21445
|
+
}).readonly(),
|
|
21446
|
+
external_exports.strictObject({ _meta: optionalMetadata, plan: planContentSchema, sessionUpdate: external_exports.literal("plan_update") }).readonly(),
|
|
21447
|
+
external_exports.strictObject({ _meta: optionalMetadata, planId: shortString, sessionUpdate: external_exports.literal("plan_removed") }).readonly(),
|
|
21448
|
+
external_exports.strictObject({
|
|
21449
|
+
_meta: optionalMetadata,
|
|
21450
|
+
availableCommands: external_exports.array(commandSchema).max(MAX_COLLECTION_SIZE).readonly(),
|
|
21451
|
+
sessionUpdate: external_exports.literal("available_commands_update")
|
|
21452
|
+
}).readonly(),
|
|
21453
|
+
external_exports.strictObject({
|
|
21454
|
+
_meta: optionalMetadata,
|
|
21455
|
+
currentModeId: shortString,
|
|
21456
|
+
sessionUpdate: external_exports.literal("current_mode_update")
|
|
21457
|
+
}).readonly(),
|
|
21458
|
+
external_exports.strictObject({
|
|
21459
|
+
_meta: optionalMetadata,
|
|
21460
|
+
configOptions: external_exports.array(sessionConfigOptionSchema2).max(MAX_COLLECTION_SIZE).readonly(),
|
|
21461
|
+
sessionUpdate: external_exports.literal("config_option_update")
|
|
21462
|
+
}).readonly(),
|
|
21463
|
+
external_exports.strictObject({
|
|
21464
|
+
_meta: optionalMetadata,
|
|
21465
|
+
sessionUpdate: external_exports.literal("session_info_update"),
|
|
21466
|
+
title: boundedString.nullable().optional(),
|
|
21467
|
+
updatedAt: shortString.nullable().optional()
|
|
21468
|
+
}).readonly(),
|
|
21469
|
+
external_exports.strictObject({
|
|
21470
|
+
_meta: optionalMetadata,
|
|
21471
|
+
cost: external_exports.strictObject({ _meta: optionalMetadata, amount: external_exports.number().finite(), currency: external_exports.string().max(16) }).readonly().nullable().optional(),
|
|
21472
|
+
sessionUpdate: external_exports.literal("usage_update"),
|
|
21473
|
+
size: external_exports.number().int().nonnegative().safe(),
|
|
21474
|
+
used: external_exports.number().int().nonnegative().safe()
|
|
21475
|
+
}).readonly(),
|
|
21476
|
+
external_exports.strictObject({
|
|
21477
|
+
_meta: optionalMetadata,
|
|
21478
|
+
compactionId: shortString,
|
|
21479
|
+
error: boundedString.nullable().optional(),
|
|
21480
|
+
sessionUpdate: external_exports.literal("compaction_update"),
|
|
21481
|
+
status: shortString,
|
|
21482
|
+
summary: external_exports.array(contentBlockV2Schema).max(MAX_COLLECTION_SIZE).readonly().nullable().optional()
|
|
21483
|
+
}).readonly(),
|
|
21484
|
+
external_exports.strictObject({
|
|
21485
|
+
_meta: optionalMetadata,
|
|
21486
|
+
compactionId: shortString,
|
|
21487
|
+
content: contentBlockV2Schema,
|
|
21488
|
+
sessionUpdate: external_exports.literal("compaction_summary_chunk")
|
|
21489
|
+
}).readonly()
|
|
21490
|
+
]);
|
|
21491
|
+
var lifecycleBase = { commandId: identifierStringSchema };
|
|
21492
|
+
var sessionEventPayloadV2Schema = external_exports.discriminatedUnion("kind", [
|
|
21493
|
+
external_exports.strictObject({ kind: external_exports.literal("acp.session.update"), update: acpSessionUpdateV2Schema }).readonly(),
|
|
21494
|
+
external_exports.strictObject({
|
|
21495
|
+
...lifecycleBase,
|
|
21496
|
+
content: external_exports.array(contentBlockV2Schema).min(1).max(100).readonly(),
|
|
21497
|
+
kind: external_exports.literal("prompt.requested")
|
|
21498
|
+
}).readonly(),
|
|
21499
|
+
external_exports.strictObject({ ...lifecycleBase, attemptId: identifierStringSchema, epoch: identifierStringSchema, kind: external_exports.literal("prompt.started") }).readonly(),
|
|
21500
|
+
external_exports.strictObject({ ...lifecycleBase, kind: external_exports.literal("prompt.completed"), stopReason: shortString }).readonly(),
|
|
21501
|
+
external_exports.strictObject({
|
|
21502
|
+
...lifecycleBase,
|
|
21503
|
+
code: identifierStringSchema,
|
|
21504
|
+
kind: external_exports.literal("prompt.failed-before-start"),
|
|
21505
|
+
message: external_exports.string().min(1).max(500)
|
|
21506
|
+
}).readonly(),
|
|
21507
|
+
external_exports.strictObject({
|
|
21508
|
+
...lifecycleBase,
|
|
21509
|
+
attemptId: identifierStringSchema,
|
|
21510
|
+
code: identifierStringSchema,
|
|
21511
|
+
kind: external_exports.literal("prompt.failed"),
|
|
21512
|
+
message: external_exports.string().min(1).max(500)
|
|
21513
|
+
}).readonly()
|
|
21514
|
+
]);
|
|
21515
|
+
var positionSchema = external_exports.string().regex(/^(0|[1-9][0-9]*)$/);
|
|
21516
|
+
var provenanceSchema = external_exports.discriminatedUnion("kind", [
|
|
21517
|
+
external_exports.strictObject({ kind: external_exports.literal("original") }).readonly(),
|
|
21518
|
+
external_exports.strictObject({
|
|
21519
|
+
kind: external_exports.literal("imported"),
|
|
21520
|
+
sourceEventId: identifierStringSchema,
|
|
21521
|
+
sourcePosition: positionSchema,
|
|
21522
|
+
sourceSessionId: identifierStringSchema
|
|
21523
|
+
}).readonly(),
|
|
21524
|
+
external_exports.strictObject({
|
|
21525
|
+
kind: external_exports.literal("forked"),
|
|
21526
|
+
sourceEventId: identifierStringSchema,
|
|
21527
|
+
sourcePosition: positionSchema,
|
|
21528
|
+
sourceSessionId: identifierStringSchema
|
|
21529
|
+
}).readonly()
|
|
21530
|
+
]);
|
|
21531
|
+
var sessionEventV2Schema = external_exports.strictObject({
|
|
21532
|
+
eventId: identifierStringSchema,
|
|
21533
|
+
payload: sessionEventPayloadV2Schema,
|
|
21534
|
+
position: positionSchema,
|
|
21535
|
+
provenance: provenanceSchema,
|
|
21536
|
+
recordedAt: external_exports.iso.datetime({ offset: true }),
|
|
21537
|
+
sessionId: identifierStringSchema
|
|
21538
|
+
}).readonly();
|
|
21539
|
+
var sessionEventEnvelopeV2Schema = external_exports.strictObject({ event: sessionEventV2Schema, kind: external_exports.literal(SESSION_EVENT_V2_KIND) }).readonly();
|
|
21540
|
+
var sessionEventLogPageV2Schema = external_exports.strictObject({
|
|
21541
|
+
events: external_exports.array(sessionEventV2Schema).max(MAX_EVENT_COUNT).readonly(),
|
|
21542
|
+
nextCursor: external_exports.string().min(1).max(512).nullable(),
|
|
21543
|
+
tailCursor: external_exports.string().max(512),
|
|
21544
|
+
truncated: external_exports.boolean(),
|
|
21545
|
+
version: external_exports.literal(2)
|
|
21546
|
+
}).readonly();
|
|
21547
|
+
var nativeEventPageRequestV2Schema = external_exports.strictObject({ cursor: external_exports.string().min(1).max(512).nullable(), eventLimit: external_exports.number().int().min(1).max(1e4) }).readonly();
|
|
21548
|
+
var executingPromptRequestEventLogV2Schema = external_exports.strictObject({
|
|
21549
|
+
attemptId: identifierStringSchema,
|
|
21550
|
+
commandId: identifierStringSchema,
|
|
21551
|
+
epoch: identifierStringSchema,
|
|
21552
|
+
events: external_exports.array(sessionEventV2Schema).max(MAX_EVENT_COUNT).readonly(),
|
|
21553
|
+
tailCursor: external_exports.string().max(512),
|
|
21554
|
+
truncated: external_exports.boolean()
|
|
21555
|
+
}).readonly();
|
|
21556
|
+
var nativeSessionEventsV2Schema = external_exports.strictObject({
|
|
21557
|
+
executingPromptRequest: executingPromptRequestEventLogV2Schema.nullable(),
|
|
21558
|
+
history: sessionEventLogPageV2Schema
|
|
21559
|
+
}).readonly();
|
|
21560
|
+
function inputValue(value) {
|
|
21561
|
+
if (typeof value !== "string") {
|
|
21562
|
+
return value;
|
|
21563
|
+
}
|
|
21564
|
+
try {
|
|
21565
|
+
return JSON.parse(value);
|
|
21566
|
+
} catch (cause) {
|
|
21567
|
+
throw new ProtocolMessageError("Session Event Log V2 message is not valid JSON", { cause });
|
|
21568
|
+
}
|
|
21569
|
+
}
|
|
21570
|
+
function decode5(value, schema) {
|
|
21571
|
+
const result = schema.safeParse(inputValue(value));
|
|
21572
|
+
if (!result.success) {
|
|
21573
|
+
throw new ProtocolMessageError("Session Event Log V2 message does not match its schema", {
|
|
21574
|
+
cause: result.error
|
|
21575
|
+
});
|
|
21576
|
+
}
|
|
21577
|
+
return result.data;
|
|
21578
|
+
}
|
|
21579
|
+
function encode4(value, schema) {
|
|
21580
|
+
return JSON.stringify(decode5(value, schema));
|
|
21581
|
+
}
|
|
21582
|
+
var decodeSessionEventV2 = (value) => decode5(value, sessionEventV2Schema);
|
|
21583
|
+
var decodeSessionEventEnvelopeV2 = (value) => decode5(value, sessionEventEnvelopeV2Schema);
|
|
21584
|
+
var encodeSessionEventEnvelopeV2 = (value) => encode4(value, sessionEventEnvelopeV2Schema);
|
|
21585
|
+
var decodeAcpSessionUpdateV2 = (value) => decode5(value, acpSessionUpdateV2Schema);
|
|
21586
|
+
|
|
21210
21587
|
// ../protocol/src/session-events.ts
|
|
21211
21588
|
var SESSION_EVENT_KIND = "session.event";
|
|
21212
21589
|
var SESSION_FORKED_KIND = "session.forked";
|
|
@@ -21224,7 +21601,7 @@ var sessionForkedSchema = external_exports.strictObject({
|
|
|
21224
21601
|
sourceSessionId: identifierStringSchema,
|
|
21225
21602
|
throughCommandId: identifierStringSchema
|
|
21226
21603
|
}).readonly();
|
|
21227
|
-
function
|
|
21604
|
+
function decode6(encoded, schema) {
|
|
21228
21605
|
let value;
|
|
21229
21606
|
try {
|
|
21230
21607
|
value = JSON.parse(encoded);
|
|
@@ -21239,7 +21616,7 @@ function decode5(encoded, schema) {
|
|
|
21239
21616
|
}
|
|
21240
21617
|
return decoded.data;
|
|
21241
21618
|
}
|
|
21242
|
-
var
|
|
21619
|
+
var encode5 = (message, schema) => {
|
|
21243
21620
|
const decoded = schema.safeParse(message);
|
|
21244
21621
|
if (!decoded.success) {
|
|
21245
21622
|
throw new ProtocolMessageError("Message does not match its schema", {
|
|
@@ -21248,15 +21625,15 @@ var encode4 = (message, schema) => {
|
|
|
21248
21625
|
}
|
|
21249
21626
|
return JSON.stringify(decoded.data);
|
|
21250
21627
|
};
|
|
21251
|
-
var decodeSessionEventEnvelope = (encoded) =>
|
|
21252
|
-
var encodeSessionEventEnvelope = (message) =>
|
|
21628
|
+
var decodeSessionEventEnvelope = (encoded) => decode6(encoded, sessionEventEnvelopeSchema);
|
|
21629
|
+
var encodeSessionEventEnvelope = (message) => encode5(message, sessionEventEnvelopeSchema);
|
|
21253
21630
|
function decodeRecordedSessionEvent(encoded) {
|
|
21254
21631
|
const kind = decodeMessageKind(encoded);
|
|
21255
21632
|
switch (kind) {
|
|
21256
21633
|
case SESSION_QUEUE_CHANGED_KIND:
|
|
21257
|
-
return
|
|
21634
|
+
return decode6(encoded, sessionQueueChangedSchema);
|
|
21258
21635
|
case SESSION_FORKED_KIND:
|
|
21259
|
-
return
|
|
21636
|
+
return decode6(encoded, sessionForkedSchema);
|
|
21260
21637
|
case AGENT_ACTIVITY_KIND:
|
|
21261
21638
|
return decodeAgentActivityEvent(encoded);
|
|
21262
21639
|
case AGENT_ACTIVITY_NARRATION_KIND:
|
|
@@ -21300,6 +21677,8 @@ var SESSION_LIVE_HISTORY_LOAD_KIND = "session.live-history.load";
|
|
|
21300
21677
|
var SESSION_LIVE_HISTORY_LOADED_KIND = "session.live-history.loaded";
|
|
21301
21678
|
var SESSION_LIVE_HISTORY_PAGE_LOAD_KIND = "session.live-history.page.load";
|
|
21302
21679
|
var SESSION_LIVE_HISTORY_PAGE_LOADED_KIND = "session.live-history.page.loaded";
|
|
21680
|
+
var SESSION_LIVE_HISTORY_V2_PAGE_LOAD_KIND = "session.live-history.v2.page.load";
|
|
21681
|
+
var SESSION_LIVE_HISTORY_V2_PAGE_LOADED_KIND = "session.live-history.v2.page.loaded";
|
|
21303
21682
|
var directoryIdentifier = external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/);
|
|
21304
21683
|
var sessionLiveHistoryLoadSchema = external_exports.strictObject({
|
|
21305
21684
|
additionalDirectoryIds: external_exports.array(directoryIdentifier).max(16).readonly(),
|
|
@@ -21333,7 +21712,24 @@ var sessionLiveHistoryPageLoadedSchema = external_exports.strictObject({
|
|
|
21333
21712
|
requestId: identifierStringSchema,
|
|
21334
21713
|
sessionId: identifierStringSchema
|
|
21335
21714
|
}).readonly();
|
|
21336
|
-
|
|
21715
|
+
var sessionLiveHistoryV2PageLoadSchema = external_exports.strictObject({
|
|
21716
|
+
additionalDirectoryIds: external_exports.array(directoryIdentifier).max(16).readonly(),
|
|
21717
|
+
agentId: identifierStringSchema,
|
|
21718
|
+
bindingId: identifierStringSchema,
|
|
21719
|
+
cursor: external_exports.string().min(1).max(512).nullable(),
|
|
21720
|
+
directoryId: directoryIdentifier,
|
|
21721
|
+
kind: external_exports.literal(SESSION_LIVE_HISTORY_V2_PAGE_LOAD_KIND),
|
|
21722
|
+
eventLimit: external_exports.number().int().min(1).max(1e4),
|
|
21723
|
+
requestId: identifierStringSchema,
|
|
21724
|
+
sessionId: identifierStringSchema
|
|
21725
|
+
}).readonly();
|
|
21726
|
+
var sessionLiveHistoryV2PageLoadedSchema = external_exports.strictObject({
|
|
21727
|
+
events: nativeSessionEventsV2Schema,
|
|
21728
|
+
kind: external_exports.literal(SESSION_LIVE_HISTORY_V2_PAGE_LOADED_KIND),
|
|
21729
|
+
requestId: identifierStringSchema,
|
|
21730
|
+
sessionId: identifierStringSchema
|
|
21731
|
+
}).readonly();
|
|
21732
|
+
function decode7(schema, encoded) {
|
|
21337
21733
|
try {
|
|
21338
21734
|
const value = JSON.parse(encoded);
|
|
21339
21735
|
return schema.parse(value);
|
|
@@ -21341,14 +21737,18 @@ function decode6(schema, encoded) {
|
|
|
21341
21737
|
throw new ProtocolMessageError("Invalid live Session history message", { cause });
|
|
21342
21738
|
}
|
|
21343
21739
|
}
|
|
21344
|
-
var decodeSessionLiveHistoryLoad = (encoded) =>
|
|
21345
|
-
var decodeSessionLiveHistoryLoaded = (encoded) =>
|
|
21740
|
+
var decodeSessionLiveHistoryLoad = (encoded) => decode7(sessionLiveHistoryLoadSchema, encoded);
|
|
21741
|
+
var decodeSessionLiveHistoryLoaded = (encoded) => decode7(sessionLiveHistoryLoadedSchema, encoded);
|
|
21346
21742
|
var encodeSessionLiveHistoryLoad = (value) => JSON.stringify(sessionLiveHistoryLoadSchema.parse(value));
|
|
21347
21743
|
var encodeSessionLiveHistoryLoaded = (value) => JSON.stringify(sessionLiveHistoryLoadedSchema.parse(value));
|
|
21348
|
-
var decodeSessionLiveHistoryPageLoad = (encoded) =>
|
|
21349
|
-
var decodeSessionLiveHistoryPageLoaded = (encoded) =>
|
|
21744
|
+
var decodeSessionLiveHistoryPageLoad = (encoded) => decode7(sessionLiveHistoryPageLoadSchema, encoded);
|
|
21745
|
+
var decodeSessionLiveHistoryPageLoaded = (encoded) => decode7(sessionLiveHistoryPageLoadedSchema, encoded);
|
|
21350
21746
|
var encodeSessionLiveHistoryPageLoad = (value) => JSON.stringify(sessionLiveHistoryPageLoadSchema.parse(value));
|
|
21351
21747
|
var encodeSessionLiveHistoryPageLoaded = (value) => JSON.stringify(sessionLiveHistoryPageLoadedSchema.parse(value));
|
|
21748
|
+
var decodeSessionLiveHistoryV2PageLoad = (encoded) => decode7(sessionLiveHistoryV2PageLoadSchema, encoded);
|
|
21749
|
+
var decodeSessionLiveHistoryV2PageLoaded = (encoded) => decode7(sessionLiveHistoryV2PageLoadedSchema, encoded);
|
|
21750
|
+
var encodeSessionLiveHistoryV2PageLoad = (value) => JSON.stringify(sessionLiveHistoryV2PageLoadSchema.parse(value));
|
|
21751
|
+
var encodeSessionLiveHistoryV2PageLoaded = (value) => JSON.stringify(sessionLiveHistoryV2PageLoadedSchema.parse(value));
|
|
21352
21752
|
|
|
21353
21753
|
// ../protocol/src/daemon-transport.ts
|
|
21354
21754
|
function defineMessageSignature(kind, encoder, decoder) {
|
|
@@ -21433,6 +21833,11 @@ var serviceToDaemonSignatures = {
|
|
|
21433
21833
|
encodeSessionLiveHistoryPageLoad,
|
|
21434
21834
|
decodeSessionLiveHistoryPageLoad
|
|
21435
21835
|
),
|
|
21836
|
+
[SESSION_LIVE_HISTORY_V2_PAGE_LOAD_KIND]: defineMessageSignature(
|
|
21837
|
+
SESSION_LIVE_HISTORY_V2_PAGE_LOAD_KIND,
|
|
21838
|
+
encodeSessionLiveHistoryV2PageLoad,
|
|
21839
|
+
decodeSessionLiveHistoryV2PageLoad
|
|
21840
|
+
),
|
|
21436
21841
|
[SESSION_PERMISSION_RESPOND_KIND]: defineMessageSignature(
|
|
21437
21842
|
SESSION_PERMISSION_RESPOND_KIND,
|
|
21438
21843
|
encodeSessionPermissionRespondCommand,
|
|
@@ -21548,6 +21953,11 @@ var daemonToServiceSignatures = {
|
|
|
21548
21953
|
encodeSessionEventEnvelope,
|
|
21549
21954
|
decodeSessionEventEnvelope
|
|
21550
21955
|
),
|
|
21956
|
+
[SESSION_EVENT_V2_KIND]: defineMessageSignature(
|
|
21957
|
+
SESSION_EVENT_V2_KIND,
|
|
21958
|
+
encodeSessionEventEnvelopeV2,
|
|
21959
|
+
decodeSessionEventEnvelopeV2
|
|
21960
|
+
),
|
|
21551
21961
|
[SESSION_OPERATION_FAILED_KIND]: defineMessageSignature(
|
|
21552
21962
|
SESSION_OPERATION_FAILED_KIND,
|
|
21553
21963
|
encodeSessionOperationFailedEvent,
|
|
@@ -21563,6 +21973,11 @@ var daemonToServiceSignatures = {
|
|
|
21563
21973
|
encodeSessionLiveHistoryPageLoaded,
|
|
21564
21974
|
decodeSessionLiveHistoryPageLoaded
|
|
21565
21975
|
),
|
|
21976
|
+
[SESSION_LIVE_HISTORY_V2_PAGE_LOADED_KIND]: defineMessageSignature(
|
|
21977
|
+
SESSION_LIVE_HISTORY_V2_PAGE_LOADED_KIND,
|
|
21978
|
+
encodeSessionLiveHistoryV2PageLoaded,
|
|
21979
|
+
decodeSessionLiveHistoryV2PageLoaded
|
|
21980
|
+
),
|
|
21566
21981
|
[SESSION_READY_KIND]: defineMessageSignature(SESSION_READY_KIND, encodeSessionReadyEvent, decodeSessionReadyEvent),
|
|
21567
21982
|
[WORKSPACE_ENTRIES_KIND]: defineMessageSignature(
|
|
21568
21983
|
WORKSPACE_ENTRIES_KIND,
|
|
@@ -26202,9 +26617,9 @@ function comparePrerelease(left, right) {
|
|
|
26202
26617
|
if (left.length === 0 || right.length === 0) {
|
|
26203
26618
|
return left.length === right.length ? 0 : left.length === 0 ? 1 : -1;
|
|
26204
26619
|
}
|
|
26205
|
-
for (let
|
|
26206
|
-
const leftPart = left[
|
|
26207
|
-
const rightPart = right[
|
|
26620
|
+
for (let index2 = 0; index2 < Math.max(left.length, right.length); index2 += 1) {
|
|
26621
|
+
const leftPart = left[index2];
|
|
26622
|
+
const rightPart = right[index2];
|
|
26208
26623
|
if (leftPart === void 0 || rightPart === void 0) {
|
|
26209
26624
|
return leftPart === rightPart ? 0 : leftPart === void 0 ? -1 : 1;
|
|
26210
26625
|
}
|
|
@@ -26229,8 +26644,8 @@ function compareAgentVersions(left, right) {
|
|
|
26229
26644
|
if (parsedLeft === null || parsedRight === null) {
|
|
26230
26645
|
return null;
|
|
26231
26646
|
}
|
|
26232
|
-
for (let
|
|
26233
|
-
const difference = (parsedLeft.core[
|
|
26647
|
+
for (let index2 = 0; index2 < Math.max(parsedLeft.core.length, parsedRight.core.length); index2 += 1) {
|
|
26648
|
+
const difference = (parsedLeft.core[index2] ?? 0) - (parsedRight.core[index2] ?? 0);
|
|
26234
26649
|
if (difference !== 0) {
|
|
26235
26650
|
return Math.sign(difference);
|
|
26236
26651
|
}
|
|
@@ -26717,7 +27132,7 @@ function createDaemonConfig(connection, agents = [], installableAgents = [], loc
|
|
|
26717
27132
|
}
|
|
26718
27133
|
|
|
26719
27134
|
// src/run-daemon.ts
|
|
26720
|
-
import { createHash as
|
|
27135
|
+
import { createHash as createHash6, randomUUID as randomUUID6 } from "node:crypto";
|
|
26721
27136
|
import { join as join17 } from "node:path";
|
|
26722
27137
|
import { styleText } from "node:util";
|
|
26723
27138
|
|
|
@@ -26840,7 +27255,7 @@ function startsWith(bytes, signature, offset = 0) {
|
|
|
26840
27255
|
if (bytes.byteLength < offset + signature.byteLength) {
|
|
26841
27256
|
return false;
|
|
26842
27257
|
}
|
|
26843
|
-
return signature.every((value,
|
|
27258
|
+
return signature.every((value, index2) => bytes[offset + index2] === value);
|
|
26844
27259
|
}
|
|
26845
27260
|
function sniffRasterMime(bytes) {
|
|
26846
27261
|
if (startsWith(bytes, PNG_SIGNATURE)) {
|
|
@@ -26968,7 +27383,7 @@ function startsWith2(bytes, signature, offset = 0) {
|
|
|
26968
27383
|
if (bytes.byteLength < offset + signature.byteLength) {
|
|
26969
27384
|
return false;
|
|
26970
27385
|
}
|
|
26971
|
-
return signature.every((value,
|
|
27386
|
+
return signature.every((value, index2) => bytes[offset + index2] === value);
|
|
26972
27387
|
}
|
|
26973
27388
|
function sniffVideoMime(bytes) {
|
|
26974
27389
|
if (startsWith2(bytes, MP4_FILE_TYPE, 4)) {
|
|
@@ -27097,10 +27512,10 @@ async function replaceImageMarkers(text2, replace) {
|
|
|
27097
27512
|
let cursor = 0;
|
|
27098
27513
|
let rewritten = "";
|
|
27099
27514
|
for (const match of matches) {
|
|
27100
|
-
const
|
|
27101
|
-
rewritten += text2.slice(cursor,
|
|
27515
|
+
const index2 = match.index ?? 0;
|
|
27516
|
+
rewritten += text2.slice(cursor, index2);
|
|
27102
27517
|
rewritten += await replace(match[1] ?? "");
|
|
27103
|
-
cursor =
|
|
27518
|
+
cursor = index2 + match[0].length;
|
|
27104
27519
|
}
|
|
27105
27520
|
return `${rewritten}${text2.slice(cursor)}`;
|
|
27106
27521
|
}
|
|
@@ -28266,6 +28681,7 @@ function sessionConfigProtocolForAgent(_agentId) {
|
|
|
28266
28681
|
|
|
28267
28682
|
// src/acp/session-contracts.ts
|
|
28268
28683
|
var NullAcpSessionObserver = class {
|
|
28684
|
+
onAcpUpdate = (_sessionId, _update) => Promise.resolve();
|
|
28269
28685
|
onCommands = () => Promise.resolve();
|
|
28270
28686
|
onConfig = () => Promise.resolve();
|
|
28271
28687
|
onContent = () => Promise.resolve();
|
|
@@ -28333,6 +28749,7 @@ function historyContentCharacters(messages) {
|
|
|
28333
28749
|
var AcpHistoryReplay = class {
|
|
28334
28750
|
#activities = /* @__PURE__ */ new Map();
|
|
28335
28751
|
#messages = [];
|
|
28752
|
+
#updates = [];
|
|
28336
28753
|
#turnActivityIds = /* @__PURE__ */ new Set();
|
|
28337
28754
|
#activityTracker = new AcpActivityTracker(
|
|
28338
28755
|
async (activity2) => {
|
|
@@ -28354,7 +28771,8 @@ var AcpHistoryReplay = class {
|
|
|
28354
28771
|
#firstMessageIndex = 0;
|
|
28355
28772
|
#characters = 0;
|
|
28356
28773
|
#truncated = false;
|
|
28357
|
-
record = async (update) => {
|
|
28774
|
+
record = async (update, rawUpdate) => {
|
|
28775
|
+
this.#updates.push(rawUpdate);
|
|
28358
28776
|
if (update.sessionUpdate === "agent_thought_chunk") {
|
|
28359
28777
|
if (update.content.type === "text") {
|
|
28360
28778
|
await this.#activityTracker.recordNarrative(
|
|
@@ -28435,6 +28853,20 @@ var AcpHistoryReplay = class {
|
|
|
28435
28853
|
this.#lastMessageId = id;
|
|
28436
28854
|
this.trimMessages();
|
|
28437
28855
|
};
|
|
28856
|
+
eventPage = (eventLimit, cursor) => {
|
|
28857
|
+
const parsedCursor = cursor === null ? this.#updates.length : Number(cursor);
|
|
28858
|
+
if (!Number.isSafeInteger(parsedCursor) || parsedCursor < 0 || parsedCursor > this.#updates.length) {
|
|
28859
|
+
throw new Error("The native event cursor is invalid");
|
|
28860
|
+
}
|
|
28861
|
+
const endUpdate = parsedCursor;
|
|
28862
|
+
const startUpdate = Math.max(0, endUpdate - eventLimit);
|
|
28863
|
+
return {
|
|
28864
|
+
nextCursor: startUpdate === 0 ? null : startUpdate.toString(),
|
|
28865
|
+
startPosition: startUpdate + 1,
|
|
28866
|
+
truncated: startUpdate > 0,
|
|
28867
|
+
updates: this.#updates.slice(startUpdate, endUpdate)
|
|
28868
|
+
};
|
|
28869
|
+
};
|
|
28438
28870
|
snapshot = async () => {
|
|
28439
28871
|
await this.#activityTracker.finish();
|
|
28440
28872
|
const messages = this.#messages.slice(this.#firstMessageIndex).map((message) => {
|
|
@@ -30422,8 +30854,8 @@ function haveSameKeys(left, right) {
|
|
|
30422
30854
|
if (leftKeys.length !== rightKeys.length) {
|
|
30423
30855
|
return false;
|
|
30424
30856
|
}
|
|
30425
|
-
for (const [
|
|
30426
|
-
if (key !== rightKeys[
|
|
30857
|
+
for (const [index2, key] of leftKeys.entries()) {
|
|
30858
|
+
if (key !== rightKeys[index2]) {
|
|
30427
30859
|
return false;
|
|
30428
30860
|
}
|
|
30429
30861
|
}
|
|
@@ -31611,6 +32043,55 @@ var sqliteTable = (name, columns, extraConfig) => {
|
|
|
31611
32043
|
return sqliteTableBase(name, columns, extraConfig);
|
|
31612
32044
|
};
|
|
31613
32045
|
|
|
32046
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6.13_better-sqlite3@12.4.1/node_modules/drizzle-orm/sqlite-core/indexes.js
|
|
32047
|
+
var IndexBuilderOn = class {
|
|
32048
|
+
constructor(name, unique) {
|
|
32049
|
+
this.name = name;
|
|
32050
|
+
this.unique = unique;
|
|
32051
|
+
}
|
|
32052
|
+
static [entityKind] = "SQLiteIndexBuilderOn";
|
|
32053
|
+
on(...columns) {
|
|
32054
|
+
return new IndexBuilder(this.name, columns, this.unique);
|
|
32055
|
+
}
|
|
32056
|
+
};
|
|
32057
|
+
var IndexBuilder = class {
|
|
32058
|
+
static [entityKind] = "SQLiteIndexBuilder";
|
|
32059
|
+
/** @internal */
|
|
32060
|
+
config;
|
|
32061
|
+
constructor(name, columns, unique) {
|
|
32062
|
+
this.config = {
|
|
32063
|
+
name,
|
|
32064
|
+
columns,
|
|
32065
|
+
unique,
|
|
32066
|
+
where: void 0
|
|
32067
|
+
};
|
|
32068
|
+
}
|
|
32069
|
+
/**
|
|
32070
|
+
* Condition for partial index.
|
|
32071
|
+
*/
|
|
32072
|
+
where(condition) {
|
|
32073
|
+
this.config.where = condition;
|
|
32074
|
+
return this;
|
|
32075
|
+
}
|
|
32076
|
+
/** @internal */
|
|
32077
|
+
build(table) {
|
|
32078
|
+
return new Index(this.config, table);
|
|
32079
|
+
}
|
|
32080
|
+
};
|
|
32081
|
+
var Index = class {
|
|
32082
|
+
static [entityKind] = "SQLiteIndex";
|
|
32083
|
+
config;
|
|
32084
|
+
constructor(config2, table) {
|
|
32085
|
+
this.config = { ...config2, table };
|
|
32086
|
+
}
|
|
32087
|
+
};
|
|
32088
|
+
function index(name) {
|
|
32089
|
+
return new IndexBuilderOn(name, false);
|
|
32090
|
+
}
|
|
32091
|
+
function uniqueIndex(name) {
|
|
32092
|
+
return new IndexBuilderOn(name, true);
|
|
32093
|
+
}
|
|
32094
|
+
|
|
31614
32095
|
// ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6.13_better-sqlite3@12.4.1/node_modules/drizzle-orm/sqlite-core/utils.js
|
|
31615
32096
|
function extractUsedTable(table) {
|
|
31616
32097
|
if (is(table, SQLiteTable)) {
|
|
@@ -31959,8 +32440,8 @@ var SQLiteDialect = class {
|
|
|
31959
32440
|
}
|
|
31960
32441
|
const joinsArray = [];
|
|
31961
32442
|
if (joins) {
|
|
31962
|
-
for (const [
|
|
31963
|
-
if (
|
|
32443
|
+
for (const [index2, joinMeta] of joins.entries()) {
|
|
32444
|
+
if (index2 === 0) {
|
|
31964
32445
|
joinsArray.push(sql` `);
|
|
31965
32446
|
}
|
|
31966
32447
|
const table = joinMeta.table;
|
|
@@ -31980,7 +32461,7 @@ var SQLiteDialect = class {
|
|
|
31980
32461
|
sql`${sql.raw(joinMeta.joinType)} join ${table}${onSql}`
|
|
31981
32462
|
);
|
|
31982
32463
|
}
|
|
31983
|
-
if (
|
|
32464
|
+
if (index2 < joins.length - 1) {
|
|
31984
32465
|
joinsArray.push(sql` `);
|
|
31985
32466
|
}
|
|
31986
32467
|
}
|
|
@@ -31993,9 +32474,9 @@ var SQLiteDialect = class {
|
|
|
31993
32474
|
buildOrderBy(orderBy) {
|
|
31994
32475
|
const orderByList = [];
|
|
31995
32476
|
if (orderBy) {
|
|
31996
|
-
for (const [
|
|
32477
|
+
for (const [index2, orderByValue] of orderBy.entries()) {
|
|
31997
32478
|
orderByList.push(orderByValue);
|
|
31998
|
-
if (
|
|
32479
|
+
if (index2 < orderBy.length - 1) {
|
|
31999
32480
|
orderByList.push(sql`, `);
|
|
32000
32481
|
}
|
|
32001
32482
|
}
|
|
@@ -32048,9 +32529,9 @@ var SQLiteDialect = class {
|
|
|
32048
32529
|
const havingSql = having ? sql` having ${having}` : void 0;
|
|
32049
32530
|
const groupByList = [];
|
|
32050
32531
|
if (groupBy) {
|
|
32051
|
-
for (const [
|
|
32532
|
+
for (const [index2, groupByValue] of groupBy.entries()) {
|
|
32052
32533
|
groupByList.push(groupByValue);
|
|
32053
|
-
if (
|
|
32534
|
+
if (index2 < groupBy.length - 1) {
|
|
32054
32535
|
groupByList.push(sql`, `);
|
|
32055
32536
|
}
|
|
32056
32537
|
}
|
|
@@ -34464,6 +34945,10 @@ var acpSessionStoreMigrations = [
|
|
|
34464
34945
|
{
|
|
34465
34946
|
"name": "0001_regular_ultimates.sql",
|
|
34466
34947
|
"sql": "ALTER TABLE `acp_session` ADD `last_terminal_command_id` text;"
|
|
34948
|
+
},
|
|
34949
|
+
{
|
|
34950
|
+
"name": "0002_equal_black_queen.sql",
|
|
34951
|
+
"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`);"
|
|
34467
34952
|
}
|
|
34468
34953
|
];
|
|
34469
34954
|
|
|
@@ -34471,7 +34956,8 @@ var acpSessionStoreMigrations = [
|
|
|
34471
34956
|
var acp_session_store_exports = {};
|
|
34472
34957
|
__export(acp_session_store_exports, {
|
|
34473
34958
|
acpSession: () => acpSession,
|
|
34474
|
-
deletedAcpSession: () => deletedAcpSession
|
|
34959
|
+
deletedAcpSession: () => deletedAcpSession,
|
|
34960
|
+
sessionEventV2: () => sessionEventV2
|
|
34475
34961
|
});
|
|
34476
34962
|
|
|
34477
34963
|
// src/schema/acp-session-store/acp-session.ts
|
|
@@ -34492,6 +34978,21 @@ var deletedAcpSession = sqliteTable("deleted_acp_session", {
|
|
|
34492
34978
|
sessionId: text("session_id").primaryKey()
|
|
34493
34979
|
});
|
|
34494
34980
|
|
|
34981
|
+
// src/schema/acp-session-store/session-event-v2.ts
|
|
34982
|
+
var sessionEventV2 = sqliteTable(
|
|
34983
|
+
"session_event_v2",
|
|
34984
|
+
{
|
|
34985
|
+
eventId: text("event_id").primaryKey(),
|
|
34986
|
+
eventJson: text("event_json").notNull(),
|
|
34987
|
+
position: integer2("position").notNull(),
|
|
34988
|
+
sessionId: text("session_id").notNull()
|
|
34989
|
+
},
|
|
34990
|
+
(table) => [
|
|
34991
|
+
uniqueIndex("session_event_v2_session_position_unique").on(table.sessionId, table.position),
|
|
34992
|
+
index("session_event_v2_session_position_index").on(table.sessionId, table.position)
|
|
34993
|
+
]
|
|
34994
|
+
);
|
|
34995
|
+
|
|
34495
34996
|
// src/acp/session-store.ts
|
|
34496
34997
|
var AcpStoredSession = class {
|
|
34497
34998
|
additionalDirectories;
|
|
@@ -34534,9 +35035,14 @@ var DeletedAcpStoredSession = class extends AcpStoredSessionLookup {
|
|
|
34534
35035
|
var MemoryAcpSessionStore = class {
|
|
34535
35036
|
#sessions = /* @__PURE__ */ new Map();
|
|
34536
35037
|
#deleted = /* @__PURE__ */ new Set();
|
|
35038
|
+
#eventsV2 = /* @__PURE__ */ new Map();
|
|
35039
|
+
appendEventV2 = (event) => {
|
|
35040
|
+
this.#eventsV2.set(event.sessionId, [...this.#eventsV2.get(event.sessionId) ?? [], event]);
|
|
35041
|
+
};
|
|
34537
35042
|
close = () => {
|
|
34538
35043
|
this.#sessions.clear();
|
|
34539
35044
|
this.#deleted.clear();
|
|
35045
|
+
this.#eventsV2.clear();
|
|
34540
35046
|
};
|
|
34541
35047
|
findNative = (agentId, nativeSessionId) => [...this.#sessions.values()].filter(
|
|
34542
35048
|
(session) => session.agentId === agentId && session.nativeSessionId === nativeSessionId
|
|
@@ -34547,6 +35053,7 @@ var MemoryAcpSessionStore = class {
|
|
|
34547
35053
|
for (const id of ids) {
|
|
34548
35054
|
this.#sessions.delete(id);
|
|
34549
35055
|
this.#deleted.add(id);
|
|
35056
|
+
this.#eventsV2.delete(id);
|
|
34550
35057
|
}
|
|
34551
35058
|
return ids;
|
|
34552
35059
|
};
|
|
@@ -34559,7 +35066,9 @@ var MemoryAcpSessionStore = class {
|
|
|
34559
35066
|
};
|
|
34560
35067
|
remove = (sessionId) => {
|
|
34561
35068
|
this.#sessions.delete(sessionId);
|
|
35069
|
+
this.#eventsV2.delete(sessionId);
|
|
34562
35070
|
};
|
|
35071
|
+
readEventsV2 = (sessionId) => this.#eventsV2.get(sessionId) ?? [];
|
|
34563
35072
|
write = (session) => {
|
|
34564
35073
|
this.#sessions.set(session.sessionId, session);
|
|
34565
35074
|
};
|
|
@@ -34608,15 +35117,15 @@ var SqliteAcpSessionStore = class {
|
|
|
34608
35117
|
this.#sqliteDatabase.close();
|
|
34609
35118
|
throw new Error("The ACP Session database was created by a newer Mobius version");
|
|
34610
35119
|
}
|
|
34611
|
-
for (let
|
|
34612
|
-
const migration = acpSessionStoreMigrations[
|
|
35120
|
+
for (let index2 = version3; index2 < acpSessionStoreMigrations.length; index2 += 1) {
|
|
35121
|
+
const migration = acpSessionStoreMigrations[index2];
|
|
34613
35122
|
if (migration === void 0) {
|
|
34614
35123
|
throw new Error("The ACP Session migration is unavailable");
|
|
34615
35124
|
}
|
|
34616
35125
|
this.#sqliteDatabase.exec("BEGIN IMMEDIATE");
|
|
34617
35126
|
try {
|
|
34618
35127
|
this.#sqliteDatabase.exec(migration.sql);
|
|
34619
|
-
this.#sqliteDatabase.pragma(`user_version = ${
|
|
35128
|
+
this.#sqliteDatabase.pragma(`user_version = ${index2 + 1}`);
|
|
34620
35129
|
this.#sqliteDatabase.exec("COMMIT");
|
|
34621
35130
|
} catch (error62) {
|
|
34622
35131
|
this.#sqliteDatabase.exec("ROLLBACK");
|
|
@@ -34627,6 +35136,14 @@ var SqliteAcpSessionStore = class {
|
|
|
34627
35136
|
close = () => {
|
|
34628
35137
|
this.#sqliteDatabase.close();
|
|
34629
35138
|
};
|
|
35139
|
+
appendEventV2 = (event) => {
|
|
35140
|
+
this.#database.insert(sessionEventV2).values({
|
|
35141
|
+
eventId: event.eventId,
|
|
35142
|
+
eventJson: JSON.stringify(event),
|
|
35143
|
+
position: Number(event.position),
|
|
35144
|
+
sessionId: event.sessionId
|
|
35145
|
+
}).run();
|
|
35146
|
+
};
|
|
34630
35147
|
findNative = (agentId, nativeSessionId) => this.#database.select().from(acpSession).where(and(eq(acpSession.agentId, agentId), eq(acpSession.nativeSessionId, nativeSessionId))).all().map(decodeStoredSession);
|
|
34631
35148
|
list = () => this.#database.select().from(acpSession).orderBy(desc(acpSession.updatedAt)).all().map(decodeStoredSession);
|
|
34632
35149
|
markDeleted = (agentId, nativeSessionId) => {
|
|
@@ -34635,6 +35152,7 @@ var SqliteAcpSessionStore = class {
|
|
|
34635
35152
|
transaction.delete(acpSession).where(and(eq(acpSession.agentId, agentId), eq(acpSession.nativeSessionId, nativeSessionId))).run();
|
|
34636
35153
|
for (const id of ids) {
|
|
34637
35154
|
transaction.insert(deletedAcpSession).values({ sessionId: id }).onConflictDoNothing().run();
|
|
35155
|
+
transaction.delete(sessionEventV2).where(eq(sessionEventV2.sessionId, id)).run();
|
|
34638
35156
|
}
|
|
34639
35157
|
});
|
|
34640
35158
|
return ids;
|
|
@@ -34648,8 +35166,12 @@ var SqliteAcpSessionStore = class {
|
|
|
34648
35166
|
const row = this.#database.select().from(acpSession).where(eq(acpSession.sessionId, sessionId)).get();
|
|
34649
35167
|
return row === void 0 ? new MissingAcpStoredSession() : new FoundAcpStoredSession(decodeStoredSession(row));
|
|
34650
35168
|
};
|
|
35169
|
+
readEventsV2 = (sessionId) => this.#database.select({ eventJson: sessionEventV2.eventJson }).from(sessionEventV2).where(eq(sessionEventV2.sessionId, sessionId)).orderBy(asc(sessionEventV2.position)).all().map((row) => decodeSessionEventV2(row.eventJson));
|
|
34651
35170
|
remove = (sessionId) => {
|
|
34652
|
-
this.#database.
|
|
35171
|
+
this.#database.transaction((transaction) => {
|
|
35172
|
+
transaction.delete(acpSession).where(eq(acpSession.sessionId, sessionId)).run();
|
|
35173
|
+
transaction.delete(sessionEventV2).where(eq(sessionEventV2.sessionId, sessionId)).run();
|
|
35174
|
+
});
|
|
34653
35175
|
};
|
|
34654
35176
|
write = (session) => {
|
|
34655
35177
|
const value = {
|
|
@@ -34682,7 +35204,7 @@ var RetryableAcpInitializationError = class extends AcpExecutionError {
|
|
|
34682
35204
|
}
|
|
34683
35205
|
};
|
|
34684
35206
|
function arraysEqual(left, right) {
|
|
34685
|
-
return left.length === right.length && left.every((value,
|
|
35207
|
+
return left.length === right.length && left.every((value, index2) => value === right[index2]);
|
|
34686
35208
|
}
|
|
34687
35209
|
function recordsEqual(left, right) {
|
|
34688
35210
|
const leftEntries = Object.entries(left);
|
|
@@ -34829,6 +35351,17 @@ var AgentSession = class _AgentSession {
|
|
|
34829
35351
|
const loaded = await this.#loadSession(signal, "ACP agent exited while loading history");
|
|
34830
35352
|
return await embedLocalHistoryImages(await loaded.history.snapshot(), signal);
|
|
34831
35353
|
};
|
|
35354
|
+
loadHistoryEventsV2 = async (eventLimit, cursor, signal) => {
|
|
35355
|
+
if (!this.#capabilities.loadSession) {
|
|
35356
|
+
throw new AcpExecutionError(
|
|
35357
|
+
"This Agent restores context but does not provide message history.",
|
|
35358
|
+
{},
|
|
35359
|
+
"native_history_unsupported"
|
|
35360
|
+
);
|
|
35361
|
+
}
|
|
35362
|
+
const loaded = await this.#loadSession(signal, "ACP agent exited while loading history");
|
|
35363
|
+
return loaded.history.eventPage(eventLimit, cursor);
|
|
35364
|
+
};
|
|
34832
35365
|
async #loadSession(signal, exitMessage) {
|
|
34833
35366
|
if (this.#sessionLoad.kind === "loaded") {
|
|
34834
35367
|
return this.#sessionLoad;
|
|
@@ -35475,8 +36008,14 @@ var AgentSession = class _AgentSession {
|
|
|
35475
36008
|
#processUpdate = async (notification) => {
|
|
35476
36009
|
this.assertNativeSession(notification.sessionId);
|
|
35477
36010
|
const update = notification.update;
|
|
36011
|
+
const rawUpdate = decodeAcpSessionUpdateV2(JSON.stringify(update));
|
|
35478
36012
|
if (this.#sessionLoad.kind !== "not-requested") {
|
|
35479
|
-
await this.#sessionLoad.history.record(update);
|
|
36013
|
+
await this.#sessionLoad.history.record(update, rawUpdate);
|
|
36014
|
+
} else {
|
|
36015
|
+
const onAcpUpdate = this.#getObserver().onAcpUpdate;
|
|
36016
|
+
if (onAcpUpdate !== void 0) {
|
|
36017
|
+
await onAcpUpdate(this.#mobiusSessionId, rawUpdate);
|
|
36018
|
+
}
|
|
35480
36019
|
}
|
|
35481
36020
|
if (this.#sessionLoad.kind === "capturing" && (update.sessionUpdate === "user_message_chunk" || update.sessionUpdate === "agent_message_chunk" || update.sessionUpdate === "agent_thought_chunk" || update.sessionUpdate === "tool_call" || update.sessionUpdate === "tool_call_update" || update.sessionUpdate === "plan" || update.sessionUpdate === "plan_update" || update.sessionUpdate === "plan_removed")) {
|
|
35482
36021
|
return;
|
|
@@ -35858,6 +36397,21 @@ var AgentQueryProcesses = class {
|
|
|
35858
36397
|
async (runtime) => await runtime.closeProcess()
|
|
35859
36398
|
);
|
|
35860
36399
|
};
|
|
36400
|
+
previewEventsV2 = async (options, nativeSessionId, eventLimit, cursor) => {
|
|
36401
|
+
return await this.#processes.runTransient(
|
|
36402
|
+
options.signal,
|
|
36403
|
+
async () => await AgentSession.startNativeSessionBrowser(
|
|
36404
|
+
options,
|
|
36405
|
+
() => this.#observer,
|
|
36406
|
+
new MemoryAcpSessionStore()
|
|
36407
|
+
),
|
|
36408
|
+
async (runtime) => {
|
|
36409
|
+
runtime.selectNativeSession(nativeSessionId);
|
|
36410
|
+
return await runtime.loadHistoryEventsV2(eventLimit, cursor, options.signal);
|
|
36411
|
+
},
|
|
36412
|
+
async (runtime) => await runtime.closeProcess()
|
|
36413
|
+
);
|
|
36414
|
+
};
|
|
35861
36415
|
close = async () => {
|
|
35862
36416
|
await Promise.all(
|
|
35863
36417
|
this.#processesByQuery.entries().map(async ([id, runtime]) => await this.retire(id, runtime))
|
|
@@ -35927,9 +36481,9 @@ var AcpProcessCapacityLock = class {
|
|
|
35927
36481
|
return await waiter.completion.promise;
|
|
35928
36482
|
} finally {
|
|
35929
36483
|
signal.removeEventListener("abort", waiter.cancel);
|
|
35930
|
-
const
|
|
35931
|
-
if (
|
|
35932
|
-
this.#waiters.splice(
|
|
36484
|
+
const index2 = this.#waiters.indexOf(waiter);
|
|
36485
|
+
if (index2 >= 0) {
|
|
36486
|
+
this.#waiters.splice(index2, 1);
|
|
35933
36487
|
}
|
|
35934
36488
|
}
|
|
35935
36489
|
};
|
|
@@ -36559,6 +37113,22 @@ var AgentRuntimeManager = class {
|
|
|
36559
37113
|
this.#nativeOperations.delete(key);
|
|
36560
37114
|
}
|
|
36561
37115
|
});
|
|
37116
|
+
previewNativeSessionEventsV2 = async (options, nativeSessionId, eventLimit, cursor) => this.#operations.run(options, async (options2) => {
|
|
37117
|
+
const key = `${options2.agent.id}:${nativeSessionId}`;
|
|
37118
|
+
if (this.#nativeOperations.has(key)) {
|
|
37119
|
+
throw new AcpExecutionError(
|
|
37120
|
+
"Wait for the native session's running operation to finish",
|
|
37121
|
+
{},
|
|
37122
|
+
"session_busy"
|
|
37123
|
+
);
|
|
37124
|
+
}
|
|
37125
|
+
this.#nativeOperations.add(key);
|
|
37126
|
+
try {
|
|
37127
|
+
return await this.#queryProcesses.previewEventsV2(options2, nativeSessionId, eventLimit, cursor);
|
|
37128
|
+
} finally {
|
|
37129
|
+
this.#nativeOperations.delete(key);
|
|
37130
|
+
}
|
|
37131
|
+
});
|
|
36562
37132
|
loadSessionHistory = async (options) => this.#operations.run(options, async (options2) => {
|
|
36563
37133
|
return await this.#executionProcesses.use(options2.sessionId, async () => {
|
|
36564
37134
|
const runtime = await this.ensureSession(options2);
|
|
@@ -36576,6 +37146,12 @@ var AgentRuntimeManager = class {
|
|
|
36576
37146
|
return await runtime.loadHistory(options2.signal);
|
|
36577
37147
|
});
|
|
36578
37148
|
});
|
|
37149
|
+
loadSessionEventsV2 = async (options, eventLimit, cursor) => this.#operations.run(options, async (options2) => {
|
|
37150
|
+
return await this.#executionProcesses.use(options2.sessionId, async () => {
|
|
37151
|
+
const runtime = await this.ensureSession(options2);
|
|
37152
|
+
return await runtime.loadHistoryEventsV2(eventLimit, cursor, options2.signal);
|
|
37153
|
+
});
|
|
37154
|
+
});
|
|
36579
37155
|
openNativeSession = async (options, origin) => this.#operations.run(options, async (options2) => {
|
|
36580
37156
|
const key = `${options2.agent.id}:${origin.nativeSessionId}`;
|
|
36581
37157
|
if (this.#nativeOperations.has(key)) {
|
|
@@ -37778,9 +38354,15 @@ function reportOperationFailure(socket, requestId, sessionId, error62, runtimeTi
|
|
|
37778
38354
|
// src/daemon-observers.ts
|
|
37779
38355
|
var DaemonAcpObserver = class {
|
|
37780
38356
|
#record;
|
|
37781
|
-
|
|
38357
|
+
#recordV2;
|
|
38358
|
+
constructor(record2, recordV2 = () => void 0) {
|
|
37782
38359
|
this.#record = record2;
|
|
38360
|
+
this.#recordV2 = recordV2;
|
|
37783
38361
|
}
|
|
38362
|
+
onAcpUpdate = (sessionId, update) => {
|
|
38363
|
+
this.#recordV2(sessionId, update);
|
|
38364
|
+
return Promise.resolve();
|
|
38365
|
+
};
|
|
37784
38366
|
onCommands = (event) => {
|
|
37785
38367
|
this.#record(event.sessionId, event);
|
|
37786
38368
|
return Promise.resolve();
|
|
@@ -37917,8 +38499,8 @@ var ACTIVE_TURN_TEXT_CHUNK_LIMIT = Math.floor(SESSION_HISTORY_CHARACTER_LIMIT /
|
|
|
37917
38499
|
function boundedRecoveryMessages(messages) {
|
|
37918
38500
|
const selected = [];
|
|
37919
38501
|
let remainingCharacters = SESSION_HISTORY_CHARACTER_LIMIT;
|
|
37920
|
-
for (let
|
|
37921
|
-
const message = messages[
|
|
38502
|
+
for (let index2 = messages.length - 1; index2 >= 0 && selected.length < SESSION_HISTORY_MESSAGE_LIMIT; index2 -= 1) {
|
|
38503
|
+
const message = messages[index2];
|
|
37922
38504
|
if (message === void 0) {
|
|
37923
38505
|
break;
|
|
37924
38506
|
}
|
|
@@ -38059,7 +38641,7 @@ var ActiveDaemonTurn = class {
|
|
|
38059
38641
|
];
|
|
38060
38642
|
} else {
|
|
38061
38643
|
this.#timeline = this.#timeline.map(
|
|
38062
|
-
(entry,
|
|
38644
|
+
(entry, index2) => index2 === target && entry.kind === "message" ? { ...entry, content: new Map([...entry.content, [event.contentId, event.content]]) } : entry
|
|
38063
38645
|
);
|
|
38064
38646
|
}
|
|
38065
38647
|
} else if (event.kind === SESSION_PERMISSION_REQUESTED_KIND || event.kind === SESSION_ELICITATION_REQUESTED_KIND) {
|
|
@@ -39070,7 +39652,7 @@ async function readAcpHistory(sessions, directories, bindingId, options, nativeS
|
|
|
39070
39652
|
async (directory) => await directories.identify(bindingId, directory, options.signal)
|
|
39071
39653
|
)
|
|
39072
39654
|
);
|
|
39073
|
-
if (primary.path !== options.cwd || additional.length !== options.additionalDirectories.length || additional.some((directory,
|
|
39655
|
+
if (primary.path !== options.cwd || additional.length !== options.additionalDirectories.length || additional.some((directory, index2) => directory.path !== options.additionalDirectories[index2])) {
|
|
39074
39656
|
throw new AcpExecutionError(
|
|
39075
39657
|
"The native Session belongs to another workspace.",
|
|
39076
39658
|
{},
|
|
@@ -39203,7 +39785,7 @@ var NativeSessionService = class {
|
|
|
39203
39785
|
"native_session_not_found"
|
|
39204
39786
|
);
|
|
39205
39787
|
}
|
|
39206
|
-
if (source.agentId !== command.agentId || source.cwd !== cwd || source.additionalDirectories.length !== additionalDirectories.length || source.additionalDirectories.some((path2,
|
|
39788
|
+
if (source.agentId !== command.agentId || source.cwd !== cwd || source.additionalDirectories.length !== additionalDirectories.length || source.additionalDirectories.some((path2, index2) => path2 !== additionalDirectories[index2])) {
|
|
39207
39789
|
throw new AcpExecutionError(
|
|
39208
39790
|
"The source conversation execution target does not match the fork request",
|
|
39209
39791
|
{},
|
|
@@ -39224,8 +39806,8 @@ var NativeSessionService = class {
|
|
|
39224
39806
|
signal.throwIfAborted();
|
|
39225
39807
|
const directory = await this.#directories.list(this.#config.bindingId, command.directoryId, signal);
|
|
39226
39808
|
const ready2 = {
|
|
39227
|
-
additionalDirectories: additionalDirectories.map((path2,
|
|
39228
|
-
directoryId: command.additionalDirectoryIds[
|
|
39809
|
+
additionalDirectories: additionalDirectories.map((path2, index2) => ({
|
|
39810
|
+
directoryId: command.additionalDirectoryIds[index2] ?? command.directoryId,
|
|
39229
39811
|
name: basename4(path2) || path2
|
|
39230
39812
|
})),
|
|
39231
39813
|
agentId: command.agentId,
|
|
@@ -39557,7 +40139,7 @@ var NativeSessionService = class {
|
|
|
39557
40139
|
resolveTarget = async (command, options, selected) => {
|
|
39558
40140
|
let cursor = null;
|
|
39559
40141
|
const visited = /* @__PURE__ */ new Set();
|
|
39560
|
-
for (let
|
|
40142
|
+
for (let index2 = 0; index2 < 100; index2 += 1) {
|
|
39561
40143
|
const page = await this.#sessions.listNativeSessions(options, cursor);
|
|
39562
40144
|
const info = page.sessions.find((entry) => entry.sessionId === selected.nativeSessionId);
|
|
39563
40145
|
if (info !== void 0) {
|
|
@@ -39565,7 +40147,7 @@ var NativeSessionService = class {
|
|
|
39565
40147
|
if (target === null) {
|
|
39566
40148
|
throw new LocalAuthorizationError("The selected native session is not authorized");
|
|
39567
40149
|
}
|
|
39568
|
-
if (target.cwd !== selected.cwd || target.additionalDirectories.length !== selected.additionalDirectories.length || target.additionalDirectories.some((path2,
|
|
40150
|
+
if (target.cwd !== selected.cwd || target.additionalDirectories.length !== selected.additionalDirectories.length || target.additionalDirectories.some((path2, index3) => path2 !== selected.additionalDirectories[index3])) {
|
|
39569
40151
|
throw new AcpExecutionError(
|
|
39570
40152
|
"This session's directory changed. Refresh the list before continuing.",
|
|
39571
40153
|
{},
|
|
@@ -40653,6 +41235,9 @@ async function streamLocalFile(command, send2, signal, workingDirectory) {
|
|
|
40653
41235
|
});
|
|
40654
41236
|
}
|
|
40655
41237
|
|
|
41238
|
+
// src/daemon-history-commands.ts
|
|
41239
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
41240
|
+
|
|
40656
41241
|
// src/authorization/resolve-session-directories.ts
|
|
40657
41242
|
import { basename as basename6 } from "node:path";
|
|
40658
41243
|
var ResolvedSessionDirectories = class {
|
|
@@ -40752,8 +41337,8 @@ function selectMessagesBefore(messages, endIndex, messageLimit, characterLimit)
|
|
|
40752
41337
|
const selected = [];
|
|
40753
41338
|
let remainingCharacters = characterLimit;
|
|
40754
41339
|
let startIndex = endIndex;
|
|
40755
|
-
for (let
|
|
40756
|
-
const message = messages[
|
|
41340
|
+
for (let index2 = endIndex - 1; index2 >= 0 && selected.length < messageLimit; index2 -= 1) {
|
|
41341
|
+
const message = messages[index2];
|
|
40757
41342
|
if (message === void 0) {
|
|
40758
41343
|
break;
|
|
40759
41344
|
}
|
|
@@ -40763,7 +41348,7 @@ function selectMessagesBefore(messages, endIndex, messageLimit, characterLimit)
|
|
|
40763
41348
|
}
|
|
40764
41349
|
selected.unshift(message);
|
|
40765
41350
|
remainingCharacters -= characters;
|
|
40766
|
-
startIndex =
|
|
41351
|
+
startIndex = index2;
|
|
40767
41352
|
}
|
|
40768
41353
|
if (selected.length === 0 && endIndex > 0) {
|
|
40769
41354
|
throw new AcpExecutionError(
|
|
@@ -41043,6 +41628,79 @@ async function executeSessionLiveHistoryPageLoad(socket, command, config2, direc
|
|
|
41043
41628
|
});
|
|
41044
41629
|
}
|
|
41045
41630
|
}
|
|
41631
|
+
function replayEvent(sessionId, position, update) {
|
|
41632
|
+
const encoded = JSON.stringify(update);
|
|
41633
|
+
const eventId = `native-${createHash5("sha256").update(sessionId).update(":").update(position.toString()).update(":").update(encoded).digest("hex")}`;
|
|
41634
|
+
return {
|
|
41635
|
+
eventId,
|
|
41636
|
+
payload: { kind: "acp.session.update", update },
|
|
41637
|
+
position: position.toString(),
|
|
41638
|
+
provenance: { kind: "original" },
|
|
41639
|
+
recordedAt: "1970-01-01T00:00:00.000Z",
|
|
41640
|
+
sessionId
|
|
41641
|
+
};
|
|
41642
|
+
}
|
|
41643
|
+
async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, directories, audit, sessions, localRecovery, executingPromptRequest, signal) {
|
|
41644
|
+
try {
|
|
41645
|
+
const local = localRecovery(command.sessionId, command.eventLimit, command.cursor);
|
|
41646
|
+
if (local !== null) {
|
|
41647
|
+
send(socket, {
|
|
41648
|
+
events: local,
|
|
41649
|
+
kind: "session.live-history.v2.page.loaded",
|
|
41650
|
+
requestId: command.requestId,
|
|
41651
|
+
sessionId: command.sessionId
|
|
41652
|
+
});
|
|
41653
|
+
return;
|
|
41654
|
+
}
|
|
41655
|
+
const resolved = await resolveSessionDirectories(
|
|
41656
|
+
directories,
|
|
41657
|
+
config2.bindingId,
|
|
41658
|
+
command.directoryId,
|
|
41659
|
+
command.additionalDirectoryIds,
|
|
41660
|
+
signal
|
|
41661
|
+
);
|
|
41662
|
+
const replay = await sessions.loadSessionEventsV2(
|
|
41663
|
+
{
|
|
41664
|
+
additionalDirectories: resolved.additionalDirectories,
|
|
41665
|
+
agent: config2.catalog.find(command.agentId),
|
|
41666
|
+
cwd: resolved.cwd,
|
|
41667
|
+
sessionId: command.sessionId,
|
|
41668
|
+
signal
|
|
41669
|
+
},
|
|
41670
|
+
command.eventLimit,
|
|
41671
|
+
command.cursor
|
|
41672
|
+
);
|
|
41673
|
+
signal.throwIfAborted();
|
|
41674
|
+
const events = replay.updates.map(
|
|
41675
|
+
(update, index2) => replayEvent(command.sessionId, replay.startPosition + index2, update)
|
|
41676
|
+
);
|
|
41677
|
+
const tailCursor = events.at(-1)?.eventId ?? "";
|
|
41678
|
+
audit.record({
|
|
41679
|
+
commandId: command.requestId,
|
|
41680
|
+
event: "session_event_log_v2_loaded",
|
|
41681
|
+
sessionId: command.sessionId
|
|
41682
|
+
});
|
|
41683
|
+
send(socket, {
|
|
41684
|
+
events: {
|
|
41685
|
+
executingPromptRequest: executingPromptRequest(command.sessionId),
|
|
41686
|
+
history: {
|
|
41687
|
+
events,
|
|
41688
|
+
nextCursor: replay.nextCursor,
|
|
41689
|
+
tailCursor,
|
|
41690
|
+
truncated: replay.truncated,
|
|
41691
|
+
version: 2
|
|
41692
|
+
}
|
|
41693
|
+
},
|
|
41694
|
+
kind: "session.live-history.v2.page.loaded",
|
|
41695
|
+
requestId: command.requestId,
|
|
41696
|
+
sessionId: command.sessionId
|
|
41697
|
+
});
|
|
41698
|
+
} catch (error62) {
|
|
41699
|
+
if (!signal.aborted) {
|
|
41700
|
+
reportOperationFailure(socket, command.requestId, command.sessionId, error62);
|
|
41701
|
+
}
|
|
41702
|
+
}
|
|
41703
|
+
}
|
|
41046
41704
|
|
|
41047
41705
|
// src/acp/session-config/apply-session-configuration.ts
|
|
41048
41706
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
@@ -41357,6 +42015,7 @@ function daemonActivity(command, activity2) {
|
|
|
41357
42015
|
async function executePrompt({
|
|
41358
42016
|
operations,
|
|
41359
42017
|
publisher,
|
|
42018
|
+
eventLogV2,
|
|
41360
42019
|
command,
|
|
41361
42020
|
config: config2,
|
|
41362
42021
|
directories,
|
|
@@ -41461,6 +42120,7 @@ async function executePrompt({
|
|
|
41461
42120
|
}
|
|
41462
42121
|
}
|
|
41463
42122
|
const stream = activateAttempt();
|
|
42123
|
+
eventLogV2.started(command.sessionId, command.commandId, attemptId, stream.epoch);
|
|
41464
42124
|
if (!prepared.prompted) {
|
|
41465
42125
|
const listing = await directories.list(config2.bindingId, command.directoryId, signal);
|
|
41466
42126
|
publisher.publish(command.sessionId, {
|
|
@@ -41530,6 +42190,7 @@ async function executePrompt({
|
|
|
41530
42190
|
sessionId: command.sessionId,
|
|
41531
42191
|
stopReason
|
|
41532
42192
|
});
|
|
42193
|
+
eventLogV2.completed(command.sessionId, command.commandId, stopReason);
|
|
41533
42194
|
operations.transitionExecution(command.commandId, stopReason === "cancelled" ? "cancelled" : "succeeded");
|
|
41534
42195
|
audit.record({
|
|
41535
42196
|
commandId: command.commandId,
|
|
@@ -41545,6 +42206,7 @@ async function executePrompt({
|
|
|
41545
42206
|
sessionId: command.sessionId,
|
|
41546
42207
|
stopReason: "cancelled"
|
|
41547
42208
|
});
|
|
42209
|
+
eventLogV2.completed(command.sessionId, command.commandId, "cancelled");
|
|
41548
42210
|
operations.transitionExecution(command.commandId, "cancelled");
|
|
41549
42211
|
audit.record({
|
|
41550
42212
|
commandId: command.commandId,
|
|
@@ -41559,12 +42221,10 @@ async function executePrompt({
|
|
|
41559
42221
|
sessionId: command.sessionId
|
|
41560
42222
|
});
|
|
41561
42223
|
const code = operationErrorCode(error62);
|
|
41562
|
-
|
|
41563
|
-
|
|
41564
|
-
|
|
41565
|
-
|
|
41566
|
-
code === "session_operation_failed" ? "The local agent could not complete the request" : operationErrorMessage(error62)
|
|
41567
|
-
);
|
|
42224
|
+
const failureCode = code === "session_operation_failed" ? "agent_execution_failed" : code;
|
|
42225
|
+
const failureMessage = code === "session_operation_failed" ? "The local agent could not complete the request" : operationErrorMessage(error62);
|
|
42226
|
+
eventLogV2.failed(command.sessionId, command.commandId, failureCode, failureMessage);
|
|
42227
|
+
reportFailure(publisher, command, failureCode, failureMessage);
|
|
41568
42228
|
operations.transitionExecution(command.commandId, "failed");
|
|
41569
42229
|
console.error("Mobius daemon command failed", error62);
|
|
41570
42230
|
}
|
|
@@ -41847,6 +42507,7 @@ function createDaemonCommandHandler({
|
|
|
41847
42507
|
nativeSessions,
|
|
41848
42508
|
operations,
|
|
41849
42509
|
publisher,
|
|
42510
|
+
eventLogV2,
|
|
41850
42511
|
activeTurns,
|
|
41851
42512
|
diagnostics,
|
|
41852
42513
|
socket,
|
|
@@ -41916,6 +42577,20 @@ function createDaemonCommandHandler({
|
|
|
41916
42577
|
);
|
|
41917
42578
|
return;
|
|
41918
42579
|
}
|
|
42580
|
+
if (kind === SESSION_LIVE_HISTORY_V2_PAGE_LOAD_KIND) {
|
|
42581
|
+
void executeSessionLiveHistoryV2PageLoad(
|
|
42582
|
+
socket,
|
|
42583
|
+
message,
|
|
42584
|
+
config2,
|
|
42585
|
+
directories,
|
|
42586
|
+
audit,
|
|
42587
|
+
sessions,
|
|
42588
|
+
eventLogV2.recovery,
|
|
42589
|
+
eventLogV2.executingPromptRequest,
|
|
42590
|
+
signal
|
|
42591
|
+
);
|
|
42592
|
+
return;
|
|
42593
|
+
}
|
|
41919
42594
|
if (kind === NATIVE_SESSION_CANCEL_KIND) {
|
|
41920
42595
|
nativeRequestHandler.cancel(message);
|
|
41921
42596
|
return;
|
|
@@ -42101,9 +42776,11 @@ function createDaemonCommandHandler({
|
|
|
42101
42776
|
return;
|
|
42102
42777
|
}
|
|
42103
42778
|
const turn = activeTurns.start(command, receipt.attemptId);
|
|
42779
|
+
eventLogV2.requested(command);
|
|
42104
42780
|
void executePrompt({
|
|
42105
42781
|
operations,
|
|
42106
42782
|
publisher,
|
|
42783
|
+
eventLogV2,
|
|
42107
42784
|
command,
|
|
42108
42785
|
config: config2,
|
|
42109
42786
|
directories,
|
|
@@ -42393,6 +43070,7 @@ async function runRelayConnection({
|
|
|
42393
43070
|
nativeSessions,
|
|
42394
43071
|
operations,
|
|
42395
43072
|
publisher,
|
|
43073
|
+
eventLogV2,
|
|
42396
43074
|
activeTurns,
|
|
42397
43075
|
connectionEpoch,
|
|
42398
43076
|
diagnostics,
|
|
@@ -42415,6 +43093,7 @@ async function runRelayConnection({
|
|
|
42415
43093
|
nativeSessions,
|
|
42416
43094
|
operations,
|
|
42417
43095
|
publisher,
|
|
43096
|
+
eventLogV2,
|
|
42418
43097
|
activeTurns,
|
|
42419
43098
|
diagnostics,
|
|
42420
43099
|
socket,
|
|
@@ -42594,6 +43273,21 @@ var DaemonSessionEventPublisher = class {
|
|
|
42594
43273
|
this.publish(sessionId, event);
|
|
42595
43274
|
}
|
|
42596
43275
|
};
|
|
43276
|
+
publishV2 = (event) => {
|
|
43277
|
+
const socket = this.#socket;
|
|
43278
|
+
if (socket === null || socket.readyState !== WebSocket9.OPEN) {
|
|
43279
|
+
return;
|
|
43280
|
+
}
|
|
43281
|
+
const encoded = encodeDaemonToServiceMessage({ event, kind: SESSION_EVENT_V2_KIND });
|
|
43282
|
+
if (socket.bufferedAmount + Buffer.byteLength(encoded, "utf8") > MAX_BUFFERED_BYTES) {
|
|
43283
|
+
socket.close(1013, "Live event transport overloaded");
|
|
43284
|
+
return;
|
|
43285
|
+
}
|
|
43286
|
+
try {
|
|
43287
|
+
socket.send(encoded);
|
|
43288
|
+
} catch {
|
|
43289
|
+
}
|
|
43290
|
+
};
|
|
42597
43291
|
};
|
|
42598
43292
|
|
|
42599
43293
|
// src/relay-connection/timer.ts
|
|
@@ -42605,6 +43299,241 @@ var SystemDaemonTimer = class {
|
|
|
42605
43299
|
};
|
|
42606
43300
|
var systemDaemonTimer = new SystemDaemonTimer();
|
|
42607
43301
|
|
|
43302
|
+
// src/session-event-log-v2.ts
|
|
43303
|
+
var EXECUTING_PROMPT_EVENT_LIMIT = 1e4;
|
|
43304
|
+
function promptContent(command) {
|
|
43305
|
+
const content = [];
|
|
43306
|
+
if (command.prompt.length > 0) {
|
|
43307
|
+
content.push({ text: command.prompt, type: "text" });
|
|
43308
|
+
}
|
|
43309
|
+
for (const image of command.images) {
|
|
43310
|
+
content.push({
|
|
43311
|
+
_meta: { mobius: { name: image.name } },
|
|
43312
|
+
data: image.data,
|
|
43313
|
+
mimeType: image.mimeType,
|
|
43314
|
+
type: "image"
|
|
43315
|
+
});
|
|
43316
|
+
}
|
|
43317
|
+
for (const resource of command.resources) {
|
|
43318
|
+
content.push(
|
|
43319
|
+
resource.type === "embedded" ? {
|
|
43320
|
+
resource: { mimeType: resource.mimeType, text: resource.text, uri: resource.uri },
|
|
43321
|
+
type: "resource"
|
|
43322
|
+
} : { mimeType: resource.mimeType, name: resource.name, type: "resource_link", uri: resource.uri }
|
|
43323
|
+
);
|
|
43324
|
+
}
|
|
43325
|
+
return content;
|
|
43326
|
+
}
|
|
43327
|
+
function encodeLocalEventCursor(cursor) {
|
|
43328
|
+
return Buffer.from(JSON.stringify(cursor), "utf8").toString("base64url");
|
|
43329
|
+
}
|
|
43330
|
+
function decodeLocalEventCursor(sessionId, cursor) {
|
|
43331
|
+
try {
|
|
43332
|
+
const value = JSON.parse(Buffer.from(cursor, "base64url").toString("utf8"));
|
|
43333
|
+
if (typeof value !== "object" || value === null || Array.isArray(value) || Object.keys(value).sort().join(",") !== "endEvent,sessionId" || Reflect.get(value, "sessionId") !== sessionId) {
|
|
43334
|
+
throw new Error("Invalid V2 event cursor target");
|
|
43335
|
+
}
|
|
43336
|
+
const endEvent = Reflect.get(value, "endEvent");
|
|
43337
|
+
if (typeof endEvent !== "number" || !Number.isSafeInteger(endEvent) || endEvent < 0) {
|
|
43338
|
+
throw new Error("Invalid V2 event cursor boundary");
|
|
43339
|
+
}
|
|
43340
|
+
return { endEvent, sessionId };
|
|
43341
|
+
} catch (cause) {
|
|
43342
|
+
throw new AcpExecutionError("The native Session event cursor is invalid", { cause }, "invalid_cursor");
|
|
43343
|
+
}
|
|
43344
|
+
}
|
|
43345
|
+
var DaemonSessionEventLogV2 = class {
|
|
43346
|
+
#positions = /* @__PURE__ */ new Map();
|
|
43347
|
+
#events = /* @__PURE__ */ new Map();
|
|
43348
|
+
#requests = /* @__PURE__ */ new Map();
|
|
43349
|
+
#loadedRequestSessions = /* @__PURE__ */ new Set();
|
|
43350
|
+
#publisher;
|
|
43351
|
+
#store;
|
|
43352
|
+
constructor(publisher, store) {
|
|
43353
|
+
this.#publisher = publisher;
|
|
43354
|
+
this.#store = store;
|
|
43355
|
+
}
|
|
43356
|
+
#eventsFor = (sessionId) => {
|
|
43357
|
+
const cached2 = this.#events.get(sessionId);
|
|
43358
|
+
if (cached2 !== void 0) {
|
|
43359
|
+
return cached2;
|
|
43360
|
+
}
|
|
43361
|
+
const stored = this.#store.readEventsV2(sessionId);
|
|
43362
|
+
this.#events.set(sessionId, stored);
|
|
43363
|
+
const lastPosition = stored.at(-1)?.position;
|
|
43364
|
+
if (lastPosition !== void 0) {
|
|
43365
|
+
this.#positions.set(sessionId, Number(lastPosition));
|
|
43366
|
+
}
|
|
43367
|
+
return stored;
|
|
43368
|
+
};
|
|
43369
|
+
#loadRequests = (sessionId) => {
|
|
43370
|
+
if (this.#loadedRequestSessions.has(sessionId)) {
|
|
43371
|
+
return;
|
|
43372
|
+
}
|
|
43373
|
+
for (const event of this.#eventsFor(sessionId)) {
|
|
43374
|
+
const payload = event.payload;
|
|
43375
|
+
if (payload.kind === "prompt.requested") {
|
|
43376
|
+
this.#requests.set(payload.commandId, {
|
|
43377
|
+
commandId: payload.commandId,
|
|
43378
|
+
events: [event],
|
|
43379
|
+
kind: "requested",
|
|
43380
|
+
sessionId
|
|
43381
|
+
});
|
|
43382
|
+
continue;
|
|
43383
|
+
}
|
|
43384
|
+
if (payload.kind === "acp.session.update") {
|
|
43385
|
+
const executing = [...this.#requests.values()].find(
|
|
43386
|
+
(request) => request.sessionId === sessionId && request.kind === "executing"
|
|
43387
|
+
);
|
|
43388
|
+
if (executing !== void 0) {
|
|
43389
|
+
this.#requests.set(executing.commandId, {
|
|
43390
|
+
...executing,
|
|
43391
|
+
events: [...executing.events, event]
|
|
43392
|
+
});
|
|
43393
|
+
}
|
|
43394
|
+
continue;
|
|
43395
|
+
}
|
|
43396
|
+
if (!("commandId" in payload)) {
|
|
43397
|
+
continue;
|
|
43398
|
+
}
|
|
43399
|
+
const state = this.#requests.get(payload.commandId);
|
|
43400
|
+
if (state === void 0) {
|
|
43401
|
+
continue;
|
|
43402
|
+
}
|
|
43403
|
+
const events = [...state.events, event];
|
|
43404
|
+
if (payload.kind === "prompt.started") {
|
|
43405
|
+
this.#requests.set(payload.commandId, {
|
|
43406
|
+
attemptId: payload.attemptId,
|
|
43407
|
+
commandId: payload.commandId,
|
|
43408
|
+
epoch: payload.epoch,
|
|
43409
|
+
events,
|
|
43410
|
+
kind: "executing",
|
|
43411
|
+
sessionId
|
|
43412
|
+
});
|
|
43413
|
+
} else if (payload.kind === "prompt.completed" || payload.kind === "prompt.failed" || payload.kind === "prompt.failed-before-start") {
|
|
43414
|
+
this.#requests.delete(payload.commandId);
|
|
43415
|
+
}
|
|
43416
|
+
}
|
|
43417
|
+
this.#loadedRequestSessions.add(sessionId);
|
|
43418
|
+
};
|
|
43419
|
+
#append = (sessionId, payload) => {
|
|
43420
|
+
this.#eventsFor(sessionId);
|
|
43421
|
+
const position = (this.#positions.get(sessionId) ?? 0) + 1;
|
|
43422
|
+
const event = {
|
|
43423
|
+
eventId: `event-${crypto.randomUUID()}`,
|
|
43424
|
+
payload,
|
|
43425
|
+
position: position.toString(),
|
|
43426
|
+
provenance: { kind: "original" },
|
|
43427
|
+
recordedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
43428
|
+
sessionId
|
|
43429
|
+
};
|
|
43430
|
+
this.#store.appendEventV2(event);
|
|
43431
|
+
this.#positions.set(sessionId, position);
|
|
43432
|
+
this.#events.set(sessionId, [...this.#eventsFor(sessionId), event]);
|
|
43433
|
+
this.#publisher.publishV2(event);
|
|
43434
|
+
return event;
|
|
43435
|
+
};
|
|
43436
|
+
requested = (command) => {
|
|
43437
|
+
const event = this.#append(command.sessionId, {
|
|
43438
|
+
commandId: command.commandId,
|
|
43439
|
+
content: promptContent(command),
|
|
43440
|
+
kind: "prompt.requested"
|
|
43441
|
+
});
|
|
43442
|
+
this.#requests.set(command.commandId, {
|
|
43443
|
+
commandId: command.commandId,
|
|
43444
|
+
events: [event],
|
|
43445
|
+
kind: "requested",
|
|
43446
|
+
sessionId: command.sessionId
|
|
43447
|
+
});
|
|
43448
|
+
};
|
|
43449
|
+
started = (sessionId, commandId, attemptId, epoch) => {
|
|
43450
|
+
this.#loadRequests(sessionId);
|
|
43451
|
+
const request = this.#requests.get(commandId);
|
|
43452
|
+
if (request?.sessionId !== sessionId) {
|
|
43453
|
+
return;
|
|
43454
|
+
}
|
|
43455
|
+
const event = this.#append(sessionId, { attemptId, commandId, epoch, kind: "prompt.started" });
|
|
43456
|
+
this.#requests.set(commandId, {
|
|
43457
|
+
attemptId,
|
|
43458
|
+
commandId,
|
|
43459
|
+
epoch,
|
|
43460
|
+
events: [...request.events, event],
|
|
43461
|
+
kind: "executing",
|
|
43462
|
+
sessionId
|
|
43463
|
+
});
|
|
43464
|
+
};
|
|
43465
|
+
acpUpdate = (sessionId, update) => {
|
|
43466
|
+
this.#loadRequests(sessionId);
|
|
43467
|
+
const event = this.#append(sessionId, { kind: "acp.session.update", update });
|
|
43468
|
+
const executing = [...this.#requests.values()].find(
|
|
43469
|
+
(request) => request.sessionId === sessionId && request.kind === "executing"
|
|
43470
|
+
);
|
|
43471
|
+
if (executing !== void 0) {
|
|
43472
|
+
this.#requests.set(executing.commandId, { ...executing, events: [...executing.events, event] });
|
|
43473
|
+
}
|
|
43474
|
+
};
|
|
43475
|
+
completed = (sessionId, commandId, stopReason) => {
|
|
43476
|
+
this.#append(sessionId, { commandId, kind: "prompt.completed", stopReason });
|
|
43477
|
+
this.#requests.delete(commandId);
|
|
43478
|
+
};
|
|
43479
|
+
failed = (sessionId, commandId, code, message) => {
|
|
43480
|
+
this.#loadRequests(sessionId);
|
|
43481
|
+
const request = this.#requests.get(commandId);
|
|
43482
|
+
if (request?.kind === "executing" && request.commandId === commandId) {
|
|
43483
|
+
this.#append(sessionId, { attemptId: request.attemptId, code, commandId, kind: "prompt.failed", message });
|
|
43484
|
+
} else {
|
|
43485
|
+
this.#append(sessionId, { code, commandId, kind: "prompt.failed-before-start", message });
|
|
43486
|
+
}
|
|
43487
|
+
this.#requests.delete(commandId);
|
|
43488
|
+
};
|
|
43489
|
+
executingPromptRequest = (sessionId) => {
|
|
43490
|
+
this.#loadRequests(sessionId);
|
|
43491
|
+
const request = [...this.#requests.values()].find(
|
|
43492
|
+
(candidate) => candidate.sessionId === sessionId && candidate.kind === "executing"
|
|
43493
|
+
);
|
|
43494
|
+
if (request?.kind !== "executing") {
|
|
43495
|
+
return null;
|
|
43496
|
+
}
|
|
43497
|
+
const events = request.events.slice(-EXECUTING_PROMPT_EVENT_LIMIT);
|
|
43498
|
+
return {
|
|
43499
|
+
attemptId: request.attemptId,
|
|
43500
|
+
commandId: request.commandId,
|
|
43501
|
+
epoch: request.epoch,
|
|
43502
|
+
events,
|
|
43503
|
+
tailCursor: events.at(-1)?.eventId ?? "",
|
|
43504
|
+
truncated: events.length < request.events.length
|
|
43505
|
+
};
|
|
43506
|
+
};
|
|
43507
|
+
recovery = (sessionId, eventLimit, cursor) => {
|
|
43508
|
+
const events = this.#eventsFor(sessionId);
|
|
43509
|
+
if (events.length === 0) {
|
|
43510
|
+
return null;
|
|
43511
|
+
}
|
|
43512
|
+
const executingPromptRequest = this.executingPromptRequest(sessionId);
|
|
43513
|
+
const executingRequestState = [...this.#requests.values()].find(
|
|
43514
|
+
(request) => request.sessionId === sessionId && request.kind === "executing"
|
|
43515
|
+
);
|
|
43516
|
+
const firstExecutingPosition = executingRequestState?.events[0]?.position;
|
|
43517
|
+
const historyEvents = firstExecutingPosition === void 0 ? events : events.filter((event) => BigInt(event.position) < BigInt(firstExecutingPosition));
|
|
43518
|
+
const endEvent = cursor === null ? historyEvents.length : decodeLocalEventCursor(sessionId, cursor).endEvent;
|
|
43519
|
+
if (endEvent > historyEvents.length) {
|
|
43520
|
+
throw new AcpExecutionError("The native Session event cursor is invalid", {}, "invalid_cursor");
|
|
43521
|
+
}
|
|
43522
|
+
const startEvent = Math.max(0, endEvent - eventLimit);
|
|
43523
|
+
const pageEvents = historyEvents.slice(startEvent, endEvent);
|
|
43524
|
+
return {
|
|
43525
|
+
executingPromptRequest,
|
|
43526
|
+
history: {
|
|
43527
|
+
events: pageEvents,
|
|
43528
|
+
nextCursor: startEvent === 0 ? null : encodeLocalEventCursor({ endEvent: startEvent, sessionId }),
|
|
43529
|
+
tailCursor: pageEvents.at(-1)?.eventId ?? "",
|
|
43530
|
+
truncated: startEvent > 0,
|
|
43531
|
+
version: 2
|
|
43532
|
+
}
|
|
43533
|
+
};
|
|
43534
|
+
};
|
|
43535
|
+
};
|
|
43536
|
+
|
|
42608
43537
|
// src/run-daemon.ts
|
|
42609
43538
|
var RELAY_RECONNECT_DELAY_MILLISECONDS = 500;
|
|
42610
43539
|
function waitForRelayRetry(signal, timer) {
|
|
@@ -42672,16 +43601,17 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
42672
43601
|
stateDirectory
|
|
42673
43602
|
});
|
|
42674
43603
|
const sessionStore = new SqliteAcpSessionStore(
|
|
42675
|
-
join17(stateDirectory, "sessions", `${
|
|
43604
|
+
join17(stateDirectory, "sessions", `${createHash6("sha256").update(config2.channelId).digest("hex")}.sqlite`)
|
|
42676
43605
|
);
|
|
42677
43606
|
const operations = new DaemonOperationState();
|
|
42678
43607
|
const publisher = new DaemonSessionEventPublisher();
|
|
43608
|
+
const eventLogV2 = new DaemonSessionEventLogV2(publisher, sessionStore);
|
|
42679
43609
|
const activeTurns = new DaemonTurnRegistry(operations);
|
|
42680
43610
|
const recordSessionEvent = (sessionId, event) => {
|
|
42681
43611
|
publisher.publish(sessionId, activeTurns.recordEvent(event));
|
|
42682
43612
|
};
|
|
42683
43613
|
const agentRuntime = new AgentRuntimeManager(
|
|
42684
|
-
new DaemonAcpObserver(recordSessionEvent),
|
|
43614
|
+
new DaemonAcpObserver(recordSessionEvent, eventLogV2.acpUpdate),
|
|
42685
43615
|
sessionStore,
|
|
42686
43616
|
{
|
|
42687
43617
|
read: async (options2, nativeSessionId, nativeTurn) => options2.agent.id === "codex" ? (await readCodexFullHistory(
|
|
@@ -42719,7 +43649,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
42719
43649
|
options2.signal
|
|
42720
43650
|
);
|
|
42721
43651
|
return cwd === options2.cwd && additionalDirectories.length === options2.additionalDirectories.length && additionalDirectories.every(
|
|
42722
|
-
(directory,
|
|
43652
|
+
(directory, index2) => directory === options2.additionalDirectories[index2]
|
|
42723
43653
|
);
|
|
42724
43654
|
});
|
|
42725
43655
|
}
|
|
@@ -42805,6 +43735,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
42805
43735
|
nativeSessions,
|
|
42806
43736
|
operations,
|
|
42807
43737
|
publisher,
|
|
43738
|
+
eventLogV2,
|
|
42808
43739
|
activeTurns,
|
|
42809
43740
|
connectionEpoch,
|
|
42810
43741
|
diagnostics,
|
|
@@ -42867,7 +43798,7 @@ import { basename as basename7, resolve as resolve7 } from "node:path";
|
|
|
42867
43798
|
import { fetch as fetch4 } from "undici";
|
|
42868
43799
|
|
|
42869
43800
|
// src/storage/runtime-installation-store.ts
|
|
42870
|
-
import { createHash as
|
|
43801
|
+
import { createHash as createHash7, randomUUID as randomUUID7 } from "node:crypto";
|
|
42871
43802
|
import { mkdir as mkdir4, open as open5, readdir as readdir3, rename as rename3, unlink, writeFile as writeFile3 } from "node:fs/promises";
|
|
42872
43803
|
import { dirname as dirname5, join as join18, resolve as resolve6 } from "node:path";
|
|
42873
43804
|
var APPLICATION_ID_PATTERN = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+){1,31}$/;
|
|
@@ -43003,7 +43934,7 @@ function installationId() {
|
|
|
43003
43934
|
return `min_${randomUUID7().replaceAll("-", "")}`;
|
|
43004
43935
|
}
|
|
43005
43936
|
function channelIndexFileName(channelId) {
|
|
43006
|
-
return `mci_${
|
|
43937
|
+
return `mci_${createHash7("sha256").update(channelId).digest("hex")}.json`;
|
|
43007
43938
|
}
|
|
43008
43939
|
function decodeInstallationPointer(value) {
|
|
43009
43940
|
if (!isRecord9(value) || !hasExactKeys(value, INSTALLATION_POINTER_KEYS) || value["version"] !== 1) {
|
|
@@ -43189,16 +44120,16 @@ var RuntimeInstallationStore = class _RuntimeInstallationStore {
|
|
|
43189
44120
|
};
|
|
43190
44121
|
#readConnectionForChannel = async (channelId, signal) => {
|
|
43191
44122
|
const normalizedChannelId = validateIdentifier(channelId, "invalid_channel_id");
|
|
43192
|
-
const
|
|
44123
|
+
const index2 = decodeChannelIndex(
|
|
43193
44124
|
await readJsonFile(this.channelIndexPath(normalizedChannelId), signal, "connection_not_found")
|
|
43194
44125
|
);
|
|
43195
|
-
if (
|
|
44126
|
+
if (index2.applicationId !== this.applicationId || index2.installationId !== this.installationId || index2.channelId !== normalizedChannelId) {
|
|
43196
44127
|
throw new RuntimeInstallationStoreError(
|
|
43197
44128
|
"connection_owner_mismatch",
|
|
43198
44129
|
"The saved Runtime connection belongs to another installation"
|
|
43199
44130
|
);
|
|
43200
44131
|
}
|
|
43201
|
-
return await this.readConnection(
|
|
44132
|
+
return await this.readConnection(index2.connectionId, signal);
|
|
43202
44133
|
};
|
|
43203
44134
|
saveConnection = async (input2, signal) => {
|
|
43204
44135
|
const stored = new VerifiedRuntimeConnection(
|