upfynai-code 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/server/cli.js +2 -2
- package/server/database/db.js +2 -2
- package/server/index.js +1 -1
- package/server/mcp-server.js +3 -3
- package/server/middleware/auth.js +12 -1
- package/server/relay-client.js +2 -2
package/package.json
CHANGED
package/server/cli.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
3
|
* Upfyn-Code CLI
|
|
4
4
|
* by Thinqmesh Technologies
|
|
@@ -184,7 +184,7 @@ Options:
|
|
|
184
184
|
Examples:
|
|
185
185
|
$ uc # Start with defaults
|
|
186
186
|
$ uc --port 8080 # Start on port 8080
|
|
187
|
-
$ uc connect --key
|
|
187
|
+
$ uc connect --key upfyn_xxx # Bridge to hosted server
|
|
188
188
|
$ uc start --port 4000 # Explicit start command
|
|
189
189
|
$ uc status # Show configuration
|
|
190
190
|
|
package/server/database/db.js
CHANGED
|
@@ -220,7 +220,7 @@ const runMigrations = async () => {
|
|
|
220
220
|
// Relay token
|
|
221
221
|
const tokens = await db.execute({ sql: 'SELECT id FROM relay_tokens WHERE user_id = ? LIMIT 1', args: [user.id] });
|
|
222
222
|
if (tokens.rows.length === 0) {
|
|
223
|
-
const token = '
|
|
223
|
+
const token = 'upfyn_' + crypto.randomBytes(32).toString('hex');
|
|
224
224
|
await db.execute({ sql: 'INSERT INTO relay_tokens (user_id, token, name) VALUES (?, ?, ?)', args: [user.id, token, 'default'] });
|
|
225
225
|
backfilled++;
|
|
226
226
|
}
|
|
@@ -567,7 +567,7 @@ const paymentDb = {
|
|
|
567
567
|
// ─── Relay Tokens DB ────────────────────────────────────────────────────────────
|
|
568
568
|
|
|
569
569
|
const relayTokensDb = {
|
|
570
|
-
generateToken: () => '
|
|
570
|
+
generateToken: () => 'upfyn_' + crypto.randomBytes(32).toString('hex'),
|
|
571
571
|
|
|
572
572
|
createToken: async (userId, name = 'default') => {
|
|
573
573
|
const token = relayTokensDb.generateToken();
|
package/server/index.js
CHANGED
|
@@ -1228,7 +1228,7 @@ function handleChatConnection(ws) {
|
|
|
1228
1228
|
// Handle relay WebSocket connections (local machine ↔ server bridge)
|
|
1229
1229
|
async function handleRelayConnection(ws, token) {
|
|
1230
1230
|
if (!token) {
|
|
1231
|
-
ws.send(JSON.stringify({ type: 'error', error: 'Relay token required. Use ?token=
|
|
1231
|
+
ws.send(JSON.stringify({ type: 'error', error: 'Relay token required. Use ?token=upfyn_xxx' }));
|
|
1232
1232
|
ws.close();
|
|
1233
1233
|
return;
|
|
1234
1234
|
}
|
package/server/mcp-server.js
CHANGED
|
@@ -474,12 +474,12 @@ export async function mountMcpServer(app, mcpServer, mcpServerFactory) {
|
|
|
474
474
|
} catch (e) { /* fall through */ }
|
|
475
475
|
}
|
|
476
476
|
|
|
477
|
-
// 2. Try Bearer token — supports JWT, relay token (rt_), or API key (up-cli-)
|
|
477
|
+
// 2. Try Bearer token — supports JWT, relay token (upfyn_/rt_), or API key (up-cli-)
|
|
478
478
|
const authHeader = req.headers['authorization'];
|
|
479
479
|
const token = authHeader && authHeader.split(' ')[1];
|
|
480
480
|
if (token) {
|
|
481
|
-
// 2a. Relay token (rt_xxx) — same token used for CLI connect
|
|
482
|
-
if (token.startsWith('rt_')) {
|
|
481
|
+
// 2a. Relay token (upfyn_xxx or legacy rt_xxx) — same token used for CLI connect
|
|
482
|
+
if (token.startsWith('upfyn_') || token.startsWith('rt_')) {
|
|
483
483
|
try {
|
|
484
484
|
const tokenData = await relayTokensDb.validateToken(token);
|
|
485
485
|
if (tokenData) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import jwt from 'jsonwebtoken';
|
|
2
|
-
import { userDb } from '../database/db.js';
|
|
2
|
+
import { userDb, relayTokensDb } from '../database/db.js';
|
|
3
3
|
import { IS_PLATFORM } from '../constants/config.js';
|
|
4
4
|
|
|
5
5
|
const JWT_SECRET = process.env.JWT_SECRET?.trim();
|
|
@@ -127,6 +127,17 @@ const authenticateWebSocket = async (request) => {
|
|
|
127
127
|
|
|
128
128
|
if (!token) return null;
|
|
129
129
|
|
|
130
|
+
// Relay token (upfyn_ prefix) — validate against DB, not JWT
|
|
131
|
+
if (token.startsWith('upfyn_') || token.startsWith('rt_')) {
|
|
132
|
+
try {
|
|
133
|
+
const tokenData = await relayTokensDb.validateToken(token);
|
|
134
|
+
if (tokenData) {
|
|
135
|
+
return { userId: Number(tokenData.user_id), username: tokenData.username };
|
|
136
|
+
}
|
|
137
|
+
} catch {}
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
|
|
130
141
|
try {
|
|
131
142
|
const decoded = jwt.verify(token, JWT_SECRET);
|
|
132
143
|
// Validate against Turso — DB is source of truth
|
package/server/relay-client.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* Bridges Claude CLI, terminal, filesystem, and git to the web UI.
|
|
7
7
|
*
|
|
8
8
|
* Usage:
|
|
9
|
-
* upfynai-code connect --server https://upfynai.thinqmesh.com --key
|
|
9
|
+
* upfynai-code connect --server https://upfynai.thinqmesh.com --key upfyn_xxx
|
|
10
10
|
* upfynai-code connect (uses saved config from ~/.upfynai/config.json)
|
|
11
11
|
*/
|
|
12
12
|
|
|
@@ -217,7 +217,7 @@ export async function connectToServer(options = {}) {
|
|
|
217
217
|
if (!relayKey) {
|
|
218
218
|
console.error(c.red('No relay key provided.'));
|
|
219
219
|
console.log('Generate a relay token from Settings > Relay Tokens in the web UI.');
|
|
220
|
-
console.log(`Then run: ${c.cyan('upfynai-code connect --key
|
|
220
|
+
console.log(`Then run: ${c.cyan('upfynai-code connect --key upfyn_your_token_here')}`);
|
|
221
221
|
process.exit(1);
|
|
222
222
|
}
|
|
223
223
|
|