@immediately-run/sdk 0.80.0 → 0.82.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/editor.cjs +7 -1
- package/dist/editor.cjs.map +1 -1
- package/dist/editor.d.cts +8 -1
- package/dist/editor.d.ts +8 -1
- package/dist/editor.js +7 -1
- package/dist/editor.js.map +1 -1
- package/dist/netFetch.cjs +7 -1
- package/dist/netFetch.cjs.map +1 -1
- package/dist/netFetch.d.cts +10 -1
- package/dist/netFetch.d.ts +10 -1
- package/dist/netFetch.js +7 -1
- package/dist/netFetch.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 +5 -4
package/dist/editor.cjs
CHANGED
|
@@ -35,7 +35,13 @@ var import_protocolSchemes = require("./protocolSchemes");
|
|
|
35
35
|
var import_protocol = require("./generated/protocol");
|
|
36
36
|
const editorRequest = async (method, arg) => {
|
|
37
37
|
const res = await (0, import_sandboxUtils.protocolRequest)(import_protocolSchemes.SCHEMES[import_protocol.PROTOCOL_EDITOR], method, [arg]);
|
|
38
|
-
|
|
38
|
+
try {
|
|
39
|
+
(0, import_protocolRefusal.throwOnRefusal)(res, `editor ${method} failed`);
|
|
40
|
+
} catch (e) {
|
|
41
|
+
const limit = res && res.ok === false ? res.limitBytes : void 0;
|
|
42
|
+
if (typeof limit === "number") e.limitBytes = limit;
|
|
43
|
+
throw e;
|
|
44
|
+
}
|
|
39
45
|
};
|
|
40
46
|
const openInEditor = (path, selection, opts) => editorRequest("open", {
|
|
41
47
|
path,
|
package/dist/editor.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/editor.ts"],"sourcesContent":["import { protocolRequest } from './sandboxUtils';\nimport { throwOnRefusal, type CodedRefusalError } from './protocolRefusal';\nimport { SCHEMES } from './protocolSchemes';\nimport { PROTOCOL_EDITOR } from './generated/protocol';\n\n/**\n * Open a working-tree file in the immediately.run host editor (UI_AS_APPS_SPEC §4 —\n * the file explorer's click-to-open). This is an INTENT: the app asks, the HOST\n * validates the path and drives the CodeMirror editor — the editor itself stays\n * host-owned (§2 recursion boundary), so an app can never own or script it beyond\n * \"please show this file\".\n *\n * Requires the elevated `editor:open` capability — a previewed app does not hold it\n * (it must not move the host's focus), so only a system app whose binding grants it\n * (the file explorer) can call this; anyone else is refused at the gate.\n */\n\n/** An error from {@link openInEditor}, carrying a machine-readable `.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. This interface\n * documents the `.code` VALUES the host sends. Nothing enforces the union at runtime —\n * `.code` is whatever string arrived — so treat an unlisted code as possible and\n * `instanceof Error` as the only reliable test.\n */\nexport interface EditorOpenError extends Error {\n code:\n | 'forbidden' // the frame lacks `editor:open` (or `editor:reveal`, for a `reveal`)\n | 'not-found' // no such file in the live working tree (the host never creates)\n | 'invalid-params' // the path was empty / contained `..` / looked like a URI\n | 'no-target' // there is no host editor session to open files in\n | 'unknown';\n}\n\ntype EditorResult = { ok: true; data: unknown } | { ok: false; code: string; message: string };\n\nconst editorRequest = async (method: string, arg: Record<string, unknown>): Promise<void> => {\n const res = (await protocolRequest(SCHEMES[PROTOCOL_EDITOR], method, [arg])) as EditorResult;\n throwOnRefusal(res, `editor ${method} failed`);\n};\n\n/** Where in a file to land when opening it (R3-388). 1-indexed `line`, matching every\n * diagnostic producer that feeds it (`tsc`, `eslint`, `BuildError`) and both VS Code\n * and IntelliJ. A `line` past end-of-file CLAMPS to the last line rather than\n * erroring — a diagnostic outlives the edit that shortened the file, and landing\n * close beats refusing to navigate. */\nexport interface EditorSelection {\n line: number;\n column?: number;\n}\n\n/** Options for {@link openInEditor} (R3-389). */\nexport interface EditorOpenOptions {\n /** Also bring the user to the editor, ACROSS activities (TOOLS_ACTIVITY_SPEC §5.2).\n * An app that owns the main pane (the Tools activity's runner sits where the editor\n * would) cannot rely on the file simply becoming visible — the editor is not on\n * screen — so this asks the host to switch to the activity that owns it.\n *\n * This is the elevated `editor:reveal` capability, not `editor:open`: a frame\n * without it is refused `forbidden` for the whole call (the file is NOT opened —\n * never silently opened-without-moving). The host decides whether the user actually\n * moves: it needs a real user gesture (a click in your frame within the last few\n * seconds counts; a call on a timer or on run completion does not) and is\n * rate-limited. The promise resolves the same either way, so treat a resolved\n * reveal as \"asked\", not \"moved\", and keep a visible fallback control. Where the\n * host owns the editor activity is host state; nothing here can name it. */\n reveal?: boolean;\n}\n\n/**\n * Ask the host to open `path` (a repo-relative working-tree path, e.g. `src/App.tsx`\n * or `/src/App.tsx`) in the editor. Resolves once the editor switches to it; rejects\n * with an {@link EditorOpenError} (`.code`) if the path is invalid, missing, or this\n * app may not open files.\n *\n * Pass `selection` to land the caret on a specific line — what a problems list needs\n * to make a diagnostic clickable. It widens nothing: a selection says where to look\n * inside a file the caller could already open, and the capability is unchanged\n * (`editor:open`).\n *\n * Pass `{ reveal: true }` to ALSO bring the user to the editor across activities —\n * see {@link EditorOpenOptions.reveal}; that one does need the elevated\n * `editor:reveal`, and is refused outright without it.\n *\n * Older hosts ignore `selection` and open the file at its existing position, so a\n * caller may pass it unconditionally. `reveal` is only sent when true, so a host that\n * predates it sees a plain open.\n */\nexport const openInEditor = (path: string, selection?: EditorSelection, opts?: EditorOpenOptions): Promise<void> =>\n editorRequest('open', {\n path,\n ...(selection ? { selection } : {}),\n ...(opts?.reveal === true ? { reveal: true } : {}),\n });\n\n/**\n * Where to land when entering the edit experience (EDITOR_FIRST_EDITING_SPEC §6).\n *\n * Three target classes, and **at most one** may be given — supplying more than one is\n * refused `invalid-params` (client-side, before anything is sent). Omit all three to\n * edit the current route's entry.\n *\n * - **Own-source** (`path`): a repo-relative path in the CURRENT repo. Self-scoped —\n * the app you are already running; the host navigates within the current route,\n * never to another repo.\n * - **Mount-file** (`file`): a file in a mount you ALREADY HOLD, opened in the main\n * edit experience (§9, settled 2026-08-28). You can only name a mount you hold: an\n * unheld one is `forbidden`, and indistinguishably so from one that does not exist,\n * because an app must not be able to probe for mounts (no existence oracle).\n * Editing a file *outside* your mounts stays picker-mediated (`pick-file`).\n * - **Bundle-file** (`bundleFile`, R3-876 / APP_CUSTOMIZATION_SPEC §5a): a\n * bundle-relative path inside a directory delegated to you READ-ONLY (an opener's\n * chroot). The host finds which of your held delegations contains it — you never\n * name a mount — and opens the delegation's SOURCE file in the main-pane editor\n * under the READER's authority: your chroot is never upgraded, and no delegation\n * is minted for you. The request needs a real user gesture (transient activation,\n * sampled on the host document) and is refused `no-activation` without one; a\n * path outside every delegation you hold is `forbidden`, indistinguishable from a\n * missing one.\n *\n * A URI, a `..` segment, or a NUL is refused `invalid-params` in any class.\n */\nexport interface EditTarget {\n /** A repo-relative working-tree path in the current repo to focus once in edit\n * mode (e.g. `src/App.tsx`). Omit to edit the current route's entry. */\n path?: string;\n /** A file in one of YOUR OWN mounts, by the portable mount reference. `relPath` is\n * mount-relative and leading-slash (e.g. `/notes/idea.mdx`). Mutually exclusive\n * with {@link EditTarget.path} and {@link EditTarget.bundleFile}.\n *\n * There is no `mode` here on purpose: writability is the HOST's live reading of\n * the mount, not the caller's claim. A `ro` mount — which is also how an anonymous\n * share-link viewer surfaces — is refused `read-only` at call time, before the\n * editor is entered, so you never land in an editor that cannot save. */\n file?: { mountId: string; relPath: string };\n /** A bundle-relative, leading-slash path inside a read-only delegation you hold\n * (R3-876 — see the class note above). Mutually exclusive with\n * {@link EditTarget.path} and {@link EditTarget.file}. */\n bundleFile?: string;\n}\n\n/** An error from {@link requestEdit}, carrying a machine-readable `.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. This interface\n * documents the `.code` VALUES the host sends. Nothing enforces the union at runtime —\n * `.code` is whatever string arrived — so treat an unlisted code as possible and\n * `instanceof Error` as the only reliable test.\n */\nexport interface RequestEditError extends Error {\n code:\n | 'read-only' // editing isn't possible here (a `ro` mount / anonymous viewer; for `bundleFile`: the READER cannot edit the source) — HIDE the affordance\n | 'forbidden' // the host refuses: a cross-repo target, a mount you do not hold, or a `bundleFile` outside every delegation you hold\n | 'invalid-params' // the target was malformed (URI / `..` / NUL / more than one target class at once)\n | 'not-found' // the mount-file/bundle-file target does not exist — and asking did NOT create it\n | 'no-target' // there is no host editor session to enter\n | 'no-activation' // R3-876: a `bundleFile` request without transient user activation on the host document (G-CUST-11) — re-issue from a real click\n | 'cancelled' // the user dismissed an interactive host UX along the way\n | 'unknown';\n}\n\n/**\n * Ask the host to enter the **edit experience** for the app you are running —\n * the present→edit transition (`/present/...` → `/edit/...`) an app cannot make\n * itself. This is an INTENT (§2 recursion boundary): the app asks, the HOST\n * performs the visible, user-observable navigation and draws all editor chrome;\n * the app never navigates or paints chrome.\n *\n * Use it to offer an \"edit this\" affordance from a run/present-mode app that opens\n * the app's own source in the platform editor — instead of shipping a bespoke\n * in-app editor (EDITOR_FIRST_EDITING_SPEC §1).\n *\n * Also opens a file from a mount you already hold, in the main edit experience:\n *\n * await requestEdit({ file: { mountId: 'space:abc', relPath: '/notes/idea.mdx' } });\n *\n * Resolves once the host begins the transition; rejects with a\n * {@link RequestEditError} (`.code`). Treat `read-only`/`forbidden` as \"editing is\n * not available — hide the affordance,\" never as an error to surface to the user.\n * `not-found` means the file is not there; nothing is created by asking to edit it.\n *\n * Naming more than one target class is refused client-side (`invalid-params`),\n * before anything reaches the wire: a precedence rule is a silent reinterpretation\n * of an ambiguous request, and the one thing worse than refusing an edit target is\n * editing a different file than the caller named.\n */\nexport const requestEdit = (target?: EditTarget): Promise<void> => {\n const classes = [target?.path, target?.file, target?.bundleFile].filter((t) => t !== undefined).length;\n if (classes > 1) {\n // Client-side twin of the host gate's three-way rule (R3-876): refuse before\n // the wire so the ambiguous request is never in flight.\n const err = new Error('requestEdit: give at most one of `path`, `file` or `bundleFile`') as CodedRefusalError;\n err.code = 'invalid-params';\n return Promise.reject(err);\n }\n return editorRequest('requestEdit', target ? { ...target } : {});\n};\n\n// ---------------------------------------------------------------------------\n// Editor SESSION management (EDITOR_AS_APP_SPEC §5.1; editor-as-app plan Phase\n// 03). Unlike `openInEditor` (the explorer's cross-app intent, `editor:open`),\n// these drive the editor's OWN open-tab set + active file, so they are gated by\n// the editor app's `editor:document` capability — a file explorer holding only\n// `editor:open` cannot call them. The host re-validates the path against the live\n// working tree; the editor itself stays host-owned (§2 recursion boundary).\n// ---------------------------------------------------------------------------\n\n/** An error from a session intent ({@link setActiveFile} / {@link closeFile}),\n * carrying a machine-readable `.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. This interface\n * documents the `.code` VALUES the host sends. Nothing enforces the union at runtime —\n * `.code` is whatever string arrived — so treat an unlisted code as possible and\n * `instanceof Error` as the only reliable test.\n */\nexport interface EditorSessionError extends Error {\n code:\n | 'forbidden' // the frame lacks `editor:document`\n | 'not-found' // no such file in the live working tree\n | 'invalid-params' // the path was empty / contained `..` / looked like a URI\n | 'no-target' // there is no host editor session\n | 'unknown';\n}\n\n/** Switch the editor's active file to `path`, opening it (adding a tab) if it is\n * not already open — native `setActiveFile` parity. Rejects with an\n * {@link EditorSessionError} (`.code`) if the path is missing/invalid or this app\n * lacks `editor:document`. */\nexport const setActiveFile = (path: string): Promise<void> => editorRequest('setActive', { path });\n\n/** Close `path`'s tab in the editor (remove it from the open set) — native\n * `closeFile` parity. Rejects with an {@link EditorSessionError} (`.code`). */\nexport const closeFile = (path: string): Promise<void> => editorRequest('close', { path });\n\n// ---------------------------------------------------------------------------\n// Working-tree mutation (UI_AS_APPS_SPEC §4 / EDITOR_AS_APP_SPEC §5.2). The file\n// explorer NAMES a working-tree path and the HOST performs the COW write (and\n// refreshes the preview) — the app holds no write port; it asks. Gated by the\n// first-party `editor:write` capability, so only a first-party chrome app (the\n// file explorer) can call these; anyone else is refused at the gate.\n// ---------------------------------------------------------------------------\n\n/** An error from a working-tree mutation, carrying a machine-readable `.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. This interface\n * documents the `.code` VALUES the host sends. Nothing enforces the union at runtime —\n * `.code` is whatever string arrived — so treat an unlisted code as possible and\n * `instanceof Error` as the only reliable test.\n */\nexport interface EditorWriteError extends Error {\n code:\n | 'forbidden' // the frame lacks `editor:write` (first-party-only)\n | 'not-found' // the target file/folder does not exist (delete/rename)\n | 'exists' // the target already exists (create/rename would clobber)\n | 'protected' // the host refuses to delete this file (e.g. package.json)\n | 'too-large' // an upload exceeds the host's size limit\n | 'invalid-params' // a path was empty / contained `..` / looked like a URI\n | 'no-target' // there is no host editor session\n | 'unknown';\n}\n\n/** Create an empty working-tree file at `path` and open it. Rejects `exists` if a\n * file is already there — see {@link EditorWriteError} for the full code list, which\n * every helper below shares. */\nexport const createFile = (path: string): Promise<void> => editorRequest('createFile', { path });\n\n/** Create a working-tree folder at `path` (materialised with a `.gitkeep`). */\nexport const createFolder = (path: string): Promise<void> => editorRequest('createFolder', { path });\n\n/** Delete a working-tree file, or a folder and everything under it. Rejects\n * `protected` for files the host won't remove, `not-found` if absent. */\nexport const deleteEntry = (path: string): Promise<void> => editorRequest('deleteEntry', { path });\n\n/** Rename/move a working-tree file from `from` to `to`. Rejects `exists` if `to`\n * is taken, `not-found` if `from` is absent. */\nexport const renameEntry = (from: string, to: string): Promise<void> => editorRequest('rename', { from, to });\n\n/** Upload binary/text `bytes` to a working-tree file at `path`. Rejects\n * `too-large` past the host's size limit. The bytes are transferred (zero-copy). */\nexport const uploadFile = (path: string, bytes: Uint8Array): Promise<void> => editorRequest('upload', { path, bytes });\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAgC;AAChC,6BAAuD;AACvD,6BAAwB;AACxB,sBAAgC;AAiChC,MAAM,gBAAgB,OAAO,QAAgB,QAAgD;AAC3F,QAAM,MAAO,UAAM,qCAAgB,+BAAQ,+BAAe,GAAG,QAAQ,CAAC,GAAG,CAAC;AAC1E,6CAAe,KAAK,UAAU,MAAM,SAAS;AAC/C;AAiDO,MAAM,eAAe,CAAC,MAAc,WAA6B,SACtE,cAAc,QAAQ;AAAA,EACpB;AAAA,EACA,GAAI,YAAY,EAAE,UAAU,IAAI,CAAC;AAAA,EACjC,GAAI,MAAM,WAAW,OAAO,EAAE,QAAQ,KAAK,IAAI,CAAC;AAClD,CAAC;AA6FI,MAAM,cAAc,CAAC,WAAuC;AACjE,QAAM,UAAU,CAAC,QAAQ,MAAM,QAAQ,MAAM,QAAQ,UAAU,EAAE,OAAO,CAAC,MAAM,MAAM,MAAS,EAAE;AAChG,MAAI,UAAU,GAAG;AAGf,UAAM,MAAM,IAAI,MAAM,iEAAiE;AACvF,QAAI,OAAO;AACX,WAAO,QAAQ,OAAO,GAAG;AAAA,EAC3B;AACA,SAAO,cAAc,eAAe,SAAS,EAAE,GAAG,OAAO,IAAI,CAAC,CAAC;AACjE;AAiCO,MAAM,gBAAgB,CAAC,SAAgC,cAAc,aAAa,EAAE,KAAK,CAAC;AAI1F,MAAM,YAAY,CAAC,SAAgC,cAAc,SAAS,EAAE,KAAK,CAAC;AAiClF,MAAM,aAAa,CAAC,SAAgC,cAAc,cAAc,EAAE,KAAK,CAAC;AAGxF,MAAM,eAAe,CAAC,SAAgC,cAAc,gBAAgB,EAAE,KAAK,CAAC;AAI5F,MAAM,cAAc,CAAC,SAAgC,cAAc,eAAe,EAAE,KAAK,CAAC;AAI1F,MAAM,cAAc,CAAC,MAAc,OAA8B,cAAc,UAAU,EAAE,MAAM,GAAG,CAAC;AAIrG,MAAM,aAAa,CAAC,MAAc,UAAqC,cAAc,UAAU,EAAE,MAAM,MAAM,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/editor.ts"],"sourcesContent":["import { protocolRequest } from './sandboxUtils';\nimport { throwOnRefusal, type CodedRefusalError } from './protocolRefusal';\nimport { SCHEMES } from './protocolSchemes';\nimport { PROTOCOL_EDITOR } from './generated/protocol';\n\n/**\n * Open a working-tree file in the immediately.run host editor (UI_AS_APPS_SPEC §4 —\n * the file explorer's click-to-open). This is an INTENT: the app asks, the HOST\n * validates the path and drives the CodeMirror editor — the editor itself stays\n * host-owned (§2 recursion boundary), so an app can never own or script it beyond\n * \"please show this file\".\n *\n * Requires the elevated `editor:open` capability — a previewed app does not hold it\n * (it must not move the host's focus), so only a system app whose binding grants it\n * (the file explorer) can call this; anyone else is refused at the gate.\n */\n\n/** An error from {@link openInEditor}, carrying a machine-readable `.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. This interface\n * documents the `.code` VALUES the host sends. Nothing enforces the union at runtime —\n * `.code` is whatever string arrived — so treat an unlisted code as possible and\n * `instanceof Error` as the only reliable test.\n */\nexport interface EditorOpenError extends Error {\n code:\n | 'forbidden' // the frame lacks `editor:open` (or `editor:reveal`, for a `reveal`)\n | 'not-found' // no such file in the live working tree (the host never creates)\n | 'invalid-params' // the path was empty / contained `..` / looked like a URI\n | 'no-target' // there is no host editor session to open files in\n | 'unknown';\n}\n\ntype EditorResult =\n | { ok: true; data: unknown }\n // R3-853: a `too-large` refusal may carry the host's `limitBytes`.\n | { ok: false; code: string; message: string; limitBytes?: number };\n\nconst editorRequest = async (method: string, arg: Record<string, unknown>): Promise<void> => {\n const res = (await protocolRequest(SCHEMES[PROTOCOL_EDITOR], method, [arg])) as EditorResult;\n try {\n throwOnRefusal(res, `editor ${method} failed`);\n } catch (e) {\n // R3-853: a `too-large` refusal may carry the host's `limitBytes` — re-attach\n // it to the thrown error (throwOnRefusal builds a code+message error only).\n // Only ever set by `upload` today; forwarded generically and harmlessly. The\n // `res &&` narrowing guard is load-bearing (review round 1): a null/undefined\n // reply is a coded refusal, never a TypeError from this read (R3-817's property).\n const limit = res && res.ok === false ? res.limitBytes : undefined;\n if (typeof limit === 'number') (e as EditorWriteError).limitBytes = limit;\n throw e;\n }\n};\n\n/** Where in a file to land when opening it (R3-388). 1-indexed `line`, matching every\n * diagnostic producer that feeds it (`tsc`, `eslint`, `BuildError`) and both VS Code\n * and IntelliJ. A `line` past end-of-file CLAMPS to the last line rather than\n * erroring — a diagnostic outlives the edit that shortened the file, and landing\n * close beats refusing to navigate. */\nexport interface EditorSelection {\n line: number;\n column?: number;\n}\n\n/** Options for {@link openInEditor} (R3-389). */\nexport interface EditorOpenOptions {\n /** Also bring the user to the editor, ACROSS activities (TOOLS_ACTIVITY_SPEC §5.2).\n * An app that owns the main pane (the Tools activity's runner sits where the editor\n * would) cannot rely on the file simply becoming visible — the editor is not on\n * screen — so this asks the host to switch to the activity that owns it.\n *\n * This is the elevated `editor:reveal` capability, not `editor:open`: a frame\n * without it is refused `forbidden` for the whole call (the file is NOT opened —\n * never silently opened-without-moving). The host decides whether the user actually\n * moves: it needs a real user gesture (a click in your frame within the last few\n * seconds counts; a call on a timer or on run completion does not) and is\n * rate-limited. The promise resolves the same either way, so treat a resolved\n * reveal as \"asked\", not \"moved\", and keep a visible fallback control. Where the\n * host owns the editor activity is host state; nothing here can name it. */\n reveal?: boolean;\n}\n\n/**\n * Ask the host to open `path` (a repo-relative working-tree path, e.g. `src/App.tsx`\n * or `/src/App.tsx`) in the editor. Resolves once the editor switches to it; rejects\n * with an {@link EditorOpenError} (`.code`) if the path is invalid, missing, or this\n * app may not open files.\n *\n * Pass `selection` to land the caret on a specific line — what a problems list needs\n * to make a diagnostic clickable. It widens nothing: a selection says where to look\n * inside a file the caller could already open, and the capability is unchanged\n * (`editor:open`).\n *\n * Pass `{ reveal: true }` to ALSO bring the user to the editor across activities —\n * see {@link EditorOpenOptions.reveal}; that one does need the elevated\n * `editor:reveal`, and is refused outright without it.\n *\n * Older hosts ignore `selection` and open the file at its existing position, so a\n * caller may pass it unconditionally. `reveal` is only sent when true, so a host that\n * predates it sees a plain open.\n */\nexport const openInEditor = (path: string, selection?: EditorSelection, opts?: EditorOpenOptions): Promise<void> =>\n editorRequest('open', {\n path,\n ...(selection ? { selection } : {}),\n ...(opts?.reveal === true ? { reveal: true } : {}),\n });\n\n/**\n * Where to land when entering the edit experience (EDITOR_FIRST_EDITING_SPEC §6).\n *\n * Three target classes, and **at most one** may be given — supplying more than one is\n * refused `invalid-params` (client-side, before anything is sent). Omit all three to\n * edit the current route's entry.\n *\n * - **Own-source** (`path`): a repo-relative path in the CURRENT repo. Self-scoped —\n * the app you are already running; the host navigates within the current route,\n * never to another repo.\n * - **Mount-file** (`file`): a file in a mount you ALREADY HOLD, opened in the main\n * edit experience (§9, settled 2026-08-28). You can only name a mount you hold: an\n * unheld one is `forbidden`, and indistinguishably so from one that does not exist,\n * because an app must not be able to probe for mounts (no existence oracle).\n * Editing a file *outside* your mounts stays picker-mediated (`pick-file`).\n * - **Bundle-file** (`bundleFile`, R3-876 / APP_CUSTOMIZATION_SPEC §5a): a\n * bundle-relative path inside a directory delegated to you READ-ONLY (an opener's\n * chroot). The host finds which of your held delegations contains it — you never\n * name a mount — and opens the delegation's SOURCE file in the main-pane editor\n * under the READER's authority: your chroot is never upgraded, and no delegation\n * is minted for you. The request needs a real user gesture (transient activation,\n * sampled on the host document) and is refused `no-activation` without one; a\n * path outside every delegation you hold is `forbidden`, indistinguishable from a\n * missing one.\n *\n * A URI, a `..` segment, or a NUL is refused `invalid-params` in any class.\n */\nexport interface EditTarget {\n /** A repo-relative working-tree path in the current repo to focus once in edit\n * mode (e.g. `src/App.tsx`). Omit to edit the current route's entry. */\n path?: string;\n /** A file in one of YOUR OWN mounts, by the portable mount reference. `relPath` is\n * mount-relative and leading-slash (e.g. `/notes/idea.mdx`). Mutually exclusive\n * with {@link EditTarget.path} and {@link EditTarget.bundleFile}.\n *\n * There is no `mode` here on purpose: writability is the HOST's live reading of\n * the mount, not the caller's claim. A `ro` mount — which is also how an anonymous\n * share-link viewer surfaces — is refused `read-only` at call time, before the\n * editor is entered, so you never land in an editor that cannot save. */\n file?: { mountId: string; relPath: string };\n /** A bundle-relative, leading-slash path inside a read-only delegation you hold\n * (R3-876 — see the class note above). Mutually exclusive with\n * {@link EditTarget.path} and {@link EditTarget.file}. */\n bundleFile?: string;\n}\n\n/** An error from {@link requestEdit}, carrying a machine-readable `.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. This interface\n * documents the `.code` VALUES the host sends. Nothing enforces the union at runtime —\n * `.code` is whatever string arrived — so treat an unlisted code as possible and\n * `instanceof Error` as the only reliable test.\n */\nexport interface RequestEditError extends Error {\n code:\n | 'read-only' // editing isn't possible here (a `ro` mount / anonymous viewer; for `bundleFile`: the READER cannot edit the source) — HIDE the affordance\n | 'forbidden' // the host refuses: a cross-repo target, a mount you do not hold, or a `bundleFile` outside every delegation you hold\n | 'invalid-params' // the target was malformed (URI / `..` / NUL / more than one target class at once)\n | 'not-found' // the mount-file/bundle-file target does not exist — and asking did NOT create it\n | 'no-target' // there is no host editor session to enter\n | 'no-activation' // R3-876: a `bundleFile` request without transient user activation on the host document (G-CUST-11) — re-issue from a real click\n | 'cancelled' // the user dismissed an interactive host UX along the way\n | 'unknown';\n}\n\n/**\n * Ask the host to enter the **edit experience** for the app you are running —\n * the present→edit transition (`/present/...` → `/edit/...`) an app cannot make\n * itself. This is an INTENT (§2 recursion boundary): the app asks, the HOST\n * performs the visible, user-observable navigation and draws all editor chrome;\n * the app never navigates or paints chrome.\n *\n * Use it to offer an \"edit this\" affordance from a run/present-mode app that opens\n * the app's own source in the platform editor — instead of shipping a bespoke\n * in-app editor (EDITOR_FIRST_EDITING_SPEC §1).\n *\n * Also opens a file from a mount you already hold, in the main edit experience:\n *\n * await requestEdit({ file: { mountId: 'space:abc', relPath: '/notes/idea.mdx' } });\n *\n * Resolves once the host begins the transition; rejects with a\n * {@link RequestEditError} (`.code`). Treat `read-only`/`forbidden` as \"editing is\n * not available — hide the affordance,\" never as an error to surface to the user.\n * `not-found` means the file is not there; nothing is created by asking to edit it.\n *\n * Naming more than one target class is refused client-side (`invalid-params`),\n * before anything reaches the wire: a precedence rule is a silent reinterpretation\n * of an ambiguous request, and the one thing worse than refusing an edit target is\n * editing a different file than the caller named.\n */\nexport const requestEdit = (target?: EditTarget): Promise<void> => {\n const classes = [target?.path, target?.file, target?.bundleFile].filter((t) => t !== undefined).length;\n if (classes > 1) {\n // Client-side twin of the host gate's three-way rule (R3-876): refuse before\n // the wire so the ambiguous request is never in flight.\n const err = new Error('requestEdit: give at most one of `path`, `file` or `bundleFile`') as CodedRefusalError;\n err.code = 'invalid-params';\n return Promise.reject(err);\n }\n return editorRequest('requestEdit', target ? { ...target } : {});\n};\n\n// ---------------------------------------------------------------------------\n// Editor SESSION management (EDITOR_AS_APP_SPEC §5.1; editor-as-app plan Phase\n// 03). Unlike `openInEditor` (the explorer's cross-app intent, `editor:open`),\n// these drive the editor's OWN open-tab set + active file, so they are gated by\n// the editor app's `editor:document` capability — a file explorer holding only\n// `editor:open` cannot call them. The host re-validates the path against the live\n// working tree; the editor itself stays host-owned (§2 recursion boundary).\n// ---------------------------------------------------------------------------\n\n/** An error from a session intent ({@link setActiveFile} / {@link closeFile}),\n * carrying a machine-readable `.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. This interface\n * documents the `.code` VALUES the host sends. Nothing enforces the union at runtime —\n * `.code` is whatever string arrived — so treat an unlisted code as possible and\n * `instanceof Error` as the only reliable test.\n */\nexport interface EditorSessionError extends Error {\n code:\n | 'forbidden' // the frame lacks `editor:document`\n | 'not-found' // no such file in the live working tree\n | 'invalid-params' // the path was empty / contained `..` / looked like a URI\n | 'no-target' // there is no host editor session\n | 'unknown';\n}\n\n/** Switch the editor's active file to `path`, opening it (adding a tab) if it is\n * not already open — native `setActiveFile` parity. Rejects with an\n * {@link EditorSessionError} (`.code`) if the path is missing/invalid or this app\n * lacks `editor:document`. */\nexport const setActiveFile = (path: string): Promise<void> => editorRequest('setActive', { path });\n\n/** Close `path`'s tab in the editor (remove it from the open set) — native\n * `closeFile` parity. Rejects with an {@link EditorSessionError} (`.code`). */\nexport const closeFile = (path: string): Promise<void> => editorRequest('close', { path });\n\n// ---------------------------------------------------------------------------\n// Working-tree mutation (UI_AS_APPS_SPEC §4 / EDITOR_AS_APP_SPEC §5.2). The file\n// explorer NAMES a working-tree path and the HOST performs the COW write (and\n// refreshes the preview) — the app holds no write port; it asks. Gated by the\n// first-party `editor:write` capability, so only a first-party chrome app (the\n// file explorer) can call these; anyone else is refused at the gate.\n// ---------------------------------------------------------------------------\n\n/** An error from a working-tree mutation, carrying a machine-readable `.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. This interface\n * documents the `.code` VALUES the host sends. Nothing enforces the union at runtime —\n * `.code` is whatever string arrived — so treat an unlisted code as possible and\n * `instanceof Error` as the only reliable test.\n */\nexport interface EditorWriteError extends Error {\n /** R3-853: on a `too-large` refusal, the host's actual limit in bytes — the\n * host names the limit (LARGE_FILE_SUPPORT §3). The SDK forwards it verbatim\n * whenever a refusal carries it; the host sends it only on `too-large`. Absent\n * on an older host. */\n limitBytes?: number;\n code:\n | 'forbidden' // the frame lacks `editor:write` (first-party-only)\n | 'not-found' // the target file/folder does not exist (delete/rename)\n | 'exists' // the target already exists (create/rename would clobber)\n | 'protected' // the host refuses to delete this file (e.g. package.json)\n | 'too-large' // an upload exceeds the host's size limit\n | 'invalid-params' // a path was empty / contained `..` / looked like a URI\n | 'no-target' // there is no host editor session\n | 'unknown';\n}\n\n/** Create an empty working-tree file at `path` and open it. Rejects `exists` if a\n * file is already there — see {@link EditorWriteError} for the full code list, which\n * every helper below shares. */\nexport const createFile = (path: string): Promise<void> => editorRequest('createFile', { path });\n\n/** Create a working-tree folder at `path` (materialised with a `.gitkeep`). */\nexport const createFolder = (path: string): Promise<void> => editorRequest('createFolder', { path });\n\n/** Delete a working-tree file, or a folder and everything under it. Rejects\n * `protected` for files the host won't remove, `not-found` if absent. */\nexport const deleteEntry = (path: string): Promise<void> => editorRequest('deleteEntry', { path });\n\n/** Rename/move a working-tree file from `from` to `to`. Rejects `exists` if `to`\n * is taken, `not-found` if `from` is absent. */\nexport const renameEntry = (from: string, to: string): Promise<void> => editorRequest('rename', { from, to });\n\n/** Upload binary/text `bytes` to a working-tree file at `path`. Rejects\n * `too-large` past the host's size limit — the rejection carries the limit as\n * `err.limitBytes` (R3-853: the host names the limit; absent on an older host).\n * The bytes are transferred (zero-copy). */\nexport const uploadFile = (path: string, bytes: Uint8Array): Promise<void> => editorRequest('upload', { path, bytes });\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAgC;AAChC,6BAAuD;AACvD,6BAAwB;AACxB,sBAAgC;AAoChC,MAAM,gBAAgB,OAAO,QAAgB,QAAgD;AAC3F,QAAM,MAAO,UAAM,qCAAgB,+BAAQ,+BAAe,GAAG,QAAQ,CAAC,GAAG,CAAC;AAC1E,MAAI;AACF,+CAAe,KAAK,UAAU,MAAM,SAAS;AAAA,EAC/C,SAAS,GAAG;AAMV,UAAM,QAAQ,OAAO,IAAI,OAAO,QAAQ,IAAI,aAAa;AACzD,QAAI,OAAO,UAAU,SAAU,CAAC,EAAuB,aAAa;AACpE,UAAM;AAAA,EACR;AACF;AAiDO,MAAM,eAAe,CAAC,MAAc,WAA6B,SACtE,cAAc,QAAQ;AAAA,EACpB;AAAA,EACA,GAAI,YAAY,EAAE,UAAU,IAAI,CAAC;AAAA,EACjC,GAAI,MAAM,WAAW,OAAO,EAAE,QAAQ,KAAK,IAAI,CAAC;AAClD,CAAC;AA6FI,MAAM,cAAc,CAAC,WAAuC;AACjE,QAAM,UAAU,CAAC,QAAQ,MAAM,QAAQ,MAAM,QAAQ,UAAU,EAAE,OAAO,CAAC,MAAM,MAAM,MAAS,EAAE;AAChG,MAAI,UAAU,GAAG;AAGf,UAAM,MAAM,IAAI,MAAM,iEAAiE;AACvF,QAAI,OAAO;AACX,WAAO,QAAQ,OAAO,GAAG;AAAA,EAC3B;AACA,SAAO,cAAc,eAAe,SAAS,EAAE,GAAG,OAAO,IAAI,CAAC,CAAC;AACjE;AAiCO,MAAM,gBAAgB,CAAC,SAAgC,cAAc,aAAa,EAAE,KAAK,CAAC;AAI1F,MAAM,YAAY,CAAC,SAAgC,cAAc,SAAS,EAAE,KAAK,CAAC;AAsClF,MAAM,aAAa,CAAC,SAAgC,cAAc,cAAc,EAAE,KAAK,CAAC;AAGxF,MAAM,eAAe,CAAC,SAAgC,cAAc,gBAAgB,EAAE,KAAK,CAAC;AAI5F,MAAM,cAAc,CAAC,SAAgC,cAAc,eAAe,EAAE,KAAK,CAAC;AAI1F,MAAM,cAAc,CAAC,MAAc,OAA8B,cAAc,UAAU,EAAE,MAAM,GAAG,CAAC;AAMrG,MAAM,aAAa,CAAC,MAAc,UAAqC,cAAc,UAAU,EAAE,MAAM,MAAM,CAAC;","names":[]}
|
package/dist/editor.d.cts
CHANGED
|
@@ -180,6 +180,11 @@ declare const closeFile: (path: string) => Promise<void>;
|
|
|
180
180
|
* `instanceof Error` as the only reliable test.
|
|
181
181
|
*/
|
|
182
182
|
interface EditorWriteError extends Error {
|
|
183
|
+
/** R3-853: on a `too-large` refusal, the host's actual limit in bytes — the
|
|
184
|
+
* host names the limit (LARGE_FILE_SUPPORT §3). The SDK forwards it verbatim
|
|
185
|
+
* whenever a refusal carries it; the host sends it only on `too-large`. Absent
|
|
186
|
+
* on an older host. */
|
|
187
|
+
limitBytes?: number;
|
|
183
188
|
code: 'forbidden' | 'not-found' | 'exists' | 'protected' | 'too-large' | 'invalid-params' | 'no-target' | 'unknown';
|
|
184
189
|
}
|
|
185
190
|
/** Create an empty working-tree file at `path` and open it. Rejects `exists` if a
|
|
@@ -195,7 +200,9 @@ declare const deleteEntry: (path: string) => Promise<void>;
|
|
|
195
200
|
* is taken, `not-found` if `from` is absent. */
|
|
196
201
|
declare const renameEntry: (from: string, to: string) => Promise<void>;
|
|
197
202
|
/** Upload binary/text `bytes` to a working-tree file at `path`. Rejects
|
|
198
|
-
* `too-large` past the host's size limit
|
|
203
|
+
* `too-large` past the host's size limit — the rejection carries the limit as
|
|
204
|
+
* `err.limitBytes` (R3-853: the host names the limit; absent on an older host).
|
|
205
|
+
* The bytes are transferred (zero-copy). */
|
|
199
206
|
declare const uploadFile: (path: string, bytes: Uint8Array) => Promise<void>;
|
|
200
207
|
|
|
201
208
|
export { type EditTarget, type EditorOpenError, type EditorOpenOptions, type EditorSelection, type EditorSessionError, type EditorWriteError, type RequestEditError, closeFile, createFile, createFolder, deleteEntry, openInEditor, renameEntry, requestEdit, setActiveFile, uploadFile };
|
package/dist/editor.d.ts
CHANGED
|
@@ -180,6 +180,11 @@ declare const closeFile: (path: string) => Promise<void>;
|
|
|
180
180
|
* `instanceof Error` as the only reliable test.
|
|
181
181
|
*/
|
|
182
182
|
interface EditorWriteError extends Error {
|
|
183
|
+
/** R3-853: on a `too-large` refusal, the host's actual limit in bytes — the
|
|
184
|
+
* host names the limit (LARGE_FILE_SUPPORT §3). The SDK forwards it verbatim
|
|
185
|
+
* whenever a refusal carries it; the host sends it only on `too-large`. Absent
|
|
186
|
+
* on an older host. */
|
|
187
|
+
limitBytes?: number;
|
|
183
188
|
code: 'forbidden' | 'not-found' | 'exists' | 'protected' | 'too-large' | 'invalid-params' | 'no-target' | 'unknown';
|
|
184
189
|
}
|
|
185
190
|
/** Create an empty working-tree file at `path` and open it. Rejects `exists` if a
|
|
@@ -195,7 +200,9 @@ declare const deleteEntry: (path: string) => Promise<void>;
|
|
|
195
200
|
* is taken, `not-found` if `from` is absent. */
|
|
196
201
|
declare const renameEntry: (from: string, to: string) => Promise<void>;
|
|
197
202
|
/** Upload binary/text `bytes` to a working-tree file at `path`. Rejects
|
|
198
|
-
* `too-large` past the host's size limit
|
|
203
|
+
* `too-large` past the host's size limit — the rejection carries the limit as
|
|
204
|
+
* `err.limitBytes` (R3-853: the host names the limit; absent on an older host).
|
|
205
|
+
* The bytes are transferred (zero-copy). */
|
|
199
206
|
declare const uploadFile: (path: string, bytes: Uint8Array) => Promise<void>;
|
|
200
207
|
|
|
201
208
|
export { type EditTarget, type EditorOpenError, type EditorOpenOptions, type EditorSelection, type EditorSessionError, type EditorWriteError, type RequestEditError, closeFile, createFile, createFolder, deleteEntry, openInEditor, renameEntry, requestEdit, setActiveFile, uploadFile };
|
package/dist/editor.js
CHANGED
|
@@ -5,7 +5,13 @@ import { SCHEMES } from "./protocolSchemes.js";
|
|
|
5
5
|
import { PROTOCOL_EDITOR } from "./generated/protocol.js";
|
|
6
6
|
const editorRequest = async (method, arg) => {
|
|
7
7
|
const res = await protocolRequest(SCHEMES[PROTOCOL_EDITOR], method, [arg]);
|
|
8
|
-
|
|
8
|
+
try {
|
|
9
|
+
throwOnRefusal(res, `editor ${method} failed`);
|
|
10
|
+
} catch (e) {
|
|
11
|
+
const limit = res && res.ok === false ? res.limitBytes : void 0;
|
|
12
|
+
if (typeof limit === "number") e.limitBytes = limit;
|
|
13
|
+
throw e;
|
|
14
|
+
}
|
|
9
15
|
};
|
|
10
16
|
const openInEditor = (path, selection, opts) => editorRequest("open", {
|
|
11
17
|
path,
|
package/dist/editor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/editor.ts"],"sourcesContent":["import { protocolRequest } from './sandboxUtils';\nimport { throwOnRefusal, type CodedRefusalError } from './protocolRefusal';\nimport { SCHEMES } from './protocolSchemes';\nimport { PROTOCOL_EDITOR } from './generated/protocol';\n\n/**\n * Open a working-tree file in the immediately.run host editor (UI_AS_APPS_SPEC §4 —\n * the file explorer's click-to-open). This is an INTENT: the app asks, the HOST\n * validates the path and drives the CodeMirror editor — the editor itself stays\n * host-owned (§2 recursion boundary), so an app can never own or script it beyond\n * \"please show this file\".\n *\n * Requires the elevated `editor:open` capability — a previewed app does not hold it\n * (it must not move the host's focus), so only a system app whose binding grants it\n * (the file explorer) can call this; anyone else is refused at the gate.\n */\n\n/** An error from {@link openInEditor}, carrying a machine-readable `.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. This interface\n * documents the `.code` VALUES the host sends. Nothing enforces the union at runtime —\n * `.code` is whatever string arrived — so treat an unlisted code as possible and\n * `instanceof Error` as the only reliable test.\n */\nexport interface EditorOpenError extends Error {\n code:\n | 'forbidden' // the frame lacks `editor:open` (or `editor:reveal`, for a `reveal`)\n | 'not-found' // no such file in the live working tree (the host never creates)\n | 'invalid-params' // the path was empty / contained `..` / looked like a URI\n | 'no-target' // there is no host editor session to open files in\n | 'unknown';\n}\n\ntype EditorResult = { ok: true; data: unknown } | { ok: false; code: string; message: string };\n\nconst editorRequest = async (method: string, arg: Record<string, unknown>): Promise<void> => {\n const res = (await protocolRequest(SCHEMES[PROTOCOL_EDITOR], method, [arg])) as EditorResult;\n throwOnRefusal(res, `editor ${method} failed`);\n};\n\n/** Where in a file to land when opening it (R3-388). 1-indexed `line`, matching every\n * diagnostic producer that feeds it (`tsc`, `eslint`, `BuildError`) and both VS Code\n * and IntelliJ. A `line` past end-of-file CLAMPS to the last line rather than\n * erroring — a diagnostic outlives the edit that shortened the file, and landing\n * close beats refusing to navigate. */\nexport interface EditorSelection {\n line: number;\n column?: number;\n}\n\n/** Options for {@link openInEditor} (R3-389). */\nexport interface EditorOpenOptions {\n /** Also bring the user to the editor, ACROSS activities (TOOLS_ACTIVITY_SPEC §5.2).\n * An app that owns the main pane (the Tools activity's runner sits where the editor\n * would) cannot rely on the file simply becoming visible — the editor is not on\n * screen — so this asks the host to switch to the activity that owns it.\n *\n * This is the elevated `editor:reveal` capability, not `editor:open`: a frame\n * without it is refused `forbidden` for the whole call (the file is NOT opened —\n * never silently opened-without-moving). The host decides whether the user actually\n * moves: it needs a real user gesture (a click in your frame within the last few\n * seconds counts; a call on a timer or on run completion does not) and is\n * rate-limited. The promise resolves the same either way, so treat a resolved\n * reveal as \"asked\", not \"moved\", and keep a visible fallback control. Where the\n * host owns the editor activity is host state; nothing here can name it. */\n reveal?: boolean;\n}\n\n/**\n * Ask the host to open `path` (a repo-relative working-tree path, e.g. `src/App.tsx`\n * or `/src/App.tsx`) in the editor. Resolves once the editor switches to it; rejects\n * with an {@link EditorOpenError} (`.code`) if the path is invalid, missing, or this\n * app may not open files.\n *\n * Pass `selection` to land the caret on a specific line — what a problems list needs\n * to make a diagnostic clickable. It widens nothing: a selection says where to look\n * inside a file the caller could already open, and the capability is unchanged\n * (`editor:open`).\n *\n * Pass `{ reveal: true }` to ALSO bring the user to the editor across activities —\n * see {@link EditorOpenOptions.reveal}; that one does need the elevated\n * `editor:reveal`, and is refused outright without it.\n *\n * Older hosts ignore `selection` and open the file at its existing position, so a\n * caller may pass it unconditionally. `reveal` is only sent when true, so a host that\n * predates it sees a plain open.\n */\nexport const openInEditor = (path: string, selection?: EditorSelection, opts?: EditorOpenOptions): Promise<void> =>\n editorRequest('open', {\n path,\n ...(selection ? { selection } : {}),\n ...(opts?.reveal === true ? { reveal: true } : {}),\n });\n\n/**\n * Where to land when entering the edit experience (EDITOR_FIRST_EDITING_SPEC §6).\n *\n * Three target classes, and **at most one** may be given — supplying more than one is\n * refused `invalid-params` (client-side, before anything is sent). Omit all three to\n * edit the current route's entry.\n *\n * - **Own-source** (`path`): a repo-relative path in the CURRENT repo. Self-scoped —\n * the app you are already running; the host navigates within the current route,\n * never to another repo.\n * - **Mount-file** (`file`): a file in a mount you ALREADY HOLD, opened in the main\n * edit experience (§9, settled 2026-08-28). You can only name a mount you hold: an\n * unheld one is `forbidden`, and indistinguishably so from one that does not exist,\n * because an app must not be able to probe for mounts (no existence oracle).\n * Editing a file *outside* your mounts stays picker-mediated (`pick-file`).\n * - **Bundle-file** (`bundleFile`, R3-876 / APP_CUSTOMIZATION_SPEC §5a): a\n * bundle-relative path inside a directory delegated to you READ-ONLY (an opener's\n * chroot). The host finds which of your held delegations contains it — you never\n * name a mount — and opens the delegation's SOURCE file in the main-pane editor\n * under the READER's authority: your chroot is never upgraded, and no delegation\n * is minted for you. The request needs a real user gesture (transient activation,\n * sampled on the host document) and is refused `no-activation` without one; a\n * path outside every delegation you hold is `forbidden`, indistinguishable from a\n * missing one.\n *\n * A URI, a `..` segment, or a NUL is refused `invalid-params` in any class.\n */\nexport interface EditTarget {\n /** A repo-relative working-tree path in the current repo to focus once in edit\n * mode (e.g. `src/App.tsx`). Omit to edit the current route's entry. */\n path?: string;\n /** A file in one of YOUR OWN mounts, by the portable mount reference. `relPath` is\n * mount-relative and leading-slash (e.g. `/notes/idea.mdx`). Mutually exclusive\n * with {@link EditTarget.path} and {@link EditTarget.bundleFile}.\n *\n * There is no `mode` here on purpose: writability is the HOST's live reading of\n * the mount, not the caller's claim. A `ro` mount — which is also how an anonymous\n * share-link viewer surfaces — is refused `read-only` at call time, before the\n * editor is entered, so you never land in an editor that cannot save. */\n file?: { mountId: string; relPath: string };\n /** A bundle-relative, leading-slash path inside a read-only delegation you hold\n * (R3-876 — see the class note above). Mutually exclusive with\n * {@link EditTarget.path} and {@link EditTarget.file}. */\n bundleFile?: string;\n}\n\n/** An error from {@link requestEdit}, carrying a machine-readable `.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. This interface\n * documents the `.code` VALUES the host sends. Nothing enforces the union at runtime —\n * `.code` is whatever string arrived — so treat an unlisted code as possible and\n * `instanceof Error` as the only reliable test.\n */\nexport interface RequestEditError extends Error {\n code:\n | 'read-only' // editing isn't possible here (a `ro` mount / anonymous viewer; for `bundleFile`: the READER cannot edit the source) — HIDE the affordance\n | 'forbidden' // the host refuses: a cross-repo target, a mount you do not hold, or a `bundleFile` outside every delegation you hold\n | 'invalid-params' // the target was malformed (URI / `..` / NUL / more than one target class at once)\n | 'not-found' // the mount-file/bundle-file target does not exist — and asking did NOT create it\n | 'no-target' // there is no host editor session to enter\n | 'no-activation' // R3-876: a `bundleFile` request without transient user activation on the host document (G-CUST-11) — re-issue from a real click\n | 'cancelled' // the user dismissed an interactive host UX along the way\n | 'unknown';\n}\n\n/**\n * Ask the host to enter the **edit experience** for the app you are running —\n * the present→edit transition (`/present/...` → `/edit/...`) an app cannot make\n * itself. This is an INTENT (§2 recursion boundary): the app asks, the HOST\n * performs the visible, user-observable navigation and draws all editor chrome;\n * the app never navigates or paints chrome.\n *\n * Use it to offer an \"edit this\" affordance from a run/present-mode app that opens\n * the app's own source in the platform editor — instead of shipping a bespoke\n * in-app editor (EDITOR_FIRST_EDITING_SPEC §1).\n *\n * Also opens a file from a mount you already hold, in the main edit experience:\n *\n * await requestEdit({ file: { mountId: 'space:abc', relPath: '/notes/idea.mdx' } });\n *\n * Resolves once the host begins the transition; rejects with a\n * {@link RequestEditError} (`.code`). Treat `read-only`/`forbidden` as \"editing is\n * not available — hide the affordance,\" never as an error to surface to the user.\n * `not-found` means the file is not there; nothing is created by asking to edit it.\n *\n * Naming more than one target class is refused client-side (`invalid-params`),\n * before anything reaches the wire: a precedence rule is a silent reinterpretation\n * of an ambiguous request, and the one thing worse than refusing an edit target is\n * editing a different file than the caller named.\n */\nexport const requestEdit = (target?: EditTarget): Promise<void> => {\n const classes = [target?.path, target?.file, target?.bundleFile].filter((t) => t !== undefined).length;\n if (classes > 1) {\n // Client-side twin of the host gate's three-way rule (R3-876): refuse before\n // the wire so the ambiguous request is never in flight.\n const err = new Error('requestEdit: give at most one of `path`, `file` or `bundleFile`') as CodedRefusalError;\n err.code = 'invalid-params';\n return Promise.reject(err);\n }\n return editorRequest('requestEdit', target ? { ...target } : {});\n};\n\n// ---------------------------------------------------------------------------\n// Editor SESSION management (EDITOR_AS_APP_SPEC §5.1; editor-as-app plan Phase\n// 03). Unlike `openInEditor` (the explorer's cross-app intent, `editor:open`),\n// these drive the editor's OWN open-tab set + active file, so they are gated by\n// the editor app's `editor:document` capability — a file explorer holding only\n// `editor:open` cannot call them. The host re-validates the path against the live\n// working tree; the editor itself stays host-owned (§2 recursion boundary).\n// ---------------------------------------------------------------------------\n\n/** An error from a session intent ({@link setActiveFile} / {@link closeFile}),\n * carrying a machine-readable `.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. This interface\n * documents the `.code` VALUES the host sends. Nothing enforces the union at runtime —\n * `.code` is whatever string arrived — so treat an unlisted code as possible and\n * `instanceof Error` as the only reliable test.\n */\nexport interface EditorSessionError extends Error {\n code:\n | 'forbidden' // the frame lacks `editor:document`\n | 'not-found' // no such file in the live working tree\n | 'invalid-params' // the path was empty / contained `..` / looked like a URI\n | 'no-target' // there is no host editor session\n | 'unknown';\n}\n\n/** Switch the editor's active file to `path`, opening it (adding a tab) if it is\n * not already open — native `setActiveFile` parity. Rejects with an\n * {@link EditorSessionError} (`.code`) if the path is missing/invalid or this app\n * lacks `editor:document`. */\nexport const setActiveFile = (path: string): Promise<void> => editorRequest('setActive', { path });\n\n/** Close `path`'s tab in the editor (remove it from the open set) — native\n * `closeFile` parity. Rejects with an {@link EditorSessionError} (`.code`). */\nexport const closeFile = (path: string): Promise<void> => editorRequest('close', { path });\n\n// ---------------------------------------------------------------------------\n// Working-tree mutation (UI_AS_APPS_SPEC §4 / EDITOR_AS_APP_SPEC §5.2). The file\n// explorer NAMES a working-tree path and the HOST performs the COW write (and\n// refreshes the preview) — the app holds no write port; it asks. Gated by the\n// first-party `editor:write` capability, so only a first-party chrome app (the\n// file explorer) can call these; anyone else is refused at the gate.\n// ---------------------------------------------------------------------------\n\n/** An error from a working-tree mutation, carrying a machine-readable `.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. This interface\n * documents the `.code` VALUES the host sends. Nothing enforces the union at runtime —\n * `.code` is whatever string arrived — so treat an unlisted code as possible and\n * `instanceof Error` as the only reliable test.\n */\nexport interface EditorWriteError extends Error {\n code:\n | 'forbidden' // the frame lacks `editor:write` (first-party-only)\n | 'not-found' // the target file/folder does not exist (delete/rename)\n | 'exists' // the target already exists (create/rename would clobber)\n | 'protected' // the host refuses to delete this file (e.g. package.json)\n | 'too-large' // an upload exceeds the host's size limit\n | 'invalid-params' // a path was empty / contained `..` / looked like a URI\n | 'no-target' // there is no host editor session\n | 'unknown';\n}\n\n/** Create an empty working-tree file at `path` and open it. Rejects `exists` if a\n * file is already there — see {@link EditorWriteError} for the full code list, which\n * every helper below shares. */\nexport const createFile = (path: string): Promise<void> => editorRequest('createFile', { path });\n\n/** Create a working-tree folder at `path` (materialised with a `.gitkeep`). */\nexport const createFolder = (path: string): Promise<void> => editorRequest('createFolder', { path });\n\n/** Delete a working-tree file, or a folder and everything under it. Rejects\n * `protected` for files the host won't remove, `not-found` if absent. */\nexport const deleteEntry = (path: string): Promise<void> => editorRequest('deleteEntry', { path });\n\n/** Rename/move a working-tree file from `from` to `to`. Rejects `exists` if `to`\n * is taken, `not-found` if `from` is absent. */\nexport const renameEntry = (from: string, to: string): Promise<void> => editorRequest('rename', { from, to });\n\n/** Upload binary/text `bytes` to a working-tree file at `path`. Rejects\n * `too-large` past the host's size limit. The bytes are transferred (zero-copy). */\nexport const uploadFile = (path: string, bytes: Uint8Array): Promise<void> => editorRequest('upload', { path, bytes });\n"],"mappings":";AAAA,SAAS,uBAAuB;AAChC,SAAS,sBAA8C;AACvD,SAAS,eAAe;AACxB,SAAS,uBAAuB;AAiChC,MAAM,gBAAgB,OAAO,QAAgB,QAAgD;AAC3F,QAAM,MAAO,MAAM,gBAAgB,QAAQ,eAAe,GAAG,QAAQ,CAAC,GAAG,CAAC;AAC1E,iBAAe,KAAK,UAAU,MAAM,SAAS;AAC/C;AAiDO,MAAM,eAAe,CAAC,MAAc,WAA6B,SACtE,cAAc,QAAQ;AAAA,EACpB;AAAA,EACA,GAAI,YAAY,EAAE,UAAU,IAAI,CAAC;AAAA,EACjC,GAAI,MAAM,WAAW,OAAO,EAAE,QAAQ,KAAK,IAAI,CAAC;AAClD,CAAC;AA6FI,MAAM,cAAc,CAAC,WAAuC;AACjE,QAAM,UAAU,CAAC,QAAQ,MAAM,QAAQ,MAAM,QAAQ,UAAU,EAAE,OAAO,CAAC,MAAM,MAAM,MAAS,EAAE;AAChG,MAAI,UAAU,GAAG;AAGf,UAAM,MAAM,IAAI,MAAM,iEAAiE;AACvF,QAAI,OAAO;AACX,WAAO,QAAQ,OAAO,GAAG;AAAA,EAC3B;AACA,SAAO,cAAc,eAAe,SAAS,EAAE,GAAG,OAAO,IAAI,CAAC,CAAC;AACjE;AAiCO,MAAM,gBAAgB,CAAC,SAAgC,cAAc,aAAa,EAAE,KAAK,CAAC;AAI1F,MAAM,YAAY,CAAC,SAAgC,cAAc,SAAS,EAAE,KAAK,CAAC;AAiClF,MAAM,aAAa,CAAC,SAAgC,cAAc,cAAc,EAAE,KAAK,CAAC;AAGxF,MAAM,eAAe,CAAC,SAAgC,cAAc,gBAAgB,EAAE,KAAK,CAAC;AAI5F,MAAM,cAAc,CAAC,SAAgC,cAAc,eAAe,EAAE,KAAK,CAAC;AAI1F,MAAM,cAAc,CAAC,MAAc,OAA8B,cAAc,UAAU,EAAE,MAAM,GAAG,CAAC;AAIrG,MAAM,aAAa,CAAC,MAAc,UAAqC,cAAc,UAAU,EAAE,MAAM,MAAM,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/editor.ts"],"sourcesContent":["import { protocolRequest } from './sandboxUtils';\nimport { throwOnRefusal, type CodedRefusalError } from './protocolRefusal';\nimport { SCHEMES } from './protocolSchemes';\nimport { PROTOCOL_EDITOR } from './generated/protocol';\n\n/**\n * Open a working-tree file in the immediately.run host editor (UI_AS_APPS_SPEC §4 —\n * the file explorer's click-to-open). This is an INTENT: the app asks, the HOST\n * validates the path and drives the CodeMirror editor — the editor itself stays\n * host-owned (§2 recursion boundary), so an app can never own or script it beyond\n * \"please show this file\".\n *\n * Requires the elevated `editor:open` capability — a previewed app does not hold it\n * (it must not move the host's focus), so only a system app whose binding grants it\n * (the file explorer) can call this; anyone else is refused at the gate.\n */\n\n/** An error from {@link openInEditor}, carrying a machine-readable `.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. This interface\n * documents the `.code` VALUES the host sends. Nothing enforces the union at runtime —\n * `.code` is whatever string arrived — so treat an unlisted code as possible and\n * `instanceof Error` as the only reliable test.\n */\nexport interface EditorOpenError extends Error {\n code:\n | 'forbidden' // the frame lacks `editor:open` (or `editor:reveal`, for a `reveal`)\n | 'not-found' // no such file in the live working tree (the host never creates)\n | 'invalid-params' // the path was empty / contained `..` / looked like a URI\n | 'no-target' // there is no host editor session to open files in\n | 'unknown';\n}\n\ntype EditorResult =\n | { ok: true; data: unknown }\n // R3-853: a `too-large` refusal may carry the host's `limitBytes`.\n | { ok: false; code: string; message: string; limitBytes?: number };\n\nconst editorRequest = async (method: string, arg: Record<string, unknown>): Promise<void> => {\n const res = (await protocolRequest(SCHEMES[PROTOCOL_EDITOR], method, [arg])) as EditorResult;\n try {\n throwOnRefusal(res, `editor ${method} failed`);\n } catch (e) {\n // R3-853: a `too-large` refusal may carry the host's `limitBytes` — re-attach\n // it to the thrown error (throwOnRefusal builds a code+message error only).\n // Only ever set by `upload` today; forwarded generically and harmlessly. The\n // `res &&` narrowing guard is load-bearing (review round 1): a null/undefined\n // reply is a coded refusal, never a TypeError from this read (R3-817's property).\n const limit = res && res.ok === false ? res.limitBytes : undefined;\n if (typeof limit === 'number') (e as EditorWriteError).limitBytes = limit;\n throw e;\n }\n};\n\n/** Where in a file to land when opening it (R3-388). 1-indexed `line`, matching every\n * diagnostic producer that feeds it (`tsc`, `eslint`, `BuildError`) and both VS Code\n * and IntelliJ. A `line` past end-of-file CLAMPS to the last line rather than\n * erroring — a diagnostic outlives the edit that shortened the file, and landing\n * close beats refusing to navigate. */\nexport interface EditorSelection {\n line: number;\n column?: number;\n}\n\n/** Options for {@link openInEditor} (R3-389). */\nexport interface EditorOpenOptions {\n /** Also bring the user to the editor, ACROSS activities (TOOLS_ACTIVITY_SPEC §5.2).\n * An app that owns the main pane (the Tools activity's runner sits where the editor\n * would) cannot rely on the file simply becoming visible — the editor is not on\n * screen — so this asks the host to switch to the activity that owns it.\n *\n * This is the elevated `editor:reveal` capability, not `editor:open`: a frame\n * without it is refused `forbidden` for the whole call (the file is NOT opened —\n * never silently opened-without-moving). The host decides whether the user actually\n * moves: it needs a real user gesture (a click in your frame within the last few\n * seconds counts; a call on a timer or on run completion does not) and is\n * rate-limited. The promise resolves the same either way, so treat a resolved\n * reveal as \"asked\", not \"moved\", and keep a visible fallback control. Where the\n * host owns the editor activity is host state; nothing here can name it. */\n reveal?: boolean;\n}\n\n/**\n * Ask the host to open `path` (a repo-relative working-tree path, e.g. `src/App.tsx`\n * or `/src/App.tsx`) in the editor. Resolves once the editor switches to it; rejects\n * with an {@link EditorOpenError} (`.code`) if the path is invalid, missing, or this\n * app may not open files.\n *\n * Pass `selection` to land the caret on a specific line — what a problems list needs\n * to make a diagnostic clickable. It widens nothing: a selection says where to look\n * inside a file the caller could already open, and the capability is unchanged\n * (`editor:open`).\n *\n * Pass `{ reveal: true }` to ALSO bring the user to the editor across activities —\n * see {@link EditorOpenOptions.reveal}; that one does need the elevated\n * `editor:reveal`, and is refused outright without it.\n *\n * Older hosts ignore `selection` and open the file at its existing position, so a\n * caller may pass it unconditionally. `reveal` is only sent when true, so a host that\n * predates it sees a plain open.\n */\nexport const openInEditor = (path: string, selection?: EditorSelection, opts?: EditorOpenOptions): Promise<void> =>\n editorRequest('open', {\n path,\n ...(selection ? { selection } : {}),\n ...(opts?.reveal === true ? { reveal: true } : {}),\n });\n\n/**\n * Where to land when entering the edit experience (EDITOR_FIRST_EDITING_SPEC §6).\n *\n * Three target classes, and **at most one** may be given — supplying more than one is\n * refused `invalid-params` (client-side, before anything is sent). Omit all three to\n * edit the current route's entry.\n *\n * - **Own-source** (`path`): a repo-relative path in the CURRENT repo. Self-scoped —\n * the app you are already running; the host navigates within the current route,\n * never to another repo.\n * - **Mount-file** (`file`): a file in a mount you ALREADY HOLD, opened in the main\n * edit experience (§9, settled 2026-08-28). You can only name a mount you hold: an\n * unheld one is `forbidden`, and indistinguishably so from one that does not exist,\n * because an app must not be able to probe for mounts (no existence oracle).\n * Editing a file *outside* your mounts stays picker-mediated (`pick-file`).\n * - **Bundle-file** (`bundleFile`, R3-876 / APP_CUSTOMIZATION_SPEC §5a): a\n * bundle-relative path inside a directory delegated to you READ-ONLY (an opener's\n * chroot). The host finds which of your held delegations contains it — you never\n * name a mount — and opens the delegation's SOURCE file in the main-pane editor\n * under the READER's authority: your chroot is never upgraded, and no delegation\n * is minted for you. The request needs a real user gesture (transient activation,\n * sampled on the host document) and is refused `no-activation` without one; a\n * path outside every delegation you hold is `forbidden`, indistinguishable from a\n * missing one.\n *\n * A URI, a `..` segment, or a NUL is refused `invalid-params` in any class.\n */\nexport interface EditTarget {\n /** A repo-relative working-tree path in the current repo to focus once in edit\n * mode (e.g. `src/App.tsx`). Omit to edit the current route's entry. */\n path?: string;\n /** A file in one of YOUR OWN mounts, by the portable mount reference. `relPath` is\n * mount-relative and leading-slash (e.g. `/notes/idea.mdx`). Mutually exclusive\n * with {@link EditTarget.path} and {@link EditTarget.bundleFile}.\n *\n * There is no `mode` here on purpose: writability is the HOST's live reading of\n * the mount, not the caller's claim. A `ro` mount — which is also how an anonymous\n * share-link viewer surfaces — is refused `read-only` at call time, before the\n * editor is entered, so you never land in an editor that cannot save. */\n file?: { mountId: string; relPath: string };\n /** A bundle-relative, leading-slash path inside a read-only delegation you hold\n * (R3-876 — see the class note above). Mutually exclusive with\n * {@link EditTarget.path} and {@link EditTarget.file}. */\n bundleFile?: string;\n}\n\n/** An error from {@link requestEdit}, carrying a machine-readable `.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. This interface\n * documents the `.code` VALUES the host sends. Nothing enforces the union at runtime —\n * `.code` is whatever string arrived — so treat an unlisted code as possible and\n * `instanceof Error` as the only reliable test.\n */\nexport interface RequestEditError extends Error {\n code:\n | 'read-only' // editing isn't possible here (a `ro` mount / anonymous viewer; for `bundleFile`: the READER cannot edit the source) — HIDE the affordance\n | 'forbidden' // the host refuses: a cross-repo target, a mount you do not hold, or a `bundleFile` outside every delegation you hold\n | 'invalid-params' // the target was malformed (URI / `..` / NUL / more than one target class at once)\n | 'not-found' // the mount-file/bundle-file target does not exist — and asking did NOT create it\n | 'no-target' // there is no host editor session to enter\n | 'no-activation' // R3-876: a `bundleFile` request without transient user activation on the host document (G-CUST-11) — re-issue from a real click\n | 'cancelled' // the user dismissed an interactive host UX along the way\n | 'unknown';\n}\n\n/**\n * Ask the host to enter the **edit experience** for the app you are running —\n * the present→edit transition (`/present/...` → `/edit/...`) an app cannot make\n * itself. This is an INTENT (§2 recursion boundary): the app asks, the HOST\n * performs the visible, user-observable navigation and draws all editor chrome;\n * the app never navigates or paints chrome.\n *\n * Use it to offer an \"edit this\" affordance from a run/present-mode app that opens\n * the app's own source in the platform editor — instead of shipping a bespoke\n * in-app editor (EDITOR_FIRST_EDITING_SPEC §1).\n *\n * Also opens a file from a mount you already hold, in the main edit experience:\n *\n * await requestEdit({ file: { mountId: 'space:abc', relPath: '/notes/idea.mdx' } });\n *\n * Resolves once the host begins the transition; rejects with a\n * {@link RequestEditError} (`.code`). Treat `read-only`/`forbidden` as \"editing is\n * not available — hide the affordance,\" never as an error to surface to the user.\n * `not-found` means the file is not there; nothing is created by asking to edit it.\n *\n * Naming more than one target class is refused client-side (`invalid-params`),\n * before anything reaches the wire: a precedence rule is a silent reinterpretation\n * of an ambiguous request, and the one thing worse than refusing an edit target is\n * editing a different file than the caller named.\n */\nexport const requestEdit = (target?: EditTarget): Promise<void> => {\n const classes = [target?.path, target?.file, target?.bundleFile].filter((t) => t !== undefined).length;\n if (classes > 1) {\n // Client-side twin of the host gate's three-way rule (R3-876): refuse before\n // the wire so the ambiguous request is never in flight.\n const err = new Error('requestEdit: give at most one of `path`, `file` or `bundleFile`') as CodedRefusalError;\n err.code = 'invalid-params';\n return Promise.reject(err);\n }\n return editorRequest('requestEdit', target ? { ...target } : {});\n};\n\n// ---------------------------------------------------------------------------\n// Editor SESSION management (EDITOR_AS_APP_SPEC §5.1; editor-as-app plan Phase\n// 03). Unlike `openInEditor` (the explorer's cross-app intent, `editor:open`),\n// these drive the editor's OWN open-tab set + active file, so they are gated by\n// the editor app's `editor:document` capability — a file explorer holding only\n// `editor:open` cannot call them. The host re-validates the path against the live\n// working tree; the editor itself stays host-owned (§2 recursion boundary).\n// ---------------------------------------------------------------------------\n\n/** An error from a session intent ({@link setActiveFile} / {@link closeFile}),\n * carrying a machine-readable `.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. This interface\n * documents the `.code` VALUES the host sends. Nothing enforces the union at runtime —\n * `.code` is whatever string arrived — so treat an unlisted code as possible and\n * `instanceof Error` as the only reliable test.\n */\nexport interface EditorSessionError extends Error {\n code:\n | 'forbidden' // the frame lacks `editor:document`\n | 'not-found' // no such file in the live working tree\n | 'invalid-params' // the path was empty / contained `..` / looked like a URI\n | 'no-target' // there is no host editor session\n | 'unknown';\n}\n\n/** Switch the editor's active file to `path`, opening it (adding a tab) if it is\n * not already open — native `setActiveFile` parity. Rejects with an\n * {@link EditorSessionError} (`.code`) if the path is missing/invalid or this app\n * lacks `editor:document`. */\nexport const setActiveFile = (path: string): Promise<void> => editorRequest('setActive', { path });\n\n/** Close `path`'s tab in the editor (remove it from the open set) — native\n * `closeFile` parity. Rejects with an {@link EditorSessionError} (`.code`). */\nexport const closeFile = (path: string): Promise<void> => editorRequest('close', { path });\n\n// ---------------------------------------------------------------------------\n// Working-tree mutation (UI_AS_APPS_SPEC §4 / EDITOR_AS_APP_SPEC §5.2). The file\n// explorer NAMES a working-tree path and the HOST performs the COW write (and\n// refreshes the preview) — the app holds no write port; it asks. Gated by the\n// first-party `editor:write` capability, so only a first-party chrome app (the\n// file explorer) can call these; anyone else is refused at the gate.\n// ---------------------------------------------------------------------------\n\n/** An error from a working-tree mutation, carrying a machine-readable `.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. This interface\n * documents the `.code` VALUES the host sends. Nothing enforces the union at runtime —\n * `.code` is whatever string arrived — so treat an unlisted code as possible and\n * `instanceof Error` as the only reliable test.\n */\nexport interface EditorWriteError extends Error {\n /** R3-853: on a `too-large` refusal, the host's actual limit in bytes — the\n * host names the limit (LARGE_FILE_SUPPORT §3). The SDK forwards it verbatim\n * whenever a refusal carries it; the host sends it only on `too-large`. Absent\n * on an older host. */\n limitBytes?: number;\n code:\n | 'forbidden' // the frame lacks `editor:write` (first-party-only)\n | 'not-found' // the target file/folder does not exist (delete/rename)\n | 'exists' // the target already exists (create/rename would clobber)\n | 'protected' // the host refuses to delete this file (e.g. package.json)\n | 'too-large' // an upload exceeds the host's size limit\n | 'invalid-params' // a path was empty / contained `..` / looked like a URI\n | 'no-target' // there is no host editor session\n | 'unknown';\n}\n\n/** Create an empty working-tree file at `path` and open it. Rejects `exists` if a\n * file is already there — see {@link EditorWriteError} for the full code list, which\n * every helper below shares. */\nexport const createFile = (path: string): Promise<void> => editorRequest('createFile', { path });\n\n/** Create a working-tree folder at `path` (materialised with a `.gitkeep`). */\nexport const createFolder = (path: string): Promise<void> => editorRequest('createFolder', { path });\n\n/** Delete a working-tree file, or a folder and everything under it. Rejects\n * `protected` for files the host won't remove, `not-found` if absent. */\nexport const deleteEntry = (path: string): Promise<void> => editorRequest('deleteEntry', { path });\n\n/** Rename/move a working-tree file from `from` to `to`. Rejects `exists` if `to`\n * is taken, `not-found` if `from` is absent. */\nexport const renameEntry = (from: string, to: string): Promise<void> => editorRequest('rename', { from, to });\n\n/** Upload binary/text `bytes` to a working-tree file at `path`. Rejects\n * `too-large` past the host's size limit — the rejection carries the limit as\n * `err.limitBytes` (R3-853: the host names the limit; absent on an older host).\n * The bytes are transferred (zero-copy). */\nexport const uploadFile = (path: string, bytes: Uint8Array): Promise<void> => editorRequest('upload', { path, bytes });\n"],"mappings":";AAAA,SAAS,uBAAuB;AAChC,SAAS,sBAA8C;AACvD,SAAS,eAAe;AACxB,SAAS,uBAAuB;AAoChC,MAAM,gBAAgB,OAAO,QAAgB,QAAgD;AAC3F,QAAM,MAAO,MAAM,gBAAgB,QAAQ,eAAe,GAAG,QAAQ,CAAC,GAAG,CAAC;AAC1E,MAAI;AACF,mBAAe,KAAK,UAAU,MAAM,SAAS;AAAA,EAC/C,SAAS,GAAG;AAMV,UAAM,QAAQ,OAAO,IAAI,OAAO,QAAQ,IAAI,aAAa;AACzD,QAAI,OAAO,UAAU,SAAU,CAAC,EAAuB,aAAa;AACpE,UAAM;AAAA,EACR;AACF;AAiDO,MAAM,eAAe,CAAC,MAAc,WAA6B,SACtE,cAAc,QAAQ;AAAA,EACpB;AAAA,EACA,GAAI,YAAY,EAAE,UAAU,IAAI,CAAC;AAAA,EACjC,GAAI,MAAM,WAAW,OAAO,EAAE,QAAQ,KAAK,IAAI,CAAC;AAClD,CAAC;AA6FI,MAAM,cAAc,CAAC,WAAuC;AACjE,QAAM,UAAU,CAAC,QAAQ,MAAM,QAAQ,MAAM,QAAQ,UAAU,EAAE,OAAO,CAAC,MAAM,MAAM,MAAS,EAAE;AAChG,MAAI,UAAU,GAAG;AAGf,UAAM,MAAM,IAAI,MAAM,iEAAiE;AACvF,QAAI,OAAO;AACX,WAAO,QAAQ,OAAO,GAAG;AAAA,EAC3B;AACA,SAAO,cAAc,eAAe,SAAS,EAAE,GAAG,OAAO,IAAI,CAAC,CAAC;AACjE;AAiCO,MAAM,gBAAgB,CAAC,SAAgC,cAAc,aAAa,EAAE,KAAK,CAAC;AAI1F,MAAM,YAAY,CAAC,SAAgC,cAAc,SAAS,EAAE,KAAK,CAAC;AAsClF,MAAM,aAAa,CAAC,SAAgC,cAAc,cAAc,EAAE,KAAK,CAAC;AAGxF,MAAM,eAAe,CAAC,SAAgC,cAAc,gBAAgB,EAAE,KAAK,CAAC;AAI5F,MAAM,cAAc,CAAC,SAAgC,cAAc,eAAe,EAAE,KAAK,CAAC;AAI1F,MAAM,cAAc,CAAC,MAAc,OAA8B,cAAc,UAAU,EAAE,MAAM,GAAG,CAAC;AAMrG,MAAM,aAAa,CAAC,MAAc,UAAqC,cAAc,UAAU,EAAE,MAAM,MAAM,CAAC;","names":[]}
|
package/dist/netFetch.cjs
CHANGED
|
@@ -29,7 +29,13 @@ var import_protocolSchemes = require("./protocolSchemes");
|
|
|
29
29
|
var import_protocol = require("./generated/protocol");
|
|
30
30
|
const hostFetch = async (url, init = {}) => {
|
|
31
31
|
const res = await (0, import_sandboxUtils.protocolRequest)(import_protocolSchemes.SCHEMES[import_protocol.PROTOCOL_FETCH], "fetch", [
|
|
32
|
-
{
|
|
32
|
+
{
|
|
33
|
+
url,
|
|
34
|
+
method: init.method,
|
|
35
|
+
headers: init.headers,
|
|
36
|
+
body: init.body,
|
|
37
|
+
...init.responseType ? { responseType: init.responseType } : {}
|
|
38
|
+
}
|
|
33
39
|
]);
|
|
34
40
|
(0, import_protocolRefusal.throwOnRefusal)(res, "hostFetch failed");
|
|
35
41
|
return res.data;
|
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 { 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 {
|
|
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 /** R3-861: `'bytes'` returns the exact response bytes in `bodyBytes` (an image,\n * a PDF — never text-decoded). Default `'text'`, unchanged. A bytes response\n * over the host's size cap is REFUSED `too-large`, never truncated. */\n responseType?: 'text' | 'bytes';\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 /** The text body — `''` when the request asked for bytes. */\n body: string;\n /** True if the body hit the host's size cap and was truncated (text mode only —\n * bytes mode refuses `too-large` instead). */\n truncated: boolean;\n /** R3-861: the exact response bytes when the request said `responseType: 'bytes'`\n * (transferred, zero-copy). */\n bodyBytes?: Uint8Array;\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 {\n url,\n method: init.method,\n headers: init.headers,\n body: init.body,\n ...(init.responseType ? { responseType: init.responseType } : {}),\n },\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;AAwCxB,MAAM,YAAY,OAAO,KAAa,OAAsB,CAAC,MAAkC;AACpG,QAAM,MAAO,UAAM,qCAAgB,+BAAQ,8BAAc,GAAG,SAAS;AAAA,IACnE;AAAA,MACE;AAAA,MACA,QAAQ,KAAK;AAAA,MACb,SAAS,KAAK;AAAA,MACd,MAAM,KAAK;AAAA,MACX,GAAI,KAAK,eAAe,EAAE,cAAc,KAAK,aAAa,IAAI,CAAC;AAAA,IACjE;AAAA,EACF,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.d.cts
CHANGED
|
@@ -4,15 +4,24 @@ interface HostFetchInit {
|
|
|
4
4
|
headers?: Record<string, string>;
|
|
5
5
|
/** Request body for non-GET/HEAD methods (string). */
|
|
6
6
|
body?: string;
|
|
7
|
+
/** R3-861: `'bytes'` returns the exact response bytes in `bodyBytes` (an image,
|
|
8
|
+
* a PDF — never text-decoded). Default `'text'`, unchanged. A bytes response
|
|
9
|
+
* over the host's size cap is REFUSED `too-large`, never truncated. */
|
|
10
|
+
responseType?: 'text' | 'bytes';
|
|
7
11
|
}
|
|
8
12
|
/** The serialized response from {@link hostFetch} (no live stream crosses the boundary). */
|
|
9
13
|
interface HostFetchResponse {
|
|
10
14
|
status: number;
|
|
11
15
|
statusText: string;
|
|
12
16
|
headers: Record<string, string>;
|
|
17
|
+
/** The text body — `''` when the request asked for bytes. */
|
|
13
18
|
body: string;
|
|
14
|
-
/** True if the body hit the host's size cap and was truncated
|
|
19
|
+
/** True if the body hit the host's size cap and was truncated (text mode only —
|
|
20
|
+
* bytes mode refuses `too-large` instead). */
|
|
15
21
|
truncated: boolean;
|
|
22
|
+
/** R3-861: the exact response bytes when the request said `responseType: 'bytes'`
|
|
23
|
+
* (transferred, zero-copy). */
|
|
24
|
+
bodyBytes?: Uint8Array;
|
|
16
25
|
}
|
|
17
26
|
/**
|
|
18
27
|
* Fetch through the host's parent-fetch proxy (§5.11). Requires the `net:fetch`
|
package/dist/netFetch.d.ts
CHANGED
|
@@ -4,15 +4,24 @@ interface HostFetchInit {
|
|
|
4
4
|
headers?: Record<string, string>;
|
|
5
5
|
/** Request body for non-GET/HEAD methods (string). */
|
|
6
6
|
body?: string;
|
|
7
|
+
/** R3-861: `'bytes'` returns the exact response bytes in `bodyBytes` (an image,
|
|
8
|
+
* a PDF — never text-decoded). Default `'text'`, unchanged. A bytes response
|
|
9
|
+
* over the host's size cap is REFUSED `too-large`, never truncated. */
|
|
10
|
+
responseType?: 'text' | 'bytes';
|
|
7
11
|
}
|
|
8
12
|
/** The serialized response from {@link hostFetch} (no live stream crosses the boundary). */
|
|
9
13
|
interface HostFetchResponse {
|
|
10
14
|
status: number;
|
|
11
15
|
statusText: string;
|
|
12
16
|
headers: Record<string, string>;
|
|
17
|
+
/** The text body — `''` when the request asked for bytes. */
|
|
13
18
|
body: string;
|
|
14
|
-
/** True if the body hit the host's size cap and was truncated
|
|
19
|
+
/** True if the body hit the host's size cap and was truncated (text mode only —
|
|
20
|
+
* bytes mode refuses `too-large` instead). */
|
|
15
21
|
truncated: boolean;
|
|
22
|
+
/** R3-861: the exact response bytes when the request said `responseType: 'bytes'`
|
|
23
|
+
* (transferred, zero-copy). */
|
|
24
|
+
bodyBytes?: Uint8Array;
|
|
16
25
|
}
|
|
17
26
|
/**
|
|
18
27
|
* Fetch through the host's parent-fetch proxy (§5.11). Requires the `net:fetch`
|
package/dist/netFetch.js
CHANGED
|
@@ -6,7 +6,13 @@ import { SCHEMES } from "./protocolSchemes.js";
|
|
|
6
6
|
import { PROTOCOL_FETCH } from "./generated/protocol.js";
|
|
7
7
|
const hostFetch = async (url, init = {}) => {
|
|
8
8
|
const res = await protocolRequest(SCHEMES[PROTOCOL_FETCH], "fetch", [
|
|
9
|
-
{
|
|
9
|
+
{
|
|
10
|
+
url,
|
|
11
|
+
method: init.method,
|
|
12
|
+
headers: init.headers,
|
|
13
|
+
body: init.body,
|
|
14
|
+
...init.responseType ? { responseType: init.responseType } : {}
|
|
15
|
+
}
|
|
10
16
|
]);
|
|
11
17
|
throwOnRefusal(res, "hostFetch failed");
|
|
12
18
|
return res.data;
|
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 { 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 {
|
|
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 /** R3-861: `'bytes'` returns the exact response bytes in `bodyBytes` (an image,\n * a PDF — never text-decoded). Default `'text'`, unchanged. A bytes response\n * over the host's size cap is REFUSED `too-large`, never truncated. */\n responseType?: 'text' | 'bytes';\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 /** The text body — `''` when the request asked for bytes. */\n body: string;\n /** True if the body hit the host's size cap and was truncated (text mode only —\n * bytes mode refuses `too-large` instead). */\n truncated: boolean;\n /** R3-861: the exact response bytes when the request said `responseType: 'bytes'`\n * (transferred, zero-copy). */\n bodyBytes?: Uint8Array;\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 {\n url,\n method: init.method,\n headers: init.headers,\n body: init.body,\n ...(init.responseType ? { responseType: init.responseType } : {}),\n },\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;AAwCxB,MAAM,YAAY,OAAO,KAAa,OAAsB,CAAC,MAAkC;AACpG,QAAM,MAAO,MAAM,gBAAgB,QAAQ,cAAc,GAAG,SAAS;AAAA,IACnE;AAAA,MACE;AAAA,MACA,QAAQ,KAAK;AAAA,MACb,SAAS,KAAK;AAAA,MACd,MAAM,KAAK;AAAA,MACX,GAAI,KAAK,eAAe,EAAE,cAAc,KAAK,aAAa,IAAI,CAAC;AAAA,IACjE;AAAA,EACF,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":[]}
|
package/dist/version.cjs
CHANGED
|
@@ -21,7 +21,7 @@ __export(version_exports, {
|
|
|
21
21
|
SDK_VERSION: () => SDK_VERSION
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(version_exports);
|
|
24
|
-
const SDK_VERSION = "0.
|
|
24
|
+
const SDK_VERSION = "0.82.0";
|
|
25
25
|
// Annotate the CommonJS export names for ESM import in node:
|
|
26
26
|
0 && (module.exports = {
|
|
27
27
|
SDK_VERSION
|
package/dist/version.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/version.ts"],"sourcesContent":["// GENERATED by scripts/gen-version.mjs from package.json — do not edit by hand.\n// Regenerated on every build (prebuild); kept honest by version.test.ts.\n\n/** This SDK's package version, baked from package.json at build (SP2-6). */\nexport const SDK_VERSION = '0.
|
|
1
|
+
{"version":3,"sources":["../src/version.ts"],"sourcesContent":["// GENERATED by scripts/gen-version.mjs from package.json — do not edit by hand.\n// Regenerated on every build (prebuild); kept honest by version.test.ts.\n\n/** This SDK's package version, baked from package.json at build (SP2-6). */\nexport const SDK_VERSION = '0.82.0';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIO,MAAM,cAAc;","names":[]}
|
package/dist/version.d.cts
CHANGED
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/dist/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/version.ts"],"sourcesContent":["// GENERATED by scripts/gen-version.mjs from package.json — do not edit by hand.\n// Regenerated on every build (prebuild); kept honest by version.test.ts.\n\n/** This SDK's package version, baked from package.json at build (SP2-6). */\nexport const SDK_VERSION = '0.
|
|
1
|
+
{"version":3,"sources":["../src/version.ts"],"sourcesContent":["// GENERATED by scripts/gen-version.mjs from package.json — do not edit by hand.\n// Regenerated on every build (prebuild); kept honest by version.test.ts.\n\n/** This SDK's package version, baked from package.json at build (SP2-6). */\nexport const SDK_VERSION = '0.82.0';\n"],"mappings":";AAIO,MAAM,cAAc;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@immediately-run/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.82.0",
|
|
4
4
|
"description": "Runtime SDK for code executing inside an immediately.run sandbox.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "github:immediately-run/immediately-run-sdk",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"check:clones": "node scripts/check-clones.mjs",
|
|
47
47
|
"check:unused": "node scripts/check-unused.mjs",
|
|
48
48
|
"check:untested": "node scripts/check-untested.mjs",
|
|
49
|
-
"verify": "npm run check:lock-version && npm run check:pins && npm run check:publish-version && npm run check:published && npm run check:verify-parity && npm run format:check && npm run check:circular && npm run check:clones && npm run check:unused && npm run check:untested && npm run check:bundler:selftest && npm run check:bundler && npm run build && npm run check:published && npm run check:reproducible && npm test && npm run test:safe-content && npm run test:metadata-e2e && npm run test:subpath-imports && npm run api:selftest && npm run api:check && npm run compat:selftest && npm run compat:previous && npm run protocol:check && npm run protocol:selftest && npm run check:ambient:selftest && npm run check:ambient && npm run check:selfhost:selftest && npm run check:selfhost && npm run check:dist-specifiers:selftest && npm run verify:codegen-parity && npm run verify:descriptor-lockstep",
|
|
49
|
+
"verify": "npm run check:lock-version && npm run check:pins && npm run check:publish-version && npm run check:published && npm run check:verify-parity && npm run format:check && npm run check:circular && npm run check:clones && npm run check:unused && npm run check:untested && npm run check:bundler:selftest && npm run check:bundler && npm run build && npm run check:published && npm run check:reproducible && npm test && npm run test:safe-content && npm run test:metadata-e2e && npm run test:subpath-imports && npm run test:netfetch-bytes-e2e && npm run api:selftest && npm run api:check && npm run compat:selftest && npm run compat:previous && npm run protocol:check && npm run protocol:selftest && npm run check:ambient:selftest && npm run check:ambient && npm run check:selfhost:selftest && npm run check:selfhost && npm run check:dist-specifiers:selftest && npm run verify:codegen-parity && npm run verify:descriptor-lockstep",
|
|
50
50
|
"docs": "typedoc --json docs/api.json && node scripts/gen-descriptor-docs.mjs && node scripts/gen-llms.mjs",
|
|
51
51
|
"prepublishOnly": "npm run check:circular && npm run build && npm run api:selftest && npm run api:check",
|
|
52
52
|
"test:safe-content": "node scripts/build-safecontent-e2e.mjs && node --test test/safeContent.e2e.mjs",
|
|
@@ -63,7 +63,8 @@
|
|
|
63
63
|
"check:ambient": "node scripts/check-ambient-types.mjs",
|
|
64
64
|
"check:dist-specifiers:selftest": "node scripts/fix-dist-esm-specifiers.mjs --self-test",
|
|
65
65
|
"check:ambient:selftest": "node scripts/check-ambient-types.mjs --self-test",
|
|
66
|
-
"check:lock-version": "node scripts/check-lock-version.mjs --self-test && node scripts/check-lock-version.mjs"
|
|
66
|
+
"check:lock-version": "node scripts/check-lock-version.mjs --self-test && node scripts/check-lock-version.mjs",
|
|
67
|
+
"test:netfetch-bytes-e2e": "node --test test/netFetchBytes.e2e.mjs"
|
|
67
68
|
},
|
|
68
69
|
"peerDependencies": {
|
|
69
70
|
"react": "^19.0.0",
|
|
@@ -73,7 +74,7 @@
|
|
|
73
74
|
"@immediately-run/mdx-plugins": "0.7.1",
|
|
74
75
|
"@immediately-run/platform-constants": "0.2.0",
|
|
75
76
|
"@immediately-run/safe-content": "0.1.0",
|
|
76
|
-
"@immediately-run/sandbox-protocol": "^0.
|
|
77
|
+
"@immediately-run/sandbox-protocol": "^0.18.0",
|
|
77
78
|
"react-error-boundary": "^6.0.0"
|
|
78
79
|
},
|
|
79
80
|
"devDependencies": {
|