44 CopilotChatView ,
55 CopilotKitProvider ,
66} from "@copilotkitnext/react" ;
7+ import { Suggestion } from "@copilotkitnext/core" ;
78
89const meta = {
910 title : "UI/CopilotChatView" ,
@@ -34,16 +35,96 @@ export const Default: Story = {
3435 ) ,
3536 ] ,
3637 render : ( ) => {
37- const messages = [
38- {
39- id : "user-1" ,
40- content : "Hello! Can you help me understand how React hooks work?" ,
41- timestamp : new Date ( ) ,
42- role : "user" as const ,
43- } ,
44- {
45- id : "assistant-1" ,
46- content : `React hooks are functions that let you use state and other React features in functional components. Here are the most common ones:
38+ return (
39+ < CopilotKitProvider >
40+ < CopilotChatConfigurationProvider threadId = "storybook-thread" >
41+ < div style = { { height : "100%" } } >
42+ < CopilotChatView
43+ messages = { storyMessages }
44+ inputProps = { {
45+ onSubmitMessage : ( value ) => {
46+ alert ( `Message submitted: ${ value } ` ) ;
47+ } ,
48+ } }
49+ messageView = { {
50+ assistantMessage : {
51+ onThumbsUp : ( ) => {
52+ alert ( "thumbsUp" ) ;
53+ } ,
54+ onThumbsDown : ( ) => {
55+ alert ( "thumbsDown" ) ;
56+ } ,
57+ } ,
58+ } }
59+ />
60+ </ div >
61+ </ CopilotChatConfigurationProvider >
62+ </ CopilotKitProvider >
63+ ) ;
64+ } ,
65+ } ;
66+
67+ export const WithSuggestions : Story = {
68+ parameters : {
69+ layout : "fullscreen" ,
70+ } ,
71+ decorators : Default . decorators ,
72+ render : ( ) => (
73+ < CopilotKitProvider >
74+ < CopilotChatConfigurationProvider threadId = "storybook-thread" >
75+ < div style = { { height : "100%" } } >
76+ < CopilotChatView
77+ messages = { storyMessages }
78+ suggestions = { suggestionSamples }
79+ onSelectSuggestion = { ( suggestion ) =>
80+ alert ( `Selected suggestion: ${ suggestion . title } ` )
81+ }
82+ inputProps = { {
83+ onSubmitMessage : ( value ) => {
84+ alert ( `Message submitted: ${ value } ` ) ;
85+ } ,
86+ } }
87+ messageView = { {
88+ assistantMessage : {
89+ onThumbsUp : ( ) => alert ( "thumbsUp" ) ,
90+ onThumbsDown : ( ) => alert ( "thumbsDown" ) ,
91+ } ,
92+ } }
93+ />
94+ </ div >
95+ </ CopilotChatConfigurationProvider >
96+ </ CopilotKitProvider >
97+ ) ,
98+ } ;
99+
100+ const suggestionSamples : Suggestion [ ] = [
101+ {
102+ title : "Summarize conversation" ,
103+ message : "Summarize our latest messages" ,
104+ isLoading : false ,
105+ } ,
106+ {
107+ title : "Draft reply" ,
108+ message : "Draft a detailed response" ,
109+ isLoading : false ,
110+ } ,
111+ {
112+ title : "List next steps" ,
113+ message : "List action items from this chat" ,
114+ isLoading : true ,
115+ } ,
116+ ] ;
117+
118+ const storyMessages = [
119+ {
120+ id : "user-1" ,
121+ content : "Hello! Can you help me understand how React hooks work?" ,
122+ timestamp : new Date ( ) ,
123+ role : "user" as const ,
124+ } ,
125+ {
126+ id : "assistant-1" ,
127+ content : `React hooks are functions that let you use state and other React features in functional components. Here are the most common ones:
47128
48129- **useState** - Manages local state
49130- **useEffect** - Handles side effects
@@ -52,18 +133,18 @@ export const Default: Story = {
52133- **useMemo** - Memoizes values
53134
54135Would you like me to explain any of these in detail?` ,
55- timestamp : new Date ( ) ,
56- role : "assistant" as const ,
57- } ,
58- {
59- id : "user-2" ,
60- content : "Yes, could you explain useState with a simple example?" ,
61- timestamp : new Date ( ) ,
62- role : "user" as const ,
63- } ,
64- {
65- id : "assistant-2" ,
66- content : `Absolutely! Here's a simple useState example:
136+ timestamp : new Date ( ) ,
137+ role : "assistant" as const ,
138+ } ,
139+ {
140+ id : "user-2" ,
141+ content : "Yes, could you explain useState with a simple example?" ,
142+ timestamp : new Date ( ) ,
143+ role : "user" as const ,
144+ } ,
145+ {
146+ id : "assistant-2" ,
147+ content : `Absolutely! Here's a simple useState example:
67148
68149\`\`\`jsx
69150import React, { useState } from 'react';
@@ -87,31 +168,7 @@ In this example:
87168- It returns an array: \`[currentValue, setterFunction]\`
88169- \`count\` is the current state value
89170- \`setCount\` is the function to update the state` ,
90- timestamp : new Date ( ) ,
91- role : "assistant" as const ,
92- } ,
93- ] ;
94-
95- return (
96- < CopilotKitProvider >
97- < CopilotChatConfigurationProvider threadId = "storybook-thread" >
98- < div style = { { height : "100%" } } >
99- < CopilotChatView
100- messages = { messages }
101- messageView = { {
102- assistantMessage : {
103- onThumbsUp : ( ) => {
104- alert ( "thumbsUp" ) ;
105- } ,
106- onThumbsDown : ( ) => {
107- alert ( "thumbsDown" ) ;
108- } ,
109- } ,
110- } }
111- />
112- </ div >
113- </ CopilotChatConfigurationProvider >
114- </ CopilotKitProvider >
115- ) ;
171+ timestamp : new Date ( ) ,
172+ role : "assistant" as const ,
116173 } ,
117- } ;
174+ ] ;
0 commit comments