@aiaiai-pt/martha-cli 0.18.0 → 0.19.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 +40 -56
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -11059,7 +11059,7 @@ import { createInterface as createInterface2 } from "node:readline";
11059
11059
  init_errors();
11060
11060
 
11061
11061
  // src/version.ts
11062
- var CLI_VERSION = "0.18.0";
11062
+ var CLI_VERSION = "0.19.0";
11063
11063
 
11064
11064
  // src/commands/sessions.ts
11065
11065
  function relativeTime(iso) {
@@ -13559,27 +13559,6 @@ var workflowsConfig = {
13559
13559
 
13560
13560
  // src/commands/agents.ts
13561
13561
  init_errors();
13562
-
13563
- // src/lib/collections.ts
13564
- init_errors();
13565
- var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
13566
- async function resolveCollectionIdForGrant(ctx, ref) {
13567
- if (UUID_RE.test(ref)) {
13568
- return ref;
13569
- }
13570
- const all = await ctx.api.get("/api/admin/collections", {
13571
- params: { active_only: "false" }
13572
- });
13573
- const bySlug = all.find((c) => c.slug === ref);
13574
- if (bySlug)
13575
- return bySlug.id;
13576
- const byName = all.find((c) => c.name === ref);
13577
- if (byName)
13578
- return byName.id;
13579
- throw new CLIError(`Collection '${ref}' not found (tried UUID, slug, and name).`, 3 /* NotFound */, "Run `martha documents collections --tree` to see available collections.");
13580
- }
13581
-
13582
- // src/commands/agents.ts
13583
13562
  function parseSetFlags(items) {
13584
13563
  const result = {};
13585
13564
  for (const item of items) {
@@ -13756,7 +13735,10 @@ var agentsConfig = {
13756
13735
  console.log(` Updated: ${agent.updated_at}`);
13757
13736
  },
13758
13737
  extraCommands: (parentCmd, getCtx, isJson) => {
13759
- parentCmd.command("add-function <agent> <functionName>").description("Add a function to an agent").option("--set <items...>", "Config overrides (key=value)").option("--collection <slug-or-id>", "Scope the grant to one collection (#372 PR2). " + "Server rejects with 400 if the function is collection-agnostic.").action(async (agent, functionName, opts) => {
13738
+ parentCmd.command("add-function <agent> <functionName>").description("Add a function to an agent").option("--set <items...>", "Config overrides (key=value)").option("--collection <slug-or-id>", "REMOVED (#609) collection access is managed separately; see error").action(async (agent, functionName, opts) => {
13739
+ if (opts.collection) {
13740
+ throw new CLIError("`--collection` was removed; collection access is managed separately: " + "`martha collections grant <collection> --to agent:<id>`.", 4 /* Validation */);
13741
+ }
13760
13742
  const ctx = getCtx();
13761
13743
  const body = {
13762
13744
  function_name: functionName
@@ -13764,36 +13746,29 @@ var agentsConfig = {
13764
13746
  if (opts.set) {
13765
13747
  body.config_overrides = parseSetFlags(opts.set);
13766
13748
  }
13767
- if (opts.collection) {
13768
- body.collection_id = await resolveCollectionIdForGrant(ctx, opts.collection);
13769
- }
13770
13749
  const result = await ctx.api.post(`${API_PATH}/${encodeURIComponent(agent)}/functions`, body);
13771
13750
  if (isJson()) {
13772
13751
  console.log(JSON.stringify(result, null, 2));
13773
13752
  return;
13774
13753
  }
13775
- const scopeLabel = opts.collection ? ` (scope: ${opts.collection})` : "";
13776
- console.log(`Added function '${functionName}' to agent '${agent}'${scopeLabel}`);
13754
+ console.log(`Added function '${functionName}' to agent '${agent}'`);
13777
13755
  });
13778
- parentCmd.command("remove-function <agent> <functionName>").description("Remove a function from an agent").option("--collection <slug-or-id>", "Revoke just the given collection scope (#372 PR2). " + "Omit to revoke the root grant (collection_id IS NULL).").action(async (agent, functionName, opts) => {
13779
- const ctx = getCtx();
13780
- let endpoint = `${API_PATH}/${encodeURIComponent(agent)}/functions/${encodeURIComponent(functionName)}`;
13756
+ parentCmd.command("remove-function <agent> <functionName>").description("Remove a function from an agent").option("--collection <slug-or-id>", "REMOVED (#609) collection access is managed separately; see error").action(async (agent, functionName, opts) => {
13781
13757
  if (opts.collection) {
13782
- const collId = await resolveCollectionIdForGrant(ctx, opts.collection);
13783
- endpoint += `?collection_id=${encodeURIComponent(collId)}`;
13758
+ throw new CLIError("`--collection` was removed; collection access is managed separately: " + "`martha collections revoke <collection> --to agent:<id>`.", 4 /* Validation */);
13784
13759
  }
13760
+ const ctx = getCtx();
13761
+ const endpoint = `${API_PATH}/${encodeURIComponent(agent)}/functions/${encodeURIComponent(functionName)}`;
13785
13762
  await ctx.api.del(endpoint);
13786
13763
  if (isJson()) {
13787
13764
  console.log(JSON.stringify({
13788
13765
  agent,
13789
13766
  function_name: functionName,
13790
- collection: opts.collection ?? null,
13791
13767
  removed: true
13792
13768
  }));
13793
13769
  return;
13794
13770
  }
13795
- const scopeLabel = opts.collection ? ` (scope: ${opts.collection})` : "";
13796
- console.log(`Removed function '${functionName}' from agent '${agent}'${scopeLabel}`);
13771
+ console.log(`Removed function '${functionName}' from agent '${agent}'`);
13797
13772
  });
13798
13773
  parentCmd.command("provision-auth <agent>").description("Provision, switch, or rotate agent auth credentials").requiredOption("--method <method>", "Auth method: service-account or api-key").action(async (agent, opts) => {
13799
13774
  const ctx = getCtx();
@@ -17051,7 +17026,10 @@ ${clients.length} client(s)`));
17051
17026
  }
17052
17027
  console.log(`Deleted client '${nameOrId}'`);
17053
17028
  });
17054
- cmd.command("grant <clientNameOrId> <type> <defName>").description("Grant a client access to a function, workflow, or agent").option("--config <items...>", "Config overrides (key=value, functions/agents only)").option("--collection <slug-or-id>", "Scope the grant to one collection (function grants only; #372 PR2)").action(async (clientNameOrId, type, defName, opts) => {
17029
+ cmd.command("grant <clientNameOrId> <type> <defName>").description("Grant a client access to a function, workflow, or agent").option("--config <items...>", "Config overrides (key=value, functions/agents only)").option("--collection <slug-or-id>", "REMOVED (#609) collection access is managed separately; see error").action(async (clientNameOrId, type, defName, opts) => {
17030
+ if (opts.collection) {
17031
+ throw new CLIError("`--collection` was removed; collection access is managed separately: " + "`martha collections grant <collection> --to client:<id>`.", 4 /* Validation */);
17032
+ }
17055
17033
  if (!VALID_TYPES.has(type)) {
17056
17034
  throw new CLIError(`Invalid type: '${type}'. Must be function, workflow, or agent.`, 4 /* Validation */);
17057
17035
  }
@@ -17079,30 +17057,23 @@ ${clients.length} client(s)`));
17079
17057
  }
17080
17058
  body.config_overrides = parseSetFlags(opts.config);
17081
17059
  }
17082
- if (opts.collection) {
17083
- if (accessType !== "function") {
17084
- throw new CLIError("--collection only applies to function grants (#372 PR2).", 4 /* Validation */);
17085
- }
17086
- body.collection_id = await resolveCollectionIdForGrant(ctx, opts.collection);
17087
- }
17088
17060
  const result = await ctx.api.post(endpoint, body);
17089
17061
  if (isJson()) {
17090
17062
  console.log(JSON.stringify(result, null, 2));
17091
17063
  return;
17092
17064
  }
17093
- const scopeLabel = opts.collection ? ` (scope: ${opts.collection})` : "";
17094
- console.log(`Granted ${accessType} '${defName}' to client '${clientNameOrId}'${scopeLabel}`);
17065
+ console.log(`Granted ${accessType} '${defName}' to client '${clientNameOrId}'`);
17095
17066
  });
17096
- cmd.command("revoke <clientNameOrId> <type> <defName>").description("Revoke a client's access to a function, workflow, or agent").option("--collection <slug-or-id>", "Revoke just the given collection scope (function grants only; #372 PR2). " + "Omit to revoke the root grant (collection_id IS NULL).").action(async (clientNameOrId, type, defName, opts) => {
17067
+ cmd.command("revoke <clientNameOrId> <type> <defName>").description("Revoke a client's access to a function, workflow, or agent").option("--collection <slug-or-id>", "REMOVED (#609) collection access is managed separately; see error").action(async (clientNameOrId, type, defName, opts) => {
17068
+ if (opts.collection) {
17069
+ throw new CLIError("`--collection` was removed; collection access is managed separately: " + "`martha collections revoke <collection> --to client:<id>`.", 4 /* Validation */);
17070
+ }
17097
17071
  if (!VALID_TYPES.has(type)) {
17098
17072
  throw new CLIError(`Invalid type: '${type}'. Must be function, workflow, or agent.`, 4 /* Validation */);
17099
17073
  }
17100
17074
  const accessType = type;
17101
17075
  const ctx = getCtx();
17102
17076
  const clientId = await resolveClientId(ctx, clientNameOrId);
17103
- if (opts.collection && accessType !== "function") {
17104
- throw new CLIError("--collection only applies to function grants (#372 PR2).", 4 /* Validation */);
17105
- }
17106
17077
  let endpoint;
17107
17078
  if (accessType === "agent") {
17108
17079
  endpoint = `${DEFS_API}/clients/${clientId}/agents/${encodeURIComponent(defName)}`;
@@ -17110,10 +17081,6 @@ ${clients.length} client(s)`));
17110
17081
  const defId = await resolveDefinitionId(ctx, accessType, defName);
17111
17082
  const typePlural = `${accessType}s`;
17112
17083
  endpoint = `${DEFS_API}/clients/${clientId}/${typePlural}/${encodeURIComponent(defId)}`;
17113
- if (opts.collection) {
17114
- const collId = await resolveCollectionIdForGrant(ctx, opts.collection);
17115
- endpoint += `?collection_id=${encodeURIComponent(collId)}`;
17116
- }
17117
17084
  }
17118
17085
  await ctx.api.del(endpoint);
17119
17086
  if (isJson()) {
@@ -17121,13 +17088,11 @@ ${clients.length} client(s)`));
17121
17088
  client: clientNameOrId,
17122
17089
  type: accessType,
17123
17090
  name: defName,
17124
- collection: opts.collection ?? null,
17125
17091
  revoked: true
17126
17092
  }));
17127
17093
  return;
17128
17094
  }
17129
- const scopeLabel = opts.collection ? ` (scope: ${opts.collection})` : "";
17130
- console.log(`Revoked ${accessType} '${defName}' from client '${clientNameOrId}'${scopeLabel}`);
17095
+ console.log(`Revoked ${accessType} '${defName}' from client '${clientNameOrId}'`);
17131
17096
  });
17132
17097
  const embed = cmd.command("embed").description("Create, configure, and test embeddable chat clients");
17133
17098
  function addEmbedConfigOptions(command) {
@@ -18396,6 +18361,25 @@ function registerPolicyCommands(program2) {
18396
18361
  // src/commands/authz.ts
18397
18362
  init_errors();
18398
18363
 
18364
+ // src/lib/collections.ts
18365
+ init_errors();
18366
+ var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
18367
+ async function resolveCollectionIdForGrant(ctx, ref) {
18368
+ if (UUID_RE.test(ref)) {
18369
+ return ref;
18370
+ }
18371
+ const all = await ctx.api.get("/api/admin/collections", {
18372
+ params: { active_only: "false" }
18373
+ });
18374
+ const bySlug = all.find((c) => c.slug === ref);
18375
+ if (bySlug)
18376
+ return bySlug.id;
18377
+ const byName = all.find((c) => c.name === ref);
18378
+ if (byName)
18379
+ return byName.id;
18380
+ throw new CLIError(`Collection '${ref}' not found (tried UUID, slug, and name).`, 3 /* NotFound */, "Run `martha documents collections --tree` to see available collections.");
18381
+ }
18382
+
18399
18383
  // src/lib/authz.ts
18400
18384
  init_errors();
18401
18385
  var EX_UNAVAILABLE = 69;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiaiai-pt/martha-cli",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "description": "Terminal-first client for the Martha AI platform",
5
5
  "homepage": "https://docs.martha.nomadriver.co",
6
6
  "repository": {