@copilotkitnext/angular 0.0.1 → 0.0.2
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/.turbo/turbo-build.log +38 -39
- package/README.md +248 -0
- package/dist/README.md +248 -0
- package/dist/styles.css +0 -27
- package/package.json +5 -5
- package/README-agent-context.md +0 -310
- package/slots.md +0 -331
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,39 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
Done in 103ms
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
> @copilotkitnext/angular@0.0.1 build /Users/mme/Code/vnext_experimental/packages/angular
|
|
4
|
+
> ng-packagr -p ng-package.json && npm run build:css
|
|
5
|
+
|
|
6
|
+
[34mBuilding Angular Package[39m
|
|
7
|
+
[37m[39m
|
|
8
|
+
[37m------------------------------------------------------------------------------[39m
|
|
9
|
+
[37mBuilding entry point '@copilotkitnext/angular'[39m
|
|
10
|
+
[37m------------------------------------------------------------------------------[39m
|
|
11
|
+
[36m⠋[39m Compiling with Angular sources in Ivy partial compilation mode.[2K[1G[36m⠙[39m Compiling with Angular sources in Ivy partial compilation mode.[2K[1G[36m⠹[39m Compiling with Angular sources in Ivy partial compilation mode.[2K[1G[36m⠸[39m Compiling with Angular sources in Ivy partial compilation mode.
|
|
12
|
+
[2K[1G[32m✔[39m Compiling with Angular sources in Ivy partial compilation mode.
|
|
13
|
+
[36m⠋[39m Writing FESM bundles[2K[1G[32m✔[39m Writing FESM bundles
|
|
14
|
+
[36m⠋[39m Copying assets[2K[1G[32m✔[39m Copying assets
|
|
15
|
+
[36m⠋[39m Writing package manifest[33mWARNING: Found a conflicting export condition for ".". The "types" condition would be overridden by ng-packagr. Please unset it.[39m
|
|
16
|
+
[33mWARNING: Found a conflicting export condition for ".". The "default" condition would be overridden by ng-packagr. Please unset it.[39m
|
|
17
|
+
[2K[1G[33m⚠[39m [33m'tslib' is no longer recommended to be used as a 'peerDependencies'. Moving it to 'dependencies'.[39m
|
|
18
|
+
[34mℹ[39m Removing scripts section in package.json as it's considered a potential security vulnerability.
|
|
19
|
+
[34mℹ[39m Removing devDependencies section in package.json.
|
|
20
|
+
[32m✔[39m Writing package manifest
|
|
21
|
+
[32m✔[39m Built @copilotkitnext/angular
|
|
22
|
+
[32m[39m
|
|
23
|
+
[32m------------------------------------------------------------------------------[39m
|
|
24
|
+
[32mBuilt Angular Package[39m
|
|
25
|
+
[32m - from: /Users/mme/Code/vnext_experimental/packages/angular[39m
|
|
26
|
+
[32m - to: /Users/mme/Code/vnext_experimental/packages/angular/dist[39m
|
|
27
|
+
[32m------------------------------------------------------------------------------[39m
|
|
28
|
+
[37m[37m[39m[37m[39m
|
|
29
|
+
[37m[37mBuild at: [1m2025-09-03T13:18:59.922Z[22m - Time: [1m3451[22mms[39m[37m[39m
|
|
30
|
+
[37m[37m[39m[37m[39m
|
|
31
|
+
|
|
32
|
+
> @copilotkitnext/angular@0.0.1 build:css
|
|
33
|
+
> npx @tailwindcss/cli -i ./src/styles/globals.css -o ./dist/styles.css
|
|
34
|
+
|
|
35
|
+
[1G[0K[1G[0K⠙[1G[0K⠹[1G[0K⠸[1G[0K⠼[1G[0K⠴[1G[0K⠦[1G[0K⠧[1G[0K⠇[1G[0K⠏[1G[0K⠋[1G[0K⠙[1G[0K⠹[1G[0K⠸[1G[0K⠼[1G[0K⠴[1G[0K⠦[1G[0K⠧[1G[0K⠇[1G[0K⠏[1G[0K⠋[1G[0K⠙[1G[0K⠹[1G[0K⠸[1G[0K⠼[1G[0K⠴[1G[0K⠦[1G[0K⠧[1G[0K⠇[1G[0K⠏[1G[0K⠋[1G[0K⠙[1G[0K⠹[1G[0K⠸[1G[0K⠼[1G[0K⠴[1G[0K⠦[1G[0K[3m[1m[34m≈[39m[22m[23m tailwindcss [34mv4.1.11[39m
|
|
36
|
+
|
|
37
|
+
Done in [34m110ms[39m
|
|
38
|
+
[1G[0K⠙[1G[0K[1G[0K⠙[1G[0K
|
package/README.md
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
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 (requires Angular 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 (Angular 19):
|
|
32
|
+
|
|
33
|
+
- `@angular/core`
|
|
34
|
+
- `@angular/common`
|
|
35
|
+
- `@angular/cdk`
|
|
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
|
+
## Agents 101 (AG-UI)
|
|
128
|
+
|
|
129
|
+
- **Agent model**: CopilotKit uses AG-UI's `AbstractAgent` interface (package `@ag-ui/client`)
|
|
130
|
+
- **Frontend vs backend**:
|
|
131
|
+
- **Backend (runtime)**: Host your real agents. You can use any AG-UI agent on the server
|
|
132
|
+
- **Frontend (Angular app)**: Discovers remote agents from the runtime automatically, and can also host local in-browser agents if desired
|
|
133
|
+
- **Default agent**: The ID `default` is special; when present, it is used by `<copilot-chat>` if no `agentId` is provided
|
|
134
|
+
- **Compatibility**: Any agent that supports AG-UI works. See https://docs.ag-ui.com/
|
|
135
|
+
|
|
136
|
+
> **Note**: In most real apps, you define agents on the server (runtime). The frontend will auto-discover them when a `runtimeUrl` is configured.
|
|
137
|
+
|
|
138
|
+
## Backend Runtime (Hono Server)
|
|
139
|
+
|
|
140
|
+
Example Angular server (from `apps/angular/demo-server`):
|
|
141
|
+
|
|
142
|
+
### `index.ts`
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
import { serve } from "@hono/node-server";
|
|
146
|
+
import { Hono } from "hono";
|
|
147
|
+
import { cors } from "hono/cors";
|
|
148
|
+
import {
|
|
149
|
+
CopilotRuntime,
|
|
150
|
+
createCopilotEndpoint,
|
|
151
|
+
InMemoryAgentRunner,
|
|
152
|
+
} from "@copilotkitnext/runtime";
|
|
153
|
+
import { AnyAGUIAgent } from "@ag-ui/your-desired-agent-framework";
|
|
154
|
+
|
|
155
|
+
const runtime = new CopilotRuntime({
|
|
156
|
+
agents: { default: new AnyAGUIAgent() },
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// Create a main app with CORS enabled
|
|
160
|
+
const app = new Hono();
|
|
161
|
+
|
|
162
|
+
// Enable CORS for local dev (Angular demo at http://localhost:4200)
|
|
163
|
+
app.use(
|
|
164
|
+
"*",
|
|
165
|
+
cors({
|
|
166
|
+
origin: "http://localhost:4200",
|
|
167
|
+
allowMethods: ["GET", "POST", "OPTIONS", "PUT", "DELETE"],
|
|
168
|
+
allowHeaders: ["Content-Type", "Authorization", "X-Requested-With"],
|
|
169
|
+
exposeHeaders: ["Content-Type"],
|
|
170
|
+
credentials: true,
|
|
171
|
+
maxAge: 86400,
|
|
172
|
+
})
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
// Create the CopilotKit endpoint
|
|
176
|
+
const copilotApp = createCopilotEndpoint({
|
|
177
|
+
runtime,
|
|
178
|
+
basePath: "/api/copilotkit",
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
// Mount the CopilotKit app
|
|
182
|
+
app.route("/", copilotApp);
|
|
183
|
+
|
|
184
|
+
const port = Number(process.env.PORT || 3001);
|
|
185
|
+
serve({ fetch: app.fetch, port });
|
|
186
|
+
console.log(
|
|
187
|
+
`CopilotKit runtime listening at http://localhost:${port}/api/copilotkit`
|
|
188
|
+
);
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## CopilotKit Angular APIs (Most Used)
|
|
192
|
+
|
|
193
|
+
### Components
|
|
194
|
+
|
|
195
|
+
- **`CopilotChatComponent`**: Full chat UI
|
|
196
|
+
- Inputs: `agentId?: string`
|
|
197
|
+
|
|
198
|
+
### Directives
|
|
199
|
+
|
|
200
|
+
- **`CopilotKitConfigDirective`** (`[copilotkitConfig]`): Set `runtimeUrl`, `headers`, `properties`, and/or `agents` declaratively
|
|
201
|
+
- **`CopilotKitAgentDirective`** (`[copilotkitAgent]`): Observe agent state; defaults to the `default` agent if no `agentId` is provided
|
|
202
|
+
|
|
203
|
+
### Providers
|
|
204
|
+
|
|
205
|
+
- **`provideCopilotKit(...)`**: Set runtime URL, headers, properties, agents, tools, human-in-the-loop handlers
|
|
206
|
+
- **`provideCopilotChatConfiguration(...)`**: Set UI labels and behavior for chat input/view
|
|
207
|
+
|
|
208
|
+
## End-to-End: Running the Demo
|
|
209
|
+
|
|
210
|
+
From the repo root:
|
|
211
|
+
|
|
212
|
+
1. **Install deps**: `pnpm install`
|
|
213
|
+
2. **Start both demo server and Angular demo app**: pnpm build && pnpm demo:angular`
|
|
214
|
+
- Frontend: runs on http://localhost:4200
|
|
215
|
+
- Backend: runs on http://localhost:3001/api/copilotkit
|
|
216
|
+
3. **Prerequisite**: Set `OPENAI_API_KEY` in `apps/angular/demo-server/.env` if using the OpenAI demo agent
|
|
217
|
+
|
|
218
|
+
## Building This Monorepo
|
|
219
|
+
|
|
220
|
+
- **Full build**: `pnpm build` (compiles all packages including Angular)
|
|
221
|
+
- **Clean**: `pnpm clean`
|
|
222
|
+
- **Package-only dev (watch)**: `pnpm dev`
|
|
223
|
+
|
|
224
|
+
## Angular Storybook
|
|
225
|
+
|
|
226
|
+
### Dev Server
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
pnpm storybook:angular
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
- Serves Storybook for Angular components on http://localhost:6007
|
|
233
|
+
- For live chat stories, ensure the demo server is running so the chat can connect:
|
|
234
|
+
```bash
|
|
235
|
+
pnpm --filter @copilotkitnext/angular-demo-server dev
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Production Build
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
pnpm -C apps/angular/storybook build
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Notes
|
|
245
|
+
|
|
246
|
+
- Node 18+ and pnpm 9+ recommended
|
|
247
|
+
- If using custom CORS or non-default ports, update `runtimeUrl` and server CORS settings accordingly
|
|
248
|
+
- Styles must be included for proper rendering; if customizing CSS, prefer overriding classes instead of modifying the distributed CSS
|
package/dist/README.md
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
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 (requires Angular 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 (Angular 19):
|
|
32
|
+
|
|
33
|
+
- `@angular/core`
|
|
34
|
+
- `@angular/common`
|
|
35
|
+
- `@angular/cdk`
|
|
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
|
+
## Agents 101 (AG-UI)
|
|
128
|
+
|
|
129
|
+
- **Agent model**: CopilotKit uses AG-UI's `AbstractAgent` interface (package `@ag-ui/client`)
|
|
130
|
+
- **Frontend vs backend**:
|
|
131
|
+
- **Backend (runtime)**: Host your real agents. You can use any AG-UI agent on the server
|
|
132
|
+
- **Frontend (Angular app)**: Discovers remote agents from the runtime automatically, and can also host local in-browser agents if desired
|
|
133
|
+
- **Default agent**: The ID `default` is special; when present, it is used by `<copilot-chat>` if no `agentId` is provided
|
|
134
|
+
- **Compatibility**: Any agent that supports AG-UI works. See https://docs.ag-ui.com/
|
|
135
|
+
|
|
136
|
+
> **Note**: In most real apps, you define agents on the server (runtime). The frontend will auto-discover them when a `runtimeUrl` is configured.
|
|
137
|
+
|
|
138
|
+
## Backend Runtime (Hono Server)
|
|
139
|
+
|
|
140
|
+
Example Angular server (from `apps/angular/demo-server`):
|
|
141
|
+
|
|
142
|
+
### `index.ts`
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
import { serve } from "@hono/node-server";
|
|
146
|
+
import { Hono } from "hono";
|
|
147
|
+
import { cors } from "hono/cors";
|
|
148
|
+
import {
|
|
149
|
+
CopilotRuntime,
|
|
150
|
+
createCopilotEndpoint,
|
|
151
|
+
InMemoryAgentRunner,
|
|
152
|
+
} from "@copilotkitnext/runtime";
|
|
153
|
+
import { AnyAGUIAgent } from "@ag-ui/your-desired-agent-framework";
|
|
154
|
+
|
|
155
|
+
const runtime = new CopilotRuntime({
|
|
156
|
+
agents: { default: new AnyAGUIAgent() },
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// Create a main app with CORS enabled
|
|
160
|
+
const app = new Hono();
|
|
161
|
+
|
|
162
|
+
// Enable CORS for local dev (Angular demo at http://localhost:4200)
|
|
163
|
+
app.use(
|
|
164
|
+
"*",
|
|
165
|
+
cors({
|
|
166
|
+
origin: "http://localhost:4200",
|
|
167
|
+
allowMethods: ["GET", "POST", "OPTIONS", "PUT", "DELETE"],
|
|
168
|
+
allowHeaders: ["Content-Type", "Authorization", "X-Requested-With"],
|
|
169
|
+
exposeHeaders: ["Content-Type"],
|
|
170
|
+
credentials: true,
|
|
171
|
+
maxAge: 86400,
|
|
172
|
+
})
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
// Create the CopilotKit endpoint
|
|
176
|
+
const copilotApp = createCopilotEndpoint({
|
|
177
|
+
runtime,
|
|
178
|
+
basePath: "/api/copilotkit",
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
// Mount the CopilotKit app
|
|
182
|
+
app.route("/", copilotApp);
|
|
183
|
+
|
|
184
|
+
const port = Number(process.env.PORT || 3001);
|
|
185
|
+
serve({ fetch: app.fetch, port });
|
|
186
|
+
console.log(
|
|
187
|
+
`CopilotKit runtime listening at http://localhost:${port}/api/copilotkit`
|
|
188
|
+
);
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## CopilotKit Angular APIs (Most Used)
|
|
192
|
+
|
|
193
|
+
### Components
|
|
194
|
+
|
|
195
|
+
- **`CopilotChatComponent`**: Full chat UI
|
|
196
|
+
- Inputs: `agentId?: string`
|
|
197
|
+
|
|
198
|
+
### Directives
|
|
199
|
+
|
|
200
|
+
- **`CopilotKitConfigDirective`** (`[copilotkitConfig]`): Set `runtimeUrl`, `headers`, `properties`, and/or `agents` declaratively
|
|
201
|
+
- **`CopilotKitAgentDirective`** (`[copilotkitAgent]`): Observe agent state; defaults to the `default` agent if no `agentId` is provided
|
|
202
|
+
|
|
203
|
+
### Providers
|
|
204
|
+
|
|
205
|
+
- **`provideCopilotKit(...)`**: Set runtime URL, headers, properties, agents, tools, human-in-the-loop handlers
|
|
206
|
+
- **`provideCopilotChatConfiguration(...)`**: Set UI labels and behavior for chat input/view
|
|
207
|
+
|
|
208
|
+
## End-to-End: Running the Demo
|
|
209
|
+
|
|
210
|
+
From the repo root:
|
|
211
|
+
|
|
212
|
+
1. **Install deps**: `pnpm install`
|
|
213
|
+
2. **Start both demo server and Angular demo app**: pnpm build && pnpm demo:angular`
|
|
214
|
+
- Frontend: runs on http://localhost:4200
|
|
215
|
+
- Backend: runs on http://localhost:3001/api/copilotkit
|
|
216
|
+
3. **Prerequisite**: Set `OPENAI_API_KEY` in `apps/angular/demo-server/.env` if using the OpenAI demo agent
|
|
217
|
+
|
|
218
|
+
## Building This Monorepo
|
|
219
|
+
|
|
220
|
+
- **Full build**: `pnpm build` (compiles all packages including Angular)
|
|
221
|
+
- **Clean**: `pnpm clean`
|
|
222
|
+
- **Package-only dev (watch)**: `pnpm dev`
|
|
223
|
+
|
|
224
|
+
## Angular Storybook
|
|
225
|
+
|
|
226
|
+
### Dev Server
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
pnpm storybook:angular
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
- Serves Storybook for Angular components on http://localhost:6007
|
|
233
|
+
- For live chat stories, ensure the demo server is running so the chat can connect:
|
|
234
|
+
```bash
|
|
235
|
+
pnpm --filter @copilotkitnext/angular-demo-server dev
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Production Build
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
pnpm -C apps/angular/storybook build
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Notes
|
|
245
|
+
|
|
246
|
+
- Node 18+ and pnpm 9+ recommended
|
|
247
|
+
- If using custom CORS or non-default ports, update `runtimeUrl` and server CORS settings accordingly
|
|
248
|
+
- Styles must be included for proper rendering; if customizing CSS, prefer overriding classes instead of modifying the distributed CSS
|
package/dist/styles.css
CHANGED
|
@@ -7,11 +7,9 @@
|
|
|
7
7
|
"Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
|
|
8
8
|
--font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
|
|
9
9
|
"Courier New", monospace;
|
|
10
|
-
--color-blue-500: oklch(62.3% 0.214 259.815);
|
|
11
10
|
--color-gray-50: oklch(98.5% 0.002 247.839);
|
|
12
11
|
--color-gray-100: oklch(96.7% 0.003 264.542);
|
|
13
12
|
--color-gray-200: oklch(92.8% 0.006 264.531);
|
|
14
|
-
--color-gray-300: oklch(87.2% 0.01 258.338);
|
|
15
13
|
--color-gray-600: oklch(44.6% 0.03 256.802);
|
|
16
14
|
--color-gray-700: oklch(37.3% 0.034 259.733);
|
|
17
15
|
--color-gray-800: oklch(27.8% 0.033 256.848);
|
|
@@ -20,7 +18,6 @@
|
|
|
20
18
|
--color-white: #fff;
|
|
21
19
|
--spacing: 0.25rem;
|
|
22
20
|
--container-3xl: 48rem;
|
|
23
|
-
--container-4xl: 56rem;
|
|
24
21
|
--text-xs: 0.75rem;
|
|
25
22
|
--text-xs--line-height: calc(1 / 0.75);
|
|
26
23
|
--text-sm: 0.875rem;
|
|
@@ -188,9 +185,6 @@
|
|
|
188
185
|
.invisible {
|
|
189
186
|
visibility: hidden;
|
|
190
187
|
}
|
|
191
|
-
.visible {
|
|
192
|
-
visibility: visible;
|
|
193
|
-
}
|
|
194
188
|
.absolute {
|
|
195
189
|
position: absolute;
|
|
196
190
|
}
|
|
@@ -768,9 +762,6 @@
|
|
|
768
762
|
.max-w-3xl {
|
|
769
763
|
max-width: var(--container-3xl);
|
|
770
764
|
}
|
|
771
|
-
.max-w-4xl {
|
|
772
|
-
max-width: var(--container-4xl);
|
|
773
|
-
}
|
|
774
765
|
.max-w-\[80\%\] {
|
|
775
766
|
max-width: 80%;
|
|
776
767
|
}
|
|
@@ -856,10 +847,6 @@
|
|
|
856
847
|
border-style: var(--tw-border-style);
|
|
857
848
|
border-width: 1px;
|
|
858
849
|
}
|
|
859
|
-
.border-2 {
|
|
860
|
-
border-style: var(--tw-border-style);
|
|
861
|
-
border-width: 2px;
|
|
862
|
-
}
|
|
863
850
|
.border-none {
|
|
864
851
|
--tw-border-style: none;
|
|
865
852
|
border-style: none;
|
|
@@ -867,15 +854,9 @@
|
|
|
867
854
|
.border-gray-200 {
|
|
868
855
|
border-color: var(--color-gray-200);
|
|
869
856
|
}
|
|
870
|
-
.border-gray-300 {
|
|
871
|
-
border-color: var(--color-gray-300);
|
|
872
|
-
}
|
|
873
857
|
.bg-black {
|
|
874
858
|
background-color: var(--color-black);
|
|
875
859
|
}
|
|
876
|
-
.bg-blue-500 {
|
|
877
|
-
background-color: var(--color-blue-500);
|
|
878
|
-
}
|
|
879
860
|
.bg-foreground {
|
|
880
861
|
background-color: var(--foreground);
|
|
881
862
|
}
|
|
@@ -917,9 +898,6 @@
|
|
|
917
898
|
.p-1 {
|
|
918
899
|
padding: calc(var(--spacing) * 1);
|
|
919
900
|
}
|
|
920
|
-
.p-4 {
|
|
921
|
-
padding: calc(var(--spacing) * 4);
|
|
922
|
-
}
|
|
923
901
|
.p-5 {
|
|
924
902
|
padding: calc(var(--spacing) * 5);
|
|
925
903
|
}
|
|
@@ -1115,11 +1093,6 @@
|
|
|
1115
1093
|
}
|
|
1116
1094
|
}
|
|
1117
1095
|
}
|
|
1118
|
-
.focus\:border-blue-500 {
|
|
1119
|
-
&:focus {
|
|
1120
|
-
border-color: var(--color-blue-500);
|
|
1121
|
-
}
|
|
1122
|
-
}
|
|
1123
1096
|
.focus\:ring-2 {
|
|
1124
1097
|
&:focus {
|
|
1125
1098
|
--tw-ring-shadow: var(--tw-ring-inset,) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color, currentcolor);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@copilotkitnext/angular",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Angular library for CopilotKit",
|
|
5
5
|
"main": "dist/fesm2022/copilotkitnext-angular.mjs",
|
|
6
6
|
"module": "dist/fesm2022/copilotkitnext-angular.mjs",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"marked": "^16.2.0",
|
|
28
28
|
"rxjs": "^7.8.1",
|
|
29
29
|
"zod": "^3.22.4",
|
|
30
|
-
"@copilotkitnext/core": "0.0.
|
|
31
|
-
"@copilotkitnext/shared": "0.0.
|
|
30
|
+
"@copilotkitnext/core": "0.0.2",
|
|
31
|
+
"@copilotkitnext/shared": "0.0.2"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"@angular/cdk": "^19.0.0",
|
|
@@ -70,8 +70,8 @@
|
|
|
70
70
|
"typescript-eslint": "^8.35.0",
|
|
71
71
|
"vitest": "^2.0.5",
|
|
72
72
|
"zone.js": "^0.15.0",
|
|
73
|
-
"@copilotkitnext/
|
|
74
|
-
"@copilotkitnext/
|
|
73
|
+
"@copilotkitnext/typescript-config": "0.0.0",
|
|
74
|
+
"@copilotkitnext/eslint-config": "0.0.0"
|
|
75
75
|
},
|
|
76
76
|
"publishConfig": {
|
|
77
77
|
"access": "public"
|
package/README-agent-context.md
DELETED
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
# CopilotKit Angular - Agent Context
|
|
2
|
-
|
|
3
|
-
This document demonstrates how to use agent context in the Angular version of CopilotKit.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
pnpm add @copilotkitnext/angular
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Usage
|
|
12
|
-
|
|
13
|
-
### 1. Directive Approach (Declarative)
|
|
14
|
-
|
|
15
|
-
The directive approach is ideal for template-driven context management.
|
|
16
|
-
|
|
17
|
-
#### Basic Usage
|
|
18
|
-
|
|
19
|
-
```typescript
|
|
20
|
-
import { Component } from "@angular/core";
|
|
21
|
-
import { CopilotKitAgentContextDirective } from "@copilotkitnext/angular";
|
|
22
|
-
|
|
23
|
-
@Component({
|
|
24
|
-
selector: "app-user-profile",
|
|
25
|
-
template: `
|
|
26
|
-
<div
|
|
27
|
-
copilotkitAgentContext
|
|
28
|
-
description="User profile data"
|
|
29
|
-
[value]="userProfile"
|
|
30
|
-
>
|
|
31
|
-
<!-- Your component content -->
|
|
32
|
-
</div>
|
|
33
|
-
`,
|
|
34
|
-
standalone: true,
|
|
35
|
-
imports: [CopilotKitAgentContextDirective],
|
|
36
|
-
})
|
|
37
|
-
export class UserProfileComponent {
|
|
38
|
-
userProfile = {
|
|
39
|
-
id: 123,
|
|
40
|
-
name: "John Doe",
|
|
41
|
-
preferences: {
|
|
42
|
-
theme: "dark",
|
|
43
|
-
language: "en",
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
#### Dynamic Values with Signals
|
|
50
|
-
|
|
51
|
-
```typescript
|
|
52
|
-
import { Component, signal, computed } from "@angular/core";
|
|
53
|
-
|
|
54
|
-
@Component({
|
|
55
|
-
selector: "app-counter",
|
|
56
|
-
template: `
|
|
57
|
-
<div
|
|
58
|
-
copilotkitAgentContext
|
|
59
|
-
description="Counter state"
|
|
60
|
-
[value]="contextValue()"
|
|
61
|
-
>
|
|
62
|
-
<button (click)="increment()">Count: {{ count() }}</button>
|
|
63
|
-
</div>
|
|
64
|
-
`,
|
|
65
|
-
})
|
|
66
|
-
export class CounterComponent {
|
|
67
|
-
count = signal(0);
|
|
68
|
-
|
|
69
|
-
contextValue = computed(() => ({
|
|
70
|
-
count: this.count(),
|
|
71
|
-
doubled: this.count() * 2,
|
|
72
|
-
timestamp: Date.now(),
|
|
73
|
-
}));
|
|
74
|
-
|
|
75
|
-
increment() {
|
|
76
|
-
this.count.update((c) => c + 1);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
#### With Observables
|
|
82
|
-
|
|
83
|
-
```typescript
|
|
84
|
-
import { Component } from "@angular/core";
|
|
85
|
-
import { interval, map } from "rxjs";
|
|
86
|
-
import { AsyncPipe } from "@angular/common";
|
|
87
|
-
|
|
88
|
-
@Component({
|
|
89
|
-
selector: "app-live-data",
|
|
90
|
-
template: `
|
|
91
|
-
<div
|
|
92
|
-
copilotkitAgentContext
|
|
93
|
-
description="Live data stream"
|
|
94
|
-
[value]="liveData$ | async"
|
|
95
|
-
>
|
|
96
|
-
<!-- Component content -->
|
|
97
|
-
</div>
|
|
98
|
-
`,
|
|
99
|
-
imports: [AsyncPipe, CopilotKitAgentContextDirective],
|
|
100
|
-
})
|
|
101
|
-
export class LiveDataComponent {
|
|
102
|
-
liveData$ = interval(1000).pipe(
|
|
103
|
-
map((tick) => ({
|
|
104
|
-
iteration: tick,
|
|
105
|
-
timestamp: new Date(),
|
|
106
|
-
data: this.generateData(tick),
|
|
107
|
-
}))
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
#### Using Context Object
|
|
113
|
-
|
|
114
|
-
```typescript
|
|
115
|
-
@Component({
|
|
116
|
-
template: `
|
|
117
|
-
<div [copilotkitAgentContext]="myContext">
|
|
118
|
-
<!-- Content -->
|
|
119
|
-
</div>
|
|
120
|
-
`
|
|
121
|
-
})
|
|
122
|
-
export class MyComponent {
|
|
123
|
-
myContext = {
|
|
124
|
-
description: 'Application state',
|
|
125
|
-
value: {
|
|
126
|
-
route: '/dashboard',
|
|
127
|
-
user: 'admin',
|
|
128
|
-
settings: { ... }
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
### 2. Programmatic Approach
|
|
135
|
-
|
|
136
|
-
For services and components that need programmatic control.
|
|
137
|
-
|
|
138
|
-
#### Basic Usage
|
|
139
|
-
|
|
140
|
-
```typescript
|
|
141
|
-
import { Component, OnInit, OnDestroy } from '@angular/core';
|
|
142
|
-
import { addAgentContext, injectCopilotKit } from '@copilotkitnext/angular';
|
|
143
|
-
|
|
144
|
-
@Component({...})
|
|
145
|
-
export class MyComponent implements OnInit, OnDestroy {
|
|
146
|
-
private copilotkit = injectCopilotKit();
|
|
147
|
-
private cleanupFns: Array<() => void> = [];
|
|
148
|
-
|
|
149
|
-
ngOnInit() {
|
|
150
|
-
// Add context and store cleanup function
|
|
151
|
-
const cleanup = addAgentContext(this.copilotkit, {
|
|
152
|
-
description: 'Component initialization data',
|
|
153
|
-
value: this.initData
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
this.cleanupFns.push(cleanup);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
ngOnDestroy() {
|
|
160
|
-
// Clean up all contexts
|
|
161
|
-
this.cleanupFns.forEach(fn => fn());
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
#### Auto-cleanup with useAgentContext
|
|
167
|
-
|
|
168
|
-
```typescript
|
|
169
|
-
import { Component, OnInit } from '@angular/core';
|
|
170
|
-
import { useAgentContext } from '@copilotkitnext/angular';
|
|
171
|
-
|
|
172
|
-
@Component({...})
|
|
173
|
-
export class MyComponent implements OnInit {
|
|
174
|
-
ngOnInit() {
|
|
175
|
-
// Automatically cleaned up when component is destroyed
|
|
176
|
-
const contextId = useAgentContext({
|
|
177
|
-
description: 'Auto-managed context',
|
|
178
|
-
value: this.data
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
console.log('Context added with ID:', contextId);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
#### Reactive Context
|
|
187
|
-
|
|
188
|
-
```typescript
|
|
189
|
-
import { Component, signal, computed } from '@angular/core';
|
|
190
|
-
import { createReactiveContext } from '@copilotkitnext/angular';
|
|
191
|
-
|
|
192
|
-
@Component({...})
|
|
193
|
-
export class ReactiveComponent {
|
|
194
|
-
private settings = signal({ theme: 'light' });
|
|
195
|
-
|
|
196
|
-
ngOnInit() {
|
|
197
|
-
const context = createReactiveContext(
|
|
198
|
-
'User settings',
|
|
199
|
-
computed(() => this.settings())
|
|
200
|
-
);
|
|
201
|
-
|
|
202
|
-
// Update context when needed
|
|
203
|
-
this.settings.set({ theme: 'dark' });
|
|
204
|
-
context.update(); // Manually trigger update if needed
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
### 3. Multiple Contexts
|
|
210
|
-
|
|
211
|
-
You can have multiple contexts active at the same time:
|
|
212
|
-
|
|
213
|
-
```typescript
|
|
214
|
-
@Component({
|
|
215
|
-
template: `
|
|
216
|
-
<div copilotkitAgentContext
|
|
217
|
-
description="User data"
|
|
218
|
-
[value]="userData">
|
|
219
|
-
|
|
220
|
-
<div copilotkitAgentContext
|
|
221
|
-
description="Form state"
|
|
222
|
-
[value]="formData">
|
|
223
|
-
|
|
224
|
-
<div copilotkitAgentContext
|
|
225
|
-
description="UI state"
|
|
226
|
-
[value]="uiState">
|
|
227
|
-
<!-- All three contexts are active here -->
|
|
228
|
-
</div>
|
|
229
|
-
</div>
|
|
230
|
-
</div>
|
|
231
|
-
`
|
|
232
|
-
})
|
|
233
|
-
export class MultiContextComponent {
|
|
234
|
-
userData = { ... };
|
|
235
|
-
formData = { ... };
|
|
236
|
-
uiState = { ... };
|
|
237
|
-
}
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
### 4. Conditional Context
|
|
241
|
-
|
|
242
|
-
Context can be conditionally added/removed:
|
|
243
|
-
|
|
244
|
-
```typescript
|
|
245
|
-
@Component({
|
|
246
|
-
template: `
|
|
247
|
-
<div *ngIf="isLoggedIn"
|
|
248
|
-
copilotkitAgentContext
|
|
249
|
-
description="Authenticated user context"
|
|
250
|
-
[value]="userContext">
|
|
251
|
-
<!-- Only added when user is logged in -->
|
|
252
|
-
</div>
|
|
253
|
-
`
|
|
254
|
-
})
|
|
255
|
-
export class ConditionalContextComponent {
|
|
256
|
-
isLoggedIn = false;
|
|
257
|
-
userContext = { ... };
|
|
258
|
-
}
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
## Best Practices
|
|
262
|
-
|
|
263
|
-
1. **Use descriptive names**: Make context descriptions clear and specific
|
|
264
|
-
2. **Keep values serializable**: Context values should be JSON-serializable
|
|
265
|
-
3. **Avoid sensitive data**: Don't include passwords, tokens, or PII in context
|
|
266
|
-
4. **Update responsibly**: Frequent updates may impact performance
|
|
267
|
-
5. **Clean up**: Always remove contexts when no longer needed
|
|
268
|
-
|
|
269
|
-
## Comparison with React
|
|
270
|
-
|
|
271
|
-
| React | Angular |
|
|
272
|
-
| ------------------------------- | ------------------------------------------------------------------ |
|
|
273
|
-
| `useAgentContext(context)` hook | `copilotkitAgentContext` directive or `useAgentContext()` function |
|
|
274
|
-
| Updates via useEffect deps | Updates via `OnChanges` lifecycle |
|
|
275
|
-
| Cleanup in useEffect return | Cleanup in `OnDestroy` lifecycle |
|
|
276
|
-
| Re-renders trigger updates | Signal/Observable changes trigger updates |
|
|
277
|
-
|
|
278
|
-
## TypeScript Support
|
|
279
|
-
|
|
280
|
-
All functions and directives are fully typed:
|
|
281
|
-
|
|
282
|
-
```typescript
|
|
283
|
-
import type { Context } from '@copilotkitnext/angular';
|
|
284
|
-
|
|
285
|
-
const myContext: Context = {
|
|
286
|
-
description: 'Typed context',
|
|
287
|
-
value: {
|
|
288
|
-
// Any serializable value
|
|
289
|
-
id: 123,
|
|
290
|
-
data: ['a', 'b', 'c'],
|
|
291
|
-
nested: { ... }
|
|
292
|
-
}
|
|
293
|
-
};
|
|
294
|
-
```
|
|
295
|
-
|
|
296
|
-
## Testing
|
|
297
|
-
|
|
298
|
-
The agent context directive and utilities are fully testable:
|
|
299
|
-
|
|
300
|
-
```typescript
|
|
301
|
-
it("should add context on init", () => {
|
|
302
|
-
const fixture = TestBed.createComponent(MyComponent);
|
|
303
|
-
fixture.detectChanges();
|
|
304
|
-
|
|
305
|
-
expect(mockCopilotKit.addContext).toHaveBeenCalledWith({
|
|
306
|
-
description: "Test context",
|
|
307
|
-
value: expectedValue,
|
|
308
|
-
});
|
|
309
|
-
});
|
|
310
|
-
```
|
package/slots.md
DELETED
|
@@ -1,331 +0,0 @@
|
|
|
1
|
-
# Angular CopilotKit Component Slots Documentation
|
|
2
|
-
|
|
3
|
-
This document provides a comprehensive inventory of all customization slots available in the Angular CopilotKit components. Each slot can be customized using templates, components, or CSS classes.
|
|
4
|
-
|
|
5
|
-
## Table of Contents
|
|
6
|
-
- [Overview](#overview)
|
|
7
|
-
- [Slot Types](#slot-types)
|
|
8
|
-
- [Component Inventory](#component-inventory)
|
|
9
|
-
- [CopilotChatView](#copilotchatview)
|
|
10
|
-
- [CopilotChatMessageView](#copilotchatmessageview)
|
|
11
|
-
- [CopilotChatAssistantMessage](#copilotchatassistantmessage)
|
|
12
|
-
- [CopilotChatUserMessage](#copilotchatusermessage)
|
|
13
|
-
- [CopilotChatInput](#copilotchatinput)
|
|
14
|
-
- [Context Interfaces](#context-interfaces)
|
|
15
|
-
- [Usage Patterns](#usage-patterns)
|
|
16
|
-
|
|
17
|
-
## Overview
|
|
18
|
-
|
|
19
|
-
Angular CopilotKit components provide extensive customization through a slot system. Each slot accepts:
|
|
20
|
-
- **Templates** (`TemplateRef<any>`) - Using `ng-template` with context variables
|
|
21
|
-
- **Components** (`Type<any>`) - Custom Angular components
|
|
22
|
-
- **CSS Classes** (`string`) - For styling customization
|
|
23
|
-
|
|
24
|
-
## Slot Types
|
|
25
|
-
|
|
26
|
-
### 1. Template Slots
|
|
27
|
-
- Defined using `@ContentChild('slotName', { read: TemplateRef })`
|
|
28
|
-
- Used with `<ng-template #slotName>`
|
|
29
|
-
- Receive context variables via `let-varName="contextProperty"`
|
|
30
|
-
|
|
31
|
-
### 2. Component Slots
|
|
32
|
-
- Defined using `@Input() slotNameComponent?: Type<any>`
|
|
33
|
-
- Accept Angular component classes
|
|
34
|
-
- Must be standalone or properly imported
|
|
35
|
-
|
|
36
|
-
### 3. CSS Class Slots
|
|
37
|
-
- Defined using `@Input() slotNameClass?: string`
|
|
38
|
-
- Apply custom CSS classes to default components
|
|
39
|
-
- Support Tailwind classes and custom CSS
|
|
40
|
-
|
|
41
|
-
## Component Inventory
|
|
42
|
-
|
|
43
|
-
### CopilotChatView
|
|
44
|
-
|
|
45
|
-
The top-level chat interface component with comprehensive customization options.
|
|
46
|
-
|
|
47
|
-
#### Available Slots
|
|
48
|
-
|
|
49
|
-
| Slot Name | Input Property | Template Property | CSS Property | Description |
|
|
50
|
-
|-----------|---------------|-------------------|--------------|-------------|
|
|
51
|
-
| Message View | `messageViewComponent` | `messageViewTemplate` | `messageViewClass` | Container for all messages |
|
|
52
|
-
| Scroll View | `scrollViewComponent` | `scrollViewTemplate` | `scrollViewClass` | Scrollable message container |
|
|
53
|
-
| Scroll Button | `scrollToBottomButtonComponent` | `scrollToBottomButtonTemplate` | `scrollToBottomButtonClass` | Button to scroll to bottom |
|
|
54
|
-
| Input | `inputComponent` | `inputTemplate` | - | Chat input field |
|
|
55
|
-
| Input Container | `inputContainerComponent` | `inputContainerTemplate` | `inputContainerClass` | Container around input |
|
|
56
|
-
| Feather | `featherComponent` | `featherTemplate` | `featherClass` | Gradient feather effect |
|
|
57
|
-
| Disclaimer | `disclaimerComponent` | `disclaimerTemplate` | `disclaimerClass` | Disclaimer message |
|
|
58
|
-
|
|
59
|
-
#### Content Child Templates
|
|
60
|
-
|
|
61
|
-
| Template Name | Selector | Context | Description |
|
|
62
|
-
|--------------|----------|---------|-------------|
|
|
63
|
-
| Custom Layout | `customLayout` | `{ messageView, input, scrollView, ... }` | Complete custom layout |
|
|
64
|
-
| Send Button | `sendButton` | `{ onClick, disabled }` | Custom send button in input |
|
|
65
|
-
| Toolbar | `toolbar` | `{ children }` | Input toolbar customization |
|
|
66
|
-
| Text Area | `textArea` | `{ value, onChange, onKeyDown }` | Custom text input area |
|
|
67
|
-
| Audio Recorder | `audioRecorder` | `{ isRecording, onStart, onStop }` | Audio recording UI |
|
|
68
|
-
| Assistant Markdown | `assistantMessageMarkdownRenderer` | `{ content }` | Markdown rendering for assistant |
|
|
69
|
-
| Thumbs Up Button | `thumbsUpButton` | `{ onClick, message }` | Thumbs up feedback button |
|
|
70
|
-
| Thumbs Down Button | `thumbsDownButton` | `{ onClick, message }` | Thumbs down feedback button |
|
|
71
|
-
| Read Aloud Button | `readAloudButton` | `{ onClick, message }` | Text-to-speech button |
|
|
72
|
-
| Regenerate Button | `regenerateButton` | `{ onClick, message }` | Regenerate response button |
|
|
73
|
-
|
|
74
|
-
#### Event Outputs
|
|
75
|
-
|
|
76
|
-
| Event | Type | Description |
|
|
77
|
-
|-------|------|-------------|
|
|
78
|
-
| `assistantMessageThumbsUp` | `EventEmitter<{ message: Message }>` | Thumbs up clicked |
|
|
79
|
-
| `assistantMessageThumbsDown` | `EventEmitter<{ message: Message }>` | Thumbs down clicked |
|
|
80
|
-
| `assistantMessageReadAloud` | `EventEmitter<{ message: Message }>` | Read aloud clicked |
|
|
81
|
-
| `assistantMessageRegenerate` | `EventEmitter<{ message: Message }>` | Regenerate clicked |
|
|
82
|
-
| `userMessageCopy` | `EventEmitter<{ message: Message }>` | Copy message clicked |
|
|
83
|
-
| `userMessageEdit` | `EventEmitter<{ message: Message }>` | Edit message clicked |
|
|
84
|
-
|
|
85
|
-
### CopilotChatMessageView
|
|
86
|
-
|
|
87
|
-
Container for displaying a list of chat messages.
|
|
88
|
-
|
|
89
|
-
#### Available Slots
|
|
90
|
-
|
|
91
|
-
| Slot Name | Input Property | Template Property | CSS Property | Description |
|
|
92
|
-
|-----------|---------------|-------------------|--------------|-------------|
|
|
93
|
-
| Assistant Message | `assistantMessageComponent` | `assistantMessageTemplate` | `assistantMessageClass` | Assistant message display |
|
|
94
|
-
| User Message | `userMessageComponent` | `userMessageTemplate` | `userMessageClass` | User message display |
|
|
95
|
-
| Cursor | `cursorComponent` | `cursorTemplate` | `cursorClass` | Typing indicator cursor |
|
|
96
|
-
|
|
97
|
-
#### Content Child Templates
|
|
98
|
-
|
|
99
|
-
| Template Name | Selector | Context | Description |
|
|
100
|
-
|--------------|----------|---------|-------------|
|
|
101
|
-
| Custom Layout | `customLayout` | `{ showCursor, messages, messageElements }` | Custom message layout |
|
|
102
|
-
|
|
103
|
-
### CopilotChatAssistantMessage
|
|
104
|
-
|
|
105
|
-
Component for displaying assistant/AI messages.
|
|
106
|
-
|
|
107
|
-
#### Available Slots
|
|
108
|
-
|
|
109
|
-
| Slot Name | Input Property | Template Property | CSS Property | Description |
|
|
110
|
-
|-----------|---------------|-------------------|--------------|-------------|
|
|
111
|
-
| Markdown Renderer | `markdownRendererSlot` | `markdownRenderer` (ContentChild) | `markdownRendererClass` | Markdown content renderer |
|
|
112
|
-
| Toolbar | `toolbarSlot` | `toolbar` (ContentChild) | `toolbarClass` | Message toolbar |
|
|
113
|
-
| Copy Button | `copyButtonSlot` | `copyButton` (ContentChild) | `copyButtonClass` | Copy message button |
|
|
114
|
-
| Thumbs Up Button | `thumbsUpButtonSlot` | `thumbsUpButton` (ContentChild) | `thumbsUpButtonClass` | Positive feedback |
|
|
115
|
-
| Thumbs Down Button | `thumbsDownButtonSlot` | `thumbsDownButton` (ContentChild) | `thumbsDownButtonClass` | Negative feedback |
|
|
116
|
-
| Read Aloud Button | `readAloudButtonSlot` | `readAloudButton` (ContentChild) | `readAloudButtonClass` | Text-to-speech |
|
|
117
|
-
| Regenerate Button | `regenerateButtonSlot` | `regenerateButton` (ContentChild) | `regenerateButtonClass` | Regenerate response |
|
|
118
|
-
|
|
119
|
-
#### Additional Inputs
|
|
120
|
-
|
|
121
|
-
| Input | Type | Description |
|
|
122
|
-
|-------|------|-------------|
|
|
123
|
-
| `message` | `AssistantMessage` | The message data |
|
|
124
|
-
| `additionalToolbarItems` | `TemplateRef<any>` | Extra toolbar items |
|
|
125
|
-
| `toolbarVisible` | `boolean` | Show/hide toolbar |
|
|
126
|
-
| `inputClass` | `string` | Additional CSS classes |
|
|
127
|
-
|
|
128
|
-
### CopilotChatUserMessage
|
|
129
|
-
|
|
130
|
-
Component for displaying user messages.
|
|
131
|
-
|
|
132
|
-
#### Available Slots
|
|
133
|
-
|
|
134
|
-
| Slot Name | Input Property | Template Property | CSS Property | Description |
|
|
135
|
-
|-----------|---------------|-------------------|--------------|-------------|
|
|
136
|
-
| Markdown Renderer | `markdownRendererSlot` | `markdownRenderer` (ContentChild) | `markdownRendererClass` | Message content renderer |
|
|
137
|
-
| Toolbar | `toolbarSlot` | `toolbar` (ContentChild) | `toolbarClass` | Message toolbar |
|
|
138
|
-
| Copy Button | `copyButtonSlot` | `copyButton` (ContentChild) | `copyButtonClass` | Copy message button |
|
|
139
|
-
| Edit Button | `editButtonSlot` | `editButton` (ContentChild) | `editButtonClass` | Edit message button |
|
|
140
|
-
|
|
141
|
-
#### Additional Inputs
|
|
142
|
-
|
|
143
|
-
| Input | Type | Description |
|
|
144
|
-
|-------|------|-------------|
|
|
145
|
-
| `message` | `UserMessage` | The message data |
|
|
146
|
-
| `additionalToolbarItems` | `TemplateRef<any>` | Extra toolbar items |
|
|
147
|
-
| `toolbarVisible` | `boolean` | Show/hide toolbar |
|
|
148
|
-
| `inputClass` | `string` | Additional CSS classes |
|
|
149
|
-
|
|
150
|
-
### CopilotChatInput
|
|
151
|
-
|
|
152
|
-
The chat input component with rich customization options.
|
|
153
|
-
|
|
154
|
-
#### Available Slots
|
|
155
|
-
|
|
156
|
-
| Slot Name | Input Property | Template Property | CSS Property | Description |
|
|
157
|
-
|-----------|---------------|-------------------|--------------|-------------|
|
|
158
|
-
| Text Area | `textAreaSlot` | `textArea` (ContentChild) | `textAreaClass` | Input text area |
|
|
159
|
-
| Send Button | `sendButtonSlot` | `sendButton` (ContentChild) | `sendButtonClass` | Send message button |
|
|
160
|
-
| Audio Recorder | `audioRecorderSlot` | `audioRecorder` (ContentChild) | `audioRecorderClass` | Voice recording UI |
|
|
161
|
-
| Toolbar | `toolbarSlot` | `toolbar` (ContentChild) | `toolbarClass` | Input toolbar |
|
|
162
|
-
|
|
163
|
-
#### Additional Inputs
|
|
164
|
-
|
|
165
|
-
| Input | Type | Description |
|
|
166
|
-
|-------|------|-------------|
|
|
167
|
-
| `placeholder` | `string` | Input placeholder text |
|
|
168
|
-
| `disabled` | `boolean` | Disable input |
|
|
169
|
-
| `inputClass` | `string` | Additional CSS classes |
|
|
170
|
-
|
|
171
|
-
## Context Interfaces
|
|
172
|
-
|
|
173
|
-
### AssistantMessageMarkdownRendererContext
|
|
174
|
-
```typescript
|
|
175
|
-
interface AssistantMessageMarkdownRendererContext {
|
|
176
|
-
content: string;
|
|
177
|
-
}
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
### AssistantMessageToolbarContext
|
|
181
|
-
```typescript
|
|
182
|
-
interface AssistantMessageToolbarContext {
|
|
183
|
-
children: any;
|
|
184
|
-
}
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
### AssistantMessageCopyButtonContext
|
|
188
|
-
```typescript
|
|
189
|
-
interface AssistantMessageCopyButtonContext {
|
|
190
|
-
onClick: () => void;
|
|
191
|
-
}
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
### ThumbsUpButtonContext
|
|
195
|
-
```typescript
|
|
196
|
-
interface ThumbsUpButtonContext {
|
|
197
|
-
onClick: () => void;
|
|
198
|
-
}
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
### ThumbsDownButtonContext
|
|
202
|
-
```typescript
|
|
203
|
-
interface ThumbsDownButtonContext {
|
|
204
|
-
onClick: () => void;
|
|
205
|
-
}
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
### ReadAloudButtonContext
|
|
209
|
-
```typescript
|
|
210
|
-
interface ReadAloudButtonContext {
|
|
211
|
-
onClick: () => void;
|
|
212
|
-
}
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
### RegenerateButtonContext
|
|
216
|
-
```typescript
|
|
217
|
-
interface RegenerateButtonContext {
|
|
218
|
-
onClick: () => void;
|
|
219
|
-
}
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
### InputContext
|
|
223
|
-
```typescript
|
|
224
|
-
interface InputContext {
|
|
225
|
-
onSend: (message: string) => void;
|
|
226
|
-
placeholder?: string;
|
|
227
|
-
disabled?: boolean;
|
|
228
|
-
}
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
### ScrollButtonContext
|
|
232
|
-
```typescript
|
|
233
|
-
interface ScrollButtonContext {
|
|
234
|
-
onClick: () => void;
|
|
235
|
-
visible: boolean;
|
|
236
|
-
}
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
## Usage Patterns
|
|
240
|
-
|
|
241
|
-
### Template Customization
|
|
242
|
-
```html
|
|
243
|
-
<copilot-chat-view>
|
|
244
|
-
<ng-template #disclaimer>
|
|
245
|
-
<div class="custom-disclaimer">
|
|
246
|
-
Custom disclaimer content
|
|
247
|
-
</div>
|
|
248
|
-
</ng-template>
|
|
249
|
-
|
|
250
|
-
<ng-template #sendButton let-onClick="onClick" let-disabled="disabled">
|
|
251
|
-
<button (click)="onClick()" [disabled]="disabled">
|
|
252
|
-
Send Message
|
|
253
|
-
</button>
|
|
254
|
-
</ng-template>
|
|
255
|
-
</copilot-chat-view>
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
### Component Customization
|
|
259
|
-
```typescript
|
|
260
|
-
@Component({
|
|
261
|
-
template: `
|
|
262
|
-
<copilot-chat-view
|
|
263
|
-
[disclaimerComponent]="customDisclaimerComponent"
|
|
264
|
-
[inputComponent]="customInputComponent">
|
|
265
|
-
</copilot-chat-view>
|
|
266
|
-
`
|
|
267
|
-
})
|
|
268
|
-
export class MyComponent {
|
|
269
|
-
customDisclaimerComponent = CustomDisclaimerComponent;
|
|
270
|
-
customInputComponent = CustomInputComponent;
|
|
271
|
-
}
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
### CSS Customization
|
|
275
|
-
```html
|
|
276
|
-
<copilot-chat-view
|
|
277
|
-
[disclaimerClass]="'bg-blue-500 text-white p-4 rounded-lg'"
|
|
278
|
-
[inputClass]="'border-2 border-gray-300 focus:border-blue-500'"
|
|
279
|
-
[messageViewClass]="'max-w-4xl mx-auto'">
|
|
280
|
-
</copilot-chat-view>
|
|
281
|
-
```
|
|
282
|
-
|
|
283
|
-
### Event Handling
|
|
284
|
-
```typescript
|
|
285
|
-
@Component({
|
|
286
|
-
template: `
|
|
287
|
-
<copilot-chat-view
|
|
288
|
-
(assistantMessageThumbsUp)="handleThumbsUp($event)"
|
|
289
|
-
(assistantMessageThumbsDown)="handleThumbsDown($event)"
|
|
290
|
-
(userMessageEdit)="handleEdit($event)">
|
|
291
|
-
</copilot-chat-view>
|
|
292
|
-
`
|
|
293
|
-
})
|
|
294
|
-
export class MyComponent {
|
|
295
|
-
handleThumbsUp(event: { message: Message }) {
|
|
296
|
-
console.log('Thumbs up for message:', event.message);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
handleThumbsDown(event: { message: Message }) {
|
|
300
|
-
console.log('Thumbs down for message:', event.message);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
handleEdit(event: { message: Message }) {
|
|
304
|
-
console.log('Edit message:', event.message);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
```
|
|
308
|
-
|
|
309
|
-
## Best Practices
|
|
310
|
-
|
|
311
|
-
1. **Use Templates for Dynamic Content**: When you need to pass context variables or handle events, use templates.
|
|
312
|
-
|
|
313
|
-
2. **Use Components for Complex Logic**: When customization requires significant logic or state management, create a custom component.
|
|
314
|
-
|
|
315
|
-
3. **Use CSS Classes for Simple Styling**: For basic visual customization, CSS classes are the simplest approach.
|
|
316
|
-
|
|
317
|
-
4. **Combine Approaches**: You can mix templates, components, and CSS classes for different slots in the same component.
|
|
318
|
-
|
|
319
|
-
5. **Type Safety**: Define proper TypeScript interfaces for your context objects when creating custom templates.
|
|
320
|
-
|
|
321
|
-
6. **Performance**: Use `ChangeDetectionStrategy.OnPush` in custom components for better performance.
|
|
322
|
-
|
|
323
|
-
7. **Accessibility**: Ensure custom components maintain proper ARIA attributes and keyboard navigation.
|
|
324
|
-
|
|
325
|
-
## Future Enhancements
|
|
326
|
-
|
|
327
|
-
- Additional slot positions for more granular customization
|
|
328
|
-
- Built-in theme presets
|
|
329
|
-
- Animation and transition customization slots
|
|
330
|
-
- Custom loading states and error handling slots
|
|
331
|
-
- Plugin system for extending functionality
|