@yourgpt/copilot-sdk 2.1.5-alpha.4 → 2.1.5-alpha.6
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/{MessageTree-CSIHErPK.d.ts → MessageTree-Clhiv_k2.d.ts} +4 -3
- package/dist/{MessageTree-B0JGQOCi.d.cts → MessageTree-Dt9qfJ55.d.cts} +4 -3
- package/dist/{chunk-XUR3IOPX.cjs → chunk-2QLF7XM7.cjs} +1557 -3120
- package/dist/chunk-2QLF7XM7.cjs.map +1 -0
- package/dist/{chunk-NUXLAZOE.cjs → chunk-3ZDRX7J2.cjs} +2 -2
- package/dist/{chunk-NUXLAZOE.cjs.map → chunk-3ZDRX7J2.cjs.map} +1 -1
- package/dist/{chunk-RKGRQRZU.js → chunk-533K2Z7C.js} +4 -4
- package/dist/{chunk-RKGRQRZU.js.map → chunk-533K2Z7C.js.map} +1 -1
- package/dist/chunk-5EGBIQYS.cjs +292 -0
- package/dist/chunk-5EGBIQYS.cjs.map +1 -0
- package/dist/{chunk-3AONOZLY.js → chunk-AIVXGTWS.js} +2 -2
- package/dist/chunk-AIVXGTWS.js.map +1 -0
- package/dist/{chunk-LLM7AHMO.js → chunk-DDZLRCVX.js} +2 -2
- package/dist/{chunk-LLM7AHMO.js.map → chunk-DDZLRCVX.js.map} +1 -1
- package/dist/{chunk-FLZO2FO3.js → chunk-I2XOCFHG.js} +1558 -3071
- package/dist/chunk-I2XOCFHG.js.map +1 -0
- package/dist/{chunk-EEH3L64W.js → chunk-PSNLKMZH.js} +73 -11
- package/dist/chunk-PSNLKMZH.js.map +1 -0
- package/dist/chunk-PURFAD2P.js +2020 -0
- package/dist/chunk-PURFAD2P.js.map +1 -0
- package/dist/chunk-QTGEEBRW.cjs +2077 -0
- package/dist/chunk-QTGEEBRW.cjs.map +1 -0
- package/dist/{chunk-TPB7XED6.cjs → chunk-TPDMBDQX.cjs} +2 -2
- package/dist/chunk-TPDMBDQX.cjs.map +1 -0
- package/dist/chunk-TXQ37MAO.js +287 -0
- package/dist/chunk-TXQ37MAO.js.map +1 -0
- package/dist/{chunk-B4YDIMP3.cjs → chunk-VION33GW.cjs} +92 -30
- package/dist/chunk-VION33GW.cjs.map +1 -0
- package/dist/{chunk-MDS23G2S.cjs → chunk-Y2A6AMGO.cjs} +10 -10
- package/dist/{chunk-MDS23G2S.cjs.map → chunk-Y2A6AMGO.cjs.map} +1 -1
- package/dist/core/index.cjs +93 -93
- package/dist/core/index.d.cts +3 -3
- package/dist/core/index.d.ts +3 -3
- package/dist/core/index.js +5 -5
- package/dist/experimental/index.cjs +644 -0
- package/dist/experimental/index.cjs.map +1 -0
- package/dist/experimental/index.d.cts +924 -0
- package/dist/experimental/index.d.ts +924 -0
- package/dist/experimental/index.js +611 -0
- package/dist/experimental/index.js.map +1 -0
- package/dist/{index-D7169xuR.d.ts → index-D8zza1Q8.d.ts} +1 -1
- package/dist/{index-CzJB8Ddo.d.cts → index-DCVjTdIZ.d.cts} +1 -1
- package/dist/mcp/index.d.cts +3 -3
- package/dist/mcp/index.d.ts +3 -3
- package/dist/react/index.cjs +140 -123
- package/dist/react/index.d.cts +378 -10
- package/dist/react/index.d.ts +378 -10
- package/dist/react/index.js +7 -6
- package/dist/styles.css +45 -0
- package/dist/tools/anthropic/index.cjs +3 -3
- package/dist/tools/anthropic/index.d.cts +1 -1
- package/dist/tools/anthropic/index.d.ts +1 -1
- package/dist/tools/anthropic/index.js +2 -2
- package/dist/tools/brave/index.cjs +6 -6
- package/dist/tools/brave/index.d.cts +1 -1
- package/dist/tools/brave/index.d.ts +1 -1
- package/dist/tools/brave/index.js +3 -3
- package/dist/tools/exa/index.cjs +6 -6
- package/dist/tools/exa/index.d.cts +1 -1
- package/dist/tools/exa/index.d.ts +1 -1
- package/dist/tools/exa/index.js +3 -3
- package/dist/tools/google/index.cjs +6 -6
- package/dist/tools/google/index.d.cts +1 -1
- package/dist/tools/google/index.d.ts +1 -1
- package/dist/tools/google/index.js +4 -4
- package/dist/tools/openai/index.cjs +6 -6
- package/dist/tools/openai/index.d.cts +1 -1
- package/dist/tools/openai/index.d.ts +1 -1
- package/dist/tools/openai/index.js +3 -3
- package/dist/tools/searxng/index.cjs +6 -6
- package/dist/tools/searxng/index.d.cts +1 -1
- package/dist/tools/searxng/index.d.ts +1 -1
- package/dist/tools/searxng/index.js +3 -3
- package/dist/tools/serper/index.cjs +6 -6
- package/dist/tools/serper/index.d.cts +1 -1
- package/dist/tools/serper/index.d.ts +1 -1
- package/dist/tools/serper/index.js +3 -3
- package/dist/tools/tavily/index.cjs +6 -6
- package/dist/tools/tavily/index.d.cts +1 -1
- package/dist/tools/tavily/index.d.ts +1 -1
- package/dist/tools/tavily/index.js +3 -3
- package/dist/tools/web-search/index.cjs +7 -7
- package/dist/tools/web-search/index.d.cts +2 -2
- package/dist/tools/web-search/index.d.ts +2 -2
- package/dist/tools/web-search/index.js +4 -4
- package/dist/{tools-tmksfhUo.d.cts → tools-DcS6Aeao.d.cts} +7 -3
- package/dist/{tools-tmksfhUo.d.ts → tools-DcS6Aeao.d.ts} +7 -3
- package/dist/{types-BqwW3Baj.d.ts → types-BUYni9B8.d.ts} +1 -1
- package/dist/{types-BLw7mxtW.d.cts → types-Cvg4DUoc.d.cts} +1 -1
- package/dist/ui/index.cjs +1297 -596
- package/dist/ui/index.cjs.map +1 -1
- package/dist/ui/index.d.cts +136 -9
- package/dist/ui/index.d.ts +136 -9
- package/dist/ui/index.js +1128 -436
- package/dist/ui/index.js.map +1 -1
- package/package.json +6 -1
- package/dist/chunk-3AONOZLY.js.map +0 -1
- package/dist/chunk-B4YDIMP3.cjs.map +0 -1
- package/dist/chunk-EEH3L64W.js.map +0 -1
- package/dist/chunk-FLZO2FO3.js.map +0 -1
- package/dist/chunk-TPB7XED6.cjs.map +0 -1
- package/dist/chunk-XUR3IOPX.cjs.map +0 -1
package/dist/react/index.d.cts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { U as UIMessage, B as BranchInfo } from '../MessageTree-
|
|
3
|
-
export { M as MessageTree } from '../MessageTree-
|
|
2
|
+
import { U as UIMessage, B as BranchInfo } from '../MessageTree-Dt9qfJ55.cjs';
|
|
3
|
+
export { M as MessageTree } from '../MessageTree-Dt9qfJ55.cjs';
|
|
4
4
|
import * as React$1 from 'react';
|
|
5
5
|
import React__default from 'react';
|
|
6
6
|
import { L as LLMConfig, l as ToolsConfig, s as ActionDefinition, o as CapturedContext, m as ToolConsentRequest, T as ToolType, n as ToolConsentResponse, S as ScreenshotOptions, C as ConsoleLogOptions, N as NetworkRequestOptions, I as IntentDetectionResult, y as InternalKnowledgeBaseConfig, B as InternalKnowledgeBaseSearchResponse, z as InternalKnowledgeBaseResult, Y as ThreadManagerState, Z as LoadStatus, U as ThreadManagerConfig, F as ThreadManager, V as ThreadManagerCallbacks, W as CreateThreadOptions, X as UpdateThreadOptions } from '../ThreadManager-DK46fVl3.cjs';
|
|
7
7
|
export { A as ActionParameter, q as CloudConfig, r as CopilotConfig, _ as LocalStorageAdapterConfig, J as createLocalStorageAdapter, O as createMemoryAdapter, i as generateSuggestionReason } from '../ThreadManager-DK46fVl3.cjs';
|
|
8
|
-
import { T as ToolDefinition, t as ToolOptimizationConfig, r as ContextUsage, f as ToolSource, P as PermissionLevel, c as ToolInputSchema, y as ToolExecution$1, e as ToolContext, b as ToolResponse$1, g as ToolRenderProps, i as ToolResultConfig, D as AIResponseMode, u as ToolSet, U as UnifiedToolCall, G as PermissionStorageConfig, H as PermissionStorageAdapter } from '../tools-
|
|
9
|
-
export { z as AgentLoopConfig, q as ContextUsagePart, h as ToolConfig, a as ToolExecutionStatus, F as ToolPermission, v as ToolSetEntry, I as tool } from '../tools-
|
|
8
|
+
import { T as ToolDefinition, t as ToolOptimizationConfig, r as ContextUsage, f as ToolSource, P as PermissionLevel, c as ToolInputSchema, y as ToolExecution$1, e as ToolContext, b as ToolResponse$1, g as ToolRenderProps, i as ToolResultConfig, D as AIResponseMode, u as ToolSet, U as UnifiedToolCall, G as PermissionStorageConfig, H as PermissionStorageAdapter } from '../tools-DcS6Aeao.cjs';
|
|
9
|
+
export { z as AgentLoopConfig, q as ContextUsagePart, h as ToolConfig, a as ToolExecutionStatus, F as ToolPermission, v as ToolSetEntry, I as tool } from '../tools-DcS6Aeao.cjs';
|
|
10
10
|
import { A as AsyncThreadStorageAdapter, M as MessageAttachment, T as ToolCall, d as Message, S as Source, a as Thread, b as ThreadData, c as ThreadStorageAdapter } from '../types-waEqyE4K.cjs';
|
|
11
11
|
export { P as PersistenceConfig, j as ThreadStorageAdapter } from '../types-waEqyE4K.cjs';
|
|
12
|
-
import { G as MCPServerConfig, U as UseMCPClientConfig, D as UseMCPClientReturn, E as UseMCPToolsConfig, F as UseMCPToolsReturn } from '../types-
|
|
13
|
-
export { b as MCPClientState } from '../types-
|
|
12
|
+
import { G as MCPServerConfig, U as UseMCPClientConfig, D as UseMCPClientReturn, E as UseMCPToolsConfig, F as UseMCPToolsReturn } from '../types-Cvg4DUoc.cjs';
|
|
13
|
+
export { b as MCPClientState } from '../types-Cvg4DUoc.cjs';
|
|
14
14
|
import { S as SkillDefinition, R as ResolvedSkill } from '../types-BckL3hiw.cjs';
|
|
15
15
|
export { C as ClientInlineSkill, b as SkillSource, c as SkillStrategy } from '../types-BckL3hiw.cjs';
|
|
16
16
|
import { U as UseMCPUIIntentsConfig, m as UseMCPUIIntentsReturn } from '../types-B20VCJXL.cjs';
|
|
@@ -142,6 +142,8 @@ interface ChatResponse {
|
|
|
142
142
|
/** Tool call ID for tool result messages */
|
|
143
143
|
tool_call_id?: string;
|
|
144
144
|
}>;
|
|
145
|
+
/** Session ID — present when server storage adapter created/resolved a session */
|
|
146
|
+
threadId?: string;
|
|
145
147
|
/** Whether client needs to execute tools */
|
|
146
148
|
requiresAction?: boolean;
|
|
147
149
|
/** Tool calls with metadata (includes hidden flag for server-side tools) */
|
|
@@ -211,6 +213,8 @@ type StreamChunk = {
|
|
|
211
213
|
tool_call_id?: string;
|
|
212
214
|
}>;
|
|
213
215
|
requiresAction?: boolean;
|
|
216
|
+
/** Session ID from server storage adapter */
|
|
217
|
+
threadId?: string;
|
|
214
218
|
} | {
|
|
215
219
|
type: "action:start";
|
|
216
220
|
id: string;
|
|
@@ -427,6 +431,17 @@ interface ChatState$1<T extends UIMessage = UIMessage> {
|
|
|
427
431
|
* Chat status
|
|
428
432
|
*/
|
|
429
433
|
type ChatStatus$1 = "ready" | "submitted" | "streaming" | "error";
|
|
434
|
+
/**
|
|
435
|
+
* YourGPT configuration for automatic session management
|
|
436
|
+
*/
|
|
437
|
+
interface YourGPTConfig {
|
|
438
|
+
/** YourGPT API key (sent as api-key header) */
|
|
439
|
+
apiKey: string;
|
|
440
|
+
/** Widget UID to scope sessions to */
|
|
441
|
+
widgetUid: string;
|
|
442
|
+
/** API base URL (default: https://api.yourgpt.ai) */
|
|
443
|
+
endpoint?: string;
|
|
444
|
+
}
|
|
430
445
|
/**
|
|
431
446
|
* Chat configuration
|
|
432
447
|
*
|
|
@@ -462,6 +477,37 @@ interface ChatConfig {
|
|
|
462
477
|
body?: Resolvable<Record<string, unknown>>;
|
|
463
478
|
/** Thread ID for conversation persistence */
|
|
464
479
|
threadId?: string;
|
|
480
|
+
/**
|
|
481
|
+
* Called once before the first message on a new thread to obtain a session/thread ID.
|
|
482
|
+
* The returned value IS the thread ID — session and thread are the same identity.
|
|
483
|
+
*
|
|
484
|
+
* Only called when `config.threadId` is not set (new thread).
|
|
485
|
+
* If `threadId` is already provided, this is skipped entirely.
|
|
486
|
+
* Takes priority over `yourgptConfig` when both are provided.
|
|
487
|
+
*
|
|
488
|
+
* @example Async server session
|
|
489
|
+
* ```ts
|
|
490
|
+
* onCreateSession={async () => {
|
|
491
|
+
* const res = await fetch('/api/sessions', { method: 'POST' })
|
|
492
|
+
* return (await res.json()).id
|
|
493
|
+
* }}
|
|
494
|
+
* ```
|
|
495
|
+
*/
|
|
496
|
+
onCreateSession?: () => string | Promise<string>;
|
|
497
|
+
/**
|
|
498
|
+
* YourGPT config — enables automatic session creation with zero boilerplate.
|
|
499
|
+
* When provided, the SDK calls YourGPT's createSession API before the first
|
|
500
|
+
* message and uses the returned session_uid as `threadId`.
|
|
501
|
+
*
|
|
502
|
+
* @example
|
|
503
|
+
* ```tsx
|
|
504
|
+
* yourgptConfig={{
|
|
505
|
+
* apiKey: process.env.YOURGPT_API_KEY,
|
|
506
|
+
* widgetUid: widgetUid,
|
|
507
|
+
* }}
|
|
508
|
+
* ```
|
|
509
|
+
*/
|
|
510
|
+
yourgptConfig?: YourGPTConfig;
|
|
465
511
|
/** Enable debug logging */
|
|
466
512
|
debug?: boolean;
|
|
467
513
|
/** Available tools (passed to LLM) */
|
|
@@ -500,6 +546,17 @@ interface ChatCallbacks<T extends UIMessage = UIMessage> {
|
|
|
500
546
|
onFinish?: (messages: T[]) => void;
|
|
501
547
|
/** Called when prompt context usage changes */
|
|
502
548
|
onContextUsageChange?: (usage: ContextUsage) => void;
|
|
549
|
+
/**
|
|
550
|
+
* Called once when a new session/thread ID is assigned (null → sessionId transition).
|
|
551
|
+
* Use this to persist the session ID in your storage layer.
|
|
552
|
+
* The returned ID is the same as the threadId that will be used for all subsequent requests.
|
|
553
|
+
*/
|
|
554
|
+
onThreadChange?: (id: string) => void;
|
|
555
|
+
/**
|
|
556
|
+
* Called when the session creation status changes.
|
|
557
|
+
* Use this to show/hide a spinner while the session is being created.
|
|
558
|
+
*/
|
|
559
|
+
onSessionStatusChange?: (status: "idle" | "creating" | "ready" | "error") => void;
|
|
503
560
|
/** Called when a server-side tool starts executing (action:start event) */
|
|
504
561
|
onServerToolStart?: (info: ServerToolInfo) => void;
|
|
505
562
|
/** Called when a server-side tool receives args (action:args event) */
|
|
@@ -509,6 +566,15 @@ interface ChatCallbacks<T extends UIMessage = UIMessage> {
|
|
|
509
566
|
result?: unknown;
|
|
510
567
|
error?: string;
|
|
511
568
|
}) => void;
|
|
569
|
+
/**
|
|
570
|
+
* Called for every raw stream chunk as it arrives.
|
|
571
|
+
* Use this to build custom real-time UI on top of the SDK — e.g. thinking
|
|
572
|
+
* step parsers, tool progress trackers, loop iteration counters.
|
|
573
|
+
* The `messageId` field is the ID of the assistant message being streamed.
|
|
574
|
+
*/
|
|
575
|
+
onStreamChunk?: (chunk: StreamChunk & {
|
|
576
|
+
messageId?: string;
|
|
577
|
+
}) => void;
|
|
512
578
|
}
|
|
513
579
|
/**
|
|
514
580
|
* Chat initialization options
|
|
@@ -722,6 +788,9 @@ declare class AbstractChat<T extends UIMessage = UIMessage> {
|
|
|
722
788
|
protected callbacks: ChatCallbacks<T>;
|
|
723
789
|
protected optimizer: ChatContextOptimizer;
|
|
724
790
|
protected lastContextUsage: ContextUsage | null;
|
|
791
|
+
private onCreateSession?;
|
|
792
|
+
private sessionInitPromise;
|
|
793
|
+
private sessionStatus;
|
|
725
794
|
private eventHandlers;
|
|
726
795
|
private streamState;
|
|
727
796
|
constructor(init: ChatInit<T>);
|
|
@@ -763,6 +832,17 @@ declare class AbstractChat<T extends UIMessage = UIMessage> {
|
|
|
763
832
|
toolCallId: string;
|
|
764
833
|
result: unknown;
|
|
765
834
|
}>): Promise<void>;
|
|
835
|
+
/**
|
|
836
|
+
* Add tool result messages to history and stop — does NOT trigger a new LLM request.
|
|
837
|
+
*
|
|
838
|
+
* Use this instead of continueWithToolResults when you want to close out pending
|
|
839
|
+
* tool_use blocks (so the history stays valid) without letting the AI continue.
|
|
840
|
+
* Optionally appends a final assistant message (e.g. an iteration-limit notice).
|
|
841
|
+
*/
|
|
842
|
+
addToolResultMessages(toolResults: Array<{
|
|
843
|
+
toolCallId: string;
|
|
844
|
+
result: unknown;
|
|
845
|
+
}>, finalAssistantContent?: string): Promise<void>;
|
|
766
846
|
/**
|
|
767
847
|
* Stop generation
|
|
768
848
|
*/
|
|
@@ -804,7 +884,9 @@ declare class AbstractChat<T extends UIMessage = UIMessage> {
|
|
|
804
884
|
/**
|
|
805
885
|
* Process a chat request
|
|
806
886
|
*/
|
|
807
|
-
protected processRequest(
|
|
887
|
+
protected processRequest(options?: {
|
|
888
|
+
preCreatedMessageId?: string;
|
|
889
|
+
}): Promise<void>;
|
|
808
890
|
/**
|
|
809
891
|
* Set tools available for the LLM
|
|
810
892
|
*/
|
|
@@ -858,6 +940,27 @@ declare class AbstractChat<T extends UIMessage = UIMessage> {
|
|
|
858
940
|
* Set dynamic context (appended to system prompt)
|
|
859
941
|
*/
|
|
860
942
|
setContext(context: string): void;
|
|
943
|
+
/**
|
|
944
|
+
* Switch to a different thread (or start a new one).
|
|
945
|
+
*
|
|
946
|
+
* - Pass the session/thread ID from persistence → used as-is, no session creation call.
|
|
947
|
+
* - Pass null → threadId cleared, new session created on first sendMessage.
|
|
948
|
+
*
|
|
949
|
+
* The session ID IS the thread ID: whatever is stored in persistence is passed here directly.
|
|
950
|
+
*/
|
|
951
|
+
setActiveThread(id: string | null): void;
|
|
952
|
+
/**
|
|
953
|
+
* Force a new session to be created on the next sendMessage.
|
|
954
|
+
* Call this when the current session has expired or credits are exhausted.
|
|
955
|
+
* After calling this, the next sendMessage will invoke onCreateSession/yourgptConfig
|
|
956
|
+
* again and onThreadChange will fire with the new session ID.
|
|
957
|
+
*/
|
|
958
|
+
renewSession(): void;
|
|
959
|
+
private setSessionStatus;
|
|
960
|
+
/**
|
|
961
|
+
* Get the current session creation status.
|
|
962
|
+
*/
|
|
963
|
+
getSessionStatus(): "idle" | "creating" | "ready" | "error";
|
|
861
964
|
/**
|
|
862
965
|
* Set system prompt dynamically
|
|
863
966
|
* This allows updating the system prompt after initialization
|
|
@@ -878,9 +981,17 @@ declare class AbstractChat<T extends UIMessage = UIMessage> {
|
|
|
878
981
|
* Additional properties merged into every request body
|
|
879
982
|
*/
|
|
880
983
|
setBody(body: ChatConfig["body"]): void;
|
|
984
|
+
/**
|
|
985
|
+
* Default session creation via yourgptConfig.
|
|
986
|
+
* Only called when yourgptConfig is set and no onCreateSession is provided.
|
|
987
|
+
* The returned session_uid IS the thread ID going forward.
|
|
988
|
+
*/
|
|
989
|
+
private _defaultCreateSession;
|
|
881
990
|
/**
|
|
882
991
|
* Build the request payload
|
|
883
992
|
*/
|
|
993
|
+
/** Inline text-file attachments into message content for the LLM */
|
|
994
|
+
private inlineTextAttachments;
|
|
884
995
|
protected buildRequest(): {
|
|
885
996
|
messages: {
|
|
886
997
|
role: string;
|
|
@@ -1315,8 +1426,39 @@ interface CopilotProviderProps {
|
|
|
1315
1426
|
tools?: ToolsConfig;
|
|
1316
1427
|
/** Thread ID for conversation persistence */
|
|
1317
1428
|
threadId?: string;
|
|
1429
|
+
/**
|
|
1430
|
+
* Called once before the first message on a new thread to create a session.
|
|
1431
|
+
* The returned value IS the thread ID — session and thread are the same identity.
|
|
1432
|
+
* Only called when `threadId` is not set. If `threadId` is provided, this is skipped.
|
|
1433
|
+
* Takes priority over `yourgptConfig`.
|
|
1434
|
+
*
|
|
1435
|
+
* @example
|
|
1436
|
+
* ```tsx
|
|
1437
|
+
* onCreateSession={async () => {
|
|
1438
|
+
* const res = await fetch('/api/sessions', { method: 'POST', headers })
|
|
1439
|
+
* return (await res.json()).id
|
|
1440
|
+
* }}
|
|
1441
|
+
* ```
|
|
1442
|
+
*/
|
|
1443
|
+
onCreateSession?: () => string | Promise<string>;
|
|
1444
|
+
/**
|
|
1445
|
+
* Called when a new session/thread ID is assigned (new thread created).
|
|
1446
|
+
* Use this to persist the session ID in your storage layer.
|
|
1447
|
+
*/
|
|
1448
|
+
onThreadChange?: (id: string) => void;
|
|
1449
|
+
/**
|
|
1450
|
+
* YourGPT config — enables automatic session creation with zero boilerplate.
|
|
1451
|
+
* The SDK calls YourGPT's createSession API before the first message and
|
|
1452
|
+
* uses the returned session_uid as `threadId`.
|
|
1453
|
+
*
|
|
1454
|
+
* @example
|
|
1455
|
+
* ```tsx
|
|
1456
|
+
* yourgptConfig={{ apiKey: "your-api-key", widgetUid: widgetUid }}
|
|
1457
|
+
* ```
|
|
1458
|
+
*/
|
|
1459
|
+
yourgptConfig?: YourGPTConfig;
|
|
1318
1460
|
/** Initial messages to populate the chat */
|
|
1319
|
-
initialMessages?:
|
|
1461
|
+
initialMessages?: UIMessage[];
|
|
1320
1462
|
/** Callback when messages change */
|
|
1321
1463
|
onMessagesChange?: (messages: Message[]) => void;
|
|
1322
1464
|
/** Callback when an error occurs */
|
|
@@ -1356,6 +1498,26 @@ interface CopilotProviderProps {
|
|
|
1356
1498
|
*/
|
|
1357
1499
|
skills?: SkillDefinition[];
|
|
1358
1500
|
}
|
|
1501
|
+
type StreamChunkWithMessageId = StreamChunk & {
|
|
1502
|
+
messageId?: string;
|
|
1503
|
+
};
|
|
1504
|
+
type StreamEventHandler = (chunk: StreamChunkWithMessageId) => void;
|
|
1505
|
+
/**
|
|
1506
|
+
* Reactive store for custom per-message metadata.
|
|
1507
|
+
* Powers useMessageMeta() — consumers write any shape they want,
|
|
1508
|
+
* all components reading the same messageId react automatically.
|
|
1509
|
+
*/
|
|
1510
|
+
declare class MessageMetaStore {
|
|
1511
|
+
private store;
|
|
1512
|
+
private listeners;
|
|
1513
|
+
private static readonly EMPTY;
|
|
1514
|
+
subscribe: (cb: () => void) => (() => void);
|
|
1515
|
+
getSnapshot: () => Map<string, Record<string, unknown>>;
|
|
1516
|
+
getMeta: (messageId: string) => Record<string, unknown>;
|
|
1517
|
+
setMeta: (messageId: string, meta: Record<string, unknown>) => void;
|
|
1518
|
+
updateMeta: (messageId: string, updater: (prev: Record<string, unknown>) => Record<string, unknown>) => void;
|
|
1519
|
+
clear: () => void;
|
|
1520
|
+
}
|
|
1359
1521
|
interface CopilotContextValue {
|
|
1360
1522
|
messages: UIMessage[];
|
|
1361
1523
|
status: "ready" | "submitted" | "streaming" | "error";
|
|
@@ -1399,16 +1561,48 @@ interface CopilotContextValue {
|
|
|
1399
1561
|
content: string;
|
|
1400
1562
|
strategy?: string;
|
|
1401
1563
|
}>) => void;
|
|
1564
|
+
agentIteration: number;
|
|
1402
1565
|
threadId?: string;
|
|
1566
|
+
/**
|
|
1567
|
+
* Switch to a different thread (or start a new one).
|
|
1568
|
+
* Pass the session/thread ID from persistence to reuse it (no new session call),
|
|
1569
|
+
* or null to start a fresh thread (new session created on first sendMessage).
|
|
1570
|
+
*/
|
|
1571
|
+
setActiveThread: (id: string | null) => void;
|
|
1572
|
+
/**
|
|
1573
|
+
* Force a new session to be created on the next sendMessage.
|
|
1574
|
+
* Call when the current session has expired or credits are exhausted.
|
|
1575
|
+
*/
|
|
1576
|
+
renewSession: () => void;
|
|
1577
|
+
/** Current session creation status */
|
|
1578
|
+
sessionStatus: "idle" | "creating" | "ready" | "error";
|
|
1403
1579
|
/**
|
|
1404
1580
|
* Runtime URL configuration.
|
|
1405
1581
|
* Can be a static string or getter function (matches what was passed to provider).
|
|
1406
1582
|
*/
|
|
1407
1583
|
runtimeUrl: Resolvable<string>;
|
|
1408
1584
|
toolsConfig?: ToolsConfig;
|
|
1585
|
+
/**
|
|
1586
|
+
* Subscribe to raw stream chunks as they arrive.
|
|
1587
|
+
* Returns an unsubscribe function. Use useCopilotEvent() for the hook API.
|
|
1588
|
+
*
|
|
1589
|
+
* @example
|
|
1590
|
+
* ```ts
|
|
1591
|
+
* const unsub = subscribeToStreamEvents((chunk) => {
|
|
1592
|
+
* if (chunk.type === 'thinking:delta') { ... }
|
|
1593
|
+
* })
|
|
1594
|
+
* return unsub // cleanup
|
|
1595
|
+
* ```
|
|
1596
|
+
*/
|
|
1597
|
+
subscribeToStreamEvents: (handler: StreamEventHandler) => () => void;
|
|
1598
|
+
/**
|
|
1599
|
+
* Reactive per-message metadata store.
|
|
1600
|
+
* Use useMessageMeta(messageId) for the hook API.
|
|
1601
|
+
*/
|
|
1602
|
+
messageMeta: MessageMetaStore;
|
|
1409
1603
|
}
|
|
1410
1604
|
declare function useCopilot(): CopilotContextValue;
|
|
1411
|
-
declare function CopilotProvider(
|
|
1605
|
+
declare function CopilotProvider(props: CopilotProviderProps): react_jsx_runtime.JSX.Element;
|
|
1412
1606
|
|
|
1413
1607
|
/**
|
|
1414
1608
|
* Chat UI state interface (UI-only state, not message data)
|
|
@@ -2661,6 +2855,71 @@ interface UseThreadManagerReturn {
|
|
|
2661
2855
|
*/
|
|
2662
2856
|
declare function useThreadManager(config?: UseThreadManagerConfig): UseThreadManagerReturn;
|
|
2663
2857
|
|
|
2858
|
+
/**
|
|
2859
|
+
* useThread — Session/thread management hook
|
|
2860
|
+
*
|
|
2861
|
+
* Provides clean semantics for managing the active session/thread.
|
|
2862
|
+
* When yourgptConfig or onCreateSession is configured, the session ID
|
|
2863
|
+
* IS the thread ID — they are the same identity.
|
|
2864
|
+
*
|
|
2865
|
+
* Use this hook instead of calling setActiveThread/renewSession directly.
|
|
2866
|
+
*/
|
|
2867
|
+
interface UseThreadReturn {
|
|
2868
|
+
/**
|
|
2869
|
+
* Current session/thread ID.
|
|
2870
|
+
* undefined until the first session is created (new thread not yet sent).
|
|
2871
|
+
*/
|
|
2872
|
+
threadId: string | undefined;
|
|
2873
|
+
/**
|
|
2874
|
+
* Current session creation status.
|
|
2875
|
+
* - "idle" — no session config, or threadId already set
|
|
2876
|
+
* - "creating" — session creation request in flight
|
|
2877
|
+
* - "ready" — threadId is set and usable
|
|
2878
|
+
* - "error" — session creation failed
|
|
2879
|
+
*/
|
|
2880
|
+
sessionStatus: "idle" | "creating" | "ready" | "error";
|
|
2881
|
+
/**
|
|
2882
|
+
* Switch to an existing thread/session.
|
|
2883
|
+
* Pass the session ID from your persistence layer — it is used as-is,
|
|
2884
|
+
* no new session creation call is made.
|
|
2885
|
+
*/
|
|
2886
|
+
switchThread: (sessionId: string) => void;
|
|
2887
|
+
/**
|
|
2888
|
+
* Start a fresh thread.
|
|
2889
|
+
* Clears the current session; a new session is created on the next sendMessage.
|
|
2890
|
+
* onThreadChange fires with the new session ID once it is assigned.
|
|
2891
|
+
*/
|
|
2892
|
+
newThread: () => void;
|
|
2893
|
+
/**
|
|
2894
|
+
* Force a new session to be created on the next sendMessage.
|
|
2895
|
+
* Call this when the current session has expired or credits are exhausted.
|
|
2896
|
+
* onThreadChange fires with the new session ID once it is assigned.
|
|
2897
|
+
*/
|
|
2898
|
+
renewSession: () => void;
|
|
2899
|
+
}
|
|
2900
|
+
/**
|
|
2901
|
+
* useThread — Clean hook for session/thread management
|
|
2902
|
+
*
|
|
2903
|
+
* @example
|
|
2904
|
+
* ```tsx
|
|
2905
|
+
* function ChatHeader() {
|
|
2906
|
+
* const { threadId, sessionStatus, newThread, switchThread, renewSession } = useThread();
|
|
2907
|
+
*
|
|
2908
|
+
* const loadThread = (stored: { sessionId: string }) => {
|
|
2909
|
+
* switchThread(stored.sessionId); // session ID IS the thread ID
|
|
2910
|
+
* };
|
|
2911
|
+
*
|
|
2912
|
+
* return (
|
|
2913
|
+
* <>
|
|
2914
|
+
* {sessionStatus === "creating" && <Spinner />}
|
|
2915
|
+
* <button onClick={newThread}>New Chat</button>
|
|
2916
|
+
* </>
|
|
2917
|
+
* );
|
|
2918
|
+
* }
|
|
2919
|
+
* ```
|
|
2920
|
+
*/
|
|
2921
|
+
declare function useThread(): UseThreadReturn;
|
|
2922
|
+
|
|
2664
2923
|
/**
|
|
2665
2924
|
* React hook for managing an MCP client connection
|
|
2666
2925
|
*
|
|
@@ -2892,6 +3151,72 @@ interface UseSkillStatusReturn {
|
|
|
2892
3151
|
}
|
|
2893
3152
|
declare function useSkillStatus(): UseSkillStatusReturn;
|
|
2894
3153
|
|
|
3154
|
+
interface MessageCheckpoint {
|
|
3155
|
+
/** Unique checkpoint ID */
|
|
3156
|
+
id: string;
|
|
3157
|
+
/** ID of the user message that triggered this checkpoint */
|
|
3158
|
+
messageId: string;
|
|
3159
|
+
/** When this checkpoint was created */
|
|
3160
|
+
timestamp: number;
|
|
3161
|
+
/** Optional human-readable label */
|
|
3162
|
+
label?: string;
|
|
3163
|
+
/** Full message list BEFORE the user message was processed */
|
|
3164
|
+
messages: UIMessage[];
|
|
3165
|
+
}
|
|
3166
|
+
interface UseMessageCheckpointsReturn {
|
|
3167
|
+
/** All saved checkpoints, oldest first */
|
|
3168
|
+
checkpoints: MessageCheckpoint[];
|
|
3169
|
+
/** True if a checkpoint exists for the given user message ID */
|
|
3170
|
+
hasCheckpoint: (messageId: string) => boolean;
|
|
3171
|
+
/** Get the checkpoint for a user message ID, or undefined */
|
|
3172
|
+
getCheckpoint: (messageId: string) => MessageCheckpoint | undefined;
|
|
3173
|
+
/**
|
|
3174
|
+
* Restore chat to the state before the user message with the given ID.
|
|
3175
|
+
* Returns the checkpoint if found, undefined otherwise.
|
|
3176
|
+
* Checkpoints created after this one are pruned.
|
|
3177
|
+
*/
|
|
3178
|
+
restore: (messageId: string) => MessageCheckpoint | undefined;
|
|
3179
|
+
/**
|
|
3180
|
+
* Manually save a checkpoint for a message ID.
|
|
3181
|
+
* Auto-save already runs on every new user message — use this for
|
|
3182
|
+
* programmatic checkpoints (e.g. before a destructive tool call).
|
|
3183
|
+
*/
|
|
3184
|
+
save: (messageId: string, label?: string) => MessageCheckpoint | undefined;
|
|
3185
|
+
/** Clear all saved checkpoints */
|
|
3186
|
+
clear: () => void;
|
|
3187
|
+
}
|
|
3188
|
+
/**
|
|
3189
|
+
* useMessageCheckpoints
|
|
3190
|
+
*
|
|
3191
|
+
* Automatically saves a checkpoint before each user message is sent to the
|
|
3192
|
+
* agent. Each checkpoint captures the full chat state that existed BEFORE
|
|
3193
|
+
* that user message, so restoring it rolls the conversation back to exactly
|
|
3194
|
+
* that point.
|
|
3195
|
+
*
|
|
3196
|
+
* Generic — works for any agentic app (flow builders, code editors, document
|
|
3197
|
+
* assistants, etc.). App-specific side effects (e.g. restoring a canvas or
|
|
3198
|
+
* database state) can be layered on top via the returned `restore` value.
|
|
3199
|
+
*
|
|
3200
|
+
* @example
|
|
3201
|
+
* ```tsx
|
|
3202
|
+
* // Inside <CopilotChat> children
|
|
3203
|
+
* function MyCheckpointActions() {
|
|
3204
|
+
* const { hasCheckpoint, restore } = useMessageCheckpoints();
|
|
3205
|
+
* return (
|
|
3206
|
+
* <CopilotChat.MessageActions role="user">
|
|
3207
|
+
* <CopilotChat.Action
|
|
3208
|
+
* icon={<RotateCcw className="size-3.5" />}
|
|
3209
|
+
* tooltip="Restore to before this message"
|
|
3210
|
+
* onClick={({ message }) => restore(message.id)}
|
|
3211
|
+
* hidden={({ message }) => !hasCheckpoint(message.id)}
|
|
3212
|
+
* />
|
|
3213
|
+
* </CopilotChat.MessageActions>
|
|
3214
|
+
* );
|
|
3215
|
+
* }
|
|
3216
|
+
* ```
|
|
3217
|
+
*/
|
|
3218
|
+
declare function useMessageCheckpoints(): UseMessageCheckpointsReturn;
|
|
3219
|
+
|
|
2895
3220
|
/**
|
|
2896
3221
|
* Create a permission storage adapter based on config
|
|
2897
3222
|
*/
|
|
@@ -3032,6 +3357,10 @@ interface ReactChatConfig {
|
|
|
3032
3357
|
llm?: ChatConfig["llm"];
|
|
3033
3358
|
/** Thread ID */
|
|
3034
3359
|
threadId?: string;
|
|
3360
|
+
/** Called once before first message to obtain a session/thread ID */
|
|
3361
|
+
onCreateSession?: () => string | Promise<string>;
|
|
3362
|
+
/** YourGPT config — enables automatic session creation */
|
|
3363
|
+
yourgptConfig?: YourGPTConfig;
|
|
3035
3364
|
/** Enable streaming (default: true) */
|
|
3036
3365
|
streaming?: boolean;
|
|
3037
3366
|
/** Request headers */
|
|
@@ -3306,4 +3635,43 @@ declare function toLLMMessages(messages: DisplayMessage[]): LLMMessage[];
|
|
|
3306
3635
|
declare function keepToolPairsAtomic(messages: DisplayMessage[]): DisplayMessage[];
|
|
3307
3636
|
declare function isCompactionMarker(msg: DisplayMessage): msg is CompactionMarker;
|
|
3308
3637
|
|
|
3309
|
-
|
|
3638
|
+
type StreamChunkType = StreamChunk["type"];
|
|
3639
|
+
type ChunkOfType<T extends StreamChunkType | "*"> = T extends "*" ? StreamChunkWithMessageId : Extract<StreamChunk, {
|
|
3640
|
+
type: T;
|
|
3641
|
+
}> & {
|
|
3642
|
+
messageId?: string;
|
|
3643
|
+
};
|
|
3644
|
+
/**
|
|
3645
|
+
* Subscribe to a specific stream event type (or all events with '*').
|
|
3646
|
+
*
|
|
3647
|
+
* The handler is called synchronously during streaming — keep it fast.
|
|
3648
|
+
* Handler identity doesn't need to be stable; the hook re-subscribes
|
|
3649
|
+
* automatically when it changes.
|
|
3650
|
+
*
|
|
3651
|
+
* @param eventType - Stream chunk type to listen for, or '*' for all
|
|
3652
|
+
* @param handler - Callback invoked for each matching chunk
|
|
3653
|
+
*/
|
|
3654
|
+
declare function useCopilotEvent<T extends StreamChunkType | "*">(eventType: T, handler: (chunk: ChunkOfType<T>) => void): void;
|
|
3655
|
+
|
|
3656
|
+
interface UseMessageMetaReturn<T extends Record<string, unknown>> {
|
|
3657
|
+
/** Current metadata for this message. Empty object if nothing set yet. */
|
|
3658
|
+
meta: T;
|
|
3659
|
+
/**
|
|
3660
|
+
* Replace metadata entirely.
|
|
3661
|
+
*/
|
|
3662
|
+
setMeta: (meta: T) => void;
|
|
3663
|
+
/**
|
|
3664
|
+
* Merge/update metadata using an updater function.
|
|
3665
|
+
* Receives previous meta, return next meta.
|
|
3666
|
+
*/
|
|
3667
|
+
updateMeta: (updater: (prev: T) => T) => void;
|
|
3668
|
+
}
|
|
3669
|
+
/**
|
|
3670
|
+
* Read and write custom metadata for a specific message ID.
|
|
3671
|
+
*
|
|
3672
|
+
* @param messageId - The message to attach metadata to.
|
|
3673
|
+
* Pass undefined to get a no-op instance (safe for conditional use).
|
|
3674
|
+
*/
|
|
3675
|
+
declare function useMessageMeta<T extends Record<string, unknown> = Record<string, unknown>>(messageId: string | undefined): UseMessageMetaReturn<T>;
|
|
3676
|
+
|
|
3677
|
+
export { type AIContextItem, AbstractAgentLoop, AbstractChat, ActionDefinition, type AgentLoopActions, type AgentLoopCallbacks, type AgentLoopState, AsyncThreadStorageAdapter, BranchInfo, type CapabilitiesResponse, CapturedContext, type ChatActions, type ChatCallbacks, type ChatConfig, type ChatState, type ChatStatus, type ToolExecution as ChatToolExecution, type ToolResponse as ChatToolResponse, type CombinedChatState, type CompactedToolResult, type CompactionEvent, type CompactionMarker, type CompactionStrategy, type ContextStats, ContextUsage, type CopilotContextValue, CopilotProvider, type CopilotProviderProps, type AgentLoopState$1 as CoreAgentLoopState, type ChatState$1 as CoreChatState, type DevLoggerState, type DisplayMessage, IntentDetectionResult, type KnowledgeBaseConfig, type KnowledgeBaseResult, type KnowledgeBaseSearchResponse, LLMConfig, type LLMMessage, Message, type MessageCheckpoint, type MessageHistoryConfig, MessageHistoryContext, type MessageHistoryContextValue, MessageMetaStore, type MessageTokenUsage, PermissionLevel, PermissionStorageAdapter, PermissionStorageConfig, type ProviderCapabilities, ReactChat, type ReactChatConfig, ReactChatState, ReactThreadManager, type ReactThreadManagerConfig, ReactThreadManagerState, ResolvedSkill, type ServerAdapterConfig, type SessionCompactionState, SkillDefinition, SkillProvider, type SkillProviderProps, Source, type StreamChunkWithMessageId, type StreamEventHandler, type Suggestion, Thread, ThreadData, type TokenUsage, ToolConsentRequest, ToolConsentResponse, ToolContext, ToolDefinition, ToolExecution$1 as ToolExecution, ToolResponse$1 as ToolResponse, ToolSet, ToolType, type ToolsActions, ToolsConfig, type ToolsState, UIMessage, UnifiedToolCall, type UseAIToolsOptions, type UseAIToolsReturn, type UseAgentOptions, type UseAgentReturn, type UseChatConfig, type UseChatReturn, type UseKnowledgeBaseConfig, UseMCPClientConfig, UseMCPClientReturn, UseMCPToolsConfig, UseMCPToolsReturn, UseMCPUIIntentsConfig, UseMCPUIIntentsReturn, type UseMessageCheckpointsReturn, type UseMessageHistoryOptions, type UseMessageHistoryReturn, type UseMessageMetaReturn, type UseSkillStatusReturn, type UseSuggestionsOptions, type UseSuggestionsReturn, type UseThreadManagerConfig, type UseThreadManagerReturn, type UseThreadReturn, type UseToolConfig, type UseToolExecutorReturn, type UseToolWithSchemaConfig, createMessageIntentHandler, createPermissionStorage, createReactChat, createReactChatState, createReactThreadManager, createReactThreadManagerState, createServerAdapter, createSessionPermissionCache, createToolIntentHandler, defaultMessageHistoryConfig, defineSkill, formatKnowledgeResultsForAI, initialAgentLoopState, isCompactionMarker, keepToolPairsAtomic, searchKnowledgeBase, toDisplayMessage, toLLMMessage, toLLMMessages, useAIAction, useAIActions, useAIContext, useAIContexts, useAITools, useAgent, useCapabilities, useChat, useContextStats, useCopilot, useCopilotEvent, useDevLogger, useFeatureSupport, useKnowledgeBase, useMCPClient, useMCPTools, useMCPUIIntents, useMessageCheckpoints, useMessageHistory, useMessageHistoryContext, useMessageMeta, useSkill, useSkillStatus, useSuggestions, useSupportedMediaTypes, useThread, useThreadManager, useTool, useToolExecutor, useToolWithSchema, useTools, useToolsWithSchema };
|