@infernetprotocol/cli 0.1.66 → 0.1.68

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.
@@ -0,0 +1,145 @@
1
+ /**
2
+ * `infernet credits` / `infernet redeem` / `infernet invites` — consumer
3
+ * compute credits and scarce invites for a signed-in account (`infernet login`).
4
+ *
5
+ * Credits are what you hold as a CUSTOMER of the network. They are separate
6
+ * from node earnings (`infernet payout`) and can never be withdrawn.
7
+ */
8
+ import { resolveCreditsOptions, createCreditsClient } from '../lib/credits-client.js';
9
+
10
+ export const CREDITS_HELP = `infernet credits — consumer compute credits
11
+
12
+ Usage:
13
+ infernet credits Balance and recent grants
14
+ infernet credits redeem <code> Redeem a credit code (also: infernet redeem <code>)
15
+ infernet invites Your invites, quota and affiliate link
16
+ infernet invites create [--note <text>] Create an invite (the code is shown once)
17
+ infernet invites revoke <invite-id> Withdraw an unused invite
18
+ infernet invites accept <code> Join on an invite (new accounts only)
19
+
20
+ Admin (INFERNET_ADMIN_TOKEN or an admin login):
21
+ infernet credits admin list
22
+ infernet credits admin mint --credits <n> [--label <text>] [--max <n>] [--expires <iso>] [--monthly]
23
+ infernet credits admin revoke <code-id>
24
+
25
+ Options: --json, --url <base>, --token <bearer>
26
+ Credits are not node earnings and cannot be withdrawn (see \`infernet payout\`).
27
+ `;
28
+
29
+ async function client(args) {
30
+ return createCreditsClient(await resolveCreditsOptions({ url: args.get('url'), token: args.get('token') }));
31
+ }
32
+
33
+ function out(args, data, text) {
34
+ process.stdout.write(args.has('json') ? `${JSON.stringify(data, null, 2)}\n` : `${text}\n`);
35
+ }
36
+
37
+ export async function redeemCode(args, code) {
38
+ if (!code) {
39
+ process.stderr.write('Usage: infernet redeem <code>\n');
40
+ return 1;
41
+ }
42
+ const c = await client(args);
43
+ try {
44
+ const r = await c.redeem(code);
45
+ out(args, r, `Redeemed: +${r.credits} credits${r.monthly ? ' every month' : ''}. Balance: ${r.balance}`);
46
+ return 0;
47
+ } catch (err) {
48
+ process.stderr.write(`${err.message}\n`);
49
+ return 1;
50
+ }
51
+ }
52
+
53
+ export async function credits(args) {
54
+ const [sub, ...rest] = args.positional;
55
+ if (args.has('help') || args.has('h') || sub === 'help') {
56
+ process.stdout.write(CREDITS_HELP);
57
+ return 0;
58
+ }
59
+ if (sub === 'redeem') return redeemCode(args, rest[0]);
60
+ const c = await client(args);
61
+ if (sub === 'admin') {
62
+ const [action, arg] = rest;
63
+ if (action === 'list') {
64
+ const rows = await c.listCodes();
65
+ out(args, rows, rows.length
66
+ ? rows.map((r) => `${r.id} ${r.grant.amount} ${r.grant.unit}${r.grant.every ? '/month' : ''} ${r.redemptions}/${r.maxRedemptions}${r.revokedAt ? ' revoked' : ''} ${r.label}`).join('\n')
67
+ : 'No codes.');
68
+ return 0;
69
+ }
70
+ if (action === 'mint') {
71
+ const body = {
72
+ credits: Number(args.get('credits') ?? args.get('amount')),
73
+ label: args.get('label'),
74
+ max_redemptions: args.get('max') ? Number(args.get('max')) : undefined,
75
+ expires_at: args.get('expires'),
76
+ monthly: args.has('monthly')
77
+ };
78
+ const r = await c.mintCode(body);
79
+ out(args, r, `Code: ${r.code}\n(shown once; only its hash is stored) id ${r.id} ${r.grant.amount} credits${r.grant.every ? '/month' : ''} max ${r.maxRedemptions}`);
80
+ return 0;
81
+ }
82
+ if (action === 'revoke' && arg) {
83
+ out(args, await c.revokeCode(arg), `Revoked ${arg}.`);
84
+ return 0;
85
+ }
86
+ process.stderr.write(CREDITS_HELP);
87
+ return 1;
88
+ }
89
+ if (sub && sub !== 'balance') {
90
+ process.stderr.write(CREDITS_HELP);
91
+ return 1;
92
+ }
93
+ const s = await c.balance();
94
+ const lines = [`Credits: ${s.balance}`];
95
+ for (const h of (s.history ?? []).slice(0, 10)) lines.push(` ${h.kind === 'spend' ? '-' : '+'}${h.amount} ${h.source} ${String(h.at).slice(0, 10)}`);
96
+ out(args, s, lines.join('\n'));
97
+ return 0;
98
+ }
99
+
100
+ export async function invites(args) {
101
+ const [sub, arg] = args.positional;
102
+ if (args.has('help') || args.has('h') || sub === 'help') {
103
+ process.stdout.write(CREDITS_HELP);
104
+ return 0;
105
+ }
106
+ const c = await client(args);
107
+ try {
108
+ if (sub === 'create') {
109
+ const r = await c.createInvite(args.get('note') ?? '');
110
+ out(args, r, `Invite: ${r.url}\n(code ${r.code}, shown once; expires ${String(r.expiresAt ?? '').slice(0, 10)})`);
111
+ return 0;
112
+ }
113
+ if (sub === 'revoke' && arg) {
114
+ out(args, await c.revokeInvite(arg), `Withdrawn ${arg}.`);
115
+ return 0;
116
+ }
117
+ if (sub === 'accept' && arg) {
118
+ const r = await c.acceptInvite(arg);
119
+ out(args, r, `Joined on the invite. Bonus: ${r.bonus}.`);
120
+ return 0;
121
+ }
122
+ if (sub && sub !== 'list') {
123
+ process.stderr.write(CREDITS_HELP);
124
+ return 1;
125
+ }
126
+ const o = await c.invites();
127
+ const lines = [
128
+ `Invites: ${o.quota.left} of ${o.quota.total} left${o.canInvite ? '' : ` (unlock ${String(o.unlocksAt ?? '').slice(0, 10)})`}`,
129
+ `Bonus: ${o.bonusCredits} credits each when an invited account confirms`,
130
+ `Link: ${o.refUrl}`
131
+ ];
132
+ for (const i of o.invites ?? []) lines.push(` ${i.id} ${i.status}${i.bonus ? ` (${i.bonus})` : ''} ${i.note ?? ''}`);
133
+ out(args, o, lines.join('\n'));
134
+ return 0;
135
+ } catch (err) {
136
+ process.stderr.write(`${err.message}\n`);
137
+ return 1;
138
+ }
139
+ }
140
+
141
+ export async function redeem(args) {
142
+ return redeemCode(args, args.positional[0]);
143
+ }
144
+
145
+ export default credits;
package/commands/help.js CHANGED
@@ -40,11 +40,14 @@ Diagnostics:
40
40
  Payments:
41
41
  payout Earnings, withdrawals and payout address
42
42
  payments Show recent payment transactions
43
+ credits Your consumer compute credits (not earnings); redeem a code
44
+ redeem Redeem a credit code: infernet redeem CR-XXXX-XXXX-XXXX-XXXX
45
+ invites Scarce invites (both sides get credits) and your affiliate link
43
46
 
44
47
  Managed endpoints:
45
48
  reservation Book a pinned operator + exact model by the hour; keys, limits,
46
49
  per-minute availability report, post-paid invoice data
47
- mcp MCP server (stdio) exposing the reservation tools
50
+ mcp MCP server (stdio): reservation, credit and invite tools
48
51
 
49
52
  Other:
50
53
  help Show this help
package/commands/mcp.js CHANGED
@@ -12,6 +12,7 @@
12
12
  */
13
13
  import { createInterface } from 'node:readline';
14
14
  import { resolveClientOptions, createReservationsClient } from '../lib/reservations-client.js';
15
+ import { resolveCreditsOptions, createCreditsClient } from '../lib/credits-client.js';
15
16
  import { CURRENT_VERSION } from '../lib/version.js';
16
17
 
17
18
  const PROTOCOL_VERSION = '2025-06-18';
@@ -83,6 +84,22 @@ export const TOOLS = [
83
84
  description: 'Post-paid invoice data: hour statuses and amount due for compliant hours only. Executes no payment.',
84
85
  inputSchema: { type: 'object', required: ['id'], properties: { id } },
85
86
  run: (c, a) => c.invoice(a.id)
87
+ },
88
+ // Consumer compute credits + invites for the `infernet login` account.
89
+ // Credits are never node earnings and cannot be withdrawn.
90
+ { name: 'credits_balance', description: 'Your consumer compute-credit balance and recent grants (signed-in account).', inputSchema: { type: 'object', properties: {} }, run: (c) => c.credits.balance() },
91
+ {
92
+ name: 'credits_redeem',
93
+ description: 'Redeem a credit code (CR-XXXX-XXXX-XXXX-XXXX) for consumer compute credits.',
94
+ inputSchema: { type: 'object', required: ['code'], properties: { code: { type: 'string' } } },
95
+ run: (c, a) => c.credits.redeem(a.code)
96
+ },
97
+ { name: 'invites_list', description: 'Your invites, quota, bonus and affiliate link.', inputSchema: { type: 'object', properties: {} }, run: (c) => c.credits.invites() },
98
+ {
99
+ name: 'invite_create',
100
+ description: 'Create a single-use invite link (shown once). Both people get credits when a new account joins on it and confirms its email.',
101
+ inputSchema: { type: 'object', properties: { note: { type: 'string' } } },
102
+ run: (c, a) => c.credits.createInvite(a.note)
86
103
  }
87
104
  ];
88
105
 
@@ -119,10 +136,11 @@ export async function handleMessage(msg, client) {
119
136
 
120
137
  export default async function mcp(args) {
121
138
  if (args.has('help') || args.has('h')) {
122
- process.stdout.write('infernet mcp — MCP server (stdio) for managed-endpoint reservations\n\n claude mcp add infernet -- infernet mcp\n');
139
+ process.stdout.write('infernet mcp — MCP server (stdio): managed-endpoint reservations, credits and invites\n\n claude mcp add infernet -- infernet mcp\n');
123
140
  return 0;
124
141
  }
125
142
  const client = createReservationsClient(await resolveClientOptions({ url: args.get('url'), token: args.get('token'), buyerToken: args.get('buyer-token') }));
143
+ client.credits = createCreditsClient(await resolveCreditsOptions({ url: args.get('url'), token: args.get('token') }));
126
144
  const rl = createInterface({ input: process.stdin });
127
145
  for await (const line of rl) {
128
146
  if (!line.trim()) continue;
package/index.js CHANGED
@@ -50,6 +50,7 @@ import rpc from './commands/rpc.js';
50
50
  import uncensored from './commands/uncensored.js';
51
51
  import reservation from './commands/reservation.js';
52
52
  import mcp from './commands/mcp.js';
53
+ import credits, { invites, redeem } from './commands/credits.js';
53
54
 
54
55
  function parseArgs(argv) {
55
56
  const positional = [];
@@ -111,11 +112,11 @@ const COMMANDS = {
111
112
  // aliases
112
113
  uninstall: remove,
113
114
  start, status, stop, restart, stats, logs,
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
115
+ payout, payments, gpu, firewall, chat, setup, model, train, publish, inference, rpc, uncensored, reservation, reservations: reservation, mcp, credits, invites, redeem, tui, doctor, service, pubkey, debug, deploy, console: consoleCmd, help
115
116
  };
116
117
 
117
118
  // Commands that can run without a loaded config.
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']);
119
+ 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', 'credits', 'invites', 'redeem', 'tui', 'doctor', 'service', 'pubkey', 'debug', 'deploy', 'console', 'upgrade', 'update', 'remove', 'uninstall']);
119
120
  // Commands that need a config but not a control-plane client (none today
120
121
  // — kept as a future escape hatch).
121
122
  const NO_CLIENT = new Set();
@@ -0,0 +1,64 @@
1
+ /**
2
+ * HTTP client for consumer compute credits and invites — shared by
3
+ * `infernet credits`, `infernet redeem`, `infernet invites` and `infernet mcp`.
4
+ *
5
+ * Base URL: --url, INFERNET_URL, config.controlPlane.url, else infernetprotocol.com
6
+ * User auth: the `infernet login` bearer (config.auth.bearerToken) or --token
7
+ * Admin (mint/list/revoke codes): INFERNET_ADMIN_TOKEN, else the login bearer
8
+ * of an admin account.
9
+ *
10
+ * Credits are a CONSUMER balance: never node earnings, never withdrawable.
11
+ */
12
+ import { loadConfig } from './config.js';
13
+
14
+ const DEFAULT_URL = 'https://infernetprotocol.com';
15
+
16
+ export async function resolveCreditsOptions(opts = {}) {
17
+ const config = await loadConfig().catch(() => null);
18
+ const bearer = config?.auth?.bearerToken || null;
19
+ return {
20
+ baseUrl: String(opts.url || process.env.INFERNET_URL || config?.controlPlane?.url || DEFAULT_URL).replace(/\/+$/, ''),
21
+ userToken: opts.token || bearer,
22
+ adminToken: opts.token || process.env.INFERNET_ADMIN_TOKEN || bearer
23
+ };
24
+ }
25
+
26
+ export function createCreditsClient({ baseUrl, userToken, adminToken, fetchImpl = fetch }) {
27
+ async function call(method, path, { body, admin = false } = {}) {
28
+ const token = admin ? adminToken : userToken;
29
+ if (!token) {
30
+ throw new Error(admin
31
+ ? 'admin authorization required: set INFERNET_ADMIN_TOKEN or run `infernet login` as an admin'
32
+ : 'not signed in: run `infernet login` first');
33
+ }
34
+ const headers = { accept: 'application/json', authorization: `Bearer ${token}` };
35
+ if (body !== undefined) headers['content-type'] = 'application/json';
36
+ const res = await fetchImpl(`${baseUrl}${path}`, {
37
+ method,
38
+ headers,
39
+ body: body === undefined ? undefined : JSON.stringify(body)
40
+ });
41
+ const text = await res.text();
42
+ let json = null;
43
+ try { json = text ? JSON.parse(text) : null; } catch { /* non-JSON */ }
44
+ if (!res.ok) {
45
+ const err = new Error(json?.error ?? `${method} ${path} -> HTTP ${res.status} ${text.slice(0, 200)}`);
46
+ err.status = res.status;
47
+ err.reason = json?.reason;
48
+ throw err;
49
+ }
50
+ return json?.data ?? json;
51
+ }
52
+ const enc = encodeURIComponent;
53
+ return {
54
+ balance: () => call('GET', '/api/v1/credits'),
55
+ redeem: (code) => call('POST', '/api/v1/credits/redeem', { body: { code } }),
56
+ invites: () => call('GET', '/api/v1/invites'),
57
+ createInvite: (note) => call('POST', '/api/v1/invites', { body: { note: note ?? '' } }),
58
+ revokeInvite: (id) => call('DELETE', `/api/v1/invites/${enc(id)}`),
59
+ acceptInvite: (code) => call('POST', '/api/v1/invites/accept', { body: { code } }),
60
+ listCodes: () => call('GET', '/api/v1/admin/credit-codes', { admin: true }),
61
+ mintCode: (input) => call('POST', '/api/v1/admin/credit-codes', { body: input, admin: true }),
62
+ revokeCode: (id) => call('DELETE', `/api/v1/admin/credit-codes/${enc(id)}`, { admin: true })
63
+ };
64
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infernetprotocol/cli",
3
- "version": "0.1.66",
3
+ "version": "0.1.68",
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",
@@ -22,21 +22,21 @@
22
22
  "node": ">=18"
23
23
  },
24
24
  "dependencies": {
25
- "@noble/ciphers": "^2.2.0",
26
- "@noble/curves": "^2.2.0",
27
- "@noble/hashes": "^2.2.0",
25
+ "@noble/ciphers": "^2.4.0",
26
+ "@noble/curves": "^2.4.0",
27
+ "@noble/hashes": "^2.4.0",
28
28
  "blessed": "^0.1.81",
29
- "dotenv": "^16.4.7",
30
- "ora": "^9.4.0",
29
+ "dotenv": "^18.0.9",
30
+ "ora": "^9.4.1",
31
31
  "react": "^17.0.2",
32
32
  "react-blessed": "^0.7.2",
33
- "@infernetprotocol/auth": "0.1.66",
34
- "@infernetprotocol/config": "0.1.66",
35
- "@infernetprotocol/engine": "0.1.66",
36
- "@infernetprotocol/gpu": "0.1.66",
37
- "@infernetprotocol/liquid-agent": "0.1.66",
38
- "@infernetprotocol/rpc-adapter": "0.1.66",
39
- "@infernetprotocol/deploy-providers": "0.1.66"
33
+ "@infernetprotocol/auth": "0.1.68",
34
+ "@infernetprotocol/deploy-providers": "0.1.68",
35
+ "@infernetprotocol/config": "0.1.68",
36
+ "@infernetprotocol/engine": "0.1.68",
37
+ "@infernetprotocol/gpu": "0.1.68",
38
+ "@infernetprotocol/liquid-agent": "0.1.68",
39
+ "@infernetprotocol/rpc-adapter": "0.1.68"
40
40
  },
41
41
  "repository": {
42
42
  "type": "git",