@copilotkitnext/angular 0.0.2 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/README.md +3 -3
  2. package/dist/README.md +3 -3
  3. package/dist/components/chat/copilot-chat-assistant-message.component.d.ts +10 -10
  4. package/dist/components/chat/copilot-chat-message-view.component.d.ts +42 -42
  5. package/dist/components/chat/copilot-chat-view.component.d.ts +14 -14
  6. package/dist/core/copilotkit.providers.d.ts +1 -1
  7. package/dist/core/copilotkit.service.d.ts +5 -5
  8. package/dist/core/copilotkit.types.d.ts +8 -10
  9. package/dist/directives/copilotkit-frontend-tool.directive.d.ts +1 -1
  10. package/dist/esm2022/components/chat/copilot-chat-assistant-message-buttons.component.mjs +384 -0
  11. package/dist/esm2022/components/chat/copilot-chat-assistant-message-renderer.component.mjs +286 -0
  12. package/dist/esm2022/components/chat/copilot-chat-assistant-message-toolbar.component.mjs +27 -0
  13. package/dist/esm2022/components/chat/copilot-chat-assistant-message.component.mjs +433 -0
  14. package/dist/esm2022/components/chat/copilot-chat-assistant-message.types.mjs +2 -0
  15. package/dist/esm2022/components/chat/copilot-chat-audio-recorder.component.mjs +202 -0
  16. package/dist/esm2022/components/chat/copilot-chat-buttons.component.mjs +321 -0
  17. package/dist/esm2022/components/chat/copilot-chat-input-defaults.mjs +38 -0
  18. package/dist/esm2022/components/chat/copilot-chat-input.component.mjs +666 -0
  19. package/dist/esm2022/components/chat/copilot-chat-input.types.mjs +10 -0
  20. package/dist/esm2022/components/chat/copilot-chat-message-view-cursor.component.mjs +45 -0
  21. package/dist/esm2022/components/chat/copilot-chat-message-view.component.mjs +296 -0
  22. package/dist/esm2022/components/chat/copilot-chat-message-view.types.mjs +2 -0
  23. package/dist/esm2022/components/chat/copilot-chat-textarea.component.mjs +188 -0
  24. package/dist/esm2022/components/chat/copilot-chat-tool-calls-view.component.mjs +216 -0
  25. package/dist/esm2022/components/chat/copilot-chat-toolbar.component.mjs +25 -0
  26. package/dist/esm2022/components/chat/copilot-chat-tools-menu.component.mjs +199 -0
  27. package/dist/esm2022/components/chat/copilot-chat-user-message-branch-navigation.component.mjs +137 -0
  28. package/dist/esm2022/components/chat/copilot-chat-user-message-buttons.component.mjs +207 -0
  29. package/dist/esm2022/components/chat/copilot-chat-user-message-renderer.component.mjs +35 -0
  30. package/dist/esm2022/components/chat/copilot-chat-user-message-toolbar.component.mjs +34 -0
  31. package/dist/esm2022/components/chat/copilot-chat-user-message.component.mjs +341 -0
  32. package/dist/esm2022/components/chat/copilot-chat-user-message.types.mjs +2 -0
  33. package/dist/esm2022/components/chat/copilot-chat-view-disclaimer.component.mjs +52 -0
  34. package/dist/esm2022/components/chat/copilot-chat-view-feather.component.mjs +55 -0
  35. package/dist/esm2022/components/chat/copilot-chat-view-handlers.service.mjs +19 -0
  36. package/dist/esm2022/components/chat/copilot-chat-view-input-container.component.mjs +110 -0
  37. package/dist/esm2022/components/chat/copilot-chat-view-scroll-to-bottom-button.component.mjs +93 -0
  38. package/dist/esm2022/components/chat/copilot-chat-view-scroll-view.component.mjs +443 -0
  39. package/dist/esm2022/components/chat/copilot-chat-view.component.mjs +479 -0
  40. package/dist/esm2022/components/chat/copilot-chat-view.types.mjs +2 -0
  41. package/dist/esm2022/components/chat/copilot-chat.component.mjs +214 -0
  42. package/dist/esm2022/components/copilotkit-tool-render.component.mjs +153 -0
  43. package/dist/esm2022/copilotkitnext-angular.mjs +5 -0
  44. package/dist/esm2022/core/chat-configuration/chat-configuration.providers.mjs +65 -0
  45. package/dist/esm2022/core/chat-configuration/chat-configuration.service.mjs +145 -0
  46. package/dist/esm2022/core/chat-configuration/chat-configuration.types.mjs +26 -0
  47. package/dist/esm2022/core/copilotkit.providers.mjs +34 -0
  48. package/dist/esm2022/core/copilotkit.service.mjs +426 -0
  49. package/dist/esm2022/core/copilotkit.types.mjs +13 -0
  50. package/dist/esm2022/directives/copilotkit-agent-context.directive.mjs +130 -0
  51. package/dist/esm2022/directives/copilotkit-agent.directive.mjs +217 -0
  52. package/dist/esm2022/directives/copilotkit-chat-config.directive.mjs +218 -0
  53. package/dist/esm2022/directives/copilotkit-config.directive.mjs +94 -0
  54. package/dist/esm2022/directives/copilotkit-frontend-tool.directive.mjs +128 -0
  55. package/dist/esm2022/directives/copilotkit-human-in-the-loop.directive.mjs +265 -0
  56. package/dist/esm2022/directives/stick-to-bottom.directive.mjs +181 -0
  57. package/dist/esm2022/index.mjs +70 -0
  58. package/dist/esm2022/lib/directives/tooltip.directive.mjs +211 -0
  59. package/dist/esm2022/lib/slots/copilot-slot.component.mjs +144 -0
  60. package/dist/esm2022/lib/slots/slot.types.mjs +6 -0
  61. package/dist/esm2022/lib/slots/slot.utils.mjs +222 -0
  62. package/dist/esm2022/lib/utils.mjs +10 -0
  63. package/dist/esm2022/services/resize-observer.service.mjs +152 -0
  64. package/dist/esm2022/services/scroll-position.service.mjs +124 -0
  65. package/dist/esm2022/types/frontend-tool.mjs +2 -0
  66. package/dist/esm2022/types/human-in-the-loop.mjs +2 -0
  67. package/dist/esm2022/utils/agent-context.utils.mjs +114 -0
  68. package/dist/esm2022/utils/agent.utils.mjs +204 -0
  69. package/dist/esm2022/utils/chat-config.utils.mjs +186 -0
  70. package/dist/esm2022/utils/copilotkit.utils.mjs +20 -0
  71. package/dist/esm2022/utils/frontend-tool.utils.mjs +224 -0
  72. package/dist/esm2022/utils/human-in-the-loop.utils.mjs +293 -0
  73. package/dist/fesm2022/copilotkitnext-angular.mjs +174 -187
  74. package/dist/fesm2022/copilotkitnext-angular.mjs.map +1 -1
  75. package/dist/utils/frontend-tool.utils.d.ts +1 -1
  76. package/package.json +23 -20
  77. package/vitest.config.mts +32 -21
  78. package/.turbo/turbo-build.log +0 -38
  79. package/.turbo/turbo-check-types.log +0 -0
  80. package/.turbo/turbo-test.log +0 -71
  81. package/ng-package.json +0 -19
  82. package/src/components/chat/__tests__/copilot-chat-assistant-message.component.spec.ts +0 -282
  83. package/src/components/chat/__tests__/copilot-chat-input.component.spec.ts +0 -419
  84. package/src/components/chat/__tests__/copilot-chat-message-view.component.spec.ts +0 -372
  85. package/src/components/chat/__tests__/copilot-chat-user-message.component.spec.ts +0 -249
  86. package/src/components/chat/copilot-chat-assistant-message-buttons.component.ts +0 -292
  87. package/src/components/chat/copilot-chat-assistant-message-renderer.component.ts +0 -472
  88. package/src/components/chat/copilot-chat-assistant-message-toolbar.component.ts +0 -29
  89. package/src/components/chat/copilot-chat-assistant-message.component.ts +0 -463
  90. package/src/components/chat/copilot-chat-assistant-message.types.ts +0 -50
  91. package/src/components/chat/copilot-chat-audio-recorder.component.ts +0 -241
  92. package/src/components/chat/copilot-chat-buttons.component.ts +0 -308
  93. package/src/components/chat/copilot-chat-buttons.component.ts.bak +0 -471
  94. package/src/components/chat/copilot-chat-input-defaults.ts +0 -47
  95. package/src/components/chat/copilot-chat-input.component.ts +0 -512
  96. package/src/components/chat/copilot-chat-input.types.ts +0 -148
  97. package/src/components/chat/copilot-chat-message-view-cursor.component.ts +0 -51
  98. package/src/components/chat/copilot-chat-message-view.component.ts +0 -233
  99. package/src/components/chat/copilot-chat-message-view.types.ts +0 -39
  100. package/src/components/chat/copilot-chat-textarea.component.ts +0 -220
  101. package/src/components/chat/copilot-chat-tool-calls-view.component.ts +0 -261
  102. package/src/components/chat/copilot-chat-toolbar.component.ts +0 -35
  103. package/src/components/chat/copilot-chat-tools-menu.component.ts +0 -185
  104. package/src/components/chat/copilot-chat-user-message-branch-navigation.component.ts +0 -121
  105. package/src/components/chat/copilot-chat-user-message-buttons.component.ts +0 -170
  106. package/src/components/chat/copilot-chat-user-message-renderer.component.ts +0 -37
  107. package/src/components/chat/copilot-chat-user-message-toolbar.component.ts +0 -37
  108. package/src/components/chat/copilot-chat-user-message.component.ts +0 -247
  109. package/src/components/chat/copilot-chat-user-message.types.ts +0 -42
  110. package/src/components/chat/copilot-chat-view-disclaimer.component.ts +0 -51
  111. package/src/components/chat/copilot-chat-view-feather.component.ts +0 -47
  112. package/src/components/chat/copilot-chat-view-handlers.service.ts +0 -14
  113. package/src/components/chat/copilot-chat-view-input-container.component.ts +0 -87
  114. package/src/components/chat/copilot-chat-view-scroll-to-bottom-button.component.ts +0 -79
  115. package/src/components/chat/copilot-chat-view-scroll-view.component.ts +0 -322
  116. package/src/components/chat/copilot-chat-view.component.ts +0 -420
  117. package/src/components/chat/copilot-chat-view.types.ts +0 -52
  118. package/src/components/chat/copilot-chat.component.ts +0 -232
  119. package/src/components/copilotkit-tool-render.component.ts +0 -169
  120. package/src/core/__tests__/copilotkit.service.spec.ts +0 -1051
  121. package/src/core/__tests__/copilotkit.service.wildcard.spec.ts +0 -316
  122. package/src/core/chat-configuration/__tests__/chat-configuration.service.spec.ts +0 -287
  123. package/src/core/chat-configuration/chat-configuration.providers.ts +0 -71
  124. package/src/core/chat-configuration/chat-configuration.service.ts +0 -162
  125. package/src/core/chat-configuration/chat-configuration.types.ts +0 -57
  126. package/src/core/copilotkit.providers.ts +0 -59
  127. package/src/core/copilotkit.service.ts +0 -542
  128. package/src/core/copilotkit.types.ts +0 -132
  129. package/src/directives/__tests__/copilotkit-agent-context.directive.spec.ts +0 -384
  130. package/src/directives/__tests__/copilotkit-agent.directive.spec.ts +0 -253
  131. package/src/directives/__tests__/copilotkit-chat-config.directive.spec.ts +0 -385
  132. package/src/directives/__tests__/copilotkit-config.directive.spec.ts +0 -69
  133. package/src/directives/__tests__/copilotkit-frontend-tool-simple.directive.spec.ts +0 -60
  134. package/src/directives/__tests__/copilotkit-frontend-tool.directive.spec.ts +0 -108
  135. package/src/directives/__tests__/copilotkit-human-in-the-loop.directive.spec.ts +0 -452
  136. package/src/directives/copilotkit-agent-context.directive.ts +0 -138
  137. package/src/directives/copilotkit-agent.directive.ts +0 -225
  138. package/src/directives/copilotkit-chat-config.directive.ts +0 -241
  139. package/src/directives/copilotkit-config.directive.ts +0 -81
  140. package/src/directives/copilotkit-frontend-tool.directive.ts +0 -145
  141. package/src/directives/copilotkit-human-in-the-loop.directive.ts +0 -281
  142. package/src/directives/stick-to-bottom.directive.ts +0 -204
  143. package/src/index.ts +0 -105
  144. package/src/lib/directives/tooltip.directive.ts +0 -292
  145. package/src/lib/slots/__tests__/slot.utils.spec.ts +0 -377
  146. package/src/lib/slots/copilot-slot.component.ts +0 -135
  147. package/src/lib/slots/index.ts +0 -3
  148. package/src/lib/slots/slot.types.ts +0 -64
  149. package/src/lib/slots/slot.utils.ts +0 -289
  150. package/src/lib/utils.ts +0 -10
  151. package/src/public-api.ts +0 -1
  152. package/src/services/resize-observer.service.ts +0 -181
  153. package/src/services/scroll-position.service.ts +0 -169
  154. package/src/styles/globals.css +0 -266
  155. package/src/styles/index.css +0 -3
  156. package/src/test-setup.ts +0 -15
  157. package/src/testing/index.ts +0 -3
  158. package/src/testing/testing.utils.ts +0 -248
  159. package/src/types/frontend-tool.ts +0 -44
  160. package/src/types/human-in-the-loop.ts +0 -52
  161. package/src/utils/__tests__/agent.utils.spec.ts +0 -234
  162. package/src/utils/__tests__/chat-config.utils.spec.ts +0 -306
  163. package/src/utils/__tests__/frontend-tool-inject.spec.ts +0 -350
  164. package/src/utils/__tests__/frontend-tool-integration.spec.ts +0 -199
  165. package/src/utils/__tests__/frontend-tool.utils.spec.ts +0 -272
  166. package/src/utils/__tests__/human-in-the-loop.utils.spec.ts +0 -365
  167. package/src/utils/agent-context.utils.ts +0 -133
  168. package/src/utils/agent.utils.ts +0 -239
  169. package/src/utils/chat-config.utils.ts +0 -221
  170. package/src/utils/copilotkit.utils.ts +0 -20
  171. package/src/utils/frontend-tool.utils.ts +0 -266
  172. package/src/utils/human-in-the-loop.utils.ts +0 -359
  173. package/tsconfig.spec.json +0 -12
@@ -1,281 +0,0 @@
1
- import {
2
- Directive,
3
- Input,
4
- Output,
5
- EventEmitter,
6
- OnInit,
7
- OnChanges,
8
- OnDestroy,
9
- SimpleChanges,
10
- TemplateRef,
11
- Type,
12
- signal,
13
- isDevMode,
14
- Inject,
15
- } from "@angular/core";
16
- import { CopilotKitService } from "../core/copilotkit.service";
17
- import type {
18
- AngularHumanInTheLoop,
19
- HumanInTheLoopProps,
20
- AngularFrontendTool,
21
- } from "../core/copilotkit.types";
22
- import { ToolCallStatus } from "../core/copilotkit.types";
23
- import * as z from "zod";
24
-
25
- /**
26
- * Directive for declaratively creating human-in-the-loop tools.
27
- * Provides reactive outputs for status changes and response events.
28
- *
29
- * @example
30
- * ```html
31
- * <!-- Basic usage -->
32
- * <div copilotkitHumanInTheLoop
33
- * [name]="'requireApproval'"
34
- * [description]="'Requires user approval'"
35
- * [args]="argsSchema"
36
- * [render]="approvalComponent"
37
- * (statusChange)="onStatusChange($event)"
38
- * (responseProvided)="onResponse($event)">
39
- * </div>
40
- *
41
- * <!-- With template -->
42
- * <div copilotkitHumanInTheLoop
43
- * [name]="'requireApproval'"
44
- * [description]="'Requires user approval'"
45
- * [args]="argsSchema"
46
- * [render]="approvalTemplate"
47
- * [(status)]="approvalStatus">
48
- * </div>
49
- *
50
- * <ng-template #approvalTemplate let-props>
51
- * <div *ngIf="props.status === 'executing'">
52
- * <p>{{ props.args.action }}</p>
53
- * <button (click)="props.respond('approved')">Approve</button>
54
- * <button (click)="props.respond('rejected')">Reject</button>
55
- * </div>
56
- * </ng-template>
57
- * ```
58
- */
59
- @Directive({
60
- selector: "[copilotkitHumanInTheLoop]",
61
- standalone: true,
62
- })
63
- export class CopilotKitHumanInTheLoopDirective<
64
- T extends Record<string, any> = Record<string, any>,
65
- >
66
- implements OnInit, OnChanges, OnDestroy
67
- {
68
- private toolId?: string;
69
- private statusSignal = signal<ToolCallStatus>(ToolCallStatus.InProgress);
70
- private resolvePromise: ((result: unknown) => void) | null = null;
71
- private _status: ToolCallStatus = ToolCallStatus.InProgress;
72
-
73
- constructor(
74
- @Inject(CopilotKitService) private readonly copilotkit: CopilotKitService
75
- ) {}
76
-
77
- /**
78
- * The name of the human-in-the-loop tool.
79
- */
80
- @Input() name!: string;
81
-
82
- /**
83
- * Description of what the tool does.
84
- */
85
- @Input() description!: string;
86
-
87
- /**
88
- * Zod schema for the tool parameters.
89
- */
90
- @Input() parameters!: z.ZodSchema<T>;
91
-
92
- /**
93
- * Component class or template to render for user interaction.
94
- */
95
- @Input() render!: Type<any> | TemplateRef<HumanInTheLoopProps<T>>;
96
-
97
- /**
98
- * Whether the tool should be registered (default: true).
99
- */
100
- @Input() enabled = true;
101
-
102
- /**
103
- * Alternative input using the directive selector.
104
- * Allows: [copilotkitHumanInTheLoop]="config"
105
- */
106
- @Input("copilotkitHumanInTheLoop")
107
- set config(value: Partial<AngularHumanInTheLoop<T>> | undefined) {
108
- if (value) {
109
- if (value.name) this.name = value.name;
110
- if (value.description) this.description = value.description;
111
- if ("parameters" in value && value.parameters)
112
- this.parameters = value.parameters as z.ZodSchema<T>;
113
- if ("render" in value && value.render) this.render = value.render;
114
- }
115
- }
116
-
117
- /**
118
- * Emits when the status changes.
119
- */
120
- @Output() statusChange = new EventEmitter<ToolCallStatus>();
121
-
122
- /**
123
- * Two-way binding for status.
124
- */
125
- @Input()
126
- get status(): ToolCallStatus {
127
- return this._status;
128
- }
129
- set status(value: ToolCallStatus) {
130
- // Input setter for two-way binding (though typically read-only)
131
- this._status = value;
132
- }
133
-
134
- /**
135
- * Emits when a response is provided by the user.
136
- */
137
- @Output() responseProvided = new EventEmitter<unknown>();
138
-
139
- /**
140
- * Emits when the tool execution starts.
141
- */
142
- @Output() executionStarted = new EventEmitter<any>();
143
-
144
- /**
145
- * Emits when the tool execution completes.
146
- */
147
- @Output() executionCompleted = new EventEmitter<unknown>();
148
-
149
- ngOnInit(): void {
150
- if (this.enabled) {
151
- this.registerTool();
152
- }
153
- }
154
-
155
- ngOnChanges(changes: SimpleChanges): void {
156
- const relevantChanges =
157
- changes["name"] ||
158
- changes["description"] ||
159
- changes["args"] ||
160
- changes["render"] ||
161
- changes["enabled"];
162
-
163
- if (relevantChanges && !relevantChanges.firstChange) {
164
- // Re-register the tool with new configuration
165
- this.unregisterTool();
166
- if (this.enabled) {
167
- this.registerTool();
168
- }
169
- }
170
- }
171
-
172
- ngOnDestroy(): void {
173
- this.unregisterTool();
174
- }
175
-
176
- /**
177
- * Programmatically trigger a response.
178
- * Useful when the directive is used as a controller.
179
- */
180
- respond(result: unknown): void {
181
- this.handleResponse(result);
182
- }
183
-
184
- private registerTool(): void {
185
- if (!this.name || !this.description || !this.parameters || !this.render) {
186
- if (isDevMode()) {
187
- throw new Error(
188
- "CopilotKitHumanInTheLoopDirective: Missing required inputs. " +
189
- "Required: name, description, parameters, and render."
190
- );
191
- }
192
- return;
193
- }
194
-
195
- // Create handler that returns a Promise
196
- const handler = async (args: T): Promise<unknown> => {
197
- return new Promise((resolve) => {
198
- this.updateStatus(ToolCallStatus.Executing);
199
- this.resolvePromise = resolve;
200
- this.executionStarted.emit(args);
201
- });
202
- };
203
-
204
- // Create the frontend tool with enhanced render
205
- const frontendTool: AngularFrontendTool<T> = {
206
- name: this.name,
207
- description: this.description,
208
- parameters: this.parameters,
209
- handler,
210
- render: this.render, // Will be enhanced by the render component
211
- };
212
-
213
- // Add the tool (returns void, so we use the tool name as ID)
214
- this.copilotkit.copilotkit.addTool(frontendTool);
215
- this.toolId = this.name;
216
-
217
- // Register the render with respond capability
218
- this.copilotkit.registerToolRender(this.name, {
219
- name: this.name,
220
- args: this.parameters,
221
- render: this.createEnhancedRender(),
222
- });
223
- }
224
-
225
- private unregisterTool(): void {
226
- if (this.toolId) {
227
- this.copilotkit.copilotkit.removeTool(this.toolId);
228
- this.copilotkit.unregisterToolRender(this.name);
229
- this.toolId = undefined;
230
- }
231
- }
232
-
233
- private createEnhancedRender(): Type<any> | TemplateRef<any> {
234
- // If it's a template, we need to wrap it with our respond function
235
- // This is handled by returning a special marker that the render component
236
- // will recognize and enhance with the respond function
237
-
238
- // Store reference to this directive instance for the render component
239
- (this.render as any).__humanInTheLoopDirective = this;
240
- (this.render as any).__humanInTheLoopStatus = this.statusSignal;
241
-
242
- return this.render;
243
- }
244
-
245
- private handleResponse(result: unknown): void {
246
- if (this.resolvePromise) {
247
- this.resolvePromise(result);
248
- this.updateStatus(ToolCallStatus.Complete);
249
- this.resolvePromise = null;
250
- this.responseProvided.emit(result);
251
- this.executionCompleted.emit(result);
252
- }
253
- }
254
-
255
- private updateStatus(status: ToolCallStatus): void {
256
- this._status = status;
257
- this.statusSignal.set(status);
258
- this.statusChange.emit(status);
259
- }
260
- }
261
-
262
- /**
263
- * Helper directive to provide respond function in templates.
264
- * This would be used internally by the tool render component.
265
- *
266
- * @internal
267
- */
268
- @Directive({
269
- selector: "[copilotkitHumanInTheLoopRespond]",
270
- standalone: true,
271
- })
272
- export class CopilotKitHumanInTheLoopRespondDirective {
273
- @Input() copilotkitHumanInTheLoopRespond?: (result: unknown) => Promise<void>;
274
-
275
- /**
276
- * Convenience method for templates to call respond.
277
- */
278
- respond(result: unknown): void {
279
- this.copilotkitHumanInTheLoopRespond?.(result);
280
- }
281
- }
@@ -1,204 +0,0 @@
1
- import {
2
- Directive,
3
- Input,
4
- Output,
5
- EventEmitter,
6
- ElementRef,
7
- OnInit,
8
- OnDestroy,
9
- AfterViewInit,
10
- inject
11
- } from '@angular/core';
12
- import { ScrollPositionService } from '../services/scroll-position.service';
13
- import { ResizeObserverService } from '../services/resize-observer.service';
14
- import { Subject, combineLatest, merge } from 'rxjs';
15
- import { takeUntil, debounceTime, filter, distinctUntilChanged } from 'rxjs/operators';
16
-
17
- export type ScrollBehavior = 'smooth' | 'instant' | 'auto';
18
-
19
- /**
20
- * Directive for implementing stick-to-bottom scroll behavior
21
- * Similar to the React use-stick-to-bottom library
22
- *
23
- * @example
24
- * ```html
25
- * <div copilotStickToBottom
26
- * [enabled]="true"
27
- * [threshold]="10"
28
- * [initialBehavior]="'smooth'"
29
- * [resizeBehavior]="'smooth'"
30
- * (isAtBottomChange)="onBottomChange($event)">
31
- * <!-- Content -->
32
- * </div>
33
- * ```
34
- */
35
- @Directive({
36
- selector: '[copilotStickToBottom]',
37
- standalone: true,
38
- providers: [ScrollPositionService, ResizeObserverService]
39
- })
40
- export class StickToBottomDirective implements OnInit, AfterViewInit, OnDestroy {
41
- @Input() enabled: boolean = true;
42
- @Input() threshold: number = 10;
43
- @Input() initialBehavior: ScrollBehavior = 'smooth';
44
- @Input() resizeBehavior: ScrollBehavior = 'smooth';
45
- @Input() debounceMs: number = 100;
46
-
47
- @Output() isAtBottomChange = new EventEmitter<boolean>();
48
- @Output() scrollToBottomRequested = new EventEmitter<void>();
49
-
50
- private elementRef = inject(ElementRef);
51
- private scrollService = inject(ScrollPositionService);
52
- private resizeService = inject(ResizeObserverService);
53
-
54
- private destroy$ = new Subject<void>();
55
- private contentElement?: HTMLElement;
56
- private wasAtBottom = true;
57
- private hasInitialized = false;
58
- private userHasScrolled = false;
59
-
60
- ngOnInit(): void {
61
- // Setup will happen in ngAfterViewInit
62
- }
63
-
64
- ngAfterViewInit(): void {
65
- const element = this.elementRef.nativeElement as HTMLElement;
66
-
67
- // Find or create content wrapper
68
- this.contentElement = element.querySelector('[data-stick-to-bottom-content]') as HTMLElement;
69
- if (!this.contentElement) {
70
- this.contentElement = element;
71
- }
72
-
73
- this.setupScrollMonitoring();
74
- this.setupResizeMonitoring();
75
- this.setupContentMutationObserver();
76
-
77
- // Initial scroll to bottom if enabled
78
- setTimeout(() => {
79
- this.hasInitialized = true;
80
- if (this.enabled) {
81
- this.scrollToBottom(this.initialBehavior);
82
- }
83
- }, 0);
84
- }
85
-
86
- private setupScrollMonitoring(): void {
87
- if (!this.enabled) return;
88
-
89
- const element = this.elementRef.nativeElement;
90
-
91
- // Monitor scroll position
92
- this.scrollService.monitorScrollPosition(element, this.threshold)
93
- .pipe(
94
- takeUntil(this.destroy$),
95
- debounceTime(this.debounceMs),
96
- distinctUntilChanged((a, b) => a.isAtBottom === b.isAtBottom)
97
- )
98
- .subscribe(state => {
99
- const wasAtBottom = this.wasAtBottom;
100
- this.wasAtBottom = state.isAtBottom;
101
-
102
- // Detect user scroll
103
- if (!state.isAtBottom && wasAtBottom && this.hasInitialized) {
104
- this.userHasScrolled = true;
105
- } else if (state.isAtBottom) {
106
- this.userHasScrolled = false;
107
- }
108
-
109
- // Emit change
110
- this.isAtBottomChange.emit(state.isAtBottom);
111
- });
112
- }
113
-
114
- private setupResizeMonitoring(): void {
115
- if (!this.enabled || !this.contentElement) return;
116
-
117
- // Monitor content resize
118
- this.resizeService.observeElement(this.contentElement, 0, 250)
119
- .pipe(
120
- takeUntil(this.destroy$),
121
- filter(() => this.enabled && !this.userHasScrolled)
122
- )
123
- .subscribe(state => {
124
- // Auto-scroll on resize if we were at bottom
125
- if (this.wasAtBottom && !state.isResizing) {
126
- this.scrollToBottom(this.resizeBehavior);
127
- }
128
- });
129
-
130
- // Monitor container resize
131
- const element = this.elementRef.nativeElement;
132
- this.resizeService.observeElement(element, 0, 250)
133
- .pipe(
134
- takeUntil(this.destroy$),
135
- filter(() => this.enabled && !this.userHasScrolled && this.wasAtBottom)
136
- )
137
- .subscribe(() => {
138
- // Adjust scroll on container resize
139
- this.scrollToBottom(this.resizeBehavior);
140
- });
141
- }
142
-
143
- private setupContentMutationObserver(): void {
144
- if (!this.enabled || !this.contentElement) return;
145
-
146
- const mutationObserver = new MutationObserver(() => {
147
- if (this.enabled && this.wasAtBottom && !this.userHasScrolled) {
148
- // Content changed, scroll to bottom if we were there
149
- requestAnimationFrame(() => {
150
- this.scrollToBottom(this.resizeBehavior);
151
- });
152
- }
153
- });
154
-
155
- mutationObserver.observe(this.contentElement, {
156
- childList: true,
157
- subtree: true,
158
- characterData: true
159
- });
160
-
161
- // Cleanup on destroy
162
- this.destroy$.subscribe(() => {
163
- mutationObserver.disconnect();
164
- });
165
- }
166
-
167
- /**
168
- * Public method to scroll to bottom
169
- * Can be called from parent component
170
- */
171
- public scrollToBottom(behavior: ScrollBehavior = 'smooth'): void {
172
- const element = this.elementRef.nativeElement;
173
- const smooth = behavior === 'smooth';
174
-
175
- this.scrollService.scrollToBottom(element, smooth);
176
- this.userHasScrolled = false;
177
- this.scrollToBottomRequested.emit();
178
- }
179
-
180
- /**
181
- * Check if currently at bottom
182
- */
183
- public isAtBottom(): boolean {
184
- return this.scrollService.isAtBottom(this.elementRef.nativeElement, this.threshold);
185
- }
186
-
187
- /**
188
- * Get current scroll state
189
- */
190
- public getScrollState() {
191
- const element = this.elementRef.nativeElement;
192
- return {
193
- scrollTop: element.scrollTop,
194
- scrollHeight: element.scrollHeight,
195
- clientHeight: element.clientHeight,
196
- isAtBottom: this.isAtBottom()
197
- };
198
- }
199
-
200
- ngOnDestroy(): void {
201
- this.destroy$.next();
202
- this.destroy$.complete();
203
- }
204
- }
package/src/index.ts DELETED
@@ -1,105 +0,0 @@
1
- export * from "./core/copilotkit.service";
2
- export * from "./core/copilotkit.types";
3
- export * from "./core/copilotkit.providers";
4
- // Re-export types from @ag-ui/core for convenience
5
- export type { Message, ToolCall, ToolMessage } from "@ag-ui/core";
6
- export * from "./core/chat-configuration/chat-configuration.types";
7
- export * from "./core/chat-configuration/chat-configuration.service";
8
- export * from "./core/chat-configuration/chat-configuration.providers";
9
- export * from "./utils/copilotkit.utils";
10
- export * from "./utils/agent-context.utils";
11
- export * from "./utils/frontend-tool.utils";
12
- // Note: tool-render.utils removed in favor of direct ToolCallRender<T> usage
13
- // Export all except AgentWatchResult which is already exported from copilotkit.types
14
- export {
15
- watchAgent,
16
- getAgent,
17
- subscribeToAgent,
18
- registerAgentWatcher,
19
- } from "./utils/agent.utils";
20
- export * from "./utils/human-in-the-loop.utils";
21
- export * from "./utils/chat-config.utils";
22
- // Slot utilities are internal only, not exported
23
- // export * from "./lib/slots/slot.types";
24
- // export * from "./lib/slots/slot.utils";
25
- // export { CopilotSlotComponent } from "./lib/slots/copilot-slot.component";
26
- export { CopilotTooltipDirective } from "./lib/directives/tooltip.directive";
27
- export { CopilotKitConfigDirective } from "./directives/copilotkit-config.directive";
28
- export { CopilotKitAgentContextDirective } from "./directives/copilotkit-agent-context.directive";
29
- export { CopilotKitFrontendToolDirective } from "./directives/copilotkit-frontend-tool.directive";
30
- export { CopilotKitAgentDirective } from "./directives/copilotkit-agent.directive";
31
- export {
32
- CopilotKitHumanInTheLoopDirective,
33
- CopilotKitHumanInTheLoopRespondDirective,
34
- } from "./directives/copilotkit-human-in-the-loop.directive";
35
- export { CopilotKitChatConfigDirective } from "./directives/copilotkit-chat-config.directive";
36
- export { CopilotKitToolRenderComponent } from "./components/copilotkit-tool-render.component";
37
-
38
- // Chat Input Components
39
- export * from "./components/chat/copilot-chat-input.types";
40
- export { CopilotChatInputComponent } from "./components/chat/copilot-chat-input.component";
41
- export { CopilotChatInputDefaults } from "./components/chat/copilot-chat-input-defaults";
42
- export { CopilotChatTextareaComponent } from "./components/chat/copilot-chat-textarea.component";
43
- export { CopilotChatAudioRecorderComponent } from "./components/chat/copilot-chat-audio-recorder.component";
44
- export {
45
- CopilotChatSendButtonComponent,
46
- CopilotChatToolbarButtonComponent,
47
- CopilotChatStartTranscribeButtonComponent,
48
- CopilotChatCancelTranscribeButtonComponent,
49
- CopilotChatFinishTranscribeButtonComponent,
50
- CopilotChatAddFileButtonComponent,
51
- } from "./components/chat/copilot-chat-buttons.component";
52
- export { CopilotChatToolbarComponent } from "./components/chat/copilot-chat-toolbar.component";
53
- export { CopilotChatToolsMenuComponent } from "./components/chat/copilot-chat-tools-menu.component";
54
-
55
- // Chat User Message Components
56
- export * from "./components/chat/copilot-chat-user-message.types";
57
- export { CopilotChatUserMessageComponent } from "./components/chat/copilot-chat-user-message.component";
58
- export { CopilotChatUserMessageRendererComponent } from "./components/chat/copilot-chat-user-message-renderer.component";
59
- export {
60
- CopilotChatUserMessageToolbarButtonComponent,
61
- CopilotChatUserMessageCopyButtonComponent,
62
- CopilotChatUserMessageEditButtonComponent,
63
- } from "./components/chat/copilot-chat-user-message-buttons.component";
64
- export { CopilotChatUserMessageToolbarComponent } from "./components/chat/copilot-chat-user-message-toolbar.component";
65
- export { CopilotChatUserMessageBranchNavigationComponent } from "./components/chat/copilot-chat-user-message-branch-navigation.component";
66
-
67
- // Chat Assistant Message Components
68
- export * from "./components/chat/copilot-chat-assistant-message.types";
69
- export { CopilotChatAssistantMessageComponent } from "./components/chat/copilot-chat-assistant-message.component";
70
- export { CopilotChatAssistantMessageRendererComponent } from "./components/chat/copilot-chat-assistant-message-renderer.component";
71
- export {
72
- CopilotChatAssistantMessageToolbarButtonComponent,
73
- CopilotChatAssistantMessageCopyButtonComponent,
74
- CopilotChatAssistantMessageThumbsUpButtonComponent,
75
- CopilotChatAssistantMessageThumbsDownButtonComponent,
76
- CopilotChatAssistantMessageReadAloudButtonComponent,
77
- CopilotChatAssistantMessageRegenerateButtonComponent,
78
- } from "./components/chat/copilot-chat-assistant-message-buttons.component";
79
- export { CopilotChatAssistantMessageToolbarComponent } from "./components/chat/copilot-chat-assistant-message-toolbar.component";
80
-
81
- // Chat Message View Components
82
- export * from "./components/chat/copilot-chat-message-view.types";
83
- export { CopilotChatMessageViewComponent } from "./components/chat/copilot-chat-message-view.component";
84
- export { CopilotChatMessageViewCursorComponent } from "./components/chat/copilot-chat-message-view-cursor.component";
85
- export { CopilotChatToolCallsViewComponent } from "./components/chat/copilot-chat-tool-calls-view.component";
86
-
87
- // Chat View Components
88
- export * from "./components/chat/copilot-chat-view.types";
89
- export { CopilotChatViewComponent } from "./components/chat/copilot-chat-view.component";
90
- export { CopilotChatViewScrollViewComponent } from "./components/chat/copilot-chat-view-scroll-view.component";
91
- export { CopilotChatViewScrollToBottomButtonComponent } from "./components/chat/copilot-chat-view-scroll-to-bottom-button.component";
92
- export { CopilotChatViewFeatherComponent } from "./components/chat/copilot-chat-view-feather.component";
93
- export { CopilotChatViewInputContainerComponent } from "./components/chat/copilot-chat-view-input-container.component";
94
- export { CopilotChatViewDisclaimerComponent } from "./components/chat/copilot-chat-view-disclaimer.component";
95
-
96
- // Main Chat Component
97
- export { CopilotChatComponent } from "./components/chat/copilot-chat.component";
98
-
99
- // Services and Directives for Chat View
100
- export { ScrollPositionService } from "./services/scroll-position.service";
101
- export { ResizeObserverService } from "./services/resize-observer.service";
102
- export { StickToBottomDirective } from "./directives/stick-to-bottom.directive";
103
-
104
- // Testing utilities are not exported from the main entry point
105
- // They should be imported directly from '@copilotkitnext/angular/testing' if needed