@axiom-lattice/client-sdk 1.0.44 → 1.0.46

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.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: options.command,
1895
- background: options.background,
1896
- enableReturnStateWhenSteamCompleted: options.enableReturnStateWhenSteamCompleted
1902
+ command,
1903
+ background,
1904
+ enableReturnStateWhenSteamCompleted,
1905
+ ...rest
1897
1906
  },
1898
1907
  onEvent,
1899
1908
  onComplete,
@@ -2426,14 +2435,14 @@ var WeChatClient = class extends AbstractClient {
2426
2435
  headers["x-tenant-id"] = this.tenantId;
2427
2436
  }
2428
2437
  const requestParams = this.buildStreamRequestParams(options);
2429
- const taskId = wx.request({
2438
+ const requestTask = wx.request({
2430
2439
  url: `${this.config.baseURL}${requestParams.url}`,
2431
2440
  method: requestParams.method,
2432
2441
  data: requestParams.body,
2433
2442
  header: headers,
2434
2443
  responseType: "text",
2435
2444
  enableChunked: true,
2436
- success: async () => {
2445
+ success: () => {
2437
2446
  },
2438
2447
  fail: (err) => {
2439
2448
  if (onError) {
@@ -2453,35 +2462,30 @@ var WeChatClient = class extends AbstractClient {
2453
2462
  onComplete();
2454
2463
  }
2455
2464
  }
2456
- },
2457
- // Using WeChat's chunked data capability
2458
- dataReceived: (res) => {
2459
- if (!res.data)
2460
- return;
2461
- const text = this.decodeUint8Array(res.data);
2462
- const lines = text.split("\n");
2463
- for (const line of lines) {
2464
- if (line.trim().startsWith("data: ")) {
2465
- try {
2466
- const eventData = JSON.parse(line.trim().slice(6));
2467
- onEvent(eventData);
2468
- } catch (error) {
2469
- if (onError) {
2470
- onError(
2471
- error instanceof Error ? error : new Error(String(error))
2472
- );
2473
- }
2465
+ }
2466
+ });
2467
+ requestTask.onChunkReceived((res) => {
2468
+ if (!res.data)
2469
+ return;
2470
+ const text = this.decodeUint8Array(res.data);
2471
+ const lines = text.split("\n");
2472
+ for (const line of lines) {
2473
+ if (line.trim().startsWith("data: ")) {
2474
+ try {
2475
+ const eventData = JSON.parse(line.trim().slice(6));
2476
+ onEvent(eventData);
2477
+ } catch (error) {
2478
+ if (onError) {
2479
+ onError(
2480
+ error instanceof Error ? error : new Error(String(error))
2481
+ );
2474
2482
  }
2475
2483
  }
2476
2484
  }
2477
2485
  }
2478
2486
  });
2479
2487
  return () => {
2480
- wx.abortRequest({
2481
- requestId: taskId,
2482
- success: () => console.log("Stream request aborted"),
2483
- fail: (err) => console.error("Failed to abort stream request:", err.errMsg)
2484
- });
2488
+ requestTask.abort();
2485
2489
  };
2486
2490
  }
2487
2491
  decodeUint8Array(uint8Array) {
@@ -2496,9 +2500,9 @@ var WeChatClient = class extends AbstractClient {
2496
2500
  ).join("");
2497
2501
  }
2498
2502
  /**
2499
- * 十六进制字符串转中文
2500
- * @param {String} hex 为十六进制字符串
2501
- * @return {String} 包含中文的字符串
2503
+ * Convert hexadecimal string to text (supports Chinese characters)
2504
+ * @param {String} hex - Hexadecimal string
2505
+ * @return {String} Decoded string including Chinese characters
2502
2506
  */
2503
2507
  hexToStr(hex) {
2504
2508
  let trimedStr = hex.trim();
@@ -2699,7 +2703,7 @@ function createSimpleMessageMerger() {
2699
2703
  );
2700
2704
  }
2701
2705
  function reset() {
2702
- messages.length = 0;
2706
+ messages = [];
2703
2707
  messageMap.clear();
2704
2708
  toolBuilders.clear();
2705
2709
  }