@copilotkitnext/angular 0.0.0-max-changeset-20260109174803
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/LICENSE +10 -0
- package/README.md +530 -0
- package/dist/LICENSE +10 -0
- package/dist/README.md +530 -0
- package/dist/esm2022/copilotkitnext-angular.mjs +5 -0
- package/dist/esm2022/index.mjs +2 -0
- package/dist/esm2022/lib/agent-context.mjs +25 -0
- package/dist/esm2022/lib/agent.mjs +73 -0
- package/dist/esm2022/lib/chat-config.mjs +35 -0
- package/dist/esm2022/lib/chat-state.mjs +18 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-assistant-message-buttons.mjs +344 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-assistant-message-renderer.mjs +260 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-assistant-message-toolbar.mjs +22 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-assistant-message.mjs +415 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-assistant-message.types.mjs +2 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-audio-recorder.mjs +196 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-buttons.mjs +299 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-input-defaults.mjs +39 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-input.mjs +634 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-input.types.mjs +10 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-message-view-cursor.mjs +27 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-message-view.mjs +268 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-message-view.types.mjs +2 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-textarea.mjs +139 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-tool-calls-view.mjs +36 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-toolbar.mjs +20 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-tools-menu.mjs +203 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-user-message-branch-navigation.mjs +98 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-user-message-buttons.mjs +182 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-user-message-renderer.mjs +28 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-user-message-toolbar.mjs +25 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-user-message.mjs +308 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-user-message.types.mjs +2 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-view-disclaimer.mjs +48 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-view-feather.mjs +41 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-view-handlers.mjs +19 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-view-input-container.mjs +96 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-view-scroll-to-bottom-button.mjs +89 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-view-scroll-view.mjs +456 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-view.mjs +404 -0
- package/dist/esm2022/lib/components/chat/copilot-chat-view.types.mjs +2 -0
- package/dist/esm2022/lib/components/chat/copilot-chat.mjs +167 -0
- package/dist/esm2022/lib/config.mjs +9 -0
- package/dist/esm2022/lib/copilotkit.mjs +115 -0
- package/dist/esm2022/lib/directives/copilotkit-agent-context.mjs +130 -0
- package/dist/esm2022/lib/directives/stick-to-bottom.mjs +170 -0
- package/dist/esm2022/lib/directives/tooltip.mjs +217 -0
- package/dist/esm2022/lib/human-in-the-loop.mjs +19 -0
- package/dist/esm2022/lib/render-tool-calls.mjs +138 -0
- package/dist/esm2022/lib/resize-observer.mjs +152 -0
- package/dist/esm2022/lib/scroll-position.mjs +124 -0
- package/dist/esm2022/lib/slots/copilot-slot.mjs +156 -0
- package/dist/esm2022/lib/slots/index.mjs +4 -0
- package/dist/esm2022/lib/slots/slot.types.mjs +6 -0
- package/dist/esm2022/lib/slots/slot.utils.mjs +235 -0
- package/dist/esm2022/lib/tools.mjs +31 -0
- package/dist/esm2022/lib/utils.mjs +10 -0
- package/dist/esm2022/public-api.mjs +48 -0
- package/dist/fesm2022/copilotkitnext-angular.mjs +6310 -0
- package/dist/fesm2022/copilotkitnext-angular.mjs.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/lib/agent-context.d.ts +12 -0
- package/dist/lib/agent.d.ts +68 -0
- package/dist/lib/chat-config.d.ts +23 -0
- package/dist/lib/chat-state.d.ts +10 -0
- package/dist/lib/components/chat/copilot-chat-assistant-message-buttons.d.ts +68 -0
- package/dist/lib/components/chat/copilot-chat-assistant-message-renderer.d.ts +26 -0
- package/dist/lib/components/chat/copilot-chat-assistant-message-toolbar.d.ts +7 -0
- package/dist/lib/components/chat/copilot-chat-assistant-message.d.ts +208 -0
- package/dist/lib/components/chat/copilot-chat-assistant-message.types.d.ts +31 -0
- package/dist/lib/components/chat/copilot-chat-audio-recorder.d.ts +40 -0
- package/dist/lib/components/chat/copilot-chat-buttons.d.ts +65 -0
- package/dist/lib/components/chat/copilot-chat-input-defaults.d.ts +38 -0
- package/dist/lib/components/chat/copilot-chat-input.d.ts +133 -0
- package/dist/lib/components/chat/copilot-chat-input.types.d.ts +129 -0
- package/dist/lib/components/chat/copilot-chat-message-view-cursor.d.ts +11 -0
- package/dist/lib/components/chat/copilot-chat-message-view.d.ts +430 -0
- package/dist/lib/components/chat/copilot-chat-message-view.types.d.ts +24 -0
- package/dist/lib/components/chat/copilot-chat-textarea.d.ts +41 -0
- package/dist/lib/components/chat/copilot-chat-tool-calls-view.d.ts +70 -0
- package/dist/lib/components/chat/copilot-chat-toolbar.d.ts +7 -0
- package/dist/lib/components/chat/copilot-chat-tools-menu.d.ts +20 -0
- package/dist/lib/components/chat/copilot-chat-user-message-branch-navigation.d.ts +35 -0
- package/dist/lib/components/chat/copilot-chat-user-message-buttons.d.ts +35 -0
- package/dist/lib/components/chat/copilot-chat-user-message-renderer.d.ts +8 -0
- package/dist/lib/components/chat/copilot-chat-user-message-toolbar.d.ts +7 -0
- package/dist/lib/components/chat/copilot-chat-user-message.d.ts +71 -0
- package/dist/lib/components/chat/copilot-chat-user-message.types.d.ts +27 -0
- package/dist/lib/components/chat/copilot-chat-view-disclaimer.d.ts +15 -0
- package/dist/lib/components/chat/copilot-chat-view-feather.d.ts +15 -0
- package/dist/lib/components/chat/copilot-chat-view-handlers.d.ts +11 -0
- package/dist/lib/components/chat/copilot-chat-view-input-container.d.ts +23 -0
- package/dist/lib/components/chat/copilot-chat-view-scroll-to-bottom-button.d.ts +16 -0
- package/dist/lib/components/chat/copilot-chat-view-scroll-view.d.ts +129 -0
- package/dist/lib/components/chat/copilot-chat-view.d.ts +284 -0
- package/dist/lib/components/chat/copilot-chat-view.types.d.ts +42 -0
- package/dist/lib/components/chat/copilot-chat.d.ts +82 -0
- package/dist/lib/config.d.ts +16 -0
- package/dist/lib/copilotkit.d.ts +29 -0
- package/dist/lib/directives/copilotkit-agent-context.d.ts +68 -0
- package/dist/lib/directives/stick-to-bottom.d.ts +62 -0
- package/dist/lib/directives/tooltip.d.ts +33 -0
- package/dist/lib/human-in-the-loop.d.ts +13 -0
- package/dist/lib/render-tool-calls.d.ts +90 -0
- package/dist/lib/resize-observer.d.ts +44 -0
- package/dist/lib/scroll-position.d.ts +50 -0
- package/dist/lib/slots/copilot-slot.d.ts +34 -0
- package/dist/lib/slots/index.d.ts +3 -0
- package/dist/lib/slots/slot.types.d.ts +55 -0
- package/dist/lib/slots/slot.utils.d.ts +110 -0
- package/dist/lib/tools.d.ts +65 -0
- package/dist/lib/utils.d.ts +6 -0
- package/dist/public-api.d.ts +47 -0
- package/dist/styles.css +1882 -0
- package/eslint.config.mjs +20 -0
- package/package.json +101 -0
- package/tsconfig.json +33 -0
- package/vitest.config.mts +45 -0
package/dist/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
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated bundle index. Do not edit.
|
|
3
|
+
*/
|
|
4
|
+
export * from './index';
|
|
5
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29waWxvdGtpdG5leHQtYW5ndWxhci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb3BpbG90a2l0bmV4dC1hbmd1bGFyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBRUgsY0FBYyxTQUFTLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyIvKipcbiAqIEdlbmVyYXRlZCBidW5kbGUgaW5kZXguIERvIG5vdCBlZGl0LlxuICovXG5cbmV4cG9ydCAqIGZyb20gJy4vaW5kZXgnO1xuIl19
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export * from "./public-api";
|
|
2
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYyxjQUFjLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgKiBmcm9tIFwiLi9wdWJsaWMtYXBpXCI7XG4iXX0=
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { effect, inject, Injector, runInInjectionContext } from "@angular/core";
|
|
2
|
+
import { CopilotKit } from "./copilotkit";
|
|
3
|
+
/**
|
|
4
|
+
* Connects context to the agent.
|
|
5
|
+
*
|
|
6
|
+
* @param context - The context (or a signal of context) to connect to the agent.
|
|
7
|
+
* @param config - Optional configuration for connecting the context.
|
|
8
|
+
*/
|
|
9
|
+
export function connectAgentContext(context, config) {
|
|
10
|
+
const injector = inject(Injector, { optional: true }) ?? config?.injector;
|
|
11
|
+
if (!injector) {
|
|
12
|
+
throw new Error("Injector not found. You must call connectAgentContext in an injector context or pass an injector in the config");
|
|
13
|
+
}
|
|
14
|
+
runInInjectionContext(injector, () => {
|
|
15
|
+
const copilotkit = inject(CopilotKit);
|
|
16
|
+
effect((teardown) => {
|
|
17
|
+
const contextValue = typeof context === "function" ? context() : context;
|
|
18
|
+
const id = copilotkit.core.addContext(contextValue);
|
|
19
|
+
teardown(() => {
|
|
20
|
+
copilotkit.core.removeContext(id);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWdlbnQtY29udGV4dC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9saWIvYWdlbnQtY29udGV4dC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsTUFBTSxFQUFFLE1BQU0sRUFBRSxRQUFRLEVBQUUscUJBQXFCLEVBQVUsTUFBTSxlQUFlLENBQUM7QUFFeEYsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLGNBQWMsQ0FBQztBQU0xQzs7Ozs7R0FLRztBQUNILE1BQU0sVUFBVSxtQkFBbUIsQ0FBQyxPQUFrQyxFQUFFLE1BQWtDO0lBQ3hHLE1BQU0sUUFBUSxHQUFHLE1BQU0sQ0FBQyxRQUFRLEVBQUUsRUFBRSxRQUFRLEVBQUUsSUFBSSxFQUFFLENBQUMsSUFBSSxNQUFNLEVBQUUsUUFBUSxDQUFDO0lBRTFFLElBQUksQ0FBQyxRQUFRLEVBQUUsQ0FBQztRQUNkLE1BQU0sSUFBSSxLQUFLLENBQ2IsZ0hBQWdILENBQ2pILENBQUM7SUFDSixDQUFDO0lBRUQscUJBQXFCLENBQUMsUUFBUSxFQUFFLEdBQUcsRUFBRTtRQUNuQyxNQUFNLFVBQVUsR0FBRyxNQUFNLENBQUMsVUFBVSxDQUFDLENBQUM7UUFFdEMsTUFBTSxDQUFDLENB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4gKi9cbmV4cG9ydCBmdW5jdGlvbiBjb25uZWN0QWdlbnRDb250ZXh0KGNvbnRleHQ6IENvbnRleHQgfCBTaWduYWw8Q29udGV4dD4sIGNvbmZpZz86IENvbm5lY3RBZ2VudENvbnRleHRDb25maWcpIHtcbiAgY29uc3QgaW5qZWN0b3IgPSBpbmplY3QoSW5qZWN0b3IsIHsgb3B0aW9uYWw6IHRydWUgfSkgPz8gY29uZmlnPy5pbmplY3RvcjtcblxuICBpZiAoIWluamVjdG9yKSB7XG4gICAgdGhyb3cgbmV3IEVycm9yKFxuICAgICAgXCJJbmplY3RvciBub3QgZm91bmQuIFlvdSBtdXN0IGNhbGwgY29ubmVjdEFnZW50Q29udGV4dCBpbiBhbiBpbmplY3RvciBjb250ZXh0IG9yIHBhc3MgYW4gaW5qZWN0b3IgaW4gdGhlIGNvbmZpZ1wiLFxuICAgICk7XG4gIH1cblxuICBydW5JbkluamVjdGlvbkNvbnRleHQoaW5qZWN0b3IsICgpID0+IHtcbiAgICBjb25zdCBjb3BpbG90a2l0ID0gaW5qZWN0KENvcGlsb3RLaXQpO1xuXG4gICAgZWZmZWN0KCh0ZWFyZG93bikgPT4ge1xuICAgICAgY29uc3QgY29udGV4dFZhbHVlID0gdHlwZW9mIGNvbnRleHQgPT09IFwiZnVuY3Rpb25cIiA/IGNvbnRleHQoKSA6IGNvbnRleHQ7XG4gICAgICBjb25zdCBpZCA9IGNvcGlsb3RraXQuY29yZS5hZGRDb250ZXh0KGNvbnRleHRWYWx1ZSk7XG5cbiAgICAgIHRlYXJkb3duKCgpID0+IHtcbiAgICAgICAgY29waWxvdGtpdC5jb3JlLnJlbW92ZUNvbnRleHQoaWQpO1xuICAgICAgfSk7XG4gICAgfSk7XG4gIH0pO1xufVxuIl19
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { DestroyRef, Injectable, inject, signal, computed, } from "@angular/core";
|
|
2
|
+
import { CopilotKit } from "./copilotkit";
|
|
3
|
+
import { DEFAULT_AGENT_ID } from "@copilotkitnext/shared";
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
export class AgentStore {
|
|
6
|
+
#subscription;
|
|
7
|
+
#isRunning = signal(false);
|
|
8
|
+
#messages = signal([]);
|
|
9
|
+
#state = signal(undefined);
|
|
10
|
+
agent;
|
|
11
|
+
isRunning = this.#isRunning.asReadonly();
|
|
12
|
+
messages = this.#messages.asReadonly();
|
|
13
|
+
state = this.#state.asReadonly();
|
|
14
|
+
constructor(abstractAgent, destroyRef) {
|
|
15
|
+
this.agent = abstractAgent;
|
|
16
|
+
this.#subscription = abstractAgent.subscribe({
|
|
17
|
+
onMessagesChanged: () => {
|
|
18
|
+
this.#messages.set(abstractAgent.messages);
|
|
19
|
+
},
|
|
20
|
+
onStateChanged: () => {
|
|
21
|
+
this.#state.set(abstractAgent.state);
|
|
22
|
+
},
|
|
23
|
+
onRunInitialized: () => {
|
|
24
|
+
this.#isRunning.set(true);
|
|
25
|
+
},
|
|
26
|
+
onRunFinalized: () => {
|
|
27
|
+
this.#isRunning.set(false);
|
|
28
|
+
},
|
|
29
|
+
onRunFailed: () => {
|
|
30
|
+
this.#isRunning.set(false);
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
destroyRef.onDestroy(() => {
|
|
34
|
+
this.teardown();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
teardown() {
|
|
38
|
+
if (this.#subscription) {
|
|
39
|
+
this.#subscription.unsubscribe();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export class CopilotkitAgentFactory {
|
|
44
|
+
#copilotkit = inject(CopilotKit);
|
|
45
|
+
createAgentStoreSignal(agentId, destroyRef) {
|
|
46
|
+
let lastAgentStore;
|
|
47
|
+
return computed(() => {
|
|
48
|
+
this.#copilotkit.agents();
|
|
49
|
+
if (lastAgentStore) {
|
|
50
|
+
lastAgentStore.teardown();
|
|
51
|
+
lastAgentStore = undefined;
|
|
52
|
+
}
|
|
53
|
+
const abstractAgent = this.#copilotkit.getAgent(agentId() || DEFAULT_AGENT_ID);
|
|
54
|
+
if (!abstractAgent)
|
|
55
|
+
return undefined;
|
|
56
|
+
lastAgentStore = new AgentStore(abstractAgent, destroyRef);
|
|
57
|
+
return lastAgentStore;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: CopilotkitAgentFactory, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
61
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: CopilotkitAgentFactory, providedIn: "root" });
|
|
62
|
+
}
|
|
63
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: CopilotkitAgentFactory, decorators: [{
|
|
64
|
+
type: Injectable,
|
|
65
|
+
args: [{ providedIn: "root" }]
|
|
66
|
+
}] });
|
|
67
|
+
export function injectAgentStore(agentId) {
|
|
68
|
+
const agentFactory = inject(CopilotkitAgentFactory);
|
|
69
|
+
const destroyRef = inject(DestroyRef);
|
|
70
|
+
const agentIdSignal = typeof agentId === "function" ? agentId : computed(() => agentId);
|
|
71
|
+
return agentFactory.createAgentStoreSignal(agentIdSignal, destroyRef);
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWdlbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvbGliL2FnZW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFDTCxVQUFVLEVBQ1YsVUFBVSxFQUNWLE1BQU0sRUFDTixNQUFNLEVBQ04sUUFBUSxHQUVULE1BQU0sZUFBZSxDQUFDO0FBQ3ZCLE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSx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