@t2000/mcp 5.14.2 → 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/bin.js +271 -57
- package/dist/bin.js.map +1 -1
- package/dist/index.js +271 -57
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -5035,10 +5035,10 @@ var require_codegen = __commonJS({
|
|
|
5035
5035
|
return this._leafNode(new Throw(error2));
|
|
5036
5036
|
}
|
|
5037
5037
|
// start self-balancing block
|
|
5038
|
-
block(
|
|
5038
|
+
block(body2, nodeCount) {
|
|
5039
5039
|
this._blockStarts.push(this._nodes.length);
|
|
5040
|
-
if (
|
|
5041
|
-
this.code(
|
|
5040
|
+
if (body2)
|
|
5041
|
+
this.code(body2).endBlock(nodeCount);
|
|
5042
5042
|
return this;
|
|
5043
5043
|
}
|
|
5044
5044
|
// end the current self-balancing block
|
|
@@ -6448,15 +6448,15 @@ var require_validate = __commonJS({
|
|
|
6448
6448
|
validateFunction(it, () => (0, boolSchema_1.topBoolOrEmptySchema)(it));
|
|
6449
6449
|
}
|
|
6450
6450
|
exports$1.validateFunctionCode = validateFunctionCode;
|
|
6451
|
-
function validateFunction({ gen, validateName, schema, schemaEnv, opts },
|
|
6451
|
+
function validateFunction({ gen, validateName, schema, schemaEnv, opts }, body2) {
|
|
6452
6452
|
if (opts.code.es5) {
|
|
6453
6453
|
gen.func(validateName, (0, codegen_1._)`${names_1.default.data}, ${names_1.default.valCxt}`, schemaEnv.$async, () => {
|
|
6454
6454
|
gen.code((0, codegen_1._)`"use strict"; ${funcSourceUrl(schema, opts)}`);
|
|
6455
6455
|
destructureValCxtES5(gen, opts);
|
|
6456
|
-
gen.code(
|
|
6456
|
+
gen.code(body2);
|
|
6457
6457
|
});
|
|
6458
6458
|
} else {
|
|
6459
|
-
gen.func(validateName, (0, codegen_1._)`${names_1.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(
|
|
6459
|
+
gen.func(validateName, (0, codegen_1._)`${names_1.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body2));
|
|
6460
6460
|
}
|
|
6461
6461
|
}
|
|
6462
6462
|
function destructureValCxt(opts) {
|
|
@@ -16984,7 +16984,7 @@ var init_mvr = __esm({
|
|
|
16984
16984
|
}));
|
|
16985
16985
|
return results;
|
|
16986
16986
|
}
|
|
16987
|
-
async #fetch(url2,
|
|
16987
|
+
async #fetch(url2, body2) {
|
|
16988
16988
|
if (!this.#url) throw new Error("MVR Api URL is not set for the current client");
|
|
16989
16989
|
const response = await fetch(`${this.#url}${url2}`, {
|
|
16990
16990
|
method: "POST",
|
|
@@ -16992,7 +16992,7 @@ var init_mvr = __esm({
|
|
|
16992
16992
|
"Content-Type": "application/json",
|
|
16993
16993
|
...MVR_API_HEADER
|
|
16994
16994
|
},
|
|
16995
|
-
body: JSON.stringify(
|
|
16995
|
+
body: JSON.stringify(body2)
|
|
16996
16996
|
});
|
|
16997
16997
|
if (!response.ok) {
|
|
16998
16998
|
const errorBody = await response.json().catch(() => ({}));
|
|
@@ -31655,14 +31655,14 @@ function createGrpcWebRequestHeader(headers, format, timeout, meta, userAgent) {
|
|
|
31655
31655
|
return headers;
|
|
31656
31656
|
}
|
|
31657
31657
|
function createGrpcWebRequestBody(message, format) {
|
|
31658
|
-
let
|
|
31659
|
-
|
|
31658
|
+
let body2 = new Uint8Array(5 + message.length);
|
|
31659
|
+
body2[0] = GrpcWebFrame.DATA;
|
|
31660
31660
|
for (let msgLen = message.length, i = 4; i > 0; i--) {
|
|
31661
|
-
|
|
31661
|
+
body2[i] = msgLen % 256;
|
|
31662
31662
|
msgLen >>>= 8;
|
|
31663
31663
|
}
|
|
31664
|
-
|
|
31665
|
-
return format === "binary" ?
|
|
31664
|
+
body2.set(message, 5);
|
|
31665
|
+
return format === "binary" ? body2 : base64encode(body2);
|
|
31666
31666
|
}
|
|
31667
31667
|
function readGrpcWebResponseHeader(headersOrFetchResponse, httpStatus, httpStatusText) {
|
|
31668
31668
|
if (arguments.length === 1) {
|
|
@@ -32734,7 +32734,7 @@ var init_dist6 = __esm({
|
|
|
32734
32734
|
super(), __privateAdd(this, _EventSource_instances), this.CONNECTING = 0, this.OPEN = 1, this.CLOSED = 2, __privateAdd(this, _readyState), __privateAdd(this, _url2), __privateAdd(this, _redirectUrl), __privateAdd(this, _withCredentials), __privateAdd(this, _fetch), __privateAdd(this, _reconnectInterval), __privateAdd(this, _reconnectTimer), __privateAdd(this, _lastEventId, null), __privateAdd(this, _controller), __privateAdd(this, _parser), __privateAdd(this, _onError, null), __privateAdd(this, _onMessage, null), __privateAdd(this, _onOpen, null), __privateAdd(this, _onFetchResponse, async (response) => {
|
|
32735
32735
|
var _a2;
|
|
32736
32736
|
__privateGet(this, _parser).reset();
|
|
32737
|
-
const { body, redirected, status, headers } = response;
|
|
32737
|
+
const { body: body2, redirected, status, headers } = response;
|
|
32738
32738
|
if (status === 204) {
|
|
32739
32739
|
__privateMethod(this, _EventSource_instances, failConnection_fn).call(this, "Server sent HTTP 204, not reconnecting", 204), this.close();
|
|
32740
32740
|
return;
|
|
@@ -32751,11 +32751,11 @@ var init_dist6 = __esm({
|
|
|
32751
32751
|
return;
|
|
32752
32752
|
__privateSet(this, _readyState, this.OPEN);
|
|
32753
32753
|
const openEvent = new Event("open");
|
|
32754
|
-
if ((_a2 = __privateGet(this, _onOpen)) == null || _a2.call(this, openEvent), this.dispatchEvent(openEvent), typeof
|
|
32754
|
+
if ((_a2 = __privateGet(this, _onOpen)) == null || _a2.call(this, openEvent), this.dispatchEvent(openEvent), typeof body2 != "object" || !body2 || !("getReader" in body2)) {
|
|
32755
32755
|
__privateMethod(this, _EventSource_instances, failConnection_fn).call(this, "Invalid response body, expected a web ReadableStream", status), this.close();
|
|
32756
32756
|
return;
|
|
32757
32757
|
}
|
|
32758
|
-
const decoder = new TextDecoder(), reader =
|
|
32758
|
+
const decoder = new TextDecoder(), reader = body2.getReader();
|
|
32759
32759
|
let open = true;
|
|
32760
32760
|
do {
|
|
32761
32761
|
const { done, value } = await reader.read();
|
|
@@ -46108,8 +46108,8 @@ function fromDataURI(uri, asBlob, options) {
|
|
|
46108
46108
|
}
|
|
46109
46109
|
const mime = match[1];
|
|
46110
46110
|
const isBase64 = match[2];
|
|
46111
|
-
const
|
|
46112
|
-
const buffer = Buffer.from(decodeURIComponent(
|
|
46111
|
+
const body2 = match[3];
|
|
46112
|
+
const buffer = Buffer.from(decodeURIComponent(body2), isBase64 ? "base64" : "utf8");
|
|
46113
46113
|
if (asBlob) {
|
|
46114
46114
|
if (!_Blob) {
|
|
46115
46115
|
throw new AxiosError_default("Blob is not supported", AxiosError_default.ERR_NOT_SUPPORT);
|
|
@@ -46659,15 +46659,15 @@ function estimateDataURLDecodedBytes(url2) {
|
|
|
46659
46659
|
const comma = url2.indexOf(",");
|
|
46660
46660
|
if (comma < 0) return 0;
|
|
46661
46661
|
const meta = url2.slice(5, comma);
|
|
46662
|
-
const
|
|
46662
|
+
const body2 = url2.slice(comma + 1);
|
|
46663
46663
|
const isBase64 = /;base64/i.test(meta);
|
|
46664
46664
|
if (isBase64) {
|
|
46665
|
-
let effectiveLen =
|
|
46666
|
-
const len =
|
|
46665
|
+
let effectiveLen = body2.length;
|
|
46666
|
+
const len = body2.length;
|
|
46667
46667
|
for (let i = 0; i < len; i++) {
|
|
46668
|
-
if (
|
|
46669
|
-
const a =
|
|
46670
|
-
const b =
|
|
46668
|
+
if (body2.charCodeAt(i) === 37 && i + 2 < len) {
|
|
46669
|
+
const a = body2.charCodeAt(i + 1);
|
|
46670
|
+
const b = body2.charCodeAt(i + 2);
|
|
46671
46671
|
const isHex3 = (a >= 48 && a <= 57 || a >= 65 && a <= 70 || a >= 97 && a <= 102) && (b >= 48 && b <= 57 || b >= 65 && b <= 70 || b >= 97 && b <= 102);
|
|
46672
46672
|
if (isHex3) {
|
|
46673
46673
|
effectiveLen -= 2;
|
|
@@ -46677,11 +46677,11 @@ function estimateDataURLDecodedBytes(url2) {
|
|
|
46677
46677
|
}
|
|
46678
46678
|
let pad = 0;
|
|
46679
46679
|
let idx = len - 1;
|
|
46680
|
-
const tailIsPct3D = (j) => j >= 2 &&
|
|
46681
|
-
|
|
46682
|
-
(
|
|
46680
|
+
const tailIsPct3D = (j) => j >= 2 && body2.charCodeAt(j - 2) === 37 && // '%'
|
|
46681
|
+
body2.charCodeAt(j - 1) === 51 && // '3'
|
|
46682
|
+
(body2.charCodeAt(j) === 68 || body2.charCodeAt(j) === 100);
|
|
46683
46683
|
if (idx >= 0) {
|
|
46684
|
-
if (
|
|
46684
|
+
if (body2.charCodeAt(idx) === 61) {
|
|
46685
46685
|
pad++;
|
|
46686
46686
|
idx--;
|
|
46687
46687
|
} else if (tailIsPct3D(idx)) {
|
|
@@ -46690,7 +46690,7 @@ function estimateDataURLDecodedBytes(url2) {
|
|
|
46690
46690
|
}
|
|
46691
46691
|
}
|
|
46692
46692
|
if (pad === 1 && idx >= 0) {
|
|
46693
|
-
if (
|
|
46693
|
+
if (body2.charCodeAt(idx) === 61) {
|
|
46694
46694
|
pad++;
|
|
46695
46695
|
} else if (tailIsPct3D(idx)) {
|
|
46696
46696
|
pad++;
|
|
@@ -46700,7 +46700,7 @@ function estimateDataURLDecodedBytes(url2) {
|
|
|
46700
46700
|
const bytes = groups * 3 - (pad || 0);
|
|
46701
46701
|
return bytes > 0 ? bytes : 0;
|
|
46702
46702
|
}
|
|
46703
|
-
return Buffer.byteLength(
|
|
46703
|
+
return Buffer.byteLength(body2, "utf8");
|
|
46704
46704
|
}
|
|
46705
46705
|
var init_estimateDataURLDecodedBytes = __esm({
|
|
46706
46706
|
"../../node_modules/.pnpm/axios@1.15.2/node_modules/axios/lib/helpers/estimateDataURLDecodedBytes.js"() {
|
|
@@ -48106,33 +48106,33 @@ var init_fetch = __esm({
|
|
|
48106
48106
|
});
|
|
48107
48107
|
});
|
|
48108
48108
|
})();
|
|
48109
|
-
const getBodyLength = async (
|
|
48110
|
-
if (
|
|
48109
|
+
const getBodyLength = async (body2) => {
|
|
48110
|
+
if (body2 == null) {
|
|
48111
48111
|
return 0;
|
|
48112
48112
|
}
|
|
48113
|
-
if (utils_default.isBlob(
|
|
48114
|
-
return
|
|
48113
|
+
if (utils_default.isBlob(body2)) {
|
|
48114
|
+
return body2.size;
|
|
48115
48115
|
}
|
|
48116
|
-
if (utils_default.isSpecCompliantForm(
|
|
48116
|
+
if (utils_default.isSpecCompliantForm(body2)) {
|
|
48117
48117
|
const _request = new Request(platform_default.origin, {
|
|
48118
48118
|
method: "POST",
|
|
48119
|
-
body
|
|
48119
|
+
body: body2
|
|
48120
48120
|
});
|
|
48121
48121
|
return (await _request.arrayBuffer()).byteLength;
|
|
48122
48122
|
}
|
|
48123
|
-
if (utils_default.isArrayBufferView(
|
|
48124
|
-
return
|
|
48123
|
+
if (utils_default.isArrayBufferView(body2) || utils_default.isArrayBuffer(body2)) {
|
|
48124
|
+
return body2.byteLength;
|
|
48125
48125
|
}
|
|
48126
|
-
if (utils_default.isURLSearchParams(
|
|
48127
|
-
|
|
48126
|
+
if (utils_default.isURLSearchParams(body2)) {
|
|
48127
|
+
body2 = body2 + "";
|
|
48128
48128
|
}
|
|
48129
|
-
if (utils_default.isString(
|
|
48130
|
-
return (await encodeText(
|
|
48129
|
+
if (utils_default.isString(body2)) {
|
|
48130
|
+
return (await encodeText(body2)).byteLength;
|
|
48131
48131
|
}
|
|
48132
48132
|
};
|
|
48133
|
-
const resolveBodyLength = async (headers,
|
|
48133
|
+
const resolveBodyLength = async (headers, body2) => {
|
|
48134
48134
|
const length = utils_default.toFiniteNumber(headers.getContentLength());
|
|
48135
|
-
return length == null ? getBodyLength(
|
|
48135
|
+
return length == null ? getBodyLength(body2) : length;
|
|
48136
48136
|
};
|
|
48137
48137
|
return async (config3) => {
|
|
48138
48138
|
let {
|
|
@@ -78725,9 +78725,9 @@ async function payWithMpp(args) {
|
|
|
78725
78725
|
}
|
|
78726
78726
|
async function pickSuiExactRequirements(response, network) {
|
|
78727
78727
|
try {
|
|
78728
|
-
const
|
|
78728
|
+
const body2 = await response.clone().json();
|
|
78729
78729
|
const want = `sui:${network === "testnet" ? "testnet" : "mainnet"}`;
|
|
78730
|
-
return
|
|
78730
|
+
return body2.accepts?.find((a) => a.scheme === "exact" && a.network === want);
|
|
78731
78731
|
} catch {
|
|
78732
78732
|
return void 0;
|
|
78733
78733
|
}
|
|
@@ -78806,13 +78806,13 @@ async function ensureAddressBalanceCovers(args) {
|
|
|
78806
78806
|
}
|
|
78807
78807
|
async function finalize(response, opts) {
|
|
78808
78808
|
const contentType = response.headers.get("content-type") ?? "";
|
|
78809
|
-
let
|
|
78809
|
+
let body2;
|
|
78810
78810
|
try {
|
|
78811
|
-
|
|
78811
|
+
body2 = contentType.includes("application/json") ? await response.json() : await response.text();
|
|
78812
78812
|
} catch {
|
|
78813
|
-
|
|
78813
|
+
body2 = null;
|
|
78814
78814
|
}
|
|
78815
|
-
return { status: response.status, body, paid: opts.paid };
|
|
78815
|
+
return { status: response.status, body: body2, paid: opts.paid };
|
|
78816
78816
|
}
|
|
78817
78817
|
async function makeGrpcBuildClient(client) {
|
|
78818
78818
|
const { SuiGrpcClient: SuiGrpcClient2 } = await Promise.resolve().then(() => (init_grpc(), grpc_exports));
|
|
@@ -79324,6 +79324,138 @@ async function resolveSuinsViaRpc(rawName, ctx = {}) {
|
|
|
79324
79324
|
return res.data?.address?.address ?? null;
|
|
79325
79325
|
}
|
|
79326
79326
|
init_errors3();
|
|
79327
|
+
init_errors3();
|
|
79328
|
+
var DEFAULT_API_BASE = "https://api.t2000.ai/v1";
|
|
79329
|
+
function envApiKey() {
|
|
79330
|
+
return typeof process !== "undefined" ? process.env?.T2000_API_KEY : void 0;
|
|
79331
|
+
}
|
|
79332
|
+
function resolveApiKey(apiKey) {
|
|
79333
|
+
const key = apiKey ?? envApiKey();
|
|
79334
|
+
if (!key) {
|
|
79335
|
+
throw new T2000Error(
|
|
79336
|
+
"INVALID_KEY",
|
|
79337
|
+
"No Private API key. Pass `apiKey` or set T2000_API_KEY. Generate one at platform.t2000.ai (Pro/Max)."
|
|
79338
|
+
);
|
|
79339
|
+
}
|
|
79340
|
+
return key;
|
|
79341
|
+
}
|
|
79342
|
+
async function failBody(res) {
|
|
79343
|
+
const text = await res.text().catch(() => "");
|
|
79344
|
+
let msg = text.slice(0, 300);
|
|
79345
|
+
try {
|
|
79346
|
+
const j = JSON.parse(text);
|
|
79347
|
+
msg = (typeof j.error === "object" ? j.error?.message : j.error) ?? msg;
|
|
79348
|
+
} catch {
|
|
79349
|
+
}
|
|
79350
|
+
throw new T2000Error(
|
|
79351
|
+
"INFERENCE_FAILED",
|
|
79352
|
+
`Inference request failed (${res.status}): ${msg}`,
|
|
79353
|
+
{ status: res.status },
|
|
79354
|
+
res.status >= 500
|
|
79355
|
+
);
|
|
79356
|
+
}
|
|
79357
|
+
function usageOf(raw) {
|
|
79358
|
+
const u2 = raw?.usage;
|
|
79359
|
+
if (!u2) {
|
|
79360
|
+
return;
|
|
79361
|
+
}
|
|
79362
|
+
return {
|
|
79363
|
+
promptTokens: u2.prompt_tokens,
|
|
79364
|
+
completionTokens: u2.completion_tokens,
|
|
79365
|
+
totalTokens: u2.total_tokens
|
|
79366
|
+
};
|
|
79367
|
+
}
|
|
79368
|
+
function body(params, stream4) {
|
|
79369
|
+
return JSON.stringify({
|
|
79370
|
+
model: params.model,
|
|
79371
|
+
messages: params.messages,
|
|
79372
|
+
...stream4 ? { stream: true } : {},
|
|
79373
|
+
...params.maxTokens != null ? { max_tokens: params.maxTokens } : {},
|
|
79374
|
+
...params.temperature != null ? { temperature: params.temperature } : {}
|
|
79375
|
+
});
|
|
79376
|
+
}
|
|
79377
|
+
async function chatCompletion(params) {
|
|
79378
|
+
const key = resolveApiKey(params.apiKey);
|
|
79379
|
+
const base = params.apiBase ?? DEFAULT_API_BASE;
|
|
79380
|
+
const res = await fetch(`${base}/chat/completions`, {
|
|
79381
|
+
method: "POST",
|
|
79382
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${key}` },
|
|
79383
|
+
body: body(params, false)
|
|
79384
|
+
});
|
|
79385
|
+
if (!res.ok) {
|
|
79386
|
+
await failBody(res);
|
|
79387
|
+
}
|
|
79388
|
+
const raw = await res.json();
|
|
79389
|
+
const content = raw?.choices?.[0]?.message?.content ?? "";
|
|
79390
|
+
return {
|
|
79391
|
+
content,
|
|
79392
|
+
model: raw?.model ?? params.model,
|
|
79393
|
+
usage: usageOf(raw),
|
|
79394
|
+
raw
|
|
79395
|
+
};
|
|
79396
|
+
}
|
|
79397
|
+
async function* chatCompletionStream(params) {
|
|
79398
|
+
const key = resolveApiKey(params.apiKey);
|
|
79399
|
+
const base = params.apiBase ?? DEFAULT_API_BASE;
|
|
79400
|
+
const res = await fetch(`${base}/chat/completions`, {
|
|
79401
|
+
method: "POST",
|
|
79402
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${key}` },
|
|
79403
|
+
body: body(params, true)
|
|
79404
|
+
});
|
|
79405
|
+
if (!(res.ok && res.body)) {
|
|
79406
|
+
await failBody(res);
|
|
79407
|
+
return;
|
|
79408
|
+
}
|
|
79409
|
+
const reader = res.body.getReader();
|
|
79410
|
+
const decoder = new TextDecoder();
|
|
79411
|
+
let buffer = "";
|
|
79412
|
+
while (true) {
|
|
79413
|
+
const { done, value } = await reader.read();
|
|
79414
|
+
if (done) {
|
|
79415
|
+
break;
|
|
79416
|
+
}
|
|
79417
|
+
buffer += decoder.decode(value, { stream: true });
|
|
79418
|
+
const lines = buffer.split("\n");
|
|
79419
|
+
buffer = lines.pop() ?? "";
|
|
79420
|
+
for (const line of lines) {
|
|
79421
|
+
const trimmed = line.trim();
|
|
79422
|
+
if (!trimmed.startsWith("data:")) {
|
|
79423
|
+
continue;
|
|
79424
|
+
}
|
|
79425
|
+
const data = trimmed.slice(5).trim();
|
|
79426
|
+
if (data === "[DONE]") {
|
|
79427
|
+
return;
|
|
79428
|
+
}
|
|
79429
|
+
try {
|
|
79430
|
+
const json = JSON.parse(data);
|
|
79431
|
+
const delta = json.choices?.[0]?.delta?.content;
|
|
79432
|
+
if (typeof delta === "string" && delta) {
|
|
79433
|
+
yield delta;
|
|
79434
|
+
}
|
|
79435
|
+
} catch {
|
|
79436
|
+
}
|
|
79437
|
+
}
|
|
79438
|
+
}
|
|
79439
|
+
}
|
|
79440
|
+
async function listModels(opts) {
|
|
79441
|
+
const base = opts?.apiBase ?? DEFAULT_API_BASE;
|
|
79442
|
+
const key = opts?.apiKey ?? envApiKey();
|
|
79443
|
+
const res = await fetch(`${base}/models`, {
|
|
79444
|
+
headers: key ? { authorization: `Bearer ${key}` } : {}
|
|
79445
|
+
});
|
|
79446
|
+
if (!res.ok) {
|
|
79447
|
+
await failBody(res);
|
|
79448
|
+
}
|
|
79449
|
+
const json = await res.json();
|
|
79450
|
+
const data = Array.isArray(json.data) ? json.data : [];
|
|
79451
|
+
return data.map((m) => ({
|
|
79452
|
+
id: m.id,
|
|
79453
|
+
contextWindow: m.context_window ?? m.context_length,
|
|
79454
|
+
inputPer1M: m.pricing?.input_per_1m ?? m.pricing?.prompt,
|
|
79455
|
+
outputPer1M: m.pricing?.output_per_1m ?? m.pricing?.completion,
|
|
79456
|
+
privacy: m.privacy ?? m.privacy_tier
|
|
79457
|
+
}));
|
|
79458
|
+
}
|
|
79327
79459
|
var DEFAULT_CONFIG_DIR = join$1(homedir(), ".t2000");
|
|
79328
79460
|
function resolveConfigPath(configDir) {
|
|
79329
79461
|
return join$1(configDir ?? DEFAULT_CONFIG_DIR, "config.json");
|
|
@@ -79586,6 +79718,24 @@ var T2000 = class _T2000 extends import_index2.default {
|
|
|
79586
79718
|
// but there is no longer any way to MINT or REDEEM vSUI through t2000.
|
|
79587
79719
|
// History: see spec/archive/v07e/AUDIT_V07E_EARNS_ITS_KEEP_2026-05-23.md
|
|
79588
79720
|
// and the S.323 build-tracker entry.
|
|
79721
|
+
// -- Private Inference API (SPEC_AUDRIC_API, S.575) --
|
|
79722
|
+
//
|
|
79723
|
+
// Inference as a wallet verb — the agent's brain + wallet in one package.
|
|
79724
|
+
// Key-based today (`apiKey` / `T2000_API_KEY`); the x402 no-key pay-per-call
|
|
79725
|
+
// path is a later add. The model runs on the t2000 Private API (ZDR; a
|
|
79726
|
+
// `phala/*` confidential tier runs in a GPU-TEE).
|
|
79727
|
+
/** Non-streaming chat completion against the Private API. */
|
|
79728
|
+
async chat(params) {
|
|
79729
|
+
return chatCompletion(params);
|
|
79730
|
+
}
|
|
79731
|
+
/** Streaming chat completion — async-iterate the assistant text deltas. */
|
|
79732
|
+
chatStream(params) {
|
|
79733
|
+
return chatCompletionStream(params);
|
|
79734
|
+
}
|
|
79735
|
+
/** The Private API model catalog (`GET /v1/models`). */
|
|
79736
|
+
async models(opts) {
|
|
79737
|
+
return listModels(opts);
|
|
79738
|
+
}
|
|
79589
79739
|
// -- Swap --
|
|
79590
79740
|
async swap(params) {
|
|
79591
79741
|
this.limits.assert({
|
|
@@ -80205,10 +80355,10 @@ Common examples:
|
|
|
80205
80355
|
headers: external_exports.record(external_exports.string()).optional().describe("Additional HTTP headers"),
|
|
80206
80356
|
maxPrice: external_exports.number().default(1).describe("Max USD to pay (default: $1.00). Set higher for commerce services.")
|
|
80207
80357
|
},
|
|
80208
|
-
async ({ url: url2, method, body, headers, maxPrice }) => {
|
|
80358
|
+
async ({ url: url2, method, body: body2, headers, maxPrice }) => {
|
|
80209
80359
|
try {
|
|
80210
80360
|
const result = await mutex.run(
|
|
80211
|
-
() => agent.pay({ url: url2, method, body, headers, maxPrice })
|
|
80361
|
+
() => agent.pay({ url: url2, method, body: body2, headers, maxPrice })
|
|
80212
80362
|
);
|
|
80213
80363
|
let text = JSON.stringify(result);
|
|
80214
80364
|
try {
|
|
@@ -80267,6 +80417,69 @@ Use the returned values to inform the user about their own configured caps befor
|
|
|
80267
80417
|
);
|
|
80268
80418
|
}
|
|
80269
80419
|
|
|
80420
|
+
// src/tools/chat.ts
|
|
80421
|
+
init_zod();
|
|
80422
|
+
var DEFAULT_MODEL = "zai/glm-5.2";
|
|
80423
|
+
function registerChatTools(server) {
|
|
80424
|
+
server.tool(
|
|
80425
|
+
"t2000_chat",
|
|
80426
|
+
"Run private inference on the t2000 Private API (OpenAI-compatible; ZDR by default, a `phala/*` tier is GPU-TEE confidential), billed to the user's t2000 credit. Requires T2000_API_KEY in the server env (generate at platform.t2000.ai \u2014 Pro/Max). Pass a single `prompt`, or a full `messages` list. Discover model ids with t2000_models; defaults to GLM 5.2.",
|
|
80427
|
+
{
|
|
80428
|
+
prompt: external_exports.string().optional().describe("User prompt (shorthand for a single user message)"),
|
|
80429
|
+
messages: external_exports.array(
|
|
80430
|
+
external_exports.object({
|
|
80431
|
+
role: external_exports.enum(["system", "user", "assistant"]),
|
|
80432
|
+
content: external_exports.string()
|
|
80433
|
+
})
|
|
80434
|
+
).optional().describe("Full message list (overrides `prompt` when present)"),
|
|
80435
|
+
model: external_exports.string().optional().describe(`Model id (default ${DEFAULT_MODEL}; see t2000_models)`),
|
|
80436
|
+
maxTokens: external_exports.number().optional().describe("Max output tokens"),
|
|
80437
|
+
temperature: external_exports.number().optional().describe("Sampling temperature (0\u20132)")
|
|
80438
|
+
},
|
|
80439
|
+
async ({ prompt, messages, model, maxTokens, temperature }) => {
|
|
80440
|
+
try {
|
|
80441
|
+
const msgs = messages ?? (prompt ? [{ role: "user", content: prompt }] : []);
|
|
80442
|
+
if (msgs.length === 0) {
|
|
80443
|
+
throw new Error("Provide `prompt` or `messages`.");
|
|
80444
|
+
}
|
|
80445
|
+
const res = await chatCompletion({
|
|
80446
|
+
model: model ?? DEFAULT_MODEL,
|
|
80447
|
+
messages: msgs,
|
|
80448
|
+
maxTokens,
|
|
80449
|
+
temperature
|
|
80450
|
+
});
|
|
80451
|
+
return {
|
|
80452
|
+
content: [
|
|
80453
|
+
{
|
|
80454
|
+
type: "text",
|
|
80455
|
+
text: JSON.stringify({
|
|
80456
|
+
model: res.model,
|
|
80457
|
+
content: res.content,
|
|
80458
|
+
usage: res.usage
|
|
80459
|
+
})
|
|
80460
|
+
}
|
|
80461
|
+
]
|
|
80462
|
+
};
|
|
80463
|
+
} catch (err) {
|
|
80464
|
+
return errorResult(err);
|
|
80465
|
+
}
|
|
80466
|
+
}
|
|
80467
|
+
);
|
|
80468
|
+
server.tool(
|
|
80469
|
+
"t2000_models",
|
|
80470
|
+
"List the t2000 Private API model catalog (id \xB7 privacy tier \xB7 per-1M pricing). Call before t2000_chat to pick a model.",
|
|
80471
|
+
{},
|
|
80472
|
+
async () => {
|
|
80473
|
+
try {
|
|
80474
|
+
const models = await listModels();
|
|
80475
|
+
return { content: [{ type: "text", text: JSON.stringify({ models }) }] };
|
|
80476
|
+
} catch (err) {
|
|
80477
|
+
return errorResult(err);
|
|
80478
|
+
}
|
|
80479
|
+
}
|
|
80480
|
+
);
|
|
80481
|
+
}
|
|
80482
|
+
|
|
80270
80483
|
// src/skills-prompts.ts
|
|
80271
80484
|
var cachedSkills = null;
|
|
80272
80485
|
function getBakedSkills() {
|
|
@@ -80295,10 +80508,10 @@ async function fetchLiveSkillBody(name) {
|
|
|
80295
80508
|
const res = await fetch(`${SKILLS_BASE_URL}/${name}`, { signal: controller.signal });
|
|
80296
80509
|
clearTimeout(timer);
|
|
80297
80510
|
if (!res.ok) return null;
|
|
80298
|
-
const
|
|
80299
|
-
if (!
|
|
80300
|
-
liveBodyCache.set(name,
|
|
80301
|
-
return
|
|
80511
|
+
const body2 = stripFrontmatter(await res.text()).trim();
|
|
80512
|
+
if (!body2) return null;
|
|
80513
|
+
liveBodyCache.set(name, body2);
|
|
80514
|
+
return body2;
|
|
80302
80515
|
} catch {
|
|
80303
80516
|
return null;
|
|
80304
80517
|
}
|
|
@@ -80338,7 +80551,7 @@ CRITICAL: When the user asks to use any external or paid API, names a provider (
|
|
|
80338
80551
|
Spending is the user's own USDC and every t2000_pay call is bounded by maxPrice. For larger or multi-step spends, state the estimated cost first and proceed once the user is happy. Use t2000_balance to check funds. The v4 wallet is payments-only; savings / lending live on audric.ai.`;
|
|
80339
80552
|
|
|
80340
80553
|
// src/index.ts
|
|
80341
|
-
var PKG_VERSION = "5.
|
|
80554
|
+
var PKG_VERSION = "5.15.0" ;
|
|
80342
80555
|
console.log = (...args) => console.error("[log]", ...args);
|
|
80343
80556
|
console.warn = (...args) => console.error("[warn]", ...args);
|
|
80344
80557
|
async function startMcpServer(opts) {
|
|
@@ -80350,6 +80563,7 @@ async function startMcpServer(opts) {
|
|
|
80350
80563
|
registerReadTools(server, agent);
|
|
80351
80564
|
registerWriteTools(server, agent);
|
|
80352
80565
|
registerLimitTool(server);
|
|
80566
|
+
registerChatTools(server);
|
|
80353
80567
|
registerSkillPrompts(server);
|
|
80354
80568
|
const transport = new StdioServerTransport();
|
|
80355
80569
|
await server.connect(transport);
|