@botiverse/porthole 0.6.0 → 0.8.0
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/README.md +25 -2
- package/THIRD_PARTY_NOTICES.md +421 -0
- package/dist/bridge/bounded-text.d.ts +34 -0
- package/dist/bridge/bounded-text.js +188 -0
- package/dist/bridge/bridge.d.ts +38 -5
- package/dist/bridge/bridge.js +469 -39
- package/dist/bridge/json-data.d.ts +28 -0
- package/dist/bridge/json-data.js +86 -0
- package/dist/bridge/navigation.d.ts +5 -0
- package/dist/bridge/navigation.js +7 -0
- package/dist/bridge/refusal.d.ts +5 -1
- package/dist/bridge/refusal.js +17 -0
- package/dist/bridge/types.d.ts +73 -5
- package/dist/check/check.d.ts +7 -0
- package/dist/check/check.js +1 -0
- package/dist/check/instrument.d.ts +3 -0
- package/dist/check/lint.js +4 -2
- package/dist/check/page-source.js +1 -1
- package/dist/check/page.js +16 -0
- package/dist/check/tools.js +2 -3
- package/dist/compile/compile.d.ts +6 -0
- package/dist/compile/compile.js +3 -1
- package/dist/compile/policy.d.ts +55 -0
- package/dist/compile/policy.js +157 -0
- package/dist/config/capabilities.d.ts +85 -7
- package/dist/config/capabilities.js +32 -2
- package/dist/config/schema.d.ts +35 -0
- package/dist/config/validate.d.ts +9 -3
- package/dist/config/validate.js +92 -8
- package/dist/config/warnings.d.ts +20 -0
- package/dist/config/warnings.js +25 -0
- package/dist/conformance/behavior.js +46 -1
- package/dist/conformance/cookies.d.ts +15 -0
- package/dist/conformance/cookies.js +80 -0
- package/dist/conformance/harness/page.d.ts +1 -0
- package/dist/conformance/harness/page.js +9 -2
- package/dist/conformance/harness-source.js +1 -1
- package/dist/conformance/host-kit.js +5 -1
- package/dist/conformance/index.d.ts +11 -0
- package/dist/conformance/index.js +2 -0
- package/dist/conformance/limits.js +38 -1
- package/dist/conformance/runtime.d.ts +58 -0
- package/dist/conformance/runtime.js +324 -0
- package/dist/conformance/served.d.ts +2 -0
- package/dist/conformance/served.js +737 -4
- package/dist/files/paths.js +4 -0
- package/dist/guide/gates.d.ts +9 -0
- package/dist/guide/gates.js +31 -0
- package/dist/guide/guide.d.ts +2 -0
- package/dist/guide/guide.js +35 -33
- package/dist/guide/limits.js +4 -4
- package/dist/guide/runtime.d.ts +13 -0
- package/dist/guide/runtime.js +210 -0
- package/dist/host/create-host.js +73 -37
- package/dist/host/locate.js +8 -0
- package/dist/host/locator.js +7 -0
- package/dist/host/pages-of-set.d.ts +43 -0
- package/dist/host/pages-of-set.js +196 -0
- package/dist/host/types.d.ts +26 -1
- package/dist/index.d.ts +11 -4
- package/dist/index.js +11 -2
- package/dist/isolation/types.d.ts +8 -0
- package/dist/mcp/adapter.js +11 -15
- package/dist/node/index.d.ts +36 -4
- package/dist/node/index.js +402 -101
- package/dist/presets/presets.d.ts +22 -8
- package/dist/presets/presets.js +40 -8
- package/dist/protocol/live-data.d.ts +6 -2
- package/dist/protocol/live-data.js +20 -1
- package/dist/protocol/mcp-apps.d.ts +13 -2
- package/dist/protocol/mcp-apps.js +10 -2
- package/dist/protocol/message-text.d.ts +8 -0
- package/dist/protocol/message-text.js +29 -0
- package/dist/protocol/runtime-calls.d.ts +28 -0
- package/dist/protocol/runtime-calls.js +116 -0
- package/dist/protocol/shell-adapter.js +64 -25
- package/dist/react/context-notice.d.ts +32 -0
- package/dist/react/context-notice.js +28 -0
- package/dist/react/dialog.js +91 -16
- package/dist/react/frame.d.ts +25 -1
- package/dist/react/frame.js +85 -2
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +2 -1
- package/dist/runtime/contract.d.ts +201 -0
- package/dist/runtime/contract.js +245 -0
- package/dist/runtime/db.d.ts +188 -0
- package/dist/runtime/db.js +502 -0
- package/dist/runtime/declaration.d.ts +100 -0
- package/dist/runtime/declaration.js +363 -0
- package/dist/runtime/levels.d.ts +33 -0
- package/dist/runtime/levels.js +41 -0
- package/dist/runtime/requests.d.ts +125 -0
- package/dist/runtime/requests.js +215 -0
- package/dist/runtime/segments.d.ts +8 -0
- package/dist/runtime/segments.js +14 -0
- package/dist/runtime/types.generated.d.ts +1 -0
- package/dist/runtime/types.generated.js +19 -0
- package/dist/server/files.d.ts +19 -1
- package/dist/server/files.js +115 -6
- package/dist/server/host.d.ts +24 -2
- package/dist/server/host.js +137 -2
- package/dist/server/index.d.ts +3 -2
- package/dist/server/index.js +2 -1
- package/dist/server/peer.d.ts +4 -0
- package/dist/server/peer.js +19 -0
- package/dist/server/proxy.d.ts +6 -0
- package/dist/server/proxy.js +12 -3
- package/dist/server/pseudonym.d.ts +9 -0
- package/dist/server/pseudonym.js +20 -0
- package/dist/server/server.d.ts +0 -5
- package/dist/server/server.js +318 -52
- package/dist/server/types.d.ts +74 -2
- package/dist/shell/document.d.ts +16 -0
- package/dist/shell/document.js +19 -2
- package/dist/shell/legacy.d.ts +21 -0
- package/dist/shell/legacy.js +63 -0
- package/dist/shell/plan.d.ts +17 -1
- package/dist/shell/plan.js +13 -2
- package/dist/shell/runtime.js +390 -56
- package/dist/shell/use.d.ts +15 -0
- package/dist/shell/use.js +235 -0
- package/docs/ADOPTING.md +205 -15
- package/docs/ARCHITECTURE.md +34 -5
- package/docs/DECISIONS.md +1867 -11
- package/docs/DESIGN.md +137 -17
- package/docs/THREAT_MODEL.md +616 -0
- package/package.json +16 -3
- package/src/bridge/bounded-text.ts +240 -0
- package/src/bridge/bridge.ts +601 -51
- package/src/bridge/json-data.ts +95 -0
- package/src/bridge/navigation.ts +10 -0
- package/src/bridge/refusal.ts +17 -0
- package/src/bridge/types.ts +76 -5
- package/src/check/check.ts +8 -0
- package/src/check/instrument.ts +3 -0
- package/src/check/lint.ts +4 -2
- package/src/check/page.ts +16 -0
- package/src/check/tools.ts +2 -3
- package/src/compile/compile.ts +9 -1
- package/src/compile/policy.ts +177 -0
- package/src/config/capabilities.ts +71 -5
- package/src/config/schema.ts +35 -0
- package/src/config/validate.ts +141 -8
- package/src/config/warnings.ts +42 -0
- package/src/conformance/behavior.ts +54 -1
- package/src/conformance/cookies.ts +93 -0
- package/src/conformance/harness/page.ts +11 -2
- package/src/conformance/host-kit.ts +10 -1
- package/src/conformance/index.ts +17 -0
- package/src/conformance/limits.ts +39 -1
- package/src/conformance/runtime.ts +594 -0
- package/src/conformance/served.ts +888 -4
- package/src/files/paths.ts +4 -0
- package/src/guide/gates.ts +37 -0
- package/src/guide/guide.ts +61 -55
- package/src/guide/limits.ts +4 -4
- package/src/guide/runtime.ts +253 -0
- package/src/host/create-host.ts +88 -36
- package/src/host/locate.ts +10 -0
- package/src/host/locator.ts +11 -0
- package/src/host/pages-of-set.ts +226 -0
- package/src/host/types.ts +33 -1
- package/src/index.ts +94 -0
- package/src/isolation/types.ts +8 -0
- package/src/mcp/adapter.ts +16 -20
- package/src/node/index.ts +507 -116
- package/src/presets/presets.ts +67 -17
- package/src/protocol/live-data.ts +31 -3
- package/src/protocol/mcp-apps.ts +11 -2
- package/src/protocol/message-text.ts +36 -0
- package/src/protocol/runtime-calls.ts +141 -0
- package/src/protocol/shell-adapter.ts +79 -26
- package/src/react/context-notice.tsx +95 -0
- package/src/react/dialog.tsx +108 -15
- package/src/react/frame.tsx +120 -0
- package/src/react/index.ts +8 -1
- package/src/runtime/contract.ts +339 -0
- package/src/runtime/db.ts +650 -0
- package/src/runtime/declaration.ts +516 -0
- package/src/runtime/levels.ts +69 -0
- package/src/runtime/requests.ts +355 -0
- package/src/runtime/segments.ts +17 -0
- package/src/runtime/types.generated.ts +19 -0
- package/src/server/files.ts +138 -7
- package/src/server/host.ts +170 -3
- package/src/server/index.ts +4 -0
- package/src/server/peer.ts +21 -0
- package/src/server/proxy.ts +13 -3
- package/src/server/pseudonym.ts +21 -0
- package/src/server/server.ts +370 -57
- package/src/server/types.ts +73 -2
- package/src/shell/document.ts +29 -4
- package/src/shell/legacy.ts +64 -0
- package/src/shell/plan.ts +37 -3
- package/src/shell/runtime.ts +390 -56
- package/src/shell/use.ts +235 -0
- package/types/runtime/v1/artifact.d.ts +50 -0
- package/types/runtime/v1/assets.d.ts +43 -0
- package/types/runtime/v1/chat.d.ts +13 -0
- package/types/runtime/v1/clipboard.d.ts +14 -0
- package/types/runtime/v1/comments.d.ts +24 -0
- package/types/runtime/v1/context.d.ts +27 -0
- package/types/runtime/v1/data.d.ts +29 -0
- package/types/runtime/v1/db.d.ts +110 -0
- package/types/runtime/v1/downloads.d.ts +22 -0
- package/types/runtime/v1/links.d.ts +13 -0
- package/types/runtime/v1/porthole.d.ts +44 -0
- package/types/runtime/v1/user.d.ts +19 -0
|
@@ -19,6 +19,8 @@ interface Shown {
|
|
|
19
19
|
readonly calls: RecordedCall[];
|
|
20
20
|
readonly events: RecordedEvent[];
|
|
21
21
|
readonly confirmations: { request: ConfirmRequest; resolve: (accepted: boolean) => void }[];
|
|
22
|
+
/** What the host put in front of the person (`show`, P100). */
|
|
23
|
+
readonly disclosed: ConfirmRequest[];
|
|
22
24
|
readonly received: unknown[];
|
|
23
25
|
origin: string | null;
|
|
24
26
|
/** Why the instance couldn't be located (the issue endpoint's refusal). */
|
|
@@ -114,6 +116,7 @@ const harness = {
|
|
|
114
116
|
const container = box(id, spec.widthPx ?? 600, spec.heightPx);
|
|
115
117
|
const calls: RecordedCall[] = [];
|
|
116
118
|
const confirmations: Shown["confirmations"] = [];
|
|
119
|
+
const disclosed: ConfirmRequest[] = [];
|
|
117
120
|
const host = createHost(spec.config, {
|
|
118
121
|
handlers: recorder(calls),
|
|
119
122
|
...(spec.confirms === false
|
|
@@ -122,6 +125,9 @@ const harness = {
|
|
|
122
125
|
confirm: (request: ConfirmRequest) =>
|
|
123
126
|
new Promise<boolean>((resolve) => confirmations.push({ request, resolve })),
|
|
124
127
|
}),
|
|
128
|
+
...(spec.shows === false
|
|
129
|
+
? {}
|
|
130
|
+
: { show: (request: ConfirmRequest) => void disclosed.push(request) }),
|
|
125
131
|
theme: (scheme) => spec.hostTheme?.[scheme] ?? {},
|
|
126
132
|
hostInfo: { name: "porthole-conformance", version: "1" },
|
|
127
133
|
...(nonce === undefined ? {} : { nonce }),
|
|
@@ -132,18 +138,19 @@ const harness = {
|
|
|
132
138
|
scheme: spec.scheme ?? "light",
|
|
133
139
|
...(spec.document === undefined ? {} : { document: spec.document }),
|
|
134
140
|
});
|
|
135
|
-
const
|
|
141
|
+
const display: Shown = {
|
|
136
142
|
handle,
|
|
137
143
|
calls,
|
|
138
144
|
events: [],
|
|
139
145
|
confirmations,
|
|
146
|
+
disclosed,
|
|
140
147
|
received: [],
|
|
141
148
|
origin: null,
|
|
142
149
|
failure: null,
|
|
143
150
|
frame: null,
|
|
144
151
|
};
|
|
145
152
|
const initialized = new Promise<void>((resolve) => handle.on("initialized", () => resolve()));
|
|
146
|
-
watch(id,
|
|
153
|
+
watch(id, display);
|
|
147
154
|
if (spec.document === undefined) {
|
|
148
155
|
await Promise.race([initialized, pause(5_000)]);
|
|
149
156
|
for (const partial of spec.partials ?? []) {
|
|
@@ -178,6 +185,7 @@ const harness = {
|
|
|
178
185
|
calls,
|
|
179
186
|
events: [],
|
|
180
187
|
confirmations: [],
|
|
188
|
+
disclosed: [],
|
|
181
189
|
received: [],
|
|
182
190
|
origin: null,
|
|
183
191
|
failure: null,
|
|
@@ -240,6 +248,7 @@ const harness = {
|
|
|
240
248
|
displays.get(id)?.handle.setContent(html, { partial });
|
|
241
249
|
},
|
|
242
250
|
calls: (id: number) => displays.get(id)?.calls ?? [],
|
|
251
|
+
shown: (id: number) => displays.get(id)?.disclosed ?? [],
|
|
243
252
|
events: (id: number) => displays.get(id)?.events ?? [],
|
|
244
253
|
errors: (id: number) =>
|
|
245
254
|
(displays.get(id)?.events ?? []).flatMap((event) =>
|
|
@@ -11,7 +11,12 @@ import type { ConformanceHarness } from "./harness/page.ts";
|
|
|
11
11
|
import type { FrameOutcome } from "../host/types.ts";
|
|
12
12
|
import type { ConformanceHost, LaunchedDisplay, LaunchSpec } from "./index.ts";
|
|
13
13
|
import { leakTests, type ConformanceFixtures, type ConformanceTest } from "./probes.ts";
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
servedTests,
|
|
16
|
+
TAB_CASES,
|
|
17
|
+
type ServedConformanceHost,
|
|
18
|
+
type ServedDisplay,
|
|
19
|
+
} from "./served.ts";
|
|
15
20
|
|
|
16
21
|
/**
|
|
17
22
|
* The conformance runner (P066): an app points it at its real page (its CSP, its nonce, its
|
|
@@ -240,6 +245,7 @@ export function hostConformance(options: HostConformanceOptions): HostConformanc
|
|
|
240
245
|
return request;
|
|
241
246
|
},
|
|
242
247
|
calls: () => invoke(page, "calls", id),
|
|
248
|
+
shown: () => invoke(page, "shown", id),
|
|
243
249
|
errors: () => invoke(page, "errors", id),
|
|
244
250
|
events: () => invoke(page, "events", id),
|
|
245
251
|
destroy: () => invoke(page, "destroy", id),
|
|
@@ -430,6 +436,7 @@ const URL_CASES = [
|
|
|
430
436
|
"served.url.ticket",
|
|
431
437
|
"served.url.tab",
|
|
432
438
|
"served.url.framed",
|
|
439
|
+
"served.url.siblings",
|
|
433
440
|
];
|
|
434
441
|
const PROXY_CASES = ["served.proxy.view", "served.proxy.parent-only", "served.proxy.egress"];
|
|
435
442
|
const DOMAIN_CASES = [
|
|
@@ -440,6 +447,8 @@ const DOMAIN_CASES = [
|
|
|
440
447
|
"served.domain.address",
|
|
441
448
|
"served.domain.storage-scope",
|
|
442
449
|
"served.domain.ticket-once",
|
|
450
|
+
"served.domain.self-navigation",
|
|
451
|
+
...TAB_CASES,
|
|
443
452
|
"served.domain.frame-ancestors",
|
|
444
453
|
"served.domain.egress",
|
|
445
454
|
];
|
package/src/conformance/index.ts
CHANGED
|
@@ -49,6 +49,11 @@ export interface LaunchSpec {
|
|
|
49
49
|
};
|
|
50
50
|
/** Whether the host has a `confirm` function (default true): without one, gated calls are refused. */
|
|
51
51
|
readonly confirms?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Whether the host has a `show` function (default true, P100): without one, `show`-gated calls
|
|
54
|
+
* (a model context update, by default) are refused.
|
|
55
|
+
*/
|
|
56
|
+
readonly shows?: boolean;
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
export interface RecordedCall {
|
|
@@ -75,6 +80,11 @@ export interface LaunchedDisplay {
|
|
|
75
80
|
): Promise<ConfirmRequest>;
|
|
76
81
|
/** The calls that reached the host's handlers, in order. */
|
|
77
82
|
calls(): Promise<readonly RecordedCall[]>;
|
|
83
|
+
/**
|
|
84
|
+
* What the host showed the person for `show`-gated calls (P100: each model context update), in
|
|
85
|
+
* order. A host whose harness doesn't say has `12.model-context` reported inapplicable.
|
|
86
|
+
*/
|
|
87
|
+
shown?(): Promise<readonly ConfirmRequest[]>;
|
|
78
88
|
/** The errors the display reported. */
|
|
79
89
|
errors(): Promise<readonly string[]>;
|
|
80
90
|
/** Every event the display emitted, in order. */
|
|
@@ -120,6 +130,13 @@ export {
|
|
|
120
130
|
// Redirect entry's cases (P068).
|
|
121
131
|
export { entryTests, type EntryConformanceHost, type EntrySuiteOptions } from "./entry.ts";
|
|
122
132
|
|
|
133
|
+
// The capability runtime's cases an app runs against its own handlers (P085-P090): no browser.
|
|
134
|
+
export {
|
|
135
|
+
defineRuntimeConformance,
|
|
136
|
+
type RuntimeCase,
|
|
137
|
+
type RuntimeConformanceOptions,
|
|
138
|
+
} from "./runtime.ts";
|
|
139
|
+
|
|
123
140
|
// The runner an app points at its real page and issue endpoint (P066).
|
|
124
141
|
export {
|
|
125
142
|
conformancePage,
|
|
@@ -149,6 +149,44 @@ export const LIMIT_PROBES: readonly Probe[] = [
|
|
|
149
149
|
expect(await quiet.errors()).toEqual([]);
|
|
150
150
|
},
|
|
151
151
|
},
|
|
152
|
+
{
|
|
153
|
+
id: "14.error-shapes",
|
|
154
|
+
item: 14,
|
|
155
|
+
title:
|
|
156
|
+
"what content logs as an error reaches the host as bounded text in any shape structured clone carries: a cycle, a BigInt, a shared graph (S05)",
|
|
157
|
+
async run(context) {
|
|
158
|
+
// A graph of 20 objects each holding the next twice: 2^20 leaves written as a tree.
|
|
159
|
+
const logs = `<script>
|
|
160
|
+
(() => {
|
|
161
|
+
const say = (data) => parent.postMessage({ jsonrpc: "2.0", method: "notifications/message", params: { level: "error", data } }, "*");
|
|
162
|
+
const cycle = { name: "porthole-cycle" };
|
|
163
|
+
cycle.self = cycle;
|
|
164
|
+
let graph = "leaf";
|
|
165
|
+
for (let i = 0; i < 20; i += 1) graph = { a: graph, b: graph };
|
|
166
|
+
say(cycle);
|
|
167
|
+
say({ big: 5n });
|
|
168
|
+
say(graph);
|
|
169
|
+
say("porthole-after");
|
|
170
|
+
})();
|
|
171
|
+
</script>`;
|
|
172
|
+
const page = `<!doctype html><html><head><title>View</title></head><body><p>x</p>${logs}</body></html>`;
|
|
173
|
+
for (const display of [
|
|
174
|
+
await context.launch({ config: inline(), content: `<p>x</p>${logs}` }),
|
|
175
|
+
await context.launch({ config: presets.mcpApp(), content: "", document: page }),
|
|
176
|
+
]) {
|
|
177
|
+
await expect
|
|
178
|
+
.poll(async () => (await display.errors()).includes("porthole-after"))
|
|
179
|
+
.toBe(true);
|
|
180
|
+
const errors = await display.errors();
|
|
181
|
+
expect(errors).toContain('{"name":"porthole-cycle","self":"[Circular]"}');
|
|
182
|
+
expect(errors).toContain('{"big":"5n"}');
|
|
183
|
+
const graph = errors.find((each) => each.startsWith('{"a":{"a":'));
|
|
184
|
+
expect(graph, "the shared graph, reported").toBeDefined();
|
|
185
|
+
expect(graph).toContain('"b":"[Repeated]"');
|
|
186
|
+
expect(graph?.length).toBeLessThanOrEqual(2_000);
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
},
|
|
152
190
|
{
|
|
153
191
|
id: "14.silent",
|
|
154
192
|
item: 14,
|
|
@@ -586,7 +624,7 @@ export const LIMIT_PROBES: readonly Probe[] = [
|
|
|
586
624
|
export const LIMIT_CHECKS: { readonly [Id in LimitId]: readonly string[] } = {
|
|
587
625
|
layout: ["11.size", "14.fill"],
|
|
588
626
|
theme: ["11.theme-flip", "11.document-theme", "14.theme-never"],
|
|
589
|
-
errors: ["14.errors"],
|
|
627
|
+
errors: ["14.errors", "14.error-shapes"],
|
|
590
628
|
silent: ["14.silent"],
|
|
591
629
|
network: ["1.connect", "2.resources"],
|
|
592
630
|
"inline-assets": ["14.inline-assets"],
|