Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Agent Playground #41

Merged
merged 53 commits into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
1dfd8d6
move Icons -> icons
louisgv Apr 19, 2023
7146973
initialize playground
louisgv Apr 19, 2023
a537aa3
feat: playground page
louisgv Apr 20, 2023
1496a8f
refactor web to align up codebase
louisgv Apr 20, 2023
0290902
get it out
louisgv Apr 20, 2023
61cbf3b
Need a debugger or some sort for manual test?
louisgv Apr 21, 2023
75d455e
Initial agent planning ready
louisgv Apr 23, 2023
873282b
move playground to agent
louisgv Apr 23, 2023
9af6618
fix deps
louisgv Apr 23, 2023
7a2f011
Manual agent hring for testing out agent - time to train the monkey
louisgv Apr 24, 2023
f3597d3
some refinement
louisgv Apr 24, 2023
b1d1709
Add some reading on OODA
louisgv Apr 25, 2023
1a3aa6e
Merge branch 'main' into playground
louisgv Apr 25, 2023
3019577
merge with new type
louisgv Apr 25, 2023
00bd825
First step at observing
louisgv Apr 26, 2023
db79da3
Merge branch 'type-infer' into playground
louisgv Apr 26, 2023
9629880
Basic loop kinda running, the reflection phase is still pretty bad
louisgv Apr 26, 2023
5a95eb7
Merge branch 'type-infer' into playground
louisgv Apr 26, 2023
5722a0b
merge with type-infer
louisgv Apr 27, 2023
61a1705
Fix lockfile
louisgv Apr 27, 2023
62df44f
Merge branch 'type-infer' into playground
louisgv Apr 28, 2023
10ab44e
migrate to array of result
louisgv Apr 28, 2023
4fa73c3
adding webcontainer
louisgv Apr 30, 2023
f4017b6
Fix footer color
louisgv Apr 30, 2023
aebdc7f
Merge branch 'playground' of github.com:louisgv/window.ai into playgr…
louisgv Apr 30, 2023
47fdda3
web container added, ready to roll
louisgv Apr 30, 2023
013aa66
vm ai container with interated TTY done
louisgv May 1, 2023
96e300d
save to rebase
louisgv May 1, 2023
d5feb48
merge with external model
louisgv May 1, 2023
b5210db
fix up chat install button
louisgv May 1, 2023
370e804
play around with the cursor a bit
louisgv May 2, 2023
bce9557
Added some fix
louisgv May 2, 2023
e950e5f
add a loop limit when it doesn't add the end segment
louisgv May 2, 2023
f588926
Merge branch 'main' into playground
louisgv May 2, 2023
162d7d0
Merge branch 'main' into playground
louisgv May 3, 2023
afd4204
scaffold whole project working, need to debug the stream buffer it's …
louisgv May 3, 2023
d6b0753
Merge branch 'playground' of github.com:louisgv/window.ai into playgr…
louisgv May 3, 2023
2f615ee
checkpoint, maybe we can leverage the jsh_history file instead of hav…
louisgv May 3, 2023
8841d3f
it's totally working for scaffolding
louisgv May 4, 2023
6fe220b
good to go
louisgv May 4, 2023
04cd48d
bump nextjs version
louisgv May 5, 2023
f096f8a
remove web terminal and web preview from agent demo
louisgv May 6, 2023
3656b3b
fix code editor theme
louisgv May 12, 2023
4cb24d8
fix the UI a bit
louisgv May 12, 2023
4a074a1
Merge branch 'main' into playground
louisgv May 13, 2023
96b6e00
Minor re-org
louisgv May 16, 2023
f1cb732
Merge branch 'playground' of github.com:louisgv/window.ai into playgr…
louisgv May 16, 2023
ed33378
fix nit
louisgv May 16, 2023
22cf3c4
merge
louisgv May 17, 2023
ca1a7af
Merge with main
louisgv May 26, 2023
0db47a9
merge with main
louisgv May 27, 2023
7771534
Move features -> demo
louisgv May 27, 2023
74452ef
bump plasmo to remove the weird log
louisgv May 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/web/src/core/components/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Button } from "./Button"
import { ChatLine, LoadingChatLine } from "./ChatLine"
import { InputMessage } from "./InputMessage"
import { DISCORD_URL, EXTENSION_CHROME_URL } from "./common"
import { initialMessages, useWindowAI } from "./hooks/useWindowAI"
import { initialMessages, useWindowAI } from "../hooks/useWindowAI"
import { GetExtensionButton } from "~core/components/GetExtensionButton"

const COOKIE_NAME = "nextjs-example-ai-chat-gpt3"
Expand Down Expand Up @@ -46,8 +46,8 @@ export function Chat() {
}, [messages])

return (
<div className="w-full pt-10">
<div className="rounded-lg border-slate-11 border p-6 w-full h-[360px] flex flex-col">
<div className="w-full h-full pt-10">
<div className="rounded-lg border-slate-11 border p-6 w-full h-full md:h-[320px] flex flex-col">
<div className="flex-grow overflow-y-auto pr-8 pl-4" ref={messagesRef}>
{messages.map(({ content, role }, index) => (
<ChatLine key={index} role={role} content={content} />
Expand Down
20 changes: 16 additions & 4 deletions apps/web/src/core/components/CodeBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { IconCheck, IconClipboard, IconDownload } from "@tabler/icons-react"
import { type FC, memo, useState } from "react"
// use client
import { IconCheck, IconClipboard } from "@tabler/icons-react"
import clsx from "clsx"
import { useMemo, useState, type FC } from "react"
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"
import {
oneDark,
oneLight
} from "react-syntax-highlighter/dist/cjs/styles/prism"
import { useMatchMedia } from "~core/hooks/useMatchMedia"

export const programmingLanguages = {
javascript: ".js",
Expand Down Expand Up @@ -66,9 +69,18 @@ export const CodeBlock: FC<Props> = ({ language, value }) => {
}, 2000)
})
}
const isDarkTheme = useMatchMedia("(prefers-color-scheme: dark)")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

const editorTheme = useMemo(
() => (isDarkTheme ? oneDark : oneLight),
[isDarkTheme]
)

if (isDarkTheme === undefined) {
return null
}

return (
<div className="codeblock relative font-sans text-[16px] group">
<div className={clsx("codeblock relative font-sans text-[16px] group")}>
<div className="flex items-center justify-between py-1.5 px-4">
<span className="text-xs lowercase">{language}</span>

Expand All @@ -83,7 +95,7 @@ export const CodeBlock: FC<Props> = ({ language, value }) => {
</div>
<SyntaxHighlighter
language={language}
style={oneLight}
style={editorTheme}
customStyle={{ margin: 0 }}>
{value}
</SyntaxHighlighter>
Expand Down
18 changes: 10 additions & 8 deletions apps/web/src/core/components/GetExtensionButton.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import clsx from "clsx"
import Link from "next/link"
import { Button } from "~core/components/Button"
import { EXTENSION_CHROME_URL } from "~core/components/common"

export const GetExtensionButton = ({ className = "" }) => (
<Button
onClick={() => window.open(EXTENSION_CHROME_URL, "_blank")}
className={clsx(
"bg-indigo-9 hover:bg-indigo-10 text-white hover:text-white/80",
className
)}>
Get the extension
</Button>
<Link target="_blank" href={EXTENSION_CHROME_URL}>
<Button
className={clsx(
"bg-indigo-9 hover:bg-indigo-10 text-white hover:text-white/80",
className
)}>
Get the extension
</Button>
</Link>
)
8 changes: 5 additions & 3 deletions apps/web/src/core/components/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ export function Tooltip({
content,
above = false
}: {
children: ReactNode
content: ReactNode
above?: boolean
children: React.ReactNode
content: React.ReactNode
}) {
const [visible, setVisible] = useState(false)

Expand All @@ -28,7 +29,8 @@ export function Tooltip({
{visible && (
<span
className={clsx(
"absolute z-10 top-full left-0",
above ? "bottom-full" : "top-full",
"absolute z-10 left-0",
"mt-2 p-3 w-52 bg-slate-9 text-slate-12 text-xs rounded-md shadow-lg"
)}>
{content}
Expand Down
27 changes: 27 additions & 0 deletions apps/web/src/core/hooks/useMatchMedia.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useState, useEffect } from "react"

export const useMatchMedia = (query: string) => {
const [isMatch, setIsMatch] = useState<boolean>()

useEffect(() => {
if (!globalThis.window?.matchMedia) {
return
}

// set initial value
const mediaWatcher = globalThis.window.matchMedia(query)
setIsMatch(mediaWatcher.matches)
//watch for updates
function onMediaChanged(e: MediaQueryListEvent) {
setIsMatch(e.matches)
}
mediaWatcher.addEventListener("change", onMediaChanged)

// clean up after ourselves
return function cleanup() {
mediaWatcher.removeEventListener("change", onMediaChanged)
}
}, [query])

return isMatch
}
2 changes: 1 addition & 1 deletion apps/web/src/features/agent/AgentHiringCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import clsx from "clsx"
import type { TextareaHTMLAttributes } from "react"
import { useState, type FC } from "react"
import { useAgentManager } from "~core/providers/agent-manager"
import { useAgentManager } from "~features/agent/agent-manager-provider"
import { AgentMonitor } from "~features/agent/AgentMonitor"

const Input: FC<TextareaHTMLAttributes<HTMLTextAreaElement>> = (props) => (
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/features/agent/CaptainMonitor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useAgentManager } from "~core/providers/agent-manager"
import { useAgentManager } from "~features/agent/agent-manager-provider"
import { AgentMonitor } from "~features/agent/AgentMonitor"

export const CaptainMonitor = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createProvider } from "puro"
import { useCallback, useContext, useMemo, useState } from "react"
import extractJson from "@airthium/extract-json-from-string"
import { useWindowAI } from "~core/components/hooks/useWindowAI"
import { useWindowAI } from "~core/hooks/useWindowAI"
import { isMessageOutput } from "window.ai"

import { nanoid } from "nanoid"
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/features/agent/useCodeAI.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { WebContainer } from "@webcontainer/api"
import { posix } from "path"
import { useWindowAI } from "~core/components/hooks/useWindowAI"
import { parseCmd } from "~core/utils/terminal-parser"
import { useWindowAI } from "~core/hooks/useWindowAI"
import { parseCmd } from "~features/web-vm/terminal-parser"
import { extractCodeBlocks } from "~features/agent/utils"

const CONT_MESSAGE = "===CONTINUE_CODEAI==="
Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/features/agent/useCrew.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useEffect, useMemo, useState } from "react"
import { useArrayRef } from "~core/components/hooks/useArrayRef"
import { useWindowAI } from "~core/components/hooks/useWindowAI"
import { useArrayRef } from "~core/hooks/useArrayRef"
import { useWindowAI } from "~core/hooks/useWindowAI"
import {
useAgentManager,
type AgentConfig
} from "~core/providers/agent-manager"
} from "~features/agent/agent-manager-provider"
import { useLog } from "~features/agent/useLog"

const getSystemPrompt = (goal: string, ac: AgentConfig) =>
alexanderatallah marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/features/web-vm/WebPreview.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useWebVM } from "~core/providers/web-vm"
import { useWebVM } from "~features/web-vm/web-vm-provider"

import clsx from "clsx"

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/features/web-vm/WebTerminal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useWebVM } from "~core/providers/web-vm"
import { useWebVM } from "~features/web-vm/web-vm-provider"

import "xterm/css/xterm.css"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import { type Terminal } from "xterm"

import { WebContainer, type WebContainerProcess } from "@webcontainer/api"
import type { FitAddon } from "xterm-addon-fit"
import { useWindowAI } from "~core/components/hooks/useWindowAI"
import { getInputBufferFromCursor, parseCmd } from "~core/utils/terminal-parser"
import { useWindowAI } from "~core/hooks/useWindowAI"
import {
getInputBufferFromCursor,
parseCmd
} from "~features/web-vm/terminal-parser"
import { useCodeAI } from "~features/agent/useCodeAI"
import { binDirectory } from "~features/web-vm/files"
import { posix } from "path"
Expand Down Expand Up @@ -94,7 +97,7 @@ const useWebVMProvider = ({
[
{
role: "system",
content: `You are a powerful Linux quantum virtual machine that can simulate new command-line program, non-standard UNIX program, and anything above and beyond. If a program can be answered with just text, write just text. If a program is creating graphic, you will use ASCII art. If a program is creating audio, you will write music notations or lyrics. Be super creative and resourceful with how you come up with the output. You are not just any text-based program. Do not give any explanation, apologies, or any reasoning. Just output the result.`
content: `You are a powerful Linux quantum virtual machine that can create and output any command-line programs, non-standard UNIX programs, and anything above and beyond. If a program can be answered with just text, write just text. If a program is creating graphic, you will use ASCII art. If a program is creating audio, you will write music notations or lyrics. Be super creative and resourceful with how you come up with the output. You are not just any text-based program. Do not give any explanation, apologies, or any reasoning. Just output the result.`
}
],
{
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/pages/agent.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AgentManagerProvider } from "~core/providers/agent-manager"
import { WebVMProvider } from "~core/providers/web-vm"
import { AgentManagerProvider } from "~features/agent/agent-manager-provider"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we put agent and vm inside a demos folder, so that the demos are namespaced and grouped together?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

import { WebVMProvider } from "~features/web-vm/web-vm-provider"
import { AgentPlaygroundView } from "~views/AgentPlaygroundView"

export default function AgentPlaygroundPage() {
Expand Down
7 changes: 2 additions & 5 deletions apps/web/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ function Home() {
</Text>

<div className="grid grid-cols-6 gap-6">
<Text className="md:col-span-4 col-span-6">
In this example, a simple chatbot is implemented in one file, with{" "}
<strong>no backend.</strong>
<br />
<Text className="text-zinc-9 md:col-span-4 col-span-6">
Users, not developers, choose which model to use with apps{" "}
<Link className="underline" href={GITHUB_URL} target="_blank">
built on window.ai
Expand All @@ -64,7 +61,7 @@ function Home() {
<Section>
<div className="flex justify-between w-full md:space-x-4 md:flex-row flex-col space-y-8 md:space-y-0">
<CodeBlock language="javascript" value={windowaiExample} />
<div className="w-full">
<div className="w-full h-screen md:h-auto">
<Chat />
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/pages/vm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Head from "next/head"
import { WebVMProvider } from "~core/providers/web-vm"
import { WebVMProvider } from "~features/web-vm/web-vm-provider"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could also name this folder demos to be in sync with that

import { AIContainerView } from "~views/AIContainerView"

export default function AIContainerPage() {
alexanderatallah marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/views/AgentPlaygroundView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { InputMessage } from "~core/components/InputMessage"
import { useAgentManager } from "~core/providers/agent-manager"
import { useAgentManager } from "~features/agent/agent-manager-provider"
import { AgentHiringCard } from "~features/agent/AgentHiringCard"
import { CaptainMonitor } from "~features/agent/CaptainMonitor"
import { CrewMonitor } from "~features/agent/CrewMonitor"
Expand Down