@yourgpt/copilot-sdk 0.1.1 → 1.0.1

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.
@@ -1,9 +1,52 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React__default from 'react';
3
- import { M as MessageAttachment, u as ToolCall, f as Source, w as LLMConfig, y as CopilotConfig, m as ToolsConfig, s as Message, z as ActionDefinition, p as CapturedContext, n as ToolConsentRequest, T as ToolType, o as ToolConsentResponse, S as ScreenshotOptions, C as ConsoleLogOptions, N as NetworkRequestOptions, I as IntentDetectionResult, O as InternalKnowledgeBaseConfig, R as InternalKnowledgeBaseSearchResponse, Q as InternalKnowledgeBaseResult } from '../thread-CLmfwine.cjs';
4
- export { A as ActionParameter, x as CloudConfig, W as PersistenceConfig, U as Thread, V as ThreadData, X as ThreadStorageAdapter, j as generateSuggestionReason } from '../thread-CLmfwine.cjs';
5
- import { T as ToolDefinition, P as PermissionLevel, c as ToolInputSchema, k as ToolExecution$1, e as ToolContext, b as ToolResponse$1, f as ToolRenderProps, h as ToolSet, U as UnifiedToolCall, q as PermissionStorageConfig, r as PermissionStorageAdapter } from '../tools-eeJ5iEC4.cjs';
6
- export { l as AgentLoopConfig, a as ToolExecutionStatus, p as ToolPermission } from '../tools-eeJ5iEC4.cjs';
3
+ import { q as LLMConfig, s as CopilotConfig, l as ToolsConfig, t as ActionDefinition, o as CapturedContext, m as ToolConsentRequest, T as ToolType, n as ToolConsentResponse, S as ScreenshotOptions, C as ConsoleLogOptions, N as NetworkRequestOptions, I as IntentDetectionResult, z as InternalKnowledgeBaseConfig, D as InternalKnowledgeBaseSearchResponse, B as InternalKnowledgeBaseResult, $ as ThreadManagerState, a0 as LoadStatus, X as ThreadManagerConfig, M as ThreadManager, Y as ThreadManagerCallbacks, Z as CreateThreadOptions, _ as UpdateThreadOptions } from '../ThreadManager-BCVt-_k_.cjs';
4
+ export { A as ActionParameter, r as CloudConfig, a1 as LocalStorageAdapterConfig, Q as createLocalStorageAdapter, U as createMemoryAdapter, i as generateSuggestionReason } from '../ThreadManager-BCVt-_k_.cjs';
5
+ import { X as AsyncThreadStorageAdapter, M as MessageAttachment, i as ToolCall, S as Source, T as ToolDefinition, x as PermissionLevel, c as ToolInputSchema, g as Message, s as ToolExecution$1, e as ToolContext, b as ToolResponse$1, n as ToolRenderProps, p as ToolSet, U as UnifiedToolCall, k as Thread, l as ThreadData, _ as ThreadStorageAdapter, z as PermissionStorageConfig, B as PermissionStorageAdapter } from '../types-BtAaOV07.cjs';
6
+ export { t as AgentLoopConfig, P as PersistenceConfig, m as ThreadStorageAdapter, a as ToolExecutionStatus, y as ToolPermission } from '../types-BtAaOV07.cjs';
7
+
8
+ /**
9
+ * Server Thread Storage Adapter
10
+ *
11
+ * Fetches threads from a user-provided API endpoint.
12
+ * Implements AsyncThreadStorageAdapter for optimized single-thread operations.
13
+ */
14
+
15
+ /**
16
+ * Configuration for server adapter
17
+ */
18
+ interface ServerAdapterConfig {
19
+ /**
20
+ * Endpoint URL for thread API
21
+ * @example "/api/threads"
22
+ */
23
+ endpoint: string;
24
+ /**
25
+ * Additional headers to include in requests (e.g., auth tokens)
26
+ */
27
+ headers?: Record<string, string>;
28
+ /**
29
+ * Custom fetch function (useful for testing or adding interceptors)
30
+ * @default globalThis.fetch
31
+ */
32
+ fetch?: typeof fetch;
33
+ }
34
+ /**
35
+ * Create a server-based thread storage adapter
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const adapter = createServerAdapter({
40
+ * threadsUrl: "/api/threads",
41
+ * headers: {
42
+ * Authorization: `Bearer ${token}`,
43
+ * },
44
+ * });
45
+ *
46
+ * const { threads } = useThreadManager({ adapter });
47
+ * ```
48
+ */
49
+ declare function createServerAdapter(config: ServerAdapterConfig): AsyncThreadStorageAdapter;
7
50
 
8
51
  /**
9
52
  * Message Types
@@ -717,6 +760,7 @@ interface CopilotContextValue {
717
760
  sendMessage: (content: string, attachments?: MessageAttachment[]) => Promise<void>;
718
761
  stop: () => void;
719
762
  clearMessages: () => void;
763
+ setMessages: (messages: UIMessage[]) => void;
720
764
  regenerate: (messageId?: string) => Promise<void>;
721
765
  registerTool: (tool: ToolDefinition) => void;
722
766
  unregisterTool: (name: string) => void;
@@ -1610,6 +1654,328 @@ interface DevLoggerState {
1610
1654
  */
1611
1655
  declare function useDevLogger(): DevLoggerState;
1612
1656
 
1657
+ /**
1658
+ * ReactThreadManagerState - React-specific implementation of ThreadManagerState
1659
+ *
1660
+ * This class implements the ThreadManagerState interface with callback-based
1661
+ * reactivity for use with React's useSyncExternalStore.
1662
+ *
1663
+ * Pattern follows ReactChatState for consistency.
1664
+ */
1665
+
1666
+ /**
1667
+ * ReactThreadManagerState implements ThreadManagerState with callback-based reactivity
1668
+ *
1669
+ * @example
1670
+ * ```tsx
1671
+ * const state = new ReactThreadManagerState();
1672
+ *
1673
+ * // Subscribe to changes (for useSyncExternalStore)
1674
+ * const unsubscribe = state.subscribe(() => {
1675
+ * console.log('State changed');
1676
+ * });
1677
+ *
1678
+ * // Get snapshot (for useSyncExternalStore)
1679
+ * const threads = state.threads;
1680
+ * ```
1681
+ */
1682
+ declare class ReactThreadManagerState implements ThreadManagerState {
1683
+ private _threads;
1684
+ private _currentThreadId;
1685
+ private _currentThread;
1686
+ private _loadStatus;
1687
+ private _error;
1688
+ private subscribers;
1689
+ constructor(initialThreads?: Thread[]);
1690
+ get threads(): Thread[];
1691
+ get currentThreadId(): string | null;
1692
+ get currentThread(): ThreadData | null;
1693
+ get loadStatus(): LoadStatus;
1694
+ get error(): Error | undefined;
1695
+ set threads(value: Thread[]);
1696
+ setThreads(threads: Thread[]): void;
1697
+ setCurrentThread(thread: ThreadData | null): void;
1698
+ setCurrentThreadId(id: string | null): void;
1699
+ addThread(thread: Thread): void;
1700
+ updateThread(id: string, updates: Partial<Thread>): void;
1701
+ removeThread(id: string): void;
1702
+ setLoadStatus(status: LoadStatus): void;
1703
+ setError(error: Error | undefined): void;
1704
+ /**
1705
+ * Subscribe to state changes.
1706
+ * Returns an unsubscribe function.
1707
+ *
1708
+ * @example
1709
+ * ```tsx
1710
+ * const threads = useSyncExternalStore(
1711
+ * state.subscribe,
1712
+ * () => state.threads
1713
+ * );
1714
+ * ```
1715
+ */
1716
+ subscribe: (callback: () => void) => (() => void);
1717
+ getThreadsSnapshot(): Thread[];
1718
+ getCurrentThreadSnapshot(): ThreadData | null;
1719
+ getLoadStatusSnapshot(): LoadStatus;
1720
+ getErrorSnapshot(): Error | undefined;
1721
+ private notify;
1722
+ /**
1723
+ * Cleanup subscriptions
1724
+ */
1725
+ dispose(): void;
1726
+ }
1727
+ /**
1728
+ * Create a ReactThreadManagerState instance
1729
+ */
1730
+ declare function createReactThreadManagerState(initialThreads?: Thread[]): ReactThreadManagerState;
1731
+
1732
+ /**
1733
+ * ReactThreadManager - React adapter for ThreadManager
1734
+ *
1735
+ * Extends ThreadManager with React-specific state management.
1736
+ */
1737
+
1738
+ /**
1739
+ * Configuration for ReactThreadManager
1740
+ */
1741
+ interface ReactThreadManagerConfig extends Omit<ThreadManagerConfig, "state"> {
1742
+ }
1743
+ /**
1744
+ * ReactThreadManager - React adapter for ThreadManager
1745
+ *
1746
+ * Uses ReactThreadManagerState for React's useSyncExternalStore compatibility.
1747
+ *
1748
+ * @example
1749
+ * ```tsx
1750
+ * const manager = createReactThreadManager();
1751
+ *
1752
+ * // In a component using useSyncExternalStore
1753
+ * const threads = useSyncExternalStore(
1754
+ * manager.subscribe,
1755
+ * manager.getThreadsSnapshot
1756
+ * );
1757
+ * ```
1758
+ */
1759
+ declare class ReactThreadManager extends ThreadManager {
1760
+ protected state: ReactThreadManagerState;
1761
+ constructor(config?: ReactThreadManagerConfig, callbacks?: ThreadManagerCallbacks);
1762
+ /**
1763
+ * Subscribe to state changes
1764
+ * Use with useSyncExternalStore
1765
+ */
1766
+ subscribe: (callback: () => void) => (() => void);
1767
+ /**
1768
+ * Get threads snapshot
1769
+ */
1770
+ getThreadsSnapshot: () => typeof this.threads;
1771
+ /**
1772
+ * Get current thread snapshot
1773
+ */
1774
+ getCurrentThreadSnapshot: () => typeof this.currentThread;
1775
+ /**
1776
+ * Get current thread ID snapshot
1777
+ */
1778
+ getCurrentThreadIdSnapshot: () => string | null;
1779
+ /**
1780
+ * Get load status snapshot
1781
+ */
1782
+ getLoadStatusSnapshot: () => typeof this.loadStatus;
1783
+ /**
1784
+ * Get error snapshot
1785
+ */
1786
+ getErrorSnapshot: () => typeof this.error;
1787
+ /**
1788
+ * Get isLoading snapshot
1789
+ */
1790
+ getIsLoadingSnapshot: () => boolean;
1791
+ private static readonly EMPTY_THREADS;
1792
+ private static readonly IDLE_STATUS;
1793
+ /**
1794
+ * Get threads snapshot for server (always empty for hydration consistency)
1795
+ */
1796
+ getThreadsServerSnapshot: () => Thread[];
1797
+ /**
1798
+ * Get current thread snapshot for server (always null)
1799
+ */
1800
+ getCurrentThreadServerSnapshot: () => typeof this.currentThread;
1801
+ /**
1802
+ * Get current thread ID snapshot for server (always null)
1803
+ */
1804
+ getCurrentThreadIdServerSnapshot: () => string | null;
1805
+ /**
1806
+ * Get load status snapshot for server (always "idle")
1807
+ */
1808
+ getLoadStatusServerSnapshot: () => typeof this.loadStatus;
1809
+ /**
1810
+ * Get error snapshot for server (always undefined)
1811
+ */
1812
+ getErrorServerSnapshot: () => typeof this.error;
1813
+ /**
1814
+ * Get isLoading snapshot for server (always false)
1815
+ */
1816
+ getIsLoadingServerSnapshot: () => boolean;
1817
+ /**
1818
+ * Dispose of the manager
1819
+ */
1820
+ dispose(): Promise<void>;
1821
+ }
1822
+ /**
1823
+ * Create a ReactThreadManager instance
1824
+ */
1825
+ declare function createReactThreadManager(config?: ReactThreadManagerConfig, callbacks?: ThreadManagerCallbacks): ReactThreadManager;
1826
+
1827
+ /**
1828
+ * useThreadManager - React hook for thread management
1829
+ *
1830
+ * Provides thread CRUD operations with localStorage persistence by default.
1831
+ * Uses useSyncExternalStore for optimal React integration.
1832
+ */
1833
+
1834
+ /**
1835
+ * Configuration for useThreadManager hook
1836
+ */
1837
+ interface UseThreadManagerConfig extends ReactThreadManagerConfig {
1838
+ /**
1839
+ * Storage adapter for persistence
1840
+ * @default localStorage adapter
1841
+ */
1842
+ adapter?: ThreadStorageAdapter | AsyncThreadStorageAdapter;
1843
+ /**
1844
+ * Debounce delay for auto-save (ms)
1845
+ * @default 1000
1846
+ */
1847
+ saveDebounce?: number;
1848
+ /**
1849
+ * Whether to auto-load threads on mount
1850
+ * @default true
1851
+ */
1852
+ autoLoad?: boolean;
1853
+ /**
1854
+ * Whether to auto-restore the last active thread on load
1855
+ * Requires adapter to support getLastActiveThreadId/setLastActiveThreadId
1856
+ * @default true
1857
+ */
1858
+ autoRestoreLastThread?: boolean;
1859
+ /**
1860
+ * Callbacks for thread events
1861
+ */
1862
+ callbacks?: ThreadManagerCallbacks;
1863
+ }
1864
+ /**
1865
+ * Return type for useThreadManager hook
1866
+ */
1867
+ interface UseThreadManagerReturn {
1868
+ /** All threads (metadata only) */
1869
+ threads: Thread[];
1870
+ /** Currently loaded thread (with messages) */
1871
+ currentThread: ThreadData | null;
1872
+ /** Currently selected thread ID */
1873
+ currentThreadId: string | null;
1874
+ /** Whether threads are currently loading */
1875
+ isLoading: boolean;
1876
+ /** Current load status */
1877
+ loadStatus: LoadStatus;
1878
+ /** Current error */
1879
+ error: Error | undefined;
1880
+ /**
1881
+ * Create a new thread
1882
+ */
1883
+ createThread: (options?: CreateThreadOptions) => Promise<ThreadData>;
1884
+ /**
1885
+ * Switch to a different thread
1886
+ */
1887
+ switchThread: (id: string) => Promise<ThreadData | null>;
1888
+ /**
1889
+ * Update the current thread
1890
+ */
1891
+ updateCurrentThread: (updates: UpdateThreadOptions) => Promise<void>;
1892
+ /**
1893
+ * Delete a thread
1894
+ */
1895
+ deleteThread: (id: string) => Promise<void>;
1896
+ /**
1897
+ * Clear the current thread selection
1898
+ */
1899
+ clearCurrentThread: () => void;
1900
+ /**
1901
+ * Refresh threads from storage
1902
+ */
1903
+ refreshThreads: () => Promise<void>;
1904
+ /**
1905
+ * Save changes immediately (bypass debounce)
1906
+ */
1907
+ saveNow: () => Promise<void>;
1908
+ /**
1909
+ * Clear all threads
1910
+ */
1911
+ clearAllThreads: () => Promise<void>;
1912
+ /**
1913
+ * Whether there are pending changes waiting to be saved
1914
+ */
1915
+ hasPendingChanges: boolean;
1916
+ /**
1917
+ * Get messages for the current thread (convenience getter)
1918
+ */
1919
+ messages: Message[];
1920
+ /**
1921
+ * Update messages for the current thread (convenience setter)
1922
+ */
1923
+ setMessages: (messages: Message[]) => Promise<void>;
1924
+ }
1925
+ /**
1926
+ * useThreadManager - React hook for thread management
1927
+ *
1928
+ * Provides thread CRUD operations with localStorage persistence by default.
1929
+ *
1930
+ * @example Basic usage (localStorage by default)
1931
+ * ```tsx
1932
+ * function App() {
1933
+ * const {
1934
+ * threads,
1935
+ * currentThread,
1936
+ * createThread,
1937
+ * switchThread,
1938
+ * updateCurrentThread,
1939
+ * } = useThreadManager();
1940
+ *
1941
+ * return (
1942
+ * <CopilotProvider
1943
+ * runtimeUrl="/api/chat"
1944
+ * threadId={currentThread?.id}
1945
+ * initialMessages={currentThread?.messages}
1946
+ * onMessagesChange={(msgs) => updateCurrentThread({ messages: msgs })}
1947
+ * >
1948
+ * <ThreadPicker
1949
+ * value={currentThread?.id}
1950
+ * threads={threads}
1951
+ * onSelect={switchThread}
1952
+ * onNewThread={() => createThread()}
1953
+ * />
1954
+ * <Chat />
1955
+ * </CopilotProvider>
1956
+ * );
1957
+ * }
1958
+ * ```
1959
+ *
1960
+ * @example With custom adapter
1961
+ * ```tsx
1962
+ * const { threads } = useThreadManager({
1963
+ * adapter: myDatabaseAdapter,
1964
+ * });
1965
+ * ```
1966
+ *
1967
+ * @example With callbacks
1968
+ * ```tsx
1969
+ * const { threads } = useThreadManager({
1970
+ * callbacks: {
1971
+ * onThreadCreated: (thread) => console.log('Created:', thread.id),
1972
+ * onError: (error) => console.error('Error:', error),
1973
+ * },
1974
+ * });
1975
+ * ```
1976
+ */
1977
+ declare function useThreadManager(config?: UseThreadManagerConfig): UseThreadManagerReturn;
1978
+
1613
1979
  /**
1614
1980
  * Create a permission storage adapter based on config
1615
1981
  */
@@ -1843,4 +2209,4 @@ interface UseChatReturn {
1843
2209
  */
1844
2210
  declare function useChat(config: UseChatConfig): UseChatReturn;
1845
2211
 
1846
- export { type AIContextItem, AbstractAgentLoop, AbstractChat, ActionDefinition, type AgentLoopActions, type AgentLoopCallbacks, type AgentLoopState, type CapabilitiesResponse, CapturedContext, type ChatActions, type ChatCallbacks, type ChatConfig, type ChatState, type ChatStatus, type ToolExecution as ChatToolExecution, type ToolResponse as ChatToolResponse, type CombinedChatState, CopilotConfig, type CopilotContextValue, CopilotProvider, type CopilotProviderProps, type AgentLoopState$1 as CoreAgentLoopState, type ChatState$1 as CoreChatState, type DevLoggerState, IntentDetectionResult, type KnowledgeBaseConfig, type KnowledgeBaseResult, type KnowledgeBaseSearchResponse, LLMConfig, Message, PermissionLevel, PermissionStorageAdapter, PermissionStorageConfig, type ProviderCapabilities, ReactChat, type ReactChatConfig, ReactChatState, Source, type Suggestion, ToolConsentRequest, ToolConsentResponse, ToolContext, ToolDefinition, ToolExecution$1 as ToolExecution, ToolResponse$1 as ToolResponse, ToolType, type ToolsActions, ToolsConfig, type ToolsState, type UIMessage, UnifiedToolCall, type UseAIToolsOptions, type UseAIToolsReturn, type UseAgentOptions, type UseAgentReturn, type UseChatConfig, type UseChatReturn, type UseKnowledgeBaseConfig, type UseSuggestionsOptions, type UseSuggestionsReturn, type UseToolConfig, type UseToolExecutorReturn, type UseToolWithSchemaConfig, createPermissionStorage, createReactChat, createReactChatState, createSessionPermissionCache, formatKnowledgeResultsForAI, initialAgentLoopState, searchKnowledgeBase, useAIAction, useAIActions, useAIContext, useAIContexts, useAITools, useAgent, useCapabilities, useChat, useCopilot, useDevLogger, useFeatureSupport, useKnowledgeBase, useSuggestions, useSupportedMediaTypes, useTool, useToolExecutor, useToolWithSchema, useTools, useToolsWithSchema };
2212
+ export { type AIContextItem, AbstractAgentLoop, AbstractChat, ActionDefinition, type AgentLoopActions, type AgentLoopCallbacks, type AgentLoopState, AsyncThreadStorageAdapter, type CapabilitiesResponse, CapturedContext, type ChatActions, type ChatCallbacks, type ChatConfig, type ChatState, type ChatStatus, type ToolExecution as ChatToolExecution, type ToolResponse as ChatToolResponse, type CombinedChatState, CopilotConfig, type CopilotContextValue, CopilotProvider, type CopilotProviderProps, type AgentLoopState$1 as CoreAgentLoopState, type ChatState$1 as CoreChatState, type DevLoggerState, IntentDetectionResult, type KnowledgeBaseConfig, type KnowledgeBaseResult, type KnowledgeBaseSearchResponse, LLMConfig, Message, PermissionLevel, PermissionStorageAdapter, PermissionStorageConfig, type ProviderCapabilities, ReactChat, type ReactChatConfig, ReactChatState, ReactThreadManager, type ReactThreadManagerConfig, ReactThreadManagerState, type ServerAdapterConfig, Source, type Suggestion, Thread, ThreadData, ToolConsentRequest, ToolConsentResponse, ToolContext, ToolDefinition, ToolExecution$1 as ToolExecution, ToolResponse$1 as ToolResponse, ToolType, type ToolsActions, ToolsConfig, type ToolsState, type UIMessage, UnifiedToolCall, type UseAIToolsOptions, type UseAIToolsReturn, type UseAgentOptions, type UseAgentReturn, type UseChatConfig, type UseChatReturn, type UseKnowledgeBaseConfig, type UseSuggestionsOptions, type UseSuggestionsReturn, type UseThreadManagerConfig, type UseThreadManagerReturn, type UseToolConfig, type UseToolExecutorReturn, type UseToolWithSchemaConfig, createPermissionStorage, createReactChat, createReactChatState, createReactThreadManager, createReactThreadManagerState, createServerAdapter, createSessionPermissionCache, formatKnowledgeResultsForAI, initialAgentLoopState, searchKnowledgeBase, useAIAction, useAIActions, useAIContext, useAIContexts, useAITools, useAgent, useCapabilities, useChat, useCopilot, useDevLogger, useFeatureSupport, useKnowledgeBase, useSuggestions, useSupportedMediaTypes, useThreadManager, useTool, useToolExecutor, useToolWithSchema, useTools, useToolsWithSchema };