@axiom-lattice/client-sdk 1.0.46 → 2.0.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/abstract-client.d.ts +10 -1
- package/dist/abstract-client.d.ts.map +1 -1
- package/dist/abstract-client.js.map +1 -1
- package/dist/client.d.ts +10 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +98 -0
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +49 -1
- package/dist/index.js +158 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +158 -0
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.ts +21 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/wechat-client.d.ts +10 -1
- package/dist/wechat-client.d.ts.map +1 -1
- package/dist/wechat-client.js +72 -0
- package/dist/wechat-client.js.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -2220,6 +2220,98 @@ var Client = class extends AbstractClient {
|
|
|
2220
2220
|
streamRequest(options, onEvent, onComplete, onError) {
|
|
2221
2221
|
return this.streamRun(options, onEvent, onComplete, onError);
|
|
2222
2222
|
}
|
|
2223
|
+
/**
|
|
2224
|
+
* Resume streaming from a known position
|
|
2225
|
+
* @param options - Options for resuming the stream
|
|
2226
|
+
* @param onEvent - Callback function that receives stream events
|
|
2227
|
+
* @param onComplete - Optional callback function called when streaming completes
|
|
2228
|
+
* @param onError - Optional callback function called when an error occurs
|
|
2229
|
+
* @returns A function that can be called to stop the stream
|
|
2230
|
+
*/
|
|
2231
|
+
resumeStream(options, onEvent, onComplete, onError) {
|
|
2232
|
+
const headers = {
|
|
2233
|
+
"Content-Type": "application/json",
|
|
2234
|
+
Accept: "text/event-stream",
|
|
2235
|
+
...this.headers
|
|
2236
|
+
};
|
|
2237
|
+
if (this.tenantId) {
|
|
2238
|
+
headers["x-tenant-id"] = this.tenantId;
|
|
2239
|
+
}
|
|
2240
|
+
const controller = new AbortController();
|
|
2241
|
+
const { signal } = controller;
|
|
2242
|
+
(async () => {
|
|
2243
|
+
try {
|
|
2244
|
+
const response = await fetch(
|
|
2245
|
+
`${this.config.baseURL}/api/resume_stream`,
|
|
2246
|
+
{
|
|
2247
|
+
method: "POST",
|
|
2248
|
+
headers,
|
|
2249
|
+
body: JSON.stringify({
|
|
2250
|
+
thread_id: options.threadId,
|
|
2251
|
+
message_id: options.messageId,
|
|
2252
|
+
known_content: options.knownContent,
|
|
2253
|
+
poll_interval: options.pollInterval || 100
|
|
2254
|
+
}),
|
|
2255
|
+
signal
|
|
2256
|
+
}
|
|
2257
|
+
);
|
|
2258
|
+
if (!response.ok) {
|
|
2259
|
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
2260
|
+
}
|
|
2261
|
+
if (!response.body) {
|
|
2262
|
+
throw new Error("Response body is null");
|
|
2263
|
+
}
|
|
2264
|
+
const reader = response.body.getReader();
|
|
2265
|
+
const decoder = new TextDecoder();
|
|
2266
|
+
let buffer = "";
|
|
2267
|
+
while (true) {
|
|
2268
|
+
const { done, value } = await reader.read();
|
|
2269
|
+
if (done)
|
|
2270
|
+
break;
|
|
2271
|
+
const chunk = decoder.decode(value, { stream: true });
|
|
2272
|
+
buffer += chunk;
|
|
2273
|
+
const lines = buffer.split("\n");
|
|
2274
|
+
buffer = lines.pop() || "";
|
|
2275
|
+
for (const line of lines) {
|
|
2276
|
+
if (line.trim().startsWith("data: ")) {
|
|
2277
|
+
try {
|
|
2278
|
+
const eventData = JSON.parse(line.trim().slice(6));
|
|
2279
|
+
onEvent(eventData);
|
|
2280
|
+
} catch (error) {
|
|
2281
|
+
console.error("Error parsing SSE data:", line, error);
|
|
2282
|
+
if (onError) {
|
|
2283
|
+
onError(
|
|
2284
|
+
error instanceof Error ? error : new Error(String(error))
|
|
2285
|
+
);
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
2291
|
+
if (buffer && buffer.trim().startsWith("data: ")) {
|
|
2292
|
+
try {
|
|
2293
|
+
const eventData = JSON.parse(buffer.trim().slice(6));
|
|
2294
|
+
onEvent(eventData);
|
|
2295
|
+
} catch (error) {
|
|
2296
|
+
console.error("Error parsing SSE data:", buffer, error);
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
if (onComplete) {
|
|
2300
|
+
onComplete();
|
|
2301
|
+
}
|
|
2302
|
+
} catch (error) {
|
|
2303
|
+
if (error instanceof DOMException && error.name === "AbortError") {
|
|
2304
|
+
return;
|
|
2305
|
+
}
|
|
2306
|
+
if (onError) {
|
|
2307
|
+
onError(error instanceof Error ? error : new Error(String(error)));
|
|
2308
|
+
}
|
|
2309
|
+
}
|
|
2310
|
+
})();
|
|
2311
|
+
return () => {
|
|
2312
|
+
controller.abort();
|
|
2313
|
+
};
|
|
2314
|
+
}
|
|
2223
2315
|
/**
|
|
2224
2316
|
* Stream run results
|
|
2225
2317
|
* @param options - Options for streaming run results
|
|
@@ -2370,6 +2462,72 @@ var WeChatClient = class extends AbstractClient {
|
|
|
2370
2462
|
streamRequest(options, onEvent, onComplete, onError) {
|
|
2371
2463
|
return this.streamRun(options, onEvent, onComplete, onError);
|
|
2372
2464
|
}
|
|
2465
|
+
/**
|
|
2466
|
+
* Resume streaming from a known position
|
|
2467
|
+
* @param options - Options for resuming the stream
|
|
2468
|
+
* @param onEvent - Callback function that receives stream events
|
|
2469
|
+
* @param onComplete - Optional callback function called when streaming completes
|
|
2470
|
+
* @param onError - Optional callback function called when an error occurs
|
|
2471
|
+
* @returns A function that can be called to stop the stream
|
|
2472
|
+
*/
|
|
2473
|
+
resumeStream(options, onEvent, onComplete, onError) {
|
|
2474
|
+
const headers = {
|
|
2475
|
+
"Content-Type": "application/json",
|
|
2476
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
|
2477
|
+
...this.config.headers
|
|
2478
|
+
};
|
|
2479
|
+
if (this.tenantId) {
|
|
2480
|
+
headers["x-tenant-id"] = this.tenantId;
|
|
2481
|
+
}
|
|
2482
|
+
const requestTask = wx.request({
|
|
2483
|
+
url: `${this.config.baseURL}/api/resume_stream`,
|
|
2484
|
+
method: "POST",
|
|
2485
|
+
data: {
|
|
2486
|
+
thread_id: options.threadId,
|
|
2487
|
+
message_id: options.messageId,
|
|
2488
|
+
known_content: options.knownContent,
|
|
2489
|
+
poll_interval: options.pollInterval || 100
|
|
2490
|
+
},
|
|
2491
|
+
header: headers,
|
|
2492
|
+
responseType: "text",
|
|
2493
|
+
enableChunked: true,
|
|
2494
|
+
success: () => {
|
|
2495
|
+
},
|
|
2496
|
+
fail: (err) => {
|
|
2497
|
+
if (onError) {
|
|
2498
|
+
onError(new Error(`Resume stream request failed: ${err.errMsg}`));
|
|
2499
|
+
}
|
|
2500
|
+
},
|
|
2501
|
+
complete: () => {
|
|
2502
|
+
if (onComplete) {
|
|
2503
|
+
onComplete();
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2506
|
+
});
|
|
2507
|
+
requestTask.onChunkReceived((res) => {
|
|
2508
|
+
if (!res.data)
|
|
2509
|
+
return;
|
|
2510
|
+
const text = this.decodeUint8Array(res.data);
|
|
2511
|
+
const lines = text.split("\n");
|
|
2512
|
+
for (const line of lines) {
|
|
2513
|
+
if (line.trim().startsWith("data: ")) {
|
|
2514
|
+
try {
|
|
2515
|
+
const eventData = JSON.parse(line.trim().slice(6));
|
|
2516
|
+
onEvent(eventData);
|
|
2517
|
+
} catch (error) {
|
|
2518
|
+
if (onError) {
|
|
2519
|
+
onError(
|
|
2520
|
+
error instanceof Error ? error : new Error(String(error))
|
|
2521
|
+
);
|
|
2522
|
+
}
|
|
2523
|
+
}
|
|
2524
|
+
}
|
|
2525
|
+
}
|
|
2526
|
+
});
|
|
2527
|
+
return () => {
|
|
2528
|
+
requestTask.abort();
|
|
2529
|
+
};
|
|
2530
|
+
}
|
|
2373
2531
|
/**
|
|
2374
2532
|
* Helper method to make WeChat HTTP requests
|
|
2375
2533
|
* @private
|