@yushaw/sanqian-sdk 0.2.1 → 0.2.3

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
 
@@ -216,10 +221,12 @@ var DiscoveryManager = class {
216
221
  const programFilesX86 = process.env["PROGRAMFILES(X86)"] || "C:\\Program Files (x86)";
217
222
  const localAppData = process.env.LOCALAPPDATA || (0, import_path.join)((0, import_os.homedir)(), "AppData", "Local");
218
223
  searchPaths.push(
219
- // Production: installed app
224
+ // Production: NSIS installer uses lowercase directory name from package.json "name"
225
+ (0, import_path.join)(localAppData, "Programs", "sanqian", "Sanqian.exe"),
226
+ // Legacy/alternative paths with uppercase
227
+ (0, import_path.join)(localAppData, "Programs", "Sanqian", "Sanqian.exe"),
220
228
  (0, import_path.join)(programFiles, "Sanqian", "Sanqian.exe"),
221
229
  (0, import_path.join)(programFilesX86, "Sanqian", "Sanqian.exe"),
222
- (0, import_path.join)(localAppData, "Programs", "Sanqian", "Sanqian.exe"),
223
230
  // Development: electron-builder output
224
231
  (0, import_path.join)((0, import_os.homedir)(), "dev", "sanqian", "dist", "win-unpacked", "Sanqian.exe")
225
232
  );
@@ -271,7 +278,7 @@ var DiscoveryManager = class {
271
278
  "/Contents/MacOS/Sanqian",
272
279
  ""
273
280
  );
274
- (0, import_child_process.spawn)("open", ["-a", appPath, "--args", "--hidden"], {
281
+ (0, import_child_process.spawn)("open", ["-g", "-a", appPath, "--args", "--hidden"], {
275
282
  detached: true,
276
283
  stdio: "ignore"
277
284
  }).unref();
@@ -300,6 +307,172 @@ var DiscoveryManager = class {
300
307
  }
301
308
  };
302
309
 
310
+ // src/errors.ts
311
+ var SANQIAN_WEBSITE = "https://sanqian.io";
312
+ var SDKErrorCode = /* @__PURE__ */ ((SDKErrorCode2) => {
313
+ SDKErrorCode2["NOT_INSTALLED"] = "NOT_INSTALLED";
314
+ SDKErrorCode2["NOT_RUNNING"] = "NOT_RUNNING";
315
+ SDKErrorCode2["CONNECTION_TIMEOUT"] = "CONNECTION_TIMEOUT";
316
+ SDKErrorCode2["STARTUP_TIMEOUT"] = "STARTUP_TIMEOUT";
317
+ SDKErrorCode2["REGISTRATION_FAILED"] = "REGISTRATION_FAILED";
318
+ SDKErrorCode2["REQUEST_TIMEOUT"] = "REQUEST_TIMEOUT";
319
+ SDKErrorCode2["REQUEST_FAILED"] = "REQUEST_FAILED";
320
+ SDKErrorCode2["DISCONNECTED"] = "DISCONNECTED";
321
+ SDKErrorCode2["WEBSOCKET_ERROR"] = "WEBSOCKET_ERROR";
322
+ SDKErrorCode2["AGENT_NOT_FOUND"] = "AGENT_NOT_FOUND";
323
+ SDKErrorCode2["CONVERSATION_NOT_FOUND"] = "CONVERSATION_NOT_FOUND";
324
+ SDKErrorCode2["TOOL_NOT_FOUND"] = "TOOL_NOT_FOUND";
325
+ SDKErrorCode2["TOOL_EXECUTION_TIMEOUT"] = "TOOL_EXECUTION_TIMEOUT";
326
+ return SDKErrorCode2;
327
+ })(SDKErrorCode || {});
328
+ var ErrorMessages = {
329
+ ["NOT_INSTALLED" /* NOT_INSTALLED */]: {
330
+ en: `Sanqian is not installed on this computer.`,
331
+ zh: `Sanqian \u5C1A\u672A\u5B89\u88C5\u5728\u6B64\u7535\u8111\u4E0A\u3002`,
332
+ hint: {
333
+ en: `Please download and install Sanqian from ${SANQIAN_WEBSITE}`,
334
+ zh: `\u8BF7\u8BBF\u95EE ${SANQIAN_WEBSITE} \u4E0B\u8F7D\u5B89\u88C5 Sanqian`
335
+ }
336
+ },
337
+ ["NOT_RUNNING" /* NOT_RUNNING */]: {
338
+ en: `Sanqian is not running.`,
339
+ zh: `Sanqian \u672A\u5728\u8FD0\u884C\u3002`,
340
+ hint: {
341
+ en: `Please start Sanqian first, or enable autoLaunchSanqian option in SDK config.`,
342
+ zh: `\u8BF7\u5148\u542F\u52A8 Sanqian\uFF0C\u6216\u5728 SDK \u914D\u7F6E\u4E2D\u542F\u7528 autoLaunchSanqian \u9009\u9879\u3002`
343
+ }
344
+ },
345
+ ["CONNECTION_TIMEOUT" /* CONNECTION_TIMEOUT */]: {
346
+ en: `Failed to connect to Sanqian (connection timeout).`,
347
+ zh: `\u8FDE\u63A5 Sanqian \u5931\u8D25\uFF08\u8FDE\u63A5\u8D85\u65F6\uFF09\u3002`,
348
+ hint: {
349
+ en: `Please check if Sanqian is running properly. If the problem persists, try restarting Sanqian.`,
350
+ 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`
351
+ }
352
+ },
353
+ ["STARTUP_TIMEOUT" /* STARTUP_TIMEOUT */]: {
354
+ en: `Sanqian failed to start within 2 minutes.`,
355
+ zh: `Sanqian \u5728 2 \u5206\u949F\u5185\u672A\u80FD\u542F\u52A8\u3002`,
356
+ hint: {
357
+ en: `Please try starting Sanqian manually. If it fails to start, reinstall from ${SANQIAN_WEBSITE}`,
358
+ 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`
359
+ }
360
+ },
361
+ ["REGISTRATION_FAILED" /* REGISTRATION_FAILED */]: {
362
+ en: `Failed to register with Sanqian.`,
363
+ zh: `\u5411 Sanqian \u6CE8\u518C\u5931\u8D25\u3002`,
364
+ hint: {
365
+ en: `Please check your SDK configuration (appName, tools). If the problem persists, try restarting Sanqian.`,
366
+ zh: `\u8BF7\u68C0\u67E5 SDK \u914D\u7F6E\uFF08appName\u3001tools\uFF09\u3002\u5982\u95EE\u9898\u6301\u7EED\uFF0C\u8BF7\u5C1D\u8BD5\u91CD\u542F Sanqian\u3002`
367
+ }
368
+ },
369
+ ["REQUEST_TIMEOUT" /* REQUEST_TIMEOUT */]: {
370
+ en: `Request timed out.`,
371
+ zh: `\u8BF7\u6C42\u8D85\u65F6\u3002`,
372
+ hint: {
373
+ en: `The operation took too long. Please try again.`,
374
+ zh: `\u64CD\u4F5C\u8017\u65F6\u8FC7\u957F\uFF0C\u8BF7\u91CD\u8BD5\u3002`
375
+ }
376
+ },
377
+ ["REQUEST_FAILED" /* REQUEST_FAILED */]: {
378
+ en: `Request failed.`,
379
+ zh: `\u8BF7\u6C42\u5931\u8D25\u3002`,
380
+ hint: {
381
+ en: `Please check the error details and try again.`,
382
+ zh: `\u8BF7\u68C0\u67E5\u9519\u8BEF\u8BE6\u60C5\u540E\u91CD\u8BD5\u3002`
383
+ }
384
+ },
385
+ ["DISCONNECTED" /* DISCONNECTED */]: {
386
+ en: `Disconnected from Sanqian.`,
387
+ zh: `\u4E0E Sanqian \u7684\u8FDE\u63A5\u5DF2\u65AD\u5F00\u3002`,
388
+ hint: {
389
+ en: `The SDK will automatically reconnect. If problems persist, check if Sanqian is still running.`,
390
+ 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`
391
+ }
392
+ },
393
+ ["WEBSOCKET_ERROR" /* WEBSOCKET_ERROR */]: {
394
+ en: `WebSocket connection error.`,
395
+ zh: `WebSocket \u8FDE\u63A5\u9519\u8BEF\u3002`,
396
+ hint: {
397
+ en: `Please check your network and firewall settings. Sanqian uses local WebSocket on port shown in settings.`,
398
+ 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`
399
+ }
400
+ },
401
+ ["AGENT_NOT_FOUND" /* AGENT_NOT_FOUND */]: {
402
+ en: `Agent not found.`,
403
+ zh: `\u627E\u4E0D\u5230\u8BE5 Agent\u3002`,
404
+ hint: {
405
+ en: `Please check the agent ID. Use listAgents() to see available agents.`,
406
+ zh: `\u8BF7\u68C0\u67E5 Agent ID\u3002\u4F7F\u7528 listAgents() \u67E5\u770B\u53EF\u7528\u7684 Agent\u3002`
407
+ }
408
+ },
409
+ ["CONVERSATION_NOT_FOUND" /* CONVERSATION_NOT_FOUND */]: {
410
+ en: `Conversation not found.`,
411
+ zh: `\u627E\u4E0D\u5230\u8BE5\u5BF9\u8BDD\u3002`,
412
+ hint: {
413
+ en: `The conversation may have been deleted. Start a new conversation with startConversation().`,
414
+ zh: `\u8BE5\u5BF9\u8BDD\u53EF\u80FD\u5DF2\u88AB\u5220\u9664\u3002\u4F7F\u7528 startConversation() \u5F00\u59CB\u65B0\u5BF9\u8BDD\u3002`
415
+ }
416
+ },
417
+ ["TOOL_NOT_FOUND" /* TOOL_NOT_FOUND */]: {
418
+ en: `Tool not found.`,
419
+ zh: `\u627E\u4E0D\u5230\u8BE5\u5DE5\u5177\u3002`,
420
+ hint: {
421
+ en: `Please check that the tool is registered in your SDK config.`,
422
+ zh: `\u8BF7\u68C0\u67E5\u8BE5\u5DE5\u5177\u662F\u5426\u5DF2\u5728 SDK \u914D\u7F6E\u4E2D\u6CE8\u518C\u3002`
423
+ }
424
+ },
425
+ ["TOOL_EXECUTION_TIMEOUT" /* TOOL_EXECUTION_TIMEOUT */]: {
426
+ en: `Tool execution timed out.`,
427
+ zh: `\u5DE5\u5177\u6267\u884C\u8D85\u65F6\u3002`,
428
+ hint: {
429
+ en: `The tool took too long to execute. Consider increasing toolExecutionTimeout in SDK config.`,
430
+ zh: `\u5DE5\u5177\u6267\u884C\u65F6\u95F4\u8FC7\u957F\u3002\u53EF\u5728 SDK \u914D\u7F6E\u4E2D\u589E\u52A0 toolExecutionTimeout\u3002`
431
+ }
432
+ }
433
+ };
434
+ var SanqianSDKError = class extends Error {
435
+ code;
436
+ messageZh;
437
+ hint;
438
+ hintZh;
439
+ constructor(code, details) {
440
+ const msg = ErrorMessages[code];
441
+ const fullMessage = details ? `${msg.en} ${details}` : msg.en;
442
+ super(fullMessage);
443
+ this.name = "SanqianSDKError";
444
+ this.code = code;
445
+ this.messageZh = details ? `${msg.zh} ${details}` : msg.zh;
446
+ this.hint = msg.hint?.en;
447
+ this.hintZh = msg.hint?.zh;
448
+ }
449
+ /**
450
+ * Get full error message with hint (English)
451
+ */
452
+ getFullMessage() {
453
+ return this.hint ? `${this.message}
454
+ ${this.hint}` : this.message;
455
+ }
456
+ /**
457
+ * Get full error message with hint (Chinese)
458
+ */
459
+ getFullMessageZh() {
460
+ return this.hintZh ? `${this.messageZh}
461
+ ${this.hintZh}` : this.messageZh;
462
+ }
463
+ /**
464
+ * Get bilingual error message
465
+ */
466
+ getBilingualMessage() {
467
+ return `${this.getFullMessage()}
468
+
469
+ ${this.getFullMessageZh()}`;
470
+ }
471
+ };
472
+ function createSDKError(code, details) {
473
+ return new SanqianSDKError(code, details);
474
+ }
475
+
303
476
  // src/client.ts
304
477
  var SanqianSDK = class _SanqianSDK {
305
478
  config;
@@ -366,7 +539,7 @@ var SanqianSDK = class _SanqianSDK {
366
539
  console.log(`[SDK] Connecting to ${url}`);
367
540
  this.ws = new import_ws.default(url);
368
541
  const connectTimeout = setTimeout(() => {
369
- reject(new Error("WebSocket connection timeout"));
542
+ reject(createSDKError("CONNECTION_TIMEOUT" /* CONNECTION_TIMEOUT */));
370
543
  this.ws?.close();
371
544
  }, 1e4);
372
545
  this.ws.on("open", async () => {
@@ -447,7 +620,7 @@ var SanqianSDK = class _SanqianSDK {
447
620
  1e4
448
621
  );
449
622
  if (!response.success) {
450
- throw new Error(response.error || "Registration failed");
623
+ throw createSDKError("REGISTRATION_FAILED" /* REGISTRATION_FAILED */, response.error);
451
624
  }
452
625
  this.state.registering = false;
453
626
  this.state.registered = true;
@@ -579,7 +752,7 @@ var SanqianSDK = class _SanqianSDK {
579
752
  this.state.registered = false;
580
753
  this.emit("disconnected", reason);
581
754
  for (const [, pending] of this.pendingRequests) {
582
- pending.reject(new Error("Disconnected"));
755
+ pending.reject(createSDKError("DISCONNECTED" /* DISCONNECTED */));
583
756
  }
584
757
  this.pendingRequests.clear();
585
758
  this.scheduleReconnect();
@@ -671,7 +844,7 @@ var SanqianSDK = class _SanqianSDK {
671
844
  return new Promise((resolve, reject) => {
672
845
  const timer = setTimeout(() => {
673
846
  this.pendingRequests.delete(id);
674
- reject(new Error("Request timeout"));
847
+ reject(createSDKError("REQUEST_TIMEOUT" /* REQUEST_TIMEOUT */));
675
848
  }, timeout);
676
849
  this.pendingRequests.set(id, {
677
850
  resolve: (value) => {
@@ -750,14 +923,12 @@ var SanqianSDK = class _SanqianSDK {
750
923
  console.log("[SDK] Sanqian not running, attempting to launch...");
751
924
  const launched = this.discovery.launchSanqian(this.config.sanqianPath);
752
925
  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
- );
926
+ throw createSDKError("NOT_INSTALLED" /* NOT_INSTALLED */);
756
927
  }
757
928
  console.log("[SDK] Sanqian launch initiated, waiting for startup...");
758
929
  info = await this.waitForSanqianStartup();
759
930
  } else {
760
- throw new Error("Sanqian is not running. Please start it manually.");
931
+ throw createSDKError("NOT_RUNNING" /* NOT_RUNNING */);
761
932
  }
762
933
  }
763
934
  await this.connectWithInfo(info);
@@ -776,9 +947,7 @@ var SanqianSDK = class _SanqianSDK {
776
947
  }
777
948
  await new Promise((resolve) => setTimeout(resolve, pollInterval));
778
949
  }
779
- throw new Error(
780
- "Sanqian startup timeout (2 minutes). Please check if Sanqian started correctly."
781
- );
950
+ throw createSDKError("STARTUP_TIMEOUT" /* STARTUP_TIMEOUT */);
782
951
  }
783
952
  /**
784
953
  * Update tool list dynamically
@@ -824,7 +993,7 @@ var SanqianSDK = class _SanqianSDK {
824
993
  };
825
994
  const response = await this.sendAndWait(message, msgId, 1e4);
826
995
  if (!response.success) {
827
- throw new Error(response.error || "Failed to create agent");
996
+ throw createSDKError("AGENT_NOT_FOUND" /* AGENT_NOT_FOUND */, response.error);
828
997
  }
829
998
  if (response.agent) {
830
999
  return response.agent;
@@ -865,7 +1034,7 @@ var SanqianSDK = class _SanqianSDK {
865
1034
  };
866
1035
  const response = await this.sendAndWait(message, msgId, 1e4);
867
1036
  if (!response.success) {
868
- throw new Error(response.error || "Failed to delete agent");
1037
+ throw createSDKError("AGENT_NOT_FOUND" /* AGENT_NOT_FOUND */, response.error);
869
1038
  }
870
1039
  }
871
1040
  /**
@@ -887,7 +1056,7 @@ var SanqianSDK = class _SanqianSDK {
887
1056
  };
888
1057
  const response = await this.sendAndWait(message, msgId, 1e4);
889
1058
  if (!response.success || !response.agent) {
890
- throw new Error(response.error || "Failed to update agent");
1059
+ throw createSDKError("AGENT_NOT_FOUND" /* AGENT_NOT_FOUND */, response.error);
891
1060
  }
892
1061
  return response.agent;
893
1062
  }
@@ -932,7 +1101,7 @@ var SanqianSDK = class _SanqianSDK {
932
1101
  };
933
1102
  const response = await this.sendAndWait(message, msgId, 1e4);
934
1103
  if (!response.success || !response.conversation) {
935
- throw new Error(response.error || "Failed to get conversation");
1104
+ throw createSDKError("CONVERSATION_NOT_FOUND" /* CONVERSATION_NOT_FOUND */, response.error);
936
1105
  }
937
1106
  return response.conversation;
938
1107
  }
@@ -949,7 +1118,7 @@ var SanqianSDK = class _SanqianSDK {
949
1118
  };
950
1119
  const response = await this.sendAndWait(message, msgId, 1e4);
951
1120
  if (!response.success) {
952
- throw new Error(response.error || "Failed to delete conversation");
1121
+ throw createSDKError("CONVERSATION_NOT_FOUND" /* CONVERSATION_NOT_FOUND */, response.error);
953
1122
  }
954
1123
  }
955
1124
  // ============================================
@@ -987,7 +1156,11 @@ var SanqianSDK = class _SanqianSDK {
987
1156
  };
988
1157
  const response = await this.sendAndWait(message, msgId, 6e5);
989
1158
  if (!response.success) {
990
- throw new Error(response.error || "Chat request failed");
1159
+ const errorLower = (response.error || "").toLowerCase();
1160
+ if (errorLower.includes("agent") && errorLower.includes("not found")) {
1161
+ throw createSDKError("AGENT_NOT_FOUND" /* AGENT_NOT_FOUND */, response.error);
1162
+ }
1163
+ throw createSDKError("REQUEST_FAILED" /* REQUEST_FAILED */, response.error);
991
1164
  }
992
1165
  return {
993
1166
  message: response.message,
@@ -1135,7 +1308,7 @@ var SanqianSDK = class _SanqianSDK {
1135
1308
  }
1136
1309
  createTimeout(ms) {
1137
1310
  return new Promise((_, reject) => {
1138
- setTimeout(() => reject(new Error("Timeout")), ms);
1311
+ setTimeout(() => reject(createSDKError("TOOL_EXECUTION_TIMEOUT" /* TOOL_EXECUTION_TIMEOUT */)), ms);
1139
1312
  });
1140
1313
  }
1141
1314
  };
@@ -1219,6 +1392,11 @@ var Conversation = class {
1219
1392
  0 && (module.exports = {
1220
1393
  Conversation,
1221
1394
  DiscoveryManager,
1222
- SanqianSDK
1395
+ ErrorMessages,
1396
+ SANQIAN_WEBSITE,
1397
+ SDKErrorCode,
1398
+ SanqianSDK,
1399
+ SanqianSDKError,
1400
+ createSDKError
1223
1401
  });
1224
1402
  //# sourceMappingURL=index.js.map