@usecrow/client 0.1.24 → 0.1.27

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,311 +1,474 @@
1
- import { C as CrowClientConfig, a as CrowEventCallbacks, I as IdentifyOptions, T as ToolHandlers, b as ContextData, M as Message, c as Conversation, S as StreamEvent, d as IdentityState, e as ToolResult } from './browserUse-CZNpayEF.js';
2
- export { A as ActiveWorkflow, f as Citation, g as CrowBrowserUse, h as ToolHandler, W as WorkflowTodo } from './browserUse-CZNpayEF.js';
3
-
4
- /**
5
- * CrowClient - Main headless client for Crow AI agents
6
- */
7
-
8
- declare class CrowClient {
9
- private config;
10
- private identity;
11
- private tools;
12
- private conversations;
13
- private context;
14
- private abortController;
15
- private callbacks;
16
- private _messages;
17
- private messageListeners;
18
- private _isLoading;
19
- private loadingListeners;
20
- constructor(config: CrowClientConfig);
21
- /**
22
- * Get current product ID
23
- */
24
- get productId(): string;
25
- /**
26
- * Get current API URL
27
- */
28
- get apiUrl(): string;
29
- /**
30
- * Get/set current model
31
- */
32
- get model(): string;
33
- set model(value: string);
34
- /**
35
- * Register event callbacks
36
- */
37
- on(callbacks: CrowEventCallbacks): void;
38
- /**
39
- * Identify the current user with a JWT token
40
- */
41
- identify(options: IdentifyOptions): void;
42
- /**
43
- * Reset user identity (call on logout)
44
- */
45
- resetUser(): void;
46
- /**
47
- * Check if user is identified
48
- */
49
- isIdentified(): boolean;
50
- /**
51
- * Check if user is verified by server
52
- */
53
- isVerified(): boolean;
54
- /**
55
- * Register client-side tool handlers
56
- */
57
- registerTools(tools: ToolHandlers): void;
58
- /**
59
- * Unregister a tool handler
60
- */
61
- unregisterTool(name: string): void;
62
- /**
63
- * Get list of registered tool names
64
- */
65
- getRegisteredTools(): string[];
66
- /**
67
- * Set context data to be sent with messages
68
- */
69
- setContext(data: ContextData): void;
70
- /**
71
- * Clear context data
72
- */
73
- clearContext(): void;
74
- /**
75
- * Get current messages
76
- */
77
- get messages(): Message[];
78
- /**
79
- * Check if currently loading/streaming
80
- */
81
- get isLoading(): boolean;
82
- /**
83
- * Subscribe to message changes
84
- */
85
- onMessages(callback: (messages: Message[]) => void): () => void;
86
- /**
87
- * Subscribe to loading state changes
88
- */
89
- onLoading(callback: (isLoading: boolean) => void): () => void;
90
- /**
91
- * Clear all messages and start new conversation
92
- */
93
- clearMessages(): void;
94
- /**
95
- * Load messages from history
96
- */
97
- loadMessages(messages: Message[]): void;
98
- private notifyMessages;
99
- private setLoading;
100
- private addMessage;
101
- private updateMessage;
102
- private generateMessageId;
103
- /**
104
- * Get current conversation ID
105
- */
106
- get conversationId(): string | null;
107
- /**
108
- * Set current conversation ID
109
- */
110
- set conversationId(id: string | null);
111
- /**
112
- * Get list of conversations for verified user
113
- */
114
- getConversations(): Promise<Conversation[]>;
115
- /**
116
- * Load conversation history
117
- */
118
- loadHistory(conversationId: string): Promise<Message[]>;
119
- /**
120
- * Switch to a different conversation
121
- */
122
- switchConversation(conversationId: string): Promise<void>;
123
- /**
124
- * Send a message and receive streaming response
125
- * Returns an async generator of stream events
126
- */
127
- sendMessage(content: string): AsyncGenerator<StreamEvent>;
128
- /**
129
- * Send a message and wait for complete response (non-streaming)
130
- */
131
- send(content: string): Promise<Message | null>;
132
- /**
133
- * Stop current generation
134
- */
135
- stop(): void;
136
- /**
137
- * Destroy the client and clean up resources
138
- */
139
- destroy(): void;
140
- }
141
-
142
- /**
143
- * Identity management for user authentication
144
- */
145
-
146
- declare class IdentityManager {
147
- private state;
148
- private listeners;
149
- /**
150
- * Identify the current user with a JWT token
151
- */
152
- identify(options: IdentifyOptions): void;
153
- /**
154
- * Update verification status (called when server confirms)
155
- */
156
- setVerified(isVerified: boolean): void;
157
- /**
158
- * Reset user identity (call on logout)
159
- */
160
- reset(): void;
161
- /**
162
- * Get current identity token
163
- */
164
- getToken(): string | null;
165
- /**
166
- * Get current identity state
167
- */
168
- getState(): IdentityState;
169
- /**
170
- * Check if user is identified
171
- */
172
- isIdentified(): boolean;
173
- /**
174
- * Check if user is verified
175
- */
176
- isVerified(): boolean;
177
- /**
178
- * Subscribe to identity changes
179
- */
180
- subscribe(callback: (state: IdentityState) => void): () => void;
181
- private notify;
182
- }
183
-
184
- /**
185
- * Client-side tool management
186
- */
187
-
188
- declare class ToolManager {
189
- private handlers;
190
- /**
191
- * Register client-side tool handlers
192
- */
193
- register(tools: ToolHandlers): void;
194
- /**
195
- * Unregister a tool handler
196
- */
197
- unregister(name: string): void;
198
- /**
199
- * Check if a tool is registered
200
- */
201
- has(name: string): boolean;
202
- /**
203
- * Get all registered tool names
204
- */
205
- getRegisteredTools(): string[];
206
- /**
207
- * Execute a client-side tool
208
- */
209
- execute(name: string, args: Record<string, unknown>): Promise<ToolResult>;
210
- }
211
-
212
- /**
213
- * Conversation management
214
- */
215
-
216
- declare class ConversationManager {
217
- private productId;
218
- private apiUrl;
219
- private currentId;
220
- constructor(productId: string, apiUrl: string);
221
- /**
222
- * Get localStorage key for this product
223
- */
224
- private getStorageKey;
225
- /**
226
- * Load conversation ID from localStorage
227
- */
228
- private loadFromStorage;
229
- /**
230
- * Save conversation ID to localStorage
231
- */
232
- private saveToStorage;
233
- /**
234
- * Clear conversation ID from localStorage
235
- */
236
- private clearStorage;
237
- /**
238
- * Get current conversation ID
239
- */
240
- getCurrentId(): string | null;
241
- /**
242
- * Set current conversation ID
243
- */
244
- setCurrentId(id: string | null): void;
245
- /**
246
- * Check if there's a restored conversation
247
- */
248
- hasRestoredConversation(): boolean;
249
- /**
250
- * Clear current conversation (start new)
251
- */
252
- clear(): void;
253
- /**
254
- * Fetch list of conversations for verified user
255
- */
256
- getConversations(identityToken: string): Promise<Conversation[]>;
257
- /**
258
- * Load conversation history for verified user
259
- */
260
- loadHistory(conversationId: string, identityToken: string): Promise<Message[]>;
261
- /**
262
- * Load conversation history for anonymous user
263
- */
264
- loadAnonymousHistory(conversationId: string): Promise<Message[]>;
265
- /**
266
- * Parse history messages from API format
267
- */
268
- private parseHistoryMessages;
269
- /**
270
- * Parse structured content (with thinking/text blocks) and extract just text
271
- */
272
- private parseContent;
273
- }
274
-
275
- /**
276
- * SSE streaming utilities for parsing server-sent events
277
- */
278
-
279
- /**
280
- * Parse a single SSE data line into a StreamEvent
281
- */
282
- declare function parseSSEData(data: string): StreamEvent | null;
283
- /**
284
- * Parse SSE chunk into lines and extract data
285
- */
286
- declare function parseSSEChunk(chunk: string): Generator<string>;
287
- /**
288
- * Create an async generator that streams events from a Response
289
- */
290
- declare function streamResponse(response: Response, signal?: AbortSignal): AsyncGenerator<StreamEvent>;
291
-
292
- /**
293
- * SDK Default Tools - automatically registered, zero configuration
294
- *
295
- * These tools are built into the Crow SDK and available to all agents
296
- * without any user configuration required.
297
- */
298
-
299
- /**
300
- * SDK Default Tools - automatically registered, zero configuration
301
- */
302
- declare const DEFAULT_TOOLS: {
303
- /**
304
- * Refresh the current page in the user's browser
305
- */
306
- readonly refreshPage: () => Promise<ToolResult>;
307
- };
308
- type DefaultToolName = keyof typeof DEFAULT_TOOLS;
309
- declare const DEFAULT_TOOL_NAMES: DefaultToolName[];
310
-
311
- export { ContextData, Conversation, ConversationManager, CrowClient, CrowClientConfig, CrowEventCallbacks, DEFAULT_TOOLS, DEFAULT_TOOL_NAMES, type DefaultToolName, IdentifyOptions, IdentityManager, IdentityState, Message, StreamEvent, ToolHandlers, ToolManager, ToolResult, parseSSEChunk, parseSSEData, streamResponse };
1
+ export declare interface ActiveWorkflow {
2
+ name: string;
3
+ todos: WorkflowTodo[];
4
+ isComplete?: boolean;
5
+ }
6
+
7
+ declare interface BrowserUseConfig {
8
+ productId: string;
9
+ apiUrl: string;
10
+ }
11
+
12
+ export declare interface Citation {
13
+ document_id: string;
14
+ filename: string;
15
+ similarity?: number;
16
+ image_url?: string;
17
+ page?: number;
18
+ }
19
+
20
+ export declare interface ContextData {
21
+ /** Current page URL or path */
22
+ page?: string;
23
+ /** Custom context data */
24
+ [key: string]: unknown;
25
+ }
26
+
27
+ export declare interface Conversation {
28
+ id: string;
29
+ name: string | null;
30
+ created_at: string;
31
+ updated_at: string;
32
+ }
33
+
34
+ export declare class ConversationManager {
35
+ private productId;
36
+ private apiUrl;
37
+ private currentId;
38
+ constructor(productId: string, apiUrl: string);
39
+ /**
40
+ * Get localStorage key for this product
41
+ */
42
+ private getStorageKey;
43
+ /**
44
+ * Load conversation ID from localStorage
45
+ */
46
+ private loadFromStorage;
47
+ /**
48
+ * Save conversation ID to localStorage
49
+ */
50
+ private saveToStorage;
51
+ /**
52
+ * Clear conversation ID from localStorage
53
+ */
54
+ private clearStorage;
55
+ /**
56
+ * Get current conversation ID
57
+ */
58
+ getCurrentId(): string | null;
59
+ /**
60
+ * Set current conversation ID
61
+ */
62
+ setCurrentId(id: string | null): void;
63
+ /**
64
+ * Check if there's a restored conversation
65
+ */
66
+ hasRestoredConversation(): boolean;
67
+ /**
68
+ * Clear current conversation (start new)
69
+ */
70
+ clear(): void;
71
+ /**
72
+ * Fetch list of conversations for verified user
73
+ */
74
+ getConversations(identityToken: string): Promise<Conversation[]>;
75
+ /**
76
+ * Load conversation history for verified user
77
+ */
78
+ loadHistory(conversationId: string, identityToken: string): Promise<Message[]>;
79
+ /**
80
+ * Load conversation history for anonymous user
81
+ */
82
+ loadAnonymousHistory(conversationId: string): Promise<Message[]>;
83
+ /**
84
+ * Parse history messages from API format
85
+ */
86
+ private parseHistoryMessages;
87
+ /**
88
+ * Parse structured content (with thinking/text blocks) and extract just text
89
+ */
90
+ private parseContent;
91
+ }
92
+
93
+ export declare class CrowBrowserUse {
94
+ private config;
95
+ private pageController;
96
+ private sessionId;
97
+ private maxSteps;
98
+ constructor(config: BrowserUseConfig);
99
+ /**
100
+ * Initialize PageController with non-blocking pointer
101
+ */
102
+ private initPageController;
103
+ /**
104
+ * Execute a browser automation task
105
+ */
106
+ execute(task: string): Promise<ToolResult>;
107
+ /**
108
+ * Start a browser-use session on the server
109
+ */
110
+ private startSession;
111
+ /**
112
+ * Process a step on the server
113
+ */
114
+ private processStep;
115
+ /**
116
+ * Execute an action using PageController
117
+ */
118
+ private executeAction;
119
+ /**
120
+ * Cleanup resources
121
+ */
122
+ private cleanup;
123
+ /**
124
+ * Stop the current task
125
+ */
126
+ stop(): Promise<void>;
127
+ }
128
+
129
+ export declare class CrowClient {
130
+ private config;
131
+ private identity;
132
+ private tools;
133
+ private conversations;
134
+ private context;
135
+ private abortController;
136
+ private callbacks;
137
+ private _messages;
138
+ private messageListeners;
139
+ private _isLoading;
140
+ private loadingListeners;
141
+ constructor(config: CrowClientConfig);
142
+ /**
143
+ * Get current product ID
144
+ */
145
+ get productId(): string;
146
+ /**
147
+ * Get current API URL
148
+ */
149
+ get apiUrl(): string;
150
+ /**
151
+ * Get/set current model
152
+ */
153
+ get model(): string;
154
+ set model(value: string);
155
+ /**
156
+ * Register event callbacks
157
+ */
158
+ on(callbacks: CrowEventCallbacks): void;
159
+ /**
160
+ * Identify the current user with a JWT token
161
+ */
162
+ identify(options: IdentifyOptions): void;
163
+ /**
164
+ * Reset user identity (call on logout)
165
+ */
166
+ resetUser(): void;
167
+ /**
168
+ * Check if user is identified
169
+ */
170
+ isIdentified(): boolean;
171
+ /**
172
+ * Check if user is verified by server
173
+ */
174
+ isVerified(): boolean;
175
+ /**
176
+ * Register client-side tool handlers
177
+ */
178
+ registerTools(tools: ToolHandlers): void;
179
+ /**
180
+ * Unregister a tool handler
181
+ */
182
+ unregisterTool(name: string): void;
183
+ /**
184
+ * Get list of registered tool names
185
+ */
186
+ getRegisteredTools(): string[];
187
+ /**
188
+ * Set context data to be sent with messages
189
+ */
190
+ setContext(data: ContextData): void;
191
+ /**
192
+ * Clear context data
193
+ */
194
+ clearContext(): void;
195
+ /**
196
+ * Get current messages
197
+ */
198
+ get messages(): Message[];
199
+ /**
200
+ * Check if currently loading/streaming
201
+ */
202
+ get isLoading(): boolean;
203
+ /**
204
+ * Subscribe to message changes
205
+ */
206
+ onMessages(callback: (messages: Message[]) => void): () => void;
207
+ /**
208
+ * Subscribe to loading state changes
209
+ */
210
+ onLoading(callback: (isLoading: boolean) => void): () => void;
211
+ /**
212
+ * Clear all messages and start new conversation
213
+ */
214
+ clearMessages(): void;
215
+ /**
216
+ * Load messages from history
217
+ */
218
+ loadMessages(messages: Message[]): void;
219
+ private notifyMessages;
220
+ private setLoading;
221
+ private addMessage;
222
+ private updateMessage;
223
+ private generateMessageId;
224
+ /**
225
+ * Get current conversation ID
226
+ */
227
+ get conversationId(): string | null;
228
+ /**
229
+ * Set current conversation ID
230
+ */
231
+ set conversationId(id: string | null);
232
+ /**
233
+ * Get list of conversations for verified user
234
+ */
235
+ getConversations(): Promise<Conversation[]>;
236
+ /**
237
+ * Load conversation history
238
+ */
239
+ loadHistory(conversationId: string): Promise<Message[]>;
240
+ /**
241
+ * Switch to a different conversation
242
+ */
243
+ switchConversation(conversationId: string): Promise<void>;
244
+ /**
245
+ * Send a message and receive streaming response
246
+ * Returns an async generator of stream events
247
+ */
248
+ sendMessage(content: string): AsyncGenerator<StreamEvent>;
249
+ /**
250
+ * Send a message and wait for complete response (non-streaming)
251
+ */
252
+ send(content: string): Promise<Message | null>;
253
+ /**
254
+ * Stop current generation
255
+ */
256
+ stop(): void;
257
+ /**
258
+ * Destroy the client and clean up resources
259
+ */
260
+ destroy(): void;
261
+ }
262
+
263
+ /**
264
+ * Core types for @usecrow/client
265
+ */
266
+ export declare interface CrowClientConfig {
267
+ /** Your Crow product ID from the dashboard */
268
+ productId: string;
269
+ /** API URL (defaults to https://api.usecrow.org) */
270
+ apiUrl?: string;
271
+ /** Default model to use */
272
+ model?: string;
273
+ }
274
+
275
+ export declare interface CrowEventCallbacks {
276
+ onMessage?: (message: Message) => void;
277
+ onMessageUpdate?: (messageId: string, updates: Partial<Message>) => void;
278
+ onToolCall?: (event: StreamEvent & {
279
+ type: 'tool_call_start' | 'tool_call_complete' | 'client_tool_call';
280
+ }) => void;
281
+ onWorkflow?: (event: StreamEvent & {
282
+ type: 'workflow_started' | 'workflow_todo_updated' | 'workflow_ended' | 'workflow_complete_prompt';
283
+ }) => void;
284
+ onVerificationStatus?: (isVerified: boolean) => void;
285
+ onError?: (error: Error) => void;
286
+ }
287
+
288
+ export declare const DEFAULT_TOOL_NAMES: DefaultToolName[];
289
+
290
+ /**
291
+ * SDK Default Tools - automatically registered, zero configuration
292
+ */
293
+ export declare const DEFAULT_TOOLS: {
294
+ /**
295
+ * Refresh the current page in the user's browser
296
+ */
297
+ readonly refreshPage: () => Promise<ToolResult>;
298
+ };
299
+
300
+ export declare type DefaultToolName = keyof typeof DEFAULT_TOOLS;
301
+
302
+ export declare interface IdentifyOptions {
303
+ /** JWT token from your backend for user verification */
304
+ token: string;
305
+ /** Optional user display name */
306
+ name?: string;
307
+ /** Optional user email */
308
+ email?: string;
309
+ /** Any additional metadata */
310
+ [key: string]: unknown;
311
+ }
312
+
313
+ export declare class IdentityManager {
314
+ private state;
315
+ private listeners;
316
+ /**
317
+ * Identify the current user with a JWT token
318
+ */
319
+ identify(options: IdentifyOptions): void;
320
+ /**
321
+ * Update verification status (called when server confirms)
322
+ */
323
+ setVerified(isVerified: boolean): void;
324
+ /**
325
+ * Reset user identity (call on logout)
326
+ */
327
+ reset(): void;
328
+ /**
329
+ * Get current identity token
330
+ */
331
+ getToken(): string | null;
332
+ /**
333
+ * Get current identity state
334
+ */
335
+ getState(): IdentityState;
336
+ /**
337
+ * Check if user is identified
338
+ */
339
+ isIdentified(): boolean;
340
+ /**
341
+ * Check if user is verified
342
+ */
343
+ isVerified(): boolean;
344
+ /**
345
+ * Subscribe to identity changes
346
+ */
347
+ subscribe(callback: (state: IdentityState) => void): () => void;
348
+ private notify;
349
+ }
350
+
351
+ export declare interface IdentityState {
352
+ token: string | null;
353
+ metadata: Record<string, unknown>;
354
+ isVerified: boolean;
355
+ }
356
+
357
+ export declare interface Message {
358
+ id: string;
359
+ content: string;
360
+ role: 'user' | 'assistant';
361
+ timestamp: Date;
362
+ /** Citations from knowledge base */
363
+ citations?: Citation[];
364
+ /** Claude's reasoning/thinking trace */
365
+ thinking?: string;
366
+ /** Whether thinking is complete */
367
+ thinkingComplete?: boolean;
368
+ }
369
+
370
+ /**
371
+ * Parse SSE chunk into lines and extract data
372
+ */
373
+ export declare function parseSSEChunk(chunk: string): Generator<string>;
374
+
375
+ /**
376
+ * Parse a single SSE data line into a StreamEvent
377
+ */
378
+ export declare function parseSSEData(data: string): StreamEvent | null;
379
+
380
+ export declare type StreamEvent = {
381
+ type: 'content';
382
+ text: string;
383
+ accumulated: string;
384
+ } | {
385
+ type: 'thinking';
386
+ content: string;
387
+ } | {
388
+ type: 'thinking_complete';
389
+ } | {
390
+ type: 'citations';
391
+ citations: Citation[];
392
+ } | {
393
+ type: 'tool_call_start';
394
+ toolName: string;
395
+ arguments: Record<string, unknown>;
396
+ } | {
397
+ type: 'tool_call_complete';
398
+ toolName: string;
399
+ success: boolean;
400
+ } | {
401
+ type: 'client_tool_call';
402
+ toolName: string;
403
+ arguments: Record<string, unknown>;
404
+ } | {
405
+ type: 'workflow_started';
406
+ name: string;
407
+ todos: WorkflowTodo[];
408
+ } | {
409
+ type: 'workflow_todo_updated';
410
+ todoId: string;
411
+ status: 'pending' | 'completed';
412
+ } | {
413
+ type: 'workflow_ended';
414
+ } | {
415
+ type: 'workflow_complete_prompt';
416
+ } | {
417
+ type: 'verification_status';
418
+ isVerified: boolean;
419
+ } | {
420
+ type: 'conversation_id';
421
+ conversationId: string;
422
+ } | {
423
+ type: 'error';
424
+ message: string;
425
+ } | {
426
+ type: 'done';
427
+ };
428
+
429
+ /**
430
+ * Create an async generator that streams events from a Response
431
+ */
432
+ export declare function streamResponse(response: Response, signal?: AbortSignal): AsyncGenerator<StreamEvent>;
433
+
434
+ export declare type ToolHandler = (args: Record<string, unknown>) => Promise<ToolResult> | ToolResult;
435
+
436
+ export declare type ToolHandlers = Record<string, ToolHandler>;
437
+
438
+ export declare class ToolManager {
439
+ private handlers;
440
+ /**
441
+ * Register client-side tool handlers
442
+ */
443
+ register(tools: ToolHandlers): void;
444
+ /**
445
+ * Unregister a tool handler
446
+ */
447
+ unregister(name: string): void;
448
+ /**
449
+ * Check if a tool is registered
450
+ */
451
+ has(name: string): boolean;
452
+ /**
453
+ * Get all registered tool names
454
+ */
455
+ getRegisteredTools(): string[];
456
+ /**
457
+ * Execute a client-side tool
458
+ */
459
+ execute(name: string, args: Record<string, unknown>): Promise<ToolResult>;
460
+ }
461
+
462
+ export declare interface ToolResult {
463
+ status: 'success' | 'error';
464
+ data?: unknown;
465
+ error?: string;
466
+ }
467
+
468
+ export declare interface WorkflowTodo {
469
+ id: string;
470
+ text: string;
471
+ status: 'pending' | 'completed';
472
+ }
473
+
474
+ export { }