@heyditto/cli 3.22.3 → 3.23.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/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/update-lock.json +1 -1
- package/package.json +4 -1
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { type HotkeySigner } from "./btauth.js";
|
|
2
|
+
export declare const SN118_NETUID = 118;
|
|
3
|
+
/** The services document Ditto's SN118 `set_service` points at. */
|
|
4
|
+
export declare const DEFAULT_SERVICES_URL = "https://api.heyditto.ai/api/v5/chain-gamma/public/services.json";
|
|
5
|
+
export declare const SESSION_HEADER = "X-Ditto-Session-Id";
|
|
6
|
+
/** Exit status when the hotkey's balance cannot pay (HTTP 402). */
|
|
7
|
+
export declare const EXIT_INSUFFICIENT_BALANCE = 3;
|
|
8
|
+
export interface Discovery {
|
|
9
|
+
servicesUrl: string;
|
|
10
|
+
netuid: number;
|
|
11
|
+
name?: string;
|
|
12
|
+
publishers: string[];
|
|
13
|
+
/** The publisher hotkey requests are signed for. */
|
|
14
|
+
receiver: string;
|
|
15
|
+
openapiUrl: string;
|
|
16
|
+
apiBase: string;
|
|
17
|
+
balanceUrl: string;
|
|
18
|
+
pricingUrl?: string;
|
|
19
|
+
paths: string[];
|
|
20
|
+
/** The user passed --allow-untrusted-origin: hosts outside heyditto.ai may be signed for. */
|
|
21
|
+
allowUntrustedOrigin: boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare class GammaHTTPError extends Error {
|
|
24
|
+
readonly status: number;
|
|
25
|
+
readonly code?: string | undefined;
|
|
26
|
+
readonly exitCode: number;
|
|
27
|
+
constructor(message: string, status: number, code?: string | undefined, exitCode?: number);
|
|
28
|
+
}
|
|
29
|
+
/** HTTP 402: the hotkey's balance is empty or the hotkey has never spent gamma here. */
|
|
30
|
+
export declare class InsufficientBalanceError extends GammaHTTPError {
|
|
31
|
+
readonly serverMessage: string;
|
|
32
|
+
constructor(message: string, serverMessage: string);
|
|
33
|
+
}
|
|
34
|
+
/** Discovered URLs must be https (plain http only for a loopback test server). */
|
|
35
|
+
export declare function checkedURL(raw: unknown, what: string, base?: string): URL;
|
|
36
|
+
export interface DiscoverOptions {
|
|
37
|
+
servicesUrl?: string;
|
|
38
|
+
netuid?: number;
|
|
39
|
+
/** A specific publisher hotkey to sign for; it must be listed. */
|
|
40
|
+
receiver?: string;
|
|
41
|
+
/** Allow signing for (and reading balances from) hosts outside heyditto.ai. */
|
|
42
|
+
allowUntrustedOrigin?: boolean;
|
|
43
|
+
}
|
|
44
|
+
/** Env var equivalent of --allow-untrusted-origin. */
|
|
45
|
+
export declare const ALLOW_UNTRUSTED_ORIGIN_ENV = "DITTO_GAMMA_ALLOW_UNTRUSTED_ORIGIN";
|
|
46
|
+
/** The only origins requests are signed for by default: https heyditto.ai and its subdomains. */
|
|
47
|
+
export declare function isTrustedOrigin(url: URL | string): boolean;
|
|
48
|
+
export declare class UntrustedOriginError extends Error {
|
|
49
|
+
}
|
|
50
|
+
/** Fetches and validates the services document and the OpenAPI spec it links. */
|
|
51
|
+
export declare function discover(o?: DiscoverOptions, env?: NodeJS.ProcessEnv): Promise<Discovery>;
|
|
52
|
+
export interface Balance {
|
|
53
|
+
hotkey: string;
|
|
54
|
+
credited_usd: string;
|
|
55
|
+
used_usd: string;
|
|
56
|
+
remaining_usd: string;
|
|
57
|
+
}
|
|
58
|
+
/** GET <balance>?hotkey=<ss58>. Public; an unknown hotkey answers zeros. */
|
|
59
|
+
export declare function fetchBalance(d: Discovery, hotkey: string): Promise<Balance>;
|
|
60
|
+
/** The btcli commands that fund a hotkey at Ditto. */
|
|
61
|
+
export declare function fundingHelp(d: Pick<Discovery, "netuid" | "receiver">, hotkeyName: string): string;
|
|
62
|
+
export interface SignedClient {
|
|
63
|
+
discovery: Discovery;
|
|
64
|
+
signer: HotkeySigner;
|
|
65
|
+
/** The btcli hotkey name for hints (falls back to the SS58). */
|
|
66
|
+
hotkeyName: string;
|
|
67
|
+
}
|
|
68
|
+
export interface SignedResponse {
|
|
69
|
+
status: number;
|
|
70
|
+
headers: Headers;
|
|
71
|
+
text: string;
|
|
72
|
+
body?: Response;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* One btauth/1-signed request. Signs the exact bytes sent with a fresh nonce;
|
|
76
|
+
* a caller that retries calls this again, so every attempt is re-signed.
|
|
77
|
+
*/
|
|
78
|
+
export declare function signedFetch(c: SignedClient, method: string, url: URL, body?: unknown, extra?: Record<string, string>, stream?: boolean, signal?: AbortSignal): Promise<SignedResponse>;
|
|
79
|
+
export declare function apiURL(d: Discovery, pathname: string): URL;
|
|
80
|
+
/** Signed GET /v1/models. */
|
|
81
|
+
export declare function listModels(c: SignedClient): Promise<{
|
|
82
|
+
raw: unknown;
|
|
83
|
+
ids: string[];
|
|
84
|
+
}>;
|
|
85
|
+
/** The pricing document's default model, the model a request should name when the user named none. */
|
|
86
|
+
export declare function defaultModel(d: Discovery): Promise<string | undefined>;
|
|
87
|
+
export declare function validSessionId(id: string): boolean;
|
|
88
|
+
/** A streamed answer may take this long in all (15 minutes) by default. */
|
|
89
|
+
export declare const DEFAULT_STREAM_TOTAL_MS = 900000;
|
|
90
|
+
/** A streamed answer may go this long without a byte (2 minutes) by default. */
|
|
91
|
+
export declare const DEFAULT_STREAM_IDLE_MS = 120000;
|
|
92
|
+
export interface StreamLimits {
|
|
93
|
+
totalMs: number;
|
|
94
|
+
idleMs: number;
|
|
95
|
+
}
|
|
96
|
+
/** Node's setTimeout maximum; a longer delay silently fires after 1 ms. */
|
|
97
|
+
export declare const MAX_TIMER_MS = 2147483647;
|
|
98
|
+
/** Throws unless ms is a whole number of milliseconds a timer can hold (1 to MAX_TIMER_MS). */
|
|
99
|
+
export declare function checkTimerMs(ms: number, what: string): number;
|
|
100
|
+
/**
|
|
101
|
+
* A timer limit given in `unit` (1 for milliseconds, 1000 for seconds), as
|
|
102
|
+
* whole milliseconds. A value below 1 ms or above the timer maximum is an
|
|
103
|
+
* error rather than a silent 0 or overflow.
|
|
104
|
+
*/
|
|
105
|
+
export declare function parseTimerLimit(raw: string, unitMs: number, what: string): number;
|
|
106
|
+
/** Stream limits from DITTO_GAMMA_STREAM_TIMEOUT_MS and DITTO_GAMMA_STREAM_IDLE_MS, or the defaults. */
|
|
107
|
+
export declare function streamLimits(env?: NodeJS.ProcessEnv): StreamLimits;
|
|
108
|
+
export declare class StreamTimeoutError extends Error {
|
|
109
|
+
}
|
|
110
|
+
export interface ChatOptions {
|
|
111
|
+
model: string;
|
|
112
|
+
prompt: string;
|
|
113
|
+
session: string;
|
|
114
|
+
stream: boolean;
|
|
115
|
+
/** Overall and between-chunk limits for a streamed answer (default: streamLimits()). */
|
|
116
|
+
limits?: StreamLimits;
|
|
117
|
+
/** Receives streamed text as it arrives. */
|
|
118
|
+
onDelta?: (text: string) => void;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Signed POST /v1/chat/completions. The session header groups turns into one
|
|
122
|
+
* thread of the hotkey account, so repeated chats build that account's history.
|
|
123
|
+
*/
|
|
124
|
+
export declare function chat(c: SignedClient, o: ChatOptions): Promise<{
|
|
125
|
+
text: string;
|
|
126
|
+
raw?: unknown;
|
|
127
|
+
model?: string;
|
|
128
|
+
}>;
|
|
129
|
+
/**
|
|
130
|
+
* Yields each SSE event's joined `data:` lines. When the consumer stops early
|
|
131
|
+
* (a `[DONE]`, an error, a timeout) the body is cancelled, so an SSE response
|
|
132
|
+
* the server leaves open never keeps the request alive. `idleMs` bounds the
|
|
133
|
+
* wait for each chunk.
|
|
134
|
+
*/
|
|
135
|
+
export declare function sseData(res: Response, opts?: {
|
|
136
|
+
idleMs?: number;
|
|
137
|
+
}): AsyncGenerator<string>;
|
|
138
|
+
export declare const MEMORY_SEARCH_TOOL = "search_memories";
|
|
139
|
+
export declare class MemoryToolUnavailableError extends Error {
|
|
140
|
+
}
|
|
141
|
+
/** Searches the hotkey account's memories with the Router's memory search tool. */
|
|
142
|
+
export declare function searchMemories(c: SignedClient, query: string, limit?: number): Promise<{
|
|
143
|
+
text: string;
|
|
144
|
+
raw: unknown;
|
|
145
|
+
}>;
|