@pmate/cli 0.24.17 → 0.24.18

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
@@ -659,6 +659,7 @@ type AgentCommandArgs = {
659
659
  baseUrl?: string;
660
660
  hubBaseUrl?: string;
661
661
  from?: string;
662
+ profileId?: string;
662
663
  json: boolean;
663
664
  } | {
664
665
  type: Command.Agent;
package/dist/index.js CHANGED
@@ -107,6 +107,7 @@ function saveLoginSession(session, requestedApp = DEFAULT_APP_ID) {
107
107
  );
108
108
  }
109
109
  const accountId = session.session.identity?.accountId?.trim();
110
+ const profileId = session.profileId?.trim();
110
111
  const token = session.token?.trim();
111
112
  const issuedAt = session.session.issuedAt?.trim();
112
113
  const expiresAt = session.session.expiresAt?.trim();
@@ -116,6 +117,7 @@ function saveLoginSession(session, requestedApp = DEFAULT_APP_ID) {
116
117
  const nextSession = {
117
118
  token,
118
119
  accountId,
120
+ ...profileId ? { profileId } : {},
119
121
  issuedAt,
120
122
  expiresAt,
121
123
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
@@ -231,7 +233,7 @@ function isStoredSession(value) {
231
233
  return false;
232
234
  }
233
235
  const session = value;
234
- return typeof session.token === "string" && !!session.token.trim() && typeof session.accountId === "string" && !!session.accountId.trim() && typeof session.issuedAt === "string" && !!session.issuedAt.trim() && typeof session.expiresAt === "string" && !!session.expiresAt.trim() && typeof session.updatedAt === "string" && !!session.updatedAt.trim();
236
+ return typeof session.token === "string" && !!session.token.trim() && typeof session.accountId === "string" && !!session.accountId.trim() && (session.profileId === void 0 || typeof session.profileId === "string" && !!session.profileId.trim()) && typeof session.issuedAt === "string" && !!session.issuedAt.trim() && typeof session.expiresAt === "string" && !!session.expiresAt.trim() && typeof session.updatedAt === "string" && !!session.updatedAt.trim();
235
237
  }
236
238
  function resolveReadApp(store, options) {
237
239
  const requestedApp = options?.app?.trim();
@@ -283,6 +285,46 @@ var init_sessionStore = __esm({
283
285
  }
284
286
  });
285
287
 
288
+ // src/profileClient.ts
289
+ async function fetchDefaultProfileId(options) {
290
+ const token = options.token.trim();
291
+ const app = options.app.trim();
292
+ const accountId = options.accountId.trim();
293
+ if (!token || !app || !accountId) {
294
+ throw new Error("Missing token, app, or accountId for profile lookup.");
295
+ }
296
+ const url = new URL(`${resolveAuthApiBaseUrl(options.authApiBaseUrl)}/profiles`);
297
+ url.searchParams.set("app", app);
298
+ url.searchParams.set("account", accountId);
299
+ const response = await fetch(url, {
300
+ headers: {
301
+ Authorization: `Bearer ${token}`
302
+ }
303
+ });
304
+ if (!response.ok) {
305
+ const detail = await response.text();
306
+ throw new Error(
307
+ `Failed to resolve default profile (${response.status}): ${detail || response.statusText}`
308
+ );
309
+ }
310
+ const envelope = await response.json();
311
+ const profileId = envelope.data?.[0]?.id?.trim();
312
+ if (!profileId) {
313
+ throw new Error(`No profile found for app ${app} and account ${accountId}.`);
314
+ }
315
+ return profileId;
316
+ }
317
+ function resolveAuthApiBaseUrl(value) {
318
+ return (value || process.env.PMATE_AUTH_API_BASE_URL || process.env.AUTH_API_BASE_URL || DEFAULT_AUTH_API_BASE_URL).replace(/\/+$/, "");
319
+ }
320
+ var DEFAULT_AUTH_API_BASE_URL;
321
+ var init_profileClient = __esm({
322
+ "src/profileClient.ts"() {
323
+ "use strict";
324
+ DEFAULT_AUTH_API_BASE_URL = "https://auth-api-v2.pmate.chat";
325
+ }
326
+ });
327
+
286
328
  // node_modules/@pmate/meta/src/types/account.types.ts
287
329
  var init_account_types = __esm({
288
330
  "node_modules/@pmate/meta/src/types/account.types.ts"() {
@@ -8512,7 +8554,11 @@ var init_AgentClient = __esm({
8512
8554
  const timeoutMs = options?.timeoutMs ?? this.timeoutMs;
8513
8555
  await this.waitForConnection(timeoutMs);
8514
8556
  const token = options?.token ?? "";
8515
- await this.sendAuth(token, timeoutMs);
8557
+ const profileId = options?.profileId;
8558
+ if (!profileId) {
8559
+ throw new Error("AgentClient user auth requires profileId");
8560
+ }
8561
+ await this.sendAuth(token, timeoutMs, profileId);
8516
8562
  return true;
8517
8563
  }
8518
8564
  async prompt(request) {
@@ -8795,11 +8841,16 @@ var init_AgentClient = __esm({
8795
8841
  });
8796
8842
  });
8797
8843
  }
8798
- async sendAuth(token, timeoutMs) {
8844
+ async sendAuth(token, timeoutMs, profileId) {
8799
8845
  if (!this.ws || !this.from) {
8800
8846
  throw new Error("AgentClient not initialized");
8801
8847
  }
8802
- const msg = Msg.create(this.from, "@hub", 4 /* AUTH */, { token, as: "user" });
8848
+ const body = {
8849
+ token,
8850
+ as: "user",
8851
+ profileId
8852
+ };
8853
+ const msg = Msg.create(this.from, "@hub", 4 /* AUTH */, body);
8803
8854
  const waiter = this.waitForAuthAck(timeoutMs);
8804
8855
  await this.ws.sendMsg(msg);
8805
8856
  const success = await waiter;
@@ -8995,11 +9046,6 @@ function resolveAgentApiBaseUrl(value) {
8995
9046
  function resolveHubBaseUrl(value) {
8996
9047
  return (value || process.env.PMATE_AGENT_HUB_BASE_URL || DEFAULT_AGENT_HUB_BASE_URL).replace(/\/+$/, "");
8997
9048
  }
8998
- function readSessionToken() {
8999
- return readRequiredSession({
9000
- preferredApp: DEFAULT_APP_ID
9001
- }).token;
9002
- }
9003
9049
  function unwrapAgentResult(agentId, value) {
9004
9050
  if (!value || typeof value !== "object") {
9005
9051
  if (value == null) {
@@ -9045,6 +9091,7 @@ var init_AgentLlmClient = __esm({
9045
9091
  import_node_path11 = __toESM(require("path"));
9046
9092
  init_dist2();
9047
9093
  init_sessionStore();
9094
+ init_profileClient();
9048
9095
  DEFAULT_AGENT_API_BASE_URL = "https://agent-api.pmate.chat";
9049
9096
  DEFAULT_AGENT_HUB_BASE_URL = "https://hub.pmate.chat";
9050
9097
  DEFAULT_NAMESPACE = "pmate-cli";
@@ -9052,8 +9099,13 @@ var init_AgentLlmClient = __esm({
9052
9099
  DEFAULT_AGENT_PROMPT_TIMEOUT_MS = 12e4;
9053
9100
  AgentLlmClient = class {
9054
9101
  constructor(options) {
9055
- this.token = options?.token ?? readSessionToken();
9102
+ this.session = readRequiredSession({
9103
+ preferredApp: DEFAULT_APP_ID
9104
+ });
9105
+ this.token = options?.token ?? this.session.token;
9106
+ this.profileId = options?.profileId?.trim() || process.env.PMATE_PROFILE_ID || this.session.profileId;
9056
9107
  this.agentApiBaseUrl = resolveAgentApiBaseUrl(options?.agentApiBaseUrl);
9108
+ this.authApiBaseUrl = resolveAuthApiBaseUrl(options?.authApiBaseUrl);
9057
9109
  this.hubBaseUrl = resolveHubBaseUrl(options?.hubBaseUrl);
9058
9110
  this.from = options?.from ?? DEFAULT_FROM;
9059
9111
  this.agentService = new AgentService({
@@ -9072,8 +9124,10 @@ var init_AgentLlmClient = __esm({
9072
9124
  timeoutMs: DEFAULT_AGENT_PROMPT_TIMEOUT_MS
9073
9125
  });
9074
9126
  try {
9127
+ const profileId = await this.resolveProfileId();
9075
9128
  await client.login(options?.from ?? this.from, {
9076
- token: this.token
9129
+ token: this.token,
9130
+ profileId
9077
9131
  });
9078
9132
  const result = await client.prompt({
9079
9133
  agentId,
@@ -9093,8 +9147,10 @@ var init_AgentLlmClient = __esm({
9093
9147
  minChunkSizeBytes: 0
9094
9148
  });
9095
9149
  try {
9150
+ const profileId = await this.resolveProfileId();
9096
9151
  await client.login(options?.from ?? this.from, {
9097
- token: this.token
9152
+ token: this.token,
9153
+ profileId
9098
9154
  });
9099
9155
  const input = new AsyncStream();
9100
9156
  const stream = client.stream({
@@ -9111,6 +9167,18 @@ var init_AgentLlmClient = __esm({
9111
9167
  client.close();
9112
9168
  }
9113
9169
  }
9170
+ async resolveProfileId() {
9171
+ const profileId = this.profileId?.trim();
9172
+ if (profileId) {
9173
+ return profileId;
9174
+ }
9175
+ return fetchDefaultProfileId({
9176
+ token: this.token,
9177
+ app: DEFAULT_APP_ID,
9178
+ accountId: this.session.accountId,
9179
+ authApiBaseUrl: this.authApiBaseUrl
9180
+ });
9181
+ }
9114
9182
  };
9115
9183
  }
9116
9184
  });
@@ -9556,8 +9624,9 @@ var ListCommandHandler = class {
9556
9624
  var import_node_child_process = require("child_process");
9557
9625
  var import_node_http = require("http");
9558
9626
  init_sessionStore();
9627
+ init_profileClient();
9559
9628
  var AUTH_UI_BASE_URL = "https://auth.pmate.chat";
9560
- var AUTH_API_BASE_URL = "https://auth-api-v2.pmate.chat";
9629
+ var AUTH_API_BASE_URL = DEFAULT_AUTH_API_BASE_URL;
9561
9630
  var CALLBACK_PATH = "/pmate-login-callback";
9562
9631
  var LOGIN_TIMEOUT_MS = 5 * 60 * 1e3;
9563
9632
  function buildHostedLoginUrl(redirectUrl, appId = DEFAULT_APP_ID) {
@@ -9588,7 +9657,12 @@ var LoginCommandHandler = class {
9588
9657
  try {
9589
9658
  const token = await callback.waitForToken;
9590
9659
  const loginResponse = await this.exchangeSession(token, appId);
9591
- savedSession = saveLoginSession(loginResponse, appId);
9660
+ const profileId = await fetchDefaultProfileId({
9661
+ token: loginResponse.token,
9662
+ app: appId,
9663
+ accountId: loginResponse.session.identity.accountId
9664
+ });
9665
+ savedSession = saveLoginSession({ ...loginResponse, profileId }, appId);
9592
9666
  } finally {
9593
9667
  await callback.close();
9594
9668
  }
@@ -16602,7 +16676,8 @@ var AgentCommandHandler = class {
16602
16676
  token,
16603
16677
  agentApiBaseUrl: baseUrl,
16604
16678
  hubBaseUrl: args.hubBaseUrl,
16605
- from: args.from
16679
+ from: args.from,
16680
+ profileId: args.profileId
16606
16681
  });
16607
16682
  if (args.filePath) {
16608
16683
  const filePayload = this.tryReadJsonObjectFile(args.filePath);
@@ -21085,7 +21160,7 @@ function parseAgentArgs(tokens) {
21085
21160
  const ref = rest.shift();
21086
21161
  if (!ref) {
21087
21162
  throw new Error(
21088
- "Usage: agent call <ns:objectId> [--payload <json>] [--file <path>] [--base-url <url>] [--hub-base-url <url>] [--from <id>] [--json]"
21163
+ "Usage: agent call <ns:objectId> [--payload <json>] [--file <path>] [--base-url <url>] [--hub-base-url <url>] [--from <id>] [--profile-id <id>] [--json]"
21089
21164
  );
21090
21165
  }
21091
21166
  const parsed = parseNamespacedRef(ref, { entityLabel: "agent ref" });
@@ -21093,6 +21168,7 @@ function parseAgentArgs(tokens) {
21093
21168
  let payload;
21094
21169
  let hubBaseUrl;
21095
21170
  let from;
21171
+ let profileId;
21096
21172
  while (rest.length > 0) {
21097
21173
  const token = rest.shift();
21098
21174
  switch (token) {
@@ -21111,6 +21187,9 @@ function parseAgentArgs(tokens) {
21111
21187
  case "--from":
21112
21188
  from = requireValue(rest, token);
21113
21189
  break;
21190
+ case "--profile-id":
21191
+ profileId = requireValue(rest, token);
21192
+ break;
21114
21193
  case "--json":
21115
21194
  json = true;
21116
21195
  break;
@@ -21128,6 +21207,7 @@ function parseAgentArgs(tokens) {
21128
21207
  baseUrl,
21129
21208
  hubBaseUrl,
21130
21209
  from,
21210
+ profileId,
21131
21211
  json
21132
21212
  };
21133
21213
  }
@@ -23842,7 +23922,7 @@ var HELP_TEXT = [
23842
23922
  ` ${import_chalk4.default.gray(" update <ns:objectId> --file <path> [--base-url <url>] [--json]")}`,
23843
23923
  ` ${import_chalk4.default.gray(" rename --from <id> --to <id> --ns <namespace> [--base-url <url>] [--json]")}`,
23844
23924
  ` ${import_chalk4.default.gray(" move --from <id> --ns <namespace> --to-ns <namespace> [--to <id>] [--base-url <url>] [--json]")}`,
23845
- ` ${import_chalk4.default.gray(" call <ns:objectId> [--payload <json>] [--file <path>] [--base-url <url>] [--hub-base-url <url>] [--from <id>] [--json]")}`,
23925
+ ` ${import_chalk4.default.gray(" call <ns:objectId> [--payload <json>] [--file <path>] [--base-url <url>] [--hub-base-url <url>] [--from <id>] [--profile-id <id>] [--json]")}`,
23846
23926
  ` ${import_chalk4.default.gray(" --file reads JSON payload files, or streams binary files such as .wav to ASR agents; --payload becomes stream params for binary files")}`,
23847
23927
  ` ${import_chalk4.default.gray(" delete <ns:objectId> [--base-url <url>] [--json]")}`,
23848
23928
  ` ${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:factory session and default hub: https://hub.pmate.chat")}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pmate/cli",
3
- "version": "0.24.17",
3
+ "version": "0.24.18",
4
4
  "description": "CLI utilities for the pMate project",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -56,7 +56,7 @@
56
56
  "yaml": "^2.8.2"
57
57
  },
58
58
  "devDependencies": {
59
- "@pmate/agent-sdk": "^1.1.5",
59
+ "@pmate/agent-sdk": "^1.1.8",
60
60
  "@pmate/meta": "^1.1.13",
61
61
  "@pmate/utils": "^1.1.3",
62
62
  "@types/node": "^25.0.3",