@copilotkitnext/angular 0.0.6 → 0.0.8

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.
@@ -4559,7 +4567,7 @@ class CopilotChatInputComponent {
4559
4567
  else if (this.audioRecorderRef?.getState() === 'recording') {
4560
4568
  this.audioRecorderRef.stop().catch(console.error);
4561
4569
  }
4562
- });
4570
+ }, { allowSignalWrites: true });
4563
4571
  // Sync with chat configuration
4564
4572
  effect(() => {
4565
4573
  const configValue = this.chatConfig?.inputValue();
@@ -9116,6 +9124,7 @@ class CopilotChatComponent {
9116
9124
  injector;
9117
9125
  agentId;
9118
9126
  threadId;
9127
+ inputComponent;
9119
9128
  constructor(chatConfig, cdr, injector) {
9120
9129
  this.chatConfig = chatConfig;
9121
9130
  this.cdr = cdr;
@@ -9143,15 +9152,14 @@ class CopilotChatComponent {
9143
9152
  }
9144
9153
  }, { allowSignalWrites: true });
9145
9154
  }
9146
- // Signals from watchAgent - using direct references instead of assignment
9147
- agent = signal(undefined).asReadonly();
9148
- messages = signal([]).asReadonly();
9149
- isRunning = signal(false).asReadonly();
9155
+ // Signals from watchAgent - destructured from watcher
9156
+ agent;
9157
+ messages;
9158
+ isRunning;
9150
9159
  showCursor = signal(false);
9151
9160
  generatedThreadId = randomUUID();
9152
- agentWatcher;
9161
+ watcher;
9153
9162
  hasConnectedOnce = false;
9154
- lastAgentId;
9155
9163
  ngOnInit() {
9156
9164
  this.setupChatHandlers();
9157
9165
  }
@@ -9238,27 +9246,21 @@ class CopilotChatComponent {
9238
9246
  // Keep input state if needed
9239
9247
  });
9240
9248
  }
9241
- ngOnDestroy() {
9242
- if (this.agentWatcher?.unsubscribe) {
9243
- this.agentWatcher.unsubscribe();
9244
- }
9245
- }
9246
9249
  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;
9250
+ // Tear down previous watcher if it exists to prevent parallel subscriptions
9251
+ this.watcher?.unsubscribe();
9252
+ // Create new watcher using the ergonomic helper
9253
+ const w = watchAgentWith(this.injector, { agentId: desiredAgentId });
9254
+ // Destructure signals directly to class fields
9255
+ this.agent = w.agent;
9256
+ this.messages = w.messages;
9257
+ this.isRunning = w.isRunning;
9258
+ this.watcher = w;
9259
+ // Reset connection state for new agent
9257
9260
  this.hasConnectedOnce = false;
9258
- this.lastAgentId = desiredAgentId;
9259
9261
  }
9260
9262
  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
- 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: [
9263
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: CopilotChatComponent, isStandalone: true, selector: "copilot-chat", inputs: { agentId: "agentId", threadId: "threadId", inputComponent: "inputComponent" }, providers: [
9262
9264
  {
9263
9265
  provide: CopilotChatConfigurationService,
9264
9266
  deps: [
@@ -9273,6 +9275,7 @@ class CopilotChatComponent {
9273
9275
  [autoScroll]="true"
9274
9276
  [messageViewClass]="'w-full'"
9275
9277
  [showCursor]="showCursor()"
9278
+ [inputComponent]="inputComponent"
9276
9279
  >
9277
9280
  </copilot-chat-view>
9278
9281
  `, isInline: true, dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "component", type: CopilotChatViewComponent, selector: "copilot-chat-view", inputs: ["messages", "autoScroll", "showCursor", "messageViewComponent", "messageViewTemplate", "messageViewClass", "scrollViewComponent", "scrollViewTemplate", "scrollViewClass", "scrollToBottomButtonComponent", "scrollToBottomButtonTemplate", "scrollToBottomButtonClass", "inputComponent", "inputTemplate", "inputContainerComponent", "inputContainerTemplate", "inputContainerClass", "featherComponent", "featherTemplate", "featherClass", "disclaimerComponent", "disclaimerTemplate", "disclaimerClass", "disclaimerText"], outputs: ["assistantMessageThumbsUp", "assistantMessageThumbsDown", "assistantMessageReadAloud", "assistantMessageRegenerate", "userMessageCopy", "userMessageEdit"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
@@ -9301,6 +9304,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImpo
9301
9304
  [autoScroll]="true"
9302
9305
  [messageViewClass]="'w-full'"
9303
9306
  [showCursor]="showCursor()"
9307
+ [inputComponent]="inputComponent"
9304
9308
  >
9305
9309
  </copilot-chat-view>
9306
9310
  `,
@@ -9311,6 +9315,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImpo
9311
9315
  type: Input
9312
9316
  }], threadId: [{
9313
9317
  type: Input
9318
+ }], inputComponent: [{
9319
+ type: Input
9314
9320
  }] } });
9315
9321
 
9316
9322
  // Testing utilities are not exported from the main entry point
@@ -9320,5 +9326,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImpo
9320
9326
  * Generated bundle index. Do not edit.
9321
9327
  */
9322
9328
 
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 };
9329
+ 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
9330
  //# sourceMappingURL=copilotkitnext-angular.mjs.map