Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

commit

Vasek Mlejnsky4f81c013eee7
diff --git a/components/Editor/RouteEditor/PromptEditor.tsx b/components/Editor/RouteEditor/PromptEditor.tsx
index 82796aa5a..9cd884570 100644
--- a/components/Editor/RouteEditor/PromptEditor.tsx
+++ b/components/Editor/RouteEditor/PromptEditor.tsx
@@ -18,7 +18,7 @@ function PromptEditor({
placeholder,
}: Props) {
const editor = useDocEditor({
- initialContent: block.prompt,
+ initialContent: block.content,
onContentChange: onChange,
placeholder,
})
diff --git a/components/Editor/RouteEditor/RequestBodyEditor.tsx b/components/Editor/RouteEditor/RequestBodyEditor.tsx
index 91cb306e9..28ff2c923 100644
--- a/components/Editor/RouteEditor/RequestBodyEditor.tsx
+++ b/components/Editor/RouteEditor/RequestBodyEditor.tsx
@@ -45,7 +45,7 @@ function RequestBodyEditor({
spellCheck="false"
name="block"
placeholder="email: string"
- value={block.prompt}
+ value={block.content}
onChange={e => onChange(e.target.value)}
className={clsx(
'w-full',
diff --git a/components/Editor/Sidebar/index.tsx b/components/Editor/Sidebar/index.tsx
index 844df1537..36315265b 100644
--- a/components/Editor/Sidebar/index.tsx
+++ b/components/Editor/Sidebar/index.tsx
@@ -5,10 +5,10 @@ import clsx from 'clsx'
import useSWRMutation from 'swr/mutation'
import Text from 'components/Text'
-import { Route, Block } from 'state/store'
+import { Route } from 'state/store'
import { useLatestDeployment } from 'hooks/useLatestDeployment'
import { useStateStore } from 'state/StoreProvider'
-import { getPromptText } from 'hooks/useDocEditor'
+import { html2markdown } from 'hooks/useDocEditor'
import DeployButton from './DeployButton'
import Logs from './Logs'
@@ -30,34 +30,39 @@ async function handlePostGenerate(url: string, { arg }: {
envs: { key: string, value: string }[],
}
}) {
- console.log(arg.route.blocks)
- return await fetch(url, {
- method: 'POST',
- body: JSON.stringify({
- projectID: arg.projectID,
- routeID: arg.route.id,
- // Transform block with structured prose into block with plain prompt text.
- blocks: arg.route.blocks.map(b => {
- switch (b.type) {
- case 'StructuredProse':
- const block: Block = {
- ...b,
- type: 'Basic',
- prompt: getPromptText(b.prompt),
- }
- return block
- default:
- return b
- }
- }),
- method: arg.route.method.toLowerCase(),
- route: arg.route.route,
- envs: arg.envs,
- }),
- headers: {
- 'Content-Type': 'application/json',
- },
- }).then(r => r.json())
+ arg.route.blocks.forEach(b => {
+ console.log(b)
+ if (b.type === 'StructuredProse') {
+ html2markdown(b.content)
+ }
+ })
+
+ // return await fetch(url, {
+ // method: 'POST',
+ // body: JSON.stringify({
+ // projectID: arg.projectID,
+ // routeID: arg.route.id,
+ // // Transform block with structured prose into block with plain prompt text.
+ // blocks: arg.route.blocks.map(b => {
+ // switch (b.type) {
+ // case 'StructuredProse':
+ // const block: Block = {
+ // ...b,
+ // content: html2markdown(b.content),
+ // }
+ // return block
+ // default:
+ // return b
+ // }
+ // }),
+ // method: arg.route.method.toLowerCase(),
+ // route: arg.route.route,
+ // envs: arg.envs,
+ // }),
+ // headers: {
+ // 'Content-Type': 'application/json',
+ // },
+ // }).then(r => r.json())
}
function Sidebar({
diff --git a/hooks/useBlock.ts b/hooks/useBlock.ts
index 57ad6706f..2bf6fa106 100644
--- a/hooks/useBlock.ts
+++ b/hooks/useBlock.ts
@@ -26,10 +26,9 @@ function useBlock(blockType: BlockType, position: number, route?: Route): [Block
? route?.blocks[blockIdx]
: undefined
- const setBlock = useCallback((prompt: string) => {
- console.log('SET BLOCK', prompt)
+ const setBlock = useCallback((content: string) => {
if (route?.id && blockIdx !== undefined && blockIdx !== -1) {
- changeBlock(route.id, blockIdx, { prompt })
+ changeBlock(route.id, blockIdx, { content })
}
}, [blockIdx, route?.id, changeBlock])
diff --git a/hooks/useDocEditor.ts b/hooks/useDocEditor.ts
index f8ffce0b1..6de54e745 100644
--- a/hooks/useDocEditor.ts
+++ b/hooks/useDocEditor.ts
@@ -31,8 +31,8 @@ const extensions = [
const schema = getSchema(extensions)
-export function getPromptText(structuredProse: string) {
- const node = createDocument(structuredProse, schema)
+export function html2markdown(html: string) {
+ const node = createDocument(html, schema)
const markdown = defaultMarkdownSerializer.serialize(node)
console.log(markdown)
return markdown
@@ -84,7 +84,6 @@ function useDocEditor({
instance.on('transaction', t => {
if (t.transaction.docChanged) {
- // onContentChange(t.transaction.doc.toJSON())
onContentChange(t.editor.getHTML())
}
})
@@ -98,7 +97,6 @@ function useDocEditor({
}, [
onContentChange,
// We don't want the initialContent in the dependencies because that would reload the editor when we type.
- // initialContent
])
return editor
diff --git a/state/store.ts b/state/store.ts
index 48eb65232..741f728dd 100644
--- a/state/store.ts
+++ b/state/store.ts
@@ -13,13 +13,14 @@ export type BlockType =
'Basic' |
// Code that looks like TypeScript interface definition without the outer parenthesses.
'RequestBody' |
- // ProseMirror XML
+ // ProseMirror HTML
'StructuredProse'
export interface Block {
id: string
type: BlockType
- prompt: string
+ // `content` is HTML when `type` is `StructuredProse`
+ content: string
}
export interface Route {
@@ -59,7 +60,7 @@ export interface State extends SerializedState {
function createBlock(type: BlockType): Block {
return {
type,
- prompt: '',
+ content: '',
id: nanoid(),
}
}