Skip to content

Commit 50d00e2

Browse files
breadonceejerelvelarde
authored andcommitted
fix: address code review feedback
- Remove misleading system prompt instruction about "save-as-template" messages (saves go directly via agent.setState, not through chat) - Replace fragile DOM querySelector hack for sending prompts with agent.addMessage() + agent.runAgent() API calls
1 parent 7e5fc35 commit 50d00e2

2 files changed

Lines changed: 8 additions & 21 deletions

File tree

apps/agent/main.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@
6060
user's new data and render via `widgetRenderer`.
6161
- When a user asks to see their templates, call `list_templates`.
6262
- When a user asks to delete a template, call `delete_template`.
63-
- A "save-as-template" message from the frontend means the user clicked the save
64-
button on a widget. Extract the template details and call `save_template`.
6563
""",
6664
)
6765

apps/app/src/app/page.tsx

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,15 @@ export default function HomePage() {
3636
agent.setState({ templates: [...templates, newTemplate] });
3737
}, [agent]);
3838

39-
// Send a prompt to the CopilotChat by finding its textarea and submitting
39+
// Send a prompt via the agent API — adds a user message and triggers a run
4040
const sendPrompt = useCallback((text: string) => {
41-
const input = document.querySelector<HTMLTextAreaElement>(
42-
'[class*="copilot"] textarea, [data-copilotkit] textarea'
43-
);
44-
if (input) {
45-
const setter = Object.getOwnPropertyDescriptor(
46-
window.HTMLTextAreaElement.prototype,
47-
"value"
48-
)?.set;
49-
setter?.call(input, text);
50-
input.dispatchEvent(new Event("input", { bubbles: true }));
51-
setTimeout(() => {
52-
const form = input.closest("form");
53-
if (form) {
54-
form.dispatchEvent(new Event("submit", { bubbles: true, cancelable: true }));
55-
}
56-
}, 50);
57-
}
58-
}, []);
41+
agent.addMessage({
42+
id: crypto.randomUUID(),
43+
role: "user",
44+
content: text,
45+
});
46+
agent.runAgent();
47+
}, [agent]);
5948

6049
// Widget bridge: handle messages from widget iframes
6150
useEffect(() => {

0 commit comments

Comments
 (0)