@botiverse/porthole 0.5.1 → 0.7.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 +41 -0
- package/dist/bridge/bridge.d.ts +13 -0
- package/dist/bridge/bridge.js +208 -13
- package/dist/bridge/navigation.d.ts +1 -6
- package/dist/bridge/navigation.js +11 -0
- package/dist/bridge/refusal.d.ts +5 -1
- package/dist/bridge/refusal.js +16 -0
- package/dist/bridge/types.d.ts +41 -4
- package/dist/check/check.d.ts +19 -3
- package/dist/check/check.js +55 -8
- package/dist/check/files.d.ts +26 -0
- package/dist/check/files.js +307 -0
- package/dist/check/instrument.d.ts +3 -0
- package/dist/check/lint.js +31 -12
- package/dist/check/page-source.js +1 -1
- package/dist/check/page.js +14 -0
- package/dist/check/tools.d.ts +23 -0
- package/dist/check/tools.js +27 -3
- package/dist/compile/policy.d.ts +34 -0
- package/dist/compile/policy.js +74 -0
- package/dist/config/capabilities.d.ts +62 -3
- package/dist/config/capabilities.js +20 -0
- package/dist/config/schema.d.ts +32 -0
- package/dist/config/validate.d.ts +1 -1
- package/dist/config/validate.js +74 -5
- package/dist/conformance/harness-source.js +1 -1
- package/dist/conformance/index.d.ts +1 -0
- package/dist/conformance/index.js +2 -0
- package/dist/conformance/runtime.d.ts +58 -0
- package/dist/conformance/runtime.js +314 -0
- package/dist/files/paths.d.ts +99 -0
- package/dist/files/paths.js +263 -0
- package/dist/files/types.d.ts +24 -0
- package/dist/files/types.js +83 -0
- package/dist/guide/gates.d.ts +3 -0
- package/dist/guide/gates.js +19 -0
- package/dist/guide/guide.d.ts +2 -0
- package/dist/guide/guide.js +44 -32
- package/dist/guide/limits.js +4 -4
- package/dist/guide/runtime.d.ts +13 -0
- package/dist/guide/runtime.js +202 -0
- package/dist/host/create-host.js +45 -0
- package/dist/host/locate.js +8 -0
- package/dist/host/locator.js +7 -0
- package/dist/host/types.d.ts +18 -0
- package/dist/index.d.ts +13 -4
- package/dist/index.js +16 -3
- package/dist/isolation/types.d.ts +8 -0
- package/dist/presets/presets.d.ts +6 -0
- package/dist/presets/presets.js +1 -0
- package/dist/protocol/adapter.d.ts +4 -0
- package/dist/protocol/mcp-apps.d.ts +6 -0
- package/dist/protocol/mcp-apps.js +6 -0
- package/dist/protocol/runtime-calls.d.ts +28 -0
- package/dist/protocol/runtime-calls.js +113 -0
- package/dist/protocol/shell-adapter.js +52 -3
- package/dist/react/dialog.js +31 -0
- package/dist/react/frame.d.ts +13 -0
- package/dist/react/frame.js +6 -0
- package/dist/runtime/contract.d.ts +193 -0
- package/dist/runtime/contract.js +216 -0
- package/dist/runtime/db.d.ts +153 -0
- package/dist/runtime/db.js +398 -0
- package/dist/runtime/declaration.d.ts +86 -0
- package/dist/runtime/declaration.js +266 -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 +199 -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 +57 -0
- package/dist/server/files.js +338 -0
- package/dist/server/host.d.ts +44 -2
- package/dist/server/host.js +42 -2
- package/dist/server/index.d.ts +5 -2
- package/dist/server/index.js +5 -1
- package/dist/server/keys.d.ts +8 -0
- package/dist/server/keys.js +34 -0
- 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 +468 -24
- package/dist/server/types.d.ts +118 -5
- package/dist/shell/document.d.ts +27 -0
- package/dist/shell/document.js +46 -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.d.ts +2 -1
- package/dist/shell/runtime.js +114 -46
- package/dist/shell/use.d.ts +15 -0
- package/dist/shell/use.js +235 -0
- package/docs/ADOPTING.md +142 -5
- package/docs/ARCHITECTURE.md +34 -5
- package/docs/DECISIONS.md +716 -7
- package/docs/DESIGN.md +97 -3
- package/package.json +3 -1
- package/src/bridge/bridge.ts +281 -17
- package/src/bridge/navigation.ts +12 -0
- package/src/bridge/refusal.ts +16 -0
- package/src/bridge/types.ts +46 -4
- package/src/check/check.ts +100 -14
- package/src/check/files.ts +384 -0
- package/src/check/instrument.ts +3 -0
- package/src/check/lint.ts +33 -12
- package/src/check/page.ts +14 -0
- package/src/check/tools.ts +52 -3
- package/src/compile/policy.ts +92 -0
- package/src/config/capabilities.ts +49 -2
- package/src/config/schema.ts +32 -0
- package/src/config/validate.ts +107 -5
- package/src/conformance/index.ts +7 -0
- package/src/conformance/runtime.ts +573 -0
- package/src/files/paths.ts +323 -0
- package/src/files/types.ts +101 -0
- package/src/guide/gates.ts +25 -0
- package/src/guide/guide.ts +78 -52
- package/src/guide/limits.ts +4 -4
- package/src/guide/runtime.ts +244 -0
- package/src/host/create-host.ts +55 -0
- package/src/host/locate.ts +10 -0
- package/src/host/locator.ts +11 -0
- package/src/host/types.ts +18 -0
- package/src/index.ts +121 -0
- package/src/isolation/types.ts +8 -0
- package/src/presets/presets.ts +7 -0
- package/src/protocol/adapter.ts +3 -1
- package/src/protocol/mcp-apps.ts +7 -0
- package/src/protocol/runtime-calls.ts +138 -0
- package/src/protocol/shell-adapter.ts +56 -2
- package/src/react/dialog.tsx +33 -0
- package/src/react/frame.tsx +19 -0
- package/src/runtime/contract.ts +305 -0
- package/src/runtime/db.ts +530 -0
- package/src/runtime/declaration.ts +378 -0
- package/src/runtime/levels.ts +69 -0
- package/src/runtime/requests.ts +339 -0
- package/src/runtime/segments.ts +17 -0
- package/src/runtime/types.generated.ts +19 -0
- package/src/server/files.ts +425 -0
- package/src/server/host.ts +84 -3
- package/src/server/index.ts +22 -0
- package/src/server/keys.ts +53 -0
- package/src/server/pseudonym.ts +21 -0
- package/src/server/server.ts +565 -26
- package/src/server/types.ts +124 -4
- package/src/shell/document.ts +74 -4
- package/src/shell/legacy.ts +64 -0
- package/src/shell/plan.ts +37 -3
- package/src/shell/runtime.ts +114 -46
- 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 +16 -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
package/src/isolation/types.ts
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
* one host app.
|
|
13
13
|
*/
|
|
14
14
|
import type { EgressConfig } from "../config/schema.ts";
|
|
15
|
+
import type { ViewerInfo } from "../runtime/levels.ts";
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* Which document a served frame loads. `preset` names the config it is served under (the server's
|
|
@@ -63,6 +64,11 @@ export interface FrameLocation {
|
|
|
63
64
|
* one that loaded. A host's own gateway may send the same message without this.
|
|
64
65
|
*/
|
|
65
66
|
readonly reports?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Who is viewing, as the host's access decided at issue (P087: `Grant.level`, `Grant.user`):
|
|
69
|
+
* the display's bridge checks each runtime method's level against it.
|
|
70
|
+
*/
|
|
71
|
+
readonly viewer?: ViewerInfo;
|
|
66
72
|
}
|
|
67
73
|
|
|
68
74
|
/** The message a served page sends its host about loading (own-prefixed, P040). */
|
|
@@ -88,4 +94,6 @@ export type FrameSource =
|
|
|
88
94
|
readonly url: string;
|
|
89
95
|
readonly origin: string;
|
|
90
96
|
readonly reports?: boolean;
|
|
97
|
+
/** The issue's viewer (`FrameLocation.viewer`), for the display's bridge. */
|
|
98
|
+
readonly viewer?: ViewerInfo;
|
|
91
99
|
};
|
package/src/presets/presets.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RuntimeVersion } from "../runtime/contract.ts";
|
|
1
2
|
import type { CapabilityName } from "../config/capabilities.ts";
|
|
2
3
|
import type {
|
|
3
4
|
CapabilityConfig,
|
|
@@ -50,6 +51,11 @@ export interface PresetOptions {
|
|
|
50
51
|
readonly storage?: StorageConfig;
|
|
51
52
|
/** Where the content's errors go (`PortholeConfig.errors`); `none` drops `reportError`. */
|
|
52
53
|
readonly errors?: "agent" | "host" | "none";
|
|
54
|
+
/**
|
|
55
|
+
* The capability runtime (P085): content reaches capabilities through `porthole.use`, and may
|
|
56
|
+
* be offered the runtime's own (`user`, `comments`, `artifact`, `assets`, `db`).
|
|
57
|
+
*/
|
|
58
|
+
readonly runtime?: RuntimeVersion;
|
|
53
59
|
}
|
|
54
60
|
|
|
55
61
|
/**
|
|
@@ -207,6 +213,7 @@ function build(
|
|
|
207
213
|
embedder: options.embedder ?? {},
|
|
208
214
|
...(options.storage === undefined ? {} : { storage: options.storage }),
|
|
209
215
|
...(options.errors === undefined ? {} : { errors: options.errors }),
|
|
216
|
+
...(options.runtime === undefined ? {} : { runtime: options.runtime }),
|
|
210
217
|
});
|
|
211
218
|
}
|
|
212
219
|
|
package/src/protocol/adapter.ts
CHANGED
|
@@ -40,7 +40,9 @@ export type AdapterEvent =
|
|
|
40
40
|
/** The view finished its handshake; content may be sent. */
|
|
41
41
|
| { readonly type: "initialized" }
|
|
42
42
|
/** The view asked to be closed. */
|
|
43
|
-
| { readonly type: "teardown-requested" }
|
|
43
|
+
| { readonly type: "teardown-requested" }
|
|
44
|
+
/** A page that came with files is opening another page of its set in the frame (P084). */
|
|
45
|
+
| { readonly type: "navigating" };
|
|
44
46
|
|
|
45
47
|
/** What the framework drives on every adapter. Adapters add their protocol's own operations. */
|
|
46
48
|
export interface AdapterConnection {
|
package/src/protocol/mcp-apps.ts
CHANGED
|
@@ -140,6 +140,13 @@ export const STALE_META = "porthole/stale";
|
|
|
140
140
|
*/
|
|
141
141
|
export const NAVIGATION_BLOCKED_METHOD = "porthole/navigation-blocked";
|
|
142
142
|
|
|
143
|
+
/**
|
|
144
|
+
* Porthole's own notification from the shell (P084): a page that came with files is opening
|
|
145
|
+
* another page of its set, `{ url }`, in the frame. The host takes the frame's next load for that
|
|
146
|
+
* page rather than for content that left (P031). The content's word: it only spares a restart.
|
|
147
|
+
*/
|
|
148
|
+
export const NAVIGATING_METHOD = "porthole/navigating";
|
|
149
|
+
|
|
143
150
|
/** The logger name the shell's error reports (`notifications/message`, level `error`) carry. */
|
|
144
151
|
export const SHELL_LOGGER = "porthole";
|
|
145
152
|
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import type { CallOutcome, HostFunctionBridge } from "../bridge/types.ts";
|
|
2
|
+
import { reasonFor, type RefusalReason } from "../bridge/refusal.ts";
|
|
3
|
+
import type { CapabilityName } from "../config/capabilities.ts";
|
|
4
|
+
import {
|
|
5
|
+
RUNTIME_CAPABILITIES,
|
|
6
|
+
RUNTIME_EVENT_METHOD,
|
|
7
|
+
isRuntimeCapabilityName,
|
|
8
|
+
type RuntimeMethod,
|
|
9
|
+
} from "../runtime/contract.ts";
|
|
10
|
+
import { DB_LIMITS } from "../runtime/db.ts";
|
|
11
|
+
import { downloadContents } from "../runtime/requests.ts";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The host side of the capability runtime's calls (P085): `porthole/call` with `{ capability,
|
|
15
|
+
* method, args }` (and `watch`, a frame-chosen id, for a subscription), each turned into the host
|
|
16
|
+
* function that serves it and passed through the bridge, which alone decides; `porthole/unwatch`
|
|
17
|
+
* ends a watch. A watch's updates go to the frame as `porthole/event` with `{ watch, data }`.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
21
|
+
value !== null && typeof value === "object" && !Array.isArray(value);
|
|
22
|
+
|
|
23
|
+
/** A runtime call as the host function that serves it gets it, or null for none. */
|
|
24
|
+
export function runtimeCall(
|
|
25
|
+
capability: unknown,
|
|
26
|
+
method: unknown,
|
|
27
|
+
args: unknown,
|
|
28
|
+
): { readonly serves: CapabilityName; readonly args: unknown; readonly watch: boolean } | null {
|
|
29
|
+
if (!isRuntimeCapabilityName(capability) || typeof method !== "string") {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
const methods: Readonly<Record<string, RuntimeMethod>> = RUNTIME_CAPABILITIES[capability].methods;
|
|
33
|
+
const spec = Object.hasOwn(methods, method) ? methods[method] : undefined;
|
|
34
|
+
// `data.subscribe` is MCP's own subscription (resources/subscribe, P079), not a runtime call.
|
|
35
|
+
if (spec === undefined || spec.serves === "subscribeData") {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
const given = isRecord(args) ? args : {};
|
|
39
|
+
const watch = spec.watch === true;
|
|
40
|
+
switch (spec.serves) {
|
|
41
|
+
case "downloadFile":
|
|
42
|
+
return {
|
|
43
|
+
serves: spec.serves,
|
|
44
|
+
args: { contents: downloadContents(given.file) ?? undefined },
|
|
45
|
+
watch,
|
|
46
|
+
};
|
|
47
|
+
case "callTool":
|
|
48
|
+
return { serves: spec.serves, args: { name: given.name, arguments: given.arguments }, watch };
|
|
49
|
+
case "readData":
|
|
50
|
+
return { serves: spec.serves, args: { uri: given.uri }, watch };
|
|
51
|
+
case "artifact":
|
|
52
|
+
case "assets":
|
|
53
|
+
case "db":
|
|
54
|
+
// One host function serves several methods: the method is its `op`.
|
|
55
|
+
return { serves: spec.serves, args: { ...given, op: method }, watch };
|
|
56
|
+
default:
|
|
57
|
+
return { serves: spec.serves, args: given, watch };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
type Answer =
|
|
62
|
+
| { readonly result: unknown }
|
|
63
|
+
| { readonly error: { code: number; message: string; data?: RefusalReason } };
|
|
64
|
+
|
|
65
|
+
/** A runtime call's outcome, as the frame hears it: its value, or why it was refused (P080). */
|
|
66
|
+
export function runtimeAnswer(serves: CapabilityName, outcome: CallOutcome<unknown>): Answer {
|
|
67
|
+
if (!outcome.ok) {
|
|
68
|
+
return {
|
|
69
|
+
error: {
|
|
70
|
+
code: -32000,
|
|
71
|
+
message: `Refused (${outcome.refusal})`,
|
|
72
|
+
data: reasonFor(serves, outcome),
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return { result: { value: outcome.value ?? null } };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const refused = (reason: RefusalReason): Answer => ({
|
|
80
|
+
error: { code: -32000, message: `Refused (${reason.code})`, data: reason },
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
/** One frame's runtime calls: its watches, and their end. */
|
|
84
|
+
export function runtimeCalls(
|
|
85
|
+
bridge: HostFunctionBridge,
|
|
86
|
+
notify: (method: string, params: Record<string, unknown>) => void,
|
|
87
|
+
) {
|
|
88
|
+
const watches = new Map<string, AbortController>();
|
|
89
|
+
return {
|
|
90
|
+
async call(params: Record<string, unknown>): Promise<Answer> {
|
|
91
|
+
const mapped = runtimeCall(params.capability, params.method, params.args);
|
|
92
|
+
if (mapped === null) {
|
|
93
|
+
return refused({ code: "not_allowed", message: "This isn't available here." });
|
|
94
|
+
}
|
|
95
|
+
if (!mapped.watch) {
|
|
96
|
+
return runtimeAnswer(mapped.serves, await bridge.call(mapped.serves, mapped.args));
|
|
97
|
+
}
|
|
98
|
+
const id = params.watch;
|
|
99
|
+
if (typeof id !== "string" || !/^[\w-]{1,64}$/u.test(id) || watches.has(id)) {
|
|
100
|
+
return refused({ code: "not_allowed", message: "The app can't take this request." });
|
|
101
|
+
}
|
|
102
|
+
if (watches.size >= DB_LIMITS.maxWatches) {
|
|
103
|
+
return refused({ code: "too_large", message: "Too many things followed at once." });
|
|
104
|
+
}
|
|
105
|
+
const controller = new AbortController();
|
|
106
|
+
watches.set(id, controller);
|
|
107
|
+
const outcome = await bridge.call(mapped.serves, mapped.args, {
|
|
108
|
+
subscription: {
|
|
109
|
+
changed: (data?: unknown) => {
|
|
110
|
+
if (!controller.signal.aborted) {
|
|
111
|
+
notify(RUNTIME_EVENT_METHOD, { watch: id, data: data ?? null });
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
signal: controller.signal,
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
if (!outcome.ok) {
|
|
118
|
+
controller.abort();
|
|
119
|
+
watches.delete(id);
|
|
120
|
+
}
|
|
121
|
+
return outcome.ok ? { result: { value: null } } : runtimeAnswer(mapped.serves, outcome);
|
|
122
|
+
},
|
|
123
|
+
/** The frame stopped following (never gated). */
|
|
124
|
+
unwatch(params: Record<string, unknown>): void {
|
|
125
|
+
const id = params.watch;
|
|
126
|
+
if (typeof id === "string") {
|
|
127
|
+
watches.get(id)?.abort();
|
|
128
|
+
watches.delete(id);
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
close(): void {
|
|
132
|
+
for (const controller of watches.values()) {
|
|
133
|
+
controller.abort();
|
|
134
|
+
}
|
|
135
|
+
watches.clear();
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
@@ -11,12 +11,19 @@ import {
|
|
|
11
11
|
import { reasonFor, type RefusalReason } from "../bridge/refusal.ts";
|
|
12
12
|
import {
|
|
13
13
|
COPY_TEXT_METHOD,
|
|
14
|
+
NAVIGATING_METHOD,
|
|
14
15
|
NAVIGATION_BLOCKED_METHOD,
|
|
15
16
|
MCP_APPS_METHODS as M,
|
|
16
17
|
MCP_APPS_PROTOCOL_VERSION,
|
|
17
18
|
type HostContext,
|
|
18
19
|
} from "./mcp-apps.ts";
|
|
19
20
|
import { liveData } from "./live-data.ts";
|
|
21
|
+
import { runtimeCalls } from "./runtime-calls.ts";
|
|
22
|
+
import {
|
|
23
|
+
RUNTIME_CALL_METHOD,
|
|
24
|
+
RUNTIME_EXPERIMENTAL_KEY,
|
|
25
|
+
RUNTIME_UNWATCH_METHOD,
|
|
26
|
+
} from "../runtime/contract.ts";
|
|
20
27
|
|
|
21
28
|
/**
|
|
22
29
|
* The core's adapter: the host side of the MCP Apps subset the shell speaks, which content using
|
|
@@ -142,7 +149,20 @@ export const shellAdapter: ProtocolAdapter<ShellConnection> = {
|
|
|
142
149
|
transport.send({ jsonrpc: "2.0", method, params });
|
|
143
150
|
|
|
144
151
|
// Live data (P079): reads, subscriptions and the host's updates, through the bridge.
|
|
145
|
-
|
|
152
|
+
let live = liveData(bridge, (uri) => notify(M.resourceUpdated, { uri }));
|
|
153
|
+
// The capability runtime (P085), where the config has one: its calls and watches.
|
|
154
|
+
const runtime = session.compiled.config.runtime;
|
|
155
|
+
let calls = runtimeCalls(bridge, notify);
|
|
156
|
+
// A new page on the same transport (another of the set's pages, P084; or a reload that says
|
|
157
|
+
// hello again) starts with nothing followed: the last page's watches and subscriptions end,
|
|
158
|
+
// so it never hears their updates or their refusals (after the review).
|
|
159
|
+
let greeted = false;
|
|
160
|
+
const forget = () => {
|
|
161
|
+
calls.close();
|
|
162
|
+
calls = runtimeCalls(bridge, notify);
|
|
163
|
+
live.close();
|
|
164
|
+
live = liveData(bridge, (uri) => notify(M.resourceUpdated, { uri }));
|
|
165
|
+
};
|
|
146
166
|
|
|
147
167
|
const flush = () => {
|
|
148
168
|
if (!initialized || closed || content === null || sentWhole) {
|
|
@@ -162,11 +182,28 @@ export const shellAdapter: ProtocolAdapter<ShellConnection> = {
|
|
|
162
182
|
const onRequest = async (request: JsonRpcRequest) => {
|
|
163
183
|
const params = request.params ?? {};
|
|
164
184
|
if (request.method === M.initialize) {
|
|
185
|
+
if (greeted) {
|
|
186
|
+
forget();
|
|
187
|
+
}
|
|
188
|
+
greeted = true;
|
|
165
189
|
respond(request.id, {
|
|
166
190
|
result: {
|
|
167
191
|
protocolVersion: MCP_APPS_PROTOCOL_VERSION,
|
|
168
192
|
hostInfo: session.hostInfo,
|
|
169
|
-
hostCapabilities:
|
|
193
|
+
hostCapabilities: {
|
|
194
|
+
...hostCapabilities((name) => bridge.declared(name)),
|
|
195
|
+
// What this display's page may `use`, in MCP Apps' extension point (P085).
|
|
196
|
+
...(runtime === undefined
|
|
197
|
+
? {}
|
|
198
|
+
: {
|
|
199
|
+
experimental: {
|
|
200
|
+
[RUNTIME_EXPERIMENTAL_KEY]: {
|
|
201
|
+
version: runtime,
|
|
202
|
+
capabilities: bridge.roster(),
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
}),
|
|
206
|
+
},
|
|
170
207
|
hostContext: session.hostContext(),
|
|
171
208
|
},
|
|
172
209
|
});
|
|
@@ -208,6 +245,13 @@ export const shellAdapter: ProtocolAdapter<ShellConnection> = {
|
|
|
208
245
|
}
|
|
209
246
|
return;
|
|
210
247
|
}
|
|
248
|
+
if (request.method === RUNTIME_CALL_METHOD && runtime !== undefined) {
|
|
249
|
+
const answered = await calls.call(params);
|
|
250
|
+
if (!closed) {
|
|
251
|
+
respond(request.id, answered);
|
|
252
|
+
}
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
211
255
|
const mapped = REQUESTS[request.method];
|
|
212
256
|
if (mapped === undefined) {
|
|
213
257
|
respond(request.id, {
|
|
@@ -249,6 +293,15 @@ export const shellAdapter: ProtocolAdapter<ShellConnection> = {
|
|
|
249
293
|
// The shell stopped a navigation (P080): an error report, with its address.
|
|
250
294
|
void bridge.call("reportError", { navigationBlocked: params.url });
|
|
251
295
|
return;
|
|
296
|
+
case RUNTIME_UNWATCH_METHOD:
|
|
297
|
+
calls.unwatch(params);
|
|
298
|
+
return;
|
|
299
|
+
case NAVIGATING_METHOD:
|
|
300
|
+
// Another page of the set opens in the frame (P084): its next load is that page, which
|
|
301
|
+
// follows nothing yet.
|
|
302
|
+
forget();
|
|
303
|
+
session.emit({ type: "navigating" });
|
|
304
|
+
return;
|
|
252
305
|
case M.requestTeardown:
|
|
253
306
|
session.emit({ type: "teardown-requested" });
|
|
254
307
|
return;
|
|
@@ -309,6 +362,7 @@ export const shellAdapter: ProtocolAdapter<ShellConnection> = {
|
|
|
309
362
|
stop();
|
|
310
363
|
pending.clear();
|
|
311
364
|
live.close();
|
|
365
|
+
calls.close();
|
|
312
366
|
},
|
|
313
367
|
};
|
|
314
368
|
},
|
package/src/react/dialog.tsx
CHANGED
|
@@ -70,6 +70,39 @@ function words(request: ConfirmRequest): Words {
|
|
|
70
70
|
return { heading: "Let it follow this?", accept: "Allow", detail: request.args.uri };
|
|
71
71
|
case "copyText":
|
|
72
72
|
return { heading: "Copy this text?", accept: "Copy", detail: request.args.text };
|
|
73
|
+
// The runtime's (P088, P089): the whole effect, as the page asked for it.
|
|
74
|
+
case "artifact":
|
|
75
|
+
return request.args.op === "publish"
|
|
76
|
+
? {
|
|
77
|
+
heading: "Publish a new version of this page?",
|
|
78
|
+
accept: "Publish",
|
|
79
|
+
detail: Object.entries(request.args.files)
|
|
80
|
+
.map(([path, file]) =>
|
|
81
|
+
file === null
|
|
82
|
+
? `${path}: removed`
|
|
83
|
+
: "text" in file
|
|
84
|
+
? `${path}: ${file.text.length.toLocaleString("en-US")} characters`
|
|
85
|
+
: `${path}: ${Math.floor((file.base64.length * 3) / 4).toLocaleString("en-US")} bytes`,
|
|
86
|
+
)
|
|
87
|
+
.join("\n"),
|
|
88
|
+
note: `From version ${request.args.base}${request.args.label === undefined ? "" : `: ${request.args.label}`}.`,
|
|
89
|
+
}
|
|
90
|
+
: { heading: "Allow this?", accept: "Allow", detail: json(request.args) };
|
|
91
|
+
case "assets":
|
|
92
|
+
return request.args.op === "upload"
|
|
93
|
+
? {
|
|
94
|
+
heading: "Add this file to the page's library?",
|
|
95
|
+
accept: "Add",
|
|
96
|
+
detail: `${request.args.name} (${request.args.type}, ${request.args.size.toLocaleString("en-US")} bytes)`,
|
|
97
|
+
note: "Everyone who can see the page can load it.",
|
|
98
|
+
}
|
|
99
|
+
: request.args.op === "delete"
|
|
100
|
+
? {
|
|
101
|
+
heading: "Remove this file from the page's library?",
|
|
102
|
+
accept: "Remove",
|
|
103
|
+
detail: request.args.id,
|
|
104
|
+
}
|
|
105
|
+
: { heading: "Allow this?", accept: "Allow", detail: json(request.args) };
|
|
73
106
|
default:
|
|
74
107
|
return { heading: "Allow this?", accept: "Allow", detail: json(request.args) };
|
|
75
108
|
}
|
package/src/react/frame.tsx
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { PageDeclaration } from "../runtime/declaration.ts";
|
|
2
|
+
import type { ViewerInfo } from "../runtime/levels.ts";
|
|
1
3
|
import {
|
|
2
4
|
createContext,
|
|
3
5
|
useCallback,
|
|
@@ -407,6 +409,17 @@ export interface PortholeFrameProps {
|
|
|
407
409
|
* shows, for its confirmations only, never sent to the frame (P077).
|
|
408
410
|
*/
|
|
409
411
|
readonly instance?: InstanceRef;
|
|
412
|
+
/**
|
|
413
|
+
* What the page declared (P086), as the host stored it with the artifact: the capabilities it
|
|
414
|
+
* reaches through `porthole.use`, and its pinned runtime. By value: a change makes the display
|
|
415
|
+
* again.
|
|
416
|
+
*/
|
|
417
|
+
readonly declaration?: PageDeclaration;
|
|
418
|
+
/**
|
|
419
|
+
* Who is viewing (P087), for an opaque frame or one whose issue gave none. By value: a change
|
|
420
|
+
* makes the display again.
|
|
421
|
+
*/
|
|
422
|
+
readonly viewer?: ViewerInfo;
|
|
410
423
|
/** The color scheme it shows in. Default: the provider's `scheme`, else light. */
|
|
411
424
|
readonly scheme?: ColorScheme;
|
|
412
425
|
/** The host's live values for the config's theme variables (from its design tokens). */
|
|
@@ -664,6 +677,8 @@ function Mount({ frame, page, initialHeightPx, placeholder, run }: MountProps):
|
|
|
664
677
|
// By value: a config or instance made inline (each render) is the same display.
|
|
665
678
|
const config = useByValue(frame.config);
|
|
666
679
|
const instance = useByValue(frame.instance);
|
|
680
|
+
const declaration = useByValue(frame.declaration);
|
|
681
|
+
const viewer = useByValue(frame.viewer);
|
|
667
682
|
const fills = config.mode === "url" || frame.fill === true || config.layout.kind === "fill";
|
|
668
683
|
// A consent that refuses everything (P080), this frame's or else the provider's, by value: a
|
|
669
684
|
// display made with it needs no data handlers, so a change makes the display again.
|
|
@@ -830,6 +845,8 @@ function Mount({ frame, page, initialHeightPx, placeholder, run }: MountProps):
|
|
|
830
845
|
initialHeightPx: startHeight,
|
|
831
846
|
...(view === undefined ? {} : { document: view }),
|
|
832
847
|
...(instance === undefined ? {} : { instance }),
|
|
848
|
+
...(declaration === undefined ? {} : { declaration }),
|
|
849
|
+
...(viewer === undefined ? {} : { viewer }),
|
|
833
850
|
...(fills ? { fill: true } : {}),
|
|
834
851
|
});
|
|
835
852
|
} catch (error) {
|
|
@@ -870,6 +887,8 @@ function Mount({ frame, page, initialHeightPx, placeholder, run }: MountProps):
|
|
|
870
887
|
config,
|
|
871
888
|
view,
|
|
872
889
|
instance,
|
|
890
|
+
declaration,
|
|
891
|
+
viewer,
|
|
873
892
|
startHeight,
|
|
874
893
|
fills,
|
|
875
894
|
pageHandlers,
|