@pmate/cli 0.20.9 → 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 +11 -0
- package/dist/index.js +127 -37
- package/package.json +1 -1
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
|
|
@@ -19429,12 +19433,12 @@ var AgentCommandHandler = class {
|
|
|
19429
19433
|
return;
|
|
19430
19434
|
}
|
|
19431
19435
|
case "list": {
|
|
19432
|
-
const items =
|
|
19436
|
+
const items = (await this.request(
|
|
19433
19437
|
baseUrl,
|
|
19434
19438
|
token,
|
|
19435
19439
|
"GET",
|
|
19436
|
-
`/agents?namespace=${encodeURIComponent(args.namespace)}`
|
|
19437
|
-
)).items
|
|
19440
|
+
args.namespace ? `/agents?namespace=${encodeURIComponent(args.namespace)}` : "/agents/all"
|
|
19441
|
+
)).items;
|
|
19438
19442
|
this.renderList(items, args.json);
|
|
19439
19443
|
return;
|
|
19440
19444
|
}
|
|
@@ -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,
|
|
@@ -19567,35 +19598,6 @@ var AgentCommandHandler = class {
|
|
|
19567
19598
|
}
|
|
19568
19599
|
return payload.data;
|
|
19569
19600
|
}
|
|
19570
|
-
async listAgentsAcrossNamespaces(baseUrl, token) {
|
|
19571
|
-
const namespacesResponse = await this.request(
|
|
19572
|
-
baseUrl,
|
|
19573
|
-
token,
|
|
19574
|
-
"GET",
|
|
19575
|
-
"/agents/namespaces"
|
|
19576
|
-
);
|
|
19577
|
-
const namespaces = namespacesResponse.items.map((item) => item.namespace?.trim()).filter((value) => Boolean(value));
|
|
19578
|
-
if (namespaces.length === 0) {
|
|
19579
|
-
return [];
|
|
19580
|
-
}
|
|
19581
|
-
const listResponses = await Promise.all(
|
|
19582
|
-
namespaces.map(async (namespace) => {
|
|
19583
|
-
const response = await this.request(
|
|
19584
|
-
baseUrl,
|
|
19585
|
-
token,
|
|
19586
|
-
"GET",
|
|
19587
|
-
`/agents?namespace=${encodeURIComponent(namespace)}`
|
|
19588
|
-
);
|
|
19589
|
-
return response.items;
|
|
19590
|
-
})
|
|
19591
|
-
);
|
|
19592
|
-
const merged = listResponses.flat();
|
|
19593
|
-
const deduped = /* @__PURE__ */ new Map();
|
|
19594
|
-
for (const item of merged) {
|
|
19595
|
-
deduped.set(item.id, item);
|
|
19596
|
-
}
|
|
19597
|
-
return Array.from(deduped.values());
|
|
19598
|
-
}
|
|
19599
19601
|
renderList(items, asJson) {
|
|
19600
19602
|
if (asJson) {
|
|
19601
19603
|
ui.plain(JSON.stringify(items, null, 2));
|
|
@@ -19618,6 +19620,24 @@ var AgentCommandHandler = class {
|
|
|
19618
19620
|
}
|
|
19619
19621
|
ui.plain(JSON.stringify(value, null, 2));
|
|
19620
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
|
+
}
|
|
19621
19641
|
renderNamespaces(items, asJson) {
|
|
19622
19642
|
if (asJson) {
|
|
19623
19643
|
ui.plain(JSON.stringify(items, null, 2));
|
|
@@ -21581,7 +21601,7 @@ function parseAgentArgs(tokens) {
|
|
|
21581
21601
|
const rawAction = rest.shift();
|
|
21582
21602
|
const action = rawAction === "view" ? "view" : rawAction;
|
|
21583
21603
|
if (!action) {
|
|
21584
|
-
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");
|
|
21585
21605
|
}
|
|
21586
21606
|
let baseUrl;
|
|
21587
21607
|
let json = false;
|
|
@@ -21745,6 +21765,62 @@ function parseAgentArgs(tokens) {
|
|
|
21745
21765
|
json
|
|
21746
21766
|
};
|
|
21747
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
|
+
}
|
|
21748
21824
|
if (action === "rename") {
|
|
21749
21825
|
let namespace;
|
|
21750
21826
|
let from;
|
|
@@ -21803,6 +21879,19 @@ function parseBareRenameId(value, entityName) {
|
|
|
21803
21879
|
}
|
|
21804
21880
|
return normalized;
|
|
21805
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
|
+
}
|
|
21806
21895
|
|
|
21807
21896
|
// src/nsCommandParser.ts
|
|
21808
21897
|
var DEFAULT_CHAIN = "pmate";
|
|
@@ -22806,7 +22895,7 @@ var HELP_TEXT = [
|
|
|
22806
22895
|
` ${import_chalk4.default.cyan("collect")} Collect threads/messages from Electron chat app via CDP`,
|
|
22807
22896
|
` ${import_chalk4.default.gray(" --list [--endpoint <url>] [--json]")}`,
|
|
22808
22897
|
` ${import_chalk4.default.gray(" --thread <name> [--endpoint <url>] [--json]")}`,
|
|
22809
|
-
` ${import_chalk4.default.cyan("agent")} Manage agent registry entries
|
|
22898
|
+
` ${import_chalk4.default.cyan("agent")} Manage agent registry entries and call agents for debugging`,
|
|
22810
22899
|
` ${import_chalk4.default.gray(" namespaces [--base-url <url>] [--json]")}`,
|
|
22811
22900
|
` ${import_chalk4.default.gray(" list [--namespace <ns>] [--base-url <url>] [--json]")}`,
|
|
22812
22901
|
` ${import_chalk4.default.gray(" get <ns:objectId> [--base-url <url>] [--json]")}`,
|
|
@@ -22814,8 +22903,9 @@ var HELP_TEXT = [
|
|
|
22814
22903
|
` ${import_chalk4.default.gray(" create [<namespace>] --file <path> [--base-url <url>] [--json]")}`,
|
|
22815
22904
|
` ${import_chalk4.default.gray(" update <ns:objectId> --file <path> [--base-url <url>] [--json]")}`,
|
|
22816
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]")}`,
|
|
22817
22907
|
` ${import_chalk4.default.gray(" delete <ns:objectId> [--base-url <url>] [--json]")}`,
|
|
22818
|
-
` ${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")}`,
|
|
22819
22909
|
` ${import_chalk4.default.cyan("ns")} Manage registered namespaces`,
|
|
22820
22910
|
` ${import_chalk4.default.gray(" list [--chain <chain>] [--base-url <url>] [--json]")}`,
|
|
22821
22911
|
` ${import_chalk4.default.gray(" get <namespace> [--chain <chain>] [--base-url <url>] [--json]")}`,
|