|
1 | 1 | "use client"; |
2 | 2 |
|
3 | | -import { useEffect, useState, useCallback } from "react"; |
| 3 | +import { useEffect, useState } from "react"; |
4 | 4 | import { ExampleLayout } from "@/components/example-layout"; |
5 | 5 | import { useGenerativeUIExamples, useExampleSuggestions } from "@/hooks"; |
6 | 6 | import { ExplainerCardsPortal } from "@/components/explainer-cards"; |
7 | 7 | import { TemplateLibrary } from "@/components/template-library"; |
8 | 8 |
|
9 | 9 | import { CopilotChat } from "@copilotkit/react-core/v2"; |
10 | | -import { useAgent } from "@copilotkit/react-core/v2"; |
11 | 10 |
|
12 | 11 | export default function HomePage() { |
13 | 12 | useGenerativeUIExamples(); |
14 | 13 | useExampleSuggestions(); |
15 | 14 |
|
16 | | - const { agent } = useAgent(); |
17 | 15 | const [templateDrawerOpen, setTemplateDrawerOpen] = useState(false); |
18 | 16 |
|
19 | | - // Save a template directly to agent state — no chat round-trip |
20 | | - const saveTemplate = useCallback((data: { |
21 | | - name: string; |
22 | | - title: string; |
23 | | - description: string; |
24 | | - html: string; |
25 | | - }) => { |
26 | | - const templates = agent.state?.templates || []; |
27 | | - const newTemplate = { |
28 | | - id: crypto.randomUUID(), |
29 | | - name: data.name || data.title || "Untitled Template", |
30 | | - description: data.description || data.title || "", |
31 | | - html: data.html, |
32 | | - data_description: "", |
33 | | - created_at: new Date().toISOString(), |
34 | | - version: 1, |
35 | | - }; |
36 | | - agent.setState({ templates: [...templates, newTemplate] }); |
37 | | - }, [agent]); |
38 | | - |
39 | | - // Send a prompt via the agent API — adds a user message and triggers a run |
40 | | - const sendPrompt = useCallback((text: string) => { |
41 | | - agent.addMessage({ |
42 | | - id: crypto.randomUUID(), |
43 | | - role: "user", |
44 | | - content: text, |
45 | | - }); |
46 | | - agent.runAgent(); |
47 | | - }, [agent]); |
48 | | - |
49 | 17 | // Widget bridge: handle messages from widget iframes |
50 | 18 | useEffect(() => { |
51 | 19 | const handler = (e: MessageEvent) => { |
52 | 20 | if (e.data?.type === "open-link" && typeof e.data.url === "string") { |
53 | 21 | window.open(e.data.url, "_blank", "noopener,noreferrer"); |
54 | 22 | } |
55 | | - // Handle save-as-template from WidgetRenderer — save directly to state |
56 | | - if (e.data?.type === "save-as-template") { |
57 | | - saveTemplate(e.data); |
58 | | - } |
59 | 23 | }; |
60 | 24 | window.addEventListener("message", handler); |
61 | 25 | return () => window.removeEventListener("message", handler); |
62 | | - }, [saveTemplate]); |
| 26 | + }, []); |
| 27 | + |
63 | 28 |
|
64 | 29 | return ( |
65 | 30 | <> |
@@ -147,7 +112,6 @@ export default function HomePage() { |
147 | 112 | <TemplateLibrary |
148 | 113 | open={templateDrawerOpen} |
149 | 114 | onClose={() => setTemplateDrawerOpen(false)} |
150 | | - onSendPrompt={sendPrompt} |
151 | 115 | /> |
152 | 116 | </> |
153 | 117 | ); |
|
0 commit comments