@copilotkit/angular 0.4.0 → 0.5.0

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.
@@ -4,7 +4,7 @@ import { CopilotKitCoreRuntimeConnectionStatus, CopilotKitCore, ɵInterruptState
4
4
  import { shouldEnableInspector, A2UI_DEFAULT_GENERATION_GUIDELINES, A2UI_DEFAULT_DESIGN_GUIDELINES, schemaToJsonSchema, partialJSONParse, DEFAULT_AGENT_ID, randomUUID as randomUUID$1, TranscriptionErrorCode, copyToClipboard, getSourceUrl, getDocumentIcon, formatFileSize, matchesAcceptFilter, exceedsMaxSize, getModalityFromMimeType, readFileAsBase64, generateVideoThumbnail, createLicenseContextValue } from '@copilotkit/shared';
5
5
  export { TranscriptionErrorCode } from '@copilotkit/shared';
6
6
  import { buildCatalogContextValue, extractCatalogComponentSchemas, A2UI_SCHEMA_CONTEXT_DESCRIPTION } from '@copilotkit/a2ui-renderer/web-components';
7
- import { Subject, lastValueFrom, filter, take, BehaviorSubject, merge, fromEvent, animationFrameScheduler, EMPTY } from 'rxjs';
7
+ import { Subject, lastValueFrom, filter, take, map, BehaviorSubject, merge, fromEvent, animationFrameScheduler, EMPTY } from 'rxjs';
8
8
  import * as i1$1 from '@angular/common';
9
9
  import { isPlatformBrowser, DOCUMENT, NgComponentOutlet, CommonModule, NgTemplateOutlet } from '@angular/common';
10
10
  import { z } from 'zod';
@@ -12,7 +12,7 @@ import { zodToJsonSchema } from 'zod-to-json-schema';
12
12
  import { randomUUID, HttpAgent, AGUIConnectNotImplementedError } from '@ag-ui/client';
13
13
  import * as i1 from '@angular/cdk/scrolling';
14
14
  import { ScrollingModule } from '@angular/cdk/scrolling';
15
- import { startWith, throttleTime, map, distinctUntilChanged, takeUntil, debounceTime, filter as filter$1, switchMap } from 'rxjs/operators';
15
+ import { startWith, throttleTime, map as map$1, distinctUntilChanged, takeUntil, debounceTime, filter as filter$1, switchMap } from 'rxjs/operators';
16
16
  import { clsx } from 'clsx';
17
17
  import { twMerge } from 'tailwind-merge';
18
18
  import { toSignal, toObservable } from '@angular/core/rxjs-interop';
@@ -160,7 +160,11 @@ class HumanInTheLoop {
160
160
  this.results.next({ toolCallId, toolName, result });
161
161
  }
162
162
  onResult(toolCallId, toolName) {
163
- return lastValueFrom(this.results.pipe(filter((result) => result.toolCallId === toolCallId && result.toolName === toolName), take(1)));
163
+ return lastValueFrom(this.results.pipe(filter((entry) => entry.toolCallId === toolCallId && entry.toolName === toolName), take(1),
164
+ // Resolve with the bare result. toolCallId/toolName are routing keys for
165
+ // this bus only — leaking them would make the tool result an envelope
166
+ // that no consumer expects.
167
+ map((entry) => entry.result)));
164
168
  }
165
169
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.0", ngImport: i0, type: HumanInTheLoop, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
166
170
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.0", ngImport: i0, type: HumanInTheLoop, providedIn: "root" });
@@ -2001,6 +2005,20 @@ class CopilotKit {
2001
2005
  * the threads drawer's license gate — re-run once the status resolves.
2002
2006
  */
2003
2007
  licenseStatus = this.#licenseStatus.asReadonly();
2008
+ #runtimeEntitlements = signal(undefined, /* @ts-ignore */
2009
+ ...(ngDevMode ? [{ debugName: "#runtimeEntitlements" }] : /* istanbul ignore next */ []));
2010
+ /**
2011
+ * Structured entitlement authority from the connected runtime's `/info`
2012
+ * response. Ready managed entitlements override legacy license status.
2013
+ */
2014
+ runtimeEntitlements = this.#runtimeEntitlements.asReadonly();
2015
+ #runtimeEntitlementRetryPending = signal(false, /* @ts-ignore */
2016
+ ...(ngDevMode ? [{ debugName: "#runtimeEntitlementRetryPending" }] : /* istanbul ignore next */ []));
2017
+ /**
2018
+ * Whether Core still owes the one bounded retry for a retryable entitlement
2019
+ * lookup. Gated UI stays pending until that retry settles.
2020
+ */
2021
+ runtimeEntitlementRetryPending = this.#runtimeEntitlementRetryPending.asReadonly();
2004
2022
  #suggestionsByAgent = signal({}, /* @ts-ignore */
2005
2023
  ...(ngDevMode ? [{ debugName: "#suggestionsByAgent" }] : /* istanbul ignore next */ []));
2006
2024
  suggestionsByAgent = this.#suggestionsByAgent.asReadonly();
@@ -2061,6 +2079,8 @@ class CopilotKit {
2061
2079
  this.#threadEndpoints.set(this.core.threadEndpoints);
2062
2080
  this.#intelligence.set(this.core.intelligence);
2063
2081
  this.#licenseStatus.set(this.core.licenseStatus);
2082
+ this.#runtimeEntitlements.set(this.core.runtimeEntitlements);
2083
+ this.#runtimeEntitlementRetryPending.set(this.core.runtimeEntitlementRetryPending);
2064
2084
  this.#config.renderToolCalls?.forEach((renderConfig) => {
2065
2085
  this.addRenderToolCall(renderConfig);
2066
2086
  });
@@ -2097,6 +2117,8 @@ class CopilotKit {
2097
2117
  this.#threadEndpoints.set(this.core.threadEndpoints);
2098
2118
  this.#intelligence.set(this.core.intelligence);
2099
2119
  this.#licenseStatus.set(this.core.licenseStatus);
2120
+ this.#runtimeEntitlements.set(this.core.runtimeEntitlements);
2121
+ this.#runtimeEntitlementRetryPending.set(this.core.runtimeEntitlementRetryPending);
2100
2122
  this.#syncBuiltInActivityMessageRenderers();
2101
2123
  this.#syncBuiltInOpenGenerativeUI();
2102
2124
  },
@@ -2133,6 +2155,13 @@ class CopilotKit {
2133
2155
  }
2134
2156
  #bindClientTool(clientToolWithInjector) {
2135
2157
  const { injector, handler, ...frontendCandidate } = clientToolWithInjector;
2158
+ // A display-only registration declares no handler, and core has its own path
2159
+ // for that: it inserts an empty tool result and completes the turn. Binding a
2160
+ // wrapper here regardless would call `undefined` on the first tool call, and
2161
+ // substituting a stub would put an invented result into the thread instead.
2162
+ if (!handler) {
2163
+ return frontendCandidate;
2164
+ }
2136
2165
  return {
2137
2166
  ...frontendCandidate,
2138
2167
  handler: (args, context) => runInInjectionContext(injector, () => handler(args, context)),
@@ -2404,6 +2433,48 @@ function registerFrontendTool(frontendTool) {
2404
2433
  copilotKit.removeTool(frontendTool.name, frontendTool.agentId);
2405
2434
  });
2406
2435
  }
2436
+ /**
2437
+ * Registers an Angular component as a tool the agent can call to display it.
2438
+ *
2439
+ * The simplest generative-UI registration there is, and the only one that needs
2440
+ * nothing on the agent side: the tool is declared by the frontend and forwarded to
2441
+ * the agent over AG-UI, so it works the same behind a Python agent as a TypeScript
2442
+ * one. Contrast `registerRenderToolCall`, which draws a tool the agent already
2443
+ * has and therefore requires that tool to exist in the agent.
2444
+ *
2445
+ * The component is an ordinary `ToolRenderer`: it takes the required `toolCall`
2446
+ * signal input and reads `toolCall().args`, exactly as it would under
2447
+ * `registerFrontendTool` or `registerRenderToolCall`.
2448
+ *
2449
+ * Registration is removed when the calling injector is destroyed.
2450
+ *
2451
+ * @param config - Name, parameter schema, and component to render.
2452
+ *
2453
+ * @example
2454
+ * ```ts
2455
+ * registerComponent({
2456
+ * name: "show_incident",
2457
+ * description: "Show one incident from the incident table.",
2458
+ * parameters: z.object({ id: z.string(), severity: z.string() }),
2459
+ * component: IncidentCardComponent,
2460
+ * });
2461
+ * ```
2462
+ */
2463
+ function registerComponent(config) {
2464
+ // The same prefix react-core and vue build, so the tool reads identically to the
2465
+ // model whichever frontend registered the component.
2466
+ const prefix = `Use this tool to display the "${config.name}" component in the chat. This tool renders a visual UI component for the user.`;
2467
+ registerFrontendTool({
2468
+ name: config.name,
2469
+ description: config.description
2470
+ ? `${prefix}\n\n${config.description}`
2471
+ : prefix,
2472
+ parameters: config.parameters,
2473
+ component: config.component,
2474
+ agentId: config.agentId,
2475
+ followUp: config.followUp,
2476
+ });
2477
+ }
2407
2478
  function registerHumanInTheLoop(humanInTheLoop) {
2408
2479
  const destroyRef = inject(DestroyRef);
2409
2480
  const copilotKit = inject(CopilotKit);
@@ -4175,7 +4246,7 @@ class ScrollPosition {
4175
4246
  // Create scroll observable
4176
4247
  const scroll$ = merge(fromEvent(el, "scroll"), this.viewportRuler.change(150)).pipe(startWith(null), // Emit initial state
4177
4248
  throttleTime(16, animationFrameScheduler, { trailing: true }), // ~60fps
4178
- map(() => this.getScrollState(el, threshold)), distinctUntilChanged((a, b) => a.isAtBottom === b.isAtBottom &&
4249
+ map$1(() => this.getScrollState(el, threshold)), distinctUntilChanged((a, b) => a.isAtBottom === b.isAtBottom &&
4179
4250
  a.scrollTop === b.scrollTop &&
4180
4251
  a.scrollHeight === b.scrollHeight), takeUntil(this.destroy$));
4181
4252
  // Subscribe and update subject
@@ -12310,10 +12381,33 @@ class CopilotThreadsDrawer {
12310
12381
  resolvedAgentId = computed(() => this.agentId() ?? this.config?.agentId() ?? DEFAULT_AGENT_ID, /* @ts-ignore */
12311
12382
  ...(ngDevMode ? [{ debugName: "resolvedAgentId" }] : /* istanbul ignore next */ []));
12312
12383
  /**
12313
- * Normalized license context derived from the core's runtime-reported status,
12314
- * via the same `@copilotkit/shared` helper the React provider uses.
12384
+ * Normalized license context derived from Core's structured and legacy
12385
+ * Runtime authority, with the same precedence as the React provider.
12315
12386
  */
12316
- licenseContext = computed(() => createLicenseContextValue(this.copilotkit.licenseStatus()), /* @ts-ignore */
12387
+ licenseContext = computed(() => {
12388
+ const runtimeLicenseStatus = this.copilotkit.licenseStatus();
12389
+ const runtimeEntitlements = this.copilotkit.runtimeEntitlements?.();
12390
+ const retryableRuntimeEntitlementFailure = runtimeEntitlements?.status !== "ready" &&
12391
+ runtimeEntitlements?.error.retryable === true;
12392
+ const hasNonReadyRuntimeEntitlement = runtimeEntitlements !== undefined &&
12393
+ runtimeEntitlements.status !== "ready";
12394
+ const hasLegacyRuntimeEntitlementFallback = runtimeLicenseStatus === "valid" || runtimeLicenseStatus === "expiring";
12395
+ const runtimeEntitlementRetryInProgress = retryableRuntimeEntitlementFailure &&
12396
+ (this.copilotkit.runtimeEntitlementRetryPending?.() ?? false) &&
12397
+ !hasLegacyRuntimeEntitlementFallback;
12398
+ const runtimeEntitlementFailureSettled = hasNonReadyRuntimeEntitlement &&
12399
+ !runtimeEntitlementRetryInProgress &&
12400
+ !hasLegacyRuntimeEntitlementFallback;
12401
+ const runtimeLicenseContext = createLicenseContextValue(runtimeEntitlementRetryInProgress ? undefined : runtimeLicenseStatus, runtimeEntitlements);
12402
+ if (!runtimeEntitlementFailureSettled) {
12403
+ return runtimeLicenseContext;
12404
+ }
12405
+ return {
12406
+ ...runtimeLicenseContext,
12407
+ checkFeature: () => false,
12408
+ getLimit: () => null,
12409
+ };
12410
+ }, /* @ts-ignore */
12317
12411
  ...(ngDevMode ? [{ debugName: "licenseContext" }] : /* istanbul ignore next */ []));
12318
12412
  /**
12319
12413
  * Two-pronged license gate, mirroring the React wrapper. `checkFeature` fails
@@ -13170,5 +13264,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.0", ngImpor
13170
13264
  * Generated bundle index. Do not edit.
13171
13265
  */
13172
13266
 
13173
- export { AGUI_SEND_STATE_SNAPSHOT_TOOL_NAME, AgentStore, AudioRecorderError, COPILOT_CHAT_CONFIGURATION, COPILOT_CHAT_CONFIGURATION_OPTIONS, COPILOT_CHAT_DEFAULT_LABELS, COPILOT_CHAT_LABELS, COPILOT_KIT_CONFIG, ChatState, CopilotA2UIActivityRenderer, CopilotA2UIProgress, CopilotA2UIRecovery, CopilotA2UIToolRenderer, CopilotChat, CopilotChatAddFileButton, CopilotChatAssistantMessage, CopilotChatAssistantMessageCopyButton, CopilotChatAssistantMessageReadAloudButton, CopilotChatAssistantMessageRegenerateButton, CopilotChatAssistantMessageRenderer, CopilotChatAssistantMessageThumbsDownButton, CopilotChatAssistantMessageThumbsUpButton, CopilotChatAssistantMessageToolbar, CopilotChatAssistantMessageToolbarButton, CopilotChatAttachmentQueue, CopilotChatAttachmentRenderer, CopilotChatAttachmentsDirective, CopilotChatAudioRecorder, CopilotChatCancelTranscribeButton, CopilotChatConfiguration, CopilotChatFinishTranscribeButton, CopilotChatInput, CopilotChatInputDefaults, CopilotChatMessageView, CopilotChatMessageViewCursor, CopilotChatReasoningMessage, CopilotChatSendButton, CopilotChatStartTranscribeButton, CopilotChatSuggestionPill, CopilotChatSuggestionView, CopilotChatTextarea, CopilotChatToolCallsView, CopilotChatToolbar, CopilotChatToolbarButton, CopilotChatToolsMenu, CopilotChatUserMessage, CopilotChatUserMessageBranchNavigation, CopilotChatUserMessageCopyButton, CopilotChatUserMessageEditButton, CopilotChatUserMessageRenderer, CopilotChatUserMessageToolbar, CopilotChatUserMessageToolbarButton, CopilotChatView, CopilotChatViewDisclaimer, CopilotChatViewFeather, CopilotChatViewHandlers, CopilotChatViewInputContainer, CopilotChatViewInputMeasure, CopilotChatViewScrollToBottomButton, CopilotChatViewScrollView, CopilotDefaultToolRenderer, CopilotKit, CopilotKitAgentContext, CopilotOpenGenerativeUIActivityRenderer, CopilotOpenGenerativeUIRenderer, CopilotOpenGenerativeUIToolRenderer, CopilotPopup, CopilotSidebar, CopilotSlot, CopilotThreadsDrawer, CopilotThreadsDrawerRow, CopilotTooltip, CopilotkitAgentFactory, CopilotkitThreadsFactory, DEFAULT_OPEN_GENERATIVE_UI_DESIGN_SKILL, GENERATE_SANDBOXED_UI_DESCRIPTION, GENERATE_SANDBOXED_UI_TOOL_NAME, GenerateSandboxedUiArgsSchema, InterruptController, InterruptExpiredError, OPEN_GENERATIVE_UI_ACTIVITY_TYPE, OPEN_GENERATIVE_UI_WEBSANDBOX_LOADER, OpenGenerativeUIContentSchema, RENDER_A2UI_TOOL_NAME, RenderA2UIArgsSchema, RenderToolCalls, ResizeObserverService, SLOT_CONFIG, ScrollPosition, StickToBottom, ThreadsStore, TooltipContent, TranscriptionError, anyActivityContentSchema, cn, connectAgentContext, createSlotConfig, createSlotRenderer, getSlotConfig, injectAgentStore, injectCapabilities, injectChatConfiguration, injectChatLabels, injectChatState, injectCopilotKitConfig, injectInterrupt, injectMemories, injectThreads, isComponentType, isSlotValue, normalizeSlotValue, parseToolCallArguments, pickToolCallHandler, provideCopilotChatConfiguration, provideCopilotChatLabels, provideCopilotKit, provideSlots, readA2UILifecycleContent, registerFrontendTool, registerHumanInTheLoop, registerRenderActivityMessage, registerRenderToolCall, renderSlot, safeToolValue, transcribeAudio, ɵCOPILOTKIT_BUILT_IN_ACTIVITY_RENDERERS, ɵCOPILOTKIT_INSPECTOR_DEVELOPMENT_MODE };
13267
+ export { AGUI_SEND_STATE_SNAPSHOT_TOOL_NAME, AgentStore, AudioRecorderError, COPILOT_CHAT_CONFIGURATION, COPILOT_CHAT_CONFIGURATION_OPTIONS, COPILOT_CHAT_DEFAULT_LABELS, COPILOT_CHAT_LABELS, COPILOT_KIT_CONFIG, ChatState, CopilotA2UIActivityRenderer, CopilotA2UIProgress, CopilotA2UIRecovery, CopilotA2UIToolRenderer, CopilotChat, CopilotChatAddFileButton, CopilotChatAssistantMessage, CopilotChatAssistantMessageCopyButton, CopilotChatAssistantMessageReadAloudButton, CopilotChatAssistantMessageRegenerateButton, CopilotChatAssistantMessageRenderer, CopilotChatAssistantMessageThumbsDownButton, CopilotChatAssistantMessageThumbsUpButton, CopilotChatAssistantMessageToolbar, CopilotChatAssistantMessageToolbarButton, CopilotChatAttachmentQueue, CopilotChatAttachmentRenderer, CopilotChatAttachmentsDirective, CopilotChatAudioRecorder, CopilotChatCancelTranscribeButton, CopilotChatConfiguration, CopilotChatFinishTranscribeButton, CopilotChatInput, CopilotChatInputDefaults, CopilotChatMessageView, CopilotChatMessageViewCursor, CopilotChatReasoningMessage, CopilotChatSendButton, CopilotChatStartTranscribeButton, CopilotChatSuggestionPill, CopilotChatSuggestionView, CopilotChatTextarea, CopilotChatToolCallsView, CopilotChatToolbar, CopilotChatToolbarButton, CopilotChatToolsMenu, CopilotChatUserMessage, CopilotChatUserMessageBranchNavigation, CopilotChatUserMessageCopyButton, CopilotChatUserMessageEditButton, CopilotChatUserMessageRenderer, CopilotChatUserMessageToolbar, CopilotChatUserMessageToolbarButton, CopilotChatView, CopilotChatViewDisclaimer, CopilotChatViewFeather, CopilotChatViewHandlers, CopilotChatViewInputContainer, CopilotChatViewInputMeasure, CopilotChatViewScrollToBottomButton, CopilotChatViewScrollView, CopilotDefaultToolRenderer, CopilotKit, CopilotKitAgentContext, CopilotOpenGenerativeUIActivityRenderer, CopilotOpenGenerativeUIRenderer, CopilotOpenGenerativeUIToolRenderer, CopilotPopup, CopilotSidebar, CopilotSlot, CopilotThreadsDrawer, CopilotThreadsDrawerRow, CopilotTooltip, CopilotkitAgentFactory, CopilotkitThreadsFactory, DEFAULT_OPEN_GENERATIVE_UI_DESIGN_SKILL, GENERATE_SANDBOXED_UI_DESCRIPTION, GENERATE_SANDBOXED_UI_TOOL_NAME, GenerateSandboxedUiArgsSchema, InterruptController, InterruptExpiredError, OPEN_GENERATIVE_UI_ACTIVITY_TYPE, OPEN_GENERATIVE_UI_WEBSANDBOX_LOADER, OpenGenerativeUIContentSchema, RENDER_A2UI_TOOL_NAME, RenderA2UIArgsSchema, RenderToolCalls, ResizeObserverService, SLOT_CONFIG, ScrollPosition, StickToBottom, ThreadsStore, TooltipContent, TranscriptionError, anyActivityContentSchema, cn, connectAgentContext, createSlotConfig, createSlotRenderer, getSlotConfig, injectAgentStore, injectCapabilities, injectChatConfiguration, injectChatLabels, injectChatState, injectCopilotKitConfig, injectInterrupt, injectMemories, injectThreads, isComponentType, isSlotValue, normalizeSlotValue, parseToolCallArguments, pickToolCallHandler, provideCopilotChatConfiguration, provideCopilotChatLabels, provideCopilotKit, provideSlots, readA2UILifecycleContent, registerComponent, registerFrontendTool, registerHumanInTheLoop, registerRenderActivityMessage, registerRenderToolCall, renderSlot, safeToolValue, transcribeAudio, ɵCOPILOTKIT_BUILT_IN_ACTIVITY_RENDERERS, ɵCOPILOTKIT_INSPECTOR_DEVELOPMENT_MODE };
13174
13268
  //# sourceMappingURL=copilotkit-angular.mjs.map