@copilotkitnext/core 0.0.10 → 0.0.12
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 +14 -10
- package/dist/index.d.ts +14 -10
- package/dist/index.js +51 -65
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -73
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -27,8 +27,8 @@ type FrontendTool<T extends Record<string, unknown> = Record<string, unknown>> =
|
|
|
27
27
|
interface CopilotKitCoreConfig {
|
|
28
28
|
/** The endpoint of the CopilotRuntime. */
|
|
29
29
|
runtimeUrl?: string;
|
|
30
|
-
/** Mapping from agent name to its `AbstractAgent` instance. */
|
|
31
|
-
|
|
30
|
+
/** Mapping from agent name to its `AbstractAgent` instance. For development only - production requires CopilotRuntime. */
|
|
31
|
+
agents__unsafe_dev_only?: Record<string, AbstractAgent>;
|
|
32
32
|
/** Headers appended to every HTTP request made by `CopilotKitCore`. */
|
|
33
33
|
headers?: Record<string, string>;
|
|
34
34
|
/** Properties sent as `forwardedProps` to the AG-UI agent. */
|
|
@@ -112,8 +112,8 @@ declare enum CopilotKitCoreRuntimeConnectionStatus {
|
|
|
112
112
|
Error = "error"
|
|
113
113
|
}
|
|
114
114
|
declare class CopilotKitCore {
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
private _headers;
|
|
116
|
+
private _properties;
|
|
117
117
|
private _context;
|
|
118
118
|
private _agents;
|
|
119
119
|
private _tools;
|
|
@@ -123,7 +123,9 @@ declare class CopilotKitCore {
|
|
|
123
123
|
private _runtimeUrl?;
|
|
124
124
|
private _runtimeVersion?;
|
|
125
125
|
private _runtimeConnectionStatus;
|
|
126
|
-
constructor({ runtimeUrl, headers, properties,
|
|
126
|
+
constructor({ runtimeUrl, headers, properties, agents__unsafe_dev_only, tools, }: CopilotKitCoreConfig);
|
|
127
|
+
private applyHeadersToAgent;
|
|
128
|
+
private applyHeadersToAgents;
|
|
127
129
|
private assignAgentIds;
|
|
128
130
|
private notifySubscribers;
|
|
129
131
|
private emitError;
|
|
@@ -137,6 +139,8 @@ declare class CopilotKitCore {
|
|
|
137
139
|
get runtimeUrl(): string | undefined;
|
|
138
140
|
setRuntimeUrl(runtimeUrl: string | undefined): void;
|
|
139
141
|
get runtimeVersion(): string | undefined;
|
|
142
|
+
get headers(): Readonly<Record<string, string>>;
|
|
143
|
+
get properties(): Readonly<Record<string, unknown>>;
|
|
140
144
|
get runtimeConnectionStatus(): CopilotKitCoreRuntimeConnectionStatus;
|
|
141
145
|
/**
|
|
142
146
|
* Runtime connection
|
|
@@ -147,9 +151,9 @@ declare class CopilotKitCore {
|
|
|
147
151
|
*/
|
|
148
152
|
setHeaders(headers: Record<string, string>): void;
|
|
149
153
|
setProperties(properties: Record<string, unknown>): void;
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
154
|
+
setAgents__unsafe_dev_only(agents: Record<string, AbstractAgent>): void;
|
|
155
|
+
addAgent__unsafe_dev_only({ id, agent }: CopilotKitCoreAddAgentParams): void;
|
|
156
|
+
removeAgent__unsafe_dev_only(id: string): void;
|
|
153
157
|
getAgent(id: string): AbstractAgent | undefined;
|
|
154
158
|
/**
|
|
155
159
|
* Context management
|
|
@@ -179,8 +183,8 @@ declare class CopilotKitCore {
|
|
|
179
183
|
/**
|
|
180
184
|
* Agent connectivity
|
|
181
185
|
*/
|
|
182
|
-
connectAgent({ agent, agentId
|
|
183
|
-
runAgent({ agent, withMessages, agentId
|
|
186
|
+
connectAgent({ agent, agentId }: CopilotKitCoreConnectAgentParams): Promise<RunAgentResult>;
|
|
187
|
+
runAgent({ agent, withMessages, agentId }: CopilotKitCoreRunAgentParams): Promise<RunAgentResult>;
|
|
184
188
|
private processAgentResult;
|
|
185
189
|
private buildFrontendTools;
|
|
186
190
|
private createAgentErrorSubscriber;
|
package/dist/index.d.ts
CHANGED
|
@@ -27,8 +27,8 @@ type FrontendTool<T extends Record<string, unknown> = Record<string, unknown>> =
|
|
|
27
27
|
interface CopilotKitCoreConfig {
|
|
28
28
|
/** The endpoint of the CopilotRuntime. */
|
|
29
29
|
runtimeUrl?: string;
|
|
30
|
-
/** Mapping from agent name to its `AbstractAgent` instance. */
|
|
31
|
-
|
|
30
|
+
/** Mapping from agent name to its `AbstractAgent` instance. For development only - production requires CopilotRuntime. */
|
|
31
|
+
agents__unsafe_dev_only?: Record<string, AbstractAgent>;
|
|
32
32
|
/** Headers appended to every HTTP request made by `CopilotKitCore`. */
|
|
33
33
|
headers?: Record<string, string>;
|
|
34
34
|
/** Properties sent as `forwardedProps` to the AG-UI agent. */
|
|
@@ -112,8 +112,8 @@ declare enum CopilotKitCoreRuntimeConnectionStatus {
|
|
|
112
112
|
Error = "error"
|
|
113
113
|
}
|
|
114
114
|
declare class CopilotKitCore {
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
private _headers;
|
|
116
|
+
private _properties;
|
|
117
117
|
private _context;
|
|
118
118
|
private _agents;
|
|
119
119
|
private _tools;
|
|
@@ -123,7 +123,9 @@ declare class CopilotKitCore {
|
|
|
123
123
|
private _runtimeUrl?;
|
|
124
124
|
private _runtimeVersion?;
|
|
125
125
|
private _runtimeConnectionStatus;
|
|
126
|
-
constructor({ runtimeUrl, headers, properties,
|
|
126
|
+
constructor({ runtimeUrl, headers, properties, agents__unsafe_dev_only, tools, }: CopilotKitCoreConfig);
|
|
127
|
+
private applyHeadersToAgent;
|
|
128
|
+
private applyHeadersToAgents;
|
|
127
129
|
private assignAgentIds;
|
|
128
130
|
private notifySubscribers;
|
|
129
131
|
private emitError;
|
|
@@ -137,6 +139,8 @@ declare class CopilotKitCore {
|
|
|
137
139
|
get runtimeUrl(): string | undefined;
|
|
138
140
|
setRuntimeUrl(runtimeUrl: string | undefined): void;
|
|
139
141
|
get runtimeVersion(): string | undefined;
|
|
142
|
+
get headers(): Readonly<Record<string, string>>;
|
|
143
|
+
get properties(): Readonly<Record<string, unknown>>;
|
|
140
144
|
get runtimeConnectionStatus(): CopilotKitCoreRuntimeConnectionStatus;
|
|
141
145
|
/**
|
|
142
146
|
* Runtime connection
|
|
@@ -147,9 +151,9 @@ declare class CopilotKitCore {
|
|
|
147
151
|
*/
|
|
148
152
|
setHeaders(headers: Record<string, string>): void;
|
|
149
153
|
setProperties(properties: Record<string, unknown>): void;
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
154
|
+
setAgents__unsafe_dev_only(agents: Record<string, AbstractAgent>): void;
|
|
155
|
+
addAgent__unsafe_dev_only({ id, agent }: CopilotKitCoreAddAgentParams): void;
|
|
156
|
+
removeAgent__unsafe_dev_only(id: string): void;
|
|
153
157
|
getAgent(id: string): AbstractAgent | undefined;
|
|
154
158
|
/**
|
|
155
159
|
* Context management
|
|
@@ -179,8 +183,8 @@ declare class CopilotKitCore {
|
|
|
179
183
|
/**
|
|
180
184
|
* Agent connectivity
|
|
181
185
|
*/
|
|
182
|
-
connectAgent({ agent, agentId
|
|
183
|
-
runAgent({ agent, withMessages, agentId
|
|
186
|
+
connectAgent({ agent, agentId }: CopilotKitCoreConnectAgentParams): Promise<RunAgentResult>;
|
|
187
|
+
runAgent({ agent, withMessages, agentId }: CopilotKitCoreRunAgentParams): Promise<RunAgentResult>;
|
|
184
188
|
private processAgentResult;
|
|
185
189
|
private buildFrontendTools;
|
|
186
190
|
private createAgentErrorSubscriber;
|
package/dist/index.js
CHANGED
|
@@ -73,8 +73,8 @@ var CopilotKitCoreRuntimeConnectionStatus = /* @__PURE__ */ ((CopilotKitCoreRunt
|
|
|
73
73
|
return CopilotKitCoreRuntimeConnectionStatus2;
|
|
74
74
|
})(CopilotKitCoreRuntimeConnectionStatus || {});
|
|
75
75
|
var CopilotKitCore = class {
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
_headers;
|
|
77
|
+
_properties;
|
|
78
78
|
_context = {};
|
|
79
79
|
_agents = {};
|
|
80
80
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -89,16 +89,27 @@ var CopilotKitCore = class {
|
|
|
89
89
|
runtimeUrl,
|
|
90
90
|
headers = {},
|
|
91
91
|
properties = {},
|
|
92
|
-
|
|
92
|
+
agents__unsafe_dev_only = {},
|
|
93
93
|
tools = []
|
|
94
94
|
}) {
|
|
95
|
-
this.
|
|
96
|
-
this.
|
|
97
|
-
this.localAgents = this.assignAgentIds(
|
|
95
|
+
this._headers = headers;
|
|
96
|
+
this._properties = properties;
|
|
97
|
+
this.localAgents = this.assignAgentIds(agents__unsafe_dev_only);
|
|
98
|
+
this.applyHeadersToAgents(this.localAgents);
|
|
98
99
|
this._agents = this.localAgents;
|
|
99
100
|
this._tools = tools;
|
|
100
101
|
this.setRuntimeUrl(runtimeUrl);
|
|
101
102
|
}
|
|
103
|
+
applyHeadersToAgent(agent) {
|
|
104
|
+
if (agent instanceof import_client2.HttpAgent) {
|
|
105
|
+
agent.headers = { ...this.headers };
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
applyHeadersToAgents(agents) {
|
|
109
|
+
Object.values(agents).forEach((agent) => {
|
|
110
|
+
this.applyHeadersToAgent(agent);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
102
113
|
assignAgentIds(agents) {
|
|
103
114
|
Object.entries(agents).forEach(([id, agent]) => {
|
|
104
115
|
if (agent && !agent.agentId) {
|
|
@@ -176,6 +187,12 @@ var CopilotKitCore = class {
|
|
|
176
187
|
get runtimeVersion() {
|
|
177
188
|
return this._runtimeVersion;
|
|
178
189
|
}
|
|
190
|
+
get headers() {
|
|
191
|
+
return this._headers;
|
|
192
|
+
}
|
|
193
|
+
get properties() {
|
|
194
|
+
return this._properties;
|
|
195
|
+
}
|
|
179
196
|
get runtimeConnectionStatus() {
|
|
180
197
|
return this._runtimeConnectionStatus;
|
|
181
198
|
}
|
|
@@ -227,6 +244,7 @@ var CopilotKitCore = class {
|
|
|
227
244
|
agentId: id,
|
|
228
245
|
description
|
|
229
246
|
});
|
|
247
|
+
this.applyHeadersToAgent(agent);
|
|
230
248
|
return [id, agent];
|
|
231
249
|
})
|
|
232
250
|
);
|
|
@@ -268,9 +286,7 @@ var CopilotKitCore = class {
|
|
|
268
286
|
"Subscriber onAgentsChanged error:"
|
|
269
287
|
);
|
|
270
288
|
const message = error instanceof Error ? error.message : JSON.stringify(error);
|
|
271
|
-
import_shared.logger.warn(
|
|
272
|
-
`Failed to load runtime info (${this.runtimeUrl}/info): ${message}`
|
|
273
|
-
);
|
|
289
|
+
import_shared.logger.warn(`Failed to load runtime info (${this.runtimeUrl}/info): ${message}`);
|
|
274
290
|
const runtimeError = error instanceof Error ? error : new Error(String(error));
|
|
275
291
|
await this.emitError({
|
|
276
292
|
error: runtimeError,
|
|
@@ -285,7 +301,8 @@ var CopilotKitCore = class {
|
|
|
285
301
|
* Configuration updates
|
|
286
302
|
*/
|
|
287
303
|
setHeaders(headers) {
|
|
288
|
-
this.
|
|
304
|
+
this._headers = headers;
|
|
305
|
+
this.applyHeadersToAgents(this._agents);
|
|
289
306
|
void this.notifySubscribers(
|
|
290
307
|
(subscriber) => subscriber.onHeadersChanged?.({
|
|
291
308
|
copilotkit: this,
|
|
@@ -295,7 +312,7 @@ var CopilotKitCore = class {
|
|
|
295
312
|
);
|
|
296
313
|
}
|
|
297
314
|
setProperties(properties) {
|
|
298
|
-
this.
|
|
315
|
+
this._properties = properties;
|
|
299
316
|
void this.notifySubscribers(
|
|
300
317
|
(subscriber) => subscriber.onPropertiesChanged?.({
|
|
301
318
|
copilotkit: this,
|
|
@@ -304,9 +321,10 @@ var CopilotKitCore = class {
|
|
|
304
321
|
"Subscriber onPropertiesChanged error:"
|
|
305
322
|
);
|
|
306
323
|
}
|
|
307
|
-
|
|
324
|
+
setAgents__unsafe_dev_only(agents) {
|
|
308
325
|
this.localAgents = this.assignAgentIds(agents);
|
|
309
326
|
this._agents = { ...this.localAgents, ...this.remoteAgents };
|
|
327
|
+
this.applyHeadersToAgents(this._agents);
|
|
310
328
|
void this.notifySubscribers(
|
|
311
329
|
(subscriber) => subscriber.onAgentsChanged?.({
|
|
312
330
|
copilotkit: this,
|
|
@@ -315,11 +333,12 @@ var CopilotKitCore = class {
|
|
|
315
333
|
"Subscriber onAgentsChanged error:"
|
|
316
334
|
);
|
|
317
335
|
}
|
|
318
|
-
|
|
336
|
+
addAgent__unsafe_dev_only({ id, agent }) {
|
|
319
337
|
this.localAgents[id] = agent;
|
|
320
338
|
if (!agent.agentId) {
|
|
321
339
|
agent.agentId = id;
|
|
322
340
|
}
|
|
341
|
+
this.applyHeadersToAgent(agent);
|
|
323
342
|
this._agents = { ...this.localAgents, ...this.remoteAgents };
|
|
324
343
|
void this.notifySubscribers(
|
|
325
344
|
(subscriber) => subscriber.onAgentsChanged?.({
|
|
@@ -329,7 +348,7 @@ var CopilotKitCore = class {
|
|
|
329
348
|
"Subscriber onAgentsChanged error:"
|
|
330
349
|
);
|
|
331
350
|
}
|
|
332
|
-
|
|
351
|
+
removeAgent__unsafe_dev_only(id) {
|
|
333
352
|
delete this.localAgents[id];
|
|
334
353
|
this._agents = { ...this.localAgents, ...this.remoteAgents };
|
|
335
354
|
void this.notifySubscribers(
|
|
@@ -380,13 +399,9 @@ var CopilotKitCore = class {
|
|
|
380
399
|
* Tool management
|
|
381
400
|
*/
|
|
382
401
|
addTool(tool) {
|
|
383
|
-
const existingToolIndex = this._tools.findIndex(
|
|
384
|
-
(t) => t.name === tool.name && t.agentId === tool.agentId
|
|
385
|
-
);
|
|
402
|
+
const existingToolIndex = this._tools.findIndex((t) => t.name === tool.name && t.agentId === tool.agentId);
|
|
386
403
|
if (existingToolIndex !== -1) {
|
|
387
|
-
import_shared.logger.warn(
|
|
388
|
-
`Tool already exists: '${tool.name}' for agent '${tool.agentId || "global"}', skipping.`
|
|
389
|
-
);
|
|
404
|
+
import_shared.logger.warn(`Tool already exists: '${tool.name}' for agent '${tool.agentId || "global"}', skipping.`);
|
|
390
405
|
return;
|
|
391
406
|
}
|
|
392
407
|
this._tools.push(tool);
|
|
@@ -407,9 +422,7 @@ var CopilotKitCore = class {
|
|
|
407
422
|
getTool(params) {
|
|
408
423
|
const { toolName, agentId } = params;
|
|
409
424
|
if (agentId) {
|
|
410
|
-
const agentTool = this._tools.find(
|
|
411
|
-
(tool) => tool.name === toolName && tool.agentId === agentId
|
|
412
|
-
);
|
|
425
|
+
const agentTool = this._tools.find((tool) => tool.name === toolName && tool.agentId === agentId);
|
|
413
426
|
if (agentTool) {
|
|
414
427
|
return agentTool;
|
|
415
428
|
}
|
|
@@ -437,10 +450,7 @@ var CopilotKitCore = class {
|
|
|
437
450
|
/**
|
|
438
451
|
* Agent connectivity
|
|
439
452
|
*/
|
|
440
|
-
async connectAgent({
|
|
441
|
-
agent,
|
|
442
|
-
agentId
|
|
443
|
-
}) {
|
|
453
|
+
async connectAgent({ agent, agentId }) {
|
|
444
454
|
try {
|
|
445
455
|
if (agent instanceof import_client2.HttpAgent) {
|
|
446
456
|
agent.headers = { ...this.headers };
|
|
@@ -467,11 +477,7 @@ var CopilotKitCore = class {
|
|
|
467
477
|
throw error;
|
|
468
478
|
}
|
|
469
479
|
}
|
|
470
|
-
async runAgent({
|
|
471
|
-
agent,
|
|
472
|
-
withMessages,
|
|
473
|
-
agentId
|
|
474
|
-
}) {
|
|
480
|
+
async runAgent({ agent, withMessages, agentId }) {
|
|
475
481
|
if (agent instanceof import_client2.HttpAgent) {
|
|
476
482
|
agent.headers = { ...this.headers };
|
|
477
483
|
}
|
|
@@ -515,9 +521,7 @@ var CopilotKitCore = class {
|
|
|
515
521
|
for (const message of newMessages) {
|
|
516
522
|
if (message.role === "assistant") {
|
|
517
523
|
for (const toolCall of message.toolCalls || []) {
|
|
518
|
-
if (newMessages.findIndex(
|
|
519
|
-
(m) => m.role === "tool" && m.toolCallId === toolCall.id
|
|
520
|
-
) === -1) {
|
|
524
|
+
if (newMessages.findIndex((m) => m.role === "tool" && m.toolCallId === toolCall.id) === -1) {
|
|
521
525
|
const tool = this.getTool({
|
|
522
526
|
toolName: toolCall.function.name,
|
|
523
527
|
agentId
|
|
@@ -562,10 +566,7 @@ var CopilotKitCore = class {
|
|
|
562
566
|
);
|
|
563
567
|
if (!errorMessage) {
|
|
564
568
|
try {
|
|
565
|
-
const result = await tool.handler(
|
|
566
|
-
parsedArgs,
|
|
567
|
-
toolCall
|
|
568
|
-
);
|
|
569
|
+
const result = await tool.handler(parsedArgs, toolCall);
|
|
569
570
|
if (result === void 0 || result === null) {
|
|
570
571
|
toolCallResult = "";
|
|
571
572
|
} else if (typeof result === "string") {
|
|
@@ -609,9 +610,7 @@ var CopilotKitCore = class {
|
|
|
609
610
|
}
|
|
610
611
|
}
|
|
611
612
|
if (!errorMessage || !isArgumentError) {
|
|
612
|
-
const messageIndex = agent.messages.findIndex(
|
|
613
|
-
(m) => m.id === message.id
|
|
614
|
-
);
|
|
613
|
+
const messageIndex = agent.messages.findIndex((m) => m.id === message.id);
|
|
615
614
|
const toolMessage = {
|
|
616
615
|
id: (0, import_shared.randomUUID)(),
|
|
617
616
|
role: "tool",
|
|
@@ -669,10 +668,7 @@ var CopilotKitCore = class {
|
|
|
669
668
|
);
|
|
670
669
|
if (!errorMessage) {
|
|
671
670
|
try {
|
|
672
|
-
const result = await wildcardTool.handler(
|
|
673
|
-
wildcardArgs,
|
|
674
|
-
toolCall
|
|
675
|
-
);
|
|
671
|
+
const result = await wildcardTool.handler(wildcardArgs, toolCall);
|
|
676
672
|
if (result === void 0 || result === null) {
|
|
677
673
|
toolCallResult = "";
|
|
678
674
|
} else if (typeof result === "string") {
|
|
@@ -716,9 +712,7 @@ var CopilotKitCore = class {
|
|
|
716
712
|
}
|
|
717
713
|
}
|
|
718
714
|
if (!errorMessage || !isArgumentError) {
|
|
719
|
-
const messageIndex = agent.messages.findIndex(
|
|
720
|
-
(m) => m.id === message.id
|
|
721
|
-
);
|
|
715
|
+
const messageIndex = agent.messages.findIndex((m) => m.id === message.id);
|
|
722
716
|
const toolMessage = {
|
|
723
717
|
id: (0, import_shared.randomUUID)(),
|
|
724
718
|
role: "tool",
|
|
@@ -762,13 +756,9 @@ var CopilotKitCore = class {
|
|
|
762
756
|
};
|
|
763
757
|
return {
|
|
764
758
|
onRunFailed: async ({ error }) => {
|
|
765
|
-
await emitAgentError(
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
{
|
|
769
|
-
source: "onRunFailed"
|
|
770
|
-
}
|
|
771
|
-
);
|
|
759
|
+
await emitAgentError(error, "agent_run_failed_event" /* AGENT_RUN_FAILED_EVENT */, {
|
|
760
|
+
source: "onRunFailed"
|
|
761
|
+
});
|
|
772
762
|
},
|
|
773
763
|
onRunErrorEvent: async ({ event }) => {
|
|
774
764
|
const eventError = event?.rawEvent instanceof Error ? event.rawEvent : event?.rawEvent?.error instanceof Error ? event.rawEvent.error : void 0;
|
|
@@ -777,15 +767,11 @@ var CopilotKitCore = class {
|
|
|
777
767
|
if (event?.code && !rawError.code) {
|
|
778
768
|
rawError.code = event.code;
|
|
779
769
|
}
|
|
780
|
-
await emitAgentError(
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
event,
|
|
786
|
-
runtimeErrorCode: event?.code
|
|
787
|
-
}
|
|
788
|
-
);
|
|
770
|
+
await emitAgentError(rawError, "agent_run_error_event" /* AGENT_RUN_ERROR_EVENT */, {
|
|
771
|
+
source: "onRunErrorEvent",
|
|
772
|
+
event,
|
|
773
|
+
runtimeErrorCode: event?.code
|
|
774
|
+
});
|
|
789
775
|
}
|
|
790
776
|
};
|
|
791
777
|
}
|