outbound-sdk 0.4.0 → 0.6.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.
Files changed (104) hide show
  1. package/README.md +2 -2
  2. package/dist/alerts/check-evaluate.d.ts +53 -0
  3. package/dist/alerts/check-measure.d.ts +100 -0
  4. package/dist/alerts/check-schema.d.ts +184 -0
  5. package/dist/alerts/check-validate.d.ts +18 -0
  6. package/dist/alerts/index.d.ts +7 -0
  7. package/dist/alerts/index.js +635 -2
  8. package/dist/budget/index.d.ts +2 -0
  9. package/dist/budget/index.js +1 -0
  10. package/dist/cards/format.d.ts +1 -1
  11. package/dist/cards/index.js +49 -19
  12. package/dist/cards/parts.d.ts +1 -6
  13. package/dist/chunks/{chunk-7LNJJ2RO.js → chunk-3JOC5DGD.js} +127 -17
  14. package/dist/chunks/chunk-53DCVFUB.js +55 -0
  15. package/dist/chunks/{chunk-E6DSDCPI.js → chunk-BK5SLY32.js} +92 -101
  16. package/dist/chunks/chunk-HPNGSG5E.js +51 -0
  17. package/dist/chunks/chunk-HWHI4LFY.js +102 -0
  18. package/dist/chunks/chunk-MGR6HREO.js +91 -0
  19. package/dist/chunks/{chunk-Y5RAJ6PZ.js → chunk-OLPMBRXM.js} +3 -2
  20. package/dist/chunks/{chunk-IZFTTMJP.js → chunk-PHNQ3WC2.js} +5 -5
  21. package/dist/chunks/chunk-SXGCKCAR.js +678 -0
  22. package/dist/chunks/chunk-TFICTGM2.js +18 -0
  23. package/dist/chunks/{chunk-ZFVHM5JI.js → chunk-UWUPUMM2.js} +11 -4
  24. package/dist/chunks/{chunk-A6WVOCA4.js → chunk-W22SDX6S.js} +4 -4
  25. package/dist/chunks/{chunk-7ZDS6SZD.js → chunk-WH6V3YNN.js} +25 -0
  26. package/dist/chunks/chunk-XL6LJVHJ.js +71 -0
  27. package/dist/chunks/{chunk-5FVKRIEJ.js → chunk-YYCT3NGV.js} +35 -11
  28. package/dist/cli/bin.js +13 -28
  29. package/dist/cli/index.d.ts +3 -0
  30. package/dist/cli/index.js +12 -11
  31. package/dist/cli/output.d.ts +9 -0
  32. package/dist/cli/update.d.ts +15 -0
  33. package/dist/emailbison/account.d.ts +7 -0
  34. package/dist/emailbison/adapter.d.ts +5 -0
  35. package/dist/emailbison/capabilities.d.ts +78 -0
  36. package/dist/emailbison/client.d.ts +29 -0
  37. package/dist/emailbison/index.d.ts +30 -0
  38. package/dist/emailbison/index.js +1018 -0
  39. package/dist/emailbison/mail.d.ts +5 -0
  40. package/dist/emailbison/map-mail.d.ts +13 -0
  41. package/dist/emailbison/map-sequence.d.ts +12 -0
  42. package/dist/emailbison/map-stats.d.ts +47 -0
  43. package/dist/emailbison/map.d.ts +24 -0
  44. package/dist/emailbison/native-params.d.ts +5 -0
  45. package/dist/emailbison/native-workspace.d.ts +167 -0
  46. package/dist/emailbison/native.d.ts +327 -0
  47. package/dist/emailbison/stats.d.ts +4 -0
  48. package/dist/emailbison/webhooks.d.ts +2 -0
  49. package/dist/fixtures/index.js +6 -6
  50. package/dist/heyreach/capabilities.d.ts +3 -0
  51. package/dist/heyreach/index.js +22 -20
  52. package/dist/index.js +19 -18
  53. package/dist/insights/copy/copy-preview.d.ts +58 -0
  54. package/dist/insights/copy/copy-reuse.d.ts +0 -13
  55. package/dist/insights/copy/index.d.ts +9 -0
  56. package/dist/insights/copy/reuse-base.d.ts +0 -2
  57. package/dist/insights/copy/shared.d.ts +3 -8
  58. package/dist/insights/copy/step-funnel.d.ts +1 -12
  59. package/dist/insights/copy/variant-test.d.ts +0 -5
  60. package/dist/insights/cost.d.ts +91 -0
  61. package/dist/insights/define.d.ts +22 -1
  62. package/dist/insights/index.d.ts +4 -3
  63. package/dist/insights/index.js +810 -415
  64. package/dist/insights/inputs.generated.d.ts +21 -24
  65. package/dist/insights/ops/campaign-diagnosis.d.ts +0 -2
  66. package/dist/insights/ops/campaign-ranking.d.ts +3 -3
  67. package/dist/insights/ops/client-report.d.ts +0 -2
  68. package/dist/insights/ops/index.d.ts +2 -6
  69. package/dist/insights/ops/shared.d.ts +10 -2
  70. package/dist/insights/plugin.d.ts +19 -0
  71. package/dist/insights/registry.d.ts +10 -10
  72. package/dist/insights/run-cap.d.ts +35 -0
  73. package/dist/insights/senders/bounce-watch.d.ts +0 -11
  74. package/dist/insights/senders/domain-health.d.ts +0 -7
  75. package/dist/insights/senders/index.d.ts +0 -4
  76. package/dist/insights/senders/sender-load.d.ts +0 -2
  77. package/dist/insights/tools.d.ts +10 -0
  78. package/dist/insights/types.d.ts +1 -1
  79. package/dist/insights/variables.d.ts +33 -0
  80. package/dist/instantly/capabilities.d.ts +13 -0
  81. package/dist/instantly/index.js +43 -28
  82. package/dist/internal/adapter.d.ts +12 -0
  83. package/dist/internal/outbound/outbound.d.ts +5 -1
  84. package/dist/internal/request-cap.d.ts +35 -0
  85. package/dist/loader/index.js +2 -2
  86. package/dist/memory/index.js +10 -10
  87. package/dist/providers/index.d.ts +21 -1
  88. package/dist/providers/index.js +1 -1
  89. package/dist/redact/index.js +4 -4
  90. package/dist/smartlead/capabilities.d.ts +5 -0
  91. package/dist/smartlead/index.js +26 -24
  92. package/dist/tools/ai-sdk.js +5 -3
  93. package/dist/tools/claude-agent.js +5 -3
  94. package/dist/tools/index.d.ts +2 -2
  95. package/dist/tools/index.js +11 -6
  96. package/dist/tools/registry.d.ts +20 -1
  97. package/dist/tools/shared.d.ts +20 -1
  98. package/dist/webhooks/index.js +17 -7
  99. package/package.json +8 -2
  100. package/dist/chunks/chunk-5CFO3CXG.js +0 -176
  101. package/dist/chunks/chunk-K4USHN4C.js +0 -40
  102. package/dist/chunks/chunk-LVQUSKEX.js +0 -17
  103. package/dist/internal/renamed.d.ts +0 -28
  104. package/dist/chunks/{chunk-C4LS2HNV.js → chunk-JWGSB7PT.js} +3 -3
@@ -33,7 +33,7 @@ var str = (value, key) => {
33
33
  return raw2 === null ? null : safe(raw2);
34
34
  };
35
35
  var show = (value, key) => str(value, key) ?? DASH;
36
- var campaignNameOf = (value) => str(value, "campaignName") ?? show(value, "name");
36
+ var campaignNameOf = (value) => show(value, "campaignName");
37
37
  var num = (value, key) => count(field(value, key));
38
38
  var bool = (value, key) => flag(field(value, key));
39
39
  var rows = (value, key) => objects(field(value, key));
@@ -230,18 +230,7 @@ var pieChart = (title, points2) => {
230
230
  var LEFT = "left";
231
231
  var RIGHT = "right";
232
232
  var measured = (value) => pctRange(num(value, "rate"), num(value, "low"), num(value, "high"));
233
- var withInterval = (value, rateKey = "rate", intervalKey = "interval") => {
234
- const interval = child(value, intervalKey);
235
- return pctRange(
236
- num(value, rateKey),
237
- num(value, "low") ?? num(interval, "low"),
238
- num(value, "high") ?? num(interval, "high")
239
- );
240
- };
241
- var replyRate = (value) => {
242
- const rate2 = child(child(value, "rates"), "replyRate");
243
- return "rate" in rate2 ? measured(rate2) : withInterval(value, "replyRate", "replyRateInterval");
244
- };
233
+ var replyRate = (value) => measured(child(child(value, "rates"), "replyRate"));
245
234
  var totalStats = (totals) => [
246
235
  ["Sent", int(num(totals, "sent"))],
247
236
  ["Replies", int(num(totals, "replied"))],
@@ -343,7 +332,7 @@ var variantTest = (data) => {
343
332
  stepOf(tested, "step"),
344
333
  `${show(variant, "variantKey")}${str(tested, "leader") === str(variant, "variantKey") ? " \u2605" : ""}`,
345
334
  int(num(variant, "sent")),
346
- withInterval(variant)
335
+ measured(variant)
347
336
  ])
348
337
  )
349
338
  },
@@ -375,6 +364,45 @@ var copyAudit = (data) => {
375
364
  title: "Copy audit"
376
365
  };
377
366
  };
367
+ var copyPreview = (data) => {
368
+ const lead = child(data, "lead");
369
+ const totals = child(data, "totals");
370
+ const unfilled = num(totals, "unfilled") ?? 0;
371
+ const variants = rows(data, "steps").flatMap(
372
+ (step) => rows(step, "variants").map((variant) => ({ step, variant }))
373
+ );
374
+ return {
375
+ bullets: [
376
+ ...new Set(
377
+ variants.flatMap(({ variant }) => strings(variant, "unfilled"))
378
+ )
379
+ ].map((name) => `\u{1F7E1} \`${name}\` is left as written.`),
380
+ finding: str(lead, "lead") === null ? "No lead was read, so the copy is shown as written." : `Rendered for ${str(lead, "email") ?? str(lead, "linkedinUrl") ?? "one lead"}, who has ${int(
381
+ num(lead, "variablesFilled")
382
+ )} of ${plural(num(totals, "variables") ?? 0, "variable")} filled.`,
383
+ stats: [
384
+ ["Steps", int(num(totals, "steps"))],
385
+ ["Variants", int(num(totals, "variants"))],
386
+ ["Variables", int(num(totals, "variables"))],
387
+ ["Left as written", int(unfilled)]
388
+ ],
389
+ subtitle: show(data, "campaign"),
390
+ table: {
391
+ align: [RIGHT, LEFT, LEFT, LEFT],
392
+ headers: ["Step", "Variant", "Subject", "Body"],
393
+ rows: variants.map(({ step, variant }) => {
394
+ const rendered = child(variant, "rendered");
395
+ return [
396
+ stepOf(step, "step"),
397
+ show(variant, "variantKey"),
398
+ clip(str(rendered, "subject") ?? DASH, 60),
399
+ clip(str(rendered, "bodyText") ?? DASH, 120)
400
+ ];
401
+ })
402
+ },
403
+ title: "Copy preview"
404
+ };
405
+ };
378
406
  var copyLabel = (piece) => clip(str(piece, "subject") ?? str(piece, "bodyPreview") ?? DASH, 60);
379
407
  var copyReuse = (data) => {
380
408
  const reused = rows(data, "reused");
@@ -397,7 +425,7 @@ var copyReuse = (data) => {
397
425
  copyLabel(piece),
398
426
  int(num(piece, "campaigns")),
399
427
  int(num(piece, "sent")),
400
- pct(num(piece, "replyRate")),
428
+ pct(num(child(child(piece, "rates"), "replyRate"), "rate")),
401
429
  pct(num(piece, "spread"))
402
430
  ])
403
431
  },
@@ -433,6 +461,7 @@ var replyTiming = (data) => {
433
461
  };
434
462
  var COPY_CARDS = /* @__PURE__ */ new Map([
435
463
  ["copy_audit", copyAudit],
464
+ ["copy_preview", copyPreview],
436
465
  ["copy_reuse", copyReuse],
437
466
  ["reply_timing", replyTiming],
438
467
  ["step_funnel", stepFunnel],
@@ -945,11 +974,11 @@ var PEOPLE_CARDS = /* @__PURE__ */ new Map([
945
974
 
946
975
  // src/cards/sender-cards.ts
947
976
  var senderName = (sender) => str(sender, "address") ?? str(sender, "name") ?? show(sender, "sender");
948
- var warmupRate = (warmup2) => num(warmup2, "rate") ?? num(warmup2, "spamRate");
977
+ var warmupRate = (warmup2) => num(warmup2, "rate");
949
978
  var bounceWatch = (data) => {
950
979
  const totals = child(data, "totals");
951
980
  const over = rows(data, "over");
952
- const threshold = pct(num(data, "maxBounceRate") ?? num(data, "threshold"));
981
+ const threshold = pct(num(data, "maxBounceRate"));
953
982
  return {
954
983
  finding: verdict(
955
984
  (num(totals, "over") ?? 0) + (num(totals, "clean") ?? 0),
@@ -970,7 +999,7 @@ var bounceWatch = (data) => {
970
999
  campaignNameOf(campaign),
971
1000
  int(num(campaign, "sent")),
972
1001
  int(num(campaign, "bounced")),
973
- withInterval(campaign)
1002
+ measured(campaign)
974
1003
  ])
975
1004
  },
976
1005
  title: "Bounce watch"
@@ -1666,7 +1695,8 @@ var asToolResult = (input) => {
1666
1695
  return {
1667
1696
  error: {
1668
1697
  code: text(field(error, "code")) ?? "Unknown",
1669
- message: text(field(error, "message")) ?? "No message was given."
1698
+ message: text(field(error, "message")) ?? "No message was given.",
1699
+ retryable: flag(field(error, "retryable")) ?? false
1670
1700
  },
1671
1701
  next: "",
1672
1702
  ok: false
@@ -4,12 +4,7 @@ export declare const LEFT = "left";
4
4
  export declare const RIGHT = "right";
5
5
  /** A rate with `low` and `high` beside it, as the ops insights report one. */
6
6
  export declare const measured: (value: Json | undefined) => string;
7
- /**
8
- * A rate with `low` and `high` beside it, or the `interval` object a result
9
- * stored before those carries.
10
- */
11
- export declare const withInterval: (value: JsonObject, rateKey?: string, intervalKey?: string) => string;
12
- /** A row's `rates.replyRate`, or its older `replyRate` and `replyRateInterval`. */
7
+ /** A row's `rates.replyRate`, with its interval. */
13
8
  export declare const replyRate: (value: JsonObject) => string;
14
9
  /** Sent, replies, positive and bounced, as fields. */
15
10
  export declare const totalStats: (totals: Json | undefined) => Stat[];
@@ -1,22 +1,19 @@
1
1
  import {
2
2
  createTools
3
- } from "./chunk-E6DSDCPI.js";
3
+ } from "./chunk-BK5SLY32.js";
4
4
  import {
5
5
  plural
6
6
  } from "./chunk-4PA526S7.js";
7
7
  import {
8
8
  createOutbound
9
- } from "./chunk-5FVKRIEJ.js";
10
- import {
11
- fromEnv
12
- } from "./chunk-ZFVHM5JI.js";
13
- import {
14
- providers
15
- } from "./chunk-7ZDS6SZD.js";
9
+ } from "./chunk-YYCT3NGV.js";
16
10
  import {
17
11
  campaignStatusSchema,
18
12
  replyCategorySchema
19
13
  } from "./chunk-QGRZDTX4.js";
14
+ import {
15
+ fromEnv
16
+ } from "./chunk-UWUPUMM2.js";
20
17
  import {
21
18
  OutboundError
22
19
  } from "./chunk-J7DDZ4C2.js";
@@ -28,6 +25,9 @@ import {
28
25
  parseJson,
29
26
  toJson
30
27
  } from "./chunk-BLCJHP5H.js";
28
+ import {
29
+ providers
30
+ } from "./chunk-WH6V3YNN.js";
31
31
 
32
32
  // src/cli/index.ts
33
33
  import { parseArgs } from "node:util";
@@ -123,6 +123,7 @@ var GLOBAL_FLAGS = [
123
123
  "max-requests",
124
124
  "no-redact",
125
125
  "provider",
126
+ "raw",
126
127
  "redact"
127
128
  ];
128
129
  var checkFlags = (name, flags, given) => {
@@ -394,6 +395,7 @@ var GLOBAL_HELP = [
394
395
  "Options:",
395
396
  " --provider <id> the adapter to use, or all for every provider whose key is set (default: OUTBOUND_SDK_PROVIDER)",
396
397
  " --compact print JSON on one line",
398
+ " --raw keep each record's raw vendor payload (left out by default)",
397
399
  " --config <file> load plugins from a file whose default export is defineConfig({ plugins })",
398
400
  " --redact mask personal fields (on by default for mcp)",
399
401
  " --no-redact do not mask personal fields, even for mcp",
@@ -410,6 +412,8 @@ var helpText = () => [
410
412
  " providers",
411
413
  ...[...COMMANDS.values()].map((command) => ` ${command.help}`),
412
414
  " mcp start a local MCP server on stdio (redact is on)",
415
+ " version print the installed version (also --version, -v)",
416
+ " update check npm for a newer version and say how to get it",
413
417
  "",
414
418
  ...GLOBAL_HELP
415
419
  ].join("\n");
@@ -624,6 +628,26 @@ var createMcpServer = (outbound, options = {}) => {
624
628
  };
625
629
  };
626
630
 
631
+ // src/cli/output.ts
632
+ var isRecord = (value) => isJsonObject(value) && "ref" in value && "schemaVersion" in value;
633
+ var withoutRaw = (value) => {
634
+ if (Array.isArray(value)) {
635
+ return value.map(withoutRaw);
636
+ }
637
+ if (!isJsonObject(value)) {
638
+ return value;
639
+ }
640
+ return Object.fromEntries(
641
+ Object.entries(value).filter(([key]) => !(key === "raw" && isRecord(value))).map(([key, item]) => [key, withoutRaw(item)])
642
+ );
643
+ };
644
+ var printAnswer = (write, value, options) => {
645
+ const shown = options.raw === true ? value : withoutRaw(value);
646
+ write(
647
+ options.compact === true ? JSON.stringify(shown) : JSON.stringify(shown, null, 2)
648
+ );
649
+ };
650
+
627
651
  // src/cli/stdio.ts
628
652
  import process from "node:process";
629
653
  import { createInterface } from "node:readline";
@@ -641,6 +665,13 @@ var serveStdio = async (server, options = {}) => {
641
665
  }
642
666
  };
643
667
 
668
+ // src/cli/update.ts
669
+ import { execFile } from "node:child_process";
670
+ import path2 from "node:path";
671
+ import process2 from "node:process";
672
+ import { fileURLToPath } from "node:url";
673
+ import { promisify } from "node:util";
674
+
644
675
  // src/cli/version.ts
645
676
  import { readFileSync } from "node:fs";
646
677
  import { z } from "zod";
@@ -654,6 +685,84 @@ var packageVersion = () => Manifest.parse(
654
685
  )
655
686
  ).version;
656
687
 
688
+ // src/cli/update.ts
689
+ var PACKAGE = "outbound-sdk";
690
+ var STANDALONE = /* @__PURE__ */ new Map([
691
+ ["mcp", []],
692
+ ["providers", []],
693
+ ["update", []],
694
+ ["version", ["version"]]
695
+ ]);
696
+ var execFileAsync = promisify(execFile);
697
+ var runNpm = async (args) => {
698
+ try {
699
+ const { stdout } = await execFileAsync("npm", [...args], {
700
+ shell: process2.platform === "win32"
701
+ });
702
+ return stdout;
703
+ } catch (error) {
704
+ const stderr = error instanceof Error && "stderr" in error ? String(error.stderr) : "";
705
+ const said = stderr.trim().split("\n").at(-1) ?? "";
706
+ throw new Error(
707
+ `npm ${args.join(" ")} failed${said === "" ? "" : `: ${said}`}`,
708
+ { cause: error }
709
+ );
710
+ }
711
+ };
712
+ var packageDir = () => path2.dirname(fileURLToPath(new URL("../../package.json", import.meta.url)));
713
+ var parts = (version) => version.split("-")[0]?.split(".").map((part) => Math.trunc(Number(part)) || 0) ?? [];
714
+ var older = (a, b) => {
715
+ const [left, right] = [parts(a), parts(b)];
716
+ for (let index = 0; index < 3; index += 1) {
717
+ const difference = (left[index] ?? 0) - (right[index] ?? 0);
718
+ if (difference !== 0) {
719
+ return difference < 0;
720
+ }
721
+ }
722
+ return false;
723
+ };
724
+ var installKind = async (npm, dir) => {
725
+ if (dir.split(path2.sep).includes("_npx")) {
726
+ return "npx";
727
+ }
728
+ const printed = await npm(["root", "--global"]).catch(() => "");
729
+ const globalRoot = printed.trim();
730
+ return globalRoot !== "" && path2.dirname(dir) === path2.resolve(globalRoot) ? "global" : "project";
731
+ };
732
+ var update = async (npm, say) => {
733
+ const installed = packageVersion();
734
+ const viewed = await npm(["view", PACKAGE, "version"]);
735
+ const latest = viewed.trim();
736
+ if (!older(installed, latest)) {
737
+ say(`${PACKAGE} ${installed} is the latest version.`);
738
+ return;
739
+ }
740
+ say(`${PACKAGE} ${installed} is installed; ${latest} is the latest.`);
741
+ const kind = await installKind(npm, packageDir());
742
+ if (kind === "npx") {
743
+ say(`Run "npx ${PACKAGE}@latest <command>" to use ${latest}.`);
744
+ return;
745
+ }
746
+ if (kind === "project") {
747
+ say(`Run "npm install ${PACKAGE}@latest" in this project to update it.`);
748
+ return;
749
+ }
750
+ say(`Running "npm install --global ${PACKAGE}@latest"...`);
751
+ await npm(["install", "--global", `${PACKAGE}@latest`]);
752
+ say(`Updated ${PACKAGE} to ${latest}.`);
753
+ };
754
+ var runSelf = async (name, flags, npm, say) => {
755
+ if (name === "version" || name === void 0 && flags.version === true) {
756
+ say(packageVersion());
757
+ return true;
758
+ }
759
+ if (name === "update" && flags.help !== true) {
760
+ await update(npm, say);
761
+ return true;
762
+ }
763
+ return false;
764
+ };
765
+
657
766
  // src/cli/index.ts
658
767
  var OPTIONS = {
659
768
  bodies: { type: "boolean" },
@@ -672,6 +781,7 @@ var OPTIONS = {
672
781
  "max-requests": { type: "string" },
673
782
  "no-redact": { type: "boolean" },
674
783
  provider: { type: "string" },
784
+ raw: { type: "boolean" },
675
785
  redact: { type: "boolean" },
676
786
  sequence: { type: "boolean" },
677
787
  settings: { type: "boolean" },
@@ -680,7 +790,8 @@ var OPTIONS = {
680
790
  stats: { type: "boolean" },
681
791
  status: { type: "string" },
682
792
  subsequences: { type: "boolean" },
683
- to: { type: "string" }
793
+ to: { type: "string" },
794
+ version: { short: "v", type: "boolean" }
684
795
  };
685
796
  var serve = async (outbound, io, unmasked) => {
686
797
  const { insightTools } = await import("../insights/index.js");
@@ -701,9 +812,6 @@ var serve = async (outbound, io, unmasked) => {
701
812
  });
702
813
  await serveStdio(server, { input: io.stdin?.() ?? [], write: io.stdout });
703
814
  };
704
- var print = (io, value, compact) => {
705
- io.stdout(compact ? JSON.stringify(value) : JSON.stringify(value, null, 2));
706
- };
707
815
  var parseStrict = (argv) => parseArgs({ allowPositionals: true, args: [...argv], options: OPTIONS });
708
816
  var helpFor = (name, asked) => {
709
817
  const command = name === void 0 ? void 0 : COMMANDS.get(name);
@@ -723,7 +831,7 @@ var parse = (argv) => {
723
831
  const [name] = loose.positionals;
724
832
  const command = name === void 0 ? void 0 : COMMANDS.get(name);
725
833
  const named = name !== void 0 && name !== "help";
726
- if (named && !command && !["mcp", "providers"].includes(name)) {
834
+ if (named && !command && !STANDALONE.has(name)) {
727
835
  throw new OutboundError(
728
836
  "Invalid",
729
837
  `Unknown command "${name}". Run "outbound help"`
@@ -732,7 +840,7 @@ var parse = (argv) => {
732
840
  if (named) {
733
841
  checkFlags(
734
842
  name,
735
- command?.flags ?? [],
843
+ command?.flags ?? STANDALONE.get(name) ?? [],
736
844
  loose.tokens.flatMap(
737
845
  (token) => token.kind === "option" ? [token.name] : []
738
846
  )
@@ -749,13 +857,15 @@ var parse = (argv) => {
749
857
  var run = async (argv, io) => {
750
858
  try {
751
859
  const { help, name, rest, values } = parse(argv);
752
- const compact = values.compact === true;
860
+ if (await runSelf(name, values, io.npm ?? runNpm, io.stdout)) {
861
+ return 0;
862
+ }
753
863
  if (help !== void 0) {
754
864
  io.stdout(help);
755
865
  return 0;
756
866
  }
757
867
  if (name === "providers") {
758
- print(io, listProviders(), compact);
868
+ printAnswer(io.stdout, listProviders(), values);
759
869
  return 0;
760
870
  }
761
871
  const command = name === void 0 ? void 0 : COMMANDS.get(name);
@@ -775,7 +885,7 @@ var run = async (argv, io) => {
775
885
  note: io.stderr,
776
886
  positionals: rest
777
887
  });
778
- print(io, answer, compact);
888
+ printAnswer(io.stdout, answer, values);
779
889
  return name === "tool" && field(answer, "ok") === false ? 1 : 0;
780
890
  } catch (error) {
781
891
  const code = OutboundError.is(error) ? error.code : "Error";
@@ -0,0 +1,55 @@
1
+ // src/internal/text.ts
2
+ var ENTITIES = /* @__PURE__ */ new Map([
3
+ ["amp", "&"],
4
+ ["apos", "'"],
5
+ ["gt", ">"],
6
+ ["lt", "<"],
7
+ ["nbsp", " "],
8
+ ["quot", '"']
9
+ ]);
10
+ var decodeEntity = (match, body) => {
11
+ if (body.startsWith("#")) {
12
+ const code = body[1]?.toLowerCase() === "x" ? Number.parseInt(body.slice(2), 16) : Number(body.slice(1));
13
+ return Number.isInteger(code) && code > 0 && code <= 1114111 ? String.fromCodePoint(code) : match;
14
+ }
15
+ return ENTITIES.get(body.toLowerCase()) ?? match;
16
+ };
17
+ var looksLikeHtml = (value) => /<[a-z!/][^>]*>/iu.test(value);
18
+ var htmlToText = (html) => html.replaceAll(/<(?:script|style)\b[^>]*>[\s\S]*?<\/(?:script|style)>/giu, "").replaceAll(/<br\s*\/?>/giu, "\n").replaceAll(/<\/(?:p|div|li|tr|h[1-6])>/giu, "\n").replaceAll(/<[^>]+>/gu, "").replaceAll(
19
+ /&(?<body>#x?[\da-f]+|[a-z]+);/giu,
20
+ (match, body) => decodeEntity(match, body)
21
+ ).replaceAll(/[ \t]+\n/gu, "\n").replaceAll(/\n{3,}/gu, "\n\n").trim();
22
+ var QUOTE_MARKERS = [
23
+ /^On .{0,200}wrote:\s*$/u,
24
+ /^-{2,}\s*Original Message\s*-{2,}\s*$/iu,
25
+ /^From:\s.+$/u,
26
+ /^Sent from my \w+/u,
27
+ /^_{10,}\s*$/u
28
+ ];
29
+ var stripQuotedHistory = (text) => {
30
+ const lines = text.split(/\r?\n/u);
31
+ const cut = lines.findIndex(
32
+ (line, index) => QUOTE_MARKERS.some((marker) => marker.test(line.trim())) || // A run of ">" lines to the end of the message is the quoted thread.
33
+ line.trimStart().startsWith(">") && lines.slice(index).every(
34
+ (rest) => rest.trim() === "" || rest.trimStart().startsWith(">")
35
+ )
36
+ );
37
+ return (cut === -1 ? lines : lines.slice(0, cut)).join("\n").trim();
38
+ };
39
+ var normalizeBody = (body, includeBody) => {
40
+ if (!includeBody || body === null || body.trim() === "") {
41
+ return { bodyHtml: null, bodyText: null };
42
+ }
43
+ const isHtml = looksLikeHtml(body);
44
+ const plain = stripQuotedHistory(isHtml ? htmlToText(body) : body);
45
+ return {
46
+ bodyHtml: isHtml ? body : null,
47
+ bodyText: plain === "" ? null : plain
48
+ };
49
+ };
50
+
51
+ export {
52
+ looksLikeHtml,
53
+ htmlToText,
54
+ normalizeBody
55
+ };