openfox 1.6.37 → 1.6.38
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/{auto-compaction-CQ66MD6K.js → auto-compaction-SCLHKKGA.js} +7 -7
- package/dist/{chat-handler-EJR4GKYO.js → chat-handler-7ARMDWRH.js} +11 -11
- package/dist/{chunk-26PIZX2A.js → chunk-5NJ5NQH5.js} +5 -5
- package/dist/{chunk-XKFPU2FA.js → chunk-7JPKRM6M.js} +2 -2
- package/dist/{chunk-AV45GQ7B.js → chunk-BHSTSA7U.js} +3 -3
- package/dist/{chunk-3EHGGBWE.js → chunk-BLNFJ22S.js} +7 -1
- package/dist/{chunk-VGFTDBWZ.js → chunk-CRSOJ2YA.js} +2 -2
- package/dist/{chunk-WJ2DPSZK.js → chunk-DSI2ZSZQ.js} +31 -31
- package/dist/{chunk-EEPU4INU.js → chunk-LIMBYVO4.js} +192 -14
- package/dist/{chunk-ZGTXED6Q.js → chunk-NBBX64KC.js} +2 -2
- package/dist/{chunk-RN2O6JK7.js → chunk-O2BOWZKC.js} +2 -2
- package/dist/{chunk-VFHCB5MC.js → chunk-TBSTW3PW.js} +4 -4
- package/dist/{chunk-PMDJEJYY.js → chunk-YVQ6DP5Y.js} +107 -15
- package/dist/cli/dev.js +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/{events-LI4NAFRZ.js → events-FHPSSSE4.js} +4 -4
- package/dist/{folding-HRZMWP4H.js → folding-NEZWWL7K.js} +4 -2
- package/dist/{orchestrator-PCWZF3E5.js → orchestrator-FKVRAIIA.js} +8 -8
- package/dist/package.json +1 -1
- package/dist/{processor-7L64YPQC.js → processor-KR5GNW3S.js} +7 -7
- package/dist/{project-creator-HY32FPFV.js → project-creator-LASKNQPA.js} +3 -3
- package/dist/{projects-GSMMEVSO.js → projects-HEUOWNSR.js} +3 -3
- package/dist/{protocol-BYM6rZvW.d.ts → protocol-Ct6VfOIJ.d.ts} +1 -0
- package/dist/{serve-VZE2CPZ2.js → serve-OGLLAEMY.js} +10 -10
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +9 -9
- package/dist/{settings-3K6P2JN6.js → settings-TWK27GYE.js} +3 -3
- package/dist/shared/index.d.ts +2 -2
- package/dist/{tools-25TQ5NQY.js → tools-6XOZHTF7.js} +7 -7
- package/dist/web/assets/{index-DapVnjIC.js → index-BCHSC7BY.js} +1 -1
- package/dist/web/assets/index-D0LRgk0o.css +32 -0
- package/dist/web/index.html +2 -2
- package/dist/web/sw.js +1 -1
- package/package.json +1 -1
- package/dist/web/assets/index-CWFxAdkp.css +0 -32
|
@@ -79,13 +79,73 @@ function applyEvents(initialMessages, events, options) {
|
|
|
79
79
|
case "tool.call": {
|
|
80
80
|
const data = event.data;
|
|
81
81
|
const msg = messages.get(data.messageId);
|
|
82
|
-
if (msg)
|
|
82
|
+
if (msg) {
|
|
83
|
+
attachToolCallToMessage(msg, data.toolCall);
|
|
84
|
+
removeFromPreparing(msg, data.toolCall.id);
|
|
85
|
+
}
|
|
83
86
|
break;
|
|
84
87
|
}
|
|
85
88
|
case "tool.result": {
|
|
86
89
|
const data = event.data;
|
|
87
90
|
const msg = messages.get(data.messageId);
|
|
88
|
-
if (msg)
|
|
91
|
+
if (msg) {
|
|
92
|
+
attachToolResultToMessage(msg, data.toolCallId, data.result);
|
|
93
|
+
removeFromPreparing(msg, data.toolCallId);
|
|
94
|
+
}
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
case "tool.preparing": {
|
|
98
|
+
const data = event.data;
|
|
99
|
+
const msg = messages.get(data.messageId);
|
|
100
|
+
if (msg) {
|
|
101
|
+
const preparing = msg.preparingToolCalls ?? [];
|
|
102
|
+
preparing.push({ index: data.index, name: data.name });
|
|
103
|
+
msg.preparingToolCalls = preparing;
|
|
104
|
+
}
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
case "tool.output": {
|
|
108
|
+
const data = event.data;
|
|
109
|
+
const msg = findMessageWithToolCall(messages, data.toolCallId);
|
|
110
|
+
if (msg) {
|
|
111
|
+
const tc = msg.toolCalls?.find((tc2) => tc2.id === data.toolCallId);
|
|
112
|
+
if (tc) {
|
|
113
|
+
const output = tc.streamingOutput ?? [];
|
|
114
|
+
output.push({ stream: data.stream, content: data.content, timestamp: event.timestamp });
|
|
115
|
+
tc.streamingOutput = output;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
case "format.retry": {
|
|
121
|
+
const data = event.data;
|
|
122
|
+
for (const msg of messages.values()) {
|
|
123
|
+
const retries = msg.formatRetries ?? [];
|
|
124
|
+
retries.push({ attempt: data.attempt, maxAttempts: data.maxAttempts, timestamp: event.timestamp });
|
|
125
|
+
msg.formatRetries = retries;
|
|
126
|
+
}
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
case "chat.done": {
|
|
130
|
+
const data = event.data;
|
|
131
|
+
const msg = messages.get(data.messageId);
|
|
132
|
+
if (msg) {
|
|
133
|
+
;
|
|
134
|
+
msg.isComplete = true;
|
|
135
|
+
msg.completeReason = data.reason;
|
|
136
|
+
}
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
case "chat.error": {
|
|
140
|
+
const data = event.data;
|
|
141
|
+
for (const msg of messages.values()) {
|
|
142
|
+
if (msg.role === "assistant" && !("isComplete" in msg)) {
|
|
143
|
+
;
|
|
144
|
+
msg.isComplete = true;
|
|
145
|
+
msg.completeReason = "error";
|
|
146
|
+
msg.stats = { error: data.error };
|
|
147
|
+
}
|
|
148
|
+
}
|
|
89
149
|
break;
|
|
90
150
|
}
|
|
91
151
|
case "session.initialized":
|
|
@@ -99,16 +159,27 @@ function applyEvents(initialMessages, events, options) {
|
|
|
99
159
|
case "context.compacted":
|
|
100
160
|
case "file.read":
|
|
101
161
|
case "todo.updated":
|
|
102
|
-
case "chat.done":
|
|
103
|
-
case "chat.error":
|
|
104
|
-
case "format.retry":
|
|
105
|
-
case "tool.preparing":
|
|
106
|
-
case "tool.output":
|
|
107
162
|
break;
|
|
108
163
|
}
|
|
109
164
|
}
|
|
110
165
|
return Array.from(messages.values());
|
|
111
166
|
}
|
|
167
|
+
function removeFromPreparing(msg, _toolCallId) {
|
|
168
|
+
if ("preparingToolCalls" in msg && Array.isArray(msg.preparingToolCalls)) {
|
|
169
|
+
;
|
|
170
|
+
msg.preparingToolCalls = [];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function findMessageWithToolCall(messages, toolCallId) {
|
|
174
|
+
for (const msg of messages.values()) {
|
|
175
|
+
if ("toolCalls" in msg && Array.isArray(msg.toolCalls)) {
|
|
176
|
+
if (msg.toolCalls.some((tc) => tc.id === toolCallId)) {
|
|
177
|
+
return msg;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return void 0;
|
|
182
|
+
}
|
|
112
183
|
function deepCloneMessage(msg) {
|
|
113
184
|
const cloned = { ...msg };
|
|
114
185
|
const obj = cloned;
|
|
@@ -233,6 +304,9 @@ Error: ${toolCall.result.error}` : `Error: ${toolCall.result.error}`),
|
|
|
233
304
|
function applyStoredMessageEvents(initialMessages, events) {
|
|
234
305
|
return applyEvents(initialMessages, events, { timestampAsNumber: false });
|
|
235
306
|
}
|
|
307
|
+
function getTimestamp(event) {
|
|
308
|
+
return event.timestamp ?? Date.now();
|
|
309
|
+
}
|
|
236
310
|
function applyTurnEventsToSnapshotMessages(initialMessages, events) {
|
|
237
311
|
const messages = applyEvents(initialMessages, events, { timestampAsNumber: true });
|
|
238
312
|
return messages.map((msg) => ({ ...msg, isStreaming: msg.isStreaming ?? true }));
|
|
@@ -335,6 +409,9 @@ function buildContextMessagesFromEventHistory(events, windowId, options) {
|
|
|
335
409
|
function foldTurnEventsToSnapshotMessages(events) {
|
|
336
410
|
return applyTurnEventsToSnapshotMessages([], events);
|
|
337
411
|
}
|
|
412
|
+
function foldTurnEventsToSnapshotMessagesFromInitial(events, initialMessages) {
|
|
413
|
+
return applyTurnEventsToSnapshotMessages(initialMessages, events);
|
|
414
|
+
}
|
|
338
415
|
function foldCriteria(events) {
|
|
339
416
|
let criteria = [];
|
|
340
417
|
for (const event of events) {
|
|
@@ -383,8 +460,10 @@ function foldContextState(events, initialWindowId) {
|
|
|
383
460
|
compactionCount = data.contextState.compactionCount;
|
|
384
461
|
latestContextState = data.contextState;
|
|
385
462
|
readFilesMap.clear();
|
|
386
|
-
|
|
387
|
-
|
|
463
|
+
if (data.readFiles) {
|
|
464
|
+
for (const entry of data.readFiles) {
|
|
465
|
+
readFilesMap.set(entry.path, { ...entry });
|
|
466
|
+
}
|
|
388
467
|
}
|
|
389
468
|
break;
|
|
390
469
|
}
|
|
@@ -477,11 +556,11 @@ function foldPendingConfirmations(events) {
|
|
|
477
556
|
}
|
|
478
557
|
return pending;
|
|
479
558
|
}
|
|
480
|
-
function foldSessionState(events, initialWindowId, maxTokens) {
|
|
559
|
+
function foldSessionState(events, initialWindowId, maxTokens, initialMessages) {
|
|
481
560
|
const mode = foldMode(events);
|
|
482
561
|
const phase = foldPhase(events);
|
|
483
562
|
const isRunning = foldIsRunning(events);
|
|
484
|
-
const messages = foldTurnEventsToSnapshotMessages(events);
|
|
563
|
+
const messages = initialMessages && initialMessages.length > 0 ? foldTurnEventsToSnapshotMessagesFromInitial(events, initialMessages) : foldTurnEventsToSnapshotMessages(events);
|
|
485
564
|
const criteria = foldCriteria(events);
|
|
486
565
|
const todos = foldTodos(events);
|
|
487
566
|
const contextResult = foldContextState(events, initialWindowId);
|
|
@@ -533,6 +612,87 @@ function foldSessionState(events, initialWindowId, maxTokens) {
|
|
|
533
612
|
}
|
|
534
613
|
}
|
|
535
614
|
}
|
|
615
|
+
let sessionInit;
|
|
616
|
+
let sessionTitle;
|
|
617
|
+
let visionFallbacks = [];
|
|
618
|
+
let formatRetries = [];
|
|
619
|
+
let pendingUserInput;
|
|
620
|
+
let taskStats;
|
|
621
|
+
let messageStats = [];
|
|
622
|
+
let contextWindows = [];
|
|
623
|
+
for (const event of events) {
|
|
624
|
+
switch (event.type) {
|
|
625
|
+
case "session.initialized": {
|
|
626
|
+
const data = event.data;
|
|
627
|
+
sessionInit = {
|
|
628
|
+
projectId: data.projectId,
|
|
629
|
+
workdir: data.workdir,
|
|
630
|
+
contextWindowId: data.contextWindowId,
|
|
631
|
+
...data.maxTokens !== void 0 && { maxTokens: data.maxTokens }
|
|
632
|
+
};
|
|
633
|
+
break;
|
|
634
|
+
}
|
|
635
|
+
case "session.name_generated": {
|
|
636
|
+
const data = event.data;
|
|
637
|
+
sessionTitle = data.name;
|
|
638
|
+
break;
|
|
639
|
+
}
|
|
640
|
+
case "vision_fallback.start": {
|
|
641
|
+
const data = event.data;
|
|
642
|
+
visionFallbacks.push({
|
|
643
|
+
messageId: data.messageId,
|
|
644
|
+
attachmentId: data.attachmentId,
|
|
645
|
+
...data.filename !== void 0 && { filename: data.filename },
|
|
646
|
+
startedAt: getTimestamp(event)
|
|
647
|
+
});
|
|
648
|
+
break;
|
|
649
|
+
}
|
|
650
|
+
case "vision_fallback.done": {
|
|
651
|
+
const data = event.data;
|
|
652
|
+
const existing = visionFallbacks.find((v) => v.messageId === data.messageId && v.attachmentId === data.attachmentId);
|
|
653
|
+
if (existing) {
|
|
654
|
+
existing.description = data.description;
|
|
655
|
+
}
|
|
656
|
+
break;
|
|
657
|
+
}
|
|
658
|
+
case "format.retry": {
|
|
659
|
+
const data = event.data;
|
|
660
|
+
formatRetries.push({
|
|
661
|
+
attempt: data.attempt,
|
|
662
|
+
maxAttempts: data.maxAttempts,
|
|
663
|
+
timestamp: getTimestamp(event)
|
|
664
|
+
});
|
|
665
|
+
break;
|
|
666
|
+
}
|
|
667
|
+
case "chat.ask_user": {
|
|
668
|
+
const data = event.data;
|
|
669
|
+
pendingUserInput = { callId: data.callId, question: data.question };
|
|
670
|
+
break;
|
|
671
|
+
}
|
|
672
|
+
case "task.completed": {
|
|
673
|
+
const data = event.data;
|
|
674
|
+
taskStats = data;
|
|
675
|
+
break;
|
|
676
|
+
}
|
|
677
|
+
case "chat.done": {
|
|
678
|
+
const data = event.data;
|
|
679
|
+
messageStats.push({
|
|
680
|
+
messageId: data.messageId,
|
|
681
|
+
reason: data.reason,
|
|
682
|
+
...data.stats !== void 0 && { stats: data.stats }
|
|
683
|
+
});
|
|
684
|
+
break;
|
|
685
|
+
}
|
|
686
|
+
case "context.compacted": {
|
|
687
|
+
const data = event.data;
|
|
688
|
+
contextWindows.push({
|
|
689
|
+
...data,
|
|
690
|
+
timestamp: getTimestamp(event)
|
|
691
|
+
});
|
|
692
|
+
break;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
}
|
|
536
696
|
return {
|
|
537
697
|
mode,
|
|
538
698
|
phase,
|
|
@@ -544,7 +704,15 @@ function foldSessionState(events, initialWindowId, maxTokens) {
|
|
|
544
704
|
currentContextWindowId: contextResult.currentContextWindowId,
|
|
545
705
|
readFiles: contextResult.readFiles,
|
|
546
706
|
...lastModeWithReminder !== void 0 && { lastModeWithReminder },
|
|
547
|
-
pendingConfirmations
|
|
707
|
+
pendingConfirmations,
|
|
708
|
+
...sessionInit !== void 0 && { sessionInit },
|
|
709
|
+
...sessionTitle !== void 0 && { sessionTitle },
|
|
710
|
+
...visionFallbacks.length > 0 && { visionFallbacks },
|
|
711
|
+
...formatRetries.length > 0 && { formatRetries },
|
|
712
|
+
...pendingUserInput !== void 0 && { pendingUserInput },
|
|
713
|
+
...taskStats !== void 0 && { taskStats },
|
|
714
|
+
...messageStats.length > 0 && { messageStats },
|
|
715
|
+
...contextWindows.length > 0 && { contextWindows }
|
|
548
716
|
};
|
|
549
717
|
}
|
|
550
718
|
function buildSnapshot(foldedState, latestSeq, snapshotAt = Date.now()) {
|
|
@@ -560,7 +728,16 @@ function buildSnapshot(foldedState, latestSeq, snapshotAt = Date.now()) {
|
|
|
560
728
|
readFiles: foldedState.readFiles,
|
|
561
729
|
...foldedState.lastModeWithReminder !== void 0 && { lastModeWithReminder: foldedState.lastModeWithReminder },
|
|
562
730
|
snapshotSeq: latestSeq,
|
|
563
|
-
snapshotAt
|
|
731
|
+
snapshotAt,
|
|
732
|
+
...foldedState.sessionInit !== void 0 && { sessionInit: foldedState.sessionInit },
|
|
733
|
+
...foldedState.sessionTitle !== void 0 && { sessionTitle: foldedState.sessionTitle },
|
|
734
|
+
...foldedState.visionFallbacks !== void 0 && { visionFallbacks: foldedState.visionFallbacks },
|
|
735
|
+
...foldedState.formatRetries !== void 0 && { formatRetries: foldedState.formatRetries },
|
|
736
|
+
...foldedState.pendingUserInput !== void 0 && { pendingUserInput: foldedState.pendingUserInput },
|
|
737
|
+
...foldedState.taskStats !== void 0 && { taskStats: foldedState.taskStats },
|
|
738
|
+
...foldedState.messageStats !== void 0 && { messageStats: foldedState.messageStats },
|
|
739
|
+
...foldedState.pendingConfirmations !== void 0 && { pendingConfirmations: foldedState.pendingConfirmations },
|
|
740
|
+
...foldedState.contextWindows !== void 0 && { contextWindows: foldedState.contextWindows }
|
|
564
741
|
};
|
|
565
742
|
}
|
|
566
743
|
function buildSnapshotFromSessionState(input) {
|
|
@@ -624,6 +801,7 @@ export {
|
|
|
624
801
|
buildContextMessagesFromStoredEvents,
|
|
625
802
|
buildContextMessagesFromEventHistory,
|
|
626
803
|
foldTurnEventsToSnapshotMessages,
|
|
804
|
+
foldTurnEventsToSnapshotMessagesFromInitial,
|
|
627
805
|
foldCriteria,
|
|
628
806
|
foldTodos,
|
|
629
807
|
foldContextState,
|
|
@@ -637,4 +815,4 @@ export {
|
|
|
637
815
|
getMessagesForWindow,
|
|
638
816
|
buildContextMessagesFromMessages
|
|
639
817
|
};
|
|
640
|
-
//# sourceMappingURL=chunk-
|
|
818
|
+
//# sourceMappingURL=chunk-LIMBYVO4.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getEventStore
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-YVQ6DP5Y.js";
|
|
4
4
|
import {
|
|
5
5
|
createContextStateMessage
|
|
6
6
|
} from "./chunk-DZHZ3UUR.js";
|
|
@@ -41,4 +41,4 @@ export {
|
|
|
41
41
|
finalizeTurnCompletion,
|
|
42
42
|
buildRunChatTurnParams
|
|
43
43
|
};
|
|
44
|
-
//# sourceMappingURL=chunk-
|
|
44
|
+
//# sourceMappingURL=chunk-NBBX64KC.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getDatabase
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-BLNFJ22S.js";
|
|
4
4
|
|
|
5
5
|
// src/server/db/settings.ts
|
|
6
6
|
var SETTINGS_KEYS = {
|
|
@@ -56,4 +56,4 @@ export {
|
|
|
56
56
|
deleteSetting,
|
|
57
57
|
getAllSettings
|
|
58
58
|
};
|
|
59
|
-
//# sourceMappingURL=chunk-
|
|
59
|
+
//# sourceMappingURL=chunk-O2BOWZKC.js.map
|
|
@@ -13,14 +13,14 @@ import {
|
|
|
13
13
|
getToolRegistryForAgent,
|
|
14
14
|
loadAllAgentsDefault,
|
|
15
15
|
runTopLevelAgentLoop
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-5NJ5NQH5.js";
|
|
17
17
|
import {
|
|
18
18
|
getCurrentContextWindowId,
|
|
19
19
|
getEventStore
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-YVQ6DP5Y.js";
|
|
21
21
|
import {
|
|
22
22
|
buildSnapshotFromSessionState
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-LIMBYVO4.js";
|
|
24
24
|
import {
|
|
25
25
|
logger
|
|
26
26
|
} from "./chunk-PNBH3RAX.js";
|
|
@@ -293,4 +293,4 @@ export {
|
|
|
293
293
|
runBuilderTurn,
|
|
294
294
|
runVerifierTurn
|
|
295
295
|
};
|
|
296
|
-
//# sourceMappingURL=chunk-
|
|
296
|
+
//# sourceMappingURL=chunk-TBSTW3PW.js.map
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildContextMessagesFromEventHistory,
|
|
3
3
|
buildMessagesFromStoredEvents,
|
|
4
|
+
buildSnapshot,
|
|
4
5
|
foldContextState,
|
|
5
6
|
foldSessionState,
|
|
6
7
|
spreadOptionalMessageFields,
|
|
7
8
|
stripPromptContextMessages
|
|
8
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-LIMBYVO4.js";
|
|
9
10
|
import {
|
|
10
11
|
getDatabase
|
|
11
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-BLNFJ22S.js";
|
|
12
13
|
import {
|
|
13
14
|
getRuntimeConfig
|
|
14
15
|
} from "./chunk-TVQOONDR.js";
|
|
@@ -346,18 +347,6 @@ var EventStore = class {
|
|
|
346
347
|
`).run(sessionId, latestSnapshotSeq);
|
|
347
348
|
return result.changes;
|
|
348
349
|
}
|
|
349
|
-
/**
|
|
350
|
-
* Get the latest snapshot sequence number for a session
|
|
351
|
-
* @returns The sequence number of the latest snapshot, or 0 if none
|
|
352
|
-
*/
|
|
353
|
-
getLatestSnapshotSeq(sessionId) {
|
|
354
|
-
const row = this.db.prepare(`
|
|
355
|
-
SELECT seq FROM events
|
|
356
|
-
WHERE session_id = ? AND event_type = 'turn.snapshot'
|
|
357
|
-
ORDER BY seq DESC LIMIT 1
|
|
358
|
-
`).get(sessionId);
|
|
359
|
-
return row?.seq ?? 0;
|
|
360
|
-
}
|
|
361
350
|
/**
|
|
362
351
|
* One-time storage optimization: delete old snapshots and strip
|
|
363
352
|
* promptContext.messages from remaining snapshots across all sessions.
|
|
@@ -394,6 +383,88 @@ var EventStore = class {
|
|
|
394
383
|
}
|
|
395
384
|
return { deletedSnapshots, strippedSnapshots };
|
|
396
385
|
}
|
|
386
|
+
/**
|
|
387
|
+
* Get the latest snapshot sequence number for a session
|
|
388
|
+
* @returns The sequence number of the latest snapshot, or 0 if none
|
|
389
|
+
*/
|
|
390
|
+
getLatestSnapshotSeq(sessionId) {
|
|
391
|
+
const row = this.db.prepare(`
|
|
392
|
+
SELECT seq FROM events
|
|
393
|
+
WHERE session_id = ? AND event_type = 'turn.snapshot'
|
|
394
|
+
ORDER BY seq DESC LIMIT 1
|
|
395
|
+
`).get(sessionId);
|
|
396
|
+
return row?.seq ?? 0;
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Consolidate orphaned events into a new snapshot and delete raw events.
|
|
400
|
+
* Uses transaction to ensure atomicity.
|
|
401
|
+
* @returns Object with snapshotSeq and deletedCount, or null if no events to consolidate
|
|
402
|
+
*/
|
|
403
|
+
consolidateSession(sessionId) {
|
|
404
|
+
const transaction = this.db.transaction(() => {
|
|
405
|
+
const events = this.getEvents(sessionId);
|
|
406
|
+
if (events.length === 0) return null;
|
|
407
|
+
const latestSnapshot = [...events].reverse().find((e) => e.type === "turn.snapshot");
|
|
408
|
+
const eventsAfterSnapshot = events.filter((e) => e.seq > (latestSnapshot?.seq ?? 0));
|
|
409
|
+
if (eventsAfterSnapshot.length === 0) return null;
|
|
410
|
+
const initEvent = events.find((e) => e.type === "session.initialized");
|
|
411
|
+
const initialWindowId = initEvent && typeof initEvent.data === "object" && "contextWindowId" in initEvent.data ? initEvent.data.contextWindowId : "legacy-window-1";
|
|
412
|
+
const latestSeq = events[events.length - 1].seq;
|
|
413
|
+
const snapshotMessages = latestSnapshot?.data && typeof latestSnapshot.data === "object" && "messages" in latestSnapshot.data ? latestSnapshot.data.messages : [];
|
|
414
|
+
const foldedState = foldSessionState(events, initialWindowId, 2e5, snapshotMessages);
|
|
415
|
+
const newSnapshot = buildSnapshot(foldedState, latestSeq);
|
|
416
|
+
const deleteResult = this.db.prepare(`
|
|
417
|
+
DELETE FROM events
|
|
418
|
+
WHERE session_id = ? AND seq <= ?
|
|
419
|
+
`).run(sessionId, latestSeq);
|
|
420
|
+
const snapshotEvent = this.append(sessionId, {
|
|
421
|
+
type: "turn.snapshot",
|
|
422
|
+
data: newSnapshot
|
|
423
|
+
});
|
|
424
|
+
return {
|
|
425
|
+
snapshotSeq: snapshotEvent.seq,
|
|
426
|
+
deletedCount: deleteResult.changes
|
|
427
|
+
};
|
|
428
|
+
});
|
|
429
|
+
try {
|
|
430
|
+
return transaction();
|
|
431
|
+
} catch (error) {
|
|
432
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
433
|
+
logger.error("Failed to consolidate session", { sessionId, error: err.message, stack: err.stack });
|
|
434
|
+
return null;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Find session IDs that have orphaned events (events after latest snapshot)
|
|
439
|
+
* and are not currently running.
|
|
440
|
+
*/
|
|
441
|
+
findOrphanedSessions() {
|
|
442
|
+
const cutoff = new Date(Date.now() - 5 * 60 * 1e3).toISOString();
|
|
443
|
+
logger.debug("Looking for orphaned sessions", { cutoff });
|
|
444
|
+
const sessions = this.db.prepare(`
|
|
445
|
+
SELECT id, is_running
|
|
446
|
+
FROM sessions
|
|
447
|
+
WHERE is_running = 0 AND updated_at < ?
|
|
448
|
+
`).all(cutoff);
|
|
449
|
+
logger.debug("Idle sessions found", { count: sessions.length });
|
|
450
|
+
const orphaned = [];
|
|
451
|
+
for (const session of sessions) {
|
|
452
|
+
const hasSnapshot = this.db.prepare(`
|
|
453
|
+
SELECT 1 FROM events WHERE session_id = ? AND event_type = 'turn.snapshot' LIMIT 1
|
|
454
|
+
`).get(session.id);
|
|
455
|
+
if (hasSnapshot) {
|
|
456
|
+
const latestSnapshotSeq = this.getLatestSnapshotSeq(session.id);
|
|
457
|
+
const eventsAfter = this.db.prepare(`
|
|
458
|
+
SELECT 1 FROM events WHERE session_id = ? AND seq > ? LIMIT 1
|
|
459
|
+
`).get(session.id, latestSnapshotSeq);
|
|
460
|
+
if (eventsAfter) {
|
|
461
|
+
orphaned.push(session.id);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
logger.info("Orphaned sessions found", { count: orphaned.length, ids: orphaned });
|
|
466
|
+
return orphaned;
|
|
467
|
+
}
|
|
397
468
|
};
|
|
398
469
|
var eventStoreInstance = null;
|
|
399
470
|
function initEventStore(db) {
|
|
@@ -403,6 +474,27 @@ function initEventStore(db) {
|
|
|
403
474
|
if (result.deletedSnapshots > 0 || result.strippedSnapshots > 0) {
|
|
404
475
|
logger.info("Storage optimized", result);
|
|
405
476
|
}
|
|
477
|
+
setImmediate(() => {
|
|
478
|
+
try {
|
|
479
|
+
logger.info("Starting orphaned session consolidation");
|
|
480
|
+
const orphanedSessions = eventStoreInstance.findOrphanedSessions();
|
|
481
|
+
if (orphanedSessions.length > 0) {
|
|
482
|
+
logger.info("Found orphaned sessions to consolidate", { count: orphanedSessions.length });
|
|
483
|
+
let consolidated = 0;
|
|
484
|
+
for (const sessionId of orphanedSessions) {
|
|
485
|
+
const result2 = eventStoreInstance.consolidateSession(sessionId);
|
|
486
|
+
if (result2) {
|
|
487
|
+
consolidated++;
|
|
488
|
+
logger.debug("Consolidated session", { sessionId, deletedCount: result2.deletedCount });
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
logger.info("Sessions consolidated", { consolidated, total: orphanedSessions.length });
|
|
492
|
+
} else {
|
|
493
|
+
logger.info("No orphaned sessions to consolidate");
|
|
494
|
+
}
|
|
495
|
+
} catch {
|
|
496
|
+
}
|
|
497
|
+
});
|
|
406
498
|
return eventStoreInstance;
|
|
407
499
|
}
|
|
408
500
|
function resetStaleRunningSessions(eventStore, db) {
|
|
@@ -1066,4 +1158,4 @@ export {
|
|
|
1066
1158
|
compactContext,
|
|
1067
1159
|
getRecentUserPromptsForSession
|
|
1068
1160
|
};
|
|
1069
|
-
//# sourceMappingURL=chunk-
|
|
1161
|
+
//# sourceMappingURL=chunk-YVQ6DP5Y.js.map
|
package/dist/cli/dev.js
CHANGED
package/dist/cli/index.js
CHANGED
|
@@ -36,7 +36,7 @@ import {
|
|
|
36
36
|
isFileInCache,
|
|
37
37
|
isStoredEvent,
|
|
38
38
|
isTurnEvent
|
|
39
|
-
} from "./chunk-
|
|
39
|
+
} from "./chunk-YVQ6DP5Y.js";
|
|
40
40
|
import {
|
|
41
41
|
buildContextMessagesFromEventHistory,
|
|
42
42
|
buildContextMessagesFromMessages,
|
|
@@ -53,8 +53,8 @@ import {
|
|
|
53
53
|
foldTodos,
|
|
54
54
|
foldTurnEventsToSnapshotMessages,
|
|
55
55
|
getMessagesForWindow
|
|
56
|
-
} from "./chunk-
|
|
57
|
-
import "./chunk-
|
|
56
|
+
} from "./chunk-LIMBYVO4.js";
|
|
57
|
+
import "./chunk-BLNFJ22S.js";
|
|
58
58
|
import "./chunk-TVQOONDR.js";
|
|
59
59
|
import "./chunk-PNBH3RAX.js";
|
|
60
60
|
export {
|
|
@@ -111,4 +111,4 @@ export {
|
|
|
111
111
|
isStoredEvent,
|
|
112
112
|
isTurnEvent
|
|
113
113
|
};
|
|
114
|
-
//# sourceMappingURL=events-
|
|
114
|
+
//# sourceMappingURL=events-FHPSSSE4.js.map
|
|
@@ -14,9 +14,10 @@ import {
|
|
|
14
14
|
foldSessionState,
|
|
15
15
|
foldTodos,
|
|
16
16
|
foldTurnEventsToSnapshotMessages,
|
|
17
|
+
foldTurnEventsToSnapshotMessagesFromInitial,
|
|
17
18
|
getMessagesForWindow,
|
|
18
19
|
spreadOptionalMessageFields
|
|
19
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-LIMBYVO4.js";
|
|
20
21
|
export {
|
|
21
22
|
buildContextMessagesFromEventHistory,
|
|
22
23
|
buildContextMessagesFromMessages,
|
|
@@ -33,7 +34,8 @@ export {
|
|
|
33
34
|
foldSessionState,
|
|
34
35
|
foldTodos,
|
|
35
36
|
foldTurnEventsToSnapshotMessages,
|
|
37
|
+
foldTurnEventsToSnapshotMessagesFromInitial,
|
|
36
38
|
getMessagesForWindow,
|
|
37
39
|
spreadOptionalMessageFields
|
|
38
40
|
};
|
|
39
|
-
//# sourceMappingURL=folding-
|
|
41
|
+
//# sourceMappingURL=folding-NEZWWL7K.js.map
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
runBuilderTurn,
|
|
4
4
|
runChatTurn,
|
|
5
5
|
runVerifierTurn
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-TBSTW3PW.js";
|
|
7
7
|
import {
|
|
8
8
|
TurnMetrics,
|
|
9
9
|
createChatDoneEvent,
|
|
@@ -11,17 +11,17 @@ import {
|
|
|
11
11
|
createMessageStartEvent,
|
|
12
12
|
createToolCallEvent,
|
|
13
13
|
createToolResultEvent
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-5NJ5NQH5.js";
|
|
15
15
|
import "./chunk-NBU6KIOD.js";
|
|
16
16
|
import "./chunk-574HZVLE.js";
|
|
17
17
|
import "./chunk-D4ZLSV6P.js";
|
|
18
|
-
import "./chunk-
|
|
19
|
-
import "./chunk-
|
|
18
|
+
import "./chunk-YVQ6DP5Y.js";
|
|
19
|
+
import "./chunk-LIMBYVO4.js";
|
|
20
20
|
import "./chunk-DZHZ3UUR.js";
|
|
21
21
|
import "./chunk-22CTURMH.js";
|
|
22
|
-
import "./chunk-
|
|
23
|
-
import "./chunk-
|
|
24
|
-
import "./chunk-
|
|
22
|
+
import "./chunk-O2BOWZKC.js";
|
|
23
|
+
import "./chunk-7JPKRM6M.js";
|
|
24
|
+
import "./chunk-BLNFJ22S.js";
|
|
25
25
|
import "./chunk-Y6HBEACI.js";
|
|
26
26
|
import "./chunk-R4HADRYO.js";
|
|
27
27
|
import "./chunk-TVQOONDR.js";
|
|
@@ -39,4 +39,4 @@ export {
|
|
|
39
39
|
runChatTurn,
|
|
40
40
|
runVerifierTurn
|
|
41
41
|
};
|
|
42
|
-
//# sourceMappingURL=orchestrator-
|
|
42
|
+
//# sourceMappingURL=orchestrator-FKVRAIIA.js.map
|
package/dist/package.json
CHANGED
|
@@ -2,21 +2,21 @@ import {
|
|
|
2
2
|
buildRunChatTurnParams,
|
|
3
3
|
finalizeTurnCompletion,
|
|
4
4
|
getSessionMessageCount
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-NBBX64KC.js";
|
|
6
6
|
import {
|
|
7
7
|
applyGeneratedSessionName,
|
|
8
8
|
generateSessionName,
|
|
9
9
|
needsNameGenerationCheck
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-BHSTSA7U.js";
|
|
11
11
|
import {
|
|
12
12
|
getEventStore
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
13
|
+
} from "./chunk-YVQ6DP5Y.js";
|
|
14
|
+
import "./chunk-LIMBYVO4.js";
|
|
15
15
|
import {
|
|
16
16
|
createChatMessageMessage,
|
|
17
17
|
createSessionRunningMessage
|
|
18
18
|
} from "./chunk-DZHZ3UUR.js";
|
|
19
|
-
import "./chunk-
|
|
19
|
+
import "./chunk-BLNFJ22S.js";
|
|
20
20
|
import "./chunk-Y6HBEACI.js";
|
|
21
21
|
import "./chunk-TVQOONDR.js";
|
|
22
22
|
import {
|
|
@@ -175,7 +175,7 @@ var QueueProcessor = class {
|
|
|
175
175
|
backend: provider?.backend ?? llmClient.getBackend(),
|
|
176
176
|
model: llmClient.getModel()
|
|
177
177
|
};
|
|
178
|
-
const { runChatTurn } = await import("./orchestrator-
|
|
178
|
+
const { runChatTurn } = await import("./orchestrator-FKVRAIIA.js");
|
|
179
179
|
const runChatTurnParams = buildRunChatTurnParams({
|
|
180
180
|
sessionManager,
|
|
181
181
|
sessionId,
|
|
@@ -208,4 +208,4 @@ var QueueProcessor = class {
|
|
|
208
208
|
export {
|
|
209
209
|
QueueProcessor
|
|
210
210
|
};
|
|
211
|
-
//# sourceMappingURL=processor-
|
|
211
|
+
//# sourceMappingURL=processor-KR5GNW3S.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createProject
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-7JPKRM6M.js";
|
|
4
|
+
import "./chunk-BLNFJ22S.js";
|
|
5
5
|
import "./chunk-PNBH3RAX.js";
|
|
6
6
|
|
|
7
7
|
// src/server/utils/project-creator.ts
|
|
@@ -59,4 +59,4 @@ export {
|
|
|
59
59
|
createDirectoryWithGit,
|
|
60
60
|
validateProjectName
|
|
61
61
|
};
|
|
62
|
-
//# sourceMappingURL=project-creator-
|
|
62
|
+
//# sourceMappingURL=project-creator-LASKNQPA.js.map
|