openfox 1.6.13 → 1.6.15
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/{ask-JQQNGB5K.js → ask-3RK5YJZE.js} +2 -2
- package/dist/{auto-compaction-QPFQEWJG.js → auto-compaction-JZIM73ZY.js} +6 -6
- package/dist/{chat-handler-FDHHTHS3.js → chat-handler-F2A2IMQB.js} +27 -57
- package/dist/{chunk-5LDTVERY.js → chunk-22CTURMH.js} +1 -3
- package/dist/{chunk-WQ4W5H6A.js → chunk-2KP34IDL.js} +163 -205
- package/dist/{chunk-POJO7A5H.js → chunk-3WHZ47PY.js} +511 -793
- package/dist/{chunk-XFXOSPYH.js → chunk-55N6FAAZ.js} +1 -1
- package/dist/{chunk-ZRDRYL6W.js → chunk-6L3X7T4K.js} +82 -160
- package/dist/{chunk-QDEKU5RL.js → chunk-F54ZJN4X.js} +38 -2
- package/dist/{chunk-7T2CA2C6.js → chunk-G4E72ST3.js} +117 -242
- package/dist/{chunk-AKFLBPPY.js → chunk-IN5EP4ZB.js} +2 -2
- package/dist/{chunk-HCZT5BDI.js → chunk-JFKYCGZ5.js} +6 -6
- package/dist/{chunk-ZHGP4PBJ.js → chunk-KOUMYBYM.js} +53 -112
- package/dist/{chunk-E6FCNB3B.js → chunk-OVLFEBRR.js} +76 -94
- package/dist/chunk-SN7OBEVL.js +44 -0
- package/dist/{chunk-LMIBGLOB.js → chunk-YM6VHAPM.js} +4 -4
- package/dist/{chunk-TXQNRBMZ.js → chunk-ZDNXCVW4.js} +2 -2
- package/dist/cli/dev.js +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/{config-TUA644W4.js → config-67AX6CNS.js} +5 -5
- package/dist/{events-EILPWKYE.js → events-2ETDOE5B.js} +3 -3
- package/dist/{folding-NZYOXNKK.js → folding-M7FMUBOL.js} +6 -4
- package/dist/{orchestrator-YKQJI3PH.js → orchestrator-SRSG2SIZ.js} +7 -7
- package/dist/package.json +14 -3
- package/dist/{processor-JU7MSV4F.js → processor-H5BQ5HQM.js} +24 -49
- package/dist/{provider-FNSGWDIW.js → provider-DKGBQHUS.js} +7 -7
- package/dist/{serve-O62TKFVA.js → serve-5AY7GMN7.js} +13 -13
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +11 -11
- package/dist/{tools-JWAF3MAR.js → tools-VOWNOP6V.js} +6 -6
- package/dist/{vision-fallback-BWCKA2FZ.js → vision-fallback-ADYRFFD4.js} +2 -2
- package/dist/web/assets/{index-MCWDS5UQ.css → index-CNeIjdxm.css} +1 -1
- package/dist/web/assets/index-mBLhctLW.js +150 -0
- package/dist/web/index.html +2 -2
- package/dist/web/sw.js +1 -1
- package/package.json +14 -3
- package/dist/web/assets/index-Cp8gfbgP.js +0 -150
- /package/dist/{command-defaults → server/commands/defaults}/commit-push.command.md +0 -0
- /package/dist/{command-defaults → server/commands/defaults}/init.command.md +0 -0
- /package/dist/{command-defaults → server/commands/defaults}/test-ui.command.md +0 -0
- /package/dist/{skill-defaults → server/skills/defaults}/browser.skill.md +0 -0
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
cancelQuestionsForSession,
|
|
7
7
|
hasPendingQuestion,
|
|
8
8
|
provideAnswer
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-22CTURMH.js";
|
|
10
10
|
export {
|
|
11
11
|
AskUserInterrupt,
|
|
12
12
|
askUserTool,
|
|
@@ -16,4 +16,4 @@ export {
|
|
|
16
16
|
hasPendingQuestion,
|
|
17
17
|
provideAnswer
|
|
18
18
|
};
|
|
19
|
-
//# sourceMappingURL=ask-
|
|
19
|
+
//# sourceMappingURL=ask-3RK5YJZE.js.map
|
|
@@ -2,14 +2,14 @@ import {
|
|
|
2
2
|
maybeAutoCompactContext,
|
|
3
3
|
performManualContextCompaction,
|
|
4
4
|
resolveCompactionStatsIdentity
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-3WHZ47PY.js";
|
|
6
6
|
import "./chunk-NBU6KIOD.js";
|
|
7
7
|
import "./chunk-574HZVLE.js";
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-
|
|
8
|
+
import "./chunk-55N6FAAZ.js";
|
|
9
|
+
import "./chunk-6L3X7T4K.js";
|
|
10
|
+
import "./chunk-2KP34IDL.js";
|
|
11
11
|
import "./chunk-NJWPSSRW.js";
|
|
12
|
-
import "./chunk-
|
|
12
|
+
import "./chunk-22CTURMH.js";
|
|
13
13
|
import "./chunk-7IOZFJBW.js";
|
|
14
14
|
import "./chunk-XKFPU2FA.js";
|
|
15
15
|
import "./chunk-3EHGGBWE.js";
|
|
@@ -22,4 +22,4 @@ export {
|
|
|
22
22
|
performManualContextCompaction,
|
|
23
23
|
resolveCompactionStatsIdentity
|
|
24
24
|
};
|
|
25
|
-
//# sourceMappingURL=auto-compaction-
|
|
25
|
+
//# sourceMappingURL=auto-compaction-JZIM73ZY.js.map
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import {
|
|
2
|
+
buildRunChatTurnParams,
|
|
3
|
+
finalizeTurnCompletion,
|
|
4
|
+
getSessionMessageCount
|
|
5
|
+
} from "./chunk-SN7OBEVL.js";
|
|
6
|
+
import {
|
|
7
|
+
applyGeneratedSessionName,
|
|
2
8
|
generateSessionName,
|
|
3
|
-
|
|
4
|
-
} from "./chunk-
|
|
9
|
+
needsNameGenerationCheck
|
|
10
|
+
} from "./chunk-F54ZJN4X.js";
|
|
5
11
|
import {
|
|
6
12
|
runChatTurn
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
13
|
+
} from "./chunk-YM6VHAPM.js";
|
|
14
|
+
import "./chunk-3WHZ47PY.js";
|
|
9
15
|
import "./chunk-NBU6KIOD.js";
|
|
10
16
|
import "./chunk-574HZVLE.js";
|
|
11
|
-
import "./chunk-
|
|
12
|
-
import {
|
|
13
|
-
getEventStore,
|
|
14
|
-
updateSessionMetadata
|
|
15
|
-
} from "./chunk-ZRDRYL6W.js";
|
|
17
|
+
import "./chunk-55N6FAAZ.js";
|
|
16
18
|
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
getEventStore
|
|
20
|
+
} from "./chunk-6L3X7T4K.js";
|
|
21
|
+
import "./chunk-2KP34IDL.js";
|
|
20
22
|
import {
|
|
21
23
|
createChatMessageMessage,
|
|
22
|
-
createContextStateMessage,
|
|
23
24
|
createPhaseChangedMessage,
|
|
24
|
-
createSessionRunningMessage
|
|
25
|
-
createSessionStateMessage
|
|
25
|
+
createSessionRunningMessage
|
|
26
26
|
} from "./chunk-NJWPSSRW.js";
|
|
27
|
-
import "./chunk-
|
|
27
|
+
import "./chunk-22CTURMH.js";
|
|
28
28
|
import "./chunk-7IOZFJBW.js";
|
|
29
29
|
import "./chunk-XKFPU2FA.js";
|
|
30
30
|
import "./chunk-3EHGGBWE.js";
|
|
@@ -61,7 +61,7 @@ async function startChatSession(sessionId, content, deps, options) {
|
|
|
61
61
|
sessionManager.setRunning(sessionId, true);
|
|
62
62
|
broadcastForSession(sessionId, createSessionRunningMessage(true));
|
|
63
63
|
try {
|
|
64
|
-
const { maybeAutoCompactContext } = await import("./auto-compaction-
|
|
64
|
+
const { maybeAutoCompactContext } = await import("./auto-compaction-JZIM73ZY.js");
|
|
65
65
|
await maybeAutoCompactContext({
|
|
66
66
|
sessionManager,
|
|
67
67
|
sessionId,
|
|
@@ -82,13 +82,7 @@ async function startChatSession(sessionId, content, deps, options) {
|
|
|
82
82
|
broadcastForSession(sessionId, createChatMessageMessage(userMessage));
|
|
83
83
|
const messageCount = getSessionMessageCount(sessionId);
|
|
84
84
|
const currentSession = sessionManager.getSession(sessionId);
|
|
85
|
-
|
|
86
|
-
sessionId,
|
|
87
|
-
title: currentSession?.metadata.title,
|
|
88
|
-
messageCount,
|
|
89
|
-
needsGeneration: currentSession ? needsNameGeneration(currentSession.metadata.title, messageCount) : false
|
|
90
|
-
});
|
|
91
|
-
if (currentSession && needsNameGeneration(currentSession.metadata.title, messageCount)) {
|
|
85
|
+
if (currentSession && needsNameGenerationCheck(sessionId, currentSession.metadata.title, messageCount)) {
|
|
92
86
|
generateSessionName({
|
|
93
87
|
userMessage: content,
|
|
94
88
|
llmClient,
|
|
@@ -101,18 +95,11 @@ async function startChatSession(sessionId, content, deps, options) {
|
|
|
101
95
|
error: result.error
|
|
102
96
|
});
|
|
103
97
|
if (result.success && result.name) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
98
|
+
applyGeneratedSessionName(sessionId, result.name, {
|
|
99
|
+
sessionManager,
|
|
100
|
+
eventStore,
|
|
101
|
+
broadcastForSession
|
|
108
102
|
});
|
|
109
|
-
const updatedSession = sessionManager.getSession(sessionId);
|
|
110
|
-
if (updatedSession) {
|
|
111
|
-
const events = eventStore.getEvents(sessionId);
|
|
112
|
-
const messages = buildMessagesFromStoredEvents(events);
|
|
113
|
-
const pendingConfirmations = foldPendingConfirmations(events);
|
|
114
|
-
broadcastForSession(sessionId, createSessionStateMessage(updatedSession, messages, pendingConfirmations));
|
|
115
|
-
}
|
|
116
103
|
}
|
|
117
104
|
}).catch((error) => {
|
|
118
105
|
logger.error("Session name generation failed", {
|
|
@@ -128,35 +115,20 @@ async function startChatSession(sessionId, content, deps, options) {
|
|
|
128
115
|
}
|
|
129
116
|
sessionManager.setRunning(sessionId, false);
|
|
130
117
|
broadcastForSession(sessionId, createSessionRunningMessage(false));
|
|
131
|
-
|
|
132
|
-
broadcastForSession(sessionId, createContextStateMessage(contextState));
|
|
118
|
+
finalizeTurnCompletion(sessionId, sessionManager, broadcastForSession);
|
|
133
119
|
throw error;
|
|
134
120
|
}
|
|
135
121
|
}
|
|
136
|
-
function getSessionMessageCount(sessionId) {
|
|
137
|
-
const eventStore = getEventStore();
|
|
138
|
-
const events = eventStore.getEvents(sessionId);
|
|
139
|
-
let count = 0;
|
|
140
|
-
for (const event of events) {
|
|
141
|
-
if (event.type === "message.start") {
|
|
142
|
-
const data = event.data;
|
|
143
|
-
if (data.role === "user") {
|
|
144
|
-
count++;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return count;
|
|
149
|
-
}
|
|
150
122
|
function startTurnWithCompletionChain(sessionId, controller, deps) {
|
|
151
123
|
const { sessionManager, llmClient, statsIdentity, broadcastForSession } = deps;
|
|
152
|
-
runChatTurn({
|
|
124
|
+
runChatTurn(buildRunChatTurnParams({
|
|
153
125
|
sessionManager,
|
|
154
126
|
sessionId,
|
|
155
127
|
llmClient,
|
|
156
128
|
statsIdentity,
|
|
157
129
|
signal: controller.signal,
|
|
158
130
|
onMessage: (msg) => broadcastForSession(sessionId, msg)
|
|
159
|
-
}).catch((error) => {
|
|
131
|
+
})).catch((error) => {
|
|
160
132
|
if (error instanceof Error && error.message === "Aborted") {
|
|
161
133
|
return;
|
|
162
134
|
}
|
|
@@ -183,9 +155,7 @@ function startTurnWithCompletionChain(sessionId, controller, deps) {
|
|
|
183
155
|
return;
|
|
184
156
|
}
|
|
185
157
|
sessionManager.clearMessageQueue(sessionId);
|
|
186
|
-
|
|
187
|
-
const contextState = sessionManager.getContextState(sessionId);
|
|
188
|
-
broadcastForSession(sessionId, createContextStateMessage(contextState));
|
|
158
|
+
finalizeTurnCompletion(sessionId, sessionManager, broadcastForSession);
|
|
189
159
|
});
|
|
190
160
|
}
|
|
191
161
|
function stopSessionExecution(sessionId, sessionManager) {
|
|
@@ -200,4 +170,4 @@ export {
|
|
|
200
170
|
startChatSession,
|
|
201
171
|
stopSessionExecution
|
|
202
172
|
};
|
|
203
|
-
//# sourceMappingURL=chat-handler-
|
|
173
|
+
//# sourceMappingURL=chat-handler-F2A2IMQB.js.map
|
|
@@ -76,8 +76,6 @@ var AskUserInterrupt = class extends Error {
|
|
|
76
76
|
this.question = question;
|
|
77
77
|
this.name = "AskUserInterrupt";
|
|
78
78
|
}
|
|
79
|
-
callId;
|
|
80
|
-
question;
|
|
81
79
|
};
|
|
82
80
|
function provideAnswer(callId, answer) {
|
|
83
81
|
const pending = pendingQuestions.get(callId);
|
|
@@ -127,4 +125,4 @@ export {
|
|
|
127
125
|
hasPendingQuestion,
|
|
128
126
|
awaitAnswer
|
|
129
127
|
};
|
|
130
|
-
//# sourceMappingURL=chunk-
|
|
128
|
+
//# sourceMappingURL=chunk-22CTURMH.js.map
|
|
@@ -1,151 +1,91 @@
|
|
|
1
|
-
// src/server/events/
|
|
2
|
-
function
|
|
1
|
+
// src/server/events/apply-events.ts
|
|
2
|
+
function extractMessageOptionalFields(data) {
|
|
3
3
|
return {
|
|
4
|
-
...
|
|
5
|
-
...
|
|
6
|
-
...
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
...message.segments ? { segments: [...message.segments] } : {},
|
|
14
|
-
...message.preparingToolCalls ? { preparingToolCalls: [...message.preparingToolCalls] } : {}
|
|
4
|
+
...data.tokenCount !== void 0 && { tokenCount: data.tokenCount },
|
|
5
|
+
...data.contextWindowId !== void 0 && { contextWindowId: data.contextWindowId },
|
|
6
|
+
...data.subAgentId !== void 0 && { subAgentId: data.subAgentId },
|
|
7
|
+
...data.subAgentType !== void 0 && { subAgentType: data.subAgentType },
|
|
8
|
+
...data.isSystemGenerated !== void 0 && { isSystemGenerated: data.isSystemGenerated },
|
|
9
|
+
...data.messageKind !== void 0 && { messageKind: data.messageKind },
|
|
10
|
+
...data.isCompactionSummary !== void 0 && { isCompactionSummary: data.isCompactionSummary },
|
|
11
|
+
...data.attachments !== void 0 && { attachments: data.attachments },
|
|
12
|
+
...data.metadata !== void 0 && { metadata: data.metadata }
|
|
15
13
|
};
|
|
16
14
|
}
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
content: message.content,
|
|
22
|
-
timestamp: new Date(message.timestamp).toISOString(),
|
|
23
|
-
...message.tokenCount !== void 0 && { tokenCount: message.tokenCount },
|
|
24
|
-
...message.isStreaming !== void 0 && { isStreaming: message.isStreaming },
|
|
25
|
-
...message.contextWindowId !== void 0 && { contextWindowId: message.contextWindowId },
|
|
26
|
-
...message.subAgentId !== void 0 && { subAgentId: message.subAgentId },
|
|
27
|
-
...message.subAgentType !== void 0 && { subAgentType: message.subAgentType },
|
|
28
|
-
...message.isSystemGenerated !== void 0 && { isSystemGenerated: message.isSystemGenerated },
|
|
29
|
-
...message.messageKind !== void 0 && { messageKind: message.messageKind },
|
|
30
|
-
...message.isCompactionSummary !== void 0 && { isCompactionSummary: message.isCompactionSummary },
|
|
31
|
-
...message.attachments !== void 0 && { attachments: message.attachments },
|
|
32
|
-
...message.thinkingContent !== void 0 && { thinkingContent: message.thinkingContent },
|
|
33
|
-
...message.toolCalls !== void 0 && { toolCalls: message.toolCalls },
|
|
34
|
-
...message.segments !== void 0 && { segments: message.segments },
|
|
35
|
-
...message.stats !== void 0 && { stats: message.stats },
|
|
36
|
-
...message.partial !== void 0 && { partial: message.partial },
|
|
37
|
-
...message.promptContext !== void 0 && { promptContext: message.promptContext },
|
|
38
|
-
...message.metadata !== void 0 && { metadata: message.metadata }
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
function shouldIncludeContextMessage(message, windowId, options) {
|
|
42
|
-
const includeVerifier = options?.includeVerifier ?? true;
|
|
43
|
-
return message.role !== "system" && (windowId === void 0 || message.contextWindowId === windowId) && (includeVerifier || message.subAgentType !== "verifier") && !message.subAgentId;
|
|
15
|
+
function attachToolCallToMessage(msg, toolCall) {
|
|
16
|
+
const existing = msg.toolCalls ?? [];
|
|
17
|
+
const newTc = { ...toolCall };
|
|
18
|
+
msg.toolCalls = [...existing, newTc];
|
|
44
19
|
}
|
|
45
|
-
function
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (message.toolCalls && message.toolCalls.length > 0) {
|
|
51
|
-
contextMsg.toolCalls = message.toolCalls.map((toolCall) => ({
|
|
52
|
-
id: toolCall.id,
|
|
53
|
-
name: toolCall.name,
|
|
54
|
-
arguments: toolCall.arguments
|
|
55
|
-
}));
|
|
56
|
-
}
|
|
57
|
-
if (message.attachments !== void 0) {
|
|
58
|
-
contextMsg.attachments = message.attachments;
|
|
59
|
-
}
|
|
60
|
-
result.push(contextMsg);
|
|
61
|
-
if (!message.toolCalls) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
for (const toolCall of message.toolCalls) {
|
|
65
|
-
if (!toolCall.result) {
|
|
66
|
-
continue;
|
|
20
|
+
function attachToolResultToMessage(msg, toolCallId, result) {
|
|
21
|
+
if (msg.toolCalls) {
|
|
22
|
+
const toolCall = msg.toolCalls.find((tc) => tc.id === toolCallId);
|
|
23
|
+
if (toolCall) {
|
|
24
|
+
toolCall.result = result;
|
|
67
25
|
}
|
|
68
|
-
result.push({
|
|
69
|
-
role: "tool",
|
|
70
|
-
content: toolCall.result.success ? toolCall.result.output ?? "Success" : toolCall.result.output ? `${toolCall.result.output}
|
|
71
|
-
|
|
72
|
-
Error: ${toolCall.result.error}` : `Error: ${toolCall.result.error}`,
|
|
73
|
-
toolCallId: toolCall.id
|
|
74
|
-
});
|
|
75
26
|
}
|
|
76
27
|
}
|
|
77
|
-
function
|
|
78
|
-
|
|
28
|
+
function updateMessageDelta(msg, content) {
|
|
29
|
+
msg.content += content;
|
|
30
|
+
}
|
|
31
|
+
function updateMessageThinking(msg, content) {
|
|
32
|
+
msg.thinkingContent = (msg.thinkingContent ?? "") + content;
|
|
33
|
+
}
|
|
34
|
+
function updateMessageDone(msg, data) {
|
|
35
|
+
msg.isStreaming = false;
|
|
36
|
+
if (data.stats) msg.stats = data.stats;
|
|
37
|
+
if (data.segments) msg.segments = data.segments;
|
|
38
|
+
if (data.partial) msg.partial = true;
|
|
39
|
+
if (data.promptContext) msg.promptContext = data.promptContext;
|
|
40
|
+
if (data.tokenCount !== void 0) msg.tokenCount = data.tokenCount;
|
|
41
|
+
}
|
|
42
|
+
function applyEvents(initialMessages, events, options) {
|
|
43
|
+
const messages = new Map(initialMessages.map((message) => [message.id, deepCloneMessage(message)]));
|
|
79
44
|
for (const event of events) {
|
|
80
45
|
switch (event.type) {
|
|
81
46
|
case "message.start": {
|
|
82
47
|
const data = event.data;
|
|
83
48
|
const isUserOrSystem = data.role === "user" || data.role === "system";
|
|
49
|
+
const timestamp = options.timestampAsNumber ? typeof event.timestamp === "number" ? event.timestamp : Date.now() : new Date(event.timestamp).toISOString();
|
|
84
50
|
messages.set(data.messageId, {
|
|
85
51
|
id: data.messageId,
|
|
86
52
|
role: data.role,
|
|
87
53
|
content: data.content ?? "",
|
|
88
|
-
timestamp
|
|
89
|
-
tokenCount: data.tokenCount ?? 0,
|
|
54
|
+
timestamp,
|
|
90
55
|
isStreaming: !isUserOrSystem,
|
|
91
|
-
|
|
92
|
-
...data
|
|
93
|
-
...data.subAgentType !== void 0 && { subAgentType: data.subAgentType },
|
|
94
|
-
...data.isSystemGenerated !== void 0 && { isSystemGenerated: data.isSystemGenerated },
|
|
95
|
-
...data.messageKind !== void 0 && { messageKind: data.messageKind },
|
|
96
|
-
...data.isCompactionSummary !== void 0 && { isCompactionSummary: data.isCompactionSummary },
|
|
97
|
-
...data.attachments !== void 0 && { attachments: data.attachments },
|
|
98
|
-
...data.metadata !== void 0 && { metadata: data.metadata }
|
|
56
|
+
tokenCount: data.tokenCount ?? 0,
|
|
57
|
+
...extractMessageOptionalFields(data)
|
|
99
58
|
});
|
|
100
59
|
break;
|
|
101
60
|
}
|
|
102
61
|
case "message.delta": {
|
|
103
62
|
const data = event.data;
|
|
104
63
|
const msg = messages.get(data.messageId);
|
|
105
|
-
if (msg)
|
|
106
|
-
msg.content += data.content;
|
|
107
|
-
}
|
|
64
|
+
if (msg) updateMessageDelta(msg, data.content);
|
|
108
65
|
break;
|
|
109
66
|
}
|
|
110
67
|
case "message.thinking": {
|
|
111
68
|
const data = event.data;
|
|
112
69
|
const msg = messages.get(data.messageId);
|
|
113
|
-
if (msg)
|
|
114
|
-
msg.thinkingContent = (msg.thinkingContent ?? "") + data.content;
|
|
115
|
-
}
|
|
70
|
+
if (msg) updateMessageThinking(msg, data.content);
|
|
116
71
|
break;
|
|
117
72
|
}
|
|
118
73
|
case "message.done": {
|
|
119
74
|
const data = event.data;
|
|
120
75
|
const msg = messages.get(data.messageId);
|
|
121
|
-
if (msg)
|
|
122
|
-
msg.isStreaming = false;
|
|
123
|
-
if (data.stats) msg.stats = data.stats;
|
|
124
|
-
if (data.segments) msg.segments = data.segments;
|
|
125
|
-
if (data.partial) msg.partial = data.partial;
|
|
126
|
-
if (data.promptContext) msg.promptContext = data.promptContext;
|
|
127
|
-
if (data.tokenCount !== void 0) msg.tokenCount = data.tokenCount;
|
|
128
|
-
}
|
|
76
|
+
if (msg) updateMessageDone(msg, data);
|
|
129
77
|
break;
|
|
130
78
|
}
|
|
131
79
|
case "tool.call": {
|
|
132
80
|
const data = event.data;
|
|
133
81
|
const msg = messages.get(data.messageId);
|
|
134
|
-
if (msg)
|
|
135
|
-
const existingToolCalls = msg.toolCalls ?? [];
|
|
136
|
-
msg.toolCalls = [...existingToolCalls, data.toolCall];
|
|
137
|
-
}
|
|
82
|
+
if (msg) attachToolCallToMessage(msg, data.toolCall);
|
|
138
83
|
break;
|
|
139
84
|
}
|
|
140
85
|
case "tool.result": {
|
|
141
86
|
const data = event.data;
|
|
142
87
|
const msg = messages.get(data.messageId);
|
|
143
|
-
if (msg
|
|
144
|
-
const toolCall = msg.toolCalls.find((tc) => tc.id === data.toolCallId);
|
|
145
|
-
if (toolCall) {
|
|
146
|
-
toolCall.result = data.result;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
88
|
+
if (msg) attachToolResultToMessage(msg, data.toolCallId, data.result);
|
|
149
89
|
break;
|
|
150
90
|
}
|
|
151
91
|
case "session.initialized":
|
|
@@ -169,7 +109,48 @@ function applyStoredMessageEvents(initialMessages, events) {
|
|
|
169
109
|
}
|
|
170
110
|
return Array.from(messages.values());
|
|
171
111
|
}
|
|
172
|
-
function
|
|
112
|
+
function deepCloneMessage(msg) {
|
|
113
|
+
const cloned = { ...msg };
|
|
114
|
+
const obj = cloned;
|
|
115
|
+
if (obj["toolCalls"]) {
|
|
116
|
+
obj["toolCalls"] = obj["toolCalls"].map((tc) => ({ ...tc, ...tc.result ? { result: { ...tc.result } } : {} }));
|
|
117
|
+
}
|
|
118
|
+
if (obj["segments"]) {
|
|
119
|
+
obj["segments"] = [...obj["segments"]];
|
|
120
|
+
}
|
|
121
|
+
if (obj["attachments"]) {
|
|
122
|
+
obj["attachments"] = [...obj["attachments"]];
|
|
123
|
+
}
|
|
124
|
+
return cloned;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// src/server/events/optimize-storage.ts
|
|
128
|
+
function stripPromptContextMessages(messages) {
|
|
129
|
+
let lastAssistantIdx = -1;
|
|
130
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
131
|
+
const msg = messages[i];
|
|
132
|
+
if (!msg) continue;
|
|
133
|
+
if (msg.role === "assistant" && msg.promptContext) {
|
|
134
|
+
lastAssistantIdx = i;
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
let changed = false;
|
|
139
|
+
for (let i = 0; i < messages.length; i++) {
|
|
140
|
+
const msg = messages[i];
|
|
141
|
+
if (!msg) continue;
|
|
142
|
+
const pc = msg.promptContext;
|
|
143
|
+
if (pc && pc.messages && pc.messages.length > 0 && i !== lastAssistantIdx) {
|
|
144
|
+
pc.messages = [];
|
|
145
|
+
changed = true;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return changed;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// src/server/events/folding.ts
|
|
152
|
+
import stripAnsi from "strip-ansi";
|
|
153
|
+
function cloneMessage(message) {
|
|
173
154
|
return {
|
|
174
155
|
...message,
|
|
175
156
|
...message.attachments ? { attachments: [...message.attachments] } : {},
|
|
@@ -180,86 +161,81 @@ function cloneSnapshotMessage(message) {
|
|
|
180
161
|
...toolCall.result ? { result: { ...toolCall.result } } : {}
|
|
181
162
|
}))
|
|
182
163
|
} : {},
|
|
183
|
-
...message.segments ? { segments: [...message.segments] } : {}
|
|
164
|
+
...message.segments ? { segments: [...message.segments] } : {},
|
|
165
|
+
...message.preparingToolCalls ? { preparingToolCalls: [...message.preparingToolCalls] } : {}
|
|
184
166
|
};
|
|
185
167
|
}
|
|
186
|
-
function
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
const data = event.data;
|
|
242
|
-
const msg = messages.get(data.messageId);
|
|
243
|
-
if (msg) {
|
|
244
|
-
const toolCalls = msg.toolCalls ?? [];
|
|
245
|
-
msg.toolCalls = [...toolCalls, data.toolCall];
|
|
246
|
-
}
|
|
247
|
-
break;
|
|
248
|
-
}
|
|
249
|
-
case "tool.result": {
|
|
250
|
-
const data = event.data;
|
|
251
|
-
const msg = messages.get(data.messageId);
|
|
252
|
-
if (msg?.toolCalls) {
|
|
253
|
-
const toolCall = msg.toolCalls.find((tc) => tc.id === data.toolCallId);
|
|
254
|
-
if (toolCall) {
|
|
255
|
-
toolCall.result = data.result;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
break;
|
|
259
|
-
}
|
|
168
|
+
function spreadOptionalMessageFields(message) {
|
|
169
|
+
return {
|
|
170
|
+
...message.thinkingContent !== void 0 && { thinkingContent: message.thinkingContent },
|
|
171
|
+
...message.toolCalls !== void 0 && { toolCalls: message.toolCalls },
|
|
172
|
+
...message.segments !== void 0 && { segments: message.segments },
|
|
173
|
+
...message.stats !== void 0 && { stats: message.stats },
|
|
174
|
+
...message.tokenCount !== void 0 && { tokenCount: message.tokenCount },
|
|
175
|
+
...message.isStreaming !== void 0 && { isStreaming: message.isStreaming },
|
|
176
|
+
...message.partial !== void 0 && { partial: message.partial },
|
|
177
|
+
...message.subAgentId !== void 0 && { subAgentId: message.subAgentId },
|
|
178
|
+
...message.subAgentType !== void 0 && { subAgentType: message.subAgentType },
|
|
179
|
+
...message.isSystemGenerated !== void 0 && { isSystemGenerated: message.isSystemGenerated },
|
|
180
|
+
...message.messageKind !== void 0 && { messageKind: message.messageKind },
|
|
181
|
+
...message.contextWindowId !== void 0 && { contextWindowId: message.contextWindowId },
|
|
182
|
+
...message.isCompactionSummary !== void 0 && { isCompactionSummary: message.isCompactionSummary },
|
|
183
|
+
...message.promptContext !== void 0 && { promptContext: message.promptContext },
|
|
184
|
+
...message.attachments !== void 0 && { attachments: message.attachments },
|
|
185
|
+
...message.metadata !== void 0 && { metadata: message.metadata }
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function snapshotMessageToMessage(message) {
|
|
189
|
+
return cloneMessage({
|
|
190
|
+
id: message.id,
|
|
191
|
+
role: message.role,
|
|
192
|
+
content: message.content,
|
|
193
|
+
timestamp: new Date(message.timestamp).toISOString(),
|
|
194
|
+
...spreadOptionalMessageFields(message)
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
function shouldIncludeContextMessage(message, windowId, options) {
|
|
198
|
+
const includeVerifier = options?.includeVerifier ?? true;
|
|
199
|
+
return message.role !== "system" && (windowId === void 0 || message.contextWindowId === windowId) && (includeVerifier || message.subAgentType !== "verifier") && !message.subAgentId;
|
|
200
|
+
}
|
|
201
|
+
function appendSnapshotMessageContext(result, message) {
|
|
202
|
+
const contextMsg = {
|
|
203
|
+
role: message.role,
|
|
204
|
+
content: message.content
|
|
205
|
+
};
|
|
206
|
+
if (message.toolCalls && message.toolCalls.length > 0) {
|
|
207
|
+
contextMsg.toolCalls = message.toolCalls.map((toolCall) => ({
|
|
208
|
+
id: toolCall.id,
|
|
209
|
+
name: toolCall.name,
|
|
210
|
+
arguments: toolCall.arguments
|
|
211
|
+
}));
|
|
212
|
+
}
|
|
213
|
+
if (message.attachments !== void 0) {
|
|
214
|
+
contextMsg.attachments = message.attachments;
|
|
215
|
+
}
|
|
216
|
+
result.push(contextMsg);
|
|
217
|
+
if (!message.toolCalls) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
for (const toolCall of message.toolCalls) {
|
|
221
|
+
if (!toolCall.result) {
|
|
222
|
+
continue;
|
|
260
223
|
}
|
|
224
|
+
result.push({
|
|
225
|
+
role: "tool",
|
|
226
|
+
content: stripAnsi(toolCall.result.success ? toolCall.result.output ?? "Success" : toolCall.result.output ? `${toolCall.result.output}
|
|
227
|
+
|
|
228
|
+
Error: ${toolCall.result.error}` : `Error: ${toolCall.result.error}`),
|
|
229
|
+
toolCallId: toolCall.id
|
|
230
|
+
});
|
|
261
231
|
}
|
|
262
|
-
|
|
232
|
+
}
|
|
233
|
+
function applyStoredMessageEvents(initialMessages, events) {
|
|
234
|
+
return applyEvents(initialMessages, events, { timestampAsNumber: false });
|
|
235
|
+
}
|
|
236
|
+
function applyTurnEventsToSnapshotMessages(initialMessages, events) {
|
|
237
|
+
const messages = applyEvents(initialMessages, events, { timestampAsNumber: true });
|
|
238
|
+
return messages.map((msg) => ({ ...msg, isStreaming: msg.isStreaming ?? true }));
|
|
263
239
|
}
|
|
264
240
|
function buildMessagesFromStoredEvents(events) {
|
|
265
241
|
const snapshotEvent = [...events].reverse().find((event) => event.type === "turn.snapshot");
|
|
@@ -315,9 +291,9 @@ function buildContextMessagesFromStoredEvents(events, windowId, options) {
|
|
|
315
291
|
const msg = {
|
|
316
292
|
id: `tool-${data.toolCallId}`,
|
|
317
293
|
role: "tool",
|
|
318
|
-
content: data.result.success ? data.result.output ?? "Success" : data.result.output ? `${data.result.output}
|
|
294
|
+
content: stripAnsi(data.result.success ? data.result.output ?? "Success" : data.result.output ? `${data.result.output}
|
|
319
295
|
|
|
320
|
-
Error: ${data.result.error}` : `Error: ${data.result.error}
|
|
296
|
+
Error: ${data.result.error}` : `Error: ${data.result.error}`),
|
|
321
297
|
toolCallId: data.toolCallId
|
|
322
298
|
};
|
|
323
299
|
if (imageMeta?.dataUrl && imageMeta?.mimeType?.startsWith("image/")) {
|
|
@@ -585,26 +561,6 @@ function buildSnapshot(foldedState, latestSeq, snapshotAt = Date.now()) {
|
|
|
585
561
|
snapshotAt
|
|
586
562
|
};
|
|
587
563
|
}
|
|
588
|
-
function stripPromptContextMessages(messages) {
|
|
589
|
-
let lastAssistantIdx = -1;
|
|
590
|
-
for (let i = messages.length - 1; i >= 0; i--) {
|
|
591
|
-
const msg = messages[i];
|
|
592
|
-
if (!msg) continue;
|
|
593
|
-
if (msg.role === "assistant" && msg.promptContext) {
|
|
594
|
-
lastAssistantIdx = i;
|
|
595
|
-
break;
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
for (let i = 0; i < messages.length; i++) {
|
|
599
|
-
const msg = messages[i];
|
|
600
|
-
if (!msg) continue;
|
|
601
|
-
const pc = msg.promptContext;
|
|
602
|
-
if (pc && i !== lastAssistantIdx) {
|
|
603
|
-
const { messages: _msgs, ...rest } = pc;
|
|
604
|
-
msg.promptContext = { ...rest, messages: [] };
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
564
|
function buildSnapshotFromSessionState(input) {
|
|
609
565
|
const { session, events, latestSeq, snapshotAt = Date.now(), maxTokens = 2e5 } = input;
|
|
610
566
|
let initialWindowId = "";
|
|
@@ -660,6 +616,8 @@ function buildContextMessagesFromMessages(messages, windowId) {
|
|
|
660
616
|
}
|
|
661
617
|
|
|
662
618
|
export {
|
|
619
|
+
stripPromptContextMessages,
|
|
620
|
+
spreadOptionalMessageFields,
|
|
663
621
|
buildMessagesFromStoredEvents,
|
|
664
622
|
buildContextMessagesFromStoredEvents,
|
|
665
623
|
buildContextMessagesFromEventHistory,
|
|
@@ -677,4 +635,4 @@ export {
|
|
|
677
635
|
getMessagesForWindow,
|
|
678
636
|
buildContextMessagesFromMessages
|
|
679
637
|
};
|
|
680
|
-
//# sourceMappingURL=chunk-
|
|
638
|
+
//# sourceMappingURL=chunk-2KP34IDL.js.map
|