@copilotz/chat-adapter 0.4.0 → 0.5.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 +11 -26
- package/dist/index.d.ts +1 -82
- package/dist/index.js +186 -104
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -101,7 +101,7 @@ VITE_COPILOTZ_API_KEY=your-api-key
|
|
|
101
101
|
|
|
102
102
|
### Real-Time Streaming
|
|
103
103
|
|
|
104
|
-
Messages stream token-by-token with a
|
|
104
|
+
Messages stream token-by-token with a unified assistant activity model. No extra configuration is needed for live lifecycle parsing — it just works.
|
|
105
105
|
|
|
106
106
|
```tsx
|
|
107
107
|
<CopilotzChat userId="user-123" />
|
|
@@ -111,30 +111,24 @@ Messages stream token-by-token with a thinking indicator while waiting for the f
|
|
|
111
111
|
|
|
112
112
|
From `0.4.0` onward, the adapter treats the Copilotz live stream as a lifecycle-native contract:
|
|
113
113
|
|
|
114
|
-
- `TOKEN` streams partial assistant text and reasoning
|
|
115
|
-
- `TOOL_CALL` starts or updates
|
|
116
|
-
- `TOOL_RESULT` completes
|
|
114
|
+
- `TOKEN` streams partial assistant text and internal reasoning state
|
|
115
|
+
- `TOOL_CALL` starts or updates assistant activity
|
|
116
|
+
- `TOOL_RESULT` completes tool activity state
|
|
117
117
|
- `LLM_RESULT` finalizes the active assistant turn
|
|
118
118
|
- `ASSET_CREATED` remains an optional live artifact event
|
|
119
119
|
- `NEW_MESSAGE` is treated as a history/artifact event, not the primary live completion signal
|
|
120
120
|
|
|
121
121
|
If you stream Copilotz events through a custom bridge, keep those event names intact.
|
|
122
122
|
|
|
123
|
-
###
|
|
123
|
+
### Assistant Activity Modes
|
|
124
124
|
|
|
125
|
-
When your agent calls tools, the UI
|
|
126
|
-
|
|
127
|
-
1. **Pending** — Tool call received
|
|
128
|
-
2. **Running** — Tool is executing
|
|
129
|
-
3. **Completed/Failed** — Result displayed with execution time
|
|
130
|
-
|
|
131
|
-
All automatic. Just enable tool display in config:
|
|
125
|
+
When your agent thinks or calls tools, the adapter normalizes those lifecycle events into one activity model for the UI. Configure the surface with `activityDisplay`:
|
|
132
126
|
|
|
133
127
|
```tsx
|
|
134
128
|
<CopilotzChat
|
|
135
129
|
userId="user-123"
|
|
136
130
|
config={{
|
|
137
|
-
features: {
|
|
131
|
+
features: { activityDisplay: 'summary' },
|
|
138
132
|
}}
|
|
139
133
|
/>
|
|
140
134
|
```
|
|
@@ -371,7 +365,7 @@ function CustomChat() {
|
|
|
371
365
|
|
|
372
366
|
## Services
|
|
373
367
|
|
|
374
|
-
###
|
|
368
|
+
### Direct API Helpers
|
|
375
369
|
|
|
376
370
|
Low-level API client for direct backend communication:
|
|
377
371
|
|
|
@@ -401,7 +395,7 @@ const threads = await fetchThreads('user-123');
|
|
|
401
395
|
const messages = await fetchThreadMessages('thread-456');
|
|
402
396
|
```
|
|
403
397
|
|
|
404
|
-
###
|
|
398
|
+
### Asset Helpers
|
|
405
399
|
|
|
406
400
|
Resolve asset references to data URLs:
|
|
407
401
|
|
|
@@ -425,16 +419,15 @@ export { CopilotzChat } from './CopilotzChat';
|
|
|
425
419
|
|
|
426
420
|
// Hooks
|
|
427
421
|
export { useCopilotz } from './useCopilotzChat';
|
|
428
|
-
export { useUrlState } from './useUrlState';
|
|
429
422
|
|
|
430
423
|
// Services
|
|
431
424
|
export {
|
|
425
|
+
CopilotzRequestError,
|
|
432
426
|
runCopilotzStream,
|
|
433
427
|
fetchThreads,
|
|
434
428
|
fetchThreadMessages,
|
|
435
429
|
updateThread,
|
|
436
430
|
deleteThread,
|
|
437
|
-
copilotzService,
|
|
438
431
|
} from './copilotzService';
|
|
439
432
|
|
|
440
433
|
export {
|
|
@@ -452,14 +445,6 @@ export type {
|
|
|
452
445
|
MediaAttachment,
|
|
453
446
|
MemoryItem,
|
|
454
447
|
} from '@copilotz/chat-ui';
|
|
455
|
-
|
|
456
|
-
// URL state types
|
|
457
|
-
export type {
|
|
458
|
-
UrlSyncConfig,
|
|
459
|
-
UrlParamsConfig,
|
|
460
|
-
UrlState,
|
|
461
|
-
UseUrlStateReturn,
|
|
462
|
-
} from './useUrlState';
|
|
463
448
|
```
|
|
464
449
|
|
|
465
450
|
---
|
|
@@ -501,7 +486,7 @@ function App() {
|
|
|
501
486
|
subtitle: 'We typically reply in a few seconds',
|
|
502
487
|
},
|
|
503
488
|
features: {
|
|
504
|
-
|
|
489
|
+
activityDisplay: 'full',
|
|
505
490
|
enableFileUpload: true,
|
|
506
491
|
enableAudioRecording: true,
|
|
507
492
|
},
|
package/dist/index.d.ts
CHANGED
|
@@ -49,10 +49,6 @@ type RestMessagePageInfo = {
|
|
|
49
49
|
oldestMessageId: string | null;
|
|
50
50
|
newestMessageId: string | null;
|
|
51
51
|
};
|
|
52
|
-
type RestMessagePage = {
|
|
53
|
-
data: RestMessage[];
|
|
54
|
-
pageInfo: RestMessagePageInfo;
|
|
55
|
-
};
|
|
56
52
|
type StreamCallbacks = {
|
|
57
53
|
onToken?: (token: string, isComplete: boolean, raw?: any, options?: {
|
|
58
54
|
isReasoning?: boolean;
|
|
@@ -104,19 +100,8 @@ declare class CopilotzRequestError extends Error {
|
|
|
104
100
|
declare function runCopilotzStream(options: RunOptions): Promise<CopilotzStreamResult>;
|
|
105
101
|
declare function fetchThreads(userId: string, getRequestHeaders?: RequestHeadersProvider): Promise<RestThread[]>;
|
|
106
102
|
declare function fetchThreadMessages(threadId: string, getRequestHeaders?: RequestHeadersProvider): Promise<RestMessage[]>;
|
|
107
|
-
declare function fetchThreadMessagesPage(threadId: string, options?: {
|
|
108
|
-
limit?: number;
|
|
109
|
-
before?: string | null;
|
|
110
|
-
}, getRequestHeaders?: RequestHeadersProvider): Promise<RestMessagePage>;
|
|
111
103
|
declare function updateThread(threadId: string, updates: Partial<RestThread>, getRequestHeaders?: RequestHeadersProvider): Promise<any>;
|
|
112
104
|
declare function deleteThread(threadId: string, getRequestHeaders?: RequestHeadersProvider): Promise<boolean>;
|
|
113
|
-
declare const copilotzService: {
|
|
114
|
-
runCopilotzStream: typeof runCopilotzStream;
|
|
115
|
-
fetchThreads: typeof fetchThreads;
|
|
116
|
-
fetchThreadMessages: typeof fetchThreadMessages;
|
|
117
|
-
updateThread: typeof updateThread;
|
|
118
|
-
deleteThread: typeof deleteThread;
|
|
119
|
-
};
|
|
120
105
|
|
|
121
106
|
interface CopilotzChatProps {
|
|
122
107
|
userId: string;
|
|
@@ -221,72 +206,6 @@ declare function useCopilotz({ userId, initialContext, bootstrap, defaultThreadN
|
|
|
221
206
|
reset: () => void;
|
|
222
207
|
};
|
|
223
208
|
|
|
224
|
-
/**
|
|
225
|
-
* Configuration for URL parameter names
|
|
226
|
-
*/
|
|
227
|
-
interface UrlParamsConfig {
|
|
228
|
-
/** URL param name for thread ID (default: 'thread') */
|
|
229
|
-
thread?: string;
|
|
230
|
-
/** URL param name for agent ID (default: 'agent') */
|
|
231
|
-
agent?: string;
|
|
232
|
-
/** URL param name for initial prompt (default: 'prompt') */
|
|
233
|
-
prompt?: string;
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* URL sync behavior configuration
|
|
237
|
-
*/
|
|
238
|
-
interface UrlSyncConfig {
|
|
239
|
-
/** Enable/disable URL sync (default: true) */
|
|
240
|
-
enabled?: boolean;
|
|
241
|
-
/**
|
|
242
|
-
* How to update the URL when state changes:
|
|
243
|
-
* - 'push': Creates browser history entries (back button works)
|
|
244
|
-
* - 'replace': Updates URL without history entries (default)
|
|
245
|
-
* - 'read-only': Only reads from URL, never writes
|
|
246
|
-
*/
|
|
247
|
-
mode?: 'push' | 'replace' | 'read-only';
|
|
248
|
-
/** Custom parameter names */
|
|
249
|
-
params?: UrlParamsConfig;
|
|
250
|
-
/**
|
|
251
|
-
* Behavior for the prompt parameter:
|
|
252
|
-
* - 'prefill': Pre-fills the input field (default)
|
|
253
|
-
* - 'auto-send': Automatically sends the message on load
|
|
254
|
-
*/
|
|
255
|
-
promptBehavior?: 'prefill' | 'auto-send';
|
|
256
|
-
/**
|
|
257
|
-
* Whether to clear the prompt param from URL after reading
|
|
258
|
-
* Prevents re-sending on refresh (default: true)
|
|
259
|
-
*/
|
|
260
|
-
clearPromptAfterRead?: boolean;
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* State values parsed from URL
|
|
264
|
-
*/
|
|
265
|
-
interface UrlState {
|
|
266
|
-
threadId: string | null;
|
|
267
|
-
agentId: string | null;
|
|
268
|
-
prompt: string | null;
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* Return type of useUrlState hook
|
|
272
|
-
*/
|
|
273
|
-
interface UseUrlStateReturn {
|
|
274
|
-
/** Current state parsed from URL */
|
|
275
|
-
state: UrlState;
|
|
276
|
-
/** Update thread ID in URL */
|
|
277
|
-
setThreadId: (threadId: string | null) => void;
|
|
278
|
-
/** Update agent ID in URL */
|
|
279
|
-
setAgentId: (agentId: string | null) => void;
|
|
280
|
-
/** Clear prompt from URL (call after consuming it) */
|
|
281
|
-
clearPrompt: () => void;
|
|
282
|
-
/** Whether URL sync is enabled */
|
|
283
|
-
isEnabled: boolean;
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* Hook to manage chat state persistence via URL parameters.
|
|
287
|
-
*/
|
|
288
|
-
declare function useUrlState(config?: UrlSyncConfig): UseUrlStateReturn;
|
|
289
|
-
|
|
290
209
|
declare function getAssetDataUrl(refOrId: string): Promise<{
|
|
291
210
|
dataUrl: string;
|
|
292
211
|
mime?: string;
|
|
@@ -297,4 +216,4 @@ type WithMetadata = {
|
|
|
297
216
|
};
|
|
298
217
|
declare function resolveAssetsInMessages<T extends WithMetadata>(messages: T[]): Promise<T[]>;
|
|
299
218
|
|
|
300
|
-
export { CopilotzChat, CopilotzRequestError, type
|
|
219
|
+
export { CopilotzChat, CopilotzRequestError, type EventInterceptor, type EventInterceptorResult, type RenderSpecialState, type RequestHeadersProvider, type RunErrorInterceptor, type SpecialChatState, type SpecialStateControls, deleteThread, fetchThreadMessages, fetchThreads, getAssetDataUrl, resolveAssetsInMessages, runCopilotzStream, updateThread, useCopilotz };
|