@copilotkitnext/angular 0.0.1 → 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 (171) hide show
  1. package/README.md +248 -0
  2. package/dist/README.md +248 -0
  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/dist/styles.css +0 -27
  72. package/package.json +23 -20
  73. package/vitest.config.mts +32 -21
  74. package/.turbo/turbo-build.log +0 -39
  75. package/.turbo/turbo-check-types.log +0 -0
  76. package/.turbo/turbo-test.log +0 -71
  77. package/README-agent-context.md +0 -310
  78. package/ng-package.json +0 -19
  79. package/slots.md +0 -331
  80. package/src/components/chat/__tests__/copilot-chat-assistant-message.component.spec.ts +0 -282
  81. package/src/components/chat/__tests__/copilot-chat-input.component.spec.ts +0 -419
  82. package/src/components/chat/__tests__/copilot-chat-message-view.component.spec.ts +0 -372
  83. package/src/components/chat/__tests__/copilot-chat-user-message.component.spec.ts +0 -249
  84. package/src/components/chat/copilot-chat-assistant-message-buttons.component.ts +0 -292
  85. package/src/components/chat/copilot-chat-assistant-message-renderer.component.ts +0 -472
  86. package/src/components/chat/copilot-chat-assistant-message-toolbar.component.ts +0 -29
  87. package/src/components/chat/copilot-chat-assistant-message.component.ts +0 -463
  88. package/src/components/chat/copilot-chat-assistant-message.types.ts +0 -50
  89. package/src/components/chat/copilot-chat-audio-recorder.component.ts +0 -241
  90. package/src/components/chat/copilot-chat-buttons.component.ts +0 -308
  91. package/src/components/chat/copilot-chat-buttons.component.ts.bak +0 -471
  92. package/src/components/chat/copilot-chat-input-defaults.ts +0 -47
  93. package/src/components/chat/copilot-chat-input.component.ts +0 -512
  94. package/src/components/chat/copilot-chat-input.types.ts +0 -148
  95. package/src/components/chat/copilot-chat-message-view-cursor.component.ts +0 -51
  96. package/src/components/chat/copilot-chat-message-view.component.ts +0 -233
  97. package/src/components/chat/copilot-chat-message-view.types.ts +0 -39
  98. package/src/components/chat/copilot-chat-textarea.component.ts +0 -220
  99. package/src/components/chat/copilot-chat-tool-calls-view.component.ts +0 -261
  100. package/src/components/chat/copilot-chat-toolbar.component.ts +0 -35
  101. package/src/components/chat/copilot-chat-tools-menu.component.ts +0 -185
  102. package/src/components/chat/copilot-chat-user-message-branch-navigation.component.ts +0 -121
  103. package/src/components/chat/copilot-chat-user-message-buttons.component.ts +0 -170
  104. package/src/components/chat/copilot-chat-user-message-renderer.component.ts +0 -37
  105. package/src/components/chat/copilot-chat-user-message-toolbar.component.ts +0 -37
  106. package/src/components/chat/copilot-chat-user-message.component.ts +0 -247
  107. package/src/components/chat/copilot-chat-user-message.types.ts +0 -42
  108. package/src/components/chat/copilot-chat-view-disclaimer.component.ts +0 -51
  109. package/src/components/chat/copilot-chat-view-feather.component.ts +0 -47
  110. package/src/components/chat/copilot-chat-view-handlers.service.ts +0 -14
  111. package/src/components/chat/copilot-chat-view-input-container.component.ts +0 -87
  112. package/src/components/chat/copilot-chat-view-scroll-to-bottom-button.component.ts +0 -79
  113. package/src/components/chat/copilot-chat-view-scroll-view.component.ts +0 -322
  114. package/src/components/chat/copilot-chat-view.component.ts +0 -420
  115. package/src/components/chat/copilot-chat-view.types.ts +0 -52
  116. package/src/components/chat/copilot-chat.component.ts +0 -232
  117. package/src/components/copilotkit-tool-render.component.ts +0 -169
  118. package/src/core/__tests__/copilotkit.service.spec.ts +0 -1051
  119. package/src/core/__tests__/copilotkit.service.wildcard.spec.ts +0 -316
  120. package/src/core/chat-configuration/__tests__/chat-configuration.service.spec.ts +0 -287
  121. package/src/core/chat-configuration/chat-configuration.providers.ts +0 -71
  122. package/src/core/chat-configuration/chat-configuration.service.ts +0 -162
  123. package/src/core/chat-configuration/chat-configuration.types.ts +0 -57
  124. package/src/core/copilotkit.providers.ts +0 -59
  125. package/src/core/copilotkit.service.ts +0 -542
  126. package/src/core/copilotkit.types.ts +0 -132
  127. package/src/directives/__tests__/copilotkit-agent-context.directive.spec.ts +0 -384
  128. package/src/directives/__tests__/copilotkit-agent.directive.spec.ts +0 -253
  129. package/src/directives/__tests__/copilotkit-chat-config.directive.spec.ts +0 -385
  130. package/src/directives/__tests__/copilotkit-config.directive.spec.ts +0 -69
  131. package/src/directives/__tests__/copilotkit-frontend-tool-simple.directive.spec.ts +0 -60
  132. package/src/directives/__tests__/copilotkit-frontend-tool.directive.spec.ts +0 -108
  133. package/src/directives/__tests__/copilotkit-human-in-the-loop.directive.spec.ts +0 -452
  134. package/src/directives/copilotkit-agent-context.directive.ts +0 -138
  135. package/src/directives/copilotkit-agent.directive.ts +0 -225
  136. package/src/directives/copilotkit-chat-config.directive.ts +0 -241
  137. package/src/directives/copilotkit-config.directive.ts +0 -81
  138. package/src/directives/copilotkit-frontend-tool.directive.ts +0 -145
  139. package/src/directives/copilotkit-human-in-the-loop.directive.ts +0 -281
  140. package/src/directives/stick-to-bottom.directive.ts +0 -204
  141. package/src/index.ts +0 -105
  142. package/src/lib/directives/tooltip.directive.ts +0 -292
  143. package/src/lib/slots/__tests__/slot.utils.spec.ts +0 -377
  144. package/src/lib/slots/copilot-slot.component.ts +0 -135
  145. package/src/lib/slots/index.ts +0 -3
  146. package/src/lib/slots/slot.types.ts +0 -64
  147. package/src/lib/slots/slot.utils.ts +0 -289
  148. package/src/lib/utils.ts +0 -10
  149. package/src/public-api.ts +0 -1
  150. package/src/services/resize-observer.service.ts +0 -181
  151. package/src/services/scroll-position.service.ts +0 -169
  152. package/src/styles/globals.css +0 -266
  153. package/src/styles/index.css +0 -3
  154. package/src/test-setup.ts +0 -15
  155. package/src/testing/index.ts +0 -3
  156. package/src/testing/testing.utils.ts +0 -248
  157. package/src/types/frontend-tool.ts +0 -44
  158. package/src/types/human-in-the-loop.ts +0 -52
  159. package/src/utils/__tests__/agent.utils.spec.ts +0 -234
  160. package/src/utils/__tests__/chat-config.utils.spec.ts +0 -306
  161. package/src/utils/__tests__/frontend-tool-inject.spec.ts +0 -350
  162. package/src/utils/__tests__/frontend-tool-integration.spec.ts +0 -199
  163. package/src/utils/__tests__/frontend-tool.utils.spec.ts +0 -272
  164. package/src/utils/__tests__/human-in-the-loop.utils.spec.ts +0 -365
  165. package/src/utils/agent-context.utils.ts +0 -133
  166. package/src/utils/agent.utils.ts +0 -239
  167. package/src/utils/chat-config.utils.ts +0 -221
  168. package/src/utils/copilotkit.utils.ts +0 -20
  169. package/src/utils/frontend-tool.utils.ts +0 -266
  170. package/src/utils/human-in-the-loop.utils.ts +0 -359
  171. package/tsconfig.spec.json +0 -12
@@ -1,44 +0,0 @@
1
- import { Type, TemplateRef } from "@angular/core";
2
- import type { z } from "zod";
3
-
4
- /**
5
- * Angular-specific frontend tool definition.
6
- * Provides a handler function that executes on the frontend when the tool is called.
7
- */
8
- export interface AngularFrontendTool<T extends Record<string, any> = Record<string, any>> {
9
- /**
10
- * The name of the tool - must be unique
11
- */
12
- name: string;
13
-
14
- /**
15
- * Description of what the tool does
16
- */
17
- description?: string;
18
-
19
- /**
20
- * Zod schema defining the parameters for the tool
21
- */
22
- parameters?: z.ZodSchema<T>;
23
-
24
- /**
25
- * Handler function that executes when the tool is called
26
- */
27
- handler?: (args: T) => Promise<any>;
28
-
29
- /**
30
- * Optional Angular component or template to render when the tool is called
31
- */
32
- render?: Type<any> | TemplateRef<any>;
33
-
34
- /**
35
- * Whether the agent should follow up after this tool completes.
36
- * Defaults to true if not specified.
37
- */
38
- followUp?: boolean;
39
-
40
- /**
41
- * Optional agent ID to constrain this tool to a specific agent
42
- */
43
- agentId?: string;
44
- }
@@ -1,52 +0,0 @@
1
- import { Type, TemplateRef } from "@angular/core";
2
- import type { z } from "zod";
3
- import { AngularFrontendTool } from "./frontend-tool";
4
- import { ToolCallStatus } from "@copilotkitnext/core";
5
-
6
- /**
7
- * Props passed to human-in-the-loop render components - discriminated union matching React
8
- */
9
- export type HumanInTheLoopProps<T = unknown> =
10
- | {
11
- name: string;
12
- description: string;
13
- args: Partial<T>;
14
- status: ToolCallStatus.InProgress;
15
- result: undefined;
16
- respond: undefined;
17
- }
18
- | {
19
- name: string;
20
- description: string;
21
- args: T;
22
- status: ToolCallStatus.Executing;
23
- result: undefined;
24
- respond: (result: unknown) => Promise<void>;
25
- }
26
- | {
27
- name: string;
28
- description: string;
29
- args: T;
30
- status: ToolCallStatus.Complete;
31
- result: string;
32
- respond: undefined;
33
- };
34
-
35
- /**
36
- * Angular human-in-the-loop tool definition.
37
- * Similar to frontend tools but designed for interactive user input scenarios.
38
- */
39
- export interface AngularHumanInTheLoop<
40
- T extends Record<string, any> = Record<string, any>,
41
- > extends Omit<AngularFrontendTool<T>, "handler" | "render"> {
42
- /**
43
- * Angular component or template to render for user interaction.
44
- * Required for human-in-the-loop tools.
45
- */
46
- render: Type<HumanInTheLoopProps<T>> | TemplateRef<HumanInTheLoopProps<T>>;
47
-
48
- /**
49
- * Parameters schema is required for human-in-the-loop tools
50
- */
51
- parameters: z.ZodType<T>;
52
- }
@@ -1,234 +0,0 @@
1
- import { TestBed } from "@angular/core/testing";
2
- import { Component, OnInit, DestroyRef, inject } from "@angular/core";
3
- import { describe, it, expect, beforeEach, vi, afterEach } from "vitest";
4
- import {
5
- watchAgent,
6
- getAgent,
7
- subscribeToAgent,
8
- registerAgentWatcher,
9
- } from "../agent.utils";
10
- import { CopilotKitService } from "../../core/copilotkit.service";
11
- import { provideCopilotKit } from "../../core/copilotkit.providers";
12
- import { AbstractAgent } from "@ag-ui/client";
13
- import { DEFAULT_AGENT_ID } from "@copilotkitnext/shared";
14
- import { effect } from "@angular/core";
15
-
16
- // Mock CopilotKitCore
17
- const mockAgent = {
18
- subscribe: vi.fn((callbacks) => ({
19
- unsubscribe: vi.fn(),
20
- })),
21
- id: "test-agent",
22
- state: {},
23
- messages: [],
24
- };
25
-
26
- const mockCopilotKitCore = {
27
- addTool: vi.fn(),
28
- removeTool: vi.fn(),
29
- setRuntimeUrl: vi.fn(),
30
- setHeaders: vi.fn(),
31
- setProperties: vi.fn(),
32
- setAgents: vi.fn(),
33
- getAgent: vi.fn((id: string) =>
34
- id === "test-agent" ? mockAgent : undefined
35
- ),
36
- subscribe: vi.fn(() => vi.fn()), // Returns unsubscribe function directly
37
- };
38
-
39
- vi.mock("@copilotkitnext/core", () => ({
40
- CopilotKitCore: vi.fn().mockImplementation(() => mockCopilotKitCore),
41
- }));
42
-
43
- describe("Agent Utilities", () => {
44
- let service: CopilotKitService;
45
-
46
- beforeEach(() => {
47
- TestBed.configureTestingModule({
48
- providers: [provideCopilotKit({})],
49
- });
50
-
51
- service = TestBed.inject(CopilotKitService);
52
- vi.clearAllMocks();
53
- });
54
-
55
- afterEach(() => {
56
- vi.clearAllMocks();
57
- });
58
-
59
- describe("getAgent", () => {
60
- it("should get agent by ID", () => {
61
- const agent = getAgent(service, "test-agent");
62
- expect(agent).toBe(mockAgent);
63
- expect(mockCopilotKitCore.getAgent).toHaveBeenCalledWith("test-agent");
64
- });
65
-
66
- it("should use default agent ID when not provided", () => {
67
- getAgent(service);
68
- expect(mockCopilotKitCore.getAgent).toHaveBeenCalledWith(
69
- DEFAULT_AGENT_ID
70
- );
71
- });
72
-
73
- it("should return undefined for non-existent agent", () => {
74
- const agent = getAgent(service, "non-existent");
75
- expect(agent).toBeUndefined();
76
- });
77
- });
78
-
79
- describe("subscribeToAgent", () => {
80
- it("should subscribe to agent events", () => {
81
- const callbacks = {
82
- onRunInitialized: vi.fn(),
83
- onRunFinalized: vi.fn(),
84
- onRunFailed: vi.fn(),
85
- };
86
-
87
- const unsubscribe = subscribeToAgent(service, "test-agent", callbacks);
88
-
89
- expect(mockAgent.subscribe).toHaveBeenCalledWith(
90
- expect.objectContaining({
91
- onRunInitialized: callbacks.onRunInitialized,
92
- onRunFinalized: callbacks.onRunFinalized,
93
- onRunFailed: callbacks.onRunFailed,
94
- })
95
- );
96
-
97
- expect(typeof unsubscribe).toBe("function");
98
- });
99
-
100
- it("should return no-op function for non-existent agent", () => {
101
- const unsubscribe = subscribeToAgent(service, "non-existent");
102
- expect(typeof unsubscribe).toBe("function");
103
- unsubscribe(); // Should not throw
104
- });
105
-
106
- it("should handle partial callbacks", () => {
107
- const callbacks = {
108
- onRunInitialized: vi.fn(),
109
- };
110
-
111
- subscribeToAgent(service, "test-agent", callbacks);
112
-
113
- expect(mockAgent.subscribe).toHaveBeenCalledWith(
114
- expect.objectContaining({
115
- onRunInitialized: callbacks.onRunInitialized,
116
- onRunFinalized: undefined,
117
- onRunFailed: undefined,
118
- })
119
- );
120
- });
121
- });
122
-
123
- describe("watchAgent", () => {
124
- it("should return reactive signals within component context", () => {
125
- @Component({
126
- template: "",
127
- standalone: true,
128
- providers: [provideCopilotKit({})],
129
- })
130
- class TestComponent {
131
- agentState: any;
132
- agentValue: AbstractAgent | undefined;
133
- messagesValue: any[] = [];
134
- isRunningValue = false;
135
-
136
- constructor() {
137
- this.agentState = watchAgent({ agentId: "test-agent" });
138
- // Use effect in constructor (injection context)
139
- effect(() => {
140
- this.agentValue = this.agentState.agent();
141
- this.messagesValue = this.agentState.messages();
142
- this.isRunningValue = this.agentState.isRunning();
143
- });
144
- }
145
- }
146
-
147
- const fixture = TestBed.createComponent(TestComponent);
148
- fixture.detectChanges();
149
-
150
- expect(fixture.componentInstance.agentState).toBeDefined();
151
- expect(fixture.componentInstance.agentState.agent).toBeDefined();
152
- expect(fixture.componentInstance.agentState.messages).toBeDefined();
153
- expect(fixture.componentInstance.agentState.isRunning).toBeDefined();
154
- expect(fixture.componentInstance.agentState.agent$).toBeDefined();
155
- expect(fixture.componentInstance.agentState.messages$).toBeDefined();
156
- expect(fixture.componentInstance.agentState.isRunning$).toBeDefined();
157
- });
158
-
159
- it("should cleanup on component destroy", () => {
160
- @Component({
161
- template: "",
162
- standalone: true,
163
- providers: [provideCopilotKit({})],
164
- })
165
- class TestComponent {
166
- agentState: any;
167
-
168
- constructor() {
169
- this.agentState = watchAgent({ agentId: "test-agent" });
170
- }
171
- }
172
-
173
- const fixture = TestBed.createComponent(TestComponent);
174
- fixture.detectChanges();
175
-
176
- const unsubscribeSpy = vi.fn();
177
- fixture.componentInstance.agentState.unsubscribe = unsubscribeSpy;
178
-
179
- fixture.destroy();
180
-
181
- // The actual unsubscribe is handled by DestroyRef,
182
- // but we can verify the function exists
183
- expect(fixture.componentInstance.agentState.unsubscribe).toBeDefined();
184
- });
185
-
186
- it("should use default agent ID when not provided", () => {
187
- @Component({
188
- template: "",
189
- standalone: true,
190
- providers: [provideCopilotKit({})],
191
- })
192
- class TestComponent {
193
- agentState = watchAgent(); // No agent ID
194
- }
195
-
196
- const fixture = TestBed.createComponent(TestComponent);
197
- fixture.detectChanges();
198
-
199
- expect(mockCopilotKitCore.getAgent).toHaveBeenCalledWith(
200
- DEFAULT_AGENT_ID
201
- );
202
- });
203
- });
204
-
205
- describe("registerAgentWatcher", () => {
206
- it("should be an alias for watchAgent", () => {
207
- @Component({
208
- template: "",
209
- standalone: true,
210
- providers: [provideCopilotKit({})],
211
- })
212
- class TestComponent {
213
- agentState = registerAgentWatcher({ agentId: "test-agent" });
214
- }
215
-
216
- const fixture = TestBed.createComponent(TestComponent);
217
- fixture.detectChanges();
218
-
219
- expect(fixture.componentInstance.agentState).toBeDefined();
220
- expect(fixture.componentInstance.agentState.agent).toBeDefined();
221
- expect(fixture.componentInstance.agentState.messages).toBeDefined();
222
- expect(fixture.componentInstance.agentState.isRunning).toBeDefined();
223
- expect(mockCopilotKitCore.getAgent).toHaveBeenCalledWith("test-agent");
224
- });
225
- });
226
-
227
- describe("CopilotKitService.getAgent", () => {
228
- it("should delegate to core getAgent", () => {
229
- const agent = service.getAgent("test-agent");
230
- expect(agent).toBe(mockAgent);
231
- expect(mockCopilotKitCore.getAgent).toHaveBeenCalledWith("test-agent");
232
- });
233
- });
234
- });
@@ -1,306 +0,0 @@
1
- import { TestBed } from '@angular/core/testing';
2
- import { Component } from '@angular/core';
3
- import { describe, it, expect, beforeEach, vi } from 'vitest';
4
- import {
5
- watchChatConfig,
6
- registerChatConfig,
7
- getChatLabels,
8
- setChatLabels,
9
- getChatInputValue,
10
- setChatInputValue,
11
- createChatConfigController
12
- } from '../chat-config.utils';
13
- import { CopilotChatConfigurationService } from '../../core/chat-configuration/chat-configuration.service';
14
- import { provideCopilotChatConfiguration } from '../../core/chat-configuration/chat-configuration.providers';
15
- import { COPILOT_CHAT_DEFAULT_LABELS } from '../../core/chat-configuration/chat-configuration.types';
16
- import { effect } from '@angular/core';
17
-
18
- describe('Chat Configuration Utilities', () => {
19
- describe('watchChatConfig', () => {
20
- it('should return reactive configuration within component context', () => {
21
- @Component({
22
- template: '',
23
- standalone: true,
24
- providers: provideCopilotChatConfiguration({
25
- labels: { chatInputPlaceholder: 'Test placeholder' },
26
- inputValue: 'test value'
27
- })
28
- })
29
- class TestComponent {
30
- config = watchChatConfig();
31
- }
32
-
33
- const fixture = TestBed.createComponent(TestComponent);
34
- fixture.detectChanges();
35
-
36
- const component = fixture.componentInstance;
37
-
38
- expect(component.config.labels().chatInputPlaceholder).toBe('Test placeholder');
39
- expect(component.config.inputValue()).toBe('test value');
40
- expect(typeof component.config.submitInput).toBe('function');
41
- expect(typeof component.config.changeInput).toBe('function');
42
- });
43
-
44
- it('should provide reactive signals that update', () => {
45
- TestBed.configureTestingModule({
46
- providers: provideCopilotChatConfiguration()
47
- });
48
-
49
- @Component({
50
- template: '',
51
- standalone: true
52
- })
53
- class TestComponent {
54
- config = watchChatConfig();
55
- }
56
-
57
- const fixture = TestBed.createComponent(TestComponent);
58
- fixture.detectChanges();
59
-
60
- const service = TestBed.inject(CopilotChatConfigurationService);
61
-
62
- // Initial value
63
- expect(fixture.componentInstance.config.labels().chatInputPlaceholder).toBe('Type a message...');
64
-
65
- // Update labels through service
66
- service.setLabels({ chatInputPlaceholder: 'Updated' });
67
-
68
- // Signals update synchronously
69
- expect(fixture.componentInstance.config.labels().chatInputPlaceholder).toBe('Updated');
70
- });
71
-
72
- it('should call service methods when handlers are invoked', () => {
73
- const submitHandler = vi.fn();
74
- const changeHandler = vi.fn();
75
-
76
- @Component({
77
- template: '',
78
- standalone: true,
79
- providers: provideCopilotChatConfiguration({
80
- onSubmitInput: submitHandler,
81
- onChangeInput: changeHandler
82
- })
83
- })
84
- class TestComponent {
85
- config = watchChatConfig();
86
- }
87
-
88
- const fixture = TestBed.createComponent(TestComponent);
89
- fixture.detectChanges();
90
-
91
- const component = fixture.componentInstance;
92
-
93
- component.config.submitInput('test submit');
94
- expect(submitHandler).toHaveBeenCalledWith('test submit');
95
-
96
- component.config.changeInput('test change');
97
- expect(changeHandler).toHaveBeenCalledWith('test change');
98
- });
99
- });
100
-
101
- describe('registerChatConfig', () => {
102
- it('should update configuration when called within injection context', () => {
103
- TestBed.configureTestingModule({
104
- providers: provideCopilotChatConfiguration()
105
- });
106
-
107
- @Component({
108
- template: '',
109
- standalone: true
110
- })
111
- class TestComponent {
112
- constructor() {
113
- registerChatConfig({
114
- labels: { chatInputPlaceholder: 'Registered placeholder' },
115
- inputValue: 'registered value'
116
- });
117
- }
118
- }
119
-
120
- const fixture = TestBed.createComponent(TestComponent);
121
- fixture.detectChanges();
122
-
123
- const service = TestBed.inject(CopilotChatConfigurationService);
124
-
125
- expect(service.labels().chatInputPlaceholder).toBe('Registered placeholder');
126
- expect(service.inputValue()).toBe('registered value');
127
- });
128
-
129
- it('should set handlers through registerChatConfig', () => {
130
- const submitHandler = vi.fn();
131
- const changeHandler = vi.fn();
132
-
133
- TestBed.configureTestingModule({
134
- providers: provideCopilotChatConfiguration()
135
- });
136
-
137
- @Component({
138
- template: '',
139
- standalone: true
140
- })
141
- class TestComponent {
142
- constructor() {
143
- registerChatConfig({
144
- onSubmitInput: submitHandler,
145
- onChangeInput: changeHandler
146
- });
147
- }
148
- }
149
-
150
- const fixture = TestBed.createComponent(TestComponent);
151
- fixture.detectChanges();
152
-
153
- const service = TestBed.inject(CopilotChatConfigurationService);
154
-
155
- service.submitInput('test');
156
- expect(submitHandler).toHaveBeenCalledWith('test');
157
-
158
- service.changeInput('change');
159
- expect(changeHandler).toHaveBeenCalledWith('change');
160
- });
161
- });
162
-
163
- describe('getChatLabels and setChatLabels', () => {
164
- let service: CopilotChatConfigurationService;
165
-
166
- beforeEach(() => {
167
- TestBed.configureTestingModule({
168
- providers: provideCopilotChatConfiguration()
169
- });
170
-
171
- service = TestBed.inject(CopilotChatConfigurationService);
172
- });
173
-
174
- it('should get current labels signal', () => {
175
- const labels = getChatLabels(service);
176
- expect(labels()).toEqual(COPILOT_CHAT_DEFAULT_LABELS);
177
- });
178
-
179
- it('should update labels', () => {
180
- setChatLabels(service, {
181
- chatInputPlaceholder: 'New placeholder',
182
- chatDisclaimerText: 'New disclaimer'
183
- });
184
-
185
- const labels = getChatLabels(service);
186
- expect(labels().chatInputPlaceholder).toBe('New placeholder');
187
- expect(labels().chatDisclaimerText).toBe('New disclaimer');
188
- });
189
-
190
- it('should merge labels with defaults', () => {
191
- setChatLabels(service, {
192
- chatInputPlaceholder: 'Custom'
193
- });
194
-
195
- const labels = getChatLabels(service);
196
- expect(labels().chatInputPlaceholder).toBe('Custom');
197
- expect(labels().chatInputToolbarAddButtonLabel).toBe(
198
- COPILOT_CHAT_DEFAULT_LABELS.chatInputToolbarAddButtonLabel
199
- );
200
- });
201
- });
202
-
203
- describe('getChatInputValue and setChatInputValue', () => {
204
- let service: CopilotChatConfigurationService;
205
-
206
- beforeEach(() => {
207
- TestBed.configureTestingModule({
208
- providers: provideCopilotChatConfiguration()
209
- });
210
-
211
- service = TestBed.inject(CopilotChatConfigurationService);
212
- });
213
-
214
- it('should get current input value signal', () => {
215
- const inputValue = getChatInputValue(service);
216
- expect(inputValue()).toBeUndefined();
217
- });
218
-
219
- it('should update input value', () => {
220
- setChatInputValue(service, 'test value');
221
-
222
- const inputValue = getChatInputValue(service);
223
- expect(inputValue()).toBe('test value');
224
- });
225
-
226
- it('should handle undefined value', () => {
227
- setChatInputValue(service, 'value');
228
- setChatInputValue(service, undefined);
229
-
230
- const inputValue = getChatInputValue(service);
231
- expect(inputValue()).toBeUndefined();
232
- });
233
-
234
- it('should trigger change handler when setting value', () => {
235
- const changeHandler = vi.fn();
236
- service.setChangeHandler(changeHandler);
237
-
238
- setChatInputValue(service, 'new value');
239
-
240
- expect(changeHandler).toHaveBeenCalledWith('new value');
241
- });
242
- });
243
-
244
- describe('createChatConfigController', () => {
245
- let service: CopilotChatConfigurationService;
246
-
247
- beforeEach(() => {
248
- TestBed.configureTestingModule({
249
- providers: provideCopilotChatConfiguration()
250
- });
251
-
252
- service = TestBed.inject(CopilotChatConfigurationService);
253
- });
254
-
255
- it('should create controller with initial configuration', () => {
256
- const controller = createChatConfigController(service, {
257
- labels: { chatInputPlaceholder: 'Controller placeholder' },
258
- inputValue: 'controller value'
259
- });
260
-
261
- expect(controller.getLabels().chatInputPlaceholder).toBe('Controller placeholder');
262
- expect(controller.getInputValue()).toBe('controller value');
263
- });
264
-
265
- it('should update configuration through controller', () => {
266
- const controller = createChatConfigController(service);
267
-
268
- controller.update({
269
- labels: { chatInputPlaceholder: 'Updated via controller' },
270
- inputValue: 'new value'
271
- });
272
-
273
- expect(service.labels().chatInputPlaceholder).toBe('Updated via controller');
274
- expect(service.inputValue()).toBe('new value');
275
- });
276
-
277
- it('should reset configuration through controller', () => {
278
- const controller = createChatConfigController(service, {
279
- labels: { chatInputPlaceholder: 'Custom' },
280
- inputValue: 'test'
281
- });
282
-
283
- controller.reset();
284
-
285
- expect(service.labels()).toEqual(COPILOT_CHAT_DEFAULT_LABELS);
286
- expect(service.inputValue()).toBeUndefined();
287
- });
288
-
289
- it('should provide getter methods', () => {
290
- const controller = createChatConfigController(service);
291
-
292
- service.setLabels({ chatInputPlaceholder: 'Test' });
293
- service.setInputValue('test value');
294
-
295
- expect(controller.getLabels().chatInputPlaceholder).toBe('Test');
296
- expect(controller.getInputValue()).toBe('test value');
297
- });
298
-
299
- it('should work without initial configuration', () => {
300
- const controller = createChatConfigController(service);
301
-
302
- expect(controller.getLabels()).toEqual(COPILOT_CHAT_DEFAULT_LABELS);
303
- expect(controller.getInputValue()).toBeUndefined();
304
- });
305
- });
306
- });