@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
package/dist/media.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /** Finite media jobs. Native-subtitle freezing remains pending. */
2
2
  import type { Transport } from "./wire.ts";
3
- import type { SourceStamp, SourceAudioTrack } from "./source.ts";
3
+ import type { SourceStamp, SourceAudioTrack, SourceOperation } from "./source.ts";
4
4
  import type { VideoNode, AudioNode } from "./processing.ts";
5
5
  import type { SubtitleStamp, SubtitleStyle, SubtitleTrack } from "./subtitles.ts";
6
6
  export type RawSnapshot = {
@@ -174,6 +174,22 @@ export type MediaJob = {
174
174
  end: number;
175
175
  };
176
176
  };
177
+ /** An export of parts (`jobs.start { parts }`): how it was written. */
178
+ join?: {
179
+ mode: "copy" | "mp4";
180
+ container: "mp4" | "mkv";
181
+ /** Each part as written, in seconds of its own file. */
182
+ parts: {
183
+ start: number;
184
+ end: number;
185
+ }[];
186
+ /** A re-encode: the output size and frame rate. */
187
+ target: {
188
+ width: number;
189
+ height: number;
190
+ fps: number;
191
+ } | null;
192
+ };
177
193
  };
178
194
  outcome: null | {
179
195
  destination: string;
@@ -196,6 +212,10 @@ export type MediaJob = {
196
212
  progress?: {
197
213
  done: number;
198
214
  total: number;
215
+ /** An export of parts: the part being written, from 1. */
216
+ part?: number;
217
+ /** An export of parts: how many parts. */
218
+ parts?: number;
199
219
  } | null;
200
220
  };
201
221
  /** The wire form of `ExportEncoding` (`jobs.start`). */
@@ -208,6 +228,62 @@ export type WireEncoding = {
208
228
  threads?: "single" | "auto";
209
229
  videoBitrate?: "source";
210
230
  };
231
+ /** A source reference as the player describes it (`media.sources.*`). */
232
+ export type WireSourceReference = {
233
+ token: string;
234
+ name: string;
235
+ duration: number;
236
+ status: "ok" | "missing" | "changed";
237
+ video: {
238
+ codec: string;
239
+ width: number;
240
+ height: number;
241
+ fps: number;
242
+ pixelFormat: string | null;
243
+ } | null;
244
+ audio: {
245
+ codec: string;
246
+ sampleRate: number;
247
+ channels: number;
248
+ } | null;
249
+ };
250
+ /** One part of an export (`jobs.start { parts }`, `jobs.check`). */
251
+ export type WireExportPart = {
252
+ source: string;
253
+ start: number;
254
+ end: number;
255
+ };
256
+ /** The answer of `jobs.check`. */
257
+ export type WireExportCheck = {
258
+ blocking: {
259
+ part: number;
260
+ problem: "unknown" | "missing" | "changed" | "noVideo" | "range";
261
+ /** `range`: the file's duration. */
262
+ duration?: number;
263
+ }[];
264
+ copy: {
265
+ ok: true;
266
+ container: "mp4" | "mkv";
267
+ } | {
268
+ ok: false;
269
+ reasons: {
270
+ part: number;
271
+ field: "videoCodec" | "videoParams" | "size" | "fps" | "pixelFormat" | "audio" | "effects";
272
+ value: string | number | null;
273
+ expected: string | number | null;
274
+ }[];
275
+ };
276
+ encode: {
277
+ width: number;
278
+ height: number;
279
+ fps: number;
280
+ audio: {
281
+ sampleRate: 48000;
282
+ channels: 2;
283
+ } | null;
284
+ } | null;
285
+ duration: number;
286
+ };
211
287
  export type MediaOperation = {
212
288
  status: "pending" | "unknown" | "unknownExpired";
213
289
  } | {
@@ -264,5 +340,36 @@ export declare function mediaClients(transport: Transport): {
264
340
  cancel: "requested" | "tooLate" | "terminal";
265
341
  }>;
266
342
  operation: (operationId: number) => Promise<MediaOperation>;
343
+ /** `jobs.start` with parts of remembered files instead of a snapshot. */
344
+ startParts: (options: {
345
+ operationId: number;
346
+ parts: WireExportPart[];
347
+ destination: string;
348
+ } & ({
349
+ kind: "rawCopy";
350
+ container?: "auto" | "mp4" | "mkv";
351
+ } | {
352
+ kind: "rawMp4";
353
+ encoding?: WireEncoding;
354
+ })) => Promise<{
355
+ jobId: number;
356
+ status: "queued";
357
+ }>;
358
+ check: (parts: WireExportPart[], encoding?: WireEncoding) => Promise<WireExportCheck>;
359
+ /** `jobs.check` of a snapshot's clip (to `end`) instead of parts. */
360
+ checkSnapshot: (snapshotId: number, end: number, encoding?: WireEncoding) => Promise<WireExportCheck>;
361
+ };
362
+ mediaSources: {
363
+ remember: (expected?: SourceStamp) => Promise<WireSourceReference>;
364
+ get: (token: string) => Promise<WireSourceReference>;
365
+ locate: (token: string) => Promise<WireSourceReference | null>;
366
+ forget: (token: string) => Promise<void>;
367
+ list: () => Promise<WireSourceReference[]>;
368
+ /** An `open` submit of the file, under the player service's operation id. */
369
+ open: (options: {
370
+ token: string;
371
+ operationId: number;
372
+ start?: number;
373
+ }) => Promise<SourceOperation>;
267
374
  };
268
375
  };
package/dist/media.js CHANGED
@@ -16,6 +16,26 @@ export function mediaClients(transport) {
16
16
  state: (jobId) => transport.request("jobs.state", { jobId }),
17
17
  cancel: (jobId, operationId) => transport.request("jobs.cancel", { jobId, operationId }),
18
18
  operation: (operationId) => transport.request("jobs.operation", { operationId }),
19
+ /** `jobs.start` with parts of remembered files instead of a snapshot. */
20
+ startParts: (options) => transport.request("jobs.start", options),
21
+ check: (parts, encoding) => transport.request("jobs.check", encoding === undefined ? { parts } : { parts, encoding }),
22
+ /** `jobs.check` of a snapshot's clip (to `end`) instead of parts. */
23
+ checkSnapshot: (snapshotId, end, encoding) => transport.request("jobs.check", encoding === undefined
24
+ ? { snapshotId, end }
25
+ : { snapshotId, end, encoding }),
26
+ },
27
+ mediaSources: {
28
+ remember: (expected) => transport.request("media.sources.remember", expected === undefined ? {} : { expected }),
29
+ get: (token) => transport.request("media.sources.get", {
30
+ token,
31
+ }),
32
+ locate: (token) => transport.request("media.sources.locate", {
33
+ token,
34
+ }),
35
+ forget: (token) => transport.request("media.sources.forget", { token }),
36
+ list: () => transport.request("media.sources.list", {}),
37
+ /** An `open` submit of the file, under the player service's operation id. */
38
+ open: (options) => transport.request("media.sources.open", options),
19
39
  },
20
40
  };
21
41
  }
@@ -15,6 +15,7 @@ export { API_VERSION, CAPABILITIES, CAPABILITY_INFO, MESSAGE_LIMIT, } from "./ca
15
15
  export { HOST_CAPABILITIES } from "./host-capabilities.ts";
16
16
  export { BAR_BUTTON_ICONS, BAR_BUTTON_LIMITS, BUILTIN_COMMANDS, BUILTIN_SUBMENUS, COMMAND_LIMITS, MENU_IDS, } from "./commands.ts";
17
17
  export { BINDING_INPUTS } from "./plugin/bindings.ts";
18
+ export { MEDIA_SOURCE_LIMITS } from "./plugin/media.ts";
18
19
  export { OSD_LIMITS } from "./plugin/osd.ts";
19
20
  export { TIMELINE_LIMITS } from "./plugin/timeline.ts";
20
21
  export { SECRET_LIMITS, SESSION_STORAGE_LIMITS } from "./plugin/services.ts";
@@ -13,6 +13,7 @@ export { API_VERSION, CAPABILITIES, CAPABILITY_INFO, MESSAGE_LIMIT, } from "./ca
13
13
  export { HOST_CAPABILITIES } from "./host-capabilities.js";
14
14
  export { BAR_BUTTON_ICONS, BAR_BUTTON_LIMITS, BUILTIN_COMMANDS, BUILTIN_SUBMENUS, COMMAND_LIMITS, MENU_IDS, } from "./commands.js";
15
15
  export { BINDING_INPUTS } from "./plugin/bindings.js";
16
+ export { MEDIA_SOURCE_LIMITS } from "./plugin/media.js";
16
17
  export { OSD_LIMITS } from "./plugin/osd.js";
17
18
  export { TIMELINE_LIMITS } from "./plugin/timeline.js";
18
19
  export { SECRET_LIMITS, SESSION_STORAGE_LIMITS } from "./plugin/services.js";
@@ -1,6 +1,6 @@
1
1
  import type { Runtime } from "./runtime.ts";
2
2
  import type { ScopeImpl } from "./scope.ts";
3
- import type { Commands } from "./types.ts";
3
+ import type { Commands, Palette } from "./types.ts";
4
4
  /**
5
5
  * One per plugin: the SDK's copy of the key labels of the plugin's own
6
6
  * commands. Started by the first `keys` read or a `player.on("commands.keys")`: it
@@ -16,4 +16,5 @@ declare class KeysService {
16
16
  }
17
17
  export declare const keysOf: (runtime: Runtime) => KeysService;
18
18
  export declare const commands: (scope: ScopeImpl) => Commands;
19
+ export declare const palette: (scope: ScopeImpl) => Palette;
19
20
  export {};
@@ -6,6 +6,7 @@ import { BAR_BUTTON_ICONS, BAR_BUTTON_LIMITS, MENU_IDS } from "../commands.js";
6
6
  import { ImageHandle } from "./view/image.js";
7
7
  import { isTextValue, textProblem } from "../i18n.js";
8
8
  import { conditionJson, isCondition } from "./when.js";
9
+ import { shownText } from "./osd.js";
9
10
  const value = (item) => typeof item === "function" ? item() : item;
10
11
  /**
11
12
  * A state field given as a function: the command is evaluated in the update
@@ -73,6 +74,10 @@ function declare(options) {
73
74
  // Only when set: players before 0.7.6 refuse the fields.
74
75
  if (category !== undefined)
75
76
  declaration.category = category;
77
+ if (options.destructive === true)
78
+ declaration.destructive = true;
79
+ else if (options.destructive !== undefined && options.destructive !== false)
80
+ throw failure("invalid", `command ${options.id}: destructive is a boolean`);
76
81
  if (options.home !== undefined) {
77
82
  if (typeof options.home !== "string")
78
83
  throw failure("invalid", `command ${options.id}: home is a command id`);
@@ -92,15 +97,19 @@ function button(id, value, inMenu) {
92
97
  order < 0 ||
93
98
  order > BAR_BUTTON_LIMITS.maxOrder)
94
99
  throw fail(`button order must be an integer 0–${BAR_BUTTON_LIMITS.maxOrder}`);
100
+ return { icon: iconJson(icon, fail, "button"), order };
101
+ }
102
+ /** An icon name of the player's set or an image, checked, in wire form. */
103
+ function iconJson(icon, fail, what) {
95
104
  if (icon instanceof ImageHandle) {
96
105
  if (icon.released)
97
- throw fail(`button image ${icon.path} was released with the scope that created it`);
98
- return { icon: icon.toJSON(), order };
106
+ throw fail(`${what} image ${icon.path} was released with the scope that created it`);
107
+ return icon.toJSON();
99
108
  }
100
109
  if (typeof icon !== "string" ||
101
110
  !BAR_BUTTON_ICONS.includes(icon))
102
- throw fail(`unknown button icon ${JSON.stringify(icon)}: a name of @vestra/icons.slint (BAR_BUTTON_ICONS) or an image from plugin.ui.image`);
103
- return { icon, order };
111
+ throw fail(`unknown ${what} icon ${JSON.stringify(icon)}: a name of @vestra/icons.slint (BAR_BUTTON_ICONS) or an image from plugin.ui.image`);
112
+ return icon;
104
113
  }
105
114
  class CommandHandle {
106
115
  id;
@@ -349,4 +358,122 @@ export const commands = (scope) => ({
349
358
  scope.runtime.depends(KEYS, id);
350
359
  return service.get(id);
351
360
  },
361
+ list: async () => {
362
+ needs(scope, "commands.run");
363
+ return scope.runtime.host.commands.list();
364
+ },
365
+ async run(id, options) {
366
+ needs(scope, "commands.run");
367
+ if (typeof id !== "string" || id === "")
368
+ throw failure("invalid", "run takes a command id: <plugin>/<id>");
369
+ const { ticket, step, of } = (options ?? {});
370
+ if (typeof ticket !== "string" || ticket === "")
371
+ throw failure("ticket", "run needs the ticket of a user action");
372
+ // As the player: both or neither, 1 <= step <= of <= 99.
373
+ const whole = (value) => Number.isInteger(value) &&
374
+ value >= 1 &&
375
+ value <= 99;
376
+ if ((step === undefined) !== (of === undefined) ||
377
+ (step !== undefined && (!whole(step) || !whole(of) || step > of)))
378
+ throw failure("invalid", "step and of go together, 1 <= step <= of <= 99");
379
+ return scope.runtime.host.commands.run({
380
+ id,
381
+ ticket,
382
+ ...(step === undefined ? {} : { step }),
383
+ ...(of === undefined ? {} : { of }),
384
+ });
385
+ },
386
+ });
387
+ /** Refuse at once without `capability`, as the player does. */
388
+ function needs(scope, capability) {
389
+ if (!scope.runtime.can(capability))
390
+ throw failure("capability", `${capability} must be declared in manifest`);
391
+ }
392
+ // ---------------------------------------------------------------- palette lead
393
+ /** `PaletteLeadOptions` checked and in wire form; the player checks lengths. */
394
+ function leadJson(options) {
395
+ if (options === null || typeof options !== "object")
396
+ throw failure("invalid", "lead takes { title, icon, ... }");
397
+ const text = (value, what) => shownText(value, undefined, what);
398
+ const out = {
399
+ title: text(options.title, "title"),
400
+ icon: iconJson(options.icon, (problem) => failure("invalid", problem), "lead"),
401
+ };
402
+ for (const key of ["placeholder", "empty", "note"])
403
+ if (options[key] !== undefined)
404
+ out[key] = text(options[key], key);
405
+ const status = options.status;
406
+ if (status === null)
407
+ out.status = null;
408
+ else if (status !== undefined) {
409
+ if (typeof status !== "object")
410
+ throw failure("invalid", "status is { text, note? } or null");
411
+ out.status = {
412
+ text: text(status.text, "status.text"),
413
+ ...(status.note === undefined
414
+ ? {}
415
+ : { note: text(status.note, "status.note") }),
416
+ };
417
+ }
418
+ return out;
419
+ }
420
+ class LeadHandle {
421
+ ready;
422
+ #scope;
423
+ #pump;
424
+ #listeners = new Set();
425
+ #event;
426
+ #disposed = false;
427
+ constructor(scope, options) {
428
+ needs(scope, "palette.lead");
429
+ const first = leadJson(options);
430
+ this.#scope = scope;
431
+ const host = scope.runtime.host.palette;
432
+ this.#pump = new Latest((value) => host.set(value));
433
+ // Not an activation step: a refusal (a development load is not built
434
+ // in) reaches `ready` and onError, and the rest of the plugin runs.
435
+ this.ready = quiet(this.#pump.push(first).then(() => { }));
436
+ this.ready.catch((error) => scope.report(error));
437
+ // Sent to the lead's owner unasked, like `commands.execute`.
438
+ this.#event = scope.runtime.raw("palette.lead", (data) => {
439
+ const raw = (data ?? {});
440
+ const run = {
441
+ query: String(raw.query ?? ""),
442
+ keep: raw.keep === true,
443
+ ticket: String(raw.ticket ?? ""),
444
+ status: raw.status === true,
445
+ };
446
+ for (const listener of [...this.#listeners])
447
+ scope.run(listener, run);
448
+ });
449
+ scope.add(this);
450
+ }
451
+ async update(options) {
452
+ if (this.#disposed)
453
+ return;
454
+ await this.#pump.push(leadJson(options));
455
+ }
456
+ onRun(listener) {
457
+ this.#listeners.add(listener);
458
+ return { dispose: async () => void this.#listeners.delete(listener) };
459
+ }
460
+ async done(ticket) {
461
+ if (typeof ticket !== "string" || ticket === "")
462
+ throw failure("invalid", "done takes a ticket");
463
+ await this.#scope.runtime.host.palette.done(ticket);
464
+ }
465
+ async dispose() {
466
+ if (this.#disposed)
467
+ return;
468
+ this.#disposed = true;
469
+ this.#scope.forget(this);
470
+ this.#listeners.clear();
471
+ await this.#event.dispose();
472
+ this.#pump.stop();
473
+ if (await this.ready.then(() => true, () => false))
474
+ await this.#scope.runtime.host.palette.clear().catch(() => { });
475
+ }
476
+ }
477
+ export const palette = (scope) => ({
478
+ lead: (options) => new LeadHandle(scope, options),
352
479
  });
@@ -1,3 +1,29 @@
1
1
  import type { ScopeImpl } from "./scope.ts";
2
2
  import type { MediaCapture } from "./types.ts";
3
3
  export declare function mediaCapture(scope: ScopeImpl): MediaCapture;
4
+ /**
5
+ * The player's bounds of remembered files and exports of their parts,
6
+ * documented in the limits reference. Exported from `./runtime` only, for
7
+ * the player's agreement test; TestHost and the SDK's own checks read
8
+ * these figures. The bound on references is a resource limit; tokens are
9
+ * an API convenience, not a security boundary.
10
+ *
11
+ * @internal
12
+ */
13
+ export declare const MEDIA_SOURCE_LIMITS: Readonly<{
14
+ /** References one plugin may hold; one more fails with `limit` (500). */
15
+ readonly references: 500;
16
+ /** Parts of one export or check, at least 1; more fail with `invalid` (100). */
17
+ readonly parts: 100;
18
+ /** Seconds of a part's end in its file (24 hours). */
19
+ readonly partEnd: 86400;
20
+ /** Seconds of all parts of one export together, as one clip (24 hours). */
21
+ readonly totalSeconds: 86400;
22
+ /**
23
+ * `remember`, `get`, `list` and checks one plugin may have the
24
+ * player working on at the same time; one more fails with `busy` (4).
25
+ */
26
+ readonly requests: 4;
27
+ /** Seconds between two `locate` dialogs of one plugin; sooner fails with `busy` (2). */
28
+ readonly locateInterval: 2;
29
+ }>;
@@ -140,6 +140,8 @@ class JobHandle {
140
140
  await this.cancel().catch(() => { });
141
141
  }
142
142
  }
143
+ /** A live snapshot's id, for `exportCheck({ snapshot })`. */
144
+ const snapshotIds = new WeakMap();
143
145
  class SnapshotHandle {
144
146
  #scope;
145
147
  #service;
@@ -150,6 +152,11 @@ class SnapshotHandle {
150
152
  this.#service = service;
151
153
  this.#frozen = frozen;
152
154
  scope.add(this);
155
+ snapshotIds.set(this, () => {
156
+ if (this.#released)
157
+ throw failure("released", "snapshot already released");
158
+ return this.#frozen.snapshotId;
159
+ });
153
160
  }
154
161
  get kind() {
155
162
  return this.#frozen.kind;
@@ -311,5 +318,164 @@ export function mediaCapture(scope) {
311
318
  : await runtime.host.snapshot.state(captured.snapshotId);
312
319
  return new SnapshotHandle(scope, service, frozen);
313
320
  },
321
+ sources: mediaSources(scope),
322
+ async export(options) {
323
+ const runtime = scope.runtime;
324
+ const service = serviceOf(runtime);
325
+ if (typeof options !== "object" || options === null)
326
+ throw failure("invalid", "export options must be an object");
327
+ needSources(scope);
328
+ const parts = checkParts(options.parts);
329
+ let mode;
330
+ if (options.format === "copy") {
331
+ const container = options.container;
332
+ if (container !== undefined &&
333
+ !["auto", "mp4", "mkv"].includes(container))
334
+ throw failure("invalid", "container must be auto, mp4 or mkv");
335
+ if (options.encoding !== undefined)
336
+ throw failure("invalid", "a copy takes no encoding");
337
+ mode = {
338
+ kind: "rawCopy",
339
+ ...(container === undefined ? {} : { container }),
340
+ };
341
+ }
342
+ else if (options.format === "mp4") {
343
+ if (options.container !== undefined)
344
+ throw failure("invalid", "a re-encode takes no container");
345
+ mode = {
346
+ kind: "rawMp4",
347
+ ...(options.encoding === undefined
348
+ ? {}
349
+ : { encoding: checkEncoding(options.encoding) }),
350
+ };
351
+ }
352
+ else
353
+ throw failure("invalid", `an export of parts is format copy or mp4, not ${String(options.format)}`);
354
+ const result = await service.mutate((operationId) => runtime.host.jobs.startParts({
355
+ operationId,
356
+ parts,
357
+ destination: options.destination,
358
+ ...mode,
359
+ }));
360
+ return new JobHandle(scope, service, result.jobId);
361
+ },
362
+ async exportCheck(input, options) {
363
+ const encoding = options?.encoding === undefined
364
+ ? undefined
365
+ : checkEncoding(options.encoding);
366
+ if (!Array.isArray(input)) {
367
+ // A snapshot's clip: needs no media.sources.
368
+ const id = input?.snapshot
369
+ ? snapshotIds.get(input.snapshot)
370
+ : undefined;
371
+ if (!id)
372
+ throw failure("invalid", "exportCheck takes parts or { snapshot, end }");
373
+ if (!Number.isFinite(input.end))
374
+ throw failure("invalid", "end must be seconds");
375
+ return scope.runtime.host.jobs.checkSnapshot(id(), input.end, encoding);
376
+ }
377
+ // As the player: parts carry their own ends; `end` is a snapshot's.
378
+ if (options?.end !== undefined)
379
+ throw failure("invalid", "end belongs to a snapshot's check; parts carry their own end");
380
+ needSources(scope);
381
+ return scope.runtime.host.jobs.check(checkParts(input), encoding);
382
+ },
383
+ };
384
+ }
385
+ /**
386
+ * The player's bounds of remembered files and exports of their parts,
387
+ * documented in the limits reference. Exported from `./runtime` only, for
388
+ * the player's agreement test; TestHost and the SDK's own checks read
389
+ * these figures. The bound on references is a resource limit; tokens are
390
+ * an API convenience, not a security boundary.
391
+ *
392
+ * @internal
393
+ */
394
+ export const MEDIA_SOURCE_LIMITS = Object.freeze({
395
+ /** References one plugin may hold; one more fails with `limit` (500). */
396
+ references: 500,
397
+ /** Parts of one export or check, at least 1; more fail with `invalid` (100). */
398
+ parts: 100,
399
+ /** Seconds of a part's end in its file (24 hours). */
400
+ partEnd: 86400,
401
+ /** Seconds of all parts of one export together, as one clip (24 hours). */
402
+ totalSeconds: 86400,
403
+ /**
404
+ * `remember`, `get`, `list` and checks one plugin may have the
405
+ * player working on at the same time; one more fails with `busy` (4).
406
+ */
407
+ requests: 4,
408
+ /** Seconds between two `locate` dialogs of one plugin; sooner fails with `busy` (2). */
409
+ locateInterval: 2,
410
+ });
411
+ /** Refuse what the player would refuse of an export's parts, naming the part. */
412
+ function checkParts(parts) {
413
+ if (!Array.isArray(parts) ||
414
+ parts.length === 0 ||
415
+ parts.length > MEDIA_SOURCE_LIMITS.parts)
416
+ throw failure("invalid", `an export takes 1 to ${MEDIA_SOURCE_LIMITS.parts} parts`);
417
+ const checked = parts.map((part, index) => {
418
+ const { source, start, end } = part ?? {};
419
+ if (typeof source !== "string" || source === "")
420
+ throw failure("invalid", `part ${index}: source must be a token`);
421
+ if (!Number.isFinite(start) ||
422
+ !Number.isFinite(end) ||
423
+ start < 0 ||
424
+ end > MEDIA_SOURCE_LIMITS.partEnd ||
425
+ end <= start)
426
+ throw failure("invalid", `part ${index}: start and end must be seconds with 0 <= start < end <= ${MEDIA_SOURCE_LIMITS.partEnd}`);
427
+ return { source, start, end };
428
+ });
429
+ const total = checked.reduce((sum, part) => sum + part.end - part.start, 0);
430
+ if (total > MEDIA_SOURCE_LIMITS.totalSeconds)
431
+ throw failure("invalid", `the parts are ${total} s long; an export takes at most ${MEDIA_SOURCE_LIMITS.totalSeconds} s`);
432
+ return checked;
433
+ }
434
+ /** The parts' tokens are media.sources': refuse at once without it, as the player does. */
435
+ function needSources(scope) {
436
+ if (!scope.runtime.can("media.sources"))
437
+ throw failure("capability", "media.sources must be declared in manifest");
438
+ }
439
+ function mediaSources(scope) {
440
+ const host = () => {
441
+ needSources(scope);
442
+ return scope.runtime.host.mediaSources;
443
+ };
444
+ const token = (value) => {
445
+ if (typeof value !== "string" || value === "")
446
+ throw failure("invalid", "token must be a non-empty string");
447
+ return value;
448
+ };
449
+ return {
450
+ async remember(options) {
451
+ // Conditional like a capture: the token is for the file in `ifCurrent`.
452
+ const expected = options?.ifCurrent === undefined
453
+ ? undefined
454
+ : playerOf(scope.runtime).expected(options.ifCurrent).expected;
455
+ return host().remember(expected);
456
+ },
457
+ get: async (value) => host().get(token(value)),
458
+ locate: async (value) => host().locate(token(value)),
459
+ forget: async (value) => host().forget(token(value)),
460
+ list: async () => host().list(),
461
+ async open(value, options = {}) {
462
+ needSources(scope);
463
+ // An open like Player.open's: the player asks playback.control too.
464
+ if (!scope.runtime.can("playback.control"))
465
+ throw failure("capability", "playback.control must be declared in manifest");
466
+ const start = options?.start;
467
+ if (start !== undefined && !(Number.isFinite(start) && start >= 0))
468
+ throw failure("invalid", "start must be seconds from 0");
469
+ const checked = token(value);
470
+ // An ordinary open, followed like player.open's (the player opens the
471
+ // path the token stands for; the plugin never sees it).
472
+ await playerOf(scope.runtime).submit({ kind: "open", source: "", startPaused: false }, {
473
+ send: (operationId) => host().open({
474
+ token: checked,
475
+ operationId,
476
+ ...(start === undefined ? {} : { start }),
477
+ }),
478
+ });
479
+ },
314
480
  };
315
481
  }
@@ -1,4 +1,4 @@
1
- import type { SourceIntent, SourceStamp, SourceState, SourceTicket } from "../source.ts";
1
+ import type { SourceIntent, SourceOperation, SourceStamp, SourceState, SourceTicket } from "../source.ts";
2
2
  import { Latest } from "./latest.ts";
3
3
  import type { Runtime } from "./runtime.ts";
4
4
  import type { ScopeImpl } from "./scope.ts";
@@ -69,6 +69,12 @@ export declare class PlayerService implements StreamSource {
69
69
  submit(intent: SourceIntent, options?: {
70
70
  signal?: AbortSignal;
71
71
  accepted?: (ticket: SourceTicket) => void;
72
+ /**
73
+ * Send the submit another way under this service's operation id
74
+ * (`media.sources.open`, which the player turns into this intent's
75
+ * `source.submit`); followed with `source.operation` as any submit.
76
+ */
77
+ send?: (operationId: number) => Promise<SourceOperation>;
72
78
  }): Promise<SourceTicket>;
73
79
  expected(state: PlayerState | undefined): {
74
80
  expected?: SourceStamp;
@@ -270,7 +270,9 @@ export class PlayerService {
270
270
  const id = ++this.#operation;
271
271
  let result;
272
272
  try {
273
- result = await this.runtime.host.source.submit(intent, id);
273
+ result = await (options.send
274
+ ? options.send(id)
275
+ : this.runtime.host.source.submit(intent, id));
274
276
  }
275
277
  catch (error) {
276
278
  if (!uncertain(error))
@@ -36,6 +36,7 @@ export declare class ScopeImpl implements Plugin {
36
36
  readonly resolvers: import("./types.ts").Resolvers;
37
37
  readonly packages: import("./types.ts").Packages;
38
38
  readonly osd: import("./types.ts").Osd;
39
+ readonly palette: import("./types.ts").Palette;
39
40
  readonly host: import("./types.ts").Host;
40
41
  readonly clipboard: import("./types.ts").Clipboard;
41
42
  readonly power: import("./types.ts").Power;
@@ -1,6 +1,6 @@
1
1
  /** Scopes own handles. Disposal runs newest first and never throws. */
2
2
  import { failure, toError } from "./errors.js";
3
- import { commands, keysOf } from "./commands.js";
3
+ import { commands, keysOf, palette } from "./commands.js";
4
4
  import { WHEN } from "./when.js";
5
5
  import { dialogs } from "./services/dialogs.js";
6
6
  import { ui } from "./view/image.js";
@@ -88,6 +88,7 @@ export class ScopeImpl {
88
88
  resolvers = resolvers(this);
89
89
  packages = packages(this);
90
90
  osd = osd(this);
91
+ palette = palette(this);
91
92
  host = host(this);
92
93
  clipboard = clipboard(this);
93
94
  power = power(this);
@@ -62,3 +62,10 @@ export declare function press(host: TestHost, inner: Internals, binding: string,
62
62
  export declare function barButtons(host: TestHost, _inner: Internals): readonly FakeBarButton[];
63
63
  /** The default handlers of this area's wire methods, by method name. */
64
64
  export declare function commandsHandlers(host: TestHost, inner: Internals): Record<string, Handler>;
65
+ /** The default handlers of `commands.run` and `palette.lead`. */
66
+ export declare function builtinHandlers(host: TestHost, inner: Internals): Record<string, Handler>;
67
+ /** Implements `TestHost.runPaletteLead`. */
68
+ export declare function runPaletteLead(host: TestHost, inner: Internals, query: string, options: {
69
+ keep?: boolean;
70
+ status?: boolean;
71
+ }): Promise<string>;