@t2000/sdk 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.cjs CHANGED
@@ -1934,7 +1934,9 @@ function body(params, stream) {
1934
1934
  return JSON.stringify({
1935
1935
  model: params.model,
1936
1936
  messages: params.messages,
1937
- ...stream ? { stream: true } : {},
1937
+ // include_usage the final stream chunk carries usage + x_receipt_id
1938
+ // (the confidential attestation receipt) so we can surface it after a stream.
1939
+ ...stream ? { stream: true, stream_options: { include_usage: true } } : {},
1938
1940
  ...params.maxTokens != null ? { max_tokens: params.maxTokens } : {},
1939
1941
  ...params.temperature != null ? { temperature: params.temperature } : {}
1940
1942
  });
@@ -1950,12 +1952,14 @@ async function chatCompletion(params) {
1950
1952
  if (!res.ok) {
1951
1953
  await failBody(res);
1952
1954
  }
1955
+ const receiptId = res.headers.get("x-receipt-id") ?? void 0;
1953
1956
  const raw = await res.json();
1954
1957
  const content = raw?.choices?.[0]?.message?.content ?? "";
1955
1958
  return {
1956
1959
  content,
1957
1960
  model: raw?.model ?? params.model,
1958
1961
  usage: usageOf(raw),
1962
+ receiptId,
1959
1963
  raw
1960
1964
  };
1961
1965
  }
@@ -1969,11 +1973,12 @@ async function* chatCompletionStream(params) {
1969
1973
  });
1970
1974
  if (!(res.ok && res.body)) {
1971
1975
  await failBody(res);
1972
- return;
1976
+ return {};
1973
1977
  }
1974
1978
  const reader = res.body.getReader();
1975
1979
  const decoder = new TextDecoder();
1976
1980
  let buffer = "";
1981
+ let receiptId;
1977
1982
  while (true) {
1978
1983
  const { done, value } = await reader.read();
1979
1984
  if (done) {
@@ -1989,10 +1994,13 @@ async function* chatCompletionStream(params) {
1989
1994
  }
1990
1995
  const data = trimmed.slice(5).trim();
1991
1996
  if (data === "[DONE]") {
1992
- return;
1997
+ return { receiptId };
1993
1998
  }
1994
1999
  try {
1995
2000
  const json = JSON.parse(data);
2001
+ if (json.x_receipt_id) {
2002
+ receiptId = json.x_receipt_id;
2003
+ }
1996
2004
  const delta = json.choices?.[0]?.delta?.content;
1997
2005
  if (typeof delta === "string" && delta) {
1998
2006
  yield delta;
@@ -2001,6 +2009,7 @@ async function* chatCompletionStream(params) {
2001
2009
  }
2002
2010
  }
2003
2011
  }
2012
+ return { receiptId };
2004
2013
  }
2005
2014
  async function listModels(opts) {
2006
2015
  const base = opts?.apiBase ?? DEFAULT_API_BASE;
@@ -2297,7 +2306,8 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
2297
2306
  async chat(params) {
2298
2307
  return chatCompletion(params);
2299
2308
  }
2300
- /** Streaming chat completion — async-iterate the assistant text deltas. */
2309
+ /** Streaming chat completion — async-iterate the assistant text deltas;
2310
+ * the generator returns `{ receiptId }` (confidential attestation) at the end. */
2301
2311
  chatStream(params) {
2302
2312
  return chatCompletionStream(params);
2303
2313
  }