Skip to content

Commit 1343103

Browse files
committed
Re-export CopilotKitInspector
1 parent c9821df commit 1343103

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { Meta, StoryObj } from "@storybook/react";
2+
import { CopilotKitInspector } from "@copilotkitnext/react";
3+
4+
const meta: Meta<typeof CopilotKitInspector> = {
5+
title: "Components/CopilotKit Inspector",
6+
component: CopilotKitInspector,
7+
};
8+
9+
export default meta;
10+
11+
type Story = StoryObj<typeof CopilotKitInspector>;
12+
13+
export const Default: Story = {
14+
args: {},
15+
};
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import * as React from "react";
2+
import { createComponent } from "@lit-labs/react";
3+
import {
4+
WEB_INSPECTOR_TAG,
5+
WebInspectorElement,
6+
defineWebInspector,
7+
} from "@copilotkitnext/web-inspector";
8+
import type { CopilotKitCore } from "@copilotkitnext/core";
9+
10+
defineWebInspector();
11+
12+
const CopilotKitInspectorBase = createComponent({
13+
tagName: WEB_INSPECTOR_TAG,
14+
elementClass: WebInspectorElement,
15+
react: React,
16+
});
17+
18+
export type CopilotKitInspectorBaseProps = React.ComponentProps<typeof CopilotKitInspectorBase>;
19+
20+
export interface CopilotKitInspectorProps extends Omit<CopilotKitInspectorBaseProps, "core"> {
21+
core?: CopilotKitCore | null;
22+
}
23+
24+
export const CopilotKitInspector = React.forwardRef<
25+
WebInspectorElement,
26+
CopilotKitInspectorProps
27+
>(
28+
({ core, ...rest }, ref) => {
29+
const innerRef = React.useRef<WebInspectorElement>(null);
30+
31+
React.useImperativeHandle(ref, () => innerRef.current as WebInspectorElement, []);
32+
33+
React.useEffect(() => {
34+
if (innerRef.current) {
35+
innerRef.current.core = core ?? null;
36+
}
37+
}, [core]);
38+
39+
return (
40+
<CopilotKitInspectorBase
41+
{...(rest as CopilotKitInspectorBaseProps)}
42+
ref={innerRef}
43+
/>
44+
); // eslint-disable-line react/jsx-props-no-spreading
45+
},
46+
);
47+
48+
CopilotKitInspector.displayName = "CopilotKitInspector";

0 commit comments

Comments
 (0)