@copilotkitnext/core 0.0.8 → 0.0.9-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.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { AbstractAgent, Message, Context, HttpAgentConfig, HttpAgent, RunAgentInput, BaseEvent } from '@ag-ui/client';
1
+ import { AbstractAgent, Message, Context, RunAgentResult, HttpAgentConfig, HttpAgent, RunAgentInput, BaseEvent } from '@ag-ui/client';
2
2
  import { z } from 'zod';
3
3
  import { Observable } from 'rxjs';
4
4
 
@@ -23,71 +23,178 @@ type FrontendTool<T extends Record<string, unknown> = Record<string, unknown>> =
23
23
  agentId?: string;
24
24
  };
25
25
 
26
+ /** Configuration options for `CopilotKitCore`. */
26
27
  interface CopilotKitCoreConfig {
28
+ /** The endpoint of the CopilotRuntime. */
27
29
  runtimeUrl?: string;
30
+ /** Mapping from agent name to its `AbstractAgent` instance. */
28
31
  agents?: Record<string, AbstractAgent>;
32
+ /** Headers appended to every HTTP request made by `CopilotKitCore`. */
29
33
  headers?: Record<string, string>;
34
+ /** Properties sent as `forwardedProps` to the AG-UI agent. */
30
35
  properties?: Record<string, unknown>;
31
- tools?: Record<string, FrontendTool<any>>;
36
+ /** Ordered collection of frontend tools available to the core. */
37
+ tools?: FrontendTool<any>[];
32
38
  }
33
39
  interface CopilotKitCoreAddAgentParams {
34
40
  id: string;
35
41
  agent: AbstractAgent;
36
42
  }
37
- interface RunAgentParams {
43
+ interface CopilotKitCoreRunAgentParams {
38
44
  agent: AbstractAgent;
39
45
  withMessages?: Message[];
40
46
  agentId?: string;
41
47
  }
48
+ interface CopilotKitCoreConnectAgentParams {
49
+ agent: AbstractAgent;
50
+ agentId?: string;
51
+ }
52
+ interface CopilotKitCoreGetToolParams {
53
+ toolName: string;
54
+ agentId?: string;
55
+ }
56
+ declare enum CopilotKitCoreErrorCode {
57
+ RUNTIME_INFO_FETCH_FAILED = "runtime_info_fetch_failed",
58
+ AGENT_CONNECT_FAILED = "agent_connect_failed",
59
+ AGENT_RUN_FAILED = "agent_run_failed",
60
+ AGENT_RUN_FAILED_EVENT = "agent_run_failed_event",
61
+ AGENT_RUN_ERROR_EVENT = "agent_run_error_event",
62
+ TOOL_ARGUMENT_PARSE_FAILED = "tool_argument_parse_failed",
63
+ TOOL_HANDLER_FAILED = "tool_handler_failed"
64
+ }
42
65
  interface CopilotKitCoreSubscriber {
43
- onRuntimeLoaded?: (event: {
66
+ onRuntimeConnectionStatusChanged?: (event: {
44
67
  copilotkit: CopilotKitCore;
68
+ status: CopilotKitCoreRuntimeConnectionStatus;
45
69
  }) => void | Promise<void>;
46
- onRuntimeLoadError?: (event: {
70
+ onToolExecutionStart?: (event: {
47
71
  copilotkit: CopilotKitCore;
72
+ toolCallId: string;
73
+ agentId: string;
74
+ toolName: string;
75
+ args: unknown;
48
76
  }) => void | Promise<void>;
77
+ onToolExecutionEnd?: (event: {
78
+ copilotkit: CopilotKitCore;
79
+ toolCallId: string;
80
+ agentId: string;
81
+ toolName: string;
82
+ result: string;
83
+ error?: string;
84
+ }) => void | Promise<void>;
85
+ onAgentsChanged?: (event: {
86
+ copilotkit: CopilotKitCore;
87
+ agents: Readonly<Record<string, AbstractAgent>>;
88
+ }) => void | Promise<void>;
89
+ onContextChanged?: (event: {
90
+ copilotkit: CopilotKitCore;
91
+ context: Readonly<Record<string, Context>>;
92
+ }) => void | Promise<void>;
93
+ onPropertiesChanged?: (event: {
94
+ copilotkit: CopilotKitCore;
95
+ properties: Readonly<Record<string, unknown>>;
96
+ }) => void | Promise<void>;
97
+ onHeadersChanged?: (event: {
98
+ copilotkit: CopilotKitCore;
99
+ headers: Readonly<Record<string, string>>;
100
+ }) => void | Promise<void>;
101
+ onError?: (event: {
102
+ copilotkit: CopilotKitCore;
103
+ error: Error;
104
+ code: CopilotKitCoreErrorCode;
105
+ context: Record<string, any>;
106
+ }) => void | Promise<void>;
107
+ }
108
+ declare enum CopilotKitCoreRuntimeConnectionStatus {
109
+ Disconnected = "disconnected",
110
+ Connected = "connected",
111
+ Connecting = "connecting",
112
+ Error = "error"
49
113
  }
50
114
  declare class CopilotKitCore {
51
- runtimeUrl?: string;
52
- didLoadRuntime: boolean;
53
- context: Record<string, Context>;
54
- tools: Record<string, FrontendTool<any>>;
55
- agents: Record<string, AbstractAgent>;
56
115
  headers: Record<string, string>;
57
116
  properties: Record<string, unknown>;
58
- version?: string;
117
+ private _context;
118
+ private _agents;
119
+ private _tools;
59
120
  private localAgents;
60
121
  private remoteAgents;
61
122
  private subscribers;
123
+ private _runtimeUrl?;
124
+ private _runtimeVersion?;
125
+ private _runtimeConnectionStatus;
62
126
  constructor({ runtimeUrl, headers, properties, agents, tools, }: CopilotKitCoreConfig);
63
- private getRuntimeInfo;
64
- private fetchRemoteAgents;
127
+ private assignAgentIds;
128
+ private notifySubscribers;
129
+ private emitError;
130
+ private resolveAgentId;
131
+ /**
132
+ * Snapshot accessors
133
+ */
134
+ get context(): Readonly<Record<string, Context>>;
135
+ get agents(): Readonly<Record<string, AbstractAgent>>;
136
+ get tools(): Readonly<FrontendTool<any>[]>;
137
+ get runtimeUrl(): string | undefined;
138
+ setRuntimeUrl(runtimeUrl: string | undefined): void;
139
+ get runtimeVersion(): string | undefined;
140
+ get runtimeConnectionStatus(): CopilotKitCoreRuntimeConnectionStatus;
141
+ /**
142
+ * Runtime connection
143
+ */
144
+ private updateRuntimeConnection;
145
+ /**
146
+ * Configuration updates
147
+ */
148
+ setHeaders(headers: Record<string, string>): void;
149
+ setProperties(properties: Record<string, unknown>): void;
65
150
  setAgents(agents: Record<string, AbstractAgent>): void;
66
151
  addAgent({ id, agent }: CopilotKitCoreAddAgentParams): void;
67
152
  removeAgent(id: string): void;
68
153
  getAgent(id: string): AbstractAgent | undefined;
154
+ /**
155
+ * Context management
156
+ */
69
157
  addContext({ description, value }: Context): string;
70
158
  removeContext(id: string): void;
71
- setRuntimeUrl(runtimeUrl?: string): void;
159
+ /**
160
+ * Tool management
161
+ */
72
162
  addTool<T extends Record<string, unknown> = Record<string, unknown>>(tool: FrontendTool<T>): void;
73
- removeTool(id: string): void;
74
- setHeaders(headers: Record<string, string>): void;
75
- setProperties(properties: Record<string, unknown>): void;
163
+ removeTool(id: string, agentId?: string): void;
164
+ /**
165
+ * Get a tool by name and optionally by agentId.
166
+ * If agentId is provided, it will first look for an agent-specific tool,
167
+ * then fall back to a global tool with the same name.
168
+ */
169
+ getTool(params: CopilotKitCoreGetToolParams): FrontendTool<any> | undefined;
170
+ /**
171
+ * Set all tools at once. Replaces existing tools.
172
+ */
173
+ setTools(tools: FrontendTool<any>[]): void;
174
+ /**
175
+ * Subscription lifecycle
176
+ */
76
177
  subscribe(subscriber: CopilotKitCoreSubscriber): () => void;
77
178
  unsubscribe(subscriber: CopilotKitCoreSubscriber): void;
78
- runAgent({ agent, withMessages, agentId, }: RunAgentParams): Promise<Awaited<ReturnType<typeof agent.runAgent>>>;
179
+ /**
180
+ * Agent connectivity
181
+ */
182
+ connectAgent({ agent, agentId, }: CopilotKitCoreConnectAgentParams): Promise<RunAgentResult>;
183
+ runAgent({ agent, withMessages, agentId, }: CopilotKitCoreRunAgentParams): Promise<RunAgentResult>;
184
+ private processAgentResult;
185
+ private buildFrontendTools;
186
+ private createAgentErrorSubscriber;
79
187
  }
80
188
 
81
- interface CopilotKitHttpAgentConfig extends Omit<HttpAgentConfig, "url"> {
189
+ interface ProxiedCopilotRuntimeAgentConfig extends Omit<HttpAgentConfig, "url"> {
82
190
  runtimeUrl?: string;
83
191
  }
84
- declare class CopilotKitHttpAgent extends HttpAgent {
85
- isCopilotKitAgent: boolean;
192
+ declare class ProxiedCopilotRuntimeAgent extends HttpAgent {
86
193
  runtimeUrl?: string;
87
- constructor(config: CopilotKitHttpAgentConfig);
88
- run(input: RunAgentInput): Observable<BaseEvent>;
194
+ constructor(config: ProxiedCopilotRuntimeAgentConfig);
195
+ connect(input: RunAgentInput): Observable<BaseEvent>;
89
196
  }
90
197
 
91
198
  declare function completePartialMarkdown(input: string): string;
92
199
 
93
- export { CopilotKitCore, type CopilotKitCoreAddAgentParams, type CopilotKitCoreConfig, type CopilotKitCoreSubscriber, CopilotKitHttpAgent, type CopilotKitHttpAgentConfig, type FrontendTool, type RunAgentParams, ToolCallStatus, completePartialMarkdown };
200
+ export { CopilotKitCore, type CopilotKitCoreAddAgentParams, type CopilotKitCoreConfig, type CopilotKitCoreConnectAgentParams, CopilotKitCoreErrorCode, type CopilotKitCoreGetToolParams, type CopilotKitCoreRunAgentParams, CopilotKitCoreRuntimeConnectionStatus, type CopilotKitCoreSubscriber, type FrontendTool, ProxiedCopilotRuntimeAgent, type ProxiedCopilotRuntimeAgentConfig, ToolCallStatus, completePartialMarkdown };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AbstractAgent, Message, Context, HttpAgentConfig, HttpAgent, RunAgentInput, BaseEvent } from '@ag-ui/client';
1
+ import { AbstractAgent, Message, Context, RunAgentResult, HttpAgentConfig, HttpAgent, RunAgentInput, BaseEvent } from '@ag-ui/client';
2
2
  import { z } from 'zod';
3
3
  import { Observable } from 'rxjs';
4
4
 
@@ -23,71 +23,178 @@ type FrontendTool<T extends Record<string, unknown> = Record<string, unknown>> =
23
23
  agentId?: string;
24
24
  };
25
25
 
26
+ /** Configuration options for `CopilotKitCore`. */
26
27
  interface CopilotKitCoreConfig {
28
+ /** The endpoint of the CopilotRuntime. */
27
29
  runtimeUrl?: string;
30
+ /** Mapping from agent name to its `AbstractAgent` instance. */
28
31
  agents?: Record<string, AbstractAgent>;
32
+ /** Headers appended to every HTTP request made by `CopilotKitCore`. */
29
33
  headers?: Record<string, string>;
34
+ /** Properties sent as `forwardedProps` to the AG-UI agent. */
30
35
  properties?: Record<string, unknown>;
31
- tools?: Record<string, FrontendTool<any>>;
36
+ /** Ordered collection of frontend tools available to the core. */
37
+ tools?: FrontendTool<any>[];
32
38
  }
33
39
  interface CopilotKitCoreAddAgentParams {
34
40
  id: string;
35
41
  agent: AbstractAgent;
36
42
  }
37
- interface RunAgentParams {
43
+ interface CopilotKitCoreRunAgentParams {
38
44
  agent: AbstractAgent;
39
45
  withMessages?: Message[];
40
46
  agentId?: string;
41
47
  }
48
+ interface CopilotKitCoreConnectAgentParams {
49
+ agent: AbstractAgent;
50
+ agentId?: string;
51
+ }
52
+ interface CopilotKitCoreGetToolParams {
53
+ toolName: string;
54
+ agentId?: string;
55
+ }
56
+ declare enum CopilotKitCoreErrorCode {
57
+ RUNTIME_INFO_FETCH_FAILED = "runtime_info_fetch_failed",
58
+ AGENT_CONNECT_FAILED = "agent_connect_failed",
59
+ AGENT_RUN_FAILED = "agent_run_failed",
60
+ AGENT_RUN_FAILED_EVENT = "agent_run_failed_event",
61
+ AGENT_RUN_ERROR_EVENT = "agent_run_error_event",
62
+ TOOL_ARGUMENT_PARSE_FAILED = "tool_argument_parse_failed",
63
+ TOOL_HANDLER_FAILED = "tool_handler_failed"
64
+ }
42
65
  interface CopilotKitCoreSubscriber {
43
- onRuntimeLoaded?: (event: {
66
+ onRuntimeConnectionStatusChanged?: (event: {
44
67
  copilotkit: CopilotKitCore;
68
+ status: CopilotKitCoreRuntimeConnectionStatus;
45
69
  }) => void | Promise<void>;
46
- onRuntimeLoadError?: (event: {
70
+ onToolExecutionStart?: (event: {
47
71
  copilotkit: CopilotKitCore;
72
+ toolCallId: string;
73
+ agentId: string;
74
+ toolName: string;
75
+ args: unknown;
48
76
  }) => void | Promise<void>;
77
+ onToolExecutionEnd?: (event: {
78
+ copilotkit: CopilotKitCore;
79
+ toolCallId: string;
80
+ agentId: string;
81
+ toolName: string;
82
+ result: string;
83
+ error?: string;
84
+ }) => void | Promise<void>;
85
+ onAgentsChanged?: (event: {
86
+ copilotkit: CopilotKitCore;
87
+ agents: Readonly<Record<string, AbstractAgent>>;
88
+ }) => void | Promise<void>;
89
+ onContextChanged?: (event: {
90
+ copilotkit: CopilotKitCore;
91
+ context: Readonly<Record<string, Context>>;
92
+ }) => void | Promise<void>;
93
+ onPropertiesChanged?: (event: {
94
+ copilotkit: CopilotKitCore;
95
+ properties: Readonly<Record<string, unknown>>;
96
+ }) => void | Promise<void>;
97
+ onHeadersChanged?: (event: {
98
+ copilotkit: CopilotKitCore;
99
+ headers: Readonly<Record<string, string>>;
100
+ }) => void | Promise<void>;
101
+ onError?: (event: {
102
+ copilotkit: CopilotKitCore;
103
+ error: Error;
104
+ code: CopilotKitCoreErrorCode;
105
+ context: Record<string, any>;
106
+ }) => void | Promise<void>;
107
+ }
108
+ declare enum CopilotKitCoreRuntimeConnectionStatus {
109
+ Disconnected = "disconnected",
110
+ Connected = "connected",
111
+ Connecting = "connecting",
112
+ Error = "error"
49
113
  }
50
114
  declare class CopilotKitCore {
51
- runtimeUrl?: string;
52
- didLoadRuntime: boolean;
53
- context: Record<string, Context>;
54
- tools: Record<string, FrontendTool<any>>;
55
- agents: Record<string, AbstractAgent>;
56
115
  headers: Record<string, string>;
57
116
  properties: Record<string, unknown>;
58
- version?: string;
117
+ private _context;
118
+ private _agents;
119
+ private _tools;
59
120
  private localAgents;
60
121
  private remoteAgents;
61
122
  private subscribers;
123
+ private _runtimeUrl?;
124
+ private _runtimeVersion?;
125
+ private _runtimeConnectionStatus;
62
126
  constructor({ runtimeUrl, headers, properties, agents, tools, }: CopilotKitCoreConfig);
63
- private getRuntimeInfo;
64
- private fetchRemoteAgents;
127
+ private assignAgentIds;
128
+ private notifySubscribers;
129
+ private emitError;
130
+ private resolveAgentId;
131
+ /**
132
+ * Snapshot accessors
133
+ */
134
+ get context(): Readonly<Record<string, Context>>;
135
+ get agents(): Readonly<Record<string, AbstractAgent>>;
136
+ get tools(): Readonly<FrontendTool<any>[]>;
137
+ get runtimeUrl(): string | undefined;
138
+ setRuntimeUrl(runtimeUrl: string | undefined): void;
139
+ get runtimeVersion(): string | undefined;
140
+ get runtimeConnectionStatus(): CopilotKitCoreRuntimeConnectionStatus;
141
+ /**
142
+ * Runtime connection
143
+ */
144
+ private updateRuntimeConnection;
145
+ /**
146
+ * Configuration updates
147
+ */
148
+ setHeaders(headers: Record<string, string>): void;
149
+ setProperties(properties: Record<string, unknown>): void;
65
150
  setAgents(agents: Record<string, AbstractAgent>): void;
66
151
  addAgent({ id, agent }: CopilotKitCoreAddAgentParams): void;
67
152
  removeAgent(id: string): void;
68
153
  getAgent(id: string): AbstractAgent | undefined;
154
+ /**
155
+ * Context management
156
+ */
69
157
  addContext({ description, value }: Context): string;
70
158
  removeContext(id: string): void;
71
- setRuntimeUrl(runtimeUrl?: string): void;
159
+ /**
160
+ * Tool management
161
+ */
72
162
  addTool<T extends Record<string, unknown> = Record<string, unknown>>(tool: FrontendTool<T>): void;
73
- removeTool(id: string): void;
74
- setHeaders(headers: Record<string, string>): void;
75
- setProperties(properties: Record<string, unknown>): void;
163
+ removeTool(id: string, agentId?: string): void;
164
+ /**
165
+ * Get a tool by name and optionally by agentId.
166
+ * If agentId is provided, it will first look for an agent-specific tool,
167
+ * then fall back to a global tool with the same name.
168
+ */
169
+ getTool(params: CopilotKitCoreGetToolParams): FrontendTool<any> | undefined;
170
+ /**
171
+ * Set all tools at once. Replaces existing tools.
172
+ */
173
+ setTools(tools: FrontendTool<any>[]): void;
174
+ /**
175
+ * Subscription lifecycle
176
+ */
76
177
  subscribe(subscriber: CopilotKitCoreSubscriber): () => void;
77
178
  unsubscribe(subscriber: CopilotKitCoreSubscriber): void;
78
- runAgent({ agent, withMessages, agentId, }: RunAgentParams): Promise<Awaited<ReturnType<typeof agent.runAgent>>>;
179
+ /**
180
+ * Agent connectivity
181
+ */
182
+ connectAgent({ agent, agentId, }: CopilotKitCoreConnectAgentParams): Promise<RunAgentResult>;
183
+ runAgent({ agent, withMessages, agentId, }: CopilotKitCoreRunAgentParams): Promise<RunAgentResult>;
184
+ private processAgentResult;
185
+ private buildFrontendTools;
186
+ private createAgentErrorSubscriber;
79
187
  }
80
188
 
81
- interface CopilotKitHttpAgentConfig extends Omit<HttpAgentConfig, "url"> {
189
+ interface ProxiedCopilotRuntimeAgentConfig extends Omit<HttpAgentConfig, "url"> {
82
190
  runtimeUrl?: string;
83
191
  }
84
- declare class CopilotKitHttpAgent extends HttpAgent {
85
- isCopilotKitAgent: boolean;
192
+ declare class ProxiedCopilotRuntimeAgent extends HttpAgent {
86
193
  runtimeUrl?: string;
87
- constructor(config: CopilotKitHttpAgentConfig);
88
- run(input: RunAgentInput): Observable<BaseEvent>;
194
+ constructor(config: ProxiedCopilotRuntimeAgentConfig);
195
+ connect(input: RunAgentInput): Observable<BaseEvent>;
89
196
  }
90
197
 
91
198
  declare function completePartialMarkdown(input: string): string;
92
199
 
93
- export { CopilotKitCore, type CopilotKitCoreAddAgentParams, type CopilotKitCoreConfig, type CopilotKitCoreSubscriber, CopilotKitHttpAgent, type CopilotKitHttpAgentConfig, type FrontendTool, type RunAgentParams, ToolCallStatus, completePartialMarkdown };
200
+ export { CopilotKitCore, type CopilotKitCoreAddAgentParams, type CopilotKitCoreConfig, type CopilotKitCoreConnectAgentParams, CopilotKitCoreErrorCode, type CopilotKitCoreGetToolParams, type CopilotKitCoreRunAgentParams, CopilotKitCoreRuntimeConnectionStatus, type CopilotKitCoreSubscriber, type FrontendTool, ProxiedCopilotRuntimeAgent, type ProxiedCopilotRuntimeAgentConfig, ToolCallStatus, completePartialMarkdown };