@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 +14 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -3
- package/dist/index.d.ts +11 -3
- package/dist/index.js +14 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -33,6 +33,9 @@ interface ChatResult {
|
|
|
33
33
|
content: string;
|
|
34
34
|
model: string;
|
|
35
35
|
usage?: ChatUsage;
|
|
36
|
+
/** Confidential calls (`phala/*`) return a TEE attestation receipt id —
|
|
37
|
+
* fetch + verify it at `/v1/aci/receipts/{id}`. Absent for ZDR models. */
|
|
38
|
+
receiptId?: string;
|
|
36
39
|
/** The verbatim OpenAI-shaped response body. */
|
|
37
40
|
raw: unknown;
|
|
38
41
|
}
|
|
@@ -49,7 +52,9 @@ interface ApiModel {
|
|
|
49
52
|
declare function chatCompletion(params: ChatParams): Promise<ChatResult>;
|
|
50
53
|
/** Streaming chat completion — yields assistant text deltas as they arrive
|
|
51
54
|
* (parses the OpenAI SSE `data:` frames). */
|
|
52
|
-
declare function chatCompletionStream(params: ChatParams): AsyncGenerator<string,
|
|
55
|
+
declare function chatCompletionStream(params: ChatParams): AsyncGenerator<string, {
|
|
56
|
+
receiptId?: string;
|
|
57
|
+
}, unknown>;
|
|
53
58
|
/** List the Private API model catalog (`GET /v1/models`). The key is sent when
|
|
54
59
|
* available but not required (the catalog may be public). */
|
|
55
60
|
declare function listModels(opts?: {
|
|
@@ -210,8 +215,11 @@ declare class T2000 extends EventEmitter<T2000Events> {
|
|
|
210
215
|
pay(options: PayOptions): Promise<PayResult>;
|
|
211
216
|
/** Non-streaming chat completion against the Private API. */
|
|
212
217
|
chat(params: ChatParams): Promise<ChatResult>;
|
|
213
|
-
/** Streaming chat completion — async-iterate the assistant text deltas
|
|
214
|
-
|
|
218
|
+
/** Streaming chat completion — async-iterate the assistant text deltas;
|
|
219
|
+
* the generator returns `{ receiptId }` (confidential attestation) at the end. */
|
|
220
|
+
chatStream(params: ChatParams): AsyncGenerator<string, {
|
|
221
|
+
receiptId?: string;
|
|
222
|
+
}, unknown>;
|
|
215
223
|
/** The Private API model catalog (`GET /v1/models`). */
|
|
216
224
|
models(opts?: {
|
|
217
225
|
apiKey?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -33,6 +33,9 @@ interface ChatResult {
|
|
|
33
33
|
content: string;
|
|
34
34
|
model: string;
|
|
35
35
|
usage?: ChatUsage;
|
|
36
|
+
/** Confidential calls (`phala/*`) return a TEE attestation receipt id —
|
|
37
|
+
* fetch + verify it at `/v1/aci/receipts/{id}`. Absent for ZDR models. */
|
|
38
|
+
receiptId?: string;
|
|
36
39
|
/** The verbatim OpenAI-shaped response body. */
|
|
37
40
|
raw: unknown;
|
|
38
41
|
}
|
|
@@ -49,7 +52,9 @@ interface ApiModel {
|
|
|
49
52
|
declare function chatCompletion(params: ChatParams): Promise<ChatResult>;
|
|
50
53
|
/** Streaming chat completion — yields assistant text deltas as they arrive
|
|
51
54
|
* (parses the OpenAI SSE `data:` frames). */
|
|
52
|
-
declare function chatCompletionStream(params: ChatParams): AsyncGenerator<string,
|
|
55
|
+
declare function chatCompletionStream(params: ChatParams): AsyncGenerator<string, {
|
|
56
|
+
receiptId?: string;
|
|
57
|
+
}, unknown>;
|
|
53
58
|
/** List the Private API model catalog (`GET /v1/models`). The key is sent when
|
|
54
59
|
* available but not required (the catalog may be public). */
|
|
55
60
|
declare function listModels(opts?: {
|
|
@@ -210,8 +215,11 @@ declare class T2000 extends EventEmitter<T2000Events> {
|
|
|
210
215
|
pay(options: PayOptions): Promise<PayResult>;
|
|
211
216
|
/** Non-streaming chat completion against the Private API. */
|
|
212
217
|
chat(params: ChatParams): Promise<ChatResult>;
|
|
213
|
-
/** Streaming chat completion — async-iterate the assistant text deltas
|
|
214
|
-
|
|
218
|
+
/** Streaming chat completion — async-iterate the assistant text deltas;
|
|
219
|
+
* the generator returns `{ receiptId }` (confidential attestation) at the end. */
|
|
220
|
+
chatStream(params: ChatParams): AsyncGenerator<string, {
|
|
221
|
+
receiptId?: string;
|
|
222
|
+
}, unknown>;
|
|
215
223
|
/** The Private API model catalog (`GET /v1/models`). */
|
|
216
224
|
models(opts?: {
|
|
217
225
|
apiKey?: string;
|
package/dist/index.js
CHANGED
|
@@ -1928,7 +1928,9 @@ function body(params, stream) {
|
|
|
1928
1928
|
return JSON.stringify({
|
|
1929
1929
|
model: params.model,
|
|
1930
1930
|
messages: params.messages,
|
|
1931
|
-
|
|
1931
|
+
// include_usage → the final stream chunk carries usage + x_receipt_id
|
|
1932
|
+
// (the confidential attestation receipt) so we can surface it after a stream.
|
|
1933
|
+
...stream ? { stream: true, stream_options: { include_usage: true } } : {},
|
|
1932
1934
|
...params.maxTokens != null ? { max_tokens: params.maxTokens } : {},
|
|
1933
1935
|
...params.temperature != null ? { temperature: params.temperature } : {}
|
|
1934
1936
|
});
|
|
@@ -1944,12 +1946,14 @@ async function chatCompletion(params) {
|
|
|
1944
1946
|
if (!res.ok) {
|
|
1945
1947
|
await failBody(res);
|
|
1946
1948
|
}
|
|
1949
|
+
const receiptId = res.headers.get("x-receipt-id") ?? void 0;
|
|
1947
1950
|
const raw = await res.json();
|
|
1948
1951
|
const content = raw?.choices?.[0]?.message?.content ?? "";
|
|
1949
1952
|
return {
|
|
1950
1953
|
content,
|
|
1951
1954
|
model: raw?.model ?? params.model,
|
|
1952
1955
|
usage: usageOf(raw),
|
|
1956
|
+
receiptId,
|
|
1953
1957
|
raw
|
|
1954
1958
|
};
|
|
1955
1959
|
}
|
|
@@ -1963,11 +1967,12 @@ async function* chatCompletionStream(params) {
|
|
|
1963
1967
|
});
|
|
1964
1968
|
if (!(res.ok && res.body)) {
|
|
1965
1969
|
await failBody(res);
|
|
1966
|
-
return;
|
|
1970
|
+
return {};
|
|
1967
1971
|
}
|
|
1968
1972
|
const reader = res.body.getReader();
|
|
1969
1973
|
const decoder = new TextDecoder();
|
|
1970
1974
|
let buffer = "";
|
|
1975
|
+
let receiptId;
|
|
1971
1976
|
while (true) {
|
|
1972
1977
|
const { done, value } = await reader.read();
|
|
1973
1978
|
if (done) {
|
|
@@ -1983,10 +1988,13 @@ async function* chatCompletionStream(params) {
|
|
|
1983
1988
|
}
|
|
1984
1989
|
const data = trimmed.slice(5).trim();
|
|
1985
1990
|
if (data === "[DONE]") {
|
|
1986
|
-
return;
|
|
1991
|
+
return { receiptId };
|
|
1987
1992
|
}
|
|
1988
1993
|
try {
|
|
1989
1994
|
const json = JSON.parse(data);
|
|
1995
|
+
if (json.x_receipt_id) {
|
|
1996
|
+
receiptId = json.x_receipt_id;
|
|
1997
|
+
}
|
|
1990
1998
|
const delta = json.choices?.[0]?.delta?.content;
|
|
1991
1999
|
if (typeof delta === "string" && delta) {
|
|
1992
2000
|
yield delta;
|
|
@@ -1995,6 +2003,7 @@ async function* chatCompletionStream(params) {
|
|
|
1995
2003
|
}
|
|
1996
2004
|
}
|
|
1997
2005
|
}
|
|
2006
|
+
return { receiptId };
|
|
1998
2007
|
}
|
|
1999
2008
|
async function listModels(opts) {
|
|
2000
2009
|
const base = opts?.apiBase ?? DEFAULT_API_BASE;
|
|
@@ -2291,7 +2300,8 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
2291
2300
|
async chat(params) {
|
|
2292
2301
|
return chatCompletion(params);
|
|
2293
2302
|
}
|
|
2294
|
-
/** Streaming chat completion — async-iterate the assistant text deltas
|
|
2303
|
+
/** Streaming chat completion — async-iterate the assistant text deltas;
|
|
2304
|
+
* the generator returns `{ receiptId }` (confidential attestation) at the end. */
|
|
2295
2305
|
chatStream(params) {
|
|
2296
2306
|
return chatCompletionStream(params);
|
|
2297
2307
|
}
|