@arjun-shah/agentbar-cli 0.1.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/README.md +19 -0
- package/bin/agentbar.js +182 -0
- package/package.json +26 -0
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @arjun-shah/agentbar-cli
|
|
2
|
+
|
|
3
|
+
CLI helper to generate and manage the Agent Plugin Bar embed snippet.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @arjun-shah/agentbar-cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
agentbar init
|
|
15
|
+
agentbar snippet
|
|
16
|
+
agentbar set siteUrl https://your-site.com
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The CLI writes `agentbar.config.json` in your project directory.
|
package/bin/agentbar.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import readline from "node:readline";
|
|
5
|
+
import process from "node:process";
|
|
6
|
+
|
|
7
|
+
const CONFIG_FILE = "agentbar.config.json";
|
|
8
|
+
const DEFAULT_CONFIG = {
|
|
9
|
+
apiBase: "https://agent-pug.vercel.app",
|
|
10
|
+
siteUrl: "",
|
|
11
|
+
siteKey: "",
|
|
12
|
+
depth: 1,
|
|
13
|
+
maxPages: 15,
|
|
14
|
+
themeColor: "#059669",
|
|
15
|
+
position: "right",
|
|
16
|
+
title: "Site Assistant",
|
|
17
|
+
subtitle: "Ask anything about this site.",
|
|
18
|
+
buttonLabel: "Ask",
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const configPath = path.join(process.cwd(), CONFIG_FILE);
|
|
22
|
+
|
|
23
|
+
const loadConfig = () => {
|
|
24
|
+
if (!fs.existsSync(configPath)) {
|
|
25
|
+
return { ...DEFAULT_CONFIG };
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const data = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
|
29
|
+
return { ...DEFAULT_CONFIG, ...data };
|
|
30
|
+
} catch {
|
|
31
|
+
return { ...DEFAULT_CONFIG };
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const saveConfig = (config) => {
|
|
36
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const renderSnippet = (config) => {
|
|
40
|
+
const lines = [
|
|
41
|
+
"<script",
|
|
42
|
+
` src=\"${config.apiBase.replace(/\/$/, "")}/agentbar.js\"`,
|
|
43
|
+
` data-site=\"${config.siteUrl || "https://your-site.com"}\"`,
|
|
44
|
+
` data-api=\"${config.apiBase.replace(/\/$/, "")}\"`,
|
|
45
|
+
` data-depth=\"${config.depth}\"`,
|
|
46
|
+
` data-max-pages=\"${config.maxPages}\"`,
|
|
47
|
+
];
|
|
48
|
+
if (config.siteKey) {
|
|
49
|
+
lines.push(` data-site-key=\"${config.siteKey}\"`);
|
|
50
|
+
}
|
|
51
|
+
if (config.themeColor) {
|
|
52
|
+
lines.push(` data-theme-color=\"${config.themeColor}\"`);
|
|
53
|
+
}
|
|
54
|
+
if (config.position) {
|
|
55
|
+
lines.push(` data-position=\"${config.position}\"`);
|
|
56
|
+
}
|
|
57
|
+
if (config.title) {
|
|
58
|
+
lines.push(` data-title=\"${config.title}\"`);
|
|
59
|
+
}
|
|
60
|
+
if (config.subtitle) {
|
|
61
|
+
lines.push(` data-subtitle=\"${config.subtitle}\"`);
|
|
62
|
+
}
|
|
63
|
+
if (config.buttonLabel) {
|
|
64
|
+
lines.push(` data-button-label=\"${config.buttonLabel}\"`);
|
|
65
|
+
}
|
|
66
|
+
lines.push("></script>");
|
|
67
|
+
return lines.join("\n");
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const printHelp = () => {
|
|
71
|
+
console.log("Agent Plugin Bar CLI\n");
|
|
72
|
+
console.log("Commands:");
|
|
73
|
+
console.log(" agentbar init Interactive setup and snippet output");
|
|
74
|
+
console.log(" agentbar snippet Print current embed snippet");
|
|
75
|
+
console.log(" agentbar set <key> <v> Update config value");
|
|
76
|
+
console.log(" agentbar config Print config JSON");
|
|
77
|
+
console.log(" agentbar help Show help\n");
|
|
78
|
+
console.log("Config keys:");
|
|
79
|
+
console.log(" siteUrl, apiBase, depth, maxPages, siteKey, themeColor, position,");
|
|
80
|
+
console.log(" title, subtitle, buttonLabel\n");
|
|
81
|
+
console.log(`Config file: ${configPath}`);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const ask = (rl, prompt, fallback) =>
|
|
85
|
+
new Promise((resolve) => {
|
|
86
|
+
const label = fallback ? `${prompt} (${fallback}): ` : `${prompt}: `;
|
|
87
|
+
rl.question(label, (answer) => {
|
|
88
|
+
const value = answer.trim();
|
|
89
|
+
resolve(value || fallback || "");
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const init = async () => {
|
|
94
|
+
const config = loadConfig();
|
|
95
|
+
const rl = readline.createInterface({
|
|
96
|
+
input: process.stdin,
|
|
97
|
+
output: process.stdout,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
config.siteUrl = await ask(rl, "Site URL", config.siteUrl || "https://your-site.com");
|
|
102
|
+
config.apiBase = await ask(rl, "API base URL", config.apiBase);
|
|
103
|
+
config.depth = Number(await ask(rl, "Crawl depth", String(config.depth)) || config.depth);
|
|
104
|
+
config.maxPages = Number(
|
|
105
|
+
await ask(rl, "Max pages", String(config.maxPages)) || config.maxPages
|
|
106
|
+
);
|
|
107
|
+
config.siteKey = await ask(rl, "Site key (optional)", config.siteKey);
|
|
108
|
+
config.themeColor = await ask(rl, "Theme color", config.themeColor);
|
|
109
|
+
config.position = await ask(rl, "Position (left/right/bottom)", config.position);
|
|
110
|
+
config.title = await ask(rl, "Widget title", config.title);
|
|
111
|
+
config.subtitle = await ask(rl, "Widget subtitle", config.subtitle);
|
|
112
|
+
config.buttonLabel = await ask(rl, "Button label", config.buttonLabel);
|
|
113
|
+
} finally {
|
|
114
|
+
rl.close();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
saveConfig(config);
|
|
118
|
+
console.log("\nSaved config to", configPath);
|
|
119
|
+
console.log("\nEmbed snippet:\n");
|
|
120
|
+
console.log(renderSnippet(config));
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const setValue = (key, value) => {
|
|
124
|
+
if (!key || typeof value === "undefined") {
|
|
125
|
+
console.error("Usage: agentbar set <key> <value>");
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const config = loadConfig();
|
|
130
|
+
const allowed = new Set(Object.keys(DEFAULT_CONFIG));
|
|
131
|
+
if (!allowed.has(key)) {
|
|
132
|
+
console.error(`Unknown key: ${key}`);
|
|
133
|
+
printHelp();
|
|
134
|
+
process.exit(1);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (key === "depth" || key === "maxPages") {
|
|
138
|
+
const parsed = Number(value);
|
|
139
|
+
if (!Number.isFinite(parsed)) {
|
|
140
|
+
console.error(`${key} must be a number.`);
|
|
141
|
+
process.exit(1);
|
|
142
|
+
}
|
|
143
|
+
config[key] = parsed;
|
|
144
|
+
} else {
|
|
145
|
+
config[key] = value;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
saveConfig(config);
|
|
149
|
+
console.log("Updated", key, "in", configPath);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const main = async () => {
|
|
153
|
+
const [command, arg1, arg2] = process.argv.slice(2);
|
|
154
|
+
|
|
155
|
+
switch (command) {
|
|
156
|
+
case "init":
|
|
157
|
+
await init();
|
|
158
|
+
return;
|
|
159
|
+
case "snippet": {
|
|
160
|
+
const config = loadConfig();
|
|
161
|
+
console.log(renderSnippet(config));
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
case "set":
|
|
165
|
+
setValue(arg1, arg2);
|
|
166
|
+
return;
|
|
167
|
+
case "config":
|
|
168
|
+
console.log(JSON.stringify(loadConfig(), null, 2));
|
|
169
|
+
return;
|
|
170
|
+
case "help":
|
|
171
|
+
case "--help":
|
|
172
|
+
case "-h":
|
|
173
|
+
case undefined:
|
|
174
|
+
printHelp();
|
|
175
|
+
return;
|
|
176
|
+
default:
|
|
177
|
+
console.error(`Unknown command: ${command}`);
|
|
178
|
+
printHelp();
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
main();
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@arjun-shah/agentbar-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Agent Plugin Bar CLI helper.",
|
|
6
|
+
"bin": {
|
|
7
|
+
"agentbar": "./bin/agentbar.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/arjunkshah/plug-your-agent.git"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"agent",
|
|
19
|
+
"ai",
|
|
20
|
+
"chatbot",
|
|
21
|
+
"cli"
|
|
22
|
+
],
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
}
|
|
26
|
+
}
|