@copilotkitnext/angular 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/esm2022/components/chat/copilot-chat.component.mjs +3 -2
- package/dist/esm2022/core/copilotkit.service.mjs +18 -21
- package/dist/esm2022/directives/copilotkit-agent.directive.mjs +8 -4
- package/dist/esm2022/directives/copilotkit-config.directive.mjs +1 -1
- package/dist/esm2022/utils/agent.utils.mjs +10 -10
- package/dist/fesm2022/copilotkitnext-angular.mjs +33 -34
- package/dist/fesm2022/copilotkitnext-angular.mjs.map +1 -1
- package/package.json +7 -7
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { InjectionToken, signal, computed, effect, untracked, Inject, Injectable, Optional, inject, DestroyRef, runInInjectionContext, ChangeDetectionStrategy, Component, ElementRef, ViewContainerRef, HostListener, Input, Directive, isDevMode, EventEmitter, Output, TemplateRef, ViewChild, ViewEncapsulation, ContentChild, ChangeDetectorRef, PLATFORM_ID, forwardRef, SkipSelf } from '@angular/core';
|
|
3
3
|
import { toObservable } from '@angular/core/rxjs-interop';
|
|
4
|
-
import { CopilotKitCore, ToolCallStatus, completePartialMarkdown } from '@copilotkitnext/core';
|
|
4
|
+
import { CopilotKitCore, CopilotKitCoreRuntimeConnectionStatus, ToolCallStatus, completePartialMarkdown, ProxiedCopilotRuntimeAgent } from '@copilotkitnext/core';
|
|
5
5
|
export { ToolCallStatus } from '@copilotkitnext/core';
|
|
6
6
|
import { DEFAULT_AGENT_ID, partialJSONParse, randomUUID } from '@copilotkitnext/shared';
|
|
7
7
|
import { Overlay, OverlayPositionBuilder, OverlayModule } from '@angular/cdk/overlay';
|
|
@@ -108,26 +108,24 @@ class CopilotKitService {
|
|
|
108
108
|
this._runtimeStateVersion = signal(0);
|
|
109
109
|
// Initialize computed signals for processed values
|
|
110
110
|
this._allTools = computed(() => {
|
|
111
|
-
const
|
|
112
|
-
// Add frontend tools
|
|
111
|
+
const toolMap = new Map();
|
|
113
112
|
this._frontendTools().forEach((tool) => {
|
|
114
|
-
|
|
113
|
+
toolMap.set(tool.name, tool);
|
|
115
114
|
});
|
|
116
|
-
// Process human-in-the-loop tools
|
|
117
115
|
this._humanInTheLoop().forEach((tool) => {
|
|
118
116
|
const frontendTool = {
|
|
119
117
|
name: tool.name,
|
|
120
118
|
description: tool.description,
|
|
121
119
|
parameters: tool.parameters,
|
|
122
120
|
followUp: tool.followUp,
|
|
123
|
-
handler: async (
|
|
121
|
+
handler: async () => {
|
|
124
122
|
console.warn(`Human-in-the-loop tool '${tool.name}' called but no interactive handler is set up.`);
|
|
125
123
|
return undefined;
|
|
126
124
|
},
|
|
127
125
|
};
|
|
128
|
-
|
|
126
|
+
toolMap.set(tool.name, frontendTool);
|
|
129
127
|
});
|
|
130
|
-
return
|
|
128
|
+
return Array.from(toolMap.values());
|
|
131
129
|
});
|
|
132
130
|
this._allRenderToolCalls = computed(() => {
|
|
133
131
|
const combined = [...this._renderToolCalls()];
|
|
@@ -194,11 +192,11 @@ class CopilotKitService {
|
|
|
194
192
|
* Process frontend tools and human-in-the-loop tools
|
|
195
193
|
*/
|
|
196
194
|
processTools(frontendTools, humanInTheLoop, renderToolCalls) {
|
|
197
|
-
const
|
|
195
|
+
const toolMap = new Map();
|
|
198
196
|
const allRenderToolCalls = [...renderToolCalls];
|
|
199
197
|
// Add frontend tools
|
|
200
198
|
frontendTools.forEach((tool) => {
|
|
201
|
-
|
|
199
|
+
toolMap.set(tool.name, tool);
|
|
202
200
|
// Add render component if provided
|
|
203
201
|
if (tool.render) {
|
|
204
202
|
allRenderToolCalls.push({
|
|
@@ -223,7 +221,7 @@ class CopilotKitService {
|
|
|
223
221
|
return undefined;
|
|
224
222
|
},
|
|
225
223
|
};
|
|
226
|
-
|
|
224
|
+
toolMap.set(tool.name, frontendTool);
|
|
227
225
|
// Add the render component
|
|
228
226
|
if (tool.render) {
|
|
229
227
|
allRenderToolCalls.push({
|
|
@@ -233,7 +231,7 @@ class CopilotKitService {
|
|
|
233
231
|
});
|
|
234
232
|
}
|
|
235
233
|
});
|
|
236
|
-
return { allTools, allRenderToolCalls };
|
|
234
|
+
return { allTools: Array.from(toolMap.values()), allRenderToolCalls };
|
|
237
235
|
}
|
|
238
236
|
/**
|
|
239
237
|
* Setup stability warning effects
|
|
@@ -268,7 +266,9 @@ class CopilotKitService {
|
|
|
268
266
|
// Sync runtime URL
|
|
269
267
|
effect(() => {
|
|
270
268
|
const url = this.runtimeUrl();
|
|
271
|
-
untracked(() =>
|
|
269
|
+
untracked(() => {
|
|
270
|
+
this.copilotkit.setRuntimeUrl(url);
|
|
271
|
+
});
|
|
272
272
|
});
|
|
273
273
|
// Sync headers
|
|
274
274
|
effect(() => {
|
|
@@ -288,9 +288,11 @@ class CopilotKitService {
|
|
|
288
288
|
// Sync tools - computed from frontend tools and human-in-the-loop
|
|
289
289
|
effect(() => {
|
|
290
290
|
const tools = this._allTools();
|
|
291
|
-
// Update copilotkit.tools directly since there's no setTools method
|
|
292
291
|
untracked(() => {
|
|
293
|
-
this.copilotkit
|
|
292
|
+
const setTools = this.copilotkit?.setTools;
|
|
293
|
+
if (typeof setTools === "function") {
|
|
294
|
+
setTools.call(this.copilotkit, tools);
|
|
295
|
+
}
|
|
294
296
|
});
|
|
295
297
|
});
|
|
296
298
|
}
|
|
@@ -299,12 +301,7 @@ class CopilotKitService {
|
|
|
299
301
|
*/
|
|
300
302
|
setupEventSubscription() {
|
|
301
303
|
const unsubscribe = this.copilotkit.subscribe({
|
|
302
|
-
|
|
303
|
-
// Increment version to notify all consumers that runtime state has changed
|
|
304
|
-
// This triggers re-evaluation of computed signals that depend on runtime state
|
|
305
|
-
this.notifyRuntimeStateChange();
|
|
306
|
-
},
|
|
307
|
-
onRuntimeLoadError: () => {
|
|
304
|
+
onRuntimeConnectionStatusChanged: () => {
|
|
308
305
|
// Increment version to notify all consumers that runtime state has changed
|
|
309
306
|
// This triggers re-evaluation of computed signals that depend on runtime state
|
|
310
307
|
this.notifyRuntimeStateChange();
|
|
@@ -1138,15 +1135,14 @@ function watchAgent(config) {
|
|
|
1138
1135
|
subscribeToAgent();
|
|
1139
1136
|
// Subscribe to CopilotKit changes to detect agent updates
|
|
1140
1137
|
const coreUnsubscribe = service.copilotkit.subscribe({
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
subscribeToAgent();
|
|
1138
|
+
onRuntimeConnectionStatusChanged({ status }) {
|
|
1139
|
+
if (status === CopilotKitCoreRuntimeConnectionStatus.Connected ||
|
|
1140
|
+
status === CopilotKitCoreRuntimeConnectionStatus.Disconnected ||
|
|
1141
|
+
status === CopilotKitCoreRuntimeConnectionStatus.Error) {
|
|
1142
|
+
// Re-check agent when runtime connection state changes
|
|
1143
|
+
currentAgent = updateAgent();
|
|
1144
|
+
subscribeToAgent();
|
|
1145
|
+
}
|
|
1150
1146
|
},
|
|
1151
1147
|
});
|
|
1152
1148
|
// Register cleanup
|
|
@@ -2446,9 +2442,12 @@ class CopilotKitAgentDirective {
|
|
|
2446
2442
|
subscribeToCore() {
|
|
2447
2443
|
// Subscribe to CopilotKit changes to detect agent updates
|
|
2448
2444
|
this.coreUnsubscribe = this.copilotkit.copilotkit.subscribe({
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2445
|
+
onRuntimeConnectionStatusChanged: ({ status }) => {
|
|
2446
|
+
if (status === CopilotKitCoreRuntimeConnectionStatus.Connected ||
|
|
2447
|
+
status === CopilotKitCoreRuntimeConnectionStatus.Disconnected) {
|
|
2448
|
+
// Re-check agent when runtime connection changes state
|
|
2449
|
+
this.setupAgent();
|
|
2450
|
+
}
|
|
2452
2451
|
},
|
|
2453
2452
|
});
|
|
2454
2453
|
}
|
|
@@ -9141,7 +9140,7 @@ class CopilotChatComponent {
|
|
|
9141
9140
|
a.threadId = this.threadId || this.generatedThreadId;
|
|
9142
9141
|
if (!this.hasConnectedOnce) {
|
|
9143
9142
|
this.hasConnectedOnce = true;
|
|
9144
|
-
if (
|
|
9143
|
+
if (a instanceof ProxiedCopilotRuntimeAgent) {
|
|
9145
9144
|
this.connectToAgent(a);
|
|
9146
9145
|
}
|
|
9147
9146
|
else {
|