@vestra-player/sdk 1.7.7 → 1.7.9

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 (39) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/api-requests.js +18 -0
  3. package/dist/capabilities.d.ts +9 -0
  4. package/dist/capabilities.js +1 -0
  5. package/dist/capability-rules.d.ts +3 -0
  6. package/dist/capability-rules.js +47 -21
  7. package/dist/commands.d.ts +27 -6
  8. package/dist/commands.js +19 -5
  9. package/dist/docs-tree.json.gz +0 -0
  10. package/dist/host-capabilities.js +71 -0
  11. package/dist/manifest.js +12 -1
  12. package/dist/media.d.ts +108 -1
  13. package/dist/media.js +20 -0
  14. package/dist/player-runtime.d.ts +1 -0
  15. package/dist/player-runtime.js +1 -0
  16. package/dist/plugin/commands.d.ts +2 -1
  17. package/dist/plugin/commands.js +131 -4
  18. package/dist/plugin/media.d.ts +26 -0
  19. package/dist/plugin/media.js +166 -0
  20. package/dist/plugin/player.d.ts +7 -1
  21. package/dist/plugin/player.js +3 -1
  22. package/dist/plugin/scope.d.ts +1 -0
  23. package/dist/plugin/scope.js +2 -1
  24. package/dist/plugin/testing/commands.d.ts +7 -0
  25. package/dist/plugin/testing/commands.js +211 -0
  26. package/dist/plugin/testing/index.d.ts +170 -3
  27. package/dist/plugin/testing/index.js +120 -4
  28. package/dist/plugin/testing/internals.d.ts +27 -0
  29. package/dist/plugin/testing/internals.js +14 -1
  30. package/dist/plugin/testing/jobs.js +348 -1
  31. package/dist/plugin/testing/media.js +29 -0
  32. package/dist/plugin/types/base.d.ts +10 -7
  33. package/dist/plugin/types/commands.d.ts +412 -1
  34. package/dist/plugin/types/snapshots.d.ts +511 -1
  35. package/dist/wire.d.ts +43 -0
  36. package/dist/wire.js +6 -0
  37. package/llms.txt +3 -3
  38. package/package.json +1 -1
  39. package/slint/vestra/icons.slint +4 -0
@@ -409,3 +409,214 @@ export function commandsHandlers(host, inner) {
409
409
  },
410
410
  };
411
411
  }
412
+ /// ---------------------------------------------------------------- built-in only: commands.run, palette.lead
413
+ /** The player's refusal of a built-in-only capability to any other plugin. */
414
+ function builtinOnly(host) {
415
+ if (!host.builtin)
416
+ throw new HostError("capability", "this capability is for built-in plugins only");
417
+ }
418
+ /** The palette's rows: the player's core commands and the plugin's own. */
419
+ function rows(host) {
420
+ return [
421
+ ...[...host.coreCommands].map(([id, command]) => ({
422
+ global: id,
423
+ local: id,
424
+ owner: "host",
425
+ command,
426
+ })),
427
+ ...[...host.commands].map(([id, command]) => ({
428
+ global: `${host.manifestId}/${id}`,
429
+ local: id,
430
+ owner: "plugin",
431
+ command,
432
+ })),
433
+ ].filter(({ command }) =>
434
+ // As the palette: no panel-only command, no disabled one without a reason.
435
+ command.declaration.focus !== "panel" &&
436
+ (command.state.enabled || !!command.display.reason));
437
+ }
438
+ /** A row as `commands.list` writes it (capabilities/commands_run.rs `listed`). */
439
+ function listed(host, inner, row) {
440
+ const { declaration, display, state } = row.command;
441
+ const builtin = row.owner === "host" || host.builtin;
442
+ const plugin = row.owner === "host" ? "Vestra Player" : host.manifestId;
443
+ const keys = declaration.path ?? [];
444
+ const parent = display.path.slice(0, -1);
445
+ const declared = declaration.category ?? null;
446
+ const category = declared !== null
447
+ ? (display.category ?? menuTextKey(declared))
448
+ : parent.length
449
+ ? parent.join(" ▸ ")
450
+ : plugin;
451
+ const categoryKey = declared !== null
452
+ ? menuTextKey(declared)
453
+ : parent.length
454
+ ? keys.slice(0, -1).map(menuTextKey).join(" ▸ ")
455
+ : row.owner === "host"
456
+ ? plugin
457
+ : host.manifestId;
458
+ const home = declaration.home ? host.commands.get(declaration.home) : null;
459
+ const place = home
460
+ ? home.display.title.replace(/…$/, "")
461
+ : !display.path.length
462
+ ? ""
463
+ : declared === null || !parent.length
464
+ ? "Menu"
465
+ : `${parent.join(" ▸ ")} ▸`;
466
+ const root = keys[0] === undefined ? undefined : menuTextKey(keys[0]);
467
+ return {
468
+ id: row.global,
469
+ label: `${category}: ${display.title}`,
470
+ labelSource: `${categoryKey}: ${menuTextKey(declaration.title)}`,
471
+ title: display.title,
472
+ category,
473
+ path: display.path,
474
+ place,
475
+ keys: commandKeys(host, inner).keys[row.local] ?? [],
476
+ plugin,
477
+ builtin,
478
+ enabled: state.enabled,
479
+ checkable: state.checked !== null,
480
+ radio: declaration.radio,
481
+ group: declaration.group,
482
+ busy: state.busy,
483
+ // Asks first: not built in, destructive, the player's Close and Quit,
484
+ // the Settings and Plugins menus.
485
+ dangerous: !builtin ||
486
+ declaration.destructive === true ||
487
+ row.global === "host/stop" ||
488
+ row.global === "host/quit" ||
489
+ root === "Settings" ||
490
+ root === "Plugins",
491
+ ...(state.checked === null ? {} : { checked: state.checked }),
492
+ ...(!state.enabled && display.reason ? { reason: display.reason } : {}),
493
+ };
494
+ }
495
+ /** `palette.lead.set` texts: at most this many characters each. */
496
+ const LEAD_TEXTS = {
497
+ title: 40,
498
+ placeholder: 60,
499
+ empty: 80,
500
+ note: 40,
501
+ "status.text": 80,
502
+ "status.note": 40,
503
+ };
504
+ /** The default handlers of `commands.run` and `palette.lead`. */
505
+ export function builtinHandlers(host, inner) {
506
+ return {
507
+ "commands.list": () => {
508
+ builtinOnly(host);
509
+ const commands = rows(host).map((row) => listed(host, inner, row));
510
+ // The revision changes with the table.
511
+ const text = JSON.stringify(commands);
512
+ if (text !== inner.listed.text)
513
+ inner.listed = { text, revision: inner.listed.revision + 1 };
514
+ return { revision: inner.listed.revision, commands };
515
+ },
516
+ "commands.run": async (p) => {
517
+ builtinOnly(host);
518
+ // The player's order: the ticket given, step and of, the command,
519
+ // then the ticket's count and rates, then the alert.
520
+ if (p.ticket === undefined || p.ticket === null)
521
+ throw new HostError("ticket", "commands.run needs the ticket of a palette.lead event");
522
+ const whole = (value) => Number.isInteger(value) && Number(value) >= 1 && Number(value) <= 99;
523
+ if ((p.step === undefined) !== (p.of === undefined) ||
524
+ (p.step !== undefined &&
525
+ (!whole(p.step) || !whole(p.of) || Number(p.step) > Number(p.of))))
526
+ throw new HostError("invalid", "step and of go together, step ≤ of");
527
+ const id = String(p.id);
528
+ const row = rows(host).find((each) => each.global === id);
529
+ if (!row)
530
+ throw new HostError("missing", `no command ${id}`);
531
+ if (id === "host/palette")
532
+ throw new HostError("invalid", "the command palette is not run this way");
533
+ const item = listed(host, inner, row);
534
+ if (!item.enabled)
535
+ throw new HostError("disabled", item.reason ?? `${item.label} is disabled`);
536
+ if (item.busy)
537
+ throw new HostError("busy", `${item.label} is busy`);
538
+ const now = Date.now();
539
+ const ticket = inner.tickets.get(String(p.ticket));
540
+ if (!ticket || now - ticket.last > 120_000) {
541
+ inner.tickets.delete(String(p.ticket));
542
+ throw new HostError("ticket", "no live ticket");
543
+ }
544
+ inner.runs = inner.runs.filter((at) => now - at < 60_000);
545
+ ticket.runs = ticket.runs.filter((at) => now - at < 1000);
546
+ if (ticket.count >= 30)
547
+ throw new HostError("limit", "a ticket runs at most 30 commands");
548
+ if (ticket.runs.length >= 4)
549
+ throw new HostError("limit", "at most 4 commands a second");
550
+ if (inner.runs.length >= 120)
551
+ throw new HostError("limit", "at most 120 commands a minute");
552
+ ticket.count++;
553
+ ticket.runs.push(now);
554
+ ticket.last = now;
555
+ inner.runs.push(now);
556
+ // The player's own alert, answered like the plugin's alerts.
557
+ if (item.dangerous) {
558
+ const answer = host.dialogAnswers.shift();
559
+ if (answer === undefined || answer === null || Array.isArray(answer))
560
+ throw new Error("test host: no confirm answer queued for commands.run");
561
+ if (!answer.confirmed)
562
+ return { ran: false, declined: true };
563
+ }
564
+ // The OSD line naming the caller and the command.
565
+ const step = p.step === undefined ? "" : ` · ${p.step}/${p.of}`;
566
+ host.osd.push(`${host.manifestId}${step} · ${item.label}`);
567
+ if (row.owner === "host")
568
+ await host.request("host.run", { action: id.slice("host/".length) });
569
+ else
570
+ host.emit("commands.execute", {
571
+ id: row.local,
572
+ revision: row.command.revision,
573
+ });
574
+ return { ran: true };
575
+ },
576
+ "palette.lead.set": (p) => {
577
+ builtinOnly(host);
578
+ for (const [name, max] of Object.entries(LEAD_TEXTS)) {
579
+ const [first, second] = name.split(".");
580
+ const value = second
581
+ ? p[first]?.[second]
582
+ : p[first];
583
+ if (value === undefined || value === null) {
584
+ if (name === "title")
585
+ throw new HostError("invalid", "title is required");
586
+ continue;
587
+ }
588
+ const length = [...menuTextKey(value)].length;
589
+ if (length < 1 || length > max)
590
+ throw new HostError("invalid", `${name} has 1–${max} characters`);
591
+ }
592
+ if (typeof p.icon !== "string" && host.imagePath(p.icon) === null)
593
+ throw new HostError("invalid", "icon is an icon name or an image");
594
+ host.paletteLead = { ...p };
595
+ },
596
+ "palette.lead.clear": () => {
597
+ builtinOnly(host);
598
+ host.paletteLead = null;
599
+ },
600
+ "palette.lead.done": (p) => {
601
+ builtinOnly(host);
602
+ inner.tickets.delete(String(p.ticket));
603
+ },
604
+ };
605
+ }
606
+ /** Implements `TestHost.runPaletteLead`. */
607
+ export async function runPaletteLead(host, inner, query, options) {
608
+ if (!host.paletteLead)
609
+ throw new Error("test host: no palette lead is set");
610
+ // One request at a time: the plugin's earlier tickets end.
611
+ inner.tickets.clear();
612
+ const ticket = `ticket-${++inner.next.ticket}`;
613
+ inner.tickets.set(ticket, { count: 0, runs: [], last: Date.now() });
614
+ host.emit("palette.lead", {
615
+ query,
616
+ keep: options.keep ?? false,
617
+ ticket,
618
+ status: options.status ?? false,
619
+ });
620
+ await host.settle();
621
+ return ticket;
622
+ }
@@ -1680,8 +1680,99 @@ export declare class TestHost implements Transport {
1680
1680
  }>;
1681
1681
  /** Snapshots taken with `media.capture`, by snapshot id. Wire-level. */
1682
1682
  readonly snapshots: Map<number, Json>;
1683
- /** Every `jobs.start` request (`kind`, `destination`, `quality`, …), newest last. */
1683
+ /**
1684
+ * Every `jobs.start` request (`kind`, `destination`, `quality`, …),
1685
+ * newest last: a snapshot's (`snapshotId`) or, since 1.7.8, an export of
1686
+ * remembered files' parts (`parts`), whose job runs half way through its
1687
+ * middle part (`progress.part`), then completes (a copy's destination gets
1688
+ * the extension of its container).
1689
+ */
1684
1690
  readonly exports: Record<string, Json>[];
1691
+ /**
1692
+ * Local files as the fake player knows them, by path, for
1693
+ * `plugin.media.sources` and exports of their parts. A file not listed is a 1080p 30 fps
1694
+ * H.264 file with AAC stereo 48 kHz sound, as long as the current
1695
+ * source. Set `status` to `missing` or `changed` to stand for a moved or
1696
+ * rewritten file; `video: null` or `audio: null` for a file without one.
1697
+ *
1698
+ * @example A second file that a copy cannot join to the first
1699
+ * The plugin's list gets a part of a 4K file, then one of a 1080p file:
1700
+ * the check then says `size` and the job has to re-encode.
1701
+ * ```ts
1702
+ * declare const host: TestHost;
1703
+ * // ---cut---
1704
+ * host.mediaFiles.set("/media/b.mp4", {
1705
+ * duration: 30,
1706
+ * video: { codec: "h264", width: 1920, height: 818, fps: 30, pixelFormat: "yuv420p" },
1707
+ * });
1708
+ * host.setSource({ phase: "ready", source: "/media/b.mp4", duration: 30 });
1709
+ * ```
1710
+ *
1711
+ * @since 1.7.8
1712
+ */
1713
+ readonly mediaFiles: Map<string, {
1714
+ /** Seconds; default the current source's duration (60 without one). */
1715
+ duration?: number;
1716
+ /** `ok` (default), `missing` or `changed`. */
1717
+ status?: "ok" | "missing" | "changed";
1718
+ /**
1719
+ * Stands for the file's size and modification time (default 0): a
1720
+ * reference made at another version reads `changed`, and
1721
+ * `remember` gives a new token for the file at a new version, as
1722
+ * the player does for a rewritten file.
1723
+ *
1724
+ * @since 1.7.8
1725
+ */
1726
+ version?: number;
1727
+ /** The video stream; `null` for none. */
1728
+ video?: {
1729
+ /** FFmpeg's codec name. */
1730
+ codec: string;
1731
+ /** Pixels. */
1732
+ width: number;
1733
+ /** Pixels. */
1734
+ height: number;
1735
+ /** Frames per second. */
1736
+ fps: number;
1737
+ /** FFmpeg's pixel format. */
1738
+ pixelFormat: string | null;
1739
+ } | null;
1740
+ /** The audio stream; `null` for none. */
1741
+ audio?: {
1742
+ /** FFmpeg's codec name. */
1743
+ codec: string;
1744
+ /** Samples per second. */
1745
+ sampleRate: number;
1746
+ /** Channel count. */
1747
+ channels: number;
1748
+ } | null;
1749
+ }>;
1750
+ /**
1751
+ * Every `plugin.media.sources.open` the plugin made (its token and
1752
+ * start, 0 for the beginning), newest last. Each opens the token's path
1753
+ * as an ordinary open: `source` becomes that path, `position` the start.
1754
+ *
1755
+ * @since 1.7.8
1756
+ */
1757
+ readonly sourceOpens: {
1758
+ /** The token opened. */
1759
+ token: string;
1760
+ /** Seconds it started at. */
1761
+ start: number;
1762
+ }[];
1763
+ /**
1764
+ * The plugin's source references (`plugin.media.sources`) by token: the
1765
+ * path each stands for. `locate` takes its answer from
1766
+ * {@link TestHost.dialogAnswers}. Wire-level.
1767
+ *
1768
+ * @since 1.7.8
1769
+ */
1770
+ readonly sourceReferences: Map<string, {
1771
+ /** The file's path (never shown to the plugin). */
1772
+ path: string;
1773
+ /** The file's `mediaFiles` version when it was remembered. */
1774
+ version?: number;
1775
+ }>;
1685
1776
  /**
1686
1777
  * Export jobs by job id. Each state query advances a job one step
1687
1778
  * (`queued` → `running` → `completed`; `cancelling` → `cancelled`).
@@ -2234,6 +2325,68 @@ export declare class TestHost implements Transport {
2234
2325
  }[];
2235
2326
  /** Every core action run (`host.run`, a core command, a pressed core binding), newest last. */
2236
2327
  readonly coreRuns: string[];
2328
+ /**
2329
+ * The plugin is built into the player (`startPlugin`'s `builtin`). Only
2330
+ * then does the host take the built-in-only capabilities
2331
+ * (`commands.run`, `palette.lead`); otherwise their calls fail with
2332
+ * `capability`, as in the player.
2333
+ *
2334
+ * @since 1.7.9
2335
+ */
2336
+ builtin: boolean;
2337
+ /**
2338
+ * The palette's lead row as the plugin last set it (`palette.lead.set`,
2339
+ * wire form), `null` without one. Wire-level.
2340
+ *
2341
+ * @since 1.7.9
2342
+ */
2343
+ paletteLead: Record<string, Json> | null;
2344
+ /**
2345
+ * Simulate the user activating the palette's lead row: Enter (`keep`:
2346
+ * Shift+Enter) with `query` typed, or Enter on the status row
2347
+ * (`status`). Mints a ticket, sends the `palette.lead` event, waits until
2348
+ * the host is idle and returns the ticket.
2349
+ *
2350
+ * Like the player, `commands.run` takes the ticket until
2351
+ * `PaletteLead.done` or 120 s after its last run, at most 30 runs, 4 a
2352
+ * second, and 120 runs a minute per plugin (`limit`). A command declared
2353
+ * `destructive` (and the player's `host/stop`) is confirmed first: the
2354
+ * answer comes from {@link TestHost.dialogAnswers}
2355
+ * (`{ confirmed: false, checked: false }` is Don't Run); each run adds
2356
+ * the command's title (and ` · step/of`) to {@link TestHost.osd}.
2357
+ *
2358
+ * @param query - What the user typed.
2359
+ * @param options - `keep`: Shift+Enter; `status`: the status row.
2360
+ * @returns The ticket of this user action.
2361
+ *
2362
+ * @example Test a request that runs a destructive command
2363
+ * The user asks the plugin to stop playback and declines the
2364
+ * confirmation. `builtin` lets the plugin hold the lead; the ticket
2365
+ * minted here is what its listener passes to `commands.run`, and the
2366
+ * queued answer declines the player's alert for `host/stop`.
2367
+ * ```ts
2368
+ * import assert from "node:assert/strict";
2369
+ * import { startPlugin } from "@vestra-player/sdk/testing";
2370
+ * import activate from "../main.ts";
2371
+ *
2372
+ * const { host, stop } = await startPlugin(activate, {
2373
+ * directory: new URL("..", import.meta.url),
2374
+ * builtin: true, // as a plugin built into the player
2375
+ * });
2376
+ * host.dialogAnswers.push({ confirmed: false, checked: false }); // Don't Run
2377
+ * await host.runPaletteLead("stop playback");
2378
+ * assert.deepEqual(host.coreRuns, []); // declined: nothing ran
2379
+ * await stop();
2380
+ * ```
2381
+ *
2382
+ * @capability None.
2383
+ * @throws `Error` without a code (rejects) The plugin has no lead row.
2384
+ * @since 1.7.9
2385
+ */
2386
+ runPaletteLead(query: string, options?: {
2387
+ keep?: boolean;
2388
+ status?: boolean;
2389
+ }): Promise<string>;
2237
2390
  /**
2238
2391
  * One of the 14 core actions (`play-pause`, `stop`, `seek-forward`, ...)
2239
2392
  * that the test host registers like the player, as `host/<id>`. Throws for
@@ -3011,8 +3164,14 @@ export declare class TestHost implements Transport {
3011
3164
  *
3012
3165
  * The manifest id and capabilities come from `directory/manifest.json`
3013
3166
  * unless `capabilities` is given; then `id` (default `"test.plugin"`) and
3014
- * `capabilities` are used and no manifest is read. Calls that need an
3015
- * undeclared capability fail with `capability`, as in the player.
3167
+ * `capabilities` are used and no manifest is read. The test host does not
3168
+ * apply the player's capability table to every request: the members that
3169
+ * check a capability on the plugin's side (`plugin.media.sources` and its
3170
+ * `open`, which also needs `playback.control`, `plugin.secrets`, timeline
3171
+ * marks, video shaders and views, among others) fail with `capability` as in
3172
+ * the player, but a call the player refuses for an undeclared capability can
3173
+ * succeed here. `vestra-plugin check` (and the TypeScript plugin) reports
3174
+ * those calls from the sources.
3016
3175
  *
3017
3176
  * Rejects when `manifest.json` cannot be read or parsed, when `activate`
3018
3177
  * throws, or when a registration made during activation fails (for example
@@ -3092,6 +3251,14 @@ export declare function startPlugin(activate: (plugin: Plugin) => unknown, optio
3092
3251
  id?: string;
3093
3252
  /** Use these capabilities instead of reading `manifest.json`. */
3094
3253
  capabilities?: string[];
3254
+ /**
3255
+ * Run the plugin as one built into the player
3256
+ * ({@link TestHost.builtin}): only then do `commands.run` and
3257
+ * `palette.lead` work. Default `false`.
3258
+ *
3259
+ * @since 1.7.9
3260
+ */
3261
+ builtin?: boolean;
3095
3262
  /** A host to use (to preset data before activation). Default: a new one. */
3096
3263
  host?: TestHost;
3097
3264
  /** Use an existing directory as `plugin.dataDirectory` (to test a restart). */
@@ -85,7 +85,7 @@ import { PATCH_FEATURE } from "../patch.js";
85
85
  import { LOCALES, LIST_SEPARATORS, loadPackageCatalog, TEXT_LIMITS, } from "../../i18n.js";
86
86
  import { Internals } from "./internals.js";
87
87
  import { on, emit, settle, close, keepsRunning, transportHandlers, tick, takenErrors, tellResidency, } from "./transport.js";
88
- import { bindingClaims, bindingKey, keysChanged, press, barButtons, commandsHandlers, } from "./commands.js";
88
+ import { bindingClaims, bindingKey, keysChanged, press, barButtons, commandsHandlers, builtinHandlers, runPaletteLead, } from "./commands.js";
89
89
  import { registerCoreActions, windowFacts, coreActionsHandlers, } from "./core-actions.js";
90
90
  import { translate, i18nHandlers } from "./i18n.js";
91
91
  import { mountOther, unmountOther, mounted, setTimelineRanges, setTimelineLayer, layoutHandlers, } from "./layout.js";
@@ -1238,8 +1238,53 @@ export class TestHost {
1238
1238
  uploads = new Map();
1239
1239
  /** Snapshots taken with `media.capture`, by snapshot id. Wire-level. */
1240
1240
  snapshots = new Map();
1241
- /** Every `jobs.start` request (`kind`, `destination`, `quality`, …), newest last. */
1241
+ /**
1242
+ * Every `jobs.start` request (`kind`, `destination`, `quality`, …),
1243
+ * newest last: a snapshot's (`snapshotId`) or, since 1.7.8, an export of
1244
+ * remembered files' parts (`parts`), whose job runs half way through its
1245
+ * middle part (`progress.part`), then completes (a copy's destination gets
1246
+ * the extension of its container).
1247
+ */
1242
1248
  exports = [];
1249
+ /**
1250
+ * Local files as the fake player knows them, by path, for
1251
+ * `plugin.media.sources` and exports of their parts. A file not listed is a 1080p 30 fps
1252
+ * H.264 file with AAC stereo 48 kHz sound, as long as the current
1253
+ * source. Set `status` to `missing` or `changed` to stand for a moved or
1254
+ * rewritten file; `video: null` or `audio: null` for a file without one.
1255
+ *
1256
+ * @example A second file that a copy cannot join to the first
1257
+ * The plugin's list gets a part of a 4K file, then one of a 1080p file:
1258
+ * the check then says `size` and the job has to re-encode.
1259
+ * ```ts
1260
+ * declare const host: TestHost;
1261
+ * // ---cut---
1262
+ * host.mediaFiles.set("/media/b.mp4", {
1263
+ * duration: 30,
1264
+ * video: { codec: "h264", width: 1920, height: 818, fps: 30, pixelFormat: "yuv420p" },
1265
+ * });
1266
+ * host.setSource({ phase: "ready", source: "/media/b.mp4", duration: 30 });
1267
+ * ```
1268
+ *
1269
+ * @since 1.7.8
1270
+ */
1271
+ mediaFiles = new Map();
1272
+ /**
1273
+ * Every `plugin.media.sources.open` the plugin made (its token and
1274
+ * start, 0 for the beginning), newest last. Each opens the token's path
1275
+ * as an ordinary open: `source` becomes that path, `position` the start.
1276
+ *
1277
+ * @since 1.7.8
1278
+ */
1279
+ sourceOpens = [];
1280
+ /**
1281
+ * The plugin's source references (`plugin.media.sources`) by token: the
1282
+ * path each stands for. `locate` takes its answer from
1283
+ * {@link TestHost.dialogAnswers}. Wire-level.
1284
+ *
1285
+ * @since 1.7.8
1286
+ */
1287
+ sourceReferences = new Map();
1243
1288
  /**
1244
1289
  * Export jobs by job id. Each state query advances a job one step
1245
1290
  * (`queued` → `running` → `completed`; `cancelling` → `cancelled`).
@@ -1783,6 +1828,68 @@ export class TestHost {
1783
1828
  steps = [];
1784
1829
  /** Every core action run (`host.run`, a core command, a pressed core binding), newest last. */
1785
1830
  coreRuns = [];
1831
+ // ------------------------------------------------------------ built-in only
1832
+ /**
1833
+ * The plugin is built into the player (`startPlugin`'s `builtin`). Only
1834
+ * then does the host take the built-in-only capabilities
1835
+ * (`commands.run`, `palette.lead`); otherwise their calls fail with
1836
+ * `capability`, as in the player.
1837
+ *
1838
+ * @since 1.7.9
1839
+ */
1840
+ builtin = false;
1841
+ /**
1842
+ * The palette's lead row as the plugin last set it (`palette.lead.set`,
1843
+ * wire form), `null` without one. Wire-level.
1844
+ *
1845
+ * @since 1.7.9
1846
+ */
1847
+ paletteLead = null;
1848
+ /**
1849
+ * Simulate the user activating the palette's lead row: Enter (`keep`:
1850
+ * Shift+Enter) with `query` typed, or Enter on the status row
1851
+ * (`status`). Mints a ticket, sends the `palette.lead` event, waits until
1852
+ * the host is idle and returns the ticket.
1853
+ *
1854
+ * Like the player, `commands.run` takes the ticket until
1855
+ * `PaletteLead.done` or 120 s after its last run, at most 30 runs, 4 a
1856
+ * second, and 120 runs a minute per plugin (`limit`). A command declared
1857
+ * `destructive` (and the player's `host/stop`) is confirmed first: the
1858
+ * answer comes from {@link TestHost.dialogAnswers}
1859
+ * (`{ confirmed: false, checked: false }` is Don't Run); each run adds
1860
+ * the command's title (and ` · step/of`) to {@link TestHost.osd}.
1861
+ *
1862
+ * @param query - What the user typed.
1863
+ * @param options - `keep`: Shift+Enter; `status`: the status row.
1864
+ * @returns The ticket of this user action.
1865
+ *
1866
+ * @example Test a request that runs a destructive command
1867
+ * The user asks the plugin to stop playback and declines the
1868
+ * confirmation. `builtin` lets the plugin hold the lead; the ticket
1869
+ * minted here is what its listener passes to `commands.run`, and the
1870
+ * queued answer declines the player's alert for `host/stop`.
1871
+ * ```ts
1872
+ * import assert from "node:assert/strict";
1873
+ * import { startPlugin } from "@vestra-player/sdk/testing";
1874
+ * import activate from "../main.ts";
1875
+ *
1876
+ * const { host, stop } = await startPlugin(activate, {
1877
+ * directory: new URL("..", import.meta.url),
1878
+ * builtin: true, // as a plugin built into the player
1879
+ * });
1880
+ * host.dialogAnswers.push({ confirmed: false, checked: false }); // Don't Run
1881
+ * await host.runPaletteLead("stop playback");
1882
+ * assert.deepEqual(host.coreRuns, []); // declined: nothing ran
1883
+ * await stop();
1884
+ * ```
1885
+ *
1886
+ * @capability None.
1887
+ * @throws `Error` without a code (rejects) The plugin has no lead row.
1888
+ * @since 1.7.9
1889
+ */
1890
+ runPaletteLead(query, options = {}) {
1891
+ return runPaletteLead(this, this.#inner, query, options);
1892
+ }
1786
1893
  /**
1787
1894
  * One of the 14 core actions (`play-pause`, `stop`, `seek-forward`, ...)
1788
1895
  * that the test host registers like the player, as `host/<id>`. Throws for
@@ -2622,6 +2729,7 @@ export class TestHost {
2622
2729
  #defaults = {
2623
2730
  ...transportHandlers(this, this.#inner),
2624
2731
  ...commandsHandlers(this, this.#inner),
2732
+ ...builtinHandlers(this, this.#inner),
2625
2733
  ...coreActionsHandlers(this, this.#inner),
2626
2734
  ...i18nHandlers(this, this.#inner),
2627
2735
  ...layoutHandlers(this, this.#inner),
@@ -2640,8 +2748,14 @@ export class TestHost {
2640
2748
  *
2641
2749
  * The manifest id and capabilities come from `directory/manifest.json`
2642
2750
  * unless `capabilities` is given; then `id` (default `"test.plugin"`) and
2643
- * `capabilities` are used and no manifest is read. Calls that need an
2644
- * undeclared capability fail with `capability`, as in the player.
2751
+ * `capabilities` are used and no manifest is read. The test host does not
2752
+ * apply the player's capability table to every request: the members that
2753
+ * check a capability on the plugin's side (`plugin.media.sources` and its
2754
+ * `open`, which also needs `playback.control`, `plugin.secrets`, timeline
2755
+ * marks, video shaders and views, among others) fail with `capability` as in
2756
+ * the player, but a call the player refuses for an undeclared capability can
2757
+ * succeed here. `vestra-plugin check` (and the TypeScript plugin) reports
2758
+ * those calls from the sources.
2645
2759
  *
2646
2760
  * Rejects when `manifest.json` cannot be read or parsed, when `activate`
2647
2761
  * throws, or when a registration made during activation fails (for example
@@ -2726,6 +2840,8 @@ export async function startPlugin(activate, options = {}) {
2726
2840
  manifest = { id: read.id, capabilities: read.capabilities };
2727
2841
  }
2728
2842
  host.manifestId = manifest.id;
2843
+ if (options.builtin)
2844
+ host.builtin = true;
2729
2845
  host.loadCatalog(directory);
2730
2846
  // Its Slint files: the values its views are given are checked against
2731
2847
  // their declared types.
@@ -41,6 +41,19 @@ export declare class Internals {
41
41
  end: number;
42
42
  container: "mp4" | "mkv" | null;
43
43
  } | null;
44
+ /** An export of parts (`jobs.start { parts }`): its part count, length and container. */
45
+ join?: {
46
+ /** Each part's token (its file's status decides the outcome). */
47
+ tokens: string[];
48
+ parts: number;
49
+ total: number;
50
+ container: "mp4" | "mkv";
51
+ written: {
52
+ start: number;
53
+ end: number;
54
+ }[];
55
+ mode: "copy" | "mp4";
56
+ };
44
57
  }>;
45
58
  sentTypes: string;
46
59
  readonly overrides: Map<string, (params: Record<string, Json>) => unknown>;
@@ -57,7 +70,21 @@ export declare class Internals {
57
70
  producer: number;
58
71
  source: number;
59
72
  resolution: number;
73
+ ticket: number;
60
74
  };
75
+ /** `commands.run` tickets: runs, run times in the last second, last use (ms). */
76
+ readonly tickets: Map<string, {
77
+ count: number;
78
+ runs: number[];
79
+ last: number;
80
+ }>;
81
+ /** The last `commands.list` table (JSON) and its revision. */
82
+ listed: {
83
+ text: string;
84
+ revision: number;
85
+ };
86
+ /** The times of the plugin's `commands.run` calls in the last minute. */
87
+ runs: number[];
61
88
  sourceBook: Map<number, Json>;
62
89
  /** The pending resolutions' stamps and operations (beside `resolutions`). */
63
90
  resolving: Map<number, {
@@ -47,7 +47,20 @@ export class Internals {
47
47
  gone.catch(() => { });
48
48
  return gone;
49
49
  })();
50
- next = { snapshot: 0, job: 0, producer: 0, source: 0, resolution: 0 };
50
+ next = {
51
+ snapshot: 0,
52
+ job: 0,
53
+ producer: 0,
54
+ source: 0,
55
+ resolution: 0,
56
+ ticket: 0,
57
+ };
58
+ /** `commands.run` tickets: runs, run times in the last second, last use (ms). */
59
+ tickets = new Map();
60
+ /** The last `commands.list` table (JSON) and its revision. */
61
+ listed = { text: "", revision: 0 };
62
+ /** The times of the plugin's `commands.run` calls in the last minute. */
63
+ runs = [];
51
64
  sourceBook = new Map();
52
65
  /** The pending resolutions' stamps and operations (beside `resolutions`). */
53
66
  resolving = new Map();