@dccxx/auggiegw 1.0.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.
package/.env ADDED
@@ -0,0 +1,2 @@
1
+ AUGMENT_GATEWAY_URL=https://augmentgateway.1app.space
2
+
package/.env.example ADDED
@@ -0,0 +1,2 @@
1
+ AUGMENT_GATEWAY_URL=https://augmentgateway.1app.space
2
+
package/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # @dccxx/auggiegw
2
+
3
+ A Node.js TypeScript package with CLI support.
4
+
5
+ ## Installation
6
+
7
+ Install dependencies:
8
+
9
+ ```bash
10
+ bun install
11
+ ```
12
+
13
+ ## Development
14
+
15
+ Build the project:
16
+
17
+ ```bash
18
+ bun run build
19
+ ```
20
+
21
+ Run linter:
22
+
23
+ ```bash
24
+ bun run lint
25
+ ```
26
+
27
+ Clean build artifacts:
28
+
29
+ ```bash
30
+ bun run clean
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ ### As a CLI tool
36
+
37
+ After building, you can run the CLI command:
38
+
39
+ ```bash
40
+ node dist/cli.js
41
+ ```
42
+
43
+ Or if installed globally:
44
+
45
+ ```bash
46
+ auggiegw
47
+ ```
48
+
49
+ ### As a library
50
+
51
+ Import and use in your Node.js project:
52
+
53
+ ```typescript
54
+ import '@dccxx/auggiegw';
55
+ ```
56
+
57
+ ## Project Structure
58
+
59
+ - `src/` - TypeScript source files
60
+ - `dist/` - Compiled JavaScript output (generated by build)
61
+ - `tsconfig.json` - TypeScript configuration
62
+ - `biome.json` - Biome linter configuration
63
+
64
+ ## Requirements
65
+
66
+ - Node.js >= 18.0.0
67
+ - Bun (for package management and running scripts)
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
package/dist/cli.js ADDED
@@ -0,0 +1,302 @@
1
+ #!/usr/bin/env node
2
+ import { exec } from 'node:child_process';
3
+ import * as fs from 'node:fs/promises';
4
+ import * as os from 'node:os';
5
+ import * as path from 'node:path';
6
+ import * as readline from 'node:readline/promises';
7
+ import { promisify } from 'node:util';
8
+ import { Command } from 'commander';
9
+ const execAsync = promisify(exec);
10
+ const AUTH_DIR = path.join(os.homedir(), '.auggiegw');
11
+ const AUTH_FILE = path.join(AUTH_DIR, 'auth.json');
12
+ const AUGMENT_DIR = path.join(os.homedir(), '.augment');
13
+ const AUGMENT_SESSION_FILE = path.join(AUGMENT_DIR, 'session.json');
14
+ const AUGMENT_COMMANDS_DIR = path.join(AUGMENT_DIR, 'commands');
15
+ function loadConfig() {
16
+ const apiUrl = process.env.AUGMENT_GATEWAY_URL || 'https://augmentgateway.1app.space';
17
+ return { apiUrl };
18
+ }
19
+ async function ensureAuthDirectory() {
20
+ try {
21
+ await fs.mkdir(AUTH_DIR, { recursive: true });
22
+ }
23
+ catch (error) {
24
+ throw new Error(`Failed to create auth directory: ${error}`);
25
+ }
26
+ }
27
+ async function saveAuthData(data) {
28
+ await ensureAuthDirectory();
29
+ await fs.writeFile(AUTH_FILE, JSON.stringify(data, null, 2), 'utf-8');
30
+ }
31
+ async function loadAuthData() {
32
+ try {
33
+ const data = await fs.readFile(AUTH_FILE, 'utf-8');
34
+ return JSON.parse(data);
35
+ }
36
+ catch (error) {
37
+ if (error.code === 'ENOENT') {
38
+ throw new Error('Not logged in. Please run "auggiegw login" first.');
39
+ }
40
+ throw new Error(`Failed to load auth data: ${error}`);
41
+ }
42
+ }
43
+ async function deleteAuthData() {
44
+ try {
45
+ await fs.unlink(AUTH_FILE);
46
+ }
47
+ catch (error) {
48
+ if (error.code !== 'ENOENT') {
49
+ throw new Error(`Failed to delete auth file: ${error}`);
50
+ }
51
+ }
52
+ }
53
+ async function saveAugmentSession(session) {
54
+ try {
55
+ await fs.mkdir(AUGMENT_DIR, { recursive: true });
56
+ await fs.writeFile(AUGMENT_SESSION_FILE, JSON.stringify(session, null, 2), 'utf-8');
57
+ }
58
+ catch (error) {
59
+ throw new Error(`Failed to save Augment session: ${error}`);
60
+ }
61
+ }
62
+ async function getPrompts(token, apiUrl, page, limit) {
63
+ const response = await fetch(`${apiUrl}/prompts?page=${page}&limit=${limit}`, {
64
+ method: 'GET',
65
+ headers: {
66
+ Authorization: `Bearer ${token}`,
67
+ },
68
+ });
69
+ if (!response.ok) {
70
+ throw new Error(`HTTP error! status: ${response.status}`);
71
+ }
72
+ const data = (await response.json());
73
+ if (!data.success) {
74
+ throw new Error('Failed to get prompts');
75
+ }
76
+ return data;
77
+ }
78
+ async function getAllPrompts(token, apiUrl) {
79
+ const allPrompts = [];
80
+ const limit = 10;
81
+ let currentPage = 1;
82
+ let hasMorePages = true;
83
+ while (hasMorePages) {
84
+ console.log(`Fetching prompts page ${currentPage}...`);
85
+ const response = await getPrompts(token, apiUrl, currentPage, limit);
86
+ if (response.data.prompts && response.data.prompts.length > 0) {
87
+ allPrompts.push(...response.data.prompts);
88
+ if (response.data.totalPages) {
89
+ hasMorePages = currentPage < response.data.totalPages;
90
+ }
91
+ else if (response.data.total) {
92
+ const calculatedTotalPages = Math.ceil(response.data.total / limit);
93
+ hasMorePages = currentPage < calculatedTotalPages;
94
+ }
95
+ else {
96
+ hasMorePages = response.data.prompts.length === limit;
97
+ }
98
+ if (hasMorePages) {
99
+ await new Promise((resolve) => setTimeout(resolve, 500));
100
+ }
101
+ currentPage++;
102
+ }
103
+ else {
104
+ hasMorePages = false;
105
+ }
106
+ }
107
+ return allPrompts;
108
+ }
109
+ async function savePromptToFile(prompt) {
110
+ try {
111
+ await fs.mkdir(AUGMENT_COMMANDS_DIR, { recursive: true });
112
+ const markdownContent = `---
113
+ description: ${prompt.name}
114
+ ---
115
+
116
+ ${prompt.content}`;
117
+ const filePath = path.join(AUGMENT_COMMANDS_DIR, `${prompt.command}.md`);
118
+ await fs.writeFile(filePath, markdownContent, 'utf-8');
119
+ }
120
+ catch (error) {
121
+ throw new Error(`Failed to save prompt file for command '${prompt.command}': ${error}`);
122
+ }
123
+ }
124
+ async function promptInput(question, hidden = false) {
125
+ const rl = readline.createInterface({
126
+ input: process.stdin,
127
+ output: process.stdout,
128
+ });
129
+ if (hidden) {
130
+ const originalWrite = process.stdout.write.bind(process.stdout);
131
+ process.stdout.write = (chunk, encoding, callback) => {
132
+ if (chunk.toString().includes(question)) {
133
+ return originalWrite(chunk, encoding, callback);
134
+ }
135
+ return true;
136
+ };
137
+ const answer = await rl.question(question);
138
+ process.stdout.write = originalWrite;
139
+ process.stdout.write('\n');
140
+ rl.close();
141
+ return answer;
142
+ }
143
+ const answer = await rl.question(question);
144
+ rl.close();
145
+ return answer;
146
+ }
147
+ async function loginToApi(username, password, apiUrl) {
148
+ const response = await fetch(`${apiUrl}/api/login`, {
149
+ method: 'POST',
150
+ headers: {
151
+ 'Content-Type': 'application/json',
152
+ },
153
+ body: JSON.stringify({ username, password }),
154
+ });
155
+ if (!response.ok) {
156
+ throw new Error(`HTTP error! status: ${response.status}`);
157
+ }
158
+ const data = (await response.json());
159
+ if (!data.success) {
160
+ throw new Error(data.message || 'Login failed');
161
+ }
162
+ return data;
163
+ }
164
+ async function getProxy(token, apiUrl) {
165
+ const response = await fetch(`${apiUrl}/proxy`, {
166
+ method: 'POST',
167
+ headers: {
168
+ Authorization: `Bearer ${token}`,
169
+ },
170
+ });
171
+ if (!response.ok) {
172
+ throw new Error(`HTTP error! status: ${response.status}`);
173
+ }
174
+ const data = (await response.json());
175
+ if (!data.success) {
176
+ throw new Error(data.message || 'Failed to get proxy');
177
+ }
178
+ return data;
179
+ }
180
+ async function authProxy(proxyId, proxyPassword, apiUrl) {
181
+ const requestBody = {
182
+ proxyId,
183
+ proxyPassword,
184
+ ipv4: '',
185
+ };
186
+ const response = await fetch(`${apiUrl}/api/proxy-auth`, {
187
+ method: 'POST',
188
+ headers: {
189
+ 'Content-Type': 'application/json',
190
+ },
191
+ body: JSON.stringify(requestBody),
192
+ });
193
+ if (!response.ok) {
194
+ throw new Error(`HTTP error! status: ${response.status}`);
195
+ }
196
+ const data = (await response.json());
197
+ return data;
198
+ }
199
+ async function handleLogin() {
200
+ try {
201
+ const config = loadConfig();
202
+ const username = await promptInput('Username: ');
203
+ const password = await promptInput('Password: ', true);
204
+ if (!username || !password) {
205
+ console.error('Error: Username and password are required');
206
+ process.exit(1);
207
+ }
208
+ console.log('Authenticating...');
209
+ const loginResponse = await loginToApi(username, password, config.apiUrl);
210
+ const authData = {
211
+ username,
212
+ token: loginResponse.data.token,
213
+ user: loginResponse.data.user,
214
+ };
215
+ await saveAuthData(authData);
216
+ console.log('Login successful! Token saved.');
217
+ console.log(`Welcome, ${loginResponse.data.user.display_name}!`);
218
+ }
219
+ catch (error) {
220
+ console.error(`Login failed: ${error}`);
221
+ process.exit(1);
222
+ }
223
+ }
224
+ async function handleLogout() {
225
+ try {
226
+ await deleteAuthData();
227
+ console.log('Logout successful! Credentials removed.');
228
+ }
229
+ catch (error) {
230
+ console.error(`Logout failed: ${error}`);
231
+ process.exit(1);
232
+ }
233
+ }
234
+ async function handleFetch() {
235
+ try {
236
+ const config = loadConfig();
237
+ const authData = await loadAuthData();
238
+ console.log('Fetching proxy configuration...');
239
+ const proxyResponse = await getProxy(authData.token, config.apiUrl);
240
+ if (!proxyResponse.data || proxyResponse.data.length === 0) {
241
+ console.error('Error: No proxy data available');
242
+ process.exit(1);
243
+ }
244
+ const firstProxy = proxyResponse.data[0];
245
+ if (!firstProxy) {
246
+ console.error('Error: No proxy data available');
247
+ process.exit(1);
248
+ }
249
+ const proxyId = firstProxy.http_user;
250
+ const rawPassword = firstProxy.http_password;
251
+ const atIndex = rawPassword.indexOf('@');
252
+ if (atIndex === -1) {
253
+ console.error('Error: Invalid proxy password format');
254
+ process.exit(1);
255
+ }
256
+ const proxyPassword = rawPassword.substring(0, atIndex);
257
+ console.log('Authenticating proxy...');
258
+ const authResponse = await authProxy(proxyId, proxyPassword, config.apiUrl);
259
+ if (authResponse.success && authResponse.data) {
260
+ const augmentSession = {
261
+ accessToken: authResponse.data.token,
262
+ tenantURL: authResponse.data.tenantUrl,
263
+ scopes: ['read', 'write'],
264
+ };
265
+ await saveAugmentSession(augmentSession);
266
+ try {
267
+ await execAsync('auggie session delete');
268
+ console.log('Session configured successfully');
269
+ }
270
+ catch (error) {
271
+ console.warn(`Warning: Failed to run auggie session delete: ${error.message}`);
272
+ }
273
+ console.log('Fetching prompts...');
274
+ const allPrompts = await getAllPrompts(authData.token, config.apiUrl);
275
+ if (allPrompts.length > 0) {
276
+ console.log(`Saving ${allPrompts.length} prompts...`);
277
+ for (const prompt of allPrompts) {
278
+ await savePromptToFile(prompt);
279
+ console.log(`Saved: ${prompt.command}.md`);
280
+ }
281
+ console.log('All prompts saved successfully');
282
+ }
283
+ else {
284
+ console.log('No prompts found');
285
+ }
286
+ }
287
+ }
288
+ catch (error) {
289
+ console.error(`Fetch failed: ${error}`);
290
+ process.exit(1);
291
+ }
292
+ }
293
+ const program = new Command();
294
+ program.name('auggiegw').description('CLI tool for auggiegw authentication').version('1.0.0');
295
+ program.command('login').description('Login and store credentials').action(handleLogin);
296
+ program.command('logout').description('Logout and remove stored credentials').action(handleLogout);
297
+ program
298
+ .command('fetch')
299
+ .description('Fetch proxy configuration and authenticate')
300
+ .action(handleFetch);
301
+ program.parse();
302
+ //# sourceMappingURL=cli.js.map
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@dccxx/auggiegw",
3
+ "version": "1.0.1",
4
+ "description": "A Node.js TypeScript package",
5
+ "main": "./dist/cli.js",
6
+ "types": "./dist/cli.d.ts",
7
+ "type": "module",
8
+ "bin": {
9
+ "auggiegw": "./dist/cli.js"
10
+ },
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "lint": "bunx biome check --write",
14
+ "clean": "rm -rf dist",
15
+ "publish": "npm publish --access public",
16
+ "dev:login": "bun run src/cli.ts login",
17
+ "dev:fetch": "bun run src/cli.ts fetch"
18
+ },
19
+ "devDependencies": {
20
+ "@biomejs/biome": "2.2.5",
21
+ "@types/node": "^24.7.0",
22
+ "typescript": "^5.9.3"
23
+ },
24
+ "engines": {
25
+ "node": ">=18.0.0"
26
+ },
27
+ "dependencies": {
28
+ "commander": "^14.0.1"
29
+ }
30
+ }