@heyditto/cli 3.22.3 → 3.24.0
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/README.md +102 -0
- package/dist/api.d.ts +32 -0
- package/dist/api.js +10 -0
- package/dist/api.js.map +1 -1
- package/dist/cli.js +4 -1
- package/dist/cli.js.map +1 -1
- package/dist/gamma/btauth.d.ts +84 -0
- package/dist/gamma/btauth.js +175 -0
- package/dist/gamma/btauth.js.map +1 -0
- package/dist/gamma/client.d.ts +145 -0
- package/dist/gamma/client.js +551 -0
- package/dist/gamma/client.js.map +1 -0
- package/dist/gamma/commands.d.ts +4 -0
- package/dist/gamma/commands.js +194 -0
- package/dist/gamma/commands.js.map +1 -0
- package/dist/gamma/hotkey.d.ts +51 -0
- package/dist/gamma/hotkey.js +241 -0
- package/dist/gamma/hotkey.js.map +1 -0
- package/dist/mcp-refresh-command.d.ts +8 -0
- package/dist/mcp-refresh-command.js +194 -0
- package/dist/mcp-refresh-command.js.map +1 -0
- package/dist/org-commands.js +13 -0
- package/dist/org-commands.js.map +1 -1
- package/dist/tools-commands.js +14 -0
- package/dist/tools-commands.js.map +1 -1
- package/dist/update-lock.json +1 -1
- package/package.json +4 -1
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gamma Integration Standard V1.3 client for Ditto Router: discovery from the
|
|
3
|
+
* SN118 services document, then btauth/1-signed calls to the paid API with
|
|
4
|
+
* the hotkey alone. No Ditto API key, login, cookie or account link is ever
|
|
5
|
+
* read or sent here: every request carries only the headers built below.
|
|
6
|
+
*
|
|
7
|
+
* Discovery: the services document (by default the URL Ditto's SN118
|
|
8
|
+
* `set_service` publishes; `btcli query services --netuid 118` shows it)
|
|
9
|
+
* names the publisher hotkeys (the receivers a request may be signed for), the
|
|
10
|
+
* OpenAPI spec whose `servers` give the inference base URL, the balance URL
|
|
11
|
+
* and the pricing document.
|
|
12
|
+
*/
|
|
13
|
+
import { decodeAddress } from "@polkadot/util-crypto";
|
|
14
|
+
import { u8aToHex } from "@polkadot/util";
|
|
15
|
+
import { signRequest } from "./btauth.js";
|
|
16
|
+
export const SN118_NETUID = 118;
|
|
17
|
+
/** The services document Ditto's SN118 `set_service` points at. */
|
|
18
|
+
export const DEFAULT_SERVICES_URL = "https://api.heyditto.ai/api/v5/chain-gamma/public/services.json";
|
|
19
|
+
export const SESSION_HEADER = "X-Ditto-Session-Id";
|
|
20
|
+
/** Exit status when the hotkey's balance cannot pay (HTTP 402). */
|
|
21
|
+
export const EXIT_INSUFFICIENT_BALANCE = 3;
|
|
22
|
+
const SESSION_PATTERN = /^[A-Za-z0-9._:@-]{1,128}$/;
|
|
23
|
+
const FETCH_TIMEOUT_MS = 30_000;
|
|
24
|
+
export class GammaHTTPError extends Error {
|
|
25
|
+
status;
|
|
26
|
+
code;
|
|
27
|
+
exitCode;
|
|
28
|
+
constructor(message, status, code, exitCode = 1) {
|
|
29
|
+
super(message);
|
|
30
|
+
this.status = status;
|
|
31
|
+
this.code = code;
|
|
32
|
+
this.exitCode = exitCode;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** HTTP 402: the hotkey's balance is empty or the hotkey has never spent gamma here. */
|
|
36
|
+
export class InsufficientBalanceError extends GammaHTTPError {
|
|
37
|
+
serverMessage;
|
|
38
|
+
constructor(message, serverMessage) {
|
|
39
|
+
super(message, 402, "insufficient_balance", EXIT_INSUFFICIENT_BALANCE);
|
|
40
|
+
this.serverMessage = serverMessage;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function isLoopback(host) {
|
|
44
|
+
return host === "localhost" || host === "127.0.0.1" || host === "[::1]" || host === "::1";
|
|
45
|
+
}
|
|
46
|
+
/** Discovered URLs must be https (plain http only for a loopback test server). */
|
|
47
|
+
export function checkedURL(raw, what, base) {
|
|
48
|
+
if (typeof raw !== "string" || raw.trim() === "")
|
|
49
|
+
throw new Error(`the services document has no ${what}`);
|
|
50
|
+
let u;
|
|
51
|
+
try {
|
|
52
|
+
u = new URL(raw, base);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
throw new Error(`the ${what} is not a URL`);
|
|
56
|
+
}
|
|
57
|
+
if (u.username || u.password)
|
|
58
|
+
throw new Error(`the ${what} must not carry credentials`);
|
|
59
|
+
if (u.protocol !== "https:" && !(u.protocol === "http:" && isLoopback(u.hostname))) {
|
|
60
|
+
throw new Error(`the ${what} must be https (got ${u.protocol}//${u.host})`);
|
|
61
|
+
}
|
|
62
|
+
return u;
|
|
63
|
+
}
|
|
64
|
+
const sameKey = (a, b) => {
|
|
65
|
+
try {
|
|
66
|
+
return u8aToHex(decodeAddress(a)) === u8aToHex(decodeAddress(b));
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
async function getJSON(url, what) {
|
|
73
|
+
let res;
|
|
74
|
+
try {
|
|
75
|
+
res = await fetch(url, { headers: { accept: "application/json" }, redirect: "error", signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
throw new Error(`could not fetch the ${what} at ${url.href}: ${error instanceof Error ? error.message : String(error)}`);
|
|
79
|
+
}
|
|
80
|
+
const text = await res.text();
|
|
81
|
+
if (!res.ok)
|
|
82
|
+
throw new GammaHTTPError(`the ${what} at ${url.href} answered HTTP ${res.status}`, res.status);
|
|
83
|
+
try {
|
|
84
|
+
return JSON.parse(text);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
throw new Error(`the ${what} at ${url.href} is not JSON`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/** Env var equivalent of --allow-untrusted-origin. */
|
|
91
|
+
export const ALLOW_UNTRUSTED_ORIGIN_ENV = "DITTO_GAMMA_ALLOW_UNTRUSTED_ORIGIN";
|
|
92
|
+
/** The only origins requests are signed for by default: https heyditto.ai and its subdomains. */
|
|
93
|
+
export function isTrustedOrigin(url) {
|
|
94
|
+
let u;
|
|
95
|
+
try {
|
|
96
|
+
u = typeof url === "string" ? new URL(url) : url;
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
if (u.protocol !== "https:" || u.username || u.password)
|
|
102
|
+
return false;
|
|
103
|
+
if (u.port !== "" && u.port !== "443")
|
|
104
|
+
return false;
|
|
105
|
+
const host = u.hostname.toLowerCase().replace(/\.$/, "");
|
|
106
|
+
return host === "heyditto.ai" || host.endsWith(".heyditto.ai");
|
|
107
|
+
}
|
|
108
|
+
function envFlag(v) {
|
|
109
|
+
return v !== undefined && /^(1|true|yes|on)$/i.test(v.trim());
|
|
110
|
+
}
|
|
111
|
+
export class UntrustedOriginError extends Error {
|
|
112
|
+
}
|
|
113
|
+
function untrusted(what, url) {
|
|
114
|
+
return new UntrustedOriginError(`refusing to use the ${what} ${url.origin}: btauth/1 requests are signed only for https://heyditto.ai and *.heyditto.ai. ` +
|
|
115
|
+
`A signed request sent elsewhere could be replayed to Ditto against your balance. ` +
|
|
116
|
+
`Pass --allow-untrusted-origin (or ${ALLOW_UNTRUSTED_ORIGIN_ENV}=1) only for a host you run yourself.`);
|
|
117
|
+
}
|
|
118
|
+
/** Fetches and validates the services document and the OpenAPI spec it links. */
|
|
119
|
+
export async function discover(o = {}, env = process.env) {
|
|
120
|
+
const servicesUrl = checkedURL(o.servicesUrl || env.DITTO_GAMMA_SERVICES_URL || DEFAULT_SERVICES_URL, "services document URL");
|
|
121
|
+
const netuid = o.netuid ?? SN118_NETUID;
|
|
122
|
+
const doc = await getJSON(servicesUrl, "services document");
|
|
123
|
+
if (!doc || typeof doc !== "object")
|
|
124
|
+
throw new Error("the services document is not a JSON object");
|
|
125
|
+
const publishers = (Array.isArray(doc.publishers) ? doc.publishers : [])
|
|
126
|
+
.filter((p) => Boolean(p) && typeof p.hotkey === "string")
|
|
127
|
+
.filter((p) => Number(p.netuid) === netuid)
|
|
128
|
+
.map((p) => p.hotkey)
|
|
129
|
+
.filter((h) => { try {
|
|
130
|
+
decodeAddress(h);
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return false;
|
|
135
|
+
} });
|
|
136
|
+
if (publishers.length === 0)
|
|
137
|
+
throw new Error(`the services document lists no publisher hotkey for netuid ${netuid}`);
|
|
138
|
+
const wanted = o.receiver || env.DITTO_GAMMA_RECEIVER;
|
|
139
|
+
let receiver = publishers[0];
|
|
140
|
+
if (wanted) {
|
|
141
|
+
const match = publishers.find((p) => sameKey(p, wanted));
|
|
142
|
+
if (!match) {
|
|
143
|
+
throw new Error(`refusing to sign for receiver ${wanted}: it is not a publisher hotkey in ${servicesUrl.href} (listed: ${publishers.join(", ")})`);
|
|
144
|
+
}
|
|
145
|
+
receiver = match;
|
|
146
|
+
}
|
|
147
|
+
const payment = (Array.isArray(doc.payments) ? doc.payments : [])
|
|
148
|
+
.find((p) => p && p.type === "gamma");
|
|
149
|
+
if (!payment)
|
|
150
|
+
throw new Error("the services document has no gamma payment entry");
|
|
151
|
+
if (payment.signature !== "btauth/1")
|
|
152
|
+
throw new Error("the services document's gamma payment does not accept btauth/1 signatures");
|
|
153
|
+
const balanceUrl = checkedURL(payment.balance, "balance URL", servicesUrl.href);
|
|
154
|
+
const service = (Array.isArray(doc.services) ? doc.services : [])
|
|
155
|
+
.find((s) => s && s.type === "openapi");
|
|
156
|
+
const openapiUrl = checkedURL(service?.endpoint, "OpenAPI endpoint", servicesUrl.href);
|
|
157
|
+
const pricingUrl = doc.pricing === undefined ? undefined : checkedURL(doc.pricing, "pricing URL", servicesUrl.href).href;
|
|
158
|
+
const spec = await getJSON(openapiUrl, "OpenAPI document");
|
|
159
|
+
const apiBase = checkedURL(spec?.servers?.[0]?.url, "OpenAPI server URL", openapiUrl.href);
|
|
160
|
+
const allowUntrustedOrigin = Boolean(o.allowUntrustedOrigin) || envFlag(env[ALLOW_UNTRUSTED_ORIGIN_ENV]);
|
|
161
|
+
const foreign = [["API base (OpenAPI servers)", apiBase], ["balance URL", balanceUrl]];
|
|
162
|
+
const warned = new Set();
|
|
163
|
+
for (const [what, url] of foreign) {
|
|
164
|
+
if (isTrustedOrigin(url))
|
|
165
|
+
continue;
|
|
166
|
+
if (!allowUntrustedOrigin)
|
|
167
|
+
throw untrusted(what, url);
|
|
168
|
+
if (!warned.has(url.host)) {
|
|
169
|
+
warned.add(url.host);
|
|
170
|
+
process.stderr.write(`warning: --allow-untrusted-origin: using ${url.host} (${what}), which is not heyditto.ai; requests signed by your hotkey will be sent there\n`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
servicesUrl: servicesUrl.href,
|
|
175
|
+
netuid,
|
|
176
|
+
name: typeof doc.name === "string" ? doc.name : undefined,
|
|
177
|
+
publishers,
|
|
178
|
+
receiver,
|
|
179
|
+
openapiUrl: openapiUrl.href,
|
|
180
|
+
apiBase: apiBase.href.replace(/\/+$/, ""),
|
|
181
|
+
balanceUrl: balanceUrl.href,
|
|
182
|
+
pricingUrl,
|
|
183
|
+
paths: Object.keys(spec?.paths ?? {}),
|
|
184
|
+
allowUntrustedOrigin,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
/** GET <balance>?hotkey=<ss58>. Public; an unknown hotkey answers zeros. */
|
|
188
|
+
export async function fetchBalance(d, hotkey) {
|
|
189
|
+
const url = new URL(d.balanceUrl);
|
|
190
|
+
if (!isTrustedOrigin(url) && !d.allowUntrustedOrigin)
|
|
191
|
+
throw untrusted("balance URL", url);
|
|
192
|
+
url.searchParams.set("hotkey", hotkey);
|
|
193
|
+
const body = await getJSON(url, "balance endpoint");
|
|
194
|
+
const str = (v) => (typeof v === "string" ? v : v === undefined || v === null ? "" : String(v));
|
|
195
|
+
return { hotkey: str(body.hotkey) || hotkey, credited_usd: str(body.credited_usd), used_usd: str(body.used_usd), remaining_usd: str(body.remaining_usd) };
|
|
196
|
+
}
|
|
197
|
+
/** The btcli commands that fund a hotkey at Ditto. */
|
|
198
|
+
export function fundingHelp(d, hotkeyName) {
|
|
199
|
+
return [
|
|
200
|
+
` btcli gamma mint --netuid ${d.netuid} --hotkey ${hotkeyName} --amount-tao TAO_AMOUNT`,
|
|
201
|
+
` btcli gamma spend --netuid ${d.netuid} --service-hotkey ${d.receiver} --amount-gamma GAMMA_AMOUNT -H ${hotkeyName}`,
|
|
202
|
+
].join("\n");
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* One btauth/1-signed request. Signs the exact bytes sent with a fresh nonce;
|
|
206
|
+
* a caller that retries calls this again, so every attempt is re-signed.
|
|
207
|
+
*/
|
|
208
|
+
export async function signedFetch(c, method, url, body, extra = {}, stream = false, signal) {
|
|
209
|
+
// Checked again at the signing point (the MCP URL and every paid route), so
|
|
210
|
+
// no signature is computed for a foreign host whatever built the URL.
|
|
211
|
+
if (!isTrustedOrigin(url) && !c.discovery.allowUntrustedOrigin)
|
|
212
|
+
throw untrusted("request URL", url);
|
|
213
|
+
const bytes = body === undefined ? undefined : Buffer.from(JSON.stringify(body), "utf8");
|
|
214
|
+
const headers = {
|
|
215
|
+
accept: extra.accept ?? "application/json",
|
|
216
|
+
...(bytes ? { "content-type": "application/json" } : {}),
|
|
217
|
+
...Object.fromEntries(Object.entries(extra).filter(([k]) => k !== "accept")),
|
|
218
|
+
...signRequest(c.signer, { method, url, body: bytes, receiver: c.discovery.receiver }),
|
|
219
|
+
};
|
|
220
|
+
let res;
|
|
221
|
+
try {
|
|
222
|
+
res = await fetch(url, { method, headers, body: bytes, redirect: "error", signal: signal ?? AbortSignal.timeout(stream ? DEFAULT_STREAM_TOTAL_MS : 300_000) });
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
throw new Error(`${method} ${url.href} failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
226
|
+
}
|
|
227
|
+
if (res.status === 402 || !res.ok || !stream) {
|
|
228
|
+
const text = await res.text();
|
|
229
|
+
if (res.status === 402)
|
|
230
|
+
throw insufficient(c, text);
|
|
231
|
+
if (!res.ok)
|
|
232
|
+
throw httpError(res.status, text, `${method} ${url.pathname}`);
|
|
233
|
+
return { status: res.status, headers: res.headers, text };
|
|
234
|
+
}
|
|
235
|
+
return { status: res.status, headers: res.headers, text: "", body: res };
|
|
236
|
+
}
|
|
237
|
+
function parseError(text) {
|
|
238
|
+
try {
|
|
239
|
+
const j = JSON.parse(text);
|
|
240
|
+
if (typeof j.error === "string")
|
|
241
|
+
return { code: j.error, message: typeof j.message === "string" ? j.message : undefined };
|
|
242
|
+
if (j.error && typeof j.error === "object") {
|
|
243
|
+
const e = j.error;
|
|
244
|
+
return { code: typeof e.code === "string" ? e.code : typeof e.type === "string" ? e.type : undefined, message: typeof e.message === "string" ? e.message : undefined };
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
catch { /* not JSON */ }
|
|
248
|
+
return {};
|
|
249
|
+
}
|
|
250
|
+
function insufficient(c, text) {
|
|
251
|
+
const e = parseError(text);
|
|
252
|
+
const server = e.message ?? "insufficient_balance";
|
|
253
|
+
return new InsufficientBalanceError([
|
|
254
|
+
`This hotkey (${c.signer.address}) has no Ditto balance to pay for this request (HTTP 402 insufficient_balance).`,
|
|
255
|
+
`Ditto said: ${server}`,
|
|
256
|
+
"Mint gamma and spend it at Ditto's publisher hotkey, then wait about 10 finalized blocks:",
|
|
257
|
+
fundingHelp(c.discovery, c.hotkeyName),
|
|
258
|
+
"Check the credit with `heyditto gamma balance`.",
|
|
259
|
+
].join("\n"), server);
|
|
260
|
+
}
|
|
261
|
+
function httpError(status, text, what) {
|
|
262
|
+
const e = parseError(text);
|
|
263
|
+
let hint = "";
|
|
264
|
+
if (status === 401 && e.code === "stale_request")
|
|
265
|
+
hint = " Check this computer's clock.";
|
|
266
|
+
if (status === 401 && e.code === "wrong_receiver")
|
|
267
|
+
hint = " The publisher hotkey may have changed; rerun to rediscover it.";
|
|
268
|
+
return new GammaHTTPError(`${what}: HTTP ${status}${e.code ? ` ${e.code}` : ""}${e.message ? `: ${e.message}` : ""}.${hint}`, status, e.code);
|
|
269
|
+
}
|
|
270
|
+
export function apiURL(d, pathname) {
|
|
271
|
+
return new URL(d.apiBase + pathname);
|
|
272
|
+
}
|
|
273
|
+
/** Signed GET /v1/models. */
|
|
274
|
+
export async function listModels(c) {
|
|
275
|
+
const res = await signedFetch(c, "GET", apiURL(c.discovery, "/v1/models"));
|
|
276
|
+
const raw = JSON.parse(res.text);
|
|
277
|
+
return { raw, ids: (raw.data ?? []).map((m) => m.id).filter((id) => typeof id === "string") };
|
|
278
|
+
}
|
|
279
|
+
/** The pricing document's default model, the model a request should name when the user named none. */
|
|
280
|
+
export async function defaultModel(d) {
|
|
281
|
+
if (!d.pricingUrl)
|
|
282
|
+
return undefined;
|
|
283
|
+
try {
|
|
284
|
+
const p = await getJSON(new URL(d.pricingUrl), "pricing document");
|
|
285
|
+
return typeof p.default_model === "string" && p.default_model ? p.default_model : undefined;
|
|
286
|
+
}
|
|
287
|
+
catch {
|
|
288
|
+
return undefined;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
export function validSessionId(id) { return SESSION_PATTERN.test(id); }
|
|
292
|
+
/** A streamed answer may take this long in all (15 minutes) by default. */
|
|
293
|
+
export const DEFAULT_STREAM_TOTAL_MS = 900_000;
|
|
294
|
+
/** A streamed answer may go this long without a byte (2 minutes) by default. */
|
|
295
|
+
export const DEFAULT_STREAM_IDLE_MS = 120_000;
|
|
296
|
+
/** Node's setTimeout maximum; a longer delay silently fires after 1 ms. */
|
|
297
|
+
export const MAX_TIMER_MS = 2_147_483_647;
|
|
298
|
+
/** Throws unless ms is a whole number of milliseconds a timer can hold (1 to MAX_TIMER_MS). */
|
|
299
|
+
export function checkTimerMs(ms, what) {
|
|
300
|
+
if (!Number.isInteger(ms) || ms < 1 || ms > MAX_TIMER_MS) {
|
|
301
|
+
throw new Error(`${what} must be between 1 ms and ${MAX_TIMER_MS} ms (about 24.8 days)`);
|
|
302
|
+
}
|
|
303
|
+
return ms;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* A timer limit given in `unit` (1 for milliseconds, 1000 for seconds), as
|
|
307
|
+
* whole milliseconds. A value below 1 ms or above the timer maximum is an
|
|
308
|
+
* error rather than a silent 0 or overflow.
|
|
309
|
+
*/
|
|
310
|
+
export function parseTimerLimit(raw, unitMs, what) {
|
|
311
|
+
const n = Number(raw.trim());
|
|
312
|
+
if (raw.trim() === "" || !Number.isFinite(n) || n <= 0)
|
|
313
|
+
throw new Error(`${what} must be a positive number`);
|
|
314
|
+
const ms = Math.floor(n * unitMs);
|
|
315
|
+
if (ms < 1)
|
|
316
|
+
throw new Error(`${what} is below 1 ms (${unitMs === 1000 ? "at least 0.001 seconds" : "at least 1"})`);
|
|
317
|
+
if (ms > MAX_TIMER_MS)
|
|
318
|
+
throw new Error(`${what} exceeds the timer maximum of ${MAX_TIMER_MS} ms (about 24.8 days)`);
|
|
319
|
+
return ms;
|
|
320
|
+
}
|
|
321
|
+
function positiveMs(raw, fallback, what) {
|
|
322
|
+
if (raw === undefined || raw.trim() === "")
|
|
323
|
+
return fallback;
|
|
324
|
+
return parseTimerLimit(raw, 1, what);
|
|
325
|
+
}
|
|
326
|
+
/** Stream limits from DITTO_GAMMA_STREAM_TIMEOUT_MS and DITTO_GAMMA_STREAM_IDLE_MS, or the defaults. */
|
|
327
|
+
export function streamLimits(env = process.env) {
|
|
328
|
+
return {
|
|
329
|
+
totalMs: positiveMs(env.DITTO_GAMMA_STREAM_TIMEOUT_MS, DEFAULT_STREAM_TOTAL_MS, "DITTO_GAMMA_STREAM_TIMEOUT_MS"),
|
|
330
|
+
idleMs: positiveMs(env.DITTO_GAMMA_STREAM_IDLE_MS, DEFAULT_STREAM_IDLE_MS, "DITTO_GAMMA_STREAM_IDLE_MS"),
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
export class StreamTimeoutError extends Error {
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Signed POST /v1/chat/completions. The session header groups turns into one
|
|
337
|
+
* thread of the hotkey account, so repeated chats build that account's history.
|
|
338
|
+
*/
|
|
339
|
+
export async function chat(c, o) {
|
|
340
|
+
if (!validSessionId(o.session))
|
|
341
|
+
throw new Error("--session must be 1-128 characters of A-Z a-z 0-9 . _ : @ -");
|
|
342
|
+
const body = { model: o.model, messages: [{ role: "user", content: o.prompt }], stream: o.stream };
|
|
343
|
+
const extra = { [SESSION_HEADER]: o.session, accept: o.stream ? "text/event-stream" : "application/json" };
|
|
344
|
+
if (!o.stream)
|
|
345
|
+
return chatOnce(c, body, extra);
|
|
346
|
+
const limits = o.limits ?? streamLimits();
|
|
347
|
+
checkTimerMs(limits.totalMs, "the stream timeout");
|
|
348
|
+
checkTimerMs(limits.idleMs, "the stream idle timeout");
|
|
349
|
+
const ac = new AbortController();
|
|
350
|
+
const overall = new StreamTimeoutError(`the streamed answer took longer than ${limits.totalMs / 1000}s; it was cancelled`);
|
|
351
|
+
const timer = setTimeout(() => ac.abort(overall), limits.totalMs);
|
|
352
|
+
try {
|
|
353
|
+
return await chatStream(c, o, body, extra, limits, ac.signal);
|
|
354
|
+
}
|
|
355
|
+
catch (error) {
|
|
356
|
+
if (ac.signal.aborted && ac.signal.reason === overall)
|
|
357
|
+
throw overall;
|
|
358
|
+
throw error;
|
|
359
|
+
}
|
|
360
|
+
finally {
|
|
361
|
+
clearTimeout(timer);
|
|
362
|
+
ac.abort();
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
async function chatOnce(c, body, extra) {
|
|
366
|
+
const res = await signedFetch(c, "POST", apiURL(c.discovery, "/v1/chat/completions"), body, extra);
|
|
367
|
+
const raw = JSON.parse(res.text);
|
|
368
|
+
const content = raw.choices?.[0]?.message?.content;
|
|
369
|
+
return { text: typeof content === "string" ? content : "", raw, model: raw.model };
|
|
370
|
+
}
|
|
371
|
+
async function chatStream(c, o, body, extra, limits, signal) {
|
|
372
|
+
const res = await signedFetch(c, "POST", apiURL(c.discovery, "/v1/chat/completions"), body, extra, true, signal);
|
|
373
|
+
if (!res.body) {
|
|
374
|
+
const raw = JSON.parse(res.text);
|
|
375
|
+
const content = raw.choices?.[0]?.message?.content;
|
|
376
|
+
return { text: typeof content === "string" ? content : "", raw, model: raw.model };
|
|
377
|
+
}
|
|
378
|
+
if (!(res.headers.get("content-type") ?? "").includes("text/event-stream")) {
|
|
379
|
+
const raw = JSON.parse(await res.body.text());
|
|
380
|
+
const content = raw.choices?.[0]?.message?.content;
|
|
381
|
+
const text = typeof content === "string" ? content : "";
|
|
382
|
+
o.onDelta?.(text);
|
|
383
|
+
return { text, raw, model: raw.model };
|
|
384
|
+
}
|
|
385
|
+
let text = "";
|
|
386
|
+
let model;
|
|
387
|
+
for await (const data of sseData(res.body, { idleMs: limits.idleMs })) {
|
|
388
|
+
if (data === "[DONE]")
|
|
389
|
+
break;
|
|
390
|
+
let event;
|
|
391
|
+
try {
|
|
392
|
+
event = JSON.parse(data);
|
|
393
|
+
}
|
|
394
|
+
catch {
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
if (event.error) {
|
|
398
|
+
const e = parseError(data);
|
|
399
|
+
if (e.code === "insufficient_balance")
|
|
400
|
+
throw insufficient(c, data);
|
|
401
|
+
throw new GammaHTTPError(`the stream ended with an error${e.code ? ` ${e.code}` : ""}${e.message ? `: ${e.message}` : ""}`, 200, e.code);
|
|
402
|
+
}
|
|
403
|
+
model ??= event.model;
|
|
404
|
+
const delta = event.choices?.[0]?.delta?.content;
|
|
405
|
+
if (typeof delta === "string" && delta) {
|
|
406
|
+
text += delta;
|
|
407
|
+
o.onDelta?.(delta);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
return { text, model };
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Yields each SSE event's joined `data:` lines. When the consumer stops early
|
|
414
|
+
* (a `[DONE]`, an error, a timeout) the body is cancelled, so an SSE response
|
|
415
|
+
* the server leaves open never keeps the request alive. `idleMs` bounds the
|
|
416
|
+
* wait for each chunk.
|
|
417
|
+
*/
|
|
418
|
+
export async function* sseData(res, opts = {}) {
|
|
419
|
+
if (!res.body)
|
|
420
|
+
return;
|
|
421
|
+
const decoder = new TextDecoder();
|
|
422
|
+
let buf = "";
|
|
423
|
+
const reader = res.body.getReader();
|
|
424
|
+
const flush = function* (final) {
|
|
425
|
+
for (;;) {
|
|
426
|
+
const m = /\r?\n\r?\n/.exec(buf);
|
|
427
|
+
let block;
|
|
428
|
+
if (m) {
|
|
429
|
+
block = buf.slice(0, m.index);
|
|
430
|
+
buf = buf.slice(m.index + m[0].length);
|
|
431
|
+
}
|
|
432
|
+
else if (final && buf.trim()) {
|
|
433
|
+
block = buf;
|
|
434
|
+
buf = "";
|
|
435
|
+
}
|
|
436
|
+
else
|
|
437
|
+
return;
|
|
438
|
+
const data = block.split(/\r?\n/).filter((l) => l.startsWith("data:")).map((l) => l.slice(5).replace(/^ /, "")).join("\n");
|
|
439
|
+
if (data)
|
|
440
|
+
yield data;
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
const read = () => {
|
|
444
|
+
const idleMs = opts.idleMs;
|
|
445
|
+
if (!idleMs)
|
|
446
|
+
return reader.read();
|
|
447
|
+
let timer;
|
|
448
|
+
const idle = new Promise((_, reject) => {
|
|
449
|
+
timer = setTimeout(() => reject(new StreamTimeoutError(`the stream sent nothing for ${idleMs / 1000}s; it was cancelled`)), idleMs);
|
|
450
|
+
});
|
|
451
|
+
return Promise.race([reader.read(), idle]).finally(() => clearTimeout(timer));
|
|
452
|
+
};
|
|
453
|
+
try {
|
|
454
|
+
for (;;) {
|
|
455
|
+
const { done, value } = await read();
|
|
456
|
+
if (done)
|
|
457
|
+
break;
|
|
458
|
+
buf += decoder.decode(value, { stream: true });
|
|
459
|
+
yield* flush(false);
|
|
460
|
+
}
|
|
461
|
+
buf += decoder.decode();
|
|
462
|
+
yield* flush(true);
|
|
463
|
+
}
|
|
464
|
+
finally {
|
|
465
|
+
try {
|
|
466
|
+
await reader.cancel();
|
|
467
|
+
}
|
|
468
|
+
catch { /* already closed or errored */ }
|
|
469
|
+
try {
|
|
470
|
+
reader.releaseLock();
|
|
471
|
+
}
|
|
472
|
+
catch { /* a read may still be settling */ }
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
// ---------------------------------------------------------------------------
|
|
476
|
+
// Memories over the Router's native MCP surface (/v1/mcp/<server>), which
|
|
477
|
+
// authenticates btauth/1 exactly as the paid routes do. Stateless
|
|
478
|
+
// streamable-HTTP: every JSON-RPC message is its own signed POST.
|
|
479
|
+
const MCP_PROTOCOL_VERSION = "2025-06-18";
|
|
480
|
+
let rpcId = 0;
|
|
481
|
+
const MCP_SESSION_HEADER = "mcp-session-id";
|
|
482
|
+
function mcpHeaders(s) {
|
|
483
|
+
return {
|
|
484
|
+
accept: "application/json, text/event-stream",
|
|
485
|
+
"mcp-protocol-version": s.version,
|
|
486
|
+
...(s.sessionId ? { [MCP_SESSION_HEADER]: s.sessionId } : {}),
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
async function mcpNotify(c, s, method) {
|
|
490
|
+
await signedFetch(c, "POST", apiURL(c.discovery, `/v1/mcp/${encodeURIComponent(s.server)}`), { jsonrpc: "2.0", method }, mcpHeaders(s));
|
|
491
|
+
}
|
|
492
|
+
async function mcpCall(c, s, method, params) {
|
|
493
|
+
const id = ++rpcId;
|
|
494
|
+
const res = await signedFetch(c, "POST", apiURL(c.discovery, `/v1/mcp/${encodeURIComponent(s.server)}`), { jsonrpc: "2.0", id, method, params }, mcpHeaders(s));
|
|
495
|
+
if (method === "initialize") {
|
|
496
|
+
const assigned = res.headers.get(MCP_SESSION_HEADER)?.trim();
|
|
497
|
+
if (assigned) {
|
|
498
|
+
if (!/^[\x21-\x7e]{1,256}$/.test(assigned))
|
|
499
|
+
throw new Error("the MCP server assigned an invalid session id");
|
|
500
|
+
s.sessionId = assigned;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
const messages = [];
|
|
504
|
+
if ((res.headers.get("content-type") ?? "").includes("text/event-stream")) {
|
|
505
|
+
for await (const data of sseData(new Response(res.text))) {
|
|
506
|
+
try {
|
|
507
|
+
messages.push(JSON.parse(data));
|
|
508
|
+
}
|
|
509
|
+
catch { /* skip */ }
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
else if (res.text.trim()) {
|
|
513
|
+
const parsed = JSON.parse(res.text);
|
|
514
|
+
messages.push(...(Array.isArray(parsed) ? parsed : [parsed]));
|
|
515
|
+
}
|
|
516
|
+
const reply = messages.find((m) => m.id === id);
|
|
517
|
+
if (!reply)
|
|
518
|
+
throw new Error(`the MCP server answered ${method} with no result`);
|
|
519
|
+
if (reply.error)
|
|
520
|
+
throw new Error(`MCP ${method} failed: ${reply.error.message ?? `code ${reply.error.code}`}`);
|
|
521
|
+
return reply.result;
|
|
522
|
+
}
|
|
523
|
+
export const MEMORY_SEARCH_TOOL = "search_memories";
|
|
524
|
+
export class MemoryToolUnavailableError extends Error {
|
|
525
|
+
}
|
|
526
|
+
/** Searches the hotkey account's memories with the Router's memory search tool. */
|
|
527
|
+
export async function searchMemories(c, query, limit) {
|
|
528
|
+
// The full lifecycle: initialize, carry any Mcp-Session-Id it assigns, send
|
|
529
|
+
// notifications/initialized, then list and call. Every message is signed.
|
|
530
|
+
const session = { server: "ditto", version: MCP_PROTOCOL_VERSION };
|
|
531
|
+
const init = await mcpCall(c, session, "initialize", {
|
|
532
|
+
protocolVersion: MCP_PROTOCOL_VERSION, capabilities: {}, clientInfo: { name: "heyditto-gamma", version: "1" },
|
|
533
|
+
});
|
|
534
|
+
if (typeof init?.protocolVersion === "string" && init.protocolVersion)
|
|
535
|
+
session.version = init.protocolVersion;
|
|
536
|
+
await mcpNotify(c, session, "notifications/initialized");
|
|
537
|
+
const list = await mcpCall(c, session, "tools/list", {});
|
|
538
|
+
const tool = (list.tools ?? []).map((t) => t.name).find((n) => n === MEMORY_SEARCH_TOOL || n?.endsWith(`__${MEMORY_SEARCH_TOOL}`));
|
|
539
|
+
if (!tool) {
|
|
540
|
+
throw new MemoryToolUnavailableError("This hotkey account's Router endpoint does not offer memory search yet. Chats sent with `heyditto gamma chat` are kept in its session thread; memory search for hotkey accounts arrives with a server update.");
|
|
541
|
+
}
|
|
542
|
+
const args = { queries: [query] };
|
|
543
|
+
if (limit !== undefined)
|
|
544
|
+
args.limit = limit;
|
|
545
|
+
const result = await mcpCall(c, session, "tools/call", { name: tool, arguments: args });
|
|
546
|
+
const text = (result.content ?? []).filter((p) => p.type === "text" && typeof p.text === "string").map((p) => p.text).join("\n");
|
|
547
|
+
if (result.isError)
|
|
548
|
+
throw new Error(`memory search failed: ${text || "the tool reported an error"}`);
|
|
549
|
+
return { text, raw: result };
|
|
550
|
+
}
|
|
551
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/gamma/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAqB,WAAW,EAAE,MAAM,aAAa,CAAC;AAE7D,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAAC;AAChC,mEAAmE;AACnE,MAAM,CAAC,MAAM,oBAAoB,GAAG,iEAAiE,CAAC;AACtG,MAAM,CAAC,MAAM,cAAc,GAAG,oBAAoB,CAAC;AACnD,mEAAmE;AACnE,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAE3C,MAAM,eAAe,GAAG,2BAA2B,CAAC;AACpD,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAkBhC,MAAM,OAAO,cAAe,SAAQ,KAAK;IACD;IAAyB;IAAwB;IAAvF,YAAY,OAAe,EAAW,MAAc,EAAW,IAAa,EA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AI,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
/** The session every `gamma chat` turn joins unless told otherwise. */
|
|
3
|
+
export declare const DEFAULT_GAMMA_SESSION = "heyditto-gamma-cli";
|
|
4
|
+
export declare function registerGammaCommands(program: Command, addExamples: (cmd: Command, examples: string) => Command): void;
|