@tangle-network/tcloud 0.1.3 → 0.2.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 +69 -10
- package/dist/chunk-HL4CXKET.js +976 -0
- package/dist/{chunk-G5LUZZKT.js → chunk-STNZT6YR.js} +4 -2
- package/dist/chunk-VD4RNZOC.js +263 -0
- package/dist/cli.cjs +671 -98
- package/dist/cli.js +3 -2
- package/dist/client-CcuHG7_w.d.cts +728 -0
- package/dist/client-CcuHG7_w.d.ts +728 -0
- package/dist/index.cjs +673 -98
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +8 -4
- package/dist/instance.cjs +1235 -0
- package/dist/instance.d.cts +110 -0
- package/dist/instance.d.ts +110 -0
- package/dist/instance.js +229 -0
- package/dist/shielded.cjs +671 -98
- package/dist/shielded.d.cts +61 -2
- package/dist/shielded.d.ts +61 -2
- package/dist/shielded.js +2 -1
- package/package.json +14 -2
- package/dist/chunk-YKLHAS4E.js +0 -661
- package/dist/shielded-xDNVqK4a.d.cts +0 -404
- package/dist/shielded-xDNVqK4a.d.ts +0 -404
|
@@ -0,0 +1,728 @@
|
|
|
1
|
+
/** Core types for the tcloud SDK */
|
|
2
|
+
interface TCloudConfig {
|
|
3
|
+
/** API base URL (default: https://router.tangle.tools/v1) */
|
|
4
|
+
baseURL?: string;
|
|
5
|
+
/** API key for standard (non-private) mode */
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
/** Default model */
|
|
8
|
+
model?: string;
|
|
9
|
+
/** Operator routing preferences */
|
|
10
|
+
routing?: RoutingConfig;
|
|
11
|
+
/** Enable shielded (private) mode */
|
|
12
|
+
shielded?: ShieldedConfig | boolean;
|
|
13
|
+
/** Privacy proxy configuration for IP hiding */
|
|
14
|
+
privacy?: PrivacyConfig;
|
|
15
|
+
/** Spending limits and metering */
|
|
16
|
+
limits?: SpendingLimits;
|
|
17
|
+
/** Retry configuration for transient failures */
|
|
18
|
+
retry?: RetryConfig | false;
|
|
19
|
+
/** Default request timeout in ms (default: 60000). Set 0 to disable. */
|
|
20
|
+
timeout?: number;
|
|
21
|
+
}
|
|
22
|
+
interface RetryConfig {
|
|
23
|
+
/** Max retry attempts (default: 3) */
|
|
24
|
+
maxRetries?: number;
|
|
25
|
+
/** Initial backoff in ms (default: 500) */
|
|
26
|
+
initialBackoffMs?: number;
|
|
27
|
+
/** Max backoff in ms (default: 30000) */
|
|
28
|
+
maxBackoffMs?: number;
|
|
29
|
+
/** Backoff multiplier (default: 2) */
|
|
30
|
+
multiplier?: number;
|
|
31
|
+
/** HTTP status codes that trigger retry (default: [429, 500, 502, 503, 504]) */
|
|
32
|
+
retryableStatuses?: number[];
|
|
33
|
+
}
|
|
34
|
+
interface SpendingLimits {
|
|
35
|
+
/** Max USD to spend per request. Rejects if estimated cost exceeds this. */
|
|
36
|
+
maxCostPerRequest?: number;
|
|
37
|
+
/** Max USD to spend across all requests in this client's lifetime. Stops at limit. */
|
|
38
|
+
maxTotalSpend?: number;
|
|
39
|
+
/** Max requests allowed. Stops at limit. */
|
|
40
|
+
maxRequests?: number;
|
|
41
|
+
/** Callback when a limit is approached (80% threshold) */
|
|
42
|
+
onLimitWarning?: (info: {
|
|
43
|
+
type: 'cost' | 'total' | 'requests';
|
|
44
|
+
current: number;
|
|
45
|
+
limit: number;
|
|
46
|
+
}) => void;
|
|
47
|
+
/** Callback when a limit is hit (request blocked) */
|
|
48
|
+
onLimitReached?: (info: {
|
|
49
|
+
type: 'cost' | 'total' | 'requests';
|
|
50
|
+
current: number;
|
|
51
|
+
limit: number;
|
|
52
|
+
}) => void;
|
|
53
|
+
}
|
|
54
|
+
interface RoutingConfig {
|
|
55
|
+
/** Routing mode: 'operator' (Tangle operators only), 'provider' (direct APIs only), 'auto' (try operators, fall back to providers) */
|
|
56
|
+
mode?: 'operator' | 'provider' | 'auto';
|
|
57
|
+
/** Preferred operator slug or address */
|
|
58
|
+
prefer?: string;
|
|
59
|
+
/** Blueprint ID — route to operators under this Blueprint */
|
|
60
|
+
blueprintId?: string;
|
|
61
|
+
/** Service instance ID — route to a specific service instance */
|
|
62
|
+
serviceId?: string;
|
|
63
|
+
/** Routing strategy */
|
|
64
|
+
strategy?: 'lowest-latency' | 'lowest-price' | 'highest-reputation' | 'round-robin';
|
|
65
|
+
/** Region filter */
|
|
66
|
+
region?: string;
|
|
67
|
+
/** Fallback operator slugs (tried in order) */
|
|
68
|
+
fallback?: string[];
|
|
69
|
+
}
|
|
70
|
+
interface EmbeddingOptions {
|
|
71
|
+
model?: string;
|
|
72
|
+
input: string | string[];
|
|
73
|
+
}
|
|
74
|
+
interface EmbeddingResponse {
|
|
75
|
+
object: string;
|
|
76
|
+
data: {
|
|
77
|
+
object: string;
|
|
78
|
+
embedding: number[];
|
|
79
|
+
index: number;
|
|
80
|
+
}[];
|
|
81
|
+
model: string;
|
|
82
|
+
usage: {
|
|
83
|
+
prompt_tokens: number;
|
|
84
|
+
total_tokens: number;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
interface ImageGenerateOptions {
|
|
88
|
+
model?: string;
|
|
89
|
+
prompt: string;
|
|
90
|
+
n?: number;
|
|
91
|
+
size?: string;
|
|
92
|
+
quality?: string;
|
|
93
|
+
response_format?: 'url' | 'b64_json';
|
|
94
|
+
}
|
|
95
|
+
interface ImageResponse {
|
|
96
|
+
created: number;
|
|
97
|
+
data: {
|
|
98
|
+
url?: string;
|
|
99
|
+
b64_json?: string;
|
|
100
|
+
revised_prompt?: string;
|
|
101
|
+
}[];
|
|
102
|
+
}
|
|
103
|
+
interface RerankOptions {
|
|
104
|
+
model?: string;
|
|
105
|
+
query: string;
|
|
106
|
+
documents: string[];
|
|
107
|
+
top_n?: number;
|
|
108
|
+
}
|
|
109
|
+
interface RerankResponse {
|
|
110
|
+
results: {
|
|
111
|
+
index: number;
|
|
112
|
+
relevance_score: number;
|
|
113
|
+
}[];
|
|
114
|
+
}
|
|
115
|
+
interface CompletionOptions {
|
|
116
|
+
model?: string;
|
|
117
|
+
prompt: string;
|
|
118
|
+
temperature?: number;
|
|
119
|
+
maxTokens?: number;
|
|
120
|
+
stop?: string | string[];
|
|
121
|
+
topP?: number;
|
|
122
|
+
}
|
|
123
|
+
interface CompletionResponse {
|
|
124
|
+
id: string;
|
|
125
|
+
object: string;
|
|
126
|
+
created: number;
|
|
127
|
+
model: string;
|
|
128
|
+
choices: {
|
|
129
|
+
text: string;
|
|
130
|
+
index: number;
|
|
131
|
+
finish_reason: string;
|
|
132
|
+
}[];
|
|
133
|
+
usage?: {
|
|
134
|
+
prompt_tokens: number;
|
|
135
|
+
completion_tokens: number;
|
|
136
|
+
total_tokens: number;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
interface TranscriptionResponse {
|
|
140
|
+
text: string;
|
|
141
|
+
}
|
|
142
|
+
interface FineTuningJobOptions {
|
|
143
|
+
model: string;
|
|
144
|
+
training_file: string;
|
|
145
|
+
hyperparameters?: {
|
|
146
|
+
n_epochs?: number | 'auto';
|
|
147
|
+
batch_size?: number | 'auto';
|
|
148
|
+
learning_rate_multiplier?: number | 'auto';
|
|
149
|
+
};
|
|
150
|
+
suffix?: string;
|
|
151
|
+
}
|
|
152
|
+
interface FineTuningJob {
|
|
153
|
+
id: string;
|
|
154
|
+
object: string;
|
|
155
|
+
model: string;
|
|
156
|
+
status: string;
|
|
157
|
+
created_at: number;
|
|
158
|
+
finished_at: number | null;
|
|
159
|
+
fine_tuned_model: string | null;
|
|
160
|
+
error: {
|
|
161
|
+
code: string;
|
|
162
|
+
message: string;
|
|
163
|
+
} | null;
|
|
164
|
+
}
|
|
165
|
+
interface BatchRequest {
|
|
166
|
+
model: string;
|
|
167
|
+
messages: ChatMessage[];
|
|
168
|
+
temperature?: number;
|
|
169
|
+
max_tokens?: number;
|
|
170
|
+
}
|
|
171
|
+
interface BatchJobResponse {
|
|
172
|
+
id: string;
|
|
173
|
+
status: 'pending' | 'processing' | 'completed' | 'failed';
|
|
174
|
+
total_items: number;
|
|
175
|
+
completed: number;
|
|
176
|
+
failed: number;
|
|
177
|
+
results: ({
|
|
178
|
+
status: 'fulfilled';
|
|
179
|
+
data: ChatCompletion;
|
|
180
|
+
} | {
|
|
181
|
+
status: 'rejected';
|
|
182
|
+
error: string;
|
|
183
|
+
})[] | null;
|
|
184
|
+
error: string | null;
|
|
185
|
+
created_at: string;
|
|
186
|
+
completed_at: string | null;
|
|
187
|
+
}
|
|
188
|
+
interface VideoGenerateOptions {
|
|
189
|
+
model?: string;
|
|
190
|
+
prompt: string;
|
|
191
|
+
duration?: number;
|
|
192
|
+
resolution?: string;
|
|
193
|
+
}
|
|
194
|
+
interface VideoResponse {
|
|
195
|
+
id: string;
|
|
196
|
+
status: string;
|
|
197
|
+
url?: string;
|
|
198
|
+
error?: string;
|
|
199
|
+
}
|
|
200
|
+
/** Request body for POST /v1/avatar/generate */
|
|
201
|
+
interface AvatarGenerateRequest {
|
|
202
|
+
/** URL to narration audio (wav/mp3) */
|
|
203
|
+
audio_url: string;
|
|
204
|
+
/** URL to face image, OR omit and use avatar_id */
|
|
205
|
+
image_url?: string;
|
|
206
|
+
/** Preset avatar identifier (provider-specific) */
|
|
207
|
+
avatar_id?: string;
|
|
208
|
+
/** Target duration in seconds (capped by operator's max_duration_seconds) */
|
|
209
|
+
duration_seconds?: number;
|
|
210
|
+
/** Output format (default: "mp4") */
|
|
211
|
+
output_format?: string;
|
|
212
|
+
}
|
|
213
|
+
/** Response from POST /v1/avatar/generate (202 Accepted) */
|
|
214
|
+
interface AvatarGenerateResponse {
|
|
215
|
+
job_id: string;
|
|
216
|
+
status: 'queued' | 'processing' | 'completed' | 'failed';
|
|
217
|
+
result?: AvatarResult;
|
|
218
|
+
error?: string;
|
|
219
|
+
}
|
|
220
|
+
/** Result payload within a completed avatar job */
|
|
221
|
+
interface AvatarResult {
|
|
222
|
+
video_url: string;
|
|
223
|
+
duration_seconds: number;
|
|
224
|
+
format: string;
|
|
225
|
+
}
|
|
226
|
+
/** Response from GET /v1/avatar/jobs/:id */
|
|
227
|
+
interface AvatarJobStatus {
|
|
228
|
+
job_id: string;
|
|
229
|
+
status: 'queued' | 'processing' | 'completed' | 'failed';
|
|
230
|
+
result?: AvatarResult;
|
|
231
|
+
error?: string;
|
|
232
|
+
}
|
|
233
|
+
interface PrivacyConfig {
|
|
234
|
+
/** 'direct' — no proxy (default). 'relayer' — route through tcloud-relayer. 'socks5' — route through SOCKS5 proxy (e.g. Tor). */
|
|
235
|
+
mode: 'direct' | 'relayer' | 'socks5';
|
|
236
|
+
/** Relayer URL for 'relayer' mode (e.g. 'http://localhost:3030') */
|
|
237
|
+
relayerUrl?: string;
|
|
238
|
+
/**
|
|
239
|
+
* SOCKS5 proxy URL for 'socks5' mode (e.g. 'socks5://127.0.0.1:9050' for Tor).
|
|
240
|
+
* Requires `socks-proxy-agent` as an optional peer dependency.
|
|
241
|
+
*/
|
|
242
|
+
socksProxy?: string;
|
|
243
|
+
}
|
|
244
|
+
interface ShieldedConfig {
|
|
245
|
+
/** Pre-existing spending private key (hex). If not set, generates ephemeral. */
|
|
246
|
+
spendingKey?: string;
|
|
247
|
+
/** Pre-existing commitment. If not set, derives from key. */
|
|
248
|
+
commitment?: string;
|
|
249
|
+
/** Chain ID (default: 3799 for Tangle testnet) */
|
|
250
|
+
chainId?: number;
|
|
251
|
+
/** ShieldedCredits contract address */
|
|
252
|
+
creditsAddress?: string;
|
|
253
|
+
/** Service ID for the blueprint */
|
|
254
|
+
serviceId?: bigint;
|
|
255
|
+
/** Privacy proxy configuration for IP hiding */
|
|
256
|
+
privacy?: PrivacyConfig;
|
|
257
|
+
}
|
|
258
|
+
interface ChatMessage {
|
|
259
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
260
|
+
content: string;
|
|
261
|
+
name?: string;
|
|
262
|
+
}
|
|
263
|
+
interface ChatOptions {
|
|
264
|
+
/** Model to use */
|
|
265
|
+
model?: string;
|
|
266
|
+
/** Messages */
|
|
267
|
+
messages: ChatMessage[];
|
|
268
|
+
/** Temperature (0-2) */
|
|
269
|
+
temperature?: number;
|
|
270
|
+
/** Max tokens to generate */
|
|
271
|
+
maxTokens?: number;
|
|
272
|
+
/** Stream response */
|
|
273
|
+
stream?: boolean;
|
|
274
|
+
/** Stop sequences */
|
|
275
|
+
stop?: string | string[];
|
|
276
|
+
/** Top-p sampling */
|
|
277
|
+
topP?: number;
|
|
278
|
+
/** Frequency penalty */
|
|
279
|
+
frequencyPenalty?: number;
|
|
280
|
+
/** Presence penalty */
|
|
281
|
+
presencePenalty?: number;
|
|
282
|
+
/** JSON mode */
|
|
283
|
+
responseFormat?: {
|
|
284
|
+
type: 'text' | 'json_object';
|
|
285
|
+
};
|
|
286
|
+
/** Tools / function calling */
|
|
287
|
+
tools?: any[];
|
|
288
|
+
/** Tool choice strategy or specific tool */
|
|
289
|
+
toolChoice?: 'none' | 'auto' | 'required' | {
|
|
290
|
+
type: 'function';
|
|
291
|
+
function: {
|
|
292
|
+
name: string;
|
|
293
|
+
};
|
|
294
|
+
};
|
|
295
|
+
/**
|
|
296
|
+
* Provider-specific parameters passed through to the upstream API.
|
|
297
|
+
* These are spread into the request body alongside standard fields.
|
|
298
|
+
* Example: `{ thinking: { type: 'enabled', budget_tokens: 8000 } }`
|
|
299
|
+
*/
|
|
300
|
+
providerOptions?: Record<string, unknown>;
|
|
301
|
+
}
|
|
302
|
+
interface ChatCompletion {
|
|
303
|
+
id: string;
|
|
304
|
+
object: string;
|
|
305
|
+
created: number;
|
|
306
|
+
model: string;
|
|
307
|
+
choices: {
|
|
308
|
+
index: number;
|
|
309
|
+
message: ChatMessage;
|
|
310
|
+
finish_reason: string;
|
|
311
|
+
}[];
|
|
312
|
+
usage?: {
|
|
313
|
+
prompt_tokens: number;
|
|
314
|
+
completion_tokens: number;
|
|
315
|
+
total_tokens: number;
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
interface ChatCompletionChunk {
|
|
319
|
+
id: string;
|
|
320
|
+
object: string;
|
|
321
|
+
created: number;
|
|
322
|
+
model: string;
|
|
323
|
+
choices: {
|
|
324
|
+
index: number;
|
|
325
|
+
delta: Partial<ChatMessage>;
|
|
326
|
+
finish_reason: string | null;
|
|
327
|
+
}[];
|
|
328
|
+
}
|
|
329
|
+
interface Model {
|
|
330
|
+
id: string;
|
|
331
|
+
name: string;
|
|
332
|
+
description?: string;
|
|
333
|
+
context_length: number;
|
|
334
|
+
pricing: {
|
|
335
|
+
prompt: string;
|
|
336
|
+
completion: string;
|
|
337
|
+
};
|
|
338
|
+
_provider?: string;
|
|
339
|
+
architecture?: {
|
|
340
|
+
input_modalities?: string[];
|
|
341
|
+
output_modalities?: string[];
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
interface Operator {
|
|
345
|
+
id: string;
|
|
346
|
+
slug: string;
|
|
347
|
+
name: string;
|
|
348
|
+
description?: string;
|
|
349
|
+
status: string;
|
|
350
|
+
endpointUrl: string;
|
|
351
|
+
blueprintType: string;
|
|
352
|
+
reputationScore: number;
|
|
353
|
+
uptimePercent: number;
|
|
354
|
+
avgLatencyMs: number;
|
|
355
|
+
totalRequests: number;
|
|
356
|
+
stakeTnt: number;
|
|
357
|
+
/** GPU model name (e.g. "A100", "H100") */
|
|
358
|
+
gpuModel?: string;
|
|
359
|
+
/** Number of GPUs available */
|
|
360
|
+
gpuCount?: number;
|
|
361
|
+
/** Total VRAM across all GPUs in MiB */
|
|
362
|
+
totalVramMib?: number;
|
|
363
|
+
/** Whether this operator is TEE-attested */
|
|
364
|
+
teeAttested?: boolean;
|
|
365
|
+
/** TEE provider if attested (e.g. "aws_nitro") */
|
|
366
|
+
teeProvider?: string;
|
|
367
|
+
models: {
|
|
368
|
+
modelId: string;
|
|
369
|
+
inputPrice: number;
|
|
370
|
+
outputPrice: number;
|
|
371
|
+
}[];
|
|
372
|
+
}
|
|
373
|
+
interface CreditBalance {
|
|
374
|
+
balance: number;
|
|
375
|
+
transactions: {
|
|
376
|
+
id: string;
|
|
377
|
+
amount: number;
|
|
378
|
+
type: string;
|
|
379
|
+
description: string;
|
|
380
|
+
createdAt: string;
|
|
381
|
+
}[];
|
|
382
|
+
}
|
|
383
|
+
/** Status event from an async job SSE stream */
|
|
384
|
+
interface JobEvent {
|
|
385
|
+
status: 'queued' | 'processing' | 'completed' | 'failed' | 'cancelled';
|
|
386
|
+
progress?: number;
|
|
387
|
+
result?: Record<string, unknown>;
|
|
388
|
+
error?: string;
|
|
389
|
+
timestamp: number;
|
|
390
|
+
}
|
|
391
|
+
/** Options for watchJob() */
|
|
392
|
+
interface WatchJobOptions {
|
|
393
|
+
/** Operator endpoint URL (if not using default routing) */
|
|
394
|
+
operatorUrl?: string;
|
|
395
|
+
/** Callback for each event (useful for progress tracking) */
|
|
396
|
+
onEvent?: (event: JobEvent) => void;
|
|
397
|
+
/** Timeout in ms (default: 5 minutes) */
|
|
398
|
+
timeout?: number;
|
|
399
|
+
/** Model to route to (for operator discovery) */
|
|
400
|
+
model?: string;
|
|
401
|
+
/** SSE bearer token (replaces API key for operator SSE auth) */
|
|
402
|
+
sseToken?: string;
|
|
403
|
+
}
|
|
404
|
+
interface SpendAuth {
|
|
405
|
+
commitment: string;
|
|
406
|
+
serviceId: string;
|
|
407
|
+
jobIndex: number;
|
|
408
|
+
amount: string;
|
|
409
|
+
operator: string;
|
|
410
|
+
nonce: string;
|
|
411
|
+
expiry: string;
|
|
412
|
+
signature: string;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Private Router — operator rotation strategies for privacy-preserving inference.
|
|
417
|
+
*
|
|
418
|
+
* Each strategy determines how requests are distributed across operators
|
|
419
|
+
* to minimize the information any single operator can gather about a user's
|
|
420
|
+
* conversation patterns.
|
|
421
|
+
*/
|
|
422
|
+
interface OperatorInfo {
|
|
423
|
+
slug: string;
|
|
424
|
+
endpointUrl: string;
|
|
425
|
+
region: string;
|
|
426
|
+
reputationScore: number;
|
|
427
|
+
avgLatencyMs: number;
|
|
428
|
+
models: string[];
|
|
429
|
+
}
|
|
430
|
+
type RoutingStrategy = 'round-robin' | 'random' | 'geo-distributed' | 'min-exposure' | 'latency-aware';
|
|
431
|
+
interface PrivateRouterConfig {
|
|
432
|
+
strategy: RoutingStrategy;
|
|
433
|
+
/** Max requests to same operator before forced rotation */
|
|
434
|
+
maxRequestsPerOperator: number;
|
|
435
|
+
/** Minimum number of distinct operators to use */
|
|
436
|
+
minOperators: number;
|
|
437
|
+
/** Region preferences (operators in these regions preferred) */
|
|
438
|
+
preferRegions?: string[];
|
|
439
|
+
/** Exclude specific operators */
|
|
440
|
+
excludeOperators?: string[];
|
|
441
|
+
/** Enable context summarization between operator switches (reduces info leakage) */
|
|
442
|
+
summarizeOnSwitch: boolean;
|
|
443
|
+
}
|
|
444
|
+
declare class PrivateRouter {
|
|
445
|
+
private config;
|
|
446
|
+
private operators;
|
|
447
|
+
private usage;
|
|
448
|
+
private currentIndex;
|
|
449
|
+
private totalRequests;
|
|
450
|
+
constructor(config?: Partial<PrivateRouterConfig>);
|
|
451
|
+
/** Set the available operator pool */
|
|
452
|
+
setOperators(operators: OperatorInfo[]): void;
|
|
453
|
+
/** Select the next operator for a request */
|
|
454
|
+
selectOperator(model: string): OperatorInfo | null;
|
|
455
|
+
/** Should we summarize context before this request? (operator is changing) */
|
|
456
|
+
shouldSummarize(model: string): boolean;
|
|
457
|
+
/** Get privacy stats */
|
|
458
|
+
getStats(): {
|
|
459
|
+
totalRequests: number;
|
|
460
|
+
operatorsUsed: number;
|
|
461
|
+
operatorBreakdown: {
|
|
462
|
+
slug: string;
|
|
463
|
+
requests: number;
|
|
464
|
+
lastUsed: number;
|
|
465
|
+
}[];
|
|
466
|
+
strategy: RoutingStrategy;
|
|
467
|
+
};
|
|
468
|
+
private roundRobin;
|
|
469
|
+
private random;
|
|
470
|
+
private geoDistributed;
|
|
471
|
+
private minExposure;
|
|
472
|
+
private latencyAware;
|
|
473
|
+
private recordUsage;
|
|
474
|
+
private getLastUsedOperator;
|
|
475
|
+
private peekNextOperator;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Core HTTP client for Tangle AI Cloud.
|
|
480
|
+
* Shared between CLI and SDK.
|
|
481
|
+
*/
|
|
482
|
+
|
|
483
|
+
declare class TCloudClient {
|
|
484
|
+
readonly baseURL: string;
|
|
485
|
+
readonly apiKey?: string;
|
|
486
|
+
readonly model: string;
|
|
487
|
+
private headers;
|
|
488
|
+
private spendAuthFn?;
|
|
489
|
+
private privacy?;
|
|
490
|
+
private limits?;
|
|
491
|
+
private retryConfig;
|
|
492
|
+
private timeoutMs;
|
|
493
|
+
private _totalSpent;
|
|
494
|
+
private _requestCount;
|
|
495
|
+
readonly privateRouter?: PrivateRouter;
|
|
496
|
+
private _cachedOperators;
|
|
497
|
+
private _operatorsCachedAt;
|
|
498
|
+
private static readonly OPERATORS_TTL_MS;
|
|
499
|
+
constructor(config?: TCloudConfig);
|
|
500
|
+
/** Set the SpendAuth signer for private mode */
|
|
501
|
+
setSpendAuthSigner(fn: () => Promise<SpendAuth>): void;
|
|
502
|
+
/** Current metering stats */
|
|
503
|
+
get usage(): {
|
|
504
|
+
totalSpent: number;
|
|
505
|
+
requestCount: number;
|
|
506
|
+
limits: {
|
|
507
|
+
maxCostPerRequest?: number;
|
|
508
|
+
maxTotalSpend?: number;
|
|
509
|
+
maxRequests?: number;
|
|
510
|
+
onLimitWarning?: (info: {
|
|
511
|
+
type: "cost" | "total" | "requests";
|
|
512
|
+
current: number;
|
|
513
|
+
limit: number;
|
|
514
|
+
}) => void;
|
|
515
|
+
onLimitReached?: (info: {
|
|
516
|
+
type: "cost" | "total" | "requests";
|
|
517
|
+
current: number;
|
|
518
|
+
limit: number;
|
|
519
|
+
}) => void;
|
|
520
|
+
} | undefined;
|
|
521
|
+
};
|
|
522
|
+
/** Check spending limits before a request. Throws TCloudError if blocked. */
|
|
523
|
+
private checkLimits;
|
|
524
|
+
/** Ensure the private router has operators loaded (with TTL-based caching) */
|
|
525
|
+
private ensureRouterOperators;
|
|
526
|
+
/** Track cost after a response, using actual pricing from response headers when available */
|
|
527
|
+
private trackCost;
|
|
528
|
+
/**
|
|
529
|
+
* Core fetch with retry + timeout. All helpers build on this.
|
|
530
|
+
* Retries on retryable status codes with exponential backoff + jitter.
|
|
531
|
+
*/
|
|
532
|
+
private _doFetch;
|
|
533
|
+
/**
|
|
534
|
+
* Shared request helper for billable JSON API calls.
|
|
535
|
+
* Enforces: checkLimits → fetch with retry/timeout → error parsing → requestCount.
|
|
536
|
+
*/
|
|
537
|
+
private _request;
|
|
538
|
+
/**
|
|
539
|
+
* Shared request helper for read-only/non-billable JSON API calls.
|
|
540
|
+
* No limits check, no request counting.
|
|
541
|
+
*/
|
|
542
|
+
private _fetch;
|
|
543
|
+
/**
|
|
544
|
+
* Shared request helper for billable calls that return non-JSON (e.g. ArrayBuffer).
|
|
545
|
+
*/
|
|
546
|
+
private _requestRaw;
|
|
547
|
+
/**
|
|
548
|
+
* Prepare headers for chat requests — operator routing + SpendAuth.
|
|
549
|
+
* Shared between chat() and chatStream() to eliminate duplication.
|
|
550
|
+
*/
|
|
551
|
+
private _prepareChatRequest;
|
|
552
|
+
/** Build the chat completions request body */
|
|
553
|
+
private _chatBody;
|
|
554
|
+
/** Chat completion (non-streaming) */
|
|
555
|
+
chat(options: ChatOptions): Promise<ChatCompletion>;
|
|
556
|
+
/** Chat completion (streaming) — returns an async iterator of chunks */
|
|
557
|
+
chatStream(options: ChatOptions): AsyncGenerator<ChatCompletionChunk>;
|
|
558
|
+
/** Convenience: send a single message and get the text response */
|
|
559
|
+
ask(message: string, modelOrOptions?: string | Partial<ChatOptions>): Promise<string>;
|
|
560
|
+
/** Convenience: send a single message and get the full completion (with usage) */
|
|
561
|
+
askFull(message: string, modelOrOptions?: string | Partial<ChatOptions>): Promise<ChatCompletion>;
|
|
562
|
+
/** Convenience: stream a single message and yield text chunks */
|
|
563
|
+
askStream(message: string, modelOrOptions?: string | Partial<ChatOptions>): AsyncGenerator<string>;
|
|
564
|
+
/** List available models */
|
|
565
|
+
models(): Promise<Model[]>;
|
|
566
|
+
/** List active operators */
|
|
567
|
+
operators(): Promise<{
|
|
568
|
+
operators: Operator[];
|
|
569
|
+
stats: any;
|
|
570
|
+
}>;
|
|
571
|
+
/** Get credit balance */
|
|
572
|
+
credits(): Promise<CreditBalance>;
|
|
573
|
+
/** Add credits */
|
|
574
|
+
addCredits(amount: number): Promise<{
|
|
575
|
+
balance: number;
|
|
576
|
+
}>;
|
|
577
|
+
/** Create a new API key */
|
|
578
|
+
createKey(name: string): Promise<{
|
|
579
|
+
key: string;
|
|
580
|
+
id: string;
|
|
581
|
+
}>;
|
|
582
|
+
/** List API keys */
|
|
583
|
+
keys(): Promise<{
|
|
584
|
+
id: string;
|
|
585
|
+
name: string;
|
|
586
|
+
prefix: string;
|
|
587
|
+
createdAt: string;
|
|
588
|
+
lastUsedAt: string | null;
|
|
589
|
+
}[]>;
|
|
590
|
+
/** Revoke an API key */
|
|
591
|
+
revokeKey(id: string): Promise<void>;
|
|
592
|
+
/** Generate embeddings */
|
|
593
|
+
embeddings(options: EmbeddingOptions): Promise<EmbeddingResponse>;
|
|
594
|
+
/** Generate images */
|
|
595
|
+
imageGenerate(options: ImageGenerateOptions): Promise<ImageResponse>;
|
|
596
|
+
/** Rerank documents by relevance to a query */
|
|
597
|
+
rerank(options: RerankOptions): Promise<RerankResponse>;
|
|
598
|
+
/** Text-to-speech */
|
|
599
|
+
speech(options: {
|
|
600
|
+
model?: string;
|
|
601
|
+
input: string;
|
|
602
|
+
voice?: string;
|
|
603
|
+
}): Promise<ArrayBuffer>;
|
|
604
|
+
/** Legacy completions endpoint */
|
|
605
|
+
completions(options: CompletionOptions): Promise<CompletionResponse>;
|
|
606
|
+
/** Audio transcription (speech-to-text) */
|
|
607
|
+
transcribe(file: Blob, options?: {
|
|
608
|
+
model?: string;
|
|
609
|
+
language?: string;
|
|
610
|
+
prompt?: string;
|
|
611
|
+
}): Promise<TranscriptionResponse>;
|
|
612
|
+
/** Create a fine-tuning job */
|
|
613
|
+
fineTuneCreate(options: FineTuningJobOptions): Promise<FineTuningJob>;
|
|
614
|
+
/** List fine-tuning jobs */
|
|
615
|
+
fineTuneList(): Promise<{
|
|
616
|
+
data: FineTuningJob[];
|
|
617
|
+
}>;
|
|
618
|
+
/** Submit a batch of chat requests */
|
|
619
|
+
batch(requests: BatchRequest[]): Promise<BatchJobResponse>;
|
|
620
|
+
/** Get batch job status */
|
|
621
|
+
batchStatus(jobId: string): Promise<BatchJobResponse>;
|
|
622
|
+
/** Generate video */
|
|
623
|
+
videoGenerate(options: VideoGenerateOptions): Promise<VideoResponse>;
|
|
624
|
+
/** Get video generation status */
|
|
625
|
+
videoStatus(id: string): Promise<VideoResponse>;
|
|
626
|
+
/** Generate an avatar video (lip-synced talking head from audio + face image).
|
|
627
|
+
* Returns 202 with a job_id for async polling via avatarJobStatus(). */
|
|
628
|
+
avatarGenerate(options: AvatarGenerateRequest): Promise<AvatarGenerateResponse>;
|
|
629
|
+
/** Poll an avatar generation job by ID. */
|
|
630
|
+
avatarJobStatus(jobId: string): Promise<AvatarJobStatus>;
|
|
631
|
+
/** Poll an avatar job until it reaches a terminal state (completed/failed).
|
|
632
|
+
* Returns the final job status. Throws on failure. */
|
|
633
|
+
pollAvatarJob(jobId: string, options?: {
|
|
634
|
+
intervalMs?: number;
|
|
635
|
+
timeoutMs?: number;
|
|
636
|
+
}): Promise<AvatarJobStatus>;
|
|
637
|
+
/**
|
|
638
|
+
* Watch an async job via SSE until it reaches a terminal state.
|
|
639
|
+
* Works with avatar, video, and training blueprint operators.
|
|
640
|
+
*
|
|
641
|
+
* @param jobId - The job ID returned by the creation endpoint
|
|
642
|
+
* @param options - Optional: operatorUrl override, onEvent callback
|
|
643
|
+
* @returns The final JobEvent (completed/failed/cancelled)
|
|
644
|
+
*/
|
|
645
|
+
watchJob(jobId: string, options?: WatchJobOptions): Promise<JobEvent>;
|
|
646
|
+
/** Create a vector collection on the operator's vector store */
|
|
647
|
+
createCollection(options: {
|
|
648
|
+
name: string;
|
|
649
|
+
dimensions: number;
|
|
650
|
+
distance_metric?: string;
|
|
651
|
+
}): Promise<any>;
|
|
652
|
+
/** List collections on the operator's vector store */
|
|
653
|
+
listCollections(): Promise<any>;
|
|
654
|
+
/** Upsert vectors into a collection */
|
|
655
|
+
upsertVectors(collection: string, vectors: Array<{
|
|
656
|
+
id: string;
|
|
657
|
+
vector: number[];
|
|
658
|
+
metadata?: Record<string, any>;
|
|
659
|
+
}>): Promise<any>;
|
|
660
|
+
/** Similarity search in a collection */
|
|
661
|
+
queryVectors(collection: string, options: {
|
|
662
|
+
vector: number[];
|
|
663
|
+
top_k?: number;
|
|
664
|
+
filter?: Record<string, any>;
|
|
665
|
+
}): Promise<any>;
|
|
666
|
+
/** RAG query — embed text + search collection in one call */
|
|
667
|
+
ragQuery(options: {
|
|
668
|
+
query: string;
|
|
669
|
+
collection: string;
|
|
670
|
+
top_k?: number;
|
|
671
|
+
embedding_model?: string;
|
|
672
|
+
}): Promise<any>;
|
|
673
|
+
/** Search models by name, provider, or capability */
|
|
674
|
+
searchModels(query: string): Promise<Model[]>;
|
|
675
|
+
/** Estimate cost for a request (without sending it) */
|
|
676
|
+
estimateCost(options: {
|
|
677
|
+
model?: string;
|
|
678
|
+
inputTokens: number;
|
|
679
|
+
outputTokens: number;
|
|
680
|
+
}): Promise<{
|
|
681
|
+
inputCost: number;
|
|
682
|
+
outputCost: number;
|
|
683
|
+
total: number;
|
|
684
|
+
}>;
|
|
685
|
+
/**
|
|
686
|
+
* Get a pricing spectrum across resource tiers for a model.
|
|
687
|
+
*
|
|
688
|
+
* Uses REAL per-operator pricing from `operator.models[].inputPrice`.
|
|
689
|
+
* Each tier filters operators by GPU count and TEE capability, then
|
|
690
|
+
* reports the cheapest and most expensive operator for that config.
|
|
691
|
+
*
|
|
692
|
+
* @param options.model - Model ID to price (falls back to client default)
|
|
693
|
+
* @param options.tiers - Number of tiers (1-7, default 5)
|
|
694
|
+
*/
|
|
695
|
+
pricingSpectrum(options: {
|
|
696
|
+
model?: string;
|
|
697
|
+
tiers?: number;
|
|
698
|
+
}): Promise<PricingTier[]>;
|
|
699
|
+
}
|
|
700
|
+
interface TierConfig {
|
|
701
|
+
name: string;
|
|
702
|
+
cpu: number;
|
|
703
|
+
ramGb: number;
|
|
704
|
+
gpu: number;
|
|
705
|
+
tee: boolean;
|
|
706
|
+
}
|
|
707
|
+
interface PricingTier {
|
|
708
|
+
tier: string;
|
|
709
|
+
config: TierConfig;
|
|
710
|
+
/** Raw cheapest per-input-token price (for programmatic use) */
|
|
711
|
+
cheapestPrice?: number;
|
|
712
|
+
/** Raw priciest per-input-token price (undefined if same as cheapest) */
|
|
713
|
+
priciestPrice?: number;
|
|
714
|
+
/** Formatted cheapest price */
|
|
715
|
+
cheapest: string;
|
|
716
|
+
/** Formatted priciest price (undefined if only one price point) */
|
|
717
|
+
priciest?: string;
|
|
718
|
+
/** Operators matching GPU/TEE requirements */
|
|
719
|
+
availableOperators: number;
|
|
720
|
+
/** Operators that also serve the requested model at a listed price */
|
|
721
|
+
operatorsWithModel: number;
|
|
722
|
+
}
|
|
723
|
+
declare class TCloudError extends Error {
|
|
724
|
+
status: number;
|
|
725
|
+
constructor(status: number, message: string);
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
export { type AvatarGenerateRequest as A, type BatchJobResponse as B, type ChatCompletion as C, type TranscriptionResponse as D, type EmbeddingOptions as E, type FineTuningJob as F, type VideoResponse as G, type ImageGenerateOptions as I, type JobEvent as J, type Model as M, type Operator as O, type PricingTier as P, type RerankOptions as R, type ShieldedConfig as S, TCloudClient as T, type VideoGenerateOptions as V, type WatchJobOptions as W, type TCloudConfig as a, type AvatarGenerateResponse as b, type AvatarJobStatus as c, type AvatarResult as d, type BatchRequest as e, type ChatCompletionChunk as f, type ChatMessage as g, type ChatOptions as h, type CompletionOptions as i, type CompletionResponse as j, type CreditBalance as k, type EmbeddingResponse as l, type FineTuningJobOptions as m, type ImageResponse as n, type OperatorInfo as o, type PrivacyConfig as p, PrivateRouter as q, type PrivateRouterConfig as r, type RerankResponse as s, type RetryConfig as t, type RoutingConfig as u, type RoutingStrategy as v, type SpendAuth as w, type SpendingLimits as x, TCloudError as y, type TierConfig as z };
|