iubcli 5.0.4 → 5.0.6
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 +87 -29
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -3583,19 +3583,28 @@ async function readInlinePrompt(options) {
|
|
|
3583
3583
|
async function readOpenCodePrompt(options) {
|
|
3584
3584
|
return readInlinePrompt(options);
|
|
3585
3585
|
}
|
|
3586
|
-
async function expandOpenCodeMentions(rawPrompt) {
|
|
3586
|
+
async function expandOpenCodeMentions(rawPrompt, signal) {
|
|
3587
3587
|
const attachedFiles = [];
|
|
3588
3588
|
const attachedImages = [];
|
|
3589
3589
|
const contexts = [];
|
|
3590
|
+
if (signal?.aborted) {
|
|
3591
|
+
return { expandedPrompt: rawPrompt, attachedFiles, attachedImages };
|
|
3592
|
+
}
|
|
3590
3593
|
const urlRegex = /(?:@)?(https?:\/\/[^\s"'<>]+)/g;
|
|
3591
3594
|
const urlMatches = Array.from(rawPrompt.matchAll(urlRegex));
|
|
3592
3595
|
const seenUrls = /* @__PURE__ */ new Set();
|
|
3593
3596
|
for (const match of urlMatches) {
|
|
3597
|
+
if (signal?.aborted) break;
|
|
3594
3598
|
const targetUrl = match[1].replace(/[.,;:!?)]+$/, "");
|
|
3595
3599
|
if (!targetUrl || seenUrls.has(targetUrl)) continue;
|
|
3596
3600
|
seenUrls.add(targetUrl);
|
|
3597
3601
|
const controller = new AbortController();
|
|
3598
3602
|
const timeout = setTimeout(() => controller.abort(), 6e3);
|
|
3603
|
+
const onAbort = () => controller.abort();
|
|
3604
|
+
if (signal) {
|
|
3605
|
+
if (signal.aborted) controller.abort();
|
|
3606
|
+
else signal.addEventListener("abort", onAbort, { once: true });
|
|
3607
|
+
}
|
|
3599
3608
|
try {
|
|
3600
3609
|
const res = await fetch(targetUrl, {
|
|
3601
3610
|
signal: controller.signal,
|
|
@@ -3622,12 +3631,17 @@ async function expandOpenCodeMentions(rawPrompt) {
|
|
|
3622
3631
|
} catch {
|
|
3623
3632
|
} finally {
|
|
3624
3633
|
clearTimeout(timeout);
|
|
3634
|
+
signal?.removeEventListener("abort", onAbort);
|
|
3625
3635
|
}
|
|
3626
3636
|
}
|
|
3637
|
+
if (signal?.aborted) {
|
|
3638
|
+
return { expandedPrompt: rawPrompt, attachedFiles, attachedImages };
|
|
3639
|
+
}
|
|
3627
3640
|
const fileRegex = /(?:^|\s)@([a-zA-Z0-9_\-\.\/\\]+)/g;
|
|
3628
3641
|
const fileMatches = Array.from(rawPrompt.matchAll(fileRegex));
|
|
3629
3642
|
const seenPaths = /* @__PURE__ */ new Set();
|
|
3630
3643
|
for (const match of fileMatches) {
|
|
3644
|
+
if (signal?.aborted) break;
|
|
3631
3645
|
const rawPath = match[1];
|
|
3632
3646
|
if (rawPath.startsWith("http://") || rawPath.startsWith("https://")) continue;
|
|
3633
3647
|
const resolvedPath = path4.resolve(process.cwd(), rawPath);
|
|
@@ -3679,6 +3693,7 @@ async function expandOpenCodeMentions(rawPrompt) {
|
|
|
3679
3693
|
const rawImageRegex = /(?:^|\s)["']?([a-zA-Z]:[\\/][^\r\n"']+\.(?:png|jpg|jpeg|webp|gif|bmp)|(?:\.{1,2}[\\/]|[a-zA-Z0-9_\-]+[\\/])[^\r\n"']+\.(?:png|jpg|jpeg|webp|gif|bmp))["']?(?=\s|$)/gi;
|
|
3680
3694
|
const rawImageMatches = Array.from(rawPrompt.matchAll(rawImageRegex));
|
|
3681
3695
|
for (const m of rawImageMatches) {
|
|
3696
|
+
if (signal?.aborted) break;
|
|
3682
3697
|
const rawPath = m[1].replace(/["']/g, "").trim();
|
|
3683
3698
|
const resolvedPath = path4.isAbsolute(rawPath) ? rawPath : path4.resolve(process.cwd(), rawPath);
|
|
3684
3699
|
if (fs4.existsSync(resolvedPath) && !attachedImages.some((img) => img.path === resolvedPath)) {
|
|
@@ -6149,22 +6164,41 @@ function detectProjectContext(rootDir = process.cwd()) {
|
|
|
6149
6164
|
// src/explorer.ts
|
|
6150
6165
|
import { GoogleGenAI } from "@google/genai";
|
|
6151
6166
|
import chalk7 from "chalk";
|
|
6152
|
-
|
|
6167
|
+
function probeAbortSignal(timeoutMs, signal) {
|
|
6168
|
+
const controller = new AbortController();
|
|
6169
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
6170
|
+
const onAbort = () => controller.abort();
|
|
6171
|
+
if (signal) {
|
|
6172
|
+
if (signal.aborted) {
|
|
6173
|
+
controller.abort();
|
|
6174
|
+
} else {
|
|
6175
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
6176
|
+
}
|
|
6177
|
+
}
|
|
6178
|
+
return {
|
|
6179
|
+
signal: controller.signal,
|
|
6180
|
+
cleanup: () => {
|
|
6181
|
+
clearTimeout(timer);
|
|
6182
|
+
if (signal) signal.removeEventListener("abort", onAbort);
|
|
6183
|
+
}
|
|
6184
|
+
};
|
|
6185
|
+
}
|
|
6186
|
+
async function probeCandidate(candidate, signal) {
|
|
6153
6187
|
const timeoutMs = 5e3;
|
|
6188
|
+
if (signal?.aborted) return false;
|
|
6154
6189
|
if (candidate.provider === "custom" && candidate.baseURL?.toLowerCase().includes("pollinations.ai")) {
|
|
6155
|
-
const
|
|
6156
|
-
const timer = setTimeout(() => controller2.abort(), timeoutMs);
|
|
6190
|
+
const gate2 = probeAbortSignal(timeoutMs, signal);
|
|
6157
6191
|
try {
|
|
6158
|
-
const res = await fetch("https://text.pollinations.ai/models", { signal:
|
|
6159
|
-
clearTimeout(timer);
|
|
6192
|
+
const res = await fetch("https://text.pollinations.ai/models", { signal: gate2.signal });
|
|
6160
6193
|
return res.ok;
|
|
6161
6194
|
} catch {
|
|
6162
|
-
clearTimeout(timer);
|
|
6163
6195
|
return false;
|
|
6196
|
+
} finally {
|
|
6197
|
+
gate2.cleanup();
|
|
6164
6198
|
}
|
|
6165
6199
|
}
|
|
6166
6200
|
if (candidate.provider === "gemini") {
|
|
6167
|
-
|
|
6201
|
+
const gate2 = probeAbortSignal(timeoutMs, signal);
|
|
6168
6202
|
try {
|
|
6169
6203
|
const ai = new GoogleGenAI({ apiKey: candidate.apiKey });
|
|
6170
6204
|
const normalized = normalizeGeminiModel(candidate.id);
|
|
@@ -6175,23 +6209,24 @@ async function probeCandidate(candidate) {
|
|
|
6175
6209
|
config: { maxOutputTokens: 10 }
|
|
6176
6210
|
}),
|
|
6177
6211
|
new Promise((_, reject) => {
|
|
6178
|
-
|
|
6212
|
+
const fail = () => reject(new Error("PROBE_ABORTED"));
|
|
6213
|
+
if (gate2.signal.aborted) fail();
|
|
6214
|
+
else gate2.signal.addEventListener("abort", fail, { once: true });
|
|
6179
6215
|
})
|
|
6180
6216
|
]);
|
|
6181
|
-
if (timer) clearTimeout(timer);
|
|
6182
6217
|
return Boolean(res && (res.text !== void 0 || res.candidates && res.candidates.length > 0));
|
|
6183
6218
|
} catch {
|
|
6184
|
-
if (timer) clearTimeout(timer);
|
|
6185
6219
|
return false;
|
|
6220
|
+
} finally {
|
|
6221
|
+
gate2.cleanup();
|
|
6186
6222
|
}
|
|
6187
6223
|
}
|
|
6188
|
-
const
|
|
6189
|
-
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
6224
|
+
const gate = probeAbortSignal(timeoutMs, signal);
|
|
6190
6225
|
try {
|
|
6191
6226
|
const targetUrl = candidate.baseURL ? candidate.baseURL.replace(/\/+$/, "") + "/chat/completions" : "https://openrouter.ai/api/v1/chat/completions";
|
|
6192
6227
|
const res = await fetch(targetUrl, {
|
|
6193
6228
|
method: "POST",
|
|
6194
|
-
signal:
|
|
6229
|
+
signal: gate.signal,
|
|
6195
6230
|
headers: {
|
|
6196
6231
|
"Content-Type": "application/json",
|
|
6197
6232
|
Authorization: `Bearer ${candidate.apiKey}`,
|
|
@@ -6204,7 +6239,6 @@ async function probeCandidate(candidate) {
|
|
|
6204
6239
|
max_tokens: 10
|
|
6205
6240
|
})
|
|
6206
6241
|
});
|
|
6207
|
-
clearTimeout(timeout);
|
|
6208
6242
|
if (!res.ok) {
|
|
6209
6243
|
return false;
|
|
6210
6244
|
}
|
|
@@ -6220,11 +6254,15 @@ async function probeCandidate(candidate) {
|
|
|
6220
6254
|
}
|
|
6221
6255
|
return Boolean(data?.choices && data.choices.length > 0);
|
|
6222
6256
|
} catch {
|
|
6223
|
-
clearTimeout(timeout);
|
|
6224
6257
|
return false;
|
|
6258
|
+
} finally {
|
|
6259
|
+
gate.cleanup();
|
|
6225
6260
|
}
|
|
6226
6261
|
}
|
|
6227
|
-
async function exploreAndSelectFreeModel(config, excludedModels = /* @__PURE__ */ new Set(), silent = false, persist = true) {
|
|
6262
|
+
async function exploreAndSelectFreeModel(config, excludedModels = /* @__PURE__ */ new Set(), silent = false, persist = true, signal) {
|
|
6263
|
+
if (signal?.aborted) {
|
|
6264
|
+
return null;
|
|
6265
|
+
}
|
|
6228
6266
|
if (!silent) {
|
|
6229
6267
|
process.stdout.write(
|
|
6230
6268
|
chalk7.cyan("\nExploring all available models across providers to find active free tokens...\n")
|
|
@@ -6277,8 +6315,10 @@ async function exploreAndSelectFreeModel(config, excludedModels = /* @__PURE__ *
|
|
|
6277
6315
|
});
|
|
6278
6316
|
}
|
|
6279
6317
|
}
|
|
6318
|
+
if (signal?.aborted) return null;
|
|
6280
6319
|
try {
|
|
6281
6320
|
const liveFree = await fetchLiveOpenRouterFreeModels();
|
|
6321
|
+
if (signal?.aborted) return null;
|
|
6282
6322
|
for (const m of liveFree) {
|
|
6283
6323
|
pushCandidate({
|
|
6284
6324
|
id: m.id,
|
|
@@ -6323,6 +6363,7 @@ async function exploreAndSelectFreeModel(config, excludedModels = /* @__PURE__ *
|
|
|
6323
6363
|
});
|
|
6324
6364
|
}
|
|
6325
6365
|
}
|
|
6366
|
+
if (signal?.aborted) return null;
|
|
6326
6367
|
try {
|
|
6327
6368
|
const localOllama = await detectLocalOllamaModels(500);
|
|
6328
6369
|
for (const m of localOllama) {
|
|
@@ -6353,13 +6394,15 @@ async function exploreAndSelectFreeModel(config, excludedModels = /* @__PURE__ *
|
|
|
6353
6394
|
const chunkSize = 4;
|
|
6354
6395
|
let testedCount = 0;
|
|
6355
6396
|
for (let i = 0; i < candidatePool.length; i += chunkSize) {
|
|
6397
|
+
if (signal?.aborted) return null;
|
|
6356
6398
|
const chunk = candidatePool.slice(i, i + chunkSize);
|
|
6357
6399
|
testedCount += chunk.length;
|
|
6358
6400
|
const probePromises = chunk.map(async (candidate) => {
|
|
6359
|
-
const ok = await probeCandidate(candidate);
|
|
6401
|
+
const ok = await probeCandidate(candidate, signal);
|
|
6360
6402
|
return ok ? candidate : null;
|
|
6361
6403
|
});
|
|
6362
6404
|
const results = await Promise.all(probePromises);
|
|
6405
|
+
if (signal?.aborted) return null;
|
|
6363
6406
|
const winner = results.find((r) => r !== null);
|
|
6364
6407
|
if (winner) {
|
|
6365
6408
|
config.model = winner.id;
|
|
@@ -6958,7 +7001,14 @@ ${String(out).slice(0, 6e3)}`);
|
|
|
6958
7001
|
if (nextOR) return nextOR;
|
|
6959
7002
|
}
|
|
6960
7003
|
const prevProviderBeforeExplore = this.config.provider;
|
|
6961
|
-
const explored = await exploreAndSelectFreeModel(
|
|
7004
|
+
const explored = await exploreAndSelectFreeModel(
|
|
7005
|
+
this.config,
|
|
7006
|
+
this.attemptedModelsInCascade,
|
|
7007
|
+
false,
|
|
7008
|
+
false,
|
|
7009
|
+
signal
|
|
7010
|
+
);
|
|
7011
|
+
if (signal?.aborted) return null;
|
|
6962
7012
|
if (explored) {
|
|
6963
7013
|
this.attemptedModelsInCascade.add(explored.id);
|
|
6964
7014
|
this.initClients();
|
|
@@ -6980,7 +7030,8 @@ ${String(out).slice(0, 6e3)}`);
|
|
|
6980
7030
|
this.attemptedModelsInCascade.clear();
|
|
6981
7031
|
this.deadProvidersInTurn.clear();
|
|
6982
7032
|
const prevProviderBeforeRecovery = this.config.provider;
|
|
6983
|
-
const recovered = await exploreAndSelectFreeModel(this.config, /* @__PURE__ */ new Set(), true, false);
|
|
7033
|
+
const recovered = await exploreAndSelectFreeModel(this.config, /* @__PURE__ */ new Set(), true, false, signal);
|
|
7034
|
+
if (signal?.aborted) return null;
|
|
6984
7035
|
if (recovered) {
|
|
6985
7036
|
this.initClients();
|
|
6986
7037
|
this.syncHistoryForProviderChange(prevProviderBeforeRecovery, this.config.provider);
|
|
@@ -6988,6 +7039,7 @@ ${String(out).slice(0, 6e3)}`);
|
|
|
6988
7039
|
return recovered.id;
|
|
6989
7040
|
}
|
|
6990
7041
|
}
|
|
7042
|
+
if (signal?.aborted) return null;
|
|
6991
7043
|
if (this.config.baseURL !== POLLINATIONS_BASE_URL || this.config.model !== POLLINATIONS_DEFAULT_MODEL) {
|
|
6992
7044
|
const prevProviderBeforeFallback = this.config.provider;
|
|
6993
7045
|
renderCascadeNotice(currentModel, POLLINATIONS_DEFAULT_MODEL, "Switching to Zero-Key Built-in Free AI");
|
|
@@ -9448,9 +9500,6 @@ Unknown command "${cmdWord}". Type ${chalk9.cyan("/help")} to see all available
|
|
|
9448
9500
|
if (isPriorityTask) {
|
|
9449
9501
|
renderPriorityTaskBanner(taskPrompt, config.model, agent.getMode());
|
|
9450
9502
|
}
|
|
9451
|
-
const { expandedPrompt, attachedImages } = await expandOpenCodeMentions(taskPrompt);
|
|
9452
|
-
const allImages = [...stagedImages, ...attachedImages];
|
|
9453
|
-
stagedImages = [];
|
|
9454
9503
|
const abortController = new AbortController();
|
|
9455
9504
|
let hasAborted = false;
|
|
9456
9505
|
const detachEscape = attachEscapeListener(() => {
|
|
@@ -9464,14 +9513,23 @@ Unknown command "${cmdWord}". Type ${chalk9.cyan("/help")} to see all available
|
|
|
9464
9513
|
});
|
|
9465
9514
|
});
|
|
9466
9515
|
try {
|
|
9467
|
-
const
|
|
9468
|
-
|
|
9469
|
-
|
|
9470
|
-
|
|
9516
|
+
const { expandedPrompt, attachedImages } = await expandOpenCodeMentions(
|
|
9517
|
+
taskPrompt,
|
|
9518
|
+
abortController.signal
|
|
9519
|
+
);
|
|
9520
|
+
const allImages = [...stagedImages, ...attachedImages];
|
|
9521
|
+
stagedImages = [];
|
|
9471
9522
|
if (abortController.signal.aborted || hasAborted) {
|
|
9472
9523
|
} else {
|
|
9473
|
-
|
|
9474
|
-
|
|
9524
|
+
const reply = await agent.chat(expandedPrompt, {
|
|
9525
|
+
signal: abortController.signal,
|
|
9526
|
+
images: allImages
|
|
9527
|
+
});
|
|
9528
|
+
if (abortController.signal.aborted || hasAborted) {
|
|
9529
|
+
} else {
|
|
9530
|
+
console.log("\n" + chalk9.bold.hex("#00A3FF")("IUB CLI:"));
|
|
9531
|
+
console.log(renderMarkdown(reply) + "\n");
|
|
9532
|
+
}
|
|
9475
9533
|
}
|
|
9476
9534
|
} catch (err) {
|
|
9477
9535
|
if (abortController.signal.aborted || hasAborted) {
|