-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
180 lines (160 loc) · 6.38 KB
/
setup.js
File metadata and controls
180 lines (160 loc) · 6.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env node
const prompts = require('prompts');
const fs = require('fs');
const path = require('path');
const ENV_PATH = path.join(__dirname, '.env');
const BANNER = `
╦┬ ┬┌┐┌┬┌─┐┌─┐┬─┐ ╔═╗┌─┐┌┬┐┌┬┐┌─┐┬─┐┌─┐┌─┐
║│ │││││├─┘├┤ ├┬┘ ║ │ │││││││├┤ ├┬┘│ ├┤
╚╝└─┘┘└┘┴┴ └─┘┴└─ ╚═╝└─┘┴ ┴┴ ┴└─┘┴└─└─┘└─┘
onX Reference Implementation — Setup
`;
async function main() {
console.log(BANNER);
if (fs.existsSync(ENV_PATH)) {
const { overwrite } = await prompts({
type: 'confirm',
name: 'overwrite',
message: '.env already exists. Overwrite?',
initial: false,
});
if (!overwrite) {
console.log('\n Keeping existing .env. Exiting.\n');
process.exit(0);
}
}
const { mode } = await prompts({
type: 'select',
name: 'mode',
message: 'What mode do you want to run?',
choices: [
{ title: 'Quick Demo', description: 'In-memory data, rate-limited AI, no setup needed', value: 'demo' },
{ title: 'Full Install', description: 'Persistent data, your AI key, settings screen', value: 'full' },
],
});
if (!mode) process.exit(1);
const profiles = [];
const env = {
APP_MODE: mode,
DATA_MODE: 'memory',
DATABASE_URL: '',
ANTHROPIC_API_KEY: '',
OPENAI_API_KEY: '',
GOOGLE_AI_API_KEY: '',
OLLAMA_URL: '',
OLLAMA_MODEL: '',
ONX_MCP_SERVER_URL: '',
SEED_DATA: 'false',
SESSION_TTL_MINUTES: '30',
MAX_MESSAGES_PER_SESSION: '20',
PORT: '3000',
NODE_ENV: 'production',
};
if (mode === 'demo') {
env.DATA_MODE = 'memory';
env.SEED_DATA = 'true';
} else {
const { dataStore } = await prompts({
type: 'select',
name: 'dataStore',
message: 'Data store?',
choices: [
{ title: 'PostgreSQL', description: 'Recommended — runs in Docker, persistent', value: 'postgres' },
{ title: 'SQLite', description: 'Lightweight — single file, no extra container', value: 'sqlite' },
],
});
if (!dataStore) process.exit(1);
env.DATA_MODE = dataStore;
if (dataStore === 'postgres') {
env.DATABASE_URL = 'postgres://juniper:juniper@db:5432/juniper';
profiles.push('postgres');
} else {
env.DATABASE_URL = 'file:./db/juniper.db';
}
const { aiProvider } = await prompts({
type: 'select',
name: 'aiProvider',
message: 'AI provider for the Playground?',
choices: [
{ title: 'Anthropic (Claude)', value: 'anthropic' },
{ title: 'OpenAI (GPT-4o / GPT-5)', value: 'openai' },
{ title: 'Google Gemini', value: 'gemini' },
{ title: 'Ollama (local, free)', value: 'ollama' },
{ title: 'Skip AI features', value: 'skip' },
],
});
if (!aiProvider) process.exit(1);
if (aiProvider === 'anthropic') {
const { key } = await prompts({ type: 'password', name: 'key', message: 'Anthropic API key:' });
env.ANTHROPIC_API_KEY = key || '';
} else if (aiProvider === 'openai') {
const { key } = await prompts({ type: 'password', name: 'key', message: 'OpenAI API key:' });
env.OPENAI_API_KEY = key || '';
} else if (aiProvider === 'gemini') {
const { key } = await prompts({ type: 'password', name: 'key', message: 'Google AI API key:' });
env.GOOGLE_AI_API_KEY = key || '';
} else if (aiProvider === 'ollama') {
const { url } = await prompts({ type: 'text', name: 'url', message: 'Ollama URL:', initial: 'http://host.docker.internal:11434' });
env.OLLAMA_URL = url || 'http://host.docker.internal:11434';
const { model } = await prompts({ type: 'text', name: 'model', message: 'Ollama model:', initial: 'llama3.1' });
env.OLLAMA_MODEL = model || 'llama3.1';
}
const { includeMcp } = await prompts({
type: 'confirm',
name: 'includeMcp',
message: 'Include MCP reference server?',
initial: false,
});
if (includeMcp) {
profiles.push('mcp');
env.ONX_MCP_SERVER_URL = 'http://mcp-server:8080';
const mcpPath = path.resolve(__dirname, '..', 'mcp-reference-server', 'server');
if (!fs.existsSync(mcpPath)) {
console.log(`\n ⚠ MCP server source not found at ${mcpPath}`);
console.log(' Clone the mcp-reference-server repo alongside this project:');
console.log(' git clone https://github.com/commerce-operations-foundation/mcp-reference-server.git\n');
}
}
const { seedData } = await prompts({
type: 'confirm',
name: 'seedData',
message: 'Load sample data? (20 products, 9 orders, 6 customers)',
initial: true,
});
env.SEED_DATA = seedData ? 'true' : 'false';
}
const envContent = [
'# Generated by setup.js',
`APP_MODE=${env.APP_MODE}`,
`DATA_MODE=${env.DATA_MODE}`,
env.DATABASE_URL ? `DATABASE_URL=${env.DATABASE_URL}` : '# DATABASE_URL=',
'',
env.ANTHROPIC_API_KEY ? `ANTHROPIC_API_KEY=${env.ANTHROPIC_API_KEY}` : '# ANTHROPIC_API_KEY=',
env.OPENAI_API_KEY ? `OPENAI_API_KEY=${env.OPENAI_API_KEY}` : '# OPENAI_API_KEY=',
env.GOOGLE_AI_API_KEY ? `GOOGLE_AI_API_KEY=${env.GOOGLE_AI_API_KEY}` : '# GOOGLE_AI_API_KEY=',
env.OLLAMA_URL ? `OLLAMA_URL=${env.OLLAMA_URL}` : '# OLLAMA_URL=',
env.OLLAMA_MODEL ? `OLLAMA_MODEL=${env.OLLAMA_MODEL}` : '# OLLAMA_MODEL=',
'',
env.ONX_MCP_SERVER_URL ? `ONX_MCP_SERVER_URL=${env.ONX_MCP_SERVER_URL}` : '# ONX_MCP_SERVER_URL=',
`SEED_DATA=${env.SEED_DATA}`,
`SESSION_TTL_MINUTES=${env.SESSION_TTL_MINUTES}`,
`MAX_MESSAGES_PER_SESSION=${env.MAX_MESSAGES_PER_SESSION}`,
`PORT=${env.PORT}`,
`NODE_ENV=${env.NODE_ENV}`,
'',
].join('\n');
fs.writeFileSync(ENV_PATH, envContent);
console.log('\n .env written successfully.\n');
const profileFlags = profiles.map(p => `--profile ${p}`).join(' ');
const composeCmd = profiles.length > 0
? `docker compose ${profileFlags} up --build`
: 'docker compose up --build';
console.log(' Run this command to start:\n');
console.log(` ${composeCmd}\n`);
console.log(' Then visit:');
console.log(' App: http://localhost:3000');
console.log(' API docs: http://localhost:3000/api/docs');
console.log(' OpenAPI: http://localhost:3000/openapi.yaml');
console.log('');
}
main().catch(console.error);