@yushaw/sanqian-sdk 0.2.0 → 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 +104 -5
- package/dist/index.d.ts +104 -5
- package/dist/index.js +291 -120
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +285 -119
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -63,6 +63,8 @@ interface ConnectionInfo {
|
|
|
63
63
|
token: string;
|
|
64
64
|
pid: number;
|
|
65
65
|
started_at: string;
|
|
66
|
+
/** Path to Sanqian executable (for SDK auto-launch) */
|
|
67
|
+
executable?: string;
|
|
66
68
|
}
|
|
67
69
|
interface ConnectionState {
|
|
68
70
|
connected: boolean;
|
|
@@ -215,6 +217,7 @@ declare class SanqianSDK {
|
|
|
215
217
|
private heartbeatAckPending;
|
|
216
218
|
private missedHeartbeats;
|
|
217
219
|
private static readonly MAX_MISSED_HEARTBEATS;
|
|
220
|
+
private connectingPromise;
|
|
218
221
|
private eventListeners;
|
|
219
222
|
constructor(config: SDKConfig);
|
|
220
223
|
/**
|
|
@@ -225,6 +228,9 @@ declare class SanqianSDK {
|
|
|
225
228
|
*
|
|
226
229
|
* If autoLaunchSanqian is enabled and Sanqian is not running,
|
|
227
230
|
* SDK will attempt to start it in hidden/tray mode.
|
|
231
|
+
*
|
|
232
|
+
* @throws Error if Sanqian executable cannot be found (when autoLaunchSanqian is enabled)
|
|
233
|
+
* @throws Error if connection times out after 2 minutes
|
|
228
234
|
*/
|
|
229
235
|
connect(): Promise<void>;
|
|
230
236
|
/**
|
|
@@ -256,11 +262,31 @@ declare class SanqianSDK {
|
|
|
256
262
|
*/
|
|
257
263
|
isConnected(): boolean;
|
|
258
264
|
/**
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
*
|
|
265
|
+
* Ensure SDK is ready for API calls.
|
|
266
|
+
*
|
|
267
|
+
* This is the unified entry point for all API methods that require a connection.
|
|
268
|
+
* It handles:
|
|
269
|
+
* - Already connected: returns immediately
|
|
270
|
+
* - Connection in progress: waits for existing attempt (deduplication)
|
|
271
|
+
* - Not connected: initiates connection (with optional auto-launch)
|
|
272
|
+
*
|
|
273
|
+
* Design pattern: gRPC wait-for-ready + ClientFactory promise deduplication
|
|
274
|
+
*
|
|
275
|
+
* @throws Error if connection fails or times out
|
|
276
|
+
*/
|
|
277
|
+
ensureReady(): Promise<void>;
|
|
278
|
+
/**
|
|
279
|
+
* Internal: Perform full connection flow
|
|
280
|
+
* Handles launching Sanqian if needed, then connecting and registering.
|
|
281
|
+
*
|
|
282
|
+
* Note: This method is protected by connectingPromise deduplication in ensureReady(),
|
|
283
|
+
* so there's no need for additional launch-in-progress tracking within a single instance.
|
|
284
|
+
*/
|
|
285
|
+
private doFullConnect;
|
|
286
|
+
/**
|
|
287
|
+
* Wait for Sanqian to start and connection.json to become available
|
|
262
288
|
*/
|
|
263
|
-
private
|
|
289
|
+
private waitForSanqianStartup;
|
|
264
290
|
/**
|
|
265
291
|
* Update tool list dynamically
|
|
266
292
|
*/
|
|
@@ -431,6 +457,11 @@ declare class DiscoveryManager {
|
|
|
431
457
|
private watcher;
|
|
432
458
|
private onChange;
|
|
433
459
|
private pollInterval;
|
|
460
|
+
/**
|
|
461
|
+
* Cached executable path from last successful connection.json read.
|
|
462
|
+
* Persists even when Sanqian is not running, for use in auto-launch.
|
|
463
|
+
*/
|
|
464
|
+
private cachedExecutable;
|
|
434
465
|
/**
|
|
435
466
|
* Get the path to connection.json
|
|
436
467
|
*/
|
|
@@ -482,6 +513,11 @@ declare class DiscoveryManager {
|
|
|
482
513
|
/**
|
|
483
514
|
* Launch Sanqian in hidden/tray mode
|
|
484
515
|
* Returns true if launch was initiated successfully
|
|
516
|
+
*
|
|
517
|
+
* Priority for finding Sanqian executable:
|
|
518
|
+
* 1. customPath parameter (if provided)
|
|
519
|
+
* 2. Cached executable from connection.json (most reliable)
|
|
520
|
+
* 3. Search in standard installation locations (fallback)
|
|
485
521
|
*/
|
|
486
522
|
launchSanqian(customPath?: string): boolean;
|
|
487
523
|
/**
|
|
@@ -490,4 +526,67 @@ declare class DiscoveryManager {
|
|
|
490
526
|
isSanqianRunning(): boolean;
|
|
491
527
|
}
|
|
492
528
|
|
|
493
|
-
|
|
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
|
@@ -63,6 +63,8 @@ interface ConnectionInfo {
|
|
|
63
63
|
token: string;
|
|
64
64
|
pid: number;
|
|
65
65
|
started_at: string;
|
|
66
|
+
/** Path to Sanqian executable (for SDK auto-launch) */
|
|
67
|
+
executable?: string;
|
|
66
68
|
}
|
|
67
69
|
interface ConnectionState {
|
|
68
70
|
connected: boolean;
|
|
@@ -215,6 +217,7 @@ declare class SanqianSDK {
|
|
|
215
217
|
private heartbeatAckPending;
|
|
216
218
|
private missedHeartbeats;
|
|
217
219
|
private static readonly MAX_MISSED_HEARTBEATS;
|
|
220
|
+
private connectingPromise;
|
|
218
221
|
private eventListeners;
|
|
219
222
|
constructor(config: SDKConfig);
|
|
220
223
|
/**
|
|
@@ -225,6 +228,9 @@ declare class SanqianSDK {
|
|
|
225
228
|
*
|
|
226
229
|
* If autoLaunchSanqian is enabled and Sanqian is not running,
|
|
227
230
|
* SDK will attempt to start it in hidden/tray mode.
|
|
231
|
+
*
|
|
232
|
+
* @throws Error if Sanqian executable cannot be found (when autoLaunchSanqian is enabled)
|
|
233
|
+
* @throws Error if connection times out after 2 minutes
|
|
228
234
|
*/
|
|
229
235
|
connect(): Promise<void>;
|
|
230
236
|
/**
|
|
@@ -256,11 +262,31 @@ declare class SanqianSDK {
|
|
|
256
262
|
*/
|
|
257
263
|
isConnected(): boolean;
|
|
258
264
|
/**
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
*
|
|
265
|
+
* Ensure SDK is ready for API calls.
|
|
266
|
+
*
|
|
267
|
+
* This is the unified entry point for all API methods that require a connection.
|
|
268
|
+
* It handles:
|
|
269
|
+
* - Already connected: returns immediately
|
|
270
|
+
* - Connection in progress: waits for existing attempt (deduplication)
|
|
271
|
+
* - Not connected: initiates connection (with optional auto-launch)
|
|
272
|
+
*
|
|
273
|
+
* Design pattern: gRPC wait-for-ready + ClientFactory promise deduplication
|
|
274
|
+
*
|
|
275
|
+
* @throws Error if connection fails or times out
|
|
276
|
+
*/
|
|
277
|
+
ensureReady(): Promise<void>;
|
|
278
|
+
/**
|
|
279
|
+
* Internal: Perform full connection flow
|
|
280
|
+
* Handles launching Sanqian if needed, then connecting and registering.
|
|
281
|
+
*
|
|
282
|
+
* Note: This method is protected by connectingPromise deduplication in ensureReady(),
|
|
283
|
+
* so there's no need for additional launch-in-progress tracking within a single instance.
|
|
284
|
+
*/
|
|
285
|
+
private doFullConnect;
|
|
286
|
+
/**
|
|
287
|
+
* Wait for Sanqian to start and connection.json to become available
|
|
262
288
|
*/
|
|
263
|
-
private
|
|
289
|
+
private waitForSanqianStartup;
|
|
264
290
|
/**
|
|
265
291
|
* Update tool list dynamically
|
|
266
292
|
*/
|
|
@@ -431,6 +457,11 @@ declare class DiscoveryManager {
|
|
|
431
457
|
private watcher;
|
|
432
458
|
private onChange;
|
|
433
459
|
private pollInterval;
|
|
460
|
+
/**
|
|
461
|
+
* Cached executable path from last successful connection.json read.
|
|
462
|
+
* Persists even when Sanqian is not running, for use in auto-launch.
|
|
463
|
+
*/
|
|
464
|
+
private cachedExecutable;
|
|
434
465
|
/**
|
|
435
466
|
* Get the path to connection.json
|
|
436
467
|
*/
|
|
@@ -482,6 +513,11 @@ declare class DiscoveryManager {
|
|
|
482
513
|
/**
|
|
483
514
|
* Launch Sanqian in hidden/tray mode
|
|
484
515
|
* Returns true if launch was initiated successfully
|
|
516
|
+
*
|
|
517
|
+
* Priority for finding Sanqian executable:
|
|
518
|
+
* 1. customPath parameter (if provided)
|
|
519
|
+
* 2. Cached executable from connection.json (most reliable)
|
|
520
|
+
* 3. Search in standard installation locations (fallback)
|
|
485
521
|
*/
|
|
486
522
|
launchSanqian(customPath?: string): boolean;
|
|
487
523
|
/**
|
|
@@ -490,4 +526,67 @@ declare class DiscoveryManager {
|
|
|
490
526
|
isSanqianRunning(): boolean;
|
|
491
527
|
}
|
|
492
528
|
|
|
493
|
-
|
|
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 };
|