@copilotkit/react-core 1.70.3 → 1.71.1
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/{copilotkit-BU3OvveB.cjs → copilotkit-BkVEkUS0.cjs} +369 -154
- package/dist/copilotkit-BkVEkUS0.cjs.map +1 -0
- package/dist/{copilotkit-Bs98akp9.d.mts → copilotkit-ChjzWqn6.d.mts} +33 -8
- package/dist/copilotkit-ChjzWqn6.d.mts.map +1 -0
- package/dist/{copilotkit-Ap_yisA5.mjs → copilotkit-D5BTo0YG.mjs} +368 -153
- package/dist/copilotkit-D5BTo0YG.mjs.map +1 -0
- package/dist/{copilotkit-X2eGbOwf.d.cts → copilotkit-DCIXZawe.d.cts} +33 -8
- package/dist/copilotkit-DCIXZawe.d.cts.map +1 -0
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +4 -4
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +180 -139
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/context.cjs +4 -0
- package/dist/v2/context.cjs.map +1 -1
- package/dist/v2/context.d.cts +3 -1
- package/dist/v2/context.d.cts.map +1 -1
- package/dist/v2/context.d.mts +3 -1
- package/dist/v2/context.d.mts.map +1 -1
- package/dist/v2/context.mjs +3 -1
- package/dist/v2/context.mjs.map +1 -1
- package/dist/v2/headless.cjs +20 -5
- package/dist/v2/headless.cjs.map +1 -1
- package/dist/v2/headless.d.cts +9 -4
- package/dist/v2/headless.d.cts.map +1 -1
- package/dist/v2/headless.d.mts +9 -4
- package/dist/v2/headless.d.mts.map +1 -1
- package/dist/v2/headless.mjs +21 -6
- package/dist/v2/headless.mjs.map +1 -1
- package/dist/v2/index.cjs +1 -1
- package/dist/v2/index.css +1 -1
- package/dist/v2/index.d.cts +1 -1
- package/dist/v2/index.d.mts +1 -1
- package/dist/v2/index.mjs +1 -1
- package/dist/v2/index.umd.js +495 -278
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +8 -9
- package/dist/copilotkit-Ap_yisA5.mjs.map +0 -1
- package/dist/copilotkit-BU3OvveB.cjs.map +0 -1
- package/dist/copilotkit-Bs98akp9.d.mts.map +0 -1
- package/dist/copilotkit-X2eGbOwf.d.cts.map +0 -1
- package/skills/react-core/SKILL.md +0 -110
- package/skills/react-core/references/agent-access.md +0 -355
- package/skills/react-core/references/attachments.md +0 -311
- package/skills/react-core/references/capabilities.md +0 -138
- package/skills/react-core/references/chat-components.md +0 -229
- package/skills/react-core/references/client-side-tools.md +0 -358
- package/skills/react-core/references/custom-message-renderers.md +0 -223
- package/skills/react-core/references/debug-mode.md +0 -140
- package/skills/react-core/references/human-in-the-loop.md +0 -312
- package/skills/react-core/references/provider-setup.md +0 -358
- package/skills/react-core/references/rendering-activity-messages.md +0 -201
- package/skills/react-core/references/rendering-tool-calls.md +0 -319
- package/skills/react-core/references/suggestions.md +0 -211
- package/skills/react-core/references/switching-agents-recipes.md +0 -161
- package/skills/react-core/references/switching-agents.md +0 -240
- package/skills/react-core/references/threads.md +0 -289
package/dist/v2/context.cjs
CHANGED
|
@@ -129,12 +129,16 @@ const LicenseContext = (0, react.createContext)({
|
|
|
129
129
|
getLimit: () => null
|
|
130
130
|
});
|
|
131
131
|
const useLicenseContext = () => (0, react.useContext)(LicenseContext);
|
|
132
|
+
const CopilotKitAgentIdContext = (0, react.createContext)(void 0);
|
|
133
|
+
const useDefaultAgentId = () => (0, react.useContext)(CopilotKitAgentIdContext);
|
|
132
134
|
|
|
133
135
|
//#endregion
|
|
136
|
+
exports.CopilotKitAgentIdContext = CopilotKitAgentIdContext;
|
|
134
137
|
exports.CopilotKitContext = CopilotKitContext;
|
|
135
138
|
exports.CopilotKitCoreReact = CopilotKitCoreReact;
|
|
136
139
|
exports.EMPTY_SET = EMPTY_SET;
|
|
137
140
|
exports.LicenseContext = LicenseContext;
|
|
138
141
|
exports.useCopilotKit = useCopilotKit;
|
|
142
|
+
exports.useDefaultAgentId = useDefaultAgentId;
|
|
139
143
|
exports.useLicenseContext = useLicenseContext;
|
|
140
144
|
//# sourceMappingURL=context.cjs.map
|
package/dist/v2/context.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.cjs","names":["CopilotKitCore"],"sources":["../../src/v2/lib/react-core.ts","../../src/v2/context.ts"],"sourcesContent":["import React from \"react\";\nimport { ReactActivityMessageRenderer, ReactToolCallRenderer } from \"../types\";\nimport { ReactCustomMessageRenderer } from \"../types/react-custom-message-renderer\";\nimport {\n CopilotKitCore,\n type CopilotKitCoreConfig,\n type CopilotKitCoreSubscriber,\n type CopilotKitCoreSubscription,\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: ReactToolCallRenderer<any>[];\n }) => void | Promise<void>;\n onInterruptElementChanged?: (event: {\n copilotkit: CopilotKitCore;\n interruptElement: React.ReactElement | null;\n }) => void | Promise<void>;\n}\n\nexport class CopilotKitCoreReact extends CopilotKitCore {\n private _renderToolCalls: ReactToolCallRenderer<any>[] = [];\n private _hookRenderToolCalls: Map<string, ReactToolCallRenderer<any>> =\n new Map();\n private _cachedMergedRenderToolCalls: ReactToolCallRenderer<any>[] | null =\n null;\n private _renderCustomMessages: ReactCustomMessageRenderer[] = [];\n private _renderActivityMessages: ReactActivityMessageRenderer<any>[] = [];\n private _interruptElement: React.ReactElement | null = null;\n\n constructor(config: CopilotKitCoreReactConfig) {\n super(config);\n this._renderToolCalls = config.renderToolCalls ?? [];\n this._renderCustomMessages = config.renderCustomMessages ?? [];\n this._renderActivityMessages = config.renderActivityMessages ?? [];\n }\n\n get renderCustomMessages(): Readonly<ReactCustomMessageRenderer[]> {\n return this._renderCustomMessages;\n }\n\n get renderActivityMessages(): Readonly<ReactActivityMessageRenderer<any>>[] {\n return this._renderActivityMessages;\n }\n\n get renderToolCalls(): Readonly<ReactToolCallRenderer<any>>[] {\n if (this._hookRenderToolCalls.size === 0) {\n return this._renderToolCalls;\n }\n if (this._cachedMergedRenderToolCalls) {\n return this._cachedMergedRenderToolCalls;\n }\n // Merge: hook entries override prop entries with the same key\n const merged = new Map<string, ReactToolCallRenderer<any>>();\n for (const rc of this._renderToolCalls) {\n merged.set(`${rc.agentId ?? \"\"}:${rc.name}`, rc);\n }\n for (const [key, rc] of this._hookRenderToolCalls) {\n merged.set(key, rc);\n }\n this._cachedMergedRenderToolCalls = Array.from(merged.values());\n return this._cachedMergedRenderToolCalls;\n }\n\n setRenderActivityMessages(\n renderers: ReactActivityMessageRenderer<any>[],\n ): void {\n this._renderActivityMessages = renderers;\n }\n\n setRenderCustomMessages(renderers: ReactCustomMessageRenderer[]): void {\n this._renderCustomMessages = renderers;\n }\n\n setRenderToolCalls(renderToolCalls: ReactToolCallRenderer<any>[]): void {\n this._renderToolCalls = renderToolCalls;\n this._cachedMergedRenderToolCalls = null;\n this._notifyRenderToolCallsChanged();\n }\n\n addHookRenderToolCall(entry: ReactToolCallRenderer<any>): void {\n const key = `${entry.agentId ?? \"\"}:${entry.name}`;\n this._hookRenderToolCalls.set(key, entry);\n this._cachedMergedRenderToolCalls = null;\n this._notifyRenderToolCallsChanged();\n }\n\n removeHookRenderToolCall(name: string, agentId?: string): void {\n const key = `${agentId ?? \"\"}:${name}`;\n if (this._hookRenderToolCalls.delete(key)) {\n this._cachedMergedRenderToolCalls = null;\n this._notifyRenderToolCallsChanged();\n }\n }\n\n private _notifyRenderToolCallsChanged(): void {\n void this.notifySubscribers((subscriber) => {\n const reactSubscriber = subscriber as CopilotKitCoreReactSubscriber;\n if (reactSubscriber.onRenderToolCallsChanged) {\n reactSubscriber.onRenderToolCallsChanged({\n copilotkit: this,\n renderToolCalls: this.renderToolCalls,\n });\n }\n }, \"Subscriber onRenderToolCallsChanged error:\");\n }\n\n get interruptElement(): React.ReactElement | null {\n return this._interruptElement;\n }\n\n setInterruptElement(element: React.ReactElement | null): void {\n this._interruptElement = element;\n void this.notifySubscribers((subscriber) => {\n const reactSubscriber = subscriber as CopilotKitCoreReactSubscriber;\n reactSubscriber.onInterruptElementChanged?.({\n copilotkit: this,\n interruptElement: this._interruptElement,\n });\n }, \"Subscriber onInterruptElementChanged error:\");\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 /**\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 */\n async waitForPendingFrameworkUpdates(): Promise<void> {\n await new Promise<void>((resolve) => setTimeout(resolve, 0));\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 * 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"],"mappings":";;;;;;;AA8BA,IAAa,sBAAb,cAAyCA,gCAAe;CAUtD,YAAY,QAAmC;AAC7C,QAAM,OAAO;0BAV0C,EAAE;8CAEzD,IAAI,KAAK;sCAET;+BAC4D,EAAE;iCACO,EAAE;2BAClB;AAIrD,OAAK,mBAAmB,OAAO,mBAAmB,EAAE;AACpD,OAAK,wBAAwB,OAAO,wBAAwB,EAAE;AAC9D,OAAK,0BAA0B,OAAO,0BAA0B,EAAE;;CAGpE,IAAI,uBAA+D;AACjE,SAAO,KAAK;;CAGd,IAAI,yBAAwE;AAC1E,SAAO,KAAK;;CAGd,IAAI,kBAA0D;AAC5D,MAAI,KAAK,qBAAqB,SAAS,EACrC,QAAO,KAAK;AAEd,MAAI,KAAK,6BACP,QAAO,KAAK;EAGd,MAAM,yBAAS,IAAI,KA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,SAAe,YAAY,WAAW,SAAS,EAAE,CAAC;;;;;;ACpIhE,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"}
|
|
1
|
+
{"version":3,"file":"context.cjs","names":["CopilotKitCore"],"sources":["../../src/v2/lib/react-core.ts","../../src/v2/context.ts"],"sourcesContent":["import React from \"react\";\nimport { ReactActivityMessageRenderer, ReactToolCallRenderer } from \"../types\";\nimport { ReactCustomMessageRenderer } from \"../types/react-custom-message-renderer\";\nimport {\n CopilotKitCore,\n type CopilotKitCoreConfig,\n type CopilotKitCoreSubscriber,\n type CopilotKitCoreSubscription,\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: ReactToolCallRenderer<any>[];\n }) => void | Promise<void>;\n onInterruptElementChanged?: (event: {\n copilotkit: CopilotKitCore;\n interruptElement: React.ReactElement | null;\n }) => void | Promise<void>;\n}\n\nexport class CopilotKitCoreReact extends CopilotKitCore {\n private _renderToolCalls: ReactToolCallRenderer<any>[] = [];\n private _hookRenderToolCalls: Map<string, ReactToolCallRenderer<any>> =\n new Map();\n private _cachedMergedRenderToolCalls: ReactToolCallRenderer<any>[] | null =\n null;\n private _renderCustomMessages: ReactCustomMessageRenderer[] = [];\n private _renderActivityMessages: ReactActivityMessageRenderer<any>[] = [];\n private _interruptElement: React.ReactElement | null = null;\n\n constructor(config: CopilotKitCoreReactConfig) {\n super(config);\n this._renderToolCalls = config.renderToolCalls ?? [];\n this._renderCustomMessages = config.renderCustomMessages ?? [];\n this._renderActivityMessages = config.renderActivityMessages ?? [];\n }\n\n get renderCustomMessages(): Readonly<ReactCustomMessageRenderer[]> {\n return this._renderCustomMessages;\n }\n\n get renderActivityMessages(): Readonly<ReactActivityMessageRenderer<any>>[] {\n return this._renderActivityMessages;\n }\n\n get renderToolCalls(): Readonly<ReactToolCallRenderer<any>>[] {\n if (this._hookRenderToolCalls.size === 0) {\n return this._renderToolCalls;\n }\n if (this._cachedMergedRenderToolCalls) {\n return this._cachedMergedRenderToolCalls;\n }\n // Merge: hook entries override prop entries with the same key\n const merged = new Map<string, ReactToolCallRenderer<any>>();\n for (const rc of this._renderToolCalls) {\n merged.set(`${rc.agentId ?? \"\"}:${rc.name}`, rc);\n }\n for (const [key, rc] of this._hookRenderToolCalls) {\n merged.set(key, rc);\n }\n this._cachedMergedRenderToolCalls = Array.from(merged.values());\n return this._cachedMergedRenderToolCalls;\n }\n\n setRenderActivityMessages(\n renderers: ReactActivityMessageRenderer<any>[],\n ): void {\n this._renderActivityMessages = renderers;\n }\n\n setRenderCustomMessages(renderers: ReactCustomMessageRenderer[]): void {\n this._renderCustomMessages = renderers;\n }\n\n setRenderToolCalls(renderToolCalls: ReactToolCallRenderer<any>[]): void {\n this._renderToolCalls = renderToolCalls;\n this._cachedMergedRenderToolCalls = null;\n this._notifyRenderToolCallsChanged();\n }\n\n addHookRenderToolCall(entry: ReactToolCallRenderer<any>): void {\n const key = `${entry.agentId ?? \"\"}:${entry.name}`;\n this._hookRenderToolCalls.set(key, entry);\n this._cachedMergedRenderToolCalls = null;\n this._notifyRenderToolCallsChanged();\n }\n\n removeHookRenderToolCall(name: string, agentId?: string): void {\n const key = `${agentId ?? \"\"}:${name}`;\n if (this._hookRenderToolCalls.delete(key)) {\n this._cachedMergedRenderToolCalls = null;\n this._notifyRenderToolCallsChanged();\n }\n }\n\n private _notifyRenderToolCallsChanged(): void {\n void this.notifySubscribers((subscriber) => {\n const reactSubscriber = subscriber as CopilotKitCoreReactSubscriber;\n if (reactSubscriber.onRenderToolCallsChanged) {\n reactSubscriber.onRenderToolCallsChanged({\n copilotkit: this,\n renderToolCalls: this.renderToolCalls,\n });\n }\n }, \"Subscriber onRenderToolCallsChanged error:\");\n }\n\n get interruptElement(): React.ReactElement | null {\n return this._interruptElement;\n }\n\n setInterruptElement(element: React.ReactElement | null): void {\n this._interruptElement = element;\n void this.notifySubscribers((subscriber) => {\n const reactSubscriber = subscriber as CopilotKitCoreReactSubscriber;\n reactSubscriber.onInterruptElementChanged?.({\n copilotkit: this,\n interruptElement: this._interruptElement,\n });\n }, \"Subscriber onInterruptElementChanged error:\");\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 /**\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 */\n async waitForPendingFrameworkUpdates(): Promise<void> {\n await new Promise<void>((resolve) => setTimeout(resolve, 0));\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 * 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":";;;;;;;AA8BA,IAAa,sBAAb,cAAyCA,gCAAe;CAUtD,YAAY,QAAmC;AAC7C,QAAM,OAAO;0BAV0C,EAAE;8CAEzD,IAAI,KAAK;sCAET;+BAC4D,EAAE;iCACO,EAAE;2BAClB;AAIrD,OAAK,mBAAmB,OAAO,mBAAmB,EAAE;AACpD,OAAK,wBAAwB,OAAO,wBAAwB,EAAE;AAC9D,OAAK,0BAA0B,OAAO,0BAA0B,EAAE;;CAGpE,IAAI,uBAA+D;AACjE,SAAO,KAAK;;CAGd,IAAI,yBAAwE;AAC1E,SAAO,KAAK;;CAGd,IAAI,kBAA0D;AAC5D,MAAI,KAAK,qBAAqB,SAAS,EACrC,QAAO,KAAK;AAEd,MAAI,KAAK,6BACP,QAAO,KAAK;EAGd,MAAM,yBAAS,IAAI,KAAyC;AAC5D,OAAK,MAAM,MAAM,KAAK,iBACpB,QAAO,IAAI,GAAG,GAAG,WAAW,GAAG,GAAG,GAAG,QAAQ,GAAG;AAElD,OAAK,MAAM,CAAC,KAAK,OAAO,KAAK,qBAC3B,QAAO,IAAI,KAAK,GAAG;AAErB,OAAK,+BAA+B,MAAM,KAAK,OAAO,QAAQ,CAAC;AAC/D,SAAO,KAAK;;CAGd,0BACE,WACM;AACN,OAAK,0BAA0B;;CAGjC,wBAAwB,WAA+C;AACrE,OAAK,wBAAwB;;CAG/B,mBAAmB,iBAAqD;AACtE,OAAK,mBAAmB;AACxB,OAAK,+BAA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Aa,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/v2/context.d.cts
CHANGED
|
@@ -147,6 +147,8 @@ declare const CopilotKitContext: react.Context<CopilotKitContextValue | null>;
|
|
|
147
147
|
declare const useCopilotKit: () => CopilotKitContextValue;
|
|
148
148
|
declare const LicenseContext: react.Context<LicenseContextValue>;
|
|
149
149
|
declare const useLicenseContext: () => LicenseContextValue;
|
|
150
|
+
declare const CopilotKitAgentIdContext: react.Context<string | undefined>;
|
|
151
|
+
declare const useDefaultAgentId: () => string | undefined;
|
|
150
152
|
//#endregion
|
|
151
|
-
export { CopilotKitContext, CopilotKitContextValue, CopilotKitCoreReact, type CopilotKitCoreReactConfig, EMPTY_SET, LicenseContext, useCopilotKit, useLicenseContext };
|
|
153
|
+
export { CopilotKitAgentIdContext, CopilotKitContext, CopilotKitContextValue, CopilotKitCoreReact, type CopilotKitCoreReactConfig, EMPTY_SET, LicenseContext, useCopilotKit, useDefaultAgentId, useLicenseContext };
|
|
152
154
|
//# sourceMappingURL=context.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.cts","names":[],"sources":["../../src/v2/types/react-tool-call-renderer.ts","../../src/v2/types/react-activity-message-renderer.ts","../../src/v2/types/react-custom-message-renderer.ts","../../src/v2/lib/react-core.ts","../../src/v2/context.ts"],"mappings":";;;;;;;;UAGiB,qBAAA;EACf,IAAA;;;;;EAKA,IAAA,GAAO,gBAAA,MAAsB,CAAA;EANO;;;;EAWpC,OAAA;EACA,MAAA,EAAQ,KAAA,CAAM,aAAA;IAER,IAAA;IACA,UAAA;IACA,IAAA,EAAM,OAAA,CAAQ,CAAA;IACd,MAAA,EAAQ,cAAA,CAAe,U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AA,CAAA,GAAwB,QAAA,CAAS,0BAAA;EAAA,IAIjC,sBAAA,CAAA,GAA0B,QAAA,CAAS,4BAAA;EAAA,IAInC,eAAA,CAAA,GAAmB,QAAA,CAAS,qBAAA;EAmBhC,yBAAA,CACE,SAAA,EAAW,4BAAA;EAKb,uBAAA,CAAwB,SAAA,EAAW,0BAAA;EAInC,kBAAA,CAAmB,eAAA,EAAiB,qBAAA;EAMpC,qBAAA,CAAsB,KAAA,EAAO,qBAAA;EAO7B,wBAAA,CAAyB,IAAA,UAAc,OAAA;EAAA,QAQ/B,6BAAA;EAAA,IAYJ,gBAAA,CAAA,GAAoB,OAAA,CAAM,YAAA;EAI9B,mBAAA,CAAoB,OAAA,EAAS,OAAA,CAAM,YAAA;EAYnC,SAAA,CACE,UAAA,EAAY,6BAAA,GACX,0BAAA;EHnH0B;;;;;;;;;;;;;EGoIvB,8BAAA,CAAA,GAAkC,OAAA;AAAA;;;UC7IzB,sBAAA;EACf,UAAA,EAAY,mBAAA;;AJTd;;;;EIeE,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"}
|
|
1
|
+
{"version":3,"file":"context.d.cts","names":[],"sources":["../../src/v2/types/react-tool-call-renderer.ts","../../src/v2/types/react-activity-message-renderer.ts","../../src/v2/types/react-custom-message-renderer.ts","../../src/v2/lib/react-core.ts","../../src/v2/context.ts"],"mappings":";;;;;;;;UAGiB,qBAAA;EACf,IAAA;;;;;EAKA,IAAA,GAAO,gBAAA,MAAsB,CAAA;EANO;;;;EAWpC,OAAA;EACA,MAAA,EAAQ,KAAA,CAAM,aAAA;IAER,IAAA;IACA,UAAA;IACA,IAAA,EAAM,OAAA,CAA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EI,MAAA,EAAQ,yBAAA;EAAA,IAOhB,oBAAA,CAAA,GAAwB,QAAA,CAAS,0BAAA;EAAA,IAIjC,sBAAA,CAAA,GAA0B,QAAA,CAAS,4BAAA;EAAA,IAInC,eAAA,CAAA,GAAmB,QAAA,CAAS,qBAAA;EAmBhC,yBAAA,CACE,SAAA,EAAW,4BAAA;EAKb,uBAAA,CAAwB,SAAA,EAAW,0BAAA;EAInC,kBAAA,CAAmB,eAAA,EAAiB,qBAAA;EAMpC,qBAAA,CAAsB,KAAA,EAAO,qBAAA;EAO7B,wBAAA,CAAyB,IAAA,UAAc,OAAA;EAAA,QAQ/B,6BAAA;EAAA,IAYJ,gBAAA,CAAA,GAAoB,OAAA,CAAM,YAAA;EAI9B,mBAAA,CAAoB,OAAA,EAAS,OAAA,CAAM,YAAA;EAYnC,SAAA,CACE,UAAA,EAAY,6BAAA,GACX,0BAAA;EHnH0B;;;;;;;;;;;;;EGoIvB,8BAAA,CAAA,GAAkC,OAAA;AAAA;;;UC7IzB,sBAAA;EACf,UAAA,EAAY,mBAAA;;AJTd;;;;EIeE,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/v2/context.d.mts
CHANGED
|
@@ -147,6 +147,8 @@ declare const CopilotKitContext: react.Context<CopilotKitContextValue | null>;
|
|
|
147
147
|
declare const useCopilotKit: () => CopilotKitContextValue;
|
|
148
148
|
declare const LicenseContext: react.Context<LicenseContextValue>;
|
|
149
149
|
declare const useLicenseContext: () => LicenseContextValue;
|
|
150
|
+
declare const CopilotKitAgentIdContext: react.Context<string | undefined>;
|
|
151
|
+
declare const useDefaultAgentId: () => string | undefined;
|
|
150
152
|
//#endregion
|
|
151
|
-
export { CopilotKitContext, CopilotKitContextValue, CopilotKitCoreReact, type CopilotKitCoreReactConfig, EMPTY_SET, LicenseContext, useCopilotKit, useLicenseContext };
|
|
153
|
+
export { CopilotKitAgentIdContext, CopilotKitContext, CopilotKitContextValue, CopilotKitCoreReact, type CopilotKitCoreReactConfig, EMPTY_SET, LicenseContext, useCopilotKit, useDefaultAgentId, useLicenseContext };
|
|
152
154
|
//# sourceMappingURL=context.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.mts","names":[],"sources":["../../src/v2/types/react-tool-call-renderer.ts","../../src/v2/types/react-activity-message-renderer.ts","../../src/v2/types/react-custom-message-renderer.ts","../../src/v2/lib/react-core.ts","../../src/v2/context.ts"],"mappings":";;;;;;;;UAGiB,qBAAA;EACf,IAAA;;;;;EAKA,IAAA,GAAO,gBAAA,MAAsB,CAAA;EANO;;;;EAWpC,OAAA;EACA,MAAA,EAAQ,KAAA,CAAM,aAAA;IAER,IAAA;IACA,UAAA;IACA,IAAA,EAAM,OAAA,CAAQ,CAAA;IACd,MAAA,EAAQ,cAAA,CAAe,UAAA;IACvB,MAAA;EAAA;IAGA,IAAA;IACA,UAAA;IACA,IAAA,EAAM,CAAA;IACN,MAAA,EAAQ,cAAA,CAAe,SAAA;IACvB,MAAA;EAAA;IAGA,IAAA;IACA,UAAA;IACA,IAAA,EAAM,CAAA;IACN,MAAA,EAAQ,cAAA,CAAe,QAAA;IACvB,MAAA;EAAA;AAAA;;;UC/BS,4BAAA;;;;EAIf,YAAA;EDLe;;;ECSf,OAAA;EDHO;;;ECOP,OAAA,EAAS,gBAAA,MAAsB,gBAAA;EDUnB;;;ECNZ,MAAA,EAAQ,KAAA,CAAM,aAAA;IACZ,YAAA;IACA,OAAA,EAAS,gBAAA;IACT,OAAA,EAAS,eAAA;IACT,KAAA,EA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AA,CAAM,YAAA;EAYnC,SAAA,CACE,UAAA,EAAY,6BAAA,GACX,0BAAA;EHnH0B;;;;;;;;;;;;;EGoIvB,8BAAA,CAAA,GAAkC,OAAA;AAAA;;;UC7IzB,sBAAA;EACf,UAAA,EAAY,mBAAA;;AJTd;;;;EIeE,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"}
|
|
1
|
+
{"version":3,"file":"context.d.mts","names":[],"sources":["../../src/v2/types/react-tool-call-renderer.ts","../../src/v2/types/react-activity-message-renderer.ts","../../src/v2/types/react-custom-message-renderer.ts","../../src/v2/lib/react-core.ts","../../src/v2/context.ts"],"mappings":";;;;;;;;UAGiB,qBAAA;EACf,IAAA;;;;;EAKA,IAAA,GAAO,gBAAA,MAAsB,CAAA;EANO;;;;EAWpC,OAAA;EACA,MAAA,EAAQ,KAAA,CAAM,aAAA;IAER,IAAA;IACA,UAAA;IACA,IAAA,EAAM,OAAA,CAAQ,CAAA;IACd,MAAA,EAAQ,cAAA,CAAe,UAAA;IACvB,MAAA;EAAA;IAGA,IAAA;IACA,UAAA;IACA,IAAA,EAAM,CAAA;IACN,MAAA,EAAQ,cAAA,CAAe,SAAA;IACvB,MAAA;EAAA;IAGA,IAAA;IACA,UAAA;IACA,IAAA,EAAM,CAAA;IACN,MAAA,EAAQ,cAAA,CAAe,QAAA;IACvB,MAAA;EAAA;AAAA;;;UC/BS,4BAAA;;;;EAIf,YAAA;EDLe;;;ECSf,OAAA;EDHO;;;ECOP,OAAA,EAAS,gBAAA,MAAsB,gBAAA;EDUnB;;;ECNZ,MAAA,EAAQ,KAAA,CAAM,aAAA;IACZ,YAAA;IACA,OAAA,EAAS,gB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AAA;EAI9B,mBAAA,CAAoB,OAAA,EAAS,OAAA,CAAM,YAAA;EAYnC,SAAA,CACE,UAAA,EAAY,6BAAA,GACX,0BAAA;EHnH0B;;;;;;;;;;;;;EGoIvB,8BAAA,CAAA,GAAkC,OAAA;AAAA;;;UC7IzB,sBAAA;EACf,UAAA,EAAY,mBAAA;;AJTd;;;;EIeE,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/v2/context.mjs
CHANGED
|
@@ -128,7 +128,9 @@ const LicenseContext = createContext({
|
|
|
128
128
|
getLimit: () => null
|
|
129
129
|
});
|
|
130
130
|
const useLicenseContext = () => useContext(LicenseContext);
|
|
131
|
+
const CopilotKitAgentIdContext = createContext(void 0);
|
|
132
|
+
const useDefaultAgentId = () => useContext(CopilotKitAgentIdContext);
|
|
131
133
|
|
|
132
134
|
//#endregion
|
|
133
|
-
export { CopilotKitContext, CopilotKitCoreReact, EMPTY_SET, LicenseContext, useCopilotKit, useLicenseContext };
|
|
135
|
+
export { CopilotKitAgentIdContext, CopilotKitContext, CopilotKitCoreReact, EMPTY_SET, LicenseContext, useCopilotKit, useDefaultAgentId, useLicenseContext };
|
|
134
136
|
//# sourceMappingURL=context.mjs.map
|
package/dist/v2/context.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.mjs","names":[],"sources":["../../src/v2/lib/react-core.ts","../../src/v2/context.ts"],"sourcesContent":["import React from \"react\";\nimport { ReactActivityMessageRenderer, ReactToolCallRenderer } from \"../types\";\nimport { ReactCustomMessageRenderer } from \"../types/react-custom-message-renderer\";\nimport {\n CopilotKitCore,\n type CopilotKitCoreConfig,\n type CopilotKitCoreSubscriber,\n type CopilotKitCoreSubscription,\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: ReactToolCallRenderer<any>[];\n }) => void | Promise<void>;\n onInterruptElementChanged?: (event: {\n copilotkit: CopilotKitCore;\n interruptElement: React.ReactElement | null;\n }) => void | Promise<void>;\n}\n\nexport class CopilotKitCoreReact extends CopilotKitCore {\n private _renderToolCalls: ReactToolCallRenderer<any>[] = [];\n private _hookRenderToolCalls: Map<string, ReactToolCallRenderer<any>> =\n new Map();\n private _cachedMergedRenderToolCalls: ReactToolCallRenderer<any>[] | null =\n null;\n private _renderCustomMessages: ReactCustomMessageRenderer[] = [];\n private _renderActivityMessages: ReactActivityMessageRenderer<any>[] = [];\n private _interruptElement: React.ReactElement | null = null;\n\n constructor(config: CopilotKitCoreReactConfig) {\n super(config);\n this._renderToolCalls = config.renderToolCalls ?? [];\n this._renderCustomMessages = config.renderCustomMessages ?? [];\n this._renderActivityMessages = config.renderActivityMessages ?? [];\n }\n\n get renderCustomMessages(): Readonly<ReactCustomMessageRenderer[]> {\n return this._renderCustomMessages;\n }\n\n get renderActivityMessages(): Readonly<ReactActivityMessageRenderer<any>>[] {\n return this._renderActivityMessages;\n }\n\n get renderToolCalls(): Readonly<ReactToolCallRenderer<any>>[] {\n if (this._hookRenderToolCalls.size === 0) {\n return this._renderToolCalls;\n }\n if (this._cachedMergedRenderToolCalls) {\n return this._cachedMergedRenderToolCalls;\n }\n // Merge: hook entries override prop entries with the same key\n const merged = new Map<string, ReactToolCallRenderer<any>>();\n for (const rc of this._renderToolCalls) {\n merged.set(`${rc.agentId ?? \"\"}:${rc.name}`, rc);\n }\n for (const [key, rc] of this._hookRenderToolCalls) {\n merged.set(key, rc);\n }\n this._cachedMergedRenderToolCalls = Array.from(merged.values());\n return this._cachedMergedRenderToolCalls;\n }\n\n setRenderActivityMessages(\n renderers: ReactActivityMessageRenderer<any>[],\n ): void {\n this._renderActivityMessages = renderers;\n }\n\n setRenderCustomMessages(renderers: ReactCustomMessageRenderer[]): void {\n this._renderCustomMessages = renderers;\n }\n\n setRenderToolCalls(renderToolCalls: ReactToolCallRenderer<any>[]): void {\n this._renderToolCalls = renderToolCalls;\n this._cachedMergedRenderToolCalls = null;\n this._notifyRenderToolCallsChanged();\n }\n\n addHookRenderToolCall(entry: ReactToolCallRenderer<any>): void {\n const key = `${entry.agentId ?? \"\"}:${entry.name}`;\n this._hookRenderToolCalls.set(key, entry);\n this._cachedMergedRenderToolCalls = null;\n this._notifyRenderToolCallsChanged();\n }\n\n removeHookRenderToolCall(name: string, agentId?: string): void {\n const key = `${agentId ?? \"\"}:${name}`;\n if (this._hookRenderToolCalls.delete(key)) {\n this._cachedMergedRenderToolCalls = null;\n this._notifyRenderToolCallsChanged();\n }\n }\n\n private _notifyRenderToolCallsChanged(): void {\n void this.notifySubscribers((subscriber) => {\n const reactSubscriber = subscriber as CopilotKitCoreReactSubscriber;\n if (reactSubscriber.onRenderToolCallsChanged) {\n reactSubscriber.onRenderToolCallsChanged({\n copilotkit: this,\n renderToolCalls: this.renderToolCalls,\n });\n }\n }, \"Subscriber onRenderToolCallsChanged error:\");\n }\n\n get interruptElement(): React.ReactElement | null {\n return this._interruptElement;\n }\n\n setInterruptElement(element: React.ReactElement | null): void {\n this._interruptElement = element;\n void this.notifySubscribers((subscriber) => {\n const reactSubscriber = subscriber as CopilotKitCoreReactSubscriber;\n reactSubscriber.onInterruptElementChanged?.({\n copilotkit: this,\n interruptElement: this._interruptElement,\n });\n }, \"Subscriber onInterruptElementChanged error:\");\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 /**\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 */\n async waitForPendingFrameworkUpdates(): Promise<void> {\n await new Promise<void>((resolve) => setTimeout(resolve, 0));\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 * 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"],"mappings":";;;;;;AA8BA,IAAa,sBAAb,cAAyC,eAAe;CAUtD,YAAY,QAAmC;AAC7C,QAAM,OAAO;0BAV0C,EAAE;8CAEzD,IAAI,KAAK;sCAET;+BAC4D,EAAE;iCACO,EAAE;2BAClB;AAIrD,OAAK,mBAAmB,OAAO,mBAAmB,EAAE;AACpD,OAAK,wBAAwB,OAAO,wBAAwB,EAAE;AAC9D,OAAK,0BAA0B,OAAO,0BAA0B,EAAE;;CAGpE,IAAI,uBAA+D;AACjE,SAAO,KAAK;;CAGd,IAAI,yBAAwE;AAC1E,SAAO,KAAK;;CAGd,IAAI,kBAA0D;AAC5D,MAAI,KAAK,qBAAqB,SAAS,EACrC,QAAO,KAAK;AAEd,MAAI,KAAK,6BACP,QAAO,KAAK;EAGd,MAAM,yBAAS,IAAI,KAAyC;AAC5D,OAAK,MAAM,MAAM,KAAK,iBACpB,QAAO,IAAI,GAAG,GAAG,WAAW,GAAG,GAAG,GAAG,QAAQ,GAAG;AAElD,OAAK,MAAM,CAAC,KAAK,OAAO,KAAK,qBAC3B,QAAO,IAAI,KAAK,GAAG;AAErB,OAAK,+BAA+B,MAAM,KAAK,OAAO,QAAQ,CAAC;AAC/D,SAAO,KAAK;;CAGd,0BACE,WACM;AACN,OAAK,0BAA0B;;CAGjC,wBAAwB,WAA+C;AACrE,OAAK,wBAAwB;;CAG/B,mBAAmB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;;GAEf,wBAAwB;AACtB,iBAAa;;GAEhB,CAAC;AACF,eAAa;AACX,gBAAa,aAAa;;IAG3B,EAAE,CAAC;AAEN,QAAO;;AAOT,MAAa,iBAAiB,cAAmC;CAC/D,QAAQ;CACR,SAAS;CACT,oBAAoB;CACpB,gBAAgB;CACjB,CAAwB;AAEzB,MAAa,0BACX,WAAW,eAAe"}
|
|
1
|
+
{"version":3,"file":"context.mjs","names":[],"sources":["../../src/v2/lib/react-core.ts","../../src/v2/context.ts"],"sourcesContent":["import React from \"react\";\nimport { ReactActivityMessageRenderer, ReactToolCallRenderer } from \"../types\";\nimport { ReactCustomMessageRenderer } from \"../types/react-custom-message-renderer\";\nimport {\n CopilotKitCore,\n type CopilotKitCoreConfig,\n type CopilotKitCoreSubscriber,\n type CopilotKitCoreSubscription,\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: ReactToolCallRenderer<any>[];\n }) => void | Promise<void>;\n onInterruptElementChanged?: (event: {\n copilotkit: CopilotKitCore;\n interruptElement: React.ReactElement | null;\n }) => void | Promise<void>;\n}\n\nexport class CopilotKitCoreReact extends CopilotKitCore {\n private _renderToolCalls: ReactToolCallRenderer<any>[] = [];\n private _hookRenderToolCalls: Map<string, ReactToolCallRenderer<any>> =\n new Map();\n private _cachedMergedRenderToolCalls: ReactToolCallRenderer<any>[] | null =\n null;\n private _renderCustomMessages: ReactCustomMessageRenderer[] = [];\n private _renderActivityMessages: ReactActivityMessageRenderer<any>[] = [];\n private _interruptElement: React.ReactElement | null = null;\n\n constructor(config: CopilotKitCoreReactConfig) {\n super(config);\n this._renderToolCalls = config.renderToolCalls ?? [];\n this._renderCustomMessages = config.renderCustomMessages ?? [];\n this._renderActivityMessages = config.renderActivityMessages ?? [];\n }\n\n get renderCustomMessages(): Readonly<ReactCustomMessageRenderer[]> {\n return this._renderCustomMessages;\n }\n\n get renderActivityMessages(): Readonly<ReactActivityMessageRenderer<any>>[] {\n return this._renderActivityMessages;\n }\n\n get renderToolCalls(): Readonly<ReactToolCallRenderer<any>>[] {\n if (this._hookRenderToolCalls.size === 0) {\n return this._renderToolCalls;\n }\n if (this._cachedMergedRenderToolCalls) {\n return this._cachedMergedRenderToolCalls;\n }\n // Merge: hook entries override prop entries with the same key\n const merged = new Map<string, ReactToolCallRenderer<any>>();\n for (const rc of this._renderToolCalls) {\n merged.set(`${rc.agentId ?? \"\"}:${rc.name}`, rc);\n }\n for (const [key, rc] of this._hookRenderToolCalls) {\n merged.set(key, rc);\n }\n this._cachedMergedRenderToolCalls = Array.from(merged.values());\n return this._cachedMergedRenderToolCalls;\n }\n\n setRenderActivityMessages(\n renderers: ReactActivityMessageRenderer<any>[],\n ): void {\n this._renderActivityMessages = renderers;\n }\n\n setRenderCustomMessages(renderers: ReactCustomMessageRenderer[]): void {\n this._renderCustomMessages = renderers;\n }\n\n setRenderToolCalls(renderToolCalls: ReactToolCallRenderer<any>[]): void {\n this._renderToolCalls = renderToolCalls;\n this._cachedMergedRenderToolCalls = null;\n this._notifyRenderToolCallsChanged();\n }\n\n addHookRenderToolCall(entry: ReactToolCallRenderer<any>): void {\n const key = `${entry.agentId ?? \"\"}:${entry.name}`;\n this._hookRenderToolCalls.set(key, entry);\n this._cachedMergedRenderToolCalls = null;\n this._notifyRenderToolCallsChanged();\n }\n\n removeHookRenderToolCall(name: string, agentId?: string): void {\n const key = `${agentId ?? \"\"}:${name}`;\n if (this._hookRenderToolCalls.delete(key)) {\n this._cachedMergedRenderToolCalls = null;\n this._notifyRenderToolCallsChanged();\n }\n }\n\n private _notifyRenderToolCallsChanged(): void {\n void this.notifySubscribers((subscriber) => {\n const reactSubscriber = subscriber as CopilotKitCoreReactSubscriber;\n if (reactSubscriber.onRenderToolCallsChanged) {\n reactSubscriber.onRenderToolCallsChanged({\n copilotkit: this,\n renderToolCalls: this.renderToolCalls,\n });\n }\n }, \"Subscriber onRenderToolCallsChanged error:\");\n }\n\n get interruptElement(): React.ReactElement | null {\n return this._interruptElement;\n }\n\n setInterruptElement(element: React.ReactElement | null): void {\n this._interruptElement = element;\n void this.notifySubscribers((subscriber) => {\n const reactSubscriber = subscriber as CopilotKitCoreReactSubscriber;\n reactSubscriber.onInterruptElementChanged?.({\n copilotkit: this,\n interruptElement: this._interruptElement,\n });\n }, \"Subscriber onInterruptElementChanged error:\");\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 /**\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 */\n async waitForPendingFrameworkUpdates(): Promise<void> {\n await new Promise<void>((resolve) => setTimeout(resolve, 0));\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 * 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"],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
|
assistantMessageToolbarCopyCodeCopiedLabel: "Copied",
|
|
90
90
|
assistantMessageToolbarCopyMessageLabel: "Copy",
|
|
91
91
|
assistantMessageToolbarInspectorLabel: "View in Inspector",
|
|
92
|
-
|
|
92
|
+
assistantMessageToolbarInspectorDescription: "Open this message in the Inspector",
|
|
93
|
+
assistantMessageToolbarInspectorLocalOnlyLabel: "Local only",
|
|
94
|
+
assistantMessageToolbarInspectorLocalOnlyDescription: "Only visible on localhost or loopback hosts in development. Never shown in production.",
|
|
95
|
+
assistantMessageToolbarInspectorTitle: "CopilotKit Inspector",
|
|
96
|
+
assistantMessageToolbarInspectorHideLabel: "Hide this icon",
|
|
97
|
+
assistantMessageToolbarInspectorHideDescription: "Until you reload this page",
|
|
93
98
|
assistantMessageToolbarThumbsUpLabel: "Good response",
|
|
94
99
|
assistantMessageToolbarThumbsDownLabel: "Bad response",
|
|
95
100
|
assistantMessageToolbarReadAloudLabel: "Read aloud",
|
|
@@ -130,7 +135,8 @@ const CopilotChatConfigurationProvider = ({ children, labels, agentId, threadId,
|
|
|
130
135
|
...parentConfig?.labels,
|
|
131
136
|
...stableLabels
|
|
132
137
|
}), [stableLabels, parentConfig?.labels]);
|
|
133
|
-
const
|
|
138
|
+
const providerAgentId = (0, _copilotkit_react_core_v2_context.useDefaultAgentId)();
|
|
139
|
+
const resolvedAgentId = agentId ?? parentConfig?.agentId ?? providerAgentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
134
140
|
const threadIdPropIsAuthoritative = threadId !== void 0 && hasExplicitThreadId !== false;
|
|
135
141
|
const isThreadIdControlled = threadIdPropIsAuthoritative;
|
|
136
142
|
const [activeThreadOverride, setActiveThreadOverride] = (0, react.useState)(null);
|
|
@@ -356,7 +362,8 @@ function useAgent({ agentId, threadId, runtimeAgentId, updates, throttleMs } = {
|
|
|
356
362
|
if (runtimeAgentId != null && threadId == null) throw new Error(`useAgent: \`runtimeAgentId\` requires \`threadId\`. A proxied agent exists to scope a thread to a private instance; without a threadId it behaves like the shared agent while adding a registration and a local agentId to keep unique. Either pass the thread, e.g. useAgent({ agentId: "${agentId ?? "chat-1"}", runtimeAgentId: "${runtimeAgentId}", threadId }), or bind to the agent directly with useAgent({ agentId: "${runtimeAgentId}" }).`);
|
|
357
363
|
if (runtimeAgentId != null && agentId == null) throw new Error(`useAgent: \`runtimeAgentId\` requires an explicit \`agentId\`. The proxied agent is registered under \`agentId\`, and the usual fallbacks (chat configuration, then "${_copilotkit_shared.DEFAULT_AGENT_ID}") name agents that already exist — registering over one throws or shadows it. Pick a local id for this hook, e.g. useAgent({ agentId: "chat-1", runtimeAgentId: "${runtimeAgentId}", threadId }).`);
|
|
358
364
|
const chatConfig = useCopilotChatConfiguration();
|
|
359
|
-
const
|
|
365
|
+
const providerAgentId = (0, _copilotkit_react_core_v2_context.useDefaultAgentId)();
|
|
366
|
+
const resolvedAgentId = agentId ?? chatConfig?.agentId ?? providerAgentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
360
367
|
const { copilotkit } = (0, _copilotkit_react_core_v2_context.useCopilotKit)();
|
|
361
368
|
const providerThrottleMs = copilotkit.defaultThrottleMs;
|
|
362
369
|
const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
|
|
@@ -775,7 +782,10 @@ function toLegacyEvent(pending) {
|
|
|
775
782
|
*/
|
|
776
783
|
function useInterrupt(config) {
|
|
777
784
|
const { copilotkit } = (0, _copilotkit_react_core_v2_context.useCopilotKit)();
|
|
778
|
-
const { agent } = useAgent({
|
|
785
|
+
const { agent } = useAgent({
|
|
786
|
+
agentId: config.agentId,
|
|
787
|
+
updates: []
|
|
788
|
+
});
|
|
779
789
|
const [pending, setPending] = (0, react.useState)(null);
|
|
780
790
|
const pendingRef = (0, react.useRef)(pending);
|
|
781
791
|
pendingRef.current = pending;
|
|
@@ -1025,7 +1035,12 @@ function useInterrupt(config) {
|
|
|
1025
1035
|
function useSuggestions({ agentId } = {}) {
|
|
1026
1036
|
const { copilotkit } = (0, _copilotkit_react_core_v2_context.useCopilotKit)();
|
|
1027
1037
|
const config = useCopilotChatConfiguration();
|
|
1028
|
-
const
|
|
1038
|
+
const providerAgentId = (0, _copilotkit_react_core_v2_context.useDefaultAgentId)();
|
|
1039
|
+
const resolvedAgentId = (0, react.useMemo)(() => agentId ?? config?.agentId ?? providerAgentId ?? _copilotkit_shared.DEFAULT_AGENT_ID, [
|
|
1040
|
+
agentId,
|
|
1041
|
+
config?.agentId,
|
|
1042
|
+
providerAgentId
|
|
1043
|
+
]);
|
|
1029
1044
|
const [suggestions, setSuggestions] = (0, react.useState)(() => {
|
|
1030
1045
|
return copilotkit.getSuggestions(resolvedAgentId).suggestions;
|
|
1031
1046
|
});
|