@infernetprotocol/cli 0.1.92 → 0.1.94
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/commands/chat.js +90 -1
- package/commands/help.js +1 -0
- package/commands/mcp.js +26 -2
- package/commands/plugins.js +103 -0
- package/index.js +3 -1
- package/lib/chat-executor.js +21 -1
- package/lib/plugins-client.js +78 -0
- package/package.json +9 -9
package/commands/chat.js
CHANGED
|
@@ -21,6 +21,8 @@
|
|
|
21
21
|
import { createEngine, MSG } from "@infernetprotocol/engine";
|
|
22
22
|
import { loadConfig } from "../lib/config.js";
|
|
23
23
|
import { submitChatJob, streamChatEvents } from "../lib/remote-chat.js";
|
|
24
|
+
import { createPluginsClient, readSse } from "../lib/plugins-client.js";
|
|
25
|
+
import { createInterface } from "node:readline/promises";
|
|
24
26
|
|
|
25
27
|
const HELP = `infernet chat — run a chat inference (P2P network or local)
|
|
26
28
|
|
|
@@ -44,6 +46,12 @@ Common flags:
|
|
|
44
46
|
|
|
45
47
|
Network-only flags:
|
|
46
48
|
--url <url> Control-plane URL override (default: config.controlPlane.url).
|
|
49
|
+
--no-plugins Do not use your plugins for this message (see \`infernet plugins\`).
|
|
50
|
+
--yes Allow plugin tools that change things without asking.
|
|
51
|
+
|
|
52
|
+
Plugins: when you are signed in (\`infernet login\`) and have plugins on, the
|
|
53
|
+
network turn runs with them: the model can call their tools, and tools that
|
|
54
|
+
change or delete things ask first. Plugin turns are sent in plaintext.
|
|
47
55
|
|
|
48
56
|
Local-only flags:
|
|
49
57
|
--backend <kind> ollama | mojo | stub. Default: auto.
|
|
@@ -126,6 +134,74 @@ async function runRemote({ baseUrl, messages, model, temperature, maxTokens, jso
|
|
|
126
134
|
return exitCode;
|
|
127
135
|
}
|
|
128
136
|
|
|
137
|
+
async function askApproval(call) {
|
|
138
|
+
if (!process.stdin.isTTY || !process.stderr.isTTY) return "deny";
|
|
139
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
140
|
+
try {
|
|
141
|
+
const args = JSON.stringify(call.arguments ?? {});
|
|
142
|
+
const a = await rl.question(`\n[plugin] allow ${call.pluginName || call.plugin} to run ${call.title || call.tool} ${args}? [y/N] `);
|
|
143
|
+
return /^y(es)?$/i.test(a.trim()) ? "allow" : "deny";
|
|
144
|
+
} finally {
|
|
145
|
+
rl.close();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** A network turn with your plugins: the server runs the tool loop, we render its events. */
|
|
150
|
+
async function runPluginChat({ baseUrl, token, messages, model, maxTokens, jsonMode, autoYes }) {
|
|
151
|
+
let body = { messages, plugins: true, ...(model ? { modelName: model } : {}), ...(typeof maxTokens === "number" ? { maxTokens } : {}) };
|
|
152
|
+
const tty = process.stdout.isTTY && !jsonMode;
|
|
153
|
+
for (let round = 0; round < 6; round++) {
|
|
154
|
+
const res = await fetch(new URL("/api/chat", baseUrl), {
|
|
155
|
+
method: "POST",
|
|
156
|
+
headers: { "content-type": "application/json", accept: "text/event-stream", authorization: `Bearer ${token}` },
|
|
157
|
+
body: JSON.stringify(body)
|
|
158
|
+
});
|
|
159
|
+
if (!res.ok || !(res.headers.get("content-type") ?? "").includes("text/event-stream")) {
|
|
160
|
+
const t = await res.text().catch(() => "");
|
|
161
|
+
let msg = t.slice(0, 300);
|
|
162
|
+
try { msg = JSON.parse(t).error ?? msg; } catch { /* text */ }
|
|
163
|
+
process.stderr.write(`error: ${msg || `HTTP ${res.status}`}\n`);
|
|
164
|
+
return 1;
|
|
165
|
+
}
|
|
166
|
+
let draft = "";
|
|
167
|
+
let printed = 0;
|
|
168
|
+
let pending = null;
|
|
169
|
+
let failed = false;
|
|
170
|
+
for await (const ev of readSse(res)) {
|
|
171
|
+
if (jsonMode) { emitJson(ev); }
|
|
172
|
+
if (ev.type === "step") { draft = ""; printed = 0; }
|
|
173
|
+
else if (ev.type === "token" && !jsonMode) {
|
|
174
|
+
draft += ev.text;
|
|
175
|
+
// Hold back a tool_call block; print prose as it streams.
|
|
176
|
+
const cut = draft.search(/```[ \t]*tool|<tool_call/i);
|
|
177
|
+
const shown = cut === -1 ? draft.replace(/`{1,3}$/, "") : draft.slice(0, cut);
|
|
178
|
+
if (shown.length > printed) { process.stdout.write(shown.slice(printed)); printed = shown.length; }
|
|
179
|
+
} else if (ev.type === "tool_call" && !jsonMode) {
|
|
180
|
+
if (printed) process.stdout.write("\n");
|
|
181
|
+
process.stderr.write(`[plugin] ${ev.plugin} · ${ev.title || ev.tool} ${JSON.stringify(ev.arguments ?? {})}\n`);
|
|
182
|
+
} else if (ev.type === "tool_result" && !jsonMode) {
|
|
183
|
+
const first = String(ev.text ?? "").split("\n").slice(0, 3).join(" ").slice(0, 200);
|
|
184
|
+
process.stderr.write(`[plugin] ${ev.denied ? "declined" : ev.isError ? "error" : "ok"}: ${first}\n`);
|
|
185
|
+
} else if (ev.type === "plugins_skipped" && !jsonMode) {
|
|
186
|
+
process.stderr.write(`[plugin] not used (sign in: infernet plugins connect <slug>): ${ev.skipped.map((s) => s.slug).join(", ")}\n`);
|
|
187
|
+
} else if (ev.type === "text" && !jsonMode) {
|
|
188
|
+
if (ev.text.length > printed) process.stdout.write(ev.text.slice(printed));
|
|
189
|
+
if (tty) process.stdout.write("\n");
|
|
190
|
+
} else if (ev.type === "approval_needed") {
|
|
191
|
+
pending = ev;
|
|
192
|
+
} else if (ev.type === "error") {
|
|
193
|
+
if (!jsonMode) process.stderr.write(`\nerror: ${ev.message}\n`);
|
|
194
|
+
failed = true;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (failed) return 1;
|
|
198
|
+
if (!pending) return 0;
|
|
199
|
+
const decision = autoYes ? "allow" : await askApproval(pending.call);
|
|
200
|
+
body = { plugins: true, resume: { approvalId: pending.approvalId, decision }, ...(model ? { modelName: model } : {}) };
|
|
201
|
+
}
|
|
202
|
+
return 0;
|
|
203
|
+
}
|
|
204
|
+
|
|
129
205
|
async function runLocal({ engineOpts, messages, model, temperature, maxTokens, jsonMode }) {
|
|
130
206
|
let engine;
|
|
131
207
|
try {
|
|
@@ -185,7 +261,7 @@ export default async function chat(args) {
|
|
|
185
261
|
|
|
186
262
|
// Reclaim values eaten by the greedy parser for known-boolean flags.
|
|
187
263
|
const reclaimed = [];
|
|
188
|
-
for (const name of ["json", "remote", "local"]) {
|
|
264
|
+
for (const name of ["json", "remote", "local", "no-plugins", "yes"]) {
|
|
189
265
|
const v = args.get(name);
|
|
190
266
|
if (typeof v === "string") reclaimed.push(v);
|
|
191
267
|
}
|
|
@@ -237,6 +313,19 @@ export default async function chat(args) {
|
|
|
237
313
|
);
|
|
238
314
|
return 2;
|
|
239
315
|
}
|
|
316
|
+
// Signed in with plugins on: the turn runs with them.
|
|
317
|
+
const token = config.auth?.bearerToken ?? null;
|
|
318
|
+
if (token && !args.has("no-plugins")) {
|
|
319
|
+
try {
|
|
320
|
+
const d = await createPluginsClient({ baseUrl: remoteUrl.replace(/\/+$/, ""), token }).list();
|
|
321
|
+
const usable = (d.plugins ?? []).filter((p) => p.enabled && !p.needs_sign_in);
|
|
322
|
+
if (usable.length) {
|
|
323
|
+
return runPluginChat({ baseUrl: remoteUrl, token, messages, model, maxTokens, jsonMode, autoYes: args.has("yes") });
|
|
324
|
+
}
|
|
325
|
+
} catch {
|
|
326
|
+
/* plugins unavailable: plain network turn */
|
|
327
|
+
}
|
|
328
|
+
}
|
|
240
329
|
return runRemote({
|
|
241
330
|
baseUrl: remoteUrl,
|
|
242
331
|
messages,
|
package/commands/help.js
CHANGED
|
@@ -41,6 +41,7 @@ Diagnostics:
|
|
|
41
41
|
Payments:
|
|
42
42
|
payout Earnings, withdrawals and payout address
|
|
43
43
|
payments Show recent payment transactions
|
|
44
|
+
plugins Tools the model can use in chat (remote MCP servers): add, ls, rm, on, off
|
|
44
45
|
credits Your consumer compute credits (not earnings); redeem a code
|
|
45
46
|
redeem Redeem a credit code: infernet redeem CR-XXXX-XXXX-XXXX-XXXX
|
|
46
47
|
invites Scarce invites (both sides get credits) and your affiliate link
|
package/commands/mcp.js
CHANGED
|
@@ -15,6 +15,7 @@ import { resolveClientOptions, createReservationsClient } from '../lib/reservati
|
|
|
15
15
|
import { createOrdersClient, x402KeyFrom, DEFAULT_MAX_USD } from '../lib/orders-client.js';
|
|
16
16
|
import { resolveCreditsOptions, createCreditsClient } from '../lib/credits-client.js';
|
|
17
17
|
import { resolveBatchOptions, createBatchClient } from '../lib/batch-client.js';
|
|
18
|
+
import { resolvePluginsOptions, createPluginsClient } from '../lib/plugins-client.js';
|
|
18
19
|
import { CURRENT_VERSION } from '../lib/version.js';
|
|
19
20
|
|
|
20
21
|
const PROTOCOL_VERSION = '2025-06-18';
|
|
@@ -186,7 +187,29 @@ export const TOOLS = [
|
|
|
186
187
|
},
|
|
187
188
|
{ name: 'batch_status', description: 'A batch: status, item counts, cost so far, funding, and outputs once finished.', inputSchema: { type: 'object', required: ['id'], properties: { id: batchId } }, run: (c, a) => c.batch.status(a.id) },
|
|
188
189
|
{ name: 'batch_results', description: 'A batch\'s results as JSONL: custom_id, status, output, estimated tokens, cost.', inputSchema: { type: 'object', required: ['id'], properties: { id: batchId } }, run: (c, a) => c.batch.results(a.id) },
|
|
189
|
-
{ name: 'billing_balance', description: 'Your compute balance: earned (node earnings) spendable, prepaid available, holds, funding order.', inputSchema: { type: 'object', properties: {} }, run: (c) => c.batch.balance() }
|
|
190
|
+
{ name: 'billing_balance', description: 'Your compute balance: earned (node earnings) spendable, prepaid available, holds, funding order.', inputSchema: { type: 'object', properties: {} }, run: (c) => c.batch.balance() },
|
|
191
|
+
// Chat plugins (remote MCP servers on the signed-in account) used by /chat,
|
|
192
|
+
// `infernet chat` and the desktop app.
|
|
193
|
+
{
|
|
194
|
+
name: 'plugins_list',
|
|
195
|
+
description: 'Your chat plugins (remote MCP servers the Infernet chat model can use) with on/off and sign-in state, plus the catalog of one-click plugins.',
|
|
196
|
+
inputSchema: { type: 'object', properties: {} },
|
|
197
|
+
annotations: { readOnlyHint: true },
|
|
198
|
+
run: (c) => c.plugins.list()
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
name: 'plugins_add',
|
|
202
|
+
description: 'Add a chat plugin by URL (https://.../mcp) or catalog name (c0mpute, threatcrush). When it needs sign-in the result has connect_url: give that link to the person to open in a browser (valid 15 minutes). No client id or secret is needed.',
|
|
203
|
+
inputSchema: { type: 'object', required: ['url'], properties: { url: { type: 'string', description: 'plugin URL or catalog name' } } },
|
|
204
|
+
run: (c, a) => c.plugins.add(a.url)
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
name: 'plugins_remove',
|
|
208
|
+
description: 'Remove a chat plugin and its stored tokens.',
|
|
209
|
+
inputSchema: { type: 'object', required: ['slug'], properties: { slug: { type: 'string' } } },
|
|
210
|
+
annotations: { destructiveHint: true },
|
|
211
|
+
run: (c, a) => c.plugins.remove(a.slug)
|
|
212
|
+
}
|
|
190
213
|
];
|
|
191
214
|
|
|
192
215
|
/** Handle one JSON-RPC message; returns the response object or null for notifications. */
|
|
@@ -222,13 +245,14 @@ export async function handleMessage(msg, client) {
|
|
|
222
245
|
|
|
223
246
|
export default async function mcp(args) {
|
|
224
247
|
if (args.has('help') || args.has('h')) {
|
|
225
|
-
process.stdout.write('infernet mcp — MCP server (stdio): self-serve orders, managed-endpoint reservations, credits, invites
|
|
248
|
+
process.stdout.write('infernet mcp — MCP server (stdio): self-serve orders, managed-endpoint reservations, credits, invites, paid batch inference and chat plugins\n\n claude mcp add infernet -- infernet mcp\n');
|
|
226
249
|
return 0;
|
|
227
250
|
}
|
|
228
251
|
const client = createReservationsClient(await resolveClientOptions({ url: args.get('url'), token: args.get('token'), buyerToken: args.get('buyer-token') }));
|
|
229
252
|
client.orders = createOrdersClient({ baseUrl: (await resolveClientOptions({ url: args.get('url') })).baseUrl });
|
|
230
253
|
client.credits = createCreditsClient(await resolveCreditsOptions({ url: args.get('url'), token: args.get('token') }));
|
|
231
254
|
client.batch = createBatchClient(await resolveBatchOptions({ url: args.get('url'), key: args.get('key'), token: args.get('token') }));
|
|
255
|
+
client.plugins = createPluginsClient(await resolvePluginsOptions({ url: args.get('url'), token: args.get('token') }));
|
|
232
256
|
const rl = createInterface({ input: process.stdin });
|
|
233
257
|
for await (const line of rl) {
|
|
234
258
|
if (!line.trim()) continue;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `infernet plugins` — chat plugins: remote MCP servers the model can use in
|
|
3
|
+
* `infernet chat`, /chat on the site, and the desktop app.
|
|
4
|
+
*
|
|
5
|
+
* infernet plugins list yours (and the catalog)
|
|
6
|
+
* infernet plugins add <url|name> add one; opens the browser to sign in if it asks
|
|
7
|
+
* infernet plugins rm <slug> remove
|
|
8
|
+
* infernet plugins on|off <slug> turn on or off
|
|
9
|
+
* infernet plugins connect <slug> sign in again
|
|
10
|
+
*/
|
|
11
|
+
import { createPluginsClient, openBrowser, resolvePluginsOptions } from '../lib/plugins-client.js';
|
|
12
|
+
|
|
13
|
+
export const PLUGINS_HELP = `infernet plugins — tools the model can use in chat (remote MCP servers)
|
|
14
|
+
|
|
15
|
+
Usage:
|
|
16
|
+
infernet plugins Your plugins and the catalog
|
|
17
|
+
infernet plugins add <url|name> Add by URL (https://.../mcp) or catalog name (c0mpute, threatcrush).
|
|
18
|
+
If it wants sign-in, a browser opens on its own page; on a
|
|
19
|
+
headless box the one-time link is printed instead.
|
|
20
|
+
infernet plugins rm <slug> Remove a plugin and its tokens
|
|
21
|
+
infernet plugins on <slug> Turn on
|
|
22
|
+
infernet plugins off <slug> Turn off
|
|
23
|
+
infernet plugins connect <slug> Sign in (again)
|
|
24
|
+
|
|
25
|
+
Options: --json, --url <base>, --token <bearer>, --no-browser
|
|
26
|
+
Signed-in account required (\`infernet login\`). \`infernet chat\` uses enabled plugins automatically.
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
function out(args, data, text) {
|
|
30
|
+
process.stdout.write(args.has('json') ? `${JSON.stringify(data, null, 2)}\n` : `${text}\n`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function line(p) {
|
|
34
|
+
const state = p.needs_sign_in ? 'needs sign-in' : p.enabled ? 'on' : 'off';
|
|
35
|
+
return ` ${p.slug.padEnd(16)} ${state.padEnd(14)} ${String(p.tools.length).padStart(3)} tools ${p.name} ${p.url}`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function signInHint(args, url) {
|
|
39
|
+
const opened = !args.has('no-browser') && openBrowser(url);
|
|
40
|
+
return opened
|
|
41
|
+
? `Opened your browser to sign in. If nothing appeared, open:\n ${url}`
|
|
42
|
+
: `Open this link in any browser to sign in (valid 15 minutes):\n ${url}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default async function plugins(args) {
|
|
46
|
+
const [sub = 'ls', ...rest] = args.positional ?? [];
|
|
47
|
+
if (args.has('help') || args.has('h') || sub === 'help') {
|
|
48
|
+
process.stdout.write(PLUGINS_HELP);
|
|
49
|
+
return 0;
|
|
50
|
+
}
|
|
51
|
+
const c = createPluginsClient(await resolvePluginsOptions({ url: args.get('url'), token: args.get('token') }));
|
|
52
|
+
const arg = rest.join(' ').trim();
|
|
53
|
+
try {
|
|
54
|
+
if (sub === 'ls' || sub === 'list') {
|
|
55
|
+
const d = await c.list();
|
|
56
|
+
const mine = d.plugins ?? [];
|
|
57
|
+
const have = new Set(mine.map((p) => p.url));
|
|
58
|
+
const text = [
|
|
59
|
+
mine.length ? 'Your plugins:' : 'No plugins yet.',
|
|
60
|
+
...mine.map(line),
|
|
61
|
+
'',
|
|
62
|
+
'Catalog (infernet plugins add <name>):',
|
|
63
|
+
...(d.catalog ?? []).map((e) => ` ${e.slug.padEnd(16)} ${have.has(e.url) ? 'added' : ' '} ${e.name}: ${e.description ?? e.url}`)
|
|
64
|
+
].join('\n');
|
|
65
|
+
out(args, d, text);
|
|
66
|
+
return 0;
|
|
67
|
+
}
|
|
68
|
+
if (sub === 'add' || sub === 'install') {
|
|
69
|
+
if (!arg) { process.stderr.write('Usage: infernet plugins add <url|name>\n'); return 2; }
|
|
70
|
+
const r = await c.add(arg);
|
|
71
|
+
const p = r.plugin;
|
|
72
|
+
let text = r.already ? `${p.name} (${p.slug}) is already added.` : `Added ${p.name} (${p.slug}), ${p.tools.length} tools.`;
|
|
73
|
+
if (r.connect_url && p.needs_sign_in) text += `\n${signInHint(args, r.connect_url)}`;
|
|
74
|
+
else if (r.connect_url && p.can_sign_in) text += `\nIt also offers sign-in for more tools: infernet plugins connect ${p.slug}`;
|
|
75
|
+
out(args, r, text);
|
|
76
|
+
return 0;
|
|
77
|
+
}
|
|
78
|
+
if (sub === 'connect' || sub === 'login') {
|
|
79
|
+
if (!arg) { process.stderr.write('Usage: infernet plugins connect <slug>\n'); return 2; }
|
|
80
|
+
const r = await c.add((await c.list()).plugins.find((p) => p.slug === arg)?.url ?? arg);
|
|
81
|
+
if (!r.connect_url) { out(args, r, `${r.plugin.name} does not use sign-in.`); return 0; }
|
|
82
|
+
out(args, r, signInHint(args, r.connect_url));
|
|
83
|
+
return 0;
|
|
84
|
+
}
|
|
85
|
+
if (sub === 'rm' || sub === 'remove' || sub === 'delete') {
|
|
86
|
+
if (!arg) { process.stderr.write('Usage: infernet plugins rm <slug>\n'); return 2; }
|
|
87
|
+
out(args, await c.remove(arg), `Removed ${arg}.`);
|
|
88
|
+
return 0;
|
|
89
|
+
}
|
|
90
|
+
if (sub === 'on' || sub === 'off' || sub === 'enable' || sub === 'disable') {
|
|
91
|
+
if (!arg) { process.stderr.write(`Usage: infernet plugins ${sub} <slug>\n`); return 2; }
|
|
92
|
+
const on = sub === 'on' || sub === 'enable';
|
|
93
|
+
const p = await c.toggle(arg, on);
|
|
94
|
+
out(args, p, `${p.slug} is ${p.enabled ? 'on' : 'off'}.`);
|
|
95
|
+
return 0;
|
|
96
|
+
}
|
|
97
|
+
process.stderr.write(`Unknown subcommand: ${sub}\n\n${PLUGINS_HELP}`);
|
|
98
|
+
return 2;
|
|
99
|
+
} catch (err) {
|
|
100
|
+
process.stderr.write(`${err.message}\n`);
|
|
101
|
+
return 1;
|
|
102
|
+
}
|
|
103
|
+
}
|
package/index.js
CHANGED
|
@@ -56,6 +56,7 @@ import mcp from './commands/mcp.js';
|
|
|
56
56
|
import credits, { invites, redeem } from './commands/credits.js';
|
|
57
57
|
import batch, { billing, keys } from './commands/batch.js';
|
|
58
58
|
import price from './commands/price.js';
|
|
59
|
+
import plugins from './commands/plugins.js';
|
|
59
60
|
|
|
60
61
|
function parseArgs(argv) {
|
|
61
62
|
const positional = [];
|
|
@@ -119,11 +120,12 @@ const COMMANDS = {
|
|
|
119
120
|
start, status, stop, restart, stats, logs,
|
|
120
121
|
payout, payments, gpu, firewall, chat, setup, model, train, publish, inference, rpc, uncensored, reservation, reservations: reservation, order, orders: order, mcp, credits, invites, redeem, batch, batches: batch, billing, keys, tui, doctor, service, pubkey, debug, deploy, console: consoleCmd, help,
|
|
121
122
|
price, prices: price,
|
|
123
|
+
plugins, plugin: plugins,
|
|
122
124
|
'house-models': houseModels, house: houseModels
|
|
123
125
|
};
|
|
124
126
|
|
|
125
127
|
// Commands that can run without a loaded config.
|
|
126
|
-
const NO_CONFIG = new Set(['init', 'login', 'help', 'stats', 'logs', 'stop', 'restart', 'gpu', 'firewall', 'chat', 'setup', 'model', 'train', 'publish', 'inference', 'rpc', 'uncensored', 'reservation', 'reservations', 'order', 'orders', 'mcp', 'credits', 'invites', 'redeem', 'batch', 'batches', 'billing', 'keys', 'tui', 'doctor', 'service', 'pubkey', 'debug', 'deploy', 'console', 'upgrade', 'update', 'remove', 'uninstall', 'house-models', 'house', 'price', 'prices']);
|
|
128
|
+
const NO_CONFIG = new Set(['init', 'login', 'help', 'stats', 'logs', 'stop', 'restart', 'gpu', 'firewall', 'chat', 'setup', 'model', 'train', 'publish', 'inference', 'rpc', 'uncensored', 'reservation', 'reservations', 'order', 'orders', 'mcp', 'credits', 'invites', 'redeem', 'batch', 'batches', 'billing', 'keys', 'tui', 'doctor', 'service', 'pubkey', 'debug', 'deploy', 'console', 'upgrade', 'update', 'remove', 'uninstall', 'house-models', 'house', 'price', 'prices', 'plugins', 'plugin']);
|
|
127
129
|
// Commands that need a config but not a control-plane client (none today
|
|
128
130
|
// — kept as a future escape hatch).
|
|
129
131
|
const NO_CLIENT = new Set();
|
package/lib/chat-executor.js
CHANGED
|
@@ -133,6 +133,18 @@ function buildEngine(cacheKey, opts) {
|
|
|
133
133
|
return engineCache.get(cacheKey);
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
+
/**
|
|
137
|
+
* The stub backend answers with canned text. That is fine when an operator
|
|
138
|
+
* asked for it (`--backend stub`, INFERNET_ENGINE_BACKEND=stub) and wrong
|
|
139
|
+
* everywhere else: auto-select falls back to it whenever no engine answers
|
|
140
|
+
* its probe, e.g. Ollama busy for a moment, and the daemon then served
|
|
141
|
+
* "This is a stub response ..." to real chat users for the rest of its life
|
|
142
|
+
* (seen on c0mpute.com chat 2026-11-11). Exported for tests.
|
|
143
|
+
*/
|
|
144
|
+
export function stubExplicitlyChosen(config = {}, env = process.env) {
|
|
145
|
+
return env.INFERNET_ENGINE_BACKEND === 'stub' || config?.engine?.backend === 'stub';
|
|
146
|
+
}
|
|
147
|
+
|
|
136
148
|
async function defaultEngine() {
|
|
137
149
|
const config = (await loadConfig()) ?? {};
|
|
138
150
|
const eng = config.engine ?? {};
|
|
@@ -145,7 +157,15 @@ async function defaultEngine() {
|
|
|
145
157
|
if (Number.isFinite(eng.ollama_num_thread) && eng.ollama_num_thread > 0) {
|
|
146
158
|
opts.numThread = eng.ollama_num_thread;
|
|
147
159
|
}
|
|
148
|
-
|
|
160
|
+
const cacheKey = `default:${eng.backend ?? 'auto'}`;
|
|
161
|
+
const engine = await buildEngine(cacheKey, opts);
|
|
162
|
+
if (engine.kind === 'stub' && !stubExplicitlyChosen(config)) {
|
|
163
|
+
// Do not keep it: the next job probes the real engines again.
|
|
164
|
+
engineCache.delete(cacheKey);
|
|
165
|
+
try { engine.shutdown?.(); } catch { /* best-effort */ }
|
|
166
|
+
throw new Error('no inference engine reachable on this node (Ollama/vLLM/llama.cpp did not answer); refusing to serve stub output');
|
|
167
|
+
}
|
|
168
|
+
return engine;
|
|
149
169
|
}
|
|
150
170
|
|
|
151
171
|
/** Best-effort: does Ollama (at host) currently serve this exact tag? */
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP client for chat plugins (remote MCP servers on your account), shared by
|
|
3
|
+
* `infernet plugins`, `infernet chat` and `infernet mcp`.
|
|
4
|
+
*
|
|
5
|
+
* Base URL: --url, INFERNET_URL, config.controlPlane.url, else infernetprotocol.com
|
|
6
|
+
* Auth: the `infernet login` bearer (config.auth.bearerToken) or --token
|
|
7
|
+
*/
|
|
8
|
+
import { spawn } from 'node:child_process';
|
|
9
|
+
import { loadConfig } from './config.js';
|
|
10
|
+
|
|
11
|
+
const DEFAULT_URL = 'https://infernetprotocol.com';
|
|
12
|
+
|
|
13
|
+
export async function resolvePluginsOptions(opts = {}) {
|
|
14
|
+
const config = await loadConfig().catch(() => null);
|
|
15
|
+
return {
|
|
16
|
+
baseUrl: String(opts.url || process.env.INFERNET_URL || config?.controlPlane?.url || DEFAULT_URL).replace(/\/+$/, ''),
|
|
17
|
+
token: opts.token || config?.auth?.bearerToken || null
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function createPluginsClient({ baseUrl, token, fetchImpl = fetch }) {
|
|
22
|
+
async function call(method, path, body) {
|
|
23
|
+
if (!token) throw new Error('not signed in: run `infernet login` first');
|
|
24
|
+
const headers = { accept: 'application/json', authorization: `Bearer ${token}` };
|
|
25
|
+
if (body !== undefined) headers['content-type'] = 'application/json';
|
|
26
|
+
const res = await fetchImpl(`${baseUrl}${path}`, { method, headers, body: body === undefined ? undefined : JSON.stringify(body) });
|
|
27
|
+
const text = await res.text();
|
|
28
|
+
let json = null;
|
|
29
|
+
try { json = text ? JSON.parse(text) : null; } catch { /* non-JSON */ }
|
|
30
|
+
if (!res.ok) {
|
|
31
|
+
const err = new Error(json?.error ?? `${method} ${path} -> HTTP ${res.status} ${text.slice(0, 200)}`);
|
|
32
|
+
err.status = res.status;
|
|
33
|
+
throw err;
|
|
34
|
+
}
|
|
35
|
+
return json?.data ?? json;
|
|
36
|
+
}
|
|
37
|
+
const enc = encodeURIComponent;
|
|
38
|
+
return {
|
|
39
|
+
list: () => call('GET', '/api/v1/plugins'),
|
|
40
|
+
add: (url) => call('POST', '/api/v1/plugins', { url }),
|
|
41
|
+
remove: (slug) => call('DELETE', `/api/v1/plugins/${enc(slug)}`),
|
|
42
|
+
toggle: (slug, enabled) => call('POST', `/api/v1/plugins/${enc(slug)}/toggle`, typeof enabled === 'boolean' ? { enabled } : {}),
|
|
43
|
+
connectUrl: (slug) => `${baseUrl}/api/v1/plugins/${enc(slug)}/connect`
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Open a URL in the default browser; false when there is no way to (headless box). */
|
|
48
|
+
export function openBrowser(url) {
|
|
49
|
+
if (process.env.INFERNET_NO_BROWSER === '1') return false;
|
|
50
|
+
const cmd = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'cmd' : 'xdg-open';
|
|
51
|
+
const args = process.platform === 'win32' ? ['/c', 'start', '', url] : [url];
|
|
52
|
+
if (process.platform === 'linux' && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY) return false;
|
|
53
|
+
try {
|
|
54
|
+
const child = spawn(cmd, args, { stdio: 'ignore', detached: true });
|
|
55
|
+
child.on('error', () => {});
|
|
56
|
+
child.unref();
|
|
57
|
+
return true;
|
|
58
|
+
} catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Parse an SSE body into JSON events. */
|
|
64
|
+
export async function* readSse(res) {
|
|
65
|
+
const decoder = new TextDecoder();
|
|
66
|
+
let buf = '';
|
|
67
|
+
for await (const chunk of res.body) {
|
|
68
|
+
buf += decoder.decode(chunk, { stream: true });
|
|
69
|
+
let idx;
|
|
70
|
+
while ((idx = buf.indexOf('\n\n')) !== -1) {
|
|
71
|
+
const frame = buf.slice(0, idx);
|
|
72
|
+
buf = buf.slice(idx + 2);
|
|
73
|
+
const data = frame.split('\n').filter((l) => l.startsWith('data:')).map((l) => l.slice(5).trimStart()).join('\n');
|
|
74
|
+
if (!data) continue;
|
|
75
|
+
try { yield JSON.parse(data); } catch { /* skip */ }
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infernetprotocol/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.94",
|
|
4
4
|
"description": "GPU-node CLI / daemon for the Infernet Protocol — register a GPU server with a Supabase control plane and start earning.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -32,14 +32,14 @@
|
|
|
32
32
|
"ora": "^9.4.1",
|
|
33
33
|
"react": "^17.0.2",
|
|
34
34
|
"react-blessed": "^0.7.2",
|
|
35
|
-
"@infernetprotocol/auth": "0.1.
|
|
36
|
-
"@infernetprotocol/config": "0.1.
|
|
37
|
-
"@infernetprotocol/engine": "0.1.
|
|
38
|
-
"@infernetprotocol/deploy-providers": "0.1.
|
|
39
|
-
"@infernetprotocol/gpu": "0.1.
|
|
40
|
-
"@infernetprotocol/liquid-agent": "0.1.
|
|
41
|
-
"@infernetprotocol/
|
|
42
|
-
"@infernetprotocol/
|
|
35
|
+
"@infernetprotocol/auth": "0.1.94",
|
|
36
|
+
"@infernetprotocol/config": "0.1.94",
|
|
37
|
+
"@infernetprotocol/engine": "0.1.94",
|
|
38
|
+
"@infernetprotocol/deploy-providers": "0.1.94",
|
|
39
|
+
"@infernetprotocol/gpu": "0.1.94",
|
|
40
|
+
"@infernetprotocol/liquid-agent": "0.1.94",
|
|
41
|
+
"@infernetprotocol/rpc-adapter": "0.1.94",
|
|
42
|
+
"@infernetprotocol/training": "0.1.94"
|
|
43
43
|
},
|
|
44
44
|
"repository": {
|
|
45
45
|
"type": "git",
|