@t2000/cli 5.15.0 → 5.16.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/index.js CHANGED
@@ -28340,7 +28340,9 @@ function body(params, stream) {
28340
28340
  return JSON.stringify({
28341
28341
  model: params.model,
28342
28342
  messages: params.messages,
28343
- ...stream ? { stream: true } : {},
28343
+ // include_usage the final stream chunk carries usage + x_receipt_id
28344
+ // (the confidential attestation receipt) so we can surface it after a stream.
28345
+ ...stream ? { stream: true, stream_options: { include_usage: true } } : {},
28344
28346
  ...params.maxTokens != null ? { max_tokens: params.maxTokens } : {},
28345
28347
  ...params.temperature != null ? { temperature: params.temperature } : {}
28346
28348
  });
@@ -28356,12 +28358,14 @@ async function chatCompletion(params) {
28356
28358
  if (!res.ok) {
28357
28359
  await failBody(res);
28358
28360
  }
28361
+ const receiptId = res.headers.get("x-receipt-id") ?? void 0;
28359
28362
  const raw = await res.json();
28360
28363
  const content = raw?.choices?.[0]?.message?.content ?? "";
28361
28364
  return {
28362
28365
  content,
28363
28366
  model: raw?.model ?? params.model,
28364
28367
  usage: usageOf(raw),
28368
+ receiptId,
28365
28369
  raw
28366
28370
  };
28367
28371
  }
@@ -28375,11 +28379,12 @@ async function* chatCompletionStream(params) {
28375
28379
  });
28376
28380
  if (!(res.ok && res.body)) {
28377
28381
  await failBody(res);
28378
- return;
28382
+ return {};
28379
28383
  }
28380
28384
  const reader = res.body.getReader();
28381
28385
  const decoder = new TextDecoder();
28382
28386
  let buffer = "";
28387
+ let receiptId;
28383
28388
  while (true) {
28384
28389
  const { done, value } = await reader.read();
28385
28390
  if (done) {
@@ -28395,10 +28400,13 @@ async function* chatCompletionStream(params) {
28395
28400
  }
28396
28401
  const data = trimmed.slice(5).trim();
28397
28402
  if (data === "[DONE]") {
28398
- return;
28403
+ return { receiptId };
28399
28404
  }
28400
28405
  try {
28401
28406
  const json = JSON.parse(data);
28407
+ if (json.x_receipt_id) {
28408
+ receiptId = json.x_receipt_id;
28409
+ }
28402
28410
  const delta = json.choices?.[0]?.delta?.content;
28403
28411
  if (typeof delta === "string" && delta) {
28404
28412
  yield delta;
@@ -28407,6 +28415,7 @@ async function* chatCompletionStream(params) {
28407
28415
  }
28408
28416
  }
28409
28417
  }
28418
+ return { receiptId };
28410
28419
  }
28411
28420
  async function listModels(opts) {
28412
28421
  const base = opts?.apiBase ?? DEFAULT_API_BASE;
@@ -28699,7 +28708,8 @@ var T2000 = class _T2000 extends import_index2.default {
28699
28708
  async chat(params) {
28700
28709
  return chatCompletion(params);
28701
28710
  }
28702
- /** Streaming chat completion — async-iterate the assistant text deltas. */
28711
+ /** Streaming chat completion — async-iterate the assistant text deltas;
28712
+ * the generator returns `{ receiptId }` (confidential attestation) at the end. */
28703
28713
  chatStream(params) {
28704
28714
  return chatCompletionStream(params);
28705
28715
  }
@@ -32377,6 +32387,12 @@ function describeSchemaFields(schema) {
32377
32387
  }
32378
32388
 
32379
32389
  // src/commands/chat.ts
32390
+ var import_picocolors9 = __toESM(require_picocolors(), 1);
32391
+ function receiptLine(receiptId) {
32392
+ if (receiptId) {
32393
+ printLine(import_picocolors9.default.dim(`\u{1F512} confidential \xB7 attested \xB7 receipt ${receiptId}`));
32394
+ }
32395
+ }
32380
32396
  var DEFAULT_MODEL = "zai/glm-5.2";
32381
32397
  function numOrUndef(v) {
32382
32398
  if (v === void 0) {
@@ -32407,20 +32423,30 @@ function registerChat(program3) {
32407
32423
  if (isJsonMode() || opts.stream === false) {
32408
32424
  const res = await chatCompletion(params);
32409
32425
  if (isJsonMode()) {
32410
- printJson({ model: res.model, content: res.content, usage: res.usage });
32426
+ printJson({
32427
+ model: res.model,
32428
+ content: res.content,
32429
+ usage: res.usage,
32430
+ receiptId: res.receiptId
32431
+ });
32411
32432
  return;
32412
32433
  }
32413
32434
  printBlank();
32414
32435
  printLine(res.content);
32436
+ receiptLine(res.receiptId);
32415
32437
  printBlank();
32416
32438
  return;
32417
32439
  }
32440
+ const gen = chatCompletionStream(params);
32418
32441
  let any = false;
32419
- for await (const delta of chatCompletionStream(params)) {
32420
- process.stdout.write(delta);
32442
+ let next = await gen.next();
32443
+ while (!next.done) {
32444
+ process.stdout.write(next.value);
32421
32445
  any = true;
32446
+ next = await gen.next();
32422
32447
  }
32423
32448
  process.stdout.write(any ? "\n" : "");
32449
+ receiptLine(next.value?.receiptId);
32424
32450
  } catch (error) {
32425
32451
  handleError(error);
32426
32452
  }
@@ -32433,9 +32459,10 @@ function registerChat(program3) {
32433
32459
  printJson({ models });
32434
32460
  return;
32435
32461
  }
32462
+ const usd = (n) => n == null ? "?" : `$${Number(n.toFixed(4))}`;
32436
32463
  printBlank();
32437
32464
  for (const m of models) {
32438
- const price = m.inputPer1M != null ? ` \u2014 $${m.inputPer1M}/$${m.outputPer1M} per 1M` : "";
32465
+ const price = m.inputPer1M != null ? ` \u2014 ${usd(m.inputPer1M)}/${usd(m.outputPer1M)} per 1M` : "";
32439
32466
  const priv = m.privacy ? ` [${m.privacy}]` : "";
32440
32467
  printLine(` ${m.id}${priv}${price}`);
32441
32468
  }
@@ -32447,7 +32474,7 @@ function registerChat(program3) {
32447
32474
  }
32448
32475
 
32449
32476
  // src/commands/services/search.ts
32450
- var import_picocolors9 = __toESM(require_picocolors(), 1);
32477
+ var import_picocolors10 = __toESM(require_picocolors(), 1);
32451
32478
 
32452
32479
  // src/commands/services/catalog.ts
32453
32480
  var DEFAULT_GATEWAY_URL = "https://mpp.t2000.ai";
@@ -32549,9 +32576,9 @@ Examples:
32549
32576
  }
32550
32577
  function renderServiceLine(svc) {
32551
32578
  const minPrice = cheapestEndpointPrice(svc);
32552
- const priceTag = minPrice !== null ? import_picocolors9.default.green(`from $${minPrice}`) : import_picocolors9.default.dim("no pricing");
32553
- const catTag = svc.categories.length > 0 ? import_picocolors9.default.dim(`[${svc.categories.join(", ")}]`) : "";
32554
- printKeyValue(import_picocolors9.default.bold(svc.name), `${priceTag} ${catTag}`);
32579
+ const priceTag = minPrice !== null ? import_picocolors10.default.green(`from $${minPrice}`) : import_picocolors10.default.dim("no pricing");
32580
+ const catTag = svc.categories.length > 0 ? import_picocolors10.default.dim(`[${svc.categories.join(", ")}]`) : "";
32581
+ printKeyValue(import_picocolors10.default.bold(svc.name), `${priceTag} ${catTag}`);
32555
32582
  printKeyValue(" url", svc.serviceUrl);
32556
32583
  printKeyValue(" about", svc.description);
32557
32584
  printBlank();
@@ -32565,7 +32592,7 @@ function cheapestEndpointPrice(svc) {
32565
32592
  }
32566
32593
 
32567
32594
  // src/commands/services/inspect.ts
32568
- var import_picocolors10 = __toESM(require_picocolors(), 1);
32595
+ var import_picocolors11 = __toESM(require_picocolors(), 1);
32569
32596
  function registerServicesInspect(parent) {
32570
32597
  parent.command("inspect").description("Show pricing + endpoints for an MPP service or endpoint URL").argument("<url>", "Service base URL or endpoint URL").option("--gateway <url>", "Override gateway base URL (default: https://mpp.t2000.ai)").addHelpText(
32571
32598
  "after",
@@ -32602,7 +32629,7 @@ Examples:
32602
32629
  return;
32603
32630
  }
32604
32631
  printBlank();
32605
- printKeyValue("Service", import_picocolors10.default.bold(service.name));
32632
+ printKeyValue("Service", import_picocolors11.default.bold(service.name));
32606
32633
  printKeyValue("URL", service.serviceUrl);
32607
32634
  printKeyValue("About", service.description);
32608
32635
  if (service.categories.length > 0) {
@@ -32632,7 +32659,7 @@ Examples:
32632
32659
  function renderEndpoint(ep, serviceUrl) {
32633
32660
  const price = `$${ep.price}`;
32634
32661
  const label = `${ep.method} ${ep.path}`.padEnd(40);
32635
- printKeyValue(label, `${import_picocolors10.default.green(price)} ${import_picocolors10.default.dim(ep.description)}`);
32662
+ printKeyValue(label, `${import_picocolors11.default.green(price)} ${import_picocolors11.default.dim(ep.description)}`);
32636
32663
  printKeyValue(" url", `${serviceUrl}${ep.path}`);
32637
32664
  printBlank();
32638
32665
  }
@@ -32655,7 +32682,7 @@ T2000_GATEWAY_URL or --gateway <url> for local development.
32655
32682
  }
32656
32683
 
32657
32684
  // src/commands/limit/show.ts
32658
- var import_picocolors11 = __toESM(require_picocolors(), 1);
32685
+ var import_picocolors12 = __toESM(require_picocolors(), 1);
32659
32686
  function registerLimitShow(parent) {
32660
32687
  parent.command("show").description("Show current spending limits").action(async (opts) => {
32661
32688
  try {
@@ -32678,10 +32705,10 @@ function registerLimitShow(parent) {
32678
32705
  }
32679
32706
  printBlank();
32680
32707
  if (limits.perTxUsd !== void 0) {
32681
- printKeyValue("Per-transaction", import_picocolors11.default.green(`$${limits.perTxUsd}`));
32708
+ printKeyValue("Per-transaction", import_picocolors12.default.green(`$${limits.perTxUsd}`));
32682
32709
  }
32683
32710
  if (limits.dailyUsd !== void 0) {
32684
- printKeyValue("Daily (cumulative)", import_picocolors11.default.green(`$${limits.dailyUsd}`));
32711
+ printKeyValue("Daily (cumulative)", import_picocolors12.default.green(`$${limits.dailyUsd}`));
32685
32712
  }
32686
32713
  printBlank();
32687
32714
  printInfo("Use `--force` on `t2 send` / `t2 swap` / `t2 pay` to override per-call.");
@@ -32693,7 +32720,7 @@ function registerLimitShow(parent) {
32693
32720
  }
32694
32721
 
32695
32722
  // src/commands/limit/set.ts
32696
- var import_picocolors12 = __toESM(require_picocolors(), 1);
32723
+ var import_picocolors13 = __toESM(require_picocolors(), 1);
32697
32724
  function parseLimitSetArgs(opts) {
32698
32725
  const perTx = opts.perTx !== void 0 ? parseUsdFlag("--per-tx", opts.perTx) : void 0;
32699
32726
  const daily = opts.daily !== void 0 ? parseUsdFlag("--daily", opts.daily) : void 0;
@@ -32735,10 +32762,10 @@ Examples:
32735
32762
  printBlank();
32736
32763
  printSuccess("Spending limits updated.");
32737
32764
  if (next?.perTxUsd !== void 0) {
32738
- printKeyValue("Per-transaction", import_picocolors12.default.green(`$${next.perTxUsd}`));
32765
+ printKeyValue("Per-transaction", import_picocolors13.default.green(`$${next.perTxUsd}`));
32739
32766
  }
32740
32767
  if (next?.dailyUsd !== void 0) {
32741
- printKeyValue("Daily (cumulative)", import_picocolors12.default.green(`$${next.dailyUsd}`));
32768
+ printKeyValue("Daily (cumulative)", import_picocolors13.default.green(`$${next.dailyUsd}`));
32742
32769
  }
32743
32770
  printBlank();
32744
32771
  printInfo("Use `t2 limit show` to view; `t2 limit reset` to clear.");
@@ -32800,7 +32827,7 @@ function registerMcpStart(parent) {
32800
32827
  parent.command("start", { isDefault: true }).description("Start MCP server (stdio transport \u2014 for AI client integration)").option("--key <path>", "Custom wallet path (default ~/.t2000/wallet.key)").action(async (opts) => {
32801
32828
  let mod2;
32802
32829
  try {
32803
- mod2 = await import("./dist-UVKQOQSP.js");
32830
+ mod2 = await import("./dist-UPUBYGXT.js");
32804
32831
  } catch {
32805
32832
  console.error("MCP server not installed. Run:\n npm install -g @t2000/mcp");
32806
32833
  process.exit(1);