feat(npm): added logic to disable auth, middleware validation, & db syncing for npm package

This commit is contained in:
Waleed Latif
2025-03-04 17:55:55 -08:00
parent 2eb02a3369
commit 301b156139
18 changed files with 739 additions and 254 deletions

View File

@@ -0,0 +1,34 @@
# Environment variables and secrets
.env
.env.*
*.env
.env.local
.env.development
.env.test
.env.production
# Development files
node_modules
.git
.gitignore
.github
.vscode
.idea
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Test files
test
tests
__tests__
coverage
# Build artifacts
.DS_Store
.cache
.next/cache
# Project specific
.sim-studio-dev

View File

@@ -1,101 +1,79 @@
# Sim Studio CLI
The Sim Studio CLI provides a convenient way to run Sim Studio directly from your terminal without needing to set up a database or complex environment.
A command-line interface for Sim Studio - a powerful, user-friendly platform for building, testing, and optimizing agentic workflows.
## Installation
```bash
npm install -g simstudio
```
Or run directly with npx:
```bash
npx simstudio
```
## Quick Start
The fastest way to get started is to run:
```bash
# Run Sim Studio with default settings
npx sim
npx simstudio start
```
# Start with custom port
npx sim start -p 8080
This will download and start a standalone version of Sim Studio, with all data stored in your browser's localStorage. No database or authentication required!
# Get help
npx sim help
## Usage
### Start Sim Studio
Start a local instance of Sim Studio:
```bash
simstudio start
```
Options:
- `--port <port>` - Specify the port to run on (default: 3000)
- `--debug` - Run in debug mode
### Help
Get help with available commands:
```bash
simstudio --help
```
## Features
- **Zero Configuration**: Get started immediately with `npx sim`
- **Local Storage**: Works entirely in the browser, no database required
- **Persistence**: Your workflows and data persist between sessions
- **Familiar Experience**: All the power of Sim Studio in a simplified package
- **Local Storage Mode**: All your workflows and settings are stored in your browser's localStorage, no database required
- **Workflow Builder**: Create and edit workflows with a visual editor
- **Workflow Execution**: Run workflows and see the results in real-time
- **Environment Variables**: Manage environment variables for your workflows
## Commands
## How It Works
- `sim` - Start Sim Studio with default settings
- `sim start` - Start Sim Studio with options
- `sim version` - Display version information
- `sim help` - Show help and usage information
When you run `simstudio start`, the CLI will:
## Options
1. Check if you're in a Sim Studio project directory
2. If not, download and extract a standalone version of Sim Studio
3. Start a local server with the standalone app
4. Open a browser window to the Sim Studio UI
- `-p, --port <port>` - Specify port (default: 3000)
- `-d, --debug` - Enable debug mode
- `-v, --version` - Show version information
- `-h, --help` - Show help information
All your data is stored in your browser's localStorage, so you can close the app and come back later without losing your work.
## Local Storage Mode
## Development
When running Sim Studio via the CLI, all data is stored using the browser's localStorage. This means:
To contribute to the development of Sim Studio CLI:
- Your workflows persist between browser sessions
- No database configuration is required
- Data is stored locally on your device
- Multiple users can't share the same workflows (single-user mode)
1. Clone the repository
2. Install dependencies with `npm install`
3. Build the CLI with `npm run build`
4. Link the CLI for local development with `npm link`
## Advanced Usage
## License
If you need multi-user capabilities or want to store data in a database, consider:
1. Using the Docker setup in the main repository
2. Setting up a full Sim Studio environment with PostgreSQL
3. Deploying to Vercel with a database
## For Developers: Building & Publishing the CLI
### Release Checklist
1. ✅ Update the CLI code with your changes
2. ✅ Bump the version in `package.json`
3. ✅ Build the standalone version:
```
npm run build:cli
```
4. ✅ Upload the generated `sim-standalone.tar.gz` to GitHub releases
5. ✅ Update the `DOWNLOAD_URL` constant in `packages/@sim/cli/src/commands/start.ts` to point to the new release URL
6. ✅ Commit all changes
7. ✅ Publish to npm:
```
npm run cli:publish
```
### About the Standalone Version
The standalone version is a pre-built and bundled version of Sim Studio that can run without a database or complex setup. It includes:
- A pre-built static export of the Next.js application
- A simple Express server to serve the static files
- Configuration to use browser localStorage for data persistence
This allows users to quickly try Sim Studio with a simple `npx sim` command without installing anything else.
### Testing the CLI Locally
To test the CLI locally:
```bash
# Build the CLI
npm run cli:build
# Run the CLI directly
npm run cli:start
# Or use the dev script
npm run cli:dev
```
## Need Help?
Visit our [documentation](https://github.com/yourusername/sim) or open an issue on GitHub.
MIT

View File

@@ -1,14 +1,14 @@
#!/usr/bin/env node
// This file is the entry point for the 'sim' command
// This file is the entry point for the 'simstudio' command
try {
require('../dist/index.js')
} catch (error) {
if (error.code === 'MODULE_NOT_FOUND') {
console.error('Sim CLI has not been built. Please run npm run build first.')
console.error('Sim Studio CLI has not been built. Please run npm run build first.')
process.exit(1)
} else {
console.error('An error occurred while starting Sim CLI:', error)
console.error('An error occurred while starting Sim Studio CLI:', error)
process.exit(1)
}
}

View File

@@ -19,7 +19,7 @@ const spinner_1 = require("../utils/spinner");
const SIM_HOME_DIR = path_1.default.join(os_1.default.homedir(), '.sim-studio');
const SIM_STANDALONE_DIR = path_1.default.join(SIM_HOME_DIR, 'standalone');
const SIM_VERSION_FILE = path_1.default.join(SIM_HOME_DIR, 'version.json');
const DOWNLOAD_URL = 'https://github.com/simstudioai/sim/releases/download/v0.1.0/sim-standalone.tar.gz';
const DOWNLOAD_URL = 'https://github.com/simstudioai/sim/releases/latest/download/sim-standalone.tar.gz';
const STANDALONE_VERSION = '0.1.0';
/**
* Start command that launches Sim Studio using local storage
@@ -39,6 +39,8 @@ async function start(options) {
...process.env,
PORT: port,
USE_LOCAL_STORAGE: 'true', // Key environment variable to switch to local storage
NEXT_PUBLIC_USE_LOCAL_STORAGE: 'true', // For client-side code
DISABLE_DB_SYNC: 'true', // Disable database sync
NODE_ENV: debug ? 'development' : 'production',
DEBUG: debug ? '*' : undefined,
};
@@ -50,11 +52,40 @@ async function start(options) {
// Running from within the project directory - we'll use the existing
// Next.js setup directly
spinner.text = 'Detected Sim Studio project, starting with local configuration...';
simProcess = (0, child_process_1.spawn)('npm', ['run', 'dev'], {
env,
stdio: 'inherit',
shell: true,
});
// When running in dev mode, we need to make sure we're not trying to use static export
// as it will fail with API routes
if (debug) {
spinner.text = 'Starting in development mode with local storage...';
simProcess = (0, child_process_1.spawn)('npm', ['run', 'dev'], {
env: env,
stdio: 'inherit',
shell: true,
});
}
else {
// In production mode, we'll use the start command which uses the built app
spinner.text = 'Starting in production mode with local storage...';
// Build first if needed
if (!fs_1.default.existsSync(path_1.default.join(process.cwd(), '.next'))) {
spinner.text = 'Building Next.js app first...';
try {
(0, child_process_2.execSync)('npm run build', {
env: env,
stdio: 'inherit'
});
}
catch (error) {
spinner.fail('Failed to build Next.js app');
console.error(chalk_1.default.red('Error:'), error instanceof Error ? error.message : error);
process.exit(1);
}
}
simProcess = (0, child_process_1.spawn)('npm', ['run', 'start'], {
env: env,
stdio: 'inherit',
shell: true,
});
}
}
else {
// Running from outside the project via npx - we'll download and start a standalone version
@@ -153,7 +184,7 @@ function checkIfInProjectDirectory() {
if (packageJson.name === 'sim' ||
packageJson.name === 'sim-studio' ||
(packageJson.dependencies &&
(packageJson.dependencies['next'] || packageJson.dependencies['@sim/cli']))) {
(packageJson.dependencies['next'] || packageJson.dependencies['@sim/cli'] || packageJson.dependencies['sim-studio-cli']))) {
return true;
}
}

View File

@@ -1,5 +1,5 @@
{
"name": "@sim/cli",
"name": "simstudio",
"version": "0.1.0",
"description": "CLI tool for Sim Studio - easily start, build and test agent workflows",
"license": "MIT",
@@ -7,19 +7,21 @@
"main": "dist/index.js",
"type": "commonjs",
"bin": {
"sim": "./bin/sim.js"
"simstudio": "./bin/sim.js"
},
"files": [
"bin",
"dist",
"README.md"
"README.md",
"standalone"
],
"scripts": {
"build": "tsc",
"start": "node bin/sim.js",
"dev": "ts-node src/index.ts",
"clean": "rimraf dist",
"prepublishOnly": "npm run clean && npm run build"
"prepublishOnly": "npm run clean && npm run build && npm run prepare-standalone && echo 'Checking for sensitive files...' && (! find . -name '.env*' -not -path '*/node_modules/*' -not -path '*/standalone/*' | grep -q .)",
"prepare-standalone": "node ../../../scripts/build-standalone.js"
},
"keywords": [
"sim",
@@ -27,7 +29,9 @@
"workflow",
"automation",
"cli",
"agent"
"agent",
"ai",
"workflow-automation"
],
"dependencies": {
"chalk": "^4.1.2",
@@ -49,5 +53,16 @@
},
"engines": {
"node": ">=16.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/simstudioai/sim"
},
"bugs": {
"url": "https://github.com/simstudioai/sim/issues"
},
"homepage": "https://github.com/simstudioai/sim#readme",
"publishConfig": {
"access": "public"
}
}

View File

@@ -20,7 +20,7 @@ const SIM_HOME_DIR = path.join(os.homedir(), '.sim-studio')
const SIM_STANDALONE_DIR = path.join(SIM_HOME_DIR, 'standalone')
const SIM_VERSION_FILE = path.join(SIM_HOME_DIR, 'version.json')
const DOWNLOAD_URL =
'https://github.com/simstudioai/sim/releases/download/v0.1.0/sim-standalone.tar.gz'
'https://github.com/simstudioai/sim/releases/latest/download/sim-standalone.tar.gz'
const STANDALONE_VERSION = '0.1.0'
/**
@@ -44,6 +44,8 @@ export async function start(options: StartOptions) {
...process.env,
PORT: port,
USE_LOCAL_STORAGE: 'true', // Key environment variable to switch to local storage
NEXT_PUBLIC_USE_LOCAL_STORAGE: 'true', // For client-side code
DISABLE_DB_SYNC: 'true', // Disable database sync
NODE_ENV: debug ? 'development' : ('production' as const),
DEBUG: debug ? '*' : undefined,
}
@@ -59,11 +61,40 @@ export async function start(options: StartOptions) {
// Next.js setup directly
spinner.text = 'Detected Sim Studio project, starting with local configuration...'
simProcess = spawn('npm', ['run', 'dev'], {
env: env as NodeJS.ProcessEnv,
stdio: 'inherit',
shell: true,
})
// When running in dev mode, we need to make sure we're not trying to use static export
// as it will fail with API routes
if (debug) {
spinner.text = 'Starting in development mode with local storage...'
simProcess = spawn('npm', ['run', 'dev'], {
env: env as NodeJS.ProcessEnv,
stdio: 'inherit',
shell: true,
})
} else {
// In production mode, we'll use the start command which uses the built app
spinner.text = 'Starting in production mode with local storage...'
// Build first if needed
if (!fs.existsSync(path.join(process.cwd(), '.next'))) {
spinner.text = 'Building Next.js app first...'
try {
execSync('npm run build', {
env: env as NodeJS.ProcessEnv,
stdio: 'inherit',
})
} catch (error) {
spinner.fail('Failed to build Next.js app')
console.error(chalk.red('Error:'), error instanceof Error ? error.message : error)
process.exit(1)
}
}
simProcess = spawn('npm', ['run', 'start'], {
env: env as NodeJS.ProcessEnv,
stdio: 'inherit',
shell: true,
})
}
} else {
// Running from outside the project via npx - we'll download and start a standalone version
spinner.text = 'Setting up standalone Sim Studio...'
@@ -176,7 +207,9 @@ function checkIfInProjectDirectory(): boolean {
packageJson.name === 'sim' ||
packageJson.name === 'sim-studio' ||
(packageJson.dependencies &&
(packageJson.dependencies['next'] || packageJson.dependencies['@sim/cli']))
(packageJson.dependencies['next'] ||
packageJson.dependencies['@sim/cli'] ||
packageJson.dependencies['sim-studio-cli']))
) {
return true
}

View File

@@ -1,16 +0,0 @@
{
"name": "sim-studio-standalone",
"version": "0.1.0",
"private": true,
"description": "Standalone server for Sim Studio",
"main": "server.js",
"dependencies": {
"express": "^4.18.2"
},
"engines": {
"node": ">=16.0.0"
},
"scripts": {
"start": "node server.js"
}
}

View File

@@ -1,76 +0,0 @@
#!/usr/bin/env node
/**
* Sim Studio Standalone Server
*
* This is a simplified server that serves the pre-built Sim Studio app
* and enables localStorage mode automatically.
*/
const express = require('express')
const path = require('path')
const fs = require('fs')
const { createServer } = require('http')
const { parse } = require('url')
// Configuration
const PORT = process.env.SIM_STUDIO_PORT || 3000
const PUBLIC_DIR = path.join(__dirname, 'public')
const HTML_FILE = path.join(PUBLIC_DIR, 'index.html')
// Create Express app
const app = express()
// Set localStorage environment variable in HTML
const injectLocalStorageScript = (html) => {
const script = `
<script>
// Set localStorage flag for Sim Studio
localStorage.setItem('USE_LOCAL_STORAGE', 'true');
console.log('Sim Studio running in local storage mode');
</script>
`
// Insert script right before the closing </head> tag
return html.replace('</head>', `${script}</head>`)
}
// Middleware to inject localStorage flag
app.use((req, res, next) => {
if (req.path === '/' || req.path.endsWith('.html')) {
const originalSend = res.send
res.send = function (body) {
if (typeof body === 'string' && body.includes('</head>')) {
body = injectLocalStorageScript(body)
}
return originalSend.call(this, body)
}
}
next()
})
// Serve static files
app.use(express.static(PUBLIC_DIR))
// SPA fallback - all routes not matched should serve index.html
app.get('*', (req, res) => {
res.sendFile(HTML_FILE)
})
// Start the server
app.listen(PORT, () => {
console.log(`
┌────────────────────────────────────────────────────┐
│ │
│ 🚀 Sim Studio is running in standalone mode! │
│ │
│ 🌐 Local: http://localhost:${PORT} ${PORT.toString().length < 4 ? ' ' : ''}
│ │
│ 💾 Using localStorage for all data │
│ 🔄 All changes will be saved in your browser │
│ │
│ Press Ctrl+C to stop the server │
│ │
└────────────────────────────────────────────────────┘
`)
})