@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
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { k as Thread, l as ThreadData, _ as ThreadStorageAdapter, X as AsyncThreadStorageAdapter, g as Message } from './types-BtAaOV07.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Tool types for App Context Awareness
|
|
3
5
|
*/
|
|
@@ -207,194 +209,6 @@ interface CustomKeywords {
|
|
|
207
209
|
*/
|
|
208
210
|
declare function createCustomDetector(customKeywords: CustomKeywords): (message: string) => IntentDetectionResult;
|
|
209
211
|
|
|
210
|
-
/**
|
|
211
|
-
* Message roles in a conversation (OpenAI format)
|
|
212
|
-
*/
|
|
213
|
-
type MessageRole = "user" | "assistant" | "system" | "tool";
|
|
214
|
-
/**
|
|
215
|
-
* A source document from knowledge base
|
|
216
|
-
*/
|
|
217
|
-
interface Source {
|
|
218
|
-
/** Unique identifier */
|
|
219
|
-
id: string;
|
|
220
|
-
/** Source title or filename */
|
|
221
|
-
title: string;
|
|
222
|
-
/** Relevant content snippet */
|
|
223
|
-
content: string;
|
|
224
|
-
/** URL if available */
|
|
225
|
-
url?: string;
|
|
226
|
-
/** Relevance score (0-1) */
|
|
227
|
-
score?: number;
|
|
228
|
-
/** Additional metadata */
|
|
229
|
-
metadata?: Record<string, unknown>;
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Tool/function call in OpenAI format
|
|
233
|
-
* Used in assistant messages when AI wants to call tools
|
|
234
|
-
*/
|
|
235
|
-
interface ToolCall {
|
|
236
|
-
/** Unique identifier for this call */
|
|
237
|
-
id: string;
|
|
238
|
-
/** Always "function" for OpenAI compatibility */
|
|
239
|
-
type: "function";
|
|
240
|
-
/** Function details */
|
|
241
|
-
function: {
|
|
242
|
-
/** Name of the function/tool */
|
|
243
|
-
name: string;
|
|
244
|
-
/** Arguments as JSON string (OpenAI format) */
|
|
245
|
-
arguments: string;
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Attachment in a message (images, files, etc.)
|
|
250
|
-
*
|
|
251
|
-
* Attachments can be stored as:
|
|
252
|
-
* - Base64 data (free tier, embedded in message)
|
|
253
|
-
* - URL (premium cloud storage, lighter payload)
|
|
254
|
-
*/
|
|
255
|
-
interface MessageAttachment {
|
|
256
|
-
/** Type of attachment */
|
|
257
|
-
type: "image" | "file" | "audio" | "video";
|
|
258
|
-
/** Base64 data (for embedded attachments) */
|
|
259
|
-
data?: string;
|
|
260
|
-
/** URL for cloud-stored attachments (managed cloud storage) */
|
|
261
|
-
url?: string;
|
|
262
|
-
/** MIME type */
|
|
263
|
-
mimeType: string;
|
|
264
|
-
/** Optional filename */
|
|
265
|
-
filename?: string;
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* Token usage information
|
|
269
|
-
*/
|
|
270
|
-
interface TokenUsage {
|
|
271
|
-
prompt_tokens: number;
|
|
272
|
-
completion_tokens: number;
|
|
273
|
-
total_tokens?: number;
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* Message metadata (flexible container for provider-specific data)
|
|
277
|
-
*/
|
|
278
|
-
interface MessageMetadata {
|
|
279
|
-
/** Extended thinking/reasoning (Claude, DeepSeek) */
|
|
280
|
-
thinking?: string;
|
|
281
|
-
/** Knowledge base sources */
|
|
282
|
-
sources?: Source[];
|
|
283
|
-
/** Attachments (images, files) */
|
|
284
|
-
attachments?: MessageAttachment[];
|
|
285
|
-
/** Model used to generate this message */
|
|
286
|
-
model?: string;
|
|
287
|
-
/** Token usage */
|
|
288
|
-
usage?: TokenUsage;
|
|
289
|
-
/** Any additional data */
|
|
290
|
-
[key: string]: unknown;
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* A message in the conversation (OpenAI format)
|
|
294
|
-
*
|
|
295
|
-
* This format is compatible with OpenAI's Chat Completions API
|
|
296
|
-
* and can be stored directly in a database (1 row per message).
|
|
297
|
-
*
|
|
298
|
-
* Message types:
|
|
299
|
-
* - user: User's input message
|
|
300
|
-
* - assistant: AI's response (may include tool_calls)
|
|
301
|
-
* - tool: Result of a tool execution (has tool_call_id)
|
|
302
|
-
* - system: System prompt (usually first message)
|
|
303
|
-
*
|
|
304
|
-
* @example
|
|
305
|
-
* // User message
|
|
306
|
-
* { role: "user", content: "What's the weather?" }
|
|
307
|
-
*
|
|
308
|
-
* // Assistant requesting tool
|
|
309
|
-
* { role: "assistant", content: null, tool_calls: [{...}] }
|
|
310
|
-
*
|
|
311
|
-
* // Tool result
|
|
312
|
-
* { role: "tool", content: '{"temp": 72}', tool_call_id: "call_abc" }
|
|
313
|
-
*
|
|
314
|
-
* // Final assistant response
|
|
315
|
-
* { role: "assistant", content: "The temperature is 72°F" }
|
|
316
|
-
*/
|
|
317
|
-
interface Message {
|
|
318
|
-
/** Unique identifier */
|
|
319
|
-
id: string;
|
|
320
|
-
/** Thread/conversation ID (for multi-session apps) */
|
|
321
|
-
thread_id?: string;
|
|
322
|
-
/** Role of the message sender */
|
|
323
|
-
role: MessageRole;
|
|
324
|
-
/** Text content (null for tool-calling assistant messages) */
|
|
325
|
-
content: string | null;
|
|
326
|
-
/**
|
|
327
|
-
* Tool calls made by assistant (OpenAI format)
|
|
328
|
-
* Only present when role is "assistant" and AI wants to call tools
|
|
329
|
-
*/
|
|
330
|
-
tool_calls?: ToolCall[];
|
|
331
|
-
/**
|
|
332
|
-
* Tool call ID this message is responding to
|
|
333
|
-
* Only present when role is "tool"
|
|
334
|
-
*/
|
|
335
|
-
tool_call_id?: string;
|
|
336
|
-
/**
|
|
337
|
-
* Flexible metadata container
|
|
338
|
-
* Contains: thinking, sources, attachments, model, usage, etc.
|
|
339
|
-
*/
|
|
340
|
-
metadata?: MessageMetadata;
|
|
341
|
-
/** When the message was created */
|
|
342
|
-
created_at: Date;
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* Helper to parse tool call arguments
|
|
346
|
-
*/
|
|
347
|
-
declare function parseToolCallArgs<T = Record<string, unknown>>(toolCall: ToolCall): T;
|
|
348
|
-
/**
|
|
349
|
-
* Helper to create a tool call
|
|
350
|
-
*/
|
|
351
|
-
declare function createToolCall(id: string, name: string, args: Record<string, unknown>): ToolCall;
|
|
352
|
-
/**
|
|
353
|
-
* Create a new message with defaults
|
|
354
|
-
*/
|
|
355
|
-
declare function createMessage(partial: Partial<Message> & Pick<Message, "role"> & {
|
|
356
|
-
content?: string | null;
|
|
357
|
-
}): Message;
|
|
358
|
-
/**
|
|
359
|
-
* Create a user message
|
|
360
|
-
*/
|
|
361
|
-
declare function createUserMessage(content: string, options?: {
|
|
362
|
-
id?: string;
|
|
363
|
-
thread_id?: string;
|
|
364
|
-
attachments?: MessageAttachment[];
|
|
365
|
-
}): Message;
|
|
366
|
-
/**
|
|
367
|
-
* Create an assistant message
|
|
368
|
-
*/
|
|
369
|
-
declare function createAssistantMessage(content: string | null, options?: {
|
|
370
|
-
id?: string;
|
|
371
|
-
thread_id?: string;
|
|
372
|
-
tool_calls?: ToolCall[];
|
|
373
|
-
thinking?: string;
|
|
374
|
-
sources?: Source[];
|
|
375
|
-
model?: string;
|
|
376
|
-
}): Message;
|
|
377
|
-
/**
|
|
378
|
-
* Create a tool result message
|
|
379
|
-
*/
|
|
380
|
-
declare function createToolMessage(toolCallId: string, result: {
|
|
381
|
-
success: boolean;
|
|
382
|
-
data?: unknown;
|
|
383
|
-
error?: string;
|
|
384
|
-
message?: string;
|
|
385
|
-
}, options?: {
|
|
386
|
-
id?: string;
|
|
387
|
-
thread_id?: string;
|
|
388
|
-
}): Message;
|
|
389
|
-
/**
|
|
390
|
-
* Check if a message has tool calls
|
|
391
|
-
*/
|
|
392
|
-
declare function hasToolCalls(message: Message): boolean;
|
|
393
|
-
/**
|
|
394
|
-
* Check if a message is a tool result
|
|
395
|
-
*/
|
|
396
|
-
declare function isToolResult(message: Message): boolean;
|
|
397
|
-
|
|
398
212
|
/**
|
|
399
213
|
* Supported LLM providers
|
|
400
214
|
*/
|
|
@@ -659,52 +473,391 @@ interface InternalKnowledgeBaseSearchResponse {
|
|
|
659
473
|
}
|
|
660
474
|
|
|
661
475
|
/**
|
|
662
|
-
*
|
|
476
|
+
* ThreadManagerState Interface
|
|
477
|
+
*
|
|
478
|
+
* Contract for framework-specific state implementations.
|
|
479
|
+
* Following the same pattern as ChatState for framework agnosticism.
|
|
663
480
|
*/
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Load status for async operations
|
|
484
|
+
*/
|
|
485
|
+
type LoadStatus = "idle" | "loading" | "loaded" | "error";
|
|
486
|
+
/**
|
|
487
|
+
* ThreadManagerState interface - Framework adapters implement this
|
|
488
|
+
*
|
|
489
|
+
* This is the key abstraction that enables framework-agnostic code.
|
|
490
|
+
* The ThreadManager class uses this interface, and each framework
|
|
491
|
+
* provides its own implementation.
|
|
492
|
+
*
|
|
493
|
+
* @example React implementation
|
|
494
|
+
* ```typescript
|
|
495
|
+
* class ReactThreadManagerState implements ThreadManagerState {
|
|
496
|
+
* #threads: Thread[] = [];
|
|
497
|
+
* #callbacks = new Set<() => void>();
|
|
498
|
+
*
|
|
499
|
+
* get threads() { return this.#threads; }
|
|
500
|
+
* set threads(t) {
|
|
501
|
+
* this.#threads = t;
|
|
502
|
+
* this.#callbacks.forEach(cb => cb()); // Trigger re-render
|
|
503
|
+
* }
|
|
504
|
+
*
|
|
505
|
+
* subscribe(cb: () => void) {
|
|
506
|
+
* this.#callbacks.add(cb);
|
|
507
|
+
* return () => this.#callbacks.delete(cb);
|
|
508
|
+
* }
|
|
509
|
+
* }
|
|
510
|
+
* ```
|
|
511
|
+
*/
|
|
512
|
+
interface ThreadManagerState {
|
|
513
|
+
/** All threads (metadata only) */
|
|
514
|
+
threads: Thread[];
|
|
515
|
+
/** Currently selected thread ID */
|
|
516
|
+
currentThreadId: string | null;
|
|
517
|
+
/** Currently loaded thread data (with messages) */
|
|
518
|
+
currentThread: ThreadData | null;
|
|
519
|
+
/** Current loading status */
|
|
520
|
+
loadStatus: LoadStatus;
|
|
521
|
+
/** Current error if any */
|
|
522
|
+
error: Error | undefined;
|
|
523
|
+
/**
|
|
524
|
+
* Set all threads
|
|
525
|
+
*/
|
|
526
|
+
setThreads(threads: Thread[]): void;
|
|
527
|
+
/**
|
|
528
|
+
* Set the current thread
|
|
529
|
+
*/
|
|
530
|
+
setCurrentThread(thread: ThreadData | null): void;
|
|
531
|
+
/**
|
|
532
|
+
* Set the current thread ID
|
|
533
|
+
*/
|
|
534
|
+
setCurrentThreadId(id: string | null): void;
|
|
535
|
+
/**
|
|
536
|
+
* Add a new thread to the list
|
|
537
|
+
*/
|
|
538
|
+
addThread(thread: Thread): void;
|
|
539
|
+
/**
|
|
540
|
+
* Update a thread's metadata
|
|
541
|
+
*/
|
|
542
|
+
updateThread(id: string, updates: Partial<Thread>): void;
|
|
543
|
+
/**
|
|
544
|
+
* Remove a thread from the list
|
|
545
|
+
*/
|
|
546
|
+
removeThread(id: string): void;
|
|
547
|
+
/**
|
|
548
|
+
* Set loading status
|
|
549
|
+
*/
|
|
550
|
+
setLoadStatus(status: LoadStatus): void;
|
|
551
|
+
/**
|
|
552
|
+
* Set error
|
|
553
|
+
*/
|
|
554
|
+
setError(error: Error | undefined): void;
|
|
555
|
+
/**
|
|
556
|
+
* Subscribe to state changes
|
|
557
|
+
* Returns unsubscribe function
|
|
558
|
+
*
|
|
559
|
+
* This is used by React's useSyncExternalStore.
|
|
560
|
+
* Vue/Svelte may not need this (they use refs/stores).
|
|
561
|
+
*/
|
|
562
|
+
subscribe?(callback: () => void): () => void;
|
|
563
|
+
/**
|
|
564
|
+
* Get immutable snapshot of threads
|
|
565
|
+
*/
|
|
566
|
+
getThreadsSnapshot?(): Thread[];
|
|
567
|
+
/**
|
|
568
|
+
* Get current thread snapshot
|
|
569
|
+
*/
|
|
570
|
+
getCurrentThreadSnapshot?(): ThreadData | null;
|
|
571
|
+
/**
|
|
572
|
+
* Get load status snapshot
|
|
573
|
+
*/
|
|
574
|
+
getLoadStatusSnapshot?(): LoadStatus;
|
|
575
|
+
/**
|
|
576
|
+
* Get error snapshot
|
|
577
|
+
*/
|
|
578
|
+
getErrorSnapshot?(): Error | undefined;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Default in-memory state implementation (for testing/vanilla JS)
|
|
582
|
+
*/
|
|
583
|
+
declare class SimpleThreadManagerState implements ThreadManagerState {
|
|
584
|
+
private _threads;
|
|
585
|
+
private _currentThreadId;
|
|
586
|
+
private _currentThread;
|
|
587
|
+
private _loadStatus;
|
|
588
|
+
private _error;
|
|
589
|
+
private callbacks;
|
|
590
|
+
get threads(): Thread[];
|
|
591
|
+
get currentThreadId(): string | null;
|
|
592
|
+
get currentThread(): ThreadData | null;
|
|
593
|
+
get loadStatus(): LoadStatus;
|
|
594
|
+
get error(): Error | undefined;
|
|
595
|
+
set threads(value: Thread[]);
|
|
596
|
+
setThreads(threads: Thread[]): void;
|
|
597
|
+
setCurrentThread(thread: ThreadData | null): void;
|
|
598
|
+
setCurrentThreadId(id: string | null): void;
|
|
599
|
+
addThread(thread: Thread): void;
|
|
600
|
+
updateThread(id: string, updates: Partial<Thread>): void;
|
|
601
|
+
removeThread(id: string): void;
|
|
602
|
+
setLoadStatus(status: LoadStatus): void;
|
|
603
|
+
setError(error: Error | undefined): void;
|
|
604
|
+
subscribe(callback: () => void): () => void;
|
|
605
|
+
getThreadsSnapshot(): Thread[];
|
|
606
|
+
getCurrentThreadSnapshot(): ThreadData | null;
|
|
607
|
+
getLoadStatusSnapshot(): LoadStatus;
|
|
608
|
+
getErrorSnapshot(): Error | undefined;
|
|
609
|
+
private notify;
|
|
673
610
|
}
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* localStorage Thread Storage Adapter
|
|
614
|
+
*
|
|
615
|
+
* Default adapter for thread persistence using browser localStorage.
|
|
616
|
+
* Stores all data in a single key for cleaner storage management.
|
|
617
|
+
*/
|
|
618
|
+
|
|
674
619
|
/**
|
|
675
|
-
*
|
|
620
|
+
* Configuration for localStorage adapter
|
|
676
621
|
*/
|
|
677
|
-
interface
|
|
678
|
-
/**
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
622
|
+
interface LocalStorageAdapterConfig {
|
|
623
|
+
/**
|
|
624
|
+
* Storage key to use
|
|
625
|
+
* @default "copilot-sdk-store"
|
|
626
|
+
*/
|
|
627
|
+
storageKey?: string;
|
|
682
628
|
}
|
|
683
629
|
/**
|
|
684
|
-
*
|
|
630
|
+
* Create a localStorage adapter for thread storage
|
|
631
|
+
*
|
|
632
|
+
* All data is stored in a single key for cleaner storage management.
|
|
633
|
+
*
|
|
634
|
+
* @example Default usage
|
|
635
|
+
* ```typescript
|
|
636
|
+
* const adapter = createLocalStorageAdapter();
|
|
637
|
+
* const threadManager = new ThreadManager({ adapter });
|
|
638
|
+
* ```
|
|
639
|
+
*
|
|
640
|
+
* @example With custom key
|
|
641
|
+
* ```typescript
|
|
642
|
+
* const adapter = createLocalStorageAdapter({
|
|
643
|
+
* storageKey: "my-app-copilot-store"
|
|
644
|
+
* });
|
|
645
|
+
* ```
|
|
646
|
+
*/
|
|
647
|
+
declare function createLocalStorageAdapter(config?: LocalStorageAdapterConfig): ThreadStorageAdapter;
|
|
648
|
+
/**
|
|
649
|
+
* Default localStorage adapter instance
|
|
685
650
|
*/
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
651
|
+
declare const localStorageAdapter: ThreadStorageAdapter;
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* In-Memory Thread Storage Adapter
|
|
655
|
+
*
|
|
656
|
+
* Non-persistent adapter useful for testing or ephemeral sessions.
|
|
657
|
+
*/
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
* Create an in-memory adapter for thread storage
|
|
661
|
+
*
|
|
662
|
+
* This adapter stores threads in memory only - data is lost on page refresh.
|
|
663
|
+
* Useful for:
|
|
664
|
+
* - Testing
|
|
665
|
+
* - Server-side rendering (where localStorage is unavailable)
|
|
666
|
+
* - Ephemeral sessions where persistence isn't needed
|
|
667
|
+
*
|
|
668
|
+
* @example
|
|
669
|
+
* ```typescript
|
|
670
|
+
* const adapter = createMemoryAdapter();
|
|
671
|
+
* const threadManager = new ThreadManager({ adapter });
|
|
672
|
+
* ```
|
|
673
|
+
*
|
|
674
|
+
* @example Pre-populate with threads
|
|
675
|
+
* ```typescript
|
|
676
|
+
* const adapter = createMemoryAdapter([
|
|
677
|
+
* { id: "1", title: "Test", messages: [], sources: [], createdAt: new Date(), updatedAt: new Date() }
|
|
678
|
+
* ]);
|
|
679
|
+
* ```
|
|
680
|
+
*/
|
|
681
|
+
declare function createMemoryAdapter(initialThreads?: ThreadData[]): ThreadStorageAdapter;
|
|
682
|
+
/**
|
|
683
|
+
* No-op adapter that never saves or loads
|
|
684
|
+
* Useful when you want to completely disable persistence
|
|
685
|
+
*/
|
|
686
|
+
declare const noopAdapter: ThreadStorageAdapter;
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* ThreadManager - Framework-agnostic Thread Management
|
|
690
|
+
*
|
|
691
|
+
* Manages thread state and persistence with pluggable storage adapters.
|
|
692
|
+
* Similar pattern to AbstractChat for framework agnosticism.
|
|
693
|
+
*/
|
|
694
|
+
|
|
695
|
+
/**
|
|
696
|
+
* Configuration for ThreadManager
|
|
697
|
+
*/
|
|
698
|
+
interface ThreadManagerConfig {
|
|
699
|
+
/**
|
|
700
|
+
* Storage adapter for persistence
|
|
701
|
+
* @default localStorage adapter
|
|
702
|
+
*/
|
|
703
|
+
adapter?: ThreadStorageAdapter | AsyncThreadStorageAdapter;
|
|
704
|
+
/**
|
|
705
|
+
* Debounce delay for auto-save (ms)
|
|
706
|
+
* @default 1000
|
|
707
|
+
*/
|
|
708
|
+
saveDebounce?: number;
|
|
709
|
+
/**
|
|
710
|
+
* Whether to auto-load threads on initialization
|
|
711
|
+
* @default true
|
|
712
|
+
*/
|
|
713
|
+
autoLoad?: boolean;
|
|
714
|
+
/**
|
|
715
|
+
* Whether to auto-restore the last active thread on load
|
|
716
|
+
* Requires adapter to support getLastActiveThreadId/setLastActiveThreadId
|
|
717
|
+
* @default true
|
|
718
|
+
*/
|
|
719
|
+
autoRestoreLastThread?: boolean;
|
|
720
|
+
/**
|
|
721
|
+
* Custom state implementation (for framework adapters)
|
|
722
|
+
* @default SimpleThreadManagerState
|
|
723
|
+
*/
|
|
724
|
+
state?: ThreadManagerState;
|
|
693
725
|
}
|
|
694
726
|
/**
|
|
695
|
-
*
|
|
727
|
+
* Callbacks for ThreadManager events
|
|
728
|
+
*/
|
|
729
|
+
interface ThreadManagerCallbacks {
|
|
730
|
+
/** Called when threads are loaded */
|
|
731
|
+
onThreadsLoaded?: (threads: Thread[]) => void;
|
|
732
|
+
/** Called when a thread is created */
|
|
733
|
+
onThreadCreated?: (thread: ThreadData) => void;
|
|
734
|
+
/** Called when a thread is switched */
|
|
735
|
+
onThreadSwitched?: (thread: ThreadData | null) => void;
|
|
736
|
+
/** Called when a thread is updated */
|
|
737
|
+
onThreadUpdated?: (thread: ThreadData) => void;
|
|
738
|
+
/** Called when a thread is deleted */
|
|
739
|
+
onThreadDeleted?: (threadId: string) => void;
|
|
740
|
+
/** Called when an error occurs */
|
|
741
|
+
onError?: (error: Error) => void;
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* Options for creating a new thread
|
|
745
|
+
*/
|
|
746
|
+
interface CreateThreadOptions {
|
|
747
|
+
/** Custom thread ID (auto-generated if not provided) */
|
|
748
|
+
id?: string;
|
|
749
|
+
/** Thread title */
|
|
750
|
+
title?: string;
|
|
751
|
+
/** Initial messages */
|
|
752
|
+
messages?: Message[];
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* Options for updating a thread
|
|
756
|
+
*/
|
|
757
|
+
interface UpdateThreadOptions {
|
|
758
|
+
/** Update title */
|
|
759
|
+
title?: string;
|
|
760
|
+
/** Update messages */
|
|
761
|
+
messages?: Message[];
|
|
762
|
+
/** Custom metadata updates */
|
|
763
|
+
[key: string]: unknown;
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* ThreadManager - Manages thread state and persistence
|
|
767
|
+
*
|
|
768
|
+
* @example Basic usage with localStorage (default)
|
|
769
|
+
* ```typescript
|
|
770
|
+
* const manager = new ThreadManager();
|
|
771
|
+
* await manager.loadThreads();
|
|
772
|
+
*
|
|
773
|
+
* const thread = await manager.createThread();
|
|
774
|
+
* console.log(manager.threads);
|
|
775
|
+
* ```
|
|
776
|
+
*
|
|
777
|
+
* @example With custom adapter
|
|
778
|
+
* ```typescript
|
|
779
|
+
* const manager = new ThreadManager({
|
|
780
|
+
* adapter: myDatabaseAdapter,
|
|
781
|
+
* });
|
|
782
|
+
* ```
|
|
696
783
|
*/
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
784
|
+
declare class ThreadManager {
|
|
785
|
+
protected state: ThreadManagerState;
|
|
786
|
+
protected adapter: ThreadStorageAdapter | AsyncThreadStorageAdapter;
|
|
787
|
+
protected callbacks: ThreadManagerCallbacks;
|
|
788
|
+
protected saveDebounce: number;
|
|
789
|
+
protected autoLoad: boolean;
|
|
790
|
+
protected autoRestoreLastThread: boolean;
|
|
791
|
+
private saveTimer;
|
|
792
|
+
private threadsData;
|
|
793
|
+
private initPromise;
|
|
794
|
+
constructor(config?: ThreadManagerConfig, callbacks?: ThreadManagerCallbacks);
|
|
795
|
+
/** All threads (metadata) */
|
|
796
|
+
get threads(): Thread[];
|
|
797
|
+
/** Currently selected thread ID */
|
|
798
|
+
get currentThreadId(): string | null;
|
|
799
|
+
/** Currently loaded thread (with messages) */
|
|
800
|
+
get currentThread(): ThreadData | null;
|
|
801
|
+
/** Whether threads are currently loading */
|
|
802
|
+
get isLoading(): boolean;
|
|
803
|
+
/** Current load status */
|
|
804
|
+
get loadStatus(): LoadStatus;
|
|
805
|
+
/** Current error */
|
|
806
|
+
get error(): Error | undefined;
|
|
807
|
+
/** Whether there are pending changes waiting to be saved */
|
|
808
|
+
get hasPendingChanges(): boolean;
|
|
809
|
+
/**
|
|
810
|
+
* Load all threads from storage
|
|
811
|
+
*/
|
|
812
|
+
loadThreads(): Promise<void>;
|
|
813
|
+
/**
|
|
814
|
+
* Wait for initialization to complete
|
|
815
|
+
*/
|
|
816
|
+
waitForInit(): Promise<void>;
|
|
817
|
+
/**
|
|
818
|
+
* Create a new thread
|
|
819
|
+
*/
|
|
820
|
+
createThread(options?: CreateThreadOptions): Promise<ThreadData>;
|
|
821
|
+
/**
|
|
822
|
+
* Switch to a different thread
|
|
823
|
+
*/
|
|
824
|
+
switchThread(id: string): Promise<ThreadData | null>;
|
|
825
|
+
/**
|
|
826
|
+
* Update the current thread
|
|
827
|
+
*/
|
|
828
|
+
updateCurrentThread(updates: UpdateThreadOptions): Promise<void>;
|
|
829
|
+
/**
|
|
830
|
+
* Delete a thread
|
|
831
|
+
*/
|
|
832
|
+
deleteThread(id: string): Promise<void>;
|
|
833
|
+
/**
|
|
834
|
+
* Clear the current thread selection
|
|
835
|
+
*/
|
|
836
|
+
clearCurrentThread(): void;
|
|
837
|
+
/**
|
|
838
|
+
* Clear all threads
|
|
839
|
+
*/
|
|
840
|
+
clearAllThreads(): Promise<void>;
|
|
841
|
+
/**
|
|
842
|
+
* Save changes immediately (bypass debounce)
|
|
843
|
+
*/
|
|
844
|
+
saveNow(): Promise<void>;
|
|
845
|
+
/**
|
|
846
|
+
* Dispose of the manager and save pending changes
|
|
847
|
+
*/
|
|
848
|
+
dispose(): Promise<void>;
|
|
849
|
+
/**
|
|
850
|
+
* Schedule a debounced save
|
|
851
|
+
*/
|
|
852
|
+
protected scheduleSave(): void;
|
|
853
|
+
/**
|
|
854
|
+
* Save the last active thread ID (for session persistence)
|
|
855
|
+
*/
|
|
856
|
+
protected saveLastActiveThread(threadId: string | null): void;
|
|
704
857
|
}
|
|
705
858
|
/**
|
|
706
|
-
*
|
|
859
|
+
* Create a ThreadManager instance
|
|
707
860
|
*/
|
|
708
|
-
declare function
|
|
861
|
+
declare function createThreadManager(config?: ThreadManagerConfig, callbacks?: ThreadManagerCallbacks): ThreadManager;
|
|
709
862
|
|
|
710
|
-
export {
|
|
863
|
+
export { type ThreadManagerState as $, type ActionParameter as A, type InternalKnowledgeBaseResult as B, type ConsoleLogOptions as C, type InternalKnowledgeBaseSearchResponse as D, type Extension as E, actionToTool as F, getDefaultModel as G, type HttpMethod as H, type IntentDetectionResult as I, DEFAULT_MODELS as J, type KnowledgeBaseProvider as K, type LLMProvider as L, ThreadManager as M, type NetworkRequestOptions as N, createThreadManager as O, type ParameterType as P, createLocalStorageAdapter as Q, localStorageAdapter as R, type ScreenshotOptions as S, type ToolType as T, createMemoryAdapter as U, noopAdapter as V, SimpleThreadManagerState as W, type ThreadManagerConfig as X, type ThreadManagerCallbacks as Y, type CreateThreadOptions as Z, type UpdateThreadOptions as _, type ScreenshotResult as a, type LoadStatus as a0, type LocalStorageAdapterConfig as a1, type ConsoleLogResult as b, type ConsoleLogEntry as c, type NetworkRequestResult as d, type NetworkRequestEntry as e, detectIntent as f, getPrimaryTool as g, hasToolSuggestions as h, generateSuggestionReason as i, createCustomDetector as j, type ConsoleLogType as k, type ToolsConfig as l, type ToolConsentRequest as m, type ToolConsentResponse as n, type CapturedContext as o, type CustomKeywords as p, type LLMConfig as q, type CloudConfig as r, type CopilotConfig as s, type ActionDefinition as t, type ActionRenderProps as u, type KnowledgeBaseConfig as v, type KnowledgeBaseResult as w, type KnowledgeBaseSearchRequest as x, type KnowledgeBaseSearchResponse as y, type InternalKnowledgeBaseConfig as z };
|