@boostyourleads/antigravity-sdk 1.0.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/dist/cli.d.ts +2 -0
- package/dist/cli.js +111 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +94 -0
- package/package.json +24 -0
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const http_1 = __importDefault(require("http"));
|
|
8
|
+
const url_1 = __importDefault(require("url"));
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const os_1 = __importDefault(require("os"));
|
|
12
|
+
const axios_1 = __importDefault(require("axios"));
|
|
13
|
+
const child_process_1 = require("child_process");
|
|
14
|
+
const PORTAL_URL = 'https://agents.boostyourleads.ca';
|
|
15
|
+
const BACKEND_URL = 'https://back-end.boostyourleads.ca';
|
|
16
|
+
const CLIENT_ID = 'antigravity-sdk';
|
|
17
|
+
const showUsage = () => {
|
|
18
|
+
console.log("BoostYourLeads CLI Agent SDK Helper");
|
|
19
|
+
console.log("Usage:");
|
|
20
|
+
console.log(" npx byl-sdk login Authenticate your local environment");
|
|
21
|
+
};
|
|
22
|
+
const handleLogin = async () => {
|
|
23
|
+
const port = 3000;
|
|
24
|
+
const redirectUri = `http://localhost:${port}/callback`;
|
|
25
|
+
const authorizeUrl = `${PORTAL_URL}/oauth/authorize?client_id=${CLIENT_ID}&redirect_uri=${encodeURIComponent(redirectUri)}&state=cli`;
|
|
26
|
+
console.log("Opening browser to authorize Antigravity SDK connection...");
|
|
27
|
+
console.log(`URL: ${authorizeUrl}\n`);
|
|
28
|
+
// Spawns native OS open command to open default browser
|
|
29
|
+
const platform = process.platform;
|
|
30
|
+
if (platform === 'darwin') {
|
|
31
|
+
(0, child_process_1.exec)(`open "${authorizeUrl}"`);
|
|
32
|
+
}
|
|
33
|
+
else if (platform === 'win32') {
|
|
34
|
+
(0, child_process_1.exec)(`start "" "${authorizeUrl}"`);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
(0, child_process_1.exec)(`xdg-open "${authorizeUrl}"`);
|
|
38
|
+
}
|
|
39
|
+
const server = http_1.default.createServer(async (req, res) => {
|
|
40
|
+
const parsedUrl = url_1.default.parse(req.url || '', true);
|
|
41
|
+
if (parsedUrl.pathname === '/callback') {
|
|
42
|
+
const code = parsedUrl.query.code;
|
|
43
|
+
if (!code) {
|
|
44
|
+
res.writeHead(400, { 'Content-Type': 'text/html' });
|
|
45
|
+
res.end("<h3>Authentication Failed: Missing authorization code</h3>");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
// Exchange Auth Code for long-lived Access Token
|
|
50
|
+
const tokenRes = await axios_1.default.post(`${BACKEND_URL}/oauth/token`, {
|
|
51
|
+
grant_type: 'authorization_code',
|
|
52
|
+
code,
|
|
53
|
+
client_id: CLIENT_ID,
|
|
54
|
+
client_secret: 'byl_antigravity_secret_2026',
|
|
55
|
+
redirect_uri: redirectUri
|
|
56
|
+
});
|
|
57
|
+
const { access_token } = tokenRes.data;
|
|
58
|
+
// Save token locally in ~/.boostyourleads/config.json
|
|
59
|
+
const configDir = path_1.default.join(os_1.default.homedir(), '.boostyourleads');
|
|
60
|
+
if (!fs_1.default.existsSync(configDir)) {
|
|
61
|
+
fs_1.default.mkdirSync(configDir, { recursive: true });
|
|
62
|
+
}
|
|
63
|
+
const configPath = path_1.default.join(configDir, 'config.json');
|
|
64
|
+
fs_1.default.writeFileSync(configPath, JSON.stringify({ accessToken: access_token }, null, 2), {
|
|
65
|
+
mode: 0o600 // Read/Write only by owner
|
|
66
|
+
});
|
|
67
|
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
68
|
+
res.end(`
|
|
69
|
+
<div style="font-family: Outfit, sans-serif; background-color: #09090b; color: white; min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;">
|
|
70
|
+
<h2 style="color: #10b981; margin-bottom: 8px;">Authentication Successful!</h2>
|
|
71
|
+
<p style="color: #a1a1aa; font-size: 14px; margin-bottom: 24px;">The Antigravity SDK has been configured on your local machine.</p>
|
|
72
|
+
<p style="color: #71717a; font-size: 11px;">You can now close this tab and return to your terminal.</p>
|
|
73
|
+
</div>
|
|
74
|
+
`);
|
|
75
|
+
console.log("✅ Successfully authenticated! Config saved to ~/.boostyourleads/config.json");
|
|
76
|
+
// Graceful shut down
|
|
77
|
+
setTimeout(() => {
|
|
78
|
+
server.close();
|
|
79
|
+
process.exit(0);
|
|
80
|
+
}, 1000);
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
const errMsg = err.response?.data?.error_description || err.message;
|
|
84
|
+
res.writeHead(500, { 'Content-Type': 'text/html' });
|
|
85
|
+
res.end(`<h3>Authentication Failed during token exchange: ${errMsg}</h3>`);
|
|
86
|
+
console.error(`❌ Token exchange error: ${errMsg}`);
|
|
87
|
+
setTimeout(() => {
|
|
88
|
+
server.close();
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}, 1000);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
|
95
|
+
res.end("Not Found");
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
server.listen(port, () => {
|
|
99
|
+
console.log(`Listening for local callback on port ${port}...`);
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
const main = () => {
|
|
103
|
+
const args = process.argv.slice(2);
|
|
104
|
+
if (args[0] === 'login') {
|
|
105
|
+
handleLogin();
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
showUsage();
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
main();
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface AntigravityAgentConfig {
|
|
2
|
+
apiKey?: string;
|
|
3
|
+
backendUrl?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare class AntigravityAgent {
|
|
6
|
+
private apiKey;
|
|
7
|
+
private backendUrl;
|
|
8
|
+
constructor(config?: AntigravityAgentConfig);
|
|
9
|
+
private getHeaders;
|
|
10
|
+
/**
|
|
11
|
+
* Run budget optimizer agent on the backend
|
|
12
|
+
*/
|
|
13
|
+
optimizeCampaigns(): Promise<any>;
|
|
14
|
+
/**
|
|
15
|
+
* Run performance auditor agent on the backend
|
|
16
|
+
*/
|
|
17
|
+
auditPerformance(): Promise<any>;
|
|
18
|
+
/**
|
|
19
|
+
* Run revenue integrity click attribution scan on the backend
|
|
20
|
+
*/
|
|
21
|
+
checkRevenueIntegrity(startDate?: string, endDate?: string): Promise<any>;
|
|
22
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AntigravityAgent = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const os_1 = __importDefault(require("os"));
|
|
11
|
+
class AntigravityAgent {
|
|
12
|
+
apiKey;
|
|
13
|
+
backendUrl;
|
|
14
|
+
constructor(config = {}) {
|
|
15
|
+
this.backendUrl = config.backendUrl || 'https://back-end.boostyourleads.ca';
|
|
16
|
+
// 1. Resolve API key / token
|
|
17
|
+
let resolvedKey = config.apiKey || process.env.BYL_API_KEY;
|
|
18
|
+
if (!resolvedKey) {
|
|
19
|
+
const configPath = path_1.default.join(os_1.default.homedir(), '.boostyourleads', 'config.json');
|
|
20
|
+
if (fs_1.default.existsSync(configPath)) {
|
|
21
|
+
try {
|
|
22
|
+
const localConfig = JSON.parse(fs_1.default.readFileSync(configPath, 'utf8'));
|
|
23
|
+
resolvedKey = localConfig.accessToken;
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
// Ignore parsing error
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (!resolvedKey) {
|
|
31
|
+
throw new Error("Authentication required. Please set the 'apiKey' option, " +
|
|
32
|
+
"the 'BYL_API_KEY' environment variable, or run 'npx byl-sdk login' to authenticate.");
|
|
33
|
+
}
|
|
34
|
+
this.apiKey = resolvedKey;
|
|
35
|
+
}
|
|
36
|
+
getHeaders() {
|
|
37
|
+
return {
|
|
38
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
39
|
+
'Content-Type': 'application/json'
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Run budget optimizer agent on the backend
|
|
44
|
+
*/
|
|
45
|
+
async optimizeCampaigns() {
|
|
46
|
+
try {
|
|
47
|
+
const res = await axios_1.default.post(`${this.backendUrl}/api/agent/budget-optimizer`, {}, {
|
|
48
|
+
headers: this.getHeaders()
|
|
49
|
+
});
|
|
50
|
+
return res.data;
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
const status = err.response?.status;
|
|
54
|
+
const message = err.response?.data?.error || err.message;
|
|
55
|
+
throw new Error(`Budget optimization failed (${status}): ${message}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Run performance auditor agent on the backend
|
|
60
|
+
*/
|
|
61
|
+
async auditPerformance() {
|
|
62
|
+
try {
|
|
63
|
+
const res = await axios_1.default.post(`${this.backendUrl}/api/agent/performance-auditor`, {}, {
|
|
64
|
+
headers: this.getHeaders()
|
|
65
|
+
});
|
|
66
|
+
return res.data;
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
const status = err.response?.status;
|
|
70
|
+
const message = err.response?.data?.error || err.message;
|
|
71
|
+
throw new Error(`Performance audit failed (${status}): ${message}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Run revenue integrity click attribution scan on the backend
|
|
76
|
+
*/
|
|
77
|
+
async checkRevenueIntegrity(startDate, endDate) {
|
|
78
|
+
try {
|
|
79
|
+
const res = await axios_1.default.post(`${this.backendUrl}/api/agent/revenue-integrity`, {
|
|
80
|
+
startDate,
|
|
81
|
+
endDate
|
|
82
|
+
}, {
|
|
83
|
+
headers: this.getHeaders()
|
|
84
|
+
});
|
|
85
|
+
return res.data;
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
const status = err.response?.status;
|
|
89
|
+
const message = err.response?.data?.error || err.message;
|
|
90
|
+
throw new Error(`Revenue integrity scan failed (${status}): ${message}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.AntigravityAgent = AntigravityAgent;
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@boostyourleads/antigravity-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "BoostYourLeads SDK integration for custom AI agents and Antigravity.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"bin": {
|
|
12
|
+
"byl-sdk": "dist/cli.js"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"axios": "^1.6.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/node": "^20.0.0",
|
|
22
|
+
"typescript": "^5.0.0"
|
|
23
|
+
}
|
|
24
|
+
}
|