@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,542 +0,0 @@
1
- import {
2
- Injectable,
3
- Inject,
4
- signal,
5
- computed,
6
- effect,
7
- untracked,
8
- } from "@angular/core";
9
- import { toObservable } from "@angular/core/rxjs-interop";
10
- import {
11
- COPILOTKIT_RUNTIME_URL,
12
- COPILOTKIT_HEADERS,
13
- COPILOTKIT_PROPERTIES,
14
- COPILOTKIT_AGENTS,
15
- COPILOTKIT_RENDER_TOOL_CALLS,
16
- COPILOTKIT_FRONTEND_TOOLS,
17
- COPILOTKIT_HUMAN_IN_THE_LOOP,
18
- CopilotKitContextValue,
19
- ToolCallRender,
20
- AngularFrontendTool,
21
- AngularHumanInTheLoop,
22
- } from "./copilotkit.types";
23
- import {
24
- CopilotKitCore,
25
- CopilotKitCoreConfig,
26
- FrontendTool,
27
- } from "@copilotkitnext/core";
28
- import { AbstractAgent } from "@ag-ui/client";
29
-
30
- /**
31
- * Angular service for managing CopilotKit state and interactions.
32
- * Provides reactive state management using Angular signals and observables.
33
- */
34
- @Injectable({ providedIn: "root" })
35
- export class CopilotKitService {
36
- // Initial values for stability tracking
37
- private readonly initialFrontendTools: AngularFrontendTool<any>[];
38
- private readonly initialHumanInTheLoop: AngularHumanInTheLoop<any>[];
39
- private readonly initialRenderToolCalls: ToolCallRender<unknown>[];
40
-
41
- // Core instance - created once
42
- readonly copilotkit: CopilotKitCore;
43
-
44
- // State signals
45
- private readonly _renderToolCalls: ReturnType<
46
- typeof signal<ToolCallRender<unknown>[]>
47
- >;
48
- private readonly _currentRenderToolCalls: ReturnType<
49
- typeof signal<ToolCallRender<unknown>[]>
50
- >;
51
- private readonly _runtimeUrl: ReturnType<typeof signal<string | undefined>>;
52
- private readonly _headers: ReturnType<typeof signal<Record<string, string>>>;
53
- private readonly _properties: ReturnType<
54
- typeof signal<Record<string, unknown>>
55
- >;
56
- private readonly _agents: ReturnType<
57
- typeof signal<Record<string, AbstractAgent>>
58
- >;
59
- private readonly _frontendTools: ReturnType<
60
- typeof signal<AngularFrontendTool<any>[]>
61
- >;
62
- private readonly _humanInTheLoop: ReturnType<
63
- typeof signal<AngularHumanInTheLoop<any>[]>
64
- >;
65
-
66
- // Runtime state change notification signal
67
- private readonly _runtimeStateVersion: ReturnType<typeof signal<number>>;
68
-
69
- // Computed signals for processed values
70
- private readonly _allTools: ReturnType<
71
- typeof computed<Record<string, FrontendTool<any>>>
72
- >;
73
- private readonly _allRenderToolCalls: ReturnType<
74
- typeof computed<ToolCallRender<unknown>[]>
75
- >;
76
-
77
- // Public readonly signals - will be initialized in constructor
78
- readonly renderToolCalls: any;
79
- readonly currentRenderToolCalls: any;
80
- readonly runtimeUrl: any;
81
- readonly headers: any;
82
- readonly properties: any;
83
- readonly agents: any;
84
- readonly frontendTools: any;
85
- readonly humanInTheLoop: any;
86
- readonly runtimeStateVersion: any;
87
-
88
- // Observable APIs for RxJS users - will be initialized in constructor
89
- readonly renderToolCalls$: any;
90
- readonly currentRenderToolCalls$: any;
91
- readonly runtimeUrl$: any;
92
- readonly headers$: any;
93
- readonly properties$: any;
94
- readonly agents$: any;
95
- readonly frontendTools$: any;
96
- readonly humanInTheLoop$: any;
97
-
98
- // Context value as computed signal - will be initialized in constructor
99
- readonly context: any;
100
- readonly context$: any;
101
-
102
- constructor(
103
- @Inject(COPILOTKIT_RUNTIME_URL) runtimeUrl: string | undefined,
104
- @Inject(COPILOTKIT_HEADERS) headers: Record<string, string>,
105
- @Inject(COPILOTKIT_PROPERTIES) properties: Record<string, unknown>,
106
- @Inject(COPILOTKIT_AGENTS) agents: Record<string, AbstractAgent>,
107
- @Inject(COPILOTKIT_RENDER_TOOL_CALLS)
108
- renderToolCalls: ToolCallRender<unknown>[],
109
- @Inject(COPILOTKIT_FRONTEND_TOOLS)
110
- frontendTools: AngularFrontendTool<any>[],
111
- @Inject(COPILOTKIT_HUMAN_IN_THE_LOOP)
112
- humanInTheLoop: AngularHumanInTheLoop<any>[]
113
- ) {
114
- // Store initial values for stability checking
115
- this.initialFrontendTools = frontendTools;
116
- this.initialHumanInTheLoop = humanInTheLoop;
117
- this.initialRenderToolCalls = renderToolCalls;
118
-
119
- // Process tools and humanInTheLoop
120
- const { allTools, allRenderToolCalls } = this.processTools(
121
- frontendTools,
122
- humanInTheLoop,
123
- renderToolCalls
124
- );
125
-
126
- // Initialize core instance with processed tools
127
- this.copilotkit = new CopilotKitCore({
128
- runtimeUrl: undefined, // Prevent server-side fetching
129
- headers,
130
- properties,
131
- agents,
132
- tools: allTools,
133
- } as CopilotKitCoreConfig);
134
-
135
- // Initialize state signals
136
- this._renderToolCalls =
137
- signal<ToolCallRender<unknown>[]>(allRenderToolCalls);
138
- this._currentRenderToolCalls =
139
- signal<ToolCallRender<unknown>[]>(allRenderToolCalls);
140
- this._runtimeUrl = signal<string | undefined>(runtimeUrl);
141
- this._headers = signal<Record<string, string>>(headers);
142
- this._properties = signal<Record<string, unknown>>(properties);
143
- this._agents = signal<Record<string, AbstractAgent>>(agents);
144
- this._frontendTools = signal<AngularFrontendTool<any>[]>(frontendTools);
145
- this._humanInTheLoop = signal<AngularHumanInTheLoop<any>[]>(humanInTheLoop);
146
- this._runtimeStateVersion = signal<number>(0);
147
-
148
- // Initialize computed signals for processed values
149
- this._allTools = computed(() => {
150
- const tools: Record<string, FrontendTool<any>> = {};
151
-
152
- // Add frontend tools
153
- this._frontendTools().forEach((tool) => {
154
- tools[tool.name] = tool as FrontendTool<any>;
155
- });
156
-
157
- // Process human-in-the-loop tools
158
- this._humanInTheLoop().forEach((tool) => {
159
- const frontendTool: FrontendTool<any> = {
160
- name: tool.name,
161
- description: tool.description,
162
- parameters: tool.parameters,
163
- followUp: tool.followUp,
164
- handler: async (args: any) => {
165
- console.warn(
166
- `Human-in-the-loop tool '${tool.name}' called but no interactive handler is set up.`
167
- );
168
- return undefined;
169
- },
170
- };
171
- tools[tool.name] = frontendTool;
172
- });
173
-
174
- return tools;
175
- });
176
-
177
- this._allRenderToolCalls = computed(() => {
178
- const combined: ToolCallRender<unknown>[] = [...this._renderToolCalls()];
179
-
180
- // Add render components from frontend tools
181
- this._frontendTools().forEach((tool) => {
182
- if (tool.render && tool.parameters) {
183
- combined.push({
184
- name: tool.name,
185
- args: tool.parameters,
186
- render: tool.render,
187
- ...(tool.agentId && { agentId: tool.agentId }),
188
- });
189
- }
190
- });
191
-
192
- // Add render components from human-in-the-loop tools
193
- this._humanInTheLoop().forEach((tool) => {
194
- if (tool.render && tool.parameters) {
195
- combined.push({
196
- name: tool.name,
197
- args: tool.parameters,
198
- render: tool.render,
199
- ...(tool.agentId && { agentId: tool.agentId }),
200
- });
201
- }
202
- });
203
-
204
- return combined;
205
- });
206
-
207
- // Initialize public readonly signals
208
- this.renderToolCalls = this._allRenderToolCalls;
209
- this.currentRenderToolCalls = this._currentRenderToolCalls.asReadonly();
210
- this.runtimeUrl = this._runtimeUrl.asReadonly();
211
- this.headers = this._headers.asReadonly();
212
- this.properties = this._properties.asReadonly();
213
- this.agents = this._agents.asReadonly();
214
- this.frontendTools = this._frontendTools.asReadonly();
215
- this.humanInTheLoop = this._humanInTheLoop.asReadonly();
216
- this.runtimeStateVersion = this._runtimeStateVersion.asReadonly();
217
-
218
- // Initialize Observable APIs
219
- this.renderToolCalls$ = toObservable(this.renderToolCalls);
220
- this.currentRenderToolCalls$ = toObservable(this.currentRenderToolCalls);
221
- this.runtimeUrl$ = toObservable(this.runtimeUrl);
222
- this.headers$ = toObservable(this.headers);
223
- this.properties$ = toObservable(this.properties);
224
- this.agents$ = toObservable(this.agents);
225
- this.frontendTools$ = toObservable(this.frontendTools);
226
- this.humanInTheLoop$ = toObservable(this.humanInTheLoop);
227
-
228
- // Initialize context value as computed signal
229
- this.context = computed<CopilotKitContextValue>(() => {
230
- // Touch the runtime state version to ensure this computed updates
231
- // when runtime events occur (loaded/error)
232
- this.runtimeStateVersion();
233
-
234
- return {
235
- copilotkit: this.copilotkit,
236
- renderToolCalls: this.renderToolCalls(),
237
- currentRenderToolCalls: this.currentRenderToolCalls(),
238
- setCurrentRenderToolCalls: (v) => this.setCurrentRenderToolCalls(v),
239
- };
240
- });
241
-
242
- this.context$ = toObservable(this.context);
243
-
244
- // Effects must be created in injection context (constructor)
245
- this.setupRuntimeSyncEffects();
246
- this.setupStabilityWarnings();
247
- this.setupEventSubscription();
248
- }
249
-
250
- /**
251
- * Process frontend tools and human-in-the-loop tools
252
- */
253
- private processTools(
254
- frontendTools: AngularFrontendTool<any>[],
255
- humanInTheLoop: AngularHumanInTheLoop<any>[],
256
- renderToolCalls: ToolCallRender<unknown>[]
257
- ): {
258
- allTools: Record<string, FrontendTool<any>>;
259
- allRenderToolCalls: ToolCallRender<unknown>[];
260
- } {
261
- const allTools: Record<string, FrontendTool<any>> = {};
262
- const allRenderToolCalls: ToolCallRender<unknown>[] = [...renderToolCalls];
263
-
264
- // Add frontend tools
265
- frontendTools.forEach((tool) => {
266
- allTools[tool.name] = tool as FrontendTool<any>;
267
-
268
- // Add render component if provided
269
- if (tool.render && tool.parameters) {
270
- allRenderToolCalls.push({
271
- name: tool.name,
272
- args: tool.parameters,
273
- render: tool.render,
274
- ...(tool.agentId && { agentId: tool.agentId }),
275
- });
276
- }
277
- });
278
-
279
- // Process human-in-the-loop tools
280
- humanInTheLoop.forEach((tool) => {
281
- // Create a frontend tool with placeholder handler
282
- const frontendTool: FrontendTool<any> = {
283
- name: tool.name,
284
- description: tool.description,
285
- parameters: tool.parameters,
286
- followUp: tool.followUp,
287
- ...(tool.agentId && { agentId: tool.agentId }),
288
- handler: async (args: any) => {
289
- // Placeholder handler - actual implementation will be handled by the render component
290
- console.warn(
291
- `Human-in-the-loop tool '${tool.name}' called but no interactive handler is set up.`
292
- );
293
- return undefined;
294
- },
295
- };
296
- allTools[tool.name] = frontendTool;
297
-
298
- // Add the render component
299
- if (tool.render && tool.parameters) {
300
- allRenderToolCalls.push({
301
- name: tool.name,
302
- args: tool.parameters,
303
- render: tool.render,
304
- ...(tool.agentId && { agentId: tool.agentId }),
305
- });
306
- }
307
- });
308
-
309
- return { allTools, allRenderToolCalls };
310
- }
311
-
312
- /**
313
- * Setup stability warning effects
314
- */
315
- private setupStabilityWarnings(): void {
316
- // Warn if frontendTools changes
317
- effect(() => {
318
- const current = this._frontendTools();
319
- if (
320
- current !== this.initialFrontendTools &&
321
- this.initialFrontendTools.length > 0
322
- ) {
323
- untracked(() => {
324
- console.error(
325
- "frontendTools must be a stable array. To add/remove tools dynamically, use dynamic tool registration."
326
- );
327
- });
328
- }
329
- });
330
-
331
- // Warn if humanInTheLoop changes
332
- effect(() => {
333
- const current = this._humanInTheLoop();
334
- if (
335
- current !== this.initialHumanInTheLoop &&
336
- this.initialHumanInTheLoop.length > 0
337
- ) {
338
- untracked(() => {
339
- console.error(
340
- "humanInTheLoop must be a stable array. To add/remove human-in-the-loop tools dynamically, use dynamic tool registration."
341
- );
342
- });
343
- }
344
- });
345
-
346
- // Warn if renderToolCalls changes
347
- effect(() => {
348
- const current = this._renderToolCalls();
349
- if (
350
- current !== this.initialRenderToolCalls &&
351
- this.initialRenderToolCalls.length > 0
352
- ) {
353
- untracked(() => {
354
- console.error(
355
- "renderToolCalls must be a stable object. To add/remove tools dynamically, use dynamic tool registration."
356
- );
357
- });
358
- }
359
- });
360
- }
361
-
362
- /**
363
- * Setup effects to sync runtime configuration with CopilotKitCore
364
- */
365
- private setupRuntimeSyncEffects(): void {
366
- // Sync runtime URL
367
- effect(() => {
368
- const url = this.runtimeUrl();
369
- untracked(() => this.copilotkit.setRuntimeUrl(url));
370
- });
371
-
372
- // Sync headers
373
- effect(() => {
374
- const headers = this.headers();
375
- untracked(() => this.copilotkit.setHeaders(headers));
376
- });
377
-
378
- // Sync properties
379
- effect(() => {
380
- const properties = this.properties();
381
- untracked(() => this.copilotkit.setProperties(properties));
382
- });
383
-
384
- // Sync agents
385
- effect(() => {
386
- const agents = this.agents();
387
- untracked(() => this.copilotkit.setAgents(agents));
388
- });
389
-
390
- // Sync tools - computed from frontend tools and human-in-the-loop
391
- effect(() => {
392
- const tools = this._allTools();
393
- // Update copilotkit.tools directly since there's no setTools method
394
- untracked(() => {
395
- this.copilotkit.tools = tools;
396
- });
397
- });
398
- }
399
-
400
- /**
401
- * Subscribe to CopilotKit runtime events
402
- */
403
- private setupEventSubscription(): void {
404
- const unsubscribe = this.copilotkit.subscribe({
405
- onRuntimeLoaded: () => {
406
- // Increment version to notify all consumers that runtime state has changed
407
- // This triggers re-evaluation of computed signals that depend on runtime state
408
- this.notifyRuntimeStateChange();
409
- },
410
- onRuntimeLoadError: () => {
411
- // Increment version to notify all consumers that runtime state has changed
412
- // This triggers re-evaluation of computed signals that depend on runtime state
413
- this.notifyRuntimeStateChange();
414
- },
415
- });
416
-
417
- // Root service lives for app lifetime; unsubscribe not needed.
418
- }
419
-
420
- /**
421
- * Notify consumers that the runtime state has changed.
422
- * This is similar to React's forceUpdate - it triggers change detection
423
- * for any computed signals or effects that depend on runtime state.
424
- */
425
- private notifyRuntimeStateChange(): void {
426
- this._runtimeStateVersion.update((version) => version + 1);
427
- }
428
-
429
- // Public mutation methods
430
-
431
- /**
432
- * Update the runtime URL
433
- */
434
- setRuntimeUrl(url?: string): void {
435
- this._runtimeUrl.set(url);
436
- }
437
-
438
- /**
439
- * Update request headers
440
- */
441
- setHeaders(headers: Record<string, string>): void {
442
- this._headers.set(headers);
443
- }
444
-
445
- /**
446
- * Update runtime properties
447
- */
448
- setProperties(properties: Record<string, unknown>): void {
449
- this._properties.set(properties);
450
- }
451
-
452
- /**
453
- * Update agents configuration
454
- */
455
- setAgents(agents: Record<string, AbstractAgent>): void {
456
- this._agents.set(agents);
457
- }
458
-
459
- /**
460
- * Get an agent by ID
461
- * @param agentId - The agent ID to retrieve
462
- * @returns The agent or undefined if not found
463
- */
464
- getAgent(agentId: string): AbstractAgent | undefined {
465
- return this.copilotkit.getAgent(agentId);
466
- }
467
-
468
- /**
469
- * Update render tool calls (warns if object reference changes)
470
- */
471
- setRenderToolCalls(renderToolCalls: ToolCallRender<unknown>[]): void {
472
- if (renderToolCalls !== this.initialRenderToolCalls) {
473
- console.error(
474
- "renderToolCalls must be a stable object. To add/remove tools dynamically, use dynamic tool registration."
475
- );
476
- }
477
- this._renderToolCalls.set(renderToolCalls);
478
- }
479
-
480
- /**
481
- * Update frontend tools array
482
- */
483
- setFrontendTools(frontendTools: AngularFrontendTool<any>[]): void {
484
- if (frontendTools !== this.initialFrontendTools) {
485
- console.error(
486
- "frontendTools must be a stable array. To add/remove tools dynamically, use dynamic tool registration."
487
- );
488
- }
489
- this._frontendTools.set(frontendTools);
490
- }
491
-
492
- /**
493
- * Update human-in-the-loop array
494
- */
495
- setHumanInTheLoop(humanInTheLoop: AngularHumanInTheLoop<any>[]): void {
496
- if (humanInTheLoop !== this.initialHumanInTheLoop) {
497
- console.error(
498
- "humanInTheLoop must be a stable array. To add/remove human-in-the-loop tools dynamically, use dynamic tool registration."
499
- );
500
- }
501
- this._humanInTheLoop.set(humanInTheLoop);
502
- }
503
-
504
- /**
505
- * Update current render tool calls
506
- */
507
- setCurrentRenderToolCalls(renderToolCalls: ToolCallRender<unknown>[]): void {
508
- this._currentRenderToolCalls.set(renderToolCalls);
509
- }
510
-
511
- /**
512
- * Register a tool render
513
- */
514
- registerToolRender(name: string, render: ToolCallRender<unknown>): void {
515
- const current = this._currentRenderToolCalls();
516
- if (current.find((r) => r.name === name)) {
517
- console.warn(`Tool render for '${name}' is being overwritten`);
518
- }
519
- this._currentRenderToolCalls.set([
520
- ...current.filter((r) => r.name !== name),
521
- render,
522
- ]);
523
- }
524
-
525
- /**
526
- * Unregister a tool render
527
- */
528
- unregisterToolRender(name: string): void {
529
- const current = this._currentRenderToolCalls();
530
- const filtered = current.filter((r) => r.name !== name);
531
- if (filtered.length !== current.length) {
532
- this._currentRenderToolCalls.set(filtered);
533
- }
534
- }
535
-
536
- /**
537
- * Get a specific tool render
538
- */
539
- getToolRender(name: string): ToolCallRender<unknown> | undefined {
540
- return this._currentRenderToolCalls().find((r) => r.name === name);
541
- }
542
- }
@@ -1,132 +0,0 @@
1
- import { InjectionToken, TemplateRef, Type, Signal } from "@angular/core";
2
- import { Observable } from "rxjs";
3
- import { CopilotKitCore, ToolCallStatus } from "@copilotkitnext/core";
4
- import { AbstractAgent } from "@ag-ui/client";
5
- import type { z } from "zod";
6
- import type { AngularFrontendTool } from "../types/frontend-tool";
7
- import type { AngularHumanInTheLoop } from "../types/human-in-the-loop";
8
-
9
- // Re-export commonly used types
10
- export type { Context } from "@ag-ui/client";
11
-
12
- // Re-export tool types from their own files
13
- export type { AngularFrontendTool } from "../types/frontend-tool";
14
- export type {
15
- AngularHumanInTheLoop,
16
- HumanInTheLoopProps,
17
- } from "../types/human-in-the-loop";
18
-
19
- // Re-export ToolCallStatus from core
20
- export { ToolCallStatus } from "@copilotkitnext/core";
21
-
22
- // Props passed to tool render components - discriminated union matching React
23
- export type ToolCallProps<T = unknown> =
24
- | {
25
- name: string;
26
- description: string;
27
- args: Partial<T>;
28
- status: ToolCallStatus.InProgress;
29
- result: undefined;
30
- }
31
- | {
32
- name: string;
33
- description: string;
34
- args: T;
35
- status: ToolCallStatus.Executing;
36
- result: undefined;
37
- }
38
- | {
39
- name: string;
40
- description: string;
41
- args: T;
42
- status: ToolCallStatus.Complete;
43
- result: string;
44
- };
45
-
46
- // Angular-specific tool call render definition with proper typing
47
- export interface AngularToolCallRender<T = unknown> {
48
- name: string;
49
- args: z.ZodSchema<T>;
50
- /**
51
- * Optional agent ID to constrain this tool render to a specific agent.
52
- * If specified, this render will only be used for the specified agent.
53
- */
54
- agentId?: string;
55
- render: Type<any> | TemplateRef<ToolCallProps<T>>;
56
- }
57
-
58
- // Type alias for convenience
59
- export type ToolCallRender<T = unknown> = AngularToolCallRender<T>;
60
-
61
- export interface CopilotKitContextValue {
62
- copilotkit: CopilotKitCore;
63
- renderToolCalls: ToolCallRender<unknown>[];
64
- currentRenderToolCalls: ToolCallRender<unknown>[];
65
- setCurrentRenderToolCalls: (v: ToolCallRender<unknown>[]) => void;
66
- }
67
-
68
- export interface CopilotKitRuntimeInputs {
69
- runtimeUrl?: string;
70
- headers?: Record<string, string>;
71
- properties?: Record<string, unknown>;
72
- agents?: Record<string, AbstractAgent>;
73
- renderToolCalls?: ToolCallRender<unknown>[];
74
- }
75
-
76
- // Injection tokens for dependency injection
77
- export const COPILOTKIT_RUNTIME_URL = new InjectionToken<string | undefined>(
78
- "COPILOTKIT_RUNTIME_URL"
79
- );
80
-
81
- export const COPILOTKIT_HEADERS = new InjectionToken<Record<string, string>>(
82
- "COPILOTKIT_HEADERS",
83
- { factory: () => ({}) }
84
- );
85
-
86
- export const COPILOTKIT_PROPERTIES = new InjectionToken<
87
- Record<string, unknown>
88
- >("COPILOTKIT_PROPERTIES", { factory: () => ({}) });
89
-
90
- export const COPILOTKIT_AGENTS = new InjectionToken<
91
- Record<string, AbstractAgent>
92
- >("COPILOTKIT_AGENTS", { factory: () => ({}) });
93
-
94
- export const COPILOTKIT_RENDER_TOOL_CALLS = new InjectionToken<
95
- ToolCallRender<unknown>[]
96
- >("COPILOTKIT_RENDER_TOOL_CALLS", { factory: () => [] });
97
-
98
- export const COPILOTKIT_FRONTEND_TOOLS = new InjectionToken<
99
- AngularFrontendTool<any>[]
100
- >("COPILOTKIT_FRONTEND_TOOLS", { factory: () => [] });
101
-
102
- export const COPILOTKIT_HUMAN_IN_THE_LOOP = new InjectionToken<
103
- AngularHumanInTheLoop<any>[]
104
- >("COPILOTKIT_HUMAN_IN_THE_LOOP", { factory: () => [] });
105
-
106
- // Agent-related types
107
- import type { Message } from "@ag-ui/client";
108
-
109
- export interface AgentWatchResult {
110
- agent: Signal<AbstractAgent | undefined>;
111
- messages: Signal<Message[]>;
112
- isRunning: Signal<boolean>;
113
- agent$: Observable<AbstractAgent | undefined>;
114
- messages$: Observable<Message[]>;
115
- isRunning$: Observable<boolean>;
116
- unsubscribe: () => void;
117
- }
118
-
119
- export interface AgentSubscriptionCallbacks {
120
- onMessagesChanged?: (params: any) => void;
121
- onStateChanged?: (params: any) => void;
122
- onRunInitialized?: (params: any) => void;
123
- onRunFinalized?: (params: any) => void;
124
- onRunFailed?: (params: any) => void;
125
- }
126
-
127
- // Human-in-the-loop state result
128
- export interface HumanInTheLoopState {
129
- status: Signal<ToolCallStatus>;
130
- toolId: string;
131
- destroy: () => void;
132
- }