kiosko 0.1.0 → 0.2.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kiosko",
3
- "version": "0.1.0",
3
+ "version": "0.2.2",
4
4
  "description": "A widget mosaic for small always-on USB LCD panels (Thermalright Trofeo Vision and friends), with a visual editor and plugins.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -40,20 +40,22 @@
40
40
  "dejavu-fonts-ttf": "^2.37.3"
41
41
  },
42
42
  "optionalDependencies": {
43
- "kiosko-plugin-agents": "^0.1.0",
44
- "kiosko-plugin-cats": "^0.1.0",
45
- "kiosko-plugin-system": "^0.1.0",
46
- "kiosko-plugin-vitals": "^0.1.0",
47
- "kiosko-plugin-usage": "^0.1.0",
48
- "kiosko-plugin-weather": "^0.1.0",
49
- "kiosko-plugin-calendar": "^0.1.0",
50
- "kiosko-plugin-news": "^0.1.0",
51
- "kiosko-plugin-mirror": "^0.1.0",
52
- "kiosko-plugin-gitlab": "^0.1.0",
53
- "kiosko-plugin-github": "^0.1.0",
54
- "kiosko-plugin-calls": "^0.1.0",
55
- "kiosko-plugin-timesheet": "^0.1.0",
56
- "kiosko-plugin-llm": "^0.1.0",
57
- "kiosko-plugin-gpu": "^0.1.0"
43
+ "usb": "^2.19.1",
44
+ "kiosko-plugin-agents": "^0.2.0",
45
+ "kiosko-plugin-cats": "^0.2.0",
46
+ "kiosko-plugin-system": "^0.2.0",
47
+ "kiosko-plugin-vitals": "^0.2.0",
48
+ "kiosko-plugin-usage": "^0.2.0",
49
+ "kiosko-plugin-weather": "^0.2.0",
50
+ "kiosko-plugin-calendar": "^0.2.0",
51
+ "kiosko-plugin-news": "^0.2.0",
52
+ "kiosko-plugin-mirror": "^0.2.0",
53
+ "kiosko-plugin-gitlab": "^0.2.0",
54
+ "kiosko-plugin-github": "^0.2.0",
55
+ "kiosko-plugin-calls": "^0.2.0",
56
+ "kiosko-plugin-timesheet": "^0.2.0",
57
+ "kiosko-plugin-llm": "^0.2.0",
58
+ "kiosko-plugin-gpu": "^0.2.0",
59
+ "kiosko-plugin-homeassistant": "^0.2.0"
58
60
  }
59
61
  }
package/sdk.js CHANGED
@@ -12,6 +12,7 @@ var CATEGORIES = [
12
12
  { id: "scene", label: { en: "Scenes", es: "Escenas" } },
13
13
  { id: "fun", label: { en: "Fun", es: "Diversi\xF3n" } }
14
14
  ];
15
+ var SDK_VERSION = "0.2.2";
15
16
  function defineWidget(w) {
16
17
  return w;
17
18
  }
@@ -52,9 +53,9 @@ var t = {
52
53
  * `repos`, `calendars`, `people`) and give it a `label`; the `help`
53
54
  * explaining the patterns comes with it.
54
55
  */
55
- filter: (o = {}) => ({
56
+ filter: ({ choices, ...o } = {}) => ({
56
57
  kind: "list",
57
- item: { kind: "string", default: "", placeholder: "name, group/*, !old-*" },
58
+ item: { kind: "string", default: "", placeholder: "name, group/*, !old-*", ...choices ? { choices } : {} },
58
59
  default: [],
59
60
  filter: true,
60
61
  help: FILTER_HELP,
@@ -139,7 +140,7 @@ function toJsonSchema(f) {
139
140
  };
140
141
  switch (f.kind) {
141
142
  case "string":
142
- return { ...base2, type: "string", ...f.format === "date" ? { format: "date" } : {}, ...f.maxLength ? { maxLength: f.maxLength } : {}, "x-ui": { ...ui, secret: f.secret, multiline: f.multiline, placeholder: f.placeholder, format: f.format } };
143
+ return { ...base2, type: "string", ...f.format === "date" ? { format: "date" } : {}, ...f.maxLength ? { maxLength: f.maxLength } : {}, "x-ui": { ...ui, secret: f.secret, multiline: f.multiline, placeholder: f.placeholder, format: f.format, choices: f.choices } };
143
144
  case "color":
144
145
  return { ...base2, type: "string", "x-ui": { ...ui, widget: "color" } };
145
146
  case "number":
@@ -149,7 +150,7 @@ function toJsonSchema(f) {
149
150
  case "enum":
150
151
  return { ...base2, type: "string", enum: [...f.values], "x-ui": { ...ui, labels: f.labels } };
151
152
  case "list":
152
- return { ...base2, type: "array", items: toJsonSchema(f.item), maxItems: f.max, ...f.filter ? { "x-ui": { ...ui, widget: "filter" }, "x-filter": true } : {} };
153
+ return { ...base2, type: "array", items: toJsonSchema(f.item), maxItems: f.max, ...f.filter ? { "x-ui": { ...ui, widget: "filter", choices: f.item.kind === "string" ? f.item.choices : void 0 }, "x-filter": true } : {} };
153
154
  case "map":
154
155
  return { ...base2, type: "object", additionalProperties: { type: "string" } };
155
156
  case "object":
@@ -439,6 +440,7 @@ function createBaseContext(o) {
439
440
  fmt: createFormatters({ locale, timeFormat: o.timeFormat ?? "auto", now: o.now }),
440
441
  log: o.log ?? (() => void 0),
441
442
  dataDir: o.dataDir ?? "",
443
+ cacheDir: o.cacheDir ?? o.dataDir ?? "",
442
444
  ...o.location ? { location: o.location } : {},
443
445
  workday: o.workday ?? DEFAULT_WORKDAY
444
446
  };
@@ -469,17 +471,233 @@ function placeOf(own, user) {
469
471
  if (!user) return void 0;
470
472
  return name ? { ...user, name } : user;
471
473
  }
474
+
475
+ // packages/sdk/src/system.ts
476
+ import { statSync } from "node:fs";
477
+ import { homedir } from "node:os";
478
+ import { join, win32 } from "node:path";
479
+ function expandPath(p, o = {}) {
480
+ const env = o.env ?? process.env;
481
+ let v = p.replace(/\$(?:\{(\w+)\}|(\w+))/g, (whole, a, b) => env[a ?? b ?? ""] ?? whole);
482
+ if ((o.os ?? process.platform) === "win32") v = v.replace(/%([^%\r\n]+)%/g, (whole, name) => env[name] ?? whole);
483
+ const home = o.home ?? homedir();
484
+ if (v === "~") return home;
485
+ return v.startsWith("~/") || v.startsWith("~\\") ? join(home, v.slice(2)) : v;
486
+ }
487
+ var CMD_UNSAFE = /["%\r\n\0]/;
488
+ function commandFor(cmd, args, o = {}) {
489
+ if ((o.os ?? process.platform) !== "win32") return { file: cmd, args };
490
+ const env = o.env ?? process.env;
491
+ const exists = o.exists ?? defaultExists;
492
+ const shim = findShim(cmd, env, exists);
493
+ if (!shim) return { file: cmd, args };
494
+ for (const a of args) if (CMD_UNSAFE.test(a)) throw new Error(`argument not allowed for ${cmd}: ${JSON.stringify(a)}`);
495
+ const quote = (s) => /^[\w@+=:,./\\-]+$/.test(s) ? s : `"${s}"`;
496
+ return { file: env.ComSpec || "cmd.exe", args: ["/d", "/s", "/c", `"${[shim, ...args].map(quote).join(" ")}"`], windowsVerbatimArguments: true };
497
+ }
498
+ function defaultExists(path) {
499
+ try {
500
+ return statSync(path).isFile();
501
+ } catch {
502
+ return false;
503
+ }
504
+ }
505
+ function findShim(cmd, env, exists) {
506
+ if (/\.(exe|com)$/i.test(cmd)) return null;
507
+ if (/\.(cmd|bat)$/i.test(cmd) && /[\\/]/.test(cmd)) return exists(cmd) ? cmd : null;
508
+ const dirs = /[\\/]/.test(cmd) ? [""] : (env.PATH ?? env.Path ?? "").split(";").filter(Boolean);
509
+ const exts = (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean);
510
+ for (const dir of dirs) {
511
+ const base2 = dir ? win32.join(dir, cmd) : cmd;
512
+ for (const ext of /\.\w+$/.test(cmd) ? [""] : exts) {
513
+ const p = base2 + ext.toLowerCase();
514
+ if (!exists(p)) continue;
515
+ return /\.(cmd|bat)$/i.test(p) ? p : null;
516
+ }
517
+ }
518
+ return null;
519
+ }
520
+
521
+ // packages/sdk/src/semver.ts
522
+ function parseVersion(s) {
523
+ const m = /^\s*v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?\s*$/.exec(s);
524
+ return m ? [Number(m[1]), Number(m[2]), Number(m[3]), m[4] ?? ""] : null;
525
+ }
526
+ function compareVersions(a, b) {
527
+ const x = parseVersion(a), y = parseVersion(b);
528
+ if (!x || !y) return 0;
529
+ for (let i = 0; i < 3; i++) if (x[i] !== y[i]) return x[i] < y[i] ? -1 : 1;
530
+ if (x[3] === y[3]) return 0;
531
+ if (!x[3]) return 1;
532
+ if (!y[3]) return -1;
533
+ return x[3] < y[3] ? -1 : 1;
534
+ }
535
+ function partial(s) {
536
+ const m = /^\s*v?(\d+|[xX*])(?:\.(\d+|[xX*]))?(?:\.(\d+|[xX*]))?(?:-([0-9A-Za-z.-]+))?\s*$/.exec(s);
537
+ if (!m) return null;
538
+ const n = (p) => p === void 0 || /^[xX*]$/.test(p) ? void 0 : Number(p);
539
+ return [n(m[1]), n(m[2]), n(m[3]), m[4] ?? ""];
540
+ }
541
+ var ver = (a, b, c, pre = "") => `${a}.${b}.${c}${pre ? `-${pre}` : ""}`;
542
+ function comparators(set) {
543
+ const out = [];
544
+ const tokens = set.trim().replace(/(>=|<=|>|<|=|\^|~)\s+/g, "$1").split(/\s+/).filter(Boolean);
545
+ if (!tokens.length) return [{ op: ">=", v: "0.0.0" }];
546
+ for (const tk of tokens) {
547
+ const m = /^(>=|<=|>|<|=|\^|~)?(.*)$/.exec(tk);
548
+ const op = m[1] ?? "";
549
+ const p = partial(m[2]);
550
+ if (!p) return null;
551
+ const [ma, mi, pa, pre] = p;
552
+ if (ma === void 0) {
553
+ out.push({ op: ">=", v: "0.0.0" });
554
+ continue;
555
+ }
556
+ if (op === "^") {
557
+ const lo = ver(ma, mi ?? 0, pa ?? 0, pre);
558
+ const hi = ma > 0 || mi === void 0 ? ver(ma + 1, 0, 0) : mi > 0 || pa === void 0 ? ver(0, mi + 1, 0) : ver(0, 0, pa + 1);
559
+ out.push({ op: ">=", v: lo }, { op: "<", v: `${hi}-0` });
560
+ } else if (op === "~") {
561
+ const lo = ver(ma, mi ?? 0, pa ?? 0, pre);
562
+ const hi = mi === void 0 ? ver(ma + 1, 0, 0) : ver(ma, mi + 1, 0);
563
+ out.push({ op: ">=", v: lo }, { op: "<", v: `${hi}-0` });
564
+ } else if (op === "" || op === "=") {
565
+ if (mi === void 0) out.push({ op: ">=", v: ver(ma, 0, 0) }, { op: "<", v: `${ver(ma + 1, 0, 0)}-0` });
566
+ else if (pa === void 0) out.push({ op: ">=", v: ver(ma, mi, 0) }, { op: "<", v: `${ver(ma, mi + 1, 0)}-0` });
567
+ else out.push({ op: "=", v: ver(ma, mi, pa, pre) });
568
+ } else {
569
+ if (pa === void 0 && (op === ">" || op === "<=")) {
570
+ const next = mi === void 0 ? ver(ma + 1, 0, 0) : ver(ma, mi + 1, 0);
571
+ out.push(op === ">" ? { op: ">=", v: next } : { op: "<", v: `${next}-0` });
572
+ } else out.push({ op, v: ver(ma, mi ?? 0, pa ?? 0, pre) });
573
+ }
574
+ }
575
+ return out;
576
+ }
577
+ function satisfies(version, range) {
578
+ const v = parseVersion(version);
579
+ if (!v) return false;
580
+ return range.split("||").some((set) => {
581
+ const cs = comparators(set);
582
+ if (!cs) return false;
583
+ const ok = cs.every(({ op, v: w }) => {
584
+ const c = compareVersions(version, w);
585
+ return op === ">=" ? c >= 0 : op === ">" ? c > 0 : op === "<=" ? c <= 0 : op === "<" ? c < 0 : c === 0;
586
+ });
587
+ if (!ok || !v[3]) return ok;
588
+ return cs.some(({ v: w }) => {
589
+ const x = parseVersion(w);
590
+ return !!x && !!x[3] && x[3] !== "0" && x[0] === v[0] && x[1] === v[1] && x[2] === v[2];
591
+ });
592
+ });
593
+ }
594
+
595
+ // packages/sdk/src/http.ts
596
+ var HttpError = class extends Error {
597
+ status;
598
+ url;
599
+ /** When the server says to come back (rate limits), epoch ms. */
600
+ retryAt;
601
+ constructor(message, o) {
602
+ super(message);
603
+ this.name = "HttpError";
604
+ this.status = o.status;
605
+ this.url = o.url;
606
+ if (o.retryAt !== void 0) this.retryAt = o.retryAt;
607
+ }
608
+ };
609
+ function retryAtOf(headers, now) {
610
+ const ra = headers.get("retry-after");
611
+ if (ra) {
612
+ const s = Number(ra);
613
+ if (Number.isFinite(s)) return now + Math.max(0, s) * 1e3;
614
+ const at = Date.parse(ra);
615
+ if (Number.isFinite(at)) return at;
616
+ }
617
+ const reset = Number(headers.get("x-ratelimit-reset"));
618
+ if (headers.get("x-ratelimit-remaining") === "0" && Number.isFinite(reset) && reset > 0) return reset * 1e3;
619
+ return void 0;
620
+ }
621
+ var hostOf = (url) => {
622
+ try {
623
+ return new URL(url).host;
624
+ } catch {
625
+ return url;
626
+ }
627
+ };
628
+ function createHttp(o = {}) {
629
+ const doFetch = o.fetch ?? fetch;
630
+ const now = o.now ?? Date.now;
631
+ const agent = `${o.agent ? `${o.agent} ` : ""}Kiosko (+https://kioskolcd.dev)`;
632
+ const cache2 = /* @__PURE__ */ new Map();
633
+ const rest = /* @__PURE__ */ new Map();
634
+ const max = o.maxCached ?? 200;
635
+ async function request(url, req = {}) {
636
+ const host = hostOf(url);
637
+ const until = rest.get(host);
638
+ if (until !== void 0) {
639
+ if (until > now()) throw new HttpError(`${host} asked to wait until ${new Date(until).toISOString()}`, { status: 429, url, retryAt: until });
640
+ rest.delete(host);
641
+ }
642
+ const method = req.method ?? "GET";
643
+ const cacheable = method === "GET" && !req.noCache;
644
+ const hit = cacheable ? cache2.get(url) : void 0;
645
+ const headers = { "User-Agent": agent, ...req.headers };
646
+ if (hit?.etag) headers["If-None-Match"] = hit.etag;
647
+ if (hit?.modified) headers["If-Modified-Since"] = hit.modified;
648
+ const res = await doFetch(url, { method, headers, ...req.body !== void 0 ? { body: req.body } : {}, ...req.signal ? { signal: req.signal } : {} });
649
+ if (res.status === 304 && hit) return { data: hit.body, status: 304, fresh: false, headers: res.headers };
650
+ const retryAt = retryAtOf(res.headers, now());
651
+ if (res.status === 429 || res.status === 503 || res.status === 403 && retryAt !== void 0) {
652
+ const at = retryAt ?? now() + 6e4;
653
+ rest.set(host, at);
654
+ throw new HttpError(`HTTP ${res.status} from ${host}: rate-limited until ${new Date(at).toISOString()}`, { status: res.status, url, retryAt: at });
655
+ }
656
+ if (!res.ok) throw new HttpError(`HTTP ${res.status} from ${host}`, { status: res.status, url });
657
+ const body = await res.text();
658
+ if (cacheable) {
659
+ const etag = res.headers.get("etag") ?? void 0;
660
+ const modified = res.headers.get("last-modified") ?? void 0;
661
+ if (etag || modified) {
662
+ cache2.delete(url);
663
+ cache2.set(url, { ...etag ? { etag } : {}, ...modified ? { modified } : {}, body });
664
+ while (cache2.size > max) cache2.delete(cache2.keys().next().value);
665
+ }
666
+ }
667
+ return { data: body, status: res.status, fresh: true, headers: res.headers };
668
+ }
669
+ return {
670
+ text: request,
671
+ async json(url, req) {
672
+ const r = await request(url, { ...req, headers: { Accept: "application/json", ...req?.headers } });
673
+ try {
674
+ return { ...r, data: JSON.parse(r.data) };
675
+ } catch {
676
+ throw new HttpError(`not JSON from ${hostOf(url)}`, { status: r.status, url });
677
+ }
678
+ },
679
+ resting(url) {
680
+ const at = rest.get(hostOf(url));
681
+ return at !== void 0 && at > now() ? at : void 0;
682
+ }
683
+ };
684
+ }
472
685
  export {
473
686
  CATEGORIES,
474
687
  DEFAULT_THEME,
475
688
  DEFAULT_WORKDAY,
476
689
  FILTER_HELP,
477
690
  FONT_FAMILIES,
691
+ HttpError,
692
+ SDK_VERSION,
478
693
  SECRET_NOTE,
479
694
  THEMES,
480
695
  TIME_FORMATS,
696
+ commandFor,
697
+ compareVersions,
481
698
  createBaseContext,
482
699
  createFormatters,
700
+ createHttp,
483
701
  dayKey,
484
702
  defaultsOf,
485
703
  defineInterlude,
@@ -488,6 +706,7 @@ export {
488
706
  defineWidget,
489
707
  drawEmpty,
490
708
  drawMore,
709
+ expandPath,
491
710
  filterPatterns,
492
711
  isWorkingAt,
493
712
  listLayout,
@@ -498,8 +717,11 @@ export {
498
717
  minutesOf,
499
718
  moreHeight,
500
719
  moreLabel,
720
+ parseVersion,
501
721
  placeOf,
722
+ retryAtOf,
502
723
  risksOf,
724
+ satisfies,
503
725
  scheduleOn,
504
726
  t,
505
727
  themeById,