@copilotkitnext/angular 0.0.2 → 0.0.5
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/README.md +3 -3
- package/dist/README.md +3 -3
- package/dist/components/chat/copilot-chat-assistant-message.component.d.ts +10 -10
- package/dist/components/chat/copilot-chat-message-view.component.d.ts +42 -42
- package/dist/components/chat/copilot-chat-view.component.d.ts +14 -14
- package/dist/core/copilotkit.providers.d.ts +1 -1
- package/dist/core/copilotkit.service.d.ts +5 -5
- package/dist/core/copilotkit.types.d.ts +8 -10
- package/dist/directives/copilotkit-frontend-tool.directive.d.ts +1 -1
- package/dist/esm2022/components/chat/copilot-chat-assistant-message-buttons.component.mjs +384 -0
- package/dist/esm2022/components/chat/copilot-chat-assistant-message-renderer.component.mjs +286 -0
- package/dist/esm2022/components/chat/copilot-chat-assistant-message-toolbar.component.mjs +27 -0
- package/dist/esm2022/components/chat/copilot-chat-assistant-message.component.mjs +433 -0
- package/dist/esm2022/components/chat/copilot-chat-assistant-message.types.mjs +2 -0
- package/dist/esm2022/components/chat/copilot-chat-audio-recorder.component.mjs +202 -0
- package/dist/esm2022/components/chat/copilot-chat-buttons.component.mjs +321 -0
- package/dist/esm2022/components/chat/copilot-chat-input-defaults.mjs +38 -0
- package/dist/esm2022/components/chat/copilot-chat-input.component.mjs +666 -0
- package/dist/esm2022/components/chat/copilot-chat-input.types.mjs +10 -0
- package/dist/esm2022/components/chat/copilot-chat-message-view-cursor.component.mjs +45 -0
- package/dist/esm2022/components/chat/copilot-chat-message-view.component.mjs +296 -0
- package/dist/esm2022/components/chat/copilot-chat-message-view.types.mjs +2 -0
- package/dist/esm2022/components/chat/copilot-chat-textarea.component.mjs +188 -0
- package/dist/esm2022/components/chat/copilot-chat-tool-calls-view.component.mjs +216 -0
- package/dist/esm2022/components/chat/copilot-chat-toolbar.component.mjs +25 -0
- package/dist/esm2022/components/chat/copilot-chat-tools-menu.component.mjs +199 -0
- package/dist/esm2022/components/chat/copilot-chat-user-message-branch-navigation.component.mjs +137 -0
- package/dist/esm2022/components/chat/copilot-chat-user-message-buttons.component.mjs +207 -0
- package/dist/esm2022/components/chat/copilot-chat-user-message-renderer.component.mjs +35 -0
- package/dist/esm2022/components/chat/copilot-chat-user-message-toolbar.component.mjs +34 -0
- package/dist/esm2022/components/chat/copilot-chat-user-message.component.mjs +341 -0
- package/dist/esm2022/components/chat/copilot-chat-user-message.types.mjs +2 -0
- package/dist/esm2022/components/chat/copilot-chat-view-disclaimer.component.mjs +52 -0
- package/dist/esm2022/components/chat/copilot-chat-view-feather.component.mjs +55 -0
- package/dist/esm2022/components/chat/copilot-chat-view-handlers.service.mjs +19 -0
- package/dist/esm2022/components/chat/copilot-chat-view-input-container.component.mjs +110 -0
- package/dist/esm2022/components/chat/copilot-chat-view-scroll-to-bottom-button.component.mjs +93 -0
- package/dist/esm2022/components/chat/copilot-chat-view-scroll-view.component.mjs +443 -0
- package/dist/esm2022/components/chat/copilot-chat-view.component.mjs +479 -0
- package/dist/esm2022/components/chat/copilot-chat-view.types.mjs +2 -0
- package/dist/esm2022/components/chat/copilot-chat.component.mjs +214 -0
- package/dist/esm2022/components/copilotkit-tool-render.component.mjs +153 -0
- package/dist/esm2022/copilotkitnext-angular.mjs +5 -0
- package/dist/esm2022/core/chat-configuration/chat-configuration.providers.mjs +65 -0
- package/dist/esm2022/core/chat-configuration/chat-configuration.service.mjs +145 -0
- package/dist/esm2022/core/chat-configuration/chat-configuration.types.mjs +26 -0
- package/dist/esm2022/core/copilotkit.providers.mjs +34 -0
- package/dist/esm2022/core/copilotkit.service.mjs +426 -0
- package/dist/esm2022/core/copilotkit.types.mjs +13 -0
- package/dist/esm2022/directives/copilotkit-agent-context.directive.mjs +130 -0
- package/dist/esm2022/directives/copilotkit-agent.directive.mjs +217 -0
- package/dist/esm2022/directives/copilotkit-chat-config.directive.mjs +218 -0
- package/dist/esm2022/directives/copilotkit-config.directive.mjs +94 -0
- package/dist/esm2022/directives/copilotkit-frontend-tool.directive.mjs +128 -0
- package/dist/esm2022/directives/copilotkit-human-in-the-loop.directive.mjs +265 -0
- package/dist/esm2022/directives/stick-to-bottom.directive.mjs +181 -0
- package/dist/esm2022/index.mjs +70 -0
- package/dist/esm2022/lib/directives/tooltip.directive.mjs +211 -0
- package/dist/esm2022/lib/slots/copilot-slot.component.mjs +144 -0
- package/dist/esm2022/lib/slots/slot.types.mjs +6 -0
- package/dist/esm2022/lib/slots/slot.utils.mjs +222 -0
- package/dist/esm2022/lib/utils.mjs +10 -0
- package/dist/esm2022/services/resize-observer.service.mjs +152 -0
- package/dist/esm2022/services/scroll-position.service.mjs +124 -0
- package/dist/esm2022/types/frontend-tool.mjs +2 -0
- package/dist/esm2022/types/human-in-the-loop.mjs +2 -0
- package/dist/esm2022/utils/agent-context.utils.mjs +114 -0
- package/dist/esm2022/utils/agent.utils.mjs +204 -0
- package/dist/esm2022/utils/chat-config.utils.mjs +186 -0
- package/dist/esm2022/utils/copilotkit.utils.mjs +20 -0
- package/dist/esm2022/utils/frontend-tool.utils.mjs +224 -0
- package/dist/esm2022/utils/human-in-the-loop.utils.mjs +293 -0
- package/dist/fesm2022/copilotkitnext-angular.mjs +174 -187
- package/dist/fesm2022/copilotkitnext-angular.mjs.map +1 -1
- package/dist/utils/frontend-tool.utils.d.ts +1 -1
- package/package.json +23 -20
- package/vitest.config.mts +32 -21
- package/.turbo/turbo-build.log +0 -38
- package/.turbo/turbo-check-types.log +0 -0
- package/.turbo/turbo-test.log +0 -71
- package/ng-package.json +0 -19
- package/src/components/chat/__tests__/copilot-chat-assistant-message.component.spec.ts +0 -282
- package/src/components/chat/__tests__/copilot-chat-input.component.spec.ts +0 -419
- package/src/components/chat/__tests__/copilot-chat-message-view.component.spec.ts +0 -372
- package/src/components/chat/__tests__/copilot-chat-user-message.component.spec.ts +0 -249
- package/src/components/chat/copilot-chat-assistant-message-buttons.component.ts +0 -292
- package/src/components/chat/copilot-chat-assistant-message-renderer.component.ts +0 -472
- package/src/components/chat/copilot-chat-assistant-message-toolbar.component.ts +0 -29
- package/src/components/chat/copilot-chat-assistant-message.component.ts +0 -463
- package/src/components/chat/copilot-chat-assistant-message.types.ts +0 -50
- package/src/components/chat/copilot-chat-audio-recorder.component.ts +0 -241
- package/src/components/chat/copilot-chat-buttons.component.ts +0 -308
- package/src/components/chat/copilot-chat-buttons.component.ts.bak +0 -471
- package/src/components/chat/copilot-chat-input-defaults.ts +0 -47
- package/src/components/chat/copilot-chat-input.component.ts +0 -512
- package/src/components/chat/copilot-chat-input.types.ts +0 -148
- package/src/components/chat/copilot-chat-message-view-cursor.component.ts +0 -51
- package/src/components/chat/copilot-chat-message-view.component.ts +0 -233
- package/src/components/chat/copilot-chat-message-view.types.ts +0 -39
- package/src/components/chat/copilot-chat-textarea.component.ts +0 -220
- package/src/components/chat/copilot-chat-tool-calls-view.component.ts +0 -261
- package/src/components/chat/copilot-chat-toolbar.component.ts +0 -35
- package/src/components/chat/copilot-chat-tools-menu.component.ts +0 -185
- package/src/components/chat/copilot-chat-user-message-branch-navigation.component.ts +0 -121
- package/src/components/chat/copilot-chat-user-message-buttons.component.ts +0 -170
- package/src/components/chat/copilot-chat-user-message-renderer.component.ts +0 -37
- package/src/components/chat/copilot-chat-user-message-toolbar.component.ts +0 -37
- package/src/components/chat/copilot-chat-user-message.component.ts +0 -247
- package/src/components/chat/copilot-chat-user-message.types.ts +0 -42
- package/src/components/chat/copilot-chat-view-disclaimer.component.ts +0 -51
- package/src/components/chat/copilot-chat-view-feather.component.ts +0 -47
- package/src/components/chat/copilot-chat-view-handlers.service.ts +0 -14
- package/src/components/chat/copilot-chat-view-input-container.component.ts +0 -87
- package/src/components/chat/copilot-chat-view-scroll-to-bottom-button.component.ts +0 -79
- package/src/components/chat/copilot-chat-view-scroll-view.component.ts +0 -322
- package/src/components/chat/copilot-chat-view.component.ts +0 -420
- package/src/components/chat/copilot-chat-view.types.ts +0 -52
- package/src/components/chat/copilot-chat.component.ts +0 -232
- package/src/components/copilotkit-tool-render.component.ts +0 -169
- package/src/core/__tests__/copilotkit.service.spec.ts +0 -1051
- package/src/core/__tests__/copilotkit.service.wildcard.spec.ts +0 -316
- package/src/core/chat-configuration/__tests__/chat-configuration.service.spec.ts +0 -287
- package/src/core/chat-configuration/chat-configuration.providers.ts +0 -71
- package/src/core/chat-configuration/chat-configuration.service.ts +0 -162
- package/src/core/chat-configuration/chat-configuration.types.ts +0 -57
- package/src/core/copilotkit.providers.ts +0 -59
- package/src/core/copilotkit.service.ts +0 -542
- package/src/core/copilotkit.types.ts +0 -132
- package/src/directives/__tests__/copilotkit-agent-context.directive.spec.ts +0 -384
- package/src/directives/__tests__/copilotkit-agent.directive.spec.ts +0 -253
- package/src/directives/__tests__/copilotkit-chat-config.directive.spec.ts +0 -385
- package/src/directives/__tests__/copilotkit-config.directive.spec.ts +0 -69
- package/src/directives/__tests__/copilotkit-frontend-tool-simple.directive.spec.ts +0 -60
- package/src/directives/__tests__/copilotkit-frontend-tool.directive.spec.ts +0 -108
- package/src/directives/__tests__/copilotkit-human-in-the-loop.directive.spec.ts +0 -452
- package/src/directives/copilotkit-agent-context.directive.ts +0 -138
- package/src/directives/copilotkit-agent.directive.ts +0 -225
- package/src/directives/copilotkit-chat-config.directive.ts +0 -241
- package/src/directives/copilotkit-config.directive.ts +0 -81
- package/src/directives/copilotkit-frontend-tool.directive.ts +0 -145
- package/src/directives/copilotkit-human-in-the-loop.directive.ts +0 -281
- package/src/directives/stick-to-bottom.directive.ts +0 -204
- package/src/index.ts +0 -105
- package/src/lib/directives/tooltip.directive.ts +0 -292
- package/src/lib/slots/__tests__/slot.utils.spec.ts +0 -377
- package/src/lib/slots/copilot-slot.component.ts +0 -135
- package/src/lib/slots/index.ts +0 -3
- package/src/lib/slots/slot.types.ts +0 -64
- package/src/lib/slots/slot.utils.ts +0 -289
- package/src/lib/utils.ts +0 -10
- package/src/public-api.ts +0 -1
- package/src/services/resize-observer.service.ts +0 -181
- package/src/services/scroll-position.service.ts +0 -169
- package/src/styles/globals.css +0 -266
- package/src/styles/index.css +0 -3
- package/src/test-setup.ts +0 -15
- package/src/testing/index.ts +0 -3
- package/src/testing/testing.utils.ts +0 -248
- package/src/types/frontend-tool.ts +0 -44
- package/src/types/human-in-the-loop.ts +0 -52
- package/src/utils/__tests__/agent.utils.spec.ts +0 -234
- package/src/utils/__tests__/chat-config.utils.spec.ts +0 -306
- package/src/utils/__tests__/frontend-tool-inject.spec.ts +0 -350
- package/src/utils/__tests__/frontend-tool-integration.spec.ts +0 -199
- package/src/utils/__tests__/frontend-tool.utils.spec.ts +0 -272
- package/src/utils/__tests__/human-in-the-loop.utils.spec.ts +0 -365
- package/src/utils/agent-context.utils.ts +0 -133
- package/src/utils/agent.utils.ts +0 -239
- package/src/utils/chat-config.utils.ts +0 -221
- package/src/utils/copilotkit.utils.ts +0 -20
- package/src/utils/frontend-tool.utils.ts +0 -266
- package/src/utils/human-in-the-loop.utils.ts +0 -359
- package/tsconfig.spec.json +0 -12
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Directive,
|
|
3
|
-
Input,
|
|
4
|
-
Output,
|
|
5
|
-
EventEmitter,
|
|
6
|
-
OnInit,
|
|
7
|
-
OnChanges,
|
|
8
|
-
OnDestroy,
|
|
9
|
-
SimpleChanges,
|
|
10
|
-
signal,
|
|
11
|
-
Inject,
|
|
12
|
-
} from "@angular/core";
|
|
13
|
-
import { toObservable } from "@angular/core/rxjs-interop";
|
|
14
|
-
import { Observable } from "rxjs";
|
|
15
|
-
import { CopilotKitService } from "../core/copilotkit.service";
|
|
16
|
-
import { AbstractAgent } from "@ag-ui/client";
|
|
17
|
-
import { DEFAULT_AGENT_ID } from "@copilotkitnext/shared";
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Directive to watch and interact with CopilotKit agents.
|
|
21
|
-
* Provides reactive outputs for agent state changes.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```html
|
|
25
|
-
* <!-- Basic usage with default agent -->
|
|
26
|
-
* <div copilotkitAgent
|
|
27
|
-
* (agentChange)="onAgentChange($event)"
|
|
28
|
-
* (runningChange)="isProcessing = $event">
|
|
29
|
-
* Content here
|
|
30
|
-
* </div>
|
|
31
|
-
*
|
|
32
|
-
* <!-- With specific agent ID -->
|
|
33
|
-
* <div copilotkitAgent
|
|
34
|
-
* [agentId]="'my-agent-id'"
|
|
35
|
-
* (agentChange)="currentAgent = $event"
|
|
36
|
-
* (runningChange)="onRunningStateChange($event)"
|
|
37
|
-
* (messagesChange)="onMessagesUpdate($event)"
|
|
38
|
-
* (stateChange)="onStateUpdate($event)">
|
|
39
|
-
* Content here
|
|
40
|
-
* </div>
|
|
41
|
-
*
|
|
42
|
-
* <!-- Two-way binding for running state -->
|
|
43
|
-
* <div copilotkitAgent
|
|
44
|
-
* [(running)]="isAgentRunning">
|
|
45
|
-
* <span *ngIf="isAgentRunning">Processing...</span>
|
|
46
|
-
* </div>
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
@Directive({
|
|
50
|
-
selector: "[copilotkitAgent]",
|
|
51
|
-
standalone: true,
|
|
52
|
-
})
|
|
53
|
-
export class CopilotKitAgentDirective implements OnInit, OnChanges, OnDestroy {
|
|
54
|
-
private agent?: AbstractAgent;
|
|
55
|
-
private agentSubscription?: { unsubscribe: () => void };
|
|
56
|
-
private coreUnsubscribe?: () => void; // subscribe returns function directly
|
|
57
|
-
private _isRunning = false;
|
|
58
|
-
private runningSignal = signal<boolean>(false);
|
|
59
|
-
private agentSignal = signal<AbstractAgent | undefined>(undefined);
|
|
60
|
-
|
|
61
|
-
constructor(
|
|
62
|
-
@Inject(CopilotKitService) private readonly copilotkit: CopilotKitService
|
|
63
|
-
) {}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* The ID of the agent to watch.
|
|
67
|
-
* If not provided, uses the default agent ID.
|
|
68
|
-
*/
|
|
69
|
-
@Input() agentId?: string;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Alternative input using the directive selector.
|
|
73
|
-
* Allows: [copilotkitAgent]="'agent-id'"
|
|
74
|
-
*/
|
|
75
|
-
@Input("copilotkitAgent")
|
|
76
|
-
set directiveAgentId(value: string | undefined) {
|
|
77
|
-
this.agentId = value || undefined;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Emits when the agent instance changes.
|
|
82
|
-
*/
|
|
83
|
-
@Output() agentChange = new EventEmitter<AbstractAgent | undefined>();
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Emits when the running state changes.
|
|
87
|
-
*/
|
|
88
|
-
@Output() runningChange = new EventEmitter<boolean>();
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Observable of the running state.
|
|
92
|
-
*/
|
|
93
|
-
get running$(): Observable<boolean> {
|
|
94
|
-
return toObservable(this.runningSignal);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Observable of the agent instance.
|
|
99
|
-
*/
|
|
100
|
-
get agent$(): Observable<AbstractAgent | undefined> {
|
|
101
|
-
return toObservable(this.agentSignal);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Two-way binding for running state.
|
|
106
|
-
*/
|
|
107
|
-
@Input()
|
|
108
|
-
get running(): boolean {
|
|
109
|
-
return this._isRunning;
|
|
110
|
-
}
|
|
111
|
-
set running(value: boolean) {
|
|
112
|
-
// Input setter for two-way binding (though typically read-only from agent)
|
|
113
|
-
this._isRunning = value;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Emits when agent messages change.
|
|
118
|
-
*/
|
|
119
|
-
@Output() messagesChange = new EventEmitter<any>();
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Emits when agent state changes.
|
|
123
|
-
*/
|
|
124
|
-
@Output() stateChange = new EventEmitter<any>();
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Emits when a run is initialized.
|
|
128
|
-
*/
|
|
129
|
-
@Output() runInitialized = new EventEmitter<any>();
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Emits when a run is finalized.
|
|
133
|
-
*/
|
|
134
|
-
@Output() runFinalized = new EventEmitter<any>();
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Emits when a run fails.
|
|
138
|
-
*/
|
|
139
|
-
@Output() runFailed = new EventEmitter<any>();
|
|
140
|
-
|
|
141
|
-
ngOnInit(): void {
|
|
142
|
-
this.setupAgent();
|
|
143
|
-
this.subscribeToCore();
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
ngOnChanges(changes: SimpleChanges): void {
|
|
147
|
-
if (changes["agentId"] && !changes["agentId"].firstChange) {
|
|
148
|
-
// Agent ID changed, re-setup
|
|
149
|
-
this.cleanupAgentSubscription();
|
|
150
|
-
this.setupAgent();
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
ngOnDestroy(): void {
|
|
155
|
-
this.cleanupAgentSubscription();
|
|
156
|
-
this.cleanupCoreSubscription();
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
private setupAgent(): void {
|
|
160
|
-
const effectiveAgentId = this.agentId ?? DEFAULT_AGENT_ID;
|
|
161
|
-
this.agent = this.copilotkit.getAgent(effectiveAgentId);
|
|
162
|
-
|
|
163
|
-
// Update signals
|
|
164
|
-
this.agentSignal.set(this.agent);
|
|
165
|
-
|
|
166
|
-
// Emit initial agent
|
|
167
|
-
this.agentChange.emit(this.agent);
|
|
168
|
-
|
|
169
|
-
// Subscribe to agent events
|
|
170
|
-
this.subscribeToAgent();
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
private subscribeToAgent(): void {
|
|
174
|
-
this.cleanupAgentSubscription();
|
|
175
|
-
|
|
176
|
-
if (this.agent) {
|
|
177
|
-
this.agentSubscription = this.agent.subscribe({
|
|
178
|
-
onMessagesChanged: (params) => {
|
|
179
|
-
this.messagesChange.emit(params);
|
|
180
|
-
},
|
|
181
|
-
onStateChanged: (params) => {
|
|
182
|
-
this.stateChange.emit(params);
|
|
183
|
-
},
|
|
184
|
-
onRunInitialized: (params) => {
|
|
185
|
-
this._isRunning = true;
|
|
186
|
-
this.runningSignal.set(true);
|
|
187
|
-
this.runningChange.emit(true);
|
|
188
|
-
this.runInitialized.emit(params);
|
|
189
|
-
},
|
|
190
|
-
onRunFinalized: (params) => {
|
|
191
|
-
this._isRunning = false;
|
|
192
|
-
this.runningSignal.set(false);
|
|
193
|
-
this.runningChange.emit(false);
|
|
194
|
-
this.runFinalized.emit(params);
|
|
195
|
-
},
|
|
196
|
-
onRunFailed: (params) => {
|
|
197
|
-
this._isRunning = false;
|
|
198
|
-
this.runningSignal.set(false);
|
|
199
|
-
this.runningChange.emit(false);
|
|
200
|
-
this.runFailed.emit(params);
|
|
201
|
-
},
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
private subscribeToCore(): void {
|
|
207
|
-
// Subscribe to CopilotKit changes to detect agent updates
|
|
208
|
-
this.coreUnsubscribe = this.copilotkit.copilotkit.subscribe({
|
|
209
|
-
onRuntimeLoaded: () => {
|
|
210
|
-
// Re-check agent when runtime loads
|
|
211
|
-
this.setupAgent();
|
|
212
|
-
},
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
private cleanupAgentSubscription(): void {
|
|
217
|
-
this.agentSubscription?.unsubscribe();
|
|
218
|
-
this.agentSubscription = undefined;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
private cleanupCoreSubscription(): void {
|
|
222
|
-
this.coreUnsubscribe?.();
|
|
223
|
-
this.coreUnsubscribe = undefined;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Directive,
|
|
3
|
-
Input,
|
|
4
|
-
Output,
|
|
5
|
-
EventEmitter,
|
|
6
|
-
OnInit,
|
|
7
|
-
OnChanges,
|
|
8
|
-
OnDestroy,
|
|
9
|
-
SimpleChanges,
|
|
10
|
-
Optional,
|
|
11
|
-
isDevMode,
|
|
12
|
-
Inject,
|
|
13
|
-
} from "@angular/core";
|
|
14
|
-
import { CopilotChatConfigurationService } from "../core/chat-configuration/chat-configuration.service";
|
|
15
|
-
import {
|
|
16
|
-
CopilotChatConfiguration,
|
|
17
|
-
CopilotChatLabels,
|
|
18
|
-
} from "../core/chat-configuration/chat-configuration.types";
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Directive for configuring CopilotKit chat settings declaratively in templates.
|
|
22
|
-
* Works with the CopilotChatConfigurationService to provide reactive chat configuration.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```html
|
|
26
|
-
* <!-- Basic usage with individual inputs -->
|
|
27
|
-
* <div copilotkitChatConfig
|
|
28
|
-
* [labels]="customLabels"
|
|
29
|
-
* [inputValue]="currentInput"
|
|
30
|
-
* (submitInput)="onSubmit($event)"
|
|
31
|
-
* (changeInput)="onChange($event)">
|
|
32
|
-
* <!-- Chat UI components -->
|
|
33
|
-
* </div>
|
|
34
|
-
*
|
|
35
|
-
* <!-- Using configuration object -->
|
|
36
|
-
* <div [copilotkitChatConfig]="chatConfig">
|
|
37
|
-
* <!-- Chat UI components -->
|
|
38
|
-
* </div>
|
|
39
|
-
*
|
|
40
|
-
* <!-- Two-way binding for input value -->
|
|
41
|
-
* <div copilotkitChatConfig
|
|
42
|
-
* [(value)]="chatInput"
|
|
43
|
-
* (submitInput)="handleSubmit($event)">
|
|
44
|
-
* <!-- Chat UI components -->
|
|
45
|
-
* </div>
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
@Directive({
|
|
49
|
-
selector: "[copilotkitChatConfig]",
|
|
50
|
-
standalone: true,
|
|
51
|
-
})
|
|
52
|
-
export class CopilotKitChatConfigDirective
|
|
53
|
-
implements OnInit, OnChanges, OnDestroy
|
|
54
|
-
{
|
|
55
|
-
private _value?: string;
|
|
56
|
-
private submitHandler?: (value: string) => void;
|
|
57
|
-
private changeHandler?: (value: string) => void;
|
|
58
|
-
|
|
59
|
-
constructor(
|
|
60
|
-
@Optional()
|
|
61
|
-
@Inject(CopilotChatConfigurationService)
|
|
62
|
-
private readonly chatConfig: CopilotChatConfigurationService | null
|
|
63
|
-
) {}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Partial labels to override defaults
|
|
67
|
-
*/
|
|
68
|
-
@Input() labels?: Partial<CopilotChatLabels>;
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* The current input value
|
|
72
|
-
*/
|
|
73
|
-
@Input() inputValue?: string;
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Event emitted when input is submitted
|
|
77
|
-
*/
|
|
78
|
-
@Output() submitInput = new EventEmitter<string>();
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Event emitted when input value changes
|
|
82
|
-
*/
|
|
83
|
-
@Output() changeInput = new EventEmitter<string>();
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Alternative: accept full configuration object
|
|
87
|
-
*/
|
|
88
|
-
@Input("copilotkitChatConfig")
|
|
89
|
-
set config(value: CopilotChatConfiguration | undefined) {
|
|
90
|
-
if (value) {
|
|
91
|
-
if (value.labels) this.labels = value.labels;
|
|
92
|
-
if (value.inputValue !== undefined) this.inputValue = value.inputValue;
|
|
93
|
-
// Store handlers for later setup
|
|
94
|
-
if (value.onSubmitInput) this.submitHandler = value.onSubmitInput;
|
|
95
|
-
if (value.onChangeInput) this.changeHandler = value.onChangeInput;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Two-way binding for input value
|
|
101
|
-
*/
|
|
102
|
-
@Input()
|
|
103
|
-
get value(): string | undefined {
|
|
104
|
-
return this._value;
|
|
105
|
-
}
|
|
106
|
-
set value(v: string | undefined) {
|
|
107
|
-
this._value = v;
|
|
108
|
-
this.valueChange.emit(v);
|
|
109
|
-
if (v !== undefined) {
|
|
110
|
-
this.updateInputValue(v);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Two-way binding output for value
|
|
116
|
-
*/
|
|
117
|
-
@Output() valueChange = new EventEmitter<string | undefined>();
|
|
118
|
-
|
|
119
|
-
ngOnInit(): void {
|
|
120
|
-
if (!this.chatConfig) {
|
|
121
|
-
if (isDevMode()) {
|
|
122
|
-
console.warn(
|
|
123
|
-
"CopilotKitChatConfigDirective: No CopilotChatConfigurationService found. " +
|
|
124
|
-
"Make sure to provide it using provideCopilotChatConfiguration()."
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
this.updateConfiguration();
|
|
131
|
-
this.setupHandlers();
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
ngOnChanges(changes: SimpleChanges): void {
|
|
135
|
-
if (!this.chatConfig) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const relevantChanges =
|
|
140
|
-
changes["labels"] || changes["inputValue"] || changes["value"];
|
|
141
|
-
|
|
142
|
-
if (relevantChanges && !relevantChanges.firstChange) {
|
|
143
|
-
this.updateConfiguration();
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
ngOnDestroy(): void {
|
|
148
|
-
// Cleanup if needed
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Submit the current input value
|
|
153
|
-
*/
|
|
154
|
-
submit(value: string): void {
|
|
155
|
-
// Emit to template binding
|
|
156
|
-
this.submitInput.emit(value);
|
|
157
|
-
|
|
158
|
-
// Call service handler
|
|
159
|
-
if (this.chatConfig) {
|
|
160
|
-
this.chatConfig.submitInput(value);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// Call provided handler
|
|
164
|
-
if (this.submitHandler) {
|
|
165
|
-
this.submitHandler(value);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Handle input value change
|
|
171
|
-
*/
|
|
172
|
-
change(value: string): void {
|
|
173
|
-
// Update internal value
|
|
174
|
-
this._value = value;
|
|
175
|
-
|
|
176
|
-
// Emit to template bindings
|
|
177
|
-
this.changeInput.emit(value);
|
|
178
|
-
this.valueChange.emit(value);
|
|
179
|
-
|
|
180
|
-
// Call service handler
|
|
181
|
-
if (this.chatConfig) {
|
|
182
|
-
this.chatConfig.changeInput(value);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// Call provided handler
|
|
186
|
-
if (this.changeHandler) {
|
|
187
|
-
this.changeHandler(value);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
private updateConfiguration(): void {
|
|
192
|
-
if (!this.chatConfig) {
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// Update labels if provided
|
|
197
|
-
if (this.labels) {
|
|
198
|
-
this.chatConfig.setLabels(this.labels);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// Update input value if provided
|
|
202
|
-
const valueToSet =
|
|
203
|
-
this._value !== undefined ? this._value : this.inputValue;
|
|
204
|
-
if (valueToSet !== undefined) {
|
|
205
|
-
this.chatConfig.setInputValue(valueToSet);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
private updateInputValue(value: string): void {
|
|
210
|
-
if (this.chatConfig) {
|
|
211
|
-
this.chatConfig.setInputValue(value);
|
|
212
|
-
this.chatConfig.changeInput(value);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
private setupHandlers(): void {
|
|
217
|
-
if (!this.chatConfig) {
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// Create composite handlers that call both service and directive handlers
|
|
222
|
-
const submitComposite = (value: string) => {
|
|
223
|
-
this.submitInput.emit(value);
|
|
224
|
-
if (this.submitHandler) {
|
|
225
|
-
this.submitHandler(value);
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
const changeComposite = (value: string) => {
|
|
230
|
-
this.changeInput.emit(value);
|
|
231
|
-
this.valueChange.emit(value);
|
|
232
|
-
if (this.changeHandler) {
|
|
233
|
-
this.changeHandler(value);
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
// Set handlers on the service
|
|
238
|
-
this.chatConfig.setSubmitHandler(submitComposite);
|
|
239
|
-
this.chatConfig.setChangeHandler(changeComposite);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { Directive, Input, OnChanges, SimpleChanges, Inject } from "@angular/core";
|
|
2
|
-
import { CopilotKitService } from "../core/copilotkit.service";
|
|
3
|
-
import { AbstractAgent } from "@ag-ui/client";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Directive to configure CopilotKit runtime settings declaratively in templates.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```html
|
|
10
|
-
* <div [copilotkitConfig]="{
|
|
11
|
-
* runtimeUrl: 'https://api.example.com',
|
|
12
|
-
* headers: { 'Authorization': 'Bearer token' }
|
|
13
|
-
* }">
|
|
14
|
-
* <!-- Your app content -->
|
|
15
|
-
* </div>
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
|
-
* Or with individual inputs:
|
|
19
|
-
* ```html
|
|
20
|
-
* <div copilotkitConfig
|
|
21
|
-
* [runtimeUrl]="apiUrl"
|
|
22
|
-
* [headers]="authHeaders"
|
|
23
|
-
* [agents]="myAgents">
|
|
24
|
-
* <!-- Your app content -->
|
|
25
|
-
* </div>
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
@Directive({
|
|
29
|
-
selector: "[copilotkitConfig]",
|
|
30
|
-
standalone: true,
|
|
31
|
-
})
|
|
32
|
-
export class CopilotKitConfigDirective implements OnChanges {
|
|
33
|
-
constructor(@Inject(CopilotKitService) private readonly copilotkit: CopilotKitService) {}
|
|
34
|
-
|
|
35
|
-
@Input() copilotkitConfig?: {
|
|
36
|
-
runtimeUrl?: string;
|
|
37
|
-
headers?: Record<string, string>;
|
|
38
|
-
properties?: Record<string, unknown>;
|
|
39
|
-
agents?: Record<string, AbstractAgent>;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
@Input() runtimeUrl?: string;
|
|
43
|
-
@Input() headers?: Record<string, string>;
|
|
44
|
-
@Input() properties?: Record<string, unknown>;
|
|
45
|
-
@Input() agents?: Record<string, AbstractAgent>;
|
|
46
|
-
|
|
47
|
-
ngOnChanges(changes: SimpleChanges): void {
|
|
48
|
-
// Handle combined config object
|
|
49
|
-
if (changes['copilotkitConfig']) {
|
|
50
|
-
const config = this.copilotkitConfig;
|
|
51
|
-
if (config) {
|
|
52
|
-
if (config.runtimeUrl !== undefined) {
|
|
53
|
-
this.copilotkit.setRuntimeUrl(config.runtimeUrl);
|
|
54
|
-
}
|
|
55
|
-
if (config.headers) {
|
|
56
|
-
this.copilotkit.setHeaders(config.headers);
|
|
57
|
-
}
|
|
58
|
-
if (config.properties) {
|
|
59
|
-
this.copilotkit.setProperties(config.properties);
|
|
60
|
-
}
|
|
61
|
-
if (config.agents) {
|
|
62
|
-
this.copilotkit.setAgents(config.agents);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Handle individual inputs
|
|
68
|
-
if (changes['runtimeUrl'] && !this.copilotkitConfig) {
|
|
69
|
-
this.copilotkit.setRuntimeUrl(this.runtimeUrl);
|
|
70
|
-
}
|
|
71
|
-
if (changes['headers'] && !this.copilotkitConfig) {
|
|
72
|
-
this.copilotkit.setHeaders(this.headers || {});
|
|
73
|
-
}
|
|
74
|
-
if (changes['properties'] && !this.copilotkitConfig) {
|
|
75
|
-
this.copilotkit.setProperties(this.properties || {});
|
|
76
|
-
}
|
|
77
|
-
if (changes['agents'] && !this.copilotkitConfig) {
|
|
78
|
-
this.copilotkit.setAgents(this.agents || {});
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Directive,
|
|
3
|
-
Input,
|
|
4
|
-
OnInit,
|
|
5
|
-
OnChanges,
|
|
6
|
-
OnDestroy,
|
|
7
|
-
SimpleChanges,
|
|
8
|
-
TemplateRef,
|
|
9
|
-
Type,
|
|
10
|
-
isDevMode,
|
|
11
|
-
Inject,
|
|
12
|
-
} from "@angular/core";
|
|
13
|
-
import { CopilotKitService } from "../core/copilotkit.service";
|
|
14
|
-
import type {
|
|
15
|
-
AngularFrontendTool,
|
|
16
|
-
AngularToolCallRender,
|
|
17
|
-
ToolCallRender,
|
|
18
|
-
} from "../core/copilotkit.types";
|
|
19
|
-
import { z } from "zod";
|
|
20
|
-
|
|
21
|
-
@Directive({
|
|
22
|
-
selector: "[copilotkitFrontendTool]",
|
|
23
|
-
standalone: true,
|
|
24
|
-
})
|
|
25
|
-
export class CopilotKitFrontendToolDirective<
|
|
26
|
-
T extends Record<string, any> = Record<string, any>,
|
|
27
|
-
>
|
|
28
|
-
implements OnInit, OnChanges, OnDestroy
|
|
29
|
-
{
|
|
30
|
-
private isRegistered = false;
|
|
31
|
-
|
|
32
|
-
constructor(
|
|
33
|
-
@Inject(CopilotKitService) private readonly copilotkit: CopilotKitService
|
|
34
|
-
) {}
|
|
35
|
-
|
|
36
|
-
@Input() name!: string;
|
|
37
|
-
@Input() description?: string;
|
|
38
|
-
@Input() parameters?: z.ZodSchema<T>;
|
|
39
|
-
@Input() handler?: (args: T) => Promise<any>;
|
|
40
|
-
@Input() render?: Type<any> | TemplateRef<any>;
|
|
41
|
-
@Input() followUp?: boolean;
|
|
42
|
-
|
|
43
|
-
// Alternative: Accept a full tool object
|
|
44
|
-
@Input("copilotkitFrontendTool") tool?: AngularFrontendTool<T>;
|
|
45
|
-
|
|
46
|
-
ngOnInit(): void {
|
|
47
|
-
this.registerTool();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
ngOnChanges(_changes: SimpleChanges): void {
|
|
51
|
-
if (this.isRegistered) {
|
|
52
|
-
// Re-register the tool if any properties change
|
|
53
|
-
this.unregisterTool();
|
|
54
|
-
this.registerTool();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
ngOnDestroy(): void {
|
|
59
|
-
this.unregisterTool();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
private registerTool(): void {
|
|
63
|
-
const tool = this.getTool();
|
|
64
|
-
|
|
65
|
-
if (!tool.name) {
|
|
66
|
-
if (isDevMode()) {
|
|
67
|
-
console.warn(
|
|
68
|
-
'CopilotKitFrontendToolDirective: "name" is required. ' +
|
|
69
|
-
'Please provide a name via [name]="toolName" or ' +
|
|
70
|
-
"[copilotkitFrontendTool]=\"{ name: 'toolName', ... }\""
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
return; // Don't register if no name
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Register the tool with CopilotKit
|
|
77
|
-
this.copilotkit.copilotkit.addTool(tool);
|
|
78
|
-
|
|
79
|
-
// Register the render if provided
|
|
80
|
-
if (tool.render) {
|
|
81
|
-
const currentRenders = this.copilotkit.currentRenderToolCalls();
|
|
82
|
-
const renderEntry: AngularToolCallRender = {
|
|
83
|
-
name: tool.name,
|
|
84
|
-
args: tool.parameters || z.object({}),
|
|
85
|
-
render: tool.render,
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
// Check for duplicate
|
|
89
|
-
const existingIndex = currentRenders.findIndex((r: ToolCallRender<unknown>) => r.name === tool.name);
|
|
90
|
-
if (existingIndex !== -1) {
|
|
91
|
-
if (isDevMode()) {
|
|
92
|
-
console.warn(
|
|
93
|
-
`[CopilotKit] Tool "${tool.name}" already has a render. ` +
|
|
94
|
-
`The previous render will be replaced. ` +
|
|
95
|
-
`This may indicate a duplicate tool registration.`
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
const updated = [...currentRenders];
|
|
99
|
-
updated[existingIndex] = renderEntry;
|
|
100
|
-
this.copilotkit.setCurrentRenderToolCalls(updated);
|
|
101
|
-
} else {
|
|
102
|
-
this.copilotkit.setCurrentRenderToolCalls([...currentRenders, renderEntry]);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
this.isRegistered = true;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
private unregisterTool(): void {
|
|
110
|
-
if (!this.isRegistered) return;
|
|
111
|
-
|
|
112
|
-
const tool = this.getTool();
|
|
113
|
-
|
|
114
|
-
if (tool.name) {
|
|
115
|
-
// Remove the tool
|
|
116
|
-
this.copilotkit.copilotkit.removeTool(tool.name);
|
|
117
|
-
|
|
118
|
-
// Remove the render if it exists
|
|
119
|
-
const currentRenders = this.copilotkit.currentRenderToolCalls();
|
|
120
|
-
const filtered = currentRenders.filter((r: ToolCallRender<unknown>) => r.name !== tool.name);
|
|
121
|
-
if (filtered.length !== currentRenders.length) {
|
|
122
|
-
this.copilotkit.setCurrentRenderToolCalls(filtered);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
this.isRegistered = false;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
private getTool(): AngularFrontendTool<T> {
|
|
130
|
-
// If full tool object is provided, use it
|
|
131
|
-
if (this.tool) {
|
|
132
|
-
return this.tool;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// Otherwise, construct from individual inputs
|
|
136
|
-
return {
|
|
137
|
-
name: this.name,
|
|
138
|
-
description: this.description,
|
|
139
|
-
parameters: this.parameters,
|
|
140
|
-
handler: this.handler,
|
|
141
|
-
render: this.render,
|
|
142
|
-
followUp: this.followUp,
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
}
|