@copilotkitnext/angular 0.0.0-0.0.0-max-changeset-10101010101010-20260109191632

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.
Files changed (118) hide show
  1. package/LICENSE +10 -0
  2. package/README.md +530 -0
  3. package/dist/LICENSE +10 -0
  4. package/dist/README.md +530 -0
  5. package/dist/esm2022/copilotkitnext-angular.mjs +5 -0
  6. package/dist/esm2022/index.mjs +2 -0
  7. package/dist/esm2022/lib/agent-context.mjs +25 -0
  8. package/dist/esm2022/lib/agent.mjs +73 -0
  9. package/dist/esm2022/lib/chat-config.mjs +35 -0
  10. package/dist/esm2022/lib/chat-state.mjs +18 -0
  11. package/dist/esm2022/lib/components/chat/copilot-chat-assistant-message-buttons.mjs +344 -0
  12. package/dist/esm2022/lib/components/chat/copilot-chat-assistant-message-renderer.mjs +260 -0
  13. package/dist/esm2022/lib/components/chat/copilot-chat-assistant-message-toolbar.mjs +22 -0
  14. package/dist/esm2022/lib/components/chat/copilot-chat-assistant-message.mjs +415 -0
  15. package/dist/esm2022/lib/components/chat/copilot-chat-assistant-message.types.mjs +2 -0
  16. package/dist/esm2022/lib/components/chat/copilot-chat-audio-recorder.mjs +196 -0
  17. package/dist/esm2022/lib/components/chat/copilot-chat-buttons.mjs +299 -0
  18. package/dist/esm2022/lib/components/chat/copilot-chat-input-defaults.mjs +39 -0
  19. package/dist/esm2022/lib/components/chat/copilot-chat-input.mjs +634 -0
  20. package/dist/esm2022/lib/components/chat/copilot-chat-input.types.mjs +10 -0
  21. package/dist/esm2022/lib/components/chat/copilot-chat-message-view-cursor.mjs +27 -0
  22. package/dist/esm2022/lib/components/chat/copilot-chat-message-view.mjs +268 -0
  23. package/dist/esm2022/lib/components/chat/copilot-chat-message-view.types.mjs +2 -0
  24. package/dist/esm2022/lib/components/chat/copilot-chat-textarea.mjs +139 -0
  25. package/dist/esm2022/lib/components/chat/copilot-chat-tool-calls-view.mjs +36 -0
  26. package/dist/esm2022/lib/components/chat/copilot-chat-toolbar.mjs +20 -0
  27. package/dist/esm2022/lib/components/chat/copilot-chat-tools-menu.mjs +203 -0
  28. package/dist/esm2022/lib/components/chat/copilot-chat-user-message-branch-navigation.mjs +98 -0
  29. package/dist/esm2022/lib/components/chat/copilot-chat-user-message-buttons.mjs +182 -0
  30. package/dist/esm2022/lib/components/chat/copilot-chat-user-message-renderer.mjs +28 -0
  31. package/dist/esm2022/lib/components/chat/copilot-chat-user-message-toolbar.mjs +25 -0
  32. package/dist/esm2022/lib/components/chat/copilot-chat-user-message.mjs +308 -0
  33. package/dist/esm2022/lib/components/chat/copilot-chat-user-message.types.mjs +2 -0
  34. package/dist/esm2022/lib/components/chat/copilot-chat-view-disclaimer.mjs +48 -0
  35. package/dist/esm2022/lib/components/chat/copilot-chat-view-feather.mjs +41 -0
  36. package/dist/esm2022/lib/components/chat/copilot-chat-view-handlers.mjs +19 -0
  37. package/dist/esm2022/lib/components/chat/copilot-chat-view-input-container.mjs +96 -0
  38. package/dist/esm2022/lib/components/chat/copilot-chat-view-scroll-to-bottom-button.mjs +89 -0
  39. package/dist/esm2022/lib/components/chat/copilot-chat-view-scroll-view.mjs +456 -0
  40. package/dist/esm2022/lib/components/chat/copilot-chat-view.mjs +404 -0
  41. package/dist/esm2022/lib/components/chat/copilot-chat-view.types.mjs +2 -0
  42. package/dist/esm2022/lib/components/chat/copilot-chat.mjs +167 -0
  43. package/dist/esm2022/lib/config.mjs +9 -0
  44. package/dist/esm2022/lib/copilotkit.mjs +115 -0
  45. package/dist/esm2022/lib/directives/copilotkit-agent-context.mjs +130 -0
  46. package/dist/esm2022/lib/directives/stick-to-bottom.mjs +170 -0
  47. package/dist/esm2022/lib/directives/tooltip.mjs +217 -0
  48. package/dist/esm2022/lib/human-in-the-loop.mjs +19 -0
  49. package/dist/esm2022/lib/render-tool-calls.mjs +138 -0
  50. package/dist/esm2022/lib/resize-observer.mjs +152 -0
  51. package/dist/esm2022/lib/scroll-position.mjs +124 -0
  52. package/dist/esm2022/lib/slots/copilot-slot.mjs +156 -0
  53. package/dist/esm2022/lib/slots/index.mjs +4 -0
  54. package/dist/esm2022/lib/slots/slot.types.mjs +6 -0
  55. package/dist/esm2022/lib/slots/slot.utils.mjs +235 -0
  56. package/dist/esm2022/lib/tools.mjs +31 -0
  57. package/dist/esm2022/lib/utils.mjs +10 -0
  58. package/dist/esm2022/public-api.mjs +48 -0
  59. package/dist/fesm2022/copilotkitnext-angular.mjs +6310 -0
  60. package/dist/fesm2022/copilotkitnext-angular.mjs.map +1 -0
  61. package/dist/index.d.ts +1 -0
  62. package/dist/lib/agent-context.d.ts +12 -0
  63. package/dist/lib/agent.d.ts +68 -0
  64. package/dist/lib/chat-config.d.ts +23 -0
  65. package/dist/lib/chat-state.d.ts +10 -0
  66. package/dist/lib/components/chat/copilot-chat-assistant-message-buttons.d.ts +68 -0
  67. package/dist/lib/components/chat/copilot-chat-assistant-message-renderer.d.ts +26 -0
  68. package/dist/lib/components/chat/copilot-chat-assistant-message-toolbar.d.ts +7 -0
  69. package/dist/lib/components/chat/copilot-chat-assistant-message.d.ts +208 -0
  70. package/dist/lib/components/chat/copilot-chat-assistant-message.types.d.ts +31 -0
  71. package/dist/lib/components/chat/copilot-chat-audio-recorder.d.ts +40 -0
  72. package/dist/lib/components/chat/copilot-chat-buttons.d.ts +65 -0
  73. package/dist/lib/components/chat/copilot-chat-input-defaults.d.ts +38 -0
  74. package/dist/lib/components/chat/copilot-chat-input.d.ts +133 -0
  75. package/dist/lib/components/chat/copilot-chat-input.types.d.ts +129 -0
  76. package/dist/lib/components/chat/copilot-chat-message-view-cursor.d.ts +11 -0
  77. package/dist/lib/components/chat/copilot-chat-message-view.d.ts +430 -0
  78. package/dist/lib/components/chat/copilot-chat-message-view.types.d.ts +24 -0
  79. package/dist/lib/components/chat/copilot-chat-textarea.d.ts +41 -0
  80. package/dist/lib/components/chat/copilot-chat-tool-calls-view.d.ts +70 -0
  81. package/dist/lib/components/chat/copilot-chat-toolbar.d.ts +7 -0
  82. package/dist/lib/components/chat/copilot-chat-tools-menu.d.ts +20 -0
  83. package/dist/lib/components/chat/copilot-chat-user-message-branch-navigation.d.ts +35 -0
  84. package/dist/lib/components/chat/copilot-chat-user-message-buttons.d.ts +35 -0
  85. package/dist/lib/components/chat/copilot-chat-user-message-renderer.d.ts +8 -0
  86. package/dist/lib/components/chat/copilot-chat-user-message-toolbar.d.ts +7 -0
  87. package/dist/lib/components/chat/copilot-chat-user-message.d.ts +71 -0
  88. package/dist/lib/components/chat/copilot-chat-user-message.types.d.ts +27 -0
  89. package/dist/lib/components/chat/copilot-chat-view-disclaimer.d.ts +15 -0
  90. package/dist/lib/components/chat/copilot-chat-view-feather.d.ts +15 -0
  91. package/dist/lib/components/chat/copilot-chat-view-handlers.d.ts +11 -0
  92. package/dist/lib/components/chat/copilot-chat-view-input-container.d.ts +23 -0
  93. package/dist/lib/components/chat/copilot-chat-view-scroll-to-bottom-button.d.ts +16 -0
  94. package/dist/lib/components/chat/copilot-chat-view-scroll-view.d.ts +129 -0
  95. package/dist/lib/components/chat/copilot-chat-view.d.ts +284 -0
  96. package/dist/lib/components/chat/copilot-chat-view.types.d.ts +42 -0
  97. package/dist/lib/components/chat/copilot-chat.d.ts +82 -0
  98. package/dist/lib/config.d.ts +16 -0
  99. package/dist/lib/copilotkit.d.ts +29 -0
  100. package/dist/lib/directives/copilotkit-agent-context.d.ts +68 -0
  101. package/dist/lib/directives/stick-to-bottom.d.ts +62 -0
  102. package/dist/lib/directives/tooltip.d.ts +33 -0
  103. package/dist/lib/human-in-the-loop.d.ts +13 -0
  104. package/dist/lib/render-tool-calls.d.ts +90 -0
  105. package/dist/lib/resize-observer.d.ts +44 -0
  106. package/dist/lib/scroll-position.d.ts +50 -0
  107. package/dist/lib/slots/copilot-slot.d.ts +34 -0
  108. package/dist/lib/slots/index.d.ts +3 -0
  109. package/dist/lib/slots/slot.types.d.ts +55 -0
  110. package/dist/lib/slots/slot.utils.d.ts +110 -0
  111. package/dist/lib/tools.d.ts +65 -0
  112. package/dist/lib/utils.d.ts +6 -0
  113. package/dist/public-api.d.ts +47 -0
  114. package/dist/styles.css +1882 -0
  115. package/eslint.config.mjs +20 -0
  116. package/package.json +101 -0
  117. package/tsconfig.json +33 -0
  118. package/vitest.config.mts +45 -0
package/LICENSE ADDED
@@ -0,0 +1,10 @@
1
+ Proprietary License
2
+
3
+ Copyright 2025 Tawkit Inc.
4
+
5
+ All rights reserved.
6
+
7
+ This software is proprietary and confidential.
8
+ Unauthorized copying, modification, distribution, or use of this software,
9
+ via any medium, is strictly prohibited without prior written permission
10
+ from the copyright holder.
package/README.md ADDED
@@ -0,0 +1,530 @@
1
+ # CopilotKit for Angular
2
+
3
+ This package provides native Angular components, directives, and providers to build Copilot chat UIs powered by the CopilotKit runtime and AG-UI agents. It mirrors the React experience with idiomatic Angular APIs.
4
+
5
+ ## Quick Start
6
+
7
+ 1. **Install**: `pnpm add @copilotkitnext/angular`
8
+ 2. **Add styles**: Add `@copilotkitnext/angular/styles.css` to your Angular app styles array or `@import "@copilotkitnext/angular/styles.css";` in a global stylesheet
9
+ 3. **Provide CopilotKit**: Set the runtime URL and optional labels via providers
10
+ 4. **Use the chat**: Drop `<copilot-chat />` into any template
11
+
12
+ ## Installation
13
+
14
+ ### Package Installation
15
+
16
+ Install `@copilotkitnext/angular` in your Angular app (supports Angular 18 and 19):
17
+
18
+ ```bash
19
+ # pnpm (recommended)
20
+ pnpm add @copilotkitnext/angular
21
+
22
+ # npm
23
+ npm install @copilotkitnext/angular
24
+
25
+ # yarn
26
+ yarn add @copilotkitnext/angular
27
+ ```
28
+
29
+ ### Peer Dependencies
30
+
31
+ Ensure these are present (matching your Angular major):
32
+
33
+ - `@angular/core`
34
+ - `@angular/common`
35
+ - `@angular/cdk` (use `^18` with Angular 18, `^19` with Angular 19)
36
+ - `rxjs`
37
+ - `tslib`
38
+
39
+ ### Styles
40
+
41
+ Reference the package CSS so the components render correctly:
42
+
43
+ **Option 1:** In `angular.json`:
44
+
45
+ ```json
46
+ "styles": [
47
+ "@copilotkitnext/angular/styles.css",
48
+ "src/styles.css"
49
+ ]
50
+ ```
51
+
52
+ **Option 2:** In your global stylesheet:
53
+
54
+ ```css
55
+ @import "@copilotkitnext/angular/styles.css";
56
+ ```
57
+
58
+ ## App Wiring (Providers)
59
+
60
+ Add CopilotKit providers in your application config to set labels and runtime URL.
61
+
62
+ ### Example (`app.config.ts`):
63
+
64
+ ```typescript
65
+ import {
66
+ provideCopilotKit,
67
+ provideCopilotChatConfiguration,
68
+ } from "@copilotkitnext/angular";
69
+
70
+ export const appConfig: ApplicationConfig = {
71
+ providers: [
72
+ importProvidersFrom(BrowserModule),
73
+ ...provideCopilotKit({
74
+ // runtimeUrl can also be set via template directive; see below
75
+ }),
76
+ provideCopilotChatConfiguration({
77
+ labels: {
78
+ chatInputPlaceholder: "Ask me anything...",
79
+ chatDisclaimerText: "AI responses may need verification.",
80
+ },
81
+ }),
82
+ ],
83
+ };
84
+ ```
85
+
86
+ ## Runtime URL (Template Directive)
87
+
88
+ You can declare the CopilotKit runtime endpoint directly in templates via the `CopilotKitConfigDirective`.
89
+
90
+ ### Component Template Example:
91
+
92
+ ```html
93
+ <div
94
+ [copilotkitConfig]="{ runtimeUrl: runtimeUrl }"
95
+ style="display:block;height:100vh"
96
+ >
97
+ <copilot-chat></copilot-chat>
98
+ </div>
99
+ ```
100
+
101
+ ### Component Class:
102
+
103
+ ```typescript
104
+ export class AppComponent {
105
+ runtimeUrl = "http://localhost:3001/api/copilotkit";
106
+ }
107
+ ```
108
+
109
+ ## Using the Chat Component
110
+
111
+ ### Minimal Usage:
112
+
113
+ ```html
114
+ <copilot-chat></copilot-chat>
115
+ ```
116
+
117
+ ### With a Specific Agent:
118
+
119
+ ```html
120
+ <copilot-chat [agentId]="'sales'"></copilot-chat>
121
+ ```
122
+
123
+ ### Behavior:
124
+
125
+ - If `agentId` is omitted, the component uses the default agent (ID: `default`)
126
+
127
+ ## Custom Input Components (Angular)
128
+
129
+ When building custom input components for CopilotKit Angular, use the service-based pattern with `CopilotChatConfigurationService` for message submission. This is the idiomatic Angular approach leveraging dependency injection.
130
+
131
+ ### Service-Based Custom Input Example:
132
+
133
+ ```typescript
134
+ import { Component } from '@angular/core';
135
+ import { FormsModule } from '@angular/forms';
136
+ import { CopilotChatConfigurationService } from '@copilotkitnext/angular';
137
+
138
+ @Component({
139
+ selector: 'my-custom-input',
140
+ standalone: true,
141
+ imports: [FormsModule],
142
+ template: `
143
+ <div class="custom-input-wrapper">
144
+ <input
145
+ [(ngModel)]="inputValue"
146
+ (keyup.enter)="submitMessage()"
147
+ placeholder="Type your message..."
148
+ />
149
+ <button (click)="submitMessage()">Send</button>
150
+ </div>
151
+ `
152
+ })
153
+ export class MyCustomInputComponent {
154
+ inputValue = '';
155
+
156
+ constructor(private chat: CopilotChatConfigurationService) {}
157
+
158
+ submitMessage() {
159
+ const value = this.inputValue.trim();
160
+ if (value) {
161
+ // Use the service to submit the message
162
+ this.chat.submitInput(value);
163
+ this.inputValue = '';
164
+ }
165
+ }
166
+ }
167
+ ```
168
+
169
+ ### Using the Custom Input Component:
170
+
171
+ ```typescript
172
+ import { Component } from '@angular/core';
173
+ import { CopilotChatViewComponent } from '@copilotkitnext/angular';
174
+ import { MyCustomInputComponent } from './my-custom-input.component';
175
+
176
+ @Component({
177
+ selector: 'app-chat',
178
+ standalone: true,
179
+ imports: [CopilotChatViewComponent],
180
+ template: `
181
+ <copilot-chat-view
182
+ [messages]="messages"
183
+ [inputComponent]="customInputComponent">
184
+ </copilot-chat-view>
185
+ `
186
+ })
187
+ export class ChatComponent {
188
+ messages = [];
189
+ customInputComponent = MyCustomInputComponent;
190
+ }
191
+ ```
192
+
193
+ ### Key Points:
194
+
195
+ - **No callback props**: Unlike React which uses `onSubmitMessage` callbacks, Angular uses dependency injection
196
+ - **Service injection**: Inject `CopilotChatConfigurationService` to access `submitInput()`
197
+ - **Cross-component communication**: The service handles message submission internally
198
+ - **Type safety**: Full TypeScript support with proper type inference
199
+
200
+ ### Alternative: Using the Chat Config Directive
201
+
202
+ For template-level hooks, you can also use the `copilotkitChatConfig` directive:
203
+
204
+ ```html
205
+ <div [copilotkitChatConfig]="{
206
+ onSubmitInput: handleSubmit,
207
+ onChangeInput: handleChange
208
+ }">
209
+ <copilot-chat></copilot-chat>
210
+ </div>
211
+ ```
212
+
213
+ ```typescript
214
+ export class ChatComponent {
215
+ handleSubmit = (value: string) => {
216
+ console.log('Message submitted:', value);
217
+ };
218
+
219
+ handleChange = (value: string) => {
220
+ console.log('Input changed:', value);
221
+ };
222
+ }
223
+ ```
224
+
225
+ ## Agents 101 (AG-UI)
226
+
227
+ - **Agent model**: CopilotKit uses AG-UI's `AbstractAgent` interface (package `@ag-ui/client`)
228
+ - **Frontend vs backend**:
229
+ - **Backend (runtime)**: Host your real agents. You can use any AG-UI agent on the server
230
+ - **Frontend (Angular app)**: Discovers remote agents from the runtime automatically, and can also host local in-browser agents if desired
231
+ - **Default agent**: The ID `default` is special; when present, it is used by `<copilot-chat>` if no `agentId` is provided
232
+ - **Compatibility**: Any agent that supports AG-UI works. See https://docs.ag-ui.com/
233
+
234
+ > **Note**: In most real apps, you define agents on the server (runtime). The frontend will auto-discover them when a `runtimeUrl` is configured.
235
+
236
+ ## Backend Runtime (Hono Server)
237
+
238
+ Example Angular server (from `apps/angular/demo-server`):
239
+
240
+ ### `index.ts`
241
+
242
+ ```typescript
243
+ import { serve } from "@hono/node-server";
244
+ import { Hono } from "hono";
245
+ import { cors } from "hono/cors";
246
+ import {
247
+ CopilotRuntime,
248
+ createCopilotEndpoint,
249
+ InMemoryAgentRunner,
250
+ } from "@copilotkitnext/runtime";
251
+ import { AnyAGUIAgent } from "@ag-ui/your-desired-agent-framework";
252
+
253
+ const runtime = new CopilotRuntime({
254
+ agents: { default: new AnyAGUIAgent() },
255
+ });
256
+
257
+ // Create a main app with CORS enabled
258
+ const app = new Hono();
259
+
260
+ // Enable CORS for local dev (Angular demo at http://localhost:4200)
261
+ app.use(
262
+ "*",
263
+ cors({
264
+ origin: "http://localhost:4200",
265
+ allowMethods: ["GET", "POST", "OPTIONS", "PUT", "DELETE"],
266
+ allowHeaders: ["Content-Type", "Authorization", "X-Requested-With"],
267
+ exposeHeaders: ["Content-Type"],
268
+ credentials: true,
269
+ maxAge: 86400,
270
+ })
271
+ );
272
+
273
+ // Create the CopilotKit endpoint
274
+ const copilotApp = createCopilotEndpoint({
275
+ runtime,
276
+ basePath: "/api/copilotkit",
277
+ });
278
+
279
+ // Mount the CopilotKit app
280
+ app.route("/", copilotApp);
281
+
282
+ const port = Number(process.env.PORT || 3001);
283
+ serve({ fetch: app.fetch, port });
284
+ console.log(
285
+ `CopilotKit runtime listening at http://localhost:${port}/api/copilotkit`
286
+ );
287
+ ```
288
+
289
+ ## CopilotKit Angular APIs (Most Used)
290
+
291
+ ### Components
292
+
293
+ - **`CopilotChatComponent`**: Full chat UI
294
+ - Inputs: `agentId?: string`
295
+
296
+ ### Directives
297
+
298
+ - **`CopilotKitConfigDirective`** (`[copilotkitConfig]`): Set `runtimeUrl`, `headers`, `properties`, and/or `agents` declaratively
299
+ - **`CopilotKitAgentDirective`** (`[copilotkitAgent]`): Observe agent state; defaults to the `default` agent if no `agentId` is provided
300
+
301
+ ### Providers
302
+
303
+ - **`provideCopilotKit(...)`**: Set runtime URL, headers, properties, agents, tools, human-in-the-loop handlers
304
+ - **`provideCopilotChatConfiguration(...)`**: Set UI labels and behavior for chat input/view
305
+
306
+ ## Headless Usage: Building Custom Chat UIs
307
+
308
+ For advanced use cases where you need full control over the chat UI, you can use the `watchAgent` utility directly to build a custom chat component.
309
+
310
+ ### Using `watchAgent` for Custom Components
311
+
312
+ The `watchAgent` function provides reactive signals for agent state, making it easy to build custom chat interfaces:
313
+
314
+ ```typescript
315
+ import { Component, effect } from "@angular/core";
316
+ import { watchAgent } from "@copilotkitnext/angular";
317
+
318
+ @Component({
319
+ selector: "my-custom-chat",
320
+ template: `
321
+ <div class="custom-chat">
322
+ <div *ngFor="let msg of messages()" class="message">
323
+ {{ msg.content }}
324
+ </div>
325
+ <input
326
+ [disabled]="isRunning()"
327
+ (keyup.enter)="sendMessage($event)"
328
+ />
329
+ </div>
330
+ `,
331
+ })
332
+ export class MyCustomChatComponent {
333
+ protected agent!: ReturnType<typeof watchAgent>["agent"];
334
+ protected messages!: ReturnType<typeof watchAgent>["messages"];
335
+ protected isRunning!: ReturnType<typeof watchAgent>["isRunning"];
336
+
337
+ constructor() {
338
+ const w = watchAgent({ agentId: "custom" });
339
+ this.agent = w.agent;
340
+ this.messages = w.messages;
341
+ this.isRunning = w.isRunning;
342
+
343
+ // React to agent changes
344
+ effect(() => {
345
+ const currentAgent = this.agent();
346
+ if (currentAgent) {
347
+ console.log("Agent ready:", currentAgent.id);
348
+ }
349
+ });
350
+ }
351
+
352
+ async sendMessage(event: Event) {
353
+ const input = event.target as HTMLInputElement;
354
+ const content = input.value.trim();
355
+ if (!content || !this.agent()) return;
356
+
357
+ // Add user message and run agent
358
+ this.agent()!.addMessage({ role: "user", content });
359
+ input.value = "";
360
+ await this.agent()!.runAgent();
361
+ }
362
+ }
363
+ ```
364
+
365
+ ### Switching Agents at Runtime
366
+
367
+ Use `watchAgentWith` when you need to switch agents dynamically outside of the constructor:
368
+
369
+ ```typescript
370
+ import { Component, Injector } from "@angular/core";
371
+ import { watchAgent, watchAgentWith } from "@copilotkitnext/angular";
372
+
373
+ @Component({
374
+ selector: "agent-switcher",
375
+ template: `
376
+ <button (click)="switchToAgent('sales')">Sales Agent</button>
377
+ <button (click)="switchToAgent('support')">Support Agent</button>
378
+ <div>Current Agent: {{ agent()?.id || 'None' }}</div>
379
+ `,
380
+ })
381
+ export class AgentSwitcherComponent {
382
+ protected agent!: ReturnType<typeof watchAgent>["agent"];
383
+ protected messages!: ReturnType<typeof watchAgent>["messages"];
384
+ protected isRunning!: ReturnType<typeof watchAgent>["isRunning"];
385
+ private watcher?: ReturnType<typeof watchAgent>;
386
+
387
+ constructor(private injector: Injector) {
388
+ // Initialize with default agent
389
+ this.switchToAgent("default");
390
+ }
391
+
392
+ switchToAgent(agentId: string) {
393
+ // Clean up previous watcher
394
+ this.watcher?.unsubscribe();
395
+
396
+ // Create new watcher with the ergonomic helper
397
+ const w = watchAgentWith(this.injector, { agentId });
398
+
399
+ // Update component signals
400
+ this.agent = w.agent;
401
+ this.messages = w.messages;
402
+ this.isRunning = w.isRunning;
403
+ this.watcher = w;
404
+ }
405
+ }
406
+ ```
407
+
408
+ ### Rendering Tool Calls (Headless)
409
+
410
+ To render tool calls in a headless UI, register renderers in your providers and drop the lightweight view in your template.
411
+
412
+ 1) Register tool renderers (e.g., a wildcard that renders any tool):
413
+
414
+ ```ts
415
+ import { ApplicationConfig, importProvidersFrom } from '@angular/core';
416
+ import { BrowserModule } from '@angular/platform-browser';
417
+ import { provideCopilotKit } from '@copilotkitnext/angular';
418
+
419
+ // Simple demo renderer (Component or TemplateRef accepted)
420
+ @Component({
421
+ standalone: true,
422
+ template: `
423
+ <div style="padding:12px;border:1px solid #e5e7eb;border-radius:8px;background:#fff;margin:8px 0;">
424
+ <div style="font-weight:600;margin-bottom:6px;">Tool: {{ name }}</div>
425
+ <pre style="margin:0;white-space:pre-wrap;">{{ args | json }}</pre>
426
+ <div *ngIf="result" style="margin-top:6px;">Result: {{ result }}</div>
427
+ </div>
428
+ `,
429
+ })
430
+ export class WildcardToolRenderComponent {
431
+ @Input() name!: string;
432
+ @Input() args: any;
433
+ @Input() status: any;
434
+ @Input() result?: string;
435
+ }
436
+
437
+ export const appConfig: ApplicationConfig = {
438
+ providers: [
439
+ importProvidersFrom(BrowserModule),
440
+ ...provideCopilotKit({
441
+ renderToolCalls: [
442
+ { name: '*', render: WildcardToolRenderComponent },
443
+ ],
444
+ }),
445
+ ],
446
+ };
447
+ ```
448
+
449
+ 2) Render tool calls under assistant messages using the headless view component:
450
+
451
+ ```ts
452
+ import { Component } from '@angular/core';
453
+ import { watchAgent, CopilotChatToolCallsViewComponent } from '@copilotkitnext/angular';
454
+
455
+ @Component({
456
+ standalone: true,
457
+ imports: [CopilotChatToolCallsViewComponent],
458
+ template: `
459
+ <div *ngFor="let m of messages()">
460
+ <div>{{ m.role }}: {{ m.content }}</div>
461
+ <ng-container *ngIf="m.role === 'assistant'">
462
+ <copilot-chat-tool-calls-view
463
+ [message]="m"
464
+ [messages]="messages()"
465
+ [isLoading]="isRunning()"
466
+ />
467
+ </ng-container>
468
+ </div>
469
+ `,
470
+ })
471
+ export class HeadlessWithToolsComponent {
472
+ agent = watchAgent().agent;
473
+ messages = watchAgent().messages;
474
+ isRunning = watchAgent().isRunning;
475
+ }
476
+ ```
477
+
478
+ Notes:
479
+ - If you prefer full manual control, you can render a specific tool call with `CopilotKitToolRenderComponent` and pass `toolName`, `args`, `status`, and `result` yourself.
480
+ - You can also register tool renders declaratively via the `CopilotKitFrontendToolDirective` by using `[copilotkitFrontendTool]` in templates.
481
+
482
+ ### Key Benefits of Headless Usage
483
+
484
+ - **Full control**: Build any UI you need without constraints
485
+ - **Reactive signals**: Automatically update UI when agent state changes
486
+ - **Type safety**: Full TypeScript support with AG-UI types
487
+ - **Memory efficient**: Automatic cleanup via Angular's DestroyRef
488
+ - **Framework agnostic**: Works with any AG-UI compatible agent
489
+
490
+ ## End-to-End: Running the Demo
491
+
492
+ From the repo root:
493
+
494
+ 1. **Install deps**: `pnpm install`
495
+ 2. **Start both demo server and Angular demo app**: pnpm build && pnpm demo:angular`
496
+ - Frontend: runs on http://localhost:4200
497
+ - Backend: runs on http://localhost:3001/api/copilotkit
498
+ 3. **Prerequisite**: Set `OPENAI_API_KEY` in `apps/angular/demo-server/.env` if using the OpenAI demo agent
499
+
500
+ ## Building This Monorepo
501
+
502
+ - **Full build**: `pnpm build` (compiles all packages including Angular)
503
+ - **Clean**: `pnpm clean`
504
+ - **Package-only dev (watch)**: `pnpm dev`
505
+
506
+ ## Angular Storybook
507
+
508
+ ### Dev Server
509
+
510
+ ```bash
511
+ pnpm storybook:angular
512
+ ```
513
+
514
+ - Serves Storybook for Angular components on http://localhost:6007
515
+ - For live chat stories, ensure the demo server is running so the chat can connect:
516
+ ```bash
517
+ pnpm --filter @copilotkitnext/angular-demo-server dev
518
+ ```
519
+
520
+ ### Production Build
521
+
522
+ ```bash
523
+ pnpm -C apps/angular/storybook build
524
+ ```
525
+
526
+ ## Notes
527
+
528
+ - Node 18+ and pnpm 9+ recommended
529
+ - If using custom CORS or non-default ports, update `runtimeUrl` and server CORS settings accordingly
530
+ - Styles must be included for proper rendering; if customizing CSS, prefer overriding classes instead of modifying the distributed CSS
package/dist/LICENSE ADDED
@@ -0,0 +1,10 @@
1
+ Proprietary License
2
+
3
+ Copyright 2025 Tawkit Inc.
4
+
5
+ All rights reserved.
6
+
7
+ This software is proprietary and confidential.
8
+ Unauthorized copying, modification, distribution, or use of this software,
9
+ via any medium, is strictly prohibited without prior written permission
10
+ from the copyright holder.