@tangle-network/tcloud 0.1.4 → 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-PILYAKCF.js → chunk-STNZT6YR.js} +4 -2
- package/dist/chunk-VD4RNZOC.js +263 -0
- package/dist/cli.cjs +616 -153
- package/dist/cli.js +3 -2
- package/dist/{shielded-BTi_OftW.d.cts → client-CcuHG7_w.d.cts} +275 -60
- package/dist/{shielded-BTi_OftW.d.ts → client-CcuHG7_w.d.ts} +275 -60
- package/dist/index.cjs +618 -153
- 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 +616 -153
- 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-KVXWEAK3.js +0 -771
package/README.md
CHANGED
|
@@ -13,6 +13,9 @@ Zero framework dependencies. Pure `fetch` + SSE. Works in Node.js, Deno, Bun, an
|
|
|
13
13
|
- [Streaming](#streaming)
|
|
14
14
|
- [Full Chat Completion](#full-chat-completion)
|
|
15
15
|
- [Private Inference](#private-inference)
|
|
16
|
+
- [Embeddings](#embeddings)
|
|
17
|
+
- [Video & Avatar Generation](#video--avatar-generation)
|
|
18
|
+
- [Async Jobs](#async-jobs)
|
|
16
19
|
- [Operator Routing](#operator-routing)
|
|
17
20
|
- [Models and Operators](#models-and-operators)
|
|
18
21
|
- [API Key Management](#api-key-management)
|
|
@@ -55,7 +58,7 @@ const client = new TCloud({
|
|
|
55
58
|
model: 'gpt-4o-mini',
|
|
56
59
|
})
|
|
57
60
|
|
|
58
|
-
const answer = await client.ask('What is Tangle Network?')
|
|
61
|
+
const answer = await client.ask('What is Tangle Network?') // string
|
|
59
62
|
console.log(answer)
|
|
60
63
|
```
|
|
61
64
|
|
|
@@ -66,7 +69,7 @@ Model is set at client creation. Override per-request when needed:
|
|
|
66
69
|
```ts
|
|
67
70
|
// Default model for all requests
|
|
68
71
|
const client = new TCloud({ apiKey: '...', model: 'gpt-4o-mini' })
|
|
69
|
-
await client.ask('Hello') //
|
|
72
|
+
await client.ask('Hello') // returns string
|
|
70
73
|
|
|
71
74
|
// Full control per-request (OpenAI-compatible)
|
|
72
75
|
const completion = await client.chat({
|
|
@@ -74,14 +77,14 @@ const completion = await client.chat({
|
|
|
74
77
|
messages: [{ role: 'user', content: 'Hello' }],
|
|
75
78
|
temperature: 0.5,
|
|
76
79
|
maxTokens: 100,
|
|
77
|
-
})
|
|
80
|
+
}) // returns ChatCompletion { id, model, choices: [{ index, message, finish_reason }], usage? }
|
|
78
81
|
|
|
79
82
|
// Get full response with usage stats
|
|
80
|
-
const full = await client.askFull('Hello')
|
|
83
|
+
const full = await client.askFull('Hello') // returns ChatCompletion
|
|
81
84
|
console.log(full.model, full.usage?.total_tokens)
|
|
82
85
|
|
|
83
86
|
// Search available models
|
|
84
|
-
const llamas = await client.searchModels('llama')
|
|
87
|
+
const llamas = await client.searchModels('llama') // returns Model[]
|
|
85
88
|
```
|
|
86
89
|
|
|
87
90
|
### Streaming
|
|
@@ -110,9 +113,10 @@ const completion = await client.chat({
|
|
|
110
113
|
],
|
|
111
114
|
temperature: 0.7,
|
|
112
115
|
maxTokens: 1024,
|
|
113
|
-
})
|
|
116
|
+
}) // returns ChatCompletion
|
|
114
117
|
|
|
115
118
|
console.log(completion.choices[0].message.content)
|
|
119
|
+
// completion.usage => { prompt_tokens, completion_tokens, total_tokens }
|
|
116
120
|
```
|
|
117
121
|
|
|
118
122
|
### Private Inference
|
|
@@ -128,6 +132,57 @@ const answer = await client.ask('Hello from the shadows')
|
|
|
128
132
|
|
|
129
133
|
Under the hood: generates an ephemeral wallet, signs a SpendAuth payload, and sends it as an `X-Payment-Signature` header. The operator validates the cryptographic proof and serves inference without knowing who you are.
|
|
130
134
|
|
|
135
|
+
### Embeddings
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
const response = await client.embeddings({
|
|
139
|
+
model: 'text-embedding-3-small',
|
|
140
|
+
input: 'What is Tangle?',
|
|
141
|
+
}) // returns EmbeddingResponse
|
|
142
|
+
// EmbeddingResponse: { object, data: [{ object, embedding: number[], index }], model, usage }
|
|
143
|
+
console.log(response.data[0].embedding.length) // 1536
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Video & Avatar Generation
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
// Generate a video from a text prompt
|
|
150
|
+
const video = await client.videoGenerate({
|
|
151
|
+
prompt: 'A sunset over mountains',
|
|
152
|
+
duration: 5,
|
|
153
|
+
}) // returns VideoResponse { id, status, url?, error? }
|
|
154
|
+
|
|
155
|
+
// Generate a talking-head avatar video
|
|
156
|
+
const avatar = await client.avatarGenerate({
|
|
157
|
+
audio_url: 'https://example.com/narration.mp3',
|
|
158
|
+
image_url: 'https://example.com/face.jpg',
|
|
159
|
+
}) // returns AvatarGenerateResponse { job_id, status, result?, error? }
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Async Jobs
|
|
163
|
+
|
|
164
|
+
Avatar and video generation are asynchronous. Use `watchJob()` for real-time SSE streaming of job progress, or poll with `avatarJobStatus()`.
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
// Submit an avatar job
|
|
168
|
+
const job = await client.avatarGenerate({
|
|
169
|
+
audio_url: 'https://...',
|
|
170
|
+
image_url: 'https://...',
|
|
171
|
+
})
|
|
172
|
+
console.log(job.job_id) // 'job-abc123'
|
|
173
|
+
console.log(job.status) // 'queued'
|
|
174
|
+
|
|
175
|
+
// Watch until complete (SSE streaming)
|
|
176
|
+
const result = await client.watchJob(job.job_id, {
|
|
177
|
+
onEvent: (e) => console.log(`${e.status} ${e.progress ?? ''}%`),
|
|
178
|
+
}) // returns JobEvent { status, progress?, result?, error?, timestamp }
|
|
179
|
+
console.log(result.result) // { video_url: 'https://...' }
|
|
180
|
+
|
|
181
|
+
// Or just poll
|
|
182
|
+
const status = await client.avatarJobStatus(job.job_id)
|
|
183
|
+
// returns AvatarJobStatus { job_id, status, result?, error? }
|
|
184
|
+
```
|
|
185
|
+
|
|
131
186
|
### Operator Routing
|
|
132
187
|
|
|
133
188
|
Route requests to specific operators or use strategy-based selection:
|
|
@@ -156,19 +211,23 @@ The gateway selects the best operator based on a composite score (reputation 40%
|
|
|
156
211
|
|
|
157
212
|
```ts
|
|
158
213
|
// List all available models
|
|
159
|
-
const models = await client.models()
|
|
214
|
+
const models = await client.models() // returns Model[]
|
|
215
|
+
// Model: { id, name, context_length, pricing: { prompt, completion }, _provider? }
|
|
160
216
|
models.forEach(m => console.log(m.id, m._provider))
|
|
161
217
|
|
|
162
218
|
// Search models by name, provider, or capability
|
|
163
|
-
const llamas = await client.searchModels('llama')
|
|
219
|
+
const llamas = await client.searchModels('llama') // returns Model[]
|
|
164
220
|
const anthropic = await client.searchModels('anthropic')
|
|
165
221
|
|
|
166
222
|
// List active operators with stats
|
|
167
223
|
const { operators, stats } = await client.operators()
|
|
224
|
+
// returns { operators: Operator[], stats: any }
|
|
225
|
+
// Operator: { id, slug, name, status, endpointUrl, reputationScore, avgLatencyMs, models, ... }
|
|
168
226
|
console.log(`${stats.activeOperators} operators serving ${stats.totalModels} models`)
|
|
169
227
|
|
|
170
228
|
// Check credit balance
|
|
171
|
-
const credits = await client.credits()
|
|
229
|
+
const credits = await client.credits() // returns CreditBalance
|
|
230
|
+
// CreditBalance: { balance: number, transactions: [{ id, amount, type, description, createdAt }] }
|
|
172
231
|
console.log(`Balance: $${credits.balance}`)
|
|
173
232
|
```
|
|
174
233
|
|
|
@@ -198,7 +257,7 @@ const cost = await client.estimateCost({
|
|
|
198
257
|
model: 'gpt-4o',
|
|
199
258
|
inputTokens: 1000,
|
|
200
259
|
outputTokens: 500,
|
|
201
|
-
})
|
|
260
|
+
}) // returns { inputCost: number, outputCost: number, total: number }
|
|
202
261
|
console.log(`Estimated: $${cost.total.toFixed(6)}`)
|
|
203
262
|
// { inputCost: 0.005, outputCost: 0.0075, total: 0.0125 }
|
|
204
263
|
```
|