@yushaw/sanqian-sdk 0.2.1 → 0.2.2

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.d.mts CHANGED
@@ -526,4 +526,67 @@ declare class DiscoveryManager {
526
526
  isSanqianRunning(): boolean;
527
527
  }
528
528
 
529
- export { type AgentConfig, type AgentInfo, type AgentUpdateConfig, type ChatMessage, type ChatRequest, type ChatResponse, type ChatStreamEvent, type ConnectionInfo, type ConnectionState, Conversation, type ConversationDetail, type ConversationInfo, type ConversationMessage, DiscoveryManager, type JSONSchema, type JSONSchemaProperty, type RemoteToolDefinition, type SDKConfig, type SDKEventName, type SDKEvents, SanqianSDK, type ToolCall, type ToolDefinition };
529
+ /**
530
+ * SDK Error Messages
531
+ *
532
+ * User-friendly error messages in English and Chinese.
533
+ * All errors guide users to sanqian.io for installation.
534
+ */
535
+ declare const SANQIAN_WEBSITE = "https://sanqian.io";
536
+ /**
537
+ * Error codes for SDK errors
538
+ */
539
+ declare enum SDKErrorCode {
540
+ NOT_INSTALLED = "NOT_INSTALLED",
541
+ NOT_RUNNING = "NOT_RUNNING",
542
+ CONNECTION_TIMEOUT = "CONNECTION_TIMEOUT",
543
+ STARTUP_TIMEOUT = "STARTUP_TIMEOUT",
544
+ REGISTRATION_FAILED = "REGISTRATION_FAILED",
545
+ REQUEST_TIMEOUT = "REQUEST_TIMEOUT",
546
+ REQUEST_FAILED = "REQUEST_FAILED",
547
+ DISCONNECTED = "DISCONNECTED",
548
+ WEBSOCKET_ERROR = "WEBSOCKET_ERROR",
549
+ AGENT_NOT_FOUND = "AGENT_NOT_FOUND",
550
+ CONVERSATION_NOT_FOUND = "CONVERSATION_NOT_FOUND",
551
+ TOOL_NOT_FOUND = "TOOL_NOT_FOUND",
552
+ TOOL_EXECUTION_TIMEOUT = "TOOL_EXECUTION_TIMEOUT"
553
+ }
554
+ /**
555
+ * Bilingual error messages
556
+ */
557
+ declare const ErrorMessages: Record<SDKErrorCode, {
558
+ en: string;
559
+ zh: string;
560
+ hint?: {
561
+ en: string;
562
+ zh: string;
563
+ };
564
+ }>;
565
+ /**
566
+ * Custom SDK Error with code and bilingual message
567
+ */
568
+ declare class SanqianSDKError extends Error {
569
+ code: SDKErrorCode;
570
+ messageZh: string;
571
+ hint?: string;
572
+ hintZh?: string;
573
+ constructor(code: SDKErrorCode, details?: string);
574
+ /**
575
+ * Get full error message with hint (English)
576
+ */
577
+ getFullMessage(): string;
578
+ /**
579
+ * Get full error message with hint (Chinese)
580
+ */
581
+ getFullMessageZh(): string;
582
+ /**
583
+ * Get bilingual error message
584
+ */
585
+ getBilingualMessage(): string;
586
+ }
587
+ /**
588
+ * Create a user-friendly SDK error
589
+ */
590
+ declare function createSDKError(code: SDKErrorCode, details?: string): SanqianSDKError;
591
+
592
+ export { type AgentConfig, type AgentInfo, type AgentUpdateConfig, type ChatMessage, type ChatRequest, type ChatResponse, type ChatStreamEvent, type ConnectionInfo, type ConnectionState, Conversation, type ConversationDetail, type ConversationInfo, type ConversationMessage, DiscoveryManager, ErrorMessages, type JSONSchema, type JSONSchemaProperty, type RemoteToolDefinition, SANQIAN_WEBSITE, type SDKConfig, SDKErrorCode, type SDKEventName, type SDKEvents, SanqianSDK, SanqianSDKError, type ToolCall, type ToolDefinition, createSDKError };
package/dist/index.d.ts CHANGED
@@ -526,4 +526,67 @@ declare class DiscoveryManager {
526
526
  isSanqianRunning(): boolean;
527
527
  }
528
528
 
529
- export { type AgentConfig, type AgentInfo, type AgentUpdateConfig, type ChatMessage, type ChatRequest, type ChatResponse, type ChatStreamEvent, type ConnectionInfo, type ConnectionState, Conversation, type ConversationDetail, type ConversationInfo, type ConversationMessage, DiscoveryManager, type JSONSchema, type JSONSchemaProperty, type RemoteToolDefinition, type SDKConfig, type SDKEventName, type SDKEvents, SanqianSDK, type ToolCall, type ToolDefinition };
529
+ /**
530
+ * SDK Error Messages
531
+ *
532
+ * User-friendly error messages in English and Chinese.
533
+ * All errors guide users to sanqian.io for installation.
534
+ */
535
+ declare const SANQIAN_WEBSITE = "https://sanqian.io";
536
+ /**
537
+ * Error codes for SDK errors
538
+ */
539
+ declare enum SDKErrorCode {
540
+ NOT_INSTALLED = "NOT_INSTALLED",
541
+ NOT_RUNNING = "NOT_RUNNING",
542
+ CONNECTION_TIMEOUT = "CONNECTION_TIMEOUT",
543
+ STARTUP_TIMEOUT = "STARTUP_TIMEOUT",
544
+ REGISTRATION_FAILED = "REGISTRATION_FAILED",
545
+ REQUEST_TIMEOUT = "REQUEST_TIMEOUT",
546
+ REQUEST_FAILED = "REQUEST_FAILED",
547
+ DISCONNECTED = "DISCONNECTED",
548
+ WEBSOCKET_ERROR = "WEBSOCKET_ERROR",
549
+ AGENT_NOT_FOUND = "AGENT_NOT_FOUND",
550
+ CONVERSATION_NOT_FOUND = "CONVERSATION_NOT_FOUND",
551
+ TOOL_NOT_FOUND = "TOOL_NOT_FOUND",
552
+ TOOL_EXECUTION_TIMEOUT = "TOOL_EXECUTION_TIMEOUT"
553
+ }
554
+ /**
555
+ * Bilingual error messages
556
+ */
557
+ declare const ErrorMessages: Record<SDKErrorCode, {
558
+ en: string;
559
+ zh: string;
560
+ hint?: {
561
+ en: string;
562
+ zh: string;
563
+ };
564
+ }>;
565
+ /**
566
+ * Custom SDK Error with code and bilingual message
567
+ */
568
+ declare class SanqianSDKError extends Error {
569
+ code: SDKErrorCode;
570
+ messageZh: string;
571
+ hint?: string;
572
+ hintZh?: string;
573
+ constructor(code: SDKErrorCode, details?: string);
574
+ /**
575
+ * Get full error message with hint (English)
576
+ */
577
+ getFullMessage(): string;
578
+ /**
579
+ * Get full error message with hint (Chinese)
580
+ */
581
+ getFullMessageZh(): string;
582
+ /**
583
+ * Get bilingual error message
584
+ */
585
+ getBilingualMessage(): string;
586
+ }
587
+ /**
588
+ * Create a user-friendly SDK error
589
+ */
590
+ declare function createSDKError(code: SDKErrorCode, details?: string): SanqianSDKError;
591
+
592
+ export { type AgentConfig, type AgentInfo, type AgentUpdateConfig, type ChatMessage, type ChatRequest, type ChatResponse, type ChatStreamEvent, type ConnectionInfo, type ConnectionState, Conversation, type ConversationDetail, type ConversationInfo, type ConversationMessage, DiscoveryManager, ErrorMessages, type JSONSchema, type JSONSchemaProperty, type RemoteToolDefinition, SANQIAN_WEBSITE, type SDKConfig, SDKErrorCode, type SDKEventName, type SDKEvents, SanqianSDK, SanqianSDKError, type ToolCall, type ToolDefinition, createSDKError };
package/dist/index.js CHANGED
@@ -32,7 +32,12 @@ var index_exports = {};
32
32
  __export(index_exports, {
33
33
  Conversation: () => Conversation,
34
34
  DiscoveryManager: () => DiscoveryManager,
35
- SanqianSDK: () => SanqianSDK
35
+ ErrorMessages: () => ErrorMessages,
36
+ SANQIAN_WEBSITE: () => SANQIAN_WEBSITE,
37
+ SDKErrorCode: () => SDKErrorCode,
38
+ SanqianSDK: () => SanqianSDK,
39
+ SanqianSDKError: () => SanqianSDKError,
40
+ createSDKError: () => createSDKError
36
41
  });
37
42
  module.exports = __toCommonJS(index_exports);
38
43
 
@@ -271,7 +276,7 @@ var DiscoveryManager = class {
271
276
  "/Contents/MacOS/Sanqian",
272
277
  ""
273
278
  );
274
- (0, import_child_process.spawn)("open", ["-a", appPath, "--args", "--hidden"], {
279
+ (0, import_child_process.spawn)("open", ["-g", "-a", appPath, "--args", "--hidden"], {
275
280
  detached: true,
276
281
  stdio: "ignore"
277
282
  }).unref();
@@ -300,6 +305,172 @@ var DiscoveryManager = class {
300
305
  }
301
306
  };
302
307
 
308
+ // src/errors.ts
309
+ var SANQIAN_WEBSITE = "https://sanqian.io";
310
+ var SDKErrorCode = /* @__PURE__ */ ((SDKErrorCode2) => {
311
+ SDKErrorCode2["NOT_INSTALLED"] = "NOT_INSTALLED";
312
+ SDKErrorCode2["NOT_RUNNING"] = "NOT_RUNNING";
313
+ SDKErrorCode2["CONNECTION_TIMEOUT"] = "CONNECTION_TIMEOUT";
314
+ SDKErrorCode2["STARTUP_TIMEOUT"] = "STARTUP_TIMEOUT";
315
+ SDKErrorCode2["REGISTRATION_FAILED"] = "REGISTRATION_FAILED";
316
+ SDKErrorCode2["REQUEST_TIMEOUT"] = "REQUEST_TIMEOUT";
317
+ SDKErrorCode2["REQUEST_FAILED"] = "REQUEST_FAILED";
318
+ SDKErrorCode2["DISCONNECTED"] = "DISCONNECTED";
319
+ SDKErrorCode2["WEBSOCKET_ERROR"] = "WEBSOCKET_ERROR";
320
+ SDKErrorCode2["AGENT_NOT_FOUND"] = "AGENT_NOT_FOUND";
321
+ SDKErrorCode2["CONVERSATION_NOT_FOUND"] = "CONVERSATION_NOT_FOUND";
322
+ SDKErrorCode2["TOOL_NOT_FOUND"] = "TOOL_NOT_FOUND";
323
+ SDKErrorCode2["TOOL_EXECUTION_TIMEOUT"] = "TOOL_EXECUTION_TIMEOUT";
324
+ return SDKErrorCode2;
325
+ })(SDKErrorCode || {});
326
+ var ErrorMessages = {
327
+ ["NOT_INSTALLED" /* NOT_INSTALLED */]: {
328
+ en: `Sanqian is not installed on this computer.`,
329
+ zh: `Sanqian \u5C1A\u672A\u5B89\u88C5\u5728\u6B64\u7535\u8111\u4E0A\u3002`,
330
+ hint: {
331
+ en: `Please download and install Sanqian from ${SANQIAN_WEBSITE}`,
332
+ zh: `\u8BF7\u8BBF\u95EE ${SANQIAN_WEBSITE} \u4E0B\u8F7D\u5B89\u88C5 Sanqian`
333
+ }
334
+ },
335
+ ["NOT_RUNNING" /* NOT_RUNNING */]: {
336
+ en: `Sanqian is not running.`,
337
+ zh: `Sanqian \u672A\u5728\u8FD0\u884C\u3002`,
338
+ hint: {
339
+ en: `Please start Sanqian first, or enable autoLaunchSanqian option in SDK config.`,
340
+ zh: `\u8BF7\u5148\u542F\u52A8 Sanqian\uFF0C\u6216\u5728 SDK \u914D\u7F6E\u4E2D\u542F\u7528 autoLaunchSanqian \u9009\u9879\u3002`
341
+ }
342
+ },
343
+ ["CONNECTION_TIMEOUT" /* CONNECTION_TIMEOUT */]: {
344
+ en: `Failed to connect to Sanqian (connection timeout).`,
345
+ zh: `\u8FDE\u63A5 Sanqian \u5931\u8D25\uFF08\u8FDE\u63A5\u8D85\u65F6\uFF09\u3002`,
346
+ hint: {
347
+ en: `Please check if Sanqian is running properly. If the problem persists, try restarting Sanqian.`,
348
+ zh: `\u8BF7\u68C0\u67E5 Sanqian \u662F\u5426\u6B63\u5E38\u8FD0\u884C\u3002\u5982\u95EE\u9898\u6301\u7EED\uFF0C\u8BF7\u5C1D\u8BD5\u91CD\u542F Sanqian\u3002`
349
+ }
350
+ },
351
+ ["STARTUP_TIMEOUT" /* STARTUP_TIMEOUT */]: {
352
+ en: `Sanqian failed to start within 2 minutes.`,
353
+ zh: `Sanqian \u5728 2 \u5206\u949F\u5185\u672A\u80FD\u542F\u52A8\u3002`,
354
+ hint: {
355
+ en: `Please try starting Sanqian manually. If it fails to start, reinstall from ${SANQIAN_WEBSITE}`,
356
+ zh: `\u8BF7\u5C1D\u8BD5\u624B\u52A8\u542F\u52A8 Sanqian\u3002\u5982\u4ECD\u65E0\u6CD5\u542F\u52A8\uFF0C\u8BF7\u4ECE ${SANQIAN_WEBSITE} \u91CD\u65B0\u5B89\u88C5\u3002`
357
+ }
358
+ },
359
+ ["REGISTRATION_FAILED" /* REGISTRATION_FAILED */]: {
360
+ en: `Failed to register with Sanqian.`,
361
+ zh: `\u5411 Sanqian \u6CE8\u518C\u5931\u8D25\u3002`,
362
+ hint: {
363
+ en: `Please check your SDK configuration (appName, tools). If the problem persists, try restarting Sanqian.`,
364
+ zh: `\u8BF7\u68C0\u67E5 SDK \u914D\u7F6E\uFF08appName\u3001tools\uFF09\u3002\u5982\u95EE\u9898\u6301\u7EED\uFF0C\u8BF7\u5C1D\u8BD5\u91CD\u542F Sanqian\u3002`
365
+ }
366
+ },
367
+ ["REQUEST_TIMEOUT" /* REQUEST_TIMEOUT */]: {
368
+ en: `Request timed out.`,
369
+ zh: `\u8BF7\u6C42\u8D85\u65F6\u3002`,
370
+ hint: {
371
+ en: `The operation took too long. Please try again.`,
372
+ zh: `\u64CD\u4F5C\u8017\u65F6\u8FC7\u957F\uFF0C\u8BF7\u91CD\u8BD5\u3002`
373
+ }
374
+ },
375
+ ["REQUEST_FAILED" /* REQUEST_FAILED */]: {
376
+ en: `Request failed.`,
377
+ zh: `\u8BF7\u6C42\u5931\u8D25\u3002`,
378
+ hint: {
379
+ en: `Please check the error details and try again.`,
380
+ zh: `\u8BF7\u68C0\u67E5\u9519\u8BEF\u8BE6\u60C5\u540E\u91CD\u8BD5\u3002`
381
+ }
382
+ },
383
+ ["DISCONNECTED" /* DISCONNECTED */]: {
384
+ en: `Disconnected from Sanqian.`,
385
+ zh: `\u4E0E Sanqian \u7684\u8FDE\u63A5\u5DF2\u65AD\u5F00\u3002`,
386
+ hint: {
387
+ en: `The SDK will automatically reconnect. If problems persist, check if Sanqian is still running.`,
388
+ zh: `SDK \u4F1A\u81EA\u52A8\u91CD\u8FDE\u3002\u5982\u95EE\u9898\u6301\u7EED\uFF0C\u8BF7\u68C0\u67E5 Sanqian \u662F\u5426\u4ECD\u5728\u8FD0\u884C\u3002`
389
+ }
390
+ },
391
+ ["WEBSOCKET_ERROR" /* WEBSOCKET_ERROR */]: {
392
+ en: `WebSocket connection error.`,
393
+ zh: `WebSocket \u8FDE\u63A5\u9519\u8BEF\u3002`,
394
+ hint: {
395
+ en: `Please check your network and firewall settings. Sanqian uses local WebSocket on port shown in settings.`,
396
+ zh: `\u8BF7\u68C0\u67E5\u7F51\u7EDC\u548C\u9632\u706B\u5899\u8BBE\u7F6E\u3002Sanqian \u4F7F\u7528\u672C\u5730 WebSocket\uFF0C\u7AEF\u53E3\u53EF\u5728\u8BBE\u7F6E\u4E2D\u67E5\u770B\u3002`
397
+ }
398
+ },
399
+ ["AGENT_NOT_FOUND" /* AGENT_NOT_FOUND */]: {
400
+ en: `Agent not found.`,
401
+ zh: `\u627E\u4E0D\u5230\u8BE5 Agent\u3002`,
402
+ hint: {
403
+ en: `Please check the agent ID. Use listAgents() to see available agents.`,
404
+ zh: `\u8BF7\u68C0\u67E5 Agent ID\u3002\u4F7F\u7528 listAgents() \u67E5\u770B\u53EF\u7528\u7684 Agent\u3002`
405
+ }
406
+ },
407
+ ["CONVERSATION_NOT_FOUND" /* CONVERSATION_NOT_FOUND */]: {
408
+ en: `Conversation not found.`,
409
+ zh: `\u627E\u4E0D\u5230\u8BE5\u5BF9\u8BDD\u3002`,
410
+ hint: {
411
+ en: `The conversation may have been deleted. Start a new conversation with startConversation().`,
412
+ zh: `\u8BE5\u5BF9\u8BDD\u53EF\u80FD\u5DF2\u88AB\u5220\u9664\u3002\u4F7F\u7528 startConversation() \u5F00\u59CB\u65B0\u5BF9\u8BDD\u3002`
413
+ }
414
+ },
415
+ ["TOOL_NOT_FOUND" /* TOOL_NOT_FOUND */]: {
416
+ en: `Tool not found.`,
417
+ zh: `\u627E\u4E0D\u5230\u8BE5\u5DE5\u5177\u3002`,
418
+ hint: {
419
+ en: `Please check that the tool is registered in your SDK config.`,
420
+ zh: `\u8BF7\u68C0\u67E5\u8BE5\u5DE5\u5177\u662F\u5426\u5DF2\u5728 SDK \u914D\u7F6E\u4E2D\u6CE8\u518C\u3002`
421
+ }
422
+ },
423
+ ["TOOL_EXECUTION_TIMEOUT" /* TOOL_EXECUTION_TIMEOUT */]: {
424
+ en: `Tool execution timed out.`,
425
+ zh: `\u5DE5\u5177\u6267\u884C\u8D85\u65F6\u3002`,
426
+ hint: {
427
+ en: `The tool took too long to execute. Consider increasing toolExecutionTimeout in SDK config.`,
428
+ zh: `\u5DE5\u5177\u6267\u884C\u65F6\u95F4\u8FC7\u957F\u3002\u53EF\u5728 SDK \u914D\u7F6E\u4E2D\u589E\u52A0 toolExecutionTimeout\u3002`
429
+ }
430
+ }
431
+ };
432
+ var SanqianSDKError = class extends Error {
433
+ code;
434
+ messageZh;
435
+ hint;
436
+ hintZh;
437
+ constructor(code, details) {
438
+ const msg = ErrorMessages[code];
439
+ const fullMessage = details ? `${msg.en} ${details}` : msg.en;
440
+ super(fullMessage);
441
+ this.name = "SanqianSDKError";
442
+ this.code = code;
443
+ this.messageZh = details ? `${msg.zh} ${details}` : msg.zh;
444
+ this.hint = msg.hint?.en;
445
+ this.hintZh = msg.hint?.zh;
446
+ }
447
+ /**
448
+ * Get full error message with hint (English)
449
+ */
450
+ getFullMessage() {
451
+ return this.hint ? `${this.message}
452
+ ${this.hint}` : this.message;
453
+ }
454
+ /**
455
+ * Get full error message with hint (Chinese)
456
+ */
457
+ getFullMessageZh() {
458
+ return this.hintZh ? `${this.messageZh}
459
+ ${this.hintZh}` : this.messageZh;
460
+ }
461
+ /**
462
+ * Get bilingual error message
463
+ */
464
+ getBilingualMessage() {
465
+ return `${this.getFullMessage()}
466
+
467
+ ${this.getFullMessageZh()}`;
468
+ }
469
+ };
470
+ function createSDKError(code, details) {
471
+ return new SanqianSDKError(code, details);
472
+ }
473
+
303
474
  // src/client.ts
304
475
  var SanqianSDK = class _SanqianSDK {
305
476
  config;
@@ -366,7 +537,7 @@ var SanqianSDK = class _SanqianSDK {
366
537
  console.log(`[SDK] Connecting to ${url}`);
367
538
  this.ws = new import_ws.default(url);
368
539
  const connectTimeout = setTimeout(() => {
369
- reject(new Error("WebSocket connection timeout"));
540
+ reject(createSDKError("CONNECTION_TIMEOUT" /* CONNECTION_TIMEOUT */));
370
541
  this.ws?.close();
371
542
  }, 1e4);
372
543
  this.ws.on("open", async () => {
@@ -447,7 +618,7 @@ var SanqianSDK = class _SanqianSDK {
447
618
  1e4
448
619
  );
449
620
  if (!response.success) {
450
- throw new Error(response.error || "Registration failed");
621
+ throw createSDKError("REGISTRATION_FAILED" /* REGISTRATION_FAILED */, response.error);
451
622
  }
452
623
  this.state.registering = false;
453
624
  this.state.registered = true;
@@ -579,7 +750,7 @@ var SanqianSDK = class _SanqianSDK {
579
750
  this.state.registered = false;
580
751
  this.emit("disconnected", reason);
581
752
  for (const [, pending] of this.pendingRequests) {
582
- pending.reject(new Error("Disconnected"));
753
+ pending.reject(createSDKError("DISCONNECTED" /* DISCONNECTED */));
583
754
  }
584
755
  this.pendingRequests.clear();
585
756
  this.scheduleReconnect();
@@ -671,7 +842,7 @@ var SanqianSDK = class _SanqianSDK {
671
842
  return new Promise((resolve, reject) => {
672
843
  const timer = setTimeout(() => {
673
844
  this.pendingRequests.delete(id);
674
- reject(new Error("Request timeout"));
845
+ reject(createSDKError("REQUEST_TIMEOUT" /* REQUEST_TIMEOUT */));
675
846
  }, timeout);
676
847
  this.pendingRequests.set(id, {
677
848
  resolve: (value) => {
@@ -750,14 +921,12 @@ var SanqianSDK = class _SanqianSDK {
750
921
  console.log("[SDK] Sanqian not running, attempting to launch...");
751
922
  const launched = this.discovery.launchSanqian(this.config.sanqianPath);
752
923
  if (!launched) {
753
- throw new Error(
754
- "Sanqian executable not found. Please ensure Sanqian is installed, or provide a custom path via sanqianPath config option."
755
- );
924
+ throw createSDKError("NOT_INSTALLED" /* NOT_INSTALLED */);
756
925
  }
757
926
  console.log("[SDK] Sanqian launch initiated, waiting for startup...");
758
927
  info = await this.waitForSanqianStartup();
759
928
  } else {
760
- throw new Error("Sanqian is not running. Please start it manually.");
929
+ throw createSDKError("NOT_RUNNING" /* NOT_RUNNING */);
761
930
  }
762
931
  }
763
932
  await this.connectWithInfo(info);
@@ -776,9 +945,7 @@ var SanqianSDK = class _SanqianSDK {
776
945
  }
777
946
  await new Promise((resolve) => setTimeout(resolve, pollInterval));
778
947
  }
779
- throw new Error(
780
- "Sanqian startup timeout (2 minutes). Please check if Sanqian started correctly."
781
- );
948
+ throw createSDKError("STARTUP_TIMEOUT" /* STARTUP_TIMEOUT */);
782
949
  }
783
950
  /**
784
951
  * Update tool list dynamically
@@ -824,7 +991,7 @@ var SanqianSDK = class _SanqianSDK {
824
991
  };
825
992
  const response = await this.sendAndWait(message, msgId, 1e4);
826
993
  if (!response.success) {
827
- throw new Error(response.error || "Failed to create agent");
994
+ throw createSDKError("AGENT_NOT_FOUND" /* AGENT_NOT_FOUND */, response.error);
828
995
  }
829
996
  if (response.agent) {
830
997
  return response.agent;
@@ -865,7 +1032,7 @@ var SanqianSDK = class _SanqianSDK {
865
1032
  };
866
1033
  const response = await this.sendAndWait(message, msgId, 1e4);
867
1034
  if (!response.success) {
868
- throw new Error(response.error || "Failed to delete agent");
1035
+ throw createSDKError("AGENT_NOT_FOUND" /* AGENT_NOT_FOUND */, response.error);
869
1036
  }
870
1037
  }
871
1038
  /**
@@ -887,7 +1054,7 @@ var SanqianSDK = class _SanqianSDK {
887
1054
  };
888
1055
  const response = await this.sendAndWait(message, msgId, 1e4);
889
1056
  if (!response.success || !response.agent) {
890
- throw new Error(response.error || "Failed to update agent");
1057
+ throw createSDKError("AGENT_NOT_FOUND" /* AGENT_NOT_FOUND */, response.error);
891
1058
  }
892
1059
  return response.agent;
893
1060
  }
@@ -932,7 +1099,7 @@ var SanqianSDK = class _SanqianSDK {
932
1099
  };
933
1100
  const response = await this.sendAndWait(message, msgId, 1e4);
934
1101
  if (!response.success || !response.conversation) {
935
- throw new Error(response.error || "Failed to get conversation");
1102
+ throw createSDKError("CONVERSATION_NOT_FOUND" /* CONVERSATION_NOT_FOUND */, response.error);
936
1103
  }
937
1104
  return response.conversation;
938
1105
  }
@@ -949,7 +1116,7 @@ var SanqianSDK = class _SanqianSDK {
949
1116
  };
950
1117
  const response = await this.sendAndWait(message, msgId, 1e4);
951
1118
  if (!response.success) {
952
- throw new Error(response.error || "Failed to delete conversation");
1119
+ throw createSDKError("CONVERSATION_NOT_FOUND" /* CONVERSATION_NOT_FOUND */, response.error);
953
1120
  }
954
1121
  }
955
1122
  // ============================================
@@ -987,7 +1154,11 @@ var SanqianSDK = class _SanqianSDK {
987
1154
  };
988
1155
  const response = await this.sendAndWait(message, msgId, 6e5);
989
1156
  if (!response.success) {
990
- throw new Error(response.error || "Chat request failed");
1157
+ const errorLower = (response.error || "").toLowerCase();
1158
+ if (errorLower.includes("agent") && errorLower.includes("not found")) {
1159
+ throw createSDKError("AGENT_NOT_FOUND" /* AGENT_NOT_FOUND */, response.error);
1160
+ }
1161
+ throw createSDKError("REQUEST_FAILED" /* REQUEST_FAILED */, response.error);
991
1162
  }
992
1163
  return {
993
1164
  message: response.message,
@@ -1135,7 +1306,7 @@ var SanqianSDK = class _SanqianSDK {
1135
1306
  }
1136
1307
  createTimeout(ms) {
1137
1308
  return new Promise((_, reject) => {
1138
- setTimeout(() => reject(new Error("Timeout")), ms);
1309
+ setTimeout(() => reject(createSDKError("TOOL_EXECUTION_TIMEOUT" /* TOOL_EXECUTION_TIMEOUT */)), ms);
1139
1310
  });
1140
1311
  }
1141
1312
  };
@@ -1219,6 +1390,11 @@ var Conversation = class {
1219
1390
  0 && (module.exports = {
1220
1391
  Conversation,
1221
1392
  DiscoveryManager,
1222
- SanqianSDK
1393
+ ErrorMessages,
1394
+ SANQIAN_WEBSITE,
1395
+ SDKErrorCode,
1396
+ SanqianSDK,
1397
+ SanqianSDKError,
1398
+ createSDKError
1223
1399
  });
1224
1400
  //# sourceMappingURL=index.js.map