clawnify 0.6.1 → 0.7.1
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.
|
@@ -28,95 +28,109 @@ import crypto from "crypto";
|
|
|
28
28
|
import http from "http";
|
|
29
29
|
import readline from "readline";
|
|
30
30
|
import open from "open";
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const url = new URL(req.url, `http://localhost:${port}`);
|
|
31
|
+
var CALLBACK_PORT = 19823;
|
|
32
|
+
var REDIRECT_URI = "https://app.clawnify.com/oauth/cli";
|
|
33
|
+
var WEB_ORIGIN = "https://app.clawnify.com";
|
|
34
|
+
function waitForCode(state) {
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
let done = false;
|
|
37
|
+
let rl = null;
|
|
38
|
+
const server = http.createServer((req, res) => {
|
|
39
|
+
const url = new URL(req.url, `http://127.0.0.1:${CALLBACK_PORT}`);
|
|
40
|
+
const corsHeaders = {
|
|
41
|
+
"Access-Control-Allow-Origin": WEB_ORIGIN,
|
|
42
|
+
"Access-Control-Allow-Methods": "GET, OPTIONS",
|
|
43
|
+
"Access-Control-Allow-Private-Network": "true"
|
|
44
|
+
};
|
|
45
|
+
if (req.method === "OPTIONS") {
|
|
46
|
+
res.writeHead(204, corsHeaders);
|
|
47
|
+
res.end();
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
51
50
|
if (url.pathname !== "/callback") {
|
|
52
|
-
res.writeHead(404);
|
|
51
|
+
res.writeHead(404, corsHeaders);
|
|
53
52
|
res.end("Not found");
|
|
54
53
|
return;
|
|
55
54
|
}
|
|
56
55
|
const code = url.searchParams.get("code");
|
|
57
56
|
const returnedState = url.searchParams.get("state");
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
res.
|
|
61
|
-
res.end(
|
|
62
|
-
"<html><body><h2>Authorization denied.</h2><p>You can close this window.</p></body></html>"
|
|
63
|
-
);
|
|
64
|
-
clearTimeout(timeout);
|
|
65
|
-
server.close();
|
|
66
|
-
reject(new Error(`Authorization denied: ${error}`));
|
|
57
|
+
if (!code || returnedState !== state) {
|
|
58
|
+
res.writeHead(400, { ...corsHeaders, "Content-Type": "application/json" });
|
|
59
|
+
res.end(JSON.stringify({ ok: false }));
|
|
67
60
|
return;
|
|
68
61
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
62
|
+
res.writeHead(200, { ...corsHeaders, "Content-Type": "application/json" });
|
|
63
|
+
res.end(JSON.stringify({ ok: true }));
|
|
64
|
+
finish(null, code);
|
|
65
|
+
});
|
|
66
|
+
const timeout = setTimeout(() => {
|
|
67
|
+
finish(new Error("Timed out waiting for authorization."));
|
|
68
|
+
}, 5 * 60 * 1e3);
|
|
69
|
+
function finish(err, code) {
|
|
70
|
+
if (done) return;
|
|
71
|
+
done = true;
|
|
72
|
+
clearTimeout(timeout);
|
|
73
|
+
server.close();
|
|
74
|
+
rl?.close();
|
|
75
|
+
if (err) reject(err);
|
|
76
|
+
else resolve(code);
|
|
77
|
+
}
|
|
78
|
+
server.on("error", () => {
|
|
79
|
+
});
|
|
80
|
+
server.listen(CALLBACK_PORT);
|
|
81
|
+
rl = readline.createInterface({
|
|
82
|
+
input: process.stdin,
|
|
83
|
+
output: process.stdout
|
|
84
|
+
});
|
|
85
|
+
rl.question("Paste code here if prompted > ", (answer) => {
|
|
86
|
+
const input = answer.trim();
|
|
87
|
+
if (!input) {
|
|
88
|
+
finish(new Error("No code provided."));
|
|
74
89
|
return;
|
|
75
90
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
body: new URLSearchParams({
|
|
81
|
-
grant_type: "authorization_code",
|
|
82
|
-
code,
|
|
83
|
-
client_id: OAUTH_CLIENT_ID,
|
|
84
|
-
redirect_uri: redirectUri,
|
|
85
|
-
code_verifier: verifier
|
|
86
|
-
})
|
|
87
|
-
});
|
|
88
|
-
if (!tokenRes.ok) {
|
|
89
|
-
const err = await tokenRes.text();
|
|
90
|
-
throw new Error(`Token exchange failed: ${err}`);
|
|
91
|
-
}
|
|
92
|
-
const tokens = await tokenRes.json();
|
|
93
|
-
res.writeHead(200, { "Content-Type": "text/html" });
|
|
94
|
-
res.end(
|
|
95
|
-
"<html><body><h2>Logged in!</h2><p>You can close this window and return to the terminal.</p></body></html>"
|
|
96
|
-
);
|
|
97
|
-
clearTimeout(timeout);
|
|
98
|
-
server.close();
|
|
99
|
-
resolve(tokens);
|
|
100
|
-
} catch (err) {
|
|
101
|
-
res.writeHead(500, { "Content-Type": "text/html" });
|
|
102
|
-
res.end(
|
|
103
|
-
"<html><body><h2>Login failed.</h2></body></html>"
|
|
104
|
-
);
|
|
105
|
-
clearTimeout(timeout);
|
|
106
|
-
server.close();
|
|
107
|
-
reject(err);
|
|
91
|
+
const [code, pastedState] = input.split("#");
|
|
92
|
+
if (!code || pastedState !== state) {
|
|
93
|
+
finish(new Error("Invalid code. Run `clawnify login` to try again."));
|
|
94
|
+
return;
|
|
108
95
|
}
|
|
96
|
+
finish(null, code);
|
|
109
97
|
});
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
async function loginCommand() {
|
|
101
|
+
const { codeVerifier: verifier, codeChallenge: challenge } = generatePkce();
|
|
102
|
+
const state = crypto.randomBytes(16).toString("hex");
|
|
103
|
+
const authUrl = new URL(OAUTH_AUTHORIZE_URL);
|
|
104
|
+
authUrl.searchParams.set("response_type", "code");
|
|
105
|
+
authUrl.searchParams.set("client_id", OAUTH_CLIENT_ID);
|
|
106
|
+
authUrl.searchParams.set("redirect_uri", REDIRECT_URI);
|
|
107
|
+
authUrl.searchParams.set("code_challenge", challenge);
|
|
108
|
+
authUrl.searchParams.set("code_challenge_method", "S256");
|
|
109
|
+
authUrl.searchParams.set("scope", "openid email");
|
|
110
|
+
authUrl.searchParams.set("state", state);
|
|
111
|
+
console.log("Opening browser to authorize...");
|
|
112
|
+
console.log("\nBrowser didn't open? Use the url below to sign in:\n");
|
|
113
|
+
console.log(` ${authUrl.toString()}
|
|
114
114
|
`);
|
|
115
|
-
|
|
116
|
-
});
|
|
117
|
-
console.log("Waiting for authorization...");
|
|
118
|
-
});
|
|
115
|
+
open(authUrl.toString()).catch(() => {
|
|
119
116
|
});
|
|
117
|
+
const code = await waitForCode(state);
|
|
118
|
+
const tokenRes = await fetch(OAUTH_TOKEN_URL, {
|
|
119
|
+
method: "POST",
|
|
120
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
121
|
+
body: new URLSearchParams({
|
|
122
|
+
grant_type: "authorization_code",
|
|
123
|
+
code,
|
|
124
|
+
client_id: OAUTH_CLIENT_ID,
|
|
125
|
+
redirect_uri: REDIRECT_URI,
|
|
126
|
+
code_verifier: verifier
|
|
127
|
+
})
|
|
128
|
+
});
|
|
129
|
+
if (!tokenRes.ok) {
|
|
130
|
+
const err = await tokenRes.text();
|
|
131
|
+
throw new Error(`Token exchange failed: ${err}`);
|
|
132
|
+
}
|
|
133
|
+
const result = await tokenRes.json();
|
|
120
134
|
let email = "unknown";
|
|
121
135
|
try {
|
|
122
136
|
const payload = JSON.parse(
|
|
@@ -131,48 +145,6 @@ async function loginCommand() {
|
|
|
131
145
|
refresh_token: result.refresh_token,
|
|
132
146
|
expires_at: expiresAt
|
|
133
147
|
});
|
|
134
|
-
let orgId;
|
|
135
|
-
try {
|
|
136
|
-
const orgsRes = await api.get("/v1/orgs");
|
|
137
|
-
if (orgsRes.ok) {
|
|
138
|
-
const { orgs } = await orgsRes.json();
|
|
139
|
-
if (orgs.length === 1) {
|
|
140
|
-
orgId = orgs[0].id;
|
|
141
|
-
console.log(`Organization: ${orgs[0].name}`);
|
|
142
|
-
} else if (orgs.length > 1) {
|
|
143
|
-
console.log("\nSelect an organization:\n");
|
|
144
|
-
orgs.forEach((org, i) => {
|
|
145
|
-
console.log(` ${i + 1}) ${org.name} (${org.role})`);
|
|
146
|
-
});
|
|
147
|
-
console.log();
|
|
148
|
-
const rl = readline.createInterface({
|
|
149
|
-
input: process.stdin,
|
|
150
|
-
output: process.stdout
|
|
151
|
-
});
|
|
152
|
-
const choice = await new Promise((resolve) => {
|
|
153
|
-
rl.question("Enter number: ", (answer) => {
|
|
154
|
-
rl.close();
|
|
155
|
-
resolve(answer.trim());
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
const index = parseInt(choice, 10) - 1;
|
|
159
|
-
if (index >= 0 && index < orgs.length) {
|
|
160
|
-
orgId = orgs[index].id;
|
|
161
|
-
console.log(`Selected: ${orgs[index].name}`);
|
|
162
|
-
} else {
|
|
163
|
-
orgId = orgs[0].id;
|
|
164
|
-
console.log(`Defaulting to: ${orgs[0].name}`);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
} catch {
|
|
169
|
-
}
|
|
170
|
-
saveAuth({
|
|
171
|
-
access_token: result.access_token,
|
|
172
|
-
refresh_token: result.refresh_token,
|
|
173
|
-
expires_at: expiresAt,
|
|
174
|
-
org_id: orgId
|
|
175
|
-
});
|
|
176
148
|
console.log(`Logged in as ${email}`);
|
|
177
149
|
}
|
|
178
150
|
|
|
@@ -874,7 +846,7 @@ function agentByName(name) {
|
|
|
874
846
|
var ALL_AGENTS = DETECTORS.map((d) => d.agent);
|
|
875
847
|
|
|
876
848
|
// src/lib/skills/content.gen.ts
|
|
877
|
-
var CLI_VERSION = "0.
|
|
849
|
+
var CLI_VERSION = "0.7.1";
|
|
878
850
|
var BUNDLED_SKILLS = [
|
|
879
851
|
{
|
|
880
852
|
name: "build-a-clawnify-app",
|
|
@@ -2883,4 +2855,4 @@ async function runCli() {
|
|
|
2883
2855
|
export {
|
|
2884
2856
|
runCli
|
|
2885
2857
|
};
|
|
2886
|
-
//# sourceMappingURL=cli-
|
|
2858
|
+
//# sourceMappingURL=cli-L7TPOLHI.js.map
|