|
1 | 1 | --- |
2 | 2 | title: "Hook Explorer" |
3 | | -description: "Discover and live-preview CopilotKit render hooks without leaving VS Code" |
| 3 | +description: "Discover and live-preview CopilotKit render hooks without leaving VS Code." |
4 | 4 | icon: "lucide/Binoculars" |
5 | 5 | --- |
6 | 6 |
|
7 | 7 | import { Steps, Step } from "fumadocs-ui/components/steps"; |
8 | 8 | import { Callout } from "fumadocs-ui/components/callout"; |
9 | 9 |
|
10 | | -The **Hook Explorer** is a sidebar view in the CopilotKit VS Code extension that scans your workspace for every CopilotKit hook call and — for hooks that carry a `render` component — opens a live preview inside VS Code. You get auto-generated form controls for `args`, `state`, `status`, and `result`, and your changes hot-reload as you edit the source file. |
| 10 | +You have a file that calls `useCopilotAction`, `useRenderTool`, `useCoAgentStateRender`, or any of the other render-capable CopilotKit hooks, and you want to iterate on the `render` prop — tweak the layout, test different statuses, feed different args — without running the full chat loop. The Hook Explorer is a sidebar and inline-CodeLens UI inside the [VS Code extension](/vs-code-extension) that does exactly that. |
11 | 11 |
|
12 | | -Use it when: |
| 12 | +By the end of this page you'll have: |
13 | 13 |
|
14 | | -- You're building an action render and want to iterate without round-tripping through the full chat UI. |
15 | | -- You want to see every `useCopilotAction` / `useRenderTool` / `useCoAgentStateRender` in your project at a glance. |
16 | | -- You need to verify how a render behaves at `inProgress` / `executing` / `complete` states without firing a real agent run. |
| 14 | +- Every CopilotKit hook call in your workspace listed in a sidebar. |
| 15 | +- A live preview panel for any render hook, with auto-generated form controls driven by the hook's declared parameters. |
| 16 | +- A one-click `▶️ Preview Component` CodeLens above every hook call in your editor. |
17 | 17 |
|
18 | 18 | ## Prerequisites |
19 | 19 |
|
20 | 20 | - The [CopilotKit VS Code extension](/vs-code-extension) installed. |
21 | 21 | - `@copilotkit/react-core` or `@copilotkit/react-core/v2` imported somewhere in your workspace. |
22 | 22 |
|
23 | 23 | <Callout type="info"> |
24 | | - The Hook Explorer runs locally against your source files — no runtime or agent is required to use it. |
| 24 | + The Hook Explorer runs entirely against your source files — no runtime, no API keys, no agent run required. |
25 | 25 | </Callout> |
26 | 26 |
|
27 | 27 | ## Explore and preview |
28 | 28 |
|
29 | 29 | <Steps> |
30 | 30 |
|
31 | 31 | <Step> |
32 | | -### Open the Hook Explorer view |
| 32 | +### Open the Hook Explorer |
33 | 33 |
|
34 | | -Click the CopilotKit icon in the Activity Bar, then expand **CopilotKit Hooks** in the sidebar. The tree shows two groups: |
35 | | - |
36 | | -- **Render hooks** — hooks whose `render` prop can be previewed (`useCopilotAction`, `useRenderTool`, `useCoAgentStateRender`, `useLangGraphInterrupt`, `useHumanInTheLoop`, and friends). |
37 | | -- **Data hooks** — hooks that don't render anything (`useCopilotReadable`, `useCoAgent`, `useCopilotAdditionalInstructions`, etc.). These are navigable but not previewable. |
38 | | - |
39 | | -Each hook type collapses into a list of per-site leaves labeled by the action name (or `line:N` for nameless hooks). |
| 34 | +Click the CopilotKit icon in the Activity Bar and expand the **CopilotKit Hooks** sidebar (first of the three views). You'll see every CopilotKit hook call in your workspace, grouped by hook name. Each row shows the action/tool name (or `line:N` for nameless hooks like `useLangGraphInterrupt`) alongside the file path and line. |
40 | 35 | </Step> |
41 | 36 |
|
42 | 37 | <Step> |
43 | | -### Open source |
| 38 | +### Preview a render hook |
44 | 39 |
|
45 | | -Click any leaf to jump to the hook call in your editor — works for both render and data hooks. Handy for finding every `useCopilotReadable` in a large codebase. |
46 | | -</Step> |
| 40 | +Click any row under a render hook (`useCopilotAction`, `useRenderTool`, …) to open the preview panel in an editor pane. The first time you open a panel for a file, the extension bundles that file through Rolldown with a capture-only stub for `@copilotkit/react-core` — your component mounts into the webview, the hook's config is captured, and the `render` prop is driven by controls on the left (or on top at narrow widths): |
47 | 41 |
|
48 | | -<Step> |
49 | | -### Preview a render |
| 42 | +- **Status** — `inProgress` / `executing` / `complete`. |
| 43 | +- **Args / parameters** — form built from your hook's `parameters` array (V1) or Zod / Standard Schema (V2). Missing fields, enum options, nested objects and arrays all work. |
| 44 | +- **Result** — editable once status is `complete`. |
| 45 | +- **Hook-specific extras** — `nodeName` for `useCoAgentStateRender`, `toolCallId` for `useRenderTool`, an event-value editor for interrupts. |
50 | 46 |
|
51 | | -Click a leaf under **Render hooks** to open the preview panel. The first time you open a panel for a file, CopilotKit bundles it with your installed `@copilotkit/*` version and mounts it inside a fake provider so the render is captured with its closures intact. |
| 47 | +The rendered output sits inside a labeled frame on the right (or below) so it's unmistakably "the component your `render` returned." Your Tailwind classes and any `.css` imports your file uses are bundled in and injected per load. |
| 48 | +</Step> |
52 | 49 |
|
53 | | -The panel has two columns: |
| 50 | +<Step> |
| 51 | +### Jump to source |
54 | 52 |
|
55 | | -- **Controls** (left) — status dropdown, auto-generated `args` form, result editor, and hook-specific extras like `nodeName` (for `useCoAgentStateRender`) or `toolCallId` (for `useRenderTool`). |
56 | | -- **Preview** (right) — your render output, re-invoked on every control change. |
| 53 | +Each sidebar row has a `</>` button on hover that opens the file at the exact line of the hook call. For data hooks (non-previewable), the row click itself opens the source — they stay useful as a navigation index even without a preview. |
57 | 54 | </Step> |
58 | 55 |
|
59 | 56 | <Step> |
60 | | -### Edit the source |
| 57 | +### Use the inline CodeLens |
61 | 58 |
|
62 | | -Save the file containing the hook. The panel rebundles, re-captures, and re-renders automatically — your form values are preserved wherever the field names and types still match the new schema. |
| 59 | +Open any `.ts` or `.tsx` file that calls a render hook. You'll see a `▶️ Preview Component` CodeLens directly above each hook call — clicking it opens the same preview panel. This is handy when you're already in the source file and don't want to round-trip through the sidebar. |
63 | 60 | </Step> |
64 | 61 |
|
65 | 62 | <Step> |
66 | | -### Toggle status and arguments |
67 | | - |
68 | | -Use the status dropdown to cycle through `inProgress` → `executing` → `complete`. The result editor activates when status is `complete`. Type into the args form to see how your render handles different inputs — tool call arguments, missing fields, enum options, etc. |
| 63 | +### Edit and re-render |
69 | 64 |
|
70 | | -Form values persist in VS Code workspace state, so your last-used args are restored the next time you open the same hook. |
| 65 | +Save the file. The extension re-scans the file, rebundles the preview, and re-captures. Your form values are preserved wherever the field names and types still match the new schema. |
71 | 66 | </Step> |
72 | 67 |
|
73 | 68 | </Steps> |
74 | 69 |
|
75 | | -## What gets discovered |
| 70 | +## Hook coverage |
76 | 71 |
|
77 | | -The scanner walks your workspace and looks for direct imports from `@copilotkit/react-core` or `@copilotkit/react-core/v2`. It respects your root and nested `.gitignore` files, and skips `node_modules`, `dist`, `.git`, `.next`, `build`, `.turbo`, `out`, plus `.test.*` / `.spec.*` / `.stories.*` files. |
| 72 | +Every render-capable CopilotKit hook is discoverable and previewable: |
78 | 73 |
|
79 | | -| Hook | Category | Preview | |
| 74 | +| Hook | Source | Preview shape | |
80 | 75 | |---|---|---| |
81 | | -| `useCopilotAction`, `useCopilotAuthenticatedAction_c` | Render | ✔ | |
82 | | -| `useCoAgentStateRender` | Render | ✔ | |
83 | | -| `useLangGraphInterrupt`, `useInterrupt` | Render | ✔ | |
84 | | -| `useRenderTool`, `useRenderToolCall`, `useDefaultRenderTool`, `useLazyToolRenderer` | Render | ✔ | |
85 | | -| `useRenderCustomMessages`, `useRenderActivityMessage` | Render | ✔ | |
86 | | -| `useHumanInTheLoop` | Render | ✔ | |
87 | | -| `useFrontendTool` | Render | ✔ (when a `render` prop is present) | |
88 | | -| `useCopilotReadable`, `useCopilotAdditionalInstructions` | Data | — | |
89 | | -| `useCoAgent`, `useAgent`, `useCopilotChat` | Data | — | |
90 | | -| `useSuggestions`, `useConfigureSuggestions`, `useCopilotChatSuggestions` | Data | — | |
91 | | - |
92 | | -## Limitations (MVP) |
93 | | - |
94 | | -- **Barrel-file re-exports** aren't resolved — import hooks directly from `@copilotkit/react-core` or `@copilotkit/react-core/v2`. If you re-export through your own index file, the scanner won't pick up the call sites. |
95 | | -- **Non-CopilotKit providers**: if your component requires `<ThemeProvider>`, Redux, Auth context, or another custom provider to render, the mount will fail. Isolate the hook into a provider-free component for preview. |
| 76 | +| `useCopilotAction` | `@copilotkit/react-core` | action (`args`, `status`, `result`) | |
| 77 | +| `useCopilotAuthenticatedAction_c` | `@copilotkit/react-core` | action | |
| 78 | +| `useCoAgentStateRender` | `@copilotkit/react-core` | coagent-state (`state`, `status`, `nodeName`) | |
| 79 | +| `useLangGraphInterrupt` | `@copilotkit/react-core` | interrupt (`event`, `resolve`) | |
| 80 | +| `useRenderTool` | `@copilotkit/react-core/v2` | render-tool (`parameters`, `status`, `toolCallId`) | |
| 81 | +| `useRenderToolCall` | `@copilotkit/react-core/v2` | render-tool | |
| 82 | +| `useDefaultRenderTool` | `@copilotkit/react-core/v2` | render-tool | |
| 83 | +| `useLazyToolRenderer` | `@copilotkit/react-core/v2` | render-tool | |
| 84 | +| `useFrontendTool` | `@copilotkit/react-core/v2` | render-tool | |
| 85 | +| `useComponent` | `@copilotkit/react-core/v2` | render-tool | |
| 86 | +| `useDefaultTool` | `@copilotkit/react-core/v2` | action | |
| 87 | +| `useHumanInTheLoop` | `@copilotkit/react-core/v2` | action | |
| 88 | +| `useInterrupt` | `@copilotkit/react-core/v2` | interrupt | |
| 89 | +| `useRenderCustomMessages` | `@copilotkit/react-core/v2` | custom-messages (`message`) | |
| 90 | +| `useRenderActivityMessage` | `@copilotkit/react-core/v2` | activity-message (`message`) | |
| 91 | + |
| 92 | +Data hooks (`useCopilotReadable`, `useCoAgent`, `useAgent`, `useCopilotChat`, etc.) appear in the sidebar for navigation but have no preview — the row click opens the source. |
| 93 | + |
| 94 | +Imported render components work too: if your `render` prop is a reference to a component defined in a sibling file (instead of an inline arrow), Rolldown walks the import chain and the preview binds to the actual component. |
| 95 | + |
| 96 | +## Behavior notes |
| 97 | + |
| 98 | +- **Auto-recovery**: if a render prop throws, the preview surface shows a readable error screen — and picking a different hook in the sidebar automatically resets the boundary. You're never stuck on a crashed preview. |
| 99 | +- **Controls persist**: your last-used args, status, and result are stored in VS Code workspace state per hook, so they're restored next time you open the same preview. |
| 100 | +- **Styles flow through**: Tailwind classes in your `render` prop work via the Tailwind browser CDN loaded into the preview panel. Local `.css` imports are collected by the bundler and injected as a `<style>` tag on each load. |
| 101 | + |
| 102 | +## Limitations |
| 103 | + |
| 104 | +- **Barrel-file re-exports aren't resolved** — import hooks directly from `@copilotkit/react-core` or `@copilotkit/react-core/v2`. If you re-export through your own index file, the scanner won't pick up the call sites. |
| 105 | +- **Non-CopilotKit providers**: if your component requires `<ThemeProvider>`, Redux, Auth, or another custom provider to render, the mount will throw. Isolate the hook into a provider-free component for preview, or stub the provider in the preview-only path. |
96 | 106 | - **Agent state typing**: `useCoAgentStateRender` state has no runtime schema (types live in TypeScript only), so the state control falls back to a raw-JSON editor. |
97 | | -- **No fixture files**: control values are stored in VS Code workspace state, not a checked-in file. Sharing preview scenarios with your team is follow-up work. |
98 | 107 | - **Dynamic action names**: if `useCopilotAction({ name: someVariable })` uses a non-literal name, the sidebar labels the entry `(dynamic) · file:line` until the runtime capture resolves it. |
99 | 108 |
|
100 | 109 | <Callout type="info"> |
101 | | - For live inspection of AG-UI events while an agent is actually running, see [AG-UI Event Inspector](/troubleshooting/event-inspector). |
| 110 | + Need to see the live AG-UI event stream while the agent is actually running? Hook Explorer is the offline, render-first tool — the [AG-UI Event Inspector](/troubleshooting/event-inspector) is the runtime, events-first complement. |
102 | 111 | </Callout> |
0 commit comments