Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Add "context" block [WIP]; Style slash command [WIP]
Tomas Valenta4a90055e8847
diff --git a/components/Editor/RouteEditor/index.tsx b/components/Editor/RouteEditor/index.tsxindex 986a784ff..c4b0f8c6d 100644--- a/components/Editor/RouteEditor/index.tsx+++ b/components/Editor/RouteEditor/index.tsx@@ -1,6 +1,4 @@-import Select from 'components/Select'-import { methods, Method, Route } from 'state/store'-import { useStateStore } from 'state/StoreProvider'+import { Route } from 'state/store'import useBlock from 'hooks/useBlock'import PromptEditor from './PromptEditor'diff --git a/components/Editor/Routes.tsx b/components/Editor/Routes.tsxindex 3703dca7c..0d5589c3f 100644--- a/components/Editor/Routes.tsx+++ b/components/Editor/Routes.tsx@@ -21,10 +21,10 @@ function Routes({deleteRoute,selectRoute,}: Props) {- const store = useStateStore()+ const [selectors] = useStateStore()- const addRoute = store.use.addRoute()- const changeRoute = store.use.changeRoute()+ const addRoute = selectors.use.addRoute()+ const changeRoute = selectors.use.changeRoute()return (<div>diff --git a/components/Editor/Sidebar/index.tsx b/components/Editor/Sidebar/index.tsxindex 13f68c63a..0d39db2c0 100644--- a/components/Editor/Sidebar/index.tsx+++ b/components/Editor/Sidebar/index.tsx@@ -70,8 +70,8 @@ function Sidebar({isMutating: isDeployRequestRunning,} = useSWRMutation(`${apiHost}/generate`, handlePostGenerate)- const store = useStateStore()- const envs = store.use.envs()+ const [selectors] = useStateStore()+ const envs = selectors.use.envs()async function deploy() {if (!route) returndiff --git a/components/Editor/extensions/SlashCommand/Item.tsx b/components/Editor/extensions/SlashCommand/Item.tsxindex ee811bd84..2c41c079e 100644--- a/components/Editor/extensions/SlashCommand/Item.tsx+++ b/components/Editor/extensions/SlashCommand/Item.tsx@@ -39,7 +39,7 @@ function Item({'overflow-ellipsis','overflow-hidden','cursor-pointer',- { 'bg-gray-100 dark:bg-black-900': isSelected },+ { 'bg-slate-300': isSelected },)}onMouseDown={selectItem}>diff --git a/components/Editor/extensions/SlashCommand/index.tsx b/components/Editor/extensions/SlashCommand/index.tsxindex 7c109efac..798834dbc 100644--- a/components/Editor/extensions/SlashCommand/index.tsx+++ b/components/Editor/extensions/SlashCommand/index.tsx@@ -6,6 +6,7 @@ import {} from 'react'import { ChainedCommands } from '@tiptap/core'+import { CommandList } from 'components/Editor/extensions/command/CommandListWrapper'import Item from './Item'@@ -17,7 +18,7 @@ interface CommandItem {const items: CommandItem[] = [{- title: 'Next.js Code Cell',+ title: '@slack/web-api',extendCommand: (cmd) => {return cmd// return cmd.set@@ -73,7 +74,7 @@ const SlashCommand: CommandList = forwardRef(({return (<divclassName="- p-1.5+ p-2w-56max-h-56@@ -87,13 +88,9 @@ const SlashCommand: CommandList = forwardRef(({roundedborder- dark:border-black-600- border-gray-500-- bg-gray-300- dark:bg-black-650+ border-slate-400- shadow-lg+ bg-white">{items.map((item, index) => (diff --git a/components/Editor/index.tsx b/components/Editor/index.tsxindex c031ba7b9..6a8f97ed4 100644--- a/components/Editor/index.tsx+++ b/components/Editor/index.tsx@@ -14,13 +14,12 @@ export interface Props {}function Editor({ project }: Props) {- const store = useStateStore()+ const [selectors] = useStateStore()const ref = useRef<HTMLDivElement | null>(null)-// TODO: Handle editor state differently so we don't rerender this component on each editor edit.- const routes = store.use.routes()- const deleteRoute = store.use.deleteRoute()+ const routes = selectors.use.routes()+ const deleteRoute = selectors.use.deleteRoute()const [selectedRouteID, setSelectedRouteID] = useState(() => routes.length > 0 ? routes[0].id : undefined)const selectedRoute = routes.find(s => s.id === selectedRouteID)@@ -38,7 +37,7 @@ function Editor({ project }: Props) {}})}-+const [sizes, setSizes] = useLocalStorage('project-board-splitter-sizes', [60, 40])const handleResize = useCallback((_: number, newSizes: number[]) => {setSizes(newSizes)diff --git a/editor/extensions/command/suggestion.ts b/editor/extensions/command/suggestion.tsindex 4b6797a3a..fcdfcd8d8 100644--- a/editor/extensions/command/suggestion.ts+++ b/editor/extensions/command/suggestion.ts@@ -1,6 +1,7 @@import { Editor, Range } from '@tiptap/core'import { Plugin, PluginKey } from 'prosemirror-state'import { Decoration, DecorationSet, EditorView } from 'prosemirror-view'+import { findSuggestionMatch } from './findSuggestionMatch'export interface SuggestionOptions<Item = unknown> {diff --git a/editor/extensions/context/contextSchema.ts b/editor/extensions/context/contextSchema.tsindex 2503b6c13..9521ba575 100644--- a/editor/extensions/context/contextSchema.ts+++ b/editor/extensions/context/contextSchema.ts@@ -18,13 +18,14 @@ export default Node.create({addAttributes() {return {+ ...attributeHandler({ htmlPrefix: HTML_ATTR_PREFIX, nodeAttribute: constants.NODE_ATTR_CELL_RUN_ON_START }),}},parseHTML() {return [{- tag: 'pre',+ tag: 'context',preserveWhitespace: 'full',},]diff --git a/hooks/useBlock.ts b/hooks/useBlock.tsindex 1d7efce45..d10c78030 100644--- a/hooks/useBlock.ts+++ b/hooks/useBlock.ts@@ -3,9 +3,9 @@ import { Route, BlockType, Block } from 'state/store'import { useStateStore } from 'state/StoreProvider'function useBlock(blockType: BlockType, route?: Route): [Block | undefined, (prompt: string) => void] {- const store = useStateStore()+ const [selectors] = useStateStore()- const changeBlock = store.use.changeBlock()+ const changeBlock = selectors.use.changeBlock()const blockIdx = route?.blocks.findIndex(r => r.type === blockType)const block = blockIdx !== undefined &&diff --git a/package.json b/package.jsonindex a8996991a..a51b6f741 100644--- a/package.json+++ b/package.json@@ -36,6 +36,8 @@"nanoid": "^4.0.1","next": "13.2.3","next-superjson-plugin": "^0.5.6",+ "prosemirror-state": "^1.4.2",+ "prosemirror-view": "^1.30.2","randomcolor": "^0.6.2","react": "18.2.0","react-dom": "18.2.0",@@ -44,6 +46,7 @@"sonner": "^0.1.6","superjson": "^1.12.2","swr": "^2.0.4",+ "tippy.js": "^6.3.7","usehooks-ts": "^2.9.1","zustand": "^4.3.5"},diff --git a/state/StoreProvider.tsx b/state/StoreProvider.tsxindex c97be6a61..d99d1ab1d 100644--- a/state/StoreProvider.tsx+++ b/state/StoreProvider.tsx@@ -15,7 +15,7 @@ import { createSelectors } from './selectors'type StoreType = ReturnType<typeof createStore>type SelectorsType = ReturnType<typeof createSelectors<StoreType>>-const storeContext = createContext<SelectorsType | null>(null)+const storeContext = createContext<[SelectorsType, StoreType] | null>(null)export interface Props extends PropsWithChildren {project: projects@@ -28,9 +28,9 @@ export function StoreProvider({children,}: Props) {const store = useMemo(() => createStore(project, client), [project.id, project.data, client])- const selectors = createSelectors(store)+ const selectors = createSelectors(store,)return (- <storeContext.Provider value={selectors}>+ <storeContext.Provider value={[selectors, store]}>{children}</storeContext.Provider>)diff --git a/state/store.ts b/state/store.tsindex e933fae99..4c731a477 100644--- a/state/store.ts+++ b/state/store.ts@@ -100,7 +100,7 @@ export function createStore(project: projects, client?: SupabaseClient<Database>initialState.envs.push({ key: '', value: '' })}- const immerStore = immer<State>((set) => ({+ const immerStore = immer<State>((set, get) => ({...initialState,addRoute: () => set(state => {state.routes.push(getDefaultRoute())diff --git a/styles/global.css b/styles/global.cssindex 5ae29ea2e..490c25644 100644--- a/styles/global.css+++ b/styles/global.css@@ -1,4 +1,6 @@@import 'highlight.js/styles/a11y-dark.css';+@import 'tippy.js/dist/tippy.css';+@import './prosemirror.css';@tailwind base;diff --git a/yarn.lock b/yarn.lockindex 862918d20..956c5baaf 100644--- a/yarn.lock+++ b/yarn.lock@@ -3472,7 +3472,7 @@ prosemirror-schema-list@^1.2.2:prosemirror-state "^1.0.0"prosemirror-transform "^1.0.0"-prosemirror-state@^1.0.0, prosemirror-state@^1.2.2, prosemirror-state@^1.3.1, prosemirror-state@^1.4.1:+prosemirror-state@^1.0.0, prosemirror-state@^1.2.2, prosemirror-state@^1.3.1, prosemirror-state@^1.4.1, prosemirror-state@^1.4.2:version "1.4.2"resolved "https://registry.yarnpkg.com/prosemirror-state/-/prosemirror-state-1.4.2.tgz#f93bd8a33a4454efab917ba9b738259d828db7e5"integrity sha512-puuzLD2mz/oTdfgd8msFbe0A42j5eNudKAAPDB0+QJRw8cO1ygjLmhLrg9RvDpf87Dkd6D4t93qdef00KKNacQ==@@ -3509,7 +3509,7 @@ prosemirror-transform@^1.0.0, prosemirror-transform@^1.1.0, prosemirror-transfordependencies:prosemirror-model "^1.0.0"-prosemirror-view@^1.0.0, prosemirror-view@^1.1.0, prosemirror-view@^1.13.3, prosemirror-view@^1.27.0, prosemirror-view@^1.28.2:+prosemirror-view@^1.0.0, prosemirror-view@^1.1.0, prosemirror-view@^1.13.3, prosemirror-view@^1.27.0, prosemirror-view@^1.28.2, prosemirror-view@^1.30.2:version "1.30.2"resolved "https://registry.yarnpkg.com/prosemirror-view/-/prosemirror-view-1.30.2.tgz#57a9d15c5baa454f0d0f4a3028ddbd9be1e8ed9b"integrity sha512-nTNzZvalQf9kHeEyO407LiV6DoOs/pXsid88UqW9Vvybo4ozJW2PJhkfZUxCUF1hR/9vJLdhxX84wuw9P9HsXA==