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

STA-6217 Move UI examples into this repo #14

Draft
wants to merge 45 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
985bad0
Copy files from other repo into /examples-ui/joke
kevinmaes Feb 20, 2024
754f923
Delete workspaces
kevinmaes Feb 20, 2024
b5f9009
Delete private: true
kevinmaes Feb 20, 2024
f605719
Delete Vite svg
kevinmaes Feb 20, 2024
de7451d
Delete private: true
kevinmaes Feb 20, 2024
e923f69
add package lock files to .gitignore
kevinmaes Feb 20, 2024
ff96597
Update openai dependency
kevinmaes Feb 20, 2024
218fda9
Move import (prettier)
kevinmaes Feb 20, 2024
2b42562
Reduce the joke example UI to only run the joke example
kevinmaes Feb 20, 2024
473c3ce
Delete App component
kevinmaes Feb 20, 2024
748df3a
Attempt to add tic tac toe example. WIP
kevinmaes Feb 20, 2024
9618cf7
Delete unused Joke.tsx in tic tac toe folder
kevinmaes Feb 20, 2024
1bba2e7
Delete examples content and move it up a level
kevinmaes Feb 20, 2024
d1745ae
Add setTopic event to schema
kevinmaes Feb 20, 2024
91808f0
Add target to tsconfig
kevinmaes Feb 22, 2024
1f99a7c
Delete comment
kevinmaes Feb 22, 2024
3e7574d
Add target to tsconfig
kevinmaes Feb 22, 2024
3242c38
Move subscription into createTicTacToeAgent
kevinmaes Feb 22, 2024
f495c6b
Delete local stately/agent dependency
kevinmaes Feb 22, 2024
2f45144
Delete export keyword
kevinmaes Feb 22, 2024
5defaa6
Fix running of ticTacToe (but not TS errors)
kevinmaes Feb 22, 2024
1a044f1
Subscribe to the agent in index.ts and call sendEvent on updates
kevinmaes Feb 22, 2024
54f833f
Refactor to return the agent
kevinmaes Feb 22, 2024
9f05bb0
Use only example app root level package.json
kevinmaes Feb 22, 2024
faebb82
Delete server/package.json
kevinmaes Feb 22, 2024
aaf3beb
Add explicit xstate dependency
kevinmaes Feb 22, 2024
224a290
Fix types
Andarist Feb 22, 2024
f339c70
Remove package.json from ticTacToe/server
kevinmaes Feb 22, 2024
be1167e
Update prettier config and apply to joke.ts
kevinmaes Feb 22, 2024
f3cb190
Add todo for schema code
kevinmaes Feb 22, 2024
991a45b
fix import
Andarist Feb 22, 2024
c016d51
fix widening issues
Andarist Feb 22, 2024
c7abfe3
Fix Joke script errors
kevinmaes Feb 22, 2024
325a908
Add type: module in root package.json with override in server
kevinmaes Feb 22, 2024
a684ca5
Fix game board alignment
kevinmaes Feb 22, 2024
1134cfe
Set text colors
kevinmaes Feb 22, 2024
0d60cae
Tweak sizing
kevinmaes Feb 22, 2024
b70e08d
Tweak heading text
kevinmaes Feb 22, 2024
61f214b
Use constants for ports
kevinmaes Feb 22, 2024
3fb204b
Add ports to .env files
kevinmaes Feb 22, 2024
e7b20fe
Add .env.template files per example app
kevinmaes Feb 23, 2024
2278b01
Add to readme for both example applications
kevinmaes Feb 23, 2024
4b4f886
Add Stately logo
kevinmaes Feb 23, 2024
bc5a7ea
Merge branch 'main' into kevin/sta-6217-move-stately-agent-examples-i…
kevinmaes Feb 28, 2024
8965011
Merge branch 'main' into kevin/sta-6217-move-stately-agent-examples-i…
kevinmaes Mar 18, 2024
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
4 changes: 4 additions & 0 deletions examples-ui/joke/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Get your OpenAI API key from: https://platform.openai.com/signup/
OPENAI_API_KEY="sk-..."
VITE_PORT="3000"
VITE_API_PORT="3001"
18 changes: 18 additions & 0 deletions examples-ui/joke/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
27 changes: 27 additions & 0 deletions examples-ui/joke/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

package-lock.json
server/package-lock.json
48 changes: 48 additions & 0 deletions examples-ui/joke/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Getting started

This directory in the `@stately/agent` repository has a self-contained app for a Joke Generator. It consists of a React/Vite client as well as a nested `server` directory for the express server app.

Install dependencies for client and server using [`pnpm`](https://pnpm.io/):

`pnpm run install` or `pnpm run i`

Sure, here's a simple markdown table as requested:

| Name | Script | Description |
| --------------- | ----------------- | --------------------------------------- |
| Client only | `pnpm run client` | Runs the client React app only |
| Server only | `pnpm run server` | Runs the express server only |
| Client + Server | `pnpm run dev` | Runs the client and server concurrently |

After running `pnpm run dev`, go to `http://localhost:3000` to view the app for the Joke Generator.

# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default {
// other rules...
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
};
```

- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
12 changes: 12 additions & 0 deletions examples-ui/joke/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Stately Agent Examples</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
48 changes: 48 additions & 0 deletions examples-ui/joke/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "agent-examples",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"client": "vite",
"server": "ts-node server/index.ts",
"dev": "concurrently \"npm run client\" \"npm run server\"",
"vite": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"@statelyai/agent": "^0.0.5",
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"concurrently": "^8.2.2",
"cors": "^2.8.5",
"express": "^4.18.2",
"openai": "^4.28.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"xstate": "^5.8.0"
},
"devDependencies": {
"@tailwindcss/forms": "^0.5.7",
"@types/react": "^18.2.55",
"@types/react-dom": "^18.2.19",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"@vitejs/plugin-react": "^4.2.1",
"autoprefixer": "^10.4.17",
"dotenv": "^16.3.1",
"eslint": "^8.56.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"nodemon": "^3.0.3",
"postcss": "^8.4.35",
"prettier": "^3.1.0",
"prettier-plugin-organize-imports": "^3.2.4",
"tailwindcss": "^3.4.1",
"ts-node": "^10.9.2",
"typescript": "^5.3.3",
"vite": "^5.1.0"
}
}
Loading