Skip to content

Commit e280bf8

Browse files
authored
Sheet action metadata (#47)
* add metadata to google actions, rename existing actions * separate out codeblock ui
1 parent e8f4ca5 commit e280bf8

File tree

6 files changed

+45
-49
lines changed

6 files changed

+45
-49
lines changed

apps/src/base/appController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export abstract class AppController<T> {
3636
// 0. Exposed actions --------------------------------------------
3737
@Action({
3838
labelRunning: "Completing task",
39-
labelDone: "Task Completed",
39+
labelDone: "Task Done",
4040
description: "Marks the task as done if the users' task is accomplished.",
4141
renderBody: ({ taskDone }: { taskDone: boolean }) => {
4242
return {text: null, code: null}
@@ -48,7 +48,7 @@ export abstract class AppController<T> {
4848

4949
@Action({
5050
labelRunning: "Responding to user",
51-
labelDone: "Replied to user",
51+
labelDone: "Reply Sent",
5252
description: "Responds to the user with the given content.",
5353
renderBody: ({ content }: { content: string }) => {
5454
return {text: null, code: null}

apps/src/google/appState.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { RPCs } from "web";
2-
import { AppController } from "../base/appController";
2+
import { AppController, Action } from "../base/appController";
33
import { DefaultAppState } from "../base/appState";
44
import { googleSheetInternalState } from "./googleSheetInternalState";
55
import { BlankMessageContent, GoogleState } from "web/types";
@@ -31,6 +31,14 @@ export class GoogleAppState extends DefaultAppState<GoogleState> {
3131
}
3232

3333
export class GoogleController extends AppController<GoogleState> {
34+
@Action({
35+
labelRunning: "Running AppScript",
36+
labelDone: "Sheet Actions",
37+
description: "Runs AppScript code in the Google Sheets",
38+
renderBody: ({ code }: { code: string }) => {
39+
return {text: null, code: code}
40+
}
41+
})
3442
async runAppsScriptCode(code: string) {
3543
if (typeof code === 'object') {
3644
code = code.code as string

web/src/components/common/ActionStack.tsx

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,7 @@ import { ChatContent } from './ChatContent';
1414
import { getApp } from "../../helpers/app";
1515
import 'reflect-metadata';
1616
import { parseArguments } from '../../planner/plannerActions';
17-
18-
import { PrismLight as SyntaxHighlighter } from 'react-syntax-highlighter';
19-
import python from 'react-syntax-highlighter/dist/esm/languages/prism/python';
20-
import sql from 'react-syntax-highlighter/dist/esm/languages/prism/sql';
21-
import vsd from 'react-syntax-highlighter/dist/esm/styles/prism/vsc-dark-plus';
22-
import { getPlatformLanguage } from '../../helpers/utils';
23-
24-
SyntaxHighlighter.registerLanguage('python', python);
25-
SyntaxHighlighter.registerLanguage('sql', sql);
17+
import { CodeBlock } from './CodeBlock';
2618

2719
function removeThinkingTags(input: string): string {
2820
return input ? input.replace(/<thinking>[\s\S]*?<\/thinking>/g, '') : input;
@@ -42,18 +34,8 @@ export const ActionStack: React.FC<{status: string, actions: Array<ActionStatusV
4234
latency
4335
}) => {
4436
const [isExpanded, setIsExpanded] = useState(false);
45-
const [controller, setController] = useState<any>(null);
4637
const currentTool = useSelector((state: RootState) => state.settings.iframeInfo.tool)
47-
48-
useEffect(() => {
49-
const fetchController = async () => {
50-
const app = await getApp();
51-
setController(app.actionController);
52-
};
53-
54-
fetchController();
55-
}, []);
56-
38+
const controller = getApp().actionController
5739
const getActionLabels = (action: string, attr: string) => {
5840
if (controller) {
5941
const metadata = Reflect.getMetadata('actionMetadata', controller, action);
@@ -88,8 +70,9 @@ export const ActionStack: React.FC<{status: string, actions: Array<ActionStatusV
8870
const toggleExpand = () => {
8971
setIsExpanded(!isExpanded)
9072
}
73+
9174
return (
92-
<HStack aria-label={title} className={'action-stack'} justifyContent={'start'} maxWidth={"100%"}>
75+
<HStack aria-label={title} className={'action-stack'} justifyContent={'start'} maxWidth={"100%"} width={isExpanded ? "100%" : ""}>
9376
<Box
9477
bg={'minusxGreen.800'}
9578
// bg={'minusxBW.600'}
@@ -101,7 +84,7 @@ export const ActionStack: React.FC<{status: string, actions: Array<ActionStatusV
10184
color={'minusxBW.50'}
10285
// color={'minusxGreen.800'}
10386
border={'1px'}
104-
maxWidth={'100%'}
87+
width={'100%'}
10588
position="relative"
10689
>
10790
{content && <>
@@ -149,9 +132,7 @@ export const ActionStack: React.FC<{status: string, actions: Array<ActionStatusV
149132
</HStack>
150133

151134
{ code && <Box width={"100%"} p={2} bg={"#1e1e1e"} borderRadius={5}>
152-
<SyntaxHighlighter language={getPlatformLanguage(currentTool)} style={vsd}>
153-
{code || ""}
154-
</SyntaxHighlighter>
135+
<CodeBlock code={code || ""} tool={currentTool}/>
155136
</Box>
156137
}
157138

@@ -218,7 +199,7 @@ const scrollUp = keyframes`
218199
`;
219200

220201
const PlanningActionStack: React.FC = () => {
221-
const planningActions = ['Planning', 'Understanding App state', 'Thinking', 'Finalizing Actions', 'Validating Answers']
202+
const planningActions = ['Planning next steps', 'Thinking about the question', 'Understanding App state', 'Finalizing Actions', 'Validating Answers']
222203
const [currentTitleIndex, setCurrentTitleIndex] = useState(0);
223204
useEffect(() => {
224205
const intervalId = setInterval(() => {
@@ -235,7 +216,8 @@ const PlanningActionStack: React.FC = () => {
235216
borderRadius={5}
236217
color={'minusxBW.50'}
237218
width={"100%"}
238-
position="relative"
219+
display={"flex"}
220+
justifyContent={"center"}
239221
>
240222
<HStack>
241223
<Box>
@@ -245,4 +227,4 @@ const PlanningActionStack: React.FC = () => {
245227
</HStack>
246228
</Box>
247229
</HStack>
248-
)}
230+
)}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react-redux'
2+
import { PrismLight as SyntaxHighlighter } from 'react-syntax-highlighter';
3+
import sql from 'react-syntax-highlighter/dist/esm/languages/prism/sql';
4+
import python from 'react-syntax-highlighter/dist/esm/languages/prism/python';
5+
import javascript from 'react-syntax-highlighter/dist/esm/languages/prism/javascript';
6+
7+
import vsd from 'react-syntax-highlighter/dist/esm/styles/prism/vsc-dark-plus';
8+
import { getPlatformLanguage } from '../../helpers/utils';
9+
10+
SyntaxHighlighter.registerLanguage('sql', sql);
11+
SyntaxHighlighter.registerLanguage('python', python);
12+
SyntaxHighlighter.registerLanguage('javascript', javascript);
13+
14+
export const CodeBlock = ({ code, tool }: { code: string, tool: string }) => {
15+
return (
16+
<SyntaxHighlighter language={getPlatformLanguage(tool)} style={vsd}>
17+
{code}
18+
</SyntaxHighlighter>
19+
)
20+
}

web/src/components/common/UserConfirmation.tsx

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,27 @@ import { setUserConfirmationInput, toggleUserConfirmation } from '../../state/ch
1616
import { useSelector } from 'react-redux'
1717
import { RootState } from '../../state/store'
1818
import { useEffect } from 'react'
19-
import { PrismLight as SyntaxHighlighter } from 'react-syntax-highlighter';
20-
import sql from 'react-syntax-highlighter/dist/esm/languages/prism/sql';
21-
import python from 'react-syntax-highlighter/dist/esm/languages/prism/python';
22-
import vsd from 'react-syntax-highlighter/dist/esm/styles/prism/vsc-dark-plus';
23-
// import { setConfirmChanges } from '../../state/settings/reducer';
24-
import { getPlatformLanguage } from '../../helpers/utils';
25-
26-
SyntaxHighlighter.registerLanguage('sql', sql);
27-
SyntaxHighlighter.registerLanguage('python', python);
19+
import { CodeBlock } from './CodeBlock'
2820

2921

3022
export const UserConfirmation = () => {
3123
const thread = useSelector((state: RootState) => state.chat.activeThread)
3224
const activeThread = useSelector((state: RootState) => state.chat.threads[thread])
3325
const userConfirmation = activeThread.userConfirmation
3426
const currentTool = useSelector((state: RootState) => state.settings.iframeInfo.tool)
35-
const confirmChanges = useSelector((state: RootState) => state.settings.confirmChanges)
3627

3728
useEffect(() => {
3829
dispatch(setUserConfirmationInput('NULL'))
3930
dispatch(toggleUserConfirmation({'show': false, 'content': ''}))
4031
}, []);
4132

42-
// const updateConfirmChanges = (value: boolean) => {
43-
// dispatch(setConfirmChanges(value))
44-
// }
45-
4633

4734
if (!userConfirmation.show) return null
4835
return (
4936
<VStack alignItems={"center"}>
5037
<Text fontWeight={"bold"} fontSize={17}>Accept below code?</Text>
5138
<Box width={"100%"} p={2} bg={"#1e1e1e"} borderRadius={5}>
52-
<SyntaxHighlighter language={getPlatformLanguage(currentTool)} style={vsd}>
53-
{userConfirmation.content}
54-
</SyntaxHighlighter>
39+
<CodeBlock code={userConfirmation.content} tool={currentTool}/>
5540
</Box>
5641
{/*two buttons with yes and no*/}
5742
<HStack width={"80%"}>

web/src/helpers/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ const PLATFORM_LANGUAGES: {
1717
[key: string]: string
1818
} = {
1919
jupyter: 'python',
20-
metabase: 'sql'
20+
metabase: 'sql',
21+
google: 'javascript'
2122
}
2223

2324
export const getPlatformLanguage = (platform: string): string => {

0 commit comments

Comments
 (0)