@plaiful/cli 0.1.0 → 0.2.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/package.json +21 -21
- package/src/cli.js +101 -1
package/package.json
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@plaiful/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "The Plaiful CLI: work on your Plaiful product from your game repo, with no AWS access",
|
|
5
|
-
"bin": {
|
|
6
|
-
"plaiful": "bin/plaiful.js"
|
|
7
|
-
},
|
|
8
|
-
"files": [
|
|
9
|
-
"bin",
|
|
10
|
-
"src",
|
|
11
|
-
"README.md"
|
|
12
|
-
],
|
|
13
|
-
"engines": {
|
|
14
|
-
"node": ">=18"
|
|
15
|
-
},
|
|
16
|
-
"license": "UNLICENSED",
|
|
17
|
-
"publishConfig": {
|
|
18
|
-
"registry": "https://registry.npmjs.org/",
|
|
19
|
-
"access": "public"
|
|
20
|
-
}
|
|
21
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@plaiful/cli",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "The Plaiful CLI: work on your Plaiful product from your game repo, with no AWS access",
|
|
5
|
+
"bin": {
|
|
6
|
+
"plaiful": "bin/plaiful.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"bin",
|
|
10
|
+
"src",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=18"
|
|
15
|
+
},
|
|
16
|
+
"license": "UNLICENSED",
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"registry": "https://registry.npmjs.org/",
|
|
19
|
+
"access": "public"
|
|
20
|
+
}
|
|
21
|
+
}
|
package/src/cli.js
CHANGED
|
@@ -32,6 +32,13 @@ const HELP = `plaiful ${version}: work on your Plaiful product from your game re
|
|
|
32
32
|
plaiful lists your product's SSM lists (NPC roles, SmartBuilder list values, ...)
|
|
33
33
|
plaiful lists get <name> one list (a name in your namespace, e.g. shop_type, or the full /path)
|
|
34
34
|
plaiful lists set <name> <values...> write a list (values as words, or one comma-separated argument)
|
|
35
|
+
plaiful agents your product's SmartBuilder agents in dev
|
|
36
|
+
plaiful agents show <name> one agent's deployed config
|
|
37
|
+
plaiful agents deploy [files...] deploy or redeploy agents from their config files (default: every .json in
|
|
38
|
+
resources/agents/<product>/); a redeploy keeps the agent's own settings
|
|
39
|
+
plaiful agents run <name> [key=value...] make one record (placeholder values as key=value)
|
|
40
|
+
plaiful agents batch <name> [file] start a batch (a batch body file, or --count <n>) → a job id
|
|
41
|
+
plaiful agents status <name> <jobId> a batch's progress
|
|
35
42
|
plaiful upload <files...> upload map tiles into your dev assets bucket (map-data/; --dest map-data)
|
|
36
43
|
plaiful clone [product] [dir] clone the game repo, write .env.development, docs pull, npm install, open Zed
|
|
37
44
|
--no-install --no-open
|
|
@@ -56,7 +63,7 @@ function parse(argv) {
|
|
|
56
63
|
for (let i = 0; i < argv.length; i += 1) {
|
|
57
64
|
const a = argv[i];
|
|
58
65
|
if (['--json', '--no-browser', '--help', '-h', '--version', '--apply', '--reset', '--rows', '--no-install', '--no-open'].includes(a)) flags[a.replace(/^-+/, '')] = true;
|
|
59
|
-
else if (a === '--product' || a === '--api' || a === '--dir' || a === '--dest') {
|
|
66
|
+
else if (a === '--product' || a === '--api' || a === '--dir' || a === '--dest' || a === '--count') {
|
|
60
67
|
if (argv[i + 1] === undefined) throw new UsageError(`${a} needs a value`);
|
|
61
68
|
flags[a.slice(2)] = argv[i += 1];
|
|
62
69
|
} else if (a.startsWith('--')) throw new UsageError(`unknown option ${a}`);
|
|
@@ -383,6 +390,98 @@ async function lists(ctx, [sub, name, ...values]) {
|
|
|
383
390
|
throw new UsageError(`plaiful lists, lists get <name> or lists set <name> <values...> (not "${sub}")`);
|
|
384
391
|
}
|
|
385
392
|
|
|
393
|
+
// ── SmartBuilder agents ─────────────────────────────────────────────────────────────────────────────────────
|
|
394
|
+
|
|
395
|
+
const agentRoute = (r, rest = '') => `/partner/${encodeURIComponent(r.product)}/agents${rest}`;
|
|
396
|
+
const AGENT_NAME = /^[a-z0-9][a-z0-9-]{0,62}$/;
|
|
397
|
+
|
|
398
|
+
function readJsonFile(ctx, f) {
|
|
399
|
+
const file = path.resolve(ctx.io.cwd(), f);
|
|
400
|
+
if (!fs.existsSync(file) || !fs.statSync(file).isFile()) throw new UsageError(`${file} isn't a file`);
|
|
401
|
+
try { return { file, json: JSON.parse(fs.readFileSync(file, 'utf8')) }; } catch (e) { throw new UsageError(`${file} isn't valid JSON (${e.message})`); }
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/** The config files to deploy: the ones named, or every .json in resources/agents/<product>/. */
|
|
405
|
+
function agentFiles(ctx, r, files) {
|
|
406
|
+
if (files.length) return files;
|
|
407
|
+
const dir = path.join(ctx.io.cwd(), 'resources', 'agents', r.product);
|
|
408
|
+
if (!fs.existsSync(dir)) throw new UsageError(`no files named, and no ${path.relative(ctx.io.cwd(), dir)}/ folder: plaiful agents deploy <file.json>`);
|
|
409
|
+
const found = fs.readdirSync(dir).filter((n) => n.endsWith('.json')).map((n) => path.join(dir, n));
|
|
410
|
+
if (!found.length) throw new UsageError(`${path.relative(ctx.io.cwd(), dir)}/ has no .json agent configs`);
|
|
411
|
+
return found;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
async function agents(ctx, [sub, name, ...rest]) {
|
|
415
|
+
const r = repo(ctx);
|
|
416
|
+
if (!sub) {
|
|
417
|
+
const { data } = await ctx.call('GET', agentRoute(r));
|
|
418
|
+
const list = data.agents || [];
|
|
419
|
+
const lines = [`${r.product}'s SmartBuilder agents in dev:`];
|
|
420
|
+
if (!list.length) lines.push(' none yet (plaiful agents deploy <file.json>, or SmartBuilder in the CMS)');
|
|
421
|
+
for (const a of list) lines.push(` ${a.name || a.agent_name}${a.display_name ? ` ${a.display_name}` : ''}${a.business_purpose ? ` (${a.business_purpose})` : ''}`);
|
|
422
|
+
ctx.out(lines.join('\n'), data);
|
|
423
|
+
return 0;
|
|
424
|
+
}
|
|
425
|
+
if (sub === 'show') {
|
|
426
|
+
if (!name) throw new UsageError('which agent? plaiful agents show <name>');
|
|
427
|
+
const { data } = await ctx.call('GET', agentRoute(r, `/${encodeURIComponent(name)}`));
|
|
428
|
+
const a = data.agent || {};
|
|
429
|
+
const lines = [`${a.agent_name || name}: ${a.display_name || ''}`.trim(),
|
|
430
|
+
` table ${(a.storage || {}).table_name || '?'}, version ${(a.metadata || {}).version || '?'}, ${(a.metadata || {}).business_purpose || 'content'}`,
|
|
431
|
+
` fields ${(a.output_fields || []).join(', ')}`,
|
|
432
|
+
` lists ${Object.entries(a.ssm_parameters || {}).map(([k, v]) => `${k} ← ${v}`).join('; ') || 'none'}`,
|
|
433
|
+
` dedup ${a.duplicate_detection && a.duplicate_detection.enabled !== false ? `on ${[].concat(a.duplicate_detection.field || 'name').join(', ')}` : 'off'}`,
|
|
434
|
+
' (--json prints the whole config)'];
|
|
435
|
+
ctx.out(lines.join('\n'), data);
|
|
436
|
+
return 0;
|
|
437
|
+
}
|
|
438
|
+
if (sub === 'deploy') {
|
|
439
|
+
const files = agentFiles(ctx, r, [name, ...rest].filter(Boolean));
|
|
440
|
+
const done = [];
|
|
441
|
+
for (const f of files) {
|
|
442
|
+
const { file, json } = readJsonFile(ctx, f);
|
|
443
|
+
const agentName = json.agent_name || path.basename(file, '.json');
|
|
444
|
+
if (!AGENT_NAME.test(agentName)) throw new UsageError(`${path.basename(file)}: "${agentName}" isn't an agent name (lowercase letters, digits, hyphens)`);
|
|
445
|
+
const { data } = await ctx.call('POST', agentRoute(r, `/${agentName}`), { config: json });
|
|
446
|
+
done.push(data);
|
|
447
|
+
if (!ctx.flags.json) ctx.out(`${data.redeployed ? 'redeployed' : 'deployed'} ${data.agent_name}: table ${data.table_name}${data.table === 'created' ? ' (new)' : ''}, version ${data.version}`);
|
|
448
|
+
}
|
|
449
|
+
if (ctx.flags.json) ctx.out('', { success: true, product: r.product, deployed: done });
|
|
450
|
+
return 0;
|
|
451
|
+
}
|
|
452
|
+
if (sub === 'run') {
|
|
453
|
+
if (!name) throw new UsageError('which agent? plaiful agents run <name> [key=value...]');
|
|
454
|
+
const body = {};
|
|
455
|
+
for (const kv of rest) {
|
|
456
|
+
const i = kv.indexOf('=');
|
|
457
|
+
if (i < 1) throw new UsageError(`"${kv}" isn't key=value`);
|
|
458
|
+
body[kv.slice(0, i)] = kv.slice(i + 1);
|
|
459
|
+
}
|
|
460
|
+
const { data } = await ctx.call('POST', agentRoute(r, `/${encodeURIComponent(name)}/run`), body);
|
|
461
|
+
const rec = data.item || data.record || data;
|
|
462
|
+
ctx.out(`made ${rec.uuid || 'a record'}${rec.name ? `: ${rec.name}` : ''}`, data);
|
|
463
|
+
return 0;
|
|
464
|
+
}
|
|
465
|
+
if (sub === 'batch') {
|
|
466
|
+
if (!name) throw new UsageError('which agent? plaiful agents batch <name> [batch-body.json] (or --count <n>)');
|
|
467
|
+
let body;
|
|
468
|
+
if (rest[0]) body = readJsonFile(ctx, rest[0]).json;
|
|
469
|
+
else if (ctx.flags.count) body = { count: Number(ctx.flags.count) };
|
|
470
|
+
else throw new UsageError('give a batch body file, or --count <n>');
|
|
471
|
+
const { data } = await ctx.call('POST', agentRoute(r, `/${encodeURIComponent(name)}/batch`), body);
|
|
472
|
+
ctx.out(`started batch ${data.job_id} (${data.total_items || '?'} records). plaiful agents status ${name} ${data.job_id}`, data);
|
|
473
|
+
return 0;
|
|
474
|
+
}
|
|
475
|
+
if (sub === 'status') {
|
|
476
|
+
const [jobId] = rest;
|
|
477
|
+
if (!name || !jobId) throw new UsageError('plaiful agents status <name> <jobId>');
|
|
478
|
+
const { data } = await ctx.call('GET', agentRoute(r, `/${encodeURIComponent(name)}/batch/${encodeURIComponent(jobId)}`));
|
|
479
|
+
ctx.out(`${data.status || '?'}: ${data.completed_items ?? '?'} done, ${data.failed_items ?? 0} failed of ${data.total_items ?? '?'}`, data);
|
|
480
|
+
return 0;
|
|
481
|
+
}
|
|
482
|
+
throw new UsageError(`plaiful agents, or agents show | deploy | run | batch | status (not "${sub}")`);
|
|
483
|
+
}
|
|
484
|
+
|
|
386
485
|
async function upload(ctx, files) {
|
|
387
486
|
const r = repo(ctx);
|
|
388
487
|
if (!files.length) throw new UsageError('upload what? plaiful upload <files...> (map tiles: ovid-map-*.json)');
|
|
@@ -526,6 +625,7 @@ const COMMANDS = {
|
|
|
526
625
|
seed: (ctx, [store, ...paths]) => seedStore(ctx, store, paths),
|
|
527
626
|
status: (ctx) => status(ctx),
|
|
528
627
|
lists: (ctx, rest) => lists(ctx, rest),
|
|
628
|
+
agents: (ctx, rest) => agents(ctx, rest),
|
|
529
629
|
upload: (ctx, files) => upload(ctx, files),
|
|
530
630
|
clone: (ctx, rest) => clone(ctx, rest),
|
|
531
631
|
env: (ctx) => envCmd(ctx),
|