├── .gitignore ├── LICENSE ├── README.md ├── app ├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public │ ├── favicon.ico │ ├── index.html │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── robots.txt ├── src │ ├── App.tsx │ ├── ChatMessages.tsx │ ├── index.css │ ├── index.tsx │ ├── logo.svg │ ├── react-app-env.d.ts │ ├── reportWebVitals.ts │ └── setupTests.ts └── tsconfig.json ├── chat.rivet-project ├── package-lock.json ├── package.json └── server ├── .eslintignore ├── .eslintrc.json ├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── src ├── RivetDebuggerRoutes.ts ├── Router.ts ├── constants │ ├── EnvVars.ts │ ├── HttpStatusCodes.ts │ └── misc.ts ├── index.ts ├── other │ └── classes.ts └── services │ ├── CalculationService.ts │ └── RivetRunner.ts ├── tsconfig.json └── tsconfig.prod.json /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | .pnp.cjs 8 | .pnp.loader.mjs 9 | 10 | # testing 11 | /coverage 12 | 13 | # production 14 | /build 15 | 16 | # misc 17 | .DS_Store 18 | .env.local 19 | .env.development.local 20 | .env.test.local 21 | .env.production.local 22 | 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Ironclad 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rivet-example 2 | 3 | An example chat application using Rivet. 4 | 5 | ## Getting Started 6 | 7 | 1. Clone this repository 8 | 2. `npm install` 9 | 3. `export OPENAI_API_KEY=[your api key]` 10 | 4. `npm start` 11 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /app/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 39 | 40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | -------------------------------------------------------------------------------- /app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.17.0", 7 | "@testing-library/react": "^13.4.0", 8 | "@testing-library/user-event": "^13.5.0", 9 | "@types/jest": "^27.5.2", 10 | "@types/node": "^16.18.40", 11 | "@types/react": "^18.2.19", 12 | "@types/react-dom": "^18.2.7", 13 | "axios": "^1.4.0", 14 | "react": "^18.2.0", 15 | "react-dom": "^18.2.0", 16 | "react-icons": "^4.11.0", 17 | "react-scripts": "5.0.1", 18 | "typescript": "^4.9.5", 19 | "web-vitals": "^2.1.4" 20 | }, 21 | "scripts": { 22 | "start": "react-scripts start", 23 | "build": "react-scripts build", 24 | "test": "react-scripts test", 25 | "eject": "react-scripts eject" 26 | }, 27 | "eslintConfig": { 28 | "extends": [ 29 | "react-app", 30 | "react-app/jest" 31 | ] 32 | }, 33 | "browserslist": { 34 | "production": [ 35 | ">0.2%", 36 | "not dead", 37 | "not op_mini all" 38 | ], 39 | "development": [ 40 | "last 1 chrome version", 41 | "last 1 firefox version", 42 | "last 1 safari version" 43 | ] 44 | }, 45 | "proxy": "http://localhost:3001" 46 | } 47 | -------------------------------------------------------------------------------- /app/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ironclad/rivet-example/70b33f802b550fad6cc3e7b9095723403af9e266/app/public/favicon.ico -------------------------------------------------------------------------------- /app/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | Rivet Example App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /app/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ironclad/rivet-example/70b33f802b550fad6cc3e7b9095723403af9e266/app/public/logo192.png -------------------------------------------------------------------------------- /app/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ironclad/rivet-example/70b33f802b550fad6cc3e7b9095723403af9e266/app/public/logo512.png -------------------------------------------------------------------------------- /app/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "Rivet Example", 3 | "name": "Rivet Example App", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /app/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /app/src/App.tsx: -------------------------------------------------------------------------------- 1 | import ChatMessages from './ChatMessages'; 2 | 3 | function App() { 4 | return ( 5 |
6 | 7 |
8 | ); 9 | } 10 | 11 | export default App; 12 | -------------------------------------------------------------------------------- /app/src/ChatMessages.tsx: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | import React, { useState } from "react"; 3 | import { FaPaperPlane, FaUserCircle, FaRobot, FaTimes } from 'react-icons/fa'; 4 | 5 | interface Message { 6 | message: string; 7 | type: 'user' | 'assistant'; 8 | } 9 | 10 | const initialMessages: Message[] = [ 11 | { message: "Hi there! How can I help you today?", type: 'assistant' }, 12 | ]; 13 | 14 | const Chatbot: React.FC = () => { 15 | const [messages, setMessages] = useState(initialMessages); 16 | const [inputValue, setInputValue] = useState(""); 17 | const [showHeader, setShowHeader] = useState(true); 18 | 19 | const handleCloseHeader = () => { 20 | setShowHeader(false); 21 | }; 22 | 23 | const handleMessageSubmit = (e: React.FormEvent) => { 24 | e.preventDefault(); 25 | const nextMessages = [...messages, { message: inputValue, type: 'user' as const }]; 26 | setMessages(nextMessages); 27 | setInputValue(""); 28 | 29 | (async () => { 30 | const response = await axios.post('http://localhost:3000/api/rivet-example', { input: nextMessages }); 31 | setMessages([...nextMessages, { message: response.data.output, type: 'assistant' as const }]); 32 | })(); 33 | }; 34 | 35 | return ( 36 |
37 | {showHeader && ( 38 |
39 |

Rivet Debugger URL:

ws://localhost:3000/api/rivet/debugger

40 | 41 |
42 | )} 43 |
44 | {messages.map((message, index) => ( 45 |
46 |
47 | {message.type === 'user' ? : } 48 |
49 |
50 | {message.message} 51 |
52 |
53 | ))} 54 |
55 |
56 |
57 | 58 |
59 | setInputValue(e.target.value)} style={{ flex: 1, padding: '8px 12px', borderRadius: '16px', marginRight: '16px' }} /> 60 | 61 |
62 |
63 | ); 64 | }; 65 | 66 | export default Chatbot; 67 | -------------------------------------------------------------------------------- /app/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /app/src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot( 8 | document.getElementById('root') as HTMLElement 9 | ); 10 | root.render( 11 | 12 | 13 | 14 | ); 15 | 16 | // If you want to start measuring performance in your app, pass a function 17 | // to log results (for example: reportWebVitals(console.log)) 18 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 19 | reportWebVitals(); 20 | -------------------------------------------------------------------------------- /app/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /app/src/reportWebVitals.ts: -------------------------------------------------------------------------------- 1 | import { ReportHandler } from 'web-vitals'; 2 | 3 | const reportWebVitals = (onPerfEntry?: ReportHandler) => { 4 | if (onPerfEntry && onPerfEntry instanceof Function) { 5 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 6 | getCLS(onPerfEntry); 7 | getFID(onPerfEntry); 8 | getFCP(onPerfEntry); 9 | getLCP(onPerfEntry); 10 | getTTFB(onPerfEntry); 11 | }); 12 | } 13 | }; 14 | 15 | export default reportWebVitals; 16 | -------------------------------------------------------------------------------- /app/src/setupTests.ts: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /app/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "noFallthroughCasesInSwitch": true, 16 | "module": "esnext", 17 | "moduleResolution": "node", 18 | "resolveJsonModule": true, 19 | "isolatedModules": true, 20 | "noEmit": true, 21 | "jsx": "react-jsx" 22 | }, 23 | "include": [ 24 | "src" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /chat.rivet-project: -------------------------------------------------------------------------------- 1 | version: 4 2 | data: 3 | attachedData: 4 | trivet: 5 | testSuites: [] 6 | version: 1 7 | graphs: 8 | 5BI0Pfuu2naOUKqGUO-yZ: 9 | metadata: 10 | description: "" 11 | id: 5BI0Pfuu2naOUKqGUO-yZ 12 | name: "* Initial Chat" 13 | nodes: 14 | '[-W6COoQKUcQ9w9B3jI03T]:subGraph "Subgraph"': 15 | data: 16 | graphId: r97vYKQCVceae5VCCKK4J 17 | useAsGraphPartialOutput: false 18 | useErrorOutput: false 19 | outgoingConnections: 20 | - output->"Coalesce" TiKgjE9lRKo7jxKHSG5Ts/input1 21 | visualData: 2200.4371718810057/1284.2891462371756/300/37 22 | '[-v8vfkQzqCrE6X_BYGRI7]:graphInput "Graph Input"': 23 | data: 24 | dataType: object[] 25 | id: messages 26 | useDefaultValueInput: true 27 | outgoingConnections: 28 | - data->"Assemble Prompt" bT5C1n80OJUvt0HWT3s2N/message1 29 | - data->"Messages" vo5dYm9w-N3DqWKg6GBB9/input1 30 | visualData: 450.33584921685747/584.509433433768/300/42 31 | '[3fKJMBoMrWywddgvRuXzX]:if "If"': 32 | outgoingConnections: 33 | - output->"Subgraph" KTDjmUolLaU2mGXtP3KX1/input 34 | - output->"Subgraph" KTDjmUolLaU2mGXtP3KX1/messages 35 | visualData: 2047.0150253100212/1654.1185972534486/125/35 36 | '[59C-lzmaNDStH3FGrlK-q]:extractRegex "Extract Regex"': 37 | data: 38 | errorOnFailed: false 39 | regex: "APPROPRIATE_SKILL: ([a-zA-Z0-9_]+)" 40 | useRegexInput: false 41 | outgoingConnections: 42 | - output1->"Match" C9hewJjzGnDPz3ekCRq6T/input 43 | visualData: 1312.5221695699574/1270.3071938320213/250/31 44 | '[C9hewJjzGnDPz3ekCRq6T]:match "Match"': 45 | data: 46 | caseCount: 3 47 | cases: 48 | - SIMPLE_REPLY 49 | - CALCULATOR 50 | - PLAY_GAME_OF_24 51 | outgoingConnections: 52 | - case1->"If" xOaYW0KIyS32L3yZCXgyz/if 53 | - case2->"If" 3fKJMBoMrWywddgvRuXzX/if 54 | - case3->"If" srBo0tH6dPQvoSOJZdlZN/if 55 | visualData: 1612.8149997157275/1256.3058258619021/250/33 56 | '[KTDjmUolLaU2mGXtP3KX1]:subGraph "Subgraph"': 57 | data: 58 | graphId: cNR0gNaGhFnKosSc7NxRg 59 | useAsGraphPartialOutput: false 60 | useErrorOutput: false 61 | outgoingConnections: 62 | - output->"Coalesce" TiKgjE9lRKo7jxKHSG5Ts/input2 63 | visualData: 2206.342358846274/1637.9389452966398/300/36 64 | '[TiKgjE9lRKo7jxKHSG5Ts]:coalesce "Coalesce"': 65 | outgoingConnections: 66 | - output->"Graph Output" a3laSCibbrhJ4FVNCl3pD/value 67 | visualData: 2635.0363832303638/1241.413797541481/150/38 68 | '[a3laSCibbrhJ4FVNCl3pD]:graphOutput "Graph Output"': 69 | data: 70 | dataType: string 71 | id: output 72 | visualData: 2865.329549900008/1217.757308376549/300/39 73 | '[bDQ8wPuk4SzLclg0UerD0]:prompt "Prompt"': 74 | data: 75 | enableFunctionCall: false 76 | promptText: How can I help? 77 | type: assistant 78 | useTypeInput: false 79 | outgoingConnections: 80 | - output->"Assemble Prompt" fykcLhOkm_HAYnw-5KIH3/message1 81 | visualData: -171.9018868674652/521.7207540964243/250/44 82 | '[bT5C1n80OJUvt0HWT3s2N]:assemblePrompt "Assemble Prompt"': 83 | outgoingConnections: 84 | - prompt->"Chat" rTcNfKE6RPuc1xmHw1XAC/prompt 85 | visualData: 1094.2224529334699/584.8127801065449/250/42 86 | '[fykcLhOkm_HAYnw-5KIH3]:assemblePrompt "Assemble Prompt"': 87 | outgoingConnections: 88 | - prompt->"Graph Input" -v8vfkQzqCrE6X_BYGRI7/default 89 | visualData: 148.0981131325348/623.7207540964243/250/44 90 | '[gDu9dzQVvUPtY2sfkkaTh]:prompt "Prompt"': 91 | data: 92 | enableFunctionCall: false 93 | promptText: How are you doing? 94 | type: user 95 | useTypeInput: false 96 | outgoingConnections: 97 | - output->"Assemble Prompt" fykcLhOkm_HAYnw-5KIH3/message2 98 | visualData: -172.9018868674652/693.7207540964243/250/44 99 | '[jWA87wcF_GlS2np55xD5z]:text "Text"': 100 | data: 101 | text: You are a helpful assistant. 102 | outgoingConnections: 103 | - output->"Chat" rTcNfKE6RPuc1xmHw1XAC/systemPrompt 104 | visualData: 1044.8468567815373/377.294598163788/300/42 105 | '[m-mbyszIqKzxgtKg1NrZ6]:prompt "Prompt"': 106 | data: 107 | enableFunctionCall: false 108 | promptText: >- 109 | Your task is to choose the most appropriate skill to execute to 110 | respond to the user. The skills you can choose from are: 111 | 112 | * CALCULATOR - do an arithmetic computation. This is appropriate if the user gives you an arithmetic formula (eg. "5 * 5 + (2 - 1)"). 113 | 114 | * PLAY_GAME_OF_24 - solve a "game of 24" puzzle. This is appropriate if the user gives you several integers. 115 | 116 | * SIMPLE_REPLY - reply to the user, based on the conversation. Only select this skill if no other skills are appropriate. 117 | 118 | 119 | FIRST, explain your reasoning. 120 | 121 | THEN, respond in the following format: 122 | 123 | 124 | APPROPRIATE_SKILL: [SKILL] 125 | type: user 126 | useTypeInput: false 127 | outgoingConnections: 128 | - output->"Assemble Prompt" bT5C1n80OJUvt0HWT3s2N/message2 129 | visualData: 800.9994867016692/733.8099103553141/250/42 130 | '[p9aXKbDTZCpwjxqZQkE5o]:subGraph "Subgraph"': 131 | data: 132 | graphId: img3RO-RZ3wj9vprc0g7x 133 | useAsGraphPartialOutput: false 134 | useErrorOutput: false 135 | outgoingConnections: 136 | - output->"Coalesce" TiKgjE9lRKo7jxKHSG5Ts/input3 137 | visualData: 2213.211121093388/1895.8418358669255/300/47 138 | '[rTcNfKE6RPuc1xmHw1XAC]:chat "Chat"': 139 | data: 140 | cache: false 141 | enableFunctionUse: false 142 | frequencyPenalty: 0 143 | maxTokens: 1024 144 | model: gpt-3.5-turbo 145 | presencePenalty: 0 146 | stop: "" 147 | temperature: 0 148 | top_p: 1 149 | useAsGraphPartialOutput: true 150 | useFrequencyPenaltyInput: false 151 | useMaxTokensInput: false 152 | useModelInput: false 153 | usePresencePenaltyInput: false 154 | useStop: false 155 | useStopInput: false 156 | useTemperatureInput: false 157 | useTopP: false 158 | useTopPInput: false 159 | useUseTopPInput: false 160 | useUserInput: false 161 | outgoingConnections: 162 | - response->"Extract Regex" 59C-lzmaNDStH3FGrlK-q/input 163 | visualData: 1434.0736493483123/577.8084754796987/200/42 164 | '[srBo0tH6dPQvoSOJZdlZN]:if "If"': 165 | outgoingConnections: 166 | - output->"Subgraph" p9aXKbDTZCpwjxqZQkE5o/input 167 | visualData: 2036.2549616500767/1920.3144962154684/125/45 168 | '[vo5dYm9w-N3DqWKg6GBB9]:passthrough "Messages"': 169 | outgoingConnections: 170 | - output1->"If" 3fKJMBoMrWywddgvRuXzX/value 171 | - output1->"If" srBo0tH6dPQvoSOJZdlZN/value 172 | - output1->"If" xOaYW0KIyS32L3yZCXgyz/value 173 | visualData: 1617.9008842151597/1671.8338365777877/175/32 174 | '[xOaYW0KIyS32L3yZCXgyz]:if "If"': 175 | outgoingConnections: 176 | - output->"Subgraph" -W6COoQKUcQ9w9B3jI03T/messages 177 | visualData: 2034.8572003388883/1304.5830896568502/125/34 178 | cNR0gNaGhFnKosSc7NxRg: 179 | metadata: 180 | description: "" 181 | id: cNR0gNaGhFnKosSc7NxRg 182 | name: Calculator 183 | nodes: 184 | '[7tExf5-mnSOS-K83RGgTp]:extractRegex "Extract Regex"': 185 | data: 186 | errorOnFailed: false 187 | regex: "COMPUTATION: (.*)" 188 | useRegexInput: false 189 | outgoingConnections: 190 | - output1->"External Call" UXAt4NG3Kg1zBVvU1RBZi/arguments 191 | visualData: 1716.0345092383493/540.2575387223877/250/13 192 | '[8Ij56L9chrM6V_OCwWsA4]:text "Text"': 193 | data: 194 | text: You are a helpful calculator. 195 | outgoingConnections: 196 | - output->"Chat" G7DYuXsaD9G6pT1q0S1bS/systemPrompt 197 | visualData: 1292.670334044323/134.05720962899662/300/12 198 | '[9XG5P2-Pk7aL-htut6RY5]:graphOutput "Graph Output"': 199 | data: 200 | dataType: string 201 | id: output 202 | visualData: 2239.088255456765/523.0296890984553/300/15 203 | '[CUa1IGD0x5BX8pmjwtBHS]:assemblePrompt "Assemble Prompt"': 204 | outgoingConnections: 205 | - prompt->"Chat" G7DYuXsaD9G6pT1q0S1bS/prompt 206 | visualData: 1353.067901234568/330.8240740740741/250/4 207 | '[G7DYuXsaD9G6pT1q0S1bS]:chat "Chat"': 208 | data: 209 | cache: false 210 | enableFunctionUse: false 211 | frequencyPenalty: 0 212 | maxTokens: 1024 213 | model: gpt-3.5-turbo 214 | presencePenalty: 0 215 | stop: "" 216 | temperature: 0.5 217 | top_p: 1 218 | useAsGraphPartialOutput: true 219 | useFrequencyPenaltyInput: false 220 | useMaxTokensInput: false 221 | useModelInput: false 222 | usePresencePenaltyInput: false 223 | useStop: false 224 | useStopInput: false 225 | useTemperatureInput: false 226 | useTopP: false 227 | useTopPInput: false 228 | useUseTopPInput: false 229 | useUserInput: false 230 | outgoingConnections: 231 | - response->"Extract Regex" 7tExf5-mnSOS-K83RGgTp/input 232 | visualData: 1726.253086419753/268.4259259259259/200/3 233 | '[GGQ9vgjldv_HQSMoPrWEk]:prompt "Prompt"': 234 | data: 235 | enableFunctionCall: false 236 | promptText: >- 237 | What is the arithmetic formula I am asking you to compute? Answer 238 | in the following format: 239 | 240 | 241 | COMPUTATION: [formula, eg. "5 * (2 - 1)"] 242 | type: user 243 | useTypeInput: false 244 | outgoingConnections: 245 | - output->"Assemble Prompt" CUa1IGD0x5BX8pmjwtBHS/message2 246 | visualData: 1039.0308641975307/446.65740740740745/250/5 247 | '[UXAt4NG3Kg1zBVvU1RBZi]:externalCall "External Call"': 248 | data: 249 | functionName: calculate 250 | useErrorOutput: false 251 | useFunctionNameInput: false 252 | outgoingConnections: 253 | - result->"Graph Output" 9XG5P2-Pk7aL-htut6RY5/value 254 | visualData: 2035.1029381506592/519.9697167603723/150/14 255 | '[bsYlfUDGifFVdX2YrJCpw]:graphInput "Graph Input"': 256 | data: 257 | dataType: chat-message[] 258 | id: messages 259 | useDefaultValueInput: false 260 | outgoingConnections: 261 | - data->"Assemble Prompt" CUa1IGD0x5BX8pmjwtBHS/message1 262 | visualData: 1006.895061728395/280.81481481481484/300/6 263 | img3RO-RZ3wj9vprc0g7x: 264 | metadata: 265 | description: "" 266 | id: img3RO-RZ3wj9vprc0g7x 267 | name: Play 24 268 | nodes: 269 | '[DDzJnQnNkq5S2CXgrqeTO]:graphInput "Graph Input"': 270 | data: 271 | dataType: chat-message[] 272 | id: input 273 | useDefaultValueInput: true 274 | outgoingConnections: 275 | - data->"Assemble Prompt" RK-JSMbiBDXHieuODZ1UQ/message1 276 | visualData: 1136.3524398032898/315.6503388790682/300/12 277 | '[IxNaO-Ge-QFsjlPWmL0X8]:graphOutput "Graph Output"': 278 | data: 279 | dataType: string 280 | id: output 281 | visualData: 2201.499861001212/982.629277966354/300/21 282 | '[JSxv1qjjpQst-gerSvo1P]:prompt "Prompt"': 283 | data: 284 | enableFunctionCall: false 285 | promptText: 5 5 1 6 286 | type: user 287 | useTypeInput: false 288 | outgoingConnections: 289 | - output->"Assemble Prompt" tMQa3krgP6sGqE5saPRtY/message1 290 | visualData: -93.82558174749487/561.3994494207175/250/7 291 | '[RK-JSMbiBDXHieuODZ1UQ]:assemblePrompt "Assemble Prompt"': 292 | outgoingConnections: 293 | - prompt->"Chat" XcI4a5ehj_O13pOmwXmxQ/prompt 294 | visualData: 1505.4893171681276/383.95171130779426/250/10 295 | '[XcI4a5ehj_O13pOmwXmxQ]:chat "Chat"': 296 | data: 297 | cache: false 298 | enableFunctionUse: false 299 | frequencyPenalty: 0 300 | maxTokens: 1024 301 | model: gpt-3.5-turbo 302 | presencePenalty: 0 303 | stop: "" 304 | temperature: 0 305 | top_p: 1 306 | useAsGraphPartialOutput: true 307 | useFrequencyPenaltyInput: false 308 | useMaxTokensInput: false 309 | useModelInput: false 310 | usePresencePenaltyInput: false 311 | useStop: false 312 | useStopInput: false 313 | useTemperatureInput: false 314 | useTopP: false 315 | useTopPInput: false 316 | useUseTopPInput: false 317 | useUserInput: false 318 | outgoingConnections: 319 | - response->"Text" rFNDdJB9Wd3KFdfVppqOi/numbers 320 | visualData: 1795.5100994530835/310.79140519008365/200/14 321 | '[hMIBnjUZGOOhd7BjO8Dmg]:prompt "Prompt"': 322 | data: 323 | enableFunctionCall: false 324 | promptText: >- 325 | I should have provided you some numbers in my previous message. 326 | 327 | 328 | Output these numbers, separated by commas. For example, "5, 5, 3, 4." 329 | type: user 330 | useTypeInput: false 331 | outgoingConnections: 332 | - output->"Assemble Prompt" RK-JSMbiBDXHieuODZ1UQ/message2 333 | visualData: 1179.187250068812/506.137919370722/250/11 334 | '[k-5Lxnn3SQtHCa-2Qc8FA]:chat "Chat"': 335 | data: 336 | cache: false 337 | enableFunctionUse: false 338 | frequencyPenalty: 0 339 | maxTokens: 1024 340 | model: gpt-3.5-turbo 341 | presencePenalty: 0 342 | stop: "" 343 | temperature: 0 344 | top_p: 1 345 | useAsGraphPartialOutput: true 346 | useFrequencyPenaltyInput: false 347 | useMaxTokensInput: false 348 | useModelInput: false 349 | usePresencePenaltyInput: false 350 | useStop: false 351 | useStopInput: false 352 | useTemperatureInput: false 353 | useTopP: false 354 | useTopPInput: false 355 | useUseTopPInput: false 356 | useUserInput: false 357 | outgoingConnections: 358 | - response->"Graph Output" IxNaO-Ge-QFsjlPWmL0X8/value 359 | visualData: 1940.7606821585725/980.7766285941701/200/20 360 | '[rFNDdJB9Wd3KFdfVppqOi]:text "Text"': 361 | data: 362 | text: > 363 | Here are some numbers: 364 | 365 | {{numbers}} 366 | 367 | 368 | Your task is to make the number 24 using all of these numbers. You can add, subtract, multiply, and divide. Use all the numbers provided exactly once. You can use them in any order. For example, if I gave you "5, 5, 3, 4" a valid answer would be "5 * 5 - (4 - 3)." 369 | 370 | 371 | NOW, output the answer in the format below: 372 | 373 | ANSWER: 5 * 5 - (4 - 3) 374 | outgoingConnections: 375 | - output->"Chat" k-5Lxnn3SQtHCa-2Qc8FA/prompt 376 | visualData: 1590.9261217085611/942.0781152700539/300/17 377 | '[tMQa3krgP6sGqE5saPRtY]:assemblePrompt "Assemble Prompt"': 378 | outgoingConnections: 379 | - prompt->"Graph Input" DDzJnQnNkq5S2CXgrqeTO/default 380 | visualData: 223.54273088295088/599.3456607134882/250/null 381 | r97vYKQCVceae5VCCKK4J: 382 | metadata: 383 | description: "" 384 | id: r97vYKQCVceae5VCCKK4J 385 | name: Simple Reply 386 | nodes: 387 | '[2WgFF9l52waW8JTlmtItb]:text "Text"': 388 | data: 389 | text: >- 390 | You are a helpful assistant. 391 | 392 | 393 | You have access to the following skills: 394 | 395 | - Calculator. If the user provides you with an arithmetic formula (eg. "5 * (2 - 1)"), you can calculate the result. 396 | 397 | - Play a game of 24. If the user provides you with a few integers, you can try to combine them with simple arithmetic operations to get to a value of 24. 398 | outgoingConnections: 399 | - output->"Chat" g1OFlelzeONyJvWgLxmiS/systemPrompt 400 | visualData: 732/104/300/null 401 | '[6Gr81m6XMKM52nSAG-2b5]:graphOutput "Graph Output"': 402 | data: 403 | dataType: string 404 | id: output 405 | visualData: 1389.6530238057808/170.04259066944488/300/4 406 | '[g1OFlelzeONyJvWgLxmiS]:chat "Chat"': 407 | data: 408 | cache: false 409 | enableFunctionUse: false 410 | frequencyPenalty: 0 411 | maxTokens: 1024 412 | model: gpt-3.5-turbo 413 | presencePenalty: 0 414 | stop: "" 415 | temperature: 0.5 416 | top_p: 1 417 | useAsGraphPartialOutput: true 418 | useFrequencyPenaltyInput: false 419 | useMaxTokensInput: false 420 | useModelInput: false 421 | usePresencePenaltyInput: false 422 | useStop: false 423 | useStopInput: false 424 | useTemperatureInput: false 425 | useTopP: false 426 | useTopPInput: false 427 | useUseTopPInput: false 428 | useUserInput: false 429 | outgoingConnections: 430 | - response->"Graph Output" 6Gr81m6XMKM52nSAG-2b5/value 431 | visualData: 1104.7082155296682/132/200/3 432 | '[yjH76st57RvQxmseZ-m_u]:graphInput "Graph Input"': 433 | data: 434 | dataType: chat-message[] 435 | id: messages 436 | useDefaultValueInput: false 437 | outgoingConnections: 438 | - data->"Chat" g1OFlelzeONyJvWgLxmiS/prompt 439 | visualData: 735.613558555666/346.6025202108885/300/5 440 | metadata: 441 | description: "" 442 | id: QiMtlIf2TmgkjfxPGu1Cd 443 | title: Untitled Project 444 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rivet-example", 3 | "version": "0.1.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "rivet-example", 9 | "version": "0.1.0", 10 | "hasInstallScript": true, 11 | "devDependencies": { 12 | "concurrently": "^8.2.0" 13 | } 14 | }, 15 | "node_modules/@babel/runtime": { 16 | "version": "7.22.10", 17 | "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.22.10.tgz", 18 | "integrity": "sha512-21t/fkKLMZI4pqP2wlmsQAWnYW1PDyKyyUV4vCi+B25ydmdaYTKXPwCj0BzSUnZf4seIiYvSA3jcZ3gdsMFkLQ==", 19 | "dev": true, 20 | "dependencies": { 21 | "regenerator-runtime": "^0.14.0" 22 | }, 23 | "engines": { 24 | "node": ">=6.9.0" 25 | } 26 | }, 27 | "node_modules/ansi-regex": { 28 | "version": "5.0.1", 29 | "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", 30 | "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", 31 | "dev": true, 32 | "engines": { 33 | "node": ">=8" 34 | } 35 | }, 36 | "node_modules/ansi-styles": { 37 | "version": "4.3.0", 38 | "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", 39 | "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", 40 | "dev": true, 41 | "dependencies": { 42 | "color-convert": "^2.0.1" 43 | }, 44 | "engines": { 45 | "node": ">=8" 46 | }, 47 | "funding": { 48 | "url": "https://github.com/chalk/ansi-styles?sponsor=1" 49 | } 50 | }, 51 | "node_modules/chalk": { 52 | "version": "4.1.2", 53 | "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", 54 | "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", 55 | "dev": true, 56 | "dependencies": { 57 | "ansi-styles": "^4.1.0", 58 | "supports-color": "^7.1.0" 59 | }, 60 | "engines": { 61 | "node": ">=10" 62 | }, 63 | "funding": { 64 | "url": "https://github.com/chalk/chalk?sponsor=1" 65 | } 66 | }, 67 | "node_modules/chalk/node_modules/supports-color": { 68 | "version": "7.2.0", 69 | "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", 70 | "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", 71 | "dev": true, 72 | "dependencies": { 73 | "has-flag": "^4.0.0" 74 | }, 75 | "engines": { 76 | "node": ">=8" 77 | } 78 | }, 79 | "node_modules/cliui": { 80 | "version": "8.0.1", 81 | "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", 82 | "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", 83 | "dev": true, 84 | "dependencies": { 85 | "string-width": "^4.2.0", 86 | "strip-ansi": "^6.0.1", 87 | "wrap-ansi": "^7.0.0" 88 | }, 89 | "engines": { 90 | "node": ">=12" 91 | } 92 | }, 93 | "node_modules/color-convert": { 94 | "version": "2.0.1", 95 | "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", 96 | "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", 97 | "dev": true, 98 | "dependencies": { 99 | "color-name": "~1.1.4" 100 | }, 101 | "engines": { 102 | "node": ">=7.0.0" 103 | } 104 | }, 105 | "node_modules/color-name": { 106 | "version": "1.1.4", 107 | "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", 108 | "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", 109 | "dev": true 110 | }, 111 | "node_modules/concurrently": { 112 | "version": "8.2.0", 113 | "resolved": "https://registry.npmjs.org/concurrently/-/concurrently-8.2.0.tgz", 114 | "integrity": "sha512-nnLMxO2LU492mTUj9qX/az/lESonSZu81UznYDoXtz1IQf996ixVqPAgHXwvHiHCAef/7S8HIK+fTFK7Ifk8YA==", 115 | "dev": true, 116 | "dependencies": { 117 | "chalk": "^4.1.2", 118 | "date-fns": "^2.30.0", 119 | "lodash": "^4.17.21", 120 | "rxjs": "^7.8.1", 121 | "shell-quote": "^1.8.1", 122 | "spawn-command": "0.0.2", 123 | "supports-color": "^8.1.1", 124 | "tree-kill": "^1.2.2", 125 | "yargs": "^17.7.2" 126 | }, 127 | "bin": { 128 | "conc": "dist/bin/concurrently.js", 129 | "concurrently": "dist/bin/concurrently.js" 130 | }, 131 | "engines": { 132 | "node": "^14.13.0 || >=16.0.0" 133 | }, 134 | "funding": { 135 | "url": "https://github.com/open-cli-tools/concurrently?sponsor=1" 136 | } 137 | }, 138 | "node_modules/date-fns": { 139 | "version": "2.30.0", 140 | "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.30.0.tgz", 141 | "integrity": "sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==", 142 | "dev": true, 143 | "dependencies": { 144 | "@babel/runtime": "^7.21.0" 145 | }, 146 | "engines": { 147 | "node": ">=0.11" 148 | }, 149 | "funding": { 150 | "type": "opencollective", 151 | "url": "https://opencollective.com/date-fns" 152 | } 153 | }, 154 | "node_modules/emoji-regex": { 155 | "version": "8.0.0", 156 | "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", 157 | "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", 158 | "dev": true 159 | }, 160 | "node_modules/escalade": { 161 | "version": "3.1.1", 162 | "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", 163 | "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==", 164 | "dev": true, 165 | "engines": { 166 | "node": ">=6" 167 | } 168 | }, 169 | "node_modules/get-caller-file": { 170 | "version": "2.0.5", 171 | "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", 172 | "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", 173 | "dev": true, 174 | "engines": { 175 | "node": "6.* || 8.* || >= 10.*" 176 | } 177 | }, 178 | "node_modules/has-flag": { 179 | "version": "4.0.0", 180 | "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", 181 | "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", 182 | "dev": true, 183 | "engines": { 184 | "node": ">=8" 185 | } 186 | }, 187 | "node_modules/is-fullwidth-code-point": { 188 | "version": "3.0.0", 189 | "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", 190 | "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", 191 | "dev": true, 192 | "engines": { 193 | "node": ">=8" 194 | } 195 | }, 196 | "node_modules/lodash": { 197 | "version": "4.17.21", 198 | "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", 199 | "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", 200 | "dev": true 201 | }, 202 | "node_modules/regenerator-runtime": { 203 | "version": "0.14.0", 204 | "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.0.tgz", 205 | "integrity": "sha512-srw17NI0TUWHuGa5CFGGmhfNIeja30WMBfbslPNhf6JrqQlLN5gcrvig1oqPxiVaXb0oW0XRKtH6Nngs5lKCIA==", 206 | "dev": true 207 | }, 208 | "node_modules/require-directory": { 209 | "version": "2.1.1", 210 | "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", 211 | "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", 212 | "dev": true, 213 | "engines": { 214 | "node": ">=0.10.0" 215 | } 216 | }, 217 | "node_modules/rxjs": { 218 | "version": "7.8.1", 219 | "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.1.tgz", 220 | "integrity": "sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==", 221 | "dev": true, 222 | "dependencies": { 223 | "tslib": "^2.1.0" 224 | } 225 | }, 226 | "node_modules/shell-quote": { 227 | "version": "1.8.1", 228 | "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.1.tgz", 229 | "integrity": "sha512-6j1W9l1iAs/4xYBI1SYOVZyFcCis9b4KCLQ8fgAGG07QvzaRLVVRQvAy85yNmmZSjYjg4MWh4gNvlPujU/5LpA==", 230 | "dev": true, 231 | "funding": { 232 | "url": "https://github.com/sponsors/ljharb" 233 | } 234 | }, 235 | "node_modules/spawn-command": { 236 | "version": "0.0.2", 237 | "resolved": "https://registry.npmjs.org/spawn-command/-/spawn-command-0.0.2.tgz", 238 | "integrity": "sha512-zC8zGoGkmc8J9ndvml8Xksr1Amk9qBujgbF0JAIWO7kXr43w0h/0GJNM/Vustixu+YE8N/MTrQ7N31FvHUACxQ==", 239 | "dev": true 240 | }, 241 | "node_modules/string-width": { 242 | "version": "4.2.3", 243 | "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", 244 | "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", 245 | "dev": true, 246 | "dependencies": { 247 | "emoji-regex": "^8.0.0", 248 | "is-fullwidth-code-point": "^3.0.0", 249 | "strip-ansi": "^6.0.1" 250 | }, 251 | "engines": { 252 | "node": ">=8" 253 | } 254 | }, 255 | "node_modules/strip-ansi": { 256 | "version": "6.0.1", 257 | "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", 258 | "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", 259 | "dev": true, 260 | "dependencies": { 261 | "ansi-regex": "^5.0.1" 262 | }, 263 | "engines": { 264 | "node": ">=8" 265 | } 266 | }, 267 | "node_modules/supports-color": { 268 | "version": "8.1.1", 269 | "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", 270 | "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", 271 | "dev": true, 272 | "dependencies": { 273 | "has-flag": "^4.0.0" 274 | }, 275 | "engines": { 276 | "node": ">=10" 277 | }, 278 | "funding": { 279 | "url": "https://github.com/chalk/supports-color?sponsor=1" 280 | } 281 | }, 282 | "node_modules/tree-kill": { 283 | "version": "1.2.2", 284 | "resolved": "https://registry.npmjs.org/tree-kill/-/tree-kill-1.2.2.tgz", 285 | "integrity": "sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==", 286 | "dev": true, 287 | "bin": { 288 | "tree-kill": "cli.js" 289 | } 290 | }, 291 | "node_modules/tslib": { 292 | "version": "2.6.1", 293 | "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.1.tgz", 294 | "integrity": "sha512-t0hLfiEKfMUoqhG+U1oid7Pva4bbDPHYfJNiB7BiIjRkj1pyC++4N3huJfqY6aRH6VTB0rvtzQwjM4K6qpfOig==", 295 | "dev": true 296 | }, 297 | "node_modules/wrap-ansi": { 298 | "version": "7.0.0", 299 | "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", 300 | "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", 301 | "dev": true, 302 | "dependencies": { 303 | "ansi-styles": "^4.0.0", 304 | "string-width": "^4.1.0", 305 | "strip-ansi": "^6.0.0" 306 | }, 307 | "engines": { 308 | "node": ">=10" 309 | }, 310 | "funding": { 311 | "url": "https://github.com/chalk/wrap-ansi?sponsor=1" 312 | } 313 | }, 314 | "node_modules/y18n": { 315 | "version": "5.0.8", 316 | "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", 317 | "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", 318 | "dev": true, 319 | "engines": { 320 | "node": ">=10" 321 | } 322 | }, 323 | "node_modules/yargs": { 324 | "version": "17.7.2", 325 | "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", 326 | "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", 327 | "dev": true, 328 | "dependencies": { 329 | "cliui": "^8.0.1", 330 | "escalade": "^3.1.1", 331 | "get-caller-file": "^2.0.5", 332 | "require-directory": "^2.1.1", 333 | "string-width": "^4.2.3", 334 | "y18n": "^5.0.5", 335 | "yargs-parser": "^21.1.1" 336 | }, 337 | "engines": { 338 | "node": ">=12" 339 | } 340 | }, 341 | "node_modules/yargs-parser": { 342 | "version": "21.1.1", 343 | "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", 344 | "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", 345 | "dev": true, 346 | "engines": { 347 | "node": ">=12" 348 | } 349 | } 350 | } 351 | } 352 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rivet-example", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "postinstall": "cd server && npm install && cd ../app && npm install", 7 | "start-server": "cd server && npm run dev", 8 | "start-client": "cd client && npm run start", 9 | "start": "concurrently --kill-others \"cd server && npm run dev\" \"cd app && npm run start\"" 10 | }, 11 | "devDependencies": { 12 | "concurrently": "^8.2.0" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /server/.eslintignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ironclad/rivet-example/70b33f802b550fad6cc3e7b9095723403af9e266/server/.eslintignore -------------------------------------------------------------------------------- /server/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "@typescript-eslint/parser", 3 | "plugins": [ 4 | "@typescript-eslint" 5 | ], 6 | "extends": [ 7 | "eslint:recommended", 8 | "plugin:@typescript-eslint/recommended", 9 | "plugin:@typescript-eslint/recommended-requiring-type-checking", 10 | "plugin:node/recommended" 11 | ], 12 | "parserOptions": { 13 | "project": "./tsconfig.json" 14 | }, 15 | "rules": { 16 | "@typescript-eslint/explicit-member-accessibility": "warn", 17 | "@typescript-eslint/no-misused-promises": 0, 18 | "@typescript-eslint/no-floating-promises": 0, 19 | "max-len": [ 20 | "warn", 21 | { 22 | "code": 80 23 | } 24 | ], 25 | "comma-dangle": ["warn", "always-multiline"], 26 | "no-console": 1, 27 | "no-extra-boolean-cast": 0, 28 | "semi": 1, 29 | "indent": ["warn", 2], 30 | "quotes": ["warn", "single"], 31 | "node/no-process-env": 1, 32 | "node/no-unsupported-features/es-syntax": [ 33 | "error", 34 | { "ignores" : ["modules"] } 35 | ], 36 | "node/no-missing-import": 0, 37 | "node/no-unpublished-import": 0 38 | }, 39 | "settings": { 40 | "node": { 41 | "tryExtensions": [".js", ".json", ".node", ".ts"] 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /server/.gitignore: -------------------------------------------------------------------------------- 1 | **/node_modules 2 | dist/ 3 | **/**/*.log 4 | -------------------------------------------------------------------------------- /server/README.md: -------------------------------------------------------------------------------- 1 | ## About 2 | 3 | This project was created with [express-generator-typescript](https://github.com/seanpmaxwell/express-generator-typescript). 4 | 5 | 6 | ## Available Scripts 7 | 8 | ### `npm run dev` 9 | 10 | Run the server in development mode. 11 | 12 | ### `npm test` 13 | 14 | Run all unit-tests with hot-reloading. 15 | 16 | ### `npm test -- --testFile="name of test file" (i.e. --testFile=Users).` 17 | 18 | Run a single unit-test. 19 | 20 | ### `npm run test:no-reloading` 21 | 22 | Run all unit-tests without hot-reloading. 23 | 24 | ### `npm run lint` 25 | 26 | Check for linting errors. 27 | 28 | ### `npm run build` 29 | 30 | Build the project for production. 31 | 32 | ### `npm start` 33 | 34 | Run the production build (Must be built first). 35 | 36 | ### `npm start -- --env="name of env file" (default is production).` 37 | 38 | Run production build with a different env file. 39 | 40 | 41 | ## Additional Notes 42 | 43 | - If `npm run dev` gives you issues with bcrypt on MacOS you may need to run: `npm rebuild bcrypt --build-from-source`. 44 | 45 | 46 | - Install rivet-node 47 | - Simple backend with code for running rivet debug server and running rivet graph 48 | - simple frontend 49 | - update one line in setup about authenticating with github (not needed after open source) -------------------------------------------------------------------------------- /server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "express-gen-ts", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "build": "tsc", 6 | "start": "node -r module-alias/register ./dist --env=production", 7 | "dev": "tsx watch ./src/index.ts" 8 | }, 9 | "engines": { 10 | "node": ">=20.9.0" 11 | }, 12 | "type": "module", 13 | "dependencies": { 14 | "@ironclad/rivet-node": "^1.10.0", 15 | "express": "^4.18.2", 16 | "express-async-errors": "^3.1.1", 17 | "module-alias": "^2.2.3", 18 | "morgan": "^1.10.0", 19 | "winston": "^3.11.0", 20 | "ws": "^8.13.0" 21 | }, 22 | "devDependencies": { 23 | "@types/express": "^4.17.17", 24 | "@types/find": "^0.2.1", 25 | "@types/morgan": "^1.9.4", 26 | "@types/node": "^20.4.9", 27 | "@types/ws": "^8.5.9", 28 | "@typescript-eslint/eslint-plugin": "^6.3.0", 29 | "@typescript-eslint/parser": "^6.3.0", 30 | "eslint": "^8.46.0", 31 | "eslint-plugin-node": "^11.1.0", 32 | "tsx": "^3.14.0", 33 | "typescript": "^5.2.2" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /server/src/RivetDebuggerRoutes.ts: -------------------------------------------------------------------------------- 1 | import { Request, Response, Router } from 'express'; 2 | import WebSocket from 'ws'; 3 | 4 | import { GraphId, GraphInputs, GraphProcessor, RivetDebuggerServer, startDebuggerServer } from '@ironclad/rivet-node'; 5 | 6 | export const rivetDebuggerServerState = { 7 | server: null as RivetDebuggerServer | null, 8 | }; 9 | 10 | export function startRivetDebuggerServer( 11 | wss: WebSocket.Server, 12 | options: { 13 | /** Gets the debugger ws client given a processor */ 14 | getClientsForProcessor?: (processor: GraphProcessor, allClients: WebSocket[]) => WebSocket[]; 15 | 16 | /** Gets the processors for a given ws client. */ 17 | getProcessorsForClient?: (client: WebSocket, allProcessors: GraphProcessor[]) => GraphProcessor[]; 18 | 19 | dynamicGraphRun?: (data: { client: WebSocket; graphId: GraphId; inputs?: GraphInputs }) => Promise; 20 | } = {}, 21 | ) { 22 | if (rivetDebuggerServerState.server) { 23 | return; 24 | } 25 | 26 | const { 27 | getClientsForProcessor = (processor, allClients) => allClients, 28 | getProcessorsForClient = (client, allProcessors) => allProcessors, 29 | dynamicGraphRun, 30 | } = options; 31 | 32 | const rivetDebuggerServer = startDebuggerServer({ 33 | server: wss, 34 | 35 | getClientsForProcessor, 36 | getProcessorsForClient, 37 | dynamicGraphRun, 38 | }); 39 | 40 | rivetDebuggerServer.on('error', (err) => { 41 | console.error('Error from rivet debugger', { err }); 42 | }); 43 | 44 | rivetDebuggerServerState.server = rivetDebuggerServer; 45 | 46 | console.info('Started rivet debugger'); 47 | } 48 | 49 | export function rivetDebuggerSocketRoutes( 50 | router: Router, 51 | options: { 52 | path?: string; 53 | onConnected?: (socket: WebSocket.WebSocket, req: Request, wss: WebSocket.Server) => void; 54 | validate?: (req: Request) => Promise; 55 | wss?: WebSocket.Server; 56 | } = {}, 57 | ) { 58 | const { 59 | path = '/rivet/debugger', 60 | onConnected = (socket, req, wsServer) => { 61 | wsServer.emit('connection', socket, req); 62 | 63 | console.info('Rivet debugger connected'); 64 | socket.on('close', () => { 65 | console.info('Rivet debugger disconnected'); 66 | }); 67 | }, 68 | validate = () => { return undefined; }, 69 | wss = new WebSocket.Server({ noServer: true }), 70 | } = options; 71 | 72 | router.get(path, async (req: Request, res: Response) => { 73 | try { 74 | const validationError = await validate?.(req); 75 | 76 | if (validationError) { 77 | res.status(400).send(validationError); 78 | return; 79 | } 80 | 81 | if (req.headers.upgrade !== 'websocket') { 82 | res.status(400).send('Expected a WebSocket connection'); 83 | return; 84 | } 85 | 86 | wss.handleUpgrade(req, req.socket, Buffer.alloc(0), (ws) => { 87 | onConnected(ws, req, wss); 88 | }); 89 | } catch (err) { 90 | console.error('Error while upgrading websocket', { err }); 91 | res.status(500).send('Internal Server Error'); 92 | } 93 | }); 94 | 95 | return { 96 | wss, 97 | }; 98 | } 99 | -------------------------------------------------------------------------------- /server/src/Router.ts: -------------------------------------------------------------------------------- 1 | import { Router } from 'express'; 2 | import { WebSocketServer } from 'ws'; 3 | 4 | import { rivetDebuggerSocketRoutes, startRivetDebuggerServer } from './RivetDebuggerRoutes.js'; 5 | import { runMessageGraph, runRivetGraph } from './services/RivetRunner.js'; 6 | 7 | 8 | // **** Variables **** // 9 | 10 | const apiRouter = Router(); 11 | 12 | apiRouter.post('/rivet-example', async (req, res) => { 13 | const input = req.body.input as { type: 'user' | 'assistant'; message: string }[]; 14 | const response = await runMessageGraph(input); 15 | 16 | res.json({ output: response }); 17 | }); 18 | 19 | // **** Websocket for Rivet debugger **** // 20 | 21 | const debuggerServer = new WebSocketServer({ noServer: true }); 22 | startRivetDebuggerServer(debuggerServer, { 23 | dynamicGraphRun: async ({ inputs, graphId }) => { 24 | await runRivetGraph(graphId, inputs); 25 | }, 26 | }); 27 | rivetDebuggerSocketRoutes(apiRouter, { 28 | path: '/rivet/debugger', 29 | wss: debuggerServer, 30 | }); 31 | 32 | // **** Export default **** // 33 | 34 | export default apiRouter; 35 | -------------------------------------------------------------------------------- /server/src/constants/EnvVars.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Environments variables declared here. 3 | */ 4 | 5 | /* eslint-disable node/no-process-env */ 6 | 7 | 8 | export default { 9 | NodeEnv: (process.env.NODE_ENV ?? 'development'), 10 | Port: (process.env.PORT ?? 3001), 11 | } as const; 12 | -------------------------------------------------------------------------------- /server/src/constants/HttpStatusCodes.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable max-len */ 2 | /** 3 | * This file was copied from here: https://gist.github.com/scokmen/f813c904ef79022e84ab2409574d1b45 4 | */ 5 | 6 | /** 7 | * Hypertext Transfer Protocol (HTTP) response status codes. 8 | * @see {@link https://en.wikipedia.org/wiki/List_of_HTTP_status_codes} 9 | */ 10 | enum HttpStatusCodes { 11 | 12 | /** 13 | * The server has received the request headers and the client should proceed to send the request body 14 | * (in the case of a request for which a body needs to be sent; for example, a POST request). 15 | * Sending a large request body to a server after a request has been rejected for inappropriate headers would be inefficient. 16 | * To have a server check the request's headers, a client must send Expect: 100-continue as a header in its initial request 17 | * and receive a 100 Continue status code in response before sending the body. The response 417 Expectation Failed indicates the request should not be continued. 18 | */ 19 | CONTINUE = 100, 20 | 21 | /** 22 | * The requester has asked the server to switch protocols and the server has agreed to do so. 23 | */ 24 | SWITCHING_PROTOCOLS = 101, 25 | 26 | /** 27 | * A WebDAV request may contain many sub-requests involving file operations, requiring a long time to complete the request. 28 | * This code indicates that the server has received and is processing the request, but no response is available yet. 29 | * This prevents the client from timing out and assuming the request was lost. 30 | */ 31 | PROCESSING = 102, 32 | 33 | /** 34 | * Standard response for successful HTTP requests. 35 | * The actual response will depend on the request method used. 36 | * In a GET request, the response will contain an entity corresponding to the requested resource. 37 | * In a POST request, the response will contain an entity describing or containing the result of the action. 38 | */ 39 | OK = 200, 40 | 41 | /** 42 | * The request has been fulfilled, resulting in the creation of a new resource. 43 | */ 44 | CREATED = 201, 45 | 46 | /** 47 | * The request has been accepted for processing, but the processing has not been completed. 48 | * The request might or might not be eventually acted upon, and may be disallowed when processing occurs. 49 | */ 50 | ACCEPTED = 202, 51 | 52 | /** 53 | * SINCE HTTP/1.1 54 | * The server is a transforming proxy that received a 200 OK from its origin, 55 | * but is returning a modified version of the origin's response. 56 | */ 57 | NON_AUTHORITATIVE_INFORMATION = 203, 58 | 59 | /** 60 | * The server successfully processed the request and is not returning any content. 61 | */ 62 | NO_CONTENT = 204, 63 | 64 | /** 65 | * The server successfully processed the request, but is not returning any content. 66 | * Unlike a 204 response, this response requires that the requester reset the document view. 67 | */ 68 | RESET_CONTENT = 205, 69 | 70 | /** 71 | * The server is delivering only part of the resource (byte serving) due to a range header sent by the client. 72 | * The range header is used by HTTP clients to enable resuming of interrupted downloads, 73 | * or split a download into multiple simultaneous streams. 74 | */ 75 | PARTIAL_CONTENT = 206, 76 | 77 | /** 78 | * The message body that follows is an XML message and can contain a number of separate response codes, 79 | * depending on how many sub-requests were made. 80 | */ 81 | MULTI_STATUS = 207, 82 | 83 | /** 84 | * The members of a DAV binding have already been enumerated in a preceding part of the (multistatus) response, 85 | * and are not being included again. 86 | */ 87 | ALREADY_REPORTED = 208, 88 | 89 | /** 90 | * The server has fulfilled a request for the resource, 91 | * and the response is a representation of the result of one or more instance-manipulations applied to the current instance. 92 | */ 93 | IM_USED = 226, 94 | 95 | /** 96 | * Indicates multiple options for the resource from which the client may choose (via agent-driven content negotiation). 97 | * For example, this code could be used to present multiple video format options, 98 | * to list files with different filename extensions, or to suggest word-sense disambiguation. 99 | */ 100 | MULTIPLE_CHOICES = 300, 101 | 102 | /** 103 | * This and all future requests should be directed to the given URI. 104 | */ 105 | MOVED_PERMANENTLY = 301, 106 | 107 | /** 108 | * This is an example of industry practice contradicting the standard. 109 | * The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect 110 | * (the original describing phrase was "Moved Temporarily"), but popular browsers implemented 302 111 | * with the functionality of a 303 See Other. Therefore, HTTP/1.1 added status codes 303 and 307 112 | * to distinguish between the two behaviours. However, some Web applications and frameworks 113 | * use the 302 status code as if it were the 303. 114 | */ 115 | FOUND = 302, 116 | 117 | /** 118 | * SINCE HTTP/1.1 119 | * The response to the request can be found under another URI using a GET method. 120 | * When received in response to a POST (or PUT/DELETE), the client should presume that 121 | * the server has received the data and should issue a redirect with a separate GET message. 122 | */ 123 | SEE_OTHER = 303, 124 | 125 | /** 126 | * Indicates that the resource has not been modified since the version specified by the request headers If-Modified-Since or If-None-Match. 127 | * In such case, there is no need to retransmit the resource since the client still has a previously-downloaded copy. 128 | */ 129 | NOT_MODIFIED = 304, 130 | 131 | /** 132 | * SINCE HTTP/1.1 133 | * The requested resource is available only through a proxy, the address for which is provided in the response. 134 | * Many HTTP clients (such as Mozilla and Internet Explorer) do not correctly handle responses with this status code, primarily for security reasons. 135 | */ 136 | USE_PROXY = 305, 137 | 138 | /** 139 | * No longer used. Originally meant "Subsequent requests should use the specified proxy." 140 | */ 141 | SWITCH_PROXY = 306, 142 | 143 | /** 144 | * SINCE HTTP/1.1 145 | * In this case, the request should be repeated with another URI; however, future requests should still use the original URI. 146 | * In contrast to how 302 was historically implemented, the request method is not allowed to be changed when reissuing the original request. 147 | * For example, a POST request should be repeated using another POST request. 148 | */ 149 | TEMPORARY_REDIRECT = 307, 150 | 151 | /** 152 | * The request and all future requests should be repeated using another URI. 153 | * 307 and 308 parallel the behaviors of 302 and 301, but do not allow the HTTP method to change. 154 | * So, for example, submitting a form to a permanently redirected resource may continue smoothly. 155 | */ 156 | PERMANENT_REDIRECT = 308, 157 | 158 | /** 159 | * The server cannot or will not process the request due to an apparent client error 160 | * (e.g., malformed request syntax, too large size, invalid request message framing, or deceptive request routing). 161 | */ 162 | BAD_REQUEST = 400, 163 | 164 | /** 165 | * Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet 166 | * been provided. The response must include a WWW-Authenticate header field containing a challenge applicable to the 167 | * requested resource. See Basic access authentication and Digest access authentication. 401 semantically means 168 | * "unauthenticated",i.e. the user does not have the necessary credentials. 169 | */ 170 | UNAUTHORIZED = 401, 171 | 172 | /** 173 | * Reserved for future use. The original intention was that this code might be used as part of some form of digital 174 | * cash or micro payment scheme, but that has not happened, and this code is not usually used. 175 | * Google Developers API uses this status if a particular developer has exceeded the daily limit on requests. 176 | */ 177 | PAYMENT_REQUIRED = 402, 178 | 179 | /** 180 | * The request was valid, but the server is refusing action. 181 | * The user might not have the necessary permissions for a resource. 182 | */ 183 | FORBIDDEN = 403, 184 | 185 | /** 186 | * The requested resource could not be found but may be available in the future. 187 | * Subsequent requests by the client are permissible. 188 | */ 189 | NOT_FOUND = 404, 190 | 191 | /** 192 | * A request method is not supported for the requested resource; 193 | * for example, a GET request on a form that requires data to be presented via POST, or a PUT request on a read-only resource. 194 | */ 195 | METHOD_NOT_ALLOWED = 405, 196 | 197 | /** 198 | * The requested resource is capable of generating only content not acceptable according to the Accept headers sent in the request. 199 | */ 200 | NOT_ACCEPTABLE = 406, 201 | 202 | /** 203 | * The client must first authenticate itself with the proxy. 204 | */ 205 | PROXY_AUTHENTICATION_REQUIRED = 407, 206 | 207 | /** 208 | * The server timed out waiting for the request. 209 | * According to HTTP specifications: 210 | * "The client did not produce a request within the time that the server was prepared to wait. The client MAY repeat the request without modifications at any later time." 211 | */ 212 | REQUEST_TIMEOUT = 408, 213 | 214 | /** 215 | * Indicates that the request could not be processed because of conflict in the request, 216 | * such as an edit conflict between multiple simultaneous updates. 217 | */ 218 | CONFLICT = 409, 219 | 220 | /** 221 | * Indicates that the resource requested is no longer available and will not be available again. 222 | * This should be used when a resource has been intentionally removed and the resource should be purged. 223 | * Upon receiving a 410 status code, the client should not request the resource in the future. 224 | * Clients such as search engines should remove the resource from their indices. 225 | * Most use cases do not require clients and search engines to purge the resource, and a "404 Not Found" may be used instead. 226 | */ 227 | GONE = 410, 228 | 229 | /** 230 | * The request did not specify the length of its content, which is required by the requested resource. 231 | */ 232 | LENGTH_REQUIRED = 411, 233 | 234 | /** 235 | * The server does not meet one of the preconditions that the requester put on the request. 236 | */ 237 | PRECONDITION_FAILED = 412, 238 | 239 | /** 240 | * The request is larger than the server is willing or able to process. Previously called "Request Entity Too Large". 241 | */ 242 | PAYLOAD_TOO_LARGE = 413, 243 | 244 | /** 245 | * The URI provided was too long for the server to process. Often the result of too much data being encoded as a query-string of a GET request, 246 | * in which case it should be converted to a POST request. 247 | * Called "Request-URI Too Long" previously. 248 | */ 249 | URI_TOO_LONG = 414, 250 | 251 | /** 252 | * The request entity has a media type which the server or resource does not support. 253 | * For example, the client uploads an image as image/svg+xml, but the server requires that images use a different format. 254 | */ 255 | UNSUPPORTED_MEDIA_TYPE = 415, 256 | 257 | /** 258 | * The client has asked for a portion of the file (byte serving), but the server cannot supply that portion. 259 | * For example, if the client asked for a part of the file that lies beyond the end of the file. 260 | * Called "Requested Range Not Satisfiable" previously. 261 | */ 262 | RANGE_NOT_SATISFIABLE = 416, 263 | 264 | /** 265 | * The server cannot meet the requirements of the Expect request-header field. 266 | */ 267 | EXPECTATION_FAILED = 417, 268 | 269 | /** 270 | * This code was defined in 1998 as one of the traditional IETF April Fools' jokes, in RFC 2324, Hyper Text Coffee Pot Control Protocol, 271 | * and is not expected to be implemented by actual HTTP servers. The RFC specifies this code should be returned by 272 | * teapots requested to brew coffee. This HTTP status is used as an Easter egg in some websites, including Google.com. 273 | */ 274 | I_AM_A_TEAPOT = 418, 275 | 276 | /** 277 | * The request was directed at a server that is not able to produce a response (for example because a connection reuse). 278 | */ 279 | MISDIRECTED_REQUEST = 421, 280 | 281 | /** 282 | * The request was well-formed but was unable to be followed due to semantic errors. 283 | */ 284 | UNPROCESSABLE_ENTITY = 422, 285 | 286 | /** 287 | * The resource that is being accessed is locked. 288 | */ 289 | LOCKED = 423, 290 | 291 | /** 292 | * The request failed due to failure of a previous request (e.g., a PROPPATCH). 293 | */ 294 | FAILED_DEPENDENCY = 424, 295 | 296 | /** 297 | * The client should switch to a different protocol such as TLS/1.0, given in the Upgrade header field. 298 | */ 299 | UPGRADE_REQUIRED = 426, 300 | 301 | /** 302 | * The origin server requires the request to be conditional. 303 | * Intended to prevent "the 'lost update' problem, where a client 304 | * GETs a resource's state, modifies it, and PUTs it back to the server, 305 | * when meanwhile a third party has modified the state on the server, leading to a conflict." 306 | */ 307 | PRECONDITION_REQUIRED = 428, 308 | 309 | /** 310 | * The user has sent too many requests in a given amount of time. Intended for use with rate-limiting schemes. 311 | */ 312 | TOO_MANY_REQUESTS = 429, 313 | 314 | /** 315 | * The server is unwilling to process the request because either an individual header field, 316 | * or all the header fields collectively, are too large. 317 | */ 318 | REQUEST_HEADER_FIELDS_TOO_LARGE = 431, 319 | 320 | /** 321 | * A server operator has received a legal demand to deny access to a resource or to a set of resources 322 | * that includes the requested resource. The code 451 was chosen as a reference to the novel Fahrenheit 451. 323 | */ 324 | UNAVAILABLE_FOR_LEGAL_REASONS = 451, 325 | 326 | /** 327 | * A generic error message, given when an unexpected condition was encountered and no more specific message is suitable. 328 | */ 329 | INTERNAL_SERVER_ERROR = 500, 330 | 331 | /** 332 | * The server either does not recognize the request method, or it lacks the ability to fulfill the request. 333 | * Usually this implies future availability (e.g., a new feature of a web-service API). 334 | */ 335 | NOT_IMPLEMENTED = 501, 336 | 337 | /** 338 | * The server was acting as a gateway or proxy and received an invalid response from the upstream server. 339 | */ 340 | BAD_GATEWAY = 502, 341 | 342 | /** 343 | * The server is currently unavailable (because it is overloaded or down for maintenance). 344 | * Generally, this is a temporary state. 345 | */ 346 | SERVICE_UNAVAILABLE = 503, 347 | 348 | /** 349 | * The server was acting as a gateway or proxy and did not receive a timely response from the upstream server. 350 | */ 351 | GATEWAY_TIMEOUT = 504, 352 | 353 | /** 354 | * The server does not support the HTTP protocol version used in the request 355 | */ 356 | HTTP_VERSION_NOT_SUPPORTED = 505, 357 | 358 | /** 359 | * Transparent content negotiation for the request results in a circular reference. 360 | */ 361 | VARIANT_ALSO_NEGOTIATES = 506, 362 | 363 | /** 364 | * The server is unable to store the representation needed to complete the request. 365 | */ 366 | INSUFFICIENT_STORAGE = 507, 367 | 368 | /** 369 | * The server detected an infinite loop while processing the request. 370 | */ 371 | LOOP_DETECTED = 508, 372 | 373 | /** 374 | * Further extensions to the request are required for the server to fulfill it. 375 | */ 376 | NOT_EXTENDED = 510, 377 | 378 | /** 379 | * The client needs to authenticate to gain network access. 380 | * Intended for use by intercepting proxies used to control access to the network (e.g., "captive portals" used 381 | * to require agreement to Terms of Service before granting full Internet access via a Wi-Fi hotspot). 382 | */ 383 | NETWORK_AUTHENTICATION_REQUIRED = 511 384 | } 385 | 386 | export default HttpStatusCodes; 387 | -------------------------------------------------------------------------------- /server/src/constants/misc.ts: -------------------------------------------------------------------------------- 1 | export enum NodeEnvs { 2 | Dev = 'development', 3 | Test = 'test', 4 | Production = 'production' 5 | } -------------------------------------------------------------------------------- /server/src/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Setup express server. 3 | */ 4 | 5 | import morgan from 'morgan'; 6 | import express, { Request, Response, NextFunction } from 'express'; 7 | import winston from 'winston'; 8 | 9 | import 'express-async-errors'; 10 | 11 | import BaseRouter from './Router.js'; 12 | 13 | import EnvVars from './constants/EnvVars.js'; 14 | import HttpStatusCodes from './constants/HttpStatusCodes.js'; 15 | 16 | import { NodeEnvs } from './constants/misc.js'; 17 | import { RouteError } from './other/classes.js'; 18 | 19 | 20 | // **** Variables **** // 21 | 22 | const app = express(); 23 | 24 | 25 | // **** Setup **** // 26 | 27 | // Basic middleware 28 | app.use(express.json()); 29 | app.use(express.urlencoded({extended: true})); 30 | 31 | // Show routes called in console during development 32 | if (EnvVars.NodeEnv === NodeEnvs.Dev) { 33 | app.use(morgan('dev')); 34 | } 35 | 36 | // Add APIs, must be after middleware 37 | app.use('/api', BaseRouter); 38 | 39 | // Add error handler 40 | app.use(( 41 | err: Error, 42 | _: Request, 43 | res: Response, 44 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 45 | next: NextFunction, 46 | ) => { 47 | if (EnvVars.NodeEnv !== NodeEnvs.Test) { 48 | winston.error(err); 49 | } 50 | let status = HttpStatusCodes.BAD_REQUEST; 51 | if (err instanceof RouteError) { 52 | status = err.status; 53 | } 54 | return res.status(status).json({ error: err.message }); 55 | }); 56 | 57 | // **** Run **** // 58 | 59 | const SERVER_START_MSG = ('Express server started on port: ' + 60 | EnvVars.Port.toString()); 61 | 62 | app.listen(EnvVars.Port, () => winston.info(SERVER_START_MSG)); 63 | -------------------------------------------------------------------------------- /server/src/other/classes.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Miscellaneous shared classes go here. 3 | */ 4 | 5 | import HttpStatusCodes from '../constants/HttpStatusCodes.js'; 6 | 7 | 8 | /** 9 | * Error with status code and message 10 | */ 11 | export class RouteError extends Error { 12 | status: HttpStatusCodes; 13 | constructor(status: HttpStatusCodes, message: string) { 14 | super(message); 15 | this.status = status; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /server/src/services/CalculationService.ts: -------------------------------------------------------------------------------- 1 | export function calculateExpression(expr: string): number | undefined { 2 | // Check if expression is safe to evaluate 3 | const isSafeExpression = /^[\d+\-*/\s().]+$/.test(expr); 4 | 5 | if (isSafeExpression) { 6 | try { 7 | // Evaluate and return the result 8 | return eval(expr); 9 | } catch (error) { 10 | console.error('Error evaluating expression:', error); 11 | return undefined; 12 | } 13 | } else { 14 | console.error('Unsafe expression detected'); 15 | return undefined; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /server/src/services/RivetRunner.ts: -------------------------------------------------------------------------------- 1 | import { 2 | GraphId, 3 | GraphInputs, 4 | GraphOutputs, 5 | coerceType, 6 | currentDebuggerState, 7 | loadProjectFromFile, 8 | runGraph 9 | } from '@ironclad/rivet-node'; 10 | 11 | import { rivetDebuggerServerState } from '../RivetDebuggerRoutes.js'; 12 | import { env } from 'process'; 13 | import { calculateExpression } from './CalculationService.js'; 14 | 15 | export async function runMessageGraph(input: { type: 'assistant' | 'user'; message: string }[]): Promise { 16 | const outputs = await runRivetGraph('5BI0Pfuu2naOUKqGUO-yZ' as GraphId, { 17 | messages: { 18 | type: 'object[]', 19 | value: input, 20 | }, 21 | }); 22 | 23 | return coerceType(outputs.output, 'string'); 24 | } 25 | 26 | export async function runRivetGraph(graphId: GraphId, inputs?: GraphInputs): Promise { 27 | const project = currentDebuggerState.uploadedProject ?? await loadProjectFromFile('../chat.rivet-project'); 28 | 29 | const outputs = await runGraph(project, { 30 | graph: graphId, 31 | openAiKey: env.OPENAI_API_KEY as string, 32 | inputs, 33 | remoteDebugger: rivetDebuggerServerState.server ?? undefined, 34 | externalFunctions: { 35 | calculate: async (_context: any, calculationStr: any) => { 36 | if (typeof calculationStr !== 'string') { 37 | throw Error('expected a string input'); 38 | } 39 | const value = calculateExpression(calculationStr); 40 | if (value) { 41 | return { 42 | type: 'number', 43 | value, 44 | }; 45 | } else { 46 | return { 47 | type: 'string', 48 | value: 'Error calculating', 49 | }; 50 | } 51 | }, 52 | }, 53 | }); 54 | 55 | return outputs; 56 | } 57 | -------------------------------------------------------------------------------- /server/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig.json to read more about this file */ 4 | /* Basic Options */ 5 | "target": "ESNext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ 6 | "module": "NodeNext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ 7 | "outDir": "dist", /* Redirect output structure to the directory. */ 8 | 9 | /* Strict Type-Checking Options */ 10 | "strict": true, /* Enable all strict type-checking options. */ 11 | 12 | /* Module Resolution Options */ 13 | "moduleResolution": "NodeNext", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ 14 | "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ 15 | "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ 16 | "skipLibCheck": true, /* Skip type checking of declaration files. */ 17 | "forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */ 18 | "useUnknownInCatchVariables": false, 19 | "project": "./tsconfig.json", 20 | }, 21 | "include": [ 22 | "src/**/*.ts" 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /server/tsconfig.prod.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "sourceMap": false, 5 | "removeComments": true 6 | }, 7 | "exclude": [ 8 | "spec", 9 | ] 10 | } 11 | --------------------------------------------------------------------------------