1
1
import { Meta , StoryObj } from "@storybook/react" ;
2
2
import { ChatToolInvocation } from "./ChatToolInvocation" ;
3
- import { MockWorkspace } from "testHelpers/entities" ;
3
+ import {
4
+ MockStartingWorkspace ,
5
+ MockStoppedWorkspace ,
6
+ MockStoppingWorkspace ,
7
+ MockWorkspace ,
8
+ } from "testHelpers/entities" ;
4
9
5
10
const meta : Meta < typeof ChatToolInvocation > = {
6
11
title : "pages/ChatPage/ChatToolInvocation" ,
@@ -11,32 +16,93 @@ export default meta;
11
16
type Story = StoryObj < typeof ChatToolInvocation > ;
12
17
13
18
export const GetWorkspace : Story = {
14
- args : {
15
- toolInvocation : {
16
- toolName : "coder_get_workspace" ,
17
- args : {
19
+ render : ( ) =>
20
+ renderInvocations (
21
+ "coder_get_workspace" ,
22
+ {
18
23
id : MockWorkspace . id ,
19
24
} ,
20
- result : MockWorkspace ,
21
- state : "result" ,
22
- toolCallId : "some-id" ,
23
- } ,
24
- } ,
25
+ MockWorkspace ,
26
+ ) ,
25
27
} ;
26
28
27
29
export const CreateWorkspace : Story = {
28
- args : {
29
- toolInvocation : {
30
- toolName : "coder_create_workspace" ,
31
- args : {
30
+ render : ( ) =>
31
+ renderInvocations (
32
+ "coder_create_workspace" ,
33
+ {
32
34
name : MockWorkspace . name ,
33
35
rich_parameters : { } ,
34
36
template_version_id : MockWorkspace . template_active_version_id ,
35
37
user : MockWorkspace . owner_name ,
36
38
} ,
37
- result : MockWorkspace ,
38
- state : "result" ,
39
- toolCallId : "some-id" ,
40
- } ,
41
- } ,
39
+ MockWorkspace ,
40
+ ) ,
41
+ } ;
42
+
43
+ export const ListWorkspaces : Story = {
44
+ render : ( ) =>
45
+ renderInvocations (
46
+ "coder_list_workspaces" ,
47
+ {
48
+ owner : "me" ,
49
+ } ,
50
+ [
51
+ MockWorkspace ,
52
+ MockStoppedWorkspace ,
53
+ MockStoppingWorkspace ,
54
+ MockStartingWorkspace ,
55
+ ] ,
56
+ ) ,
57
+ } ;
58
+
59
+ const renderInvocations = < T extends ChatToolInvocation [ "toolName" ] > (
60
+ toolName : T ,
61
+ args : Extract < ChatToolInvocation , { toolName : T } > [ "args" ] ,
62
+ result : Extract <
63
+ ChatToolInvocation ,
64
+ { toolName : T ; state : "result" }
65
+ > [ "result" ] ,
66
+ error ?: string ,
67
+ ) => {
68
+ return (
69
+ < >
70
+ < ChatToolInvocation
71
+ toolInvocation = { {
72
+ toolCallId : "call" ,
73
+ toolName,
74
+ args : args as any ,
75
+ state : "call" ,
76
+ } }
77
+ />
78
+ < ChatToolInvocation
79
+ toolInvocation = { {
80
+ toolCallId : "partial-call" ,
81
+ toolName,
82
+ args : args as any ,
83
+ state : "partial-call" ,
84
+ } }
85
+ />
86
+ < ChatToolInvocation
87
+ toolInvocation = { {
88
+ toolCallId : "result" ,
89
+ toolName,
90
+ args : args as any ,
91
+ state : "result" ,
92
+ result : result as any ,
93
+ } }
94
+ />
95
+ < ChatToolInvocation
96
+ toolInvocation = { {
97
+ toolCallId : "result" ,
98
+ toolName,
99
+ args : args as any ,
100
+ state : "result" ,
101
+ result : {
102
+ error : error || "Something bad happened!" ,
103
+ } ,
104
+ } }
105
+ />
106
+ </ >
107
+ ) ;
42
108
} ;
0 commit comments