@yushaw/sanqian-sdk 0.3.6 → 0.3.8

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.
@@ -455,6 +455,36 @@ interface AgentUpdateConfig {
455
455
  */
456
456
  searchable?: boolean;
457
457
  }
458
+ /**
459
+ * Session resource pushed by an app.
460
+ * Content is provided at push time (not fetched like attached_resources).
461
+ * Global scope - visible in all Chat UI instances, persists until app disconnects.
462
+ */
463
+ interface SessionResource {
464
+ /** Resource ID (auto-generated if not provided) */
465
+ id?: string;
466
+ /** Display title (required) */
467
+ title: string;
468
+ /** Content (required, format controlled by app) */
469
+ content: string;
470
+ /** Optional summary for UI tooltip */
471
+ summary?: string;
472
+ /** Optional icon (emoji or URL) */
473
+ icon?: string;
474
+ /** Optional resource type for styling */
475
+ type?: ResourceType;
476
+ }
477
+ /**
478
+ * Stored session resource with full metadata
479
+ */
480
+ interface StoredSessionResource extends SessionResource {
481
+ /** Full ID: "appName:resourceId" */
482
+ fullId: string;
483
+ /** Source app name */
484
+ appName: string;
485
+ /** Push timestamp (ISO 8601) */
486
+ pushedAt: string;
487
+ }
458
488
  interface SDKEvents {
459
489
  connected: () => void;
460
490
  disconnected: (reason: string) => void;
@@ -464,6 +494,12 @@ interface SDKEvents {
464
494
  name: string;
465
495
  arguments: Record<string, unknown>;
466
496
  }) => void;
497
+ /** Called when a session resource is pushed or updated */
498
+ resourcePushed: (resource: StoredSessionResource) => void;
499
+ /** Called when user removes a session resource from Chat UI */
500
+ resourceRemoved: (resourceId: string) => void;
501
+ /** Called when all session resources are cleared by this app */
502
+ resourcesCleared: (appName: string) => void;
467
503
  }
468
504
  type SDKEventName = keyof SDKEvents;
469
505
 
package/dist/index.d.mts CHANGED
@@ -589,6 +589,36 @@ interface SearchCapabilitiesOptions {
589
589
  /** Exclude these IDs */
590
590
  exclude?: string[];
591
591
  }
592
+ /**
593
+ * Session resource pushed by an app.
594
+ * Content is provided at push time (not fetched like attached_resources).
595
+ * Global scope - visible in all Chat UI instances, persists until app disconnects.
596
+ */
597
+ interface SessionResource {
598
+ /** Resource ID (auto-generated if not provided) */
599
+ id?: string;
600
+ /** Display title (required) */
601
+ title: string;
602
+ /** Content (required, format controlled by app) */
603
+ content: string;
604
+ /** Optional summary for UI tooltip */
605
+ summary?: string;
606
+ /** Optional icon (emoji or URL) */
607
+ icon?: string;
608
+ /** Optional resource type for styling */
609
+ type?: ResourceType;
610
+ }
611
+ /**
612
+ * Stored session resource with full metadata
613
+ */
614
+ interface StoredSessionResource extends SessionResource {
615
+ /** Full ID: "appName:resourceId" */
616
+ fullId: string;
617
+ /** Source app name */
618
+ appName: string;
619
+ /** Push timestamp (ISO 8601) */
620
+ pushedAt: string;
621
+ }
592
622
  interface SDKEvents {
593
623
  connected: () => void;
594
624
  disconnected: (reason: string) => void;
@@ -598,8 +628,49 @@ interface SDKEvents {
598
628
  name: string;
599
629
  arguments: Record<string, unknown>;
600
630
  }) => void;
631
+ /** Called when a session resource is pushed or updated */
632
+ resourcePushed: (resource: StoredSessionResource) => void;
633
+ /** Called when user removes a session resource from Chat UI */
634
+ resourceRemoved: (resourceId: string) => void;
635
+ /** Called when all session resources are cleared by this app */
636
+ resourcesCleared: (appName: string) => void;
601
637
  }
602
638
  type SDKEventName = keyof SDKEvents;
639
+ /**
640
+ * Extended SDK methods available on SanqianSDK instance.
641
+ * Use this interface when you need type-safe access to these methods
642
+ * without type assertions.
643
+ */
644
+ interface SDKExtendedMethods {
645
+ /** Get all session resources pushed by this app (local cache) */
646
+ getSessionResources(): StoredSessionResource[];
647
+ /** Fetch session resources from server (optionally filtered by agent) */
648
+ fetchSessionResources(agentId?: string): Promise<StoredSessionResource[]>;
649
+ /** Cancel an in-flight chat run */
650
+ cancelRun(runId: string): void;
651
+ /** Remove a session resource */
652
+ removeSessionResource(resourceId: string): Promise<void>;
653
+ /** Get messages from a conversation */
654
+ getMessages?(conversationId: string, options?: {
655
+ limit?: number;
656
+ offset?: number;
657
+ }): Promise<{
658
+ messages?: Array<{
659
+ id?: string;
660
+ role: string;
661
+ content: string;
662
+ thinking?: string | null;
663
+ tool_calls?: ToolCall[] | null;
664
+ created_at?: string;
665
+ file_paths?: string[];
666
+ }>;
667
+ has_more?: boolean;
668
+ }>;
669
+ /** Subscribe to events */
670
+ on<T extends SDKEventName>(event: T, listener: SDKEvents[T]): void;
671
+ /** Unsubscribe from events */
672
+ off<T extends SDKEventName>(event: T, listener: SDKEvents[T]): void;
673
+ }
603
674
 
604
675
  declare class SanqianSDK {
605
676
  private config;
@@ -609,6 +680,7 @@ declare class SanqianSDK {
609
680
  private state;
610
681
  private toolHandlers;
611
682
  private contextProviders;
683
+ private sessionResources;
612
684
  private pendingRequests;
613
685
  private heartbeatTimer;
614
686
  private reconnectTimer;
@@ -678,6 +750,7 @@ declare class SanqianSDK {
678
750
  private handleContextGetCurrent;
679
751
  private handleContextGetList;
680
752
  private handleContextGetById;
753
+ private handleResourceRemovedByUser;
681
754
  private handleDisconnect;
682
755
  /**
683
756
  * Check if auto-reconnect should be enabled
@@ -843,6 +916,7 @@ declare class SanqianSDK {
843
916
  persistHistory?: boolean;
844
917
  attachedContexts?: string[];
845
918
  attachedResources?: string[];
919
+ sessionResources?: string[];
846
920
  }): AsyncGenerator<ChatStreamEvent>;
847
921
  /**
848
922
  * Send HITL (Human-in-the-Loop) response to resume after interrupt
@@ -901,6 +975,88 @@ declare class SanqianSDK {
901
975
  * @returns Embedding configuration or { available: false } if not configured
902
976
  */
903
977
  getEmbeddingConfig(): Promise<EmbeddingConfigResult>;
978
+ /**
979
+ * Push a session resource to Sanqian
980
+ *
981
+ * Session resources are temporary context pushed by the app, visible in all Chat UI instances.
982
+ * They persist until the app disconnects or explicitly removes them.
983
+ *
984
+ * @example
985
+ * ```typescript
986
+ * const stored = await sdk.pushResource({
987
+ * title: 'Current Note',
988
+ * content: '<note>\n# My Note\nContent here...\n</note>',
989
+ * summary: 'My Note - 2024-01-15',
990
+ * icon: '📝',
991
+ * type: 'note',
992
+ * });
993
+ * console.log(`Pushed: ${stored.fullId}`); // "my-app:abc123"
994
+ * ```
995
+ *
996
+ * @param resource - Resource to push
997
+ * @returns Stored resource with full ID and metadata
998
+ */
999
+ pushResource(resource: SessionResource): Promise<StoredSessionResource>;
1000
+ /**
1001
+ * Remove a session resource
1002
+ *
1003
+ * @example
1004
+ * ```typescript
1005
+ * await sdk.removeResource('my-app:abc123');
1006
+ * ```
1007
+ *
1008
+ * @param resourceId - Full resource ID (appName:resourceId)
1009
+ */
1010
+ removeResource(resourceId: string): Promise<void>;
1011
+ /**
1012
+ * Clear all session resources pushed by this app
1013
+ *
1014
+ * @example
1015
+ * ```typescript
1016
+ * await sdk.clearResources();
1017
+ * ```
1018
+ */
1019
+ clearResources(): Promise<void>;
1020
+ /**
1021
+ * Get all session resources pushed by this app
1022
+ *
1023
+ * Returns the local cache of resources pushed by this SDK instance.
1024
+ * Does NOT fetch from server - use this for quick local state access.
1025
+ *
1026
+ * @example
1027
+ * ```typescript
1028
+ * const resources = sdk.getSessionResources();
1029
+ * console.log(`Active resources: ${resources.length}`);
1030
+ * for (const r of resources) {
1031
+ * console.log(`- ${r.fullId}: ${r.title}`);
1032
+ * }
1033
+ * ```
1034
+ *
1035
+ * @returns Array of stored session resources
1036
+ */
1037
+ getSessionResources(): StoredSessionResource[];
1038
+ /**
1039
+ * Fetch session resources from server
1040
+ *
1041
+ * Unlike getSessionResources() which returns only this app's local cache,
1042
+ * this method fetches session resources from the server.
1043
+ *
1044
+ * @example
1045
+ * ```typescript
1046
+ * // Fetch ALL resources (for backend/debugging)
1047
+ * const allResources = await sdk.fetchSessionResources();
1048
+ *
1049
+ * // Fetch resources filtered by agent (for UI display)
1050
+ * const agentResources = await sdk.fetchSessionResources('assistant');
1051
+ * ```
1052
+ *
1053
+ * @param agentId - Optional agent ID to filter resources by association.
1054
+ * - If not provided: returns ALL resources
1055
+ * - If provided: returns only resources from apps configured
1056
+ * in the agent's attached_contexts
1057
+ * @returns Array of session resources
1058
+ */
1059
+ fetchSessionResources(agentId?: string): Promise<StoredSessionResource[]>;
904
1060
  /**
905
1061
  * List available capabilities (tools, skills, agents)
906
1062
  *
@@ -1173,4 +1329,4 @@ declare class SanqianSDKError extends Error {
1173
1329
  */
1174
1330
  declare function createSDKError(code: SDKErrorCode, details?: string): SanqianSDKError;
1175
1331
 
1176
- 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 ContextCapability, type ContextData, type ContextListItem, type ContextProvider, Conversation, type ConversationDetail, type ConversationHistoryResult, type ConversationInfo, type ConversationMessage, DiscoveryManager, type EmbeddingConfigResult, ErrorMessages, type HitlInterruptPayload, type HitlInterruptType, type HitlResponse, type HitlRiskLevel, type JSONSchema, type JSONSchemaProperty, type ListCapabilitiesOptions, type RemoteToolDefinition, type ResourceListOptions, type ResourceListResult, type ResourceType, SANQIAN_WEBSITE, type SDKConfig, SDKErrorCode, type SDKEventName, type SDKEvents, SanqianSDK, SanqianSDKError, type SearchCapabilitiesOptions, type SkillCapability, type ToolCall, type ToolCapability, type ToolDefinition, createSDKError };
1332
+ 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 ContextCapability, type ContextData, type ContextListItem, type ContextProvider, Conversation, type ConversationDetail, type ConversationHistoryResult, type ConversationInfo, type ConversationMessage, DiscoveryManager, type EmbeddingConfigResult, ErrorMessages, type HitlInterruptPayload, type HitlInterruptType, type HitlResponse, type HitlRiskLevel, type JSONSchema, type JSONSchemaProperty, type ListCapabilitiesOptions, type RemoteToolDefinition, type ResourceListOptions, type ResourceListResult, type ResourceType, SANQIAN_WEBSITE, type SDKConfig, SDKErrorCode, type SDKEventName, type SDKEvents, type SDKExtendedMethods, SanqianSDK, SanqianSDKError, type SearchCapabilitiesOptions, type SessionResource, type SkillCapability, type StoredSessionResource, type ToolCall, type ToolCapability, type ToolDefinition, createSDKError };
package/dist/index.d.ts CHANGED
@@ -589,6 +589,36 @@ interface SearchCapabilitiesOptions {
589
589
  /** Exclude these IDs */
590
590
  exclude?: string[];
591
591
  }
592
+ /**
593
+ * Session resource pushed by an app.
594
+ * Content is provided at push time (not fetched like attached_resources).
595
+ * Global scope - visible in all Chat UI instances, persists until app disconnects.
596
+ */
597
+ interface SessionResource {
598
+ /** Resource ID (auto-generated if not provided) */
599
+ id?: string;
600
+ /** Display title (required) */
601
+ title: string;
602
+ /** Content (required, format controlled by app) */
603
+ content: string;
604
+ /** Optional summary for UI tooltip */
605
+ summary?: string;
606
+ /** Optional icon (emoji or URL) */
607
+ icon?: string;
608
+ /** Optional resource type for styling */
609
+ type?: ResourceType;
610
+ }
611
+ /**
612
+ * Stored session resource with full metadata
613
+ */
614
+ interface StoredSessionResource extends SessionResource {
615
+ /** Full ID: "appName:resourceId" */
616
+ fullId: string;
617
+ /** Source app name */
618
+ appName: string;
619
+ /** Push timestamp (ISO 8601) */
620
+ pushedAt: string;
621
+ }
592
622
  interface SDKEvents {
593
623
  connected: () => void;
594
624
  disconnected: (reason: string) => void;
@@ -598,8 +628,49 @@ interface SDKEvents {
598
628
  name: string;
599
629
  arguments: Record<string, unknown>;
600
630
  }) => void;
631
+ /** Called when a session resource is pushed or updated */
632
+ resourcePushed: (resource: StoredSessionResource) => void;
633
+ /** Called when user removes a session resource from Chat UI */
634
+ resourceRemoved: (resourceId: string) => void;
635
+ /** Called when all session resources are cleared by this app */
636
+ resourcesCleared: (appName: string) => void;
601
637
  }
602
638
  type SDKEventName = keyof SDKEvents;
639
+ /**
640
+ * Extended SDK methods available on SanqianSDK instance.
641
+ * Use this interface when you need type-safe access to these methods
642
+ * without type assertions.
643
+ */
644
+ interface SDKExtendedMethods {
645
+ /** Get all session resources pushed by this app (local cache) */
646
+ getSessionResources(): StoredSessionResource[];
647
+ /** Fetch session resources from server (optionally filtered by agent) */
648
+ fetchSessionResources(agentId?: string): Promise<StoredSessionResource[]>;
649
+ /** Cancel an in-flight chat run */
650
+ cancelRun(runId: string): void;
651
+ /** Remove a session resource */
652
+ removeSessionResource(resourceId: string): Promise<void>;
653
+ /** Get messages from a conversation */
654
+ getMessages?(conversationId: string, options?: {
655
+ limit?: number;
656
+ offset?: number;
657
+ }): Promise<{
658
+ messages?: Array<{
659
+ id?: string;
660
+ role: string;
661
+ content: string;
662
+ thinking?: string | null;
663
+ tool_calls?: ToolCall[] | null;
664
+ created_at?: string;
665
+ file_paths?: string[];
666
+ }>;
667
+ has_more?: boolean;
668
+ }>;
669
+ /** Subscribe to events */
670
+ on<T extends SDKEventName>(event: T, listener: SDKEvents[T]): void;
671
+ /** Unsubscribe from events */
672
+ off<T extends SDKEventName>(event: T, listener: SDKEvents[T]): void;
673
+ }
603
674
 
604
675
  declare class SanqianSDK {
605
676
  private config;
@@ -609,6 +680,7 @@ declare class SanqianSDK {
609
680
  private state;
610
681
  private toolHandlers;
611
682
  private contextProviders;
683
+ private sessionResources;
612
684
  private pendingRequests;
613
685
  private heartbeatTimer;
614
686
  private reconnectTimer;
@@ -678,6 +750,7 @@ declare class SanqianSDK {
678
750
  private handleContextGetCurrent;
679
751
  private handleContextGetList;
680
752
  private handleContextGetById;
753
+ private handleResourceRemovedByUser;
681
754
  private handleDisconnect;
682
755
  /**
683
756
  * Check if auto-reconnect should be enabled
@@ -843,6 +916,7 @@ declare class SanqianSDK {
843
916
  persistHistory?: boolean;
844
917
  attachedContexts?: string[];
845
918
  attachedResources?: string[];
919
+ sessionResources?: string[];
846
920
  }): AsyncGenerator<ChatStreamEvent>;
847
921
  /**
848
922
  * Send HITL (Human-in-the-Loop) response to resume after interrupt
@@ -901,6 +975,88 @@ declare class SanqianSDK {
901
975
  * @returns Embedding configuration or { available: false } if not configured
902
976
  */
903
977
  getEmbeddingConfig(): Promise<EmbeddingConfigResult>;
978
+ /**
979
+ * Push a session resource to Sanqian
980
+ *
981
+ * Session resources are temporary context pushed by the app, visible in all Chat UI instances.
982
+ * They persist until the app disconnects or explicitly removes them.
983
+ *
984
+ * @example
985
+ * ```typescript
986
+ * const stored = await sdk.pushResource({
987
+ * title: 'Current Note',
988
+ * content: '<note>\n# My Note\nContent here...\n</note>',
989
+ * summary: 'My Note - 2024-01-15',
990
+ * icon: '📝',
991
+ * type: 'note',
992
+ * });
993
+ * console.log(`Pushed: ${stored.fullId}`); // "my-app:abc123"
994
+ * ```
995
+ *
996
+ * @param resource - Resource to push
997
+ * @returns Stored resource with full ID and metadata
998
+ */
999
+ pushResource(resource: SessionResource): Promise<StoredSessionResource>;
1000
+ /**
1001
+ * Remove a session resource
1002
+ *
1003
+ * @example
1004
+ * ```typescript
1005
+ * await sdk.removeResource('my-app:abc123');
1006
+ * ```
1007
+ *
1008
+ * @param resourceId - Full resource ID (appName:resourceId)
1009
+ */
1010
+ removeResource(resourceId: string): Promise<void>;
1011
+ /**
1012
+ * Clear all session resources pushed by this app
1013
+ *
1014
+ * @example
1015
+ * ```typescript
1016
+ * await sdk.clearResources();
1017
+ * ```
1018
+ */
1019
+ clearResources(): Promise<void>;
1020
+ /**
1021
+ * Get all session resources pushed by this app
1022
+ *
1023
+ * Returns the local cache of resources pushed by this SDK instance.
1024
+ * Does NOT fetch from server - use this for quick local state access.
1025
+ *
1026
+ * @example
1027
+ * ```typescript
1028
+ * const resources = sdk.getSessionResources();
1029
+ * console.log(`Active resources: ${resources.length}`);
1030
+ * for (const r of resources) {
1031
+ * console.log(`- ${r.fullId}: ${r.title}`);
1032
+ * }
1033
+ * ```
1034
+ *
1035
+ * @returns Array of stored session resources
1036
+ */
1037
+ getSessionResources(): StoredSessionResource[];
1038
+ /**
1039
+ * Fetch session resources from server
1040
+ *
1041
+ * Unlike getSessionResources() which returns only this app's local cache,
1042
+ * this method fetches session resources from the server.
1043
+ *
1044
+ * @example
1045
+ * ```typescript
1046
+ * // Fetch ALL resources (for backend/debugging)
1047
+ * const allResources = await sdk.fetchSessionResources();
1048
+ *
1049
+ * // Fetch resources filtered by agent (for UI display)
1050
+ * const agentResources = await sdk.fetchSessionResources('assistant');
1051
+ * ```
1052
+ *
1053
+ * @param agentId - Optional agent ID to filter resources by association.
1054
+ * - If not provided: returns ALL resources
1055
+ * - If provided: returns only resources from apps configured
1056
+ * in the agent's attached_contexts
1057
+ * @returns Array of session resources
1058
+ */
1059
+ fetchSessionResources(agentId?: string): Promise<StoredSessionResource[]>;
904
1060
  /**
905
1061
  * List available capabilities (tools, skills, agents)
906
1062
  *
@@ -1173,4 +1329,4 @@ declare class SanqianSDKError extends Error {
1173
1329
  */
1174
1330
  declare function createSDKError(code: SDKErrorCode, details?: string): SanqianSDKError;
1175
1331
 
1176
- 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 ContextCapability, type ContextData, type ContextListItem, type ContextProvider, Conversation, type ConversationDetail, type ConversationHistoryResult, type ConversationInfo, type ConversationMessage, DiscoveryManager, type EmbeddingConfigResult, ErrorMessages, type HitlInterruptPayload, type HitlInterruptType, type HitlResponse, type HitlRiskLevel, type JSONSchema, type JSONSchemaProperty, type ListCapabilitiesOptions, type RemoteToolDefinition, type ResourceListOptions, type ResourceListResult, type ResourceType, SANQIAN_WEBSITE, type SDKConfig, SDKErrorCode, type SDKEventName, type SDKEvents, SanqianSDK, SanqianSDKError, type SearchCapabilitiesOptions, type SkillCapability, type ToolCall, type ToolCapability, type ToolDefinition, createSDKError };
1332
+ 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 ContextCapability, type ContextData, type ContextListItem, type ContextProvider, Conversation, type ConversationDetail, type ConversationHistoryResult, type ConversationInfo, type ConversationMessage, DiscoveryManager, type EmbeddingConfigResult, ErrorMessages, type HitlInterruptPayload, type HitlInterruptType, type HitlResponse, type HitlRiskLevel, type JSONSchema, type JSONSchemaProperty, type ListCapabilitiesOptions, type RemoteToolDefinition, type ResourceListOptions, type ResourceListResult, type ResourceType, SANQIAN_WEBSITE, type SDKConfig, SDKErrorCode, type SDKEventName, type SDKEvents, type SDKExtendedMethods, SanqianSDK, SanqianSDKError, type SearchCapabilitiesOptions, type SessionResource, type SkillCapability, type StoredSessionResource, type ToolCall, type ToolCapability, type ToolDefinition, createSDKError };
package/dist/index.js CHANGED
@@ -515,6 +515,8 @@ var SanqianSDK = class _SanqianSDK {
515
515
  toolHandlers = /* @__PURE__ */ new Map();
516
516
  // Context providers by id
517
517
  contextProviders = /* @__PURE__ */ new Map();
518
+ // Session resources pushed by this app (local cache)
519
+ sessionResources = /* @__PURE__ */ new Map();
518
520
  // Pending request futures
519
521
  pendingRequests = /* @__PURE__ */ new Map();
520
522
  // Timers
@@ -716,6 +718,7 @@ var SanqianSDK = class _SanqianSDK {
716
718
  this.ws.close(1e3, "Client disconnect");
717
719
  this.ws = null;
718
720
  }
721
+ this.sessionResources.clear();
719
722
  this.state = {
720
723
  connected: false,
721
724
  registering: false,
@@ -803,6 +806,9 @@ var SanqianSDK = class _SanqianSDK {
803
806
  case "context_get_by_id":
804
807
  this.handleContextGetById(message);
805
808
  break;
809
+ case "resource_removed_by_user":
810
+ this.handleResourceRemovedByUser(message);
811
+ break;
806
812
  default:
807
813
  this.warn(`Unknown message type: ${type}`);
808
814
  }
@@ -1055,6 +1061,15 @@ var SanqianSDK = class _SanqianSDK {
1055
1061
  }
1056
1062
  }
1057
1063
  // ============================================
1064
+ // Session Resource Handlers
1065
+ // ============================================
1066
+ handleResourceRemovedByUser(message) {
1067
+ const { resourceId } = message;
1068
+ this.log(`Resource removed by user: ${resourceId}`);
1069
+ this.sessionResources.delete(resourceId);
1070
+ this.emit("resourceRemoved", resourceId);
1071
+ }
1072
+ // ============================================
1058
1073
  // Connection Management
1059
1074
  // ============================================
1060
1075
  handleDisconnect(reason) {
@@ -1602,6 +1617,7 @@ var SanqianSDK = class _SanqianSDK {
1602
1617
  auto_discover_subagents: options?.autoDiscoverSubagents ?? false,
1603
1618
  attached_contexts: options?.attachedContexts,
1604
1619
  attached_resources: options?.attachedResources,
1620
+ session_resources: options?.sessionResources,
1605
1621
  remote_tools: options?.remoteTools?.map((t) => ({
1606
1622
  name: t.name,
1607
1623
  description: t.description,
@@ -1754,6 +1770,159 @@ var SanqianSDK = class _SanqianSDK {
1754
1770
  return response.config || { available: false };
1755
1771
  }
1756
1772
  // ============================================
1773
+ // Session Resources API
1774
+ // ============================================
1775
+ /**
1776
+ * Push a session resource to Sanqian
1777
+ *
1778
+ * Session resources are temporary context pushed by the app, visible in all Chat UI instances.
1779
+ * They persist until the app disconnects or explicitly removes them.
1780
+ *
1781
+ * @example
1782
+ * ```typescript
1783
+ * const stored = await sdk.pushResource({
1784
+ * title: 'Current Note',
1785
+ * content: '<note>\n# My Note\nContent here...\n</note>',
1786
+ * summary: 'My Note - 2024-01-15',
1787
+ * icon: '📝',
1788
+ * type: 'note',
1789
+ * });
1790
+ * console.log(`Pushed: ${stored.fullId}`); // "my-app:abc123"
1791
+ * ```
1792
+ *
1793
+ * @param resource - Resource to push
1794
+ * @returns Stored resource with full ID and metadata
1795
+ */
1796
+ async pushResource(resource) {
1797
+ await this.ensureReady();
1798
+ const msgId = this.generateId();
1799
+ const message = {
1800
+ id: msgId,
1801
+ type: "resource_push",
1802
+ resource
1803
+ };
1804
+ const response = await this.sendAndWait(message, msgId, 1e4);
1805
+ if (!response.success || !response.resourceId) {
1806
+ throw createSDKError("REQUEST_FAILED" /* REQUEST_FAILED */, response.error || "Failed to push resource");
1807
+ }
1808
+ const stored = {
1809
+ ...resource,
1810
+ fullId: response.resourceId,
1811
+ appName: this.config.appName,
1812
+ pushedAt: (/* @__PURE__ */ new Date()).toISOString()
1813
+ };
1814
+ this.sessionResources.set(stored.fullId, stored);
1815
+ this.emit("resourcePushed", stored);
1816
+ this.log(`Pushed resource: ${stored.fullId}`);
1817
+ return stored;
1818
+ }
1819
+ /**
1820
+ * Remove a session resource
1821
+ *
1822
+ * @example
1823
+ * ```typescript
1824
+ * await sdk.removeResource('my-app:abc123');
1825
+ * ```
1826
+ *
1827
+ * @param resourceId - Full resource ID (appName:resourceId)
1828
+ */
1829
+ async removeResource(resourceId) {
1830
+ await this.ensureReady();
1831
+ const msgId = this.generateId();
1832
+ const message = {
1833
+ id: msgId,
1834
+ type: "resource_remove",
1835
+ resourceId
1836
+ };
1837
+ const response = await this.sendAndWait(message, msgId, 1e4);
1838
+ if (!response.success) {
1839
+ throw createSDKError("REQUEST_FAILED" /* REQUEST_FAILED */, response.error || "Failed to remove resource");
1840
+ }
1841
+ this.sessionResources.delete(resourceId);
1842
+ this.emit("resourceRemoved", resourceId);
1843
+ this.log(`Removed resource: ${resourceId}`);
1844
+ }
1845
+ /**
1846
+ * Clear all session resources pushed by this app
1847
+ *
1848
+ * @example
1849
+ * ```typescript
1850
+ * await sdk.clearResources();
1851
+ * ```
1852
+ */
1853
+ async clearResources() {
1854
+ await this.ensureReady();
1855
+ const msgId = this.generateId();
1856
+ const message = {
1857
+ id: msgId,
1858
+ type: "resource_clear"
1859
+ };
1860
+ const response = await this.sendAndWait(message, msgId, 1e4);
1861
+ if (!response.success) {
1862
+ throw createSDKError("REQUEST_FAILED" /* REQUEST_FAILED */, response.error || "Failed to clear resources");
1863
+ }
1864
+ this.sessionResources.clear();
1865
+ this.emit("resourcesCleared", this.config.appName);
1866
+ this.log("Cleared all resources");
1867
+ }
1868
+ /**
1869
+ * Get all session resources pushed by this app
1870
+ *
1871
+ * Returns the local cache of resources pushed by this SDK instance.
1872
+ * Does NOT fetch from server - use this for quick local state access.
1873
+ *
1874
+ * @example
1875
+ * ```typescript
1876
+ * const resources = sdk.getSessionResources();
1877
+ * console.log(`Active resources: ${resources.length}`);
1878
+ * for (const r of resources) {
1879
+ * console.log(`- ${r.fullId}: ${r.title}`);
1880
+ * }
1881
+ * ```
1882
+ *
1883
+ * @returns Array of stored session resources
1884
+ */
1885
+ getSessionResources() {
1886
+ return Array.from(this.sessionResources.values());
1887
+ }
1888
+ /**
1889
+ * Fetch session resources from server
1890
+ *
1891
+ * Unlike getSessionResources() which returns only this app's local cache,
1892
+ * this method fetches session resources from the server.
1893
+ *
1894
+ * @example
1895
+ * ```typescript
1896
+ * // Fetch ALL resources (for backend/debugging)
1897
+ * const allResources = await sdk.fetchSessionResources();
1898
+ *
1899
+ * // Fetch resources filtered by agent (for UI display)
1900
+ * const agentResources = await sdk.fetchSessionResources('assistant');
1901
+ * ```
1902
+ *
1903
+ * @param agentId - Optional agent ID to filter resources by association.
1904
+ * - If not provided: returns ALL resources
1905
+ * - If provided: returns only resources from apps configured
1906
+ * in the agent's attached_contexts
1907
+ * @returns Array of session resources
1908
+ */
1909
+ async fetchSessionResources(agentId) {
1910
+ await this.ensureReady();
1911
+ let url = `${this.getHttpBaseUrl()}/api/sdk/session-resources`;
1912
+ if (agentId) {
1913
+ const params = new URLSearchParams({ agent_id: agentId });
1914
+ url += `?${params.toString()}`;
1915
+ }
1916
+ const response = await fetch(url);
1917
+ if (!response.ok) {
1918
+ throw createSDKError(
1919
+ "REQUEST_FAILED" /* REQUEST_FAILED */,
1920
+ `Failed to fetch session resources: ${response.statusText}`
1921
+ );
1922
+ }
1923
+ return response.json();
1924
+ }
1925
+ // ============================================
1757
1926
  // Capability Discovery API
1758
1927
  // ============================================
1759
1928
  /**