@copilotkit/react-core 2.0.0-rc.25 → 2.0.0-rc.27
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/dist/{MarkdownSurfaces-v9AplTEj.cjs → MarkdownSurfaces-BbrHcSHN.cjs} +2 -3
- package/dist/{MarkdownSurfaces-v9AplTEj.cjs.map → MarkdownSurfaces-BbrHcSHN.cjs.map} +1 -1
- package/dist/{MarkdownSurfaces-CD0FAiZq.mjs → MarkdownSurfaces-DQbRS91-.mjs} +2 -3
- package/dist/{MarkdownSurfaces-CD0FAiZq.mjs.map → MarkdownSurfaces-DQbRS91-.mjs.map} +1 -1
- package/dist/context.cjs +14 -1
- package/dist/context.cjs.map +1 -1
- package/dist/context.d.cts +12 -1
- package/dist/context.d.cts.map +1 -1
- package/dist/context.d.mts +12 -1
- package/dist/context.d.mts.map +1 -1
- package/dist/context.mjs +14 -1
- package/dist/context.mjs.map +1 -1
- package/dist/generative-ui.cjs +1 -1
- package/dist/generative-ui.mjs +1 -1
- package/dist/headless.cjs +11 -41
- package/dist/headless.cjs.map +1 -1
- package/dist/headless.d.cts +18 -18
- package/dist/headless.d.cts.map +1 -1
- package/dist/headless.d.mts +6 -17
- package/dist/headless.d.mts.map +1 -1
- package/dist/headless.mjs +13 -43
- package/dist/headless.mjs.map +1 -1
- package/dist/index.cjs +513 -564
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -26
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +21 -26
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +276 -567
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +514 -566
- package/dist/index.umd.js.map +1 -1
- package/package.json +8 -8
package/dist/context.cjs
CHANGED
|
@@ -49,7 +49,10 @@ var CopilotKitCoreReact = class extends _copilotkit_core.CopilotKitCore {
|
|
|
49
49
|
get renderActivityMessages() {
|
|
50
50
|
return this._renderers.activity;
|
|
51
51
|
}
|
|
52
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* Prop, hook and built-in renderers merged. For one name and agentId, a
|
|
54
|
+
* hook renderer wins over a prop one, and both win over a built-in one.
|
|
55
|
+
*/
|
|
53
56
|
get renderToolCalls() {
|
|
54
57
|
return this._renderers.toolCalls;
|
|
55
58
|
}
|
|
@@ -68,6 +71,16 @@ var CopilotKitCoreReact = class extends _copilotkit_core.CopilotKitCore {
|
|
|
68
71
|
removeHookRenderToolCall(name, agentId) {
|
|
69
72
|
this._renderers.removeHookToolCall(name, agentId);
|
|
70
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* @internal Add a renderer for a tool a built-in feature owns (A2UI,
|
|
76
|
+
* generative UI). Prop and hook renderers with the same name and agent win
|
|
77
|
+
* over it, and `setRenderToolCalls` never removes it.
|
|
78
|
+
*
|
|
79
|
+
* @returns A function that removes the renderer.
|
|
80
|
+
*/
|
|
81
|
+
ɵaddBuiltInRenderToolCall(entry) {
|
|
82
|
+
return this._renderers.addBuiltInToolCall(entry);
|
|
83
|
+
}
|
|
71
84
|
notifyRenderersChanged(kind) {
|
|
72
85
|
this.notifySubscribers((subscriber) => {
|
|
73
86
|
const reactSubscriber = subscriber;
|
package/dist/context.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.cjs","names":["CopilotKitCore","ɵRendererRegistry"],"sources":["../src/lib/react-core.ts","../src/context.ts"],"sourcesContent":["import React from \"react\";\nimport type {\n ReactActivityMessageRenderer,\n ReactToolCallRenderer,\n} from \"../types\";\nimport type { ReactCustomMessageRenderer } from \"../types/react-custom-message-renderer\";\nimport { CopilotKitCore, ɵRendererRegistry } from \"@copilotkit/core\";\nimport type {\n CopilotKitCoreConfig,\n CopilotKitCoreSubscriber,\n CopilotKitCoreSubscription,\n ɵRendererKind,\n} from \"@copilotkit/core\";\n\nexport interface CopilotKitCoreReactConfig extends CopilotKitCoreConfig {\n // Add any additional configuration properties specific to the React implementation\n renderToolCalls?: ReactToolCallRenderer<any>[];\n renderActivityMessages?: ReactActivityMessageRenderer<any>[];\n\n // Add custom message renderers\n renderCustomMessages?: ReactCustomMessageRenderer[];\n}\n\nexport interface CopilotKitCoreReactSubscriber extends CopilotKitCoreSubscriber {\n onRenderToolCallsChanged?: (event: {\n copilotkit: CopilotKitCore;\n renderToolCalls: readonly ReactToolCallRenderer<any>[];\n }) => void | Promise<void>;\n onRenderActivityMessagesChanged?: (event: {\n copilotkit: CopilotKitCore;\n renderActivityMessages: readonly ReactActivityMessageRenderer<any>[];\n }) => void | Promise<void>;\n onRenderCustomMessagesChanged?: (event: {\n copilotkit: CopilotKitCore;\n renderCustomMessages: readonly ReactCustomMessageRenderer[];\n }) => void | Promise<void>;\n onInterruptElementChanged?: (event: {\n copilotkit: CopilotKitCore;\n interruptElement: React.ReactElement | null;\n }) => void | Promise<void>;\n}\n\n/**\n * Wait for pending React state updates before the follow-up agent run.\n *\n * When a frontend tool handler calls setState(), React 18 batches the update\n * and schedules a commit via its internal scheduler (MessageChannel). The\n * useAgentContext hook registers context via useLayoutEffect, which runs\n * synchronously after React commits that batch.\n *\n * Awaiting a zero-delay timeout yields to the macrotask queue. React's\n * MessageChannel task runs first, committing the pending state and running\n * useLayoutEffect (which updates the context store). The follow-up runAgent\n * call then reads fresh context.\n */\nfunction waitForReactCommit() {\n return new Promise<void>((resolve) => setTimeout(resolve, 0));\n}\n\nexport class CopilotKitCoreReact extends CopilotKitCore {\n private readonly _renderers: ɵRendererRegistry<\n ReactToolCallRenderer<any>,\n ReactActivityMessageRenderer<any>,\n ReactCustomMessageRenderer\n >;\n\n constructor(config: CopilotKitCoreReactConfig) {\n super({\n ...config,\n ɵwaitForFrameworkUpdates: waitForReactCommit,\n });\n this._renderers = new ɵRendererRegistry({\n toolCalls: config.renderToolCalls,\n activity: config.renderActivityMessages,\n custom: config.renderCustomMessages,\n });\n this._renderers.subscribe((kind) => this.notifyRenderersChanged(kind));\n // The element lives in core's generic interrupt slot; keep the React\n // subscriber event for existing listeners.\n this.ɵsubscribeToInterruptPayload(() => {\n void this.notifySubscribers((subscriber) => {\n const reactSubscriber = subscriber as CopilotKitCoreReactSubscriber;\n return reactSubscriber.onInterruptElementChanged?.({\n copilotkit: this,\n interruptElement: this.interruptElement,\n });\n }, \"Subscriber onInterruptElementChanged error:\");\n });\n }\n\n get renderCustomMessages() {\n return this._renderers.custom;\n }\n\n get renderActivityMessages() {\n return this._renderers.activity;\n }\n\n /** Prop and hook renderers merged; a hook renderer wins over a prop one. */\n get renderToolCalls() {\n return this._renderers.toolCalls;\n }\n\n setRenderActivityMessages(\n renderers: ReactActivityMessageRenderer<any>[],\n ): void {\n this._renderers.setActivity(renderers);\n }\n\n setRenderCustomMessages(renderers: ReactCustomMessageRenderer[]): void {\n this._renderers.setCustom(renderers);\n }\n\n setRenderToolCalls(renderToolCalls: ReactToolCallRenderer<any>[]): void {\n this._renderers.setPropToolCalls(renderToolCalls);\n }\n\n addHookRenderToolCall(entry: ReactToolCallRenderer<any>): void {\n this._renderers.addHookToolCall(entry);\n }\n\n removeHookRenderToolCall(name: string, agentId?: string): void {\n this._renderers.removeHookToolCall(name, agentId);\n }\n\n private notifyRenderersChanged(kind: ɵRendererKind): void {\n void this.notifySubscribers((subscriber) => {\n const reactSubscriber = subscriber as CopilotKitCoreReactSubscriber;\n switch (kind) {\n case \"toolCalls\":\n return reactSubscriber.onRenderToolCallsChanged?.({\n copilotkit: this,\n renderToolCalls: this.renderToolCalls,\n });\n case \"activity\":\n return reactSubscriber.onRenderActivityMessagesChanged?.({\n copilotkit: this,\n renderActivityMessages: this.renderActivityMessages,\n });\n case \"custom\":\n return reactSubscriber.onRenderCustomMessagesChanged?.({\n copilotkit: this,\n renderCustomMessages: this.renderCustomMessages,\n });\n }\n }, `Subscriber renderer change (${kind}) error:`);\n }\n\n get interruptElement(): React.ReactElement | null {\n return this.ɵinterruptPayload as React.ReactElement | null;\n }\n\n setInterruptElement(element: React.ReactElement | null): void {\n this.ɵsetInterruptPayload(element);\n }\n\n // Override to accept React-specific subscriber type\n subscribe(\n subscriber: CopilotKitCoreReactSubscriber,\n ): CopilotKitCoreSubscription {\n return super.subscribe(subscriber);\n }\n}\n","\"use client\";\n\nimport { createContext, useContext, useEffect, useReducer } from \"react\";\nimport { CopilotKitCoreReact } from \"./lib/react-core\";\nimport type { CopilotKitCoreReactConfig } from \"./lib/react-core\";\nimport type { LicenseContextValue } from \"@copilotkit/shared\";\n\n// Re-export so headless.ts (and consumers) reference the same type declaration.\nexport { CopilotKitCoreReact };\nexport type { CopilotKitCoreReactConfig };\n\nexport interface CopilotKitContextValue {\n copilotkit: CopilotKitCoreReact;\n /**\n * Whether CopilotKit should automatically mount Intelligence indicators.\n * Defaults to true when omitted for compatibility with custom providers.\n */\n showIntelligenceIndicator?: boolean;\n /**\n * Set of tool call IDs currently being executed.\n * This is tracked at the provider level to ensure tool execution events\n * are captured even before child components mount.\n */\n executingToolCallIds: ReadonlySet<string>;\n}\n\nexport const EMPTY_SET: ReadonlySet<string> = new Set();\n\nexport const CopilotKitContext = createContext<CopilotKitContextValue | null>(\n null,\n);\n\nexport const useCopilotKit = (): CopilotKitContextValue => {\n const context = useContext(CopilotKitContext);\n const [, forceUpdate] = useReducer((x: number) => x + 1, 0);\n\n if (!context) {\n throw new Error(\"useCopilotKit must be used within CopilotKitProvider\");\n }\n useEffect(() => {\n const subscription = context.copilotkit.subscribe({\n onRuntimeConnectionStatusChanged: () => {\n forceUpdate();\n },\n onHeadersChanged: () => {\n forceUpdate();\n },\n });\n return () => {\n subscription.unsubscribe();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return context;\n};\n\n// License context — shared between web and RN providers.\n// Default is permissive (all features allowed) — providers override via createLicenseContextValue.\n// Inlined here to avoid a runtime import from @copilotkit/shared, which pulls in\n// Node-only deps (jose) that break React Native's Metro bundler.\nexport const LicenseContext = createContext<LicenseContextValue>({\n status: null,\n license: null,\n checkFeature: () => true,\n getLimit: () => null,\n} as LicenseContextValue);\n\nexport const useLicenseContext = (): LicenseContextValue =>\n useContext(LicenseContext);\n\n// Provider-level default agent id, published by `<CopilotKitProvider agentId>`.\n//\n// This is a context of its own rather than a `CopilotChatConfigurationProvider`\n// rendered at the root, because that provider also owns a thread: it resolves a\n// threadId (minting a UUID when none is given) and the top-most one owns the\n// imperative active-thread override. Rendering it around the whole application\n// would hand every `<CopilotChat>` the same inherited threadId, so two sibling\n// chats would share one transcript. A bare string context carries the agent\n// default and nothing else.\n//\n// It is the LAST fallback before `DEFAULT_AGENT_ID`, so an explicit `agentId`\n// argument, a `<CopilotChat agentId>`, and a `<CopilotChatConfigurationProvider\n// agentId>` all still win.\nexport const CopilotKitAgentIdContext = createContext<string | undefined>(\n undefined,\n);\n\nexport const useDefaultAgentId = (): string | undefined =>\n useContext(CopilotKitAgentIdContext);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAuDA,SAAS,qBAAqB;AAC5B,QAAO,IAAI,SAAe,YAAY,WAAW,SAAS,EAAE,CAAC;;AAG/D,IAAa,sBAAb,cAAyCA,gCAAe;CACtD,AAAiB;CAMjB,YAAY,QAAmC;AAC7C,QAAM;GACJ,GAAG;GACH,0BAA0B;GAC3B,CAAC;AACF,OAAK,aAAa,IAAIC,mCAAkB;GACtC,WAAW,OAAO;GAClB,UAAU,OAAO;GACjB,QAAQ,OAAO;GAChB,CAAC;AACF,OAAK,WAAW,WAAW,SAAS,KAAK,uBAAuB,KAAK,CAAC;AAGtE,OAAK,mCAAmC;AACtC,GAAK,KAAK,mBAAmB,eAAe;AAE1C,WADwB,WACD,4BAA4B;KACjD,YAAY;KACZ,kBAAkB,KAAK;KACxB,CAAC;MACD,8CAA8C;IACjD;;CAGJ,IAAI,uBAAuB;AACzB,SAAO,KAAK,WAAW;;CAGzB,IAAI,yBAAyB;AAC3B,SAAO,KAAK,WAAW;;;CAIzB,IAAI,kBAAkB;AACpB,SAAO,KAAK,WAAW;;CAGzB,0BACE,WACM;AACN,OAAK,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AAS;CACT,oBAAoB;CACpB,gBAAgB;CACjB,CAAwB;AAEzB,MAAa,gDACA,eAAe;AAe5B,MAAa,oDACX,OACD;AAED,MAAa,gDACA,yBAAyB"}
|
|
1
|
+
{"version":3,"file":"context.cjs","names":["CopilotKitCore","ɵRendererRegistry"],"sources":["../src/lib/react-core.ts","../src/context.ts"],"sourcesContent":["import React from \"react\";\nimport type {\n ReactActivityMessageRenderer,\n ReactToolCallRenderer,\n} from \"../types\";\nimport type { ReactCustomMessageRenderer } from \"../types/react-custom-message-renderer\";\nimport { CopilotKitCore, ɵRendererRegistry } from \"@copilotkit/core\";\nimport type {\n CopilotKitCoreConfig,\n CopilotKitCoreSubscriber,\n CopilotKitCoreSubscription,\n ɵRendererKind,\n} from \"@copilotkit/core\";\n\nexport interface CopilotKitCoreReactConfig extends CopilotKitCoreConfig {\n // Add any additional configuration properties specific to the React implementation\n renderToolCalls?: ReactToolCallRenderer<any>[];\n renderActivityMessages?: ReactActivityMessageRenderer<any>[];\n\n // Add custom message renderers\n renderCustomMessages?: ReactCustomMessageRenderer[];\n}\n\nexport interface CopilotKitCoreReactSubscriber extends CopilotKitCoreSubscriber {\n onRenderToolCallsChanged?: (event: {\n copilotkit: CopilotKitCore;\n renderToolCalls: readonly ReactToolCallRenderer<any>[];\n }) => void | Promise<void>;\n onRenderActivityMessagesChanged?: (event: {\n copilotkit: CopilotKitCore;\n renderActivityMessages: readonly ReactActivityMessageRenderer<any>[];\n }) => void | Promise<void>;\n onRenderCustomMessagesChanged?: (event: {\n copilotkit: CopilotKitCore;\n renderCustomMessages: readonly ReactCustomMessageRenderer[];\n }) => void | Promise<void>;\n onInterruptElementChanged?: (event: {\n copilotkit: CopilotKitCore;\n interruptElement: React.ReactElement | null;\n }) => void | Promise<void>;\n}\n\n/**\n * Wait for pending React state updates before the follow-up agent run.\n *\n * When a frontend tool handler calls setState(), React 18 batches the update\n * and schedules a commit via its internal scheduler (MessageChannel). The\n * useAgentContext hook registers context via useLayoutEffect, which runs\n * synchronously after React commits that batch.\n *\n * Awaiting a zero-delay timeout yields to the macrotask queue. React's\n * MessageChannel task runs first, committing the pending state and running\n * useLayoutEffect (which updates the context store). The follow-up runAgent\n * call then reads fresh context.\n */\nfunction waitForReactCommit() {\n return new Promise<void>((resolve) => setTimeout(resolve, 0));\n}\n\nexport class CopilotKitCoreReact extends CopilotKitCore {\n private readonly _renderers: ɵRendererRegistry<\n ReactToolCallRenderer<any>,\n ReactActivityMessageRenderer<any>,\n ReactCustomMessageRenderer\n >;\n\n constructor(config: CopilotKitCoreReactConfig) {\n super({\n ...config,\n ɵwaitForFrameworkUpdates: waitForReactCommit,\n });\n this._renderers = new ɵRendererRegistry({\n toolCalls: config.renderToolCalls,\n activity: config.renderActivityMessages,\n custom: config.renderCustomMessages,\n });\n this._renderers.subscribe((kind) => this.notifyRenderersChanged(kind));\n // The element lives in core's generic interrupt slot; keep the React\n // subscriber event for existing listeners.\n this.ɵsubscribeToInterruptPayload(() => {\n void this.notifySubscribers((subscriber) => {\n const reactSubscriber = subscriber as CopilotKitCoreReactSubscriber;\n return reactSubscriber.onInterruptElementChanged?.({\n copilotkit: this,\n interruptElement: this.interruptElement,\n });\n }, \"Subscriber onInterruptElementChanged error:\");\n });\n }\n\n get renderCustomMessages() {\n return this._renderers.custom;\n }\n\n get renderActivityMessages() {\n return this._renderers.activity;\n }\n\n /**\n * Prop, hook and built-in renderers merged. For one name and agentId, a\n * hook renderer wins over a prop one, and both win over a built-in one.\n */\n get renderToolCalls() {\n return this._renderers.toolCalls;\n }\n\n setRenderActivityMessages(\n renderers: ReactActivityMessageRenderer<any>[],\n ): void {\n this._renderers.setActivity(renderers);\n }\n\n setRenderCustomMessages(renderers: ReactCustomMessageRenderer[]): void {\n this._renderers.setCustom(renderers);\n }\n\n setRenderToolCalls(renderToolCalls: ReactToolCallRenderer<any>[]): void {\n this._renderers.setPropToolCalls(renderToolCalls);\n }\n\n addHookRenderToolCall(entry: ReactToolCallRenderer<any>): void {\n this._renderers.addHookToolCall(entry);\n }\n\n removeHookRenderToolCall(name: string, agentId?: string): void {\n this._renderers.removeHookToolCall(name, agentId);\n }\n\n /**\n * @internal Add a renderer for a tool a built-in feature owns (A2UI,\n * generative UI). Prop and hook renderers with the same name and agent win\n * over it, and `setRenderToolCalls` never removes it.\n *\n * @returns A function that removes the renderer.\n */\n ɵaddBuiltInRenderToolCall(entry: ReactToolCallRenderer): () => void {\n return this._renderers.addBuiltInToolCall(entry);\n }\n\n private notifyRenderersChanged(kind: ɵRendererKind): void {\n void this.notifySubscribers((subscriber) => {\n const reactSubscriber = subscriber as CopilotKitCoreReactSubscriber;\n switch (kind) {\n case \"toolCalls\":\n return reactSubscriber.onRenderToolCallsChanged?.({\n copilotkit: this,\n renderToolCalls: this.renderToolCalls,\n });\n case \"activity\":\n return reactSubscriber.onRenderActivityMessagesChanged?.({\n copilotkit: this,\n renderActivityMessages: this.renderActivityMessages,\n });\n case \"custom\":\n return reactSubscriber.onRenderCustomMessagesChanged?.({\n copilotkit: this,\n renderCustomMessages: this.renderCustomMessages,\n });\n }\n }, `Subscriber renderer change (${kind}) error:`);\n }\n\n get interruptElement(): React.ReactElement | null {\n return this.ɵinterruptPayload as React.ReactElement | null;\n }\n\n setInterruptElement(element: React.ReactElement | null): void {\n this.ɵsetInterruptPayload(element);\n }\n\n // Override to accept React-specific subscriber type\n subscribe(\n subscriber: CopilotKitCoreReactSubscriber,\n ): CopilotKitCoreSubscription {\n return super.subscribe(subscriber);\n }\n}\n","\"use client\";\n\nimport { createContext, useContext, useEffect, useReducer } from \"react\";\nimport { CopilotKitCoreReact } from \"./lib/react-core\";\nimport type { CopilotKitCoreReactConfig } from \"./lib/react-core\";\nimport type { LicenseContextValue } from \"@copilotkit/shared\";\n\n// Re-export so headless.ts (and consumers) reference the same type declaration.\nexport { CopilotKitCoreReact };\nexport type { CopilotKitCoreReactConfig };\n\nexport interface CopilotKitContextValue {\n copilotkit: CopilotKitCoreReact;\n /**\n * Whether CopilotKit should automatically mount Intelligence indicators.\n * Defaults to true when omitted for compatibility with custom providers.\n */\n showIntelligenceIndicator?: boolean;\n /**\n * Set of tool call IDs currently being executed.\n * This is tracked at the provider level to ensure tool execution events\n * are captured even before child components mount.\n */\n executingToolCallIds: ReadonlySet<string>;\n}\n\nexport const EMPTY_SET: ReadonlySet<string> = new Set();\n\nexport const CopilotKitContext = createContext<CopilotKitContextValue | null>(\n null,\n);\n\nexport const useCopilotKit = (): CopilotKitContextValue => {\n const context = useContext(CopilotKitContext);\n const [, forceUpdate] = useReducer((x: number) => x + 1, 0);\n\n if (!context) {\n throw new Error(\"useCopilotKit must be used within CopilotKitProvider\");\n }\n useEffect(() => {\n const subscription = context.copilotkit.subscribe({\n onRuntimeConnectionStatusChanged: () => {\n forceUpdate();\n },\n onHeadersChanged: () => {\n forceUpdate();\n },\n });\n return () => {\n subscription.unsubscribe();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return context;\n};\n\n// License context — shared between web and RN providers.\n// Default is permissive (all features allowed) — providers override via createLicenseContextValue.\n// Inlined here to avoid a runtime import from @copilotkit/shared, which pulls in\n// Node-only deps (jose) that break React Native's Metro bundler.\nexport const LicenseContext = createContext<LicenseContextValue>({\n status: null,\n license: null,\n checkFeature: () => true,\n getLimit: () => null,\n} as LicenseContextValue);\n\nexport const useLicenseContext = (): LicenseContextValue =>\n useContext(LicenseContext);\n\n// Provider-level default agent id, published by `<CopilotKitProvider agentId>`.\n//\n// This is a context of its own rather than a `CopilotChatConfigurationProvider`\n// rendered at the root, because that provider also owns a thread: it resolves a\n// threadId (minting a UUID when none is given) and the top-most one owns the\n// imperative active-thread override. Rendering it around the whole application\n// would hand every `<CopilotChat>` the same inherited threadId, so two sibling\n// chats would share one transcript. A bare string context carries the agent\n// default and nothing else.\n//\n// It is the LAST fallback before `DEFAULT_AGENT_ID`, so an explicit `agentId`\n// argument, a `<CopilotChat agentId>`, and a `<CopilotChatConfigurationProvider\n// agentId>` all still win.\nexport const CopilotKitAgentIdContext = createContext<string | undefined>(\n undefined,\n);\n\nexport const useDefaultAgentId = (): string | undefined =>\n useContext(CopilotKitAgentIdContext);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAuDA,SAAS,qBAAqB;AAC5B,QAAO,IAAI,SAAe,YAAY,WAAW,SAAS,EAAE,CAAC;;AAG/D,IAAa,sBAAb,cAAyCA,gCAAe;CACtD,AAAiB;CAMjB,YAAY,QAAmC;AAC7C,QAAM;GACJ,GAAG;GACH,0BAA0B;GAC3B,CAAC;AACF,OAAK,aAAa,IAAIC,mCAAkB;GACtC,WAAW,OAAO;GAClB,UAAU,OAAO;GACjB,QAAQ,OAAO;GAChB,CAAC;AACF,OAAK,WAAW,WAAW,SAAS,KAAK,uBAAuB,KAAK,CAAC;AAGtE,OAAK,mCAAmC;AACtC,GAAK,KAAK,mBAAmB,eAAe;AAE1C,WADwB,WACD,4BAA4B;KACjD,YAAY;KACZ,kBAAkB,KAAK;KACxB,CAAC;MACD,8CAA8C;IACjD;;CAGJ,IAAI,uBAAuB;AACzB,SAAO,KAAK,WAAW;;CAGzB,IAAI,yBAAyB;AAC3B,SAAO,KAAK,WAAW;;;;;;CAOzB,IAAI,kBAAkB;AACpB,SAAO,KAAK,WAAW;;CAGzB,0BACE,WACM;AACN,OAAK,WAAW,YAAY,UAAU;;CAGxC,wBAAwB,WAA+C;AACrE,OAAK,WAAW,UAAU,UAAU;;CAGtC,mBAAmB,iBAAqD;AACtE,OAAK,WAAW,iBAAiB,gBAAgB;;CAGnD,sBAAsB,OAAyC;AAC7D,OAAK,WAAW,gBAAgB,MAAM;;CAGxC,yBAAyB,MAAc,SAAwB;AAC7D,OAAK,WAAW,mBAAmB,MAAM,QAAQ;;;;;;;;;CAUnD,0BAA0B,OAA0C;AAClE,SAAO,KAAK,WAAW,mBAAmB,MAAM;;CAGlD,AAAQ,uBAAuB,MAA2B;AACxD,EAAK,KAAK,mBAAmB,eAAe;GAC1C,MAAM,kBAAkB;AACxB,WAAQ,MAAR;IACE,KAAK,YACH,QAAO,gBAAgB,2BAA2B;KAChD,YAAY;KACZ,iBAAiB,KAAK;KACvB,CAAC;IACJ,KAAK,WACH,QAAO,gBAAgB,kCAAkC;KACvD,YAAY;KACZ,wBAAwB,KAAK;KAC9B,CAAC;IACJ,KAAK,SACH,QAAO,gBAAgB,gCAAgC;KACrD,YAAY;KACZ,sBAAsB,KAAK;KAC5B,CAAC;;KAEL,+BAA+B,KAAK,UAAU;;CAGnD,IAAI,mBAA8C;AAChD,SAAO,KAAK;;CAGd,oBAAoB,SAA0C;AAC5D,OAAK,qBAAqB,QAAQ;;CAIpC,UACE,YAC4B;AAC5B,SAAO,MAAM,UAAU,WAAW;;;;;;ACpJtC,MAAa,4BAAiC,IAAI,KAAK;AAEvD,MAAa,6CACX,KACD;AAED,MAAa,sBAA8C;CACzD,MAAM,gCAAqB,kBAAkB;CAC7C,MAAM,GAAG,sCAA2B,MAAc,IAAI,GAAG,EAAE;AAE3D,KAAI,CAAC,QACH,OAAM,IAAI,MAAM,uDAAuD;AAEzE,4BAAgB;EACd,MAAM,eAAe,QAAQ,WAAW,UAAU;GAChD,wCAAwC;AACtC,iBAAa;;GAEf,wBAAwB;AACtB,iBAAa;;GAEhB,CAAC;AACF,eAAa;AACX,gBAAa,aAAa;;IAG3B,EAAE,CAAC;AAEN,QAAO;;AAOT,MAAa,0CAAoD;CAC/D,QAAQ;CACR,SAAS;CACT,oBAAoB;CACpB,gBAAgB;CACjB,CAAwB;AAEzB,MAAa,gDACA,eAAe;AAe5B,MAAa,oDACX,OACD;AAED,MAAa,gDACA,yBAAyB"}
|
package/dist/context.d.cts
CHANGED
|
@@ -70,13 +70,24 @@ declare class CopilotKitCoreReact extends CopilotKitCore {
|
|
|
70
70
|
constructor(config: CopilotKitCoreReactConfig);
|
|
71
71
|
get renderCustomMessages(): readonly ReactCustomMessageRenderer[];
|
|
72
72
|
get renderActivityMessages(): readonly ReactActivityMessageRenderer<any>[];
|
|
73
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* Prop, hook and built-in renderers merged. For one name and agentId, a
|
|
75
|
+
* hook renderer wins over a prop one, and both win over a built-in one.
|
|
76
|
+
*/
|
|
74
77
|
get renderToolCalls(): readonly ReactToolCallRenderer<any>[];
|
|
75
78
|
setRenderActivityMessages(renderers: ReactActivityMessageRenderer<any>[]): void;
|
|
76
79
|
setRenderCustomMessages(renderers: ReactCustomMessageRenderer[]): void;
|
|
77
80
|
setRenderToolCalls(renderToolCalls: ReactToolCallRenderer<any>[]): void;
|
|
78
81
|
addHookRenderToolCall(entry: ReactToolCallRenderer<any>): void;
|
|
79
82
|
removeHookRenderToolCall(name: string, agentId?: string): void;
|
|
83
|
+
/**
|
|
84
|
+
* @internal Add a renderer for a tool a built-in feature owns (A2UI,
|
|
85
|
+
* generative UI). Prop and hook renderers with the same name and agent win
|
|
86
|
+
* over it, and `setRenderToolCalls` never removes it.
|
|
87
|
+
*
|
|
88
|
+
* @returns A function that removes the renderer.
|
|
89
|
+
*/
|
|
90
|
+
ɵaddBuiltInRenderToolCall(entry: ReactToolCallRenderer): () => void;
|
|
80
91
|
private notifyRenderersChanged;
|
|
81
92
|
get interruptElement(): React.ReactElement | null;
|
|
82
93
|
setInterruptElement(element: React.ReactElement | null): void;
|
package/dist/context.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.cts","names":[],"sources":["../src/types/react-tool-call-renderer.ts","../src/types/react-activity-message-renderer.ts","../src/types/react-custom-message-renderer.ts","../src/lib/react-core.ts","../src/context.ts"],"mappings":";;;;;;;;;;AAeA;;;;;KAAY,qBAAA,gBAAqC,mBAAA,CAC/C,CAAA,EACA,KAAA,CAAM,aAAA,CAAc,mBAAA,CAAoB,CAAA;;;;;;;AAF1C;;;KCFY,4BAAA,qBACV,0BAAA,CACE,gBAAA,EACA,KAAA,CAAM,aAAA,CAAc,0BAAA,CAA2B,gBAAA;;;;;ADDnD;;;KEAK,6BAAA,GAAgC,IAAA,CACnC,wBAAA;EAGA,aAAA;AAAA;;;;;;KAQU,0BAAA,GACV,wBAAA,CAAyB,KAAA,CAAM,aAAA,CAAc,6BAAA;;;UCd9B,yBAAA,SAAkC,oBAAA;EAEjD,eAAA,GAAkB,qBAAA;EAClB,sBAAA,GAAyB,4BAAA;EAGzB,oBAAA,GAAuB,0BAAA;AAAA;AAAA,UAGR,6BAAA,SAAsC,wBAAA;EACrD,wBAAA,IAA4B,KAAA;IAC1B,UAAA,EAAY,cAAA;IACZ,eAAA,WAA0B,qBAAA;EAAA,aACf,OAAA;EACb,+BAAA,IAAmC,KAAA;IACjC,UAAA,EAAY,cAAA;IACZ,sBAAA,WAAiC,4BAAA;EAAA,aACtB,OAAA;EACb,6BAAA,IAAiC,KAAA;IAC/B,UAAA,EAAY,cAAA;IACZ,oBAAA,WAA+B,0BAAA;EAAA,aACpB,OAAA;EACb,yBAAA,IAA6B,KAAA;IAC3B,UAAA,EAAY,cAAA;IACZ,gBAAA,EAAkB,KAAA,CAAM,YAAA;EAAA,aACb,OAAA;AAAA;AAAA,cAoBF,mBAAA,SAA4B,cAAA;EAAA,iBACtB,UAAA;cAML,MAAA,EAAQ,yBAAA;EAAA,IAwBhB,oBAAA,CAAA,YAAoB,0BAAA;EAAA,IAIpB,sBAAA,CAAA,YAAsB,4BAAA;EF9EJ
|
|
1
|
+
{"version":3,"file":"context.d.cts","names":[],"sources":["../src/types/react-tool-call-renderer.ts","../src/types/react-activity-message-renderer.ts","../src/types/react-custom-message-renderer.ts","../src/lib/react-core.ts","../src/context.ts"],"mappings":";;;;;;;;;;AAeA;;;;;KAAY,qBAAA,gBAAqC,mBAAA,CAC/C,CAAA,EACA,KAAA,CAAM,aAAA,CAAc,mBAAA,CAAoB,CAAA;;;;;;;AAF1C;;;KCFY,4BAAA,qBACV,0BAAA,CACE,gBAAA,EACA,KAAA,CAAM,aAAA,CAAc,0BAAA,CAA2B,gBAAA;;;;;ADDnD;;;KEAK,6BAAA,GAA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A,EAAS,KAAA,CAAM,YAAA;EAKnC,SAAA,CACE,UAAA,EAAY,6BAAA,GACX,0BAAA;AAAA;;;UClKY,sBAAA;EACf,UAAA,EAAY,mBAAA;EJGmB;;;;EIE/B,yBAAA;EJAA;;;;;EIMA,oBAAA,EAAsB,WAAA;AAAA;AAAA,cAGX,SAAA,EAAW,WAAA;AAAA,cAEX,iBAAA,EAAiB,KAAA,CAAA,OAAA,CAAA,sBAAA;AAAA,cAIjB,aAAA,QAAoB,sBAAA;AAAA,cA6BpB,cAAA,EAAc,KAAA,CAAA,OAAA,CAAA,mBAAA;AAAA,cAOd,iBAAA,QAAwB,mBAAA;AAAA,cAgBxB,wBAAA,EAEZ,KAAA,CAFoC,OAAA;AAAA,cAIxB,iBAAA"}
|
package/dist/context.d.mts
CHANGED
|
@@ -70,13 +70,24 @@ declare class CopilotKitCoreReact extends CopilotKitCore {
|
|
|
70
70
|
constructor(config: CopilotKitCoreReactConfig);
|
|
71
71
|
get renderCustomMessages(): readonly ReactCustomMessageRenderer[];
|
|
72
72
|
get renderActivityMessages(): readonly ReactActivityMessageRenderer<any>[];
|
|
73
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* Prop, hook and built-in renderers merged. For one name and agentId, a
|
|
75
|
+
* hook renderer wins over a prop one, and both win over a built-in one.
|
|
76
|
+
*/
|
|
74
77
|
get renderToolCalls(): readonly ReactToolCallRenderer<any>[];
|
|
75
78
|
setRenderActivityMessages(renderers: ReactActivityMessageRenderer<any>[]): void;
|
|
76
79
|
setRenderCustomMessages(renderers: ReactCustomMessageRenderer[]): void;
|
|
77
80
|
setRenderToolCalls(renderToolCalls: ReactToolCallRenderer<any>[]): void;
|
|
78
81
|
addHookRenderToolCall(entry: ReactToolCallRenderer<any>): void;
|
|
79
82
|
removeHookRenderToolCall(name: string, agentId?: string): void;
|
|
83
|
+
/**
|
|
84
|
+
* @internal Add a renderer for a tool a built-in feature owns (A2UI,
|
|
85
|
+
* generative UI). Prop and hook renderers with the same name and agent win
|
|
86
|
+
* over it, and `setRenderToolCalls` never removes it.
|
|
87
|
+
*
|
|
88
|
+
* @returns A function that removes the renderer.
|
|
89
|
+
*/
|
|
90
|
+
ɵaddBuiltInRenderToolCall(entry: ReactToolCallRenderer): () => void;
|
|
80
91
|
private notifyRenderersChanged;
|
|
81
92
|
get interruptElement(): React.ReactElement | null;
|
|
82
93
|
setInterruptElement(element: React.ReactElement | null): void;
|
package/dist/context.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.mts","names":[],"sources":["../src/types/react-tool-call-renderer.ts","../src/types/react-activity-message-renderer.ts","../src/types/react-custom-message-renderer.ts","../src/lib/react-core.ts","../src/context.ts"],"mappings":";;;;;;;;;;AAeA;;;;;KAAY,qBAAA,gBAAqC,mBAAA,CAC/C,CAAA,EACA,KAAA,CAAM,aAAA,CAAc,mBAAA,CAAoB,CAAA;;;;;;;AAF1C;;;KCFY,4BAAA,qBACV,0BAAA,CACE,gBAAA,EACA,KAAA,CAAM,aAAA,CAAc,0BAAA,CAA2B,gBAAA;;;;;ADDnD;;;KEAK,6BAAA,GAAgC,IAAA,CACnC,wBAAA;EAGA,aAAA;AAAA;;;;;;KAQU,0BAAA,GACV,wBAAA,CAAyB,KAAA,CAAM,aAAA,CAAc,6BAAA;;;UCd9B,yBAAA,SAAkC,oBAAA;EAEjD,eAAA,GAAkB,qBAAA;EAClB,sBAAA,GAAyB,4BAAA;EAGzB,oBAAA,GAAuB,0BAAA;AAAA;AAAA,UAGR,6BAAA,SAAsC,wBAAA;EACrD,wBAAA,IAA4B,KAAA;IAC1B,UAAA,EAAY,cAAA;IACZ,eAAA,WAA0B,qBAAA;EAAA,aACf,OAAA;EACb,+BAAA,IAAmC,KAAA;IACjC,UAAA,EAAY,cAAA;IACZ,sBAAA,WAAiC,4BAAA;EAAA,aACtB,OAAA;EACb,6BAAA,IAAiC,KAAA;IAC/B,UAAA,EAAY,cAAA;IACZ,oBAAA,WAA+B,0BAAA;EAAA,aACpB,OAAA;EACb,yBAAA,IAA6B,KAAA;IAC3B,UAAA,EAAY,cAAA;IACZ,gBAAA,EAAkB,KAAA,CAAM,YAAA;EAAA,aACb,OAAA;AAAA;AAAA,cAoBF,mBAAA,SAA4B,cAAA;EAAA,iBACtB,UAAA;cAML,MAAA,EAAQ,yBAAA;EAAA,IAwBhB,oBAAA,CAAA,YAAoB,0BAAA;EAAA,IAIpB,sBAAA,CAAA,YAAsB,4BAAA;EF9EJ
|
|
1
|
+
{"version":3,"file":"context.d.mts","names":[],"sources":["../src/types/react-tool-call-renderer.ts","../src/types/react-activity-message-renderer.ts","../src/types/react-custom-message-renderer.ts","../src/lib/react-core.ts","../src/context.ts"],"mappings":";;;;;;;;;;AAeA;;;;;KAAY,qBAAA,gBAAqC,mBAAA,CAC/C,CAAA,EACA,KAAA,CAAM,aAAA,CAAc,mBAAA,CAAoB,CAAA;;;;;;;AAF1C;;;KCFY,4BAAA,qBACV,0BAAA,CACE,gBAAA,EACA,KAAA,CAAM,aAAA,CAAc,0BAAA,CAA2B,gBAAA;;;;;ADDnD;;;KEAK,6BAAA,GAAgC,IAAA,CACnC,wBAAA;EAGA,aAAA;AAAA;;;;;;KAQU,0BAAA,GACV,wBAAA,CAAyB,KAAA,CAAM,aAAA,CAAc,6BAAA;;;UCd9B,yBAAA,SAAkC,oBAAA;EAEjD,eAAA,GAAkB,qBAAA;EAClB,sBAAA,GAAyB,4BAAA;EAGzB,oBAAA,GAAuB,0BAAA;AAAA;AAAA,UAGR,6BAAA,SAAsC,wBAAA;EACrD,wBAAA,IAA4B,KAAA;IAC1B,UAAA,EAAY,cAAA;IACZ,eAAA,WAA0B,qBAAA;EAAA,aACf,OAAA;EACb,+BAAA,IAAmC,KAAA;IACjC,UAAA,EAAY,cAAA;IACZ,sBAAA,WAAiC,4BAAA;EAAA,aACtB,OAAA;EACb,6BAAA,IAAiC,KAAA;IAC/B,UAAA,EAAY,cAAA;IACZ,oBAAA,WAA+B,0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oreReact = class extends CopilotKitCore {
|
|
|
48
48
|
get renderActivityMessages() {
|
|
49
49
|
return this._renderers.activity;
|
|
50
50
|
}
|
|
51
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* Prop, hook and built-in renderers merged. For one name and agentId, a
|
|
53
|
+
* hook renderer wins over a prop one, and both win over a built-in one.
|
|
54
|
+
*/
|
|
52
55
|
get renderToolCalls() {
|
|
53
56
|
return this._renderers.toolCalls;
|
|
54
57
|
}
|
|
@@ -67,6 +70,16 @@ var CopilotKitCoreReact = class extends CopilotKitCore {
|
|
|
67
70
|
removeHookRenderToolCall(name, agentId) {
|
|
68
71
|
this._renderers.removeHookToolCall(name, agentId);
|
|
69
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* @internal Add a renderer for a tool a built-in feature owns (A2UI,
|
|
75
|
+
* generative UI). Prop and hook renderers with the same name and agent win
|
|
76
|
+
* over it, and `setRenderToolCalls` never removes it.
|
|
77
|
+
*
|
|
78
|
+
* @returns A function that removes the renderer.
|
|
79
|
+
*/
|
|
80
|
+
ɵaddBuiltInRenderToolCall(entry) {
|
|
81
|
+
return this._renderers.addBuiltInToolCall(entry);
|
|
82
|
+
}
|
|
70
83
|
notifyRenderersChanged(kind) {
|
|
71
84
|
this.notifySubscribers((subscriber) => {
|
|
72
85
|
const reactSubscriber = subscriber;
|
package/dist/context.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.mjs","names":[],"sources":["../src/lib/react-core.ts","../src/context.ts"],"sourcesContent":["import React from \"react\";\nimport type {\n ReactActivityMessageRenderer,\n ReactToolCallRenderer,\n} from \"../types\";\nimport type { ReactCustomMessageRenderer } from \"../types/react-custom-message-renderer\";\nimport { CopilotKitCore, ɵRendererRegistry } from \"@copilotkit/core\";\nimport type {\n CopilotKitCoreConfig,\n CopilotKitCoreSubscriber,\n CopilotKitCoreSubscription,\n ɵRendererKind,\n} from \"@copilotkit/core\";\n\nexport interface CopilotKitCoreReactConfig extends CopilotKitCoreConfig {\n // Add any additional configuration properties specific to the React implementation\n renderToolCalls?: ReactToolCallRenderer<any>[];\n renderActivityMessages?: ReactActivityMessageRenderer<any>[];\n\n // Add custom message renderers\n renderCustomMessages?: ReactCustomMessageRenderer[];\n}\n\nexport interface CopilotKitCoreReactSubscriber extends CopilotKitCoreSubscriber {\n onRenderToolCallsChanged?: (event: {\n copilotkit: CopilotKitCore;\n renderToolCalls: readonly ReactToolCallRenderer<any>[];\n }) => void | Promise<void>;\n onRenderActivityMessagesChanged?: (event: {\n copilotkit: CopilotKitCore;\n renderActivityMessages: readonly ReactActivityMessageRenderer<any>[];\n }) => void | Promise<void>;\n onRenderCustomMessagesChanged?: (event: {\n copilotkit: CopilotKitCore;\n renderCustomMessages: readonly ReactCustomMessageRenderer[];\n }) => void | Promise<void>;\n onInterruptElementChanged?: (event: {\n copilotkit: CopilotKitCore;\n interruptElement: React.ReactElement | null;\n }) => void | Promise<void>;\n}\n\n/**\n * Wait for pending React state updates before the follow-up agent run.\n *\n * When a frontend tool handler calls setState(), React 18 batches the update\n * and schedules a commit via its internal scheduler (MessageChannel). The\n * useAgentContext hook registers context via useLayoutEffect, which runs\n * synchronously after React commits that batch.\n *\n * Awaiting a zero-delay timeout yields to the macrotask queue. React's\n * MessageChannel task runs first, committing the pending state and running\n * useLayoutEffect (which updates the context store). The follow-up runAgent\n * call then reads fresh context.\n */\nfunction waitForReactCommit() {\n return new Promise<void>((resolve) => setTimeout(resolve, 0));\n}\n\nexport class CopilotKitCoreReact extends CopilotKitCore {\n private readonly _renderers: ɵRendererRegistry<\n ReactToolCallRenderer<any>,\n ReactActivityMessageRenderer<any>,\n ReactCustomMessageRenderer\n >;\n\n constructor(config: CopilotKitCoreReactConfig) {\n super({\n ...config,\n ɵwaitForFrameworkUpdates: waitForReactCommit,\n });\n this._renderers = new ɵRendererRegistry({\n toolCalls: config.renderToolCalls,\n activity: config.renderActivityMessages,\n custom: config.renderCustomMessages,\n });\n this._renderers.subscribe((kind) => this.notifyRenderersChanged(kind));\n // The element lives in core's generic interrupt slot; keep the React\n // subscriber event for existing listeners.\n this.ɵsubscribeToInterruptPayload(() => {\n void this.notifySubscribers((subscriber) => {\n const reactSubscriber = subscriber as CopilotKitCoreReactSubscriber;\n return reactSubscriber.onInterruptElementChanged?.({\n copilotkit: this,\n interruptElement: this.interruptElement,\n });\n }, \"Subscriber onInterruptElementChanged error:\");\n });\n }\n\n get renderCustomMessages() {\n return this._renderers.custom;\n }\n\n get renderActivityMessages() {\n return this._renderers.activity;\n }\n\n /** Prop and hook renderers merged; a hook renderer wins over a prop one. */\n get renderToolCalls() {\n return this._renderers.toolCalls;\n }\n\n setRenderActivityMessages(\n renderers: ReactActivityMessageRenderer<any>[],\n ): void {\n this._renderers.setActivity(renderers);\n }\n\n setRenderCustomMessages(renderers: ReactCustomMessageRenderer[]): void {\n this._renderers.setCustom(renderers);\n }\n\n setRenderToolCalls(renderToolCalls: ReactToolCallRenderer<any>[]): void {\n this._renderers.setPropToolCalls(renderToolCalls);\n }\n\n addHookRenderToolCall(entry: ReactToolCallRenderer<any>): void {\n this._renderers.addHookToolCall(entry);\n }\n\n removeHookRenderToolCall(name: string, agentId?: string): void {\n this._renderers.removeHookToolCall(name, agentId);\n }\n\n private notifyRenderersChanged(kind: ɵRendererKind): void {\n void this.notifySubscribers((subscriber) => {\n const reactSubscriber = subscriber as CopilotKitCoreReactSubscriber;\n switch (kind) {\n case \"toolCalls\":\n return reactSubscriber.onRenderToolCallsChanged?.({\n copilotkit: this,\n renderToolCalls: this.renderToolCalls,\n });\n case \"activity\":\n return reactSubscriber.onRenderActivityMessagesChanged?.({\n copilotkit: this,\n renderActivityMessages: this.renderActivityMessages,\n });\n case \"custom\":\n return reactSubscriber.onRenderCustomMessagesChanged?.({\n copilotkit: this,\n renderCustomMessages: this.renderCustomMessages,\n });\n }\n }, `Subscriber renderer change (${kind}) error:`);\n }\n\n get interruptElement(): React.ReactElement | null {\n return this.ɵinterruptPayload as React.ReactElement | null;\n }\n\n setInterruptElement(element: React.ReactElement | null): void {\n this.ɵsetInterruptPayload(element);\n }\n\n // Override to accept React-specific subscriber type\n subscribe(\n subscriber: CopilotKitCoreReactSubscriber,\n ): CopilotKitCoreSubscription {\n return super.subscribe(subscriber);\n }\n}\n","\"use client\";\n\nimport { createContext, useContext, useEffect, useReducer } from \"react\";\nimport { CopilotKitCoreReact } from \"./lib/react-core\";\nimport type { CopilotKitCoreReactConfig } from \"./lib/react-core\";\nimport type { LicenseContextValue } from \"@copilotkit/shared\";\n\n// Re-export so headless.ts (and consumers) reference the same type declaration.\nexport { CopilotKitCoreReact };\nexport type { CopilotKitCoreReactConfig };\n\nexport interface CopilotKitContextValue {\n copilotkit: CopilotKitCoreReact;\n /**\n * Whether CopilotKit should automatically mount Intelligence indicators.\n * Defaults to true when omitted for compatibility with custom providers.\n */\n showIntelligenceIndicator?: boolean;\n /**\n * Set of tool call IDs currently being executed.\n * This is tracked at the provider level to ensure tool execution events\n * are captured even before child components mount.\n */\n executingToolCallIds: ReadonlySet<string>;\n}\n\nexport const EMPTY_SET: ReadonlySet<string> = new Set();\n\nexport const CopilotKitContext = createContext<CopilotKitContextValue | null>(\n null,\n);\n\nexport const useCopilotKit = (): CopilotKitContextValue => {\n const context = useContext(CopilotKitContext);\n const [, forceUpdate] = useReducer((x: number) => x + 1, 0);\n\n if (!context) {\n throw new Error(\"useCopilotKit must be used within CopilotKitProvider\");\n }\n useEffect(() => {\n const subscription = context.copilotkit.subscribe({\n onRuntimeConnectionStatusChanged: () => {\n forceUpdate();\n },\n onHeadersChanged: () => {\n forceUpdate();\n },\n });\n return () => {\n subscription.unsubscribe();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return context;\n};\n\n// License context — shared between web and RN providers.\n// Default is permissive (all features allowed) — providers override via createLicenseContextValue.\n// Inlined here to avoid a runtime import from @copilotkit/shared, which pulls in\n// Node-only deps (jose) that break React Native's Metro bundler.\nexport const LicenseContext = createContext<LicenseContextValue>({\n status: null,\n license: null,\n checkFeature: () => true,\n getLimit: () => null,\n} as LicenseContextValue);\n\nexport const useLicenseContext = (): LicenseContextValue =>\n useContext(LicenseContext);\n\n// Provider-level default agent id, published by `<CopilotKitProvider agentId>`.\n//\n// This is a context of its own rather than a `CopilotChatConfigurationProvider`\n// rendered at the root, because that provider also owns a thread: it resolves a\n// threadId (minting a UUID when none is given) and the top-most one owns the\n// imperative active-thread override. Rendering it around the whole application\n// would hand every `<CopilotChat>` the same inherited threadId, so two sibling\n// chats would share one transcript. A bare string context carries the agent\n// default and nothing else.\n//\n// It is the LAST fallback before `DEFAULT_AGENT_ID`, so an explicit `agentId`\n// argument, a `<CopilotChat agentId>`, and a `<CopilotChatConfigurationProvider\n// agentId>` all still win.\nexport const CopilotKitAgentIdContext = createContext<string | undefined>(\n undefined,\n);\n\nexport const useDefaultAgentId = (): string | undefined =>\n useContext(CopilotKitAgentIdContext);\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAuDA,SAAS,qBAAqB;AAC5B,QAAO,IAAI,SAAe,YAAY,WAAW,SAAS,EAAE,CAAC;;AAG/D,IAAa,sBAAb,cAAyC,eAAe;CACtD,AAAiB;CAMjB,YAAY,QAAmC;AAC7C,QAAM;GACJ,GAAG;GACH,0BAA0B;GAC3B,CAAC;AACF,OAAK,aAAa,IAAI,kBAAkB;GACtC,WAAW,OAAO;GAClB,UAAU,OAAO;GACjB,QAAQ,OAAO;GAChB,CAAC;AACF,OAAK,WAAW,WAAW,SAAS,KAAK,uBAAuB,KAAK,CAAC;AAGtE,OAAK,mCAAmC;AACtC,GAAK,KAAK,mBAAmB,eAAe;AAE1C,WADwB,WACD,4BAA4B;KACjD,YAAY;KACZ,kBAAkB,KAAK;KACxB,CAAC;MACD,8CAA8C;IACjD;;CAGJ,IAAI,uBAAuB;AACzB,SAAO,KAAK,WAAW;;CAGzB,IAAI,yBAAyB;AAC3B,SAAO,KAAK,WAAW;;;CAIzB,IAAI,kBAAkB;AAC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B,EAAE,CAAC;AAEN,QAAO;;AAOT,MAAa,iBAAiB,cAAmC;CAC/D,QAAQ;CACR,SAAS;CACT,oBAAoB;CACpB,gBAAgB;CACjB,CAAwB;AAEzB,MAAa,0BACX,WAAW,eAAe;AAe5B,MAAa,2BAA2B,cACtC,OACD;AAED,MAAa,0BACX,WAAW,yBAAyB"}
|
|
1
|
+
{"version":3,"file":"context.mjs","names":[],"sources":["../src/lib/react-core.ts","../src/context.ts"],"sourcesContent":["import React from \"react\";\nimport type {\n ReactActivityMessageRenderer,\n ReactToolCallRenderer,\n} from \"../types\";\nimport type { ReactCustomMessageRenderer } from \"../types/react-custom-message-renderer\";\nimport { CopilotKitCore, ɵRendererRegistry } from \"@copilotkit/core\";\nimport type {\n CopilotKitCoreConfig,\n CopilotKitCoreSubscriber,\n CopilotKitCoreSubscription,\n ɵRendererKind,\n} from \"@copilotkit/core\";\n\nexport interface CopilotKitCoreReactConfig extends CopilotKitCoreConfig {\n // Add any additional configuration properties specific to the React implementation\n renderToolCalls?: ReactToolCallRenderer<any>[];\n renderActivityMessages?: ReactActivityMessageRenderer<any>[];\n\n // Add custom message renderers\n renderCustomMessages?: ReactCustomMessageRenderer[];\n}\n\nexport interface CopilotKitCoreReactSubscriber extends CopilotKitCoreSubscriber {\n onRenderToolCallsChanged?: (event: {\n copilotkit: CopilotKitCore;\n renderToolCalls: readonly ReactToolCallRenderer<any>[];\n }) => void | Promise<void>;\n onRenderActivityMessagesChanged?: (event: {\n copilotkit: CopilotKitCore;\n renderActivityMessages: readonly ReactActivityMessageRenderer<any>[];\n }) => void | Promise<void>;\n onRenderCustomMessagesChanged?: (event: {\n copilotkit: CopilotKitCore;\n renderCustomMessages: readonly ReactCustomMessageRenderer[];\n }) => void | Promise<void>;\n onInterruptElementChanged?: (event: {\n copilotkit: CopilotKitCore;\n interruptElement: React.ReactElement | null;\n }) => void | Promise<void>;\n}\n\n/**\n * Wait for pending React state updates before the follow-up agent run.\n *\n * When a frontend tool handler calls setState(), React 18 batches the update\n * and schedules a commit via its internal scheduler (MessageChannel). The\n * useAgentContext hook registers context via useLayoutEffect, which runs\n * synchronously after React commits that batch.\n *\n * Awaiting a zero-delay timeout yields to the macrotask queue. React's\n * MessageChannel task runs first, committing the pending state and running\n * useLayoutEffect (which updates the context store). The follow-up runAgent\n * call then reads fresh context.\n */\nfunction waitForReactCommit() {\n return new Promise<void>((resolve) => setTimeout(resolve, 0));\n}\n\nexport class CopilotKitCoreReact extends CopilotKitCore {\n private readonly _renderers: ɵRendererRegistry<\n ReactToolCallRenderer<any>,\n ReactActivityMessageRenderer<any>,\n ReactCustomMessageRenderer\n >;\n\n constructor(config: CopilotKitCoreReactConfig) {\n super({\n ...config,\n ɵwaitForFrameworkUpdates: waitForReactCommit,\n });\n this._renderers = new ɵRendererRegistry({\n toolCalls: config.renderToolCalls,\n activity: config.renderActivityMessages,\n custom: config.renderCustomMessages,\n });\n this._renderers.subscribe((kind) => this.notifyRenderersChanged(kind));\n // The element lives in core's generic interrupt slot; keep the React\n // subscriber event for existing listeners.\n this.ɵsubscribeToInterruptPayload(() => {\n void this.notifySubscribers((subscriber) => {\n const reactSubscriber = subscriber as CopilotKitCoreReactSubscriber;\n return reactSubscriber.onInterruptElementChanged?.({\n copilotkit: this,\n interruptElement: this.interruptElement,\n });\n }, \"Subscriber onInterruptElementChanged error:\");\n });\n }\n\n get renderCustomMessages() {\n return this._renderers.custom;\n }\n\n get renderActivityMessages() {\n return this._renderers.activity;\n }\n\n /**\n * Prop, hook and built-in renderers merged. For one name and agentId, a\n * hook renderer wins over a prop one, and both win over a built-in one.\n */\n get renderToolCalls() {\n return this._renderers.toolCalls;\n }\n\n setRenderActivityMessages(\n renderers: ReactActivityMessageRenderer<any>[],\n ): void {\n this._renderers.setActivity(renderers);\n }\n\n setRenderCustomMessages(renderers: ReactCustomMessageRenderer[]): void {\n this._renderers.setCustom(renderers);\n }\n\n setRenderToolCalls(renderToolCalls: ReactToolCallRenderer<any>[]): void {\n this._renderers.setPropToolCalls(renderToolCalls);\n }\n\n addHookRenderToolCall(entry: ReactToolCallRenderer<any>): void {\n this._renderers.addHookToolCall(entry);\n }\n\n removeHookRenderToolCall(name: string, agentId?: string): void {\n this._renderers.removeHookToolCall(name, agentId);\n }\n\n /**\n * @internal Add a renderer for a tool a built-in feature owns (A2UI,\n * generative UI). Prop and hook renderers with the same name and agent win\n * over it, and `setRenderToolCalls` never removes it.\n *\n * @returns A function that removes the renderer.\n */\n ɵaddBuiltInRenderToolCall(entry: ReactToolCallRenderer): () => void {\n return this._renderers.addBuiltInToolCall(entry);\n }\n\n private notifyRenderersChanged(kind: ɵRendererKind): void {\n void this.notifySubscribers((subscriber) => {\n const reactSubscriber = subscriber as CopilotKitCoreReactSubscriber;\n switch (kind) {\n case \"toolCalls\":\n return reactSubscriber.onRenderToolCallsChanged?.({\n copilotkit: this,\n renderToolCalls: this.renderToolCalls,\n });\n case \"activity\":\n return reactSubscriber.onRenderActivityMessagesChanged?.({\n copilotkit: this,\n renderActivityMessages: this.renderActivityMessages,\n });\n case \"custom\":\n return reactSubscriber.onRenderCustomMessagesChanged?.({\n copilotkit: this,\n renderCustomMessages: this.renderCustomMessages,\n });\n }\n }, `Subscriber renderer change (${kind}) error:`);\n }\n\n get interruptElement(): React.ReactElement | null {\n return this.ɵinterruptPayload as React.ReactElement | null;\n }\n\n setInterruptElement(element: React.ReactElement | null): void {\n this.ɵsetInterruptPayload(element);\n }\n\n // Override to accept React-specific subscriber type\n subscribe(\n subscriber: CopilotKitCoreReactSubscriber,\n ): CopilotKitCoreSubscription {\n return super.subscribe(subscriber);\n }\n}\n","\"use client\";\n\nimport { createContext, useContext, useEffect, useReducer } from \"react\";\nimport { CopilotKitCoreReact } from \"./lib/react-core\";\nimport type { CopilotKitCoreReactConfig } from \"./lib/react-core\";\nimport type { LicenseContextValue } from \"@copilotkit/shared\";\n\n// Re-export so headless.ts (and consumers) reference the same type declaration.\nexport { CopilotKitCoreReact };\nexport type { CopilotKitCoreReactConfig };\n\nexport interface CopilotKitContextValue {\n copilotkit: CopilotKitCoreReact;\n /**\n * Whether CopilotKit should automatically mount Intelligence indicators.\n * Defaults to true when omitted for compatibility with custom providers.\n */\n showIntelligenceIndicator?: boolean;\n /**\n * Set of tool call IDs currently being executed.\n * This is tracked at the provider level to ensure tool execution events\n * are captured even before child components mount.\n */\n executingToolCallIds: ReadonlySet<string>;\n}\n\nexport const EMPTY_SET: ReadonlySet<string> = new Set();\n\nexport const CopilotKitContext = createContext<CopilotKitContextValue | null>(\n null,\n);\n\nexport const useCopilotKit = (): CopilotKitContextValue => {\n const context = useContext(CopilotKitContext);\n const [, forceUpdate] = useReducer((x: number) => x + 1, 0);\n\n if (!context) {\n throw new Error(\"useCopilotKit must be used within CopilotKitProvider\");\n }\n useEffect(() => {\n const subscription = context.copilotkit.subscribe({\n onRuntimeConnectionStatusChanged: () => {\n forceUpdate();\n },\n onHeadersChanged: () => {\n forceUpdate();\n },\n });\n return () => {\n subscription.unsubscribe();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return context;\n};\n\n// License context — shared between web and RN providers.\n// Default is permissive (all features allowed) — providers override via createLicenseContextValue.\n// Inlined here to avoid a runtime import from @copilotkit/shared, which pulls in\n// Node-only deps (jose) that break React Native's Metro bundler.\nexport const LicenseContext = createContext<LicenseContextValue>({\n status: null,\n license: null,\n checkFeature: () => true,\n getLimit: () => null,\n} as LicenseContextValue);\n\nexport const useLicenseContext = (): LicenseContextValue =>\n useContext(LicenseContext);\n\n// Provider-level default agent id, published by `<CopilotKitProvider agentId>`.\n//\n// This is a context of its own rather than a `CopilotChatConfigurationProvider`\n// rendered at the root, because that provider also owns a thread: it resolves a\n// threadId (minting a UUID when none is given) and the top-most one owns the\n// imperative active-thread override. Rendering it around the whole application\n// would hand every `<CopilotChat>` the same inherited threadId, so two sibling\n// chats would share one transcript. A bare string context carries the agent\n// default and nothing else.\n//\n// It is the LAST fallback before `DEFAULT_AGENT_ID`, so an explicit `agentId`\n// argument, a `<CopilotChat agentId>`, and a `<CopilotChatConfigurationProvider\n// agentId>` all still win.\nexport const CopilotKitAgentIdContext = createContext<string | undefined>(\n undefined,\n);\n\nexport const useDefaultAgentId = (): string | undefined =>\n useContext(CopilotKitAgentIdContext);\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAuDA,SAAS,qBAAqB;AAC5B,QAAO,IAAI,SAAe,YAAY,WAAW,SAAS,EAAE,CAAC;;AAG/D,IAAa,sBAAb,cAAyC,eAAe;CACtD,AAAiB;CAMjB,YAAY,QAAmC;AAC7C,QAAM;GACJ,GAAG;GACH,0BAA0B;GAC3B,CAAC;AACF,OAAK,aAAa,IAAI,kBAAkB;GACtC,WAAW,OAAO;GAClB,UAAU,OAAO;GACjB,QAAQ,OAAO;GAChB,CAAC;AACF,OAAK,WAAW,WAAW,SAAS,KAAK,uBAAuB,KAAK,CAAC;AAGtE,OAAK,mCAAmC;AACtC,GAAK,KAAK,mBAAmB,eAAe;AAE1C,WADwB,WACD,4BAA4B;KACjD,YAAY;KACZ,kBAAkB,KAAK;KACxB,CAAC;MACD,8CAA8C;IACjD;;CAGJ,IAAI,uBAAuB;AACzB,SAAO,KAAK,WAAW;;CAGzB,IAAI,yBAAyB;AAC3B,SAAO,KAAK,WAAW;;;;;;CAOzB,IAAI,kBAAkB;AACpB,SAAO,KAAK,WAAW;;CAGzB,0BACE,WACM;AACN,OAAK,WAAW,YAAY,UAAU;;CAGxC,wBAAwB,WAA+C;AACrE,OAAK,WAAW,UAAU,UAAU;;CAGtC,mBAAmB,iBAAqD;AACtE,OAAK,WAAW,iBAAiB,gBAAgB;;CAGnD,sBAAsB,OAAyC;AAC7D,OAAK,WAAW,gBAAgB,MAAM;;CAGxC,yBAAyB,MAAc,SAAwB;AAC7D,OAAK,WAAW,mBAAmB,MAAM,QAAQ;;;;;;;;;CAUnD,0BAA0B,OAA0C;AAClE,SAAO,KAAK,WAAW,mBAAmB,MAAM;;CAGlD,AAAQ,uBAAuB,M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Tag, { value: 'Module' });
|
|
4
|
-
const require_MarkdownSurfaces = require('./MarkdownSurfaces-
|
|
4
|
+
const require_MarkdownSurfaces = require('./MarkdownSurfaces-BbrHcSHN.cjs');
|
|
5
5
|
let react = require("react");
|
|
6
6
|
react = require_MarkdownSurfaces.__toESM(react);
|
|
7
7
|
let react_jsx_runtime = require("react/jsx-runtime");
|
package/dist/generative-ui.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { F as toJsonSchema, K as IconSvg, O as isRecord, P as createGenerativeUI, _ as GenerativeUINodeContext, b as useRequiredGenerativeUIRuntime, c as SurfaceView, d as namedRole, f as useGenerativeUIAccessibility, g as useManagerVersion, h as useGenerativeUIState, j as GenerativeUIError, l as DARK_THEME_CSS, m as useGenerativeUIFunction, n as ProviderMarkdown, p as wrapperAria, r as DefaultGenerativeUIChatCard, t as MarkdownSurfaces, u as controlAria, y as useGenerativeUIRuntime } from "./MarkdownSurfaces-
|
|
3
|
+
import { F as toJsonSchema, K as IconSvg, O as isRecord, P as createGenerativeUI, _ as GenerativeUINodeContext, b as useRequiredGenerativeUIRuntime, c as SurfaceView, d as namedRole, f as useGenerativeUIAccessibility, g as useManagerVersion, h as useGenerativeUIState, j as GenerativeUIError, l as DARK_THEME_CSS, m as useGenerativeUIFunction, n as ProviderMarkdown, p as wrapperAria, r as DefaultGenerativeUIChatCard, t as MarkdownSurfaces, u as controlAria, y as useGenerativeUIRuntime } from "./MarkdownSurfaces-DQbRS91-.mjs";
|
|
4
4
|
import React, { Suspense, createContext, isValidElement, memo, useCallback, useContext, useEffect, useId, useInsertionEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
5
5
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
6
6
|
import { A2UI_CHILD_LIST_MARK, A2UI_CHILD_LIST_REF, A2UI_COMPONENT_ID_MARK, A2UI_COMPONENT_ID_REF, GENERATIVE_UI_FUNCTIONS, GENERATIVE_UI_MAX_TARGET_COMPONENTS, childRefKind, functionCallers } from "@copilotkit/shared";
|
package/dist/headless.cjs
CHANGED
|
@@ -458,21 +458,7 @@ function useFrontendTool(tool, deps) {
|
|
|
458
458
|
const { copilotkit } = (0, _copilotkit_react_core_context.useCopilotKit)();
|
|
459
459
|
const depsVersion = useDepsVersion(deps);
|
|
460
460
|
(0, react.useLayoutEffect)(() => {
|
|
461
|
-
|
|
462
|
-
if (copilotkit.getTool({
|
|
463
|
-
toolName: name,
|
|
464
|
-
agentId: tool.agentId
|
|
465
|
-
})) console.warn(`Tool '${name}' already exists for agent '${tool.agentId || "global"}'. Overriding with latest registration.`);
|
|
466
|
-
const unregister = copilotkit.addTool(tool);
|
|
467
|
-
if (tool.render) copilotkit.addHookRenderToolCall({
|
|
468
|
-
name,
|
|
469
|
-
args: tool.parameters,
|
|
470
|
-
agentId: tool.agentId,
|
|
471
|
-
render: tool.render
|
|
472
|
-
});
|
|
473
|
-
return () => {
|
|
474
|
-
unregister();
|
|
475
|
-
};
|
|
461
|
+
return (0, _copilotkit_core.ɵregisterFrontendTools)(copilotkit, [tool], (renderer) => copilotkit.addHookRenderToolCall(renderer));
|
|
476
462
|
}, [
|
|
477
463
|
tool.name,
|
|
478
464
|
tool.available,
|
|
@@ -542,30 +528,7 @@ function useFrontendTools(tools, deps) {
|
|
|
542
528
|
const toolList = tools ?? EMPTY_TOOLS;
|
|
543
529
|
const extraDeps = deps ?? EMPTY_DEPS;
|
|
544
530
|
(0, react.useLayoutEffect)(() => {
|
|
545
|
-
|
|
546
|
-
for (const tool of toolList) {
|
|
547
|
-
const key = `${tool.agentId ?? ""}:${tool.name}`;
|
|
548
|
-
if (deduped.has(key)) console.warn(`Tool '${tool.name}' is listed more than once for agent '${tool.agentId || "global"}' in the same useFrontendTools call. Using the last entry.`);
|
|
549
|
-
deduped.set(key, tool);
|
|
550
|
-
}
|
|
551
|
-
const registered = [...deduped.values()];
|
|
552
|
-
const unregisters = [];
|
|
553
|
-
for (const tool of registered) {
|
|
554
|
-
if (copilotkit.getTool({
|
|
555
|
-
toolName: tool.name,
|
|
556
|
-
agentId: tool.agentId
|
|
557
|
-
})) console.warn(`Tool '${tool.name}' already exists for agent '${tool.agentId || "global"}'. Overriding with latest registration.`);
|
|
558
|
-
unregisters.push(copilotkit.addTool(tool));
|
|
559
|
-
if (tool.render) copilotkit.addHookRenderToolCall({
|
|
560
|
-
name: tool.name,
|
|
561
|
-
args: tool.parameters,
|
|
562
|
-
agentId: tool.agentId,
|
|
563
|
-
render: tool.render
|
|
564
|
-
});
|
|
565
|
-
}
|
|
566
|
-
return () => {
|
|
567
|
-
for (const unregister of unregisters) unregister();
|
|
568
|
-
};
|
|
531
|
+
return (0, _copilotkit_core.ɵregisterFrontendTools)(copilotkit, toolList, (renderer) => copilotkit.addHookRenderToolCall(renderer));
|
|
569
532
|
}, [
|
|
570
533
|
JSON.stringify(toolList.map((tool) => [
|
|
571
534
|
tool.name,
|
|
@@ -749,7 +712,11 @@ function useSuggestions({ agentId } = {}) {
|
|
|
749
712
|
const { copilotkit } = (0, _copilotkit_react_core_context.useCopilotKit)();
|
|
750
713
|
const config = useCopilotChatConfiguration();
|
|
751
714
|
const providerAgentId = (0, _copilotkit_react_core_context.useDefaultAgentId)();
|
|
752
|
-
const resolvedAgentId = (0, react.useMemo)(() =>
|
|
715
|
+
const resolvedAgentId = (0, react.useMemo)(() => (0, _copilotkit_core.ɵresolveAgentId)({
|
|
716
|
+
agentId,
|
|
717
|
+
chatAgentId: config?.agentId,
|
|
718
|
+
providerAgentId
|
|
719
|
+
}), [
|
|
753
720
|
agentId,
|
|
754
721
|
config?.agentId,
|
|
755
722
|
providerAgentId
|
|
@@ -792,7 +759,10 @@ function useConfigureSuggestions(config, deps) {
|
|
|
792
759
|
const { copilotkit } = (0, _copilotkit_react_core_context.useCopilotKit)();
|
|
793
760
|
const chatConfig = useCopilotChatConfiguration();
|
|
794
761
|
const providerAgentId = (0, _copilotkit_react_core_context.useDefaultAgentId)();
|
|
795
|
-
const chatAgentId =
|
|
762
|
+
const chatAgentId = (0, _copilotkit_core.ɵresolveAgentId)({
|
|
763
|
+
chatAgentId: chatConfig?.agentId,
|
|
764
|
+
providerAgentId
|
|
765
|
+
});
|
|
796
766
|
const extraDeps = deps ?? [];
|
|
797
767
|
const bindingRef = (0, react.useRef)(null);
|
|
798
768
|
const latestRef = (0, react.useRef)({
|