@copilotz/chat-adapter 0.1.0 → 0.1.3

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/dist/index.d.ts CHANGED
@@ -1,7 +1,93 @@
1
1
  import React from 'react';
2
- import { ChatUserContext, ChatConfig, ChatCallbacks, MemoryItem, ChatMessage, ChatThread, MediaAttachment } from '@copilotz/chat-ui';
2
+ import { ChatUserContext, ChatConfig, ChatCallbacks, MemoryItem, AgentOption, ChatMessage, ChatThread, MediaAttachment } from '@copilotz/chat-ui';
3
3
  export { ChatCallbacks, ChatConfig, ChatMessage, ChatThread, ChatUserContext, MediaAttachment, MemoryItem } from '@copilotz/chat-ui';
4
4
 
5
+ /**
6
+ * Configuration for URL parameter names
7
+ */
8
+ interface UrlParamsConfig {
9
+ /** URL param name for thread ID (default: 'thread') */
10
+ thread?: string;
11
+ /** URL param name for agent ID (default: 'agent') */
12
+ agent?: string;
13
+ /** URL param name for initial prompt (default: 'prompt') */
14
+ prompt?: string;
15
+ }
16
+ /**
17
+ * URL sync behavior configuration
18
+ */
19
+ interface UrlSyncConfig {
20
+ /** Enable/disable URL sync (default: true) */
21
+ enabled?: boolean;
22
+ /**
23
+ * How to update the URL when state changes:
24
+ * - 'push': Creates browser history entries (back button works)
25
+ * - 'replace': Updates URL without history entries (default)
26
+ * - 'read-only': Only reads from URL, never writes
27
+ */
28
+ mode?: 'push' | 'replace' | 'read-only';
29
+ /** Custom parameter names */
30
+ params?: UrlParamsConfig;
31
+ /**
32
+ * Behavior for the prompt parameter:
33
+ * - 'prefill': Pre-fills the input field (default)
34
+ * - 'auto-send': Automatically sends the message on load
35
+ */
36
+ promptBehavior?: 'prefill' | 'auto-send';
37
+ /**
38
+ * Whether to clear the prompt param from URL after reading
39
+ * Prevents re-sending on refresh (default: true)
40
+ */
41
+ clearPromptAfterRead?: boolean;
42
+ }
43
+ /**
44
+ * State values parsed from URL
45
+ */
46
+ interface UrlState {
47
+ threadId: string | null;
48
+ agentId: string | null;
49
+ prompt: string | null;
50
+ }
51
+ /**
52
+ * Return type of useUrlState hook
53
+ */
54
+ interface UseUrlStateReturn {
55
+ /** Current state parsed from URL */
56
+ state: UrlState;
57
+ /** Update thread ID in URL */
58
+ setThreadId: (threadId: string | null) => void;
59
+ /** Update agent ID in URL */
60
+ setAgentId: (agentId: string | null) => void;
61
+ /** Clear prompt from URL (call after consuming it) */
62
+ clearPrompt: () => void;
63
+ /** Whether URL sync is enabled */
64
+ isEnabled: boolean;
65
+ }
66
+ /**
67
+ * Hook to manage chat state persistence via URL parameters.
68
+ *
69
+ * Supports:
70
+ * - Thread ID: Navigate to specific conversation
71
+ * - Agent ID: Pre-select an agent
72
+ * - Prompt: Pre-fill or auto-send a message
73
+ *
74
+ * @example
75
+ * ```tsx
76
+ * const { state, setThreadId, setAgentId } = useUrlState({
77
+ * enabled: true,
78
+ * mode: 'replace',
79
+ * params: { thread: 't', agent: 'a', prompt: 'q' }
80
+ * });
81
+ *
82
+ * // Read initial values
83
+ * console.log(state.threadId, state.agentId, state.prompt);
84
+ *
85
+ * // Update URL when thread changes
86
+ * setThreadId('abc123');
87
+ * ```
88
+ */
89
+ declare function useUrlState(config?: UrlSyncConfig): UseUrlStateReturn;
90
+
5
91
  interface CopilotzChatProps {
6
92
  userId: string;
7
93
  userName?: string;
@@ -40,7 +126,41 @@ interface CopilotzChatProps {
40
126
  onUpdateMemory?: (memoryId: string, content: string) => void;
41
127
  /** Called when user deletes a memory */
42
128
  onDeleteMemory?: (memoryId: string) => void;
129
+ /** Empty-state suggestions */
130
+ suggestions?: string[];
131
+ /** Agent selector data (built-in ChatUI) */
132
+ agentOptions?: AgentOption[];
133
+ selectedAgentId?: string | null;
134
+ onSelectAgent?: (agentId: string) => void;
43
135
  className?: string;
136
+ /**
137
+ * URL state synchronization configuration.
138
+ * When enabled, syncs thread ID, agent, and prompt to/from URL parameters.
139
+ *
140
+ * Features:
141
+ * - `?thread=abc123` - Opens specific thread
142
+ * - `?agent=support-bot` - Pre-selects agent
143
+ * - `?prompt=Hello` - Pre-fills or auto-sends message
144
+ *
145
+ * @example
146
+ * ```tsx
147
+ * <CopilotzChat
148
+ * userId="user123"
149
+ * urlSync={{ enabled: true }}
150
+ * />
151
+ *
152
+ * // With custom param names
153
+ * <CopilotzChat
154
+ * userId="user123"
155
+ * urlSync={{
156
+ * enabled: true,
157
+ * params: { thread: 't', agent: 'a', prompt: 'q' },
158
+ * promptBehavior: 'auto-send'
159
+ * }}
160
+ * />
161
+ * ```
162
+ */
163
+ urlSync?: UrlSyncConfig;
44
164
  }
45
165
  declare const CopilotzChat: React.FC<CopilotzChatProps>;
46
166
 
@@ -56,8 +176,26 @@ interface UseCopilotzOptions {
56
176
  };
57
177
  defaultThreadName?: string;
58
178
  onToolOutput?: (output: Record<string, unknown>) => void;
179
+ preferredAgentName?: string | null;
180
+ /**
181
+ * URL state synchronization configuration.
182
+ * When enabled, thread ID and agent are synced to/from URL parameters.
183
+ *
184
+ * @example
185
+ * ```tsx
186
+ * const chat = useCopilotz({
187
+ * userId: 'user123',
188
+ * urlSync: {
189
+ * enabled: true,
190
+ * mode: 'replace',
191
+ * params: { thread: 't', agent: 'a', prompt: 'q' }
192
+ * }
193
+ * });
194
+ * ```
195
+ */
196
+ urlSync?: UrlSyncConfig;
59
197
  }
60
- declare function useCopilotz({ userId, initialContext, bootstrap, defaultThreadName, onToolOutput }: UseCopilotzOptions): {
198
+ declare function useCopilotz({ userId, initialContext, bootstrap, defaultThreadName, onToolOutput, preferredAgentName, urlSync }: UseCopilotzOptions): {
61
199
  messages: ChatMessage[];
62
200
  threads: ChatThread[];
63
201
  currentThreadId: string | null;
@@ -73,6 +211,14 @@ declare function useCopilotz({ userId, initialContext, bootstrap, defaultThreadN
73
211
  fetchAndSetThreadsState: (uid: string, preferredExternalId?: string | null) => Promise<string | null | undefined>;
74
212
  loadThreadMessages: (threadId: string) => Promise<void>;
75
213
  reset: () => void;
214
+ /** Initial prompt from URL (if urlSync enabled) - use for pre-filling input */
215
+ initialPrompt: string | null;
216
+ /** Clear the initial prompt from URL (call after consuming it) */
217
+ clearInitialPrompt: () => void;
218
+ /** URL agent ID (if urlSync enabled) - use for agent pre-selection */
219
+ urlAgentId: string | null;
220
+ /** Update agent ID in URL */
221
+ setUrlAgentId: (agentId: string | null) => void;
76
222
  };
77
223
 
78
224
  type RestThread = {
@@ -122,6 +268,7 @@ type RunOptions = {
122
268
  args: Record<string, unknown>;
123
269
  id?: string;
124
270
  }>;
271
+ selectedAgent?: string | null;
125
272
  } & StreamCallbacks;
126
273
  type CopilotzStreamResult = {
127
274
  text: string;
@@ -152,4 +299,4 @@ type WithMetadata = {
152
299
  };
153
300
  declare function resolveAssetsInMessages<T extends WithMetadata>(messages: T[]): Promise<T[]>;
154
301
 
155
- export { CopilotzChat, type CopilotzStreamResult, copilotzService, deleteMessagesByThreadId, deleteThread, fetchThreadMessages, fetchThreads, getAssetDataUrl, resolveAssetsInMessages, runCopilotzStream, updateThread, useCopilotz };
302
+ export { CopilotzChat, type CopilotzStreamResult, type UrlParamsConfig, type UrlState, type UrlSyncConfig, type UseUrlStateReturn, copilotzService, deleteMessagesByThreadId, deleteThread, fetchThreadMessages, fetchThreads, getAssetDataUrl, resolveAssetsInMessages, runCopilotzStream, updateThread, useCopilotz, useUrlState };