@immediately-run/sdk 0.74.1 → 0.74.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dnd.cjs.map +1 -1
- package/dist/dnd.d.cts +3 -3
- package/dist/dnd.d.ts +3 -3
- package/dist/dnd.js.map +1 -1
- package/dist/editor.cjs.map +1 -1
- package/dist/editor.d.cts +12 -12
- package/dist/editor.d.ts +12 -12
- package/dist/editor.js.map +1 -1
- package/dist/feed.cjs +2 -5
- package/dist/feed.cjs.map +1 -1
- package/dist/feed.js +2 -5
- package/dist/feed.js.map +1 -1
- package/dist/mounts.cjs.map +1 -1
- package/dist/mounts.d.cts +3 -3
- package/dist/mounts.d.ts +3 -3
- package/dist/mounts.js.map +1 -1
- package/dist/netFetch.cjs +2 -5
- package/dist/netFetch.cjs.map +1 -1
- package/dist/netFetch.js +2 -5
- package/dist/netFetch.js.map +1 -1
- package/dist/openExternal.cjs.map +1 -1
- package/dist/openExternal.d.cts +9 -3
- package/dist/openExternal.d.ts +9 -3
- package/dist/openExternal.js.map +1 -1
- package/dist/openRepository.cjs.map +1 -1
- package/dist/openRepository.d.cts +9 -3
- package/dist/openRepository.d.ts +9 -3
- package/dist/openRepository.js.map +1 -1
- package/dist/protocolRefusal.cjs.map +1 -1
- package/dist/protocolRefusal.d.cts +31 -10
- package/dist/protocolRefusal.d.ts +31 -10
- package/dist/protocolRefusal.js.map +1 -1
- package/dist/secrets.cjs.map +1 -1
- package/dist/secrets.d.cts +3 -3
- package/dist/secrets.d.ts +3 -3
- package/dist/secrets.js.map +1 -1
- package/dist/spacesMode.cjs.map +1 -1
- package/dist/spacesMode.d.cts +9 -3
- package/dist/spacesMode.d.ts +9 -3
- package/dist/spacesMode.js.map +1 -1
- package/dist/theme.cjs +4 -15
- package/dist/theme.cjs.map +1 -1
- package/dist/theme.js +4 -15
- package/dist/theme.js.map +1 -1
- package/dist/vcs.cjs.map +1 -1
- package/dist/vcs.d.cts +3 -3
- package/dist/vcs.d.ts +3 -3
- package/dist/vcs.js.map +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.d.cts +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +1 -1
package/dist/dnd.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/dnd.ts"],"sourcesContent":["// Cross-app drag-out (FILE_EXPLORER_SPEC §7; UI_AS_APPS_SPEC §2 host-mediated).\n//\n// Native HTML5 drag-and-drop does NOT cross the sandboxed cross-origin iframe\n// boundary, and pointer events inside one app's iframe never reach the host or a\n// sibling. So a drag that STARTS in one app (the file explorer) and ENDS over\n// another (the previewed app) can only be mediated by the host (the TCB). This\n// module is the SDK surface for that one net-new platform primitive:\n//\n// - SOURCE side (the file explorer, needs the first-party `dnd:source` cap):\n// `startItemDrag(item)` asks the host to begin a host-mediated drag carrying a\n// file/dir reference (+ optional inlined bytes for a small file). The host draws\n// the trusted drag ghost, tracks the pointer across regions, and on drop over the\n// preview delivers the item to that app. `cancelItemDrag()` aborts.\n// - RECEIVER side (the previewed app, NO new grant — it opts in by subscribing):\n// `onItemDrop(cb)` / `useDroppedItem()` deliver the dropped item with host-attached,\n// unspoofable provenance (`from` = source region id) and the drop position.\n//\n// The payload is UNTRUSTED app data (CLAUDE.md §5): the host attaches `from`; the app\n// validates everything else. v1 inlines bytes only for small files (the source can\n// only relay data it can already read — no new read authority is minted).\nimport { useEffect, useState } from 'react';\nimport { throwOnRefusal } from './protocolRefusal';\nimport { protocolRequest, sendMessage, addListener } from './sandboxUtils';\nimport { DND_CANCEL, DROPPED_ITEM, PROTOCOL_DND } from './generated/protocol';\nimport { SCHEMES } from './protocolSchemes';\n\n/** A file/dir being dragged out of an app. `bytes` is present only for a small file\n * the source chose to inline (transferred zero-copy); a dir or an over-cap file\n * carries the reference only (`kind`/`name`/`mountId`/`relPath`). */\nexport interface DraggableItem {\n kind: 'file' | 'dir';\n /** Basename — display only. */\n name: string;\n /** Which mounted filesystem the item lives in. */\n mountId: string;\n /** Path within that mount (leading slash, no `..`). */\n relPath: string;\n /** Optional inlined content for a small file. */\n bytes?: Uint8Array;\n}\n\n/** An item dropped onto THIS app by a host-mediated cross-app drag. */\nexport interface DroppedItem {\n /** The dragged item (`bytes` present iff the source inlined them). */\n item: DraggableItem;\n /** Host-attached source region id — unspoofable (T19), like an `ipc` `from`. */\n from: string;\n /** Drop point in this app's viewport. */\n position: { x: number; y: number };\n}\n\n/** An error from {@link startItemDrag}, 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
|
|
1
|
+
{"version":3,"sources":["../src/dnd.ts"],"sourcesContent":["// Cross-app drag-out (FILE_EXPLORER_SPEC §7; UI_AS_APPS_SPEC §2 host-mediated).\n//\n// Native HTML5 drag-and-drop does NOT cross the sandboxed cross-origin iframe\n// boundary, and pointer events inside one app's iframe never reach the host or a\n// sibling. So a drag that STARTS in one app (the file explorer) and ENDS over\n// another (the previewed app) can only be mediated by the host (the TCB). This\n// module is the SDK surface for that one net-new platform primitive:\n//\n// - SOURCE side (the file explorer, needs the first-party `dnd:source` cap):\n// `startItemDrag(item)` asks the host to begin a host-mediated drag carrying a\n// file/dir reference (+ optional inlined bytes for a small file). The host draws\n// the trusted drag ghost, tracks the pointer across regions, and on drop over the\n// preview delivers the item to that app. `cancelItemDrag()` aborts.\n// - RECEIVER side (the previewed app, NO new grant — it opts in by subscribing):\n// `onItemDrop(cb)` / `useDroppedItem()` deliver the dropped item with host-attached,\n// unspoofable provenance (`from` = source region id) and the drop position.\n//\n// The payload is UNTRUSTED app data (CLAUDE.md §5): the host attaches `from`; the app\n// validates everything else. v1 inlines bytes only for small files (the source can\n// only relay data it can already read — no new read authority is minted).\nimport { useEffect, useState } from 'react';\nimport { throwOnRefusal } from './protocolRefusal';\nimport { protocolRequest, sendMessage, addListener } from './sandboxUtils';\nimport { DND_CANCEL, DROPPED_ITEM, PROTOCOL_DND } from './generated/protocol';\nimport { SCHEMES } from './protocolSchemes';\n\n/** A file/dir being dragged out of an app. `bytes` is present only for a small file\n * the source chose to inline (transferred zero-copy); a dir or an over-cap file\n * carries the reference only (`kind`/`name`/`mountId`/`relPath`). */\nexport interface DraggableItem {\n kind: 'file' | 'dir';\n /** Basename — display only. */\n name: string;\n /** Which mounted filesystem the item lives in. */\n mountId: string;\n /** Path within that mount (leading slash, no `..`). */\n relPath: string;\n /** Optional inlined content for a small file. */\n bytes?: Uint8Array;\n}\n\n/** An item dropped onto THIS app by a host-mediated cross-app drag. */\nexport interface DroppedItem {\n /** The dragged item (`bytes` present iff the source inlined them). */\n item: DraggableItem;\n /** Host-attached source region id — unspoofable (T19), like an `ipc` `from`. */\n from: string;\n /** Drop point in this app's viewport. */\n position: { x: number; y: number };\n}\n\n/** An error from {@link startItemDrag}, 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 ItemDragError extends Error {\n code:\n | 'forbidden' // the frame lacks the first-party `dnd:source` capability\n | 'invalid-params' // the item was malformed (empty path / `..` / URI / bad kind)\n | 'too-large' // inlined `bytes` exceed the host's size limit\n | 'rate-limited' // too many drags started too fast (capacity-class, fail-open)\n | 'unknown';\n}\n\n/**\n * Begin a host-mediated drag of `item` out of this app. Resolves once the host has\n * taken over the drag (drawn the ghost, installed the pointer-capture layer); rejects\n * with an {@link ItemDragError} if this app may not initiate drags (`forbidden`) or the\n * item is invalid. Only a first-party chrome app holding `dnd:source` may call this — a\n * previewed/third-party app is refused at the gate (it must not synthesize drags into\n * sibling apps).\n */\nexport const startItemDrag = async (item: DraggableItem): Promise<void> => {\n const res = (await protocolRequest(SCHEMES[PROTOCOL_DND], 'startDrag', [item])) as\n | { ok: true }\n | { ok: false; code?: string; message?: string }\n | undefined;\n throwOnRefusal(res, 'dnd startDrag failed');\n};\n\n/** Abort an in-progress host-mediated drag this app started (e.g. the user pressed\n * Escape, or the gesture was cancelled). Best-effort and fire-and-forget. */\nexport const cancelItemDrag = (): void => {\n sendMessage(DND_CANCEL, {});\n};\n\n/** Subscribe to items dropped onto this app by a host-mediated cross-app drag.\n * Returns an unsubscribe fn. Subscribing is the opt-in: an app that never subscribes\n * receives nothing (the host shows a \"not accepted\" cue and the drop is a no-op). */\nexport const onItemDrop = (listener: (d: DroppedItem) => void): (() => void) =>\n addListener(DROPPED_ITEM, (m: { item: DraggableItem; from: string; position: { x: number; y: number } }) =>\n listener({ item: m.item, from: m.from, position: m.position }),\n );\n\n/** React hook: the most recently dropped item (or `null`). */\nexport const useDroppedItem = (): DroppedItem | null => {\n const [dropped, setDropped] = useState<DroppedItem | null>(null);\n useEffect(() => onItemDrop(setDropped), []);\n return dropped;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBA,mBAAoC;AACpC,6BAA+B;AAC/B,0BAA0D;AAC1D,sBAAuD;AACvD,6BAAwB;AAoDjB,MAAM,gBAAgB,OAAO,SAAuC;AACzE,QAAM,MAAO,UAAM,qCAAgB,+BAAQ,4BAAY,GAAG,aAAa,CAAC,IAAI,CAAC;AAI7E,6CAAe,KAAK,sBAAsB;AAC5C;AAIO,MAAM,iBAAiB,MAAY;AACxC,uCAAY,4BAAY,CAAC,CAAC;AAC5B;AAKO,MAAM,aAAa,CAAC,iBACzB;AAAA,EAAY;AAAA,EAAc,CAAC,MACzB,SAAS,EAAE,MAAM,EAAE,MAAM,MAAM,EAAE,MAAM,UAAU,EAAE,SAAS,CAAC;AAC/D;AAGK,MAAM,iBAAiB,MAA0B;AACtD,QAAM,CAAC,SAAS,UAAU,QAAI,uBAA6B,IAAI;AAC/D,8BAAU,MAAM,WAAW,UAAU,GAAG,CAAC,CAAC;AAC1C,SAAO;AACT;","names":[]}
|
package/dist/dnd.d.cts
CHANGED
|
@@ -28,9 +28,9 @@ interface DroppedItem {
|
|
|
28
28
|
*
|
|
29
29
|
* **What you actually catch.** The SDK throws a plain `Error` with `.code` assigned — a
|
|
30
30
|
* `CodedRefusalError` from `protocolRefusal.ts` — never a distinct class. This interface
|
|
31
|
-
* documents the `.code` VALUES the host sends
|
|
32
|
-
*
|
|
33
|
-
* reliable test.
|
|
31
|
+
* documents the `.code` VALUES the host sends. Nothing enforces the union at runtime —
|
|
32
|
+
* `.code` is whatever string arrived — so treat an unlisted code as possible and
|
|
33
|
+
* `instanceof Error` as the only reliable test.
|
|
34
34
|
*/
|
|
35
35
|
interface ItemDragError extends Error {
|
|
36
36
|
code: 'forbidden' | 'invalid-params' | 'too-large' | 'rate-limited' | 'unknown';
|
package/dist/dnd.d.ts
CHANGED
|
@@ -28,9 +28,9 @@ interface DroppedItem {
|
|
|
28
28
|
*
|
|
29
29
|
* **What you actually catch.** The SDK throws a plain `Error` with `.code` assigned — a
|
|
30
30
|
* `CodedRefusalError` from `protocolRefusal.ts` — never a distinct class. This interface
|
|
31
|
-
* documents the `.code` VALUES the host sends
|
|
32
|
-
*
|
|
33
|
-
* reliable test.
|
|
31
|
+
* documents the `.code` VALUES the host sends. Nothing enforces the union at runtime —
|
|
32
|
+
* `.code` is whatever string arrived — so treat an unlisted code as possible and
|
|
33
|
+
* `instanceof Error` as the only reliable test.
|
|
34
34
|
*/
|
|
35
35
|
interface ItemDragError extends Error {
|
|
36
36
|
code: 'forbidden' | 'invalid-params' | 'too-large' | 'rate-limited' | 'unknown';
|
package/dist/dnd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/dnd.ts"],"sourcesContent":["// Cross-app drag-out (FILE_EXPLORER_SPEC §7; UI_AS_APPS_SPEC §2 host-mediated).\n//\n// Native HTML5 drag-and-drop does NOT cross the sandboxed cross-origin iframe\n// boundary, and pointer events inside one app's iframe never reach the host or a\n// sibling. So a drag that STARTS in one app (the file explorer) and ENDS over\n// another (the previewed app) can only be mediated by the host (the TCB). This\n// module is the SDK surface for that one net-new platform primitive:\n//\n// - SOURCE side (the file explorer, needs the first-party `dnd:source` cap):\n// `startItemDrag(item)` asks the host to begin a host-mediated drag carrying a\n// file/dir reference (+ optional inlined bytes for a small file). The host draws\n// the trusted drag ghost, tracks the pointer across regions, and on drop over the\n// preview delivers the item to that app. `cancelItemDrag()` aborts.\n// - RECEIVER side (the previewed app, NO new grant — it opts in by subscribing):\n// `onItemDrop(cb)` / `useDroppedItem()` deliver the dropped item with host-attached,\n// unspoofable provenance (`from` = source region id) and the drop position.\n//\n// The payload is UNTRUSTED app data (CLAUDE.md §5): the host attaches `from`; the app\n// validates everything else. v1 inlines bytes only for small files (the source can\n// only relay data it can already read — no new read authority is minted).\nimport { useEffect, useState } from 'react';\nimport { throwOnRefusal } from './protocolRefusal';\nimport { protocolRequest, sendMessage, addListener } from './sandboxUtils';\nimport { DND_CANCEL, DROPPED_ITEM, PROTOCOL_DND } from './generated/protocol';\nimport { SCHEMES } from './protocolSchemes';\n\n/** A file/dir being dragged out of an app. `bytes` is present only for a small file\n * the source chose to inline (transferred zero-copy); a dir or an over-cap file\n * carries the reference only (`kind`/`name`/`mountId`/`relPath`). */\nexport interface DraggableItem {\n kind: 'file' | 'dir';\n /** Basename — display only. */\n name: string;\n /** Which mounted filesystem the item lives in. */\n mountId: string;\n /** Path within that mount (leading slash, no `..`). */\n relPath: string;\n /** Optional inlined content for a small file. */\n bytes?: Uint8Array;\n}\n\n/** An item dropped onto THIS app by a host-mediated cross-app drag. */\nexport interface DroppedItem {\n /** The dragged item (`bytes` present iff the source inlined them). */\n item: DraggableItem;\n /** Host-attached source region id — unspoofable (T19), like an `ipc` `from`. */\n from: string;\n /** Drop point in this app's viewport. */\n position: { x: number; y: number };\n}\n\n/** An error from {@link startItemDrag}, 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
|
|
1
|
+
{"version":3,"sources":["../src/dnd.ts"],"sourcesContent":["// Cross-app drag-out (FILE_EXPLORER_SPEC §7; UI_AS_APPS_SPEC §2 host-mediated).\n//\n// Native HTML5 drag-and-drop does NOT cross the sandboxed cross-origin iframe\n// boundary, and pointer events inside one app's iframe never reach the host or a\n// sibling. So a drag that STARTS in one app (the file explorer) and ENDS over\n// another (the previewed app) can only be mediated by the host (the TCB). This\n// module is the SDK surface for that one net-new platform primitive:\n//\n// - SOURCE side (the file explorer, needs the first-party `dnd:source` cap):\n// `startItemDrag(item)` asks the host to begin a host-mediated drag carrying a\n// file/dir reference (+ optional inlined bytes for a small file). The host draws\n// the trusted drag ghost, tracks the pointer across regions, and on drop over the\n// preview delivers the item to that app. `cancelItemDrag()` aborts.\n// - RECEIVER side (the previewed app, NO new grant — it opts in by subscribing):\n// `onItemDrop(cb)` / `useDroppedItem()` deliver the dropped item with host-attached,\n// unspoofable provenance (`from` = source region id) and the drop position.\n//\n// The payload is UNTRUSTED app data (CLAUDE.md §5): the host attaches `from`; the app\n// validates everything else. v1 inlines bytes only for small files (the source can\n// only relay data it can already read — no new read authority is minted).\nimport { useEffect, useState } from 'react';\nimport { throwOnRefusal } from './protocolRefusal';\nimport { protocolRequest, sendMessage, addListener } from './sandboxUtils';\nimport { DND_CANCEL, DROPPED_ITEM, PROTOCOL_DND } from './generated/protocol';\nimport { SCHEMES } from './protocolSchemes';\n\n/** A file/dir being dragged out of an app. `bytes` is present only for a small file\n * the source chose to inline (transferred zero-copy); a dir or an over-cap file\n * carries the reference only (`kind`/`name`/`mountId`/`relPath`). */\nexport interface DraggableItem {\n kind: 'file' | 'dir';\n /** Basename — display only. */\n name: string;\n /** Which mounted filesystem the item lives in. */\n mountId: string;\n /** Path within that mount (leading slash, no `..`). */\n relPath: string;\n /** Optional inlined content for a small file. */\n bytes?: Uint8Array;\n}\n\n/** An item dropped onto THIS app by a host-mediated cross-app drag. */\nexport interface DroppedItem {\n /** The dragged item (`bytes` present iff the source inlined them). */\n item: DraggableItem;\n /** Host-attached source region id — unspoofable (T19), like an `ipc` `from`. */\n from: string;\n /** Drop point in this app's viewport. */\n position: { x: number; y: number };\n}\n\n/** An error from {@link startItemDrag}, 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 ItemDragError extends Error {\n code:\n | 'forbidden' // the frame lacks the first-party `dnd:source` capability\n | 'invalid-params' // the item was malformed (empty path / `..` / URI / bad kind)\n | 'too-large' // inlined `bytes` exceed the host's size limit\n | 'rate-limited' // too many drags started too fast (capacity-class, fail-open)\n | 'unknown';\n}\n\n/**\n * Begin a host-mediated drag of `item` out of this app. Resolves once the host has\n * taken over the drag (drawn the ghost, installed the pointer-capture layer); rejects\n * with an {@link ItemDragError} if this app may not initiate drags (`forbidden`) or the\n * item is invalid. Only a first-party chrome app holding `dnd:source` may call this — a\n * previewed/third-party app is refused at the gate (it must not synthesize drags into\n * sibling apps).\n */\nexport const startItemDrag = async (item: DraggableItem): Promise<void> => {\n const res = (await protocolRequest(SCHEMES[PROTOCOL_DND], 'startDrag', [item])) as\n | { ok: true }\n | { ok: false; code?: string; message?: string }\n | undefined;\n throwOnRefusal(res, 'dnd startDrag failed');\n};\n\n/** Abort an in-progress host-mediated drag this app started (e.g. the user pressed\n * Escape, or the gesture was cancelled). Best-effort and fire-and-forget. */\nexport const cancelItemDrag = (): void => {\n sendMessage(DND_CANCEL, {});\n};\n\n/** Subscribe to items dropped onto this app by a host-mediated cross-app drag.\n * Returns an unsubscribe fn. Subscribing is the opt-in: an app that never subscribes\n * receives nothing (the host shows a \"not accepted\" cue and the drop is a no-op). */\nexport const onItemDrop = (listener: (d: DroppedItem) => void): (() => void) =>\n addListener(DROPPED_ITEM, (m: { item: DraggableItem; from: string; position: { x: number; y: number } }) =>\n listener({ item: m.item, from: m.from, position: m.position }),\n );\n\n/** React hook: the most recently dropped item (or `null`). */\nexport const useDroppedItem = (): DroppedItem | null => {\n const [dropped, setDropped] = useState<DroppedItem | null>(null);\n useEffect(() => onItemDrop(setDropped), []);\n return dropped;\n};\n"],"mappings":";AAoBA,SAAS,WAAW,gBAAgB;AACpC,SAAS,sBAAsB;AAC/B,SAAS,iBAAiB,aAAa,mBAAmB;AAC1D,SAAS,YAAY,cAAc,oBAAoB;AACvD,SAAS,eAAe;AAoDjB,MAAM,gBAAgB,OAAO,SAAuC;AACzE,QAAM,MAAO,MAAM,gBAAgB,QAAQ,YAAY,GAAG,aAAa,CAAC,IAAI,CAAC;AAI7E,iBAAe,KAAK,sBAAsB;AAC5C;AAIO,MAAM,iBAAiB,MAAY;AACxC,cAAY,YAAY,CAAC,CAAC;AAC5B;AAKO,MAAM,aAAa,CAAC,aACzB;AAAA,EAAY;AAAA,EAAc,CAAC,MACzB,SAAS,EAAE,MAAM,EAAE,MAAM,MAAM,EAAE,MAAM,UAAU,EAAE,SAAS,CAAC;AAC/D;AAGK,MAAM,iBAAiB,MAA0B;AACtD,QAAM,CAAC,SAAS,UAAU,IAAI,SAA6B,IAAI;AAC/D,YAAU,MAAM,WAAW,UAAU,GAAG,CAAC,CAAC;AAC1C,SAAO;AACT;","names":[]}
|
package/dist/editor.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/editor.ts"],"sourcesContent":["import { protocolRequest } from './sandboxUtils';\nimport { throwOnRefusal } 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; it was always a cast and is not enforced at\n * runtime, so treat an unlisted code as possible and `instanceof Error` as the only\n * 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 * Two target classes, and **at most one** may be given — supplying both is refused\n * `invalid-params`. Omit both to 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 *\n * A URI, a `..` segment, or a NUL is refused `invalid-params` in either 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}.\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}\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; it was always a cast and is not enforced at\n * runtime, so treat an unlisted code as possible and `instanceof Error` as the only\n * reliable test.\n */\nexport interface RequestEditError extends Error {\n code:\n | 'read-only' // editing isn't possible here (a `ro` mount / anonymous viewer) — HIDE the affordance\n | 'forbidden' // the host refuses: a cross-repo target, or a mount you do not hold\n | 'invalid-params' // the target was malformed (URI / `..` / NUL / both target classes at once)\n | 'not-found' // the mount-file target does not exist — and asking did NOT create it\n | 'no-target' // there is no host editor session to enter\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 */\nexport const requestEdit = (target?: EditTarget): Promise<void> =>\n editorRequest('requestEdit', target ? { ...target } : {});\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; it was always a cast and is not enforced at\n * runtime, so treat an unlisted code as possible and `instanceof Error` as the only\n * 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; it was always a cast and is not enforced at\n * runtime, so treat an unlisted code as possible and `instanceof Error` as the only\n * 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,6BAA+B;AAC/B,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;AAwEI,MAAM,cAAc,CAAC,WAC1B,cAAc,eAAe,SAAS,EAAE,GAAG,OAAO,IAAI,CAAC,CAAC;AAiCnD,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 } 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 * Two target classes, and **at most one** may be given — supplying both is refused\n * `invalid-params`. Omit both to 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 *\n * A URI, a `..` segment, or a NUL is refused `invalid-params` in either 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}.\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}\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) — HIDE the affordance\n | 'forbidden' // the host refuses: a cross-repo target, or a mount you do not hold\n | 'invalid-params' // the target was malformed (URI / `..` / NUL / both target classes at once)\n | 'not-found' // the mount-file target does not exist — and asking did NOT create it\n | 'no-target' // there is no host editor session to enter\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 */\nexport const requestEdit = (target?: EditTarget): Promise<void> =>\n editorRequest('requestEdit', target ? { ...target } : {});\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,6BAA+B;AAC/B,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;AAwEI,MAAM,cAAc,CAAC,WAC1B,cAAc,eAAe,SAAS,EAAE,GAAG,OAAO,IAAI,CAAC,CAAC;AAiCnD,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":[]}
|
package/dist/editor.d.cts
CHANGED
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
*
|
|
14
14
|
* **What you actually catch.** The SDK throws a plain `Error` with `.code` assigned — a
|
|
15
15
|
* `CodedRefusalError` from `protocolRefusal.ts` — never a distinct class. This interface
|
|
16
|
-
* documents the `.code` VALUES the host sends
|
|
17
|
-
*
|
|
18
|
-
* reliable test.
|
|
16
|
+
* documents the `.code` VALUES the host sends. Nothing enforces the union at runtime —
|
|
17
|
+
* `.code` is whatever string arrived — so treat an unlisted code as possible and
|
|
18
|
+
* `instanceof Error` as the only reliable test.
|
|
19
19
|
*/
|
|
20
20
|
interface EditorOpenError extends Error {
|
|
21
21
|
code: 'forbidden' | 'not-found' | 'invalid-params' | 'no-target' | 'unknown';
|
|
@@ -104,9 +104,9 @@ interface EditTarget {
|
|
|
104
104
|
*
|
|
105
105
|
* **What you actually catch.** The SDK throws a plain `Error` with `.code` assigned — a
|
|
106
106
|
* `CodedRefusalError` from `protocolRefusal.ts` — never a distinct class. This interface
|
|
107
|
-
* documents the `.code` VALUES the host sends
|
|
108
|
-
*
|
|
109
|
-
* reliable test.
|
|
107
|
+
* documents the `.code` VALUES the host sends. Nothing enforces the union at runtime —
|
|
108
|
+
* `.code` is whatever string arrived — so treat an unlisted code as possible and
|
|
109
|
+
* `instanceof Error` as the only reliable test.
|
|
110
110
|
*/
|
|
111
111
|
interface RequestEditError extends Error {
|
|
112
112
|
code: 'read-only' | 'forbidden' | 'invalid-params' | 'not-found' | 'no-target' | 'unknown';
|
|
@@ -137,9 +137,9 @@ declare const requestEdit: (target?: EditTarget) => Promise<void>;
|
|
|
137
137
|
*
|
|
138
138
|
* **What you actually catch.** The SDK throws a plain `Error` with `.code` assigned — a
|
|
139
139
|
* `CodedRefusalError` from `protocolRefusal.ts` — never a distinct class. This interface
|
|
140
|
-
* documents the `.code` VALUES the host sends
|
|
141
|
-
*
|
|
142
|
-
* reliable test.
|
|
140
|
+
* documents the `.code` VALUES the host sends. Nothing enforces the union at runtime —
|
|
141
|
+
* `.code` is whatever string arrived — so treat an unlisted code as possible and
|
|
142
|
+
* `instanceof Error` as the only reliable test.
|
|
143
143
|
*/
|
|
144
144
|
interface EditorSessionError extends Error {
|
|
145
145
|
code: 'forbidden' | 'not-found' | 'invalid-params' | 'no-target' | 'unknown';
|
|
@@ -156,9 +156,9 @@ declare const closeFile: (path: string) => Promise<void>;
|
|
|
156
156
|
*
|
|
157
157
|
* **What you actually catch.** The SDK throws a plain `Error` with `.code` assigned — a
|
|
158
158
|
* `CodedRefusalError` from `protocolRefusal.ts` — never a distinct class. This interface
|
|
159
|
-
* documents the `.code` VALUES the host sends
|
|
160
|
-
*
|
|
161
|
-
* reliable test.
|
|
159
|
+
* documents the `.code` VALUES the host sends. Nothing enforces the union at runtime —
|
|
160
|
+
* `.code` is whatever string arrived — so treat an unlisted code as possible and
|
|
161
|
+
* `instanceof Error` as the only reliable test.
|
|
162
162
|
*/
|
|
163
163
|
interface EditorWriteError extends Error {
|
|
164
164
|
code: 'forbidden' | 'not-found' | 'exists' | 'protected' | 'too-large' | 'invalid-params' | 'no-target' | 'unknown';
|
package/dist/editor.d.ts
CHANGED
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
*
|
|
14
14
|
* **What you actually catch.** The SDK throws a plain `Error` with `.code` assigned — a
|
|
15
15
|
* `CodedRefusalError` from `protocolRefusal.ts` — never a distinct class. This interface
|
|
16
|
-
* documents the `.code` VALUES the host sends
|
|
17
|
-
*
|
|
18
|
-
* reliable test.
|
|
16
|
+
* documents the `.code` VALUES the host sends. Nothing enforces the union at runtime —
|
|
17
|
+
* `.code` is whatever string arrived — so treat an unlisted code as possible and
|
|
18
|
+
* `instanceof Error` as the only reliable test.
|
|
19
19
|
*/
|
|
20
20
|
interface EditorOpenError extends Error {
|
|
21
21
|
code: 'forbidden' | 'not-found' | 'invalid-params' | 'no-target' | 'unknown';
|
|
@@ -104,9 +104,9 @@ interface EditTarget {
|
|
|
104
104
|
*
|
|
105
105
|
* **What you actually catch.** The SDK throws a plain `Error` with `.code` assigned — a
|
|
106
106
|
* `CodedRefusalError` from `protocolRefusal.ts` — never a distinct class. This interface
|
|
107
|
-
* documents the `.code` VALUES the host sends
|
|
108
|
-
*
|
|
109
|
-
* reliable test.
|
|
107
|
+
* documents the `.code` VALUES the host sends. Nothing enforces the union at runtime —
|
|
108
|
+
* `.code` is whatever string arrived — so treat an unlisted code as possible and
|
|
109
|
+
* `instanceof Error` as the only reliable test.
|
|
110
110
|
*/
|
|
111
111
|
interface RequestEditError extends Error {
|
|
112
112
|
code: 'read-only' | 'forbidden' | 'invalid-params' | 'not-found' | 'no-target' | 'unknown';
|
|
@@ -137,9 +137,9 @@ declare const requestEdit: (target?: EditTarget) => Promise<void>;
|
|
|
137
137
|
*
|
|
138
138
|
* **What you actually catch.** The SDK throws a plain `Error` with `.code` assigned — a
|
|
139
139
|
* `CodedRefusalError` from `protocolRefusal.ts` — never a distinct class. This interface
|
|
140
|
-
* documents the `.code` VALUES the host sends
|
|
141
|
-
*
|
|
142
|
-
* reliable test.
|
|
140
|
+
* documents the `.code` VALUES the host sends. Nothing enforces the union at runtime —
|
|
141
|
+
* `.code` is whatever string arrived — so treat an unlisted code as possible and
|
|
142
|
+
* `instanceof Error` as the only reliable test.
|
|
143
143
|
*/
|
|
144
144
|
interface EditorSessionError extends Error {
|
|
145
145
|
code: 'forbidden' | 'not-found' | 'invalid-params' | 'no-target' | 'unknown';
|
|
@@ -156,9 +156,9 @@ declare const closeFile: (path: string) => Promise<void>;
|
|
|
156
156
|
*
|
|
157
157
|
* **What you actually catch.** The SDK throws a plain `Error` with `.code` assigned — a
|
|
158
158
|
* `CodedRefusalError` from `protocolRefusal.ts` — never a distinct class. This interface
|
|
159
|
-
* documents the `.code` VALUES the host sends
|
|
160
|
-
*
|
|
161
|
-
* reliable test.
|
|
159
|
+
* documents the `.code` VALUES the host sends. Nothing enforces the union at runtime —
|
|
160
|
+
* `.code` is whatever string arrived — so treat an unlisted code as possible and
|
|
161
|
+
* `instanceof Error` as the only reliable test.
|
|
162
162
|
*/
|
|
163
163
|
interface EditorWriteError extends Error {
|
|
164
164
|
code: 'forbidden' | 'not-found' | 'exists' | 'protected' | 'too-large' | 'invalid-params' | 'no-target' | 'unknown';
|
package/dist/editor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/editor.ts"],"sourcesContent":["import { protocolRequest } from './sandboxUtils';\nimport { throwOnRefusal } 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; it was always a cast and is not enforced at\n * runtime, so treat an unlisted code as possible and `instanceof Error` as the only\n * 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 * Two target classes, and **at most one** may be given — supplying both is refused\n * `invalid-params`. Omit both to 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 *\n * A URI, a `..` segment, or a NUL is refused `invalid-params` in either 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}.\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}\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; it was always a cast and is not enforced at\n * runtime, so treat an unlisted code as possible and `instanceof Error` as the only\n * reliable test.\n */\nexport interface RequestEditError extends Error {\n code:\n | 'read-only' // editing isn't possible here (a `ro` mount / anonymous viewer) — HIDE the affordance\n | 'forbidden' // the host refuses: a cross-repo target, or a mount you do not hold\n | 'invalid-params' // the target was malformed (URI / `..` / NUL / both target classes at once)\n | 'not-found' // the mount-file target does not exist — and asking did NOT create it\n | 'no-target' // there is no host editor session to enter\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 */\nexport const requestEdit = (target?: EditTarget): Promise<void> =>\n editorRequest('requestEdit', target ? { ...target } : {});\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; it was always a cast and is not enforced at\n * runtime, so treat an unlisted code as possible and `instanceof Error` as the only\n * 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; it was always a cast and is not enforced at\n * runtime, so treat an unlisted code as possible and `instanceof Error` as the only\n * 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,sBAAsB;AAC/B,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;AAwEI,MAAM,cAAc,CAAC,WAC1B,cAAc,eAAe,SAAS,EAAE,GAAG,OAAO,IAAI,CAAC,CAAC;AAiCnD,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 } 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 * Two target classes, and **at most one** may be given — supplying both is refused\n * `invalid-params`. Omit both to 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 *\n * A URI, a `..` segment, or a NUL is refused `invalid-params` in either 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}.\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}\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) — HIDE the affordance\n | 'forbidden' // the host refuses: a cross-repo target, or a mount you do not hold\n | 'invalid-params' // the target was malformed (URI / `..` / NUL / both target classes at once)\n | 'not-found' // the mount-file target does not exist — and asking did NOT create it\n | 'no-target' // there is no host editor session to enter\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 */\nexport const requestEdit = (target?: EditTarget): Promise<void> =>\n editorRequest('requestEdit', target ? { ...target } : {});\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,sBAAsB;AAC/B,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;AAwEI,MAAM,cAAc,CAAC,WAC1B,cAAc,eAAe,SAAS,EAAE,GAAG,OAAO,IAAI,CAAC,CAAC;AAiCnD,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":[]}
|
package/dist/feed.cjs
CHANGED
|
@@ -22,15 +22,12 @@ __export(feed_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(feed_exports);
|
|
24
24
|
var import_sandboxUtils = require("./sandboxUtils");
|
|
25
|
+
var import_protocolRefusal = require("./protocolRefusal");
|
|
25
26
|
var import_protocolSchemes = require("./protocolSchemes");
|
|
26
27
|
var import_protocol = require("./generated/protocol");
|
|
27
28
|
const feedFetch = async (instanceId, params = {}) => {
|
|
28
29
|
const res = await (0, import_sandboxUtils.protocolRequest)(import_protocolSchemes.SCHEMES[import_protocol.PROTOCOL_FEED], "fetch", [{ instanceId, params }]);
|
|
29
|
-
|
|
30
|
-
const err = new Error(res?.message ?? "feedFetch failed");
|
|
31
|
-
err.code = (res && "code" in res ? res.code : void 0) ?? "unknown";
|
|
32
|
-
throw err;
|
|
33
|
-
}
|
|
30
|
+
(0, import_protocolRefusal.throwOnRefusal)(res, "feedFetch failed");
|
|
34
31
|
return res.data;
|
|
35
32
|
};
|
|
36
33
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/feed.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/feed.ts"],"sourcesContent":["// feedFetch — the connector's egress, and the difference between it and `hostFetch`\n// is the whole of D2 (`reckoner/docs/specs/CONNECTOR_EGRESS_FIXING_SPEC.md` §2).\n//\n// `hostFetch(url, init)` takes a URL. The host checks it against your effective\n// allowlist, but *within* that allowlist your app picks which host, which path and\n// what body, on every call. That is fine for an app whose logic you control.\n//\n// It is not fine for a **connector** — an app whose job is to pump bytes from a feed\n// into a document, where the bytes it fetched are, in effect, a program steering it\n// (`REPORTING_SPREADSHEET §3.2` RB-1). An allowlist bounds the host *set*; it does\n// nothing about per-call choice inside that set, and nothing at all about the body.\n//\n// So `feedFetch` does not take a URL. It takes a **feed-instance id** and a typed\n// **param object**, and the host constructs the request from a template it compiled,\n// at grant time, from your app's trusted feed configuration. Your code cannot name a\n// target, so content your code just read cannot name one either.\n//\n// What that means in practice when you write a connector:\n//\n// • the origin, path and method come from your manifest's `feed:fetch` config —\n// not from this call, and not from anything you fetched;\n// • `params` fill only the slots the template declared, and each is typed\n// (an ISO-8601 instant, a bounded integer, or one of a declared enum). A value\n// that is not what the slot declared is rejected — including, incidentally,\n// anything URL-shaped;\n// • **pagination is not yours.** The host mints the cursor, keeps it, and spends it;\n// you neither supply nor receive one. A cursor you round-tripped would be either\n// bytes you authored or a function of bytes you fetched, and both are exactly what\n// this surface exists to prevent;\n// • a `POST`/body feed's body comes from the template too. There is no parameter\n// that carries body bytes.\n//\n// Hold `feed:fetch` **instead of** `net:fetch`, not alongside it. An app holding\n// `net:fetch` has the URL surface back regardless of any template it was also given,\n// which is why they are two capabilities and not one with a flag.\n\nimport { protocolRequest } from './sandboxUtils';\nimport { SCHEMES } from './protocolSchemes';\nimport { PROTOCOL_FEED } from './generated/protocol';\n\n/** Values a feed template's declared slots accept. The host validates each against\n * the slot's declared type; anything else is `invalid-params`. */\nexport type FeedParams = Record<string, string | number>;\n\n/** The serialized response from {@link feedFetch} — the same shape `hostFetch`\n * returns, because reading a feed should feel like reading a fetch. The difference\n * is entirely in what you may ASK for. */\nexport interface FeedFetchResponse {\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 * Fire one of your app's configured feeds through the host.\n *\n * ```ts\n * // `instanceId` comes from the host when the feed is launched — it is opaque,\n * // host-minted, and bound to your app; you never construct one.\n * const res = await feedFetch(instanceId, { since: '2026-08-01T00:00:00Z' });\n * const rows = JSON.parse(res.body);\n * ```\n *\n * A reachable server's reply — including a non-2xx status — RESOLVES; inspect\n * `.status`. Everything else REJECTS with an {@link Error} carrying a machine `.code`:\n *\n * - `forbidden` — you do not hold `feed:fetch`, or `instanceId` is not one of yours.\n * **The two are deliberately indistinguishable**, so this is not an oracle for which\n * feeds exist.\n * - `invalid-params` — a param the template does not declare, a value that is not what\n * its slot declared, or a body that would exceed the template's cap. Naming a cursor\n * slot lands here too: the cursor is the host's, not a parameter.\n * - `budget` — this instance's request budget is spent. It bounds runaway loops; it is\n * a tripwire, not containment.\n * - `unsupported` — the host's pinned egress path is unavailable. `feedFetch`\n * deliberately has **no fallback**: the alternative path does no DNS resolution and no\n * socket pinning, and silently downgrading a credentialed feed onto it is the hazard\n * this whole mechanism removes. A connector that cannot use the pinned path does not\n * fetch.\n * - `blocked` / `redirect` / `too-large` / `network` — the same server-side SSRF,\n * per-hop redirect and size guards every proxied fetch meets.\n */\n// The parameter is spelled structurally rather than as `FeedParams`, deliberately: the\n// wire descriptor in `@immediately-run/sandbox-protocol` records the type that actually\n// crosses the boundary, and an SDK-local alias name in a CROSS-REPO wire contract would\n// describe this package rather than the protocol. `FeedParams` stays exported as the\n// name callers write.\nexport const feedFetch = async (\n instanceId: string,\n params: Record<string, string | number> = {},\n): Promise<FeedFetchResponse> => {\n const res = (await protocolRequest(SCHEMES[PROTOCOL_FEED], 'fetch', [{ instanceId, params }])) as\n | { ok: true; data: FeedFetchResponse }\n | { ok: false; code?: string; message?: string }\n | undefined;\n
|
|
1
|
+
{"version":3,"sources":["../src/feed.ts"],"sourcesContent":["// feedFetch — the connector's egress, and the difference between it and `hostFetch`\n// is the whole of D2 (`reckoner/docs/specs/CONNECTOR_EGRESS_FIXING_SPEC.md` §2).\n//\n// `hostFetch(url, init)` takes a URL. The host checks it against your effective\n// allowlist, but *within* that allowlist your app picks which host, which path and\n// what body, on every call. That is fine for an app whose logic you control.\n//\n// It is not fine for a **connector** — an app whose job is to pump bytes from a feed\n// into a document, where the bytes it fetched are, in effect, a program steering it\n// (`REPORTING_SPREADSHEET §3.2` RB-1). An allowlist bounds the host *set*; it does\n// nothing about per-call choice inside that set, and nothing at all about the body.\n//\n// So `feedFetch` does not take a URL. It takes a **feed-instance id** and a typed\n// **param object**, and the host constructs the request from a template it compiled,\n// at grant time, from your app's trusted feed configuration. Your code cannot name a\n// target, so content your code just read cannot name one either.\n//\n// What that means in practice when you write a connector:\n//\n// • the origin, path and method come from your manifest's `feed:fetch` config —\n// not from this call, and not from anything you fetched;\n// • `params` fill only the slots the template declared, and each is typed\n// (an ISO-8601 instant, a bounded integer, or one of a declared enum). A value\n// that is not what the slot declared is rejected — including, incidentally,\n// anything URL-shaped;\n// • **pagination is not yours.** The host mints the cursor, keeps it, and spends it;\n// you neither supply nor receive one. A cursor you round-tripped would be either\n// bytes you authored or a function of bytes you fetched, and both are exactly what\n// this surface exists to prevent;\n// • a `POST`/body feed's body comes from the template too. There is no parameter\n// that carries body bytes.\n//\n// Hold `feed:fetch` **instead of** `net:fetch`, not alongside it. An app holding\n// `net:fetch` has the URL surface back regardless of any template it was also given,\n// which is why they are two capabilities and not one with a flag.\n\nimport { protocolRequest } from './sandboxUtils';\nimport { throwOnRefusal } from './protocolRefusal';\nimport { SCHEMES } from './protocolSchemes';\nimport { PROTOCOL_FEED } from './generated/protocol';\n\n/** Values a feed template's declared slots accept. The host validates each against\n * the slot's declared type; anything else is `invalid-params`. */\nexport type FeedParams = Record<string, string | number>;\n\n/** The serialized response from {@link feedFetch} — the same shape `hostFetch`\n * returns, because reading a feed should feel like reading a fetch. The difference\n * is entirely in what you may ASK for. */\nexport interface FeedFetchResponse {\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 * Fire one of your app's configured feeds through the host.\n *\n * ```ts\n * // `instanceId` comes from the host when the feed is launched — it is opaque,\n * // host-minted, and bound to your app; you never construct one.\n * const res = await feedFetch(instanceId, { since: '2026-08-01T00:00:00Z' });\n * const rows = JSON.parse(res.body);\n * ```\n *\n * A reachable server's reply — including a non-2xx status — RESOLVES; inspect\n * `.status`. Everything else REJECTS with an {@link Error} carrying a machine `.code`:\n *\n * - `forbidden` — you do not hold `feed:fetch`, or `instanceId` is not one of yours.\n * **The two are deliberately indistinguishable**, so this is not an oracle for which\n * feeds exist.\n * - `invalid-params` — a param the template does not declare, a value that is not what\n * its slot declared, or a body that would exceed the template's cap. Naming a cursor\n * slot lands here too: the cursor is the host's, not a parameter.\n * - `budget` — this instance's request budget is spent. It bounds runaway loops; it is\n * a tripwire, not containment.\n * - `unsupported` — the host's pinned egress path is unavailable. `feedFetch`\n * deliberately has **no fallback**: the alternative path does no DNS resolution and no\n * socket pinning, and silently downgrading a credentialed feed onto it is the hazard\n * this whole mechanism removes. A connector that cannot use the pinned path does not\n * fetch.\n * - `blocked` / `redirect` / `too-large` / `network` — the same server-side SSRF,\n * per-hop redirect and size guards every proxied fetch meets.\n */\n// The parameter is spelled structurally rather than as `FeedParams`, deliberately: the\n// wire descriptor in `@immediately-run/sandbox-protocol` records the type that actually\n// crosses the boundary, and an SDK-local alias name in a CROSS-REPO wire contract would\n// describe this package rather than the protocol. `FeedParams` stays exported as the\n// name callers write.\nexport const feedFetch = async (\n instanceId: string,\n params: Record<string, string | number> = {},\n): Promise<FeedFetchResponse> => {\n const res = (await protocolRequest(SCHEMES[PROTOCOL_FEED], 'fetch', [{ instanceId, params }])) as\n | { ok: true; data: FeedFetchResponse }\n | { ok: false; code?: string; message?: string }\n | undefined;\n throwOnRefusal(res, 'feedFetch failed');\n return res.data;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoCA,0BAAgC;AAChC,6BAA+B;AAC/B,6BAAwB;AACxB,sBAA8B;AAoDvB,MAAM,YAAY,OACvB,YACA,SAA0C,CAAC,MACZ;AAC/B,QAAM,MAAO,UAAM,qCAAgB,+BAAQ,6BAAa,GAAG,SAAS,CAAC,EAAE,YAAY,OAAO,CAAC,CAAC;AAI5F,6CAAe,KAAK,kBAAkB;AACtC,SAAO,IAAI;AACb;","names":[]}
|
package/dist/feed.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import "./chunk-VHAA22YE.js";
|
|
2
2
|
import { protocolRequest } from "./sandboxUtils.js";
|
|
3
|
+
import { throwOnRefusal } from "./protocolRefusal.js";
|
|
3
4
|
import { SCHEMES } from "./protocolSchemes.js";
|
|
4
5
|
import { PROTOCOL_FEED } from "./generated/protocol.js";
|
|
5
6
|
const feedFetch = async (instanceId, params = {}) => {
|
|
6
7
|
const res = await protocolRequest(SCHEMES[PROTOCOL_FEED], "fetch", [{ instanceId, params }]);
|
|
7
|
-
|
|
8
|
-
const err = new Error(res?.message ?? "feedFetch failed");
|
|
9
|
-
err.code = (res && "code" in res ? res.code : void 0) ?? "unknown";
|
|
10
|
-
throw err;
|
|
11
|
-
}
|
|
8
|
+
throwOnRefusal(res, "feedFetch failed");
|
|
12
9
|
return res.data;
|
|
13
10
|
};
|
|
14
11
|
export {
|
package/dist/feed.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/feed.ts"],"sourcesContent":["// feedFetch — the connector's egress, and the difference between it and `hostFetch`\n// is the whole of D2 (`reckoner/docs/specs/CONNECTOR_EGRESS_FIXING_SPEC.md` §2).\n//\n// `hostFetch(url, init)` takes a URL. The host checks it against your effective\n// allowlist, but *within* that allowlist your app picks which host, which path and\n// what body, on every call. That is fine for an app whose logic you control.\n//\n// It is not fine for a **connector** — an app whose job is to pump bytes from a feed\n// into a document, where the bytes it fetched are, in effect, a program steering it\n// (`REPORTING_SPREADSHEET §3.2` RB-1). An allowlist bounds the host *set*; it does\n// nothing about per-call choice inside that set, and nothing at all about the body.\n//\n// So `feedFetch` does not take a URL. It takes a **feed-instance id** and a typed\n// **param object**, and the host constructs the request from a template it compiled,\n// at grant time, from your app's trusted feed configuration. Your code cannot name a\n// target, so content your code just read cannot name one either.\n//\n// What that means in practice when you write a connector:\n//\n// • the origin, path and method come from your manifest's `feed:fetch` config —\n// not from this call, and not from anything you fetched;\n// • `params` fill only the slots the template declared, and each is typed\n// (an ISO-8601 instant, a bounded integer, or one of a declared enum). A value\n// that is not what the slot declared is rejected — including, incidentally,\n// anything URL-shaped;\n// • **pagination is not yours.** The host mints the cursor, keeps it, and spends it;\n// you neither supply nor receive one. A cursor you round-tripped would be either\n// bytes you authored or a function of bytes you fetched, and both are exactly what\n// this surface exists to prevent;\n// • a `POST`/body feed's body comes from the template too. There is no parameter\n// that carries body bytes.\n//\n// Hold `feed:fetch` **instead of** `net:fetch`, not alongside it. An app holding\n// `net:fetch` has the URL surface back regardless of any template it was also given,\n// which is why they are two capabilities and not one with a flag.\n\nimport { protocolRequest } from './sandboxUtils';\nimport { SCHEMES } from './protocolSchemes';\nimport { PROTOCOL_FEED } from './generated/protocol';\n\n/** Values a feed template's declared slots accept. The host validates each against\n * the slot's declared type; anything else is `invalid-params`. */\nexport type FeedParams = Record<string, string | number>;\n\n/** The serialized response from {@link feedFetch} — the same shape `hostFetch`\n * returns, because reading a feed should feel like reading a fetch. The difference\n * is entirely in what you may ASK for. */\nexport interface FeedFetchResponse {\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 * Fire one of your app's configured feeds through the host.\n *\n * ```ts\n * // `instanceId` comes from the host when the feed is launched — it is opaque,\n * // host-minted, and bound to your app; you never construct one.\n * const res = await feedFetch(instanceId, { since: '2026-08-01T00:00:00Z' });\n * const rows = JSON.parse(res.body);\n * ```\n *\n * A reachable server's reply — including a non-2xx status — RESOLVES; inspect\n * `.status`. Everything else REJECTS with an {@link Error} carrying a machine `.code`:\n *\n * - `forbidden` — you do not hold `feed:fetch`, or `instanceId` is not one of yours.\n * **The two are deliberately indistinguishable**, so this is not an oracle for which\n * feeds exist.\n * - `invalid-params` — a param the template does not declare, a value that is not what\n * its slot declared, or a body that would exceed the template's cap. Naming a cursor\n * slot lands here too: the cursor is the host's, not a parameter.\n * - `budget` — this instance's request budget is spent. It bounds runaway loops; it is\n * a tripwire, not containment.\n * - `unsupported` — the host's pinned egress path is unavailable. `feedFetch`\n * deliberately has **no fallback**: the alternative path does no DNS resolution and no\n * socket pinning, and silently downgrading a credentialed feed onto it is the hazard\n * this whole mechanism removes. A connector that cannot use the pinned path does not\n * fetch.\n * - `blocked` / `redirect` / `too-large` / `network` — the same server-side SSRF,\n * per-hop redirect and size guards every proxied fetch meets.\n */\n// The parameter is spelled structurally rather than as `FeedParams`, deliberately: the\n// wire descriptor in `@immediately-run/sandbox-protocol` records the type that actually\n// crosses the boundary, and an SDK-local alias name in a CROSS-REPO wire contract would\n// describe this package rather than the protocol. `FeedParams` stays exported as the\n// name callers write.\nexport const feedFetch = async (\n instanceId: string,\n params: Record<string, string | number> = {},\n): Promise<FeedFetchResponse> => {\n const res = (await protocolRequest(SCHEMES[PROTOCOL_FEED], 'fetch', [{ instanceId, params }])) as\n | { ok: true; data: FeedFetchResponse }\n | { ok: false; code?: string; message?: string }\n | undefined;\n
|
|
1
|
+
{"version":3,"sources":["../src/feed.ts"],"sourcesContent":["// feedFetch — the connector's egress, and the difference between it and `hostFetch`\n// is the whole of D2 (`reckoner/docs/specs/CONNECTOR_EGRESS_FIXING_SPEC.md` §2).\n//\n// `hostFetch(url, init)` takes a URL. The host checks it against your effective\n// allowlist, but *within* that allowlist your app picks which host, which path and\n// what body, on every call. That is fine for an app whose logic you control.\n//\n// It is not fine for a **connector** — an app whose job is to pump bytes from a feed\n// into a document, where the bytes it fetched are, in effect, a program steering it\n// (`REPORTING_SPREADSHEET §3.2` RB-1). An allowlist bounds the host *set*; it does\n// nothing about per-call choice inside that set, and nothing at all about the body.\n//\n// So `feedFetch` does not take a URL. It takes a **feed-instance id** and a typed\n// **param object**, and the host constructs the request from a template it compiled,\n// at grant time, from your app's trusted feed configuration. Your code cannot name a\n// target, so content your code just read cannot name one either.\n//\n// What that means in practice when you write a connector:\n//\n// • the origin, path and method come from your manifest's `feed:fetch` config —\n// not from this call, and not from anything you fetched;\n// • `params` fill only the slots the template declared, and each is typed\n// (an ISO-8601 instant, a bounded integer, or one of a declared enum). A value\n// that is not what the slot declared is rejected — including, incidentally,\n// anything URL-shaped;\n// • **pagination is not yours.** The host mints the cursor, keeps it, and spends it;\n// you neither supply nor receive one. A cursor you round-tripped would be either\n// bytes you authored or a function of bytes you fetched, and both are exactly what\n// this surface exists to prevent;\n// • a `POST`/body feed's body comes from the template too. There is no parameter\n// that carries body bytes.\n//\n// Hold `feed:fetch` **instead of** `net:fetch`, not alongside it. An app holding\n// `net:fetch` has the URL surface back regardless of any template it was also given,\n// which is why they are two capabilities and not one with a flag.\n\nimport { protocolRequest } from './sandboxUtils';\nimport { throwOnRefusal } from './protocolRefusal';\nimport { SCHEMES } from './protocolSchemes';\nimport { PROTOCOL_FEED } from './generated/protocol';\n\n/** Values a feed template's declared slots accept. The host validates each against\n * the slot's declared type; anything else is `invalid-params`. */\nexport type FeedParams = Record<string, string | number>;\n\n/** The serialized response from {@link feedFetch} — the same shape `hostFetch`\n * returns, because reading a feed should feel like reading a fetch. The difference\n * is entirely in what you may ASK for. */\nexport interface FeedFetchResponse {\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 * Fire one of your app's configured feeds through the host.\n *\n * ```ts\n * // `instanceId` comes from the host when the feed is launched — it is opaque,\n * // host-minted, and bound to your app; you never construct one.\n * const res = await feedFetch(instanceId, { since: '2026-08-01T00:00:00Z' });\n * const rows = JSON.parse(res.body);\n * ```\n *\n * A reachable server's reply — including a non-2xx status — RESOLVES; inspect\n * `.status`. Everything else REJECTS with an {@link Error} carrying a machine `.code`:\n *\n * - `forbidden` — you do not hold `feed:fetch`, or `instanceId` is not one of yours.\n * **The two are deliberately indistinguishable**, so this is not an oracle for which\n * feeds exist.\n * - `invalid-params` — a param the template does not declare, a value that is not what\n * its slot declared, or a body that would exceed the template's cap. Naming a cursor\n * slot lands here too: the cursor is the host's, not a parameter.\n * - `budget` — this instance's request budget is spent. It bounds runaway loops; it is\n * a tripwire, not containment.\n * - `unsupported` — the host's pinned egress path is unavailable. `feedFetch`\n * deliberately has **no fallback**: the alternative path does no DNS resolution and no\n * socket pinning, and silently downgrading a credentialed feed onto it is the hazard\n * this whole mechanism removes. A connector that cannot use the pinned path does not\n * fetch.\n * - `blocked` / `redirect` / `too-large` / `network` — the same server-side SSRF,\n * per-hop redirect and size guards every proxied fetch meets.\n */\n// The parameter is spelled structurally rather than as `FeedParams`, deliberately: the\n// wire descriptor in `@immediately-run/sandbox-protocol` records the type that actually\n// crosses the boundary, and an SDK-local alias name in a CROSS-REPO wire contract would\n// describe this package rather than the protocol. `FeedParams` stays exported as the\n// name callers write.\nexport const feedFetch = async (\n instanceId: string,\n params: Record<string, string | number> = {},\n): Promise<FeedFetchResponse> => {\n const res = (await protocolRequest(SCHEMES[PROTOCOL_FEED], 'fetch', [{ instanceId, params }])) as\n | { ok: true; data: FeedFetchResponse }\n | { ok: false; code?: string; message?: string }\n | undefined;\n throwOnRefusal(res, 'feedFetch failed');\n return res.data;\n};\n"],"mappings":";AAoCA,SAAS,uBAAuB;AAChC,SAAS,sBAAsB;AAC/B,SAAS,eAAe;AACxB,SAAS,qBAAqB;AAoDvB,MAAM,YAAY,OACvB,YACA,SAA0C,CAAC,MACZ;AAC/B,QAAM,MAAO,MAAM,gBAAgB,QAAQ,aAAa,GAAG,SAAS,CAAC,EAAE,YAAY,OAAO,CAAC,CAAC;AAI5F,iBAAe,KAAK,kBAAkB;AACtC,SAAO,IAAI;AACb;","names":[]}
|