@yourgpt/copilot-sdk 2.1.4 → 2.1.5-alpha.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/dist/MessageTree-CoIt_4nB.d.cts +161 -0
- package/dist/MessageTree-CzaN9Eul.d.ts +161 -0
- package/dist/{ThreadManager-Dkp_eLty.d.ts → ThreadManager-BEAECB7Y.d.ts} +1 -1
- package/dist/{ThreadManager-LfFRhr4e.d.cts → ThreadManager-Cw5fwyCN.d.cts} +1 -1
- package/dist/{chunk-POZNNKNJ.cjs → chunk-246B6X5D.cjs} +8 -2
- package/dist/chunk-246B6X5D.cjs.map +1 -0
- package/dist/{chunk-QLH6TSCC.js → chunk-4QXY2PBG.js} +8 -2
- package/dist/chunk-4QXY2PBG.js.map +1 -0
- package/dist/{chunk-7PKGRYHY.js → chunk-6BMQZIS3.js} +3094 -355
- package/dist/chunk-6BMQZIS3.js.map +1 -0
- package/dist/{chunk-N6VZ7FOW.cjs → chunk-76RE7AJE.cjs} +3277 -520
- package/dist/chunk-76RE7AJE.cjs.map +1 -0
- package/dist/chunk-BJYA5NDL.cjs +96 -0
- package/dist/chunk-BJYA5NDL.cjs.map +1 -0
- package/dist/{chunk-LZMBBGWH.js → chunk-ENFWM3EY.js} +4 -4
- package/dist/{chunk-LZMBBGWH.js.map → chunk-ENFWM3EY.js.map} +1 -1
- package/dist/{chunk-OQPRIB73.cjs → chunk-I3SQUNTT.cjs} +71 -25
- package/dist/chunk-I3SQUNTT.cjs.map +1 -0
- package/dist/{chunk-WAPGTQDR.cjs → chunk-JKGFQUHJ.cjs} +10 -10
- package/dist/{chunk-WAPGTQDR.cjs.map → chunk-JKGFQUHJ.cjs.map} +1 -1
- package/dist/{chunk-XGITAEXU.js → chunk-LLM7AHMO.js} +2 -2
- package/dist/{chunk-XGITAEXU.js.map → chunk-LLM7AHMO.js.map} +1 -1
- package/dist/{chunk-ASV6JLYG.cjs → chunk-NUXLAZOE.cjs} +2 -2
- package/dist/{chunk-ASV6JLYG.cjs.map → chunk-NUXLAZOE.cjs.map} +1 -1
- package/dist/{chunk-37KEHUCE.js → chunk-UXJ6LIZB.js} +51 -7
- package/dist/chunk-UXJ6LIZB.js.map +1 -0
- package/dist/chunk-VNLLW3ZI.js +94 -0
- package/dist/chunk-VNLLW3ZI.js.map +1 -0
- package/dist/core/index.cjs +99 -91
- package/dist/core/index.d.cts +7 -7
- package/dist/core/index.d.ts +7 -7
- package/dist/core/index.js +5 -5
- package/dist/{index-BHkRA0mM.d.cts → index-CiExk87c.d.cts} +1 -1
- package/dist/{index-tB0qI8my.d.ts → index-Dwrcf-CP.d.ts} +1 -1
- package/dist/mcp/index.d.cts +3 -3
- package/dist/mcp/index.d.ts +3 -3
- package/dist/react/index.cjs +113 -52
- package/dist/react/index.d.cts +673 -77
- package/dist/react/index.d.ts +673 -77
- package/dist/react/index.js +7 -6
- package/dist/server/index.cjs +339 -0
- package/dist/server/index.cjs.map +1 -0
- package/dist/server/index.d.cts +171 -0
- package/dist/server/index.d.ts +171 -0
- package/dist/server/index.js +332 -0
- package/dist/server/index.js.map +1 -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 +3 -3
- 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 +3 -3
- 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-coIcskZ4.d.ts → tools-DHZhF5km.d.cts} +161 -1
- package/dist/{tools-coIcskZ4.d.cts → tools-DHZhF5km.d.ts} +161 -1
- package/dist/{types-rjaSVmEF.d.ts → types-BTyJu0WD.d.ts} +1 -1
- package/dist/types-BckL3hiw.d.cts +93 -0
- package/dist/types-BckL3hiw.d.ts +93 -0
- package/dist/{types-C8t4Ut8f.d.cts → types-BdX7uPj0.d.cts} +1 -1
- package/dist/{types-DG2ya08y.d.ts → types-BeFBBZ5i.d.cts} +64 -1
- package/dist/{types-DG2ya08y.d.cts → types-BeFBBZ5i.d.ts} +64 -1
- package/dist/ui/index.cjs +468 -163
- package/dist/ui/index.cjs.map +1 -1
- package/dist/ui/index.d.cts +81 -4
- package/dist/ui/index.d.ts +81 -4
- package/dist/ui/index.js +416 -112
- package/dist/ui/index.js.map +1 -1
- package/package.json +6 -1
- package/dist/chunk-37KEHUCE.js.map +0 -1
- package/dist/chunk-7PKGRYHY.js.map +0 -1
- package/dist/chunk-N6VZ7FOW.cjs.map +0 -1
- package/dist/chunk-OQPRIB73.cjs.map +0 -1
- package/dist/chunk-POZNNKNJ.cjs.map +0 -1
- package/dist/chunk-QLH6TSCC.js.map +0 -1
package/dist/react/index.d.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { U as UIMessage, B as BranchInfo } from '../MessageTree-CzaN9Eul.js';
|
|
3
|
+
export { M as MessageTree } from '../MessageTree-CzaN9Eul.js';
|
|
4
|
+
import * as React$1 from 'react';
|
|
2
5
|
import React__default from 'react';
|
|
3
|
-
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-
|
|
4
|
-
export { A as ActionParameter, q as CloudConfig, r as CopilotConfig, _ as LocalStorageAdapterConfig, J as createLocalStorageAdapter, O as createMemoryAdapter, i as generateSuggestionReason } from '../ThreadManager-
|
|
5
|
-
import { T as ToolDefinition, f as ToolSource, P as PermissionLevel, c as ToolInputSchema,
|
|
6
|
-
export {
|
|
7
|
-
import { A as AsyncThreadStorageAdapter,
|
|
8
|
-
export { P as PersistenceConfig,
|
|
9
|
-
import { G as MCPServerConfig, U as UseMCPClientConfig, D as UseMCPClientReturn, E as UseMCPToolsConfig, F as UseMCPToolsReturn } from '../types-
|
|
10
|
-
export { b as MCPClientState } from '../types-
|
|
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-BEAECB7Y.js';
|
|
7
|
+
export { A as ActionParameter, q as CloudConfig, r as CopilotConfig, _ as LocalStorageAdapterConfig, J as createLocalStorageAdapter, O as createMemoryAdapter, i as generateSuggestionReason } from '../ThreadManager-BEAECB7Y.js';
|
|
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-DHZhF5km.js';
|
|
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-DHZhF5km.js';
|
|
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-BeFBBZ5i.js';
|
|
11
|
+
export { P as PersistenceConfig, j as ThreadStorageAdapter } from '../types-BeFBBZ5i.js';
|
|
12
|
+
import { G as MCPServerConfig, U as UseMCPClientConfig, D as UseMCPClientReturn, E as UseMCPToolsConfig, F as UseMCPToolsReturn } from '../types-BTyJu0WD.js';
|
|
13
|
+
export { b as MCPClientState } from '../types-BTyJu0WD.js';
|
|
14
|
+
import { S as SkillDefinition, R as ResolvedSkill } from '../types-BckL3hiw.js';
|
|
15
|
+
export { C as ClientInlineSkill, b as SkillSource, c as SkillStrategy } from '../types-BckL3hiw.js';
|
|
11
16
|
import { U as UseMCPUIIntentsConfig, m as UseMCPUIIntentsReturn } from '../types-B20VCJXL.js';
|
|
12
17
|
|
|
13
18
|
/**
|
|
@@ -114,6 +119,16 @@ interface ChatRequest {
|
|
|
114
119
|
actions?: unknown[];
|
|
115
120
|
/** Additional body properties */
|
|
116
121
|
body?: Record<string, unknown>;
|
|
122
|
+
/**
|
|
123
|
+
* Inline client skills to send to the server for merging with server-side skills.
|
|
124
|
+
* Set by AbstractChat when useSkill() hooks are active.
|
|
125
|
+
*/
|
|
126
|
+
__skills?: Array<{
|
|
127
|
+
name: string;
|
|
128
|
+
description: string;
|
|
129
|
+
content: string;
|
|
130
|
+
strategy?: string;
|
|
131
|
+
}>;
|
|
117
132
|
}
|
|
118
133
|
/**
|
|
119
134
|
* Chat response (non-streaming)
|
|
@@ -283,46 +298,6 @@ interface ChatTransport {
|
|
|
283
298
|
setBody?(body: Resolvable<Record<string, unknown>>): void;
|
|
284
299
|
}
|
|
285
300
|
|
|
286
|
-
/**
|
|
287
|
-
* Message Types
|
|
288
|
-
*
|
|
289
|
-
* Pure type definitions for chat messages.
|
|
290
|
-
* No logic, no side effects - just types.
|
|
291
|
-
*/
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* Chat message roles
|
|
295
|
-
*/
|
|
296
|
-
type MessageRole = "user" | "assistant" | "system" | "tool";
|
|
297
|
-
/**
|
|
298
|
-
* UIMessage - The source of truth for UI state
|
|
299
|
-
*
|
|
300
|
-
* Inspired by Vercel AI SDK's UIMessage pattern.
|
|
301
|
-
* This is what your UI renders and what gets persisted.
|
|
302
|
-
*/
|
|
303
|
-
interface UIMessage {
|
|
304
|
-
/** Unique message ID */
|
|
305
|
-
id: string;
|
|
306
|
-
/** Message role */
|
|
307
|
-
role: MessageRole;
|
|
308
|
-
/** Message content */
|
|
309
|
-
content: string;
|
|
310
|
-
/** Thinking/reasoning content (for extended thinking models) */
|
|
311
|
-
thinking?: string;
|
|
312
|
-
/** Message attachments (images, PDFs, etc) */
|
|
313
|
-
attachments?: MessageAttachment[];
|
|
314
|
-
/** Tool calls made by assistant */
|
|
315
|
-
toolCalls?: ToolCall[];
|
|
316
|
-
/** Tool call ID (for tool result messages) */
|
|
317
|
-
toolCallId?: string;
|
|
318
|
-
/** Sources from knowledge base */
|
|
319
|
-
sources?: Source[];
|
|
320
|
-
/** Creation timestamp */
|
|
321
|
-
createdAt: Date;
|
|
322
|
-
/** Additional metadata */
|
|
323
|
-
metadata?: Record<string, unknown>;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
301
|
/**
|
|
327
302
|
* ChatState Interface
|
|
328
303
|
*
|
|
@@ -422,6 +397,30 @@ interface ChatState$1<T extends UIMessage = UIMessage> {
|
|
|
422
397
|
* Get error snapshot
|
|
423
398
|
*/
|
|
424
399
|
getErrorSnapshot?(): Error | undefined;
|
|
400
|
+
/**
|
|
401
|
+
* Set the current leaf message ID.
|
|
402
|
+
* Used by regenerate() to rewind the active path before pushing a new response.
|
|
403
|
+
*/
|
|
404
|
+
setCurrentLeaf?(leafId: string | null): void;
|
|
405
|
+
/**
|
|
406
|
+
* Get all messages across all branches (for persistence).
|
|
407
|
+
* The base messages getter returns only the visible path.
|
|
408
|
+
*/
|
|
409
|
+
getAllMessages?(): T[];
|
|
410
|
+
/**
|
|
411
|
+
* Get branch navigation info for a message.
|
|
412
|
+
* Returns null if the message has no siblings.
|
|
413
|
+
*/
|
|
414
|
+
getBranchInfo?(messageId: string): BranchInfo | null;
|
|
415
|
+
/**
|
|
416
|
+
* Navigate to a specific message variant (sibling branch).
|
|
417
|
+
* Updates the active path to go through messageId.
|
|
418
|
+
*/
|
|
419
|
+
switchBranch?(messageId: string): void;
|
|
420
|
+
/**
|
|
421
|
+
* Whether any message has siblings (branching has occurred).
|
|
422
|
+
*/
|
|
423
|
+
readonly hasBranches?: boolean;
|
|
425
424
|
}
|
|
426
425
|
|
|
427
426
|
/**
|
|
@@ -463,10 +462,12 @@ interface ChatConfig {
|
|
|
463
462
|
body?: Resolvable<Record<string, unknown>>;
|
|
464
463
|
/** Thread ID for conversation persistence */
|
|
465
464
|
threadId?: string;
|
|
466
|
-
/**
|
|
465
|
+
/** Enable debug logging */
|
|
467
466
|
debug?: boolean;
|
|
468
467
|
/** Available tools (passed to LLM) */
|
|
469
468
|
tools?: ToolDefinition[];
|
|
469
|
+
/** Optional prompt/tool optimization controls */
|
|
470
|
+
optimization?: ToolOptimizationConfig;
|
|
470
471
|
}
|
|
471
472
|
/**
|
|
472
473
|
* Server-side tool execution info (from streaming action events)
|
|
@@ -497,6 +498,8 @@ interface ChatCallbacks<T extends UIMessage = UIMessage> {
|
|
|
497
498
|
onToolCalls?: (toolCalls: T["toolCalls"]) => void;
|
|
498
499
|
/** Called when generation is complete */
|
|
499
500
|
onFinish?: (messages: T[]) => void;
|
|
501
|
+
/** Called when prompt context usage changes */
|
|
502
|
+
onContextUsageChange?: (usage: ContextUsage) => void;
|
|
500
503
|
/** Called when a server-side tool starts executing (action:start event) */
|
|
501
504
|
onServerToolStart?: (info: ServerToolInfo) => void;
|
|
502
505
|
/** Called when a server-side tool receives args (action:args event) */
|
|
@@ -641,6 +644,39 @@ interface AgentLoopActions {
|
|
|
641
644
|
*/
|
|
642
645
|
declare const initialAgentLoopState: AgentLoopState$1;
|
|
643
646
|
|
|
647
|
+
type RequestMessage = ChatRequest["messages"][number];
|
|
648
|
+
type RequestTool = {
|
|
649
|
+
name: string;
|
|
650
|
+
description: string;
|
|
651
|
+
category?: string;
|
|
652
|
+
group?: string;
|
|
653
|
+
deferLoading?: boolean;
|
|
654
|
+
profiles?: string[];
|
|
655
|
+
searchKeywords?: string[];
|
|
656
|
+
inputSchema: unknown;
|
|
657
|
+
};
|
|
658
|
+
declare class ChatContextOptimizer {
|
|
659
|
+
private config;
|
|
660
|
+
private activeProfile;
|
|
661
|
+
private lastContextUsage;
|
|
662
|
+
constructor(config?: ToolOptimizationConfig);
|
|
663
|
+
updateConfig(config?: ToolOptimizationConfig): void;
|
|
664
|
+
setActiveProfile(profile?: string): void;
|
|
665
|
+
getContextUsage(): ContextUsage | null;
|
|
666
|
+
prepare(params: {
|
|
667
|
+
messages: UIMessage[];
|
|
668
|
+
tools?: ToolDefinition[];
|
|
669
|
+
systemPrompt?: string;
|
|
670
|
+
}): {
|
|
671
|
+
messages: RequestMessage[];
|
|
672
|
+
tools?: RequestTool[];
|
|
673
|
+
contextUsage: ContextUsage;
|
|
674
|
+
warnings: string[];
|
|
675
|
+
};
|
|
676
|
+
private selectTools;
|
|
677
|
+
private transformMessages;
|
|
678
|
+
}
|
|
679
|
+
|
|
644
680
|
/**
|
|
645
681
|
* Event types emitted by AbstractChat
|
|
646
682
|
*/
|
|
@@ -682,6 +718,8 @@ declare class AbstractChat<T extends UIMessage = UIMessage> {
|
|
|
682
718
|
protected transport: ChatTransport;
|
|
683
719
|
protected config: ChatConfig;
|
|
684
720
|
protected callbacks: ChatCallbacks<T>;
|
|
721
|
+
protected optimizer: ChatContextOptimizer;
|
|
722
|
+
protected lastContextUsage: ContextUsage | null;
|
|
685
723
|
private eventHandlers;
|
|
686
724
|
private streamState;
|
|
687
725
|
constructor(init: ChatInit<T>);
|
|
@@ -696,8 +734,16 @@ declare class AbstractChat<T extends UIMessage = UIMessage> {
|
|
|
696
734
|
/**
|
|
697
735
|
* Send a message
|
|
698
736
|
* Returns false if a request is already in progress
|
|
737
|
+
*
|
|
738
|
+
* @param content - Message content
|
|
739
|
+
* @param attachments - Optional attachments
|
|
740
|
+
* @param options - Optional branching options
|
|
741
|
+
* @param options.editMessageId - Edit flow: new message branches from the
|
|
742
|
+
* same parent as this message ID, creating a parallel conversation path
|
|
699
743
|
*/
|
|
700
|
-
sendMessage(content: string, attachments?: MessageAttachment[]
|
|
744
|
+
sendMessage(content: string, attachments?: MessageAttachment[], options?: {
|
|
745
|
+
editMessageId?: string;
|
|
746
|
+
}): Promise<boolean>;
|
|
701
747
|
/**
|
|
702
748
|
* Resolve any tool_calls that don't have corresponding tool_results.
|
|
703
749
|
* This prevents Anthropic API errors when tool_use has no tool_result.
|
|
@@ -728,9 +774,21 @@ declare class AbstractChat<T extends UIMessage = UIMessage> {
|
|
|
728
774
|
*/
|
|
729
775
|
setMessages(messages: T[]): void;
|
|
730
776
|
/**
|
|
731
|
-
* Regenerate last response
|
|
777
|
+
* Regenerate last response.
|
|
778
|
+
*
|
|
779
|
+
* Branch-aware: when the state supports branching (setCurrentLeaf is available),
|
|
780
|
+
* regenerate creates a new sibling response instead of destroying the original.
|
|
781
|
+
* The old response is preserved and navigable via switchBranch().
|
|
782
|
+
*
|
|
783
|
+
* Legacy fallback: when branching is not available, uses old slice() behavior.
|
|
732
784
|
*/
|
|
733
785
|
regenerate(messageId?: string): Promise<void>;
|
|
786
|
+
/**
|
|
787
|
+
* Returns all messages across all branches when the state supports it
|
|
788
|
+
* (branch-aware), otherwise returns the visible path.
|
|
789
|
+
* Use this whenever firing onMessagesChange so inactive branches are not lost.
|
|
790
|
+
*/
|
|
791
|
+
private _allMessages;
|
|
734
792
|
/**
|
|
735
793
|
* Subscribe to events
|
|
736
794
|
*/
|
|
@@ -749,10 +807,51 @@ declare class AbstractChat<T extends UIMessage = UIMessage> {
|
|
|
749
807
|
* Set tools available for the LLM
|
|
750
808
|
*/
|
|
751
809
|
setTools(tools: ToolDefinition[]): void;
|
|
810
|
+
/**
|
|
811
|
+
* Update prompt/tool optimization behavior.
|
|
812
|
+
*/
|
|
813
|
+
setOptimizationConfig(config?: ToolOptimizationConfig): void;
|
|
814
|
+
/**
|
|
815
|
+
* Select the active tool profile for future requests.
|
|
816
|
+
*/
|
|
817
|
+
setToolProfile(profile?: string): void;
|
|
818
|
+
/**
|
|
819
|
+
* Get the most recent prompt context usage snapshot.
|
|
820
|
+
*/
|
|
821
|
+
getContextUsage(): ContextUsage | null;
|
|
822
|
+
/**
|
|
823
|
+
* Inline skills from the client (sent on every request for server to merge)
|
|
824
|
+
*/
|
|
825
|
+
protected inlineSkills: Array<{
|
|
826
|
+
name: string;
|
|
827
|
+
description: string;
|
|
828
|
+
content: string;
|
|
829
|
+
strategy?: string;
|
|
830
|
+
}>;
|
|
831
|
+
/**
|
|
832
|
+
* Set inline skills (called by SkillProvider via React layer)
|
|
833
|
+
*/
|
|
834
|
+
setInlineSkills(skills: Array<{
|
|
835
|
+
name: string;
|
|
836
|
+
description: string;
|
|
837
|
+
content: string;
|
|
838
|
+
strategy?: string;
|
|
839
|
+
}>): void;
|
|
752
840
|
/**
|
|
753
841
|
* Dynamic context from useAIContext hook
|
|
754
842
|
*/
|
|
755
843
|
protected dynamicContext: string;
|
|
844
|
+
/**
|
|
845
|
+
* Optional transform applied to messages just before building the HTTP request.
|
|
846
|
+
* Used by the message-history / compaction system to send a pruned message list
|
|
847
|
+
* without mutating the in-memory store (which keeps the full history for display).
|
|
848
|
+
*/
|
|
849
|
+
private requestMessageTransform;
|
|
850
|
+
/**
|
|
851
|
+
* Set (or clear) the per-request message transform.
|
|
852
|
+
* Pass null to disable.
|
|
853
|
+
*/
|
|
854
|
+
setRequestMessageTransform(fn: ((messages: UIMessage[]) => UIMessage[]) | null): void;
|
|
756
855
|
/**
|
|
757
856
|
* Set dynamic context (appended to system prompt)
|
|
758
857
|
*/
|
|
@@ -781,32 +880,37 @@ declare class AbstractChat<T extends UIMessage = UIMessage> {
|
|
|
781
880
|
* Build the request payload
|
|
782
881
|
*/
|
|
783
882
|
protected buildRequest(): {
|
|
784
|
-
messages:
|
|
785
|
-
role:
|
|
786
|
-
content: string;
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
attachments?:
|
|
790
|
-
}
|
|
791
|
-
role: MessageRole;
|
|
792
|
-
content: string;
|
|
793
|
-
tool_calls: ToolCall[] | undefined;
|
|
794
|
-
tool_call_id: string | undefined;
|
|
795
|
-
attachments: MessageAttachment[] | undefined;
|
|
796
|
-
})[];
|
|
883
|
+
messages: {
|
|
884
|
+
role: string;
|
|
885
|
+
content: string | null;
|
|
886
|
+
tool_calls?: unknown[];
|
|
887
|
+
tool_call_id?: string;
|
|
888
|
+
attachments?: unknown[];
|
|
889
|
+
}[];
|
|
797
890
|
threadId: string | undefined;
|
|
798
891
|
systemPrompt: string | undefined;
|
|
799
892
|
llm: Partial<LLMConfig> | undefined;
|
|
800
893
|
tools: {
|
|
801
894
|
name: string;
|
|
802
895
|
description: string;
|
|
896
|
+
category: string | undefined;
|
|
897
|
+
group: string | undefined;
|
|
898
|
+
deferLoading: boolean | undefined;
|
|
899
|
+
profiles: string[] | undefined;
|
|
900
|
+
searchKeywords: string[] | undefined;
|
|
803
901
|
inputSchema: ToolInputSchema;
|
|
804
902
|
}[] | undefined;
|
|
903
|
+
__skills: {
|
|
904
|
+
name: string;
|
|
905
|
+
description: string;
|
|
906
|
+
content: string;
|
|
907
|
+
strategy?: string;
|
|
908
|
+
}[] | undefined;
|
|
805
909
|
};
|
|
806
910
|
/**
|
|
807
911
|
* Handle streaming response
|
|
808
912
|
*/
|
|
809
|
-
protected handleStreamResponse(stream: AsyncIterable<StreamChunk
|
|
913
|
+
protected handleStreamResponse(stream: AsyncIterable<StreamChunk>, preCreatedMessageId?: string): Promise<void>;
|
|
810
914
|
/**
|
|
811
915
|
* Handle JSON (non-streaming) response
|
|
812
916
|
*/
|
|
@@ -815,10 +919,11 @@ declare class AbstractChat<T extends UIMessage = UIMessage> {
|
|
|
815
919
|
* Handle errors
|
|
816
920
|
*/
|
|
817
921
|
protected handleError(error: Error): void;
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
*/
|
|
922
|
+
private _log?;
|
|
923
|
+
private get log();
|
|
821
924
|
protected debug(action: string, data?: unknown): void;
|
|
925
|
+
protected debugGroup(label: string, collapsed?: boolean): void;
|
|
926
|
+
protected debugGroupEnd(): void;
|
|
822
927
|
/**
|
|
823
928
|
* Type guard for async iterable
|
|
824
929
|
*/
|
|
@@ -1010,6 +1115,191 @@ declare class AbstractAgentLoop implements AgentLoopActions {
|
|
|
1010
1115
|
revive(): void;
|
|
1011
1116
|
}
|
|
1012
1117
|
|
|
1118
|
+
/**
|
|
1119
|
+
* Message History Types
|
|
1120
|
+
*
|
|
1121
|
+
* Core types for the dual-layer context management system.
|
|
1122
|
+
* DisplayMessage extends UIMessage for full backward-compat.
|
|
1123
|
+
*/
|
|
1124
|
+
|
|
1125
|
+
/**
|
|
1126
|
+
* DisplayMessage — what the UI renders, never shrinks.
|
|
1127
|
+
* Extends UIMessage so it can be used anywhere UIMessage is accepted.
|
|
1128
|
+
*/
|
|
1129
|
+
interface DisplayMessage extends UIMessage {
|
|
1130
|
+
/** Unix timestamp (ms). Mirrors createdAt for easier arithmetic. */
|
|
1131
|
+
timestamp: number;
|
|
1132
|
+
}
|
|
1133
|
+
/**
|
|
1134
|
+
* CompactionMarker — injected into displayMessages when compaction fires.
|
|
1135
|
+
* Shown in the UI as a divider: "Earlier conversation summarized".
|
|
1136
|
+
*/
|
|
1137
|
+
interface CompactionMarker extends DisplayMessage {
|
|
1138
|
+
role: "system";
|
|
1139
|
+
/** Discriminator — always 'compaction-marker' */
|
|
1140
|
+
type: "compaction-marker";
|
|
1141
|
+
/** Human-readable summary of what was compacted */
|
|
1142
|
+
content: string;
|
|
1143
|
+
/** IDs of the DisplayMessages that were summarized */
|
|
1144
|
+
summarizedMessageIds: string[];
|
|
1145
|
+
/** Approximate tokens saved by this compaction */
|
|
1146
|
+
tokensSaved: number;
|
|
1147
|
+
}
|
|
1148
|
+
/**
|
|
1149
|
+
* LLMMessage — the compacted form sent to the model on each request.
|
|
1150
|
+
* Derived from DisplayMessages; never persisted directly.
|
|
1151
|
+
*/
|
|
1152
|
+
interface LLMMessage {
|
|
1153
|
+
role: "system" | "user" | "assistant" | "tool";
|
|
1154
|
+
content: string;
|
|
1155
|
+
tool_calls?: ToolCall[];
|
|
1156
|
+
tool_call_id?: string;
|
|
1157
|
+
}
|
|
1158
|
+
/**
|
|
1159
|
+
* CompactedToolResult — replaces a full tool result when it is old
|
|
1160
|
+
* enough to prune. Preserves key metadata without the full payload.
|
|
1161
|
+
*/
|
|
1162
|
+
interface CompactedToolResult {
|
|
1163
|
+
type: "compacted-tool-result";
|
|
1164
|
+
toolName: string;
|
|
1165
|
+
toolCallId: string;
|
|
1166
|
+
args: Record<string, unknown>;
|
|
1167
|
+
executedAt: number;
|
|
1168
|
+
status: "success" | "error";
|
|
1169
|
+
/** Original byte size before compaction */
|
|
1170
|
+
originalSize: number;
|
|
1171
|
+
/** One-line summary e.g. "Searched for 'react hooks' — 15 results" */
|
|
1172
|
+
summary: string;
|
|
1173
|
+
/** First 200 chars of original result, if no LLM summary available */
|
|
1174
|
+
extract?: string;
|
|
1175
|
+
}
|
|
1176
|
+
/**
|
|
1177
|
+
* SessionCompactionState — persisted to localStorage between reloads.
|
|
1178
|
+
*/
|
|
1179
|
+
interface SessionCompactionState {
|
|
1180
|
+
/** The current rolling summary (null = no compaction yet) */
|
|
1181
|
+
rollingSummary: string | null;
|
|
1182
|
+
/** Timestamp of last compaction (null = never compacted) */
|
|
1183
|
+
lastCompactionAt: number | null;
|
|
1184
|
+
/** How many times compaction has run this session */
|
|
1185
|
+
compactionCount: number;
|
|
1186
|
+
/** Cumulative tokens saved across all compactions */
|
|
1187
|
+
totalTokensSaved: number;
|
|
1188
|
+
/** User-pinned facts that survive all compaction */
|
|
1189
|
+
workingMemory: string[];
|
|
1190
|
+
/** Current displayMessages count (for diagnostics) */
|
|
1191
|
+
displayMessageCount: number;
|
|
1192
|
+
/** Current llmMessages count (for diagnostics) */
|
|
1193
|
+
llmMessageCount: number;
|
|
1194
|
+
}
|
|
1195
|
+
/**
|
|
1196
|
+
* TokenUsage — live token estimate after each AI response.
|
|
1197
|
+
*/
|
|
1198
|
+
interface TokenUsage {
|
|
1199
|
+
/** Estimated tokens currently in LLM context */
|
|
1200
|
+
current: number;
|
|
1201
|
+
/** Max tokens configured (maxContextTokens) */
|
|
1202
|
+
max: number;
|
|
1203
|
+
/** current / max (0–1) */
|
|
1204
|
+
percentage: number;
|
|
1205
|
+
/** True when percentage > compactionThreshold */
|
|
1206
|
+
isApproaching: boolean;
|
|
1207
|
+
}
|
|
1208
|
+
/**
|
|
1209
|
+
* CompactionEvent — fired via onCompaction callback after each compaction.
|
|
1210
|
+
*/
|
|
1211
|
+
interface CompactionEvent {
|
|
1212
|
+
/** 'auto' = threshold triggered, 'manual' = compactSession() called */
|
|
1213
|
+
type: "auto" | "manual";
|
|
1214
|
+
compactionCount: number;
|
|
1215
|
+
messagesSummarized: number;
|
|
1216
|
+
tokensSaved: number;
|
|
1217
|
+
timestamp: number;
|
|
1218
|
+
}
|
|
1219
|
+
type CompactionStrategy = "none" | "sliding-window" | "summary-buffer" | "selective-prune";
|
|
1220
|
+
/**
|
|
1221
|
+
* MessageHistoryConfig — passed as messageHistory prop to CopilotProvider
|
|
1222
|
+
* or directly to useMessageHistory().
|
|
1223
|
+
*/
|
|
1224
|
+
interface MessageHistoryConfig {
|
|
1225
|
+
/**
|
|
1226
|
+
* Compaction strategy.
|
|
1227
|
+
* @default 'none' — current SDK behaviour, zero breaking changes
|
|
1228
|
+
*/
|
|
1229
|
+
strategy?: CompactionStrategy;
|
|
1230
|
+
/**
|
|
1231
|
+
* Hard token ceiling for LLM context.
|
|
1232
|
+
* @default 128000
|
|
1233
|
+
*/
|
|
1234
|
+
maxContextTokens?: number;
|
|
1235
|
+
/**
|
|
1236
|
+
* Tokens reserved for the model's reply; subtracted from budget before pruning.
|
|
1237
|
+
* @default 4096
|
|
1238
|
+
*/
|
|
1239
|
+
reserveForResponse?: number;
|
|
1240
|
+
/**
|
|
1241
|
+
* Ratio of maxContextTokens at which auto-compaction fires.
|
|
1242
|
+
* @default 0.75
|
|
1243
|
+
*/
|
|
1244
|
+
compactionThreshold?: number;
|
|
1245
|
+
/**
|
|
1246
|
+
* Minimum messages always kept verbatim (most recent N). Never compacted.
|
|
1247
|
+
* @default 10
|
|
1248
|
+
*/
|
|
1249
|
+
recentBuffer?: number;
|
|
1250
|
+
/**
|
|
1251
|
+
* Hard char truncation cap per tool result before sending. 0 = no cap.
|
|
1252
|
+
* @default 10000
|
|
1253
|
+
*/
|
|
1254
|
+
toolResultMaxChars?: number;
|
|
1255
|
+
/**
|
|
1256
|
+
* Your /api/compact endpoint. Required when strategy is 'summary-buffer'.
|
|
1257
|
+
*/
|
|
1258
|
+
compactionUrl?: string;
|
|
1259
|
+
/**
|
|
1260
|
+
* Persist display history + compaction state across page reloads.
|
|
1261
|
+
* @default false
|
|
1262
|
+
*/
|
|
1263
|
+
persistSession?: boolean;
|
|
1264
|
+
/**
|
|
1265
|
+
* localStorage/IndexedDB key prefix.
|
|
1266
|
+
* @default 'copilot-session'
|
|
1267
|
+
*/
|
|
1268
|
+
storageKey?: string;
|
|
1269
|
+
/** Fired after every compaction. */
|
|
1270
|
+
onCompaction?: (event: CompactionEvent) => void;
|
|
1271
|
+
/** Fired after every message with current token estimate. */
|
|
1272
|
+
onTokenUsage?: (usage: TokenUsage) => void;
|
|
1273
|
+
}
|
|
1274
|
+
interface UseMessageHistoryOptions extends MessageHistoryConfig {
|
|
1275
|
+
/** Disable auto-compaction for this component even if provider has it on. */
|
|
1276
|
+
skipCompaction?: boolean;
|
|
1277
|
+
/** Token estimation precision. @default 'fast' */
|
|
1278
|
+
tokenEstimation?: "fast" | "accurate" | "off";
|
|
1279
|
+
/** Custom async summarizer. Overrides /api/compact. */
|
|
1280
|
+
summarizer?: (messages: LLMMessage[]) => Promise<string>;
|
|
1281
|
+
}
|
|
1282
|
+
interface UseMessageHistoryReturn {
|
|
1283
|
+
/** Full immutable UI history. Pass to CopilotChat. */
|
|
1284
|
+
displayMessages: DisplayMessage[];
|
|
1285
|
+
/** Compacted LLM context. Rebuilt on each render. */
|
|
1286
|
+
llmMessages: LLMMessage[];
|
|
1287
|
+
/** Live token estimate. Updated after each AI response. */
|
|
1288
|
+
tokenUsage: TokenUsage;
|
|
1289
|
+
/** True while auto-compaction is running (summarizing old messages). */
|
|
1290
|
+
isCompacting: boolean;
|
|
1291
|
+
/** Compaction metadata. */
|
|
1292
|
+
compactionState: SessionCompactionState;
|
|
1293
|
+
/** Manually trigger compaction. Optional instructions guide the summarizer. */
|
|
1294
|
+
compactSession: (instructions?: string) => Promise<void>;
|
|
1295
|
+
/** Pin a string that survives all future compactions. */
|
|
1296
|
+
addToWorkingMemory: (fact: string) => void;
|
|
1297
|
+
/** Remove all working memory facts. */
|
|
1298
|
+
clearWorkingMemory: () => void;
|
|
1299
|
+
/** Clear history, compaction state, and persistence. Fresh start. */
|
|
1300
|
+
resetSession: () => void;
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1013
1303
|
interface CopilotProviderProps {
|
|
1014
1304
|
children: React__default.ReactNode;
|
|
1015
1305
|
/**
|
|
@@ -1049,6 +1339,20 @@ interface CopilotProviderProps {
|
|
|
1049
1339
|
maxIterationsMessage?: string;
|
|
1050
1340
|
/** MCP servers to connect to automatically */
|
|
1051
1341
|
mcpServers?: MCPServerConfig[];
|
|
1342
|
+
/** Optional prompt/tool optimization controls (tool profiles, context budgets, etc.) */
|
|
1343
|
+
optimization?: ToolOptimizationConfig;
|
|
1344
|
+
/**
|
|
1345
|
+
* Context window management config. Controls compaction strategy, token budgets,
|
|
1346
|
+
* session persistence, and working memory.
|
|
1347
|
+
* @default strategy: 'none' — current behaviour, zero breaking changes
|
|
1348
|
+
*/
|
|
1349
|
+
messageHistory?: MessageHistoryConfig;
|
|
1350
|
+
/**
|
|
1351
|
+
* Convenience prop to pre-register inline skills.
|
|
1352
|
+
* Wraps children with <SkillProvider skills={skills}>.
|
|
1353
|
+
* Only inline skills (source.type === "inline") are supported client-side.
|
|
1354
|
+
*/
|
|
1355
|
+
skills?: SkillDefinition[];
|
|
1052
1356
|
}
|
|
1053
1357
|
interface CopilotContextValue {
|
|
1054
1358
|
messages: UIMessage[];
|
|
@@ -1060,6 +1364,12 @@ interface CopilotContextValue {
|
|
|
1060
1364
|
clearMessages: () => void;
|
|
1061
1365
|
setMessages: (messages: UIMessage[]) => void;
|
|
1062
1366
|
regenerate: (messageId?: string) => Promise<void>;
|
|
1367
|
+
switchBranch: (messageId: string) => void;
|
|
1368
|
+
getBranchInfo: (messageId: string) => BranchInfo | null;
|
|
1369
|
+
editMessage: (messageId: string, newContent: string) => Promise<void>;
|
|
1370
|
+
hasBranches: boolean;
|
|
1371
|
+
/** Get ALL messages across all branches (for persistence). Visible path only when no branches. */
|
|
1372
|
+
getAllMessages: () => UIMessage[];
|
|
1063
1373
|
registerTool: (tool: ToolDefinition) => void;
|
|
1064
1374
|
unregisterTool: (name: string) => void;
|
|
1065
1375
|
registeredTools: ToolDefinition[];
|
|
@@ -1073,6 +1383,20 @@ interface CopilotContextValue {
|
|
|
1073
1383
|
addContext: (context: string, parentId?: string) => string;
|
|
1074
1384
|
removeContext: (id: string) => void;
|
|
1075
1385
|
setSystemPrompt: (prompt: string) => void;
|
|
1386
|
+
/** Total characters currently registered in the AI context tree (system prompt contribution). */
|
|
1387
|
+
contextChars: number;
|
|
1388
|
+
/**
|
|
1389
|
+
* Live prompt context usage snapshot — updated on every message send.
|
|
1390
|
+
* Includes token counts and percentages for systemPrompt, history, toolResults, tools buckets.
|
|
1391
|
+
* null until the first message is sent.
|
|
1392
|
+
*/
|
|
1393
|
+
contextUsage: ContextUsage | null;
|
|
1394
|
+
setInlineSkills: (skills: Array<{
|
|
1395
|
+
name: string;
|
|
1396
|
+
description: string;
|
|
1397
|
+
content: string;
|
|
1398
|
+
strategy?: string;
|
|
1399
|
+
}>) => void;
|
|
1076
1400
|
threadId?: string;
|
|
1077
1401
|
/**
|
|
1078
1402
|
* Runtime URL configuration.
|
|
@@ -1082,7 +1406,7 @@ interface CopilotContextValue {
|
|
|
1082
1406
|
toolsConfig?: ToolsConfig;
|
|
1083
1407
|
}
|
|
1084
1408
|
declare function useCopilot(): CopilotContextValue;
|
|
1085
|
-
declare function CopilotProvider({ children, runtimeUrl, systemPrompt, tools: toolsConfig, threadId, initialMessages, onMessagesChange, onError, streaming, headers, body, debug, maxIterations, maxIterationsMessage, mcpServers, }: CopilotProviderProps): react_jsx_runtime.JSX.Element;
|
|
1409
|
+
declare function CopilotProvider({ children, runtimeUrl, systemPrompt, tools: toolsConfig, threadId, initialMessages, onMessagesChange, onError, streaming, headers, body, debug, maxIterations, maxIterationsMessage, mcpServers, optimization, messageHistory, skills, }: CopilotProviderProps): react_jsx_runtime.JSX.Element;
|
|
1086
1410
|
|
|
1087
1411
|
/**
|
|
1088
1412
|
* Chat UI state interface (UI-only state, not message data)
|
|
@@ -1150,7 +1474,7 @@ interface ChatActions {
|
|
|
1150
1474
|
stopGeneration: () => void;
|
|
1151
1475
|
/** Clear all messages */
|
|
1152
1476
|
clearMessages: () => void;
|
|
1153
|
-
/** Regenerate last response */
|
|
1477
|
+
/** Regenerate last response (branch-aware: preserves original as sibling) */
|
|
1154
1478
|
regenerate: (messageId?: string) => Promise<void>;
|
|
1155
1479
|
/** Set messages directly */
|
|
1156
1480
|
setMessages: (messages: Message[]) => void;
|
|
@@ -1160,6 +1484,17 @@ interface ChatActions {
|
|
|
1160
1484
|
* - Free: converts to base64
|
|
1161
1485
|
*/
|
|
1162
1486
|
processAttachment: (file: File) => Promise<MessageAttachment>;
|
|
1487
|
+
/** Navigate to a sibling branch (← / → navigation) */
|
|
1488
|
+
switchBranch: (messageId: string) => void;
|
|
1489
|
+
/** Get branch navigation info for a message */
|
|
1490
|
+
getBranchInfo: (messageId: string) => BranchInfo | null;
|
|
1491
|
+
/**
|
|
1492
|
+
* Edit a user message: sends newContent as a new branch from the same
|
|
1493
|
+
* parent as the original message. Preserves the original in place.
|
|
1494
|
+
*/
|
|
1495
|
+
editMessage: (messageId: string, newContent: string) => Promise<void>;
|
|
1496
|
+
/** Whether any message has siblings (branching has occurred) */
|
|
1497
|
+
hasBranches: boolean;
|
|
1163
1498
|
}
|
|
1164
1499
|
/**
|
|
1165
1500
|
* Tools actions interface
|
|
@@ -1413,6 +1748,28 @@ interface UseToolConfig<TParams = Record<string, unknown>> {
|
|
|
1413
1748
|
* @default false
|
|
1414
1749
|
*/
|
|
1415
1750
|
hidden?: boolean;
|
|
1751
|
+
/** Deferred tools stay out of the default request payload; discovered only when query matches */
|
|
1752
|
+
deferLoading?: boolean;
|
|
1753
|
+
/** Profile memberships for selective tool loading */
|
|
1754
|
+
profiles?: string[];
|
|
1755
|
+
/** Extra keywords for dynamic tool-selection scoring */
|
|
1756
|
+
searchKeywords?: string[];
|
|
1757
|
+
/** Optional group for profile-based selection */
|
|
1758
|
+
group?: string;
|
|
1759
|
+
/** Optional category for search, filtering, and budgets */
|
|
1760
|
+
category?: string;
|
|
1761
|
+
/** Per-tool prompt/result shaping controls */
|
|
1762
|
+
resultConfig?: ToolResultConfig;
|
|
1763
|
+
/** Human-readable title for UI display */
|
|
1764
|
+
title?: string | ((args: TParams) => string);
|
|
1765
|
+
/** Title shown while executing */
|
|
1766
|
+
executingTitle?: string | ((args: TParams) => string);
|
|
1767
|
+
/** Title shown after completion */
|
|
1768
|
+
completedTitle?: string | ((args: TParams) => string);
|
|
1769
|
+
/** How the AI should respond when this tool's result is rendered as UI */
|
|
1770
|
+
aiResponseMode?: AIResponseMode;
|
|
1771
|
+
/** Context/summary sent to AI instead of full result */
|
|
1772
|
+
aiContext?: string | ((result: ToolResponse$1, args: Record<string, unknown>) => string);
|
|
1416
1773
|
}
|
|
1417
1774
|
/**
|
|
1418
1775
|
* Register a client-side tool
|
|
@@ -2463,6 +2820,74 @@ declare function createMessageIntentHandler(sendMessage: (message: string) => vo
|
|
|
2463
2820
|
*/
|
|
2464
2821
|
declare function createToolIntentHandler(callTool: (name: string, args?: Record<string, unknown>) => Promise<unknown>): UseMCPUIIntentsConfig;
|
|
2465
2822
|
|
|
2823
|
+
/**
|
|
2824
|
+
* Per-message token usage returned by the LLM provider.
|
|
2825
|
+
*/
|
|
2826
|
+
interface MessageTokenUsage {
|
|
2827
|
+
prompt_tokens: number;
|
|
2828
|
+
completion_tokens: number;
|
|
2829
|
+
total_tokens: number;
|
|
2830
|
+
}
|
|
2831
|
+
/**
|
|
2832
|
+
* Context window stats — updated reactively as messages are sent and contexts change.
|
|
2833
|
+
*/
|
|
2834
|
+
interface ContextStats {
|
|
2835
|
+
/**
|
|
2836
|
+
* Full context usage snapshot from the last send — includes token counts and
|
|
2837
|
+
* percentages for every budget bucket (systemPrompt, history, toolResults, tools).
|
|
2838
|
+
* null until the first message is sent.
|
|
2839
|
+
*/
|
|
2840
|
+
contextUsage: ContextUsage | null;
|
|
2841
|
+
/**
|
|
2842
|
+
* Convenience: total estimated tokens currently in the prompt (from contextUsage).
|
|
2843
|
+
* Falls back to a fast chars/3.5 estimate from contextChars before first send.
|
|
2844
|
+
*/
|
|
2845
|
+
totalTokens: number;
|
|
2846
|
+
/**
|
|
2847
|
+
* Convenience: percentage of context window used (0–1).
|
|
2848
|
+
* 0 until first send.
|
|
2849
|
+
*/
|
|
2850
|
+
usagePercent: number;
|
|
2851
|
+
/** Total characters currently in the AI context (system prompt contribution). */
|
|
2852
|
+
contextChars: number;
|
|
2853
|
+
/** Number of tools currently registered in the agent loop. */
|
|
2854
|
+
toolCount: number;
|
|
2855
|
+
/** Number of visible (non-system) messages in the active thread. */
|
|
2856
|
+
messageCount: number;
|
|
2857
|
+
/**
|
|
2858
|
+
* Actual token usage from the last assistant message metadata (if provider returned it).
|
|
2859
|
+
* null if not available.
|
|
2860
|
+
*/
|
|
2861
|
+
lastResponseUsage: MessageTokenUsage | null;
|
|
2862
|
+
}
|
|
2863
|
+
/**
|
|
2864
|
+
* useContextStats — live snapshot of the AI copilot's context window usage.
|
|
2865
|
+
*
|
|
2866
|
+
* `contextUsage` is the richest field — it has full breakdown by bucket with
|
|
2867
|
+
* token counts and percentages, updated on every message send.
|
|
2868
|
+
*
|
|
2869
|
+
* @example
|
|
2870
|
+
* ```tsx
|
|
2871
|
+
* const { contextUsage, toolCount, totalTokens, usagePercent } = useContextStats();
|
|
2872
|
+
* // contextUsage.breakdown.systemPrompt.percent — % of window used by system prompt
|
|
2873
|
+
* // contextUsage.breakdown.history.tokens — tokens from conversation history
|
|
2874
|
+
* // usagePercent — overall window fill (0–1)
|
|
2875
|
+
* ```
|
|
2876
|
+
*/
|
|
2877
|
+
declare function useContextStats(): ContextStats;
|
|
2878
|
+
|
|
2879
|
+
declare function useSkill(skill: SkillDefinition): void;
|
|
2880
|
+
|
|
2881
|
+
interface UseSkillStatusReturn {
|
|
2882
|
+
/** All currently registered skills */
|
|
2883
|
+
skills: ResolvedSkill[];
|
|
2884
|
+
/** Number of registered skills */
|
|
2885
|
+
count: number;
|
|
2886
|
+
/** Check if a skill with the given name is registered */
|
|
2887
|
+
has: (name: string) => boolean;
|
|
2888
|
+
}
|
|
2889
|
+
declare function useSkillStatus(): UseSkillStatusReturn;
|
|
2890
|
+
|
|
2466
2891
|
/**
|
|
2467
2892
|
* Create a permission storage adapter based on config
|
|
2468
2893
|
*/
|
|
@@ -2476,14 +2901,16 @@ declare function createSessionPermissionCache(): Map<string, PermissionLevel>;
|
|
|
2476
2901
|
/**
|
|
2477
2902
|
* ReactChatState - React-specific implementation of ChatState
|
|
2478
2903
|
*
|
|
2479
|
-
*
|
|
2480
|
-
*
|
|
2904
|
+
* Backed by MessageTree for conversation branching support.
|
|
2905
|
+
* The `messages` getter returns only the visible path (active branch).
|
|
2906
|
+
* Use `getAllMessages()` for full persistence.
|
|
2481
2907
|
*
|
|
2482
2908
|
* Pattern inspired by Vercel AI SDK's useSyncExternalStore pattern.
|
|
2483
2909
|
*/
|
|
2484
2910
|
|
|
2485
2911
|
/**
|
|
2486
2912
|
* ReactChatState implements ChatState with callback-based reactivity
|
|
2913
|
+
* and full conversation branching support via MessageTree.
|
|
2487
2914
|
*
|
|
2488
2915
|
* @example
|
|
2489
2916
|
* ```tsx
|
|
@@ -2494,16 +2921,25 @@ declare function createSessionPermissionCache(): Map<string, PermissionLevel>;
|
|
|
2494
2921
|
* console.log('State changed');
|
|
2495
2922
|
* });
|
|
2496
2923
|
*
|
|
2497
|
-
* // Get
|
|
2924
|
+
* // Get visible path (active branch only)
|
|
2498
2925
|
* const messages = state.messages;
|
|
2926
|
+
*
|
|
2927
|
+
* // Get all messages across branches (for persistence)
|
|
2928
|
+
* const all = state.getAllMessages();
|
|
2499
2929
|
* ```
|
|
2500
2930
|
*/
|
|
2501
2931
|
declare class ReactChatState<T extends UIMessage = UIMessage> implements ChatState$1<T> {
|
|
2502
|
-
private
|
|
2932
|
+
private tree;
|
|
2503
2933
|
private _status;
|
|
2504
2934
|
private _error;
|
|
2505
2935
|
private subscribers;
|
|
2506
2936
|
constructor(initialMessages?: T[]);
|
|
2937
|
+
/**
|
|
2938
|
+
* Returns the VISIBLE PATH (active branch) — what the UI renders
|
|
2939
|
+
* and what gets sent to the API.
|
|
2940
|
+
*
|
|
2941
|
+
* For all messages across all branches, use getAllMessages().
|
|
2942
|
+
*/
|
|
2507
2943
|
get messages(): T[];
|
|
2508
2944
|
get status(): ChatStatus$1;
|
|
2509
2945
|
get error(): Error | undefined;
|
|
@@ -2517,6 +2953,27 @@ declare class ReactChatState<T extends UIMessage = UIMessage> implements ChatSta
|
|
|
2517
2953
|
updateMessageById(id: string, updater: (message: T) => T): boolean;
|
|
2518
2954
|
setMessages(messages: T[]): void;
|
|
2519
2955
|
clearMessages(): void;
|
|
2956
|
+
/**
|
|
2957
|
+
* Returns ALL messages across all branches.
|
|
2958
|
+
* Use this for persistence (ThreadManager save).
|
|
2959
|
+
*/
|
|
2960
|
+
getAllMessages(): T[];
|
|
2961
|
+
/**
|
|
2962
|
+
* Get branch navigation info for a message.
|
|
2963
|
+
* Returns null if the message has no siblings.
|
|
2964
|
+
*/
|
|
2965
|
+
getBranchInfo(messageId: string): BranchInfo | null;
|
|
2966
|
+
/**
|
|
2967
|
+
* Navigate to a sibling branch.
|
|
2968
|
+
* Triggers re-render via notify().
|
|
2969
|
+
*/
|
|
2970
|
+
switchBranch(messageId: string): void;
|
|
2971
|
+
/**
|
|
2972
|
+
* Set the current leaf (used by regenerate() to rewind active path).
|
|
2973
|
+
* Triggers re-render via notify().
|
|
2974
|
+
*/
|
|
2975
|
+
setCurrentLeaf(leafId: string | null): void;
|
|
2976
|
+
get hasBranches(): boolean;
|
|
2520
2977
|
/**
|
|
2521
2978
|
* Subscribe to state changes.
|
|
2522
2979
|
* Returns an unsubscribe function.
|
|
@@ -2626,6 +3083,23 @@ declare class ReactChat extends AbstractChat<UIMessage> {
|
|
|
2626
3083
|
* Subscribe to error events
|
|
2627
3084
|
*/
|
|
2628
3085
|
onError(handler: ChatEventHandler<"error">): () => void;
|
|
3086
|
+
/**
|
|
3087
|
+
* Navigate to a sibling branch (makes it the active path).
|
|
3088
|
+
*/
|
|
3089
|
+
switchBranch(messageId: string): void;
|
|
3090
|
+
/**
|
|
3091
|
+
* Get branch navigation info for a message.
|
|
3092
|
+
* Returns null if the message has no siblings.
|
|
3093
|
+
*/
|
|
3094
|
+
getBranchInfo(messageId: string): BranchInfo | null;
|
|
3095
|
+
/**
|
|
3096
|
+
* Get all messages across all branches (for persistence).
|
|
3097
|
+
*/
|
|
3098
|
+
getAllMessages(): UIMessage[];
|
|
3099
|
+
/**
|
|
3100
|
+
* Whether any message has siblings (branching has occurred).
|
|
3101
|
+
*/
|
|
3102
|
+
get hasBranches(): boolean;
|
|
2629
3103
|
dispose(): void;
|
|
2630
3104
|
/**
|
|
2631
3105
|
* Revive a disposed instance (for React StrictMode compatibility)
|
|
@@ -2654,7 +3128,7 @@ interface UseChatConfig extends Omit<ReactChatConfig, "callbacks"> {
|
|
|
2654
3128
|
* Hook return type
|
|
2655
3129
|
*/
|
|
2656
3130
|
interface UseChatReturn {
|
|
2657
|
-
/** All messages */
|
|
3131
|
+
/** All messages (visible path — active branch only) */
|
|
2658
3132
|
messages: UIMessage[];
|
|
2659
3133
|
/** Current status */
|
|
2660
3134
|
status: ChatStatus$1;
|
|
@@ -2674,7 +3148,7 @@ interface UseChatReturn {
|
|
|
2674
3148
|
clearMessages: () => void;
|
|
2675
3149
|
/** Set messages directly */
|
|
2676
3150
|
setMessages: (messages: UIMessage[]) => void;
|
|
2677
|
-
/** Regenerate last response */
|
|
3151
|
+
/** Regenerate last response (branch-aware: preserves original as sibling) */
|
|
2678
3152
|
regenerate: (messageId?: string) => Promise<void>;
|
|
2679
3153
|
/** Continue with tool results */
|
|
2680
3154
|
continueWithToolResults: (toolResults: Array<{
|
|
@@ -2683,6 +3157,27 @@ interface UseChatReturn {
|
|
|
2683
3157
|
}>) => Promise<void>;
|
|
2684
3158
|
/** Reference to the ReactChat instance */
|
|
2685
3159
|
chatRef: React.RefObject<ReactChat | null>;
|
|
3160
|
+
/**
|
|
3161
|
+
* Navigate to a sibling branch (← / → navigation).
|
|
3162
|
+
* Only populated when chat is branch-aware.
|
|
3163
|
+
*/
|
|
3164
|
+
switchBranch?: (messageId: string) => void;
|
|
3165
|
+
/**
|
|
3166
|
+
* Get branch navigation info for a message.
|
|
3167
|
+
* Returns null if the message has no siblings.
|
|
3168
|
+
* Only populated when chat is branch-aware.
|
|
3169
|
+
*/
|
|
3170
|
+
getBranchInfo?: (messageId: string) => BranchInfo | null;
|
|
3171
|
+
/**
|
|
3172
|
+
* Edit a user message: sends newContent as a new branch from the same
|
|
3173
|
+
* parent as the original message. Preserves the original message in place.
|
|
3174
|
+
* Only populated when chat is branch-aware.
|
|
3175
|
+
*/
|
|
3176
|
+
editMessage?: (messageId: string, newContent: string) => Promise<void>;
|
|
3177
|
+
/**
|
|
3178
|
+
* Whether any message has siblings (branching has occurred).
|
|
3179
|
+
*/
|
|
3180
|
+
hasBranches?: boolean;
|
|
2686
3181
|
}
|
|
2687
3182
|
/**
|
|
2688
3183
|
* useChat - Thin React wrapper using useSyncExternalStore
|
|
@@ -2706,4 +3201,105 @@ interface UseChatReturn {
|
|
|
2706
3201
|
*/
|
|
2707
3202
|
declare function useChat(config: UseChatConfig): UseChatReturn;
|
|
2708
3203
|
|
|
2709
|
-
|
|
3204
|
+
interface SkillProviderProps {
|
|
3205
|
+
children: React__default.ReactNode;
|
|
3206
|
+
/** Pre-register skills (eager or auto strategies) */
|
|
3207
|
+
skills?: SkillDefinition[];
|
|
3208
|
+
/**
|
|
3209
|
+
* Future: URL to fetch a remote skill manifest
|
|
3210
|
+
* @experimental
|
|
3211
|
+
*/
|
|
3212
|
+
remoteManifest?: string;
|
|
3213
|
+
}
|
|
3214
|
+
declare function SkillProvider({ children, skills: skillsProp, }: SkillProviderProps): react_jsx_runtime.JSX.Element;
|
|
3215
|
+
|
|
3216
|
+
/**
|
|
3217
|
+
* defineSkill — type-safe skill factory
|
|
3218
|
+
*
|
|
3219
|
+
* Identity function with type inference. Same pattern as useTool.
|
|
3220
|
+
*
|
|
3221
|
+
* @example
|
|
3222
|
+
* ```ts
|
|
3223
|
+
* const brandVoice = defineSkill({
|
|
3224
|
+
* name: "brand-voice",
|
|
3225
|
+
* description: "Ensures responses match our brand tone",
|
|
3226
|
+
* strategy: "eager",
|
|
3227
|
+
* source: {
|
|
3228
|
+
* type: "inline",
|
|
3229
|
+
* content: "Always respond in a friendly, concise tone...",
|
|
3230
|
+
* },
|
|
3231
|
+
* });
|
|
3232
|
+
*
|
|
3233
|
+
* // Use in SkillProvider
|
|
3234
|
+
* <SkillProvider skills={[brandVoice]}>
|
|
3235
|
+
* <App />
|
|
3236
|
+
* </SkillProvider>
|
|
3237
|
+
* ```
|
|
3238
|
+
*/
|
|
3239
|
+
|
|
3240
|
+
declare function defineSkill(def: SkillDefinition): SkillDefinition;
|
|
3241
|
+
|
|
3242
|
+
/**
|
|
3243
|
+
* useMessageHistory
|
|
3244
|
+
*
|
|
3245
|
+
* Dual-layer message access with optional compaction.
|
|
3246
|
+
* Strategy 'none' (default) = zero-config, 100% backward-compat.
|
|
3247
|
+
*/
|
|
3248
|
+
|
|
3249
|
+
declare function useMessageHistory(options?: UseMessageHistoryOptions): UseMessageHistoryReturn;
|
|
3250
|
+
|
|
3251
|
+
interface MessageHistoryContextValue {
|
|
3252
|
+
/** Merged config (provider defaults, overridable per-component) */
|
|
3253
|
+
config: Required<Pick<MessageHistoryConfig, "strategy" | "maxContextTokens" | "reserveForResponse" | "compactionThreshold" | "recentBuffer" | "toolResultMaxChars" | "persistSession" | "storageKey">> & MessageHistoryConfig;
|
|
3254
|
+
/** Current token usage (updated after each AI response) */
|
|
3255
|
+
tokenUsage: TokenUsage;
|
|
3256
|
+
/** Current compaction state */
|
|
3257
|
+
compactionState: SessionCompactionState;
|
|
3258
|
+
}
|
|
3259
|
+
declare const defaultMessageHistoryConfig: {
|
|
3260
|
+
strategy: "none";
|
|
3261
|
+
maxContextTokens: number;
|
|
3262
|
+
reserveForResponse: number;
|
|
3263
|
+
compactionThreshold: number;
|
|
3264
|
+
recentBuffer: number;
|
|
3265
|
+
toolResultMaxChars: number;
|
|
3266
|
+
persistSession: boolean;
|
|
3267
|
+
storageKey: string;
|
|
3268
|
+
};
|
|
3269
|
+
declare const MessageHistoryContext: React$1.Context<MessageHistoryContextValue>;
|
|
3270
|
+
declare function useMessageHistoryContext(): MessageHistoryContextValue;
|
|
3271
|
+
|
|
3272
|
+
/**
|
|
3273
|
+
* Message Utilities
|
|
3274
|
+
*
|
|
3275
|
+
* Conversion helpers between UIMessage / DisplayMessage / LLMMessage.
|
|
3276
|
+
* Core invariant: tool-call pairs are always kept atomic.
|
|
3277
|
+
*/
|
|
3278
|
+
|
|
3279
|
+
/**
|
|
3280
|
+
* Promote a UIMessage to a DisplayMessage.
|
|
3281
|
+
* Safe to call on an existing DisplayMessage (idempotent).
|
|
3282
|
+
*/
|
|
3283
|
+
declare function toDisplayMessage(msg: UIMessage): DisplayMessage;
|
|
3284
|
+
/**
|
|
3285
|
+
* Convert a DisplayMessage to the LLMMessage format sent to the model.
|
|
3286
|
+
* CompactionMarkers are converted to system messages with the rolling summary.
|
|
3287
|
+
*/
|
|
3288
|
+
declare function toLLMMessage(msg: DisplayMessage): LLMMessage;
|
|
3289
|
+
/**
|
|
3290
|
+
* Convert an array of DisplayMessages to LLMMessages.
|
|
3291
|
+
*/
|
|
3292
|
+
declare function toLLMMessages(messages: DisplayMessage[]): LLMMessage[];
|
|
3293
|
+
/**
|
|
3294
|
+
* Keep tool-call pairs atomic — an assistant message with tool_calls
|
|
3295
|
+
* must always be followed by its tool-result messages.
|
|
3296
|
+
*
|
|
3297
|
+
* When slicing/pruning, call this to ensure the window boundary never
|
|
3298
|
+
* splits an assistant message from its tool results.
|
|
3299
|
+
*
|
|
3300
|
+
* Returns the input array with any split pairs re-attached at the start.
|
|
3301
|
+
*/
|
|
3302
|
+
declare function keepToolPairsAtomic(messages: DisplayMessage[]): DisplayMessage[];
|
|
3303
|
+
declare function isCompactionMarker(msg: DisplayMessage): msg is CompactionMarker;
|
|
3304
|
+
|
|
3305
|
+
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 MessageHistoryConfig, MessageHistoryContext, type MessageHistoryContextValue, 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 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 UseMessageHistoryOptions, type UseMessageHistoryReturn, type UseSkillStatusReturn, type UseSuggestionsOptions, type UseSuggestionsReturn, type UseThreadManagerConfig, type UseThreadManagerReturn, 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, useDevLogger, useFeatureSupport, useKnowledgeBase, useMCPClient, useMCPTools, useMCPUIIntents, useMessageHistory, useMessageHistoryContext, useSkill, useSkillStatus, useSuggestions, useSupportedMediaTypes, useThreadManager, useTool, useToolExecutor, useToolWithSchema, useTools, useToolsWithSchema };
|