@infernetprotocol/cli 0.1.54 → 0.1.56
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/help.js +5 -0
- package/commands/mcp.js +136 -0
- package/commands/reservation.js +154 -0
- package/commands/start.js +18 -2
- package/index.js +4 -2
- package/lib/reservations-client.js +128 -0
- package/package.json +7 -7
package/commands/help.js
CHANGED
|
@@ -41,6 +41,11 @@ Payments:
|
|
|
41
41
|
payout Manage payout coin/address
|
|
42
42
|
payments Show recent payment transactions
|
|
43
43
|
|
|
44
|
+
Managed endpoints:
|
|
45
|
+
reservation Book a pinned operator + exact model by the hour; keys, limits,
|
|
46
|
+
per-minute availability report, post-paid invoice data
|
|
47
|
+
mcp MCP server (stdio) exposing the reservation tools
|
|
48
|
+
|
|
44
49
|
Other:
|
|
45
50
|
help Show this help
|
|
46
51
|
|
package/commands/mcp.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `infernet mcp` — Model Context Protocol server over stdio.
|
|
3
|
+
*
|
|
4
|
+
* Exposes managed-endpoint reservations (docs/prd/16-managed-endpoints.md) as
|
|
5
|
+
* MCP tools so an agent can book, key, monitor and reconcile reservations.
|
|
6
|
+
* Same auth as `infernet reservation` (INFERNET_ADMIN_TOKEN / login bearer, or
|
|
7
|
+
* INFERNET_BUYER_TOKEN for the read-only buyer tools).
|
|
8
|
+
*
|
|
9
|
+
* claude mcp add infernet -- infernet mcp
|
|
10
|
+
*
|
|
11
|
+
* Newline-delimited JSON-RPC 2.0, no dependencies.
|
|
12
|
+
*/
|
|
13
|
+
import { createInterface } from 'node:readline';
|
|
14
|
+
import { resolveClientOptions, createReservationsClient } from '../lib/reservations-client.js';
|
|
15
|
+
import { CURRENT_VERSION } from '../lib/version.js';
|
|
16
|
+
|
|
17
|
+
const PROTOCOL_VERSION = '2025-06-18';
|
|
18
|
+
|
|
19
|
+
const id = { type: 'string', description: 'reservation id (uuid)' };
|
|
20
|
+
|
|
21
|
+
export const TOOLS = [
|
|
22
|
+
{
|
|
23
|
+
name: 'reservation_list',
|
|
24
|
+
description: 'List managed-endpoint reservations (admin).',
|
|
25
|
+
inputSchema: { type: 'object', properties: {} },
|
|
26
|
+
run: (c) => c.list()
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: 'reservation_create',
|
|
30
|
+
description: 'Book a managed endpoint: exact model ids on one named operator target (provider_id of an Infernet node, or an OpenAI-compatible endpoint_url), starting at a whole UTC hour for N hours, with included tokens and per-key/shared rps + concurrency limits. Returns the reservation and a one-time buyer token. Does not set or agree a price unless price_per_hour is passed.',
|
|
31
|
+
inputSchema: {
|
|
32
|
+
type: 'object',
|
|
33
|
+
required: ['name', 'operator_name', 'models', 'start_at', 'hours'],
|
|
34
|
+
properties: {
|
|
35
|
+
name: { type: 'string' },
|
|
36
|
+
buyer: { type: 'string' },
|
|
37
|
+
operator_name: { type: 'string' },
|
|
38
|
+
models: { type: 'array', items: { type: 'string' } },
|
|
39
|
+
provider_id: { type: 'string' },
|
|
40
|
+
endpoint_url: { type: 'string' },
|
|
41
|
+
endpoint_api_key: { type: 'string' },
|
|
42
|
+
start_at: { type: 'string', description: 'ISO timestamp on a whole UTC hour' },
|
|
43
|
+
hours: { type: 'integer', minimum: 1, maximum: 720 },
|
|
44
|
+
included_tokens: { type: 'integer', minimum: 0 },
|
|
45
|
+
per_key_rps: { type: 'integer', minimum: 1 },
|
|
46
|
+
per_key_concurrency: { type: 'integer', minimum: 1 },
|
|
47
|
+
shared_rps: { type: 'integer', minimum: 1 },
|
|
48
|
+
shared_concurrency: { type: 'integer', minimum: 1 },
|
|
49
|
+
required_minutes_per_hour: { type: 'integer', minimum: 1, maximum: 60 },
|
|
50
|
+
probe_completion: { type: 'boolean' },
|
|
51
|
+
price_per_hour: { type: 'number', minimum: 0 },
|
|
52
|
+
currency: { type: 'string' },
|
|
53
|
+
notes: { type: 'string' }
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
run: (c, a) => c.create(a)
|
|
57
|
+
},
|
|
58
|
+
{ name: 'reservation_get', description: 'Show one reservation.', inputSchema: { type: 'object', required: ['id'], properties: { id } }, run: (c, a) => c.get(a.id) },
|
|
59
|
+
{ name: 'reservation_cancel', description: 'Cancel a reservation (keys stop working; hours become non-billable).', inputSchema: { type: 'object', required: ['id'], properties: { id } }, run: (c, a) => c.cancel(a.id) },
|
|
60
|
+
{ name: 'reservation_keys', description: 'List a reservation\'s API keys (prefixes only).', inputSchema: { type: 'object', required: ['id'], properties: { id } }, run: (c, a) => c.listKeys(a.id) },
|
|
61
|
+
{
|
|
62
|
+
name: 'reservation_key_issue',
|
|
63
|
+
description: 'Issue an API key on a reservation for a reseller\'s customer. The key is returned once.',
|
|
64
|
+
inputSchema: { type: 'object', required: ['id'], properties: { id, label: { type: 'string' } } },
|
|
65
|
+
run: (c, a) => c.issueKey(a.id, a.label)
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: 'reservation_key_revoke',
|
|
69
|
+
description: 'Revoke a reservation API key.',
|
|
70
|
+
inputSchema: { type: 'object', required: ['id', 'key_id'], properties: { id, key_id: { type: 'string' } } },
|
|
71
|
+
run: (c, a) => c.revokeKey(a.id, a.key_id)
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: 'reservation_report',
|
|
75
|
+
description: 'Per-hour availability/compliance report with usage (requests, tokens, limit hits). minutes=true includes every per-minute probe record.',
|
|
76
|
+
inputSchema: { type: 'object', required: ['id'], properties: { id, minutes: { type: 'boolean' } } },
|
|
77
|
+
run: (c, a) => c.report(a.id, { minutes: a.minutes === true })
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: 'reservation_invoice',
|
|
81
|
+
description: 'Post-paid invoice data: hour statuses and amount due for compliant hours only. Executes no payment.',
|
|
82
|
+
inputSchema: { type: 'object', required: ['id'], properties: { id } },
|
|
83
|
+
run: (c, a) => c.invoice(a.id)
|
|
84
|
+
}
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
/** Handle one JSON-RPC message; returns the response object or null for notifications. */
|
|
88
|
+
export async function handleMessage(msg, client) {
|
|
89
|
+
const reply = (result) => ({ jsonrpc: '2.0', id: msg.id, result });
|
|
90
|
+
const fail = (code, message) => ({ jsonrpc: '2.0', id: msg.id ?? null, error: { code, message } });
|
|
91
|
+
if (msg?.id === undefined || msg?.id === null) return null; // notification
|
|
92
|
+
switch (msg.method) {
|
|
93
|
+
case 'initialize':
|
|
94
|
+
return reply({
|
|
95
|
+
protocolVersion: msg.params?.protocolVersion ?? PROTOCOL_VERSION,
|
|
96
|
+
capabilities: { tools: {} },
|
|
97
|
+
serverInfo: { name: 'infernet', version: CURRENT_VERSION }
|
|
98
|
+
});
|
|
99
|
+
case 'ping':
|
|
100
|
+
return reply({});
|
|
101
|
+
case 'tools/list':
|
|
102
|
+
return reply({ tools: TOOLS.map(({ run, ...t }) => t) });
|
|
103
|
+
case 'tools/call': {
|
|
104
|
+
const tool = TOOLS.find((t) => t.name === msg.params?.name);
|
|
105
|
+
if (!tool) return fail(-32602, `unknown tool: ${msg.params?.name}`);
|
|
106
|
+
try {
|
|
107
|
+
const data = await tool.run(client, msg.params?.arguments ?? {});
|
|
108
|
+
return reply({ content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] });
|
|
109
|
+
} catch (e) {
|
|
110
|
+
return reply({ isError: true, content: [{ type: 'text', text: e?.message ?? String(e) }] });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
default:
|
|
114
|
+
return fail(-32601, `method not found: ${msg.method}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export default async function mcp(args) {
|
|
119
|
+
if (args.has('help') || args.has('h')) {
|
|
120
|
+
process.stdout.write('infernet mcp — MCP server (stdio) for managed-endpoint reservations\n\n claude mcp add infernet -- infernet mcp\n');
|
|
121
|
+
return 0;
|
|
122
|
+
}
|
|
123
|
+
const client = createReservationsClient(await resolveClientOptions({ url: args.get('url'), token: args.get('token'), buyerToken: args.get('buyer-token') }));
|
|
124
|
+
const rl = createInterface({ input: process.stdin });
|
|
125
|
+
for await (const line of rl) {
|
|
126
|
+
if (!line.trim()) continue;
|
|
127
|
+
let msg;
|
|
128
|
+
try { msg = JSON.parse(line); } catch {
|
|
129
|
+
process.stdout.write(`${JSON.stringify({ jsonrpc: '2.0', id: null, error: { code: -32700, message: 'parse error' } })}\n`);
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
const res = await handleMessage(msg, client);
|
|
133
|
+
if (res) process.stdout.write(`${JSON.stringify(res)}\n`);
|
|
134
|
+
}
|
|
135
|
+
return 0;
|
|
136
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `infernet reservation` — managed endpoints / reservations
|
|
3
|
+
* (docs/prd/16-managed-endpoints.md). Talks to /api/v1/reservations/*.
|
|
4
|
+
*/
|
|
5
|
+
import {
|
|
6
|
+
resolveClientOptions, createReservationsClient, createBodyFromFlags, renderReport, renderInvoice
|
|
7
|
+
} from '../lib/reservations-client.js';
|
|
8
|
+
|
|
9
|
+
const HELP = `infernet reservation — managed model endpoints for resellers
|
|
10
|
+
|
|
11
|
+
A reservation pins exact model id(s) on one named operator target for whole
|
|
12
|
+
UTC hours, with included tokens and per-key / shared rate + concurrency
|
|
13
|
+
limits. Keys issued on it work against /v1/chat/completions and /v1/models.
|
|
14
|
+
Every minute of the window is probed; the report and invoice view are built
|
|
15
|
+
from those probes. Nothing is charged.
|
|
16
|
+
|
|
17
|
+
Usage:
|
|
18
|
+
infernet reservation list
|
|
19
|
+
infernet reservation create --name N --operator O --models m1[,m2]
|
|
20
|
+
(--provider-id <node uuid> | --endpoint-url https://op.example/v1 [--endpoint-key K])
|
|
21
|
+
--start 2026-10-12T15:00:00Z --hours 1 --included-tokens 2000000
|
|
22
|
+
--per-key-rps 2 --per-key-concurrency 2 --shared-rps 10 --shared-concurrency 8
|
|
23
|
+
[--buyer KAI] [--required-minutes 60] [--probe-completion]
|
|
24
|
+
[--price-per-hour 0] [--currency USD] [--notes "..."]
|
|
25
|
+
infernet reservation show <id>
|
|
26
|
+
infernet reservation price <id> --price-per-hour X [--currency USD]
|
|
27
|
+
infernet reservation cancel <id>
|
|
28
|
+
infernet reservation keys <id>
|
|
29
|
+
infernet reservation key-issue <id> [--label customer-a]
|
|
30
|
+
infernet reservation key-revoke <id> <keyId>
|
|
31
|
+
infernet reservation report <id> [--minutes] [--json]
|
|
32
|
+
infernet reservation invoice <id> [--json]
|
|
33
|
+
infernet reservation buyer-token <id> rotate the buyer's read-only token
|
|
34
|
+
infernet reservation watch <id> [--every 15] live per-hour availability view
|
|
35
|
+
|
|
36
|
+
Auth:
|
|
37
|
+
admin --token or INFERNET_ADMIN_TOKEN, else your \`infernet login\` bearer
|
|
38
|
+
(its email must be in the server's INFERNET_ADMIN_EMAILS)
|
|
39
|
+
buyer --buyer-token or INFERNET_BUYER_TOKEN (one reservation: show, report,
|
|
40
|
+
invoice, keys, key-issue, key-revoke)
|
|
41
|
+
url --url or INFERNET_URL (default: config control plane, else infernetprotocol.com)
|
|
42
|
+
`;
|
|
43
|
+
|
|
44
|
+
function out(obj) {
|
|
45
|
+
process.stdout.write(`${JSON.stringify(obj, null, 2)}\n`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function needId(id) {
|
|
49
|
+
if (!id) throw new Error('reservation id required (see `infernet reservation --help`)');
|
|
50
|
+
return id;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function summary(r) {
|
|
54
|
+
const target = r.target_kind === 'node' ? `node ${r.provider_id}` : r.endpoint_url;
|
|
55
|
+
return `${r.id} ${r.phase.padEnd(9)} ${r.start_at} +${r.hours}h ${r.models.join(',')} ${r.operator_name} (${target})${r.buyer ? ` buyer=${r.buyer}` : ''}`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function watch(client, id, everySec) {
|
|
59
|
+
const tty = process.stdout.isTTY;
|
|
60
|
+
let stop = false;
|
|
61
|
+
process.on('SIGINT', () => { stop = true; });
|
|
62
|
+
while (!stop) {
|
|
63
|
+
let text;
|
|
64
|
+
try {
|
|
65
|
+
text = renderReport(await client.report(id), { color: tty });
|
|
66
|
+
} catch (e) {
|
|
67
|
+
text = `report failed: ${e.message}`;
|
|
68
|
+
}
|
|
69
|
+
if (tty) process.stdout.write('\x1b[2J\x1b[H');
|
|
70
|
+
process.stdout.write(`${text}\n\n${tty ? `refreshing every ${everySec}s — Ctrl-C to quit` : ''}\n`);
|
|
71
|
+
if (!tty) return 0;
|
|
72
|
+
await new Promise((r) => setTimeout(r, everySec * 1000));
|
|
73
|
+
}
|
|
74
|
+
return 0;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export default async function reservation(args) {
|
|
78
|
+
const [sub, a1, a2] = args.positional;
|
|
79
|
+
if (!sub || args.has('help') || args.has('h') || sub === 'help') {
|
|
80
|
+
process.stdout.write(HELP);
|
|
81
|
+
return sub ? 0 : (args.has('help') ? 0 : 1);
|
|
82
|
+
}
|
|
83
|
+
const opts = await resolveClientOptions({ url: args.get('url'), token: args.get('token'), buyerToken: args.get('buyer-token') });
|
|
84
|
+
const client = createReservationsClient(opts);
|
|
85
|
+
const json = args.has('json');
|
|
86
|
+
|
|
87
|
+
switch (sub) {
|
|
88
|
+
case 'list': {
|
|
89
|
+
const rows = await client.list();
|
|
90
|
+
if (json) return out(rows), 0;
|
|
91
|
+
if (rows.length === 0) process.stdout.write('no reservations\n');
|
|
92
|
+
for (const r of rows) process.stdout.write(`${summary(r)}\n`);
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
case 'create': {
|
|
96
|
+
const created = await client.create(createBodyFromFlags((k) => args.get(k) ?? (args.has(k) ? true : undefined)));
|
|
97
|
+
if (json) return out(created), 0;
|
|
98
|
+
process.stdout.write(`created ${summary(created.reservation)}\n`);
|
|
99
|
+
process.stdout.write(`buyer token (shown once — give it to the buyer):\n ${created.buyer_token}\n`);
|
|
100
|
+
process.stdout.write(`next: infernet reservation key-issue ${created.reservation.id} --label <customer>\n`);
|
|
101
|
+
return 0;
|
|
102
|
+
}
|
|
103
|
+
case 'show': {
|
|
104
|
+
const r = await client.get(needId(a1));
|
|
105
|
+
return out(r), 0;
|
|
106
|
+
}
|
|
107
|
+
case 'price': {
|
|
108
|
+
const patch = { price_per_hour: args.get('price-per-hour') === 'null' ? null : Number(args.get('price-per-hour')) };
|
|
109
|
+
if (args.get('currency')) patch.currency = args.get('currency');
|
|
110
|
+
if (args.get('price-per-hour') === undefined) throw new Error('--price-per-hour is required');
|
|
111
|
+
return out(await client.update(needId(a1), patch)), 0;
|
|
112
|
+
}
|
|
113
|
+
case 'cancel':
|
|
114
|
+
return out(await client.cancel(needId(a1))), 0;
|
|
115
|
+
case 'keys': {
|
|
116
|
+
const keys = await client.listKeys(needId(a1));
|
|
117
|
+
if (json) return out(keys), 0;
|
|
118
|
+
for (const k of keys) process.stdout.write(`${k.id} ${k.key_prefix}… ${k.label ?? ''} ${k.revoked_at ? `revoked ${k.revoked_at}` : 'active'}\n`);
|
|
119
|
+
if (keys.length === 0) process.stdout.write('no keys\n');
|
|
120
|
+
return 0;
|
|
121
|
+
}
|
|
122
|
+
case 'key-issue': {
|
|
123
|
+
const k = await client.issueKey(needId(a1), args.get('label'));
|
|
124
|
+
if (json) return out(k), 0;
|
|
125
|
+
process.stdout.write(`key ${k.id}${k.label ? ` (${k.label})` : ''} — shown once:\n ${k.key}\n`);
|
|
126
|
+
return 0;
|
|
127
|
+
}
|
|
128
|
+
case 'key-revoke':
|
|
129
|
+
if (!a2) throw new Error('usage: infernet reservation key-revoke <id> <keyId>');
|
|
130
|
+
return out(await client.revokeKey(needId(a1), a2)), 0;
|
|
131
|
+
case 'report': {
|
|
132
|
+
const rep = await client.report(needId(a1), { minutes: args.has('minutes') });
|
|
133
|
+
if (json || args.has('minutes')) return out(rep), 0;
|
|
134
|
+
process.stdout.write(`${renderReport(rep, { color: process.stdout.isTTY })}\n`);
|
|
135
|
+
return 0;
|
|
136
|
+
}
|
|
137
|
+
case 'invoice': {
|
|
138
|
+
const inv = await client.invoice(needId(a1));
|
|
139
|
+
if (json) return out(inv), 0;
|
|
140
|
+
process.stdout.write(`${renderInvoice(inv)}\n`);
|
|
141
|
+
return 0;
|
|
142
|
+
}
|
|
143
|
+
case 'buyer-token': {
|
|
144
|
+
const r = await client.rotateBuyerToken(needId(a1));
|
|
145
|
+
process.stdout.write(`new buyer token (the old one no longer works):\n ${r.buyer_token}\n`);
|
|
146
|
+
return 0;
|
|
147
|
+
}
|
|
148
|
+
case 'watch':
|
|
149
|
+
return watch(client, needId(a1), Math.max(5, Number(args.get('every') ?? 15) || 15));
|
|
150
|
+
default:
|
|
151
|
+
process.stderr.write(`unknown subcommand: ${sub}\n\n${HELP}`);
|
|
152
|
+
return 1;
|
|
153
|
+
}
|
|
154
|
+
}
|
package/commands/start.js
CHANGED
|
@@ -82,6 +82,7 @@ live queries (see \`infernet status\`, \`infernet stats\`, \`infernet logs\`).
|
|
|
82
82
|
const DEFAULT_HEARTBEAT_MS = 30_000;
|
|
83
83
|
const DEFAULT_POLL_MS = 15_000;
|
|
84
84
|
const UPDATE_CHECK_MS = 5 * 60 * 1000; // 5 minutes
|
|
85
|
+
const UPDATE_DRAIN_MS = 10 * 60 * 1000; // wait for in-flight jobs before restarting
|
|
85
86
|
|
|
86
87
|
async function writePidFile(pid) {
|
|
87
88
|
const p = getDaemonPidPath();
|
|
@@ -189,7 +190,10 @@ async function runDaemon(args, ctx) {
|
|
|
189
190
|
lastPollAt: null,
|
|
190
191
|
pollsOk: 0,
|
|
191
192
|
pollsFailed: 0,
|
|
192
|
-
activeJobIds: new Set()
|
|
193
|
+
activeJobIds: new Set(),
|
|
194
|
+
// Set while a self-update waits for in-flight jobs to finish: the
|
|
195
|
+
// poll loop takes no new jobs, so the restart can happen.
|
|
196
|
+
draining: false
|
|
193
197
|
};
|
|
194
198
|
|
|
195
199
|
const pidPath = await writePidFile(process.pid);
|
|
@@ -513,6 +517,7 @@ async function runDaemon(args, ctx) {
|
|
|
513
517
|
stats.pollsOk += 1;
|
|
514
518
|
return;
|
|
515
519
|
}
|
|
520
|
+
if (stats.draining) return;
|
|
516
521
|
try {
|
|
517
522
|
const result = await client.pollJobs({ limit: 5 });
|
|
518
523
|
stats.pollsOk += 1;
|
|
@@ -1544,6 +1549,8 @@ async function runDaemon(args, ctx) {
|
|
|
1544
1549
|
let isUpgrading = false;
|
|
1545
1550
|
const updateTimer = setInterval(async () => {
|
|
1546
1551
|
if (shuttingDown || isUpgrading) return;
|
|
1552
|
+
// Never start an upgrade under a running job; the next check retries.
|
|
1553
|
+
if (stats.activeJobIds.size > 0) return;
|
|
1547
1554
|
const latest = await fetchLatestVersion();
|
|
1548
1555
|
if (!latest || !isNewerVersion(CURRENT_VERSION, latest)) return;
|
|
1549
1556
|
isUpgrading = true;
|
|
@@ -1568,7 +1575,16 @@ async function runDaemon(args, ctx) {
|
|
|
1568
1575
|
process.stderr.write(`[update] post-upgrade setup: ${err?.message ?? err}\n`);
|
|
1569
1576
|
}
|
|
1570
1577
|
|
|
1571
|
-
//
|
|
1578
|
+
// Jobs that arrived while the installer ran get to finish: stop taking
|
|
1579
|
+
// new ones and wait. Restarting under them used to fail every one
|
|
1580
|
+
// ("daemon restarting for self-update", 23 jobs on 2026-09-30).
|
|
1581
|
+
stats.draining = true;
|
|
1582
|
+
const drainUntil = Date.now() + UPDATE_DRAIN_MS;
|
|
1583
|
+
while (stats.activeJobIds.size > 0 && Date.now() < drainUntil) {
|
|
1584
|
+
await new Promise((r) => setTimeout(r, 1000));
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
// Release whatever is still running after the drain window.
|
|
1572
1588
|
for (const jobId of stats.activeJobIds) {
|
|
1573
1589
|
try {
|
|
1574
1590
|
await client.failJob(jobId, 'daemon restarting for self-update');
|
package/index.js
CHANGED
|
@@ -48,6 +48,8 @@ import publish from './commands/publish.js';
|
|
|
48
48
|
import inference from './commands/inference.js';
|
|
49
49
|
import rpc from './commands/rpc.js';
|
|
50
50
|
import uncensored from './commands/uncensored.js';
|
|
51
|
+
import reservation from './commands/reservation.js';
|
|
52
|
+
import mcp from './commands/mcp.js';
|
|
51
53
|
|
|
52
54
|
function parseArgs(argv) {
|
|
53
55
|
const positional = [];
|
|
@@ -109,11 +111,11 @@ const COMMANDS = {
|
|
|
109
111
|
// aliases
|
|
110
112
|
uninstall: remove,
|
|
111
113
|
start, status, stop, restart, stats, logs,
|
|
112
|
-
payout, payments, gpu, firewall, chat, setup, model, train, publish, inference, rpc, uncensored, tui, doctor, service, pubkey, debug, deploy, console: consoleCmd, help
|
|
114
|
+
payout, payments, gpu, firewall, chat, setup, model, train, publish, inference, rpc, uncensored, reservation, reservations: reservation, mcp, tui, doctor, service, pubkey, debug, deploy, console: consoleCmd, help
|
|
113
115
|
};
|
|
114
116
|
|
|
115
117
|
// Commands that can run without a loaded config.
|
|
116
|
-
const NO_CONFIG = new Set(['init', 'login', 'help', 'stats', 'logs', 'stop', 'restart', 'gpu', 'firewall', 'chat', 'setup', 'model', 'train', 'publish', 'inference', 'rpc', 'uncensored', 'tui', 'doctor', 'service', 'pubkey', 'debug', 'deploy', 'console', 'upgrade', 'update', 'remove', 'uninstall']);
|
|
118
|
+
const NO_CONFIG = new Set(['init', 'login', 'help', 'stats', 'logs', 'stop', 'restart', 'gpu', 'firewall', 'chat', 'setup', 'model', 'train', 'publish', 'inference', 'rpc', 'uncensored', 'reservation', 'reservations', 'mcp', 'tui', 'doctor', 'service', 'pubkey', 'debug', 'deploy', 'console', 'upgrade', 'update', 'remove', 'uninstall']);
|
|
117
119
|
// Commands that need a config but not a control-plane client (none today
|
|
118
120
|
// — kept as a future escape hatch).
|
|
119
121
|
const NO_CLIENT = new Set();
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP client for /api/v1/reservations/* — shared by `infernet reservation`,
|
|
3
|
+
* `infernet reservation watch` and the `infernet mcp` server.
|
|
4
|
+
*
|
|
5
|
+
* Base URL: --url, INFERNET_URL, config.controlPlane.url, else infernetprotocol.com
|
|
6
|
+
* Admin auth: --token, INFERNET_ADMIN_TOKEN, else the `infernet login` bearer
|
|
7
|
+
* Buyer auth: --buyer-token or INFERNET_BUYER_TOKEN (one reservation: show,
|
|
8
|
+
* report, invoice, keys)
|
|
9
|
+
*/
|
|
10
|
+
import { loadConfig } from './config.js';
|
|
11
|
+
|
|
12
|
+
const DEFAULT_URL = 'https://infernetprotocol.com';
|
|
13
|
+
|
|
14
|
+
export async function resolveClientOptions(opts = {}) {
|
|
15
|
+
const config = await loadConfig().catch(() => null);
|
|
16
|
+
return {
|
|
17
|
+
baseUrl: String(opts.url || process.env.INFERNET_URL || config?.controlPlane?.url || DEFAULT_URL).replace(/\/+$/, ''),
|
|
18
|
+
adminToken: opts.token || process.env.INFERNET_ADMIN_TOKEN || config?.auth?.bearerToken || null,
|
|
19
|
+
buyerToken: opts.buyerToken || process.env.INFERNET_BUYER_TOKEN || null
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function createReservationsClient({ baseUrl, adminToken, buyerToken, fetchImpl = fetch }) {
|
|
24
|
+
async function call(method, path, { body, asBuyer = false } = {}) {
|
|
25
|
+
const headers = { accept: 'application/json' };
|
|
26
|
+
if (body !== undefined) headers['content-type'] = 'application/json';
|
|
27
|
+
if (asBuyer && buyerToken) headers['x-buyer-token'] = buyerToken;
|
|
28
|
+
else if (adminToken) headers.authorization = `Bearer ${adminToken}`;
|
|
29
|
+
const res = await fetchImpl(`${baseUrl}${path}`, {
|
|
30
|
+
method,
|
|
31
|
+
headers,
|
|
32
|
+
body: body === undefined ? undefined : JSON.stringify(body)
|
|
33
|
+
});
|
|
34
|
+
const text = await res.text();
|
|
35
|
+
let json = null;
|
|
36
|
+
try { json = text ? JSON.parse(text) : null; } catch { /* non-JSON */ }
|
|
37
|
+
if (!res.ok) {
|
|
38
|
+
const detail = json?.details ? `: ${json.details.join('; ')}` : '';
|
|
39
|
+
const err = new Error(`${method} ${path} -> HTTP ${res.status} ${json?.error ?? text.slice(0, 200)}${detail}`);
|
|
40
|
+
err.status = res.status;
|
|
41
|
+
throw err;
|
|
42
|
+
}
|
|
43
|
+
return json?.data ?? json;
|
|
44
|
+
}
|
|
45
|
+
// Per-reservation paths use the buyer token when one is configured and no admin token is.
|
|
46
|
+
const reader = () => Boolean(buyerToken) && !adminToken;
|
|
47
|
+
const enc = encodeURIComponent;
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
list: () => call('GET', '/api/v1/reservations'),
|
|
51
|
+
create: (input) => call('POST', '/api/v1/reservations', { body: input }),
|
|
52
|
+
get: (id) => call('GET', `/api/v1/reservations/${enc(id)}`, { asBuyer: reader() }),
|
|
53
|
+
update: (id, patch) => call('PATCH', `/api/v1/reservations/${enc(id)}`, { body: patch }),
|
|
54
|
+
cancel: (id) => call('PATCH', `/api/v1/reservations/${enc(id)}`, { body: { status: 'cancelled' } }),
|
|
55
|
+
listKeys: (id) => call('GET', `/api/v1/reservations/${enc(id)}/keys`, { asBuyer: reader() }),
|
|
56
|
+
issueKey: (id, label) => call('POST', `/api/v1/reservations/${enc(id)}/keys`, { body: { label }, asBuyer: reader() }),
|
|
57
|
+
revokeKey: (id, keyId) => call('DELETE', `/api/v1/reservations/${enc(id)}/keys/${enc(keyId)}`, { asBuyer: reader() }),
|
|
58
|
+
report: (id, { minutes = false } = {}) => call('GET', `/api/v1/reservations/${enc(id)}/report${minutes ? '?minutes=1' : ''}`, { asBuyer: reader() }),
|
|
59
|
+
invoice: (id) => call('GET', `/api/v1/reservations/${enc(id)}/invoice`, { asBuyer: reader() }),
|
|
60
|
+
rotateBuyerToken: (id) => call('POST', `/api/v1/reservations/${enc(id)}/buyer-token`)
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** CLI flags -> create body. Kept here so the MCP tool and CLI agree. */
|
|
65
|
+
export function createBodyFromFlags(get) {
|
|
66
|
+
const num = (k) => (get(k) === undefined ? undefined : Number(get(k)));
|
|
67
|
+
const body = {
|
|
68
|
+
name: get('name'),
|
|
69
|
+
buyer: get('buyer'),
|
|
70
|
+
operator_name: get('operator'),
|
|
71
|
+
models: get('models') ? String(get('models')).split(',').map((s) => s.trim()).filter(Boolean) : undefined,
|
|
72
|
+
provider_id: get('provider-id'),
|
|
73
|
+
endpoint_url: get('endpoint-url'),
|
|
74
|
+
endpoint_api_key: get('endpoint-key'),
|
|
75
|
+
start_at: get('start'),
|
|
76
|
+
hours: num('hours'),
|
|
77
|
+
included_tokens: num('included-tokens'),
|
|
78
|
+
per_key_rps: num('per-key-rps'),
|
|
79
|
+
per_key_concurrency: num('per-key-concurrency'),
|
|
80
|
+
shared_rps: num('shared-rps'),
|
|
81
|
+
shared_concurrency: num('shared-concurrency'),
|
|
82
|
+
required_minutes_per_hour: num('required-minutes'),
|
|
83
|
+
probe_completion: get('probe-completion') === true || get('probe-completion') === 'true' ? true : undefined,
|
|
84
|
+
price_per_hour: get('price-per-hour'),
|
|
85
|
+
currency: get('currency'),
|
|
86
|
+
notes: get('notes')
|
|
87
|
+
};
|
|
88
|
+
for (const k of Object.keys(body)) if (body[k] === undefined) delete body[k];
|
|
89
|
+
return body;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** One line per hour: a 60-char minute strip (# confirmed, x failed, . unconfirmed). */
|
|
93
|
+
export function renderReport(report, { color = false } = {}) {
|
|
94
|
+
const paint = (c, s) => (color ? `\x1b[${c}m${s}\x1b[0m` : s);
|
|
95
|
+
const statusColor = { compliant: 32, non_compliant: 31, in_progress: 33, upcoming: 90, cancelled: 90 };
|
|
96
|
+
const lines = [];
|
|
97
|
+
lines.push(`reservation ${report.reservation_id} phase=${report.phase} tokens ${report.tokens_used}/${report.included_tokens || '∞'}`);
|
|
98
|
+
lines.push(`rule: ${report.rule}`);
|
|
99
|
+
lines.push('');
|
|
100
|
+
for (const h of report.hours) {
|
|
101
|
+
const m = h.minutes;
|
|
102
|
+
const u = h.usage;
|
|
103
|
+
const lh = u.limit_hits;
|
|
104
|
+
lines.push(
|
|
105
|
+
`h${String(h.hour).padStart(3)} ${h.start.replace(':00.000Z', 'Z')} `
|
|
106
|
+
+ paint(statusColor[h.status] ?? 0, h.status.padEnd(13))
|
|
107
|
+
+ ` ${String(m.confirmed).padStart(2)}/${m.required} confirmed ${m.failed} failed ${m.unconfirmed} unconfirmed`
|
|
108
|
+
+ ` req=${u.requests} tok=${u.prompt_tokens + u.completion_tokens} 429s=${lh.rps + lh.concurrency + lh.tokens}`
|
|
109
|
+
);
|
|
110
|
+
for (const f of h.failures.slice(0, 5)) lines.push(` ${f.minute} ${f.reason}`);
|
|
111
|
+
if (h.failures.length > 5) lines.push(` … ${h.failures.length - 5} more`);
|
|
112
|
+
}
|
|
113
|
+
return lines.join('\n');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function renderInvoice(inv) {
|
|
117
|
+
const money = (n) => (n === null ? '(unpriced)' : `${Number(n).toFixed(2)} ${inv.currency}`);
|
|
118
|
+
const lines = [
|
|
119
|
+
`invoice data for reservation ${inv.reservation_id}${inv.buyer ? ` (buyer ${inv.buyer})` : ''}`,
|
|
120
|
+
`operator ${inv.operator_name} models ${inv.models.join(', ')}`,
|
|
121
|
+
`price per hour ${money(inv.price_per_hour)} final=${inv.final}`,
|
|
122
|
+
`hours: ${inv.hours_reserved} reserved, ${inv.hours_compliant} compliant, ${inv.hours_non_compliant} non-compliant, ${inv.hours_open} open`,
|
|
123
|
+
''
|
|
124
|
+
];
|
|
125
|
+
for (const l of inv.lines) lines.push(` h${String(l.hour).padStart(3)} ${l.start} ${l.status.padEnd(13)} ${String(l.confirmed_minutes).padStart(2)} min ${money(l.amount)}`);
|
|
126
|
+
lines.push('', `amount due: ${money(inv.amount_due)}`, inv.note);
|
|
127
|
+
return lines.join('\n');
|
|
128
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infernetprotocol/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.56",
|
|
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",
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
"ora": "^9.4.0",
|
|
31
31
|
"react": "^17.0.2",
|
|
32
32
|
"react-blessed": "^0.7.2",
|
|
33
|
-
"@infernetprotocol/auth": "0.1.
|
|
34
|
-
"@infernetprotocol/
|
|
35
|
-
"@infernetprotocol/
|
|
36
|
-
"@infernetprotocol/
|
|
37
|
-
"@infernetprotocol/gpu": "0.1.
|
|
38
|
-
"@infernetprotocol/rpc-adapter": "0.1.
|
|
33
|
+
"@infernetprotocol/auth": "0.1.56",
|
|
34
|
+
"@infernetprotocol/config": "0.1.56",
|
|
35
|
+
"@infernetprotocol/engine": "0.1.56",
|
|
36
|
+
"@infernetprotocol/deploy-providers": "0.1.56",
|
|
37
|
+
"@infernetprotocol/gpu": "0.1.56",
|
|
38
|
+
"@infernetprotocol/rpc-adapter": "0.1.56"
|
|
39
39
|
},
|
|
40
40
|
"repository": {
|
|
41
41
|
"type": "git",
|