@dubeyvishal/orbital-cli 1.2.9 → 1.3.9
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dubeyvishal/orbital-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.9",
|
|
4
4
|
"description": "A fullstack CLI-based AI platform with chat mode, multi-tool agents, and agentic AI workflows. Includes GitHub login with device authorization, secure authentication, and modular client–server architecture for building intelligent automation tools.",
|
|
5
5
|
"author": "Vishal Dubey",
|
|
6
6
|
"license": "MIT",
|
|
@@ -3,12 +3,9 @@ import { cancel, confirm, intro, outro, isCancel } from "@clack/prompts";
|
|
|
3
3
|
import chalk from "chalk";
|
|
4
4
|
import { Command } from "commander";
|
|
5
5
|
import open from "open";
|
|
6
|
-
import os from "os";
|
|
7
6
|
import path from "path";
|
|
8
7
|
import yoctoSpinner from "yocto-spinner";
|
|
9
8
|
import * as z from "zod";
|
|
10
|
-
import { createAuthClient } from "better-auth/client";
|
|
11
|
-
import { deviceAuthorizationClient } from "better-auth/client/plugins";
|
|
12
9
|
|
|
13
10
|
import { fileURLToPath } from "url";
|
|
14
11
|
import { getStoredToken, isTokenExpired, storeToken ,TOKEN_FILE } from "../../../lib/token.js";
|
|
@@ -17,12 +14,56 @@ import { apiRequestSafe } from "../../utils/apiClient.js";
|
|
|
17
14
|
import { requireGeminiApiKey } from "../../../lib/orbitalConfig.js";
|
|
18
15
|
|
|
19
16
|
|
|
20
|
-
|
|
21
17
|
const __filename = fileURLToPath(import.meta.url);
|
|
22
18
|
const __dirname = path.dirname(__filename);
|
|
23
19
|
|
|
24
20
|
const URL = API_BASE;
|
|
25
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Request a device authorization code from the server via direct fetch.
|
|
24
|
+
* Replaces: authClient.device.code()
|
|
25
|
+
*/
|
|
26
|
+
const requestDeviceCode = async (serverUrl, clientId, scope) => {
|
|
27
|
+
const res = await fetch(`${serverUrl}/api/auth/device/authorize`, {
|
|
28
|
+
method: "POST",
|
|
29
|
+
headers: { "Content-Type": "application/json" },
|
|
30
|
+
body: JSON.stringify({ client_id: clientId, scope }),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const body = await res.json();
|
|
34
|
+
|
|
35
|
+
if (!res.ok) {
|
|
36
|
+
return { data: null, error: body };
|
|
37
|
+
}
|
|
38
|
+
return { data: body, error: null };
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Poll for a device token from the server via direct fetch.
|
|
43
|
+
* Replaces: authClient.device.token()
|
|
44
|
+
*/
|
|
45
|
+
const requestDeviceToken = async (serverUrl, deviceCode, clientId) => {
|
|
46
|
+
const res = await fetch(`${serverUrl}/api/auth/device/token`, {
|
|
47
|
+
method: "POST",
|
|
48
|
+
headers: {
|
|
49
|
+
"Content-Type": "application/json",
|
|
50
|
+
"user-agent": "Orbital CLI",
|
|
51
|
+
},
|
|
52
|
+
body: JSON.stringify({
|
|
53
|
+
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
54
|
+
device_code: deviceCode,
|
|
55
|
+
client_id: clientId,
|
|
56
|
+
}),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const body = await res.json();
|
|
60
|
+
|
|
61
|
+
if (!res.ok) {
|
|
62
|
+
return { data: null, error: body };
|
|
63
|
+
}
|
|
64
|
+
return { data: body, error: null };
|
|
65
|
+
};
|
|
66
|
+
|
|
26
67
|
const resolveClientId = async (cliClientId) => {
|
|
27
68
|
const resolved = (cliClientId || "").trim();
|
|
28
69
|
if (resolved.length > 0) return resolved;
|
|
@@ -85,20 +126,16 @@ export const loginAction = async (cmdOptions) => {
|
|
|
85
126
|
}
|
|
86
127
|
}
|
|
87
128
|
|
|
88
|
-
const authClient = createAuthClient({
|
|
89
|
-
baseURL: serverUrl,
|
|
90
|
-
plugins: [deviceAuthorizationClient()],
|
|
91
|
-
});
|
|
92
|
-
|
|
93
129
|
const spinner = yoctoSpinner({
|
|
94
130
|
text: "Requesting device authorization...",
|
|
95
131
|
}).start();
|
|
96
132
|
|
|
97
133
|
try {
|
|
98
|
-
const { data, error } = await
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
134
|
+
const { data, error } = await requestDeviceCode(
|
|
135
|
+
serverUrl,
|
|
136
|
+
clientId,
|
|
137
|
+
"openid profile email",
|
|
138
|
+
);
|
|
102
139
|
|
|
103
140
|
spinner.stop();
|
|
104
141
|
|
|
@@ -150,7 +187,7 @@ export const loginAction = async (cmdOptions) => {
|
|
|
150
187
|
);
|
|
151
188
|
|
|
152
189
|
const token = await pollForToken(
|
|
153
|
-
|
|
190
|
+
serverUrl,
|
|
154
191
|
device_code,
|
|
155
192
|
clientId,
|
|
156
193
|
interval,
|
|
@@ -179,7 +216,7 @@ export const loginAction = async (cmdOptions) => {
|
|
|
179
216
|
};
|
|
180
217
|
|
|
181
218
|
const pollForToken = async (
|
|
182
|
-
|
|
219
|
+
serverUrl,
|
|
183
220
|
deviceCode,
|
|
184
221
|
clientId,
|
|
185
222
|
initialInterval,
|
|
@@ -199,16 +236,11 @@ const pollForToken = async (
|
|
|
199
236
|
if (!spinner.isSpinning) spinner.start();
|
|
200
237
|
|
|
201
238
|
try {
|
|
202
|
-
const { data, error } = await
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
headers: {
|
|
208
|
-
"user-agent": `My CLI`,
|
|
209
|
-
},
|
|
210
|
-
},
|
|
211
|
-
});
|
|
239
|
+
const { data, error } = await requestDeviceToken(
|
|
240
|
+
serverUrl,
|
|
241
|
+
deviceCode,
|
|
242
|
+
clientId,
|
|
243
|
+
);
|
|
212
244
|
|
|
213
245
|
if (data?.access_token) {
|
|
214
246
|
spinner.stop();
|
|
@@ -254,7 +286,7 @@ const pollForToken = async (
|
|
|
254
286
|
};
|
|
255
287
|
|
|
256
288
|
export const login = new Command("login")
|
|
257
|
-
.description("Login to
|
|
258
|
-
.option("--server-url <url>", "The
|
|
289
|
+
.description("Login to Orbital CLI")
|
|
290
|
+
.option("--server-url <url>", "The server URL", URL)
|
|
259
291
|
.option("--client-id <id>", "The OAuth client ID")
|
|
260
292
|
.action(loginAction);
|