@yushaw/sanqian-sdk 0.3.9 → 0.3.11

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.
@@ -273,8 +273,20 @@ interface ChatStreamEvent {
273
273
  /** Run ID (for "interrupt" event) - needed to send HITL response */
274
274
  run_id?: string;
275
275
  }
276
- /** HITL interrupt types */
277
- type HitlInterruptType = "approval_request" | "user_input_request";
276
+ /**
277
+ * HITL interrupt types.
278
+ *
279
+ * - approval_request: Pre-execution approval. User approves/rejects tool execution.
280
+ * Example: "Delete file X?" -> Approve / Reject
281
+ *
282
+ * - user_input_request: Agent asks for user input. User provides text or selects options.
283
+ * Example: "What format?" -> ["JSON", "CSV"] or free text
284
+ *
285
+ * - user_action_request: Tool requires user to complete an action externally.
286
+ * User performs the action (e.g., login), then confirms completion.
287
+ * Example: "Login required" -> [User logs in] -> "Done" / "Skip"
288
+ */
289
+ type HitlInterruptType = "approval_request" | "user_input_request" | "user_action_request";
278
290
  /** HITL risk levels for approval requests */
279
291
  type HitlRiskLevel = "low" | "medium" | "high";
280
292
  /** HITL interrupt payload - sent from backend when HITL is triggered */
@@ -303,6 +315,14 @@ interface HitlInterruptPayload {
303
315
  required?: boolean;
304
316
  /** Timeout in seconds */
305
317
  timeout?: number;
318
+ /** Interrupt source - "tool_interrupt" means a tool triggered this during execution */
319
+ source?: "tool_interrupt";
320
+ /** Name of the tool that triggered the interrupt */
321
+ source_tool?: string;
322
+ /** Tool call ID for correlation */
323
+ source_tool_call_id?: string;
324
+ /** Reason for the interrupt (e.g., "login_required", "captcha_detected") */
325
+ source_reason?: string;
306
326
  }
307
327
  /** HITL response - sent from client to backend */
308
328
  interface HitlResponse {
@@ -455,6 +475,161 @@ interface AgentUpdateConfig {
455
475
  */
456
476
  searchable?: boolean;
457
477
  }
478
+ /** Embedding configuration returned from Sanqian */
479
+ interface EmbeddingConfigResult {
480
+ /** Whether embedding is configured in Sanqian */
481
+ available: boolean;
482
+ /** API URL for embedding service */
483
+ apiUrl?: string;
484
+ /** API key (decrypted) */
485
+ apiKey?: string;
486
+ /** Model name */
487
+ modelName?: string;
488
+ /** Embedding dimensions */
489
+ dimensions?: number;
490
+ }
491
+ /** Rerank configuration returned from Sanqian */
492
+ interface RerankConfigResult {
493
+ /** Whether rerank is configured in Sanqian */
494
+ available: boolean;
495
+ /** API URL for rerank service */
496
+ apiUrl?: string;
497
+ /** API key (decrypted) */
498
+ apiKey?: string;
499
+ /** Model name */
500
+ modelName?: string;
501
+ }
502
+ /** Capability type */
503
+ type CapabilityType = "tool" | "skill" | "agent" | "context";
504
+ /** Tool capability info */
505
+ interface ToolCapability {
506
+ type: "tool";
507
+ /** Tool ID (e.g., "file_ops", "sdk_myapp_xxx", "mcp_server_tool") */
508
+ id: string;
509
+ /** Tool description */
510
+ description: string;
511
+ /** Source: builtin, sdk, or mcp */
512
+ source: "builtin" | "sdk" | "mcp";
513
+ /** Source ID (SDK app name or MCP server name) */
514
+ sourceId?: string;
515
+ /** Tool category */
516
+ category?: string;
517
+ /** Tool tags */
518
+ tags?: string[];
519
+ /** Tool parameters JSON Schema */
520
+ parameters?: JSONSchema;
521
+ /** Display name (localized) */
522
+ display?: {
523
+ zh?: string;
524
+ en?: string;
525
+ };
526
+ /** Short description (localized) */
527
+ shortDesc?: {
528
+ zh?: string;
529
+ en?: string;
530
+ };
531
+ }
532
+ /** Skill capability info */
533
+ interface SkillCapability {
534
+ type: "skill";
535
+ /** Skill ID (e.g., "pdf", "web-research") */
536
+ id: string;
537
+ /** Skill description */
538
+ description: string;
539
+ /** Source: builtin or custom */
540
+ source: "builtin" | "custom";
541
+ /** Display name (localized) */
542
+ display?: {
543
+ zh?: string;
544
+ en?: string;
545
+ };
546
+ /** Short description (localized) */
547
+ shortDesc?: {
548
+ zh?: string;
549
+ en?: string;
550
+ };
551
+ }
552
+ /** Agent capability info */
553
+ interface AgentCapability {
554
+ type: "agent";
555
+ /** Agent ID */
556
+ id: string;
557
+ /** Agent display name */
558
+ name: string;
559
+ /** Agent description */
560
+ description?: string;
561
+ /** Source: builtin, custom, or sdk */
562
+ source: "builtin" | "custom" | "sdk";
563
+ /** Source ID (SDK app name for sdk agents) */
564
+ sourceId?: string;
565
+ /** Agent icon/emoji */
566
+ icon?: string;
567
+ /** Display name (localized) */
568
+ display?: {
569
+ zh?: string;
570
+ en?: string;
571
+ };
572
+ /** Short description (localized) */
573
+ shortDesc?: {
574
+ zh?: string;
575
+ en?: string;
576
+ };
577
+ }
578
+ /** Context capability info */
579
+ interface ContextCapability {
580
+ type: "context";
581
+ /** Context provider ID */
582
+ id: string;
583
+ /** Context provider display name */
584
+ name: string;
585
+ /** Context provider description */
586
+ description?: string;
587
+ /** Source: sdk (context providers are always from SDK apps) */
588
+ source: "sdk";
589
+ /** Source ID (SDK app name) */
590
+ sourceId: string;
591
+ /** Context provider icon/emoji */
592
+ icon?: string;
593
+ /** Whether this provider supports getCurrent */
594
+ hasCurrent: boolean;
595
+ /** Whether this provider supports getList */
596
+ hasList: boolean;
597
+ /** Whether this provider supports getById */
598
+ hasGetById: boolean;
599
+ }
600
+ /** Union type for all capabilities */
601
+ type Capability = ToolCapability | SkillCapability | AgentCapability | ContextCapability;
602
+ /** Capability search result with score */
603
+ interface CapabilitySearchResult {
604
+ /** The capability */
605
+ capability: Capability;
606
+ /** Relevance score */
607
+ score: number;
608
+ /** Usage hint */
609
+ howToUse?: string;
610
+ }
611
+ /** Options for listing capabilities */
612
+ interface ListCapabilitiesOptions {
613
+ /** Filter by type (default: "all") */
614
+ type?: CapabilityType | "all";
615
+ /** Filter by source (e.g., "builtin", "sdk", "mcp") */
616
+ source?: string;
617
+ /** Filter by category (tools only) */
618
+ category?: string;
619
+ /** SDK app name (for including own private agents) */
620
+ appName?: string;
621
+ /** Agent scope filter: "searchable" (default) or "available" (includes non-searchable but enabled agents) */
622
+ scope?: "searchable" | "available";
623
+ }
624
+ /** Options for searching capabilities */
625
+ interface SearchCapabilitiesOptions {
626
+ /** Filter by type (default: "all") */
627
+ type?: CapabilityType | "all";
628
+ /** Max results (default: 10) */
629
+ limit?: number;
630
+ /** Exclude these IDs */
631
+ exclude?: string[];
632
+ }
458
633
  /**
459
634
  * Session resource pushed by an app.
460
635
  * Content is provided at push time (not fetched like attached_resources).
@@ -518,6 +693,10 @@ declare class SanqianSDK {
518
693
  private connectingPromise;
519
694
  private reconnectRefCount;
520
695
  private eventListeners;
696
+ private sessionResources;
697
+ private contextProviders;
698
+ private runIdToMsgId;
699
+ private pendingStreamMsgId;
521
700
  private log;
522
701
  private warn;
523
702
  constructor(config: SDKConfig);
@@ -531,6 +710,18 @@ declare class SanqianSDK {
531
710
  private register;
532
711
  private handleMessage;
533
712
  private handleChatStream;
713
+ private handleResourceRemovedByUser;
714
+ private getHandlerByRunId;
715
+ private handleBackendStart;
716
+ private handleBackendStream;
717
+ private handleBackendThinking;
718
+ private handleBackendToolStart;
719
+ private handleBackendToolArgsChunk;
720
+ private handleBackendToolResult;
721
+ private handleBackendComplete;
722
+ private handleBackendError;
723
+ private handleBackendCancelled;
724
+ private handleBackendInterrupt;
534
725
  private handleToolCall;
535
726
  private sendToolResult;
536
727
  private handleDisconnect;
@@ -605,7 +796,74 @@ declare class SanqianSDK {
605
796
  * @param response - User's response (approval, input, etc.)
606
797
  */
607
798
  sendHitlResponse(runId: string, response: HitlResponse): void;
799
+ /**
800
+ * Cancel an in-flight chat run
801
+ *
802
+ * @param runId - The run_id from the stream "start"/"interrupt" event
803
+ */
804
+ cancelRun(runId: string): void;
608
805
  startConversation(agentId: string): Conversation;
806
+ /**
807
+ * Get embedding configuration from Sanqian
808
+ *
809
+ * Returns the current embedding model configuration including API URL, key, and model name.
810
+ * This allows external apps to use the same embedding service configured in Sanqian.
811
+ */
812
+ getEmbeddingConfig(): Promise<EmbeddingConfigResult>;
813
+ /**
814
+ * Get rerank configuration from Sanqian
815
+ *
816
+ * Returns the current rerank model configuration including API URL, key, and model name.
817
+ * This allows external apps to use the same rerank service configured in Sanqian.
818
+ */
819
+ getRerankConfig(): Promise<RerankConfigResult>;
820
+ /**
821
+ * Push a session resource to Sanqian
822
+ *
823
+ * Session resources are temporary context pushed by the app, visible in all Chat UI instances.
824
+ * They persist until the app disconnects or explicitly removes them.
825
+ */
826
+ pushResource(resource: SessionResource): Promise<StoredSessionResource>;
827
+ /**
828
+ * Remove a session resource
829
+ */
830
+ removeResource(resourceId: string): Promise<void>;
831
+ /**
832
+ * Clear all session resources pushed by this app
833
+ */
834
+ clearResources(): Promise<void>;
835
+ /**
836
+ * Get all session resources pushed by this app (local cache)
837
+ */
838
+ getSessionResources(): StoredSessionResource[];
839
+ /**
840
+ * Fetch session resources from server
841
+ */
842
+ fetchSessionResources(agentId?: string): Promise<StoredSessionResource[]>;
843
+ /**
844
+ * List available capabilities (tools, skills, agents)
845
+ */
846
+ listCapabilities(options?: ListCapabilitiesOptions): Promise<Capability[]>;
847
+ /**
848
+ * Search capabilities by query using hybrid search (BM25 + Vector)
849
+ */
850
+ searchCapabilities(query: string, options?: SearchCapabilitiesOptions): Promise<CapabilitySearchResult[]>;
851
+ /**
852
+ * List available tools
853
+ */
854
+ listTools(source?: "builtin" | "sdk" | "mcp"): Promise<ToolCapability[]>;
855
+ /**
856
+ * List available skills
857
+ */
858
+ listSkills(): Promise<SkillCapability[]>;
859
+ /**
860
+ * List all available agents
861
+ */
862
+ listAvailableAgents(): Promise<AgentCapability[]>;
863
+ /**
864
+ * Update context providers dynamically
865
+ */
866
+ updateContexts(contexts: ContextProvider[]): Promise<void>;
609
867
  on<T extends SDKEventName>(event: T, listener: SDKEvents[T]): this;
610
868
  off<T extends SDKEventName>(event: T, listener: SDKEvents[T]): this;
611
869
  once<T extends SDKEventName>(event: T, listener: SDKEvents[T]): this;
@@ -704,4 +962,4 @@ declare class SanqianSDKError extends Error {
704
962
  */
705
963
  declare function createSDKError(code: SDKErrorCode, details?: string): SanqianSDKError;
706
964
 
707
- 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, ErrorMessages, type HitlInterruptPayload, type HitlInterruptType, type HitlResponse, type HitlRiskLevel, type JSONSchema, type JSONSchemaProperty, type RemoteToolDefinition, SANQIAN_WEBSITE, type SDKConfig, SDKErrorCode, type SDKEventName, type SDKEvents, SanqianSDK, SanqianSDKError, type ToolCall, type ToolDefinition, createSDKError };
965
+ export { type AgentCapability, type AgentConfig, type AgentInfo, type AgentUpdateConfig, type Capability, type CapabilitySearchResult, type CapabilityType, type ChatMessage, type ChatRequest, type ChatResponse, type ChatStreamEvent, type ConnectionInfo, type ConnectionState, type ContextData, type ContextListItem, type ContextProvider, Conversation, type ConversationDetail, type ConversationInfo, type ConversationMessage, type EmbeddingConfigResult, ErrorMessages, type HitlInterruptPayload, type HitlInterruptType, type HitlResponse, type HitlRiskLevel, type JSONSchema, type JSONSchemaProperty, type ListCapabilitiesOptions, type RemoteToolDefinition, type RerankConfigResult, SANQIAN_WEBSITE, type SDKConfig, SDKErrorCode, type SDKEventName, type SDKEvents, SanqianSDK, SanqianSDKError, type SearchCapabilitiesOptions, type SessionResource, type SkillCapability, type StoredSessionResource, type ToolCall, type ToolCapability, type ToolDefinition, createSDKError };