poe-code 11.0.31 → 12.0.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.
package/dist/index.js CHANGED
@@ -87349,86 +87349,6 @@ var init_gaslight = __esm({
87349
87349
  }
87350
87350
  });
87351
87351
 
87352
- // src/sdk/credentials.ts
87353
- async function getPoeApiKey() {
87354
- const envKey = Object.hasOwn(process.env, "POE_API_KEY") ? process.env.POE_API_KEY : void 0;
87355
- if (typeof envKey === "string" && envKey.trim().length > 0) {
87356
- return envKey.trim();
87357
- }
87358
- const { store } = createSecretStore({
87359
- backendEnvVar: "POE_AUTH_BACKEND",
87360
- fileStore: {
87361
- salt: "poe-code:encrypted-file-auth-store:v1",
87362
- defaultDirectory: ".poe-code",
87363
- defaultFileName: "credentials.enc"
87364
- }
87365
- });
87366
- const storedKey = await store.get();
87367
- if (typeof storedKey === "string" && storedKey.trim().length > 0) {
87368
- return storedKey.trim();
87369
- }
87370
- throw new AuthenticationError("No API key found. Set POE_API_KEY or run 'poe-code login'.");
87371
- }
87372
- async function getPoeAuthIdentity(options = {}) {
87373
- const apiKey = options.apiKey ?? await getPoeApiKey();
87374
- return fetchPoeAuthIdentity({
87375
- apiKey,
87376
- baseUrl: options.baseUrl ?? resolvePoeApiBaseUrl(options.variables),
87377
- httpClient: options.httpClient
87378
- });
87379
- }
87380
- async function fetchPoeAuthIdentity(options) {
87381
- const httpClient = options.httpClient ?? createDefaultHttpClient();
87382
- const response = await httpClient(`${trimTrailingSlashes(options.baseUrl ?? resolvePoeApiBaseUrl())}/whoami`, {
87383
- method: "POST",
87384
- headers: {
87385
- Authorization: `Bearer ${options.apiKey}`
87386
- }
87387
- });
87388
- if (!response.ok) {
87389
- throw new ApiError(`Failed to fetch identity (HTTP ${response.status})`, {
87390
- httpStatus: response.status,
87391
- endpoint: "/v1/whoami"
87392
- });
87393
- }
87394
- return parsePoeAuthIdentity(await response.json());
87395
- }
87396
- function parsePoeAuthIdentity(value) {
87397
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
87398
- throw new ApiError("Malformed identity response from Poe API.", {
87399
- endpoint: "/v1/whoami"
87400
- });
87401
- }
87402
- const identity = value;
87403
- if (typeof identity.user_id !== "number" || !Number.isFinite(identity.user_id) || typeof identity.handle !== "string" || identity.handle.trim().length === 0 || typeof identity.name !== "string" || identity.name.trim().length === 0 || typeof identity.profile_picture !== "string") {
87404
- throw new ApiError("Malformed identity response from Poe API.", {
87405
- endpoint: "/v1/whoami"
87406
- });
87407
- }
87408
- return value;
87409
- }
87410
- function createDefaultHttpClient() {
87411
- return async (url, init) => {
87412
- const response = await globalThis.fetch(url, init);
87413
- return {
87414
- ok: response.ok,
87415
- status: response.status,
87416
- json: () => response.json()
87417
- };
87418
- };
87419
- }
87420
- function trimTrailingSlashes(value) {
87421
- return value.replace(/\/+$/, "");
87422
- }
87423
- var init_credentials = __esm({
87424
- "src/sdk/credentials.ts"() {
87425
- "use strict";
87426
- init_src17();
87427
- init_errors();
87428
- init_environment2();
87429
- }
87430
- });
87431
-
87432
87352
  // packages/github-workflows/src/frontmatter.ts
87433
87353
  var init_frontmatter4 = __esm({
87434
87354
  "packages/github-workflows/src/frontmatter.ts"() {
@@ -104750,6 +104670,34 @@ var init_logout = __esm({
104750
104670
  }
104751
104671
  });
104752
104672
 
104673
+ // src/sdk/auth-check.ts
104674
+ async function checkPoeAuth(options) {
104675
+ const response = await options.httpClient(createCurrentBalanceUrl2(options.baseUrl), {
104676
+ method: "GET",
104677
+ headers: {
104678
+ Authorization: `Bearer ${options.apiKey}`
104679
+ }
104680
+ });
104681
+ if (!response.ok) {
104682
+ throw new ApiError(`Failed to check authentication (HTTP ${response.status})`, {
104683
+ httpStatus: response.status,
104684
+ endpoint: "/usage/current_balance"
104685
+ });
104686
+ }
104687
+ }
104688
+ function createCurrentBalanceUrl2(baseUrl) {
104689
+ const url = new URL(baseUrl);
104690
+ const path191 = url.pathname.endsWith("/") ? url.pathname.slice(0, -1) : url.pathname;
104691
+ url.pathname = `${path191}/usage/current_balance`;
104692
+ return url.toString();
104693
+ }
104694
+ var init_auth_check = __esm({
104695
+ "src/sdk/auth-check.ts"() {
104696
+ "use strict";
104697
+ init_errors();
104698
+ }
104699
+ });
104700
+
104753
104701
  // src/cli/commands/json-output.ts
104754
104702
  function writeJson(value) {
104755
104703
  process.stdout.write(`${JSON.stringify(value)}
@@ -104779,8 +104727,6 @@ function registerAuthCommand(program, container) {
104779
104727
  auth.command("api_key", { hidden: true }).option("--reveal", "Print the full API key to stdout (for use in command substitution).").action(async (options) => {
104780
104728
  await executeApiKey(program, container, options);
104781
104729
  });
104782
- registerWhoamiCommand(auth, program, container);
104783
- registerWhoamiCommand(program, program, container);
104784
104730
  auth.command("login").description("Store a Poe API key for reuse across commands.").option("--api-key <key>", apiKeyFlagDescription("POE_API_KEY")).action(async (options) => {
104785
104731
  await executeLogin(program, container, options);
104786
104732
  });
@@ -104790,11 +104736,6 @@ function registerAuthCommand(program, container) {
104790
104736
  await executeLogout(program, container);
104791
104737
  });
104792
104738
  }
104793
- function registerWhoamiCommand(parent, program, container) {
104794
- parent.command("whoami").description("Print Poe account identity as JSON (uses POE_API_KEY if set).").option("--json", "Accepted for consistency with other commands; whoami always prints JSON.").action(async () => {
104795
- await executeWhoami(program, container);
104796
- });
104797
- }
104798
104739
  async function executeStatus(program, container, options = {}) {
104799
104740
  const flags = resolveCommandFlags(program);
104800
104741
  if (options.json === true) {
@@ -104811,24 +104752,23 @@ async function executeStatus(program, container, options = {}) {
104811
104752
  return;
104812
104753
  }
104813
104754
  if (flags.dryRun) {
104814
- resources.logger.dryRun("Dry run: would fetch identity from Poe API.");
104755
+ resources.logger.dryRun("Dry run: would check authentication with the Poe API.");
104815
104756
  resources.context.finalize();
104816
104757
  return;
104817
104758
  }
104818
104759
  const s = spinner();
104819
104760
  s.start("Checking authentication...");
104820
- let identity;
104821
104761
  try {
104822
- identity = await fetchPoeAuthIdentity({
104762
+ await checkPoeAuth({
104823
104763
  apiKey,
104824
- baseUrl: container.env.poeApiBaseUrl,
104764
+ baseUrl: container.env.poeBaseUrl,
104825
104765
  httpClient: container.httpClient
104826
104766
  });
104827
104767
  } catch (error3) {
104828
104768
  s.stop("Authentication failed");
104829
104769
  throw error3;
104830
104770
  }
104831
- s.stop(`Logged in as ${identity.name} (@${identity.handle})`);
104771
+ s.stop("Logged in");
104832
104772
  resources.context.finalize();
104833
104773
  } catch (error3) {
104834
104774
  if (error3 instanceof Error) {
@@ -104849,14 +104789,12 @@ async function writeStatusJson(container, flags) {
104849
104789
  writeJson({ loggedIn: true, dryRun: true });
104850
104790
  return;
104851
104791
  }
104852
- writeJson({
104853
- loggedIn: true,
104854
- identity: await fetchPoeAuthIdentity({
104855
- apiKey,
104856
- baseUrl: container.env.poeApiBaseUrl,
104857
- httpClient: container.httpClient
104858
- })
104792
+ await checkPoeAuth({
104793
+ apiKey,
104794
+ baseUrl: container.env.poeBaseUrl,
104795
+ httpClient: container.httpClient
104859
104796
  });
104797
+ writeJson({ loggedIn: true });
104860
104798
  }
104861
104799
  async function executeApiKey(program, container, options) {
104862
104800
  const flags = resolveCommandFlags(program);
@@ -104879,7 +104817,9 @@ async function executeApiKey(program, container, options) {
104879
104817
  }
104880
104818
  process.stdout.write(`${maskApiKey(apiKey)}
104881
104819
  `);
104882
- resources.logger.warn("Masked to the last 4 characters. Re-run with --reveal to print the full secret.");
104820
+ resources.logger.warn(
104821
+ "Masked to the last 4 characters. Re-run with --reveal to print the full secret."
104822
+ );
104883
104823
  resources.context.finalize();
104884
104824
  }
104885
104825
  function maskApiKey(apiKey) {
@@ -104893,27 +104833,6 @@ async function resolveAuthCredential(container, options = {}) {
104893
104833
  }
104894
104834
  return container.readApiKey(options);
104895
104835
  }
104896
- async function executeWhoami(program, container) {
104897
- const flags = resolveCommandFlags(program);
104898
- const apiKey = await resolveAuthCredential(container, { readOnly: flags.dryRun });
104899
- if (!apiKey) {
104900
- process.exitCode = 1;
104901
- return;
104902
- }
104903
- if (flags.dryRun) {
104904
- const resources = createExecutionResources(container, flags, "auth:whoami");
104905
- resources.logger.dryRun("Dry run: would fetch identity from Poe API.");
104906
- resources.context.finalize();
104907
- return;
104908
- }
104909
- writeJson(
104910
- await fetchPoeAuthIdentity({
104911
- apiKey,
104912
- baseUrl: container.env.poeApiBaseUrl,
104913
- httpClient: container.httpClient
104914
- })
104915
- );
104916
- }
104917
104836
  var init_auth = __esm({
104918
104837
  "src/cli/commands/auth.ts"() {
104919
104838
  "use strict";
@@ -104921,7 +104840,7 @@ var init_auth = __esm({
104921
104840
  init_shared();
104922
104841
  init_login();
104923
104842
  init_logout();
104924
- init_credentials();
104843
+ init_auth_check();
104925
104844
  init_json_output();
104926
104845
  }
104927
104846
  });
@@ -141960,6 +141879,8 @@ function wrapSandboxClosureForHost(closure, stackFrames, budget, callbacks) {
141960
141879
  );
141961
141880
  return pending;
141962
141881
  };
141882
+ if (closure.length !== void 0)
141883
+ Object.defineProperty(wrapped, "length", { value: closure.length });
141963
141884
  callbacks?.seen.set(closure, wrapped);
141964
141885
  callbacks?.entries.set(id, invoke2);
141965
141886
  callbacks?.hostFunctions.set(id, wrapped);
@@ -154022,12 +153943,12 @@ async function checkAuth2(container, credential) {
154022
153943
  return { name: "auth", ok: false, detail: 'Not logged in. Run "poe-code login".' };
154023
153944
  }
154024
153945
  try {
154025
- const identity = await fetchPoeAuthIdentity({
153946
+ await checkPoeAuth({
154026
153947
  apiKey: credential,
154027
- baseUrl: container.env.poeApiBaseUrl,
153948
+ baseUrl: container.env.poeBaseUrl,
154028
153949
  httpClient: container.httpClient
154029
153950
  });
154030
- return { name: "auth", ok: true, detail: `Logged in as ${identity.name} (@${identity.handle})` };
153951
+ return { name: "auth", ok: true, detail: "Logged in" };
154031
153952
  } catch (error3) {
154032
153953
  return {
154033
153954
  name: "auth",
@@ -154096,11 +154017,7 @@ async function checkRuntimes(services, resources) {
154096
154017
  if (!binaryName) {
154097
154018
  continue;
154098
154019
  }
154099
- const check = createBinaryExistsCheck(
154100
- binaryName,
154101
- `${service}-binary`,
154102
- `${binaryName} on PATH`
154103
- );
154020
+ const check = createBinaryExistsCheck(binaryName, `${service}-binary`, `${binaryName} on PATH`);
154104
154021
  try {
154105
154022
  await check.run({
154106
154023
  isDryRun: false,
@@ -154135,7 +154052,7 @@ var init_doctor = __esm({
154135
154052
  init_src8();
154136
154053
  init_shared();
154137
154054
  init_config5();
154138
- init_credentials();
154055
+ init_auth_check();
154139
154056
  init_command_checks();
154140
154057
  }
154141
154058
  });
@@ -155834,7 +155751,7 @@ var init_package2 = __esm({
155834
155751
  "package.json"() {
155835
155752
  package_default2 = {
155836
155753
  name: "poe-code",
155837
- version: "11.0.31",
155754
+ version: "12.0.0",
155838
155755
  description: "CLI tool to configure Poe API for developer workflows.",
155839
155756
  license: "MIT",
155840
155757
  type: "module",
@@ -156991,7 +156908,6 @@ var init_program = __esm({
156991
156908
  "ralph",
156992
156909
  "usage",
156993
156910
  "dashboard",
156994
- "whoami",
156995
156911
  "version",
156996
156912
  "help"
156997
156913
  ];
@@ -157358,7 +157274,81 @@ async function installSkill2(agentId, source, options = {}) {
157358
157274
 
157359
157275
  // src/index.ts
157360
157276
  init_gaslight();
157361
- init_credentials();
157277
+
157278
+ // src/sdk/credentials.ts
157279
+ init_src17();
157280
+ init_errors();
157281
+ init_environment2();
157282
+ async function getPoeApiKey() {
157283
+ const envKey = Object.hasOwn(process.env, "POE_API_KEY") ? process.env.POE_API_KEY : void 0;
157284
+ if (typeof envKey === "string" && envKey.trim().length > 0) {
157285
+ return envKey.trim();
157286
+ }
157287
+ const { store } = createSecretStore({
157288
+ backendEnvVar: "POE_AUTH_BACKEND",
157289
+ fileStore: {
157290
+ salt: "poe-code:encrypted-file-auth-store:v1",
157291
+ defaultDirectory: ".poe-code",
157292
+ defaultFileName: "credentials.enc"
157293
+ }
157294
+ });
157295
+ const storedKey = await store.get();
157296
+ if (typeof storedKey === "string" && storedKey.trim().length > 0) {
157297
+ return storedKey.trim();
157298
+ }
157299
+ throw new AuthenticationError("No API key found. Set POE_API_KEY or run 'poe-code login'.");
157300
+ }
157301
+ async function getPoeAuthIdentity(options = {}) {
157302
+ const apiKey = options.apiKey ?? await getPoeApiKey();
157303
+ return fetchPoeAuthIdentity({
157304
+ apiKey,
157305
+ baseUrl: options.baseUrl ?? resolvePoeApiBaseUrl(options.variables),
157306
+ httpClient: options.httpClient
157307
+ });
157308
+ }
157309
+ async function fetchPoeAuthIdentity(options) {
157310
+ const httpClient = options.httpClient ?? createDefaultHttpClient();
157311
+ const response = await httpClient(`${trimTrailingSlashes(options.baseUrl ?? resolvePoeApiBaseUrl())}/whoami`, {
157312
+ method: "POST",
157313
+ headers: {
157314
+ Authorization: `Bearer ${options.apiKey}`
157315
+ }
157316
+ });
157317
+ if (!response.ok) {
157318
+ throw new ApiError(`Failed to fetch identity (HTTP ${response.status})`, {
157319
+ httpStatus: response.status,
157320
+ endpoint: "/v1/whoami"
157321
+ });
157322
+ }
157323
+ return parsePoeAuthIdentity(await response.json());
157324
+ }
157325
+ function parsePoeAuthIdentity(value) {
157326
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
157327
+ throw new ApiError("Malformed identity response from Poe API.", {
157328
+ endpoint: "/v1/whoami"
157329
+ });
157330
+ }
157331
+ const identity = value;
157332
+ if (typeof identity.user_id !== "number" || !Number.isFinite(identity.user_id) || typeof identity.handle !== "string" || identity.handle.trim().length === 0 || typeof identity.name !== "string" || identity.name.trim().length === 0 || typeof identity.profile_picture !== "string") {
157333
+ throw new ApiError("Malformed identity response from Poe API.", {
157334
+ endpoint: "/v1/whoami"
157335
+ });
157336
+ }
157337
+ return value;
157338
+ }
157339
+ function createDefaultHttpClient() {
157340
+ return async (url, init) => {
157341
+ const response = await globalThis.fetch(url, init);
157342
+ return {
157343
+ ok: response.ok,
157344
+ status: response.status,
157345
+ json: () => response.json()
157346
+ };
157347
+ };
157348
+ }
157349
+ function trimTrailingSlashes(value) {
157350
+ return value.replace(/\/+$/, "");
157351
+ }
157362
157352
 
157363
157353
  // src/agent.ts
157364
157354
  init_src20();