@myapihq/cli 1.0.0 → 1.0.2
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/commands/account.js +12 -0
- package/dist/commands/setup.d.ts +1 -0
- package/dist/commands/setup.js +144 -0
- package/dist/index.js +5 -0
- package/package.json +1 -1
- package/src/commands/account.ts +16 -1
- package/src/commands/setup.ts +119 -0
- package/src/index.ts +6 -0
package/dist/commands/account.js
CHANGED
|
@@ -42,6 +42,18 @@ const config_js_1 = require("../config.js");
|
|
|
42
42
|
const output_js_1 = require("../output.js");
|
|
43
43
|
const readline = __importStar(require("readline"));
|
|
44
44
|
async function create() {
|
|
45
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
46
|
+
const ask = (q) => new Promise(resolve => rl.question(q, resolve));
|
|
47
|
+
const choice = await ask('Do you want to (1) auto-create a new account or (2) paste an existing API key? [1/2]: ');
|
|
48
|
+
rl.close();
|
|
49
|
+
if (choice.trim() === '2') {
|
|
50
|
+
const rl2 = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
51
|
+
const key = await new Promise(resolve => rl2.question('Paste your API key: ', resolve));
|
|
52
|
+
rl2.close();
|
|
53
|
+
(0, config_js_1.saveConfig)({ api_key: key.trim(), account_id: '', pin: '' });
|
|
54
|
+
(0, output_js_1.success)(`API key saved to ~/.myapi/config.json`);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
45
57
|
const agent = await sdk_1.hq.createAgentAccount();
|
|
46
58
|
const keyInfo = await sdk_1.hq.createApiKey(agent.token, 'default');
|
|
47
59
|
(0, config_js_1.saveConfig)({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function setup(): Promise<void>;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.setup = setup;
|
|
37
|
+
const sdk_1 = require("@myapihq/sdk");
|
|
38
|
+
const config_js_1 = require("../config.js");
|
|
39
|
+
const output_js_1 = require("../output.js");
|
|
40
|
+
const readline = __importStar(require("readline"));
|
|
41
|
+
const child_process_1 = require("child_process");
|
|
42
|
+
const fs = __importStar(require("fs"));
|
|
43
|
+
const path = __importStar(require("path"));
|
|
44
|
+
const os = __importStar(require("os"));
|
|
45
|
+
function ask(rl, q) {
|
|
46
|
+
return new Promise(resolve => rl.question(q, resolve));
|
|
47
|
+
}
|
|
48
|
+
function yn(answer, defaultYes = true) {
|
|
49
|
+
const t = answer.trim().toLowerCase();
|
|
50
|
+
if (t === '')
|
|
51
|
+
return defaultYes;
|
|
52
|
+
return t === 'y' || t === 'yes';
|
|
53
|
+
}
|
|
54
|
+
async function getOrCreateKey(rl) {
|
|
55
|
+
const choice = await ask(rl, '\n(1) Auto-create a new account (2) Paste an existing API key [1/2]: ');
|
|
56
|
+
if (choice.trim() === '2') {
|
|
57
|
+
const key = await ask(rl, 'Paste your API key: ');
|
|
58
|
+
(0, config_js_1.saveConfig)({ api_key: key.trim(), account_id: '', pin: '' });
|
|
59
|
+
(0, output_js_1.success)('API key saved to ~/.myapi/config.json');
|
|
60
|
+
return key.trim();
|
|
61
|
+
}
|
|
62
|
+
(0, output_js_1.info)('Creating account...');
|
|
63
|
+
const agent = await sdk_1.hq.createAgentAccount();
|
|
64
|
+
const keyInfo = await sdk_1.hq.createApiKey(agent.token, 'default');
|
|
65
|
+
(0, config_js_1.saveConfig)({ api_key: keyInfo.api_key, account_id: agent.account_id, pin: agent.pin });
|
|
66
|
+
(0, output_js_1.success)(`Account created!\n\nAPI Key: ${keyInfo.api_key}\nPIN: ${agent.pin}\n\nSave your PIN — it's the only way to recover your account.`);
|
|
67
|
+
return keyInfo.api_key;
|
|
68
|
+
}
|
|
69
|
+
function registerClaudeMcp() {
|
|
70
|
+
try {
|
|
71
|
+
(0, child_process_1.execSync)('claude mcp add myapi -- npx -y @myapihq/mcp', { stdio: 'inherit' });
|
|
72
|
+
(0, output_js_1.success)('Claude Code MCP registered');
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
(0, output_js_1.info)('Could not auto-register. Run manually:\n claude mcp add myapi -- npx -y @myapihq/mcp');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function registerGeminiMcp() {
|
|
79
|
+
const configPath = path.join(os.homedir(), '.gemini', 'settings.json');
|
|
80
|
+
try {
|
|
81
|
+
let settings = {};
|
|
82
|
+
if (fs.existsSync(configPath)) {
|
|
83
|
+
settings = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
84
|
+
}
|
|
85
|
+
settings.mcpServers = settings.mcpServers ?? {};
|
|
86
|
+
settings.mcpServers.myapi = { command: 'npx', args: ['-y', '@myapihq/mcp'] };
|
|
87
|
+
fs.mkdirSync(path.dirname(configPath), { recursive: true });
|
|
88
|
+
fs.writeFileSync(configPath, JSON.stringify(settings, null, 2));
|
|
89
|
+
(0, output_js_1.success)('Gemini CLI MCP registered (~/.gemini/settings.json)');
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
(0, output_js_1.info)('Could not auto-configure Gemini CLI. Add manually to ~/.gemini/settings.json:');
|
|
93
|
+
(0, output_js_1.info)(' { "mcpServers": { "myapi": { "command": "npx", "args": ["-y", "@myapihq/mcp"] } } }');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async function setup() {
|
|
97
|
+
(0, output_js_1.info)('MyAPI Setup\n');
|
|
98
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
99
|
+
// Step 1: credentials
|
|
100
|
+
const existing = (0, config_js_1.loadConfig)();
|
|
101
|
+
if (existing?.api_key) {
|
|
102
|
+
const reuse = await ask(rl, `Found existing account (${existing.account_id || existing.api_key.slice(0, 20) + '...'}). Use it? [Y/n]: `);
|
|
103
|
+
if (!yn(reuse, true)) {
|
|
104
|
+
await getOrCreateKey(rl);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
(0, output_js_1.info)('Using existing credentials.');
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
await getOrCreateKey(rl);
|
|
112
|
+
}
|
|
113
|
+
// Step 2: which agents
|
|
114
|
+
(0, output_js_1.info)('\nWhich AI agents do you use?');
|
|
115
|
+
const useClaude = yn(await ask(rl, ' Claude Code? [Y/n]: '), true);
|
|
116
|
+
const useGemini = yn(await ask(rl, ' Gemini CLI? [y/N]: '), false);
|
|
117
|
+
const useCursor = yn(await ask(rl, ' Cursor / Windsurf? [y/N]: '), false);
|
|
118
|
+
// Step 3: Claude — MCP or Skills or both
|
|
119
|
+
let claudeMcp = false;
|
|
120
|
+
let claudeSkills = false;
|
|
121
|
+
if (useClaude) {
|
|
122
|
+
(0, output_js_1.info)('\nFor Claude Code, how do you want to connect?');
|
|
123
|
+
claudeMcp = yn(await ask(rl, ' MCP server — live API calls via tool use? [Y/n]: '), true);
|
|
124
|
+
claudeSkills = yn(await ask(rl, ' Skills plugin — inline docs + prompts? [y/N]: '), false);
|
|
125
|
+
}
|
|
126
|
+
rl.close();
|
|
127
|
+
// Step 4: apply
|
|
128
|
+
(0, output_js_1.info)('\nApplying configuration...\n');
|
|
129
|
+
if (claudeMcp)
|
|
130
|
+
registerClaudeMcp();
|
|
131
|
+
if (useGemini)
|
|
132
|
+
registerGeminiMcp();
|
|
133
|
+
if (claudeSkills) {
|
|
134
|
+
(0, output_js_1.info)('To install the MyAPI skill inside Claude Code, run:');
|
|
135
|
+
(0, output_js_1.info)(' /plugin marketplace add myapihq/claude-skills');
|
|
136
|
+
(0, output_js_1.info)(' /plugin install my-api-hq@myapi-skills');
|
|
137
|
+
}
|
|
138
|
+
if (useCursor) {
|
|
139
|
+
(0, output_js_1.info)('\nFor Cursor / Windsurf — add the skill as a rule:');
|
|
140
|
+
(0, output_js_1.info)(' https://github.com/myapihq/claude-skills/blob/main/skills/my-api-hq/SKILL.md');
|
|
141
|
+
}
|
|
142
|
+
(0, output_js_1.info)('');
|
|
143
|
+
(0, output_js_1.success)('Setup complete! Try: myapi billing balance');
|
|
144
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -39,6 +39,7 @@ const output_js_1 = require("./output.js");
|
|
|
39
39
|
const sdk_1 = require("@myapihq/sdk");
|
|
40
40
|
const accountCmd = __importStar(require("./commands/account.js"));
|
|
41
41
|
const billingCmd = __importStar(require("./commands/billing.js"));
|
|
42
|
+
const setupCmd = __importStar(require("./commands/setup.js"));
|
|
42
43
|
async function main() {
|
|
43
44
|
const { args, flags } = (0, utils_js_1.parseArgs)(process.argv.slice(2));
|
|
44
45
|
if (args.length === 0) {
|
|
@@ -48,6 +49,9 @@ async function main() {
|
|
|
48
49
|
const [command, subcommand, ...restArgs] = args;
|
|
49
50
|
try {
|
|
50
51
|
switch (command) {
|
|
52
|
+
case 'setup':
|
|
53
|
+
await setupCmd.setup();
|
|
54
|
+
break;
|
|
51
55
|
case 'account':
|
|
52
56
|
if (subcommand === 'create')
|
|
53
57
|
await accountCmd.create();
|
|
@@ -95,6 +99,7 @@ function printHelp() {
|
|
|
95
99
|
Usage: myapi <command> [subcommand] [args]
|
|
96
100
|
|
|
97
101
|
Commands:
|
|
102
|
+
setup Interactive setup wizard
|
|
98
103
|
account Manage your account and API keys
|
|
99
104
|
billing Check balance and top up
|
|
100
105
|
|
package/package.json
CHANGED
package/src/commands/account.ts
CHANGED
|
@@ -4,9 +4,24 @@ import { success, error, printTable } from '../output.js';
|
|
|
4
4
|
import * as readline from 'readline';
|
|
5
5
|
|
|
6
6
|
export async function create() {
|
|
7
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
8
|
+
const ask = (q: string) => new Promise<string>(resolve => rl.question(q, resolve));
|
|
9
|
+
|
|
10
|
+
const choice = await ask('Do you want to (1) auto-create a new account or (2) paste an existing API key? [1/2]: ');
|
|
11
|
+
rl.close();
|
|
12
|
+
|
|
13
|
+
if (choice.trim() === '2') {
|
|
14
|
+
const rl2 = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
15
|
+
const key = await new Promise<string>(resolve => rl2.question('Paste your API key: ', resolve));
|
|
16
|
+
rl2.close();
|
|
17
|
+
saveConfig({ api_key: key.trim(), account_id: '', pin: '' });
|
|
18
|
+
success(`API key saved to ~/.myapi/config.json`);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
7
22
|
const agent = await hq.createAgentAccount();
|
|
8
23
|
const keyInfo = await hq.createApiKey(agent.token, 'default');
|
|
9
|
-
|
|
24
|
+
|
|
10
25
|
saveConfig({
|
|
11
26
|
api_key: keyInfo.api_key,
|
|
12
27
|
account_id: agent.account_id,
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { hq } from '@myapihq/sdk';
|
|
2
|
+
import { loadConfig, saveConfig } from '../config.js';
|
|
3
|
+
import { success, info } from '../output.js';
|
|
4
|
+
import * as readline from 'readline';
|
|
5
|
+
import { execSync } from 'child_process';
|
|
6
|
+
import * as fs from 'fs';
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
import * as os from 'os';
|
|
9
|
+
|
|
10
|
+
function ask(rl: readline.Interface, q: string): Promise<string> {
|
|
11
|
+
return new Promise(resolve => rl.question(q, resolve));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function yn(answer: string, defaultYes = true): boolean {
|
|
15
|
+
const t = answer.trim().toLowerCase();
|
|
16
|
+
if (t === '') return defaultYes;
|
|
17
|
+
return t === 'y' || t === 'yes';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function getOrCreateKey(rl: readline.Interface): Promise<string> {
|
|
21
|
+
const choice = await ask(rl, '\n(1) Auto-create a new account (2) Paste an existing API key [1/2]: ');
|
|
22
|
+
|
|
23
|
+
if (choice.trim() === '2') {
|
|
24
|
+
const key = await ask(rl, 'Paste your API key: ');
|
|
25
|
+
saveConfig({ api_key: key.trim(), account_id: '', pin: '' });
|
|
26
|
+
success('API key saved to ~/.myapi/config.json');
|
|
27
|
+
return key.trim();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
info('Creating account...');
|
|
31
|
+
const agent = await hq.createAgentAccount();
|
|
32
|
+
const keyInfo = await hq.createApiKey(agent.token, 'default');
|
|
33
|
+
saveConfig({ api_key: keyInfo.api_key, account_id: agent.account_id, pin: agent.pin });
|
|
34
|
+
success(`Account created!\n\nAPI Key: ${keyInfo.api_key}\nPIN: ${agent.pin}\n\nSave your PIN — it's the only way to recover your account.`);
|
|
35
|
+
return keyInfo.api_key;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function registerClaudeMcp() {
|
|
39
|
+
try {
|
|
40
|
+
execSync('claude mcp add myapi -- npx -y @myapihq/mcp', { stdio: 'inherit' });
|
|
41
|
+
success('Claude Code MCP registered');
|
|
42
|
+
} catch {
|
|
43
|
+
info('Could not auto-register. Run manually:\n claude mcp add myapi -- npx -y @myapihq/mcp');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function registerGeminiMcp() {
|
|
48
|
+
const configPath = path.join(os.homedir(), '.gemini', 'settings.json');
|
|
49
|
+
try {
|
|
50
|
+
let settings: Record<string, any> = {};
|
|
51
|
+
if (fs.existsSync(configPath)) {
|
|
52
|
+
settings = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
53
|
+
}
|
|
54
|
+
settings.mcpServers = settings.mcpServers ?? {};
|
|
55
|
+
settings.mcpServers.myapi = { command: 'npx', args: ['-y', '@myapihq/mcp'] };
|
|
56
|
+
fs.mkdirSync(path.dirname(configPath), { recursive: true });
|
|
57
|
+
fs.writeFileSync(configPath, JSON.stringify(settings, null, 2));
|
|
58
|
+
success('Gemini CLI MCP registered (~/.gemini/settings.json)');
|
|
59
|
+
} catch {
|
|
60
|
+
info('Could not auto-configure Gemini CLI. Add manually to ~/.gemini/settings.json:');
|
|
61
|
+
info(' { "mcpServers": { "myapi": { "command": "npx", "args": ["-y", "@myapihq/mcp"] } } }');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export async function setup() {
|
|
66
|
+
info('MyAPI Setup\n');
|
|
67
|
+
|
|
68
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
69
|
+
|
|
70
|
+
// Step 1: credentials
|
|
71
|
+
const existing = loadConfig();
|
|
72
|
+
if (existing?.api_key) {
|
|
73
|
+
const reuse = await ask(rl, `Found existing account (${existing.account_id || existing.api_key.slice(0, 20) + '...'}). Use it? [Y/n]: `);
|
|
74
|
+
if (!yn(reuse, true)) {
|
|
75
|
+
await getOrCreateKey(rl);
|
|
76
|
+
} else {
|
|
77
|
+
info('Using existing credentials.');
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
await getOrCreateKey(rl);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Step 2: which agents
|
|
84
|
+
info('\nWhich AI agents do you use?');
|
|
85
|
+
const useClaude = yn(await ask(rl, ' Claude Code? [Y/n]: '), true);
|
|
86
|
+
const useGemini = yn(await ask(rl, ' Gemini CLI? [y/N]: '), false);
|
|
87
|
+
const useCursor = yn(await ask(rl, ' Cursor / Windsurf? [y/N]: '), false);
|
|
88
|
+
|
|
89
|
+
// Step 3: Claude — MCP or Skills or both
|
|
90
|
+
let claudeMcp = false;
|
|
91
|
+
let claudeSkills = false;
|
|
92
|
+
if (useClaude) {
|
|
93
|
+
info('\nFor Claude Code, how do you want to connect?');
|
|
94
|
+
claudeMcp = yn(await ask(rl, ' MCP server — live API calls via tool use? [Y/n]: '), true);
|
|
95
|
+
claudeSkills = yn(await ask(rl, ' Skills plugin — inline docs + prompts? [y/N]: '), false);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
rl.close();
|
|
99
|
+
|
|
100
|
+
// Step 4: apply
|
|
101
|
+
info('\nApplying configuration...\n');
|
|
102
|
+
|
|
103
|
+
if (claudeMcp) registerClaudeMcp();
|
|
104
|
+
if (useGemini) registerGeminiMcp();
|
|
105
|
+
|
|
106
|
+
if (claudeSkills) {
|
|
107
|
+
info('To install the MyAPI skill inside Claude Code, run:');
|
|
108
|
+
info(' /plugin marketplace add myapihq/claude-skills');
|
|
109
|
+
info(' /plugin install my-api-hq@myapi-skills');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (useCursor) {
|
|
113
|
+
info('\nFor Cursor / Windsurf — add the skill as a rule:');
|
|
114
|
+
info(' https://github.com/myapihq/claude-skills/blob/main/skills/my-api-hq/SKILL.md');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
info('');
|
|
118
|
+
success('Setup complete! Try: myapi billing balance');
|
|
119
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { MyApiError } from '@myapihq/sdk';
|
|
|
6
6
|
|
|
7
7
|
import * as accountCmd from './commands/account.js';
|
|
8
8
|
import * as billingCmd from './commands/billing.js';
|
|
9
|
+
import * as setupCmd from './commands/setup.js';
|
|
9
10
|
|
|
10
11
|
async function main() {
|
|
11
12
|
const { args, flags } = parseArgs(process.argv.slice(2));
|
|
@@ -19,6 +20,10 @@ async function main() {
|
|
|
19
20
|
|
|
20
21
|
try {
|
|
21
22
|
switch (command) {
|
|
23
|
+
case 'setup':
|
|
24
|
+
await setupCmd.setup();
|
|
25
|
+
break;
|
|
26
|
+
|
|
22
27
|
case 'account':
|
|
23
28
|
if (subcommand === 'create') await accountCmd.create();
|
|
24
29
|
else if (subcommand === 'token') await accountCmd.token(flags);
|
|
@@ -57,6 +62,7 @@ function printHelp() {
|
|
|
57
62
|
Usage: myapi <command> [subcommand] [args]
|
|
58
63
|
|
|
59
64
|
Commands:
|
|
65
|
+
setup Interactive setup wizard
|
|
60
66
|
account Manage your account and API keys
|
|
61
67
|
billing Check balance and top up
|
|
62
68
|
|