forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.tsx
More file actions
43 lines (35 loc) · 1.18 KB
/
Copy pathpage.tsx
File metadata and controls
43 lines (35 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"use client";
import React from "react";
import {
CopilotKit,
useAgent,
UseAgentUpdate,
} from "@copilotkit/react-core/v2";
import { DemoLayout } from "./demo-layout";
import { useSharedStateStreamingSuggestions } from "./suggestions";
interface StreamingAgentState {
document?: string;
}
export default function SharedStateStreamingDemo() {
return (
<CopilotKit runtimeUrl="/api/copilotkit" agent="shared-state-streaming">
<DemoContent />
</CopilotKit>
);
}
function DemoContent() {
// @region[frontend-use-coagent-state]
// Subscribe to BOTH state changes and run-status changes. The former
// drives the per-token document rerender; the latter toggles the
// "LIVE" badge when the agent starts / stops.
const { agent } = useAgent({
agentId: "shared-state-streaming",
updates: [UseAgentUpdate.OnStateChanged, UseAgentUpdate.OnRunStatusChanged],
});
// @endregion[frontend-use-coagent-state]
useSharedStateStreamingSuggestions();
const agentState = agent.state as StreamingAgentState | undefined;
const document = agentState?.document ?? "";
const isRunning = agent.isRunning;
return <DemoLayout document={document} isStreaming={isRunning} />;
}