@opencrater/sdk 0.8.56 → 0.8.58

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.

Potentially problematic release.


This version of @opencrater/sdk might be problematic. Click here for more details.

Files changed (2) hide show
  1. package/dist/paint.js +18 -10
  2. package/package.json +1 -1
package/dist/paint.js CHANGED
@@ -222,7 +222,7 @@ function osc8(url, text) {
222
222
  return `${ESC}]8;;${url}${ESC}\\${text}${ESC}]8;;${ESC}\\`;
223
223
  }
224
224
  function visibleLength(s) {
225
- return s.replace(/\x1b\[[0-9;]*m/g, "").replace(/\x1b\]8;;[^\x1b\x07]*(?:\x1b\\|\x07)/g, "").length;
225
+ return s.replace(/\x1b\[[0-9;]*m/g, "").replace(/\x1b\]8;;[^\x1b\x07]*(?:\x1b\\|\x07)/g, "").replace(/[︎️]/g, "").length;
226
226
  }
227
227
  function truncate(s, max) {
228
228
  return s.length <= max ? s : `${s.slice(0, Math.max(0, max - 1))}\u2026`;
@@ -244,6 +244,9 @@ function wrap(text, width) {
244
244
  return out;
245
245
  }
246
246
  var IS_WINDOWS = process.platform === "win32";
247
+ function tp(glyph) {
248
+ return IS_WINDOWS ? `${glyph}\uFE0E` : glyph;
249
+ }
247
250
  function posixSink(fd) {
248
251
  const close = () => {
249
252
  try {
@@ -430,7 +433,7 @@ function spawnWindowsConsoleSink() {
430
433
  function wmiSpawnDetached(cmdLine) {
431
434
  try {
432
435
  const esc = cmdLine.replace(/'/g, "''");
433
- const ps = `$ErrorActionPreference='Stop';try{$su=([wmiclass]'Win32_ProcessStartup').CreateInstance();$su.CreateFlags=[uint32]134217728;$r=([wmiclass]'Win32_Process').Create('${esc}',$null,$su);if($r.ReturnValue -eq 0){[Console]::Out.Write('OCPID '+$r.ProcessId)}else{[Console]::Out.Write('OCERR rv='+$r.ReturnValue)}}catch{[Console]::Out.Write('OCERR '+$_.Exception.Message)}`;
436
+ const ps = `$ErrorActionPreference='Stop';try{$r=$null;try{$su=([wmiclass]'Win32_ProcessStartup').CreateInstance();$su.CreateFlags=[uint32]8;$r=([wmiclass]'Win32_Process').Create('${esc}',$null,$su)}catch{};if($r -eq $null -or $r.ReturnValue -ne 0){$r=([wmiclass]'Win32_Process').Create('${esc}')};if($r.ReturnValue -eq 0){[Console]::Out.Write('OCPID '+$r.ProcessId)}else{[Console]::Out.Write('OCERR rv='+$r.ReturnValue)}}catch{[Console]::Out.Write('OCERR '+$_.Exception.Message)}`;
434
437
  const b64 = Buffer.from(ps, "utf16le").toString("base64");
435
438
  const res = child_process.spawnSync(
436
439
  powershellPath(),
@@ -937,7 +940,7 @@ function main() {
937
940
  const flowMode = process.env["OPENCRATER_FLOW"] === "1";
938
941
  const muted = process.env["OPENCRATER_MUTE"] === "1";
939
942
  const origin = payload.apiOrigin ?? "https://api.opencrater.to";
940
- const badge = format === "video" ? "\u25B6 " : format === "audio" ? "\u266A " : "";
943
+ const badge = format === "video" ? `${tp("\u25B6")} ` : format === "audio" ? `${tp("\u266A")} ` : "";
941
944
  let inlineMedia = null;
942
945
  let ansiFrames = null;
943
946
  let frameIdx = 0;
@@ -971,7 +974,7 @@ function main() {
971
974
  const label = rawLabel && !dupTitle ? `Sponsored \xB7 ${rawLabel}` : "Sponsored";
972
975
  const lines = [];
973
976
  const xTarget = dismissServerUrl ?? `${origin}/x/${payload.impressionId}`;
974
- const xLink = payload.impressionId || payload.replay && dismissServerUrl ? osc8(xTarget, "\u2715") : "";
977
+ const xLink = payload.impressionId || payload.replay && dismissServerUrl ? osc8(xTarget, tp("\u2715")) : "";
975
978
  const secsLeft = deadlineAt > 0 && !flowMode ? Math.max(0, Math.ceil((deadlineAt - Date.now()) / 1e3)) : 0;
976
979
  const cdText = secsLeft > 0 ? `Auto dismiss in: ${secsLeft}s ` : "";
977
980
  const cdColor = !color ? "" : secsLeft <= 5 ? `${ESC}[1;38;5;196m` : secsLeft <= 12 ? `${ESC}[1;38;5;178m` : `${ESC}[1;38;5;35m`;
@@ -984,7 +987,7 @@ function main() {
984
987
  lines.push(`${titleColor}${truncate(payload.title.toUpperCase(), textW)}${reset}`);
985
988
  for (const row of wrap(payload.body, textW)) lines.push(row);
986
989
  if (audioState !== "none") {
987
- const glyph = audioState === "playing" ? "\u23F8 pause" : audioState === "paused" ? "\u25B6 play" : "\u25B6 replay";
990
+ const glyph = audioState === "playing" ? `${tp("\u23F8")} pause` : audioState === "paused" ? `${tp("\u25B6")} play` : `${tp("\u25B6")} replay`;
988
991
  const n = Math.max(6, Math.min(14, textW - glyph.length - 5));
989
992
  const BARS = "\u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588";
990
993
  let bars = "";
@@ -995,9 +998,10 @@ function main() {
995
998
  bars += BARS[Math.max(0, Math.min(7, Math.floor(v * 8)))];
996
999
  }
997
1000
  const control = audioToggleUrl ? osc8(audioToggleUrl, glyph) : glyph;
998
- lines.push(`\u266A ${accent}${bars}${reset} ${accent}${control}${reset}`);
1001
+ lines.push(`${tp("\u266A")} ${accent}${bars}${reset} ${accent}${control}${reset}`);
999
1002
  }
1000
- const osc8Ok = protocol !== "none" || ["vscode", "ghostty"].includes(process.env["TERM_PROGRAM"] ?? "");
1003
+ const osc8Ok = protocol !== "none" || ["vscode", "ghostty"].includes(process.env["TERM_PROGRAM"] ?? "") || process.env["WT_SESSION"] !== void 0 || // Windows Terminal supports OSC 8 hyperlinks
1004
+ process.env["ConEmuANSI"] === "ON";
1001
1005
  const pill = (text, bg, fg) => color ? `${ESC}[48;2;${bg[0]};${bg[1]};${bg[2]};38;2;${fg[0]};${fg[1]};${fg[2]};1m ${text} ${ESC}[0m` : `[ ${text} ]`;
1002
1006
  const AMBER = [240, 178, 50];
1003
1007
  const INK = [12, 12, 10];
@@ -1017,7 +1021,7 @@ function main() {
1017
1021
  tail.push(pill(`${badge}${truncate(payload.url, inner - 4 - badge.length)}`, AMBER, INK));
1018
1022
  }
1019
1023
  const reportTarget = reportLocalUrl ?? (payload.impressionId ? `${origin}/r/${payload.impressionId}` : null);
1020
- const flag = reportTarget && osc8Ok ? ` \xB7 ${osc8(reportTarget, "\u2691 report")}` : "";
1024
+ const flag = reportTarget && osc8Ok ? ` \xB7 ${osc8(reportTarget, `${tp("\u2691")} report`)}` : "";
1021
1025
  const hint = osc8Ok ? "dismiss: \u2318-click \u2715 or npx opencrater x \xB7 opt out: npx opencrater off" : "dismiss: npx opencrater x \xB7 opt out: npx opencrater off";
1022
1026
  tail.push(`${dim}${truncate(hint, Math.max(0, inner - visibleLength(flag)))}${flag}${reset}`);
1023
1027
  return { head: lines, tail };
@@ -1474,6 +1478,10 @@ function main() {
1474
1478
  paint();
1475
1479
  interval = setInterval(paint, animated ? ANIM_MS : REPAINT_MS);
1476
1480
  startActivityWatch();
1481
+ startDismissServer();
1482
+ startDismissPoll();
1483
+ process.on("SIGINT", () => cleanup(true));
1484
+ process.on("SIGHUP", () => cleanup(true));
1477
1485
  setTimeout(() => cleanup(true), duration2);
1478
1486
  return;
1479
1487
  }
@@ -1553,7 +1561,7 @@ function main() {
1553
1561
  }
1554
1562
  paint();
1555
1563
  interval = setInterval(paint, REPAINT_MS);
1556
- const startDismissServer = () => {
1564
+ function startDismissServer() {
1557
1565
  if (!payload.impressionId && !payload.replay || flowMode) return;
1558
1566
  try {
1559
1567
  const nonce = crypto.randomBytes(8).toString("hex");
@@ -1613,7 +1621,7 @@ function main() {
1613
1621
  });
1614
1622
  } catch {
1615
1623
  }
1616
- };
1624
+ }
1617
1625
  try {
1618
1626
  fs2.writeFileSync(
1619
1627
  path3__namespace.join(os.homedir(), ".config", "opencrater", "last-ad.json"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrater/sdk",
3
- "version": "0.8.56",
3
+ "version": "0.8.58",
4
4
  "description": "OpenCrater SDK — sponsor cards for CLI tools and MCP servers. Fail-silent, zero dependencies.",
5
5
  "keywords": [
6
6
  "opencrater",