@axiom-lattice/client-sdk 1.0.45 → 1.0.50
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/ChunkMessageMerger.js +1 -1
- package/dist/ChunkMessageMerger.js.map +1 -1
- package/dist/abstract-client.d.ts +10 -1
- package/dist/abstract-client.d.ts.map +1 -1
- package/dist/abstract-client.js +5 -3
- 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 +50 -1
- package/dist/index.js +171 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +171 -4
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.ts +22 -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
|
@@ -1885,15 +1885,24 @@ var AbstractClient = class {
|
|
|
1885
1885
|
* @returns A function that can be called to stop the stream
|
|
1886
1886
|
*/
|
|
1887
1887
|
stream: (options, onEvent, onComplete, onError) => {
|
|
1888
|
+
const {
|
|
1889
|
+
command,
|
|
1890
|
+
threadId,
|
|
1891
|
+
files,
|
|
1892
|
+
background,
|
|
1893
|
+
enableReturnStateWhenSteamCompleted,
|
|
1894
|
+
...rest
|
|
1895
|
+
} = options;
|
|
1888
1896
|
const message = options.messages[options.messages.length - 1];
|
|
1889
1897
|
return this.streamRequest(
|
|
1890
1898
|
{
|
|
1891
1899
|
threadId: options.threadId,
|
|
1892
1900
|
message: typeof message.content === "string" ? message.content : JSON.stringify(message.content),
|
|
1893
1901
|
streaming: true,
|
|
1894
|
-
command
|
|
1895
|
-
background
|
|
1896
|
-
enableReturnStateWhenSteamCompleted
|
|
1902
|
+
command,
|
|
1903
|
+
background,
|
|
1904
|
+
enableReturnStateWhenSteamCompleted,
|
|
1905
|
+
...rest
|
|
1897
1906
|
},
|
|
1898
1907
|
onEvent,
|
|
1899
1908
|
onComplete,
|
|
@@ -2211,6 +2220,98 @@ var Client = class extends AbstractClient {
|
|
|
2211
2220
|
streamRequest(options, onEvent, onComplete, onError) {
|
|
2212
2221
|
return this.streamRun(options, onEvent, onComplete, onError);
|
|
2213
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
|
+
}
|
|
2214
2315
|
/**
|
|
2215
2316
|
* Stream run results
|
|
2216
2317
|
* @param options - Options for streaming run results
|
|
@@ -2361,6 +2462,72 @@ var WeChatClient = class extends AbstractClient {
|
|
|
2361
2462
|
streamRequest(options, onEvent, onComplete, onError) {
|
|
2362
2463
|
return this.streamRun(options, onEvent, onComplete, onError);
|
|
2363
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
|
+
}
|
|
2364
2531
|
/**
|
|
2365
2532
|
* Helper method to make WeChat HTTP requests
|
|
2366
2533
|
* @private
|
|
@@ -2694,7 +2861,7 @@ function createSimpleMessageMerger() {
|
|
|
2694
2861
|
);
|
|
2695
2862
|
}
|
|
2696
2863
|
function reset() {
|
|
2697
|
-
messages
|
|
2864
|
+
messages = [];
|
|
2698
2865
|
messageMap.clear();
|
|
2699
2866
|
toolBuilders.clear();
|
|
2700
2867
|
}
|