@aiaiai-pt/martha-cli 0.23.0 → 0.24.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.
Files changed (2) hide show
  1. package/dist/index.js +191 -9
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -11077,7 +11077,7 @@ import { createInterface as createInterface2 } from "node:readline";
11077
11077
  init_errors();
11078
11078
 
11079
11079
  // src/version.ts
11080
- var CLI_VERSION = "0.23.0";
11080
+ var CLI_VERSION = "0.24.0";
11081
11081
 
11082
11082
  // src/commands/sessions.ts
11083
11083
  function relativeTime(iso) {
@@ -14772,6 +14772,128 @@ Usage:
14772
14772
  }
14773
14773
  };
14774
14774
 
14775
+ // src/commands/prompts.ts
14776
+ var API_PATH2 = "/api/admin/definitions/prompts";
14777
+ var promptsConfig = {
14778
+ typeName: "prompt",
14779
+ typeNamePlural: "prompts",
14780
+ apiPath: API_PATH2,
14781
+ extractList: (data) => {
14782
+ const d = data;
14783
+ if (d.items && Array.isArray(d.items)) {
14784
+ return d.items;
14785
+ }
14786
+ throw new Error("Unexpected API response shape for prompts list");
14787
+ },
14788
+ extractTotal: (data) => {
14789
+ const d = data;
14790
+ return d.total;
14791
+ },
14792
+ listColumns: [
14793
+ { header: "NAME", accessor: (item) => String(item.name ?? "") },
14794
+ {
14795
+ header: "SCOPE",
14796
+ accessor: (item) => String(item.scope ?? "-")
14797
+ },
14798
+ {
14799
+ header: "PROD VER",
14800
+ accessor: (item) => {
14801
+ const prod = item.production;
14802
+ return prod?.version ? String(prod.version) : "-";
14803
+ }
14804
+ },
14805
+ {
14806
+ header: "STAGING VER",
14807
+ accessor: (item) => {
14808
+ const staging = item.staging;
14809
+ return staging?.version ? String(staging.version) : "-";
14810
+ }
14811
+ },
14812
+ {
14813
+ header: "PROTECTED",
14814
+ accessor: (item) => item.is_protected ? "yes" : "no"
14815
+ }
14816
+ ],
14817
+ renderDetail: (prompt2) => {
14818
+ console.log(source_default.bold(`Prompt: ${prompt2.name}
14819
+ `));
14820
+ if (prompt2.description)
14821
+ console.log(` ${prompt2.description}
14822
+ `);
14823
+ console.log(` Scope: ${prompt2.scope ?? "-"}`);
14824
+ console.log(` Protected: ${prompt2.is_protected ? source_default.yellow("yes") : "no"}`);
14825
+ const prod = prompt2.production;
14826
+ const staging = prompt2.staging;
14827
+ console.log(` Prod Ver: ${prod?.version ?? "-"}`);
14828
+ console.log(` Staging Ver: ${staging?.version ?? "-"}`);
14829
+ if (prompt2.updated_at)
14830
+ console.log(` Updated: ${prompt2.updated_at}`);
14831
+ const content = prompt2.content;
14832
+ if (content) {
14833
+ console.log(`
14834
+ ${source_default.bold("Content:")}`);
14835
+ const lines = content.split(`
14836
+ `).slice(0, 10);
14837
+ for (const line of lines) {
14838
+ console.log(` ${line}`);
14839
+ }
14840
+ if (content.split(`
14841
+ `).length > 10) {
14842
+ console.log(source_default.dim(` ... (${content.split(`
14843
+ `).length - 10} more lines)`));
14844
+ }
14845
+ }
14846
+ },
14847
+ extraListOptions: (cmd) => {
14848
+ cmd.option("--scope <scope>", "Filter by scope (global, tenant, agent)").option("--protected", "Show only protected prompts");
14849
+ },
14850
+ buildListParams: (opts) => {
14851
+ const params = {};
14852
+ if (opts.scope)
14853
+ params.scope = opts.scope;
14854
+ if (opts.protected)
14855
+ params.is_protected = "true";
14856
+ return params;
14857
+ },
14858
+ extraCommands: (parentCmd, getCtx, isJson) => {
14859
+ parentCmd.command("promote <name>").description("Promote staging version to production").action(async (name) => {
14860
+ const ctx = getCtx();
14861
+ const result = await ctx.api.post(`${API_PATH2}/${encodeURIComponent(name)}/promote`, {});
14862
+ if (isJson()) {
14863
+ console.log(JSON.stringify(result, null, 2));
14864
+ return;
14865
+ }
14866
+ const prodVer = result.production_version_number ?? result.version;
14867
+ console.log(`Promoted '${name}' staging → production (version ${prodVer})`);
14868
+ });
14869
+ parentCmd.command("linked-collections <name>").description("List collections using this prompt as an extra prompt").action(async (name) => {
14870
+ const ctx = getCtx();
14871
+ const response = await ctx.api.get(`${API_PATH2}/${encodeURIComponent(name)}/linked-collections`);
14872
+ const items = response.linked_collections ?? [];
14873
+ if (isJson()) {
14874
+ console.log(JSON.stringify(response, null, 2));
14875
+ return;
14876
+ }
14877
+ if (items.length === 0) {
14878
+ console.log(source_default.dim("No collections linked to this prompt."));
14879
+ return;
14880
+ }
14881
+ const nameW = Math.max(10, ...items.map((c) => String(c.collection_name ?? "").length));
14882
+ const header = ["COLLECTION", "DOCS", "PAGES", "CHUNKS"].map((h, i) => h.padEnd([nameW, 8, 8, 8][i])).join(" ");
14883
+ console.log(source_default.bold(header));
14884
+ console.log(source_default.dim("-".repeat(header.length)));
14885
+ for (const c of items) {
14886
+ console.log([
14887
+ String(c.collection_name ?? "").padEnd(nameW),
14888
+ String(c.document_count ?? 0).padEnd(8),
14889
+ String(c.page_count ?? 0).padEnd(8),
14890
+ String(c.chunk_count ?? 0).padEnd(8)
14891
+ ].join(" "));
14892
+ }
14893
+ });
14894
+ }
14895
+ };
14896
+
14775
14897
  // src/commands/triggers.ts
14776
14898
  init_errors();
14777
14899
  function triggerKind(item) {
@@ -15140,6 +15262,65 @@ ${items.length} collections`));
15140
15262
  if (col.updated_at)
15141
15263
  console.log(` Updated: ${col.updated_at}`);
15142
15264
  });
15265
+ cmd.command("collection-available-prompts <id>").description("List prompts available for a collection's extra prompts").action(async (id) => {
15266
+ const ctx = getCtx();
15267
+ const col = await resolveCollection(ctx, id);
15268
+ const items = await ctx.api.get(`/api/admin/collections/${encodeURIComponent(col.id)}/available-prompts`);
15269
+ if (isJson()) {
15270
+ console.log(JSON.stringify(items, null, 2));
15271
+ return;
15272
+ }
15273
+ if (items.length === 0) {
15274
+ console.log(source_default.dim("No prompts available."));
15275
+ return;
15276
+ }
15277
+ const nameW = Math.max(10, ...items.map((p) => String(p.name ?? "").length));
15278
+ const scopeW = Math.max(6, ...items.map((p) => String(p.scope ?? "").length));
15279
+ const header = ["NAME", "SCOPE", "DESCRIPTION"].map((h, i) => h.padEnd([nameW, scopeW, 40][i])).join(" ");
15280
+ console.log(source_default.bold(header));
15281
+ console.log(source_default.dim("-".repeat(header.length)));
15282
+ for (const p of items) {
15283
+ const desc = String(p.description ?? "-").slice(0, 40);
15284
+ console.log([
15285
+ String(p.name ?? "").padEnd(nameW),
15286
+ String(p.scope ?? "-").padEnd(scopeW),
15287
+ desc
15288
+ ].join(" "));
15289
+ }
15290
+ });
15291
+ cmd.command("collection-get-prompts <id>").description("Get current extra prompts for a collection").action(async (id) => {
15292
+ const ctx = getCtx();
15293
+ const col = await ctx.api.get(`/api/admin/collections/${encodeURIComponent(id)}`);
15294
+ if (isJson()) {
15295
+ console.log(JSON.stringify({ extra_prompt_ids: col.extra_prompt_ids ?? [] }, null, 2));
15296
+ return;
15297
+ }
15298
+ const promptIds = col.extra_prompt_ids ?? [];
15299
+ if (promptIds.length === 0) {
15300
+ console.log(source_default.dim("No extra prompts configured."));
15301
+ return;
15302
+ }
15303
+ console.log(source_default.bold(`Extra Prompts for '${col.name}':`));
15304
+ for (const pid of promptIds) {
15305
+ console.log(` - ${pid}`);
15306
+ }
15307
+ });
15308
+ cmd.command("collection-set-prompts <id> [prompt-ids...]").description("Set extra prompts for a collection (replaces existing)").option("--clear", "Clear all extra prompts").action(async (id, promptIds, opts) => {
15309
+ const ctx = getCtx();
15310
+ const col = await resolveCollection(ctx, id);
15311
+ const extraPromptIds = opts.clear ? [] : promptIds;
15312
+ const result = await ctx.api.put(`/api/admin/collections/${encodeURIComponent(col.id)}`, { extra_prompt_ids: extraPromptIds });
15313
+ if (isJson()) {
15314
+ console.log(JSON.stringify({ extra_prompt_ids: result.extra_prompt_ids ?? [] }, null, 2));
15315
+ return;
15316
+ }
15317
+ const newIds = result.extra_prompt_ids ?? [];
15318
+ if (newIds.length === 0) {
15319
+ console.log(`Cleared extra prompts for '${col.name}'`);
15320
+ } else {
15321
+ console.log(`Set ${newIds.length} extra prompt(s) for '${col.name}'`);
15322
+ }
15323
+ });
15143
15324
  cmd.command("create-collection").description("Create a new document collection").requiredOption("--name <name>", "Collection name").option("--description <text>", "Collection description").option("--parent <slug-or-id>", "Create as a sub-collection of the given collection (#372 PR1)").action(async (opts) => {
15144
15325
  const ctx = getCtx();
15145
15326
  const tenantId = await ctx.getTenantId();
@@ -16290,7 +16471,7 @@ ${items.length} task(s) available`));
16290
16471
 
16291
16472
  // src/commands/teams.ts
16292
16473
  init_errors();
16293
- var API_PATH2 = "/api/admin/teams";
16474
+ var API_PATH3 = "/api/admin/teams";
16294
16475
  var fmtDate3 = (v) => typeof v === "string" ? new Date(v).toISOString().slice(0, 16).replace("T", " ") : "-";
16295
16476
  function registerTeamCommands(program2) {
16296
16477
  const cmd = program2.command("teams").description("Manage agent teams");
@@ -16314,7 +16495,7 @@ function registerTeamCommands(program2) {
16314
16495
  };
16315
16496
  if (opts.description)
16316
16497
  body.description = opts.description;
16317
- const result = await ctx.api.post(API_PATH2, body);
16498
+ const result = await ctx.api.post(API_PATH3, body);
16318
16499
  if (isJson()) {
16319
16500
  console.log(JSON.stringify(result, null, 2));
16320
16501
  return;
@@ -16325,7 +16506,7 @@ function registerTeamCommands(program2) {
16325
16506
  });
16326
16507
  cmd.command("list").description("List teams").action(async () => {
16327
16508
  const ctx = getCtx();
16328
- const items = await ctx.api.get(API_PATH2);
16509
+ const items = await ctx.api.get(API_PATH3);
16329
16510
  if (isJson()) {
16330
16511
  console.log(JSON.stringify(items, null, 2));
16331
16512
  return;
@@ -16364,7 +16545,7 @@ ${items.length} team(s)`));
16364
16545
  });
16365
16546
  cmd.command("view <nameOrId>").description("View team details with members").action(async (nameOrId) => {
16366
16547
  const ctx = getCtx();
16367
- const item = await ctx.api.get(`${API_PATH2}/${encodeURIComponent(nameOrId)}`);
16548
+ const item = await ctx.api.get(`${API_PATH3}/${encodeURIComponent(nameOrId)}`);
16368
16549
  if (isJson()) {
16369
16550
  console.log(JSON.stringify(item, null, 2));
16370
16551
  return;
@@ -16401,7 +16582,7 @@ ${items.length} team(s)`));
16401
16582
  if (Object.keys(body).length === 0) {
16402
16583
  throw new CLIError("No fields to update. Use --name, --description, or --routing.", 4 /* Validation */);
16403
16584
  }
16404
- const result = await ctx.api.put(`${API_PATH2}/${encodeURIComponent(nameOrId)}`, body);
16585
+ const result = await ctx.api.put(`${API_PATH3}/${encodeURIComponent(nameOrId)}`, body);
16405
16586
  if (isJson()) {
16406
16587
  console.log(JSON.stringify(result, null, 2));
16407
16588
  return;
@@ -16416,7 +16597,7 @@ ${items.length} team(s)`));
16416
16597
  throw new CLIError("Cancelled. Use --yes to skip confirmation.", 1 /* Error */);
16417
16598
  }
16418
16599
  }
16419
- await ctx.api.del(`${API_PATH2}/${encodeURIComponent(nameOrId)}`);
16600
+ await ctx.api.del(`${API_PATH3}/${encodeURIComponent(nameOrId)}`);
16420
16601
  if (isJson()) {
16421
16602
  console.log(JSON.stringify({ name: nameOrId, deleted: true }));
16422
16603
  return;
@@ -16429,7 +16610,7 @@ ${items.length} team(s)`));
16429
16610
  agent_name: agentName,
16430
16611
  role: opts.role
16431
16612
  };
16432
- const result = await ctx.api.post(`${API_PATH2}/${encodeURIComponent(team)}/members`, body);
16613
+ const result = await ctx.api.post(`${API_PATH3}/${encodeURIComponent(team)}/members`, body);
16433
16614
  if (isJson()) {
16434
16615
  console.log(JSON.stringify(result, null, 2));
16435
16616
  return;
@@ -16438,7 +16619,7 @@ ${items.length} team(s)`));
16438
16619
  });
16439
16620
  cmd.command("remove-member <team> <agentId>").description("Remove an agent from a team").action(async (team, agentId) => {
16440
16621
  const ctx = getCtx();
16441
- await ctx.api.del(`${API_PATH2}/${encodeURIComponent(team)}/members/${encodeURIComponent(agentId)}`);
16622
+ await ctx.api.del(`${API_PATH3}/${encodeURIComponent(team)}/members/${encodeURIComponent(agentId)}`);
16442
16623
  if (isJson()) {
16443
16624
  console.log(JSON.stringify({ team, agent_id: agentId, removed: true }));
16444
16625
  return;
@@ -20585,6 +20766,7 @@ registerConfigCommand(program2);
20585
20766
  registerDefinitionCommands(program2, functionsConfig);
20586
20767
  registerDefinitionCommands(program2, workflowsConfig);
20587
20768
  registerDefinitionCommands(program2, agentsConfig);
20769
+ registerDefinitionCommands(program2, promptsConfig);
20588
20770
  registerDefinitionCommands(program2, triggersConfig);
20589
20771
  registerDefinitionsApply(program2);
20590
20772
  registerDefinitionsExport(program2);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiaiai-pt/martha-cli",
3
- "version": "0.23.0",
3
+ "version": "0.24.0",
4
4
  "description": "Terminal-first client for the Martha AI platform",
5
5
  "homepage": "https://docs.martha.nomadriver.co",
6
6
  "repository": {