@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.
- package/LICENSE +21 -0
- package/dist/{thread-CLmfwine.d.ts → ThreadManager-BCVt-_k_.d.cts} +376 -223
- package/dist/{thread-CLmfwine.d.cts → ThreadManager-BjC15mh8.d.ts} +376 -223
- package/dist/{chunk-IH7WXWX4.cjs → chunk-42YQ4ATO.cjs} +889 -2
- package/dist/chunk-42YQ4ATO.cjs.map +1 -0
- package/dist/{chunk-R452HH3J.cjs → chunk-BN75ZW24.cjs} +455 -26
- package/dist/chunk-BN75ZW24.cjs.map +1 -0
- package/dist/{chunk-QWQELTEB.js → chunk-QSEGNATZ.js} +882 -3
- package/dist/chunk-QSEGNATZ.js.map +1 -0
- package/dist/{chunk-FO75W5UI.js → chunk-XAVZZVUL.js} +428 -4
- package/dist/chunk-XAVZZVUL.js.map +1 -0
- package/dist/core/index.cjs +99 -71
- package/dist/core/index.d.cts +4 -4
- package/dist/core/index.d.ts +4 -4
- package/dist/core/index.js +1 -1
- package/dist/react/index.cjs +66 -34
- package/dist/react/index.d.cts +371 -5
- package/dist/react/index.d.ts +371 -5
- package/dist/react/index.js +2 -2
- package/dist/{tools-eeJ5iEC4.d.ts → types-BtAaOV07.d.cts} +367 -1
- package/dist/{tools-eeJ5iEC4.d.cts → types-BtAaOV07.d.ts} +367 -1
- package/dist/ui/index.cjs +1703 -467
- package/dist/ui/index.cjs.map +1 -1
- package/dist/ui/index.d.cts +333 -38
- package/dist/ui/index.d.ts +333 -38
- package/dist/ui/index.js +1699 -467
- package/dist/ui/index.js.map +1 -1
- package/package.json +9 -9
- package/dist/chunk-FO75W5UI.js.map +0 -1
- package/dist/chunk-IH7WXWX4.cjs.map +0 -1
- package/dist/chunk-QWQELTEB.js.map +0 -1
- package/dist/chunk-R452HH3J.cjs.map +0 -1
|
@@ -592,4 +592,370 @@ declare function success<T = unknown>(data?: T, message?: string): ToolResponse<
|
|
|
592
592
|
*/
|
|
593
593
|
declare function failure(error: string): ToolResponse;
|
|
594
594
|
|
|
595
|
-
|
|
595
|
+
/**
|
|
596
|
+
* Message roles in a conversation (OpenAI format)
|
|
597
|
+
*/
|
|
598
|
+
type MessageRole = "user" | "assistant" | "system" | "tool";
|
|
599
|
+
/**
|
|
600
|
+
* A source document from knowledge base
|
|
601
|
+
*/
|
|
602
|
+
interface Source {
|
|
603
|
+
/** Unique identifier */
|
|
604
|
+
id: string;
|
|
605
|
+
/** Source title or filename */
|
|
606
|
+
title: string;
|
|
607
|
+
/** Relevant content snippet */
|
|
608
|
+
content: string;
|
|
609
|
+
/** URL if available */
|
|
610
|
+
url?: string;
|
|
611
|
+
/** Relevance score (0-1) */
|
|
612
|
+
score?: number;
|
|
613
|
+
/** Additional metadata */
|
|
614
|
+
metadata?: Record<string, unknown>;
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Tool/function call in OpenAI format
|
|
618
|
+
* Used in assistant messages when AI wants to call tools
|
|
619
|
+
*/
|
|
620
|
+
interface ToolCall {
|
|
621
|
+
/** Unique identifier for this call */
|
|
622
|
+
id: string;
|
|
623
|
+
/** Always "function" for OpenAI compatibility */
|
|
624
|
+
type: "function";
|
|
625
|
+
/** Function details */
|
|
626
|
+
function: {
|
|
627
|
+
/** Name of the function/tool */
|
|
628
|
+
name: string;
|
|
629
|
+
/** Arguments as JSON string (OpenAI format) */
|
|
630
|
+
arguments: string;
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* Attachment in a message (images, files, etc.)
|
|
635
|
+
*
|
|
636
|
+
* Attachments can be stored as:
|
|
637
|
+
* - Base64 data (free tier, embedded in message)
|
|
638
|
+
* - URL (premium cloud storage, lighter payload)
|
|
639
|
+
*/
|
|
640
|
+
interface MessageAttachment {
|
|
641
|
+
/** Type of attachment */
|
|
642
|
+
type: "image" | "file" | "audio" | "video";
|
|
643
|
+
/** Base64 data (for embedded attachments) */
|
|
644
|
+
data?: string;
|
|
645
|
+
/** URL for cloud-stored attachments (managed cloud storage) */
|
|
646
|
+
url?: string;
|
|
647
|
+
/** MIME type */
|
|
648
|
+
mimeType: string;
|
|
649
|
+
/** Optional filename */
|
|
650
|
+
filename?: string;
|
|
651
|
+
}
|
|
652
|
+
/**
|
|
653
|
+
* Token usage information
|
|
654
|
+
*/
|
|
655
|
+
interface TokenUsage {
|
|
656
|
+
prompt_tokens: number;
|
|
657
|
+
completion_tokens: number;
|
|
658
|
+
total_tokens?: number;
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Message metadata (flexible container for provider-specific data)
|
|
662
|
+
*/
|
|
663
|
+
interface MessageMetadata {
|
|
664
|
+
/** Extended thinking/reasoning (Claude, DeepSeek) */
|
|
665
|
+
thinking?: string;
|
|
666
|
+
/** Knowledge base sources */
|
|
667
|
+
sources?: Source[];
|
|
668
|
+
/** Attachments (images, files) */
|
|
669
|
+
attachments?: MessageAttachment[];
|
|
670
|
+
/** Model used to generate this message */
|
|
671
|
+
model?: string;
|
|
672
|
+
/** Token usage */
|
|
673
|
+
usage?: TokenUsage;
|
|
674
|
+
/** Any additional data */
|
|
675
|
+
[key: string]: unknown;
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* A message in the conversation (OpenAI format)
|
|
679
|
+
*
|
|
680
|
+
* This format is compatible with OpenAI's Chat Completions API
|
|
681
|
+
* and can be stored directly in a database (1 row per message).
|
|
682
|
+
*
|
|
683
|
+
* Message types:
|
|
684
|
+
* - user: User's input message
|
|
685
|
+
* - assistant: AI's response (may include tool_calls)
|
|
686
|
+
* - tool: Result of a tool execution (has tool_call_id)
|
|
687
|
+
* - system: System prompt (usually first message)
|
|
688
|
+
*
|
|
689
|
+
* @example
|
|
690
|
+
* // User message
|
|
691
|
+
* { role: "user", content: "What's the weather?" }
|
|
692
|
+
*
|
|
693
|
+
* // Assistant requesting tool
|
|
694
|
+
* { role: "assistant", content: null, tool_calls: [{...}] }
|
|
695
|
+
*
|
|
696
|
+
* // Tool result
|
|
697
|
+
* { role: "tool", content: '{"temp": 72}', tool_call_id: "call_abc" }
|
|
698
|
+
*
|
|
699
|
+
* // Final assistant response
|
|
700
|
+
* { role: "assistant", content: "The temperature is 72°F" }
|
|
701
|
+
*/
|
|
702
|
+
interface Message {
|
|
703
|
+
/** Unique identifier */
|
|
704
|
+
id: string;
|
|
705
|
+
/** Thread/conversation ID (for multi-session apps) */
|
|
706
|
+
thread_id?: string;
|
|
707
|
+
/** Role of the message sender */
|
|
708
|
+
role: MessageRole;
|
|
709
|
+
/** Text content (null for tool-calling assistant messages) */
|
|
710
|
+
content: string | null;
|
|
711
|
+
/**
|
|
712
|
+
* Tool calls made by assistant (OpenAI format)
|
|
713
|
+
* Only present when role is "assistant" and AI wants to call tools
|
|
714
|
+
*/
|
|
715
|
+
tool_calls?: ToolCall[];
|
|
716
|
+
/**
|
|
717
|
+
* Tool call ID this message is responding to
|
|
718
|
+
* Only present when role is "tool"
|
|
719
|
+
*/
|
|
720
|
+
tool_call_id?: string;
|
|
721
|
+
/**
|
|
722
|
+
* Flexible metadata container
|
|
723
|
+
* Contains: thinking, sources, attachments, model, usage, etc.
|
|
724
|
+
*/
|
|
725
|
+
metadata?: MessageMetadata;
|
|
726
|
+
/** When the message was created */
|
|
727
|
+
created_at: Date;
|
|
728
|
+
}
|
|
729
|
+
/**
|
|
730
|
+
* Helper to parse tool call arguments
|
|
731
|
+
*/
|
|
732
|
+
declare function parseToolCallArgs<T = Record<string, unknown>>(toolCall: ToolCall): T;
|
|
733
|
+
/**
|
|
734
|
+
* Helper to create a tool call
|
|
735
|
+
*/
|
|
736
|
+
declare function createToolCall(id: string, name: string, args: Record<string, unknown>): ToolCall;
|
|
737
|
+
/**
|
|
738
|
+
* Create a new message with defaults
|
|
739
|
+
*/
|
|
740
|
+
declare function createMessage(partial: Partial<Message> & Pick<Message, "role"> & {
|
|
741
|
+
content?: string | null;
|
|
742
|
+
}): Message;
|
|
743
|
+
/**
|
|
744
|
+
* Create a user message
|
|
745
|
+
*/
|
|
746
|
+
declare function createUserMessage(content: string, options?: {
|
|
747
|
+
id?: string;
|
|
748
|
+
thread_id?: string;
|
|
749
|
+
attachments?: MessageAttachment[];
|
|
750
|
+
}): Message;
|
|
751
|
+
/**
|
|
752
|
+
* Create an assistant message
|
|
753
|
+
*/
|
|
754
|
+
declare function createAssistantMessage(content: string | null, options?: {
|
|
755
|
+
id?: string;
|
|
756
|
+
thread_id?: string;
|
|
757
|
+
tool_calls?: ToolCall[];
|
|
758
|
+
thinking?: string;
|
|
759
|
+
sources?: Source[];
|
|
760
|
+
model?: string;
|
|
761
|
+
}): Message;
|
|
762
|
+
/**
|
|
763
|
+
* Create a tool result message
|
|
764
|
+
*/
|
|
765
|
+
declare function createToolMessage(toolCallId: string, result: {
|
|
766
|
+
success: boolean;
|
|
767
|
+
data?: unknown;
|
|
768
|
+
error?: string;
|
|
769
|
+
message?: string;
|
|
770
|
+
}, options?: {
|
|
771
|
+
id?: string;
|
|
772
|
+
thread_id?: string;
|
|
773
|
+
}): Message;
|
|
774
|
+
/**
|
|
775
|
+
* Check if a message has tool calls
|
|
776
|
+
*/
|
|
777
|
+
declare function hasToolCalls(message: Message): boolean;
|
|
778
|
+
/**
|
|
779
|
+
* Check if a message is a tool result
|
|
780
|
+
*/
|
|
781
|
+
declare function isToolResult(message: Message): boolean;
|
|
782
|
+
|
|
783
|
+
/**
|
|
784
|
+
* Thread metadata (for listing threads)
|
|
785
|
+
*/
|
|
786
|
+
interface Thread {
|
|
787
|
+
/** Unique thread identifier */
|
|
788
|
+
id: string;
|
|
789
|
+
/** Thread title (auto-generated from first message or manual) */
|
|
790
|
+
title?: string;
|
|
791
|
+
/** Preview of the first message (for thread lists) */
|
|
792
|
+
preview?: string;
|
|
793
|
+
/** Number of messages in this thread */
|
|
794
|
+
messageCount?: number;
|
|
795
|
+
/** When thread was created */
|
|
796
|
+
createdAt: Date;
|
|
797
|
+
/** When thread was last updated */
|
|
798
|
+
updatedAt: Date;
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
801
|
+
* Full thread data including messages
|
|
802
|
+
*/
|
|
803
|
+
interface ThreadData extends Thread {
|
|
804
|
+
/** Messages in this thread */
|
|
805
|
+
messages: Message[];
|
|
806
|
+
/** Sources from knowledge base for this thread */
|
|
807
|
+
sources: Source[];
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* Persistence storage interface for custom adapters
|
|
811
|
+
*/
|
|
812
|
+
interface ThreadStorageAdapter$1 {
|
|
813
|
+
/** Save threads to storage */
|
|
814
|
+
save: (threads: ThreadData[]) => Promise<void>;
|
|
815
|
+
/** Load threads from storage */
|
|
816
|
+
load: () => Promise<ThreadData[]>;
|
|
817
|
+
/** Clear all threads from storage */
|
|
818
|
+
clear: () => Promise<void>;
|
|
819
|
+
}
|
|
820
|
+
/**
|
|
821
|
+
* Persistence configuration
|
|
822
|
+
*/
|
|
823
|
+
interface PersistenceConfig {
|
|
824
|
+
/** Enable persistence (default: false) */
|
|
825
|
+
enabled: boolean;
|
|
826
|
+
/** Storage type */
|
|
827
|
+
storage?: "localStorage" | "custom";
|
|
828
|
+
/** Custom storage adapter (required if storage is 'custom') */
|
|
829
|
+
customStorage?: ThreadStorageAdapter$1;
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* Generate a thread title from message content
|
|
833
|
+
*/
|
|
834
|
+
declare function generateThreadTitle(content: string): string;
|
|
835
|
+
|
|
836
|
+
/**
|
|
837
|
+
* Thread Storage Adapter Types
|
|
838
|
+
*
|
|
839
|
+
* Interfaces for thread persistence adapters.
|
|
840
|
+
*/
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* Basic thread storage adapter interface
|
|
844
|
+
* Used by ThreadManager for persistence
|
|
845
|
+
*/
|
|
846
|
+
interface ThreadStorageAdapter {
|
|
847
|
+
/** Save all threads to storage */
|
|
848
|
+
save: (threads: ThreadData[]) => Promise<void>;
|
|
849
|
+
/** Load all threads from storage */
|
|
850
|
+
load: () => Promise<ThreadData[]>;
|
|
851
|
+
/** Clear all threads from storage */
|
|
852
|
+
clear: () => Promise<void>;
|
|
853
|
+
/**
|
|
854
|
+
* Get the last active thread ID
|
|
855
|
+
* Optional - used for session persistence
|
|
856
|
+
*/
|
|
857
|
+
getLastActiveThreadId?: () => Promise<string | null>;
|
|
858
|
+
/**
|
|
859
|
+
* Set the last active thread ID
|
|
860
|
+
* Optional - used for session persistence
|
|
861
|
+
*/
|
|
862
|
+
setLastActiveThreadId?: (threadId: string | null) => Promise<void>;
|
|
863
|
+
}
|
|
864
|
+
/**
|
|
865
|
+
* Pagination options for listing threads
|
|
866
|
+
*/
|
|
867
|
+
interface ListThreadsOptions {
|
|
868
|
+
/** Maximum number of threads to return */
|
|
869
|
+
limit?: number;
|
|
870
|
+
/** Number of threads to skip */
|
|
871
|
+
offset?: number;
|
|
872
|
+
/** Sort order (default: updatedAt desc) */
|
|
873
|
+
orderBy?: "createdAt" | "updatedAt";
|
|
874
|
+
/** Sort direction */
|
|
875
|
+
orderDir?: "asc" | "desc";
|
|
876
|
+
}
|
|
877
|
+
/**
|
|
878
|
+
* Paginated response for thread listing
|
|
879
|
+
*/
|
|
880
|
+
interface ListThreadsResult {
|
|
881
|
+
/** Threads for current page */
|
|
882
|
+
threads: Thread[];
|
|
883
|
+
/** Total number of threads */
|
|
884
|
+
total: number;
|
|
885
|
+
/** Whether there are more threads */
|
|
886
|
+
hasMore: boolean;
|
|
887
|
+
}
|
|
888
|
+
/**
|
|
889
|
+
* Async thread storage adapter with optimized single-thread operations
|
|
890
|
+
*
|
|
891
|
+
* Use this interface when implementing database backends (Supabase, Firebase, etc.)
|
|
892
|
+
* These methods are optional - if not provided, ThreadManager falls back to
|
|
893
|
+
* full save/load operations.
|
|
894
|
+
*
|
|
895
|
+
* @example Supabase adapter
|
|
896
|
+
* ```typescript
|
|
897
|
+
* const supabaseAdapter: AsyncThreadStorageAdapter = {
|
|
898
|
+
* save: async (threads) => { /* batch upsert *\/ },
|
|
899
|
+
* load: async () => { /* select all *\/ },
|
|
900
|
+
* clear: async () => { /* delete all *\/ },
|
|
901
|
+
*
|
|
902
|
+
* // Optimized operations
|
|
903
|
+
* getThread: async (id) => {
|
|
904
|
+
* const { data } = await supabase
|
|
905
|
+
* .from('threads')
|
|
906
|
+
* .select('*, messages(*)')
|
|
907
|
+
* .eq('id', id)
|
|
908
|
+
* .single();
|
|
909
|
+
* return data;
|
|
910
|
+
* },
|
|
911
|
+
* createThread: async (thread) => {
|
|
912
|
+
* const { data } = await supabase.from('threads').insert(thread).select().single();
|
|
913
|
+
* return data;
|
|
914
|
+
* },
|
|
915
|
+
* updateThread: async (id, updates) => {
|
|
916
|
+
* const { data } = await supabase.from('threads').update(updates).eq('id', id).select().single();
|
|
917
|
+
* return data;
|
|
918
|
+
* },
|
|
919
|
+
* deleteThread: async (id) => {
|
|
920
|
+
* await supabase.from('threads').delete().eq('id', id);
|
|
921
|
+
* },
|
|
922
|
+
* listThreads: async ({ limit, offset }) => {
|
|
923
|
+
* const { data, count } = await supabase
|
|
924
|
+
* .from('threads')
|
|
925
|
+
* .select('*', { count: 'exact' })
|
|
926
|
+
* .order('updatedAt', { ascending: false })
|
|
927
|
+
* .range(offset, offset + limit - 1);
|
|
928
|
+
* return { threads: data, total: count, hasMore: (offset + limit) < count };
|
|
929
|
+
* },
|
|
930
|
+
* };
|
|
931
|
+
* ```
|
|
932
|
+
*/
|
|
933
|
+
interface AsyncThreadStorageAdapter extends ThreadStorageAdapter {
|
|
934
|
+
/**
|
|
935
|
+
* Get a single thread by ID
|
|
936
|
+
* If provided, used instead of loading all threads
|
|
937
|
+
*/
|
|
938
|
+
getThread?: (id: string) => Promise<ThreadData | null>;
|
|
939
|
+
/**
|
|
940
|
+
* Create a new thread
|
|
941
|
+
* If provided, used instead of saving all threads
|
|
942
|
+
*/
|
|
943
|
+
createThread?: (thread: ThreadData) => Promise<ThreadData>;
|
|
944
|
+
/**
|
|
945
|
+
* Update an existing thread
|
|
946
|
+
* If provided, used instead of saving all threads
|
|
947
|
+
*/
|
|
948
|
+
updateThread?: (id: string, updates: Partial<ThreadData>) => Promise<ThreadData>;
|
|
949
|
+
/**
|
|
950
|
+
* Delete a thread by ID
|
|
951
|
+
* If provided, used instead of saving all threads
|
|
952
|
+
*/
|
|
953
|
+
deleteThread?: (id: string) => Promise<void>;
|
|
954
|
+
/**
|
|
955
|
+
* List threads with pagination
|
|
956
|
+
* If provided, used for efficient thread listing
|
|
957
|
+
*/
|
|
958
|
+
listThreads?: (options?: ListThreadsOptions) => Promise<ListThreadsResult>;
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
export { type AIProvider as A, type PermissionStorageAdapter as B, generateThreadTitle as C, createMessage as D, createUserMessage as E, createAssistantMessage as F, createToolMessage as G, createToolCall as H, parseToolCallArgs as I, type JSONSchemaProperty as J, hasToolCalls as K, isToolResult as L, type MessageAttachment as M, tool as N, toolToOpenAIFormat as O, type PersistenceConfig as P, toolToAnthropicFormat as Q, createToolResult as R, type Source as S, type ToolDefinition as T, type UnifiedToolCall as U, success as V, failure as W, type AsyncThreadStorageAdapter as X, type ListThreadsOptions as Y, type ListThreadsResult as Z, type ThreadStorageAdapter as _, type ToolExecutionStatus as a, type ToolResponse as b, type ToolInputSchema as c, type ToolLocation as d, type ToolContext as e, type MessageRole as f, type Message as g, type MessageMetadata as h, type ToolCall as i, type TokenUsage as j, type Thread as k, type ThreadData as l, type ThreadStorageAdapter$1 as m, type ToolRenderProps as n, type ToolConfig as o, type ToolSet as p, type UnifiedToolResult as q, type ToolApprovalStatus as r, type ToolExecution as s, type AgentLoopConfig as t, type AgentLoopState as u, type AIResponseMode as v, type AIContent as w, type PermissionLevel as x, type ToolPermission as y, type PermissionStorageConfig as z };
|