@aivin-labs/cli 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/README.md +214 -0
- package/bin/assets/aivin-icon.png +0 -0
- package/bin/cli.mjs +1256 -0
- package/bin/lib/auth.mjs +355 -0
- package/bin/lib/browserAutomation.mjs +575 -0
- package/bin/lib/codegen.mjs +858 -0
- package/bin/lib/connectors.mjs +217 -0
- package/bin/lib/context.mjs +149 -0
- package/bin/lib/deploy.mjs +350 -0
- package/bin/lib/mcpProxy.mjs +380 -0
- package/bin/lib/mission.mjs +68 -0
- package/bin/lib/missionStream.mjs +656 -0
- package/bin/lib/pluginTrigger.mjs +535 -0
- package/bin/lib/scaffold.mjs +653 -0
- package/bin/lib/store.mjs +204 -0
- package/bin/lib/tasks.mjs +345 -0
- package/bin/lib/util.mjs +40 -0
- package/bin/lib/workspace.mjs +280 -0
- package/docs/CHANGELOG.md +8 -0
- package/docs/CLI.md +1079 -0
- package/docs/GETTING_STARTED.md +234 -0
- package/package.json +59 -0
package/bin/cli.mjs
ADDED
|
@@ -0,0 +1,1256 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import inquirer from 'inquirer';
|
|
8
|
+
import { spawn } from 'child_process';
|
|
9
|
+
import axios from 'axios';
|
|
10
|
+
import dotenv from 'dotenv';
|
|
11
|
+
import { fileURLToPath, pathToFileURL } from 'url';
|
|
12
|
+
import { dirname } from 'path';
|
|
13
|
+
import { createRequire } from 'module';
|
|
14
|
+
// Same flatten logic PluginServer.ts uses for local/production runtime resolution - re-exported
|
|
15
|
+
// from the installed @aivin-labs/sdk (not vendored here) so deploy and runtime agree on exactly
|
|
16
|
+
// the same rules for what manifest.json's { ...commonFields, plugins: [...] } authoring shape
|
|
17
|
+
// expands into.
|
|
18
|
+
import { flattenManifestFile } from '@aivin-labs/sdk';
|
|
19
|
+
|
|
20
|
+
import { DEFAULT_AIVIN_BASE_URL, GLOBAL_CREDENTIALS_PATH, fetchWebUrl, loadActiveContext, clearActiveContext } from './lib/context.mjs';
|
|
21
|
+
import { requireArg } from './lib/util.mjs';
|
|
22
|
+
import { readStdin, createFromJSON, createInteractive, validatePluginConfig, validateMcpProxyConfig } from './lib/scaffold.mjs';
|
|
23
|
+
import { buildDeploymentPayload, deployPlugin, incrementVersion } from './lib/deploy.mjs';
|
|
24
|
+
import { initInteractive, makePluginFromDescription, convertExistingProject } from './lib/codegen.mjs';
|
|
25
|
+
import { searchPlugins, streamPluginLogs, triggerPlugin } from './lib/pluginTrigger.mjs';
|
|
26
|
+
import { connectorAuthHeaders, connectorBaseUrl, listConnectors, registerConnector, searchConnectors } from './lib/connectors.mjs';
|
|
27
|
+
import { attachStore, createStore, deleteStore, detachStore, listStores, setStoreEnabled } from './lib/store.mjs';
|
|
28
|
+
import { buildMcpManifest, createMcpProxyPlugin, scanAndPublishMcp } from './lib/mcpProxy.mjs';
|
|
29
|
+
import {
|
|
30
|
+
saveGlobalApiKey,
|
|
31
|
+
browserLogin,
|
|
32
|
+
basicLogin,
|
|
33
|
+
requireSavedApiKey,
|
|
34
|
+
logAccountIdentity,
|
|
35
|
+
listRemoteApiKeys,
|
|
36
|
+
generateApiKey,
|
|
37
|
+
revokeApiKeyByName,
|
|
38
|
+
tryFetchWhoami,
|
|
39
|
+
parseApiKeyClient,
|
|
40
|
+
} from './lib/auth.mjs';
|
|
41
|
+
import {
|
|
42
|
+
missionAuthHeaders,
|
|
43
|
+
missionServerUrl,
|
|
44
|
+
resolveWorkspace,
|
|
45
|
+
searchAgents,
|
|
46
|
+
pullAgentIntoWorkspace,
|
|
47
|
+
createAgent,
|
|
48
|
+
publishAgent,
|
|
49
|
+
installAgentInteractive,
|
|
50
|
+
listAgentsCmd,
|
|
51
|
+
} from './lib/workspace.mjs';
|
|
52
|
+
import { runMission, runBrowserMission } from './lib/mission.mjs';
|
|
53
|
+
import {
|
|
54
|
+
createAutomationJob,
|
|
55
|
+
listTasks,
|
|
56
|
+
listMyTasks,
|
|
57
|
+
getTaskById,
|
|
58
|
+
updateTaskById,
|
|
59
|
+
deleteTaskById,
|
|
60
|
+
createTask,
|
|
61
|
+
pickWorkspaceAndProject,
|
|
62
|
+
createProjectCmd,
|
|
63
|
+
updateProjectCmd,
|
|
64
|
+
deleteProjectCmd,
|
|
65
|
+
listProjectsCmd,
|
|
66
|
+
} from './lib/tasks.mjs';
|
|
67
|
+
|
|
68
|
+
// Load env vars: the current project's `.env` first (any deliberate per-project override), THEN
|
|
69
|
+
// fill in AIVIN_BASE_URL/API_KEY/SDK_ENDPOINT from the machine's active context if the project
|
|
70
|
+
// didn't set them. `dotenv.config()` never overrides a variable that's already set, so a project's
|
|
71
|
+
// own `.env` (or a real shell env var) always wins over the global context, exactly like before -
|
|
72
|
+
// but nothing requires a project to have a `.env` at all anymore for the common single-context case.
|
|
73
|
+
// `quiet: true` - otherwise dotenv prints an "injected env" tip line to stdout on every run, which
|
|
74
|
+
// would corrupt `--json-output` mode (meant for clean, parseable JSON on stdout).
|
|
75
|
+
dotenv.config({ quiet: true });
|
|
76
|
+
|
|
77
|
+
{
|
|
78
|
+
const activeContext = loadActiveContext();
|
|
79
|
+
if (activeContext) {
|
|
80
|
+
if (!process.env.AIVIN_BASE_URL) process.env.AIVIN_BASE_URL = activeContext.base_url;
|
|
81
|
+
if (!process.env.API_KEY) process.env.API_KEY = activeContext.api_key;
|
|
82
|
+
if (!process.env.SDK_ENDPOINT && activeContext.sdk_endpoint) process.env.SDK_ENDPOINT = activeContext.sdk_endpoint;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
87
|
+
|
|
88
|
+
const __dirname = dirname(__filename);
|
|
89
|
+
|
|
90
|
+
// This CLI's own version (`aivin --version`) - distinct from whatever @aivin-labs/sdk version a
|
|
91
|
+
// given plugin project has installed. See lib/scaffold.mjs for how a fresh scaffold's `@aivin-labs/
|
|
92
|
+
// sdk` dependency pin is resolved (from the actually-installed sdk, not from here).
|
|
93
|
+
const CLI_PACKAGE_JSON = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'));
|
|
94
|
+
|
|
95
|
+
const CLI_VERSION = CLI_PACKAGE_JSON.version;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* `aivin start` spawns the plugin project's own installed `@aivin-labs/sdk`'s `bin/server.mjs`,
|
|
99
|
+
* which loads `src/main.ts` directly via Node's native TS execution (no separate compile step) -
|
|
100
|
+
* the same mechanism this CLI's own `engines.node` field (">=22.0.0") documents as required for
|
|
101
|
+
* itself. Node <22 doesn't strip TS types at all, so that failure doesn't surface as anything about
|
|
102
|
+
* Node versions - it's a raw loader error ("Unknown file extension \".ts\"") thrown from deep inside
|
|
103
|
+
* `server.mjs`, giving no hint that the fix is just "use a newer Node". Check the constraint up
|
|
104
|
+
* front instead, once, with a message that says exactly what's wrong and how to fix it.
|
|
105
|
+
*/
|
|
106
|
+
function checkNodeVersion() {
|
|
107
|
+
const required = CLI_PACKAGE_JSON.engines?.node;
|
|
108
|
+
const requiredMajor = required && parseInt(required.match(/(\d+)/)?.[1], 10);
|
|
109
|
+
const currentMajor = parseInt(process.versions.node.split('.')[0], 10);
|
|
110
|
+
if (requiredMajor && currentMajor < requiredMajor) {
|
|
111
|
+
console.error(
|
|
112
|
+
chalk.red(`❌ Node ${process.version} detected - aivin requires Node ${required} (native TypeScript execution).`),
|
|
113
|
+
);
|
|
114
|
+
console.error(chalk.gray(` Switch versions (e.g. \`nvm use ${requiredMajor}\`) and try again.`));
|
|
115
|
+
process.exit(1);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Resolves `bin/server.mjs` from the CURRENT PROJECT's own installed `@aivin-labs/sdk` (not this
|
|
121
|
+
* CLI's install location - after the cli/sdk package split those are two different places, and
|
|
122
|
+
* `aivin start`/`aivin test` must run whatever sdk version the plugin project actually depends on,
|
|
123
|
+
* the same one its own `npm install` resolved). Resolves `@aivin-labs/sdk/package.json` (an
|
|
124
|
+
* explicit "./package.json" export, see the sdk's package.json) via Node's normal module resolution
|
|
125
|
+
* rooted at the current directory, then derives `bin/server.mjs` from its location by plain path
|
|
126
|
+
* math - deliberately not a second module-specifier resolution, since `bin/server.mjs` itself isn't
|
|
127
|
+
* (and doesn't need to be) part of the sdk's public `exports` map.
|
|
128
|
+
*/
|
|
129
|
+
function resolveLocalSdkServerPath(currentDir = process.cwd()) {
|
|
130
|
+
const localRequire = createRequire(pathToFileURL(path.join(currentDir, 'noop.cjs')).href);
|
|
131
|
+
let sdkPackageJsonPath;
|
|
132
|
+
try {
|
|
133
|
+
sdkPackageJsonPath = localRequire.resolve('@aivin-labs/sdk/package.json');
|
|
134
|
+
} catch (error) {
|
|
135
|
+
throw new Error(
|
|
136
|
+
`Could not find @aivin-labs/sdk installed in ${currentDir} - run \`npm install\` first.`,
|
|
137
|
+
{ cause: error },
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
return path.join(path.dirname(sdkPackageJsonPath), 'bin', 'server.mjs');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const program = new Command();
|
|
144
|
+
|
|
145
|
+
program.name('aivin').description('aivin CLI - scaffold, run, and deploy Aivin plugins').version(CLI_VERSION);
|
|
146
|
+
|
|
147
|
+
// Command: create plugin
|
|
148
|
+
program
|
|
149
|
+
.command('create [name]')
|
|
150
|
+
.description('Create new plugin')
|
|
151
|
+
.option('--json <config>', 'JSON config (AI mode)')
|
|
152
|
+
.option('--stdin', 'Read from stdin')
|
|
153
|
+
.option('--name <name>', 'Plugin name (if not specified, will prompt)')
|
|
154
|
+
.option('--silent', 'Silent mode')
|
|
155
|
+
.option('--json-output', 'JSON output')
|
|
156
|
+
.action(async (name, options) => {
|
|
157
|
+
if (name) options.name = name;
|
|
158
|
+
try {
|
|
159
|
+
let result;
|
|
160
|
+
|
|
161
|
+
if (options.stdin) {
|
|
162
|
+
const stdinData = await readStdin();
|
|
163
|
+
result = await createFromJSON(stdinData, options);
|
|
164
|
+
} else if (options.json) {
|
|
165
|
+
result = await createFromJSON(options.json, options);
|
|
166
|
+
} else {
|
|
167
|
+
result = await createInteractive(options);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (options.jsonOutput && result) {
|
|
171
|
+
console.log(JSON.stringify(result, null, 2));
|
|
172
|
+
}
|
|
173
|
+
} catch (error) {
|
|
174
|
+
if (options.jsonOutput) {
|
|
175
|
+
console.log(
|
|
176
|
+
JSON.stringify(
|
|
177
|
+
{
|
|
178
|
+
success: false,
|
|
179
|
+
error: error.message,
|
|
180
|
+
code: error.code || 'ERROR',
|
|
181
|
+
},
|
|
182
|
+
null,
|
|
183
|
+
2,
|
|
184
|
+
),
|
|
185
|
+
);
|
|
186
|
+
} else if (!options.silent) {
|
|
187
|
+
console.error(chalk.red('❌'), error.message);
|
|
188
|
+
}
|
|
189
|
+
process.exit(1);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
// Command: init plugin - guided one-step replacement for `create` + `plugin make`
|
|
194
|
+
program
|
|
195
|
+
.command('init [name]')
|
|
196
|
+
.description('Set up a new plugin step by step: asks what it should do, then generates real working code from that description')
|
|
197
|
+
.option('--name <name>', 'Plugin name (if not specified, will prompt)')
|
|
198
|
+
.option('--model <model>', 'LLM model to use for generation')
|
|
199
|
+
.option('--provider <provider>', 'LLM provider to use for generation')
|
|
200
|
+
.action(async (name, options) => {
|
|
201
|
+
if (name) options.name = name;
|
|
202
|
+
try {
|
|
203
|
+
await initInteractive(options);
|
|
204
|
+
} catch (error) {
|
|
205
|
+
console.error(chalk.red('❌'), error.message);
|
|
206
|
+
process.exit(1);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
// Command: Validate plugin config
|
|
211
|
+
program
|
|
212
|
+
.command('validate')
|
|
213
|
+
.description('Validate manifest.json in the current directory (or --json/--stdin for scripted use)')
|
|
214
|
+
.option('--json <config>', 'JSON config, instead of reading manifest.json from the current directory')
|
|
215
|
+
.option('--stdin', 'Read JSON config from stdin, instead of reading manifest.json')
|
|
216
|
+
.option('--json-output', 'JSON output')
|
|
217
|
+
.action(async (options) => {
|
|
218
|
+
try {
|
|
219
|
+
let configData;
|
|
220
|
+
|
|
221
|
+
if (options.stdin) {
|
|
222
|
+
configData = await readStdin();
|
|
223
|
+
} else if (options.json) {
|
|
224
|
+
configData = options.json;
|
|
225
|
+
} else {
|
|
226
|
+
// Simple, no-flags default: validate manifest.json in the current directory - the case
|
|
227
|
+
// you actually want most of the time (`aivin validate` from inside your plugin project).
|
|
228
|
+
// --json/--stdin remain for scripted/CI use where the config isn't a file on disk yet.
|
|
229
|
+
const manifestPath = path.join(process.cwd(), 'manifest.json');
|
|
230
|
+
if (!fs.existsSync(manifestPath)) {
|
|
231
|
+
throw new Error('No manifest.json found in the current directory. Pass --json <config> or --stdin instead.');
|
|
232
|
+
}
|
|
233
|
+
configData = fs.readFileSync(manifestPath, 'utf8');
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Expand the default { ...commonFields, plugins: [...] } shape and validate every entry -
|
|
237
|
+
// flattenManifestFile itself throws on structural problems (empty plugins[], missing
|
|
238
|
+
// id/name/func, bare top-level array).
|
|
239
|
+
const config = flattenManifestFile(JSON.parse(configData));
|
|
240
|
+
const entries = Array.isArray(config) ? config : [config];
|
|
241
|
+
const errors = entries.flatMap((entry, i) =>
|
|
242
|
+
validatePluginConfig(entry).errors.map((e) =>
|
|
243
|
+
entries.length > 1 ? `plugins[${i}] (${entry.name || 'unnamed'}): ${e}` : e,
|
|
244
|
+
),
|
|
245
|
+
);
|
|
246
|
+
const result = { valid: errors.length === 0, errors };
|
|
247
|
+
|
|
248
|
+
if (options.jsonOutput) {
|
|
249
|
+
console.log(
|
|
250
|
+
JSON.stringify(
|
|
251
|
+
{
|
|
252
|
+
valid: result.valid,
|
|
253
|
+
errors: result.errors,
|
|
254
|
+
},
|
|
255
|
+
null,
|
|
256
|
+
2,
|
|
257
|
+
),
|
|
258
|
+
);
|
|
259
|
+
} else {
|
|
260
|
+
if (result.valid) {
|
|
261
|
+
console.log(chalk.green('✅ Valid'));
|
|
262
|
+
} else {
|
|
263
|
+
console.log(chalk.red('❌ Invalid:'));
|
|
264
|
+
result.errors.forEach((error) => console.log(` • ${error}`));
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
if (!result.valid) process.exit(1);
|
|
269
|
+
} catch (error) {
|
|
270
|
+
if (options.jsonOutput) {
|
|
271
|
+
console.log(JSON.stringify({ valid: false, error: error.message }, null, 2));
|
|
272
|
+
} else {
|
|
273
|
+
console.error(chalk.red('❌'), error.message);
|
|
274
|
+
}
|
|
275
|
+
process.exit(1);
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
// Command: start plugin server
|
|
280
|
+
program
|
|
281
|
+
.command('start')
|
|
282
|
+
.description('Start plugin server')
|
|
283
|
+
.option('--debug', 'Log every sdk.* call live as it happens (human-readable), not just the final trace summary')
|
|
284
|
+
.option('--debug-json', 'Same live per-call logging as --debug, but one JSON object per line on stdout - for a script/coding agent to parse instead of a human')
|
|
285
|
+
.option('--no-watch', 'Disable hot-reload - restart manually (Ctrl+C + `aivin start` again) after editing src/ instead')
|
|
286
|
+
.action((options) => {
|
|
287
|
+
checkNodeVersion();
|
|
288
|
+
let serverPath;
|
|
289
|
+
try {
|
|
290
|
+
serverPath = resolveLocalSdkServerPath();
|
|
291
|
+
} catch (error) {
|
|
292
|
+
console.error(chalk.red('❌'), error.message);
|
|
293
|
+
process.exit(1);
|
|
294
|
+
}
|
|
295
|
+
const debugEnv = options.debugJson ? { SDK_DEBUG: 'json' } : options.debug ? { SDK_DEBUG: 'true' } : {};
|
|
296
|
+
const watchEnv = options.watch === false ? { AIVIN_START_WATCH: 'false' } : {};
|
|
297
|
+
const child = spawn('node', [serverPath], {
|
|
298
|
+
stdio: 'inherit',
|
|
299
|
+
env: { ...process.env, ...debugEnv, ...watchEnv },
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
child.on('error', (error) => {
|
|
303
|
+
console.error(chalk.red('❌'), error.message);
|
|
304
|
+
process.exit(1);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
child.on('exit', (code) => {
|
|
308
|
+
if (code !== 0) {
|
|
309
|
+
process.exit(code);
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
// Command: deploy plugin to server (always private to your org - see buildDeploymentPayload's
|
|
315
|
+
// doc comment above for why there's no public/store-submission scope here)
|
|
316
|
+
program
|
|
317
|
+
.command('deploy')
|
|
318
|
+
.description('Deploy plugin to your org on the Aivin server')
|
|
319
|
+
.action(async () => {
|
|
320
|
+
try {
|
|
321
|
+
await deployPlugin({
|
|
322
|
+
endpointPath: '/plugins/deploy',
|
|
323
|
+
label: 'Deploying plugin',
|
|
324
|
+
});
|
|
325
|
+
} catch (error) {
|
|
326
|
+
console.error(chalk.red('❌'), error.message);
|
|
327
|
+
process.exit(1);
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
// Command: deploy to a throwaway test instance (backend rejects this in production)
|
|
332
|
+
program
|
|
333
|
+
.command('test')
|
|
334
|
+
.description(
|
|
335
|
+
'Deploy to a non-production test instance, then smoke-test it with generated input and save a report to .test/',
|
|
336
|
+
)
|
|
337
|
+
.option('--workspace <id>', 'Workspace id to run the smoke test against (default: auto-picks your first one)')
|
|
338
|
+
.option('--no-smoke-test', 'Only deploy - skip the generated-input invoke test and report')
|
|
339
|
+
.action(async (options) => {
|
|
340
|
+
try {
|
|
341
|
+
await deployPlugin({
|
|
342
|
+
endpointPath: '/plugins/test/deploy',
|
|
343
|
+
label: 'Deploying to test instance',
|
|
344
|
+
smokeTest: options.smokeTest !== false,
|
|
345
|
+
workspaceOverride: options.workspace,
|
|
346
|
+
});
|
|
347
|
+
} catch (error) {
|
|
348
|
+
console.error(chalk.red('❌'), error.message);
|
|
349
|
+
process.exit(1);
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
const pluginCommand = program.command('plugin').description('AI-assisted plugin authoring');
|
|
354
|
+
|
|
355
|
+
pluginCommand
|
|
356
|
+
.command('search [query]')
|
|
357
|
+
.description("Search the platform's plugin ecosystem for something to reuse instead of writing it yourself")
|
|
358
|
+
.option('--workspace <id>', 'Restrict to plugins visible in this workspace (default: your whole org)')
|
|
359
|
+
.option('--limit <n>', 'Max results to show')
|
|
360
|
+
.option('--plain', 'Print a flat list instead of the interactive browser (for scripts/CI)')
|
|
361
|
+
.action(async (query, options) => {
|
|
362
|
+
try {
|
|
363
|
+
query = await requireArg(query, { prompt: 'What are you looking for?', usage: 'Usage: aivin plugin search "<query>"' });
|
|
364
|
+
await searchPlugins(query, options);
|
|
365
|
+
} catch (error) {
|
|
366
|
+
console.error(chalk.red('❌'), error.message);
|
|
367
|
+
process.exit(1);
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
pluginCommand
|
|
372
|
+
.command('make [description]')
|
|
373
|
+
.description('Generate src/main.ts from a natural-language business description')
|
|
374
|
+
.option('--model <model>', 'LLM model to use for generation')
|
|
375
|
+
.option('--provider <provider>', 'LLM provider to use for generation')
|
|
376
|
+
.action(async (description, options) => {
|
|
377
|
+
try {
|
|
378
|
+
description = await requireArg(description, { prompt: 'What should this plugin do?', usage: 'Usage: aivin plugin make "<description>"' });
|
|
379
|
+
await makePluginFromDescription(description, options);
|
|
380
|
+
} catch (error) {
|
|
381
|
+
console.error(chalk.red('❌'), error.message);
|
|
382
|
+
process.exit(1);
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
pluginCommand
|
|
387
|
+
.command('convert [hint]')
|
|
388
|
+
.description('Turn an existing project in the current directory into an Aivin plugin')
|
|
389
|
+
.option('--model <model>', 'LLM model to use for generation')
|
|
390
|
+
.option('--provider <provider>', 'LLM provider to use for generation')
|
|
391
|
+
.option('--force', 'Re-run conversion even if src/main.ts already exists (e.g. redo a previous bad/stale result)')
|
|
392
|
+
.action(async (hint, options) => {
|
|
393
|
+
try {
|
|
394
|
+
await convertExistingProject(hint, options);
|
|
395
|
+
} catch (error) {
|
|
396
|
+
console.error(chalk.red('❌'), error.message);
|
|
397
|
+
process.exit(1);
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
pluginCommand
|
|
402
|
+
.command('trigger [mission] [input]')
|
|
403
|
+
.description('Invoke this deployed plugin for real and print the result - like the platform\'s Playground')
|
|
404
|
+
.option('-a, --auto <prompt>', 'Natural-language prompt - the platform auto-maps it onto the input schema for you')
|
|
405
|
+
.option('--id <pluginId>', 'Plugin id to trigger directly - skips the local manifest.json lookup (e.g. for `aivin mcp` plugins, which have no local project directory)')
|
|
406
|
+
.option('--func <name>', 'Which function to trigger, for a multi-function plugin (matches name/func/id) - ignored when --id is given')
|
|
407
|
+
.option('--workspace <id>', 'Workspace id to run against (default: auto-picks your first one)')
|
|
408
|
+
.option('--agent <id>', 'Agent id to run as, if the plugin needs one for HIL/confirm behavior to be accurate')
|
|
409
|
+
.option('--watch-logs', 'Also stream the plugin\'s own live console output inline (same feed as `aivin plugin logs`) instead of needing a second terminal - requires permission to view that plugin\'s logs (your own/org\'s deployments; most store plugins from other orgs will just skip this and fall back to the REST result only)')
|
|
410
|
+
.option('--save', 'Write this run\'s result to .test/trigger/<timestamp>.json for later --compare')
|
|
411
|
+
.option('--compare <file>', 'Diff this run\'s result against a previously --save\'d .test/trigger/*.json file')
|
|
412
|
+
.action(async (mission, input, options) => {
|
|
413
|
+
try {
|
|
414
|
+
await triggerPlugin(mission, input, options);
|
|
415
|
+
} catch (error) {
|
|
416
|
+
console.error(chalk.red('❌'), error.message);
|
|
417
|
+
process.exit(1);
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
pluginCommand
|
|
422
|
+
.command('logs [pluginId]')
|
|
423
|
+
.description('Tail a deployed plugin\'s own console output live (defaults to the current directory\'s manifest.json id)')
|
|
424
|
+
.option('--func <name>', 'Which function\'s id to resolve, for a multi-function plugin (only used when pluginId is omitted)')
|
|
425
|
+
.action(async (pluginId, options) => {
|
|
426
|
+
try {
|
|
427
|
+
await streamPluginLogs(pluginId, options);
|
|
428
|
+
} catch (error) {
|
|
429
|
+
console.error(chalk.red('❌'), error.message);
|
|
430
|
+
process.exit(1);
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
const connectorCommand = program.command('connector').description('Register and discover reusable connectors (OAuth apps / credential-form namespaces)');
|
|
435
|
+
|
|
436
|
+
connectorCommand
|
|
437
|
+
.command('register')
|
|
438
|
+
.description('Register a new connector namespace, interactively')
|
|
439
|
+
.action(async () => {
|
|
440
|
+
try {
|
|
441
|
+
await registerConnector();
|
|
442
|
+
} catch (error) {
|
|
443
|
+
console.error(chalk.red('❌'), error.message);
|
|
444
|
+
process.exit(1);
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
connectorCommand
|
|
449
|
+
.command('search [query]')
|
|
450
|
+
.description("Search connectors for something to reuse instead of registering a new one")
|
|
451
|
+
.option('--limit <n>', 'Max results to show')
|
|
452
|
+
.option('--plain', 'Print a flat list instead of the interactive browser (for scripts/CI)')
|
|
453
|
+
.action(async (query, options) => {
|
|
454
|
+
try {
|
|
455
|
+
query = await requireArg(query, { prompt: 'What are you looking for?', usage: 'Usage: aivin connector search "<query>"' });
|
|
456
|
+
await searchConnectors(query, options);
|
|
457
|
+
} catch (error) {
|
|
458
|
+
console.error(chalk.red('❌'), error.message);
|
|
459
|
+
process.exit(1);
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
connectorCommand
|
|
464
|
+
.command('list')
|
|
465
|
+
.description('List connectors visible to your org')
|
|
466
|
+
.option('--page <n>', 'Page number')
|
|
467
|
+
.option('--limit <n>', 'Items per page')
|
|
468
|
+
.option('--include-deprecated', "Also show your org's deprecated connectors (hidden by default)")
|
|
469
|
+
.option('--plain', 'Print a flat list instead of the interactive browser (for scripts/CI)')
|
|
470
|
+
.action(async (options) => {
|
|
471
|
+
try {
|
|
472
|
+
await listConnectors(options);
|
|
473
|
+
} catch (error) {
|
|
474
|
+
console.error(chalk.red('❌'), error.message);
|
|
475
|
+
process.exit(1);
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
connectorCommand
|
|
480
|
+
.command('deprecate [id]')
|
|
481
|
+
.description("Hide a connector you own from search/list without breaking plugins already using it")
|
|
482
|
+
.action(async (id) => {
|
|
483
|
+
try {
|
|
484
|
+
id = await requireArg(id, { prompt: 'Connector id to deprecate:', usage: 'Usage: aivin connector deprecate <id>' });
|
|
485
|
+
await axios.post(`${connectorBaseUrl()}/connectors/${encodeURIComponent(id)}/deprecate`, {}, connectorAuthHeaders());
|
|
486
|
+
console.log(chalk.green(`✅ "${id}" is now deprecated - still usable, hidden from new search/list.`));
|
|
487
|
+
} catch (error) {
|
|
488
|
+
const message = error.response?.data?.message || error.message;
|
|
489
|
+
console.error(chalk.red('❌'), message);
|
|
490
|
+
process.exit(1);
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
connectorCommand
|
|
495
|
+
.command('undeprecate [id]')
|
|
496
|
+
.description('Make a previously-deprecated connector you own discoverable again')
|
|
497
|
+
.action(async (id) => {
|
|
498
|
+
try {
|
|
499
|
+
id = await requireArg(id, { prompt: 'Connector id to un-deprecate:', usage: 'Usage: aivin connector undeprecate <id>' });
|
|
500
|
+
await axios.post(`${connectorBaseUrl()}/connectors/${encodeURIComponent(id)}/undeprecate`, {}, connectorAuthHeaders());
|
|
501
|
+
console.log(chalk.green(`✅ "${id}" is discoverable again.`));
|
|
502
|
+
} catch (error) {
|
|
503
|
+
const message = error.response?.data?.message || error.message;
|
|
504
|
+
console.error(chalk.red('❌'), message);
|
|
505
|
+
process.exit(1);
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
const pluginStoreCommand = program
|
|
510
|
+
.command('pluginstore')
|
|
511
|
+
.description('Self-hosted aivin-service worker (Docker) - attach it to your org as a plugin store. See docs/GETTING_STARTED.md.');
|
|
512
|
+
|
|
513
|
+
pluginStoreCommand
|
|
514
|
+
.command('create [store_id]')
|
|
515
|
+
.description('Create a new plugin store + attach this machine as its first node')
|
|
516
|
+
.option('--label <label>', 'Display label for the store (defaults to store_id)')
|
|
517
|
+
.option('--node-label <label>', 'Display label for this node/instance')
|
|
518
|
+
.option('--data-dir <path>', 'Where to write worker-identity.json (default: ~/.aivin/service-data)')
|
|
519
|
+
.action(async (storeId, options) => {
|
|
520
|
+
try {
|
|
521
|
+
await createStore(storeId, options);
|
|
522
|
+
} catch (error) {
|
|
523
|
+
console.error(chalk.red('❌'), error.message);
|
|
524
|
+
process.exit(1);
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
pluginStoreCommand
|
|
529
|
+
.command('attach [store_id]')
|
|
530
|
+
.description('Attach this machine as another node of an existing plugin store')
|
|
531
|
+
.option('--node-label <label>', 'Display label for this node/instance')
|
|
532
|
+
.option('--data-dir <path>', 'Where to write worker-identity.json (default: ~/.aivin/service-data)')
|
|
533
|
+
.action(async (storeId, options) => {
|
|
534
|
+
try {
|
|
535
|
+
await attachStore(storeId, options);
|
|
536
|
+
} catch (error) {
|
|
537
|
+
console.error(chalk.red('❌'), error.message);
|
|
538
|
+
process.exit(1);
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
pluginStoreCommand
|
|
543
|
+
.command('ls')
|
|
544
|
+
.description('List plugin stores visible to your org, with online/offline status per node')
|
|
545
|
+
.action(async (options) => {
|
|
546
|
+
try {
|
|
547
|
+
await listStores(options);
|
|
548
|
+
} catch (error) {
|
|
549
|
+
console.error(chalk.red('❌'), error.message);
|
|
550
|
+
process.exit(1);
|
|
551
|
+
}
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
pluginStoreCommand
|
|
555
|
+
.command('enable [store_id]')
|
|
556
|
+
.description('Enable a store for your org (org admin only)')
|
|
557
|
+
.action(async (storeId) => {
|
|
558
|
+
try {
|
|
559
|
+
storeId = await requireArg(storeId, { prompt: 'Store id to enable:', usage: 'Usage: aivin pluginstore enable <store_id>' });
|
|
560
|
+
await setStoreEnabled(storeId, true);
|
|
561
|
+
} catch (error) {
|
|
562
|
+
console.error(chalk.red('❌'), error.message);
|
|
563
|
+
process.exit(1);
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
|
|
567
|
+
pluginStoreCommand
|
|
568
|
+
.command('disable [store_id]')
|
|
569
|
+
.description('Disable a store for your org without deleting it (org admin only)')
|
|
570
|
+
.action(async (storeId) => {
|
|
571
|
+
try {
|
|
572
|
+
storeId = await requireArg(storeId, { prompt: 'Store id to disable:', usage: 'Usage: aivin pluginstore disable <store_id>' });
|
|
573
|
+
await setStoreEnabled(storeId, false);
|
|
574
|
+
} catch (error) {
|
|
575
|
+
console.error(chalk.red('❌'), error.message);
|
|
576
|
+
process.exit(1);
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
pluginStoreCommand
|
|
581
|
+
.command('rm [store_id]')
|
|
582
|
+
.description('Delete a store - revokes EVERY node attached to it, not just this machine (org admin only)')
|
|
583
|
+
.option('-y, --yes', 'Skip the confirmation prompt')
|
|
584
|
+
.action(async (storeId, options) => {
|
|
585
|
+
try {
|
|
586
|
+
storeId = await requireArg(storeId, { prompt: 'Store id to delete:', usage: 'Usage: aivin pluginstore rm <store_id>' });
|
|
587
|
+
await deleteStore(storeId, options);
|
|
588
|
+
} catch (error) {
|
|
589
|
+
console.error(chalk.red('❌'), error.message);
|
|
590
|
+
process.exit(1);
|
|
591
|
+
}
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
pluginStoreCommand
|
|
595
|
+
.command('detach')
|
|
596
|
+
.description("Remove THIS machine's pairing only (local file only, no BE call) - the running aivin-service picks it up automatically")
|
|
597
|
+
.option('--data-dir <path>', 'Where worker-identity.json lives (default: ~/.aivin/service-data)')
|
|
598
|
+
.action((options) => {
|
|
599
|
+
try {
|
|
600
|
+
detachStore(options);
|
|
601
|
+
} catch (error) {
|
|
602
|
+
console.error(chalk.red('❌'), error.message);
|
|
603
|
+
process.exit(1);
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
const mcpCommand = program
|
|
608
|
+
.command('mcp')
|
|
609
|
+
.description('MCP proxy plugins - wrap an external MCP server tool/resource/prompt, no code required');
|
|
610
|
+
|
|
611
|
+
mcpCommand
|
|
612
|
+
.argument('[url]', 'GitHub/GitLab/npm/Smithery URL, or a live MCP server URL, to scan and convert')
|
|
613
|
+
.option('--publish', 'Deploy to your org, then submit for community store review (needs admin approval)')
|
|
614
|
+
.option('--private', 'Deploy to your org only - default')
|
|
615
|
+
.option('--org', 'Alias of --private - there is no narrower per-workspace scope today')
|
|
616
|
+
.action(async (url, options) => {
|
|
617
|
+
try {
|
|
618
|
+
url = await requireArg(url, {
|
|
619
|
+
prompt: 'GitHub/GitLab/npm/Smithery URL, or a live MCP server URL:',
|
|
620
|
+
usage: 'Usage: aivin mcp <url> [--publish|--private|--org]',
|
|
621
|
+
});
|
|
622
|
+
await scanAndPublishMcp(url, options);
|
|
623
|
+
} catch (error) {
|
|
624
|
+
console.error(chalk.red('❌'), error.message);
|
|
625
|
+
process.exit(1);
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
mcpCommand
|
|
630
|
+
.command('create [name]')
|
|
631
|
+
.description('Scaffold a manifest-only plugin that proxies to an external MCP server')
|
|
632
|
+
.option('--transport <transport>', 'stdio | sse')
|
|
633
|
+
.option('--command <command>', 'Command to launch the MCP server (stdio transport)')
|
|
634
|
+
.option('--args <args>', 'Space-separated args for --command (stdio transport)')
|
|
635
|
+
.option('--url <url>', 'Remote MCP server URL (sse transport)')
|
|
636
|
+
.option('--kind <kind>', 'tool | resource | prompt (default: tool)')
|
|
637
|
+
.option('--tool-name <name>', 'MCP tool name (kind=tool)')
|
|
638
|
+
.option('--resource-uri <uri>', 'MCP resource URI (kind=resource)')
|
|
639
|
+
.option('--resource-mime-type <mime>', 'MIME type of the resource (kind=resource)')
|
|
640
|
+
.option('--prompt-name <name>', 'MCP prompt name (kind=prompt)')
|
|
641
|
+
.option('--description <description>', 'Plugin description')
|
|
642
|
+
.option(
|
|
643
|
+
'--auth-secret-key <key>',
|
|
644
|
+
'Name of the workspace secret to use as the Bearer token, if the MCP server needs auth',
|
|
645
|
+
)
|
|
646
|
+
.action(async (name, options) => {
|
|
647
|
+
try {
|
|
648
|
+
name = await requireArg(name, { prompt: 'Plugin name (lowercase letters, numbers, hyphens):', usage: 'Usage: aivin mcp create <name>' });
|
|
649
|
+
await createMcpProxyPlugin(name, options);
|
|
650
|
+
} catch (error) {
|
|
651
|
+
console.error(chalk.red('❌'), error.message);
|
|
652
|
+
process.exit(1);
|
|
653
|
+
}
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
program
|
|
657
|
+
.command('login')
|
|
658
|
+
.argument('[baseUrl]', 'Server to log into (REST API base) - defaults to production (api.aivin.cloud). Pass a staging/self-hosted host to switch the machine\'s active context to it, e.g. `aivin login beta-api.aivin.vn`.')
|
|
659
|
+
.description('Log in and save an API key for plugin deployment (opens your browser by default)')
|
|
660
|
+
.option('-k, --api-key <key>', 'Set API key directly (skip login entirely)')
|
|
661
|
+
.option('--basic', 'Log in with email/password directly in the terminal instead of a browser')
|
|
662
|
+
.option('--google', 'Alias of the default browser flow - pick Google once the page opens')
|
|
663
|
+
.option('--client <client>', 'Client/org id to use with --basic (default: "aivin.cloud")')
|
|
664
|
+
.action(async (baseUrl, options) => {
|
|
665
|
+
try {
|
|
666
|
+
// Bare hostname (no scheme) is the common case for a quick `aivin login beta-api.aivin.vn` -
|
|
667
|
+
// assume https, same as every other *.aivin.* endpoint in this file.
|
|
668
|
+
const resolvedBaseUrl = baseUrl ? (/^https?:\/\//.test(baseUrl) ? baseUrl : `https://${baseUrl}`) : DEFAULT_AIVIN_BASE_URL;
|
|
669
|
+
process.env.AIVIN_BASE_URL = resolvedBaseUrl;
|
|
670
|
+
|
|
671
|
+
if (options.apiKey) {
|
|
672
|
+
console.log(chalk.blue('🔑 Setting API key...'));
|
|
673
|
+
// Best-effort - `aivin whoami` reads straight from the saved file with no server calls of
|
|
674
|
+
// its own, so whatever identity is resolvable here is all it will ever have to show.
|
|
675
|
+
const identity = await tryFetchWhoami(resolvedBaseUrl, options.apiKey);
|
|
676
|
+
const sdkEndpoint = saveGlobalApiKey(options.apiKey, resolvedBaseUrl, identity);
|
|
677
|
+
console.log(chalk.green('✅ API key set successfully!'));
|
|
678
|
+
console.log(chalk.gray(` Active context: ${resolvedBaseUrl}${sdkEndpoint ? ` (SDK_ENDPOINT: ${sdkEndpoint})` : ''}`));
|
|
679
|
+
console.log(chalk.green(`💾 Saved to ${GLOBAL_CREDENTIALS_PATH} - every project on this machine now targets this server.`));
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
// Only the browser flow needs a web app URL - fetch it from the backend itself (not needed/
|
|
684
|
+
// fetched for --basic, which never touches AIVIN_WEB_URL at all). Same override precedence
|
|
685
|
+
// as everywhere else: a caller-set AIVIN_WEB_URL (project .env/shell) always wins.
|
|
686
|
+
if (!options.basic && !process.env.AIVIN_WEB_URL) {
|
|
687
|
+
const webUrl = await fetchWebUrl(resolvedBaseUrl);
|
|
688
|
+
if (webUrl) {
|
|
689
|
+
process.env.AIVIN_WEB_URL = webUrl;
|
|
690
|
+
} else {
|
|
691
|
+
// fetchWebUrl swallows its own errors (bad host, typo'd domain, TLS/DNS failure) and
|
|
692
|
+
// returns null - warn instead of silently opening the PRODUCTION web app's login page,
|
|
693
|
+
// which would mint a key for the wrong server without any indication why.
|
|
694
|
+
console.log(chalk.yellow(`⚠️ Couldn't reach ${resolvedBaseUrl} to resolve its web app URL - check the host is correct.`));
|
|
695
|
+
console.log(chalk.yellow(` Falling back to the production web app (https://brain.aivin.cloud) - the key it mints will still be saved against ${resolvedBaseUrl}, likely NOT what you want.`));
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
const apiKey = options.basic ? await basicLogin(options) : await browserLogin();
|
|
700
|
+
|
|
701
|
+
console.log(chalk.green('✅ Login successful!'));
|
|
702
|
+
const identity = await tryFetchWhoami(resolvedBaseUrl, apiKey);
|
|
703
|
+
const sdkEndpoint = saveGlobalApiKey(apiKey, resolvedBaseUrl, identity);
|
|
704
|
+
console.log(chalk.gray(` Active context: ${resolvedBaseUrl}${sdkEndpoint ? ` (SDK_ENDPOINT: ${sdkEndpoint})` : ''}`));
|
|
705
|
+
console.log(chalk.green(`💾 Saved to ${GLOBAL_CREDENTIALS_PATH} - every project on this machine now targets this server.`));
|
|
706
|
+
} catch (error) {
|
|
707
|
+
console.log(chalk.red('❌ Login failed:'), error.message);
|
|
708
|
+
process.exit(1);
|
|
709
|
+
}
|
|
710
|
+
});
|
|
711
|
+
|
|
712
|
+
program
|
|
713
|
+
.command('logout')
|
|
714
|
+
.description('Clear the saved API key on this machine (~/.aivin/credentials) - run `aivin login` again to log back in')
|
|
715
|
+
.action(() => {
|
|
716
|
+
try {
|
|
717
|
+
// Captured BEFORE clearing so we can tell whether the currently-effective API_KEY (already
|
|
718
|
+
// loaded into process.env at startup - see the dotenv/loadActiveContext precedence block at
|
|
719
|
+
// the top of this file) came from this file or from a project's own .env, which logout never
|
|
720
|
+
// touches.
|
|
721
|
+
const savedContext = loadActiveContext();
|
|
722
|
+
const cleared = clearActiveContext();
|
|
723
|
+
if (cleared) {
|
|
724
|
+
console.log(chalk.green(`✅ Logged out - removed ${GLOBAL_CREDENTIALS_PATH}`));
|
|
725
|
+
} else {
|
|
726
|
+
console.log(chalk.gray('Already logged out - no saved credentials found.'));
|
|
727
|
+
}
|
|
728
|
+
if (process.env.API_KEY && process.env.API_KEY !== savedContext?.api_key) {
|
|
729
|
+
console.log(chalk.gray(" Note: this directory still has its own API_KEY set (from a project .env or shell env) - unset that too if you want it fully logged out here."));
|
|
730
|
+
}
|
|
731
|
+
} catch (error) {
|
|
732
|
+
console.error(chalk.red('❌'), error.message);
|
|
733
|
+
process.exit(1);
|
|
734
|
+
}
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
program
|
|
738
|
+
.command('whoami')
|
|
739
|
+
.description('Show which account is currently logged in on this machine (reads ~/.aivin/credentials - no server call)')
|
|
740
|
+
.action(() => {
|
|
741
|
+
try {
|
|
742
|
+
const apiKey = requireSavedApiKey();
|
|
743
|
+
const serverUrl = process.env.AIVIN_BASE_URL || DEFAULT_AIVIN_BASE_URL;
|
|
744
|
+
const localClient = parseApiKeyClient(apiKey);
|
|
745
|
+
|
|
746
|
+
// The effective API_KEY may come from a project's own .env instead of `~/.aivin/credentials`
|
|
747
|
+
// (see the dotenv precedence near the top of this file) - identity/login time only exist in
|
|
748
|
+
// the latter, so a project .env override has nothing to show beyond the key's own client id.
|
|
749
|
+
const savedContext = loadActiveContext();
|
|
750
|
+
const fromSavedContext = savedContext?.api_key === apiKey;
|
|
751
|
+
const identity = fromSavedContext ? savedContext : {};
|
|
752
|
+
|
|
753
|
+
console.log(chalk.green('✅ Logged in'));
|
|
754
|
+
console.log(chalk.gray(' Email: ') + (identity.email || chalk.gray('unknown')));
|
|
755
|
+
console.log(chalk.gray(' Name: ') + (identity.name || chalk.gray('unknown')));
|
|
756
|
+
console.log(chalk.gray(' Org: ') + (identity.org_name || identity.client || localClient || chalk.gray('unknown')));
|
|
757
|
+
if (identity.org_domain) console.log(chalk.gray(' Domain: ') + identity.org_domain);
|
|
758
|
+
console.log(chalk.gray(' Server: ') + serverUrl);
|
|
759
|
+
if (fromSavedContext && savedContext.logged_in_at) {
|
|
760
|
+
console.log(chalk.gray(' Logged in at: ') + new Date(savedContext.logged_in_at).toLocaleString());
|
|
761
|
+
} else if (!fromSavedContext) {
|
|
762
|
+
console.log(chalk.gray(" (API_KEY is from this project's .env, not `aivin login` - no recorded identity/login time)"));
|
|
763
|
+
} else if (!identity.email) {
|
|
764
|
+
console.log(chalk.gray(' (Account info wasn\'t resolvable at login time - run `aivin login` again to refresh it)'));
|
|
765
|
+
}
|
|
766
|
+
} catch (error) {
|
|
767
|
+
console.error(chalk.red('❌'), error.message);
|
|
768
|
+
process.exit(1);
|
|
769
|
+
}
|
|
770
|
+
});
|
|
771
|
+
|
|
772
|
+
const keyCommand = program.command('key').description('Manage named API keys for your account');
|
|
773
|
+
|
|
774
|
+
keyCommand
|
|
775
|
+
.command('gen [name]')
|
|
776
|
+
.description('Create (or replace) a named API key for your account - shown only once')
|
|
777
|
+
.option('--save', 'Also save this key as this machine\'s default (~/.aivin/credentials), like `aivin login -k`')
|
|
778
|
+
.action(async (name, options) => {
|
|
779
|
+
try {
|
|
780
|
+
name = await requireArg(name, { prompt: 'Name for this API key:', usage: 'Usage: aivin key gen <name>' });
|
|
781
|
+
console.log(chalk.blue(`🔑 Creating API key "${name}"...`));
|
|
782
|
+
const plainKey = await generateApiKey(name);
|
|
783
|
+
console.log(chalk.green('✅ API key created!'));
|
|
784
|
+
console.log(chalk.yellow('🔑 Key:'), chalk.cyan(plainKey));
|
|
785
|
+
console.log(chalk.gray(' This is shown only once - store it somewhere safe.'));
|
|
786
|
+
if (options.save) {
|
|
787
|
+
const serverUrl = process.env.AIVIN_BASE_URL || DEFAULT_AIVIN_BASE_URL;
|
|
788
|
+
const identity = await tryFetchWhoami(serverUrl, plainKey);
|
|
789
|
+
saveGlobalApiKey(plainKey, serverUrl, identity);
|
|
790
|
+
console.log(chalk.green(`💾 Saved to ${GLOBAL_CREDENTIALS_PATH} - every project on this machine can use it now.`));
|
|
791
|
+
}
|
|
792
|
+
} catch (error) {
|
|
793
|
+
console.error(chalk.red('❌'), error.message);
|
|
794
|
+
process.exit(1);
|
|
795
|
+
}
|
|
796
|
+
});
|
|
797
|
+
|
|
798
|
+
keyCommand
|
|
799
|
+
.command('revoke [name]')
|
|
800
|
+
.description('Revoke a named API key for your account')
|
|
801
|
+
.action(async (name) => {
|
|
802
|
+
try {
|
|
803
|
+
name = await requireArg(name, { prompt: 'Name of the API key to revoke:', usage: 'Usage: aivin key revoke <name>' });
|
|
804
|
+
console.log(chalk.blue(`🔑 Revoking API key "${name}"...`));
|
|
805
|
+
await revokeApiKeyByName(name);
|
|
806
|
+
console.log(chalk.green(`✅ API key "${name}" revoked.`));
|
|
807
|
+
} catch (error) {
|
|
808
|
+
console.error(chalk.red('❌'), error.message);
|
|
809
|
+
process.exit(1);
|
|
810
|
+
}
|
|
811
|
+
});
|
|
812
|
+
|
|
813
|
+
keyCommand
|
|
814
|
+
.command('list')
|
|
815
|
+
.description('List API keys on your account')
|
|
816
|
+
.action(async () => {
|
|
817
|
+
try {
|
|
818
|
+
const serverUrl = process.env.AIVIN_BASE_URL || 'https://api.aivin.cloud';
|
|
819
|
+
const apiKey = requireSavedApiKey();
|
|
820
|
+
await logAccountIdentity(serverUrl, apiKey);
|
|
821
|
+
const items = await listRemoteApiKeys(serverUrl, apiKey);
|
|
822
|
+
if (items.length === 0) {
|
|
823
|
+
console.log(chalk.gray('No API keys found.'));
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
items.forEach((k) => {
|
|
827
|
+
const created = k.created_at ? new Date(k.created_at).toISOString() : 'unknown';
|
|
828
|
+
console.log(` ${chalk.cyan(k.name)} ${chalk.gray(`(created ${created})`)}`);
|
|
829
|
+
});
|
|
830
|
+
} catch (error) {
|
|
831
|
+
console.error(chalk.red('❌'), error.message);
|
|
832
|
+
process.exit(1);
|
|
833
|
+
}
|
|
834
|
+
});
|
|
835
|
+
|
|
836
|
+
program
|
|
837
|
+
.command('browser [mission]')
|
|
838
|
+
.description("Run an AI Browser mission - by default opens/reuses a local browser window dedicated to AI Browser (own profile, own cookies - log in once, watch missions run live from then on); --remote uses a server-side browser instead")
|
|
839
|
+
.option('--remote', 'Use a server-side pooled browser instead of your own local one (no local browser needed, no cookies/logins carried over)')
|
|
840
|
+
.option('--debug-port <port>', 'Local mode only: port to look for/launch your browser\'s remote debugging on (default: 9222, auto-tries a few nearby ports if that one is taken by something else) - pass this to pin an exact port instead')
|
|
841
|
+
.option('--browser <edge|chrome>', "Local mode only: which browser to drive - default: auto-detects your OS's actual default browser, falling back to whichever of Edge/Chrome is installed if that can't be determined")
|
|
842
|
+
.option('--url <url>', "Local mode only: open this URL before the mission starts, instead of a blank page - skips a wasted first analysis step and avoids the AI having to search the web to find the target site itself (auto-guessed for a few well-known sites mentioned by name in the mission if omitted)")
|
|
843
|
+
.option('--workspace <id>', 'Workspace id to run in (default: your personal workspace)')
|
|
844
|
+
.option('--project <id>', 'Project id within the workspace (--remote only)')
|
|
845
|
+
.option('--agent <id>', "Agent id to run as (default: an auto-created/cached agent for local mode, or the workspace's default agent for --remote) - AI Browser is triggered as a tool this agent uses, real HIL suspend/resume requires an agent context")
|
|
846
|
+
.option('--no-watch', 'Fire the mission and return immediately - skip streaming live progress and auto-opening the viewer')
|
|
847
|
+
.option('--view', 'Just (re)open the fullscreen interactive viewer for whatever HIL session is already active - no mission is started')
|
|
848
|
+
.action(async (mission, options) => {
|
|
849
|
+
try {
|
|
850
|
+
if (!options.view) {
|
|
851
|
+
mission = await requireArg(mission, {
|
|
852
|
+
prompt: 'What should the AI Browser do?',
|
|
853
|
+
usage: 'Usage: aivin browser "<mission detail>" (or: aivin browser --view to just reopen the interactive viewer)',
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
await runBrowserMission(mission, options);
|
|
857
|
+
} catch (error) {
|
|
858
|
+
console.error(chalk.red('❌'), error.message);
|
|
859
|
+
process.exit(1);
|
|
860
|
+
}
|
|
861
|
+
});
|
|
862
|
+
|
|
863
|
+
const doCommand = program
|
|
864
|
+
.command('do [agentNickname] [mission]')
|
|
865
|
+
.description("Have <agentNickname> work toward a goal in the background - not a specific deployed plugin")
|
|
866
|
+
.option('--workspace <id>', 'Workspace id to run in (default: your personal workspace)')
|
|
867
|
+
.option('--project <id>', 'Project id within the workspace')
|
|
868
|
+
.option('--no-watch', 'Fire the mission and return immediately - skip streaming live progress')
|
|
869
|
+
.action(async (agentNickname, mission, options) => {
|
|
870
|
+
try {
|
|
871
|
+
mission = await requireArg(mission, {
|
|
872
|
+
prompt: 'What should the agent do?',
|
|
873
|
+
usage: 'Usage: aivin do <agent_nickname> "<mission detail>" (or: aivin do job "<automation job description>")',
|
|
874
|
+
});
|
|
875
|
+
await runMission(agentNickname, mission, options);
|
|
876
|
+
} catch (error) {
|
|
877
|
+
console.error(chalk.red('❌'), error.message);
|
|
878
|
+
process.exit(1);
|
|
879
|
+
}
|
|
880
|
+
});
|
|
881
|
+
|
|
882
|
+
doCommand
|
|
883
|
+
.command('job [description]')
|
|
884
|
+
.description('Create a new automation job from a plain-language description')
|
|
885
|
+
.option('--workspace <id>', 'Workspace id to create the job in (default: your personal workspace)')
|
|
886
|
+
.option('--project <id>', 'Project id within the workspace')
|
|
887
|
+
.option('--agent <id>', "Agent id the job runs as (default: the workspace's default agent)")
|
|
888
|
+
.option('--schedule <condition>', 'Natural-language schedule, e.g. "every Monday at 9am" (default: let the platform infer one)')
|
|
889
|
+
.action(async (description, options) => {
|
|
890
|
+
try {
|
|
891
|
+
description = await requireArg(description, { prompt: 'What should this automation job do?', usage: 'Usage: aivin do job "<automation job description>"' });
|
|
892
|
+
await createAutomationJob(description, options);
|
|
893
|
+
} catch (error) {
|
|
894
|
+
console.error(chalk.red('❌'), error.message);
|
|
895
|
+
process.exit(1);
|
|
896
|
+
}
|
|
897
|
+
});
|
|
898
|
+
|
|
899
|
+
const taskCommand = program
|
|
900
|
+
.command('task [description]')
|
|
901
|
+
.description('Create a new task from a plain-language description')
|
|
902
|
+
.option('--workspace <id>', 'Workspace id to create the task in (default: your personal workspace)')
|
|
903
|
+
.option('--project <id>', 'Project id within the workspace')
|
|
904
|
+
.option('--assignee <userId>', 'User id to assign the task to (default: unassigned)')
|
|
905
|
+
.action(async (description, options) => {
|
|
906
|
+
try {
|
|
907
|
+
description = await requireArg(description, {
|
|
908
|
+
prompt: 'What is this task?',
|
|
909
|
+
usage: 'Usage: aivin task "<description>" (or: aivin task list/mine/get/update/delete)',
|
|
910
|
+
});
|
|
911
|
+
await createTask(description, options);
|
|
912
|
+
} catch (error) {
|
|
913
|
+
console.error(chalk.red('❌'), error.message);
|
|
914
|
+
process.exit(1);
|
|
915
|
+
}
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
taskCommand
|
|
919
|
+
.command('list')
|
|
920
|
+
.description('List tasks in a project')
|
|
921
|
+
.option('--workspace <id>', 'Workspace id (default: your personal workspace)')
|
|
922
|
+
.option('--project <id>', "Project id (default: the workspace's first project)")
|
|
923
|
+
.option('--status <status>', 'Filter by status (todo/doing/done/backlog/cancel)')
|
|
924
|
+
.option('--assignee <userId>', 'Filter by assignee user id')
|
|
925
|
+
.option('--search <text>', 'Filter by search text')
|
|
926
|
+
.action(async (options) => {
|
|
927
|
+
try {
|
|
928
|
+
await listTasks(options);
|
|
929
|
+
} catch (error) {
|
|
930
|
+
console.error(chalk.red('❌'), error.message);
|
|
931
|
+
process.exit(1);
|
|
932
|
+
}
|
|
933
|
+
});
|
|
934
|
+
|
|
935
|
+
taskCommand
|
|
936
|
+
.command('mine')
|
|
937
|
+
.description('List tasks assigned to you in a project')
|
|
938
|
+
.option('--workspace <id>', 'Workspace id (default: your personal workspace)')
|
|
939
|
+
.option('--project <id>', "Project id (default: the workspace's first project)")
|
|
940
|
+
.action(async (options) => {
|
|
941
|
+
try {
|
|
942
|
+
await listMyTasks(options);
|
|
943
|
+
} catch (error) {
|
|
944
|
+
console.error(chalk.red('❌'), error.message);
|
|
945
|
+
process.exit(1);
|
|
946
|
+
}
|
|
947
|
+
});
|
|
948
|
+
|
|
949
|
+
taskCommand
|
|
950
|
+
.command('get [id]')
|
|
951
|
+
.description('Get a task by id')
|
|
952
|
+
.action(async (id) => {
|
|
953
|
+
try {
|
|
954
|
+
id = await requireArg(id, { prompt: 'Task id:', usage: 'Usage: aivin task get <id>' });
|
|
955
|
+
await getTaskById(id);
|
|
956
|
+
} catch (error) {
|
|
957
|
+
console.error(chalk.red('❌'), error.message);
|
|
958
|
+
process.exit(1);
|
|
959
|
+
}
|
|
960
|
+
});
|
|
961
|
+
|
|
962
|
+
taskCommand
|
|
963
|
+
.command('update [id]')
|
|
964
|
+
.description('Update a task')
|
|
965
|
+
.option('--status <status>', 'todo|doing|done|backlog|cancel')
|
|
966
|
+
.option('--title <title>', 'New title')
|
|
967
|
+
.option('--description <text>', 'New content/description')
|
|
968
|
+
.option('--assignee <userId>', 'Reassign to this user id')
|
|
969
|
+
.option('--priority <priority>', 'low|medium|high|urgent')
|
|
970
|
+
.action(async (id, options) => {
|
|
971
|
+
try {
|
|
972
|
+
id = await requireArg(id, { prompt: 'Task id:', usage: 'Usage: aivin task update <id>' });
|
|
973
|
+
await updateTaskById(id, options);
|
|
974
|
+
} catch (error) {
|
|
975
|
+
console.error(chalk.red('❌'), error.message);
|
|
976
|
+
process.exit(1);
|
|
977
|
+
}
|
|
978
|
+
});
|
|
979
|
+
|
|
980
|
+
taskCommand
|
|
981
|
+
.command('delete [id]')
|
|
982
|
+
.description('Delete a task')
|
|
983
|
+
.action(async (id) => {
|
|
984
|
+
try {
|
|
985
|
+
id = await requireArg(id, { prompt: 'Task id to delete:', usage: 'Usage: aivin task delete <id>' });
|
|
986
|
+
await deleteTaskById(id);
|
|
987
|
+
} catch (error) {
|
|
988
|
+
console.error(chalk.red('❌'), error.message);
|
|
989
|
+
process.exit(1);
|
|
990
|
+
}
|
|
991
|
+
});
|
|
992
|
+
|
|
993
|
+
program
|
|
994
|
+
.command('workspace')
|
|
995
|
+
.description('Browse your workspaces and projects, and pick one to use with --workspace/--project')
|
|
996
|
+
.option('--plain', 'Print a flat list instead of the interactive picker (for scripts/CI)')
|
|
997
|
+
.action(async (options) => {
|
|
998
|
+
try {
|
|
999
|
+
await pickWorkspaceAndProject(options);
|
|
1000
|
+
} catch (error) {
|
|
1001
|
+
console.error(chalk.red('❌'), error.message);
|
|
1002
|
+
process.exit(1);
|
|
1003
|
+
}
|
|
1004
|
+
});
|
|
1005
|
+
|
|
1006
|
+
const agentCommand = program.command('agent').description('List, search, install, create, and publish AI Staff agents');
|
|
1007
|
+
|
|
1008
|
+
agentCommand
|
|
1009
|
+
.command('list')
|
|
1010
|
+
.description('Browse agents already installed in a workspace (↑/↓ to move, space/enter for details, q to quit)')
|
|
1011
|
+
.option('--workspace <id>', 'Workspace id (default: your personal workspace)')
|
|
1012
|
+
.option('--plain', 'Print a flat list instead of the interactive browser (for scripts/CI)')
|
|
1013
|
+
.action(async (options) => {
|
|
1014
|
+
try {
|
|
1015
|
+
await listAgentsCmd(options);
|
|
1016
|
+
} catch (error) {
|
|
1017
|
+
console.error(chalk.red('❌'), error.message);
|
|
1018
|
+
process.exit(1);
|
|
1019
|
+
}
|
|
1020
|
+
});
|
|
1021
|
+
|
|
1022
|
+
agentCommand
|
|
1023
|
+
.command('search [query]')
|
|
1024
|
+
.description('Search the AI Staff marketplace for an agent')
|
|
1025
|
+
.option('--workspace <id>', 'Workspace id for context (default: your personal workspace)')
|
|
1026
|
+
.option('--limit <n>', 'Max results to show')
|
|
1027
|
+
.action(async (query, options) => {
|
|
1028
|
+
try {
|
|
1029
|
+
query = await requireArg(query, { prompt: 'What are you looking for?', usage: 'Usage: aivin agent search "<query>"' });
|
|
1030
|
+
const serverUrl = missionServerUrl();
|
|
1031
|
+
const authHeaders = missionAuthHeaders();
|
|
1032
|
+
const workspace = await resolveWorkspace(serverUrl, authHeaders, options.workspace);
|
|
1033
|
+
const results = await searchAgents(serverUrl, authHeaders, {
|
|
1034
|
+
query,
|
|
1035
|
+
workspaceId: workspace.id || workspace._id,
|
|
1036
|
+
limit: options.limit,
|
|
1037
|
+
});
|
|
1038
|
+
if (results.length === 0) {
|
|
1039
|
+
console.log(chalk.yellow(`No agents found matching "${query}".`));
|
|
1040
|
+
return;
|
|
1041
|
+
}
|
|
1042
|
+
console.log(chalk.blue(`Found ${results.length} agent(s) matching "${query}":\n`));
|
|
1043
|
+
results.forEach((a) => {
|
|
1044
|
+
console.log(chalk.bold(a.nickname || a.name) + chalk.gray(` (${a.id})`));
|
|
1045
|
+
if (a.bio) console.log(` ${a.bio}`);
|
|
1046
|
+
console.log();
|
|
1047
|
+
});
|
|
1048
|
+
} catch (error) {
|
|
1049
|
+
console.error(chalk.red('❌'), error.message);
|
|
1050
|
+
process.exit(1);
|
|
1051
|
+
}
|
|
1052
|
+
});
|
|
1053
|
+
|
|
1054
|
+
agentCommand
|
|
1055
|
+
.command('install [query]')
|
|
1056
|
+
.description('Search the marketplace and install an agent into a workspace')
|
|
1057
|
+
.option('--workspace <id>', 'Workspace id to install into (default: your personal workspace)')
|
|
1058
|
+
.action(async (query, options) => {
|
|
1059
|
+
try {
|
|
1060
|
+
const serverUrl = missionServerUrl();
|
|
1061
|
+
const authHeaders = missionAuthHeaders();
|
|
1062
|
+
const workspace = await resolveWorkspace(serverUrl, authHeaders, options.workspace);
|
|
1063
|
+
const workspaceId = workspace.id || workspace._id;
|
|
1064
|
+
|
|
1065
|
+
let picked;
|
|
1066
|
+
if (query) {
|
|
1067
|
+
const results = await searchAgents(serverUrl, authHeaders, { query, workspaceId, limit: 10 });
|
|
1068
|
+
if (results.length === 0) throw new Error(`No marketplace agents found matching "${query}".`);
|
|
1069
|
+
if (!process.stdout.isTTY || !process.stdin.isTTY) {
|
|
1070
|
+
picked = results[0];
|
|
1071
|
+
} else {
|
|
1072
|
+
const { pickedAgent } = await inquirer.prompt([
|
|
1073
|
+
{
|
|
1074
|
+
type: 'select',
|
|
1075
|
+
name: 'pickedAgent',
|
|
1076
|
+
message: 'Install which agent?',
|
|
1077
|
+
choices: results.map((a) => ({ name: `${a.nickname || a.name}${a.bio ? chalk.gray(` - ${a.bio}`) : ''}`, value: a })),
|
|
1078
|
+
},
|
|
1079
|
+
]);
|
|
1080
|
+
picked = pickedAgent;
|
|
1081
|
+
}
|
|
1082
|
+
} else {
|
|
1083
|
+
picked = await installAgentInteractive(serverUrl, authHeaders, workspaceId);
|
|
1084
|
+
console.log(chalk.gray(`Installed into ${workspace.name || workspaceId}.`));
|
|
1085
|
+
return;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
await pullAgentIntoWorkspace(serverUrl, authHeaders, { agentId: picked.id, workspaceId });
|
|
1089
|
+
console.log(chalk.green(`✅ Installed "${picked.nickname || picked.name}" into ${workspace.name || workspaceId}.`));
|
|
1090
|
+
} catch (error) {
|
|
1091
|
+
console.error(chalk.red('❌'), error.message);
|
|
1092
|
+
process.exit(1);
|
|
1093
|
+
}
|
|
1094
|
+
});
|
|
1095
|
+
|
|
1096
|
+
agentCommand
|
|
1097
|
+
.command('make')
|
|
1098
|
+
.description('Create a brand new AI Staff agent')
|
|
1099
|
+
.option('--name <name>', 'Agent name')
|
|
1100
|
+
.option('--nickname <nickname>', 'Agent nickname (used to @-mention/target it)')
|
|
1101
|
+
.option('--email <email>', 'Agent email')
|
|
1102
|
+
.option('--bio <bio>', 'Short bio')
|
|
1103
|
+
.option('--workspace <id>', 'Workspace to install the new agent into (default: your personal workspace)')
|
|
1104
|
+
.action(async (options) => {
|
|
1105
|
+
try {
|
|
1106
|
+
const serverUrl = missionServerUrl();
|
|
1107
|
+
const authHeaders = missionAuthHeaders();
|
|
1108
|
+
const workspace = await resolveWorkspace(serverUrl, authHeaders, options.workspace);
|
|
1109
|
+
|
|
1110
|
+
const canPrompt = process.stdout.isTTY && process.stdin.isTTY;
|
|
1111
|
+
const answers = { name: options.name, nickname: options.nickname, email: options.email, bio: options.bio };
|
|
1112
|
+
if ((!answers.name || !answers.nickname || !answers.email) && canPrompt) {
|
|
1113
|
+
const prompted = await inquirer.prompt(
|
|
1114
|
+
[
|
|
1115
|
+
!answers.name && { type: 'input', name: 'name', message: 'Agent name:', validate: (v) => v.trim().length > 0 || 'Required' },
|
|
1116
|
+
!answers.nickname && {
|
|
1117
|
+
type: 'input',
|
|
1118
|
+
name: 'nickname',
|
|
1119
|
+
message: 'Agent nickname (used to @-mention/target it):',
|
|
1120
|
+
validate: (v) => v.trim().length > 0 || 'Required',
|
|
1121
|
+
},
|
|
1122
|
+
!answers.email && { type: 'input', name: 'email', message: 'Agent email:', validate: (v) => v.trim().length > 0 || 'Required' },
|
|
1123
|
+
!answers.bio && { type: 'input', name: 'bio', message: 'Short bio (optional):' },
|
|
1124
|
+
].filter(Boolean),
|
|
1125
|
+
);
|
|
1126
|
+
Object.assign(answers, prompted);
|
|
1127
|
+
}
|
|
1128
|
+
if (!answers.name || !answers.nickname || !answers.email) {
|
|
1129
|
+
throw new Error('Usage: aivin agent make --name <name> --nickname <nickname> --email <email> [--bio <bio>]');
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
const agent = await createAgent(serverUrl, authHeaders, { ...answers, workspaceId: workspace.id || workspace._id });
|
|
1133
|
+
console.log(chalk.green(`✅ Created agent "${agent.nickname || agent.name}"!`));
|
|
1134
|
+
if (agent.id) console.log(chalk.gray(` ID: ${agent.id}`));
|
|
1135
|
+
} catch (error) {
|
|
1136
|
+
console.error(chalk.red('❌'), error.message);
|
|
1137
|
+
process.exit(1);
|
|
1138
|
+
}
|
|
1139
|
+
});
|
|
1140
|
+
|
|
1141
|
+
agentCommand
|
|
1142
|
+
.command('publish [agentId]')
|
|
1143
|
+
.description('Publish an agent you own to the marketplace')
|
|
1144
|
+
.option('--workspace <id>', 'Workspace the agent lives in (default: your personal workspace)')
|
|
1145
|
+
.action(async (agentId, options) => {
|
|
1146
|
+
try {
|
|
1147
|
+
const serverUrl = missionServerUrl();
|
|
1148
|
+
const authHeaders = missionAuthHeaders();
|
|
1149
|
+
const workspace = await resolveWorkspace(serverUrl, authHeaders, options.workspace);
|
|
1150
|
+
|
|
1151
|
+
if (!agentId) {
|
|
1152
|
+
const agents = workspace.agents || [];
|
|
1153
|
+
if (agents.length === 0) throw new Error(`Workspace "${workspace.name}" has no agents to publish.`);
|
|
1154
|
+
if (!process.stdout.isTTY || !process.stdin.isTTY) {
|
|
1155
|
+
throw new Error('Usage: aivin agent publish <agentId>');
|
|
1156
|
+
}
|
|
1157
|
+
const { pickedAgentId } = await inquirer.prompt([
|
|
1158
|
+
{
|
|
1159
|
+
type: 'select',
|
|
1160
|
+
name: 'pickedAgentId',
|
|
1161
|
+
message: 'Publish which agent?',
|
|
1162
|
+
choices: agents.map((a) => ({ name: a.nickname || a.name || a.id, value: a.id || a.agent_id })),
|
|
1163
|
+
},
|
|
1164
|
+
]);
|
|
1165
|
+
agentId = pickedAgentId;
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
await publishAgent(serverUrl, authHeaders, { agentId, workspaceId: workspace.id || workspace._id });
|
|
1169
|
+
console.log(chalk.green(`✅ Published agent ${agentId} to the marketplace.`));
|
|
1170
|
+
} catch (error) {
|
|
1171
|
+
console.error(chalk.red('❌'), error.message);
|
|
1172
|
+
process.exit(1);
|
|
1173
|
+
}
|
|
1174
|
+
});
|
|
1175
|
+
|
|
1176
|
+
const projectCommand = program.command('project').description('List, create, update, and delete projects within a workspace');
|
|
1177
|
+
|
|
1178
|
+
projectCommand
|
|
1179
|
+
.command('list')
|
|
1180
|
+
.description('List projects in a workspace')
|
|
1181
|
+
.option('--workspace <id>', 'Workspace id (default: your personal workspace)')
|
|
1182
|
+
.action(async (options) => {
|
|
1183
|
+
try {
|
|
1184
|
+
await listProjectsCmd(options);
|
|
1185
|
+
} catch (error) {
|
|
1186
|
+
console.error(chalk.red('❌'), error.message);
|
|
1187
|
+
process.exit(1);
|
|
1188
|
+
}
|
|
1189
|
+
});
|
|
1190
|
+
|
|
1191
|
+
projectCommand
|
|
1192
|
+
.command('create [name]')
|
|
1193
|
+
.description('Create a new project in a workspace')
|
|
1194
|
+
.option('--workspace <id>', 'Workspace id (default: your personal workspace)')
|
|
1195
|
+
.action(async (name, options) => {
|
|
1196
|
+
try {
|
|
1197
|
+
name = await requireArg(name, { prompt: 'Project name:', usage: 'Usage: aivin project create <name>' });
|
|
1198
|
+
await createProjectCmd(name, options);
|
|
1199
|
+
} catch (error) {
|
|
1200
|
+
console.error(chalk.red('❌'), error.message);
|
|
1201
|
+
process.exit(1);
|
|
1202
|
+
}
|
|
1203
|
+
});
|
|
1204
|
+
|
|
1205
|
+
projectCommand
|
|
1206
|
+
.command('update [id]')
|
|
1207
|
+
.description('Update a project (currently: rename)')
|
|
1208
|
+
.option('--workspace <id>', 'Workspace id (default: your personal workspace)')
|
|
1209
|
+
.option('--name <name>', 'New name')
|
|
1210
|
+
.action(async (id, options) => {
|
|
1211
|
+
try {
|
|
1212
|
+
id = await requireArg(id, { prompt: 'Project id:', usage: 'Usage: aivin project update <id> --name <new name>' });
|
|
1213
|
+
await updateProjectCmd(id, options);
|
|
1214
|
+
} catch (error) {
|
|
1215
|
+
console.error(chalk.red('❌'), error.message);
|
|
1216
|
+
process.exit(1);
|
|
1217
|
+
}
|
|
1218
|
+
});
|
|
1219
|
+
|
|
1220
|
+
projectCommand
|
|
1221
|
+
.command('delete [id]')
|
|
1222
|
+
.description('Delete a project')
|
|
1223
|
+
.option('--workspace <id>', 'Workspace id (default: your personal workspace)')
|
|
1224
|
+
.action(async (id, options) => {
|
|
1225
|
+
try {
|
|
1226
|
+
id = await requireArg(id, { prompt: 'Project id to delete:', usage: 'Usage: aivin project delete <id>' });
|
|
1227
|
+
await deleteProjectCmd(id, options);
|
|
1228
|
+
} catch (error) {
|
|
1229
|
+
console.error(chalk.red('❌'), error.message);
|
|
1230
|
+
process.exit(1);
|
|
1231
|
+
}
|
|
1232
|
+
});
|
|
1233
|
+
|
|
1234
|
+
export { validatePluginConfig, incrementVersion, validateMcpProxyConfig, buildDeploymentPayload, buildMcpManifest };
|
|
1235
|
+
|
|
1236
|
+
// Only parse argv when run directly (`aivin ...` / `node bin/cli.mjs ...`),
|
|
1237
|
+
// not when this module is imported (e.g. by tests) - otherwise Commander
|
|
1238
|
+
// would parse the importing process's argv and could call process.exit().
|
|
1239
|
+
//
|
|
1240
|
+
// `import.meta.url` is always the module's real (symlink-resolved) path, but `process.argv[1]` is
|
|
1241
|
+
// whatever literal path launched it - through `npm link`'s global shim that's a symlink
|
|
1242
|
+
// (~/AppData/Roaming/npm/node_modules/@aivin-labs/sdk/bin/cli.mjs -> this repo), which would never
|
|
1243
|
+
// string-equal the resolved URL and silently skip program.parse() entirely (global `aivin` would
|
|
1244
|
+
// do nothing at all). Resolve argv[1] through the same symlink before comparing.
|
|
1245
|
+
function resolveIsMain() {
|
|
1246
|
+
if (!process.argv[1]) return false;
|
|
1247
|
+
try {
|
|
1248
|
+
return import.meta.url === pathToFileURL(fs.realpathSync(process.argv[1])).href;
|
|
1249
|
+
} catch {
|
|
1250
|
+
return import.meta.url === pathToFileURL(process.argv[1]).href;
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
if (resolveIsMain()) {
|
|
1255
|
+
program.parse(process.argv);
|
|
1256
|
+
}
|