@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,133 +0,0 @@
1
- import { DestroyRef, inject } from '@angular/core';
2
- import { CopilotKitService } from '../core/copilotkit.service';
3
- import { Context } from '@ag-ui/client';
4
-
5
- /**
6
- * Programmatically adds an agent context to CopilotKit and returns a cleanup function.
7
- *
8
- * @param context - The context to add
9
- * @returns A cleanup function that removes the context
10
- *
11
- * @example
12
- * ```typescript
13
- * export class MyComponent implements OnInit {
14
- * private copilotkit = injectCopilotKit();
15
- *
16
- * ngOnInit() {
17
- * const cleanup = addAgentContext(this.copilotkit, {
18
- * description: 'User preferences',
19
- * value: this.userSettings
20
- * });
21
- *
22
- * // Store cleanup for later or register with DestroyRef
23
- * this.cleanupFns.push(cleanup);
24
- * }
25
- * }
26
- * ```
27
- */
28
- export function addAgentContext(
29
- copilotkit: CopilotKitService,
30
- context: Context
31
- ): () => void {
32
- const contextId = copilotkit.copilotkit.addContext(context);
33
-
34
- return () => {
35
- copilotkit.copilotkit.removeContext(contextId);
36
- };
37
- }
38
-
39
- /**
40
- * Registers an agent context with CopilotKit and automatically removes it when the component/service is destroyed.
41
- * Must be called within an injection context.
42
- *
43
- * @param context - The context to add
44
- * @returns The context ID
45
- *
46
- * @example
47
- * ```typescript
48
- * export class MyComponent implements OnInit {
49
- * ngOnInit() {
50
- * // Automatically cleaned up on component destroy
51
- * registerAgentContext({
52
- * description: 'Component state',
53
- * value: this.state
54
- * });
55
- * }
56
- * }
57
- * ```
58
- */
59
- export function registerAgentContext(context: Context): string {
60
- const copilotkit = inject(CopilotKitService);
61
- const destroyRef = inject(DestroyRef);
62
-
63
- const contextId = copilotkit.copilotkit.addContext(context);
64
-
65
- // Register cleanup with Angular's DestroyRef
66
- destroyRef.onDestroy(() => {
67
- copilotkit.copilotkit.removeContext(contextId);
68
- });
69
-
70
- return contextId;
71
- }
72
-
73
- /**
74
- * Creates a reactive context that updates whenever the value changes.
75
- * Uses Angular signals for reactivity.
76
- *
77
- * @param description - Static or signal-based description
78
- * @param value - Signal that provides the context value
79
- * @returns Object with update and destroy methods
80
- *
81
- * @example
82
- * ```typescript
83
- * export class MyComponent {
84
- * private userSettings = signal({ theme: 'dark' });
85
- *
86
- * ngOnInit() {
87
- * const context = createReactiveContext(
88
- * 'User settings',
89
- * computed(() => this.userSettings())
90
- * );
91
- *
92
- * // Updates automatically when userSettings signal changes
93
- * }
94
- * }
95
- * ```
96
- */
97
- export function createReactiveContext(
98
- description: string | (() => string),
99
- value: () => any
100
- ): { update: () => void; destroy: () => void } {
101
- const copilotkit = inject(CopilotKitService);
102
- let currentContextId: string | undefined;
103
-
104
- const update = () => {
105
- // Remove old context if it exists
106
- if (currentContextId) {
107
- copilotkit.copilotkit.removeContext(currentContextId);
108
- }
109
-
110
- // Add new context
111
- const desc = typeof description === 'function' ? description() : description;
112
- currentContextId = copilotkit.copilotkit.addContext({
113
- description: desc,
114
- value: value()
115
- });
116
- };
117
-
118
- const destroy = () => {
119
- if (currentContextId) {
120
- copilotkit.copilotkit.removeContext(currentContextId);
121
- currentContextId = undefined;
122
- }
123
- };
124
-
125
- // Initial setup
126
- update();
127
-
128
- // Register cleanup
129
- const destroyRef = inject(DestroyRef);
130
- destroyRef.onDestroy(destroy);
131
-
132
- return { update, destroy };
133
- }
@@ -1,239 +0,0 @@
1
- import { DestroyRef, inject, signal, computed } from "@angular/core";
2
- import { toObservable } from "@angular/core/rxjs-interop";
3
- import { CopilotKitService } from "../core/copilotkit.service";
4
- import {
5
- AgentSubscriptionCallbacks,
6
- AgentWatchResult,
7
- } from "../core/copilotkit.types";
8
- import { AbstractAgent } from "@ag-ui/client";
9
- import { DEFAULT_AGENT_ID } from "@copilotkitnext/shared";
10
-
11
- /**
12
- * Watches an agent and provides reactive signals for its state.
13
- * Must be called within an injection context.
14
- * Automatically cleans up when the component/service is destroyed.
15
- *
16
- * @param config - Optional configuration with agentId
17
- * @returns Object with agent, messages, and isRunning signals plus observables
18
- *
19
- * @example
20
- * ```typescript
21
- * export class MyComponent {
22
- * // Automatically tracks agent state
23
- * agentState = watchAgent({ agentId: 'my-agent' });
24
- *
25
- * constructor() {
26
- * effect(() => {
27
- * const messages = this.agentState.messages();
28
- * const isRunning = this.agentState.isRunning();
29
- * console.log('Messages:', messages.length, 'Running:', isRunning);
30
- * });
31
- * }
32
- * }
33
- * ```
34
- */
35
- export function watchAgent(config?: { agentId?: string }): AgentWatchResult {
36
- // Use inject() internally to get required services
37
- const service = inject(CopilotKitService);
38
- const destroyRef = inject(DestroyRef);
39
- const effectiveAgentId = config?.agentId ?? DEFAULT_AGENT_ID;
40
-
41
- // Create reactive signals with tick mechanism for reliable updates
42
- const agentSignal = signal<AbstractAgent | undefined>(undefined);
43
- const tick = signal<number>(0);
44
- const isRunningSignal = signal<boolean>(false);
45
-
46
- // Create computed messages signal that reacts to tick changes
47
- const messages = computed(() => {
48
- // Access tick to ensure recomputation
49
- tick();
50
- const a = agentSignal();
51
- if (!a) return [];
52
- // Return a shallow clone to ensure change detection
53
- return a.messages.map((m) => ({ ...m }));
54
- });
55
-
56
- // Get initial agent
57
- const updateAgent = () => {
58
- const agent = service.copilotkit.getAgent(effectiveAgentId);
59
- agentSignal.set(agent);
60
- return agent;
61
- };
62
-
63
- // Initial update
64
- let currentAgent = updateAgent();
65
-
66
- // Subscribe to agent changes
67
- let agentSubscription: { unsubscribe: () => void } | undefined;
68
-
69
- const subscribeToAgent = () => {
70
- // Unsubscribe from previous agent if any
71
- agentSubscription?.unsubscribe();
72
-
73
- if (currentAgent) {
74
- agentSubscription = currentAgent.subscribe({
75
- onMessagesChanged() {
76
- // Increment tick to force recomputation of messages computed
77
- tick.update((v) => v + 1);
78
- },
79
- onStateChanged() {
80
- // Increment tick to force recomputation
81
- tick.update((v) => v + 1);
82
- },
83
- onRunInitialized() {
84
- isRunningSignal.set(true);
85
- },
86
- onRunFinalized() {
87
- isRunningSignal.set(false);
88
- },
89
- onRunFailed() {
90
- isRunningSignal.set(false);
91
- },
92
- });
93
- }
94
- };
95
-
96
- // Initial subscription
97
- subscribeToAgent();
98
-
99
- // Subscribe to CopilotKit changes to detect agent updates
100
- const coreUnsubscribe = service.copilotkit.subscribe({
101
- onRuntimeLoaded() {
102
- // Re-check agent when runtime loads
103
- currentAgent = updateAgent();
104
- subscribeToAgent();
105
- },
106
- onRuntimeLoadError() {
107
- // Also re-check agent on runtime load error to ensure consistency
108
- currentAgent = updateAgent();
109
- subscribeToAgent();
110
- },
111
- });
112
-
113
- // Register cleanup
114
- const unsubscribe = () => {
115
- agentSubscription?.unsubscribe();
116
- coreUnsubscribe(); // subscribe returns a function directly
117
- };
118
-
119
- destroyRef.onDestroy(unsubscribe);
120
-
121
- // Create observables from signals using toObservable
122
- const agent$ = toObservable(agentSignal);
123
- const isRunning$ = toObservable(isRunningSignal);
124
- const messages$ = toObservable(messages);
125
-
126
- return {
127
- agent: agentSignal.asReadonly(),
128
- messages: messages,
129
- isRunning: isRunningSignal.asReadonly(),
130
- agent$,
131
- messages$,
132
- isRunning$,
133
- unsubscribe,
134
- };
135
- }
136
-
137
- /**
138
- * Gets an agent by ID without subscribing to changes.
139
- *
140
- * @param service - The CopilotKitService instance
141
- * @param agentId - Optional agent ID (defaults to DEFAULT_AGENT_ID)
142
- * @returns The agent or undefined if not found
143
- *
144
- * @example
145
- * ```typescript
146
- * export class MyComponent {
147
- * constructor(private copilotkit: CopilotKitService) {}
148
- *
149
- * getCurrentAgent() {
150
- * return getAgent(this.copilotkit, 'my-agent');
151
- * }
152
- * }
153
- * ```
154
- */
155
- export function getAgent(
156
- service: CopilotKitService,
157
- agentId?: string
158
- ): AbstractAgent | undefined {
159
- const effectiveAgentId = agentId ?? DEFAULT_AGENT_ID;
160
- return service.copilotkit.getAgent(effectiveAgentId);
161
- }
162
-
163
- // Re-export the type for convenience (the actual type is in copilotkit.types)
164
- export type { AgentWatchResult } from "../core/copilotkit.types";
165
-
166
- /**
167
- * Subscribes to an agent's events with custom callbacks.
168
- * Returns a cleanup function that should be called to unsubscribe.
169
- *
170
- * @param service - The CopilotKitService instance
171
- * @param agentId - Optional agent ID (defaults to DEFAULT_AGENT_ID)
172
- * @param callbacks - Event callbacks
173
- * @returns Cleanup function to unsubscribe
174
- *
175
- * @example
176
- * ```typescript
177
- * export class MyComponent implements OnInit, OnDestroy {
178
- * private unsubscribe?: () => void;
179
- *
180
- * constructor(private copilotkit: CopilotKitService) {}
181
- *
182
- * ngOnInit() {
183
- * this.unsubscribe = subscribeToAgent(this.copilotkit, 'my-agent', {
184
- * onRunInitialized: () => console.log('Run started'),
185
- * onRunFinalized: () => console.log('Run completed'),
186
- * onRunFailed: (error) => console.error('Run failed', error),
187
- * });
188
- * }
189
- *
190
- * ngOnDestroy() {
191
- * this.unsubscribe?.();
192
- * }
193
- * }
194
- * ```
195
- */
196
- export function subscribeToAgent(
197
- service: CopilotKitService,
198
- agentId?: string,
199
- callbacks?: AgentSubscriptionCallbacks
200
- ): () => void {
201
- const effectiveAgentId = agentId ?? DEFAULT_AGENT_ID;
202
- const agent = service.copilotkit.getAgent(effectiveAgentId);
203
-
204
- if (!agent) {
205
- // Return no-op cleanup if agent doesn't exist
206
- return () => {};
207
- }
208
-
209
- const subscription = agent.subscribe({
210
- onMessagesChanged: callbacks?.onMessagesChanged,
211
- onStateChanged: callbacks?.onStateChanged,
212
- onRunInitialized: callbacks?.onRunInitialized,
213
- onRunFinalized: callbacks?.onRunFinalized,
214
- onRunFailed: callbacks?.onRunFailed,
215
- });
216
-
217
- return () => subscription.unsubscribe();
218
- }
219
-
220
- /**
221
- * Registers an agent watcher that automatically cleans up on component destroy.
222
- * This is an alias for watchAgent with a more explicit name.
223
- * Must be called within an injection context.
224
- *
225
- * @param config - Optional configuration with agentId
226
- * @returns Object with agent, messages, and isRunning signals plus observables
227
- *
228
- * @example
229
- * ```typescript
230
- * export class MyComponent {
231
- * agentState = registerAgentWatcher({ agentId: 'my-agent' });
232
- * }
233
- * ```
234
- */
235
- export function registerAgentWatcher(config?: {
236
- agentId?: string;
237
- }): AgentWatchResult {
238
- return watchAgent(config);
239
- }
@@ -1,221 +0,0 @@
1
- import { inject, Signal } from '@angular/core';
2
- import { CopilotChatConfigurationService } from '../core/chat-configuration/chat-configuration.service';
3
- import {
4
- CopilotChatConfiguration,
5
- CopilotChatLabels
6
- } from '../core/chat-configuration/chat-configuration.types';
7
-
8
- /**
9
- * Watches chat configuration and provides reactive access to all configuration values.
10
- * Must be called within an injection context.
11
- *
12
- * @returns Object with reactive signals and handler functions
13
- *
14
- * @example
15
- * ```typescript
16
- * export class ChatInputComponent {
17
- * config = watchChatConfig();
18
- *
19
- * constructor() {
20
- * effect(() => {
21
- * const placeholder = this.config.labels().chatInputPlaceholder;
22
- * console.log('Placeholder:', placeholder);
23
- * });
24
- * }
25
- *
26
- * handleSubmit(value: string) {
27
- * this.config.submitInput(value);
28
- * }
29
- * }
30
- * ```
31
- */
32
- export function watchChatConfig(): {
33
- labels: Signal<CopilotChatLabels>;
34
- inputValue: Signal<string | undefined>;
35
- submitInput: (value: string) => void;
36
- changeInput: (value: string) => void;
37
- } {
38
- const service = inject(CopilotChatConfigurationService);
39
-
40
- return {
41
- labels: service.labels,
42
- inputValue: service.inputValue,
43
- submitInput: (value: string) => service.submitInput(value),
44
- changeInput: (value: string) => service.changeInput(value)
45
- };
46
- }
47
-
48
- /**
49
- * Registers chat configuration within an injection context.
50
- * Automatically updates the configuration when called.
51
- *
52
- * @param config - The configuration to register
53
- *
54
- * @example
55
- * ```typescript
56
- * export class ChatComponent {
57
- * constructor() {
58
- * registerChatConfig({
59
- * labels: {
60
- * chatInputPlaceholder: "How can I help?"
61
- * },
62
- * onSubmitInput: (value) => this.handleSubmit(value)
63
- * });
64
- * }
65
- * }
66
- * ```
67
- */
68
- export function registerChatConfig(config: CopilotChatConfiguration): void {
69
- const service = inject(CopilotChatConfigurationService);
70
- service.updateConfiguration(config);
71
- }
72
-
73
- /**
74
- * Gets the current chat labels signal.
75
- *
76
- * @param service - The CopilotChatConfigurationService instance
77
- * @returns Signal containing the current labels
78
- *
79
- * @example
80
- * ```typescript
81
- * export class ChatComponent {
82
- * constructor(private chatConfig: CopilotChatConfigurationService) {
83
- * const labels = getChatLabels(this.chatConfig);
84
- * effect(() => {
85
- * console.log('Current labels:', labels());
86
- * });
87
- * }
88
- * }
89
- * ```
90
- */
91
- export function getChatLabels(
92
- service: CopilotChatConfigurationService
93
- ): Signal<CopilotChatLabels> {
94
- return service.labels;
95
- }
96
-
97
- /**
98
- * Updates chat labels.
99
- *
100
- * @param service - The CopilotChatConfigurationService instance
101
- * @param labels - Partial labels to merge with defaults
102
- *
103
- * @example
104
- * ```typescript
105
- * export class ChatComponent {
106
- * updatePlaceholder(text: string) {
107
- * setChatLabels(this.chatConfig, {
108
- * chatInputPlaceholder: text
109
- * });
110
- * }
111
- * }
112
- * ```
113
- */
114
- export function setChatLabels(
115
- service: CopilotChatConfigurationService,
116
- labels: Partial<CopilotChatLabels>
117
- ): void {
118
- service.setLabels(labels);
119
- }
120
-
121
- /**
122
- * Gets the current input value signal.
123
- *
124
- * @param service - The CopilotChatConfigurationService instance
125
- * @returns Signal containing the current input value
126
- *
127
- * @example
128
- * ```typescript
129
- * export class ChatInputComponent {
130
- * inputValue = getChatInputValue(this.chatConfig);
131
- *
132
- * constructor(private chatConfig: CopilotChatConfigurationService) {
133
- * effect(() => {
134
- * const value = this.inputValue();
135
- * if (value) {
136
- * this.updateTextarea(value);
137
- * }
138
- * });
139
- * }
140
- * }
141
- * ```
142
- */
143
- export function getChatInputValue(
144
- service: CopilotChatConfigurationService
145
- ): Signal<string | undefined> {
146
- return service.inputValue;
147
- }
148
-
149
- /**
150
- * Sets the current input value.
151
- *
152
- * @param service - The CopilotChatConfigurationService instance
153
- * @param value - The new input value
154
- *
155
- * @example
156
- * ```typescript
157
- * export class ChatInputComponent {
158
- * onInputChange(event: Event) {
159
- * const value = (event.target as HTMLInputElement).value;
160
- * setChatInputValue(this.chatConfig, value);
161
- * }
162
- * }
163
- * ```
164
- */
165
- export function setChatInputValue(
166
- service: CopilotChatConfigurationService,
167
- value: string | undefined
168
- ): void {
169
- service.setInputValue(value);
170
- }
171
-
172
- /**
173
- * Creates a chat configuration controller with dynamic update capabilities.
174
- * This is useful when you need to programmatically manage configuration.
175
- *
176
- * @param service - The CopilotChatConfigurationService instance
177
- * @param initialConfig - Optional initial configuration
178
- * @returns Controller object with update and reset methods
179
- *
180
- * @example
181
- * ```typescript
182
- * export class ChatManagerComponent {
183
- * chatController = createChatConfigController(this.chatConfig, {
184
- * labels: { chatInputPlaceholder: "Ask me..." }
185
- * });
186
- *
187
- * constructor(private chatConfig: CopilotChatConfigurationService) {}
188
- *
189
- * updateForSupportMode() {
190
- * this.chatController.update({
191
- * labels: { chatInputPlaceholder: "Describe your issue..." }
192
- * });
193
- * }
194
- *
195
- * resetToDefaults() {
196
- * this.chatController.reset();
197
- * }
198
- * }
199
- * ```
200
- */
201
- export function createChatConfigController(
202
- service: CopilotChatConfigurationService,
203
- initialConfig?: CopilotChatConfiguration
204
- ): {
205
- update: (config: CopilotChatConfiguration) => void;
206
- reset: () => void;
207
- getLabels: () => CopilotChatLabels;
208
- getInputValue: () => string | undefined;
209
- } {
210
- // Apply initial configuration if provided
211
- if (initialConfig) {
212
- service.updateConfiguration(initialConfig);
213
- }
214
-
215
- return {
216
- update: (config: CopilotChatConfiguration) => service.updateConfiguration(config),
217
- reset: () => service.reset(),
218
- getLabels: () => service.labels(),
219
- getInputValue: () => service.inputValue()
220
- };
221
- }
@@ -1,20 +0,0 @@
1
- import { inject } from "@angular/core";
2
- import { CopilotKitService } from "../core/copilotkit.service";
3
-
4
- /**
5
- * Utility function to inject the CopilotKit service in a component or directive.
6
- *
7
- * @example
8
- * ```typescript
9
- * export class MyComponent {
10
- * private copilotkit = injectCopilotKit();
11
- *
12
- * sendMessage() {
13
- * this.copilotkit.copilotkit.sendMessage(...);
14
- * }
15
- * }
16
- * ```
17
- */
18
- export function injectCopilotKit() {
19
- return inject(CopilotKitService);
20
- }