@botconnector/bccli 0.4.16 → 0.5.0-rc.4
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/LICENSE +203 -21
- package/THIRD_PARTY_NOTICES.md +9 -0
- package/branding.mjs +347 -0
- package/cli.mjs +120 -0
- package/core.mjs +260 -0
- package/credentials.mjs +52 -0
- package/gateway.mjs +2 -0
- package/model-command.mjs +61 -0
- package/package.json +35 -59
- package/provider-cli.mjs +77 -0
- package/providers.mjs +166 -0
- package/proxy.mjs +242 -0
- package/startup-menu.mjs +120 -0
- package/README.en.md +0 -253
- package/README.md +0 -250
- package/dist/abort.d.ts +0 -5
- package/dist/acp-JZW3XHE5.js +0 -221
- package/dist/acp.d.ts +0 -44
- package/dist/agent.d.ts +0 -147
- package/dist/agents.d.ts +0 -4
- package/dist/args-XVO7TB4C.js +0 -13
- package/dist/args.d.ts +0 -59
- package/dist/budget.d.ts +0 -26
- package/dist/checkpoints.d.ts +0 -35
- package/dist/chunk-3CYQYHPK.js +0 -202
- package/dist/chunk-6JK4IBGK.js +0 -1075
- package/dist/chunk-6SDRWEPN.js +0 -50
- package/dist/chunk-7GM6NN5E.js +0 -341
- package/dist/chunk-7XD47KN5.js +0 -71
- package/dist/chunk-INMSTUB2.js +0 -56
- package/dist/chunk-ISOKH5WB.js +0 -256
- package/dist/chunk-JUC3ZOCV.js +0 -50
- package/dist/chunk-KDVL2NP6.js +0 -861
- package/dist/chunk-KEKDRROL.js +0 -216
- package/dist/chunk-KJIXA6MP.js +0 -159
- package/dist/chunk-OK2USAXX.js +0 -88
- package/dist/chunk-PSO7R5AD.js +0 -10
- package/dist/chunk-Q42ZGVAQ.js +0 -91
- package/dist/chunk-R754XIBJ.js +0 -523
- package/dist/chunk-S3QEZDKB.js +0 -270
- package/dist/chunk-SWNRA3EW.js +0 -78
- package/dist/chunk-TLCL6DC7.js +0 -378
- package/dist/chunk-V5D6PJQN.js +0 -8
- package/dist/chunk-YYTFJUO2.js +0 -148
- package/dist/chunk-ZJRZTMJF.js +0 -2669
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +0 -233
- package/dist/clipboardImage.d.ts +0 -17
- package/dist/commands.d.ts +0 -16
- package/dist/completion-Q7VHOPPV.js +0 -125
- package/dist/completion.d.ts +0 -14
- package/dist/config-T7MKGJVG.js +0 -34
- package/dist/config-YYEAEN2C.js +0 -25
- package/dist/config.d.ts +0 -99
- package/dist/context.d.ts +0 -13
- package/dist/contextWindow.d.ts +0 -3
- package/dist/diff.d.ts +0 -7
- package/dist/exit.d.ts +0 -9
- package/dist/extensions.d.ts +0 -34
- package/dist/ghBotCli-7VUGI63S.js +0 -680
- package/dist/ghBotCli.d.ts +0 -9
- package/dist/ghBotDispatch.d.ts +0 -68
- package/dist/ghBotRunner.d.ts +0 -82
- package/dist/ghBotServe.d.ts +0 -21
- package/dist/ghBotWebhook.d.ts +0 -45
- package/dist/hooks.d.ts +0 -27
- package/dist/i18n/id.d.ts +0 -1
- package/dist/i18n.d.ts +0 -16
- package/dist/integrationCli-FBRSTF5F.js +0 -876
- package/dist/integrationCli.d.ts +0 -9
- package/dist/keybinds.d.ts +0 -22
- package/dist/login-BSMUGW7L.js +0 -18
- package/dist/login.d.ts +0 -21
- package/dist/lsp.d.ts +0 -73
- package/dist/mcp/catalog.d.ts +0 -14
- package/dist/mcp/config.d.ts +0 -36
- package/dist/mcp/manager.d.ts +0 -52
- package/dist/mcp/oauth.d.ts +0 -82
- package/dist/mcpCli-ZT7CRYMP.js +0 -113
- package/dist/mcpCli.d.ts +0 -3
- package/dist/mcpServer/serve.d.ts +0 -8
- package/dist/mcpServer/server.d.ts +0 -19
- package/dist/models.d.ts +0 -13
- package/dist/modelsCli-2ZRW4CC4.js +0 -36
- package/dist/modelsCli.d.ts +0 -15
- package/dist/npmRunner-LU43GM3W.js +0 -46
- package/dist/npmRunner.d.ts +0 -21
- package/dist/oauthLogin-THSM6FE7.js +0 -210
- package/dist/oauthLogin.d.ts +0 -47
- package/dist/permissions.d.ts +0 -30
- package/dist/pluginSpec.d.ts +0 -25
- package/dist/plugins.d.ts +0 -45
- package/dist/pluginsCli-EKQI4CJW.js +0 -288
- package/dist/pluginsCli.d.ts +0 -16
- package/dist/prCli-FMQTOBIV.js +0 -94
- package/dist/prCli.d.ts +0 -46
- package/dist/presets.d.ts +0 -8
- package/dist/print.d.ts +0 -17
- package/dist/provider.d.ts +0 -145
- package/dist/providerCli-3TFEKV4C.js +0 -15
- package/dist/providerCli.d.ts +0 -17
- package/dist/providers.d.ts +0 -6
- package/dist/reasoning.d.ts +0 -12
- package/dist/repomap.d.ts +0 -10
- package/dist/sdk.d.ts +0 -61
- package/dist/sdk.js +0 -6494
- package/dist/serve-3BODPEPR.js +0 -532
- package/dist/serve-V6YVZTNR.js +0 -178
- package/dist/serve.d.ts +0 -37
- package/dist/serveHeartbeat.d.ts +0 -14
- package/dist/serveProtocol.d.ts +0 -47
- package/dist/session-LX4UNPCD.js +0 -12
- package/dist/session.d.ts +0 -33
- package/dist/setup-MFG3BWEU.js +0 -24
- package/dist/setup.d.ts +0 -79
- package/dist/slash/copy.d.ts +0 -1
- package/dist/slash/diff.d.ts +0 -1
- package/dist/slash/doctor.d.ts +0 -18
- package/dist/slash/export.d.ts +0 -2
- package/dist/slash/info.d.ts +0 -46
- package/dist/slash/memory.d.ts +0 -10
- package/dist/statsCli-7MIQHLVW.js +0 -353
- package/dist/statsCli.d.ts +0 -62
- package/dist/textToolCalls.d.ts +0 -6
- package/dist/thinking.d.ts +0 -17
- package/dist/tokenBudget.d.ts +0 -22
- package/dist/tools/bash.d.ts +0 -54
- package/dist/tools/diagnostics.d.ts +0 -13
- package/dist/tools/edit.d.ts +0 -12
- package/dist/tools/fetch.d.ts +0 -41
- package/dist/tools/glob.d.ts +0 -5
- package/dist/tools/globSafety.d.ts +0 -7
- package/dist/tools/grep.d.ts +0 -25
- package/dist/tools/ignore.d.ts +0 -2
- package/dist/tools/index.d.ts +0 -12
- package/dist/tools/memory.d.ts +0 -13
- package/dist/tools/paths.d.ts +0 -4
- package/dist/tools/plan.d.ts +0 -10
- package/dist/tools/read.d.ts +0 -16
- package/dist/tools/repomap.d.ts +0 -2
- package/dist/tools/sandbox.d.ts +0 -15
- package/dist/tools/shell.d.ts +0 -18
- package/dist/tools/skill.d.ts +0 -3
- package/dist/tools/task.d.ts +0 -28
- package/dist/tools/todo.d.ts +0 -13
- package/dist/tools/types.d.ts +0 -52
- package/dist/tools/websearch.d.ts +0 -9
- package/dist/tools/write.d.ts +0 -5
- package/dist/transferCli-SRSYQLSJ.js +0 -73
- package/dist/transferCli.d.ts +0 -23
- package/dist/ui/App.d.ts +0 -7
- package/dist/ui/DiffView.d.ts +0 -3
- package/dist/ui/EditableText.d.ts +0 -7
- package/dist/ui/LinePrompt.d.ts +0 -6
- package/dist/ui/ListPicker.d.ts +0 -11
- package/dist/ui/Markdown.d.ts +0 -8
- package/dist/ui/McpMenu.d.ts +0 -11
- package/dist/ui/ModelPicker.d.ts +0 -6
- package/dist/ui/PermissionPrompt.d.ts +0 -5
- package/dist/ui/PlanApproval.d.ts +0 -5
- package/dist/ui/PromptInput.d.ts +0 -20
- package/dist/ui/ProviderMenu.d.ts +0 -10
- package/dist/ui/Spinner.d.ts +0 -4
- package/dist/ui/StatusBar.d.ts +0 -9
- package/dist/ui/TodoList.d.ts +0 -4
- package/dist/ui/ToolBlock.d.ts +0 -14
- package/dist/ui/complete.d.ts +0 -8
- package/dist/ui/index.d.ts +0 -7
- package/dist/ui/lineEdit.d.ts +0 -42
- package/dist/ui/liveCap.d.ts +0 -9
- package/dist/ui/replay.d.ts +0 -4
- package/dist/ui/stdinFilter.d.ts +0 -18
- package/dist/ui/table.d.ts +0 -20
- package/dist/ui/theme.d.ts +0 -5
- package/dist/ui/thinkingMouse.d.ts +0 -38
- package/dist/ui/transcript.d.ts +0 -55
- package/dist/ui/tty.d.ts +0 -11
- package/dist/ui/vim.d.ts +0 -26
- package/dist/ui-LZ4JGF2V.js +0 -2913
- package/dist/update-P7MU4ZM7.js +0 -145
- package/dist/update.d.ts +0 -30
- package/dist/verify.d.ts +0 -16
- package/dist/version.d.ts +0 -1
- package/dist/webBudget.d.ts +0 -25
- package/dist/worktree.d.ts +0 -12
package/dist/chunk-6SDRWEPN.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
PRESETS,
|
|
4
|
-
bccliHome,
|
|
5
|
-
readCredentials,
|
|
6
|
-
readJsonConfig,
|
|
7
|
-
removeCredential,
|
|
8
|
-
writeFileAtomic
|
|
9
|
-
} from "./chunk-TLCL6DC7.js";
|
|
10
|
-
|
|
11
|
-
// src/providers.ts
|
|
12
|
-
import { join } from "path";
|
|
13
|
-
function providerName(config, id) {
|
|
14
|
-
return PRESETS.find((p) => p.id === id)?.name ?? config.providers[id]?.name ?? id;
|
|
15
|
-
}
|
|
16
|
-
function hasKey(config, id, env = process.env) {
|
|
17
|
-
const provider = config.providers[id];
|
|
18
|
-
if (!provider) return false;
|
|
19
|
-
if (!provider.apiKeyEnv) return true;
|
|
20
|
-
return !!env[provider.apiKeyEnv] || !!readCredentials(env)[id];
|
|
21
|
-
}
|
|
22
|
-
var globalPath = (env) => join(bccliHome(env), "config.json");
|
|
23
|
-
function readGlobalConfigFile(env = process.env) {
|
|
24
|
-
return readJsonConfig(globalPath(env));
|
|
25
|
-
}
|
|
26
|
-
function save(data, env) {
|
|
27
|
-
writeFileAtomic(globalPath(env), `${JSON.stringify(data, null, 2)}
|
|
28
|
-
`);
|
|
29
|
-
}
|
|
30
|
-
function writeGlobalConfig(patch, env = process.env) {
|
|
31
|
-
const current = readGlobalConfigFile(env);
|
|
32
|
-
const next = { ...current, ...patch };
|
|
33
|
-
if (patch.providers) next.providers = { ...current.providers, ...patch.providers };
|
|
34
|
-
save(next, env);
|
|
35
|
-
}
|
|
36
|
-
function removeGlobalProvider(id, env = process.env) {
|
|
37
|
-
removeCredential(id, env);
|
|
38
|
-
const current = readGlobalConfigFile(env);
|
|
39
|
-
if (!current.providers?.[id]) return;
|
|
40
|
-
const { [id]: _removed, ...providers } = current.providers;
|
|
41
|
-
save({ ...current, providers }, env);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export {
|
|
45
|
-
providerName,
|
|
46
|
-
hasKey,
|
|
47
|
-
readGlobalConfigFile,
|
|
48
|
-
writeGlobalConfig,
|
|
49
|
-
removeGlobalProvider
|
|
50
|
-
};
|
package/dist/chunk-7GM6NN5E.js
DELETED
|
@@ -1,341 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
defineTool
|
|
4
|
-
} from "./chunk-PSO7R5AD.js";
|
|
5
|
-
import {
|
|
6
|
-
t
|
|
7
|
-
} from "./chunk-R754XIBJ.js";
|
|
8
|
-
|
|
9
|
-
// src/tools/websearch.ts
|
|
10
|
-
import { z } from "zod";
|
|
11
|
-
var clean = (items, max) => (Array.isArray(items) ? items : []).filter((r) => typeof r?.url === "string" && /^https?:\/\//.test(r.url)).slice(0, max).map((r) => ({
|
|
12
|
-
title: String(r.title || r.url).slice(0, 200),
|
|
13
|
-
url: r.url,
|
|
14
|
-
snippet: String(r.snippet || r.description || "").replace(/\s+/g, " ").trim().slice(0, 600)
|
|
15
|
-
}));
|
|
16
|
-
async function postJson(url, body, headers, signal) {
|
|
17
|
-
const res = await fetch(url, {
|
|
18
|
-
method: "POST",
|
|
19
|
-
headers: { "content-type": "application/json", ...headers },
|
|
20
|
-
body: JSON.stringify(body),
|
|
21
|
-
signal: AbortSignal.any([signal, AbortSignal.timeout(3e4)])
|
|
22
|
-
});
|
|
23
|
-
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
24
|
-
return res.json();
|
|
25
|
-
}
|
|
26
|
-
function createWebSearchTool(opts) {
|
|
27
|
-
const keenableURL = opts.keenableURL ?? "https://api.keenable.ai/v1/search/public";
|
|
28
|
-
return defineTool({
|
|
29
|
-
name: "web_search",
|
|
30
|
-
description: "Search the web. Returns titles, URLs and short snippets. Use it to find the right pages instead of guessing URLs; then fetch a result URL when you need the full page.",
|
|
31
|
-
schema: z.object({
|
|
32
|
-
query: z.string().min(1).max(500).describe("Search query"),
|
|
33
|
-
max_results: z.number().int().min(1).max(10).optional().describe("Number of results (default 6)")
|
|
34
|
-
}),
|
|
35
|
-
kind: "read",
|
|
36
|
-
target: (input) => input.query,
|
|
37
|
-
parallelSafe: () => true,
|
|
38
|
-
async run(input, ctx) {
|
|
39
|
-
const max = input.max_results ?? 6;
|
|
40
|
-
const errors = [];
|
|
41
|
-
let results = [];
|
|
42
|
-
const bc = opts.botconnector();
|
|
43
|
-
if (bc) {
|
|
44
|
-
try {
|
|
45
|
-
const data = await postJson(`${bc.baseURL.replace(/\/+$/, "")}/web/search`, { query: input.query, max_results: max }, { authorization: `Bearer ${bc.apiKey}` }, ctx.signal);
|
|
46
|
-
results = clean(data.results, max);
|
|
47
|
-
} catch (error) {
|
|
48
|
-
errors.push(`BotConnector: ${error.message}`);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
if (!results.length) {
|
|
52
|
-
try {
|
|
53
|
-
const data = await postJson(keenableURL, { query: input.query }, { "x-keenable-title": "BotConnector" }, ctx.signal);
|
|
54
|
-
results = clean(data.results, max);
|
|
55
|
-
} catch (error) {
|
|
56
|
-
errors.push(`Keenable: ${error.message}`);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
if (!results.length) {
|
|
60
|
-
return { output: errors.length ? `Web search failed (${errors.join("; ")}).` : "No results.", isError: errors.length > 0 };
|
|
61
|
-
}
|
|
62
|
-
const output = results.map((r, i) => `${i + 1}. ${r.title}
|
|
63
|
-
${r.url}${r.snippet ? `
|
|
64
|
-
${r.snippet}` : ""}`).join("\n");
|
|
65
|
-
return { output, display: t("{n} results", { n: results.length }) };
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// src/tools/fetch.ts
|
|
71
|
-
import { lookup as dnsCbLookup } from "dns";
|
|
72
|
-
import { lookup as dnsLookup } from "dns/promises";
|
|
73
|
-
import { isIP } from "net";
|
|
74
|
-
import { Agent, fetch as undiciFetch } from "undici";
|
|
75
|
-
import { z as z2 } from "zod";
|
|
76
|
-
var MAX_CHARS = 12e3;
|
|
77
|
-
var FOCUS_CHUNKS = 3;
|
|
78
|
-
var FOCUS_SIZE = 800;
|
|
79
|
-
var CACHE_MAX = 16;
|
|
80
|
-
var CACHE_TTL_MS = 15 * 6e4;
|
|
81
|
-
var CACHE_MAX_CHARS = 2e6;
|
|
82
|
-
var MAX_BYTES = 5 * 1024 * 1024;
|
|
83
|
-
async function readCapped(res) {
|
|
84
|
-
const reader = res.body?.getReader();
|
|
85
|
-
if (!reader) return { text: "", truncated: false };
|
|
86
|
-
const chunks = [];
|
|
87
|
-
let size = 0;
|
|
88
|
-
for (; ; ) {
|
|
89
|
-
const { done, value } = await reader.read();
|
|
90
|
-
if (done) return { text: Buffer.concat(chunks).toString("utf8"), truncated: false };
|
|
91
|
-
size += value.length;
|
|
92
|
-
if (size > MAX_BYTES) {
|
|
93
|
-
chunks.push(value.subarray(0, value.length - (size - MAX_BYTES)));
|
|
94
|
-
await reader.cancel();
|
|
95
|
-
return { text: Buffer.concat(chunks).toString("utf8"), truncated: true };
|
|
96
|
-
}
|
|
97
|
-
chunks.push(value);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
function htmlToText(html) {
|
|
101
|
-
return html.replace(/<(script|style|noscript)[\s\S]*?<\/\1>/gi, "").replace(/<(br|\/p|\/div|\/h[1-6]|\/li|\/tr)\s*\/?>/gi, "\n").replace(/<[^>]+>/g, "").replace(/ /g, " ").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, "&").split("\n").map((l) => l.replace(/\s+/g, " ").trim()).filter(Boolean).join("\n");
|
|
102
|
-
}
|
|
103
|
-
function describeFetchError(error) {
|
|
104
|
-
const cause = error.cause;
|
|
105
|
-
const code = cause?.code ?? "";
|
|
106
|
-
const detail = cause?.message ?? error.message;
|
|
107
|
-
if (error.name === "TimeoutError") return "no response within 30 seconds";
|
|
108
|
-
if (code === "ENOTFOUND" || code === "EAI_AGAIN") return `${detail} \u2014 DNS could not find the host (typo, offline, or blocked by DNS/ISP)`;
|
|
109
|
-
if (/CERT|SELF_SIGNED|UNABLE_TO/.test(code)) {
|
|
110
|
-
return `${detail} \u2014 TLS certificate rejected; often caused by an antivirus or proxy that inspects HTTPS. Try running with NODE_OPTIONS=--use-system-ca`;
|
|
111
|
-
}
|
|
112
|
-
if (/ECONNRESET|ECONNREFUSED|ETIMEDOUT|EHOSTUNREACH|ENETUNREACH|UND_ERR_CONNECT_TIMEOUT|UND_ERR_SOCKET/.test(code)) {
|
|
113
|
-
return `${detail} \u2014 connection failed (firewall, proxy, or the site is blocked by the network)`;
|
|
114
|
-
}
|
|
115
|
-
return code ? `${detail} (${code})` : detail;
|
|
116
|
-
}
|
|
117
|
-
var tokensOf = (text) => Math.ceil(text.length / 4);
|
|
118
|
-
function isPrivateHost(host) {
|
|
119
|
-
const h = host.toLowerCase().replace(/^\[|\]$/g, "");
|
|
120
|
-
if (h === "localhost" || /\.(local|internal|lan|localdomain|home\.arpa)$/.test(h)) return true;
|
|
121
|
-
if (h.includes(":")) return /^(::1?$|f[cd]|fe[89ab]|::ffff:)/.test(h);
|
|
122
|
-
const v4 = h.match(/^(\d+)\.(\d+)\.\d+\.\d+$/);
|
|
123
|
-
if (v4) {
|
|
124
|
-
const [a, b] = [Number(v4[1]), Number(v4[2])];
|
|
125
|
-
return a === 0 || a === 10 || a === 127 || a === 169 && b === 254 || a === 172 && b >= 16 && b <= 31 || a === 192 && b === 168 || a === 100 && b >= 64 && b <= 127;
|
|
126
|
-
}
|
|
127
|
-
return !h.includes(".");
|
|
128
|
-
}
|
|
129
|
-
var words = (s) => s.toLowerCase().match(/[\p{L}\p{N}]{2,}/gu) ?? [];
|
|
130
|
-
function pinLookup(pinned) {
|
|
131
|
-
return (hostname, options, callback) => {
|
|
132
|
-
const opts = typeof options === "object" && options !== null ? options : {};
|
|
133
|
-
const family = typeof options === "number" ? options : opts.family;
|
|
134
|
-
const realDns = () => dnsCbLookup(hostname, typeof options === "number" ? { family: options } : opts, callback);
|
|
135
|
-
if (!pinned.length) return realDns();
|
|
136
|
-
const list = family ? pinned.filter((a) => a.family === family) : pinned;
|
|
137
|
-
if (!list.length) {
|
|
138
|
-
callback(Object.assign(new Error(`no pinned address for family ${family}`), { code: "ENOTFOUND" }), "");
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
if (opts.all) callback(null, list);
|
|
142
|
-
else callback(null, list[0].address, list[0].family);
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
function pickRelevant(text, query, count = FOCUS_CHUNKS, size = FOCUS_SIZE) {
|
|
146
|
-
const chunks = [];
|
|
147
|
-
let cur = "";
|
|
148
|
-
for (const line of text.split("\n")) {
|
|
149
|
-
for (let i = 0; i < Math.max(line.length, 1); i += size) {
|
|
150
|
-
cur += `${line.slice(i, i + size)}
|
|
151
|
-
`;
|
|
152
|
-
if (cur.length >= size) {
|
|
153
|
-
chunks.push(cur.trimEnd());
|
|
154
|
-
cur = "";
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
if (cur.trim()) chunks.push(cur.trimEnd());
|
|
159
|
-
const q = [...new Set(words(query))];
|
|
160
|
-
const docs = chunks.map(words);
|
|
161
|
-
const avg = docs.reduce((n, d) => n + d.length, 0) / (docs.length || 1) || 1;
|
|
162
|
-
const idf = q.map((t2) => {
|
|
163
|
-
const df = docs.filter((d) => d.includes(t2)).length;
|
|
164
|
-
return Math.log(1 + (docs.length - df + 0.5) / (df + 0.5));
|
|
165
|
-
});
|
|
166
|
-
const scored = docs.map((d, i) => ({
|
|
167
|
-
i,
|
|
168
|
-
score: q.reduce((sum, t2, k) => {
|
|
169
|
-
const tf = d.filter((w) => w === t2).length;
|
|
170
|
-
return sum + idf[k] * tf * 2.2 / (tf + 1.2 * (0.25 + 0.75 * d.length / avg));
|
|
171
|
-
}, 0)
|
|
172
|
-
})).filter((c) => c.score > 0).sort((a, b) => b.score - a.score).slice(0, count).sort((a, b) => a.i - b.i);
|
|
173
|
-
return scored.length ? scored.map((c) => chunks[c.i]).join("\n\u2026\n") : null;
|
|
174
|
-
}
|
|
175
|
-
var cache = /* @__PURE__ */ new Map();
|
|
176
|
-
function remember(key, value, size) {
|
|
177
|
-
if (size > CACHE_MAX_CHARS) return;
|
|
178
|
-
cache.delete(key);
|
|
179
|
-
cache.set(key, value);
|
|
180
|
-
if (cache.size > CACHE_MAX) cache.delete(cache.keys().next().value);
|
|
181
|
-
}
|
|
182
|
-
function recall(key) {
|
|
183
|
-
const hit = cache.get(key);
|
|
184
|
-
if (typeof hit === "object" && Date.now() - hit.at > CACHE_TTL_MS) {
|
|
185
|
-
cache.delete(key);
|
|
186
|
-
return void 0;
|
|
187
|
-
}
|
|
188
|
-
return hit;
|
|
189
|
-
}
|
|
190
|
-
var ACCEPT = "text/markdown, text/html;q=0.9, text/plain;q=0.8, */*;q=0.5";
|
|
191
|
-
var withCost = (text, what) => `${what} \xB7 ${t("~{n} tokens", { n: tokensOf(text) })}`;
|
|
192
|
-
function createFetchTool(opts = {}) {
|
|
193
|
-
const keenableURL = opts.keenableURL === void 0 ? "https://api.keenable.ai/v1/fetch/public" : opts.keenableURL;
|
|
194
|
-
const isPrivate = opts.isPrivate ?? isPrivateHost;
|
|
195
|
-
const lookup = opts.lookup ?? ((hostname) => dnsLookup(hostname, { all: true }));
|
|
196
|
-
return defineTool({
|
|
197
|
-
name: "fetch",
|
|
198
|
-
description: `Fetch a URL (http/https) as text/markdown. Costs the user tokens, so ask for as little as you need:
|
|
199
|
-
- Pass \`prompt\` (what you want to know from the page) to get only the relevant excerpt instead of the whole page. Prefer this whenever you are looking for specific facts.
|
|
200
|
-
- Without \`prompt\` you get the first ${MAX_CHARS} characters; the reply tells you the \`offset\` to continue from.
|
|
201
|
-
- Fetching a page that is already in this conversation is wasteful; reuse what you have.`,
|
|
202
|
-
schema: z2.object({
|
|
203
|
-
url: z2.string().describe("Absolute http(s) URL"),
|
|
204
|
-
prompt: z2.string().max(2e3).optional().describe("What to look for in the page; returns only the relevant excerpt"),
|
|
205
|
-
offset: z2.number().int().min(0).optional().describe("Start reading at this character (to continue a truncated page)")
|
|
206
|
-
}),
|
|
207
|
-
kind: "fetch",
|
|
208
|
-
target: (input) => input.url,
|
|
209
|
-
async run(input, ctx) {
|
|
210
|
-
if (!/^https?:\/\//i.test(input.url)) return { output: "URL must start with http:// or https://", isError: true };
|
|
211
|
-
const target = new URL(input.url);
|
|
212
|
-
let pinned;
|
|
213
|
-
if (!isPrivate(target.hostname) && isIP(target.hostname) === 0) {
|
|
214
|
-
try {
|
|
215
|
-
const addresses = await lookup(target.hostname);
|
|
216
|
-
const internal = addresses.find((a) => isPrivate(a.address));
|
|
217
|
-
if (internal) {
|
|
218
|
-
return {
|
|
219
|
-
output: t("Blocked: {host} resolves to a private address ({addr}). Fetching an internal host through a public DNS name is not allowed.", { host: target.hostname, addr: internal.address }),
|
|
220
|
-
isError: true
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
pinned = addresses;
|
|
224
|
-
} catch {
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
const prompt = input.prompt?.trim();
|
|
228
|
-
const askKeenable = !!prompt && !input.offset && !!keenableURL && !target.username && !target.password && !isPrivate(target.hostname);
|
|
229
|
-
if (askKeenable) {
|
|
230
|
-
const key = `x
|
|
231
|
-
${input.url}
|
|
232
|
-
${prompt}`;
|
|
233
|
-
const hit = recall(key);
|
|
234
|
-
if (hit) {
|
|
235
|
-
ctx.refundFetch?.();
|
|
236
|
-
return { output: hit, display: withCost(hit, t("focused excerpt \xB7 cache")) };
|
|
237
|
-
}
|
|
238
|
-
const out = await extractWithKeenable(keenableURL, input.url, prompt, ctx.signal);
|
|
239
|
-
if (out) {
|
|
240
|
-
const output2 = `[Excerpt from ${input.url} for "${prompt}" (extracted by Keenable). If it says the answer is not there, try fetch without a prompt.]
|
|
241
|
-
${out}`;
|
|
242
|
-
remember(key, output2, output2.length);
|
|
243
|
-
return { output: output2, display: withCost(output2, t("focused excerpt (Keenable)")) };
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
let page = recall(`p
|
|
247
|
-
${input.url}`);
|
|
248
|
-
const cached = !!page;
|
|
249
|
-
if (cached) ctx.refundFetch?.();
|
|
250
|
-
if (!page) {
|
|
251
|
-
const loaded = await loadPage(input.url, ctx.signal, pinned, opts.fetchPage);
|
|
252
|
-
if ("error" in loaded) return { output: loaded.error, isError: true };
|
|
253
|
-
page = loaded;
|
|
254
|
-
remember(`p
|
|
255
|
-
${input.url}`, page, page.text.length);
|
|
256
|
-
}
|
|
257
|
-
const { text, truncated } = page;
|
|
258
|
-
const via = cached ? " \xB7 cache" : "";
|
|
259
|
-
if (prompt && !input.offset) {
|
|
260
|
-
const picked = pickRelevant(text, prompt);
|
|
261
|
-
if (picked) {
|
|
262
|
-
const output2 = `[Most relevant excerpt from ${input.url} for "${prompt}" (${text.length} characters total). Full page: fetch without a prompt.]
|
|
263
|
-
${picked}`;
|
|
264
|
-
return { output: output2, display: withCost(output2, `${t("focused excerpt (local)")}${via}`) };
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
const offset = input.offset ?? 0;
|
|
268
|
-
if (offset >= text.length && text.length > 0) {
|
|
269
|
-
return { output: `offset ${offset} is past the end of the page (${text.length} characters).`, isError: true };
|
|
270
|
-
}
|
|
271
|
-
const end = Math.min(offset + MAX_CHARS, text.length);
|
|
272
|
-
let output = text.slice(offset, end);
|
|
273
|
-
if (end < text.length || truncated) {
|
|
274
|
-
const total = truncated ? `${text.length}+` : text.length;
|
|
275
|
-
output += `
|
|
276
|
-
\u2026 [truncated: characters ${offset}-${end} of ${total}. Continue with offset=${end}, or use prompt for a focused excerpt.]`;
|
|
277
|
-
}
|
|
278
|
-
const size = truncated ? t("over 5 MB, truncated") : t("{n} characters", { n: text.length });
|
|
279
|
-
return { output, display: withCost(output, `${size}${via}`) };
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
async function extractWithKeenable(endpoint, url, prompt, signal) {
|
|
284
|
-
try {
|
|
285
|
-
const u = new URL(endpoint);
|
|
286
|
-
u.searchParams.set("url", url);
|
|
287
|
-
u.searchParams.set("prompt", prompt);
|
|
288
|
-
u.searchParams.set("live", "true");
|
|
289
|
-
u.searchParams.set("max_chars", String(MAX_CHARS));
|
|
290
|
-
const res = await fetch(u, { headers: { "X-Keenable-Title": "BotConnector" }, signal: AbortSignal.any([signal, AbortSignal.timeout(25e3)]) });
|
|
291
|
-
if (!res.ok) return void 0;
|
|
292
|
-
const content = (await res.json()).content;
|
|
293
|
-
return typeof content === "string" && content.trim() ? content.slice(0, MAX_CHARS) : void 0;
|
|
294
|
-
} catch {
|
|
295
|
-
return void 0;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
async function loadPage(inputUrl, signal, pinned, fetchPage) {
|
|
299
|
-
let url = new URL(inputUrl);
|
|
300
|
-
const dispatcher = pinned?.length ? new Agent({ connect: { lookup: pinLookup(pinned) } }) : void 0;
|
|
301
|
-
const doFetch = fetchPage ?? (dispatcher ? undiciFetch : fetch);
|
|
302
|
-
try {
|
|
303
|
-
let res;
|
|
304
|
-
for (let hop = 0; hop < 5; hop++) {
|
|
305
|
-
res = await doFetch(url, {
|
|
306
|
-
headers: { accept: ACCEPT },
|
|
307
|
-
signal: AbortSignal.any([signal, AbortSignal.timeout(3e4)]),
|
|
308
|
-
redirect: "manual",
|
|
309
|
-
...dispatcher ? { dispatcher } : {}
|
|
310
|
-
});
|
|
311
|
-
const location = res.status >= 300 && res.status < 400 ? res.headers.get("location") : null;
|
|
312
|
-
if (!location) break;
|
|
313
|
-
const next = new URL(location, url);
|
|
314
|
-
if (next.host !== url.host) {
|
|
315
|
-
await res.body?.cancel();
|
|
316
|
-
return { error: `Redirect to another host: ${next.href}. Call fetch again with that URL if needed (permission will be requested).` };
|
|
317
|
-
}
|
|
318
|
-
await res.body?.cancel();
|
|
319
|
-
url = next;
|
|
320
|
-
}
|
|
321
|
-
if (!res) return { error: `Failed to fetch ${inputUrl}` };
|
|
322
|
-
const { text: body, truncated } = await readCapped(res);
|
|
323
|
-
const type = res.headers.get("content-type") ?? "";
|
|
324
|
-
const text = type.includes("html") ? htmlToText(body) : body;
|
|
325
|
-
if (!res.ok) return { error: `HTTP ${res.status} from ${inputUrl}: ${text.slice(0, 500)}` };
|
|
326
|
-
return { text, truncated, at: Date.now() };
|
|
327
|
-
} catch (error) {
|
|
328
|
-
return { error: `Failed to fetch ${inputUrl}: ${describeFetchError(error)}` };
|
|
329
|
-
} finally {
|
|
330
|
-
await dispatcher?.close().catch(() => {
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
var fetchTool = createFetchTool();
|
|
335
|
-
|
|
336
|
-
export {
|
|
337
|
-
isPrivateHost,
|
|
338
|
-
createFetchTool,
|
|
339
|
-
fetchTool,
|
|
340
|
-
createWebSearchTool
|
|
341
|
-
};
|
package/dist/chunk-7XD47KN5.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
t
|
|
4
|
-
} from "./chunk-R754XIBJ.js";
|
|
5
|
-
|
|
6
|
-
// src/reasoning.ts
|
|
7
|
-
var REASONING_LEVELS = ["auto", "off", "low", "medium", "high", "max"];
|
|
8
|
-
var OPENAI_LEVELS = ["auto", "low", "medium", "high"];
|
|
9
|
-
var BOTCONNECTOR_LEVELS = REASONING_LEVELS;
|
|
10
|
-
function isReasoningLevel(value) {
|
|
11
|
-
return REASONING_LEVELS.includes(value);
|
|
12
|
-
}
|
|
13
|
-
function parseReasoningLevel(value, label = "reasoning") {
|
|
14
|
-
if (!isReasoningLevel(value)) {
|
|
15
|
-
throw new Error(t("{label} must be one of: {levels}", { label, levels: REASONING_LEVELS.join(", ") }));
|
|
16
|
-
}
|
|
17
|
-
return value;
|
|
18
|
-
}
|
|
19
|
-
function reasoningCapability(providerId) {
|
|
20
|
-
switch (providerId) {
|
|
21
|
-
case "bc-cloud":
|
|
22
|
-
return { levels: BOTCONNECTOR_LEVELS, parameter: "reasoning_effort" };
|
|
23
|
-
case "openai":
|
|
24
|
-
case "gmi":
|
|
25
|
-
case "gmicloud":
|
|
26
|
-
case "vertex-maas":
|
|
27
|
-
case "deepseek":
|
|
28
|
-
case "groq":
|
|
29
|
-
case "together":
|
|
30
|
-
case "fireworks":
|
|
31
|
-
case "mistral":
|
|
32
|
-
return { levels: OPENAI_LEVELS, parameter: "reasoning_effort" };
|
|
33
|
-
case "openrouter":
|
|
34
|
-
return { levels: ["auto", "low", "medium", "high"], parameter: "reasoning" };
|
|
35
|
-
default:
|
|
36
|
-
return void 0;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
function supportedReasoningLevels(providerId) {
|
|
40
|
-
return reasoningCapability(providerId)?.levels ?? ["auto"];
|
|
41
|
-
}
|
|
42
|
-
function assertReasoningSupported(providerId, level) {
|
|
43
|
-
if (level === "auto") return;
|
|
44
|
-
const capability = reasoningCapability(providerId);
|
|
45
|
-
if (!capability) {
|
|
46
|
-
throw new Error(t("This provider has no manual reasoning setting yet. Use Auto."));
|
|
47
|
-
}
|
|
48
|
-
if (!capability.levels.includes(level)) {
|
|
49
|
-
const supported = capability.levels.filter((x) => x !== "auto").map(capitalize).join("/");
|
|
50
|
-
throw new Error(t("This model/provider does not support reasoning level '{level}'. Use Auto{supported}.", { level, supported: supported ? `/${supported}` : "" }));
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
function reasoningPayload(providerId, level) {
|
|
54
|
-
if (level === "auto") return {};
|
|
55
|
-
assertReasoningSupported(providerId, level);
|
|
56
|
-
const capability = reasoningCapability(providerId);
|
|
57
|
-
if (capability.parameter === "reasoning") return { reasoning: { effort: level } };
|
|
58
|
-
return { reasoning_effort: level };
|
|
59
|
-
}
|
|
60
|
-
function capitalize(value) {
|
|
61
|
-
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export {
|
|
65
|
-
REASONING_LEVELS,
|
|
66
|
-
isReasoningLevel,
|
|
67
|
-
parseReasoningLevel,
|
|
68
|
-
supportedReasoningLevels,
|
|
69
|
-
assertReasoningSupported,
|
|
70
|
-
reasoningPayload
|
|
71
|
-
};
|
package/dist/chunk-INMSTUB2.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
hasKey,
|
|
4
|
-
providerName
|
|
5
|
-
} from "./chunk-6SDRWEPN.js";
|
|
6
|
-
import {
|
|
7
|
-
createProvider
|
|
8
|
-
} from "./chunk-6JK4IBGK.js";
|
|
9
|
-
import {
|
|
10
|
-
PRESETS,
|
|
11
|
-
readCredentials
|
|
12
|
-
} from "./chunk-TLCL6DC7.js";
|
|
13
|
-
import {
|
|
14
|
-
t
|
|
15
|
-
} from "./chunk-R754XIBJ.js";
|
|
16
|
-
|
|
17
|
-
// src/models.ts
|
|
18
|
-
function order(ids) {
|
|
19
|
-
const presetIds = PRESETS.map((p) => p.id);
|
|
20
|
-
const presets = presetIds.filter((id) => ids.includes(id));
|
|
21
|
-
const custom = ids.filter((id) => !presetIds.includes(id)).sort();
|
|
22
|
-
return [...presets, ...custom];
|
|
23
|
-
}
|
|
24
|
-
async function listAllModels(config, env = process.env, opts = {}) {
|
|
25
|
-
const timeoutMs = opts.timeoutMs ?? 5e3;
|
|
26
|
-
const baseFetch = opts.fetch ?? fetch;
|
|
27
|
-
const untrusted = new Set(config.projectProviders ?? []);
|
|
28
|
-
const ids = order(Object.keys(config.providers)).filter((id) => opts.only ? id === opts.only : !untrusted.has(id) && hasKey(config, id, env));
|
|
29
|
-
const results = await Promise.all(
|
|
30
|
-
ids.map(async (id) => {
|
|
31
|
-
const provider = config.providers[id];
|
|
32
|
-
const apiKey = (opts.keyOverride && id === opts.only ? opts.keyOverride : void 0) || readCredentials(env)[id] || (provider.apiKeyEnv ? env[provider.apiKeyEnv] : void 0) || void 0;
|
|
33
|
-
const local = !provider.apiKeyEnv;
|
|
34
|
-
const timedFetch = ((input, init) => baseFetch(input, { ...init, signal: AbortSignal.timeout(timeoutMs) }));
|
|
35
|
-
const list = createProvider({ baseURL: provider.baseURL.replace(/\/+$/, ""), apiKey, model: "", fetch: timedFetch }).listModels();
|
|
36
|
-
let timer;
|
|
37
|
-
const timeout = new Promise((_, reject) => {
|
|
38
|
-
timer = setTimeout(() => reject(new Error("timeout")), timeoutMs);
|
|
39
|
-
});
|
|
40
|
-
try {
|
|
41
|
-
const models = await Promise.race([list, timeout]);
|
|
42
|
-
return { providerId: id, providerName: providerName(config, id), models };
|
|
43
|
-
} catch {
|
|
44
|
-
if (local && !opts.only) return void 0;
|
|
45
|
-
return { providerId: id, providerName: providerName(config, id), models: [], error: t("could not be reached") };
|
|
46
|
-
} finally {
|
|
47
|
-
clearTimeout(timer);
|
|
48
|
-
}
|
|
49
|
-
})
|
|
50
|
-
);
|
|
51
|
-
return results.filter((g) => !!g);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export {
|
|
55
|
-
listAllModels
|
|
56
|
-
};
|