@bharatpanigrahi/onw-cli 1.0.5 → 1.0.7
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 +3 -12
- package/src/cli/chat/chat-with-ai-agent.js +6 -14
- package/src/cli/chat/chat-with-ai-tool.js +6 -14
- package/src/cli/chat/chat-with-ai.js +6 -14
- package/src/cli/commands/ai/wakeUp.js +9 -22
- package/src/cli/commands/auth/login.js +12 -21
- package/src/cli/main.js +2 -2
- package/src/index.js +4 -0
- package/src/lib/api-client.js +33 -0
- package/src/routes/user.js +82 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bharatpanigrahi/onw-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "A CLI tool for Claude AI",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -10,10 +10,7 @@
|
|
|
10
10
|
"onw-cli": "./src/cli/main.js"
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
|
-
"
|
|
14
|
-
"dev": "nodemon src/index.js",
|
|
15
|
-
"start": "node src/index.js",
|
|
16
|
-
"postinstall": "npx prisma generate"
|
|
13
|
+
"start": "node src/index.js"
|
|
17
14
|
},
|
|
18
15
|
"keywords": [
|
|
19
16
|
"claude",
|
|
@@ -28,20 +25,14 @@
|
|
|
28
25
|
"@clack/prompts": "^1.1.0",
|
|
29
26
|
"@prisma/client": "^6.19.2",
|
|
30
27
|
"ai": "^6.0.141",
|
|
31
|
-
"better-auth": "^1.5.6",
|
|
32
28
|
"boxen": "^8.0.1",
|
|
33
29
|
"chalk": "^5.6.2",
|
|
34
30
|
"commandor": "^0.1.3",
|
|
35
|
-
"cors": "^2.8.6",
|
|
36
|
-
"dotenv": "^17.3.1",
|
|
37
|
-
"express": "^5.2.1",
|
|
38
31
|
"figlet": "^1.11.0",
|
|
39
32
|
"marked": "^15.0.12",
|
|
40
33
|
"marked-terminal": "^7.3.0",
|
|
41
|
-
"nodemon": "^3.1.14",
|
|
42
34
|
"open": "^11.0.0",
|
|
43
35
|
"yocto-spinner": "^1.1.0",
|
|
44
|
-
"zod": "^4.3.6"
|
|
45
|
-
"prisma": "^6.19.2"
|
|
36
|
+
"zod": "^4.3.6"
|
|
46
37
|
}
|
|
47
38
|
}
|
|
@@ -5,7 +5,7 @@ import { text, isCancel, cancel, intro, outro, confirm } from "@clack/prompts";
|
|
|
5
5
|
import { AIService } from "../ai/google-service.js";
|
|
6
6
|
import { ChatService } from "../../service/chat.service.js";
|
|
7
7
|
import { getStoredToken } from "../../lib/token.js";
|
|
8
|
-
import
|
|
8
|
+
import { fetchUserFromAPI } from "../../lib/api-client.js";
|
|
9
9
|
import { generateApplication } from "../../config/agent.config.js";
|
|
10
10
|
import { saveMessage } from "./chat-with-ai.js";
|
|
11
11
|
|
|
@@ -19,22 +19,14 @@ async function getUserFromToken() {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
const spinner = yoctoSpinner({ text: "Authenticating..." }).start();
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
if (!user) {
|
|
22
|
+
try {
|
|
23
|
+
const user = await fetchUserFromAPI(token?.access_token, true);
|
|
24
|
+
spinner.success(`Welcome back, ${user.name}!`);
|
|
25
|
+
return user;
|
|
26
|
+
} catch (error) {
|
|
32
27
|
spinner.error("User not found");
|
|
33
28
|
throw new Error("User not found please login again.");
|
|
34
29
|
}
|
|
35
|
-
|
|
36
|
-
spinner.success(`Welcome back, ${user.name}!`);
|
|
37
|
-
return user;
|
|
38
30
|
}
|
|
39
31
|
|
|
40
32
|
async function initConversation(userId, conversationId = null) {
|
|
@@ -14,7 +14,7 @@ import { markedTerminal } from "marked-terminal";
|
|
|
14
14
|
import { AIService } from "../ai/google-service.js";
|
|
15
15
|
import { ChatService } from "../../service/chat.service.js";
|
|
16
16
|
import { getStoredToken } from "../../lib/token.js";
|
|
17
|
-
import
|
|
17
|
+
import { fetchUserFromAPI } from "../../lib/api-client.js";
|
|
18
18
|
import {
|
|
19
19
|
avaiableTools,
|
|
20
20
|
enableTools,
|
|
@@ -57,22 +57,14 @@ async function getUserFromToken() {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
const spinner = yoctoSpinner({ text: "Authenticating..." }).start();
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
if (!user) {
|
|
60
|
+
try {
|
|
61
|
+
const user = await fetchUserFromAPI(token?.access_token, true);
|
|
62
|
+
spinner.success(`Welcome back, ${user.name}!`);
|
|
63
|
+
return user;
|
|
64
|
+
} catch (error) {
|
|
70
65
|
spinner.error("User not found");
|
|
71
66
|
throw new Error("User not found please login again.");
|
|
72
67
|
}
|
|
73
|
-
|
|
74
|
-
spinner.success(`Welcome back, ${user.name}!`);
|
|
75
|
-
return user;
|
|
76
68
|
}
|
|
77
69
|
|
|
78
70
|
async function selectTools() {
|
|
@@ -7,7 +7,7 @@ import { markedTerminal } from "marked-terminal";
|
|
|
7
7
|
import { ChatService } from "../../service/chat.service.js";
|
|
8
8
|
import { AIService } from "../ai/google-service.js";
|
|
9
9
|
import { getStoredToken } from "../../lib/token.js";
|
|
10
|
-
import
|
|
10
|
+
import { fetchUserFromAPI } from "../../lib/api-client.js";
|
|
11
11
|
|
|
12
12
|
marked.use(
|
|
13
13
|
markedTerminal({
|
|
@@ -38,22 +38,14 @@ async function getUserFromToken() {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
const spinner = yoctoSpinner({ text: "Authenticating..." }).start();
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
if (!user) {
|
|
41
|
+
try {
|
|
42
|
+
const user = await fetchUserFromAPI(token?.access_token, true);
|
|
43
|
+
spinner.success(`Welcome back, ${user.name}!`);
|
|
44
|
+
return user;
|
|
45
|
+
} catch (error) {
|
|
51
46
|
spinner.error("User not found");
|
|
52
47
|
throw new Error("User not found please login again.");
|
|
53
48
|
}
|
|
54
|
-
|
|
55
|
-
spinner.success(`Welcome back, ${user.name}!`);
|
|
56
|
-
return user;
|
|
57
49
|
}
|
|
58
50
|
|
|
59
51
|
export function displayMessages(messages) {
|
|
@@ -3,7 +3,7 @@ import { Command } from "commander";
|
|
|
3
3
|
import yoctoSpinner from "yocto-spinner";
|
|
4
4
|
import { select } from "@clack/prompts";
|
|
5
5
|
import { getStoredToken } from "../../../lib/token.js";
|
|
6
|
-
import
|
|
6
|
+
import { fetchUserFromAPI } from "../../../lib/api-client.js";
|
|
7
7
|
import { startChat } from "../../chat/chat-with-ai.js";
|
|
8
8
|
import { startToolChat } from "../../chat/chat-with-ai-tool.js";
|
|
9
9
|
import { startAgentChat } from "../../chat/chat-with-ai-agent.js";
|
|
@@ -19,30 +19,17 @@ const wakeUpAction = async () => {
|
|
|
19
19
|
const spinner = yoctoSpinner({ text: "Fetching user information" });
|
|
20
20
|
spinner.start();
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
sessions: {
|
|
25
|
-
some: {
|
|
26
|
-
token: token?.access_token,
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
select: {
|
|
31
|
-
id: true,
|
|
32
|
-
name: true,
|
|
33
|
-
email: true,
|
|
34
|
-
image: true,
|
|
35
|
-
},
|
|
36
|
-
});
|
|
22
|
+
try {
|
|
23
|
+
const user = await fetchUserFromAPI(token?.access_token, false);
|
|
37
24
|
|
|
38
|
-
|
|
25
|
+
spinner.stop();
|
|
39
26
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
27
|
+
if (!user) {
|
|
28
|
+
console.log(chalk.red("User not found"));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
44
31
|
|
|
45
|
-
|
|
32
|
+
console.log(chalk.green(`Welcome back, ${user.name}!\n`));
|
|
46
33
|
|
|
47
34
|
const choice = await select({
|
|
48
35
|
message: "Select an Option",
|
|
@@ -11,7 +11,7 @@ import os from "os";
|
|
|
11
11
|
import path from "path";
|
|
12
12
|
import yoctoSpinner from "yocto-spinner";
|
|
13
13
|
import * as z from "zod/v4";
|
|
14
|
-
import
|
|
14
|
+
import { fetchUserFromAPI } from "../../../lib/api-client.js";
|
|
15
15
|
import dotenv from "dotenv";
|
|
16
16
|
import {
|
|
17
17
|
clearStoredToken,
|
|
@@ -248,27 +248,18 @@ export async function whoamiAction(opts) {
|
|
|
248
248
|
process.exit(1);
|
|
249
249
|
}
|
|
250
250
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
sessions: {
|
|
254
|
-
some: {
|
|
255
|
-
token: token.access_token,
|
|
256
|
-
},
|
|
257
|
-
},
|
|
258
|
-
},
|
|
259
|
-
select: {
|
|
260
|
-
id: true,
|
|
261
|
-
name: true,
|
|
262
|
-
email: true,
|
|
263
|
-
image: true,
|
|
264
|
-
},
|
|
265
|
-
});
|
|
251
|
+
try {
|
|
252
|
+
const user = await fetchUserFromAPI(token.access_token, false);
|
|
266
253
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
254
|
+
console.log(
|
|
255
|
+
chalk.bold.greenBright(
|
|
256
|
+
`\n👤 User: ${user.name} Email: ${user.email} ID: ${user.id}`,
|
|
257
|
+
),
|
|
258
|
+
);
|
|
259
|
+
} catch (error) {
|
|
260
|
+
console.log(chalk.red(`Error fetching user: ${error.message}`));
|
|
261
|
+
process.exit(1);
|
|
262
|
+
}
|
|
272
263
|
}
|
|
273
264
|
|
|
274
265
|
export const login = new Command("login")
|
package/src/cli/main.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import dotenv from "dotenv";
|
|
3
|
+
// import dotenv from "dotenv";
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
import figlet from "figlet";
|
|
6
6
|
import { Command } from "commander";
|
|
7
7
|
import { login, logout, whoami } from "./commands/auth/login.js";
|
|
8
8
|
import { wakeUp } from "./commands/ai/wakeUp.js";
|
|
9
9
|
|
|
10
|
-
dotenv.config();
|
|
10
|
+
// dotenv.config();
|
|
11
11
|
|
|
12
12
|
async function main() {
|
|
13
13
|
// Display banner
|
package/src/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import cors from "cors";
|
|
|
3
3
|
import { toNodeHandler } from "better-auth/node";
|
|
4
4
|
import dotenv from "dotenv";
|
|
5
5
|
import { auth } from "./lib/auth.js";
|
|
6
|
+
import userRoutes from "./routes/user.js";
|
|
6
7
|
|
|
7
8
|
dotenv.config();
|
|
8
9
|
const app = express();
|
|
@@ -20,6 +21,9 @@ app.all("/api/auth/*splat", toNodeHandler(auth));
|
|
|
20
21
|
|
|
21
22
|
app.use(express.json());
|
|
22
23
|
|
|
24
|
+
// User API routes
|
|
25
|
+
app.use("/api/user", userRoutes);
|
|
26
|
+
|
|
23
27
|
const PORT = process.env.PORT || 3000;
|
|
24
28
|
|
|
25
29
|
app.get("/", (req, res) => {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import dotenv from "dotenv";
|
|
2
|
+
|
|
3
|
+
dotenv.config();
|
|
4
|
+
|
|
5
|
+
const API_BASE_URL = "https://claude-code-topaz.vercel.app";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Fetch user data from the backend API using access token
|
|
9
|
+
* @param {string} token - The access token from session
|
|
10
|
+
* @param {boolean} fullUser - If true, returns full user object. If false, returns selective fields
|
|
11
|
+
* @returns {Promise<Object>} User object
|
|
12
|
+
*/
|
|
13
|
+
export async function fetchUserFromAPI(token, fullUser = false) {
|
|
14
|
+
if (!token) {
|
|
15
|
+
throw new Error("No token provided");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
const endpoint = fullUser ? "/api/user/me/full" : "/api/user/me";
|
|
20
|
+
const response = await fetch(`${API_BASE_URL}${endpoint}?token=${token}`);
|
|
21
|
+
|
|
22
|
+
if (!response.ok) {
|
|
23
|
+
const errorData = await response.json();
|
|
24
|
+
throw new Error(errorData.error || "Failed to fetch user");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const user = await response.json();
|
|
28
|
+
return user;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error("Error fetching user from API:", error.message);
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import prisma from "../lib/db.js";
|
|
2
|
+
import { Router } from "express";
|
|
3
|
+
|
|
4
|
+
const router = Router();
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* GET /api/user/me
|
|
8
|
+
* Get current user from session token
|
|
9
|
+
* Query params: token (access token from session)
|
|
10
|
+
* Returns: User object { id, name, email, image }
|
|
11
|
+
*/
|
|
12
|
+
router.get("/me", async (req, res) => {
|
|
13
|
+
try {
|
|
14
|
+
const { token } = req.query;
|
|
15
|
+
|
|
16
|
+
if (!token) {
|
|
17
|
+
return res.status(401).json({ error: "No token provided" });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const user = await prisma.user.findFirst({
|
|
21
|
+
where: {
|
|
22
|
+
sessions: {
|
|
23
|
+
some: {
|
|
24
|
+
token: token,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
select: {
|
|
29
|
+
id: true,
|
|
30
|
+
name: true,
|
|
31
|
+
email: true,
|
|
32
|
+
image: true,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
if (!user) {
|
|
37
|
+
return res.status(401).json({ error: "User not found" });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
res.json(user);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
console.error("Error fetching user:", error);
|
|
43
|
+
res.status(500).json({ error: "Internal server error" });
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* GET /api/user/me/full
|
|
49
|
+
* Get full current user object from session token (with all fields)
|
|
50
|
+
* Query params: token (access token from session)
|
|
51
|
+
* Returns: Full User object
|
|
52
|
+
*/
|
|
53
|
+
router.get("/me/full", async (req, res) => {
|
|
54
|
+
try {
|
|
55
|
+
const { token } = req.query;
|
|
56
|
+
|
|
57
|
+
if (!token) {
|
|
58
|
+
return res.status(401).json({ error: "No token provided" });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const user = await prisma.user.findFirst({
|
|
62
|
+
where: {
|
|
63
|
+
sessions: {
|
|
64
|
+
some: {
|
|
65
|
+
token: token,
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
if (!user) {
|
|
72
|
+
return res.status(401).json({ error: "User not found" });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
res.json(user);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.error("Error fetching user:", error);
|
|
78
|
+
res.status(500).json({ error: "Internal server error" });
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
export default router;
|