mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-09 15:07:55 -05:00
fix(cli): improve root path redirect and bump version to 0.1.3
This commit is contained in:
4
packages/simstudio/package-lock.json
generated
4
packages/simstudio/package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@simstudio/cli",
|
"name": "@simstudio/cli",
|
||||||
"version": "0.1.1",
|
"version": "0.1.4",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@simstudio/cli",
|
"name": "@simstudio/cli",
|
||||||
"version": "0.1.1",
|
"version": "0.1.4",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chalk": "^4.1.2",
|
"chalk": "^4.1.2",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "simstudio",
|
"name": "simstudio",
|
||||||
"version": "0.1.2",
|
"version": "0.1.3",
|
||||||
"description": "CLI tool for Sim Studio - easily start, build and test agent workflows",
|
"description": "CLI tool for Sim Studio - easily start, build and test agent workflows",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"author": "Sim Studio Team",
|
"author": "Sim Studio Team",
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ interface StartOptions {
|
|||||||
const SIM_HOME_DIR = path.join(os.homedir(), '.sim-studio')
|
const SIM_HOME_DIR = path.join(os.homedir(), '.sim-studio')
|
||||||
const SIM_STANDALONE_DIR = path.join(SIM_HOME_DIR, 'standalone')
|
const SIM_STANDALONE_DIR = path.join(SIM_HOME_DIR, 'standalone')
|
||||||
const SIM_VERSION_FILE = path.join(SIM_HOME_DIR, 'version.json')
|
const SIM_VERSION_FILE = path.join(SIM_HOME_DIR, 'version.json')
|
||||||
|
const STANDALONE_VERSION = '0.1.3'
|
||||||
const DOWNLOAD_URL =
|
const DOWNLOAD_URL =
|
||||||
'https://github.com/simstudioai/sim/releases/latest/download/sim-standalone.tar.gz'
|
'https://github.com/simstudioai/sim/releases/latest/download/sim-standalone.tar.gz'
|
||||||
const STANDALONE_VERSION = '0.1.2'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start command that launches Sim Studio using local storage
|
* Start command that launches Sim Studio using local storage
|
||||||
@@ -124,7 +124,7 @@ export async function start(options: StartOptions) {
|
|||||||
// Download and extract if needed
|
// Download and extract if needed
|
||||||
if (needsDownload) {
|
if (needsDownload) {
|
||||||
try {
|
try {
|
||||||
await downloadStandaloneApp(spinner)
|
await downloadStandaloneApp(spinner, options)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
spinner.fail(
|
spinner.fail(
|
||||||
`Failed to download Sim Studio: ${error instanceof Error ? error.message : String(error)}`
|
`Failed to download Sim Studio: ${error instanceof Error ? error.message : String(error)}`
|
||||||
@@ -254,7 +254,7 @@ function checkIfInProjectDirectory(): boolean {
|
|||||||
/**
|
/**
|
||||||
* Downloads and extracts the standalone app
|
* Downloads and extracts the standalone app
|
||||||
*/
|
*/
|
||||||
async function downloadStandaloneApp(spinner: SimpleSpinner): Promise<void> {
|
async function downloadStandaloneApp(spinner: SimpleSpinner, options: StartOptions): Promise<void> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// Create temp directory
|
// Create temp directory
|
||||||
const tmpDir = path.join(os.tmpdir(), `sim-download-${Date.now()}`)
|
const tmpDir = path.join(os.tmpdir(), `sim-download-${Date.now()}`)
|
||||||
@@ -263,10 +263,19 @@ async function downloadStandaloneApp(spinner: SimpleSpinner): Promise<void> {
|
|||||||
const tarballPath = path.join(tmpDir, 'sim-standalone.tar.gz')
|
const tarballPath = path.join(tmpDir, 'sim-standalone.tar.gz')
|
||||||
const file = createWriteStream(tarballPath)
|
const file = createWriteStream(tarballPath)
|
||||||
|
|
||||||
spinner.text = 'Downloading Sim Studio...'
|
spinner.text = 'Downloading Sim Studio standalone package...'
|
||||||
|
|
||||||
// Function to handle the download
|
// Function to handle the download
|
||||||
const downloadFile = (url: string) => {
|
const downloadFile = (url: string, redirectCount = 0) => {
|
||||||
|
// Prevent infinite redirects
|
||||||
|
if (redirectCount > 5) {
|
||||||
|
spinner.fail('Too many redirects')
|
||||||
|
if (options.debug) {
|
||||||
|
console.error('Redirect chain:', url)
|
||||||
|
}
|
||||||
|
return reject(new Error('Download failed: Too many redirects'))
|
||||||
|
}
|
||||||
|
|
||||||
https
|
https
|
||||||
.get(url, (response) => {
|
.get(url, (response) => {
|
||||||
// Handle redirects (302, 301, 307, etc.)
|
// Handle redirects (302, 301, 307, etc.)
|
||||||
@@ -279,18 +288,34 @@ async function downloadStandaloneApp(spinner: SimpleSpinner): Promise<void> {
|
|||||||
// Close the current file stream before following the redirect
|
// Close the current file stream before following the redirect
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
spinner.text = `Following redirect to ${response.headers.location}...`
|
const redirectUrl = response.headers.location.startsWith('http')
|
||||||
|
? response.headers.location
|
||||||
|
: new URL(response.headers.location, url).toString()
|
||||||
|
|
||||||
// Follow the redirect
|
// Only update spinner text on first redirect, then just show "Following redirects..."
|
||||||
downloadFile(response.headers.location)
|
if (redirectCount === 0) {
|
||||||
|
spinner.text = 'Following GitHub redirects...'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.debug) {
|
||||||
|
console.log(`Redirect ${redirectCount + 1}: ${url} -> ${redirectUrl}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Follow the redirect with incremented counter
|
||||||
|
downloadFile(redirectUrl, redirectCount + 1)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.statusCode !== 200) {
|
if (response.statusCode !== 200) {
|
||||||
spinner.fail(`Failed to download: ${response.statusCode}`)
|
spinner.fail(`Failed to download: ${response.statusCode}`)
|
||||||
|
if (options.debug) {
|
||||||
|
console.error('URL that failed:', url)
|
||||||
|
console.error('Headers:', JSON.stringify(response.headers, null, 2))
|
||||||
|
}
|
||||||
return reject(new Error(`Download failed with status code: ${response.statusCode}`))
|
return reject(new Error(`Download failed with status code: ${response.statusCode}`))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
spinner.text = 'Downloading Sim Studio standalone package...'
|
||||||
response.pipe(file)
|
response.pipe(file)
|
||||||
|
|
||||||
file.on('finish', () => {
|
file.on('finish', () => {
|
||||||
|
|||||||
@@ -156,7 +156,9 @@ app.prepare().then(() => {
|
|||||||
// Generate a UUID for the new workflow
|
// Generate a UUID for the new workflow
|
||||||
const uuid = crypto.randomUUID();
|
const uuid = crypto.randomUUID();
|
||||||
console.log(\`Redirecting to new workflow: \${uuid}\`);
|
console.log(\`Redirecting to new workflow: \${uuid}\`);
|
||||||
res.redirect(\`/w/\${uuid}\`);
|
|
||||||
|
// Use 302 redirect to ensure it's not cached and is followed
|
||||||
|
return res.redirect(302, \`/w/\${uuid}\`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle all other requests with Next.js
|
// Handle all other requests with Next.js
|
||||||
@@ -170,6 +172,7 @@ app.prepare().then(() => {
|
|||||||
console.log(\`> Sim Studio standalone server ready on http://localhost:\${port}\`);
|
console.log(\`> Sim Studio standalone server ready on http://localhost:\${port}\`);
|
||||||
console.log('> Running in local storage mode - all data will be stored in the browser');
|
console.log('> Running in local storage mode - all data will be stored in the browser');
|
||||||
console.log('> Authentication is disabled - anyone can access the app');
|
console.log('> Authentication is disabled - anyone can access the app');
|
||||||
|
console.log('> Root path (/) will redirect to a new workflow automatically');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
`
|
`
|
||||||
|
|||||||
Reference in New Issue
Block a user