@botiverse/porthole 0.3.1 → 0.3.3

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.
@@ -1,7 +1,7 @@
1
1
  import { type CapabilityName } from "../config/capabilities.ts";
2
2
  import type { AnnotationReport } from "../annotate/types.ts";
3
3
  import type { PortholeConfig } from "../config/schema.ts";
4
- import type { CapabilityHandlers, Confirm, HostFunctionBridge, Refusal } from "./types.ts";
4
+ import type { CapabilityHandlers, Confirm, ConfirmDisplay, HostFunctionBridge, Refusal } from "./types.ts";
5
5
  /**
6
6
  * The host-function bridge: every capability call from a frame passes here, and nowhere else
7
7
  * reaches a host handler. In order: declared → arguments well formed → not muted → within its
@@ -26,10 +26,7 @@ export type BridgeEvent = {
26
26
  };
27
27
  export interface BridgeOptions {
28
28
  readonly config: PortholeConfig;
29
- readonly display: {
30
- readonly id: string;
31
- readonly title: string;
32
- };
29
+ readonly display: ConfirmDisplay;
33
30
  readonly handlers: CapabilityHandlers;
34
31
  readonly confirm?: Confirm;
35
32
  /** Whether the embedding page has user activation now; undefined where it can't tell. */
@@ -1,4 +1,5 @@
1
1
  import type { CapabilityArgs, CapabilityName, CapabilityResults, HandledCapability } from "../config/capabilities.ts";
2
+ import type { InstanceRef } from "../isolation/types.ts";
2
3
  /**
3
4
  * The host-function bridge (ARCHITECTURE § Framework layer): carries a capability call from the
4
5
  * frame to the host's handler and its result back, checking at the boundary that the capability
@@ -17,15 +18,21 @@ export type CapabilityHandler<N extends CapabilityName> = (args: CapabilityArgs[
17
18
  export type CapabilityHandlers = {
18
19
  readonly [N in HandledCapability]?: CapabilityHandler<N>;
19
20
  };
21
+ /**
22
+ * The display a confirmation is for, as the host named it: its id and title, and the instance it
23
+ * shows where it is served (P076), so a host can word its dialog from its own records.
24
+ */
25
+ export interface ConfirmDisplay {
26
+ readonly id: string;
27
+ readonly title: string;
28
+ readonly instance?: InstanceRef;
29
+ }
20
30
  /** What a person is asked to confirm: the call's whole effect, not a summary the content chose. */
21
31
  export type ConfirmRequest = {
22
32
  [N in CapabilityName]: {
23
33
  readonly capability: N;
24
34
  readonly args: CapabilityArgs[N];
25
- readonly display: {
26
- readonly id: string;
27
- readonly title: string;
28
- };
35
+ readonly display: ConfirmDisplay;
29
36
  };
30
37
  }[CapabilityName];
31
38
  /**
@@ -52,8 +52,8 @@ export interface CheckOptions {
52
52
  /** The most distinct problems `text` names (default 8): the rest are counted. */
53
53
  readonly maxProblems?: number;
54
54
  /**
55
- * The check page's script (`import page from "@botiverse/porthole/check/page"`). Node finds it
56
- * itself; a bundled runtime (a Worker) passes it.
55
+ * The check page's script. Default: Porthole's own (`@botiverse/porthole/check/page`), imported
56
+ * with this module, so a bundle (a Worker, a single executable) has it too (P075).
57
57
  */
58
58
  readonly page?: string;
59
59
  }
@@ -1,15 +1,10 @@
1
- var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
- if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
- return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
- return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
- });
6
- }
7
- return path;
8
- };
9
1
  import { presets } from "../presets/presets.js";
10
2
  import { createServer } from "../server/server.js";
11
3
  import { CHECK_CONTENT_DOMAIN, CHECK_ORIGIN } from "./drivers.js";
12
4
  import { lintContent } from "./lint.js";
5
+ // The check page's script, imported as a module so a bundler takes it in (P075): no file is
6
+ // looked up beside this one at run time.
7
+ import PAGE_SCRIPT from "./page-source.js";
13
8
  import { instrumented, namedScripts, } from "./instrument.js";
14
9
  /** The content source the check's served origins match. */
15
10
  const CHECK_SOURCE = `https://*.${CHECK_CONTENT_DOMAIN}`;
@@ -25,16 +20,6 @@ function checkedAs(config) {
25
20
  ? presets.artifact({ egress: opaque.egress, limits: opaque.limits })
26
21
  : opaque;
27
22
  }
28
- /** The check page's script: given, or (Node) the package's own. */
29
- async function pageScript(given) {
30
- if (given !== undefined) {
31
- return given;
32
- }
33
- // Not a literal: a bundler for a Worker leaves it alone (a Worker passes `page`).
34
- const where = new URL(import.meta.url.endsWith(".ts") ? "./page-source.ts" : "./page-source.js", import.meta.url).href;
35
- const loaded = (await import(__rewriteRelativeImportExtension(where)));
36
- return loaded.default;
37
- }
38
23
  const escapeScript = (code) => code.replace(/<\/script/giu, "<\\/script");
39
24
  export async function checkPage(options) {
40
25
  const { config } = options;
@@ -52,7 +37,7 @@ export async function checkPage(options) {
52
37
  const schemes = options.schemes ?? (unthemed ? ["light"] : ["light", "dark"]);
53
38
  const settle = options.settleMs ?? 1_500;
54
39
  const fills = config.layout.kind === "fill";
55
- const script = await pageScript(options.page);
40
+ const script = options.page ?? PAGE_SCRIPT;
56
41
  const html = `<!doctype html><html><head><meta charset="utf-8"><title>Porthole check</title><style>body{margin:0;padding:8px}section{margin-bottom:16px}</style></head><body><script>${escapeScript(script)}</script></body></html>`;
57
42
  // Its inline scripts named, so an error says the line in the content as written (P074).
58
43
  const { content, scriptLines } = namedScripts(options.content);