@t2000/sdk 5.14.3 → 5.15.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/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +162 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +60 -3
- package/dist/index.d.ts +60 -3
- package/dist/index.js +159 -7
- package/dist/index.js.map +1 -1
- package/dist/{send-D2nKpwJN.d.cts → send-CUUOLK_H.d.cts} +1 -1
- package/dist/{send-D2nKpwJN.d.ts → send-CUUOLK_H.d.ts} +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1136,9 +1136,9 @@ async function payWithMpp(args) {
|
|
|
1136
1136
|
}
|
|
1137
1137
|
async function pickSuiExactRequirements(response, network) {
|
|
1138
1138
|
try {
|
|
1139
|
-
const
|
|
1139
|
+
const body2 = await response.clone().json();
|
|
1140
1140
|
const want = `sui:${network === "testnet" ? "testnet" : "mainnet"}`;
|
|
1141
|
-
return
|
|
1141
|
+
return body2.accepts?.find((a) => a.scheme === "exact" && a.network === want);
|
|
1142
1142
|
} catch {
|
|
1143
1143
|
return void 0;
|
|
1144
1144
|
}
|
|
@@ -1217,13 +1217,13 @@ async function ensureAddressBalanceCovers(args) {
|
|
|
1217
1217
|
}
|
|
1218
1218
|
async function finalize(response, opts) {
|
|
1219
1219
|
const contentType = response.headers.get("content-type") ?? "";
|
|
1220
|
-
let
|
|
1220
|
+
let body2;
|
|
1221
1221
|
try {
|
|
1222
|
-
|
|
1222
|
+
body2 = contentType.includes("application/json") ? await response.json() : await response.text();
|
|
1223
1223
|
} catch {
|
|
1224
|
-
|
|
1224
|
+
body2 = null;
|
|
1225
1225
|
}
|
|
1226
|
-
return { status: response.status, body, paid: opts.paid };
|
|
1226
|
+
return { status: response.status, body: body2, paid: opts.paid };
|
|
1227
1227
|
}
|
|
1228
1228
|
async function makeGrpcBuildClient(client) {
|
|
1229
1229
|
const { SuiGrpcClient: SuiGrpcClient2 } = await import('@mysten/sui/grpc');
|
|
@@ -1887,6 +1887,140 @@ async function normalizeAddressInput(value, ctx = {}) {
|
|
|
1887
1887
|
|
|
1888
1888
|
// src/t2000.ts
|
|
1889
1889
|
init_errors();
|
|
1890
|
+
|
|
1891
|
+
// src/inference.ts
|
|
1892
|
+
init_errors();
|
|
1893
|
+
var DEFAULT_API_BASE = "https://api.t2000.ai/v1";
|
|
1894
|
+
function envApiKey() {
|
|
1895
|
+
return typeof process !== "undefined" ? process.env?.T2000_API_KEY : void 0;
|
|
1896
|
+
}
|
|
1897
|
+
function resolveApiKey(apiKey) {
|
|
1898
|
+
const key = apiKey ?? envApiKey();
|
|
1899
|
+
if (!key) {
|
|
1900
|
+
throw new exports.T2000Error(
|
|
1901
|
+
"INVALID_KEY",
|
|
1902
|
+
"No Private API key. Pass `apiKey` or set T2000_API_KEY. Generate one at platform.t2000.ai (Pro/Max)."
|
|
1903
|
+
);
|
|
1904
|
+
}
|
|
1905
|
+
return key;
|
|
1906
|
+
}
|
|
1907
|
+
async function failBody(res) {
|
|
1908
|
+
const text = await res.text().catch(() => "");
|
|
1909
|
+
let msg = text.slice(0, 300);
|
|
1910
|
+
try {
|
|
1911
|
+
const j = JSON.parse(text);
|
|
1912
|
+
msg = (typeof j.error === "object" ? j.error?.message : j.error) ?? msg;
|
|
1913
|
+
} catch {
|
|
1914
|
+
}
|
|
1915
|
+
throw new exports.T2000Error(
|
|
1916
|
+
"INFERENCE_FAILED",
|
|
1917
|
+
`Inference request failed (${res.status}): ${msg}`,
|
|
1918
|
+
{ status: res.status },
|
|
1919
|
+
res.status >= 500
|
|
1920
|
+
);
|
|
1921
|
+
}
|
|
1922
|
+
function usageOf(raw) {
|
|
1923
|
+
const u = raw?.usage;
|
|
1924
|
+
if (!u) {
|
|
1925
|
+
return;
|
|
1926
|
+
}
|
|
1927
|
+
return {
|
|
1928
|
+
promptTokens: u.prompt_tokens,
|
|
1929
|
+
completionTokens: u.completion_tokens,
|
|
1930
|
+
totalTokens: u.total_tokens
|
|
1931
|
+
};
|
|
1932
|
+
}
|
|
1933
|
+
function body(params, stream) {
|
|
1934
|
+
return JSON.stringify({
|
|
1935
|
+
model: params.model,
|
|
1936
|
+
messages: params.messages,
|
|
1937
|
+
...stream ? { stream: true } : {},
|
|
1938
|
+
...params.maxTokens != null ? { max_tokens: params.maxTokens } : {},
|
|
1939
|
+
...params.temperature != null ? { temperature: params.temperature } : {}
|
|
1940
|
+
});
|
|
1941
|
+
}
|
|
1942
|
+
async function chatCompletion(params) {
|
|
1943
|
+
const key = resolveApiKey(params.apiKey);
|
|
1944
|
+
const base = params.apiBase ?? DEFAULT_API_BASE;
|
|
1945
|
+
const res = await fetch(`${base}/chat/completions`, {
|
|
1946
|
+
method: "POST",
|
|
1947
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${key}` },
|
|
1948
|
+
body: body(params, false)
|
|
1949
|
+
});
|
|
1950
|
+
if (!res.ok) {
|
|
1951
|
+
await failBody(res);
|
|
1952
|
+
}
|
|
1953
|
+
const raw = await res.json();
|
|
1954
|
+
const content = raw?.choices?.[0]?.message?.content ?? "";
|
|
1955
|
+
return {
|
|
1956
|
+
content,
|
|
1957
|
+
model: raw?.model ?? params.model,
|
|
1958
|
+
usage: usageOf(raw),
|
|
1959
|
+
raw
|
|
1960
|
+
};
|
|
1961
|
+
}
|
|
1962
|
+
async function* chatCompletionStream(params) {
|
|
1963
|
+
const key = resolveApiKey(params.apiKey);
|
|
1964
|
+
const base = params.apiBase ?? DEFAULT_API_BASE;
|
|
1965
|
+
const res = await fetch(`${base}/chat/completions`, {
|
|
1966
|
+
method: "POST",
|
|
1967
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${key}` },
|
|
1968
|
+
body: body(params, true)
|
|
1969
|
+
});
|
|
1970
|
+
if (!(res.ok && res.body)) {
|
|
1971
|
+
await failBody(res);
|
|
1972
|
+
return;
|
|
1973
|
+
}
|
|
1974
|
+
const reader = res.body.getReader();
|
|
1975
|
+
const decoder = new TextDecoder();
|
|
1976
|
+
let buffer = "";
|
|
1977
|
+
while (true) {
|
|
1978
|
+
const { done, value } = await reader.read();
|
|
1979
|
+
if (done) {
|
|
1980
|
+
break;
|
|
1981
|
+
}
|
|
1982
|
+
buffer += decoder.decode(value, { stream: true });
|
|
1983
|
+
const lines = buffer.split("\n");
|
|
1984
|
+
buffer = lines.pop() ?? "";
|
|
1985
|
+
for (const line of lines) {
|
|
1986
|
+
const trimmed = line.trim();
|
|
1987
|
+
if (!trimmed.startsWith("data:")) {
|
|
1988
|
+
continue;
|
|
1989
|
+
}
|
|
1990
|
+
const data = trimmed.slice(5).trim();
|
|
1991
|
+
if (data === "[DONE]") {
|
|
1992
|
+
return;
|
|
1993
|
+
}
|
|
1994
|
+
try {
|
|
1995
|
+
const json = JSON.parse(data);
|
|
1996
|
+
const delta = json.choices?.[0]?.delta?.content;
|
|
1997
|
+
if (typeof delta === "string" && delta) {
|
|
1998
|
+
yield delta;
|
|
1999
|
+
}
|
|
2000
|
+
} catch {
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
async function listModels(opts) {
|
|
2006
|
+
const base = opts?.apiBase ?? DEFAULT_API_BASE;
|
|
2007
|
+
const key = opts?.apiKey ?? envApiKey();
|
|
2008
|
+
const res = await fetch(`${base}/models`, {
|
|
2009
|
+
headers: key ? { authorization: `Bearer ${key}` } : {}
|
|
2010
|
+
});
|
|
2011
|
+
if (!res.ok) {
|
|
2012
|
+
await failBody(res);
|
|
2013
|
+
}
|
|
2014
|
+
const json = await res.json();
|
|
2015
|
+
const data = Array.isArray(json.data) ? json.data : [];
|
|
2016
|
+
return data.map((m) => ({
|
|
2017
|
+
id: m.id,
|
|
2018
|
+
contextWindow: m.context_window ?? m.context_length,
|
|
2019
|
+
inputPer1M: m.pricing?.input_per_1m ?? m.pricing?.prompt,
|
|
2020
|
+
outputPer1M: m.pricing?.output_per_1m ?? m.pricing?.completion,
|
|
2021
|
+
privacy: m.privacy ?? m.privacy_tier
|
|
2022
|
+
}));
|
|
2023
|
+
}
|
|
1890
2024
|
var DEFAULT_CONFIG_DIR = path.join(os.homedir(), ".t2000");
|
|
1891
2025
|
function resolveConfigPath(configDir) {
|
|
1892
2026
|
return path.join(configDir ?? DEFAULT_CONFIG_DIR, "config.json");
|
|
@@ -2153,6 +2287,24 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
2153
2287
|
// but there is no longer any way to MINT or REDEEM vSUI through t2000.
|
|
2154
2288
|
// History: see spec/archive/v07e/AUDIT_V07E_EARNS_ITS_KEEP_2026-05-23.md
|
|
2155
2289
|
// and the S.323 build-tracker entry.
|
|
2290
|
+
// -- Private Inference API (SPEC_AUDRIC_API, S.575) --
|
|
2291
|
+
//
|
|
2292
|
+
// Inference as a wallet verb — the agent's brain + wallet in one package.
|
|
2293
|
+
// Key-based today (`apiKey` / `T2000_API_KEY`); the x402 no-key pay-per-call
|
|
2294
|
+
// path is a later add. The model runs on the t2000 Private API (ZDR; a
|
|
2295
|
+
// `phala/*` confidential tier runs in a GPU-TEE).
|
|
2296
|
+
/** Non-streaming chat completion against the Private API. */
|
|
2297
|
+
async chat(params) {
|
|
2298
|
+
return chatCompletion(params);
|
|
2299
|
+
}
|
|
2300
|
+
/** Streaming chat completion — async-iterate the assistant text deltas. */
|
|
2301
|
+
chatStream(params) {
|
|
2302
|
+
return chatCompletionStream(params);
|
|
2303
|
+
}
|
|
2304
|
+
/** The Private API model catalog (`GET /v1/models`). */
|
|
2305
|
+
async models(opts) {
|
|
2306
|
+
return listModels(opts);
|
|
2307
|
+
}
|
|
2156
2308
|
// -- Swap --
|
|
2157
2309
|
async swap(params) {
|
|
2158
2310
|
this.limits.assert({
|
|
@@ -2919,6 +3071,7 @@ exports.AUDRIC_PARENT_NAME = AUDRIC_PARENT_NAME;
|
|
|
2919
3071
|
exports.AUDRIC_PARENT_NFT_ID = AUDRIC_PARENT_NFT_ID;
|
|
2920
3072
|
exports.CETUS_USDC_SUI_POOL = CETUS_USDC_SUI_POOL;
|
|
2921
3073
|
exports.CLOCK_ID = CLOCK_ID;
|
|
3074
|
+
exports.DEFAULT_API_BASE = DEFAULT_API_BASE;
|
|
2922
3075
|
exports.DEFAULT_GRPC_URL = DEFAULT_GRPC_URL;
|
|
2923
3076
|
exports.DEFAULT_NETWORK = DEFAULT_NETWORK;
|
|
2924
3077
|
exports.GASLESS_MIN_STABLE_AMOUNT = GASLESS_MIN_STABLE_AMOUNT;
|
|
@@ -2956,6 +3109,8 @@ exports.buildAddLeafTx = buildAddLeafTx;
|
|
|
2956
3109
|
exports.buildRevokeLeafTx = buildRevokeLeafTx;
|
|
2957
3110
|
exports.buildSendTx = buildSendTx;
|
|
2958
3111
|
exports.buildSwapTx = buildSwapTx;
|
|
3112
|
+
exports.chatCompletion = chatCompletion;
|
|
3113
|
+
exports.chatCompletionStream = chatCompletionStream;
|
|
2959
3114
|
exports.checkPositiveAmount = checkPositiveAmount;
|
|
2960
3115
|
exports.checkSuiAddress = checkSuiAddress;
|
|
2961
3116
|
exports.classifyAction = classifyAction;
|
|
@@ -2995,6 +3150,7 @@ exports.isAllowedAsset = isAllowedAsset;
|
|
|
2995
3150
|
exports.isCetusRouteFresh = isCetusRouteFresh;
|
|
2996
3151
|
exports.isInRegistry = isInRegistry;
|
|
2997
3152
|
exports.keypairFromPrivateKey = keypairFromPrivateKey;
|
|
3153
|
+
exports.listModels = listModels;
|
|
2998
3154
|
exports.loadKey = loadKey;
|
|
2999
3155
|
exports.looksLikeSuiNs = looksLikeSuiNs;
|
|
3000
3156
|
exports.mapMoveAbortCode = mapMoveAbortCode;
|