mirror of
https://github.com/CopilotKit/CopilotKit.git
synced 2026-09-14 16:26:20 +08:00
d4a9bc3355
## Problem The published declaration files for `@copilotkit/react-core`, `@copilotkit/react-ui`, and `@copilotkit/react-textarea` contain imports that TypeScript cannot resolve, so **`attw` (Are The Types Wrong) reports `InternalResolutionError` across every resolution mode** (`node10` / `node16` / `bundler`). In `@copilotkit/react-core` this was being **masked in CI** by `--ignore-rules internal-resolution-error` on the package's `attw` script — so the existing `check:packages` gate looked green while consumers under `moduleResolution: bundler`/`node16`/`nodenext` got broken types (the symptom reported in #3324: `has no exported member 'useAgent'`, etc.). Two distinct artifacts leaked into the emitted `.d.ts` / `.d.cts` / `.d.mts` (neither affects the JS bundles): 1. **Side-effect CSS imports** — `import "./index.css"` is intentionally kept in the JS so styles auto-load for bundler consumers, but `rolldown-plugin-dts` also left it in the declarations, where TypeScript can't resolve a `.css` as a typed module. 2. **Extensionless relative `./context` import** — `@copilotkit/react-core/v2/headless` re-exports the externalized context module; the JS bundle correctly externalizes it to `@copilotkit/react-core/v2/context`, but the declaration kept the relative `./context`, which is invalid in ESM declarations. > Note: this is **not** the missing-`exports.types`-condition theory from #3324. tsdown deliberately relies on co-located `.d.mts`/`.d.cts` siblings; `@copilotkit/core` already resolves cleanly. The real defects are the two leaked imports above. ## Fix A small tsdown `build:done` hook post-processes the emitted declarations **on disk** (after every format is written, so it catches both `.d.mts` and `.d.cts`): - strips side-effect CSS imports from declarations (JS keeps them); - rewrites the relative `./context` import to the `@copilotkit/react-core/v2/context` package path (matching how the JS bundle externalizes it). Also: - **Removed the `--ignore-rules internal-resolution-error` band-aid** from `react-core`'s `attw` script so the existing CI gate validates for real. - **Dropped the dead `codeSplitting` option** from the UMD configs — tsdown never reads it (it's a rolldown-only key), and it was failing `tsc` in the configs that type-check themselves. UMD output is unchanged (single file). ## Verification - All three packages build; **no CSS or relative-`./context` imports remain in any declaration**, while the JS bundles still contain them (styles auto-load preserved). - `attw` + `publint` pass for all packages **with no suppression** (`react-core`'s `/v2`, `/v2/headless`, `/v2/context` are green for node16-cjs/esm/bundler). - Unit tests pass. - A standalone consumer project (real tarball install, `skipLibCheck: false`) type-checks the public APIs — including `useAgent` / `useFrontendTool` / `useConfigureSuggestions` — cleanly under **both `bundler` and `nodenext`**, and the headless↔context class is nominally identical. ## Out of scope (follow-ups) - `@copilotkit/react-native`: its `--ignore-rules internal-resolution-error` currently suppresses nothing (no IRE) and it has a separate `NoResolution` flag. - `@copilotkit/vue`: a large, genuine set of `.vue`/relative-import declaration errors unrelated to this change. Relates to #3324. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
CopilotKit - React UI
✨ Why CopilotKit?
- Minutes to integrate - Get started quickly with our CLI
- Framework agnostic - Works with React, Next.js, AGUI and more
- Production-ready UI - Use customizable components or build with headless UI
- Built-in security - Prompt injection protection
- Open source - Full transparency and community-driven
🧑💻 Real life use cases
Deploy deeply-integrated AI assistants & agents that work alongside your users inside your applications.
🖥️ Code Samples
Drop in these building blocks and tailor them to your needs.
Build with Headless APIs and Pre-Built Components
// Headless UI with full control
const { visibleMessages, appendMessage, setMessages, ... } = useCopilotChat();
// Pre-built components with deep customization options (CSS + pass custom sub-components)
<CopilotPopup
instructions={"You are assisting the user as best as you can. Answer in the best way possible given the data you have."}
labels={{ title: "Popup Assistant", initial: "Need any help?" }}
/>
// Frontend actions + generative UI, with full streaming support
useCopilotAction({
name: "appendToSpreadsheet",
description: "Append rows to the current spreadsheet",
parameters: [
{ name: "rows", type: "object[]", attributes: [{ name: "cells", type: "object[]", attributes: [{ name: "value", type: "string" }] }] }
],
render: ({ status, args }) => <Spreadsheet data={canonicalSpreadsheetData(args.rows)} />,
handler: ({ rows }) => setSpreadsheet({ ...spreadsheet, rows: [...spreadsheet.rows, ...canonicalSpreadsheetData(rows)] }),
});
Integrate In-App CoAgents with LangGraph
// Share state between app and agent
const { agentState } = useCoAgent({
name: "basic_agent",
initialState: { input: "NYC" }
});
// agentic generative UI
useCoAgentStateRender({
name: "basic_agent",
render: ({ state }) => <WeatherDisplay {...state.final_response} />,
});
// Human in the Loop (Approval)
useCopilotAction({
name: "email_tool",
parameters: [
{
name: "email_draft",
type: "string",
description: "The email content",
required: true,
},
],
renderAndWaitForResponse: ({ args, status, respond }) => {
return (
<EmailConfirmation
emailContent={args.email_draft || ""}
isExecuting={status === "executing"}
onCancel={() => respond?.({ approved: false })}
onSend={() =>
respond?.({
approved: true,
metadata: { sentAt: new Date().toISOString() },
})
}
/>
);
},
});
// intermediate agent state streaming (supports both LangGraph.js + LangGraph python)
const modifiedConfig = copilotKitCustomizeConfig(config, {
emitIntermediateState: [
{
stateKey: "outline",
tool: "set_outline",
toolArgument: "outline",
},
],
});
const response = await ChatOpenAI({ model: "gpt-4o" }).invoke(
messages,
modifiedConfig,
);
🏆 Featured Examples
Documentation
To get started with CopilotKit, please check out the documentation.