@copilotkitnext/angular 0.0.2 → 0.0.4

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 (168) 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/esm2022/components/chat/copilot-chat-assistant-message-buttons.component.mjs +384 -0
  7. package/dist/esm2022/components/chat/copilot-chat-assistant-message-renderer.component.mjs +286 -0
  8. package/dist/esm2022/components/chat/copilot-chat-assistant-message-toolbar.component.mjs +27 -0
  9. package/dist/esm2022/components/chat/copilot-chat-assistant-message.component.mjs +433 -0
  10. package/dist/esm2022/components/chat/copilot-chat-assistant-message.types.mjs +2 -0
  11. package/dist/esm2022/components/chat/copilot-chat-audio-recorder.component.mjs +202 -0
  12. package/dist/esm2022/components/chat/copilot-chat-buttons.component.mjs +321 -0
  13. package/dist/esm2022/components/chat/copilot-chat-input-defaults.mjs +38 -0
  14. package/dist/esm2022/components/chat/copilot-chat-input.component.mjs +666 -0
  15. package/dist/esm2022/components/chat/copilot-chat-input.types.mjs +10 -0
  16. package/dist/esm2022/components/chat/copilot-chat-message-view-cursor.component.mjs +45 -0
  17. package/dist/esm2022/components/chat/copilot-chat-message-view.component.mjs +296 -0
  18. package/dist/esm2022/components/chat/copilot-chat-message-view.types.mjs +2 -0
  19. package/dist/esm2022/components/chat/copilot-chat-textarea.component.mjs +188 -0
  20. package/dist/esm2022/components/chat/copilot-chat-tool-calls-view.component.mjs +216 -0
  21. package/dist/esm2022/components/chat/copilot-chat-toolbar.component.mjs +25 -0
  22. package/dist/esm2022/components/chat/copilot-chat-tools-menu.component.mjs +199 -0
  23. package/dist/esm2022/components/chat/copilot-chat-user-message-branch-navigation.component.mjs +137 -0
  24. package/dist/esm2022/components/chat/copilot-chat-user-message-buttons.component.mjs +207 -0
  25. package/dist/esm2022/components/chat/copilot-chat-user-message-renderer.component.mjs +35 -0
  26. package/dist/esm2022/components/chat/copilot-chat-user-message-toolbar.component.mjs +34 -0
  27. package/dist/esm2022/components/chat/copilot-chat-user-message.component.mjs +341 -0
  28. package/dist/esm2022/components/chat/copilot-chat-user-message.types.mjs +2 -0
  29. package/dist/esm2022/components/chat/copilot-chat-view-disclaimer.component.mjs +52 -0
  30. package/dist/esm2022/components/chat/copilot-chat-view-feather.component.mjs +55 -0
  31. package/dist/esm2022/components/chat/copilot-chat-view-handlers.service.mjs +19 -0
  32. package/dist/esm2022/components/chat/copilot-chat-view-input-container.component.mjs +110 -0
  33. package/dist/esm2022/components/chat/copilot-chat-view-scroll-to-bottom-button.component.mjs +93 -0
  34. package/dist/esm2022/components/chat/copilot-chat-view-scroll-view.component.mjs +443 -0
  35. package/dist/esm2022/components/chat/copilot-chat-view.component.mjs +479 -0
  36. package/dist/esm2022/components/chat/copilot-chat-view.types.mjs +2 -0
  37. package/dist/esm2022/components/chat/copilot-chat.component.mjs +214 -0
  38. package/dist/esm2022/components/copilotkit-tool-render.component.mjs +153 -0
  39. package/dist/esm2022/copilotkitnext-angular.mjs +5 -0
  40. package/dist/esm2022/core/chat-configuration/chat-configuration.providers.mjs +65 -0
  41. package/dist/esm2022/core/chat-configuration/chat-configuration.service.mjs +145 -0
  42. package/dist/esm2022/core/chat-configuration/chat-configuration.types.mjs +26 -0
  43. package/dist/esm2022/core/copilotkit.providers.mjs +34 -0
  44. package/dist/esm2022/core/copilotkit.service.mjs +430 -0
  45. package/dist/esm2022/core/copilotkit.types.mjs +12 -0
  46. package/dist/esm2022/directives/copilotkit-agent-context.directive.mjs +130 -0
  47. package/dist/esm2022/directives/copilotkit-agent.directive.mjs +217 -0
  48. package/dist/esm2022/directives/copilotkit-chat-config.directive.mjs +218 -0
  49. package/dist/esm2022/directives/copilotkit-config.directive.mjs +94 -0
  50. package/dist/esm2022/directives/copilotkit-frontend-tool.directive.mjs +130 -0
  51. package/dist/esm2022/directives/copilotkit-human-in-the-loop.directive.mjs +266 -0
  52. package/dist/esm2022/directives/stick-to-bottom.directive.mjs +181 -0
  53. package/dist/esm2022/index.mjs +70 -0
  54. package/dist/esm2022/lib/directives/tooltip.directive.mjs +211 -0
  55. package/dist/esm2022/lib/slots/copilot-slot.component.mjs +144 -0
  56. package/dist/esm2022/lib/slots/slot.types.mjs +6 -0
  57. package/dist/esm2022/lib/slots/slot.utils.mjs +222 -0
  58. package/dist/esm2022/lib/utils.mjs +10 -0
  59. package/dist/esm2022/services/resize-observer.service.mjs +152 -0
  60. package/dist/esm2022/services/scroll-position.service.mjs +124 -0
  61. package/dist/esm2022/types/frontend-tool.mjs +2 -0
  62. package/dist/esm2022/types/human-in-the-loop.mjs +2 -0
  63. package/dist/esm2022/utils/agent-context.utils.mjs +114 -0
  64. package/dist/esm2022/utils/agent.utils.mjs +204 -0
  65. package/dist/esm2022/utils/chat-config.utils.mjs +186 -0
  66. package/dist/esm2022/utils/copilotkit.utils.mjs +20 -0
  67. package/dist/esm2022/utils/frontend-tool.utils.mjs +228 -0
  68. package/dist/esm2022/utils/human-in-the-loop.utils.mjs +296 -0
  69. package/dist/fesm2022/copilotkitnext-angular.mjs +163 -164
  70. package/dist/fesm2022/copilotkitnext-angular.mjs.map +1 -1
  71. package/package.json +21 -18
  72. package/vitest.config.mts +32 -21
  73. package/.turbo/turbo-build.log +0 -38
  74. package/.turbo/turbo-check-types.log +0 -0
  75. package/.turbo/turbo-test.log +0 -71
  76. package/ng-package.json +0 -19
  77. package/src/components/chat/__tests__/copilot-chat-assistant-message.component.spec.ts +0 -282
  78. package/src/components/chat/__tests__/copilot-chat-input.component.spec.ts +0 -419
  79. package/src/components/chat/__tests__/copilot-chat-message-view.component.spec.ts +0 -372
  80. package/src/components/chat/__tests__/copilot-chat-user-message.component.spec.ts +0 -249
  81. package/src/components/chat/copilot-chat-assistant-message-buttons.component.ts +0 -292
  82. package/src/components/chat/copilot-chat-assistant-message-renderer.component.ts +0 -472
  83. package/src/components/chat/copilot-chat-assistant-message-toolbar.component.ts +0 -29
  84. package/src/components/chat/copilot-chat-assistant-message.component.ts +0 -463
  85. package/src/components/chat/copilot-chat-assistant-message.types.ts +0 -50
  86. package/src/components/chat/copilot-chat-audio-recorder.component.ts +0 -241
  87. package/src/components/chat/copilot-chat-buttons.component.ts +0 -308
  88. package/src/components/chat/copilot-chat-buttons.component.ts.bak +0 -471
  89. package/src/components/chat/copilot-chat-input-defaults.ts +0 -47
  90. package/src/components/chat/copilot-chat-input.component.ts +0 -512
  91. package/src/components/chat/copilot-chat-input.types.ts +0 -148
  92. package/src/components/chat/copilot-chat-message-view-cursor.component.ts +0 -51
  93. package/src/components/chat/copilot-chat-message-view.component.ts +0 -233
  94. package/src/components/chat/copilot-chat-message-view.types.ts +0 -39
  95. package/src/components/chat/copilot-chat-textarea.component.ts +0 -220
  96. package/src/components/chat/copilot-chat-tool-calls-view.component.ts +0 -261
  97. package/src/components/chat/copilot-chat-toolbar.component.ts +0 -35
  98. package/src/components/chat/copilot-chat-tools-menu.component.ts +0 -185
  99. package/src/components/chat/copilot-chat-user-message-branch-navigation.component.ts +0 -121
  100. package/src/components/chat/copilot-chat-user-message-buttons.component.ts +0 -170
  101. package/src/components/chat/copilot-chat-user-message-renderer.component.ts +0 -37
  102. package/src/components/chat/copilot-chat-user-message-toolbar.component.ts +0 -37
  103. package/src/components/chat/copilot-chat-user-message.component.ts +0 -247
  104. package/src/components/chat/copilot-chat-user-message.types.ts +0 -42
  105. package/src/components/chat/copilot-chat-view-disclaimer.component.ts +0 -51
  106. package/src/components/chat/copilot-chat-view-feather.component.ts +0 -47
  107. package/src/components/chat/copilot-chat-view-handlers.service.ts +0 -14
  108. package/src/components/chat/copilot-chat-view-input-container.component.ts +0 -87
  109. package/src/components/chat/copilot-chat-view-scroll-to-bottom-button.component.ts +0 -79
  110. package/src/components/chat/copilot-chat-view-scroll-view.component.ts +0 -322
  111. package/src/components/chat/copilot-chat-view.component.ts +0 -420
  112. package/src/components/chat/copilot-chat-view.types.ts +0 -52
  113. package/src/components/chat/copilot-chat.component.ts +0 -232
  114. package/src/components/copilotkit-tool-render.component.ts +0 -169
  115. package/src/core/__tests__/copilotkit.service.spec.ts +0 -1051
  116. package/src/core/__tests__/copilotkit.service.wildcard.spec.ts +0 -316
  117. package/src/core/chat-configuration/__tests__/chat-configuration.service.spec.ts +0 -287
  118. package/src/core/chat-configuration/chat-configuration.providers.ts +0 -71
  119. package/src/core/chat-configuration/chat-configuration.service.ts +0 -162
  120. package/src/core/chat-configuration/chat-configuration.types.ts +0 -57
  121. package/src/core/copilotkit.providers.ts +0 -59
  122. package/src/core/copilotkit.service.ts +0 -542
  123. package/src/core/copilotkit.types.ts +0 -132
  124. package/src/directives/__tests__/copilotkit-agent-context.directive.spec.ts +0 -384
  125. package/src/directives/__tests__/copilotkit-agent.directive.spec.ts +0 -253
  126. package/src/directives/__tests__/copilotkit-chat-config.directive.spec.ts +0 -385
  127. package/src/directives/__tests__/copilotkit-config.directive.spec.ts +0 -69
  128. package/src/directives/__tests__/copilotkit-frontend-tool-simple.directive.spec.ts +0 -60
  129. package/src/directives/__tests__/copilotkit-frontend-tool.directive.spec.ts +0 -108
  130. package/src/directives/__tests__/copilotkit-human-in-the-loop.directive.spec.ts +0 -452
  131. package/src/directives/copilotkit-agent-context.directive.ts +0 -138
  132. package/src/directives/copilotkit-agent.directive.ts +0 -225
  133. package/src/directives/copilotkit-chat-config.directive.ts +0 -241
  134. package/src/directives/copilotkit-config.directive.ts +0 -81
  135. package/src/directives/copilotkit-frontend-tool.directive.ts +0 -145
  136. package/src/directives/copilotkit-human-in-the-loop.directive.ts +0 -281
  137. package/src/directives/stick-to-bottom.directive.ts +0 -204
  138. package/src/index.ts +0 -105
  139. package/src/lib/directives/tooltip.directive.ts +0 -292
  140. package/src/lib/slots/__tests__/slot.utils.spec.ts +0 -377
  141. package/src/lib/slots/copilot-slot.component.ts +0 -135
  142. package/src/lib/slots/index.ts +0 -3
  143. package/src/lib/slots/slot.types.ts +0 -64
  144. package/src/lib/slots/slot.utils.ts +0 -289
  145. package/src/lib/utils.ts +0 -10
  146. package/src/public-api.ts +0 -1
  147. package/src/services/resize-observer.service.ts +0 -181
  148. package/src/services/scroll-position.service.ts +0 -169
  149. package/src/styles/globals.css +0 -266
  150. package/src/styles/index.css +0 -3
  151. package/src/test-setup.ts +0 -15
  152. package/src/testing/index.ts +0 -3
  153. package/src/testing/testing.utils.ts +0 -248
  154. package/src/types/frontend-tool.ts +0 -44
  155. package/src/types/human-in-the-loop.ts +0 -52
  156. package/src/utils/__tests__/agent.utils.spec.ts +0 -234
  157. package/src/utils/__tests__/chat-config.utils.spec.ts +0 -306
  158. package/src/utils/__tests__/frontend-tool-inject.spec.ts +0 -350
  159. package/src/utils/__tests__/frontend-tool-integration.spec.ts +0 -199
  160. package/src/utils/__tests__/frontend-tool.utils.spec.ts +0 -272
  161. package/src/utils/__tests__/human-in-the-loop.utils.spec.ts +0 -365
  162. package/src/utils/agent-context.utils.ts +0 -133
  163. package/src/utils/agent.utils.ts +0 -239
  164. package/src/utils/chat-config.utils.ts +0 -221
  165. package/src/utils/copilotkit.utils.ts +0 -20
  166. package/src/utils/frontend-tool.utils.ts +0 -266
  167. package/src/utils/human-in-the-loop.utils.ts +0 -359
  168. package/tsconfig.spec.json +0 -12
@@ -1,385 +0,0 @@
1
- import { Component } from "@angular/core";
2
- import { TestBed } from "@angular/core/testing";
3
- import { describe, it, expect, beforeEach, vi } from "vitest";
4
- import { CopilotKitChatConfigDirective } from "../copilotkit-chat-config.directive";
5
- import { CopilotChatConfigurationService } from "../../core/chat-configuration/chat-configuration.service";
6
- import { provideCopilotChatConfiguration } from "../../core/chat-configuration/chat-configuration.providers";
7
- import { By } from "@angular/platform-browser";
8
-
9
- describe("CopilotKitChatConfigDirective", () => {
10
- describe("Basic Usage", () => {
11
- let service: CopilotChatConfigurationService;
12
-
13
- beforeEach(() => {
14
- TestBed.configureTestingModule({
15
- providers: provideCopilotChatConfiguration(),
16
- imports: [CopilotKitChatConfigDirective],
17
- });
18
-
19
- service = TestBed.inject(CopilotChatConfigurationService);
20
- });
21
-
22
- it("should create directive and update service", () => {
23
- @Component({
24
- template: `
25
- <div
26
- copilotkitChatConfig
27
- [labels]="labels"
28
- [inputValue]="inputValue"
29
- ></div>
30
- `,
31
- standalone: true,
32
- imports: [CopilotKitChatConfigDirective],
33
- })
34
- class TestComponent {
35
- labels = { chatInputPlaceholder: "Test placeholder" };
36
- inputValue = "test value";
37
- }
38
-
39
- const fixture = TestBed.createComponent(TestComponent);
40
- fixture.detectChanges();
41
-
42
- expect(service.labels().chatInputPlaceholder).toBe("Test placeholder");
43
- expect(service.inputValue()).toBe("test value");
44
- });
45
-
46
- it("should support configuration object input", () => {
47
- @Component({
48
- template: ` <div [copilotkitChatConfig]="config"></div> `,
49
- standalone: true,
50
- imports: [CopilotKitChatConfigDirective],
51
- })
52
- class TestComponent {
53
- config = {
54
- labels: { chatInputPlaceholder: "Config placeholder" },
55
- inputValue: "config value",
56
- };
57
- }
58
-
59
- const fixture = TestBed.createComponent(TestComponent);
60
- fixture.detectChanges();
61
-
62
- expect(service.labels().chatInputPlaceholder).toBe("Config placeholder");
63
- expect(service.inputValue()).toBe("config value");
64
- });
65
-
66
- it("should handle missing service gracefully", () => {
67
- // Create a component without providing the service
68
- TestBed.resetTestingModule();
69
- TestBed.configureTestingModule({
70
- imports: [CopilotKitChatConfigDirective],
71
- });
72
-
73
- @Component({
74
- template: ` <div copilotkitChatConfig [labels]="{}"></div> `,
75
- standalone: true,
76
- imports: [CopilotKitChatConfigDirective],
77
- })
78
- class TestComponent {}
79
-
80
- const consoleSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
81
-
82
- expect(() => {
83
- const fixture = TestBed.createComponent(TestComponent);
84
- fixture.detectChanges();
85
- }).not.toThrow();
86
-
87
- expect(consoleSpy).toHaveBeenCalledWith(
88
- expect.stringContaining("No CopilotChatConfigurationService found")
89
- );
90
-
91
- consoleSpy.mockRestore();
92
- });
93
- });
94
-
95
- describe("Event Emissions", () => {
96
- let service: CopilotChatConfigurationService;
97
-
98
- beforeEach(() => {
99
- TestBed.configureTestingModule({
100
- providers: provideCopilotChatConfiguration(),
101
- imports: [CopilotKitChatConfigDirective],
102
- });
103
-
104
- service = TestBed.inject(CopilotChatConfigurationService);
105
- });
106
-
107
- it("should emit submitInput event", () => {
108
- let submittedValue: string | undefined;
109
-
110
- @Component({
111
- template: `
112
- <div copilotkitChatConfig (submitInput)="onSubmit($event)"></div>
113
- `,
114
- standalone: true,
115
- imports: [CopilotKitChatConfigDirective],
116
- })
117
- class TestComponent {
118
- onSubmit(value: string) {
119
- submittedValue = value;
120
- }
121
- }
122
-
123
- const fixture = TestBed.createComponent(TestComponent);
124
- fixture.detectChanges();
125
-
126
- const directiveEl = fixture.debugElement.query(
127
- By.directive(CopilotKitChatConfigDirective)
128
- );
129
- const directive = directiveEl.injector.get(CopilotKitChatConfigDirective);
130
-
131
- directive.submit("test message");
132
-
133
- expect(submittedValue).toBe("test message");
134
- });
135
-
136
- it("should emit changeInput event", () => {
137
- let changedValue: string | undefined;
138
-
139
- @Component({
140
- template: `
141
- <div copilotkitChatConfig (changeInput)="onChange($event)"></div>
142
- `,
143
- standalone: true,
144
- imports: [CopilotKitChatConfigDirective],
145
- })
146
- class TestComponent {
147
- onChange(value: string) {
148
- changedValue = value;
149
- }
150
- }
151
-
152
- const fixture = TestBed.createComponent(TestComponent);
153
- fixture.detectChanges();
154
-
155
- const directiveEl = fixture.debugElement.query(
156
- By.directive(CopilotKitChatConfigDirective)
157
- );
158
- const directive = directiveEl.injector.get(CopilotKitChatConfigDirective);
159
-
160
- directive.change("typing...");
161
-
162
- expect(changedValue).toBe("typing...");
163
- });
164
- });
165
-
166
- describe("Two-Way Binding", () => {
167
- let service: CopilotChatConfigurationService;
168
-
169
- beforeEach(() => {
170
- TestBed.configureTestingModule({
171
- providers: provideCopilotChatConfiguration(),
172
- imports: [CopilotKitChatConfigDirective],
173
- });
174
-
175
- service = TestBed.inject(CopilotChatConfigurationService);
176
- });
177
-
178
- it("should support two-way binding for value", () => {
179
- @Component({
180
- template: ` <div copilotkitChatConfig [(value)]="inputText"></div> `,
181
- standalone: true,
182
- imports: [CopilotKitChatConfigDirective],
183
- })
184
- class TestComponent {
185
- inputText = "initial";
186
- }
187
-
188
- const fixture = TestBed.createComponent(TestComponent);
189
- fixture.detectChanges();
190
-
191
- const directiveEl = fixture.debugElement.query(
192
- By.directive(CopilotKitChatConfigDirective)
193
- );
194
- const directive = directiveEl.injector.get(CopilotKitChatConfigDirective);
195
-
196
- // Setting value on directive should update component
197
- directive.value = "updated";
198
- expect(directive.value).toBe("updated");
199
-
200
- // Changing value through directive method
201
- directive.change("changed");
202
- fixture.detectChanges();
203
-
204
- expect(directive.value).toBe("changed");
205
- });
206
- });
207
-
208
- describe("Dynamic Updates", () => {
209
- let service: CopilotChatConfigurationService;
210
-
211
- beforeEach(() => {
212
- TestBed.configureTestingModule({
213
- providers: provideCopilotChatConfiguration(),
214
- imports: [CopilotKitChatConfigDirective],
215
- });
216
-
217
- service = TestBed.inject(CopilotChatConfigurationService);
218
- });
219
-
220
- it("should update configuration when inputs change", () => {
221
- @Component({
222
- template: `
223
- <div
224
- copilotkitChatConfig
225
- [labels]="labels"
226
- [inputValue]="inputValue"
227
- ></div>
228
- `,
229
- standalone: true,
230
- imports: [CopilotKitChatConfigDirective],
231
- })
232
- class TestComponent {
233
- labels = { chatInputPlaceholder: "Initial" };
234
- inputValue = "initial value";
235
- }
236
-
237
- const fixture = TestBed.createComponent(TestComponent);
238
- fixture.detectChanges();
239
-
240
- expect(service.labels().chatInputPlaceholder).toBe("Initial");
241
-
242
- // Update labels
243
- fixture.componentInstance.labels = { chatInputPlaceholder: "Updated" };
244
- fixture.detectChanges();
245
-
246
- expect(service.labels().chatInputPlaceholder).toBe("Updated");
247
-
248
- // Update input value
249
- fixture.componentInstance.inputValue = "updated value";
250
- fixture.detectChanges();
251
-
252
- expect(service.inputValue()).toBe("updated value");
253
- });
254
- });
255
-
256
- describe("Handler Integration", () => {
257
- let service: CopilotChatConfigurationService;
258
-
259
- beforeEach(() => {
260
- TestBed.configureTestingModule({
261
- providers: provideCopilotChatConfiguration(),
262
- imports: [CopilotKitChatConfigDirective],
263
- });
264
-
265
- service = TestBed.inject(CopilotChatConfigurationService);
266
- });
267
-
268
- it("should integrate handlers from config object", () => {
269
- const submitHandler = vi.fn();
270
- const changeHandler = vi.fn();
271
-
272
- @Component({
273
- template: ` <div [copilotkitChatConfig]="config"></div> `,
274
- standalone: true,
275
- imports: [CopilotKitChatConfigDirective],
276
- })
277
- class TestComponent {
278
- config = {
279
- onSubmitInput: submitHandler,
280
- onChangeInput: changeHandler,
281
- };
282
- }
283
-
284
- const fixture = TestBed.createComponent(TestComponent);
285
- fixture.detectChanges();
286
-
287
- const directiveEl = fixture.debugElement.query(
288
- By.directive(CopilotKitChatConfigDirective)
289
- );
290
- const directive = directiveEl.injector.get(CopilotKitChatConfigDirective);
291
-
292
- // Submit should call the handler
293
- directive.submit("test submit");
294
- expect(submitHandler).toHaveBeenCalledWith("test submit");
295
-
296
- // Change should call the handler
297
- directive.change("test change");
298
- expect(changeHandler).toHaveBeenCalledWith("test change");
299
- });
300
-
301
- it("should call both directive and service handlers", () => {
302
- const directiveSubmitHandler = vi.fn();
303
- const serviceSubmitHandler = vi.fn();
304
-
305
- @Component({
306
- template: `
307
- <div copilotkitChatConfig (submitInput)="onSubmit($event)"></div>
308
- `,
309
- standalone: true,
310
- imports: [CopilotKitChatConfigDirective],
311
- })
312
- class TestComponent {
313
- onSubmit = directiveSubmitHandler;
314
- }
315
-
316
- const fixture = TestBed.createComponent(TestComponent);
317
- fixture.detectChanges();
318
-
319
- // Also set a handler on the service
320
- service.setSubmitHandler(serviceSubmitHandler);
321
-
322
- const directiveEl = fixture.debugElement.query(
323
- By.directive(CopilotKitChatConfigDirective)
324
- );
325
- const directive = directiveEl.injector.get(CopilotKitChatConfigDirective);
326
-
327
- directive.submit("test");
328
-
329
- // Both handlers should be called
330
- expect(directiveSubmitHandler).toHaveBeenCalledWith("test");
331
- // Note: The directive overrides the service handler, so it's part of the composite
332
- });
333
- });
334
-
335
- describe("Public Methods", () => {
336
- let service: CopilotChatConfigurationService;
337
-
338
- beforeEach(() => {
339
- TestBed.configureTestingModule({
340
- providers: provideCopilotChatConfiguration(),
341
- imports: [CopilotKitChatConfigDirective],
342
- });
343
-
344
- service = TestBed.inject(CopilotChatConfigurationService);
345
- });
346
-
347
- it("should expose submit method", () => {
348
- @Component({
349
- template: ` <div copilotkitChatConfig></div> `,
350
- standalone: true,
351
- imports: [CopilotKitChatConfigDirective],
352
- })
353
- class TestComponent {}
354
-
355
- const fixture = TestBed.createComponent(TestComponent);
356
- fixture.detectChanges();
357
-
358
- const directiveEl = fixture.debugElement.query(
359
- By.directive(CopilotKitChatConfigDirective)
360
- );
361
- const directive = directiveEl.injector.get(CopilotKitChatConfigDirective);
362
-
363
- expect(typeof directive.submit).toBe("function");
364
- });
365
-
366
- it("should expose change method", () => {
367
- @Component({
368
- template: ` <div copilotkitChatConfig></div> `,
369
- standalone: true,
370
- imports: [CopilotKitChatConfigDirective],
371
- })
372
- class TestComponent {}
373
-
374
- const fixture = TestBed.createComponent(TestComponent);
375
- fixture.detectChanges();
376
-
377
- const directiveEl = fixture.debugElement.query(
378
- By.directive(CopilotKitChatConfigDirective)
379
- );
380
- const directive = directiveEl.injector.get(CopilotKitChatConfigDirective);
381
-
382
- expect(typeof directive.change).toBe("function");
383
- });
384
- });
385
- });
@@ -1,69 +0,0 @@
1
- import { Component } from "@angular/core";
2
- import { TestBed } from "@angular/core/testing";
3
- import { describe, it, expect, beforeEach, vi } from "vitest";
4
- import { CopilotKitConfigDirective } from "../copilotkit-config.directive";
5
- import { CopilotKitService } from "../../core/copilotkit.service";
6
- import { provideCopilotKit } from "../../core/copilotkit.providers";
7
-
8
- // Mock CopilotKitCore to prevent network calls
9
- vi.mock("@copilotkitnext/core", () => ({
10
- CopilotKitCore: vi.fn().mockImplementation(() => ({
11
- setRuntimeUrl: vi.fn(),
12
- setHeaders: vi.fn(),
13
- setProperties: vi.fn(),
14
- setAgents: vi.fn(),
15
- subscribe: vi.fn(() => () => {}), // Return unsubscribe function
16
- })),
17
- }));
18
-
19
- @Component({
20
- template: ` <div [copilotkitConfig]="config"></div> `,
21
- standalone: true,
22
- imports: [CopilotKitConfigDirective],
23
- })
24
- class TestComponent {
25
- config = {
26
- runtimeUrl: "https://api.test.com",
27
- headers: { "X-Test": "value" },
28
- };
29
- }
30
-
31
- describe("CopilotKitConfigDirective", () => {
32
- let service: CopilotKitService;
33
-
34
- beforeEach(async () => {
35
- await TestBed.configureTestingModule({
36
- imports: [TestComponent, CopilotKitConfigDirective],
37
- providers: [provideCopilotKit({})],
38
- }).compileComponents();
39
-
40
- service = TestBed.inject(CopilotKitService);
41
- });
42
-
43
- it("should update service when config changes", () => {
44
- const setRuntimeUrlSpy = vi.spyOn(service, "setRuntimeUrl");
45
- const setHeadersSpy = vi.spyOn(service, "setHeaders");
46
-
47
- const fixture = TestBed.createComponent(TestComponent);
48
- fixture.detectChanges();
49
-
50
- expect(setRuntimeUrlSpy).toHaveBeenCalledWith("https://api.test.com");
51
- expect(setHeadersSpy).toHaveBeenCalledWith({ "X-Test": "value" });
52
- });
53
-
54
- it("should handle config updates", () => {
55
- const fixture = TestBed.createComponent(TestComponent);
56
- fixture.detectChanges();
57
-
58
- const setRuntimeUrlSpy = vi.spyOn(service, "setRuntimeUrl");
59
-
60
- // Update config
61
- fixture.componentInstance.config = {
62
- runtimeUrl: "https://api.updated.com",
63
- headers: { "X-Test": "updated" },
64
- };
65
- fixture.detectChanges();
66
-
67
- expect(setRuntimeUrlSpy).toHaveBeenCalledWith("https://api.updated.com");
68
- });
69
- });
@@ -1,60 +0,0 @@
1
- import { Component } from "@angular/core";
2
- import { TestBed } from "@angular/core/testing";
3
- import { describe, it, expect, beforeEach, vi, afterEach } from "vitest";
4
- import { CopilotKitFrontendToolDirective } from "../copilotkit-frontend-tool.directive";
5
- import { CopilotKitService } from "../../core/copilotkit.service";
6
- import { provideCopilotKit } from "../../core/copilotkit.providers";
7
- import { z } from "zod";
8
-
9
- // Mock CopilotKitCore
10
- vi.mock("@copilotkitnext/core", () => ({
11
- CopilotKitCore: vi.fn().mockImplementation(() => ({
12
- addTool: vi.fn(),
13
- removeTool: vi.fn(),
14
- setRuntimeUrl: vi.fn(),
15
- setHeaders: vi.fn(),
16
- setProperties: vi.fn(),
17
- setAgents: vi.fn(),
18
- subscribe: vi.fn(() => () => {}),
19
- })),
20
- }));
21
-
22
- describe("CopilotKitFrontendToolDirective - Simple", () => {
23
- let service: CopilotKitService;
24
-
25
- beforeEach(() => {
26
- TestBed.configureTestingModule({
27
- providers: [provideCopilotKit({})],
28
- });
29
- service = TestBed.inject(CopilotKitService);
30
- });
31
-
32
- afterEach(() => {
33
- vi.clearAllMocks();
34
- });
35
-
36
- it.skip("should create directive instance", () => {
37
- // Cannot test direct instantiation with inject()
38
- expect(true).toBe(true);
39
- });
40
-
41
- it.skip("should have required inputs", () => {
42
- // Cannot test direct instantiation with inject()
43
- expect(true).toBe(true);
44
- });
45
-
46
- it.skip("should register tool on init", () => {
47
- // Cannot test direct instantiation with inject()
48
- expect(true).toBe(true);
49
- });
50
-
51
- it.skip("should unregister tool on destroy", () => {
52
- // Cannot test direct instantiation with inject()
53
- expect(true).toBe(true);
54
- });
55
-
56
- it.skip("should warn if name is missing", () => {
57
- // Cannot test direct instantiation with inject()
58
- expect(true).toBe(true);
59
- });
60
- });
@@ -1,108 +0,0 @@
1
- import { Component } from "@angular/core";
2
- import { TestBed } from "@angular/core/testing";
3
- import { describe, it, expect, beforeEach, vi, afterEach } from "vitest";
4
- import { CopilotKitFrontendToolDirective } from "../copilotkit-frontend-tool.directive";
5
- import { CopilotKitService } from "../../core/copilotkit.service";
6
- import { provideCopilotKit } from "../../core/copilotkit.providers";
7
- import { z } from "zod";
8
-
9
- // Mock CopilotKitCore
10
- vi.mock("@copilotkitnext/core", () => ({
11
- CopilotKitCore: vi.fn().mockImplementation(() => ({
12
- addTool: vi.fn(),
13
- removeTool: vi.fn(),
14
- setRuntimeUrl: vi.fn(),
15
- setHeaders: vi.fn(),
16
- setProperties: vi.fn(),
17
- setAgents: vi.fn(),
18
- subscribe: vi.fn(() => () => {}),
19
- })),
20
- }));
21
-
22
- describe("CopilotKitFrontendToolDirective", () => {
23
- let service: CopilotKitService;
24
- let addToolSpy: any;
25
- let removeToolSpy: any;
26
-
27
- beforeEach(() => {
28
- TestBed.configureTestingModule({
29
- providers: [provideCopilotKit({})],
30
- });
31
-
32
- service = TestBed.inject(CopilotKitService);
33
- addToolSpy = vi.spyOn(service.copilotkit, "addTool");
34
- removeToolSpy = vi.spyOn(service.copilotkit, "removeTool");
35
- });
36
-
37
- afterEach(() => {
38
- vi.clearAllMocks();
39
- });
40
-
41
- describe("Basic Registration", () => {
42
- it("should register tool with static values", () => {
43
- @Component({
44
- template: `
45
- <div
46
- copilotkitFrontendTool
47
- name="testTool"
48
- description="Test tool"
49
- ></div>
50
- `,
51
- standalone: true,
52
- imports: [CopilotKitFrontendToolDirective],
53
- })
54
- class TestComponent {}
55
-
56
- const fixture = TestBed.createComponent(TestComponent);
57
- fixture.detectChanges();
58
-
59
- expect(addToolSpy).toHaveBeenCalledWith(
60
- expect.objectContaining({
61
- name: "testTool",
62
- description: "Test tool",
63
- })
64
- );
65
- });
66
-
67
- it("should warn if name is missing", () => {
68
- const consoleSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
69
-
70
- @Component({
71
- template: `<div copilotkitFrontendTool></div>`,
72
- standalone: true,
73
- imports: [CopilotKitFrontendToolDirective],
74
- })
75
- class MissingNameComponent {}
76
-
77
- const fixture = TestBed.createComponent(MissingNameComponent);
78
- fixture.detectChanges();
79
-
80
- expect(addToolSpy).not.toHaveBeenCalled();
81
- expect(consoleSpy).toHaveBeenCalledWith(
82
- 'CopilotKitFrontendToolDirective: "name" is required. Please provide a name via [name]="toolName" or [copilotkitFrontendTool]="{ name: \'toolName\', ... }"'
83
- );
84
-
85
- consoleSpy.mockRestore();
86
- });
87
- });
88
-
89
- describe("Cleanup", () => {
90
- it("should remove tool on destroy", () => {
91
- @Component({
92
- template: ` <div copilotkitFrontendTool name="cleanupTool"></div> `,
93
- standalone: true,
94
- imports: [CopilotKitFrontendToolDirective],
95
- })
96
- class CleanupComponent {}
97
-
98
- const fixture = TestBed.createComponent(CleanupComponent);
99
- fixture.detectChanges();
100
-
101
- expect(addToolSpy).toHaveBeenCalled();
102
-
103
- fixture.destroy();
104
-
105
- expect(removeToolSpy).toHaveBeenCalledWith("cleanupTool");
106
- });
107
- });
108
- });