kimiflare 0.88.0 → 0.88.2
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 +125 -48
- package/dist/index.js.map +1 -1
- package/dist/sdk/index.js +86 -40
- package/dist/sdk/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3418,15 +3418,87 @@ async function fetchWithRetry(url, init, retries = 3) {
|
|
|
3418
3418
|
}
|
|
3419
3419
|
throw lastError ?? new Error("embeddings request failed after retries");
|
|
3420
3420
|
}
|
|
3421
|
+
function parseOpenAiEmbeddingResponse(json2) {
|
|
3422
|
+
if (!json2 || typeof json2 !== "object") {
|
|
3423
|
+
throw new Error("embeddings response was not an object");
|
|
3424
|
+
}
|
|
3425
|
+
const data = json2.data;
|
|
3426
|
+
if (!Array.isArray(data)) {
|
|
3427
|
+
throw new Error("embeddings response contained no data array");
|
|
3428
|
+
}
|
|
3429
|
+
const indexed = [];
|
|
3430
|
+
for (const item of data) {
|
|
3431
|
+
if (!item || typeof item !== "object") continue;
|
|
3432
|
+
const embedding = item.embedding;
|
|
3433
|
+
const idx = item.index;
|
|
3434
|
+
if (!Array.isArray(embedding)) continue;
|
|
3435
|
+
indexed.push({
|
|
3436
|
+
index: typeof idx === "number" ? idx : indexed.length,
|
|
3437
|
+
vector: new Float32Array(embedding)
|
|
3438
|
+
});
|
|
3439
|
+
}
|
|
3440
|
+
if (indexed.length === 0) {
|
|
3441
|
+
throw new Error("embeddings response contained no vectors");
|
|
3442
|
+
}
|
|
3443
|
+
indexed.sort((a, b) => a.index - b.index);
|
|
3444
|
+
return indexed.map((item) => {
|
|
3445
|
+
if (item.vector.length === 0) {
|
|
3446
|
+
throw new Error("embeddings response contained empty vector");
|
|
3447
|
+
}
|
|
3448
|
+
return item.vector;
|
|
3449
|
+
});
|
|
3450
|
+
}
|
|
3451
|
+
function parseWorkersAiEmbeddingResponse(json2) {
|
|
3452
|
+
let vectors = [];
|
|
3453
|
+
if (json2 && typeof json2 === "object") {
|
|
3454
|
+
const result = json2.result;
|
|
3455
|
+
if (result && typeof result === "object") {
|
|
3456
|
+
const data = result.data;
|
|
3457
|
+
if (Array.isArray(data)) {
|
|
3458
|
+
if (Array.isArray(data[0])) {
|
|
3459
|
+
vectors = data;
|
|
3460
|
+
} else {
|
|
3461
|
+
const shape = result.shape;
|
|
3462
|
+
if (shape && shape.length === 2) {
|
|
3463
|
+
const dim = shape[1];
|
|
3464
|
+
const flat = data;
|
|
3465
|
+
vectors = [];
|
|
3466
|
+
for (let i = 0; i < flat.length; i += dim) {
|
|
3467
|
+
vectors.push(flat.slice(i, i + dim));
|
|
3468
|
+
}
|
|
3469
|
+
}
|
|
3470
|
+
}
|
|
3471
|
+
}
|
|
3472
|
+
}
|
|
3473
|
+
}
|
|
3474
|
+
if (vectors.length === 0) {
|
|
3475
|
+
throw new Error("embeddings response contained no vectors");
|
|
3476
|
+
}
|
|
3477
|
+
return vectors.map((vec) => {
|
|
3478
|
+
const arr = new Float32Array(vec);
|
|
3479
|
+
if (arr.length === 0) {
|
|
3480
|
+
throw new Error("embeddings response contained empty vector");
|
|
3481
|
+
}
|
|
3482
|
+
return arr;
|
|
3483
|
+
});
|
|
3484
|
+
}
|
|
3421
3485
|
async function fetchEmbeddings(opts2) {
|
|
3422
3486
|
const model = opts2.model ?? DEFAULT_MODEL2;
|
|
3487
|
+
const texts = opts2.texts.map(truncateForEmbedding);
|
|
3488
|
+
if (texts.length === 0) {
|
|
3489
|
+
return [];
|
|
3490
|
+
}
|
|
3423
3491
|
let url;
|
|
3424
3492
|
const headers = {
|
|
3425
3493
|
"Content-Type": "application/json",
|
|
3426
3494
|
"User-Agent": getUserAgent()
|
|
3427
3495
|
};
|
|
3496
|
+
let body;
|
|
3497
|
+
let parseResponse;
|
|
3428
3498
|
if (opts2.gateway) {
|
|
3429
|
-
url = `https://gateway.ai.cloudflare.com/v1/${
|
|
3499
|
+
url = `https://gateway.ai.cloudflare.com/v1/${encodeURIComponent(
|
|
3500
|
+
opts2.accountId
|
|
3501
|
+
)}/${encodeURIComponent(opts2.gateway.id)}/compat/embeddings`;
|
|
3430
3502
|
headers.Authorization = `Bearer ${opts2.apiToken}`;
|
|
3431
3503
|
const merged = {
|
|
3432
3504
|
...opts2.gateway.metadata ?? {},
|
|
@@ -3440,48 +3512,22 @@ async function fetchEmbeddings(opts2) {
|
|
|
3440
3512
|
if (opts2.gateway.skipCache !== void 0) {
|
|
3441
3513
|
headers["cf-aig-skip-cache"] = String(opts2.gateway.skipCache);
|
|
3442
3514
|
}
|
|
3515
|
+
body = JSON.stringify({
|
|
3516
|
+
model: `workers-ai/${model}`,
|
|
3517
|
+
input: texts
|
|
3518
|
+
});
|
|
3519
|
+
parseResponse = parseOpenAiEmbeddingResponse;
|
|
3443
3520
|
} else {
|
|
3444
|
-
url = `https://api.cloudflare.com/client/v4/accounts/${
|
|
3521
|
+
url = `https://api.cloudflare.com/client/v4/accounts/${encodeURIComponent(
|
|
3522
|
+
opts2.accountId
|
|
3523
|
+
)}/ai/run/${encodeURIComponent(model)}`;
|
|
3445
3524
|
headers.Authorization = `Bearer ${opts2.apiToken}`;
|
|
3525
|
+
body = JSON.stringify({ text: texts });
|
|
3526
|
+
parseResponse = parseWorkersAiEmbeddingResponse;
|
|
3446
3527
|
}
|
|
3447
|
-
const
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
const body = JSON.stringify({ text: [truncated] });
|
|
3451
|
-
const res = await fetchWithRetry(url, { method: "POST", headers, body });
|
|
3452
|
-
const json2 = await res.json();
|
|
3453
|
-
let vectors = [];
|
|
3454
|
-
if (json2 && typeof json2 === "object") {
|
|
3455
|
-
const result = json2.result;
|
|
3456
|
-
if (result && typeof result === "object") {
|
|
3457
|
-
const data = result.data;
|
|
3458
|
-
if (Array.isArray(data)) {
|
|
3459
|
-
if (Array.isArray(data[0])) {
|
|
3460
|
-
vectors = data;
|
|
3461
|
-
} else {
|
|
3462
|
-
const shape = result.shape;
|
|
3463
|
-
if (shape && shape.length === 2) {
|
|
3464
|
-
const dim = shape[1];
|
|
3465
|
-
const flat = data;
|
|
3466
|
-
vectors = [];
|
|
3467
|
-
for (let i = 0; i < flat.length; i += dim) {
|
|
3468
|
-
vectors.push(flat.slice(i, i + dim));
|
|
3469
|
-
}
|
|
3470
|
-
}
|
|
3471
|
-
}
|
|
3472
|
-
}
|
|
3473
|
-
}
|
|
3474
|
-
}
|
|
3475
|
-
if (vectors.length === 0) {
|
|
3476
|
-
throw new Error("embeddings response contained no vectors");
|
|
3477
|
-
}
|
|
3478
|
-
const vec = new Float32Array(vectors[0]);
|
|
3479
|
-
if (vec.length === 0) {
|
|
3480
|
-
throw new Error("embeddings response contained empty vector");
|
|
3481
|
-
}
|
|
3482
|
-
results.push(vec);
|
|
3483
|
-
}
|
|
3484
|
-
return results;
|
|
3528
|
+
const res = await fetchWithRetry(url, { method: "POST", headers, body });
|
|
3529
|
+
const json2 = await res.json();
|
|
3530
|
+
return parseResponse(json2);
|
|
3485
3531
|
}
|
|
3486
3532
|
function cosineSimilarity(a, b) {
|
|
3487
3533
|
if (a.length !== b.length) {
|
|
@@ -16006,7 +16052,7 @@ var init_builtins = __esm({
|
|
|
16006
16052
|
{ name: "mode", argHint: "edit|plan|auto|multi-agent-experimental", description: "Switch agent mode", source: "builtin" },
|
|
16007
16053
|
{ name: "multi-agent", argHint: "[enable|disable|status|setup]", description: "Configure multi-agent (endpoint, auto-implement, set up)", source: "builtin" },
|
|
16008
16054
|
{ name: "theme", argHint: "[<name>]", description: "Switch color theme", source: "builtin" },
|
|
16009
|
-
{ name: "ui", argHint: "ink
|
|
16055
|
+
{ name: "ui", argHint: "ink", description: "Switch UI engine to React Ink (takes effect on next launch). Camouflage is opt-in via --ui camouflage.", source: "builtin" },
|
|
16010
16056
|
{ name: "plan", description: "Switch to plan mode", source: "builtin" },
|
|
16011
16057
|
{ name: "auto", description: "Switch to auto mode", source: "builtin" },
|
|
16012
16058
|
{ name: "edit", description: "Switch to edit mode", source: "builtin" },
|
|
@@ -20656,7 +20702,7 @@ Executor opened PR: ${prUrl}` : plan });
|
|
|
20656
20702
|
{
|
|
20657
20703
|
value: "camouflage",
|
|
20658
20704
|
label: "Camouflage",
|
|
20659
|
-
description: "experimental
|
|
20705
|
+
description: "experimental \u2014 opt in with `kimiflare --ui camouflage`"
|
|
20660
20706
|
}
|
|
20661
20707
|
],
|
|
20662
20708
|
default: current,
|
|
@@ -20676,6 +20722,14 @@ Executor opened PR: ${prUrl}` : plan });
|
|
|
20676
20722
|
});
|
|
20677
20723
|
return true;
|
|
20678
20724
|
}
|
|
20725
|
+
if (nextUi === "camouflage") {
|
|
20726
|
+
cam.send("ShowToast", {
|
|
20727
|
+
text: "Camouflage is experimental and must be opted into explicitly. Launch with `kimiflare --ui camouflage` or set `KIMIFLARE_UI=camouflage`.",
|
|
20728
|
+
kind: "error",
|
|
20729
|
+
ttl_ms: 12e3
|
|
20730
|
+
});
|
|
20731
|
+
return true;
|
|
20732
|
+
}
|
|
20679
20733
|
try {
|
|
20680
20734
|
const existing = await loadConfig() ?? null;
|
|
20681
20735
|
if (existing) {
|
|
@@ -20690,7 +20744,7 @@ Executor opened PR: ${prUrl}` : plan });
|
|
|
20690
20744
|
return true;
|
|
20691
20745
|
}
|
|
20692
20746
|
cam.send("ShowToast", {
|
|
20693
|
-
text: `UI engine set to "${nextUi}". RESTART kimiflare for it to take effect
|
|
20747
|
+
text: `UI engine set to "${nextUi}". RESTART kimiflare for it to take effect. (or \`unset KIMIFLARE_UI\` if you previously exported it)`,
|
|
20694
20748
|
kind: "error",
|
|
20695
20749
|
ttl_ms: 12e3
|
|
20696
20750
|
});
|
|
@@ -28598,7 +28652,7 @@ function UiPicker({ current, onPick }) {
|
|
|
28598
28652
|
{
|
|
28599
28653
|
label: "Camouflage",
|
|
28600
28654
|
value: "camouflage",
|
|
28601
|
-
description: "experimental
|
|
28655
|
+
description: "experimental \u2014 opt in with `kimiflare --ui camouflage`"
|
|
28602
28656
|
},
|
|
28603
28657
|
{ label: "< Back", value: "__back__", description: "" }
|
|
28604
28658
|
];
|
|
@@ -31976,6 +32030,17 @@ var init_slash_commands = __esm({
|
|
|
31976
32030
|
return true;
|
|
31977
32031
|
}
|
|
31978
32032
|
const next = arg;
|
|
32033
|
+
if (next === "camouflage") {
|
|
32034
|
+
setEvents((e) => [
|
|
32035
|
+
...e,
|
|
32036
|
+
{
|
|
32037
|
+
kind: "error",
|
|
32038
|
+
key: mkKey2(),
|
|
32039
|
+
text: "Camouflage is experimental and must be opted into explicitly. Launch with `kimiflare --ui camouflage` or set `KIMIFLARE_UI=camouflage`."
|
|
32040
|
+
}
|
|
32041
|
+
]);
|
|
32042
|
+
return true;
|
|
32043
|
+
}
|
|
31979
32044
|
ctx.setCfg((prev) => {
|
|
31980
32045
|
if (!prev) return prev;
|
|
31981
32046
|
const updated = { ...prev, uiEngine: next };
|
|
@@ -31988,7 +32053,7 @@ var init_slash_commands = __esm({
|
|
|
31988
32053
|
{
|
|
31989
32054
|
kind: "error",
|
|
31990
32055
|
key: mkKey2(),
|
|
31991
|
-
text: `UI engine set to "${next}". RESTART kimiflare for it to take effect.`
|
|
32056
|
+
text: `UI engine set to "${next}". RESTART kimiflare for it to take effect.`
|
|
31992
32057
|
}
|
|
31993
32058
|
]);
|
|
31994
32059
|
return true;
|
|
@@ -34639,6 +34704,17 @@ ${wcagWarnings.join("\n")}` }
|
|
|
34639
34704
|
(picked) => {
|
|
34640
34705
|
setShowUiPicker(false);
|
|
34641
34706
|
if (!picked) return;
|
|
34707
|
+
if (picked === "camouflage") {
|
|
34708
|
+
setEvents((e) => [
|
|
34709
|
+
...e,
|
|
34710
|
+
{
|
|
34711
|
+
kind: "error",
|
|
34712
|
+
key: mkKey(),
|
|
34713
|
+
text: "Camouflage is experimental and must be opted into explicitly. Launch with `kimiflare --ui camouflage` or set `KIMIFLARE_UI=camouflage`."
|
|
34714
|
+
}
|
|
34715
|
+
]);
|
|
34716
|
+
return;
|
|
34717
|
+
}
|
|
34642
34718
|
setCfg((c) => {
|
|
34643
34719
|
if (!c) return c;
|
|
34644
34720
|
const updated = { ...c, uiEngine: picked };
|
|
@@ -34651,7 +34727,7 @@ ${wcagWarnings.join("\n")}` }
|
|
|
34651
34727
|
{
|
|
34652
34728
|
kind: "error",
|
|
34653
34729
|
key: mkKey(),
|
|
34654
|
-
text: `UI engine set to "${picked}". RESTART kimiflare for it to take effect.`
|
|
34730
|
+
text: `UI engine set to "${picked}". RESTART kimiflare for it to take effect.`
|
|
34655
34731
|
}
|
|
34656
34732
|
]);
|
|
34657
34733
|
},
|
|
@@ -36366,7 +36442,7 @@ function buildTextLines(version) {
|
|
|
36366
36442
|
` ${bold}${accent}Kimiflare${reset}`,
|
|
36367
36443
|
"",
|
|
36368
36444
|
` ${dim}Terminal coding agent${reset}`,
|
|
36369
|
-
` ${dim}powered by Kimi-K2.
|
|
36445
|
+
` ${dim}powered by Kimi-K2.7${reset}`,
|
|
36370
36446
|
"",
|
|
36371
36447
|
` ${dim}v${version}${reset}`,
|
|
36372
36448
|
"",
|
|
@@ -36904,7 +36980,8 @@ async function main() {
|
|
|
36904
36980
|
process.exit(2);
|
|
36905
36981
|
}
|
|
36906
36982
|
const logoText = renderLogo(getAppVersion());
|
|
36907
|
-
const
|
|
36983
|
+
const explicitUi = opts.ui ?? process.env.KIMIFLARE_UI;
|
|
36984
|
+
const uiEngine = (explicitUi ?? (cfg?.uiEngine === "ink" ? "ink" : void 0) ?? "ink").toLowerCase();
|
|
36908
36985
|
if (uiEngine !== "camouflage") {
|
|
36909
36986
|
console.log(logoText);
|
|
36910
36987
|
}
|