@copilotkitnext/core 0.0.11 → 0.0.13-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/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { ToolCall, AbstractAgent, Message, Context, RunAgentResult, HttpAgentConfig, HttpAgent, RunAgentInput, BaseEvent } from '@ag-ui/client';
1
+ import * as _ag_ui_client from '@ag-ui/client';
2
+ import { ToolCall, AbstractAgent, Message, RunAgentResult, Tool, Context, HttpAgentConfig, HttpAgent, RunAgentInput, BaseEvent } from '@ag-ui/client';
2
3
  import { z } from 'zod';
3
4
  import { Observable } from 'rxjs';
4
5
 
@@ -22,37 +23,230 @@ type FrontendTool<T extends Record<string, unknown> = Record<string, unknown>> =
22
23
  */
23
24
  agentId?: string;
24
25
  };
26
+ type Suggestion = {
27
+ title: string;
28
+ message: string;
29
+ /** Indicates whether this suggestion is still being generated. */
30
+ isLoading: boolean;
31
+ };
32
+ type SuggestionAvailability = "before-first-message" | "after-first-message" | "always" | "disabled";
33
+ type DynamicSuggestionsConfig = {
34
+ /**
35
+ * A prompt or instructions for the GPT to generate suggestions.
36
+ */
37
+ instructions: string;
38
+ /**
39
+ * The minimum number of suggestions to generate. Defaults to `1`.
40
+ * @default 1
41
+ */
42
+ minSuggestions?: number;
43
+ /**
44
+ * The maximum number of suggestions to generate. Defaults to `3`.
45
+ * @default 1
46
+ */
47
+ maxSuggestions?: number;
48
+ /**
49
+ * When the suggestions are available. Defaults to "after-first-message".
50
+ */
51
+ available?: SuggestionAvailability;
52
+ /**
53
+ * The agent ID of the provider of the suggestions. Defaults to `"default"`.
54
+ */
55
+ providerAgentId?: string;
56
+ /**
57
+ * The agent ID of the consumer of the suggestions. Defaults to `"*"` (all agents).
58
+ */
59
+ consumerAgentId?: string;
60
+ };
61
+ type StaticSuggestionsConfig = {
62
+ /**
63
+ * The suggestions to display.
64
+ */
65
+ suggestions: Omit<Suggestion, "isLoading">[];
66
+ /**
67
+ * When the suggestions are available. Defaults to "before-first-message".
68
+ */
69
+ available?: SuggestionAvailability;
70
+ /**
71
+ * The agent ID of the consumer of the suggestions. Defaults to `"*"` (all agents).
72
+ */
73
+ consumerAgentId?: string;
74
+ };
75
+ type SuggestionsConfig = DynamicSuggestionsConfig | StaticSuggestionsConfig;
25
76
 
26
- /** Configuration options for `CopilotKitCore`. */
27
- interface CopilotKitCoreConfig {
28
- /** The endpoint of the CopilotRuntime. */
29
- runtimeUrl?: string;
30
- /** Mapping from agent name to its `AbstractAgent` instance. */
31
- agents?: Record<string, AbstractAgent>;
32
- /** Headers appended to every HTTP request made by `CopilotKitCore`. */
33
- headers?: Record<string, string>;
34
- /** Properties sent as `forwardedProps` to the AG-UI agent. */
35
- properties?: Record<string, unknown>;
36
- /** Ordered collection of frontend tools available to the core. */
37
- tools?: FrontendTool<any>[];
38
- }
39
77
  interface CopilotKitCoreAddAgentParams {
40
78
  id: string;
41
79
  agent: AbstractAgent;
42
80
  }
81
+ /**
82
+ * Manages agent registration, lifecycle, and runtime connectivity for CopilotKitCore.
83
+ * Handles both local development agents and remote runtime agents.
84
+ */
85
+ declare class AgentRegistry {
86
+ private core;
87
+ private _agents;
88
+ private localAgents;
89
+ private remoteAgents;
90
+ private _runtimeUrl?;
91
+ private _runtimeVersion?;
92
+ private _runtimeConnectionStatus;
93
+ constructor(core: CopilotKitCore);
94
+ /**
95
+ * Get all agents as a readonly record
96
+ */
97
+ get agents(): Readonly<Record<string, AbstractAgent>>;
98
+ get runtimeUrl(): string | undefined;
99
+ get runtimeVersion(): string | undefined;
100
+ get runtimeConnectionStatus(): CopilotKitCoreRuntimeConnectionStatus;
101
+ /**
102
+ * Initialize agents from configuration
103
+ */
104
+ initialize(agents: Record<string, AbstractAgent>): void;
105
+ /**
106
+ * Set the runtime URL and update connection
107
+ */
108
+ setRuntimeUrl(runtimeUrl: string | undefined): void;
109
+ /**
110
+ * Set all agents at once (for development use)
111
+ */
112
+ setAgents__unsafe_dev_only(agents: Record<string, AbstractAgent>): void;
113
+ /**
114
+ * Add a single agent (for development use)
115
+ */
116
+ addAgent__unsafe_dev_only({ id, agent }: CopilotKitCoreAddAgentParams): void;
117
+ /**
118
+ * Remove an agent by ID (for development use)
119
+ */
120
+ removeAgent__unsafe_dev_only(id: string): void;
121
+ /**
122
+ * Get an agent by ID
123
+ */
124
+ getAgent(id: string): AbstractAgent | undefined;
125
+ /**
126
+ * Apply current headers to an agent
127
+ */
128
+ applyHeadersToAgent(agent: AbstractAgent): void;
129
+ /**
130
+ * Apply current headers to all agents
131
+ */
132
+ applyHeadersToAgents(agents: Record<string, AbstractAgent>): void;
133
+ /**
134
+ * Update runtime connection and fetch remote agents
135
+ */
136
+ private updateRuntimeConnection;
137
+ /**
138
+ * Assign agent IDs to a record of agents
139
+ */
140
+ private assignAgentIds;
141
+ /**
142
+ * Validate and assign an agent ID
143
+ */
144
+ private validateAndAssignAgentId;
145
+ /**
146
+ * Notify subscribers of runtime status changes
147
+ */
148
+ private notifyRuntimeStatusChanged;
149
+ /**
150
+ * Notify subscribers of agent changes
151
+ */
152
+ private notifyAgentsChanged;
153
+ }
154
+
43
155
  interface CopilotKitCoreRunAgentParams {
44
156
  agent: AbstractAgent;
45
157
  withMessages?: Message[];
46
- agentId?: string;
47
158
  }
48
159
  interface CopilotKitCoreConnectAgentParams {
49
160
  agent: AbstractAgent;
50
- agentId?: string;
51
161
  }
52
162
  interface CopilotKitCoreGetToolParams {
53
163
  toolName: string;
54
164
  agentId?: string;
55
165
  }
166
+ /**
167
+ * Handles agent execution, tool calling, and agent connectivity for CopilotKitCore.
168
+ * Manages the complete lifecycle of agent runs including tool execution and follow-ups.
169
+ */
170
+ declare class RunHandler {
171
+ private core;
172
+ private _tools;
173
+ constructor(core: CopilotKitCore);
174
+ /**
175
+ * Get all tools as a readonly array
176
+ */
177
+ get tools(): Readonly<FrontendTool<any>[]>;
178
+ /**
179
+ * Initialize with tools
180
+ */
181
+ initialize(tools: FrontendTool<any>[]): void;
182
+ /**
183
+ * Add a tool to the registry
184
+ */
185
+ addTool<T extends Record<string, unknown> = Record<string, unknown>>(tool: FrontendTool<T>): void;
186
+ /**
187
+ * Remove a tool by name and optionally by agentId
188
+ */
189
+ removeTool(id: string, agentId?: string): void;
190
+ /**
191
+ * Get a tool by name and optionally by agentId.
192
+ * If agentId is provided, it will first look for an agent-specific tool,
193
+ * then fall back to a global tool with the same name.
194
+ */
195
+ getTool(params: CopilotKitCoreGetToolParams): FrontendTool<any> | undefined;
196
+ /**
197
+ * Set all tools at once. Replaces existing tools.
198
+ */
199
+ setTools(tools: FrontendTool<any>[]): void;
200
+ /**
201
+ * Connect an agent (establish initial connection)
202
+ */
203
+ connectAgent({ agent }: CopilotKitCoreConnectAgentParams): Promise<RunAgentResult>;
204
+ /**
205
+ * Run an agent
206
+ */
207
+ runAgent({ agent, withMessages }: CopilotKitCoreRunAgentParams): Promise<RunAgentResult>;
208
+ /**
209
+ * Process agent result and execute tools
210
+ */
211
+ private processAgentResult;
212
+ /**
213
+ * Execute a specific tool
214
+ */
215
+ private executeSpecificTool;
216
+ /**
217
+ * Execute a wildcard tool
218
+ */
219
+ private executeWildcardTool;
220
+ /**
221
+ * Build frontend tools for an agent
222
+ */
223
+ buildFrontendTools(agentId?: string): Tool[];
224
+ /**
225
+ * Create an agent error subscriber
226
+ */
227
+ private createAgentErrorSubscriber;
228
+ }
229
+
230
+ /** Configuration options for `CopilotKitCore`. */
231
+ interface CopilotKitCoreConfig {
232
+ /** The endpoint of the CopilotRuntime. */
233
+ runtimeUrl?: string;
234
+ /** Mapping from agent name to its `AbstractAgent` instance. For development only - production requires CopilotRuntime. */
235
+ agents__unsafe_dev_only?: Record<string, AbstractAgent>;
236
+ /** Headers appended to every HTTP request made by `CopilotKitCore`. */
237
+ headers?: Record<string, string>;
238
+ /** Properties sent as `forwardedProps` to the AG-UI agent. */
239
+ properties?: Record<string, unknown>;
240
+ /** Ordered collection of frontend tools available to the core. */
241
+ tools?: FrontendTool<any>[];
242
+ /** Suggestions config for the core. */
243
+ suggestionsConfig?: SuggestionsConfig[];
244
+ }
245
+
246
+ type CopilotKitCoreGetSuggestionsResult = {
247
+ suggestions: Suggestion[];
248
+ isLoading: boolean;
249
+ };
56
250
  declare enum CopilotKitCoreErrorCode {
57
251
  RUNTIME_INFO_FETCH_FAILED = "runtime_info_fetch_failed",
58
252
  AGENT_CONNECT_FAILED = "agent_connect_failed",
@@ -90,6 +284,23 @@ interface CopilotKitCoreSubscriber {
90
284
  copilotkit: CopilotKitCore;
91
285
  context: Readonly<Record<string, Context>>;
92
286
  }) => void | Promise<void>;
287
+ onSuggestionsConfigChanged?: (event: {
288
+ copilotkit: CopilotKitCore;
289
+ suggestionsConfig: Readonly<Record<string, SuggestionsConfig>>;
290
+ }) => void | Promise<void>;
291
+ onSuggestionsChanged?: (event: {
292
+ copilotkit: CopilotKitCore;
293
+ agentId: string;
294
+ suggestions: Suggestion[];
295
+ }) => void | Promise<void>;
296
+ onSuggestionsStartedLoading?: (event: {
297
+ copilotkit: CopilotKitCore;
298
+ agentId: string;
299
+ }) => void | Promise<void>;
300
+ onSuggestionsFinishedLoading?: (event: {
301
+ copilotkit: CopilotKitCore;
302
+ agentId: string;
303
+ }) => void | Promise<void>;
93
304
  onPropertiesChanged?: (event: {
94
305
  copilotkit: CopilotKitCore;
95
306
  properties: Readonly<Record<string, unknown>>;
@@ -112,24 +323,22 @@ declare enum CopilotKitCoreRuntimeConnectionStatus {
112
323
  Error = "error"
113
324
  }
114
325
  declare class CopilotKitCore {
115
- headers: Record<string, string>;
116
- properties: Record<string, unknown>;
117
- private _context;
118
- private _agents;
119
- private _tools;
120
- private localAgents;
121
- private remoteAgents;
326
+ private _headers;
327
+ private _properties;
122
328
  private subscribers;
123
- private _runtimeUrl?;
124
- private _runtimeVersion?;
125
- private _runtimeConnectionStatus;
126
- constructor({ runtimeUrl, headers, properties, agents, tools, }: CopilotKitCoreConfig);
127
- private applyHeadersToAgent;
128
- private applyHeadersToAgents;
129
- private assignAgentIds;
329
+ private agentRegistry;
330
+ private contextStore;
331
+ private suggestionEngine;
332
+ private runHandler;
333
+ constructor({ runtimeUrl, headers, properties, agents__unsafe_dev_only, tools, suggestionsConfig, }: CopilotKitCoreConfig);
334
+ /**
335
+ * Internal method used by delegate classes to notify subscribers
336
+ */
130
337
  private notifySubscribers;
338
+ /**
339
+ * Internal method used by delegate classes to emit errors
340
+ */
131
341
  private emitError;
132
- private resolveAgentId;
133
342
  /**
134
343
  * Snapshot accessors
135
344
  */
@@ -139,39 +348,40 @@ declare class CopilotKitCore {
139
348
  get runtimeUrl(): string | undefined;
140
349
  setRuntimeUrl(runtimeUrl: string | undefined): void;
141
350
  get runtimeVersion(): string | undefined;
351
+ get headers(): Readonly<Record<string, string>>;
352
+ get properties(): Readonly<Record<string, unknown>>;
142
353
  get runtimeConnectionStatus(): CopilotKitCoreRuntimeConnectionStatus;
143
- /**
144
- * Runtime connection
145
- */
146
- private updateRuntimeConnection;
147
354
  /**
148
355
  * Configuration updates
149
356
  */
150
357
  setHeaders(headers: Record<string, string>): void;
151
358
  setProperties(properties: Record<string, unknown>): void;
152
- setAgents(agents: Record<string, AbstractAgent>): void;
153
- addAgent({ id, agent }: CopilotKitCoreAddAgentParams): void;
154
- removeAgent(id: string): void;
359
+ /**
360
+ * Agent management (delegated to AgentRegistry)
361
+ */
362
+ setAgents__unsafe_dev_only(agents: Record<string, AbstractAgent>): void;
363
+ addAgent__unsafe_dev_only(params: CopilotKitCoreAddAgentParams): void;
364
+ removeAgent__unsafe_dev_only(id: string): void;
155
365
  getAgent(id: string): AbstractAgent | undefined;
156
366
  /**
157
- * Context management
367
+ * Context management (delegated to ContextStore)
158
368
  */
159
- addContext({ description, value }: Context): string;
369
+ addContext(context: Context): string;
160
370
  removeContext(id: string): void;
161
371
  /**
162
- * Tool management
372
+ * Suggestions management (delegated to SuggestionEngine)
163
373
  */
164
- addTool<T extends Record<string, unknown> = Record<string, unknown>>(tool: FrontendTool<T>): void;
165
- removeTool(id: string, agentId?: string): void;
374
+ addSuggestionsConfig(config: SuggestionsConfig): string;
375
+ removeSuggestionsConfig(id: string): void;
376
+ reloadSuggestions(agentId: string): void;
377
+ clearSuggestions(agentId: string): void;
378
+ getSuggestions(agentId: string): CopilotKitCoreGetSuggestionsResult;
166
379
  /**
167
- * Get a tool by name and optionally by agentId.
168
- * If agentId is provided, it will first look for an agent-specific tool,
169
- * then fall back to a global tool with the same name.
380
+ * Tool management (delegated to RunHandler)
170
381
  */
382
+ addTool<T extends Record<string, unknown> = Record<string, unknown>>(tool: FrontendTool<T>): void;
383
+ removeTool(id: string, agentId?: string): void;
171
384
  getTool(params: CopilotKitCoreGetToolParams): FrontendTool<any> | undefined;
172
- /**
173
- * Set all tools at once. Replaces existing tools.
174
- */
175
385
  setTools(tools: FrontendTool<any>[]): void;
176
386
  /**
177
387
  * Subscription lifecycle
@@ -179,13 +389,115 @@ declare class CopilotKitCore {
179
389
  subscribe(subscriber: CopilotKitCoreSubscriber): () => void;
180
390
  unsubscribe(subscriber: CopilotKitCoreSubscriber): void;
181
391
  /**
182
- * Agent connectivity
392
+ * Agent connectivity (delegated to RunHandler)
393
+ */
394
+ connectAgent(params: CopilotKitCoreConnectAgentParams): Promise<_ag_ui_client.RunAgentResult>;
395
+ runAgent(params: CopilotKitCoreRunAgentParams): Promise<_ag_ui_client.RunAgentResult>;
396
+ /**
397
+ * Internal method used by RunHandler to build frontend tools
183
398
  */
184
- connectAgent({ agent, agentId, }: CopilotKitCoreConnectAgentParams): Promise<RunAgentResult>;
185
- runAgent({ agent, withMessages, agentId, }: CopilotKitCoreRunAgentParams): Promise<RunAgentResult>;
186
- private processAgentResult;
187
399
  private buildFrontendTools;
188
- private createAgentErrorSubscriber;
400
+ }
401
+
402
+ /**
403
+ * Manages context storage and lifecycle for CopilotKitCore.
404
+ * Context represents additional information available to agents during execution.
405
+ */
406
+ declare class ContextStore {
407
+ private core;
408
+ private _context;
409
+ constructor(core: CopilotKitCore);
410
+ /**
411
+ * Get all context entries as a readonly record
412
+ */
413
+ get context(): Readonly<Record<string, Context>>;
414
+ /**
415
+ * Add a new context entry
416
+ * @returns The ID of the created context entry
417
+ */
418
+ addContext({ description, value }: Context): string;
419
+ /**
420
+ * Remove a context entry by ID
421
+ */
422
+ removeContext(id: string): void;
423
+ /**
424
+ * Notify all subscribers of context changes
425
+ */
426
+ private notifySubscribers;
427
+ }
428
+
429
+ /**
430
+ * Manages suggestion generation, streaming, and lifecycle for CopilotKitCore.
431
+ * Handles both dynamic (AI-generated) and static suggestions.
432
+ */
433
+ declare class SuggestionEngine {
434
+ private core;
435
+ private _suggestionsConfig;
436
+ private _suggestions;
437
+ private _runningSuggestions;
438
+ constructor(core: CopilotKitCore);
439
+ /**
440
+ * Initialize with suggestion configs
441
+ */
442
+ initialize(suggestionsConfig: SuggestionsConfig[]): void;
443
+ /**
444
+ * Add a suggestion configuration
445
+ * @returns The ID of the created config
446
+ */
447
+ addSuggestionsConfig(config: SuggestionsConfig): string;
448
+ /**
449
+ * Remove a suggestion configuration by ID
450
+ */
451
+ removeSuggestionsConfig(id: string): void;
452
+ /**
453
+ * Reload suggestions for a specific agent
454
+ * This triggers generation of new suggestions based on current configs
455
+ */
456
+ reloadSuggestions(agentId: string): void;
457
+ /**
458
+ * Clear all suggestions for a specific agent
459
+ */
460
+ clearSuggestions(agentId: string): void;
461
+ /**
462
+ * Get current suggestions for an agent
463
+ */
464
+ getSuggestions(agentId: string): CopilotKitCoreGetSuggestionsResult;
465
+ /**
466
+ * Generate suggestions using a provider agent
467
+ */
468
+ private generateSuggestions;
469
+ /**
470
+ * Finalize suggestions by marking them as no longer loading
471
+ */
472
+ private finalizeSuggestions;
473
+ /**
474
+ * Extract suggestions from messages (called during streaming)
475
+ */
476
+ extractSuggestions(messages: Message[], suggestionId: string, consumerAgentId: string, isRunning: boolean): void;
477
+ /**
478
+ * Notify subscribers of suggestions config changes
479
+ */
480
+ private notifySuggestionsConfigChanged;
481
+ /**
482
+ * Notify subscribers of suggestions changes
483
+ */
484
+ private notifySuggestionsChanged;
485
+ /**
486
+ * Notify subscribers that suggestions started loading
487
+ */
488
+ private notifySuggestionsStartedLoading;
489
+ /**
490
+ * Notify subscribers that suggestions finished loading
491
+ */
492
+ private notifySuggestionsFinishedLoading;
493
+ /**
494
+ * Check if suggestions should be shown based on availability and message count
495
+ */
496
+ private shouldShowSuggestions;
497
+ /**
498
+ * Add static suggestions directly without AI generation
499
+ */
500
+ private addStaticSuggestions;
189
501
  }
190
502
 
191
503
  interface ProxiedCopilotRuntimeAgentConfig extends Omit<HttpAgentConfig, "url"> {
@@ -199,4 +511,4 @@ declare class ProxiedCopilotRuntimeAgent extends HttpAgent {
199
511
 
200
512
  declare function completePartialMarkdown(input: string): string;
201
513
 
202
- export { CopilotKitCore, type CopilotKitCoreAddAgentParams, type CopilotKitCoreConfig, type CopilotKitCoreConnectAgentParams, CopilotKitCoreErrorCode, type CopilotKitCoreGetToolParams, type CopilotKitCoreRunAgentParams, CopilotKitCoreRuntimeConnectionStatus, type CopilotKitCoreSubscriber, type FrontendTool, ProxiedCopilotRuntimeAgent, type ProxiedCopilotRuntimeAgentConfig, ToolCallStatus, completePartialMarkdown };
514
+ export { AgentRegistry, ContextStore, CopilotKitCore, type CopilotKitCoreAddAgentParams, type CopilotKitCoreConfig, type CopilotKitCoreConnectAgentParams, CopilotKitCoreErrorCode, type CopilotKitCoreGetSuggestionsResult, type CopilotKitCoreGetToolParams, type CopilotKitCoreRunAgentParams, CopilotKitCoreRuntimeConnectionStatus, type CopilotKitCoreSubscriber, type DynamicSuggestionsConfig, type FrontendTool, ProxiedCopilotRuntimeAgent, type ProxiedCopilotRuntimeAgentConfig, RunHandler, type StaticSuggestionsConfig, type Suggestion, type SuggestionAvailability, SuggestionEngine, type SuggestionsConfig, ToolCallStatus, completePartialMarkdown };