kimiflare 0.18.0 → 0.19.0
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/index.js +34 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -39,6 +39,8 @@ async function loadConfig() {
|
|
|
39
39
|
const cacheStablePrompts = envCacheStable === "0" || envCacheStable === "false" ? false : true;
|
|
40
40
|
const envCompiled = process.env.KIMIFLARE_COMPILED_CONTEXT;
|
|
41
41
|
const compiledContext = envCompiled === "1" || envCompiled === "true" ? true : false;
|
|
42
|
+
const envImageTurns = process.env.KIMIFLARE_IMAGE_HISTORY_TURNS;
|
|
43
|
+
const imageHistoryTurns = envImageTurns ? parseInt(envImageTurns, 10) : void 0;
|
|
42
44
|
if (envAccount && envToken) {
|
|
43
45
|
return {
|
|
44
46
|
accountId: envAccount,
|
|
@@ -50,7 +52,8 @@ async function loadConfig() {
|
|
|
50
52
|
coauthorName: envCoauthor?.name,
|
|
51
53
|
coauthorEmail: envCoauthor?.email,
|
|
52
54
|
cacheStablePrompts,
|
|
53
|
-
compiledContext
|
|
55
|
+
compiledContext,
|
|
56
|
+
imageHistoryTurns: Number.isNaN(imageHistoryTurns) ? void 0 : imageHistoryTurns
|
|
54
57
|
};
|
|
55
58
|
}
|
|
56
59
|
try {
|
|
@@ -68,7 +71,8 @@ async function loadConfig() {
|
|
|
68
71
|
coauthorEmail: envCoauthor?.email ?? parsed.coauthorEmail,
|
|
69
72
|
mcpServers: parsed.mcpServers,
|
|
70
73
|
cacheStablePrompts: parsed.cacheStablePrompts ?? cacheStablePrompts,
|
|
71
|
-
compiledContext: parsed.compiledContext ?? compiledContext
|
|
74
|
+
compiledContext: parsed.compiledContext ?? compiledContext,
|
|
75
|
+
imageHistoryTurns: Number.isNaN(imageHistoryTurns) ? parsed.imageHistoryTurns : imageHistoryTurns
|
|
72
76
|
};
|
|
73
77
|
}
|
|
74
78
|
} catch {
|
|
@@ -175,6 +179,30 @@ function stableStringify(value, replacer, space) {
|
|
|
175
179
|
const sorted = sortKeys(value);
|
|
176
180
|
return JSON.stringify(sorted, replacer, space);
|
|
177
181
|
}
|
|
182
|
+
function stripOldImages(messages, keepLastTurns) {
|
|
183
|
+
if (keepLastTurns < 0) return messages;
|
|
184
|
+
let userCount = 0;
|
|
185
|
+
let cutoffIndex = messages.length;
|
|
186
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
187
|
+
if (messages[i].role === "user") {
|
|
188
|
+
userCount++;
|
|
189
|
+
if (userCount === keepLastTurns) {
|
|
190
|
+
cutoffIndex = i;
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return messages.map((m, idx) => {
|
|
196
|
+
if (m.role !== "user" || idx >= cutoffIndex) return m;
|
|
197
|
+
if (!Array.isArray(m.content)) return m;
|
|
198
|
+
const stripped = m.content.filter((p) => p.type !== "image_url");
|
|
199
|
+
if (stripped.length === m.content.length) return m;
|
|
200
|
+
return {
|
|
201
|
+
...m,
|
|
202
|
+
content: stripped.length > 0 ? stripped : "[image omitted]"
|
|
203
|
+
};
|
|
204
|
+
});
|
|
205
|
+
}
|
|
178
206
|
var init_messages = __esm({
|
|
179
207
|
"src/agent/messages.ts"() {
|
|
180
208
|
"use strict";
|
|
@@ -760,6 +788,9 @@ async function runAgentTurn(opts2) {
|
|
|
760
788
|
apiMessages = stripped;
|
|
761
789
|
}
|
|
762
790
|
}
|
|
791
|
+
if (opts2.keepLastImageTurns !== void 0) {
|
|
792
|
+
apiMessages = stripOldImages(apiMessages, opts2.keepLastImageTurns);
|
|
793
|
+
}
|
|
763
794
|
const events = runKimi({
|
|
764
795
|
accountId: opts2.accountId,
|
|
765
796
|
apiToken: opts2.apiToken,
|
|
@@ -6071,6 +6102,7 @@ use: /thinking low | medium | high`
|
|
|
6071
6102
|
reasoningEffort: effortRef.current,
|
|
6072
6103
|
coauthor: cfg.coauthor !== false ? { name: cfg.coauthorName || "kimiflare", email: cfg.coauthorEmail || "kimiflare@proton.me" } : void 0,
|
|
6073
6104
|
sessionId: ensureSessionId(),
|
|
6105
|
+
keepLastImageTurns: cfg.imageHistoryTurns ?? 2,
|
|
6074
6106
|
callbacks: {
|
|
6075
6107
|
onAssistantStart: () => {
|
|
6076
6108
|
const id = nextAssistantId++;
|