@immediately-run/sdk 0.73.0 → 0.74.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.
- package/dist/dnd.cjs +2 -5
- package/dist/dnd.cjs.map +1 -1
- package/dist/dnd.d.cts +8 -1
- package/dist/dnd.d.ts +8 -1
- package/dist/dnd.js +2 -5
- package/dist/dnd.js.map +1 -1
- package/dist/editor.cjs +2 -5
- package/dist/editor.cjs.map +1 -1
- package/dist/editor.d.cts +34 -5
- package/dist/editor.d.ts +34 -5
- package/dist/editor.js +2 -5
- package/dist/editor.js.map +1 -1
- package/dist/feed.cjs +2 -5
- package/dist/feed.cjs.map +1 -1
- package/dist/feed.js +2 -5
- package/dist/feed.js.map +1 -1
- package/dist/generated/spaces.cjs +40 -0
- package/dist/generated/spaces.cjs.map +1 -1
- package/dist/generated/spaces.d.cts +96 -1
- package/dist/generated/spaces.d.ts +96 -1
- package/dist/generated/spaces.js +35 -0
- package/dist/generated/spaces.js.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/ipc.cjs +3 -10
- package/dist/ipc.cjs.map +1 -1
- package/dist/ipc.js +3 -10
- package/dist/ipc.js.map +1 -1
- package/dist/llm.cjs.map +1 -1
- package/dist/llm.d.cts +14 -0
- package/dist/llm.d.ts +14 -0
- package/dist/llm.js.map +1 -1
- package/dist/mounts.cjs +12 -10
- package/dist/mounts.cjs.map +1 -1
- package/dist/mounts.d.cts +9 -2
- package/dist/mounts.d.ts +9 -2
- package/dist/mounts.js +13 -11
- package/dist/mounts.js.map +1 -1
- package/dist/netFetch.cjs +2 -5
- package/dist/netFetch.cjs.map +1 -1
- package/dist/netFetch.js +2 -5
- package/dist/netFetch.js.map +1 -1
- package/dist/openExternal.cjs.map +1 -1
- package/dist/openExternal.d.cts +13 -7
- package/dist/openExternal.d.ts +13 -7
- package/dist/openExternal.js.map +1 -1
- package/dist/openRepository.cjs.map +1 -1
- package/dist/openRepository.d.cts +13 -7
- package/dist/openRepository.d.ts +13 -7
- package/dist/openRepository.js.map +1 -1
- package/dist/protocolRefusal.cjs.map +1 -1
- package/dist/protocolRefusal.d.cts +50 -5
- package/dist/protocolRefusal.d.ts +50 -5
- package/dist/protocolRefusal.js.map +1 -1
- package/dist/secrets.cjs.map +1 -1
- package/dist/secrets.d.cts +8 -1
- package/dist/secrets.d.ts +8 -1
- package/dist/secrets.js.map +1 -1
- package/dist/spacesMode.cjs.map +1 -1
- package/dist/spacesMode.d.cts +13 -1
- package/dist/spacesMode.d.ts +13 -1
- package/dist/spacesMode.js.map +1 -1
- package/dist/theme.cjs +4 -15
- package/dist/theme.cjs.map +1 -1
- package/dist/theme.js +4 -15
- package/dist/theme.js.map +1 -1
- package/dist/vcs.cjs +2 -5
- package/dist/vcs.cjs.map +1 -1
- package/dist/vcs.d.cts +8 -1
- package/dist/vcs.d.ts +8 -1
- package/dist/vcs.js +2 -5
- package/dist/vcs.js.map +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.d.cts +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +4 -3
package/dist/netFetch.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/netFetch.ts"],"sourcesContent":["// hostFetch — the app-facing side of the §5.11 parent-fetch proxy. The app calls\n// `hostFetch(url, init)`; the HOST performs the fetch with its real origin, but\n// only after validating `url` against your manifest's\n// `requests.\"net:fetch\".hosts` ∩ the user's consented hosts, blocking SSRF\n// targets, omitting immediately.run credentials, refusing redirects, and bounding\n// the response size. No raw network handle ever crosses the boundary (§8.10) —\n// only the serialized response.\n\nimport { protocolRequest } from './sandboxUtils';\nimport { protocolStream } from './protocolStream';\nimport { SCHEMES } from './protocolSchemes';\nimport { PROTOCOL_FETCH } from './generated/protocol';\n\n/** Request options for {@link hostFetch}: method, headers, and a string body. */\nexport interface HostFetchInit {\n method?: string;\n headers?: Record<string, string>;\n /** Request body for non-GET/HEAD methods (string). */\n body?: string;\n}\n\n/** The serialized response from {@link hostFetch} (no live stream crosses the boundary). */\nexport interface HostFetchResponse {\n status: number;\n statusText: string;\n headers: Record<string, string>;\n body: string;\n /** True if the body hit the host's size cap and was truncated. */\n truncated: boolean;\n}\n\n/**\n * Fetch through the host's parent-fetch proxy (§5.11). Requires the `net:fetch`\n * capability with `url`'s origin in your effective allowlist (manifest ∩ the\n * user's consent) — both are arranged at load via the consent screen.\n *\n * A reachable server's reply (including a non-2xx status) RESOLVES — inspect\n * `.status`. A gate/SSRF/transport failure REJECTS with an {@link Error} carrying\n * a machine `.code`: `forbidden` (outside the allowlist), `blocked` (SSRF target),\n * `invalid` (bad url/scheme), `redirect` (the host refuses to follow redirects),\n * `too-large`, or `network`.\n */\nexport const hostFetch = async (url: string, init: HostFetchInit = {}): Promise<HostFetchResponse> => {\n const res = (await protocolRequest(SCHEMES[PROTOCOL_FETCH], 'fetch', [\n { url, method: init.method, headers: init.headers, body: init.body },\n ])) as { ok: true; data: HostFetchResponse } | { ok: false; code?: string; message?: string } | undefined;\n
|
|
1
|
+
{"version":3,"sources":["../src/netFetch.ts"],"sourcesContent":["// hostFetch — the app-facing side of the §5.11 parent-fetch proxy. The app calls\n// `hostFetch(url, init)`; the HOST performs the fetch with its real origin, but\n// only after validating `url` against your manifest's\n// `requests.\"net:fetch\".hosts` ∩ the user's consented hosts, blocking SSRF\n// targets, omitting immediately.run credentials, refusing redirects, and bounding\n// the response size. No raw network handle ever crosses the boundary (§8.10) —\n// only the serialized response.\n\nimport { protocolRequest } from './sandboxUtils';\nimport { throwOnRefusal } from './protocolRefusal';\nimport { protocolStream } from './protocolStream';\nimport { SCHEMES } from './protocolSchemes';\nimport { PROTOCOL_FETCH } from './generated/protocol';\n\n/** Request options for {@link hostFetch}: method, headers, and a string body. */\nexport interface HostFetchInit {\n method?: string;\n headers?: Record<string, string>;\n /** Request body for non-GET/HEAD methods (string). */\n body?: string;\n}\n\n/** The serialized response from {@link hostFetch} (no live stream crosses the boundary). */\nexport interface HostFetchResponse {\n status: number;\n statusText: string;\n headers: Record<string, string>;\n body: string;\n /** True if the body hit the host's size cap and was truncated. */\n truncated: boolean;\n}\n\n/**\n * Fetch through the host's parent-fetch proxy (§5.11). Requires the `net:fetch`\n * capability with `url`'s origin in your effective allowlist (manifest ∩ the\n * user's consent) — both are arranged at load via the consent screen.\n *\n * A reachable server's reply (including a non-2xx status) RESOLVES — inspect\n * `.status`. A gate/SSRF/transport failure REJECTS with an {@link Error} carrying\n * a machine `.code`: `forbidden` (outside the allowlist), `blocked` (SSRF target),\n * `invalid` (bad url/scheme), `redirect` (the host refuses to follow redirects),\n * `too-large`, or `network`.\n */\nexport const hostFetch = async (url: string, init: HostFetchInit = {}): Promise<HostFetchResponse> => {\n const res = (await protocolRequest(SCHEMES[PROTOCOL_FETCH], 'fetch', [\n { url, method: init.method, headers: init.headers, body: init.body },\n ])) as { ok: true; data: HostFetchResponse } | { ok: false; code?: string; message?: string } | undefined;\n throwOnRefusal(res, 'hostFetch failed');\n return res.data;\n};\n\n/** One streamed slice of the response body (a chunk as it arrives from the\n * host). Concatenate `.chunk` across the stream to rebuild the body. */\nexport interface HostFetchStreamEvent {\n chunk: string;\n}\n\n/** The terminal value of a {@link hostFetchStream} run — the response metadata,\n * delivered once after the last body chunk. There is no `body` field: the body\n * arrived as the stream of {@link HostFetchStreamEvent}s. */\nexport interface HostFetchStreamResult {\n status: number;\n statusText: string;\n headers: Record<string, string>;\n /** True if the stream hit the host's cumulative byte cap and was truncated. */\n truncated: boolean;\n /** Total decoded body bytes delivered. */\n bytes: number;\n}\n\n/**\n * Stream a response through the host's parent-fetch proxy (§5.11 streaming;\n * `LLM_AND_AGENTS_SPEC §2.2`) — the streaming counterpart of {@link hostFetch},\n * for SSE / LLM token streaming. Same `net:fetch` gate (manifest ∩ consent),\n * same credential-less rule and per-hop SSRF re-check; the response body is\n * pumped as a sequence of {@link HostFetchStreamEvent} chunks instead of a single\n * buffered reply.\n *\n * ```ts\n * let body = '';\n * for await (const { chunk } of hostFetchStream(url, { method: 'POST', body })) {\n * body += chunk; // e.g. parse SSE / token deltas as they arrive\n * }\n * ```\n *\n * The generator **returns** a {@link HostFetchStreamResult} (status + headers +\n * `truncated`/`bytes`) when the body completes. A gate/SSRF/transport failure —\n * or one of the host's stream bounds — **throws** a `StreamError` (from\n * `./protocolStream`) carrying a\n * machine `.code`: `forbidden` (outside the allowlist), `blocked` (SSRF target),\n * `invalid` (bad url/scheme), `redirect` (the host refuses to follow redirects),\n * `idle-timeout` / `total-timeout` (the host's stream bounds), `byte-cap`, or\n * `network`. The stream is bounded by the host's idle/total timeouts and a\n * cumulative byte cap, so it cannot be used as an unbounded transfer channel.\n *\n * Requires the host to implement the `protocol-fetch` streaming emitter; until\n * that lands a streaming request fails with `not-streamable` and callers should\n * fall back to {@link hostFetch} (`LLM_AND_AGENTS_SPEC §2.2`, roadmap P3-71).\n */\nexport function hostFetchStream(\n url: string,\n init: HostFetchInit = {},\n): AsyncGenerator<HostFetchStreamEvent, HostFetchStreamResult, void> {\n return protocolStream<HostFetchStreamEvent, HostFetchStreamResult>(PROTOCOL_FETCH, 'fetchStream', [\n { url, method: init.method, headers: init.headers, body: init.body },\n ]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,0BAAgC;AAChC,6BAA+B;AAC/B,4BAA+B;AAC/B,6BAAwB;AACxB,sBAA+B;AA+BxB,MAAM,YAAY,OAAO,KAAa,OAAsB,CAAC,MAAkC;AACpG,QAAM,MAAO,UAAM,qCAAgB,+BAAQ,8BAAc,GAAG,SAAS;AAAA,IACnE,EAAE,KAAK,QAAQ,KAAK,QAAQ,SAAS,KAAK,SAAS,MAAM,KAAK,KAAK;AAAA,EACrE,CAAC;AACD,6CAAe,KAAK,kBAAkB;AACtC,SAAO,IAAI;AACb;AAkDO,SAAS,gBACd,KACA,OAAsB,CAAC,GAC4C;AACnE,aAAO,sCAA4D,gCAAgB,eAAe;AAAA,IAChG,EAAE,KAAK,QAAQ,KAAK,QAAQ,SAAS,KAAK,SAAS,MAAM,KAAK,KAAK;AAAA,EACrE,CAAC;AACH;","names":[]}
|
package/dist/netFetch.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import "./chunk-VHAA22YE.js";
|
|
2
2
|
import { protocolRequest } from "./sandboxUtils.js";
|
|
3
|
+
import { throwOnRefusal } from "./protocolRefusal.js";
|
|
3
4
|
import { protocolStream } from "./protocolStream.js";
|
|
4
5
|
import { SCHEMES } from "./protocolSchemes.js";
|
|
5
6
|
import { PROTOCOL_FETCH } from "./generated/protocol.js";
|
|
@@ -7,11 +8,7 @@ const hostFetch = async (url, init = {}) => {
|
|
|
7
8
|
const res = await protocolRequest(SCHEMES[PROTOCOL_FETCH], "fetch", [
|
|
8
9
|
{ url, method: init.method, headers: init.headers, body: init.body }
|
|
9
10
|
]);
|
|
10
|
-
|
|
11
|
-
const err = new Error(res?.message ?? "hostFetch failed");
|
|
12
|
-
err.code = (res && "code" in res ? res.code : void 0) ?? "unknown";
|
|
13
|
-
throw err;
|
|
14
|
-
}
|
|
11
|
+
throwOnRefusal(res, "hostFetch failed");
|
|
15
12
|
return res.data;
|
|
16
13
|
};
|
|
17
14
|
function hostFetchStream(url, init = {}) {
|
package/dist/netFetch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/netFetch.ts"],"sourcesContent":["// hostFetch — the app-facing side of the §5.11 parent-fetch proxy. The app calls\n// `hostFetch(url, init)`; the HOST performs the fetch with its real origin, but\n// only after validating `url` against your manifest's\n// `requests.\"net:fetch\".hosts` ∩ the user's consented hosts, blocking SSRF\n// targets, omitting immediately.run credentials, refusing redirects, and bounding\n// the response size. No raw network handle ever crosses the boundary (§8.10) —\n// only the serialized response.\n\nimport { protocolRequest } from './sandboxUtils';\nimport { protocolStream } from './protocolStream';\nimport { SCHEMES } from './protocolSchemes';\nimport { PROTOCOL_FETCH } from './generated/protocol';\n\n/** Request options for {@link hostFetch}: method, headers, and a string body. */\nexport interface HostFetchInit {\n method?: string;\n headers?: Record<string, string>;\n /** Request body for non-GET/HEAD methods (string). */\n body?: string;\n}\n\n/** The serialized response from {@link hostFetch} (no live stream crosses the boundary). */\nexport interface HostFetchResponse {\n status: number;\n statusText: string;\n headers: Record<string, string>;\n body: string;\n /** True if the body hit the host's size cap and was truncated. */\n truncated: boolean;\n}\n\n/**\n * Fetch through the host's parent-fetch proxy (§5.11). Requires the `net:fetch`\n * capability with `url`'s origin in your effective allowlist (manifest ∩ the\n * user's consent) — both are arranged at load via the consent screen.\n *\n * A reachable server's reply (including a non-2xx status) RESOLVES — inspect\n * `.status`. A gate/SSRF/transport failure REJECTS with an {@link Error} carrying\n * a machine `.code`: `forbidden` (outside the allowlist), `blocked` (SSRF target),\n * `invalid` (bad url/scheme), `redirect` (the host refuses to follow redirects),\n * `too-large`, or `network`.\n */\nexport const hostFetch = async (url: string, init: HostFetchInit = {}): Promise<HostFetchResponse> => {\n const res = (await protocolRequest(SCHEMES[PROTOCOL_FETCH], 'fetch', [\n { url, method: init.method, headers: init.headers, body: init.body },\n ])) as { ok: true; data: HostFetchResponse } | { ok: false; code?: string; message?: string } | undefined;\n
|
|
1
|
+
{"version":3,"sources":["../src/netFetch.ts"],"sourcesContent":["// hostFetch — the app-facing side of the §5.11 parent-fetch proxy. The app calls\n// `hostFetch(url, init)`; the HOST performs the fetch with its real origin, but\n// only after validating `url` against your manifest's\n// `requests.\"net:fetch\".hosts` ∩ the user's consented hosts, blocking SSRF\n// targets, omitting immediately.run credentials, refusing redirects, and bounding\n// the response size. No raw network handle ever crosses the boundary (§8.10) —\n// only the serialized response.\n\nimport { protocolRequest } from './sandboxUtils';\nimport { throwOnRefusal } from './protocolRefusal';\nimport { protocolStream } from './protocolStream';\nimport { SCHEMES } from './protocolSchemes';\nimport { PROTOCOL_FETCH } from './generated/protocol';\n\n/** Request options for {@link hostFetch}: method, headers, and a string body. */\nexport interface HostFetchInit {\n method?: string;\n headers?: Record<string, string>;\n /** Request body for non-GET/HEAD methods (string). */\n body?: string;\n}\n\n/** The serialized response from {@link hostFetch} (no live stream crosses the boundary). */\nexport interface HostFetchResponse {\n status: number;\n statusText: string;\n headers: Record<string, string>;\n body: string;\n /** True if the body hit the host's size cap and was truncated. */\n truncated: boolean;\n}\n\n/**\n * Fetch through the host's parent-fetch proxy (§5.11). Requires the `net:fetch`\n * capability with `url`'s origin in your effective allowlist (manifest ∩ the\n * user's consent) — both are arranged at load via the consent screen.\n *\n * A reachable server's reply (including a non-2xx status) RESOLVES — inspect\n * `.status`. A gate/SSRF/transport failure REJECTS with an {@link Error} carrying\n * a machine `.code`: `forbidden` (outside the allowlist), `blocked` (SSRF target),\n * `invalid` (bad url/scheme), `redirect` (the host refuses to follow redirects),\n * `too-large`, or `network`.\n */\nexport const hostFetch = async (url: string, init: HostFetchInit = {}): Promise<HostFetchResponse> => {\n const res = (await protocolRequest(SCHEMES[PROTOCOL_FETCH], 'fetch', [\n { url, method: init.method, headers: init.headers, body: init.body },\n ])) as { ok: true; data: HostFetchResponse } | { ok: false; code?: string; message?: string } | undefined;\n throwOnRefusal(res, 'hostFetch failed');\n return res.data;\n};\n\n/** One streamed slice of the response body (a chunk as it arrives from the\n * host). Concatenate `.chunk` across the stream to rebuild the body. */\nexport interface HostFetchStreamEvent {\n chunk: string;\n}\n\n/** The terminal value of a {@link hostFetchStream} run — the response metadata,\n * delivered once after the last body chunk. There is no `body` field: the body\n * arrived as the stream of {@link HostFetchStreamEvent}s. */\nexport interface HostFetchStreamResult {\n status: number;\n statusText: string;\n headers: Record<string, string>;\n /** True if the stream hit the host's cumulative byte cap and was truncated. */\n truncated: boolean;\n /** Total decoded body bytes delivered. */\n bytes: number;\n}\n\n/**\n * Stream a response through the host's parent-fetch proxy (§5.11 streaming;\n * `LLM_AND_AGENTS_SPEC §2.2`) — the streaming counterpart of {@link hostFetch},\n * for SSE / LLM token streaming. Same `net:fetch` gate (manifest ∩ consent),\n * same credential-less rule and per-hop SSRF re-check; the response body is\n * pumped as a sequence of {@link HostFetchStreamEvent} chunks instead of a single\n * buffered reply.\n *\n * ```ts\n * let body = '';\n * for await (const { chunk } of hostFetchStream(url, { method: 'POST', body })) {\n * body += chunk; // e.g. parse SSE / token deltas as they arrive\n * }\n * ```\n *\n * The generator **returns** a {@link HostFetchStreamResult} (status + headers +\n * `truncated`/`bytes`) when the body completes. A gate/SSRF/transport failure —\n * or one of the host's stream bounds — **throws** a `StreamError` (from\n * `./protocolStream`) carrying a\n * machine `.code`: `forbidden` (outside the allowlist), `blocked` (SSRF target),\n * `invalid` (bad url/scheme), `redirect` (the host refuses to follow redirects),\n * `idle-timeout` / `total-timeout` (the host's stream bounds), `byte-cap`, or\n * `network`. The stream is bounded by the host's idle/total timeouts and a\n * cumulative byte cap, so it cannot be used as an unbounded transfer channel.\n *\n * Requires the host to implement the `protocol-fetch` streaming emitter; until\n * that lands a streaming request fails with `not-streamable` and callers should\n * fall back to {@link hostFetch} (`LLM_AND_AGENTS_SPEC §2.2`, roadmap P3-71).\n */\nexport function hostFetchStream(\n url: string,\n init: HostFetchInit = {},\n): AsyncGenerator<HostFetchStreamEvent, HostFetchStreamResult, void> {\n return protocolStream<HostFetchStreamEvent, HostFetchStreamResult>(PROTOCOL_FETCH, 'fetchStream', [\n { url, method: init.method, headers: init.headers, body: init.body },\n ]);\n}\n"],"mappings":";AAQA,SAAS,uBAAuB;AAChC,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAC/B,SAAS,eAAe;AACxB,SAAS,sBAAsB;AA+BxB,MAAM,YAAY,OAAO,KAAa,OAAsB,CAAC,MAAkC;AACpG,QAAM,MAAO,MAAM,gBAAgB,QAAQ,cAAc,GAAG,SAAS;AAAA,IACnE,EAAE,KAAK,QAAQ,KAAK,QAAQ,SAAS,KAAK,SAAS,MAAM,KAAK,KAAK;AAAA,EACrE,CAAC;AACD,iBAAe,KAAK,kBAAkB;AACtC,SAAO,IAAI;AACb;AAkDO,SAAS,gBACd,KACA,OAAsB,CAAC,GAC4C;AACnE,SAAO,eAA4D,gBAAgB,eAAe;AAAA,IAChG,EAAE,KAAK,QAAQ,KAAK,QAAQ,SAAS,KAAK,SAAS,MAAM,KAAK,KAAK;AAAA,EACrE,CAAC;AACH;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/openExternal.ts"],"sourcesContent":["// Host-mediated \"open this external link in a new tab\" (R3-619).\n//\n// An app frame cannot open an ordinary top-level tab itself for a destination that has to\n// act as itself: a `window.open` or `<a target=\"_blank\">` from inside the sandboxed frame\n// inherits the sandbox (`allow-popups` without `allow-popups-to-escape-sandbox`), so the\n// opened tab runs at the same opaque origin and anything that signs in or posts fails.\n//\n// Unlike `openRepository`, the app here names a URL, not coordinates — the destination is\n// arbitrary, not a platform route. So the host validates the URL and confirms every call\n// (the full destination in its own chrome, opened only on the user's click). The app never\n// receives a `Window` handle; it asks, and the host decides whether and how to open.\n//\n// The same two host-side conditions as `openRepository` hold, and neither is something this\n// call can assert for itself: the confirmation needs the HOST document's live transient\n// user activation (a real click, which the host samples rather than believes), and the\n// confirmation must not consume that activation before the open. Both surface here as\n// ordinary coded refusals.\nimport { protocolRequest } from './sandboxUtils';\nimport { throwOnRefusal } from './protocolRefusal';\nimport { PROTOCOL_OPENLINK } from './generated/protocol';\nimport { SCHEMES } from './protocolSchemes';\n\n/** Why the host refused to open the link.\n *\n * - `invalid` — the URL is not a clean `https:` external destination (scheme, credentials,\n * length, or the host's own origin).\n * - `no-activation` — no live user gesture on the host document. Call this from a click\n * handler; a timer or a boot path will always get this.\n * - `declined` — the host showed the confirmation and the user did not confirm.\n * - `forbidden` — the app does not hold the baseline `link:open` capability.\n * - `unsupported` — this host has no outward-link surface wired (an older host).\n * - `unknown` — the host refused without naming a code. */\nexport type OpenExternalErrorCode = 'invalid' | 'no-activation' | 'declined' | 'forbidden' | 'unsupported' | 'unknown';\n\nexport interface OpenExternalError extends Error {\n code: OpenExternalErrorCode;\n}\n\n/** The host's reply: the envelope resolves inside the promise, so a refusal is a resolved\n * `{ ok: false }` rather than a rejection at the transport layer. */\ntype OpenExternalReply = { ok: true; url?: string } | { ok: false; code?: string; message?: string };\n\n/**\n * Ask the host to open an external link in a new browser tab.\n *\n * Resolves once the host has performed the open; it does not wait for — and cannot observe —\n * the opened tab loading. Rejects with a typed {@link OpenExternalError} carrying `code` when\n * the host refuses.\n *\n *
|
|
1
|
+
{"version":3,"sources":["../src/openExternal.ts"],"sourcesContent":["// Host-mediated \"open this external link in a new tab\" (R3-619).\n//\n// An app frame cannot open an ordinary top-level tab itself for a destination that has to\n// act as itself: a `window.open` or `<a target=\"_blank\">` from inside the sandboxed frame\n// inherits the sandbox (`allow-popups` without `allow-popups-to-escape-sandbox`), so the\n// opened tab runs at the same opaque origin and anything that signs in or posts fails.\n//\n// Unlike `openRepository`, the app here names a URL, not coordinates — the destination is\n// arbitrary, not a platform route. So the host validates the URL and confirms every call\n// (the full destination in its own chrome, opened only on the user's click). The app never\n// receives a `Window` handle; it asks, and the host decides whether and how to open.\n//\n// The same two host-side conditions as `openRepository` hold, and neither is something this\n// call can assert for itself: the confirmation needs the HOST document's live transient\n// user activation (a real click, which the host samples rather than believes), and the\n// confirmation must not consume that activation before the open. Both surface here as\n// ordinary coded refusals.\nimport { protocolRequest } from './sandboxUtils';\nimport { throwOnRefusal } from './protocolRefusal';\nimport { PROTOCOL_OPENLINK } from './generated/protocol';\nimport { SCHEMES } from './protocolSchemes';\n\n/** Why the host refused to open the link.\n *\n * - `invalid` — the URL is not a clean `https:` external destination (scheme, credentials,\n * length, or the host's own origin).\n * - `no-activation` — no live user gesture on the host document. Call this from a click\n * handler; a timer or a boot path will always get this.\n * - `declined` — the host showed the confirmation and the user did not confirm.\n * - `forbidden` — the app does not hold the baseline `link:open` capability.\n * - `unsupported` — this host has no outward-link surface wired (an older host).\n * - `unknown` — the host refused without naming a code.\n *\n * **What you actually catch.** The SDK throws a plain `Error` with `.code` assigned — a\n * `CodedRefusalError` from `protocolRefusal.ts` — never a distinct class. These are the\n * `.code` VALUES the host sends. Nothing enforces the union at runtime — `.code` is\n * whatever string arrived — so treat an unlisted code as possible and `instanceof Error`\n * as the only reliable test.\n *\n * (This note is on the code alias rather than on the interface because the alias is where\n * the codes are documented. Every doclink in this file names the INTERFACE, so a reader\n * following one lands a hop away from this — a wart, not a plan. Stated without a\n * direction on purpose: two earlier revisions of this sentence asserted a positional\n * claim, and both were wrong.) */\nexport type OpenExternalErrorCode = 'invalid' | 'no-activation' | 'declined' | 'forbidden' | 'unsupported' | 'unknown';\n\nexport interface OpenExternalError extends Error {\n code: OpenExternalErrorCode;\n}\n\n/** The host's reply: the envelope resolves inside the promise, so a refusal is a resolved\n * `{ ok: false }` rather than a rejection at the transport layer. */\ntype OpenExternalReply = { ok: true; url?: string } | { ok: false; code?: string; message?: string };\n\n/**\n * Ask the host to open an external link in a new browser tab.\n *\n * Resolves once the host has performed the open; it does not wait for — and cannot observe —\n * the opened tab loading. Rejects with a typed {@link OpenExternalError} carrying `code` when\n * the host refuses.\n *\n * Call it directly from a user gesture. The host samples its own transient activation when\n * the request arrives, so anything that defers the call past the gesture (an `await` before\n * it, a `setTimeout`, a retry) will be refused `no-activation`. None of the refusals are\n * worth retrying: each names a condition a retry cannot change.\n */\nexport async function openExternal(url: string): Promise<void> {\n const res = (await protocolRequest(SCHEMES[PROTOCOL_OPENLINK], 'open', [{ url }])) as OpenExternalReply;\n throwOnRefusal(res, 'external link open refused');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBA,0BAAgC;AAChC,6BAA+B;AAC/B,sBAAkC;AAClC,6BAAwB;AA8CxB,eAAsB,aAAa,KAA4B;AAC7D,QAAM,MAAO,UAAM,qCAAgB,+BAAQ,iCAAiB,GAAG,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAC;AAChF,6CAAe,KAAK,4BAA4B;AAClD;","names":[]}
|
package/dist/openExternal.d.cts
CHANGED
|
@@ -7,7 +7,19 @@
|
|
|
7
7
|
* - `declined` — the host showed the confirmation and the user did not confirm.
|
|
8
8
|
* - `forbidden` — the app does not hold the baseline `link:open` capability.
|
|
9
9
|
* - `unsupported` — this host has no outward-link surface wired (an older host).
|
|
10
|
-
* - `unknown` — the host refused without naming a code.
|
|
10
|
+
* - `unknown` — the host refused without naming a code.
|
|
11
|
+
*
|
|
12
|
+
* **What you actually catch.** The SDK throws a plain `Error` with `.code` assigned — a
|
|
13
|
+
* `CodedRefusalError` from `protocolRefusal.ts` — never a distinct class. These are the
|
|
14
|
+
* `.code` VALUES the host sends. Nothing enforces the union at runtime — `.code` is
|
|
15
|
+
* whatever string arrived — so treat an unlisted code as possible and `instanceof Error`
|
|
16
|
+
* as the only reliable test.
|
|
17
|
+
*
|
|
18
|
+
* (This note is on the code alias rather than on the interface because the alias is where
|
|
19
|
+
* the codes are documented. Every doclink in this file names the INTERFACE, so a reader
|
|
20
|
+
* following one lands a hop away from this — a wart, not a plan. Stated without a
|
|
21
|
+
* direction on purpose: two earlier revisions of this sentence asserted a positional
|
|
22
|
+
* claim, and both were wrong.) */
|
|
11
23
|
type OpenExternalErrorCode = 'invalid' | 'no-activation' | 'declined' | 'forbidden' | 'unsupported' | 'unknown';
|
|
12
24
|
interface OpenExternalError extends Error {
|
|
13
25
|
code: OpenExternalErrorCode;
|
|
@@ -19,12 +31,6 @@ interface OpenExternalError extends Error {
|
|
|
19
31
|
* the opened tab loading. Rejects with a typed {@link OpenExternalError} carrying `code` when
|
|
20
32
|
* the host refuses.
|
|
21
33
|
*
|
|
22
|
-
* **Known gap, 2026-09-25 (R3-778): this does NOT reject today.** The host handler
|
|
23
|
-
* RETURNS its refusals — `invalid`, `no-activation` and **`declined`** (the user pressing "no" on the host's confirmation) — and site-main's dispatcher wraps a
|
|
24
|
-
* handler's return value in an `ok: true` envelope, so every one of those refusals
|
|
25
|
-
* reaches this function as a SUCCESS and `openExternal()` resolves. Do not rely on the
|
|
26
|
-
* `code` branch until R3-778 lands; see `protocolRefusal.ts` for the mechanism.
|
|
27
|
-
*
|
|
28
34
|
* Call it directly from a user gesture. The host samples its own transient activation when
|
|
29
35
|
* the request arrives, so anything that defers the call past the gesture (an `await` before
|
|
30
36
|
* it, a `setTimeout`, a retry) will be refused `no-activation`. None of the refusals are
|
package/dist/openExternal.d.ts
CHANGED
|
@@ -7,7 +7,19 @@
|
|
|
7
7
|
* - `declined` — the host showed the confirmation and the user did not confirm.
|
|
8
8
|
* - `forbidden` — the app does not hold the baseline `link:open` capability.
|
|
9
9
|
* - `unsupported` — this host has no outward-link surface wired (an older host).
|
|
10
|
-
* - `unknown` — the host refused without naming a code.
|
|
10
|
+
* - `unknown` — the host refused without naming a code.
|
|
11
|
+
*
|
|
12
|
+
* **What you actually catch.** The SDK throws a plain `Error` with `.code` assigned — a
|
|
13
|
+
* `CodedRefusalError` from `protocolRefusal.ts` — never a distinct class. These are the
|
|
14
|
+
* `.code` VALUES the host sends. Nothing enforces the union at runtime — `.code` is
|
|
15
|
+
* whatever string arrived — so treat an unlisted code as possible and `instanceof Error`
|
|
16
|
+
* as the only reliable test.
|
|
17
|
+
*
|
|
18
|
+
* (This note is on the code alias rather than on the interface because the alias is where
|
|
19
|
+
* the codes are documented. Every doclink in this file names the INTERFACE, so a reader
|
|
20
|
+
* following one lands a hop away from this — a wart, not a plan. Stated without a
|
|
21
|
+
* direction on purpose: two earlier revisions of this sentence asserted a positional
|
|
22
|
+
* claim, and both were wrong.) */
|
|
11
23
|
type OpenExternalErrorCode = 'invalid' | 'no-activation' | 'declined' | 'forbidden' | 'unsupported' | 'unknown';
|
|
12
24
|
interface OpenExternalError extends Error {
|
|
13
25
|
code: OpenExternalErrorCode;
|
|
@@ -19,12 +31,6 @@ interface OpenExternalError extends Error {
|
|
|
19
31
|
* the opened tab loading. Rejects with a typed {@link OpenExternalError} carrying `code` when
|
|
20
32
|
* the host refuses.
|
|
21
33
|
*
|
|
22
|
-
* **Known gap, 2026-09-25 (R3-778): this does NOT reject today.** The host handler
|
|
23
|
-
* RETURNS its refusals — `invalid`, `no-activation` and **`declined`** (the user pressing "no" on the host's confirmation) — and site-main's dispatcher wraps a
|
|
24
|
-
* handler's return value in an `ok: true` envelope, so every one of those refusals
|
|
25
|
-
* reaches this function as a SUCCESS and `openExternal()` resolves. Do not rely on the
|
|
26
|
-
* `code` branch until R3-778 lands; see `protocolRefusal.ts` for the mechanism.
|
|
27
|
-
*
|
|
28
34
|
* Call it directly from a user gesture. The host samples its own transient activation when
|
|
29
35
|
* the request arrives, so anything that defers the call past the gesture (an `await` before
|
|
30
36
|
* it, a `setTimeout`, a retry) will be refused `no-activation`. None of the refusals are
|
package/dist/openExternal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/openExternal.ts"],"sourcesContent":["// Host-mediated \"open this external link in a new tab\" (R3-619).\n//\n// An app frame cannot open an ordinary top-level tab itself for a destination that has to\n// act as itself: a `window.open` or `<a target=\"_blank\">` from inside the sandboxed frame\n// inherits the sandbox (`allow-popups` without `allow-popups-to-escape-sandbox`), so the\n// opened tab runs at the same opaque origin and anything that signs in or posts fails.\n//\n// Unlike `openRepository`, the app here names a URL, not coordinates — the destination is\n// arbitrary, not a platform route. So the host validates the URL and confirms every call\n// (the full destination in its own chrome, opened only on the user's click). The app never\n// receives a `Window` handle; it asks, and the host decides whether and how to open.\n//\n// The same two host-side conditions as `openRepository` hold, and neither is something this\n// call can assert for itself: the confirmation needs the HOST document's live transient\n// user activation (a real click, which the host samples rather than believes), and the\n// confirmation must not consume that activation before the open. Both surface here as\n// ordinary coded refusals.\nimport { protocolRequest } from './sandboxUtils';\nimport { throwOnRefusal } from './protocolRefusal';\nimport { PROTOCOL_OPENLINK } from './generated/protocol';\nimport { SCHEMES } from './protocolSchemes';\n\n/** Why the host refused to open the link.\n *\n * - `invalid` — the URL is not a clean `https:` external destination (scheme, credentials,\n * length, or the host's own origin).\n * - `no-activation` — no live user gesture on the host document. Call this from a click\n * handler; a timer or a boot path will always get this.\n * - `declined` — the host showed the confirmation and the user did not confirm.\n * - `forbidden` — the app does not hold the baseline `link:open` capability.\n * - `unsupported` — this host has no outward-link surface wired (an older host).\n * - `unknown` — the host refused without naming a code. */\nexport type OpenExternalErrorCode = 'invalid' | 'no-activation' | 'declined' | 'forbidden' | 'unsupported' | 'unknown';\n\nexport interface OpenExternalError extends Error {\n code: OpenExternalErrorCode;\n}\n\n/** The host's reply: the envelope resolves inside the promise, so a refusal is a resolved\n * `{ ok: false }` rather than a rejection at the transport layer. */\ntype OpenExternalReply = { ok: true; url?: string } | { ok: false; code?: string; message?: string };\n\n/**\n * Ask the host to open an external link in a new browser tab.\n *\n * Resolves once the host has performed the open; it does not wait for — and cannot observe —\n * the opened tab loading. Rejects with a typed {@link OpenExternalError} carrying `code` when\n * the host refuses.\n *\n *
|
|
1
|
+
{"version":3,"sources":["../src/openExternal.ts"],"sourcesContent":["// Host-mediated \"open this external link in a new tab\" (R3-619).\n//\n// An app frame cannot open an ordinary top-level tab itself for a destination that has to\n// act as itself: a `window.open` or `<a target=\"_blank\">` from inside the sandboxed frame\n// inherits the sandbox (`allow-popups` without `allow-popups-to-escape-sandbox`), so the\n// opened tab runs at the same opaque origin and anything that signs in or posts fails.\n//\n// Unlike `openRepository`, the app here names a URL, not coordinates — the destination is\n// arbitrary, not a platform route. So the host validates the URL and confirms every call\n// (the full destination in its own chrome, opened only on the user's click). The app never\n// receives a `Window` handle; it asks, and the host decides whether and how to open.\n//\n// The same two host-side conditions as `openRepository` hold, and neither is something this\n// call can assert for itself: the confirmation needs the HOST document's live transient\n// user activation (a real click, which the host samples rather than believes), and the\n// confirmation must not consume that activation before the open. Both surface here as\n// ordinary coded refusals.\nimport { protocolRequest } from './sandboxUtils';\nimport { throwOnRefusal } from './protocolRefusal';\nimport { PROTOCOL_OPENLINK } from './generated/protocol';\nimport { SCHEMES } from './protocolSchemes';\n\n/** Why the host refused to open the link.\n *\n * - `invalid` — the URL is not a clean `https:` external destination (scheme, credentials,\n * length, or the host's own origin).\n * - `no-activation` — no live user gesture on the host document. Call this from a click\n * handler; a timer or a boot path will always get this.\n * - `declined` — the host showed the confirmation and the user did not confirm.\n * - `forbidden` — the app does not hold the baseline `link:open` capability.\n * - `unsupported` — this host has no outward-link surface wired (an older host).\n * - `unknown` — the host refused without naming a code.\n *\n * **What you actually catch.** The SDK throws a plain `Error` with `.code` assigned — a\n * `CodedRefusalError` from `protocolRefusal.ts` — never a distinct class. These are the\n * `.code` VALUES the host sends. Nothing enforces the union at runtime — `.code` is\n * whatever string arrived — so treat an unlisted code as possible and `instanceof Error`\n * as the only reliable test.\n *\n * (This note is on the code alias rather than on the interface because the alias is where\n * the codes are documented. Every doclink in this file names the INTERFACE, so a reader\n * following one lands a hop away from this — a wart, not a plan. Stated without a\n * direction on purpose: two earlier revisions of this sentence asserted a positional\n * claim, and both were wrong.) */\nexport type OpenExternalErrorCode = 'invalid' | 'no-activation' | 'declined' | 'forbidden' | 'unsupported' | 'unknown';\n\nexport interface OpenExternalError extends Error {\n code: OpenExternalErrorCode;\n}\n\n/** The host's reply: the envelope resolves inside the promise, so a refusal is a resolved\n * `{ ok: false }` rather than a rejection at the transport layer. */\ntype OpenExternalReply = { ok: true; url?: string } | { ok: false; code?: string; message?: string };\n\n/**\n * Ask the host to open an external link in a new browser tab.\n *\n * Resolves once the host has performed the open; it does not wait for — and cannot observe —\n * the opened tab loading. Rejects with a typed {@link OpenExternalError} carrying `code` when\n * the host refuses.\n *\n * Call it directly from a user gesture. The host samples its own transient activation when\n * the request arrives, so anything that defers the call past the gesture (an `await` before\n * it, a `setTimeout`, a retry) will be refused `no-activation`. None of the refusals are\n * worth retrying: each names a condition a retry cannot change.\n */\nexport async function openExternal(url: string): Promise<void> {\n const res = (await protocolRequest(SCHEMES[PROTOCOL_OPENLINK], 'open', [{ url }])) as OpenExternalReply;\n throwOnRefusal(res, 'external link open refused');\n}\n"],"mappings":";AAiBA,SAAS,uBAAuB;AAChC,SAAS,sBAAsB;AAC/B,SAAS,yBAAyB;AAClC,SAAS,eAAe;AA8CxB,eAAsB,aAAa,KAA4B;AAC7D,QAAM,MAAO,MAAM,gBAAgB,QAAQ,iBAAiB,GAAG,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAC;AAChF,iBAAe,KAAK,4BAA4B;AAClD;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/openRepository.ts"],"sourcesContent":["// Host-mediated \"open this repository in a new tab\" (R3-476).\n//\n// An app frame cannot open a first-party tab itself. A `window.open` from inside the\n// sandboxed frame inherits the sandbox — the opened tab runs at the same opaque origin and\n// cannot load the host — and `target=\"_top\"` would replace the app's own frame rather than\n// open a tab. So the app asks the host, and the host performs the open from its own context.\n//\n// The app names COORDINATES and nothing else. It cannot pass a URL, a route prefix or a\n// path: the host builds the destination from its own route grammar, so this call can only\n// ever reach one of the platform's own repository routes. That is the point of the shape —\n// an app that could spell the destination could open anything.\n//\n// Two more conditions hold on the host side, and neither is something this call can assert\n// for itself: the open needs the HOST document's live transient user activation (a real\n// click, which the host samples rather than believes), and one gesture opens exactly one\n// tab. Both surface here as ordinary coded refusals.\nimport { protocolRequest } from './sandboxUtils';\nimport { throwOnRefusal } from './protocolRefusal';\nimport { PROTOCOL_OPENREPO } from './generated/protocol';\nimport { SCHEMES } from './protocolSchemes';\n\n/** Where a repository lives. The same three fields a `RecentProject` carries — this is a\n * location the user may already have navigated to under their own authority. */\nexport interface RepositoryCoordinates {\n provider: string;\n namespace: string;\n repository: string;\n}\n\n/** Why the host refused to open a tab.\n *\n * - `invalid` — the coordinates are not three clean path segments.\n * - `no-activation` — no live user gesture on the host document. Call this from a click\n * handler; a timer or a boot path will always get this. A SECOND call inside one gesture\n * also lands here: `window.open` consumes the host's transient activation, so one click\n * buys exactly one tab and the next needs a real second click.\n * - `forbidden` — the app does not hold the baseline `route:read` capability.\n * - `unsupported` — this host has no repository-open surface wired.\n * - `unknown` — the host refused without naming a code. */\nexport type OpenRepositoryErrorCode = 'invalid' | 'no-activation' | 'forbidden' | 'unsupported' | 'unknown';\n\nexport interface OpenRepositoryError extends Error {\n code: OpenRepositoryErrorCode;\n}\n\n/** The host's reply: the envelope resolves INSIDE the promise, so a refusal is a resolved\n * `{ ok: false }` rather than a rejection at the transport layer. */\ntype OpenRepositoryReply = { ok: true; url?: string } | { ok: false; code?: string; message?: string };\n\n/**\n * Ask the host to open a repository in a new browser tab.\n *\n * Resolves once the host has performed the open; it does not wait for — and cannot observe —\n * the opened tab loading. Rejects with a typed {@link OpenRepositoryError} carrying `code`\n * when the host refuses.\n *\n *
|
|
1
|
+
{"version":3,"sources":["../src/openRepository.ts"],"sourcesContent":["// Host-mediated \"open this repository in a new tab\" (R3-476).\n//\n// An app frame cannot open a first-party tab itself. A `window.open` from inside the\n// sandboxed frame inherits the sandbox — the opened tab runs at the same opaque origin and\n// cannot load the host — and `target=\"_top\"` would replace the app's own frame rather than\n// open a tab. So the app asks the host, and the host performs the open from its own context.\n//\n// The app names COORDINATES and nothing else. It cannot pass a URL, a route prefix or a\n// path: the host builds the destination from its own route grammar, so this call can only\n// ever reach one of the platform's own repository routes. That is the point of the shape —\n// an app that could spell the destination could open anything.\n//\n// Two more conditions hold on the host side, and neither is something this call can assert\n// for itself: the open needs the HOST document's live transient user activation (a real\n// click, which the host samples rather than believes), and one gesture opens exactly one\n// tab. Both surface here as ordinary coded refusals.\nimport { protocolRequest } from './sandboxUtils';\nimport { throwOnRefusal } from './protocolRefusal';\nimport { PROTOCOL_OPENREPO } from './generated/protocol';\nimport { SCHEMES } from './protocolSchemes';\n\n/** Where a repository lives. The same three fields a `RecentProject` carries — this is a\n * location the user may already have navigated to under their own authority. */\nexport interface RepositoryCoordinates {\n provider: string;\n namespace: string;\n repository: string;\n}\n\n/** Why the host refused to open a tab.\n *\n * - `invalid` — the coordinates are not three clean path segments.\n * - `no-activation` — no live user gesture on the host document. Call this from a click\n * handler; a timer or a boot path will always get this. A SECOND call inside one gesture\n * also lands here: `window.open` consumes the host's transient activation, so one click\n * buys exactly one tab and the next needs a real second click.\n * - `forbidden` — the app does not hold the baseline `route:read` capability.\n * - `unsupported` — this host has no repository-open surface wired.\n * - `unknown` — the host refused without naming a code.\n *\n * **What you actually catch.** The SDK throws a plain `Error` with `.code` assigned — a\n * `CodedRefusalError` from `protocolRefusal.ts` — never a distinct class. These are the\n * `.code` VALUES the host sends. Nothing enforces the union at runtime — `.code` is\n * whatever string arrived — so treat an unlisted code as possible and `instanceof Error`\n * as the only reliable test.\n *\n * (This note is on the code alias rather than on the interface because the alias is where\n * the codes are documented. Every doclink in this file names the INTERFACE, so a reader\n * following one lands a hop away from this — a wart, not a plan. Stated without a\n * direction on purpose: two earlier revisions of this sentence asserted a positional\n * claim, and both were wrong.) */\nexport type OpenRepositoryErrorCode = 'invalid' | 'no-activation' | 'forbidden' | 'unsupported' | 'unknown';\n\nexport interface OpenRepositoryError extends Error {\n code: OpenRepositoryErrorCode;\n}\n\n/** The host's reply: the envelope resolves INSIDE the promise, so a refusal is a resolved\n * `{ ok: false }` rather than a rejection at the transport layer. */\ntype OpenRepositoryReply = { ok: true; url?: string } | { ok: false; code?: string; message?: string };\n\n/**\n * Ask the host to open a repository in a new browser tab.\n *\n * Resolves once the host has performed the open; it does not wait for — and cannot observe —\n * the opened tab loading. Rejects with a typed {@link OpenRepositoryError} carrying `code`\n * when the host refuses.\n *\n * Call it directly from a user gesture. The host samples its own transient activation when\n * the request arrives, so anything that defers the call past the gesture (an `await` before\n * it, a `setTimeout`, a retry) will be refused `no-activation`. None of the refusals are\n * worth retrying: each names a condition a retry cannot change.\n */\nexport async function openRepository(coordinates: RepositoryCoordinates): Promise<void> {\n const { provider, namespace, repository } = coordinates;\n const res = (await protocolRequest(SCHEMES[PROTOCOL_OPENREPO], 'open', [\n { provider, namespace, repository },\n ])) as OpenRepositoryReply;\n throwOnRefusal(res, 'repository open refused');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,0BAAgC;AAChC,6BAA+B;AAC/B,sBAAkC;AAClC,6BAAwB;AAsDxB,eAAsB,eAAe,aAAmD;AACtF,QAAM,EAAE,UAAU,WAAW,WAAW,IAAI;AAC5C,QAAM,MAAO,UAAM,qCAAgB,+BAAQ,iCAAiB,GAAG,QAAQ;AAAA,IACrE,EAAE,UAAU,WAAW,WAAW;AAAA,EACpC,CAAC;AACD,6CAAe,KAAK,yBAAyB;AAC/C;","names":[]}
|
|
@@ -14,7 +14,19 @@ interface RepositoryCoordinates {
|
|
|
14
14
|
* buys exactly one tab and the next needs a real second click.
|
|
15
15
|
* - `forbidden` — the app does not hold the baseline `route:read` capability.
|
|
16
16
|
* - `unsupported` — this host has no repository-open surface wired.
|
|
17
|
-
* - `unknown` — the host refused without naming a code.
|
|
17
|
+
* - `unknown` — the host refused without naming a code.
|
|
18
|
+
*
|
|
19
|
+
* **What you actually catch.** The SDK throws a plain `Error` with `.code` assigned — a
|
|
20
|
+
* `CodedRefusalError` from `protocolRefusal.ts` — never a distinct class. These are the
|
|
21
|
+
* `.code` VALUES the host sends. Nothing enforces the union at runtime — `.code` is
|
|
22
|
+
* whatever string arrived — so treat an unlisted code as possible and `instanceof Error`
|
|
23
|
+
* as the only reliable test.
|
|
24
|
+
*
|
|
25
|
+
* (This note is on the code alias rather than on the interface because the alias is where
|
|
26
|
+
* the codes are documented. Every doclink in this file names the INTERFACE, so a reader
|
|
27
|
+
* following one lands a hop away from this — a wart, not a plan. Stated without a
|
|
28
|
+
* direction on purpose: two earlier revisions of this sentence asserted a positional
|
|
29
|
+
* claim, and both were wrong.) */
|
|
18
30
|
type OpenRepositoryErrorCode = 'invalid' | 'no-activation' | 'forbidden' | 'unsupported' | 'unknown';
|
|
19
31
|
interface OpenRepositoryError extends Error {
|
|
20
32
|
code: OpenRepositoryErrorCode;
|
|
@@ -26,12 +38,6 @@ interface OpenRepositoryError extends Error {
|
|
|
26
38
|
* the opened tab loading. Rejects with a typed {@link OpenRepositoryError} carrying `code`
|
|
27
39
|
* when the host refuses.
|
|
28
40
|
*
|
|
29
|
-
* **Known gap, 2026-09-25 (R3-778): this does NOT reject today.** The host handler
|
|
30
|
-
* RETURNS its refusals — `invalid` and `no-activation` — and site-main's dispatcher wraps a
|
|
31
|
-
* handler's return value in an `ok: true` envelope, so every one of those refusals
|
|
32
|
-
* reaches this function as a SUCCESS and `openRepository()` resolves. Do not rely on the
|
|
33
|
-
* `code` branch until R3-778 lands; see `protocolRefusal.ts` for the mechanism.
|
|
34
|
-
*
|
|
35
41
|
* Call it directly from a user gesture. The host samples its own transient activation when
|
|
36
42
|
* the request arrives, so anything that defers the call past the gesture (an `await` before
|
|
37
43
|
* it, a `setTimeout`, a retry) will be refused `no-activation`. None of the refusals are
|
package/dist/openRepository.d.ts
CHANGED
|
@@ -14,7 +14,19 @@ interface RepositoryCoordinates {
|
|
|
14
14
|
* buys exactly one tab and the next needs a real second click.
|
|
15
15
|
* - `forbidden` — the app does not hold the baseline `route:read` capability.
|
|
16
16
|
* - `unsupported` — this host has no repository-open surface wired.
|
|
17
|
-
* - `unknown` — the host refused without naming a code.
|
|
17
|
+
* - `unknown` — the host refused without naming a code.
|
|
18
|
+
*
|
|
19
|
+
* **What you actually catch.** The SDK throws a plain `Error` with `.code` assigned — a
|
|
20
|
+
* `CodedRefusalError` from `protocolRefusal.ts` — never a distinct class. These are the
|
|
21
|
+
* `.code` VALUES the host sends. Nothing enforces the union at runtime — `.code` is
|
|
22
|
+
* whatever string arrived — so treat an unlisted code as possible and `instanceof Error`
|
|
23
|
+
* as the only reliable test.
|
|
24
|
+
*
|
|
25
|
+
* (This note is on the code alias rather than on the interface because the alias is where
|
|
26
|
+
* the codes are documented. Every doclink in this file names the INTERFACE, so a reader
|
|
27
|
+
* following one lands a hop away from this — a wart, not a plan. Stated without a
|
|
28
|
+
* direction on purpose: two earlier revisions of this sentence asserted a positional
|
|
29
|
+
* claim, and both were wrong.) */
|
|
18
30
|
type OpenRepositoryErrorCode = 'invalid' | 'no-activation' | 'forbidden' | 'unsupported' | 'unknown';
|
|
19
31
|
interface OpenRepositoryError extends Error {
|
|
20
32
|
code: OpenRepositoryErrorCode;
|
|
@@ -26,12 +38,6 @@ interface OpenRepositoryError extends Error {
|
|
|
26
38
|
* the opened tab loading. Rejects with a typed {@link OpenRepositoryError} carrying `code`
|
|
27
39
|
* when the host refuses.
|
|
28
40
|
*
|
|
29
|
-
* **Known gap, 2026-09-25 (R3-778): this does NOT reject today.** The host handler
|
|
30
|
-
* RETURNS its refusals — `invalid` and `no-activation` — and site-main's dispatcher wraps a
|
|
31
|
-
* handler's return value in an `ok: true` envelope, so every one of those refusals
|
|
32
|
-
* reaches this function as a SUCCESS and `openRepository()` resolves. Do not rely on the
|
|
33
|
-
* `code` branch until R3-778 lands; see `protocolRefusal.ts` for the mechanism.
|
|
34
|
-
*
|
|
35
41
|
* Call it directly from a user gesture. The host samples its own transient activation when
|
|
36
42
|
* the request arrives, so anything that defers the call past the gesture (an `await` before
|
|
37
43
|
* it, a `setTimeout`, a retry) will be refused `no-activation`. None of the refusals are
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/openRepository.ts"],"sourcesContent":["// Host-mediated \"open this repository in a new tab\" (R3-476).\n//\n// An app frame cannot open a first-party tab itself. A `window.open` from inside the\n// sandboxed frame inherits the sandbox — the opened tab runs at the same opaque origin and\n// cannot load the host — and `target=\"_top\"` would replace the app's own frame rather than\n// open a tab. So the app asks the host, and the host performs the open from its own context.\n//\n// The app names COORDINATES and nothing else. It cannot pass a URL, a route prefix or a\n// path: the host builds the destination from its own route grammar, so this call can only\n// ever reach one of the platform's own repository routes. That is the point of the shape —\n// an app that could spell the destination could open anything.\n//\n// Two more conditions hold on the host side, and neither is something this call can assert\n// for itself: the open needs the HOST document's live transient user activation (a real\n// click, which the host samples rather than believes), and one gesture opens exactly one\n// tab. Both surface here as ordinary coded refusals.\nimport { protocolRequest } from './sandboxUtils';\nimport { throwOnRefusal } from './protocolRefusal';\nimport { PROTOCOL_OPENREPO } from './generated/protocol';\nimport { SCHEMES } from './protocolSchemes';\n\n/** Where a repository lives. The same three fields a `RecentProject` carries — this is a\n * location the user may already have navigated to under their own authority. */\nexport interface RepositoryCoordinates {\n provider: string;\n namespace: string;\n repository: string;\n}\n\n/** Why the host refused to open a tab.\n *\n * - `invalid` — the coordinates are not three clean path segments.\n * - `no-activation` — no live user gesture on the host document. Call this from a click\n * handler; a timer or a boot path will always get this. A SECOND call inside one gesture\n * also lands here: `window.open` consumes the host's transient activation, so one click\n * buys exactly one tab and the next needs a real second click.\n * - `forbidden` — the app does not hold the baseline `route:read` capability.\n * - `unsupported` — this host has no repository-open surface wired.\n * - `unknown` — the host refused without naming a code. */\nexport type OpenRepositoryErrorCode = 'invalid' | 'no-activation' | 'forbidden' | 'unsupported' | 'unknown';\n\nexport interface OpenRepositoryError extends Error {\n code: OpenRepositoryErrorCode;\n}\n\n/** The host's reply: the envelope resolves INSIDE the promise, so a refusal is a resolved\n * `{ ok: false }` rather than a rejection at the transport layer. */\ntype OpenRepositoryReply = { ok: true; url?: string } | { ok: false; code?: string; message?: string };\n\n/**\n * Ask the host to open a repository in a new browser tab.\n *\n * Resolves once the host has performed the open; it does not wait for — and cannot observe —\n * the opened tab loading. Rejects with a typed {@link OpenRepositoryError} carrying `code`\n * when the host refuses.\n *\n *
|
|
1
|
+
{"version":3,"sources":["../src/openRepository.ts"],"sourcesContent":["// Host-mediated \"open this repository in a new tab\" (R3-476).\n//\n// An app frame cannot open a first-party tab itself. A `window.open` from inside the\n// sandboxed frame inherits the sandbox — the opened tab runs at the same opaque origin and\n// cannot load the host — and `target=\"_top\"` would replace the app's own frame rather than\n// open a tab. So the app asks the host, and the host performs the open from its own context.\n//\n// The app names COORDINATES and nothing else. It cannot pass a URL, a route prefix or a\n// path: the host builds the destination from its own route grammar, so this call can only\n// ever reach one of the platform's own repository routes. That is the point of the shape —\n// an app that could spell the destination could open anything.\n//\n// Two more conditions hold on the host side, and neither is something this call can assert\n// for itself: the open needs the HOST document's live transient user activation (a real\n// click, which the host samples rather than believes), and one gesture opens exactly one\n// tab. Both surface here as ordinary coded refusals.\nimport { protocolRequest } from './sandboxUtils';\nimport { throwOnRefusal } from './protocolRefusal';\nimport { PROTOCOL_OPENREPO } from './generated/protocol';\nimport { SCHEMES } from './protocolSchemes';\n\n/** Where a repository lives. The same three fields a `RecentProject` carries — this is a\n * location the user may already have navigated to under their own authority. */\nexport interface RepositoryCoordinates {\n provider: string;\n namespace: string;\n repository: string;\n}\n\n/** Why the host refused to open a tab.\n *\n * - `invalid` — the coordinates are not three clean path segments.\n * - `no-activation` — no live user gesture on the host document. Call this from a click\n * handler; a timer or a boot path will always get this. A SECOND call inside one gesture\n * also lands here: `window.open` consumes the host's transient activation, so one click\n * buys exactly one tab and the next needs a real second click.\n * - `forbidden` — the app does not hold the baseline `route:read` capability.\n * - `unsupported` — this host has no repository-open surface wired.\n * - `unknown` — the host refused without naming a code.\n *\n * **What you actually catch.** The SDK throws a plain `Error` with `.code` assigned — a\n * `CodedRefusalError` from `protocolRefusal.ts` — never a distinct class. These are the\n * `.code` VALUES the host sends. Nothing enforces the union at runtime — `.code` is\n * whatever string arrived — so treat an unlisted code as possible and `instanceof Error`\n * as the only reliable test.\n *\n * (This note is on the code alias rather than on the interface because the alias is where\n * the codes are documented. Every doclink in this file names the INTERFACE, so a reader\n * following one lands a hop away from this — a wart, not a plan. Stated without a\n * direction on purpose: two earlier revisions of this sentence asserted a positional\n * claim, and both were wrong.) */\nexport type OpenRepositoryErrorCode = 'invalid' | 'no-activation' | 'forbidden' | 'unsupported' | 'unknown';\n\nexport interface OpenRepositoryError extends Error {\n code: OpenRepositoryErrorCode;\n}\n\n/** The host's reply: the envelope resolves INSIDE the promise, so a refusal is a resolved\n * `{ ok: false }` rather than a rejection at the transport layer. */\ntype OpenRepositoryReply = { ok: true; url?: string } | { ok: false; code?: string; message?: string };\n\n/**\n * Ask the host to open a repository in a new browser tab.\n *\n * Resolves once the host has performed the open; it does not wait for — and cannot observe —\n * the opened tab loading. Rejects with a typed {@link OpenRepositoryError} carrying `code`\n * when the host refuses.\n *\n * Call it directly from a user gesture. The host samples its own transient activation when\n * the request arrives, so anything that defers the call past the gesture (an `await` before\n * it, a `setTimeout`, a retry) will be refused `no-activation`. None of the refusals are\n * worth retrying: each names a condition a retry cannot change.\n */\nexport async function openRepository(coordinates: RepositoryCoordinates): Promise<void> {\n const { provider, namespace, repository } = coordinates;\n const res = (await protocolRequest(SCHEMES[PROTOCOL_OPENREPO], 'open', [\n { provider, namespace, repository },\n ])) as OpenRepositoryReply;\n throwOnRefusal(res, 'repository open refused');\n}\n"],"mappings":";AAgBA,SAAS,uBAAuB;AAChC,SAAS,sBAAsB;AAC/B,SAAS,yBAAyB;AAClC,SAAS,eAAe;AAsDxB,eAAsB,eAAe,aAAmD;AACtF,QAAM,EAAE,UAAU,WAAW,WAAW,IAAI;AAC5C,QAAM,MAAO,MAAM,gBAAgB,QAAQ,iBAAiB,GAAG,QAAQ;AAAA,IACrE,EAAE,UAAU,WAAW,WAAW;AAAA,EACpC,CAAC;AACD,iBAAe,KAAK,yBAAyB;AAC/C;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/protocolRefusal.ts"],"sourcesContent":["// The one place the SDK turns a host reply envelope into a typed, coded rejection (R6).\n//\n// ---------------------------------------------------------------------------\n// THE CENSUS — counted wrong twice, so here is how to re-derive it\n// ---------------------------------------------------------------------------\n//\n// Review round 1 found three copies of this block and this file said \"three\". Round 2\n// found five. Round 3 counted the grep and found the TYPED family is **ten**, across\n// eight files — `mounts.ts` alone has three separate request helpers, each with its own\n// copy, which round 2 read as one helper reached from three call sites.\n//\n// This PR folds the five that its own review rounds actually looked at:\n//\n// openExternal.ts · openRepository.ts · spacesMode.ts · secrets.ts · mounts.ts `request`\n//\n// The other five — `mounts.ts`'s `settingsRequest` and `localStoreRequest`, `editor.ts`,\n// `vcs.ts`, `dnd.ts` and `ipc.ts` (two sites) — were folded here too and then SPLIT BACK\n// OUT, because the gate caps at three rounds and they landed after the last one; nothing\n// had reviewed them. They go in their own PR. If you are reading this and that PR has\n// merged, this paragraph is the thing to delete.\n//\n// Not folded at all, deliberately: the UNTYPED family — `catalog.ts`, `feed.ts`,\n// `netFetch.ts`, `recents.ts`, `tasks.ts`, `theme.ts` (three sites) and `launch.ts`. They\n// are not alike: `launch.ts` folds an extra `!res.data?.launchId` into the same condition,\n// and the rest build their errors differently. Folding them is a behaviour change, not an\n// extraction.\n//\n// **Do not trust any list above; re-derive it.** `grep -n 'ok !== true' src/ | grep -v\n// '\\.test\\.'` is the whole population, and both miscounts came from reading files instead\n// of counting the grep. `check:clones` cannot help: minLines 6, minTokens 50, and no\n// identifier normalisation, so blocks differing only in type names read as distinct.\n//\n// ---------------------------------------------------------------------------\n// WHICH `ok` THIS READS, AND WHY IT MATTERS\n// ---------------------------------------------------------------------------\n//\n// It reads the DISPATCHER ENVELOPE's `ok` — the host's answer to \"did this call\n// succeed\", not a handler's own return value. site-main declares that envelope\n// (`src/editor/requestDispatcher.ts`):\n//\n// type SpaceResult =\n// | { ok: true; data: unknown }\n// | { ok: false; code: string; message: string };\n//\n// and the sandbox resolves it to the SDK unmodified (`src/protocol/iframe.ts`,\n// `resolve(msg.result)`). So a refusal reaches us as `{ok:false, code, message}` — which\n// is exactly what this function unwraps — and the host produces that frame by THROWING\n// `spaceError(code, message)`. The dispatcher's `.catch` turns the throw into the frame.\n//\n// **A handler that RETURNS `{ok:false, code}` instead of throwing does not produce a\n// refusal.** The dispatcher wraps a return value as `result: {ok: true, data: <return>}`,\n// so the envelope says the call succeeded and the refusal is buried one level down, where\n// nothing looks. Two shipped handlers do this today (site-main; audited round 2):\n//\n// `handleOpenRepository` returns `invalid`, `no-activation`\n// `handleOpenLink` returns `invalid`, `no-activation`, **`declined`**\n//\n// `declined` is the user pressing \"no\" on the host's confirmation dialog, and\n// `openExternal()` reports that to the app as a successful open. Driven against the built\n// SDK with each reply shape:\n//\n// thrown -> threw, code=no-activation\n// returned -> RESOLVED (the app believes the tab opened)\n//\n// That is a live defect in site-main's handlers, not here — the envelope is the contract\n// and this reads the contract. Filed as R3-778. It is written down here because this is\n// the file a host author will be pointed at when they ask what shape to reply with, and\n// the answer is: **throw `spaceError`; never return `{ok:false}`.**\n//\n// Deliberately NOT done: sniffing `res.data?.ok === false` as a second refusal shape. On a\n// SUCCESS, `data` is whatever the handler returned — so a handler whose legitimate payload\n// happens to carry `ok: false` would be turned into a refusal. It would bless the broken\n// shape and create a second contract where the spec names one.\n\n/** An error carrying a stable, host-supplied `code` the app can branch on. */\nexport interface CodedRefusalError<C extends string = string> extends Error {\n code: C;\n}\n\n/**\n * Throw a typed, coded error unless the host's reply envelope says the call succeeded.\n *\n * `fallbackMessage` is used when the host refused without a message, and `'unknown'` is\n * the code when it refused without one — a refusal is never reported as a success just\n * because it arrived under-specified.\n *\n * `code` and `message` must be STRINGS to be used. The five call sites this replaced\n * tested for PRESENCE (`'code' in res`, `res?.message ?? …`), so a host sending\n * `code: 42` surfaced `err.code === 42` on a field the type declares `string`, and\n * `message: 42` became the string `\"42\"`. Both now fall back. That is a deliberate\n * tightening, pinned by tests, not an accident of the rewrite.\n *\n * It is an ASSERTION function, not a `void` one, because the inline form it replaced\n * narrowed `res` as a side effect of its `if`/`throw`: `secrets.ts` and `mounts.ts` read\n * `res.data` on the next line and stopped compiling without it. A caller that only needs\n * the throw can ignore the narrowing; one that reads the payload gets it for free. (TS\n * requires the call target to be an explicitly-typed declared name — this is why it is a\n * `function` declaration and not an arrow const.)\n */\nexport function throwOnRefusal(res: unknown, fallbackMessage: string): asserts res is { ok: true; data?: unknown } {\n const r = res as { ok?: unknown; code?: unknown; message?: unknown } | null | undefined;\n if (r && r.ok === true) return;\n const err = new Error(typeof r?.message === 'string' ? r.message : fallbackMessage) as CodedRefusalError;\n err.code = typeof r?.code === 'string' ? r.code : 'unknown';\n throw err;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAmGO,SAAS,eAAe,KAAc,iBAAsE;AACjH,QAAM,IAAI;AACV,MAAI,KAAK,EAAE,OAAO,KAAM;AACxB,QAAM,MAAM,IAAI,MAAM,OAAO,GAAG,YAAY,WAAW,EAAE,UAAU,eAAe;AAClF,MAAI,OAAO,OAAO,GAAG,SAAS,WAAW,EAAE,OAAO;AAClD,QAAM;AACR;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/protocolRefusal.ts"],"sourcesContent":["// The one place the SDK turns a host reply envelope into a typed, coded rejection (R6).\n//\n// ---------------------------------------------------------------------------\n// THE CENSUS — miscounted four times. COUNT THE GREP, and say which unit.\n// ---------------------------------------------------------------------------\n//\n// R3-708's review said three copies, then five, then \"ten across eight files\". This file\n// then said ten while the list beneath it summed to twelve, and a fourth reviewer caught\n// that. The count is:\n//\n// **seventeen CALL SITES across twelve FILES** — `grep -n 'throwOnRefusal(' src/*.ts`,\n// minus the declaration here and minus `*.test.*`:\n//\n// dnd.ts · editor.ts · feed.ts · ipc.ts (×2) · mounts.ts (×3) · netFetch.ts ·\n// openExternal.ts · openRepository.ts · secrets.ts · spacesMode.ts · theme.ts (×3) ·\n// vcs.ts\n//\n// Every miscount came from the same two mistakes: reading files instead of counting the\n// grep, and never saying which unit was being counted. `mounts.ts` has three separate\n// request helpers, each with its own copy; R3-780 touched five FILES and seven SITES.\n// \"Ten\" was neither.\n//\n// Not folded, deliberately, and the reason is NOT that they are all unalike — that was the\n// previous excuse and it was false for three of them:\n//\n// · `catalog.ts`, `recents.ts`, `tasks.ts` are pure copies of the shape `ipc.ts` had\n// until R3-780 folded it — untyped `Error & { code?: string }`, `res?.code ??\n// 'unknown'`. (`recents.ts` casts `code` as required rather than optional; immaterial,\n// the cast erases.) They are foldable and nothing here argues otherwise;\n// · `feed.ts`, `netFetch.ts` and `theme.ts` (×3) read `res && 'code' in res`, which\n// THREW `TypeError: Cannot use 'in' operator` on a string reply — FOLDED in R3-817\n// (0.74.3), a behaviour change reviewed as its own item, exactly as this bullet\n// prescribed;\n// · `launch.ts` folds `!res.data?.launchId` into the same condition and RETURNS\n// `{ ok: false, code }` instead of throwing. Different control flow entirely.\n//\n// So the remaining work is two items, not one, and they are not the same size.\n//\n// `check:clones` cannot help with any of this: minLines 6, minTokens 50, and no identifier\n// normalisation, so blocks differing only in type names read as distinct.\n//\n// ---------------------------------------------------------------------------\n// THIS FILE'S OWN TEST IS LOAD-BEARING FOR ALL SEVENTEEN SITES\n// ---------------------------------------------------------------------------\n//\n// Measured: changing the guard to `r.ok !== false` compiles clean and leaves **ten of the\n// seventeen SITES** green — seven of the twelve files: `dnd`, `editor`, `ipc`, `mounts`,\n// `secrets`, `spacesMode` and `vcs`. Every one of them stubs an explicit `{ ok: false }`,\n// so they pin \"throws on a refusal envelope\" and nothing about a malformed or absent\n// reply. The catchers: `openExternal`, `openRepository`, the five R3-817 sites (whose\n// string-reply tests reject on a non-envelope — the mutation never throws), plus\n// `protocolRefusal.test.ts`. (Re-run 2026-09-30 on the post-fold tree: suites red —\n// feed, netFetch, theme, openExternal, openRepository, protocolRefusal; the seven\n// families green.)\n//\n// (An earlier version of this paragraph said \"nine of the twelve sites' suites\", which\n// mixes sites with suites — the exact mistake the census block above is headed about —\n// and omitted `secrets` and `spacesMode` from the green list.)\n//\n// Each inline form this replaced carried its own `!res ||` guard, visible at the call site.\n// That guarantee now lives here alone. Do not weaken `protocolRefusal.test.ts` on the\n// grounds that \"the consumers cover it\" — they do not, and seventeen near-duplicate malformed\n// -reply tests would be the duplication this extraction exists to remove.\n//\n// ---------------------------------------------------------------------------\n// WHICH `ok` THIS READS, AND WHY IT MATTERS\n// ---------------------------------------------------------------------------\n//\n// It reads the DISPATCHER ENVELOPE's `ok` — the host's answer to \"did this call\n// succeed\", not a handler's own return value. site-main declares that envelope\n// (`src/editor/requestDispatcher.ts`):\n//\n// type SpaceResult =\n// | { ok: true; data: unknown }\n// | { ok: false; code: string; message: string };\n//\n// and the sandbox resolves it to the SDK unmodified (`src/protocol/iframe.ts`,\n// `resolve(msg.result)`). So a refusal reaches us as `{ok:false, code, message}` — which\n// is exactly what this function unwraps — and the host produces that frame by THROWING\n// `spaceError(code, message)`. The dispatcher's `.catch` turns the throw into the frame.\n//\n// **A handler that RETURNS `{ok:false, code}` instead of throwing does not produce a\n// refusal.** The dispatcher wraps a return value as `result: {ok: true, data: <return>}`,\n// so the envelope says the call succeeded and the refusal is buried one level down, where\n// nothing looks. Two shipped handlers did this until R3-778 closed it (site-main; audited sdk#184 round 2, 2026-09-25; fixed 2026-09-28 — both now throw, and a dispatcher assertion reddens on the shape):\n//\n// `handleOpenRepository` returns `invalid`, `no-activation`\n// `handleOpenLink` returns `invalid`, `no-activation`, **`declined`**\n//\n// `declined` is the user pressing \"no\" on the host's confirmation dialog, and\n// `openExternal()` reported that to the app as a successful open, until R3-778 closed it. Driven against the built\n// SDK with each reply shape:\n//\n// thrown -> threw, code=no-activation\n// returned -> RESOLVED (the app believes the tab opened)\n//\n// That was a live defect in site-main's handlers until R3-778 closed it (2026-09-28), not here — the envelope is the contract\n// and this reads the contract. Filed as R3-778. It is written down here because this is\n// the file a host author will be pointed at when they ask what shape to reply with, and\n// the answer is: **throw `spaceError`; never return `{ok:false}`.**\n//\n// Deliberately NOT done: sniffing `res.data?.ok === false` as a second refusal shape. On a\n// SUCCESS, `data` is whatever the handler returned — so a handler whose legitimate payload\n// happens to carry `ok: false` would be turned into a refusal. It would bless the broken\n// shape and create a second contract where the spec names one.\n\n/** An error carrying a stable, host-supplied `code` the app can branch on. */\nexport interface CodedRefusalError<C extends string = string> extends Error {\n code: C;\n}\n\n/**\n * Throw a typed, coded error unless the host's reply envelope says the call succeeded.\n *\n * `fallbackMessage` is used when the host refused without a message, and `'unknown'` is\n * the code when it refused without one — a refusal is never reported as a success just\n * because it arrived under-specified.\n *\n * `code` and `message` must be STRINGS to be used. Seventeen sites call this;\n * **sixteen** had an inline copy it replaced (`spacesMode.ts` was written against the\n * helper in R3-708 and replaced nothing). All sixteen tested for PRESENCE, in **three**\n * shapes:\n *\n * - **seven** cast the value: `(res?.code as SomeError['code']) ?? 'unknown'` —\n * `dnd`, `editor`, `vcs`, `mounts` (×3), `secrets`;\n * - **seven** used the `in` operator — `openExternal`, `openRepository` (with the cast;\n * folded in R3-708) and `feed`, `netFetch`, `theme` ×3 (without it; folded in R3-817,\n * the TypeError fix disclosed above);\n * - **two** used a bare `res?.code ?? 'unknown'` onto `Error & { code?: string }` —\n * `ipc.ts`.\n *\n * Every one of them let a host sending `code: 42` surface `err.code === 42` on a field\n * declared `string`, and turned `message: 42` into the string `\"42\"`. Both now fall back,\n * to `'unknown'` and `fallbackMessage`. A deliberate tightening, pinned by\n * `protocolRefusal.test.ts` — and since this package ships no changelog, this paragraph is\n * where a consumer learns of it.\n *\n * The `ipc.ts` pair changed one more thing: their anonymous type declared `code` OPTIONAL\n * and `CodedRefusalError` requires it. No runtime difference for a missing code — the old\n * code assigned `'unknown'` exactly when the new one does (a non-string `code` falls back\n * too, as the paragraph above discloses) — but a consumer narrowing on `'code' in err`\n * can stop.\n *\n * Folding the two `in`-operator sites also removed a latent `TypeError`: `'code' in res`\n * throws on a string reply.\n *\n * ONE revision of this paragraph got that backwards, and this is the fourth attempt to\n * describe it accurately. The original text was right FOR ITS REFERENT — it named\n * `'code' in res` as a shape replaced, without saying which sites, and at the time the\n * sites it referred to were R3-708's four, two of which used that form. R3-780 then folded\n * five DIFFERENT files and inherited the sentence unchanged, so it became false in place\n * without anyone editing it. That silent shift is the likeliest reason the next revision\n * \"corrected\" it to say NO replaced site used it — which is false the other way:\n * `openExternal` and `openRepository` did.\n *\n * The mechanism is worth more than the correction, because it is repeatable. `'code' in\n * res` is **gone from `main`** since R3-817 (0.74.3) folded the last five — a reviewer who\n * greps `main` finds nothing, and this paragraph is the record of where it lived and why\n * it misread twice before. What a grep of `main` cannot show is that the\n * form was ALSO at two sites R3-708 folded. The tree that answers the question is the one\n * before the fold, `d4b07cc1^`. Read that before rewriting this paragraph again.\n *\n * It is an ASSERTION function, not a `void` one, because the inline form it replaced\n * narrowed `res` as a side effect of its `if`/`throw`: `secrets.ts` and `mounts.ts` read\n * `res.data` on the next line and stopped compiling without it. A caller that only needs\n * the throw can ignore the narrowing; one that reads the payload gets it for free. (TS\n * requires the call target to be an explicitly-typed declared name — this is why it is a\n * `function` declaration and not an arrow const.)\n *\n * R3-817 (0.74.3): the five remaining inline copies (`feed.ts`, `netFetch.ts`,\n * `theme.ts` ×3) folded onto this — removing a latent defect with them: their\n * `res && 'code' in res` guard threw `TypeError: Cannot use 'in' operator` on a\n * bare-STRING reply (a proxy error page, a relay), escaping past every `err.code`\n * branch an app wrote. This function reads `typeof r?.code === 'string'` and\n * cannot throw on any input; the TypeError path no longer exists.\n */\nexport function throwOnRefusal(res: unknown, fallbackMessage: string): asserts res is { ok: true; data?: unknown } {\n const r = res as { ok?: unknown; code?: unknown; message?: unknown } | null | undefined;\n if (r && r.ok === true) return;\n const err = new Error(typeof r?.message === 'string' ? r.message : fallbackMessage) as CodedRefusalError;\n err.code = typeof r?.code === 'string' ? r.code : 'unknown';\n throw err;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgLO,SAAS,eAAe,KAAc,iBAAsE;AACjH,QAAM,IAAI;AACV,MAAI,KAAK,EAAE,OAAO,KAAM;AACxB,QAAM,MAAM,IAAI,MAAM,OAAO,GAAG,YAAY,WAAW,EAAE,UAAU,eAAe;AAClF,MAAI,OAAO,OAAO,GAAG,SAAS,WAAW,EAAE,OAAO;AAClD,QAAM;AACR;","names":[]}
|
|
@@ -9,11 +9,49 @@ interface CodedRefusalError<C extends string = string> extends Error {
|
|
|
9
9
|
* the code when it refused without one — a refusal is never reported as a success just
|
|
10
10
|
* because it arrived under-specified.
|
|
11
11
|
*
|
|
12
|
-
* `code` and `message` must be STRINGS to be used.
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
12
|
+
* `code` and `message` must be STRINGS to be used. Seventeen sites call this;
|
|
13
|
+
* **sixteen** had an inline copy it replaced (`spacesMode.ts` was written against the
|
|
14
|
+
* helper in R3-708 and replaced nothing). All sixteen tested for PRESENCE, in **three**
|
|
15
|
+
* shapes:
|
|
16
|
+
*
|
|
17
|
+
* - **seven** cast the value: `(res?.code as SomeError['code']) ?? 'unknown'` —
|
|
18
|
+
* `dnd`, `editor`, `vcs`, `mounts` (×3), `secrets`;
|
|
19
|
+
* - **seven** used the `in` operator — `openExternal`, `openRepository` (with the cast;
|
|
20
|
+
* folded in R3-708) and `feed`, `netFetch`, `theme` ×3 (without it; folded in R3-817,
|
|
21
|
+
* the TypeError fix disclosed above);
|
|
22
|
+
* - **two** used a bare `res?.code ?? 'unknown'` onto `Error & { code?: string }` —
|
|
23
|
+
* `ipc.ts`.
|
|
24
|
+
*
|
|
25
|
+
* Every one of them let a host sending `code: 42` surface `err.code === 42` on a field
|
|
26
|
+
* declared `string`, and turned `message: 42` into the string `"42"`. Both now fall back,
|
|
27
|
+
* to `'unknown'` and `fallbackMessage`. A deliberate tightening, pinned by
|
|
28
|
+
* `protocolRefusal.test.ts` — and since this package ships no changelog, this paragraph is
|
|
29
|
+
* where a consumer learns of it.
|
|
30
|
+
*
|
|
31
|
+
* The `ipc.ts` pair changed one more thing: their anonymous type declared `code` OPTIONAL
|
|
32
|
+
* and `CodedRefusalError` requires it. No runtime difference for a missing code — the old
|
|
33
|
+
* code assigned `'unknown'` exactly when the new one does (a non-string `code` falls back
|
|
34
|
+
* too, as the paragraph above discloses) — but a consumer narrowing on `'code' in err`
|
|
35
|
+
* can stop.
|
|
36
|
+
*
|
|
37
|
+
* Folding the two `in`-operator sites also removed a latent `TypeError`: `'code' in res`
|
|
38
|
+
* throws on a string reply.
|
|
39
|
+
*
|
|
40
|
+
* ONE revision of this paragraph got that backwards, and this is the fourth attempt to
|
|
41
|
+
* describe it accurately. The original text was right FOR ITS REFERENT — it named
|
|
42
|
+
* `'code' in res` as a shape replaced, without saying which sites, and at the time the
|
|
43
|
+
* sites it referred to were R3-708's four, two of which used that form. R3-780 then folded
|
|
44
|
+
* five DIFFERENT files and inherited the sentence unchanged, so it became false in place
|
|
45
|
+
* without anyone editing it. That silent shift is the likeliest reason the next revision
|
|
46
|
+
* "corrected" it to say NO replaced site used it — which is false the other way:
|
|
47
|
+
* `openExternal` and `openRepository` did.
|
|
48
|
+
*
|
|
49
|
+
* The mechanism is worth more than the correction, because it is repeatable. `'code' in
|
|
50
|
+
* res` is **gone from `main`** since R3-817 (0.74.3) folded the last five — a reviewer who
|
|
51
|
+
* greps `main` finds nothing, and this paragraph is the record of where it lived and why
|
|
52
|
+
* it misread twice before. What a grep of `main` cannot show is that the
|
|
53
|
+
* form was ALSO at two sites R3-708 folded. The tree that answers the question is the one
|
|
54
|
+
* before the fold, `d4b07cc1^`. Read that before rewriting this paragraph again.
|
|
17
55
|
*
|
|
18
56
|
* It is an ASSERTION function, not a `void` one, because the inline form it replaced
|
|
19
57
|
* narrowed `res` as a side effect of its `if`/`throw`: `secrets.ts` and `mounts.ts` read
|
|
@@ -21,6 +59,13 @@ interface CodedRefusalError<C extends string = string> extends Error {
|
|
|
21
59
|
* the throw can ignore the narrowing; one that reads the payload gets it for free. (TS
|
|
22
60
|
* requires the call target to be an explicitly-typed declared name — this is why it is a
|
|
23
61
|
* `function` declaration and not an arrow const.)
|
|
62
|
+
*
|
|
63
|
+
* R3-817 (0.74.3): the five remaining inline copies (`feed.ts`, `netFetch.ts`,
|
|
64
|
+
* `theme.ts` ×3) folded onto this — removing a latent defect with them: their
|
|
65
|
+
* `res && 'code' in res` guard threw `TypeError: Cannot use 'in' operator` on a
|
|
66
|
+
* bare-STRING reply (a proxy error page, a relay), escaping past every `err.code`
|
|
67
|
+
* branch an app wrote. This function reads `typeof r?.code === 'string'` and
|
|
68
|
+
* cannot throw on any input; the TypeError path no longer exists.
|
|
24
69
|
*/
|
|
25
70
|
declare function throwOnRefusal(res: unknown, fallbackMessage: string): asserts res is {
|
|
26
71
|
ok: true;
|
|
@@ -9,11 +9,49 @@ interface CodedRefusalError<C extends string = string> extends Error {
|
|
|
9
9
|
* the code when it refused without one — a refusal is never reported as a success just
|
|
10
10
|
* because it arrived under-specified.
|
|
11
11
|
*
|
|
12
|
-
* `code` and `message` must be STRINGS to be used.
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
12
|
+
* `code` and `message` must be STRINGS to be used. Seventeen sites call this;
|
|
13
|
+
* **sixteen** had an inline copy it replaced (`spacesMode.ts` was written against the
|
|
14
|
+
* helper in R3-708 and replaced nothing). All sixteen tested for PRESENCE, in **three**
|
|
15
|
+
* shapes:
|
|
16
|
+
*
|
|
17
|
+
* - **seven** cast the value: `(res?.code as SomeError['code']) ?? 'unknown'` —
|
|
18
|
+
* `dnd`, `editor`, `vcs`, `mounts` (×3), `secrets`;
|
|
19
|
+
* - **seven** used the `in` operator — `openExternal`, `openRepository` (with the cast;
|
|
20
|
+
* folded in R3-708) and `feed`, `netFetch`, `theme` ×3 (without it; folded in R3-817,
|
|
21
|
+
* the TypeError fix disclosed above);
|
|
22
|
+
* - **two** used a bare `res?.code ?? 'unknown'` onto `Error & { code?: string }` —
|
|
23
|
+
* `ipc.ts`.
|
|
24
|
+
*
|
|
25
|
+
* Every one of them let a host sending `code: 42` surface `err.code === 42` on a field
|
|
26
|
+
* declared `string`, and turned `message: 42` into the string `"42"`. Both now fall back,
|
|
27
|
+
* to `'unknown'` and `fallbackMessage`. A deliberate tightening, pinned by
|
|
28
|
+
* `protocolRefusal.test.ts` — and since this package ships no changelog, this paragraph is
|
|
29
|
+
* where a consumer learns of it.
|
|
30
|
+
*
|
|
31
|
+
* The `ipc.ts` pair changed one more thing: their anonymous type declared `code` OPTIONAL
|
|
32
|
+
* and `CodedRefusalError` requires it. No runtime difference for a missing code — the old
|
|
33
|
+
* code assigned `'unknown'` exactly when the new one does (a non-string `code` falls back
|
|
34
|
+
* too, as the paragraph above discloses) — but a consumer narrowing on `'code' in err`
|
|
35
|
+
* can stop.
|
|
36
|
+
*
|
|
37
|
+
* Folding the two `in`-operator sites also removed a latent `TypeError`: `'code' in res`
|
|
38
|
+
* throws on a string reply.
|
|
39
|
+
*
|
|
40
|
+
* ONE revision of this paragraph got that backwards, and this is the fourth attempt to
|
|
41
|
+
* describe it accurately. The original text was right FOR ITS REFERENT — it named
|
|
42
|
+
* `'code' in res` as a shape replaced, without saying which sites, and at the time the
|
|
43
|
+
* sites it referred to were R3-708's four, two of which used that form. R3-780 then folded
|
|
44
|
+
* five DIFFERENT files and inherited the sentence unchanged, so it became false in place
|
|
45
|
+
* without anyone editing it. That silent shift is the likeliest reason the next revision
|
|
46
|
+
* "corrected" it to say NO replaced site used it — which is false the other way:
|
|
47
|
+
* `openExternal` and `openRepository` did.
|
|
48
|
+
*
|
|
49
|
+
* The mechanism is worth more than the correction, because it is repeatable. `'code' in
|
|
50
|
+
* res` is **gone from `main`** since R3-817 (0.74.3) folded the last five — a reviewer who
|
|
51
|
+
* greps `main` finds nothing, and this paragraph is the record of where it lived and why
|
|
52
|
+
* it misread twice before. What a grep of `main` cannot show is that the
|
|
53
|
+
* form was ALSO at two sites R3-708 folded. The tree that answers the question is the one
|
|
54
|
+
* before the fold, `d4b07cc1^`. Read that before rewriting this paragraph again.
|
|
17
55
|
*
|
|
18
56
|
* It is an ASSERTION function, not a `void` one, because the inline form it replaced
|
|
19
57
|
* narrowed `res` as a side effect of its `if`/`throw`: `secrets.ts` and `mounts.ts` read
|
|
@@ -21,6 +59,13 @@ interface CodedRefusalError<C extends string = string> extends Error {
|
|
|
21
59
|
* the throw can ignore the narrowing; one that reads the payload gets it for free. (TS
|
|
22
60
|
* requires the call target to be an explicitly-typed declared name — this is why it is a
|
|
23
61
|
* `function` declaration and not an arrow const.)
|
|
62
|
+
*
|
|
63
|
+
* R3-817 (0.74.3): the five remaining inline copies (`feed.ts`, `netFetch.ts`,
|
|
64
|
+
* `theme.ts` ×3) folded onto this — removing a latent defect with them: their
|
|
65
|
+
* `res && 'code' in res` guard threw `TypeError: Cannot use 'in' operator` on a
|
|
66
|
+
* bare-STRING reply (a proxy error page, a relay), escaping past every `err.code`
|
|
67
|
+
* branch an app wrote. This function reads `typeof r?.code === 'string'` and
|
|
68
|
+
* cannot throw on any input; the TypeError path no longer exists.
|
|
24
69
|
*/
|
|
25
70
|
declare function throwOnRefusal(res: unknown, fallbackMessage: string): asserts res is {
|
|
26
71
|
ok: true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/protocolRefusal.ts"],"sourcesContent":["// The one place the SDK turns a host reply envelope into a typed, coded rejection (R6).\n//\n// ---------------------------------------------------------------------------\n// THE CENSUS — counted wrong twice, so here is how to re-derive it\n// ---------------------------------------------------------------------------\n//\n// Review round 1 found three copies of this block and this file said \"three\". Round 2\n// found five. Round 3 counted the grep and found the TYPED family is **ten**, across\n// eight files — `mounts.ts` alone has three separate request helpers, each with its own\n// copy, which round 2 read as one helper reached from three call sites.\n//\n// This PR folds the five that its own review rounds actually looked at:\n//\n// openExternal.ts · openRepository.ts · spacesMode.ts · secrets.ts · mounts.ts `request`\n//\n// The other five — `mounts.ts`'s `settingsRequest` and `localStoreRequest`, `editor.ts`,\n// `vcs.ts`, `dnd.ts` and `ipc.ts` (two sites) — were folded here too and then SPLIT BACK\n// OUT, because the gate caps at three rounds and they landed after the last one; nothing\n// had reviewed them. They go in their own PR. If you are reading this and that PR has\n// merged, this paragraph is the thing to delete.\n//\n// Not folded at all, deliberately: the UNTYPED family — `catalog.ts`, `feed.ts`,\n// `netFetch.ts`, `recents.ts`, `tasks.ts`, `theme.ts` (three sites) and `launch.ts`. They\n// are not alike: `launch.ts` folds an extra `!res.data?.launchId` into the same condition,\n// and the rest build their errors differently. Folding them is a behaviour change, not an\n// extraction.\n//\n// **Do not trust any list above; re-derive it.** `grep -n 'ok !== true' src/ | grep -v\n// '\\.test\\.'` is the whole population, and both miscounts came from reading files instead\n// of counting the grep. `check:clones` cannot help: minLines 6, minTokens 50, and no\n// identifier normalisation, so blocks differing only in type names read as distinct.\n//\n// ---------------------------------------------------------------------------\n// WHICH `ok` THIS READS, AND WHY IT MATTERS\n// ---------------------------------------------------------------------------\n//\n// It reads the DISPATCHER ENVELOPE's `ok` — the host's answer to \"did this call\n// succeed\", not a handler's own return value. site-main declares that envelope\n// (`src/editor/requestDispatcher.ts`):\n//\n// type SpaceResult =\n// | { ok: true; data: unknown }\n// | { ok: false; code: string; message: string };\n//\n// and the sandbox resolves it to the SDK unmodified (`src/protocol/iframe.ts`,\n// `resolve(msg.result)`). So a refusal reaches us as `{ok:false, code, message}` — which\n// is exactly what this function unwraps — and the host produces that frame by THROWING\n// `spaceError(code, message)`. The dispatcher's `.catch` turns the throw into the frame.\n//\n// **A handler that RETURNS `{ok:false, code}` instead of throwing does not produce a\n// refusal.** The dispatcher wraps a return value as `result: {ok: true, data: <return>}`,\n// so the envelope says the call succeeded and the refusal is buried one level down, where\n// nothing looks. Two shipped handlers do this today (site-main; audited round 2):\n//\n// `handleOpenRepository` returns `invalid`, `no-activation`\n// `handleOpenLink` returns `invalid`, `no-activation`, **`declined`**\n//\n// `declined` is the user pressing \"no\" on the host's confirmation dialog, and\n// `openExternal()` reports that to the app as a successful open. Driven against the built\n// SDK with each reply shape:\n//\n// thrown -> threw, code=no-activation\n// returned -> RESOLVED (the app believes the tab opened)\n//\n// That is a live defect in site-main's handlers, not here — the envelope is the contract\n// and this reads the contract. Filed as R3-778. It is written down here because this is\n// the file a host author will be pointed at when they ask what shape to reply with, and\n// the answer is: **throw `spaceError`; never return `{ok:false}`.**\n//\n// Deliberately NOT done: sniffing `res.data?.ok === false` as a second refusal shape. On a\n// SUCCESS, `data` is whatever the handler returned — so a handler whose legitimate payload\n// happens to carry `ok: false` would be turned into a refusal. It would bless the broken\n// shape and create a second contract where the spec names one.\n\n/** An error carrying a stable, host-supplied `code` the app can branch on. */\nexport interface CodedRefusalError<C extends string = string> extends Error {\n code: C;\n}\n\n/**\n * Throw a typed, coded error unless the host's reply envelope says the call succeeded.\n *\n * `fallbackMessage` is used when the host refused without a message, and `'unknown'` is\n * the code when it refused without one — a refusal is never reported as a success just\n * because it arrived under-specified.\n *\n * `code` and `message` must be STRINGS to be used. The five call sites this replaced\n * tested for PRESENCE (`'code' in res`, `res?.message ?? …`), so a host sending\n * `code: 42` surfaced `err.code === 42` on a field the type declares `string`, and\n * `message: 42` became the string `\"42\"`. Both now fall back. That is a deliberate\n * tightening, pinned by tests, not an accident of the rewrite.\n *\n * It is an ASSERTION function, not a `void` one, because the inline form it replaced\n * narrowed `res` as a side effect of its `if`/`throw`: `secrets.ts` and `mounts.ts` read\n * `res.data` on the next line and stopped compiling without it. A caller that only needs\n * the throw can ignore the narrowing; one that reads the payload gets it for free. (TS\n * requires the call target to be an explicitly-typed declared name — this is why it is a\n * `function` declaration and not an arrow const.)\n */\nexport function throwOnRefusal(res: unknown, fallbackMessage: string): asserts res is { ok: true; data?: unknown } {\n const r = res as { ok?: unknown; code?: unknown; message?: unknown } | null | undefined;\n if (r && r.ok === true) return;\n const err = new Error(typeof r?.message === 'string' ? r.message : fallbackMessage) as CodedRefusalError;\n err.code = typeof r?.code === 'string' ? r.code : 'unknown';\n throw err;\n}\n"],"mappings":";AAmGO,SAAS,eAAe,KAAc,iBAAsE;AACjH,QAAM,IAAI;AACV,MAAI,KAAK,EAAE,OAAO,KAAM;AACxB,QAAM,MAAM,IAAI,MAAM,OAAO,GAAG,YAAY,WAAW,EAAE,UAAU,eAAe;AAClF,MAAI,OAAO,OAAO,GAAG,SAAS,WAAW,EAAE,OAAO;AAClD,QAAM;AACR;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/protocolRefusal.ts"],"sourcesContent":["// The one place the SDK turns a host reply envelope into a typed, coded rejection (R6).\n//\n// ---------------------------------------------------------------------------\n// THE CENSUS — miscounted four times. COUNT THE GREP, and say which unit.\n// ---------------------------------------------------------------------------\n//\n// R3-708's review said three copies, then five, then \"ten across eight files\". This file\n// then said ten while the list beneath it summed to twelve, and a fourth reviewer caught\n// that. The count is:\n//\n// **seventeen CALL SITES across twelve FILES** — `grep -n 'throwOnRefusal(' src/*.ts`,\n// minus the declaration here and minus `*.test.*`:\n//\n// dnd.ts · editor.ts · feed.ts · ipc.ts (×2) · mounts.ts (×3) · netFetch.ts ·\n// openExternal.ts · openRepository.ts · secrets.ts · spacesMode.ts · theme.ts (×3) ·\n// vcs.ts\n//\n// Every miscount came from the same two mistakes: reading files instead of counting the\n// grep, and never saying which unit was being counted. `mounts.ts` has three separate\n// request helpers, each with its own copy; R3-780 touched five FILES and seven SITES.\n// \"Ten\" was neither.\n//\n// Not folded, deliberately, and the reason is NOT that they are all unalike — that was the\n// previous excuse and it was false for three of them:\n//\n// · `catalog.ts`, `recents.ts`, `tasks.ts` are pure copies of the shape `ipc.ts` had\n// until R3-780 folded it — untyped `Error & { code?: string }`, `res?.code ??\n// 'unknown'`. (`recents.ts` casts `code` as required rather than optional; immaterial,\n// the cast erases.) They are foldable and nothing here argues otherwise;\n// · `feed.ts`, `netFetch.ts` and `theme.ts` (×3) read `res && 'code' in res`, which\n// THREW `TypeError: Cannot use 'in' operator` on a string reply — FOLDED in R3-817\n// (0.74.3), a behaviour change reviewed as its own item, exactly as this bullet\n// prescribed;\n// · `launch.ts` folds `!res.data?.launchId` into the same condition and RETURNS\n// `{ ok: false, code }` instead of throwing. Different control flow entirely.\n//\n// So the remaining work is two items, not one, and they are not the same size.\n//\n// `check:clones` cannot help with any of this: minLines 6, minTokens 50, and no identifier\n// normalisation, so blocks differing only in type names read as distinct.\n//\n// ---------------------------------------------------------------------------\n// THIS FILE'S OWN TEST IS LOAD-BEARING FOR ALL SEVENTEEN SITES\n// ---------------------------------------------------------------------------\n//\n// Measured: changing the guard to `r.ok !== false` compiles clean and leaves **ten of the\n// seventeen SITES** green — seven of the twelve files: `dnd`, `editor`, `ipc`, `mounts`,\n// `secrets`, `spacesMode` and `vcs`. Every one of them stubs an explicit `{ ok: false }`,\n// so they pin \"throws on a refusal envelope\" and nothing about a malformed or absent\n// reply. The catchers: `openExternal`, `openRepository`, the five R3-817 sites (whose\n// string-reply tests reject on a non-envelope — the mutation never throws), plus\n// `protocolRefusal.test.ts`. (Re-run 2026-09-30 on the post-fold tree: suites red —\n// feed, netFetch, theme, openExternal, openRepository, protocolRefusal; the seven\n// families green.)\n//\n// (An earlier version of this paragraph said \"nine of the twelve sites' suites\", which\n// mixes sites with suites — the exact mistake the census block above is headed about —\n// and omitted `secrets` and `spacesMode` from the green list.)\n//\n// Each inline form this replaced carried its own `!res ||` guard, visible at the call site.\n// That guarantee now lives here alone. Do not weaken `protocolRefusal.test.ts` on the\n// grounds that \"the consumers cover it\" — they do not, and seventeen near-duplicate malformed\n// -reply tests would be the duplication this extraction exists to remove.\n//\n// ---------------------------------------------------------------------------\n// WHICH `ok` THIS READS, AND WHY IT MATTERS\n// ---------------------------------------------------------------------------\n//\n// It reads the DISPATCHER ENVELOPE's `ok` — the host's answer to \"did this call\n// succeed\", not a handler's own return value. site-main declares that envelope\n// (`src/editor/requestDispatcher.ts`):\n//\n// type SpaceResult =\n// | { ok: true; data: unknown }\n// | { ok: false; code: string; message: string };\n//\n// and the sandbox resolves it to the SDK unmodified (`src/protocol/iframe.ts`,\n// `resolve(msg.result)`). So a refusal reaches us as `{ok:false, code, message}` — which\n// is exactly what this function unwraps — and the host produces that frame by THROWING\n// `spaceError(code, message)`. The dispatcher's `.catch` turns the throw into the frame.\n//\n// **A handler that RETURNS `{ok:false, code}` instead of throwing does not produce a\n// refusal.** The dispatcher wraps a return value as `result: {ok: true, data: <return>}`,\n// so the envelope says the call succeeded and the refusal is buried one level down, where\n// nothing looks. Two shipped handlers did this until R3-778 closed it (site-main; audited sdk#184 round 2, 2026-09-25; fixed 2026-09-28 — both now throw, and a dispatcher assertion reddens on the shape):\n//\n// `handleOpenRepository` returns `invalid`, `no-activation`\n// `handleOpenLink` returns `invalid`, `no-activation`, **`declined`**\n//\n// `declined` is the user pressing \"no\" on the host's confirmation dialog, and\n// `openExternal()` reported that to the app as a successful open, until R3-778 closed it. Driven against the built\n// SDK with each reply shape:\n//\n// thrown -> threw, code=no-activation\n// returned -> RESOLVED (the app believes the tab opened)\n//\n// That was a live defect in site-main's handlers until R3-778 closed it (2026-09-28), not here — the envelope is the contract\n// and this reads the contract. Filed as R3-778. It is written down here because this is\n// the file a host author will be pointed at when they ask what shape to reply with, and\n// the answer is: **throw `spaceError`; never return `{ok:false}`.**\n//\n// Deliberately NOT done: sniffing `res.data?.ok === false` as a second refusal shape. On a\n// SUCCESS, `data` is whatever the handler returned — so a handler whose legitimate payload\n// happens to carry `ok: false` would be turned into a refusal. It would bless the broken\n// shape and create a second contract where the spec names one.\n\n/** An error carrying a stable, host-supplied `code` the app can branch on. */\nexport interface CodedRefusalError<C extends string = string> extends Error {\n code: C;\n}\n\n/**\n * Throw a typed, coded error unless the host's reply envelope says the call succeeded.\n *\n * `fallbackMessage` is used when the host refused without a message, and `'unknown'` is\n * the code when it refused without one — a refusal is never reported as a success just\n * because it arrived under-specified.\n *\n * `code` and `message` must be STRINGS to be used. Seventeen sites call this;\n * **sixteen** had an inline copy it replaced (`spacesMode.ts` was written against the\n * helper in R3-708 and replaced nothing). All sixteen tested for PRESENCE, in **three**\n * shapes:\n *\n * - **seven** cast the value: `(res?.code as SomeError['code']) ?? 'unknown'` —\n * `dnd`, `editor`, `vcs`, `mounts` (×3), `secrets`;\n * - **seven** used the `in` operator — `openExternal`, `openRepository` (with the cast;\n * folded in R3-708) and `feed`, `netFetch`, `theme` ×3 (without it; folded in R3-817,\n * the TypeError fix disclosed above);\n * - **two** used a bare `res?.code ?? 'unknown'` onto `Error & { code?: string }` —\n * `ipc.ts`.\n *\n * Every one of them let a host sending `code: 42` surface `err.code === 42` on a field\n * declared `string`, and turned `message: 42` into the string `\"42\"`. Both now fall back,\n * to `'unknown'` and `fallbackMessage`. A deliberate tightening, pinned by\n * `protocolRefusal.test.ts` — and since this package ships no changelog, this paragraph is\n * where a consumer learns of it.\n *\n * The `ipc.ts` pair changed one more thing: their anonymous type declared `code` OPTIONAL\n * and `CodedRefusalError` requires it. No runtime difference for a missing code — the old\n * code assigned `'unknown'` exactly when the new one does (a non-string `code` falls back\n * too, as the paragraph above discloses) — but a consumer narrowing on `'code' in err`\n * can stop.\n *\n * Folding the two `in`-operator sites also removed a latent `TypeError`: `'code' in res`\n * throws on a string reply.\n *\n * ONE revision of this paragraph got that backwards, and this is the fourth attempt to\n * describe it accurately. The original text was right FOR ITS REFERENT — it named\n * `'code' in res` as a shape replaced, without saying which sites, and at the time the\n * sites it referred to were R3-708's four, two of which used that form. R3-780 then folded\n * five DIFFERENT files and inherited the sentence unchanged, so it became false in place\n * without anyone editing it. That silent shift is the likeliest reason the next revision\n * \"corrected\" it to say NO replaced site used it — which is false the other way:\n * `openExternal` and `openRepository` did.\n *\n * The mechanism is worth more than the correction, because it is repeatable. `'code' in\n * res` is **gone from `main`** since R3-817 (0.74.3) folded the last five — a reviewer who\n * greps `main` finds nothing, and this paragraph is the record of where it lived and why\n * it misread twice before. What a grep of `main` cannot show is that the\n * form was ALSO at two sites R3-708 folded. The tree that answers the question is the one\n * before the fold, `d4b07cc1^`. Read that before rewriting this paragraph again.\n *\n * It is an ASSERTION function, not a `void` one, because the inline form it replaced\n * narrowed `res` as a side effect of its `if`/`throw`: `secrets.ts` and `mounts.ts` read\n * `res.data` on the next line and stopped compiling without it. A caller that only needs\n * the throw can ignore the narrowing; one that reads the payload gets it for free. (TS\n * requires the call target to be an explicitly-typed declared name — this is why it is a\n * `function` declaration and not an arrow const.)\n *\n * R3-817 (0.74.3): the five remaining inline copies (`feed.ts`, `netFetch.ts`,\n * `theme.ts` ×3) folded onto this — removing a latent defect with them: their\n * `res && 'code' in res` guard threw `TypeError: Cannot use 'in' operator` on a\n * bare-STRING reply (a proxy error page, a relay), escaping past every `err.code`\n * branch an app wrote. This function reads `typeof r?.code === 'string'` and\n * cannot throw on any input; the TypeError path no longer exists.\n */\nexport function throwOnRefusal(res: unknown, fallbackMessage: string): asserts res is { ok: true; data?: unknown } {\n const r = res as { ok?: unknown; code?: unknown; message?: unknown } | null | undefined;\n if (r && r.ok === true) return;\n const err = new Error(typeof r?.message === 'string' ? r.message : fallbackMessage) as CodedRefusalError;\n err.code = typeof r?.code === 'string' ? r.code : 'unknown';\n throw err;\n}\n"],"mappings":";AAgLO,SAAS,eAAe,KAAc,iBAAsE;AACjH,QAAM,IAAI;AACV,MAAI,KAAK,EAAE,OAAO,KAAM;AACxB,QAAM,MAAM,IAAI,MAAM,OAAO,GAAG,YAAY,WAAW,EAAE,UAAU,eAAe;AAClF,MAAI,OAAO,OAAO,GAAG,SAAS,WAAW,EAAE,OAAO;AAClD,QAAM;AACR;","names":[]}
|