Skip to content

Commit 84e368c

Browse files
author
Yann Leflour
committed
add history components
1 parent e619d31 commit 84e368c

15 files changed

+684
-94
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"files.exclude": {
33
"ui-sketcher-webview": true,
44
"ui-sketcher-extension": true
5-
}
5+
},
6+
"editor.defaultFormatter": "esbenp.prettier-vscode"
67
}

pnpm-lock.yaml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui-sketcher-webview/.eslintrc.cjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = {
55
"eslint:recommended",
66
"plugin:@typescript-eslint/recommended",
77
"plugin:react-hooks/recommended",
8-
"plugin:storybook/recommended"
8+
"plugin:storybook/recommended",
99
],
1010
ignorePatterns: ["dist", ".eslintrc.cjs"],
1111
parser: "@typescript-eslint/parser",
@@ -22,5 +22,6 @@ module.exports = {
2222
{ allowConstantExport: true },
2323
],
2424
"react-hooks/rules-of-hooks": "off",
25+
"no-case-declarations": "off",
2526
},
2627
};

ui-sketcher-webview/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"react-markdown": "^9.0.1",
2727
"react-syntax-highlighter": "^15.5.0",
2828
"remark-gfm": "^4.0.0",
29+
"use-constant": "^1.1.1",
2930
"valtio": "^1.12.1"
3031
},
3132
"pnpm": {

ui-sketcher-webview/src/chat/Chat.tsx

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { proxy, useSnapshot } from "valtio";
1+
import { useSnapshot } from "valtio";
22
import RMarkdown from "react-markdown";
33
import remarkGfm from "remark-gfm";
44
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
@@ -13,37 +13,6 @@ import {
1313
} from "react";
1414
import { ArrowDownCircleFill, ArrowUpSquareFill } from "react-bootstrap-icons";
1515

16-
function useLocal<T extends object | undefined>(input: T) {
17-
return useRef(proxy(input)).current as T;
18-
}
19-
20-
const history = proxy([
21-
{
22-
type: "system",
23-
message: `
24-
# Hello World
25-
This is a test
26-
27-
\`\`\`js
28-
console.log("Hello World!");
29-
return true;
30-
\`\`\`
31-
32-
`,
33-
},
34-
{ type: "user", message: "Hi!" },
35-
{ type: "system", message: "Hello!" },
36-
{ type: "user", message: "Hi!" },
37-
{ type: "system", message: "Hello!" },
38-
{ type: "user", message: "Hi!" },
39-
{ type: "system", message: "Hello!" },
40-
{ type: "user", message: "Hi!" },
41-
{ type: "system", message: "Hello!" },
42-
{ type: "user", message: "Hi!" },
43-
{ type: "system", message: "Hello!" },
44-
{ type: "user", message: "Hi!" },
45-
]);
46-
4716
const Mardown = ({ children }: { children: string }) => (
4817
<RMarkdown
4918
remarkPlugins={[remarkGfm]}
@@ -61,6 +30,7 @@ const Code = (
6130
HTMLElement
6231
>,
6332
) => {
33+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
6434
const { children, className, ref, ...rest } = props;
6535
const match = /language-(\w+)/.exec(className || "");
6636

@@ -230,17 +200,14 @@ const Input = ({ onSubmit }: InputProps) => {
230200
};
231201

232202
export const Chat = () => {
233-
const historySnap = useSnapshot(history);
234-
const [value] = useState("");
235-
236-
const onSizeChange = (size: number) => {};
203+
const historySnap = useSnapshot(state);
237204

238205
return (
239206
<div className="flex h-full max-h-full flex-col gap-3 bg-white">
240-
<History history={historySnap} />
207+
<History history={historySnap.history} />
241208
<Input
242209
onSubmit={(data) => {
243-
console.warn(data);
210+
state.history.push({ type: "user", message: data });
244211
}}
245212
/>
246213
</div>
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import { Meta, StoryObj } from "@storybook/react";
2+
3+
import { History } from "./History";
4+
5+
const meta: Meta<typeof History> = {
6+
component: History,
7+
};
8+
9+
export default meta;
10+
type Story = StoryObj<typeof History>;
11+
12+
export const Running: Story = {
13+
args: {
14+
history: [
15+
{
16+
id: "1",
17+
role: "user",
18+
content: `### Hello I need to create a new file
19+
20+
\`\`\`json
21+
{
22+
"test": "test"
23+
}
24+
\`\`\``,
25+
},
26+
{
27+
id: "2",
28+
role: "system",
29+
state: "thinking",
30+
steps: [
31+
{
32+
type: "tools",
33+
status: "running",
34+
tools: [
35+
{
36+
id: "1",
37+
name: "tool 1",
38+
args: { test: "test 1" },
39+
},
40+
],
41+
},
42+
],
43+
},
44+
],
45+
},
46+
};
47+
48+
export const Fixing: Story = {
49+
args: {
50+
history: [
51+
{
52+
id: "1",
53+
role: "user",
54+
content: "Hello I need to create a new file",
55+
},
56+
{
57+
id: "2",
58+
role: "system",
59+
state: "thinking",
60+
steps: [
61+
{
62+
type: "tools",
63+
status: "done",
64+
tools: [
65+
{
66+
id: "1",
67+
status: "error",
68+
name: "tool 1",
69+
args: { test: "test 1" },
70+
output: { error: "error" },
71+
},
72+
],
73+
},
74+
{
75+
type: "tools",
76+
status: "running",
77+
tools: [
78+
{
79+
id: "1",
80+
name: "tool 1",
81+
args: { test: "test 1" },
82+
},
83+
],
84+
},
85+
],
86+
},
87+
],
88+
},
89+
};
90+
91+
export const Done: Story = {
92+
args: {
93+
history: [
94+
{
95+
id: "1",
96+
role: "user",
97+
content: "Hello World",
98+
},
99+
{
100+
id: "2",
101+
role: "system",
102+
state: "thinking",
103+
steps: [
104+
{
105+
type: "tools",
106+
status: "done",
107+
tools: [
108+
{
109+
id: "1",
110+
status: "success",
111+
name: "tool 1",
112+
args: { test: "test 1" },
113+
output: { success: true },
114+
},
115+
],
116+
},
117+
{
118+
type: "message",
119+
content: `I've create a new file for you using:
120+
121+
- Test
122+
- List
123+
124+
\`\`\`bash
125+
touch file.json
126+
\`\`\`
127+
`,
128+
},
129+
],
130+
},
131+
],
132+
},
133+
};

0 commit comments

Comments
 (0)