@tangle-network/tcloud
Version:
TypeScript SDK and CLI for Tangle Router, Sandbox, model routing, and agent service calls
117 lines (116 loc) • 4.35 kB
JavaScript
import { a as ParentBudgetExhaustedError, c as parseModelNotAllowed, i as MIN_CHILD_KEY_BUDGET_USD, l as resolveModelWithinAllowList, n as TCloudClient, o as deriveChildBudgetUsd, r as TCloudError, s as formatModelNotAllowedRefusal, t as BridgeSession, u as PrivateRouter } from "./client-BnSLiyHL.js";
import { createShieldedClient, estimateCost, generateWallet, signSpendAuth } from "./shielded.js";
import { TCloudSandbox, createTeeAttestationChallenge, generateAttestationNonce, startTeeAttestationHeartbeat } from "./sandbox.js";
import { assertAttestation, createNitroHardwareVerifier, createSevSnpHardwareVerifier, createTdxHardwareVerifier, normalizeTeeType, parseAttestation, parseNitroAttestationDocument, parseSevSnpReport, toHex, verifyAttestation, verifyAttestationAsync } from "@tangle-network/tcloud-attestation";
//#region src/index.ts
/**
* tcloud — Tangle AI Cloud SDK
*
* Drop-in replacement for the OpenAI SDK with decentralized operator routing
* and optional privacy via ShieldedCredits.
*
* Usage:
*
* ```ts
* // Standard mode (like OpenAI SDK)
* import { TCloud } from 'tcloud'
* const client = new TCloud({ apiKey: 'sk-tan-...' })
* const response = await client.ask('What is Tangle?')
*
* // Private mode (anonymous, no API key)
* const private = TCloud.shielded()
* const response = await private.ask('What is Tangle?')
* // SpendAuth signed automatically, operator never knows who you are
*
* // Streaming
* for await (const chunk of client.askStream('Tell me a story')) {
* process.stdout.write(chunk)
* }
*
* // Full OpenAI-compatible options
* const completion = await client.chat({
* model: 'meta-llama/llama-4-maverick',
* messages: [
* { role: 'system', content: 'You are helpful.' },
* { role: 'user', content: 'Hello' },
* ],
* temperature: 0.7,
* maxTokens: 1024,
* })
* ```
*/
var TCloud = class TCloud extends TCloudClient {
constructor(config) {
super(config);
}
/**
* Create a standard client with API key authentication.
*
* ```ts
* const client = TCloud.create({ apiKey: 'sk-tan-...' })
* ```
*/
static create(config) {
return new TCloud(config);
}
/**
* Create a shielded (private) client.
* Generates an ephemeral wallet and signs SpendAuth automatically.
* No API key needed. The operator never learns your identity.
*
* ```ts
* const client = TCloud.shielded()
* const response = await client.ask('Hello from the shadows')
* console.log(client.wallet.commitment) // anonymous credit account
* ```
*/
static shielded(config) {
return createShieldedClient(config);
}
/**
* Create a client that rotates operators per call.
* See {@link TCloudClient.rotating} for semantics.
*
* ```ts
* const client = TCloud.rotating({
* apiKey: process.env.TANGLE_API_KEY,
* routing: { strategy: 'min-exposure' },
* })
* const stats = client.getRotationStats()
* ```
*/
static rotating(config) {
return TCloudClient.rotating(config);
}
/**
* Generate a new ephemeral wallet (without creating a client).
*
* ```ts
* const wallet = TCloud.generateWallet()
* console.log(wallet.address, wallet.commitment)
* ```
*/
static generateWallet = generateWallet;
/**
* Create a Sandbox SDK client using this TCloud client's API key by default.
*
* ```ts
* const tcloud = new TCloud({ apiKey })
* const sandbox = await tcloud.sandbox().create({ name: 'runner' })
* ```
*/
sandbox(config = {}) {
const apiKey = config.apiKey ?? this.apiKey;
if (!apiKey) throw new Error("TCloud.sandbox() requires an apiKey");
return new TCloudSandbox({
...config,
apiKey
});
}
/** Create a standalone Sandbox SDK client. */
static sandbox(config) {
return new TCloudSandbox(config);
}
};
//#endregion
export { BridgeSession, MIN_CHILD_KEY_BUDGET_USD, ParentBudgetExhaustedError, PrivateRouter, TCloud, TCloudClient, TCloudError, TCloudSandbox, assertAttestation, createNitroHardwareVerifier, createSevSnpHardwareVerifier, createShieldedClient, createTdxHardwareVerifier, createTeeAttestationChallenge, deriveChildBudgetUsd, estimateCost, formatModelNotAllowedRefusal, generateAttestationNonce, generateWallet, normalizeTeeType, parseAttestation, parseModelNotAllowed, parseNitroAttestationDocument, parseSevSnpReport, resolveModelWithinAllowList, signSpendAuth, startTeeAttestationHeartbeat, toHex, verifyAttestation, verifyAttestationAsync };