@copilotkit/angular 2.0.0-rc.58 → 2.0.0-rc.60

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.
package/README.md CHANGED
@@ -122,6 +122,8 @@ export interface CopilotKitConfig {
122
122
  humanInTheLoop?: HumanInTheLoopConfig[];
123
123
  defaultToolRendering?: boolean;
124
124
  openGenerativeUI?: OpenGenerativeUIConfig;
125
+ /** @deprecated Use `provideGenerativeUI`. */
126
+ a2ui?: { catalog?: GenerativeUI; theme?: GenerativeUITheme };
125
127
  }
126
128
  ```
127
129
 
@@ -142,6 +144,10 @@ export interface CopilotKitConfig {
142
144
  It is disabled by default so missing renderers remain visible integration
143
145
  errors rather than silently changing the experience.
144
146
  - `openGenerativeUI`: Sandboxed UI functions and optional design guidance.
147
+ - `a2ui`: Deprecated. Use `provideGenerativeUI` from
148
+ `@copilotkit/angular/generative-ui`. `a2ui: { catalog, theme }` works as
149
+ `provideGenerativeUI({ ui: catalog, theme })`. When the app also calls
150
+ `provideGenerativeUI`, its options win.
145
151
 
146
152
  ### Injection helpers
147
153
 
package/dist/README.md CHANGED
@@ -122,6 +122,8 @@ export interface CopilotKitConfig {
122
122
  humanInTheLoop?: HumanInTheLoopConfig[];
123
123
  defaultToolRendering?: boolean;
124
124
  openGenerativeUI?: OpenGenerativeUIConfig;
125
+ /** @deprecated Use `provideGenerativeUI`. */
126
+ a2ui?: { catalog?: GenerativeUI; theme?: GenerativeUITheme };
125
127
  }
126
128
  ```
127
129
 
@@ -142,6 +144,10 @@ export interface CopilotKitConfig {
142
144
  It is disabled by default so missing renderers remain visible integration
143
145
  errors rather than silently changing the experience.
144
146
  - `openGenerativeUI`: Sandboxed UI functions and optional design guidance.
147
+ - `a2ui`: Deprecated. Use `provideGenerativeUI` from
148
+ `@copilotkit/angular/generative-ui`. `a2ui: { catalog, theme }` works as
149
+ `provideGenerativeUI({ ui: catalog, theme })`. When the app also calls
150
+ `provideGenerativeUI`, its options win.
145
151
 
146
152
  ### Injection helpers
147
153
 
@@ -1,6 +1,6 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, inject, computed, input, Component, signal, untracked, RendererFactory2, effect, reflectComponentType, inputBinding, outputBinding, Injector, createComponent, DOCUMENT, EnvironmentInjector, ViewContainerRef, DestroyRef, Directive, Injectable, ApplicationRef, isSignal, isDevMode, makeEnvironmentProviders, provideEnvironmentInitializer, PLATFORM_ID, viewChild, assertInInjectionContext, runInInjectionContext, ElementRef, output, linkedSignal, Renderer2, forwardRef, model, afterNextRender, viewChildren, afterRenderEffect } from '@angular/core';
3
- import { COPILOT_CHAT_CONFIGURATION, CopilotKit, CopilotChatAssistantMessageRenderer, ɵCOPILOTKIT_ASSISTANT_MARKDOWN_RENDERER as _COPILOTKIT_ASSISTANT_MARKDOWN_RENDERER, ɵCOPILOTKIT_BUILT_IN_ACTIVITY_RENDERERS as _COPILOTKIT_BUILT_IN_ACTIVITY_RENDERERS } from '@copilotkit/angular';
2
+ import { InjectionToken, inject, computed, input, Component, signal, untracked, RendererFactory2, effect, reflectComponentType, inputBinding, outputBinding, Injector, createComponent, DOCUMENT, EnvironmentInjector, ViewContainerRef, DestroyRef, Directive, Injectable, ApplicationRef, isSignal, isDevMode, provideEnvironmentInitializer, makeEnvironmentProviders, PLATFORM_ID, viewChild, assertInInjectionContext, runInInjectionContext, ElementRef, output, linkedSignal, Renderer2, forwardRef, model, afterNextRender, viewChildren, afterRenderEffect } from '@angular/core';
3
+ import { COPILOT_CHAT_CONFIGURATION, CopilotKit, CopilotChatAssistantMessageRenderer, ɵCOPILOTKIT_A2UI_CONFIG as _COPILOTKIT_A2UI_CONFIG, ɵCOPILOTKIT_ASSISTANT_MARKDOWN_RENDERER as _COPILOTKIT_ASSISTANT_MARKDOWN_RENDERER, ɵCOPILOTKIT_BUILT_IN_ACTIVITY_RENDERERS as _COPILOTKIT_BUILT_IN_ACTIVITY_RENDERERS, ɵsetA2UIGenerativeUIProviders as _setA2UIGenerativeUIProviders } from '@copilotkit/angular';
4
4
  import { NgComponentOutlet, isPlatformBrowser, NgTemplateOutlet } from '@angular/common';
5
5
  import { A2UI_COMPONENT_ENVELOPE_KEYS, isPathBinding, mapAtChildRef, isActionBinding, GENERATIVE_UI_ROOT_ID, GENERATIVE_UI_CHAT_TARGET, GENERATIVE_UI_ACTIVITY_TYPE, GENERATIVE_UI_FUNCTION_CALL_ACTIVITY_TYPE, buildGenerativeUIMarkdownGuidelines, generativeUIGuideFeatures, GENERATIVE_UI_MARKDOWN_GUIDELINES_DESCRIPTION, renderGenerativeUISchema, defaultGenerativeUIPromptSpec, GENERATIVE_UI_MARKDOWN_SCHEMA_CONTEXT_DESCRIPTION, DEFAULT_AGENT_ID, randomUUID, toA2UIActionMessage, GENERATIVE_UI_RENDER_TOOL, COPILOTKIT_FORWARDED_PROPS_KEY } from '@copilotkit/shared';
6
6
  import { z } from 'zod';
@@ -1975,26 +1975,37 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.0", ngImpor
1975
1975
  }]
1976
1976
  }], propDecorators: { content: [{ type: i0.Input, args: [{ isSignal: true, alias: "content", required: false }] }], messageId: [{ type: i0.Input, args: [{ isSignal: true, alias: "messageId", required: false }] }], isStreaming: [{ type: i0.Input, args: [{ isSignal: true, alias: "isStreaming", required: false }] }] } });
1977
1977
 
1978
+ /** The config given to `provideGenerativeUI`. */
1979
+ const APP_GENERATIVE_UI_CONFIG = new InjectionToken("APP_GENERATIVE_UI_CONFIG");
1978
1980
  /**
1979
- * Experimental. Native generative UI for the app: the agent renders the
1980
- * components of `ui` in the chat and in `<copilot-generative-ui-surface>`
1981
- * targets. Add it to the application providers, next to
1982
- * `provideCopilotKit`. It must be at the root: the chat resolves its
1983
- * renderers from the root injector.
1984
- *
1985
- * @example
1986
- * ```ts
1987
- * bootstrapApplication(App, {
1988
- * providers: [
1989
- * provideCopilotKit({ runtimeUrl: "/api/copilotkit" }),
1990
- * provideGenerativeUI({ ui: standardUI }),
1991
- * ],
1992
- * });
1993
- * ```
1981
+ * The config of `provideGenerativeUI`, with the options of the deprecated
1982
+ * `a2ui` option of `provideCopilotKit` that it leaves out: `a2ui.catalog` is
1983
+ * the `ui` and `a2ui.theme` the `theme`.
1994
1984
  */
1995
- function provideGenerativeUI(config) {
1996
- return makeEnvironmentProviders([
1997
- { provide: GENERATIVE_UI_CONFIG, useValue: config },
1985
+ function resolveGenerativeUIConfig() {
1986
+ const app = inject(APP_GENERATIVE_UI_CONFIG, { optional: true });
1987
+ const a2ui = inject(_COPILOTKIT_A2UI_CONFIG, { optional: true });
1988
+ if (app && !a2ui)
1989
+ return app;
1990
+ const ui = app?.ui ?? a2ui?.catalog;
1991
+ if (!ui) {
1992
+ throw new Error("Generative UI needs provideGenerativeUI({ ui }) in the application providers.");
1993
+ }
1994
+ return {
1995
+ ...app,
1996
+ ui,
1997
+ theme: app?.theme ?? a2ui?.theme,
1998
+ };
1999
+ }
2000
+ /**
2001
+ * The providers of generative UI other than the app's config. Both
2002
+ * `provideGenerativeUI` and the deprecated `a2ui` option add them, so they
2003
+ * give the same result twice: the config comes from one factory, and the
2004
+ * root starts once.
2005
+ */
2006
+ function generativeUIProviders(transport) {
2007
+ return [
2008
+ { provide: GENERATIVE_UI_CONFIG, useFactory: resolveGenerativeUIConfig },
1998
2009
  { provide: GENERATIVE_UI_RUNTIME, useExisting: CopilotGenerativeUI },
1999
2010
  ...generativeUIActivityRenderers.map((renderer) => ({
2000
2011
  provide: _COPILOTKIT_BUILT_IN_ACTIVITY_RENDERERS,
@@ -2003,7 +2014,7 @@ function provideGenerativeUI(config) {
2003
2014
  })),
2004
2015
  // The markdown transport renders the fences of each assistant message as
2005
2016
  // surfaces, unless the app gives the message its own markdown renderer.
2006
- ...(config.transport === "markdown"
2017
+ ...(transport === "markdown"
2007
2018
  ? [
2008
2019
  {
2009
2020
  provide: _COPILOTKIT_ASSISTANT_MARKDOWN_RENDERER,
@@ -2013,8 +2024,35 @@ function provideGenerativeUI(config) {
2013
2024
  : []),
2014
2025
  // The envelope is advertised before the first run.
2015
2026
  provideEnvironmentInitializer(() => inject(CopilotGenerativeUI).start()),
2027
+ ];
2028
+ }
2029
+ /**
2030
+ * Experimental. Native generative UI for the app: the agent renders the
2031
+ * components of `ui` in the chat and in `<copilot-generative-ui-surface>`
2032
+ * targets. Add it to the application providers, next to
2033
+ * `provideCopilotKit`. It must be at the root: the chat resolves its
2034
+ * renderers from the root injector.
2035
+ *
2036
+ * @example
2037
+ * ```ts
2038
+ * bootstrapApplication(App, {
2039
+ * providers: [
2040
+ * provideCopilotKit({ runtimeUrl: "/api/copilotkit" }),
2041
+ * provideGenerativeUI({ ui: standardUI }),
2042
+ * ],
2043
+ * });
2044
+ * ```
2045
+ */
2046
+ function provideGenerativeUI(config) {
2047
+ return makeEnvironmentProviders([
2048
+ { provide: APP_GENERATIVE_UI_CONFIG, useValue: config },
2049
+ ...generativeUIProviders(config.transport),
2016
2050
  ]);
2017
2051
  }
2052
+ // The deprecated `a2ui` option of `provideCopilotKit` turns generative UI on
2053
+ // with these providers. `@copilotkit/angular` cannot import this entry, so
2054
+ // this entry hands them over when it loads.
2055
+ _setA2UIGenerativeUIProviders(() => makeEnvironmentProviders(generativeUIProviders("tool")));
2018
2056
 
2019
2057
  /**
2020
2058
  * Experimental. A named place on the page where the agent can render UI.