Skip to content

Commit

Permalink
examples: playground (#502)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonom authored Jul 15, 2024
1 parent efcdf48 commit 7daca39
Show file tree
Hide file tree
Showing 49 changed files with 3,093 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/with-playground/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
3 changes: 3 additions & 0 deletions examples/with-playground/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
36 changes: 36 additions & 0 deletions examples/with-playground/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
12 changes: 12 additions & 0 deletions examples/with-playground/app/api/chat/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { createOpenAI } from "@ai-sdk/openai";
import { createEdgeRuntimeAPI } from "@assistant-ui/react/edge";

export const maxDuration = 30;

export const { POST } = createEdgeRuntimeAPI({
model: ({ apiKey, modelName }) => {
if (!apiKey) throw new Error("apiKey is required");
if (!modelName) throw new Error("modelName is required");
return createOpenAI({ apiKey })(modelName as any);
},
});
Binary file added examples/with-playground/app/favicon.ico
Binary file not shown.
3 changes: 3 additions & 0 deletions examples/with-playground/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
23 changes: 23 additions & 0 deletions examples/with-playground/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { Metadata } from "next";
import { Inter } from "next/font/google";

import "./globals.css";

const inter = Inter({ subsets: ["latin"] });

export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body className={inter.className}>{children}</body>
</html>
);
}
54 changes: 54 additions & 0 deletions examples/with-playground/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"use client";

import {
AssistantPlayground,
requestOptionsFromOpenAI,
} from "@assistant-ui/react-playground";
import { usePlaygroundRuntime } from "@assistant-ui/react-playground";
import { AssistantRuntimeProvider } from "@assistant-ui/react";

export default function Home() {
const runtime = usePlaygroundRuntime({
api: "/api/chat",
initialMessages: [],
});

const handleLoadTestData = () => {
runtime.thread.setRequestData(
requestOptionsFromOpenAI({
model: "gpt-4o",
messages: [
{
role: "user",
content: "Write a poem about the weather",
},
{
role: "assistant",
content: "The weather is sunny and warm.",
},
],
}),
);
};

return (
<AssistantRuntimeProvider runtime={runtime}>
<div className="flex h-dvh flex-col overflow-hidden">
<div className="mx-4 flex items-center justify-between border-b py-4">
<h1 className="text-2xl font-bold">Playground</h1>
<button
className="bg-aui-foreground px-4 py-2"
onClick={handleLoadTestData}
>
Load Test Data
</button>
</div>
<div className="flex-grow overflow-hidden">
<div className="flex h-full flex-col overflow-scroll">
<AssistantPlayground />
</div>
</div>
</div>
</AssistantRuntimeProvider>
);
}
4 changes: 4 additions & 0 deletions examples/with-playground/next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};

export default nextConfig;
32 changes: 32 additions & 0 deletions examples/with-playground/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "with-playground",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@ai-sdk/openai": "^0.0.36",
"@assistant-ui/react": "workspace:*",
"@assistant-ui/react-playground": "workspace:*",
"next": "14.2.5",
"react": "^18",
"react-dom": "^18",
"tailwindcss-animate": "^1.0.7"
},
"devDependencies": {
"@assistant-ui/tsconfig": "workspace:^",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"eslint": "^8",
"eslint-config-next": "14.2.5",
"postcss": "^8",
"tailwindcss": "^3.4.4",
"typescript": "^5"
},
"packageManager": "[email protected]+sha512.f549b8a52c9d2b8536762f99c0722205efc5af913e77835dbccc3b0b0b2ca9e7dc8022b78062c17291c48e88749c70ce88eb5a74f1fa8c4bf5e18bb46c8bd83a"
}
8 changes: 8 additions & 0 deletions examples/with-playground/postcss.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('postcss-load-config').Config} */
const config = {
plugins: {
tailwindcss: {},
},
};

export default config;
18 changes: 18 additions & 0 deletions examples/with-playground/tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { Config } from "tailwindcss";

const config = {
darkMode: ["class"],
content: [
"./pages/**/*.{ts,tsx}",
"./components/**/*.{ts,tsx}",
"./app/**/*.{ts,tsx}",
"./src/**/*.{ts,tsx}",
"./node_modules/@assistant-ui/react-playground/{dist,src}/**/*.{js,ts,tsx}",
],
plugins: [
require("tailwindcss-animate"),
require("@assistant-ui/react/tailwindcss")({ components: ["base"] }),
],
} satisfies Config;

export default config;
21 changes: 21 additions & 0 deletions examples/with-playground/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": "@assistant-ui/tsconfig/base.json",
"compilerOptions": {
"target": "ES6",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./*"],

},
"allowJs": true,
"strictNullChecks": true,
"jsx": "preserve"
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
3 changes: 3 additions & 0 deletions packages/react-playground/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
3 changes: 3 additions & 0 deletions packages/react-playground/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `@assistant-ui/react-playground`

A playground runtime for `@assistant-ui/react`.
17 changes: 17 additions & 0 deletions packages/react-playground/components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "default",
"rsc": true,
"tsx": true,
"tailwind": {
"config": "tailwind.config.ts",
"css": "app/globals.css",
"baseColor": "zinc",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils"
}
}
85 changes: 85 additions & 0 deletions packages/react-playground/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"name": "@assistant-ui/react-playground",
"version": "0.0.0-alpha.0",
"license": "MIT",
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
},
"source": "./src/index.ts",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"files": [
"dist",
"README.md"
],
"sideEffects": false,
"scripts": {
"build": "tsx scripts/build.mts"
},
"dependencies": {
"@ai-sdk/provider": "^0.0.12",
"@radix-ui/react-avatar": "^1.1.0",
"@radix-ui/react-dialog": "^1.1.1",
"@radix-ui/react-dropdown-menu": "^2.1.1",
"@radix-ui/react-select": "^2.1.1",
"@radix-ui/react-slider": "^1.2.0",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-tooltip": "^1.1.2",
"class-variance-authority": "^0.7.0",
"classnames": "^2.5.1",
"clsx": "^2.1.1",
"lucide-react": "^0.407.0",
"openai": "^4.52.7",
"prismjs": "^1.29.0",
"react-simple-code-editor": "^0.14.1",
"react-textarea-autosize": "^8.5.3",
"tailwind-merge": "^2.4.0",
"zustand": "^4.5.4"
},
"peerDependencies": {
"@assistant-ui/react": "^0.4.4",
"@types/react": "*",
"react": "^18",
"tailwindcss": "^3.4.4"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"tailwindcss": {
"optional": true
}
},
"devDependencies": {
"@assistant-ui/tsconfig": "workspace:*",
"@types/prismjs": "^1.26.4",
"eslint": "^8",
"eslint-config-next": "14.2.5",
"tailwindcss": "^3.4.4",
"tailwindcss-animate": "^1.0.7",
"tsup": "^8.1.0",
"tsx": "^4.16.2"
},
"publishConfig": {
"access": "public",
"provenance": true
},
"homepage": "https://assistant-ui.com/",
"repository": {
"type": "git",
"url": "git+https://github.com/Yonom/assistant-ui.git"
},
"bugs": {
"url": "https://github.com/Yonom/assistant-ui/issues"
}
}
36 changes: 36 additions & 0 deletions packages/react-playground/scripts/build.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { build } from "tsup";

// JS
await build({
entry: ["src/index.ts"],
format: ["cjs", "esm"],
dts: true,
sourcemap: true,
clean: true,
esbuildOptions: (options) => {
options.banner = {
js: '"use client";',
};
},
});

// await build({
// entry: ["src/tailwindcss/index.ts"],
// outDir: "dist/tailwindcss",
// format: ["cjs", "esm"],
// dts: true,
// sourcemap: true,
// });

// // css

// await build({
// entry: ["src/styles/tailwindcss/markdown.css"],
// outDir: "dist/styles",
// });

// mkdirSync("dist/styles/tailwindcss", { recursive: true });
// copyFileSync(
// "src/styles/tailwindcss/markdown.css",
// "dist/styles/tailwindcss/markdown.css",
// );
Loading

0 comments on commit 7daca39

Please sign in to comment.