@copilotkitnext/angular 0.0.6 → 0.0.7

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.
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, signal, computed, effect, untracked, Inject, Injectable, Optional, inject, DestroyRef, ChangeDetectionStrategy, Component, ElementRef, ViewContainerRef, HostListener, Input, Directive, isDevMode, EventEmitter, Output, TemplateRef, ViewChild, ViewEncapsulation, ContentChild, ChangeDetectorRef, PLATFORM_ID, forwardRef, runInInjectionContext, SkipSelf } from '@angular/core';
2
+ import { InjectionToken, signal, computed, effect, untracked, Inject, Injectable, Optional, inject, DestroyRef, runInInjectionContext, ChangeDetectionStrategy, Component, ElementRef, ViewContainerRef, HostListener, Input, Directive, isDevMode, EventEmitter, Output, TemplateRef, ViewChild, ViewEncapsulation, ContentChild, ChangeDetectorRef, PLATFORM_ID, forwardRef, SkipSelf } from '@angular/core';
3
3
  import { toObservable } from '@angular/core/rxjs-interop';
4
4
  import { CopilotKitCore, ToolCallStatus, completePartialMarkdown } from '@copilotkitnext/core';
5
5
  export { ToolCallStatus } from '@copilotkitnext/core';
@@ -1191,6 +1191,32 @@ function getAgent(service, agentId) {
1191
1191
  const effectiveAgentId = agentId ?? DEFAULT_AGENT_ID;
1192
1192
  return service.copilotkit.getAgent(effectiveAgentId);
1193
1193
  }
1194
+ /**
1195
+ * Convenience wrapper for watchAgent that handles injection context.
1196
+ * Useful when you need to call watchAgent outside of a constructor or field initializer.
1197
+ *
1198
+ * @param injector - The Angular Injector to use for injection context
1199
+ * @param config - Optional configuration with agentId
1200
+ * @returns Object with agent, messages, and isRunning signals plus observables
1201
+ *
1202
+ * @example
1203
+ * ```typescript
1204
+ * export class MyComponent {
1205
+ * constructor(private injector: Injector) {}
1206
+ *
1207
+ * switchAgent(newAgentId: string) {
1208
+ * // Can call outside of constructor using watchAgentWith
1209
+ * const watcher = watchAgentWith(this.injector, { agentId: newAgentId });
1210
+ * this.agent = watcher.agent;
1211
+ * this.messages = watcher.messages;
1212
+ * this.isRunning = watcher.isRunning;
1213
+ * }
1214
+ * }
1215
+ * ```
1216
+ */
1217
+ function watchAgentWith(injector, config) {
1218
+ return runInInjectionContext(injector, () => watchAgent(config));
1219
+ }
1194
1220
  /**
1195
1221
  * Subscribes to an agent's events with custom callbacks.
1196
1222
  * Returns a cleanup function that should be called to unsubscribe.
@@ -1237,24 +1263,6 @@ function subscribeToAgent(service, agentId, callbacks) {
1237
1263
  });
1238
1264
  return () => subscription.unsubscribe();
1239
1265
  }
1240
- /**
1241
- * Registers an agent watcher that automatically cleans up on component destroy.
1242
- * This is an alias for watchAgent with a more explicit name.
1243
- * Must be called within an injection context.
1244
- *
1245
- * @param config - Optional configuration with agentId
1246
- * @returns Object with agent, messages, and isRunning signals plus observables
1247
- *
1248
- * @example
1249
- * ```typescript
1250
- * export class MyComponent {
1251
- * agentState = registerAgentWatcher({ agentId: 'my-agent' });
1252
- * }
1253
- * ```
1254
- */
1255
- function registerAgentWatcher(config) {
1256
- return watchAgent(config);
1257
- }
1258
1266
 
1259
1267
  /**
1260
1268
  * Registers a human-in-the-loop tool that requires user interaction.
@@ -9143,15 +9151,14 @@ class CopilotChatComponent {
9143
9151
  }
9144
9152
  }, { allowSignalWrites: true });
9145
9153
  }
9146
- // Signals from watchAgent - using direct references instead of assignment
9147
- agent = signal(undefined).asReadonly();
9148
- messages = signal([]).asReadonly();
9149
- isRunning = signal(false).asReadonly();
9154
+ // Signals from watchAgent - destructured from watcher
9155
+ agent;
9156
+ messages;
9157
+ isRunning;
9150
9158
  showCursor = signal(false);
9151
9159
  generatedThreadId = randomUUID();
9152
- agentWatcher;
9160
+ watcher;
9153
9161
  hasConnectedOnce = false;
9154
- lastAgentId;
9155
9162
  ngOnInit() {
9156
9163
  this.setupChatHandlers();
9157
9164
  }
@@ -9238,24 +9245,18 @@ class CopilotChatComponent {
9238
9245
  // Keep input state if needed
9239
9246
  });
9240
9247
  }
9241
- ngOnDestroy() {
9242
- if (this.agentWatcher?.unsubscribe) {
9243
- this.agentWatcher.unsubscribe();
9244
- }
9245
- }
9246
9248
  createWatcher(desiredAgentId) {
9247
- // Tear down previous watcher if it exists
9248
- if (this.agentWatcher?.unsubscribe) {
9249
- this.agentWatcher.unsubscribe();
9250
- this.agentWatcher = undefined;
9251
- }
9252
- // Setup watcher for desired agent - ensure injection context
9253
- this.agentWatcher = runInInjectionContext(this.injector, () => watchAgent({ agentId: desiredAgentId }));
9254
- this.agent = this.agentWatcher.agent;
9255
- this.messages = this.agentWatcher.messages;
9256
- this.isRunning = this.agentWatcher.isRunning;
9249
+ // Tear down previous watcher if it exists to prevent parallel subscriptions
9250
+ this.watcher?.unsubscribe();
9251
+ // Create new watcher using the ergonomic helper
9252
+ const w = watchAgentWith(this.injector, { agentId: desiredAgentId });
9253
+ // Destructure signals directly to class fields
9254
+ this.agent = w.agent;
9255
+ this.messages = w.messages;
9256
+ this.isRunning = w.isRunning;
9257
+ this.watcher = w;
9258
+ // Reset connection state for new agent
9257
9259
  this.hasConnectedOnce = false;
9258
- this.lastAgentId = desiredAgentId;
9259
9260
  }
9260
9261
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: CopilotChatComponent, deps: [{ token: CopilotChatConfigurationService, optional: true }, { token: i0.ChangeDetectorRef }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Component });
9261
9262
  static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: CopilotChatComponent, isStandalone: true, selector: "copilot-chat", inputs: { agentId: "agentId", threadId: "threadId" }, providers: [
@@ -9320,5 +9321,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImpo
9320
9321
  * Generated bundle index. Do not edit.
9321
9322
  */
9322
9323
 
9323
- export { AudioRecorderError, COPILOTKIT_AGENTS, COPILOTKIT_FRONTEND_TOOLS, COPILOTKIT_HEADERS, COPILOTKIT_HUMAN_IN_THE_LOOP, COPILOTKIT_PROPERTIES, COPILOTKIT_RENDER_TOOL_CALLS, COPILOTKIT_RUNTIME_URL, COPILOT_CHAT_DEFAULT_LABELS, COPILOT_CHAT_INITIAL_CONFIG, CopilotChatAddFileButtonComponent, CopilotChatAssistantMessageComponent, CopilotChatAssistantMessageCopyButtonComponent, CopilotChatAssistantMessageReadAloudButtonComponent, CopilotChatAssistantMessageRegenerateButtonComponent, CopilotChatAssistantMessageRendererComponent, CopilotChatAssistantMessageThumbsDownButtonComponent, CopilotChatAssistantMessageThumbsUpButtonComponent, CopilotChatAssistantMessageToolbarButtonComponent, CopilotChatAssistantMessageToolbarComponent, CopilotChatAudioRecorderComponent, CopilotChatCancelTranscribeButtonComponent, CopilotChatComponent, CopilotChatConfigurationService, CopilotChatFinishTranscribeButtonComponent, CopilotChatInputComponent, CopilotChatInputDefaults, CopilotChatMessageViewComponent, CopilotChatMessageViewCursorComponent, CopilotChatSendButtonComponent, CopilotChatStartTranscribeButtonComponent, CopilotChatTextareaComponent, CopilotChatToolCallsViewComponent, CopilotChatToolbarButtonComponent, CopilotChatToolbarComponent, CopilotChatToolsMenuComponent, CopilotChatUserMessageBranchNavigationComponent, CopilotChatUserMessageComponent, CopilotChatUserMessageCopyButtonComponent, CopilotChatUserMessageEditButtonComponent, CopilotChatUserMessageRendererComponent, CopilotChatUserMessageToolbarButtonComponent, CopilotChatUserMessageToolbarComponent, CopilotChatViewComponent, CopilotChatViewDisclaimerComponent, CopilotChatViewFeatherComponent, CopilotChatViewInputContainerComponent, CopilotChatViewScrollToBottomButtonComponent, CopilotChatViewScrollViewComponent, CopilotKitAgentContextDirective, CopilotKitAgentDirective, CopilotKitChatConfigDirective, CopilotKitConfigDirective, CopilotKitFrontendToolDirective, CopilotKitHumanInTheLoopDirective, CopilotKitHumanInTheLoopRespondDirective, CopilotKitService, CopilotKitToolRenderComponent, CopilotTooltipDirective, ResizeObserverService, ScrollPositionService, StickToBottomDirective, addAgentContext, addFrontendTool, addHumanInTheLoop, createChatConfigController, createDynamicFrontendTool, createHumanInTheLoop, createReactiveContext, enhancePropsForHumanInTheLoop, getAgent, getChatInputValue, getChatLabels, injectCopilotKit, provideCopilotChatConfiguration, provideCopilotKit, registerAgentContext, registerAgentWatcher, registerChatConfig, registerFrontendTool, registerHumanInTheLoop, removeFrontendTool, setChatInputValue, setChatLabels, subscribeToAgent, watchAgent, watchChatConfig };
9324
+ export { AudioRecorderError, COPILOTKIT_AGENTS, COPILOTKIT_FRONTEND_TOOLS, COPILOTKIT_HEADERS, COPILOTKIT_HUMAN_IN_THE_LOOP, COPILOTKIT_PROPERTIES, COPILOTKIT_RENDER_TOOL_CALLS, COPILOTKIT_RUNTIME_URL, COPILOT_CHAT_DEFAULT_LABELS, COPILOT_CHAT_INITIAL_CONFIG, CopilotChatAddFileButtonComponent, CopilotChatAssistantMessageComponent, CopilotChatAssistantMessageCopyButtonComponent, CopilotChatAssistantMessageReadAloudButtonComponent, CopilotChatAssistantMessageRegenerateButtonComponent, CopilotChatAssistantMessageRendererComponent, CopilotChatAssistantMessageThumbsDownButtonComponent, CopilotChatAssistantMessageThumbsUpButtonComponent, CopilotChatAssistantMessageToolbarButtonComponent, CopilotChatAssistantMessageToolbarComponent, CopilotChatAudioRecorderComponent, CopilotChatCancelTranscribeButtonComponent, CopilotChatComponent, CopilotChatConfigurationService, CopilotChatFinishTranscribeButtonComponent, CopilotChatInputComponent, CopilotChatInputDefaults, CopilotChatMessageViewComponent, CopilotChatMessageViewCursorComponent, CopilotChatSendButtonComponent, CopilotChatStartTranscribeButtonComponent, CopilotChatTextareaComponent, CopilotChatToolCallsViewComponent, CopilotChatToolbarButtonComponent, CopilotChatToolbarComponent, CopilotChatToolsMenuComponent, CopilotChatUserMessageBranchNavigationComponent, CopilotChatUserMessageComponent, CopilotChatUserMessageCopyButtonComponent, CopilotChatUserMessageEditButtonComponent, CopilotChatUserMessageRendererComponent, CopilotChatUserMessageToolbarButtonComponent, CopilotChatUserMessageToolbarComponent, CopilotChatViewComponent, CopilotChatViewDisclaimerComponent, CopilotChatViewFeatherComponent, CopilotChatViewInputContainerComponent, CopilotChatViewScrollToBottomButtonComponent, CopilotChatViewScrollViewComponent, CopilotKitAgentContextDirective, CopilotKitAgentDirective, CopilotKitChatConfigDirective, CopilotKitConfigDirective, CopilotKitFrontendToolDirective, CopilotKitHumanInTheLoopDirective, CopilotKitHumanInTheLoopRespondDirective, CopilotKitService, CopilotKitToolRenderComponent, CopilotTooltipDirective, ResizeObserverService, ScrollPositionService, StickToBottomDirective, addAgentContext, addFrontendTool, addHumanInTheLoop, createChatConfigController, createDynamicFrontendTool, createHumanInTheLoop, createReactiveContext, enhancePropsForHumanInTheLoop, getAgent, getChatInputValue, getChatLabels, injectCopilotKit, provideCopilotChatConfiguration, provideCopilotKit, registerAgentContext, registerChatConfig, registerFrontendTool, registerHumanInTheLoop, removeFrontendTool, setChatInputValue, setChatLabels, subscribeToAgent, watchAgent, watchAgentWith, watchChatConfig };
9324
9325
  //# sourceMappingURL=copilotkitnext-angular.mjs.map