poe-code 3.0.23 → 3.0.24

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
@@ -15375,12 +15375,30 @@ var symbols = {
15375
15375
  // packages/design-system/src/components/logger.ts
15376
15376
  import { log } from "@clack/prompts";
15377
15377
  import chalk6 from "chalk";
15378
+
15379
+ // packages/design-system/src/internal/output-format.ts
15380
+ var VALID_FORMATS = /* @__PURE__ */ new Set(["terminal", "markdown", "json"]);
15381
+ var cached;
15382
+ function resolveOutputFormat(env = process.env) {
15383
+ if (cached) {
15384
+ return cached;
15385
+ }
15386
+ const raw = env.OUTPUT_FORMAT?.toLowerCase();
15387
+ cached = VALID_FORMATS.has(raw) ? raw : "terminal";
15388
+ return cached;
15389
+ }
15390
+
15391
+ // packages/design-system/src/components/logger.ts
15378
15392
  function createLogger(emitter) {
15379
15393
  const emit = (level, message) => {
15380
15394
  if (emitter) {
15381
15395
  emitter(message);
15382
15396
  return;
15383
15397
  }
15398
+ if (resolveOutputFormat() !== "terminal") {
15399
+ process.stdout.write(message + "\n");
15400
+ return;
15401
+ }
15384
15402
  if (level === "success") {
15385
15403
  log.message(message, { symbol: symbols.success });
15386
15404
  return;
@@ -15457,7 +15475,10 @@ function formatCommandNotFoundPanel(input) {
15457
15475
 
15458
15476
  // packages/design-system/src/components/table.ts
15459
15477
  import { Table } from "console-table-printer";
15460
- function renderTable(options) {
15478
+ function stripAnsi2(value) {
15479
+ return value.replace(/\u001b\[[0-9;]*m/g, "");
15480
+ }
15481
+ function renderTableTerminal(options) {
15461
15482
  const { theme, columns, rows } = options;
15462
15483
  const table = new Table({
15463
15484
  style: {
@@ -15499,6 +15520,37 @@ function renderTable(options) {
15499
15520
  }
15500
15521
  return table.render();
15501
15522
  }
15523
+ function renderTableMarkdown(options) {
15524
+ const { columns, rows } = options;
15525
+ const header = `| ${columns.map((c) => c.title).join(" | ")} |`;
15526
+ const separator = `| ${columns.map((c) => c.alignment === "right" ? "---:" : ":---").join(" | ")} |`;
15527
+ const dataRows = rows.map(
15528
+ (row) => `| ${columns.map((c) => stripAnsi2(row[c.name] ?? "").replace(/\|/g, "\\|")).join(" | ")} |`
15529
+ );
15530
+ return [header, separator, ...dataRows].join("\n");
15531
+ }
15532
+ function renderTableJson(options) {
15533
+ const { columns, rows } = options;
15534
+ const cleaned = rows.map((row) => {
15535
+ const obj = {};
15536
+ for (const col of columns) {
15537
+ obj[col.name] = stripAnsi2(row[col.name] ?? "");
15538
+ }
15539
+ return obj;
15540
+ });
15541
+ return JSON.stringify(cleaned, null, 2);
15542
+ }
15543
+ function renderTable(options) {
15544
+ const format = resolveOutputFormat();
15545
+ switch (format) {
15546
+ case "markdown":
15547
+ return renderTableMarkdown(options);
15548
+ case "json":
15549
+ return renderTableJson(options);
15550
+ default:
15551
+ return renderTableTerminal(options);
15552
+ }
15553
+ }
15502
15554
 
15503
15555
  // packages/design-system/src/acp/index.ts
15504
15556
  var acp_exports = {};
@@ -15549,7 +15601,7 @@ function renderReasoning(text4) {
15549
15601
  writeLine(chalk7.dim(` \u2713 ${truncate(text4, 80)}`));
15550
15602
  }
15551
15603
  function renderUsage(tokens) {
15552
- const cached2 = typeof tokens.cached === "number" && tokens.cached > 0 ? ` (${tokens.cached} cached)` : "";
15604
+ const cached3 = typeof tokens.cached === "number" && tokens.cached > 0 ? ` (${tokens.cached} cached)` : "";
15553
15605
  let cost = "";
15554
15606
  if (typeof tokens.costUsd === "number") {
15555
15607
  const formatted = new Intl.NumberFormat("en-US", {
@@ -15562,7 +15614,7 @@ function renderUsage(tokens) {
15562
15614
  }
15563
15615
  writeLine(
15564
15616
  chalk7.green(
15565
- `\u2713 tokens: ${tokens.input} in${cached2} \u2192 ${tokens.output} out${cost}`
15617
+ `\u2713 tokens: ${tokens.input} in${cached3} \u2192 ${tokens.output} out${cost}`
15566
15618
  )
15567
15619
  );
15568
15620
  }
@@ -15573,16 +15625,45 @@ function renderError(message) {
15573
15625
  // packages/design-system/src/prompts/index.ts
15574
15626
  import * as clack from "@clack/prompts";
15575
15627
  import { isCancel, cancel, log as log2 } from "@clack/prompts";
15628
+ function stripAnsi3(value) {
15629
+ return value.replace(/\u001b\[[0-9;]*m/g, "");
15630
+ }
15576
15631
  function intro2(title) {
15632
+ const format = resolveOutputFormat();
15633
+ if (format === "markdown") {
15634
+ process.stdout.write(`# ${stripAnsi3(title)}
15635
+
15636
+ `);
15637
+ return;
15638
+ }
15639
+ if (format === "json") {
15640
+ return;
15641
+ }
15577
15642
  clack.intro(text.intro(title));
15578
15643
  }
15579
15644
  function introPlain(title) {
15645
+ const format = resolveOutputFormat();
15646
+ if (format === "markdown") {
15647
+ process.stdout.write(`# ${stripAnsi3(title)}
15648
+
15649
+ `);
15650
+ return;
15651
+ }
15652
+ if (format === "json") {
15653
+ return;
15654
+ }
15580
15655
  clack.intro(title);
15581
15656
  }
15582
15657
  function outro2(message) {
15658
+ if (resolveOutputFormat() !== "terminal") {
15659
+ return;
15660
+ }
15583
15661
  clack.outro(message);
15584
15662
  }
15585
15663
  function note2(message, title) {
15664
+ if (resolveOutputFormat() !== "terminal") {
15665
+ return;
15666
+ }
15586
15667
  clack.note(message, title);
15587
15668
  }
15588
15669
  async function select2(opts) {
@@ -15637,6 +15718,10 @@ function createLoggerFactory(emitter, theme) {
15637
15718
  emitter(message);
15638
15719
  return;
15639
15720
  }
15721
+ if (resolveOutputFormat() !== "terminal") {
15722
+ process.stdout.write(message + "\n");
15723
+ return;
15724
+ }
15640
15725
  if (level === "success") {
15641
15726
  log2.message(message, { symbol: successSymbol });
15642
15727
  return;
@@ -15675,6 +15760,11 @@ function createLoggerFactory(emitter, theme) {
15675
15760
  emitter(`${label}: ${value}`);
15676
15761
  return;
15677
15762
  }
15763
+ if (resolveOutputFormat() !== "terminal") {
15764
+ process.stdout.write(`${label}: ${value}
15765
+ `);
15766
+ return;
15767
+ }
15678
15768
  const symbol2 = theme?.errorSymbol ?? chalk10.red("\u25A0");
15679
15769
  log2.message(`${label}
15680
15770
  ${value}`, { symbol: symbol2 });
@@ -15720,6 +15810,10 @@ function createLoggerFactory(emitter, theme) {
15720
15810
  emitter(formatMessage(message));
15721
15811
  return;
15722
15812
  }
15813
+ if (resolveOutputFormat() !== "terminal") {
15814
+ process.stdout.write(formatMessage(message) + "\n");
15815
+ return;
15816
+ }
15723
15817
  log2.message(formatMessage(message), { symbol: chalk10.gray("\u2502") });
15724
15818
  },
15725
15819
  intro(title) {
@@ -15738,6 +15832,11 @@ function createLoggerFactory(emitter, theme) {
15738
15832
  emitter(`${label}: ${value}`);
15739
15833
  return;
15740
15834
  }
15835
+ if (resolveOutputFormat() !== "terminal") {
15836
+ process.stdout.write(`${label}: ${value}
15837
+ `);
15838
+ return;
15839
+ }
15741
15840
  const symbol2 = theme?.resolvedSymbol ?? chalk10.magenta("\u25C7");
15742
15841
  log2.message(`${label}
15743
15842
  ${value}`, { symbol: symbol2 });
@@ -24184,7 +24283,7 @@ __export(util_exports, {
24184
24283
  assignProp: () => assignProp,
24185
24284
  base64ToUint8Array: () => base64ToUint8Array,
24186
24285
  base64urlToUint8Array: () => base64urlToUint8Array,
24187
- cached: () => cached,
24286
+ cached: () => cached2,
24188
24287
  captureStackTrace: () => captureStackTrace,
24189
24288
  cleanEnum: () => cleanEnum,
24190
24289
  cleanRegex: () => cleanRegex,
@@ -24260,7 +24359,7 @@ function jsonStringifyReplacer(_, value) {
24260
24359
  return value.toString();
24261
24360
  return value;
24262
24361
  }
24263
- function cached(getter) {
24362
+ function cached2(getter) {
24264
24363
  const set2 = false;
24265
24364
  return {
24266
24365
  get value() {
@@ -24376,7 +24475,7 @@ var captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace :
24376
24475
  function isObject(data) {
24377
24476
  return typeof data === "object" && data !== null && !Array.isArray(data);
24378
24477
  }
24379
- var allowsEval = cached(() => {
24478
+ var allowsEval = cached2(() => {
24380
24479
  if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) {
24381
24480
  return false;
24382
24481
  }
@@ -26463,7 +26562,7 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
26463
26562
  }
26464
26563
  });
26465
26564
  }
26466
- const _normalized = cached(() => normalizeDef(def));
26565
+ const _normalized = cached2(() => normalizeDef(def));
26467
26566
  defineLazy(inst._zod, "propValues", () => {
26468
26567
  const shape = def.shape;
26469
26568
  const propValues = {};
@@ -26514,7 +26613,7 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
26514
26613
  var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) => {
26515
26614
  $ZodObject.init(inst, def);
26516
26615
  const superParse = inst._zod.parse;
26517
- const _normalized = cached(() => normalizeDef(def));
26616
+ const _normalized = cached2(() => normalizeDef(def));
26518
26617
  const generateFastpass = (shape) => {
26519
26618
  const doc = new Doc(["shape", "payload", "ctx"]);
26520
26619
  const normalized = _normalized.value;
@@ -26750,7 +26849,7 @@ var $ZodDiscriminatedUnion = /* @__PURE__ */ $constructor("$ZodDiscriminatedUnio
26750
26849
  }
26751
26850
  return propValues;
26752
26851
  });
26753
- const disc = cached(() => {
26852
+ const disc = cached2(() => {
26754
26853
  const opts = def.options;
26755
26854
  const map2 = /* @__PURE__ */ new Map();
26756
26855
  for (const o of opts) {
@@ -35714,6 +35813,192 @@ function registerUsageCommand(program, container) {
35714
35813
  });
35715
35814
  }
35716
35815
 
35816
+ // src/cli/commands/models.ts
35817
+ init_shared();
35818
+ init_credentials();
35819
+ function formatTokenCount(tokens) {
35820
+ if (tokens >= 1048576) {
35821
+ const value = tokens / 1048576;
35822
+ return `${Number.isInteger(value) ? value : value.toFixed(1)}M`;
35823
+ }
35824
+ if (tokens >= 1024) {
35825
+ const value = tokens / 1024;
35826
+ return `${Number.isInteger(value) ? value : value.toFixed(1)}K`;
35827
+ }
35828
+ return String(tokens);
35829
+ }
35830
+ function formatPrice(perToken) {
35831
+ const perMTok = Math.round(perToken * 1e6 * 100) / 100;
35832
+ return `$${perMTok.toFixed(2)}`;
35833
+ }
35834
+ function formatOptionalPrice(value) {
35835
+ return value != null ? formatPrice(value) : "-";
35836
+ }
35837
+ function formatDate(ms) {
35838
+ const date4 = new Date(ms);
35839
+ const year = date4.getUTCFullYear();
35840
+ const month = String(date4.getUTCMonth() + 1).padStart(2, "0");
35841
+ const day = String(date4.getUTCDate()).padStart(2, "0");
35842
+ return `${year}-${month}-${day}`;
35843
+ }
35844
+ function hasFeature(model, feature) {
35845
+ if (feature === "reasoning") return model.reasoning != null;
35846
+ return (model.supported_features ?? []).includes(feature);
35847
+ }
35848
+ function registerModelsCommand(program, container) {
35849
+ program.command("models").description("List available Poe API models.").option("--provider <name>", "Filter by provider name").option("--model <name>", "Filter by model id").option("--feature <name>", "Filter by feature (tools, web_search, reasoning)").option("--input <modalities>", "Filter by input modalities (e.g. text,image)").option("--output <modalities>", "Filter by output modalities (e.g. text)").option("--view <name>", "Table view: capabilities or pricing", "capabilities").action(async function() {
35850
+ const flags = resolveCommandFlags(program);
35851
+ const resources = createExecutionResources(
35852
+ container,
35853
+ flags,
35854
+ "models"
35855
+ );
35856
+ const commandOptions = this.opts();
35857
+ resources.logger.intro("models");
35858
+ try {
35859
+ const apiKey = await loadCredentials({
35860
+ fs: container.fs,
35861
+ filePath: container.env.credentialsPath
35862
+ });
35863
+ if (!apiKey) {
35864
+ throw new AuthenticationError(
35865
+ "Poe API key not found. Run 'poe-code login' first."
35866
+ );
35867
+ }
35868
+ if (flags.dryRun) {
35869
+ resources.logger.dryRun(
35870
+ "Dry run: would fetch models from Poe API."
35871
+ );
35872
+ return;
35873
+ }
35874
+ const response = await container.httpClient(
35875
+ `${container.env.poeBaseUrl}/v1/models`,
35876
+ {
35877
+ method: "GET",
35878
+ headers: {
35879
+ Authorization: `Bearer ${apiKey}`
35880
+ }
35881
+ }
35882
+ );
35883
+ if (!response.ok) {
35884
+ throw new ApiError(
35885
+ `Failed to fetch models (HTTP ${response.status})`,
35886
+ {
35887
+ httpStatus: response.status,
35888
+ endpoint: "/v1/models"
35889
+ }
35890
+ );
35891
+ }
35892
+ const result = await response.json();
35893
+ const allModels = result.data;
35894
+ if (allModels.length === 0) {
35895
+ resources.logger.info("No models found.");
35896
+ return;
35897
+ }
35898
+ let filtered = allModels;
35899
+ if (commandOptions.provider) {
35900
+ const term = commandOptions.provider.toLowerCase();
35901
+ filtered = filtered.filter(
35902
+ (m) => m.owned_by.toLowerCase().includes(term)
35903
+ );
35904
+ }
35905
+ if (commandOptions.model) {
35906
+ const term = commandOptions.model.toLowerCase();
35907
+ filtered = filtered.filter(
35908
+ (m) => m.id.toLowerCase().includes(term)
35909
+ );
35910
+ }
35911
+ if (commandOptions.feature) {
35912
+ const feature = commandOptions.feature.toLowerCase();
35913
+ filtered = filtered.filter((m) => hasFeature(m, feature));
35914
+ }
35915
+ if (commandOptions.input) {
35916
+ const required2 = commandOptions.input.toLowerCase().split(",");
35917
+ filtered = filtered.filter((m) => {
35918
+ const modalities = m.architecture?.input_modalities ?? [];
35919
+ return required2.every((r) => modalities.includes(r));
35920
+ });
35921
+ }
35922
+ if (commandOptions.output) {
35923
+ const required2 = commandOptions.output.toLowerCase().split(",");
35924
+ filtered = filtered.filter((m) => {
35925
+ const modalities = m.architecture?.output_modalities ?? [];
35926
+ return required2.every((r) => modalities.includes(r));
35927
+ });
35928
+ }
35929
+ if (filtered.length === 0) {
35930
+ resources.logger.info("No models match the given filters.");
35931
+ return;
35932
+ }
35933
+ filtered.sort((a, b) => b.created - a.created);
35934
+ const theme = getTheme();
35935
+ let columns;
35936
+ let rows;
35937
+ if (commandOptions.view === "pricing") {
35938
+ columns = [
35939
+ { name: "Model", title: "Model", alignment: "left", maxLen: 35 },
35940
+ { name: "Context", title: "Context", alignment: "right", maxLen: 9 },
35941
+ { name: "Input", title: "Input $/MTok", alignment: "right", maxLen: 12 },
35942
+ { name: "Output", title: "Output $/MTok", alignment: "right", maxLen: 13 },
35943
+ { name: "CacheRead", title: "Cache Read", alignment: "right", maxLen: 10 },
35944
+ { name: "CacheWrite", title: "Cache Write", alignment: "right", maxLen: 11 },
35945
+ { name: "Request", title: "Request", alignment: "right", maxLen: 9 }
35946
+ ];
35947
+ rows = filtered.map((model) => {
35948
+ const pricing = model.pricing;
35949
+ return {
35950
+ Model: theme.accent(`${model.owned_by.toLowerCase()}/${model.id}`),
35951
+ Context: model.context_window?.context_length != null ? formatTokenCount(model.context_window.context_length) : "-",
35952
+ Input: formatOptionalPrice(pricing?.prompt ?? null),
35953
+ Output: formatOptionalPrice(pricing?.completion ?? null),
35954
+ CacheRead: formatOptionalPrice(pricing?.input_cache_read ?? null),
35955
+ CacheWrite: formatOptionalPrice(pricing?.input_cache_write ?? null),
35956
+ Request: formatOptionalPrice(pricing?.request ?? null)
35957
+ };
35958
+ });
35959
+ } else {
35960
+ const allFeatures = Array.from(
35961
+ new Set(filtered.flatMap((m) => m.supported_features ?? []))
35962
+ ).sort();
35963
+ columns = [
35964
+ { name: "Model", title: "Model", alignment: "left", maxLen: 35 },
35965
+ { name: "Date", title: "Date Added", alignment: "left", maxLen: 12 },
35966
+ { name: "Modality", title: "Modality", alignment: "left", maxLen: 18 },
35967
+ { name: "Context", title: "Context", alignment: "right", maxLen: 9 },
35968
+ { name: "Reasoning", title: "Reasoning", alignment: "left", maxLen: 9 },
35969
+ ...allFeatures.map((feature) => ({
35970
+ name: feature,
35971
+ title: feature,
35972
+ alignment: "left",
35973
+ maxLen: Math.max(feature.length, 3)
35974
+ }))
35975
+ ];
35976
+ rows = filtered.map((model) => {
35977
+ const row = {
35978
+ Model: theme.accent(`${model.owned_by.toLowerCase()}/${model.id}`),
35979
+ Date: theme.muted(formatDate(model.created)),
35980
+ Modality: model.architecture ? `${model.architecture.input_modalities.join(",")}->${model.architecture.output_modalities.join(",")}` : "-",
35981
+ Context: model.context_window?.context_length != null ? formatTokenCount(model.context_window.context_length) : "-",
35982
+ Reasoning: model.reasoning ? theme.success("\u2713") : ""
35983
+ };
35984
+ for (const feature of allFeatures) {
35985
+ row[feature] = (model.supported_features ?? []).includes(feature) ? theme.success("\u2713") : "";
35986
+ }
35987
+ return row;
35988
+ });
35989
+ }
35990
+ resources.logger.info(renderTable({ theme, columns, rows }));
35991
+ } catch (error2) {
35992
+ if (error2 instanceof Error) {
35993
+ resources.logger.logException(error2, "models", {
35994
+ operation: "fetch-models"
35995
+ });
35996
+ }
35997
+ throw error2;
35998
+ }
35999
+ });
36000
+ }
36001
+
35717
36002
  // package.json
35718
36003
  var package_default = {
35719
36004
  name: "poe-code",
@@ -36035,6 +36320,7 @@ function bootstrapProgram(container) {
36035
36320
  registerSkillCommand(program, container);
36036
36321
  registerRalphCommand(program, container);
36037
36322
  registerUsageCommand(program, container);
36323
+ registerModelsCommand(program, container);
36038
36324
  program.action(function() {
36039
36325
  const args = this.args;
36040
36326
  if (args.length > 0) {