@copilotkitnext/core 0.0.0-max-changeset-20260109174803
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/index.d.mts +644 -0
- package/dist/index.d.ts +644 -0
- package/dist/index.js +1959 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1926 -0
- package/dist/index.mjs.map +1 -0
- package/eslint.config.mjs +3 -0
- package/package.json +50 -0
- package/vitest.config.mjs +15 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,644 @@
|
|
|
1
|
+
import * as _ag_ui_client from '@ag-ui/client';
|
|
2
|
+
import { ToolCall, AbstractAgent, RunAgentResult, Tool, Context, State, Message, HttpAgentConfig, HttpAgent, RunAgentInput, BaseEvent } from '@ag-ui/client';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { Observable } from 'rxjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Status of a tool call execution
|
|
8
|
+
*/
|
|
9
|
+
declare enum ToolCallStatus {
|
|
10
|
+
InProgress = "inProgress",
|
|
11
|
+
Executing = "executing",
|
|
12
|
+
Complete = "complete"
|
|
13
|
+
}
|
|
14
|
+
type CopilotRuntimeTransport = "rest" | "single";
|
|
15
|
+
type FrontendTool<T extends Record<string, unknown> = Record<string, unknown>> = {
|
|
16
|
+
name: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
parameters?: z.ZodType<T>;
|
|
19
|
+
handler?: (args: T, toolCall: ToolCall) => Promise<unknown>;
|
|
20
|
+
followUp?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Optional agent ID to constrain this tool to a specific agent.
|
|
23
|
+
* If specified, this tool will only be available to the specified agent.
|
|
24
|
+
*/
|
|
25
|
+
agentId?: string;
|
|
26
|
+
};
|
|
27
|
+
type Suggestion = {
|
|
28
|
+
title: string;
|
|
29
|
+
message: string;
|
|
30
|
+
/** Indicates whether this suggestion is still being generated. */
|
|
31
|
+
isLoading: boolean;
|
|
32
|
+
};
|
|
33
|
+
type SuggestionAvailability = "before-first-message" | "after-first-message" | "always" | "disabled";
|
|
34
|
+
type DynamicSuggestionsConfig = {
|
|
35
|
+
/**
|
|
36
|
+
* A prompt or instructions for the GPT to generate suggestions.
|
|
37
|
+
*/
|
|
38
|
+
instructions: string;
|
|
39
|
+
/**
|
|
40
|
+
* The minimum number of suggestions to generate. Defaults to `1`.
|
|
41
|
+
* @default 1
|
|
42
|
+
*/
|
|
43
|
+
minSuggestions?: number;
|
|
44
|
+
/**
|
|
45
|
+
* The maximum number of suggestions to generate. Defaults to `3`.
|
|
46
|
+
* @default 1
|
|
47
|
+
*/
|
|
48
|
+
maxSuggestions?: number;
|
|
49
|
+
/**
|
|
50
|
+
* When the suggestions are available. Defaults to "after-first-message".
|
|
51
|
+
*/
|
|
52
|
+
available?: SuggestionAvailability;
|
|
53
|
+
/**
|
|
54
|
+
* The agent ID of the provider of the suggestions. Defaults to `"default"`.
|
|
55
|
+
*/
|
|
56
|
+
providerAgentId?: string;
|
|
57
|
+
/**
|
|
58
|
+
* The agent ID of the consumer of the suggestions. Defaults to `"*"` (all agents).
|
|
59
|
+
*/
|
|
60
|
+
consumerAgentId?: string;
|
|
61
|
+
};
|
|
62
|
+
type StaticSuggestionsConfig = {
|
|
63
|
+
/**
|
|
64
|
+
* The suggestions to display.
|
|
65
|
+
*/
|
|
66
|
+
suggestions: Omit<Suggestion, "isLoading">[];
|
|
67
|
+
/**
|
|
68
|
+
* When the suggestions are available. Defaults to "before-first-message".
|
|
69
|
+
*/
|
|
70
|
+
available?: SuggestionAvailability;
|
|
71
|
+
/**
|
|
72
|
+
* The agent ID of the consumer of the suggestions. Defaults to `"*"` (all agents).
|
|
73
|
+
*/
|
|
74
|
+
consumerAgentId?: string;
|
|
75
|
+
};
|
|
76
|
+
type SuggestionsConfig = DynamicSuggestionsConfig | StaticSuggestionsConfig;
|
|
77
|
+
|
|
78
|
+
interface CopilotKitCoreAddAgentParams {
|
|
79
|
+
id: string;
|
|
80
|
+
agent: AbstractAgent;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Manages agent registration, lifecycle, and runtime connectivity for CopilotKitCore.
|
|
84
|
+
* Handles both local development agents and remote runtime agents.
|
|
85
|
+
*/
|
|
86
|
+
declare class AgentRegistry {
|
|
87
|
+
private core;
|
|
88
|
+
private _agents;
|
|
89
|
+
private localAgents;
|
|
90
|
+
private remoteAgents;
|
|
91
|
+
private _runtimeUrl?;
|
|
92
|
+
private _runtimeVersion?;
|
|
93
|
+
private _runtimeConnectionStatus;
|
|
94
|
+
private _runtimeTransport;
|
|
95
|
+
constructor(core: CopilotKitCore);
|
|
96
|
+
/**
|
|
97
|
+
* Get all agents as a readonly record
|
|
98
|
+
*/
|
|
99
|
+
get agents(): Readonly<Record<string, AbstractAgent>>;
|
|
100
|
+
get runtimeUrl(): string | undefined;
|
|
101
|
+
get runtimeVersion(): string | undefined;
|
|
102
|
+
get runtimeConnectionStatus(): CopilotKitCoreRuntimeConnectionStatus;
|
|
103
|
+
get runtimeTransport(): CopilotRuntimeTransport;
|
|
104
|
+
/**
|
|
105
|
+
* Initialize agents from configuration
|
|
106
|
+
*/
|
|
107
|
+
initialize(agents: Record<string, AbstractAgent>): void;
|
|
108
|
+
/**
|
|
109
|
+
* Set the runtime URL and update connection
|
|
110
|
+
*/
|
|
111
|
+
setRuntimeUrl(runtimeUrl: string | undefined): void;
|
|
112
|
+
setRuntimeTransport(runtimeTransport: CopilotRuntimeTransport): void;
|
|
113
|
+
/**
|
|
114
|
+
* Set all agents at once (for development use)
|
|
115
|
+
*/
|
|
116
|
+
setAgents__unsafe_dev_only(agents: Record<string, AbstractAgent>): void;
|
|
117
|
+
/**
|
|
118
|
+
* Add a single agent (for development use)
|
|
119
|
+
*/
|
|
120
|
+
addAgent__unsafe_dev_only({ id, agent }: CopilotKitCoreAddAgentParams): void;
|
|
121
|
+
/**
|
|
122
|
+
* Remove an agent by ID (for development use)
|
|
123
|
+
*/
|
|
124
|
+
removeAgent__unsafe_dev_only(id: string): void;
|
|
125
|
+
/**
|
|
126
|
+
* Get an agent by ID
|
|
127
|
+
*/
|
|
128
|
+
getAgent(id: string): AbstractAgent | undefined;
|
|
129
|
+
/**
|
|
130
|
+
* Apply current headers to an agent
|
|
131
|
+
*/
|
|
132
|
+
applyHeadersToAgent(agent: AbstractAgent): void;
|
|
133
|
+
/**
|
|
134
|
+
* Apply current headers to all agents
|
|
135
|
+
*/
|
|
136
|
+
applyHeadersToAgents(agents: Record<string, AbstractAgent>): void;
|
|
137
|
+
/**
|
|
138
|
+
* Update runtime connection and fetch remote agents
|
|
139
|
+
*/
|
|
140
|
+
private updateRuntimeConnection;
|
|
141
|
+
private fetchRuntimeInfo;
|
|
142
|
+
/**
|
|
143
|
+
* Assign agent IDs to a record of agents
|
|
144
|
+
*/
|
|
145
|
+
private assignAgentIds;
|
|
146
|
+
/**
|
|
147
|
+
* Validate and assign an agent ID
|
|
148
|
+
*/
|
|
149
|
+
private validateAndAssignAgentId;
|
|
150
|
+
/**
|
|
151
|
+
* Notify subscribers of runtime status changes
|
|
152
|
+
*/
|
|
153
|
+
private notifyRuntimeStatusChanged;
|
|
154
|
+
/**
|
|
155
|
+
* Notify subscribers of agent changes
|
|
156
|
+
*/
|
|
157
|
+
private notifyAgentsChanged;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
interface CopilotKitCoreRunAgentParams {
|
|
161
|
+
agent: AbstractAgent;
|
|
162
|
+
}
|
|
163
|
+
interface CopilotKitCoreConnectAgentParams {
|
|
164
|
+
agent: AbstractAgent;
|
|
165
|
+
}
|
|
166
|
+
interface CopilotKitCoreGetToolParams {
|
|
167
|
+
toolName: string;
|
|
168
|
+
agentId?: string;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Handles agent execution, tool calling, and agent connectivity for CopilotKitCore.
|
|
172
|
+
* Manages the complete lifecycle of agent runs including tool execution and follow-ups.
|
|
173
|
+
*/
|
|
174
|
+
declare class RunHandler {
|
|
175
|
+
private core;
|
|
176
|
+
private _tools;
|
|
177
|
+
constructor(core: CopilotKitCore);
|
|
178
|
+
/**
|
|
179
|
+
* Get all tools as a readonly array
|
|
180
|
+
*/
|
|
181
|
+
get tools(): Readonly<FrontendTool<any>[]>;
|
|
182
|
+
/**
|
|
183
|
+
* Initialize with tools
|
|
184
|
+
*/
|
|
185
|
+
initialize(tools: FrontendTool<any>[]): void;
|
|
186
|
+
/**
|
|
187
|
+
* Add a tool to the registry
|
|
188
|
+
*/
|
|
189
|
+
addTool<T extends Record<string, unknown> = Record<string, unknown>>(tool: FrontendTool<T>): void;
|
|
190
|
+
/**
|
|
191
|
+
* Remove a tool by name and optionally by agentId
|
|
192
|
+
*/
|
|
193
|
+
removeTool(id: string, agentId?: string): void;
|
|
194
|
+
/**
|
|
195
|
+
* Get a tool by name and optionally by agentId.
|
|
196
|
+
* If agentId is provided, it will first look for an agent-specific tool,
|
|
197
|
+
* then fall back to a global tool with the same name.
|
|
198
|
+
*/
|
|
199
|
+
getTool(params: CopilotKitCoreGetToolParams): FrontendTool<any> | undefined;
|
|
200
|
+
/**
|
|
201
|
+
* Set all tools at once. Replaces existing tools.
|
|
202
|
+
*/
|
|
203
|
+
setTools(tools: FrontendTool<any>[]): void;
|
|
204
|
+
/**
|
|
205
|
+
* Connect an agent (establish initial connection)
|
|
206
|
+
*/
|
|
207
|
+
connectAgent({ agent }: CopilotKitCoreConnectAgentParams): Promise<RunAgentResult>;
|
|
208
|
+
/**
|
|
209
|
+
* Run an agent
|
|
210
|
+
*/
|
|
211
|
+
runAgent({ agent }: CopilotKitCoreRunAgentParams): Promise<RunAgentResult>;
|
|
212
|
+
/**
|
|
213
|
+
* Process agent result and execute tools
|
|
214
|
+
*/
|
|
215
|
+
private processAgentResult;
|
|
216
|
+
/**
|
|
217
|
+
* Execute a specific tool
|
|
218
|
+
*/
|
|
219
|
+
private executeSpecificTool;
|
|
220
|
+
/**
|
|
221
|
+
* Execute a wildcard tool
|
|
222
|
+
*/
|
|
223
|
+
private executeWildcardTool;
|
|
224
|
+
/**
|
|
225
|
+
* Build frontend tools for an agent
|
|
226
|
+
*/
|
|
227
|
+
buildFrontendTools(agentId?: string): Tool[];
|
|
228
|
+
/**
|
|
229
|
+
* Create an agent error subscriber
|
|
230
|
+
*/
|
|
231
|
+
private createAgentErrorSubscriber;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** Configuration options for `CopilotKitCore`. */
|
|
235
|
+
interface CopilotKitCoreConfig {
|
|
236
|
+
/** The endpoint of the CopilotRuntime. */
|
|
237
|
+
runtimeUrl?: string;
|
|
238
|
+
/** Transport style for CopilotRuntime endpoints. Defaults to REST. */
|
|
239
|
+
runtimeTransport?: CopilotRuntimeTransport;
|
|
240
|
+
/** Mapping from agent name to its `AbstractAgent` instance. For development only - production requires CopilotRuntime. */
|
|
241
|
+
agents__unsafe_dev_only?: Record<string, AbstractAgent>;
|
|
242
|
+
/** Headers appended to every HTTP request made by `CopilotKitCore`. */
|
|
243
|
+
headers?: Record<string, string>;
|
|
244
|
+
/** Properties sent as `forwardedProps` to the AG-UI agent. */
|
|
245
|
+
properties?: Record<string, unknown>;
|
|
246
|
+
/** Ordered collection of frontend tools available to the core. */
|
|
247
|
+
tools?: FrontendTool<any>[];
|
|
248
|
+
/** Suggestions config for the core. */
|
|
249
|
+
suggestionsConfig?: SuggestionsConfig[];
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
interface CopilotKitCoreStopAgentParams {
|
|
253
|
+
agent: AbstractAgent;
|
|
254
|
+
}
|
|
255
|
+
type CopilotKitCoreGetSuggestionsResult = {
|
|
256
|
+
suggestions: Suggestion[];
|
|
257
|
+
isLoading: boolean;
|
|
258
|
+
};
|
|
259
|
+
declare enum CopilotKitCoreErrorCode {
|
|
260
|
+
RUNTIME_INFO_FETCH_FAILED = "runtime_info_fetch_failed",
|
|
261
|
+
AGENT_CONNECT_FAILED = "agent_connect_failed",
|
|
262
|
+
AGENT_RUN_FAILED = "agent_run_failed",
|
|
263
|
+
AGENT_RUN_FAILED_EVENT = "agent_run_failed_event",
|
|
264
|
+
AGENT_RUN_ERROR_EVENT = "agent_run_error_event",
|
|
265
|
+
TOOL_ARGUMENT_PARSE_FAILED = "tool_argument_parse_failed",
|
|
266
|
+
TOOL_HANDLER_FAILED = "tool_handler_failed"
|
|
267
|
+
}
|
|
268
|
+
interface CopilotKitCoreSubscriber {
|
|
269
|
+
onRuntimeConnectionStatusChanged?: (event: {
|
|
270
|
+
copilotkit: CopilotKitCore;
|
|
271
|
+
status: CopilotKitCoreRuntimeConnectionStatus;
|
|
272
|
+
}) => void | Promise<void>;
|
|
273
|
+
onToolExecutionStart?: (event: {
|
|
274
|
+
copilotkit: CopilotKitCore;
|
|
275
|
+
toolCallId: string;
|
|
276
|
+
agentId: string;
|
|
277
|
+
toolName: string;
|
|
278
|
+
args: unknown;
|
|
279
|
+
}) => void | Promise<void>;
|
|
280
|
+
onToolExecutionEnd?: (event: {
|
|
281
|
+
copilotkit: CopilotKitCore;
|
|
282
|
+
toolCallId: string;
|
|
283
|
+
agentId: string;
|
|
284
|
+
toolName: string;
|
|
285
|
+
result: string;
|
|
286
|
+
error?: string;
|
|
287
|
+
}) => void | Promise<void>;
|
|
288
|
+
onAgentsChanged?: (event: {
|
|
289
|
+
copilotkit: CopilotKitCore;
|
|
290
|
+
agents: Readonly<Record<string, AbstractAgent>>;
|
|
291
|
+
}) => void | Promise<void>;
|
|
292
|
+
onContextChanged?: (event: {
|
|
293
|
+
copilotkit: CopilotKitCore;
|
|
294
|
+
context: Readonly<Record<string, Context>>;
|
|
295
|
+
}) => void | Promise<void>;
|
|
296
|
+
onSuggestionsConfigChanged?: (event: {
|
|
297
|
+
copilotkit: CopilotKitCore;
|
|
298
|
+
suggestionsConfig: Readonly<Record<string, SuggestionsConfig>>;
|
|
299
|
+
}) => void | Promise<void>;
|
|
300
|
+
onSuggestionsChanged?: (event: {
|
|
301
|
+
copilotkit: CopilotKitCore;
|
|
302
|
+
agentId: string;
|
|
303
|
+
suggestions: Suggestion[];
|
|
304
|
+
}) => void | Promise<void>;
|
|
305
|
+
onSuggestionsStartedLoading?: (event: {
|
|
306
|
+
copilotkit: CopilotKitCore;
|
|
307
|
+
agentId: string;
|
|
308
|
+
}) => void | Promise<void>;
|
|
309
|
+
onSuggestionsFinishedLoading?: (event: {
|
|
310
|
+
copilotkit: CopilotKitCore;
|
|
311
|
+
agentId: string;
|
|
312
|
+
}) => void | Promise<void>;
|
|
313
|
+
onPropertiesChanged?: (event: {
|
|
314
|
+
copilotkit: CopilotKitCore;
|
|
315
|
+
properties: Readonly<Record<string, unknown>>;
|
|
316
|
+
}) => void | Promise<void>;
|
|
317
|
+
onHeadersChanged?: (event: {
|
|
318
|
+
copilotkit: CopilotKitCore;
|
|
319
|
+
headers: Readonly<Record<string, string>>;
|
|
320
|
+
}) => void | Promise<void>;
|
|
321
|
+
onError?: (event: {
|
|
322
|
+
copilotkit: CopilotKitCore;
|
|
323
|
+
error: Error;
|
|
324
|
+
code: CopilotKitCoreErrorCode;
|
|
325
|
+
context: Record<string, any>;
|
|
326
|
+
}) => void | Promise<void>;
|
|
327
|
+
}
|
|
328
|
+
interface CopilotKitCoreSubscription {
|
|
329
|
+
unsubscribe: () => void;
|
|
330
|
+
}
|
|
331
|
+
declare enum CopilotKitCoreRuntimeConnectionStatus {
|
|
332
|
+
Disconnected = "disconnected",
|
|
333
|
+
Connected = "connected",
|
|
334
|
+
Connecting = "connecting",
|
|
335
|
+
Error = "error"
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Internal interface for delegate classes to access CopilotKitCore methods.
|
|
339
|
+
* This provides type safety while allowing controlled access to private functionality.
|
|
340
|
+
*/
|
|
341
|
+
interface CopilotKitCoreFriendsAccess {
|
|
342
|
+
notifySubscribers(handler: (subscriber: CopilotKitCoreSubscriber) => void | Promise<void>, errorMessage: string): Promise<void>;
|
|
343
|
+
emitError(params: {
|
|
344
|
+
error: Error;
|
|
345
|
+
code: CopilotKitCoreErrorCode;
|
|
346
|
+
context?: Record<string, any>;
|
|
347
|
+
}): Promise<void>;
|
|
348
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
349
|
+
readonly properties: Readonly<Record<string, unknown>>;
|
|
350
|
+
readonly context: Readonly<Record<string, Context>>;
|
|
351
|
+
buildFrontendTools(agentId?: string): _ag_ui_client.Tool[];
|
|
352
|
+
getAgent(id: string): AbstractAgent | undefined;
|
|
353
|
+
readonly suggestionEngine: {
|
|
354
|
+
clearSuggestions(agentId: string): void;
|
|
355
|
+
reloadSuggestions(agentId: string): void;
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
declare class CopilotKitCore {
|
|
359
|
+
private _headers;
|
|
360
|
+
private _properties;
|
|
361
|
+
private subscribers;
|
|
362
|
+
private agentRegistry;
|
|
363
|
+
private contextStore;
|
|
364
|
+
private suggestionEngine;
|
|
365
|
+
private runHandler;
|
|
366
|
+
private stateManager;
|
|
367
|
+
constructor({ runtimeUrl, runtimeTransport, headers, properties, agents__unsafe_dev_only, tools, suggestionsConfig, }: CopilotKitCoreConfig);
|
|
368
|
+
/**
|
|
369
|
+
* Internal method used by delegate classes and subclasses to notify subscribers
|
|
370
|
+
*/
|
|
371
|
+
protected notifySubscribers(handler: (subscriber: CopilotKitCoreSubscriber) => void | Promise<void>, errorMessage: string): Promise<void>;
|
|
372
|
+
/**
|
|
373
|
+
* Internal method used by delegate classes to emit errors
|
|
374
|
+
*/
|
|
375
|
+
private emitError;
|
|
376
|
+
/**
|
|
377
|
+
* Snapshot accessors
|
|
378
|
+
*/
|
|
379
|
+
get context(): Readonly<Record<string, Context>>;
|
|
380
|
+
get agents(): Readonly<Record<string, AbstractAgent>>;
|
|
381
|
+
get tools(): Readonly<FrontendTool<any>[]>;
|
|
382
|
+
get runtimeUrl(): string | undefined;
|
|
383
|
+
setRuntimeUrl(runtimeUrl: string | undefined): void;
|
|
384
|
+
get runtimeTransport(): CopilotRuntimeTransport;
|
|
385
|
+
setRuntimeTransport(runtimeTransport: CopilotRuntimeTransport): void;
|
|
386
|
+
get runtimeVersion(): string | undefined;
|
|
387
|
+
get headers(): Readonly<Record<string, string>>;
|
|
388
|
+
get properties(): Readonly<Record<string, unknown>>;
|
|
389
|
+
get runtimeConnectionStatus(): CopilotKitCoreRuntimeConnectionStatus;
|
|
390
|
+
/**
|
|
391
|
+
* Configuration updates
|
|
392
|
+
*/
|
|
393
|
+
setHeaders(headers: Record<string, string>): void;
|
|
394
|
+
setProperties(properties: Record<string, unknown>): void;
|
|
395
|
+
/**
|
|
396
|
+
* Agent management (delegated to AgentRegistry)
|
|
397
|
+
*/
|
|
398
|
+
setAgents__unsafe_dev_only(agents: Record<string, AbstractAgent>): void;
|
|
399
|
+
addAgent__unsafe_dev_only(params: CopilotKitCoreAddAgentParams): void;
|
|
400
|
+
removeAgent__unsafe_dev_only(id: string): void;
|
|
401
|
+
getAgent(id: string): AbstractAgent | undefined;
|
|
402
|
+
/**
|
|
403
|
+
* Context management (delegated to ContextStore)
|
|
404
|
+
*/
|
|
405
|
+
addContext(context: Context): string;
|
|
406
|
+
removeContext(id: string): void;
|
|
407
|
+
/**
|
|
408
|
+
* Suggestions management (delegated to SuggestionEngine)
|
|
409
|
+
*/
|
|
410
|
+
addSuggestionsConfig(config: SuggestionsConfig): string;
|
|
411
|
+
removeSuggestionsConfig(id: string): void;
|
|
412
|
+
reloadSuggestions(agentId: string): void;
|
|
413
|
+
clearSuggestions(agentId: string): void;
|
|
414
|
+
getSuggestions(agentId: string): CopilotKitCoreGetSuggestionsResult;
|
|
415
|
+
/**
|
|
416
|
+
* Tool management (delegated to RunHandler)
|
|
417
|
+
*/
|
|
418
|
+
addTool<T extends Record<string, unknown> = Record<string, unknown>>(tool: FrontendTool<T>): void;
|
|
419
|
+
removeTool(id: string, agentId?: string): void;
|
|
420
|
+
getTool(params: CopilotKitCoreGetToolParams): FrontendTool<any> | undefined;
|
|
421
|
+
setTools(tools: FrontendTool<any>[]): void;
|
|
422
|
+
/**
|
|
423
|
+
* Subscription lifecycle
|
|
424
|
+
*/
|
|
425
|
+
subscribe(subscriber: CopilotKitCoreSubscriber): CopilotKitCoreSubscription;
|
|
426
|
+
/**
|
|
427
|
+
* Agent connectivity (delegated to RunHandler)
|
|
428
|
+
*/
|
|
429
|
+
connectAgent(params: CopilotKitCoreConnectAgentParams): Promise<_ag_ui_client.RunAgentResult>;
|
|
430
|
+
stopAgent(params: CopilotKitCoreStopAgentParams): void;
|
|
431
|
+
runAgent(params: CopilotKitCoreRunAgentParams): Promise<_ag_ui_client.RunAgentResult>;
|
|
432
|
+
/**
|
|
433
|
+
* State management (delegated to StateManager)
|
|
434
|
+
*/
|
|
435
|
+
getStateByRun(agentId: string, threadId: string, runId: string): State | undefined;
|
|
436
|
+
getRunIdForMessage(agentId: string, threadId: string, messageId: string): string | undefined;
|
|
437
|
+
getRunIdsForThread(agentId: string, threadId: string): string[];
|
|
438
|
+
/**
|
|
439
|
+
* Internal method used by RunHandler to build frontend tools
|
|
440
|
+
*/
|
|
441
|
+
private buildFrontendTools;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Manages context storage and lifecycle for CopilotKitCore.
|
|
446
|
+
* Context represents additional information available to agents during execution.
|
|
447
|
+
*/
|
|
448
|
+
declare class ContextStore {
|
|
449
|
+
private core;
|
|
450
|
+
private _context;
|
|
451
|
+
constructor(core: CopilotKitCore);
|
|
452
|
+
/**
|
|
453
|
+
* Get all context entries as a readonly record
|
|
454
|
+
*/
|
|
455
|
+
get context(): Readonly<Record<string, Context>>;
|
|
456
|
+
/**
|
|
457
|
+
* Add a new context entry
|
|
458
|
+
* @returns The ID of the created context entry
|
|
459
|
+
*/
|
|
460
|
+
addContext({ description, value }: Context): string;
|
|
461
|
+
/**
|
|
462
|
+
* Remove a context entry by ID
|
|
463
|
+
*/
|
|
464
|
+
removeContext(id: string): void;
|
|
465
|
+
/**
|
|
466
|
+
* Notify all subscribers of context changes
|
|
467
|
+
*/
|
|
468
|
+
private notifySubscribers;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* Manages suggestion generation, streaming, and lifecycle for CopilotKitCore.
|
|
473
|
+
* Handles both dynamic (AI-generated) and static suggestions.
|
|
474
|
+
*/
|
|
475
|
+
declare class SuggestionEngine {
|
|
476
|
+
private core;
|
|
477
|
+
private _suggestionsConfig;
|
|
478
|
+
private _suggestions;
|
|
479
|
+
private _runningSuggestions;
|
|
480
|
+
constructor(core: CopilotKitCore);
|
|
481
|
+
/**
|
|
482
|
+
* Initialize with suggestion configs
|
|
483
|
+
*/
|
|
484
|
+
initialize(suggestionsConfig: SuggestionsConfig[]): void;
|
|
485
|
+
/**
|
|
486
|
+
* Add a suggestion configuration
|
|
487
|
+
* @returns The ID of the created config
|
|
488
|
+
*/
|
|
489
|
+
addSuggestionsConfig(config: SuggestionsConfig): string;
|
|
490
|
+
/**
|
|
491
|
+
* Remove a suggestion configuration by ID
|
|
492
|
+
*/
|
|
493
|
+
removeSuggestionsConfig(id: string): void;
|
|
494
|
+
/**
|
|
495
|
+
* Reload suggestions for a specific agent
|
|
496
|
+
* This triggers generation of new suggestions based on current configs
|
|
497
|
+
*/
|
|
498
|
+
reloadSuggestions(agentId: string): void;
|
|
499
|
+
/**
|
|
500
|
+
* Clear all suggestions for a specific agent
|
|
501
|
+
*/
|
|
502
|
+
clearSuggestions(agentId: string): void;
|
|
503
|
+
/**
|
|
504
|
+
* Get current suggestions for an agent
|
|
505
|
+
*/
|
|
506
|
+
getSuggestions(agentId: string): CopilotKitCoreGetSuggestionsResult;
|
|
507
|
+
/**
|
|
508
|
+
* Generate suggestions using a provider agent
|
|
509
|
+
*/
|
|
510
|
+
private generateSuggestions;
|
|
511
|
+
/**
|
|
512
|
+
* Finalize suggestions by marking them as no longer loading
|
|
513
|
+
*/
|
|
514
|
+
private finalizeSuggestions;
|
|
515
|
+
/**
|
|
516
|
+
* Extract suggestions from messages (called during streaming)
|
|
517
|
+
*/
|
|
518
|
+
extractSuggestions(messages: Message[], suggestionId: string, consumerAgentId: string, isRunning: boolean): void;
|
|
519
|
+
/**
|
|
520
|
+
* Notify subscribers of suggestions config changes
|
|
521
|
+
*/
|
|
522
|
+
private notifySuggestionsConfigChanged;
|
|
523
|
+
/**
|
|
524
|
+
* Notify subscribers of suggestions changes
|
|
525
|
+
*/
|
|
526
|
+
private notifySuggestionsChanged;
|
|
527
|
+
/**
|
|
528
|
+
* Notify subscribers that suggestions started loading
|
|
529
|
+
*/
|
|
530
|
+
private notifySuggestionsStartedLoading;
|
|
531
|
+
/**
|
|
532
|
+
* Notify subscribers that suggestions finished loading
|
|
533
|
+
*/
|
|
534
|
+
private notifySuggestionsFinishedLoading;
|
|
535
|
+
/**
|
|
536
|
+
* Check if suggestions should be shown based on availability and message count
|
|
537
|
+
*/
|
|
538
|
+
private shouldShowSuggestions;
|
|
539
|
+
/**
|
|
540
|
+
* Add static suggestions directly without AI generation
|
|
541
|
+
*/
|
|
542
|
+
private addStaticSuggestions;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* Manages state and message tracking by run for CopilotKitCore.
|
|
547
|
+
* Tracks agent state snapshots and message-to-run associations.
|
|
548
|
+
*/
|
|
549
|
+
declare class StateManager {
|
|
550
|
+
private core;
|
|
551
|
+
private stateByRun;
|
|
552
|
+
private messageToRun;
|
|
553
|
+
private agentSubscriptions;
|
|
554
|
+
constructor(core: CopilotKitCore);
|
|
555
|
+
/**
|
|
556
|
+
* Initialize state tracking for an agent
|
|
557
|
+
*/
|
|
558
|
+
initialize(): void;
|
|
559
|
+
/**
|
|
560
|
+
* Subscribe to an agent's events to track state and messages
|
|
561
|
+
*/
|
|
562
|
+
subscribeToAgent(agent: AbstractAgent): void;
|
|
563
|
+
/**
|
|
564
|
+
* Unsubscribe from an agent's events
|
|
565
|
+
*/
|
|
566
|
+
unsubscribeFromAgent(agentId: string): void;
|
|
567
|
+
/**
|
|
568
|
+
* Get state for a specific run
|
|
569
|
+
* Returns a deep copy to prevent external mutations
|
|
570
|
+
*/
|
|
571
|
+
getStateByRun(agentId: string, threadId: string, runId: string): State | undefined;
|
|
572
|
+
/**
|
|
573
|
+
* Get runId associated with a message
|
|
574
|
+
*/
|
|
575
|
+
getRunIdForMessage(agentId: string, threadId: string, messageId: string): string | undefined;
|
|
576
|
+
/**
|
|
577
|
+
* Get all states for an agent's thread
|
|
578
|
+
*/
|
|
579
|
+
getStatesForThread(agentId: string, threadId: string): Map<string, State>;
|
|
580
|
+
/**
|
|
581
|
+
* Get all run IDs for an agent's thread
|
|
582
|
+
*/
|
|
583
|
+
getRunIdsForThread(agentId: string, threadId: string): string[];
|
|
584
|
+
/**
|
|
585
|
+
* Handle run started event
|
|
586
|
+
*/
|
|
587
|
+
private handleRunStarted;
|
|
588
|
+
/**
|
|
589
|
+
* Handle run finished event
|
|
590
|
+
*/
|
|
591
|
+
private handleRunFinished;
|
|
592
|
+
/**
|
|
593
|
+
* Handle state snapshot event
|
|
594
|
+
*/
|
|
595
|
+
private handleStateSnapshot;
|
|
596
|
+
/**
|
|
597
|
+
* Handle state delta event
|
|
598
|
+
*/
|
|
599
|
+
private handleStateDelta;
|
|
600
|
+
/**
|
|
601
|
+
* Handle messages snapshot event
|
|
602
|
+
*/
|
|
603
|
+
private handleMessagesSnapshot;
|
|
604
|
+
/**
|
|
605
|
+
* Handle new message event
|
|
606
|
+
*/
|
|
607
|
+
private handleNewMessage;
|
|
608
|
+
/**
|
|
609
|
+
* Save state for a specific run
|
|
610
|
+
*/
|
|
611
|
+
private saveState;
|
|
612
|
+
/**
|
|
613
|
+
* Associate a message with a run
|
|
614
|
+
*/
|
|
615
|
+
private associateMessageWithRun;
|
|
616
|
+
/**
|
|
617
|
+
* Clear all state for an agent
|
|
618
|
+
*/
|
|
619
|
+
clearAgentState(agentId: string): void;
|
|
620
|
+
/**
|
|
621
|
+
* Clear all state for a thread
|
|
622
|
+
*/
|
|
623
|
+
clearThreadState(agentId: string, threadId: string): void;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
interface ProxiedCopilotRuntimeAgentConfig extends Omit<HttpAgentConfig, "url"> {
|
|
627
|
+
runtimeUrl?: string;
|
|
628
|
+
transport?: CopilotRuntimeTransport;
|
|
629
|
+
}
|
|
630
|
+
declare class ProxiedCopilotRuntimeAgent extends HttpAgent {
|
|
631
|
+
runtimeUrl?: string;
|
|
632
|
+
private transport;
|
|
633
|
+
private singleEndpointUrl?;
|
|
634
|
+
constructor(config: ProxiedCopilotRuntimeAgentConfig);
|
|
635
|
+
abortRun(): void;
|
|
636
|
+
connect(input: RunAgentInput): Observable<BaseEvent>;
|
|
637
|
+
run(input: RunAgentInput): Observable<BaseEvent>;
|
|
638
|
+
clone(): ProxiedCopilotRuntimeAgent;
|
|
639
|
+
private createSingleRouteRequestInit;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
declare function completePartialMarkdown(input: string): string;
|
|
643
|
+
|
|
644
|
+
export { AgentRegistry, ContextStore, CopilotKitCore, type CopilotKitCoreAddAgentParams, type CopilotKitCoreConfig, type CopilotKitCoreConnectAgentParams, CopilotKitCoreErrorCode, type CopilotKitCoreFriendsAccess, type CopilotKitCoreGetSuggestionsResult, type CopilotKitCoreGetToolParams, type CopilotKitCoreRunAgentParams, CopilotKitCoreRuntimeConnectionStatus, type CopilotKitCoreStopAgentParams, type CopilotKitCoreSubscriber, type CopilotKitCoreSubscription, type CopilotRuntimeTransport, type DynamicSuggestionsConfig, type FrontendTool, ProxiedCopilotRuntimeAgent, type ProxiedCopilotRuntimeAgentConfig, RunHandler, StateManager, type StaticSuggestionsConfig, type Suggestion, type SuggestionAvailability, SuggestionEngine, type SuggestionsConfig, ToolCallStatus, completePartialMarkdown };
|