@copilotz/chat-adapter 0.1.0

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/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # @copilotz/chat-adapter
2
+
3
+ Copilotz API adapter and ready-to-use `CopilotzChat` wrapper for the chat UI.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @copilotz/chat-adapter
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```tsx
14
+ import { CopilotzChat } from '@copilotz/chat-adapter';
15
+ import '@copilotz/chat-ui/styles.css';
16
+
17
+ export function Example() {
18
+ return (
19
+ <CopilotzChat
20
+ userId="user-1"
21
+ config={{
22
+ branding: { title: 'Copilotz' }
23
+ }}
24
+ />
25
+ );
26
+ }
27
+ ```
@@ -0,0 +1,155 @@
1
+ import React from 'react';
2
+ import { ChatUserContext, ChatConfig, ChatCallbacks, MemoryItem, ChatMessage, ChatThread, MediaAttachment } from '@copilotz/chat-ui';
3
+ export { ChatCallbacks, ChatConfig, ChatMessage, ChatThread, ChatUserContext, MediaAttachment, MemoryItem } from '@copilotz/chat-ui';
4
+
5
+ interface CopilotzChatProps {
6
+ userId: string;
7
+ userName?: string;
8
+ userAvatar?: string;
9
+ userEmail?: string;
10
+ initialContext?: ChatUserContext;
11
+ bootstrap?: {
12
+ initialMessage?: string;
13
+ initialToolCalls?: Array<{
14
+ name: string;
15
+ args: Record<string, unknown>;
16
+ }>;
17
+ };
18
+ config?: ChatConfig;
19
+ callbacks?: Partial<ChatCallbacks>;
20
+ /**
21
+ * Custom component to render in the right sidebar panel (e.g. Profile info).
22
+ * Can be:
23
+ * - A React node (static)
24
+ * - A function receiving context: `(context) => ReactNode`
25
+ * - A render function receiving panel props: `(props: { onClose, isMobile }) => ReactNode`
26
+ * Toggle visibility via the header button.
27
+ */
28
+ customComponent?: React.ReactNode | ((context: ChatUserContext) => React.ReactNode) | ((props: {
29
+ onClose: () => void;
30
+ isMobile: boolean;
31
+ }) => React.ReactNode);
32
+ onToolOutput?: (output: Record<string, unknown>) => void;
33
+ /** Called when user clicks logout in the user menu */
34
+ onLogout?: () => void;
35
+ /** Called when user clicks "View Profile" in the user menu */
36
+ onViewProfile?: () => void;
37
+ /** Called when user adds a memory */
38
+ onAddMemory?: (content: string, category?: MemoryItem['category']) => void;
39
+ /** Called when user updates a memory */
40
+ onUpdateMemory?: (memoryId: string, content: string) => void;
41
+ /** Called when user deletes a memory */
42
+ onDeleteMemory?: (memoryId: string) => void;
43
+ className?: string;
44
+ }
45
+ declare const CopilotzChat: React.FC<CopilotzChatProps>;
46
+
47
+ interface UseCopilotzOptions {
48
+ userId: string | null;
49
+ initialContext?: ChatUserContext;
50
+ bootstrap?: {
51
+ initialMessage?: string;
52
+ initialToolCalls?: Array<{
53
+ name: string;
54
+ args: Record<string, unknown>;
55
+ }>;
56
+ };
57
+ defaultThreadName?: string;
58
+ onToolOutput?: (output: Record<string, unknown>) => void;
59
+ }
60
+ declare function useCopilotz({ userId, initialContext, bootstrap, defaultThreadName, onToolOutput }: UseCopilotzOptions): {
61
+ messages: ChatMessage[];
62
+ threads: ChatThread[];
63
+ currentThreadId: string | null;
64
+ isStreaming: boolean;
65
+ userContextSeed: Partial<ChatUserContext>;
66
+ sendMessage: (content: string, attachments?: MediaAttachment[]) => Promise<void>;
67
+ createThread: (title?: string) => void;
68
+ selectThread: (threadId: string) => Promise<void>;
69
+ renameThread: (threadId: string, newTitle: string) => Promise<void>;
70
+ archiveThread: (threadId: string) => Promise<void>;
71
+ deleteThread: (threadId: string) => Promise<void>;
72
+ stopGeneration: () => void;
73
+ fetchAndSetThreadsState: (uid: string, preferredExternalId?: string | null) => Promise<string | null | undefined>;
74
+ loadThreadMessages: (threadId: string) => Promise<void>;
75
+ reset: () => void;
76
+ };
77
+
78
+ type RestThread = {
79
+ id: string;
80
+ name?: string | null;
81
+ externalId?: string | null;
82
+ description?: string | null;
83
+ participants?: string[] | null;
84
+ status?: string | null;
85
+ metadata?: Record<string, unknown> | null;
86
+ createdAt?: string;
87
+ updatedAt?: string;
88
+ };
89
+ type RestMessage = {
90
+ id: string;
91
+ threadId: string;
92
+ senderId?: string | null;
93
+ senderType: string;
94
+ senderUserId?: string | null;
95
+ content?: string | null;
96
+ metadata?: Record<string, unknown> | null;
97
+ toolCalls?: Array<Record<string, unknown>> | null;
98
+ createdAt?: string;
99
+ updatedAt?: string;
100
+ };
101
+ type StreamCallbacks = {
102
+ onToken?: (token: string, isComplete: boolean, raw?: any) => void;
103
+ onMessageEvent?: (payload: any) => void;
104
+ onAssetEvent?: (payload: any) => void;
105
+ signal?: AbortSignal;
106
+ };
107
+ type RunOptions = {
108
+ threadId?: string;
109
+ threadExternalId?: string;
110
+ content: string;
111
+ user: {
112
+ externalId: string;
113
+ name?: string;
114
+ email?: string;
115
+ metadata?: Record<string, unknown>;
116
+ };
117
+ attachments?: MediaAttachment[];
118
+ metadata?: Record<string, unknown>;
119
+ threadMetadata?: Record<string, unknown>;
120
+ toolCalls?: Array<{
121
+ name: string;
122
+ args: Record<string, unknown>;
123
+ id?: string;
124
+ }>;
125
+ } & StreamCallbacks;
126
+ type CopilotzStreamResult = {
127
+ text: string;
128
+ messages: any[];
129
+ media: Record<string, string> | null;
130
+ };
131
+ declare function runCopilotzStream(options: RunOptions): Promise<CopilotzStreamResult>;
132
+ declare function fetchThreads(userId: string): Promise<RestThread[]>;
133
+ declare function fetchThreadMessages(threadId: string): Promise<RestMessage[]>;
134
+ declare function updateThread(threadId: string, updates: Partial<RestThread>): Promise<any>;
135
+ declare function deleteMessagesByThreadId(threadId: string): Promise<void>;
136
+ declare function deleteThread(threadId: string): Promise<boolean>;
137
+ declare const copilotzService: {
138
+ runCopilotzStream: typeof runCopilotzStream;
139
+ fetchThreads: typeof fetchThreads;
140
+ fetchThreadMessages: typeof fetchThreadMessages;
141
+ updateThread: typeof updateThread;
142
+ deleteThread: typeof deleteThread;
143
+ };
144
+
145
+ declare function getAssetDataUrl(refOrId: string): Promise<{
146
+ dataUrl: string;
147
+ mime?: string;
148
+ assetId: string;
149
+ }>;
150
+ type WithMetadata = {
151
+ metadata?: Record<string, unknown> | null;
152
+ };
153
+ declare function resolveAssetsInMessages<T extends WithMetadata>(messages: T[]): Promise<T[]>;
154
+
155
+ export { CopilotzChat, type CopilotzStreamResult, copilotzService, deleteMessagesByThreadId, deleteThread, fetchThreadMessages, fetchThreads, getAssetDataUrl, resolveAssetsInMessages, runCopilotzStream, updateThread, useCopilotz };