@pmate/cli 0.20.10 → 0.20.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -418,6 +418,17 @@ type AgentCommandArgs = {
418
418
  name: string;
419
419
  baseUrl?: string;
420
420
  json: boolean;
421
+ } | {
422
+ type: Command.Agent;
423
+ action: "call";
424
+ namespace: string;
425
+ name: string;
426
+ payload?: Record<string, unknown>;
427
+ filePath?: string;
428
+ baseUrl?: string;
429
+ hubBaseUrl?: string;
430
+ from?: string;
431
+ json: boolean;
421
432
  } | {
422
433
  type: Command.Agent;
423
434
  action: "rename";
package/dist/index.js CHANGED
@@ -12683,12 +12683,15 @@ var init_AgentLlmClient = __esm({
12683
12683
  }
12684
12684
  async prompt(name, payload, namespace = DEFAULT_NAMESPACE) {
12685
12685
  const agentId = `${namespace}:${name}`;
12686
+ return this.call(agentId, payload);
12687
+ }
12688
+ async call(agentId, payload, options) {
12686
12689
  const client = new import_agent_sdk.AgentClient({
12687
- baseUrl: this.hubBaseUrl,
12690
+ baseUrl: options?.hubBaseUrl ?? this.hubBaseUrl,
12688
12691
  agentService: this.agentService
12689
12692
  });
12690
12693
  try {
12691
- await client.login(this.from, {
12694
+ await client.login(options?.from ?? this.from, {
12692
12695
  token: this.token
12693
12696
  });
12694
12697
  const result = await client.prompt({
@@ -19108,6 +19111,7 @@ function parseMessageText(raw) {
19108
19111
  // src/commands/AgentCommandHandler.ts
19109
19112
  var import_node_fs11 = require("fs");
19110
19113
  var import_node_path16 = __toESM(require("path"));
19114
+ init_AgentLlmClient();
19111
19115
  init_sessionStore();
19112
19116
 
19113
19117
  // src/storeClient.ts
@@ -19476,6 +19480,25 @@ var AgentCommandHandler = class {
19476
19480
  this.renderJson(record, args.json);
19477
19481
  return;
19478
19482
  }
19483
+ case "call": {
19484
+ const payload = args.filePath ? this.readJsonObjectFile(args.filePath) : args.payload;
19485
+ const client = this.createRuntimeClient({
19486
+ token,
19487
+ agentApiBaseUrl: baseUrl,
19488
+ hubBaseUrl: args.hubBaseUrl,
19489
+ from: args.from
19490
+ });
19491
+ const result = await client.call(
19492
+ formatNamespacedDisplayId(args.namespace, args.name),
19493
+ payload,
19494
+ {
19495
+ hubBaseUrl: args.hubBaseUrl,
19496
+ from: args.from
19497
+ }
19498
+ );
19499
+ this.renderCallResult(result, args.json);
19500
+ return;
19501
+ }
19479
19502
  case "delete": {
19480
19503
  const record = await this.request(
19481
19504
  baseUrl,
@@ -19547,6 +19570,14 @@ var AgentCommandHandler = class {
19547
19570
  throw new Error(`Invalid JSON in ${absolutePath}: ${message}`);
19548
19571
  }
19549
19572
  }
19573
+ readJsonObjectFile(filePath) {
19574
+ const parsed = this.readJsonFile(filePath);
19575
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
19576
+ const absolutePath = import_node_path16.default.resolve(process.cwd(), filePath);
19577
+ throw new Error(`Invalid JSON in ${absolutePath}: expected an object`);
19578
+ }
19579
+ return parsed;
19580
+ }
19550
19581
  async request(baseUrl, token, method, pathname, body) {
19551
19582
  const response = await fetch(`${baseUrl}${pathname}`, {
19552
19583
  method,
@@ -19589,6 +19620,24 @@ var AgentCommandHandler = class {
19589
19620
  }
19590
19621
  ui.plain(JSON.stringify(value, null, 2));
19591
19622
  }
19623
+ renderCallResult(value, asJson) {
19624
+ if (value === null) {
19625
+ if (asJson) {
19626
+ this.renderJson(value, true);
19627
+ return;
19628
+ }
19629
+ ui.warn("Agent returned no result.");
19630
+ return;
19631
+ }
19632
+ if (typeof value === "string" && !asJson) {
19633
+ ui.plain(value);
19634
+ return;
19635
+ }
19636
+ this.renderJson(value, true);
19637
+ }
19638
+ createRuntimeClient(options) {
19639
+ return new AgentLlmClient(options);
19640
+ }
19592
19641
  renderNamespaces(items, asJson) {
19593
19642
  if (asJson) {
19594
19643
  ui.plain(JSON.stringify(items, null, 2));
@@ -21552,7 +21601,7 @@ function parseAgentArgs(tokens) {
21552
21601
  const rawAction = rest.shift();
21553
21602
  const action = rawAction === "view" ? "view" : rawAction;
21554
21603
  if (!action) {
21555
- throw new Error("Missing agent action. Use: agent namespaces|list|get|view|create|update|rename|delete");
21604
+ throw new Error("Missing agent action. Use: agent namespaces|list|get|view|create|update|rename|call|delete");
21556
21605
  }
21557
21606
  let baseUrl;
21558
21607
  let json = false;
@@ -21716,6 +21765,62 @@ function parseAgentArgs(tokens) {
21716
21765
  json
21717
21766
  };
21718
21767
  }
21768
+ if (action === "call") {
21769
+ const ref = rest.shift();
21770
+ if (!ref) {
21771
+ throw new Error(
21772
+ "Usage: agent call <ns:objectId> [--payload <json>] [--file <path>] [--base-url <url>] [--hub-base-url <url>] [--from <id>] [--json]"
21773
+ );
21774
+ }
21775
+ const parsed = parseNamespacedRef(ref, { entityLabel: "agent ref" });
21776
+ let filePath;
21777
+ let payload;
21778
+ let hubBaseUrl;
21779
+ let from;
21780
+ while (rest.length > 0) {
21781
+ const token = rest.shift();
21782
+ switch (token) {
21783
+ case "--payload":
21784
+ if (filePath) {
21785
+ throw new Error("Agent call accepts either --payload or --file, not both.");
21786
+ }
21787
+ payload = parseJsonObject(requireValue(rest, token), token);
21788
+ break;
21789
+ case "--file":
21790
+ if (payload) {
21791
+ throw new Error("Agent call accepts either --payload or --file, not both.");
21792
+ }
21793
+ filePath = requireValue(rest, token);
21794
+ break;
21795
+ case "--base-url":
21796
+ baseUrl = requireValue(rest, token);
21797
+ break;
21798
+ case "--hub-base-url":
21799
+ hubBaseUrl = requireValue(rest, token);
21800
+ break;
21801
+ case "--from":
21802
+ from = requireValue(rest, token);
21803
+ break;
21804
+ case "--json":
21805
+ json = true;
21806
+ break;
21807
+ default:
21808
+ throw new Error(`Unknown agent call option: ${token}`);
21809
+ }
21810
+ }
21811
+ return {
21812
+ type: "agent" /* Agent */,
21813
+ action,
21814
+ namespace: parsed.namespace,
21815
+ name: parsed.objectId,
21816
+ payload,
21817
+ filePath,
21818
+ baseUrl,
21819
+ hubBaseUrl,
21820
+ from,
21821
+ json
21822
+ };
21823
+ }
21719
21824
  if (action === "rename") {
21720
21825
  let namespace;
21721
21826
  let from;
@@ -21774,6 +21879,19 @@ function parseBareRenameId(value, entityName) {
21774
21879
  }
21775
21880
  return normalized;
21776
21881
  }
21882
+ function parseJsonObject(value, optionName) {
21883
+ let parsed;
21884
+ try {
21885
+ parsed = JSON.parse(value);
21886
+ } catch (error) {
21887
+ const message = error instanceof Error ? error.message : String(error);
21888
+ throw new Error(`Invalid JSON for ${optionName}: ${message}`);
21889
+ }
21890
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
21891
+ throw new Error(`Invalid JSON for ${optionName}: expected an object.`);
21892
+ }
21893
+ return parsed;
21894
+ }
21777
21895
 
21778
21896
  // src/nsCommandParser.ts
21779
21897
  var DEFAULT_CHAIN = "pmate";
@@ -22777,7 +22895,7 @@ var HELP_TEXT = [
22777
22895
  ` ${import_chalk4.default.cyan("collect")} Collect threads/messages from Electron chat app via CDP`,
22778
22896
  ` ${import_chalk4.default.gray(" --list [--endpoint <url>] [--json]")}`,
22779
22897
  ` ${import_chalk4.default.gray(" --thread <name> [--endpoint <url>] [--json]")}`,
22780
- ` ${import_chalk4.default.cyan("agent")} Manage agent registry entries via agent-ui-api`,
22898
+ ` ${import_chalk4.default.cyan("agent")} Manage agent registry entries and call agents for debugging`,
22781
22899
  ` ${import_chalk4.default.gray(" namespaces [--base-url <url>] [--json]")}`,
22782
22900
  ` ${import_chalk4.default.gray(" list [--namespace <ns>] [--base-url <url>] [--json]")}`,
22783
22901
  ` ${import_chalk4.default.gray(" get <ns:objectId> [--base-url <url>] [--json]")}`,
@@ -22785,8 +22903,9 @@ var HELP_TEXT = [
22785
22903
  ` ${import_chalk4.default.gray(" create [<namespace>] --file <path> [--base-url <url>] [--json]")}`,
22786
22904
  ` ${import_chalk4.default.gray(" update <ns:objectId> --file <path> [--base-url <url>] [--json]")}`,
22787
22905
  ` ${import_chalk4.default.gray(" rename --from <id> --to <id> --ns <namespace> [--base-url <url>] [--json]")}`,
22906
+ ` ${import_chalk4.default.gray(" call <ns:objectId> [--payload <json>] [--file <path>] [--base-url <url>] [--hub-base-url <url>] [--from <id>] [--json]")}`,
22788
22907
  ` ${import_chalk4.default.gray(" delete <ns:objectId> [--base-url <url>] [--json]")}`,
22789
- ` ${import_chalk4.default.gray(" list defaults to all namespaces; create defaults to namespace: pmate; default base URL: https://agent-api.pmate.chat")}`,
22908
+ ` ${import_chalk4.default.gray(" list defaults to all namespaces; create defaults to namespace: pmate; default base URL: https://agent-api.pmate.chat; call uses pmate:cli session and default hub: https://hub.pmate.chat")}`,
22790
22909
  ` ${import_chalk4.default.cyan("ns")} Manage registered namespaces`,
22791
22910
  ` ${import_chalk4.default.gray(" list [--chain <chain>] [--base-url <url>] [--json]")}`,
22792
22911
  ` ${import_chalk4.default.gray(" get <namespace> [--chain <chain>] [--base-url <url>] [--json]")}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pmate/cli",
3
- "version": "0.20.10",
3
+ "version": "0.20.11",
4
4
  "description": "CLI utilities for the pMate project",
5
5
  "license": "MIT",
6
6
  "bin": {