@copilotkitnext/core 1.51.4-next.7 → 1.51.4
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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +211 -82
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +214 -83
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +4 -5
package/dist/index.d.mts
CHANGED
|
@@ -221,11 +221,11 @@ declare class RunHandler {
|
|
|
221
221
|
/**
|
|
222
222
|
* Connect an agent (establish initial connection)
|
|
223
223
|
*/
|
|
224
|
-
connectAgent({ agent }: CopilotKitCoreConnectAgentParams): Promise<RunAgentResult>;
|
|
224
|
+
connectAgent({ agent, }: CopilotKitCoreConnectAgentParams): Promise<RunAgentResult>;
|
|
225
225
|
/**
|
|
226
226
|
* Run an agent
|
|
227
227
|
*/
|
|
228
|
-
runAgent({ agent }: CopilotKitCoreRunAgentParams): Promise<RunAgentResult>;
|
|
228
|
+
runAgent({ agent, }: CopilotKitCoreRunAgentParams): Promise<RunAgentResult>;
|
|
229
229
|
/**
|
|
230
230
|
* Process agent result and execute tools
|
|
231
231
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -221,11 +221,11 @@ declare class RunHandler {
|
|
|
221
221
|
/**
|
|
222
222
|
* Connect an agent (establish initial connection)
|
|
223
223
|
*/
|
|
224
|
-
connectAgent({ agent }: CopilotKitCoreConnectAgentParams): Promise<RunAgentResult>;
|
|
224
|
+
connectAgent({ agent, }: CopilotKitCoreConnectAgentParams): Promise<RunAgentResult>;
|
|
225
225
|
/**
|
|
226
226
|
* Run an agent
|
|
227
227
|
*/
|
|
228
|
-
runAgent({ agent }: CopilotKitCoreRunAgentParams): Promise<RunAgentResult>;
|
|
228
|
+
runAgent({ agent, }: CopilotKitCoreRunAgentParams): Promise<RunAgentResult>;
|
|
229
229
|
/**
|
|
230
230
|
* Process agent result and execute tools
|
|
231
231
|
*/
|
package/dist/index.js
CHANGED
|
@@ -65,7 +65,9 @@ var ProxiedCopilotRuntimeAgent = class extends import_client.HttpAgent {
|
|
|
65
65
|
const transport = config.transport ?? "rest";
|
|
66
66
|
const runUrl = transport === "single" ? normalizedRuntimeUrl ?? config.runtimeUrl ?? "" : `${normalizedRuntimeUrl ?? config.runtimeUrl}/agent/${encodeURIComponent(config.agentId ?? "")}/run`;
|
|
67
67
|
if (!runUrl) {
|
|
68
|
-
throw new Error(
|
|
68
|
+
throw new Error(
|
|
69
|
+
"ProxiedCopilotRuntimeAgent requires a runtimeUrl when transport is set to 'single'."
|
|
70
|
+
);
|
|
69
71
|
}
|
|
70
72
|
super({
|
|
71
73
|
...config,
|
|
@@ -89,7 +91,10 @@ var ProxiedCopilotRuntimeAgent = class extends import_client.HttpAgent {
|
|
|
89
91
|
if (!this.singleEndpointUrl) {
|
|
90
92
|
return;
|
|
91
93
|
}
|
|
92
|
-
const headers = new Headers({
|
|
94
|
+
const headers = new Headers({
|
|
95
|
+
...this.headers,
|
|
96
|
+
"Content-Type": "application/json"
|
|
97
|
+
});
|
|
93
98
|
void fetch(this.singleEndpointUrl, {
|
|
94
99
|
method: "POST",
|
|
95
100
|
headers,
|
|
@@ -129,13 +134,20 @@ var ProxiedCopilotRuntimeAgent = class extends import_client.HttpAgent {
|
|
|
129
134
|
if (!this.singleEndpointUrl) {
|
|
130
135
|
throw new Error("Single endpoint transport requires a runtimeUrl");
|
|
131
136
|
}
|
|
132
|
-
const requestInit = this.createSingleRouteRequestInit(
|
|
133
|
-
|
|
134
|
-
|
|
137
|
+
const requestInit = this.createSingleRouteRequestInit(
|
|
138
|
+
input,
|
|
139
|
+
"agent/connect",
|
|
140
|
+
{
|
|
141
|
+
agentId: this.agentId
|
|
142
|
+
}
|
|
143
|
+
);
|
|
135
144
|
const httpEvents2 = (0, import_client.runHttpRequest)(this.singleEndpointUrl, requestInit);
|
|
136
145
|
return withAbortErrorHandling((0, import_client.transformHttpEventStream)(httpEvents2));
|
|
137
146
|
}
|
|
138
|
-
const httpEvents = (0, import_client.runHttpRequest)(
|
|
147
|
+
const httpEvents = (0, import_client.runHttpRequest)(
|
|
148
|
+
`${this.runtimeUrl}/agent/${this.agentId}/connect`,
|
|
149
|
+
this.requestInit(input)
|
|
150
|
+
);
|
|
139
151
|
return withAbortErrorHandling((0, import_client.transformHttpEventStream)(httpEvents));
|
|
140
152
|
}
|
|
141
153
|
run(input) {
|
|
@@ -143,9 +155,13 @@ var ProxiedCopilotRuntimeAgent = class extends import_client.HttpAgent {
|
|
|
143
155
|
if (!this.singleEndpointUrl) {
|
|
144
156
|
throw new Error("Single endpoint transport requires a runtimeUrl");
|
|
145
157
|
}
|
|
146
|
-
const requestInit = this.createSingleRouteRequestInit(
|
|
147
|
-
|
|
148
|
-
|
|
158
|
+
const requestInit = this.createSingleRouteRequestInit(
|
|
159
|
+
input,
|
|
160
|
+
"agent/run",
|
|
161
|
+
{
|
|
162
|
+
agentId: this.agentId
|
|
163
|
+
}
|
|
164
|
+
);
|
|
149
165
|
const httpEvents = (0, import_client.runHttpRequest)(this.singleEndpointUrl, requestInit);
|
|
150
166
|
return withAbortErrorHandling((0, import_client.transformHttpEventStream)(httpEvents));
|
|
151
167
|
}
|
|
@@ -161,7 +177,9 @@ var ProxiedCopilotRuntimeAgent = class extends import_client.HttpAgent {
|
|
|
161
177
|
}
|
|
162
178
|
createSingleRouteRequestInit(input, method, params) {
|
|
163
179
|
if (!this.agentId) {
|
|
164
|
-
throw new Error(
|
|
180
|
+
throw new Error(
|
|
181
|
+
"ProxiedCopilotRuntimeAgent requires agentId to make runtime requests"
|
|
182
|
+
);
|
|
165
183
|
}
|
|
166
184
|
const baseInit = super.requestInit(input);
|
|
167
185
|
const headers = new Headers(baseInit.headers ?? {});
|
|
@@ -172,7 +190,10 @@ var ProxiedCopilotRuntimeAgent = class extends import_client.HttpAgent {
|
|
|
172
190
|
try {
|
|
173
191
|
originalBody = JSON.parse(baseInit.body);
|
|
174
192
|
} catch (error) {
|
|
175
|
-
console.warn(
|
|
193
|
+
console.warn(
|
|
194
|
+
"ProxiedCopilotRuntimeAgent: failed to parse request body for single route transport",
|
|
195
|
+
error
|
|
196
|
+
);
|
|
176
197
|
originalBody = void 0;
|
|
177
198
|
}
|
|
178
199
|
}
|
|
@@ -304,7 +325,9 @@ var AgentRegistry = class {
|
|
|
304
325
|
*/
|
|
305
326
|
applyHeadersToAgent(agent) {
|
|
306
327
|
if (agent instanceof import_client2.HttpAgent) {
|
|
307
|
-
agent.headers = {
|
|
328
|
+
agent.headers = {
|
|
329
|
+
...this.core.headers
|
|
330
|
+
};
|
|
308
331
|
}
|
|
309
332
|
}
|
|
310
333
|
/**
|
|
@@ -344,12 +367,16 @@ var AgentRegistry = class {
|
|
|
344
367
|
this._audioFileTranscriptionEnabled = false;
|
|
345
368
|
this.remoteAgents = {};
|
|
346
369
|
this._agents = this.localAgents;
|
|
347
|
-
await this.notifyRuntimeStatusChanged(
|
|
370
|
+
await this.notifyRuntimeStatusChanged(
|
|
371
|
+
"disconnected" /* Disconnected */
|
|
372
|
+
);
|
|
348
373
|
await this.notifyAgentsChanged();
|
|
349
374
|
return;
|
|
350
375
|
}
|
|
351
376
|
this._runtimeConnectionStatus = "connecting" /* Connecting */;
|
|
352
|
-
await this.notifyRuntimeStatusChanged(
|
|
377
|
+
await this.notifyRuntimeStatusChanged(
|
|
378
|
+
"connecting" /* Connecting */
|
|
379
|
+
);
|
|
353
380
|
try {
|
|
354
381
|
const runtimeInfoResponse = await this.fetchRuntimeInfo();
|
|
355
382
|
const {
|
|
@@ -376,7 +403,9 @@ var AgentRegistry = class {
|
|
|
376
403
|
this._runtimeConnectionStatus = "connected" /* Connected */;
|
|
377
404
|
this._runtimeVersion = version;
|
|
378
405
|
this._audioFileTranscriptionEnabled = runtimeInfoResponse.audioFileTranscriptionEnabled ?? false;
|
|
379
|
-
await this.notifyRuntimeStatusChanged(
|
|
406
|
+
await this.notifyRuntimeStatusChanged(
|
|
407
|
+
"connected" /* Connected */
|
|
408
|
+
);
|
|
380
409
|
await this.notifyAgentsChanged();
|
|
381
410
|
} catch (error) {
|
|
382
411
|
this._runtimeConnectionStatus = "error" /* Error */;
|
|
@@ -384,10 +413,14 @@ var AgentRegistry = class {
|
|
|
384
413
|
this._audioFileTranscriptionEnabled = false;
|
|
385
414
|
this.remoteAgents = {};
|
|
386
415
|
this._agents = this.localAgents;
|
|
387
|
-
await this.notifyRuntimeStatusChanged(
|
|
416
|
+
await this.notifyRuntimeStatusChanged(
|
|
417
|
+
"error" /* Error */
|
|
418
|
+
);
|
|
388
419
|
await this.notifyAgentsChanged();
|
|
389
420
|
const message = error instanceof Error ? error.message : JSON.stringify(error);
|
|
390
|
-
import_shared.logger.warn(
|
|
421
|
+
import_shared.logger.warn(
|
|
422
|
+
`Failed to load runtime info (${this.runtimeUrl}/info): ${message}`
|
|
423
|
+
);
|
|
391
424
|
const runtimeError = error instanceof Error ? error : new Error(String(error));
|
|
392
425
|
await this.core.emitError({
|
|
393
426
|
error: runtimeError,
|
|
@@ -418,7 +451,9 @@ var AgentRegistry = class {
|
|
|
418
451
|
...credentials ? { credentials } : {}
|
|
419
452
|
});
|
|
420
453
|
if ("ok" in response2 && !response2.ok) {
|
|
421
|
-
throw new Error(
|
|
454
|
+
throw new Error(
|
|
455
|
+
`Runtime info request failed with status ${response2.status}`
|
|
456
|
+
);
|
|
422
457
|
}
|
|
423
458
|
return await response2.json();
|
|
424
459
|
}
|
|
@@ -427,7 +462,9 @@ var AgentRegistry = class {
|
|
|
427
462
|
...credentials ? { credentials } : {}
|
|
428
463
|
});
|
|
429
464
|
if ("ok" in response && !response.ok) {
|
|
430
|
-
throw new Error(
|
|
465
|
+
throw new Error(
|
|
466
|
+
`Runtime info request failed with status ${response.status}`
|
|
467
|
+
);
|
|
431
468
|
}
|
|
432
469
|
return await response.json();
|
|
433
470
|
}
|
|
@@ -618,26 +655,33 @@ var SuggestionEngine = class {
|
|
|
618
655
|
async generateSuggestions(suggestionId, config, consumerAgentId) {
|
|
619
656
|
let agent = void 0;
|
|
620
657
|
try {
|
|
621
|
-
const suggestionsProviderAgent = this.core.getAgent(
|
|
622
|
-
config.providerAgentId ?? "default"
|
|
623
|
-
);
|
|
658
|
+
const suggestionsProviderAgent = this.core.getAgent(config.providerAgentId ?? "default");
|
|
624
659
|
if (!suggestionsProviderAgent) {
|
|
625
|
-
throw new Error(
|
|
660
|
+
throw new Error(
|
|
661
|
+
`Suggestions provider agent not found: ${config.providerAgentId}`
|
|
662
|
+
);
|
|
626
663
|
}
|
|
627
664
|
const suggestionsConsumerAgent = this.core.getAgent(consumerAgentId);
|
|
628
665
|
if (!suggestionsConsumerAgent) {
|
|
629
|
-
throw new Error(
|
|
666
|
+
throw new Error(
|
|
667
|
+
`Suggestions consumer agent not found: ${consumerAgentId}`
|
|
668
|
+
);
|
|
630
669
|
}
|
|
631
670
|
const clonedAgent = suggestionsProviderAgent.clone();
|
|
632
671
|
agent = clonedAgent;
|
|
633
672
|
agent.threadId = suggestionId;
|
|
634
|
-
agent.messages = JSON.parse(
|
|
673
|
+
agent.messages = JSON.parse(
|
|
674
|
+
JSON.stringify(suggestionsConsumerAgent.messages)
|
|
675
|
+
);
|
|
635
676
|
agent.state = JSON.parse(JSON.stringify(suggestionsConsumerAgent.state));
|
|
636
677
|
this._suggestions[consumerAgentId] = {
|
|
637
678
|
...this._suggestions[consumerAgentId] ?? {},
|
|
638
679
|
[suggestionId]: []
|
|
639
680
|
};
|
|
640
|
-
this._runningSuggestions[consumerAgentId] = [
|
|
681
|
+
this._runningSuggestions[consumerAgentId] = [
|
|
682
|
+
...this._runningSuggestions[consumerAgentId] ?? [],
|
|
683
|
+
agent
|
|
684
|
+
];
|
|
641
685
|
agent.addMessage({
|
|
642
686
|
id: suggestionId,
|
|
643
687
|
role: "user",
|
|
@@ -650,16 +694,26 @@ var SuggestionEngine = class {
|
|
|
650
694
|
});
|
|
651
695
|
await agent.runAgent(
|
|
652
696
|
{
|
|
653
|
-
context: Object.values(
|
|
697
|
+
context: Object.values(
|
|
698
|
+
this.core.context
|
|
699
|
+
),
|
|
654
700
|
forwardedProps: {
|
|
655
701
|
...this.core.properties,
|
|
656
|
-
toolChoice: {
|
|
702
|
+
toolChoice: {
|
|
703
|
+
type: "function",
|
|
704
|
+
function: { name: "copilotkitSuggest" }
|
|
705
|
+
}
|
|
657
706
|
},
|
|
658
707
|
tools: [SUGGEST_TOOL]
|
|
659
708
|
},
|
|
660
709
|
{
|
|
661
710
|
onMessagesChanged: ({ messages }) => {
|
|
662
|
-
this.extractSuggestions(
|
|
711
|
+
this.extractSuggestions(
|
|
712
|
+
messages,
|
|
713
|
+
suggestionId,
|
|
714
|
+
consumerAgentId,
|
|
715
|
+
true
|
|
716
|
+
);
|
|
663
717
|
}
|
|
664
718
|
}
|
|
665
719
|
);
|
|
@@ -685,7 +739,9 @@ var SuggestionEngine = class {
|
|
|
685
739
|
const agentSuggestions = this._suggestions[consumerAgentId];
|
|
686
740
|
const currentSuggestions = agentSuggestions?.[suggestionId];
|
|
687
741
|
if (agentSuggestions && currentSuggestions && currentSuggestions.length > 0) {
|
|
688
|
-
const finalizedSuggestions = currentSuggestions.filter(
|
|
742
|
+
const finalizedSuggestions = currentSuggestions.filter(
|
|
743
|
+
(suggestion) => suggestion.title !== "" || suggestion.message !== ""
|
|
744
|
+
).map((suggestion) => ({
|
|
689
745
|
...suggestion,
|
|
690
746
|
isLoading: false
|
|
691
747
|
}));
|
|
@@ -694,8 +750,14 @@ var SuggestionEngine = class {
|
|
|
694
750
|
} else {
|
|
695
751
|
delete agentSuggestions[suggestionId];
|
|
696
752
|
}
|
|
697
|
-
const allSuggestions = Object.values(
|
|
698
|
-
|
|
753
|
+
const allSuggestions = Object.values(
|
|
754
|
+
this._suggestions[consumerAgentId] ?? {}
|
|
755
|
+
).flat();
|
|
756
|
+
void this.notifySuggestionsChanged(
|
|
757
|
+
consumerAgentId,
|
|
758
|
+
allSuggestions,
|
|
759
|
+
"finalized"
|
|
760
|
+
);
|
|
699
761
|
}
|
|
700
762
|
}
|
|
701
763
|
/**
|
|
@@ -739,8 +801,14 @@ var SuggestionEngine = class {
|
|
|
739
801
|
const agentSuggestions = this._suggestions[consumerAgentId];
|
|
740
802
|
if (agentSuggestions) {
|
|
741
803
|
agentSuggestions[suggestionId] = suggestions;
|
|
742
|
-
const allSuggestions = Object.values(
|
|
743
|
-
|
|
804
|
+
const allSuggestions = Object.values(
|
|
805
|
+
this._suggestions[consumerAgentId] ?? {}
|
|
806
|
+
).flat();
|
|
807
|
+
void this.notifySuggestionsChanged(
|
|
808
|
+
consumerAgentId,
|
|
809
|
+
allSuggestions,
|
|
810
|
+
"suggestions changed"
|
|
811
|
+
);
|
|
744
812
|
}
|
|
745
813
|
}
|
|
746
814
|
/**
|
|
@@ -829,8 +897,14 @@ var SuggestionEngine = class {
|
|
|
829
897
|
...this._suggestions[consumerAgentId] ?? {},
|
|
830
898
|
[suggestionId]: suggestions
|
|
831
899
|
};
|
|
832
|
-
const allSuggestions = Object.values(
|
|
833
|
-
|
|
900
|
+
const allSuggestions = Object.values(
|
|
901
|
+
this._suggestions[consumerAgentId] ?? {}
|
|
902
|
+
).flat();
|
|
903
|
+
void this.notifySuggestionsChanged(
|
|
904
|
+
consumerAgentId,
|
|
905
|
+
allSuggestions,
|
|
906
|
+
"static suggestions added"
|
|
907
|
+
);
|
|
834
908
|
}
|
|
835
909
|
};
|
|
836
910
|
function isDynamicSuggestionsConfig(config) {
|
|
@@ -894,9 +968,13 @@ var RunHandler = class {
|
|
|
894
968
|
* Add a tool to the registry
|
|
895
969
|
*/
|
|
896
970
|
addTool(tool) {
|
|
897
|
-
const existingToolIndex = this._tools.findIndex(
|
|
971
|
+
const existingToolIndex = this._tools.findIndex(
|
|
972
|
+
(t) => t.name === tool.name && t.agentId === tool.agentId
|
|
973
|
+
);
|
|
898
974
|
if (existingToolIndex !== -1) {
|
|
899
|
-
import_shared4.logger.warn(
|
|
975
|
+
import_shared4.logger.warn(
|
|
976
|
+
`Tool already exists: '${tool.name}' for agent '${tool.agentId || "global"}', skipping.`
|
|
977
|
+
);
|
|
900
978
|
return;
|
|
901
979
|
}
|
|
902
980
|
this._tools.push(tool);
|
|
@@ -920,7 +998,9 @@ var RunHandler = class {
|
|
|
920
998
|
getTool(params) {
|
|
921
999
|
const { toolName, agentId } = params;
|
|
922
1000
|
if (agentId) {
|
|
923
|
-
const agentTool = this._tools.find(
|
|
1001
|
+
const agentTool = this._tools.find(
|
|
1002
|
+
(tool) => tool.name === toolName && tool.agentId === agentId
|
|
1003
|
+
);
|
|
924
1004
|
if (agentTool) {
|
|
925
1005
|
return agentTool;
|
|
926
1006
|
}
|
|
@@ -936,13 +1016,17 @@ var RunHandler = class {
|
|
|
936
1016
|
/**
|
|
937
1017
|
* Connect an agent (establish initial connection)
|
|
938
1018
|
*/
|
|
939
|
-
async connectAgent({
|
|
1019
|
+
async connectAgent({
|
|
1020
|
+
agent
|
|
1021
|
+
}) {
|
|
940
1022
|
try {
|
|
941
1023
|
await agent.detachActiveRun();
|
|
942
1024
|
agent.setMessages([]);
|
|
943
1025
|
agent.setState({});
|
|
944
1026
|
if (agent instanceof import_client3.HttpAgent) {
|
|
945
|
-
agent.headers = {
|
|
1027
|
+
agent.headers = {
|
|
1028
|
+
...this.core.headers
|
|
1029
|
+
};
|
|
946
1030
|
}
|
|
947
1031
|
const runAgentResult = await agent.connectAgent(
|
|
948
1032
|
{
|
|
@@ -969,19 +1053,25 @@ var RunHandler = class {
|
|
|
969
1053
|
/**
|
|
970
1054
|
* Run an agent
|
|
971
1055
|
*/
|
|
972
|
-
async runAgent({
|
|
1056
|
+
async runAgent({
|
|
1057
|
+
agent
|
|
1058
|
+
}) {
|
|
973
1059
|
if (agent.agentId) {
|
|
974
1060
|
void this.core.suggestionEngine.clearSuggestions(agent.agentId);
|
|
975
1061
|
}
|
|
976
1062
|
if (agent instanceof import_client3.HttpAgent) {
|
|
977
|
-
agent.headers = {
|
|
1063
|
+
agent.headers = {
|
|
1064
|
+
...this.core.headers
|
|
1065
|
+
};
|
|
978
1066
|
}
|
|
979
1067
|
try {
|
|
980
1068
|
const runAgentResult = await agent.runAgent(
|
|
981
1069
|
{
|
|
982
1070
|
forwardedProps: this.core.properties,
|
|
983
1071
|
tools: this.buildFrontendTools(agent.agentId),
|
|
984
|
-
context: Object.values(
|
|
1072
|
+
context: Object.values(
|
|
1073
|
+
this.core.context
|
|
1074
|
+
)
|
|
985
1075
|
},
|
|
986
1076
|
this.createAgentErrorSubscriber(agent)
|
|
987
1077
|
);
|
|
@@ -1013,20 +1103,37 @@ var RunHandler = class {
|
|
|
1013
1103
|
for (const message of newMessages) {
|
|
1014
1104
|
if (message.role === "assistant") {
|
|
1015
1105
|
for (const toolCall of message.toolCalls || []) {
|
|
1016
|
-
if (newMessages.findIndex(
|
|
1106
|
+
if (newMessages.findIndex(
|
|
1107
|
+
(m) => m.role === "tool" && m.toolCallId === toolCall.id
|
|
1108
|
+
) === -1) {
|
|
1017
1109
|
const tool = this.getTool({
|
|
1018
1110
|
toolName: toolCall.function.name,
|
|
1019
1111
|
agentId: agent.agentId
|
|
1020
1112
|
});
|
|
1021
1113
|
if (tool) {
|
|
1022
|
-
const followUp = await this.executeSpecificTool(
|
|
1114
|
+
const followUp = await this.executeSpecificTool(
|
|
1115
|
+
tool,
|
|
1116
|
+
toolCall,
|
|
1117
|
+
message,
|
|
1118
|
+
agent,
|
|
1119
|
+
agentId
|
|
1120
|
+
);
|
|
1023
1121
|
if (followUp) {
|
|
1024
1122
|
needsFollowUp = true;
|
|
1025
1123
|
}
|
|
1026
1124
|
} else {
|
|
1027
|
-
const wildcardTool = this.getTool({
|
|
1125
|
+
const wildcardTool = this.getTool({
|
|
1126
|
+
toolName: "*",
|
|
1127
|
+
agentId: agent.agentId
|
|
1128
|
+
});
|
|
1028
1129
|
if (wildcardTool) {
|
|
1029
|
-
const followUp = await this.executeWildcardTool(
|
|
1130
|
+
const followUp = await this.executeWildcardTool(
|
|
1131
|
+
wildcardTool,
|
|
1132
|
+
toolCall,
|
|
1133
|
+
message,
|
|
1134
|
+
agent,
|
|
1135
|
+
agentId
|
|
1136
|
+
);
|
|
1030
1137
|
if (followUp) {
|
|
1031
1138
|
needsFollowUp = true;
|
|
1032
1139
|
}
|
|
@@ -1085,7 +1192,10 @@ var RunHandler = class {
|
|
|
1085
1192
|
);
|
|
1086
1193
|
if (!errorMessage) {
|
|
1087
1194
|
try {
|
|
1088
|
-
const result = await tool.handler(parsedArgs, {
|
|
1195
|
+
const result = await tool.handler(parsedArgs, {
|
|
1196
|
+
toolCall,
|
|
1197
|
+
agent
|
|
1198
|
+
});
|
|
1089
1199
|
if (result === void 0 || result === null) {
|
|
1090
1200
|
toolCallResult = "";
|
|
1091
1201
|
} else if (typeof result === "string") {
|
|
@@ -1096,18 +1206,20 @@ var RunHandler = class {
|
|
|
1096
1206
|
} catch (error) {
|
|
1097
1207
|
const handlerError = error instanceof Error ? error : new Error(String(error));
|
|
1098
1208
|
errorMessage = handlerError.message;
|
|
1099
|
-
await this.core.emitError(
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1209
|
+
await this.core.emitError(
|
|
1210
|
+
{
|
|
1211
|
+
error: handlerError,
|
|
1212
|
+
code: "tool_handler_failed" /* TOOL_HANDLER_FAILED */,
|
|
1213
|
+
context: {
|
|
1214
|
+
agentId,
|
|
1215
|
+
toolCallId: toolCall.id,
|
|
1216
|
+
toolName: toolCall.function.name,
|
|
1217
|
+
parsedArgs,
|
|
1218
|
+
toolType: "specific",
|
|
1219
|
+
messageId: message.id
|
|
1220
|
+
}
|
|
1109
1221
|
}
|
|
1110
|
-
|
|
1222
|
+
);
|
|
1111
1223
|
}
|
|
1112
1224
|
}
|
|
1113
1225
|
if (errorMessage) {
|
|
@@ -1193,7 +1305,10 @@ var RunHandler = class {
|
|
|
1193
1305
|
);
|
|
1194
1306
|
if (!errorMessage) {
|
|
1195
1307
|
try {
|
|
1196
|
-
const result = await wildcardTool.handler(wildcardArgs, {
|
|
1308
|
+
const result = await wildcardTool.handler(wildcardArgs, {
|
|
1309
|
+
toolCall,
|
|
1310
|
+
agent
|
|
1311
|
+
});
|
|
1197
1312
|
if (result === void 0 || result === null) {
|
|
1198
1313
|
toolCallResult = "";
|
|
1199
1314
|
} else if (typeof result === "string") {
|
|
@@ -1204,18 +1319,20 @@ var RunHandler = class {
|
|
|
1204
1319
|
} catch (error) {
|
|
1205
1320
|
const handlerError = error instanceof Error ? error : new Error(String(error));
|
|
1206
1321
|
errorMessage = handlerError.message;
|
|
1207
|
-
await this.core.emitError(
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1322
|
+
await this.core.emitError(
|
|
1323
|
+
{
|
|
1324
|
+
error: handlerError,
|
|
1325
|
+
code: "tool_handler_failed" /* TOOL_HANDLER_FAILED */,
|
|
1326
|
+
context: {
|
|
1327
|
+
agentId,
|
|
1328
|
+
toolCallId: toolCall.id,
|
|
1329
|
+
toolName: toolCall.function.name,
|
|
1330
|
+
parsedArgs: wildcardArgs,
|
|
1331
|
+
toolType: "wildcard",
|
|
1332
|
+
messageId: message.id
|
|
1333
|
+
}
|
|
1217
1334
|
}
|
|
1218
|
-
|
|
1335
|
+
);
|
|
1219
1336
|
}
|
|
1220
1337
|
}
|
|
1221
1338
|
if (errorMessage) {
|
|
@@ -1281,9 +1398,13 @@ var RunHandler = class {
|
|
|
1281
1398
|
};
|
|
1282
1399
|
return {
|
|
1283
1400
|
onRunFailed: async ({ error }) => {
|
|
1284
|
-
await emitAgentError(
|
|
1285
|
-
|
|
1286
|
-
|
|
1401
|
+
await emitAgentError(
|
|
1402
|
+
error,
|
|
1403
|
+
"agent_run_failed_event" /* AGENT_RUN_FAILED_EVENT */,
|
|
1404
|
+
{
|
|
1405
|
+
source: "onRunFailed"
|
|
1406
|
+
}
|
|
1407
|
+
);
|
|
1287
1408
|
},
|
|
1288
1409
|
onRunErrorEvent: async ({ event }) => {
|
|
1289
1410
|
const eventError = event?.rawEvent instanceof Error ? event.rawEvent : event?.rawEvent?.error instanceof Error ? event.rawEvent.error : void 0;
|
|
@@ -1292,11 +1413,15 @@ var RunHandler = class {
|
|
|
1292
1413
|
if (event?.code && !rawError.code) {
|
|
1293
1414
|
rawError.code = event.code;
|
|
1294
1415
|
}
|
|
1295
|
-
await emitAgentError(
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1416
|
+
await emitAgentError(
|
|
1417
|
+
rawError,
|
|
1418
|
+
"agent_run_error_event" /* AGENT_RUN_ERROR_EVENT */,
|
|
1419
|
+
{
|
|
1420
|
+
source: "onRunErrorEvent",
|
|
1421
|
+
event,
|
|
1422
|
+
runtimeErrorCode: event?.code
|
|
1423
|
+
}
|
|
1424
|
+
);
|
|
1300
1425
|
}
|
|
1301
1426
|
};
|
|
1302
1427
|
}
|
|
@@ -1670,7 +1795,9 @@ var CopilotKitCore = class {
|
|
|
1670
1795
|
*/
|
|
1671
1796
|
setHeaders(headers) {
|
|
1672
1797
|
this._headers = headers;
|
|
1673
|
-
this.agentRegistry.applyHeadersToAgents(
|
|
1798
|
+
this.agentRegistry.applyHeadersToAgents(
|
|
1799
|
+
this.agentRegistry.agents
|
|
1800
|
+
);
|
|
1674
1801
|
void this.notifySubscribers(
|
|
1675
1802
|
(subscriber) => subscriber.onHeadersChanged?.({
|
|
1676
1803
|
copilotkit: this,
|
|
@@ -1681,7 +1808,9 @@ var CopilotKitCore = class {
|
|
|
1681
1808
|
}
|
|
1682
1809
|
setCredentials(credentials) {
|
|
1683
1810
|
this._credentials = credentials;
|
|
1684
|
-
this.agentRegistry.applyCredentialsToAgents(
|
|
1811
|
+
this.agentRegistry.applyCredentialsToAgents(
|
|
1812
|
+
this.agentRegistry.agents
|
|
1813
|
+
);
|
|
1685
1814
|
}
|
|
1686
1815
|
setProperties(properties) {
|
|
1687
1816
|
this._properties = properties;
|