@immediately-run/sdk 0.71.0 → 0.73.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/index.cjs +2 -0
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +2 -1
  4. package/dist/index.d.ts +2 -1
  5. package/dist/index.js +1 -0
  6. package/dist/index.js.map +1 -1
  7. package/dist/llm.cjs +10 -1
  8. package/dist/llm.cjs.map +1 -1
  9. package/dist/llm.d.cts +44 -14
  10. package/dist/llm.d.ts +44 -14
  11. package/dist/llm.js +9 -1
  12. package/dist/llm.js.map +1 -1
  13. package/dist/mounts.cjs +2 -5
  14. package/dist/mounts.cjs.map +1 -1
  15. package/dist/mounts.js +2 -5
  16. package/dist/mounts.js.map +1 -1
  17. package/dist/openExternal.cjs +2 -7
  18. package/dist/openExternal.cjs.map +1 -1
  19. package/dist/openExternal.d.cts +6 -0
  20. package/dist/openExternal.d.ts +6 -0
  21. package/dist/openExternal.js +2 -7
  22. package/dist/openExternal.js.map +1 -1
  23. package/dist/openRepository.cjs +2 -7
  24. package/dist/openRepository.cjs.map +1 -1
  25. package/dist/openRepository.d.cts +6 -0
  26. package/dist/openRepository.d.ts +6 -0
  27. package/dist/openRepository.js +2 -7
  28. package/dist/openRepository.js.map +1 -1
  29. package/dist/protocolRefusal.cjs +35 -0
  30. package/dist/protocolRefusal.cjs.map +1 -0
  31. package/dist/protocolRefusal.d.cts +30 -0
  32. package/dist/protocolRefusal.d.ts +30 -0
  33. package/dist/protocolRefusal.js +12 -0
  34. package/dist/protocolRefusal.js.map +1 -0
  35. package/dist/protocolSchemes.cjs +1 -0
  36. package/dist/protocolSchemes.cjs.map +1 -1
  37. package/dist/protocolSchemes.d.cts +1 -0
  38. package/dist/protocolSchemes.d.ts +1 -0
  39. package/dist/protocolSchemes.js +2 -0
  40. package/dist/protocolSchemes.js.map +1 -1
  41. package/dist/secrets.cjs +2 -5
  42. package/dist/secrets.cjs.map +1 -1
  43. package/dist/secrets.js +2 -5
  44. package/dist/secrets.js.map +1 -1
  45. package/dist/spacesMode.cjs +101 -0
  46. package/dist/spacesMode.cjs.map +1 -0
  47. package/dist/spacesMode.d.cts +143 -0
  48. package/dist/spacesMode.d.ts +143 -0
  49. package/dist/spacesMode.js +75 -0
  50. package/dist/spacesMode.js.map +1 -0
  51. package/dist/version.cjs +1 -1
  52. package/dist/version.cjs.map +1 -1
  53. package/dist/version.d.cts +1 -1
  54. package/dist/version.d.ts +1 -1
  55. package/dist/version.js +1 -1
  56. package/dist/version.js.map +1 -1
  57. package/package.json +2 -2
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/protocolRefusal.ts"],"sourcesContent":["// The one place the SDK turns a host reply envelope into a typed, coded rejection (R6).\n//\n// ---------------------------------------------------------------------------\n// THE CENSUS — counted wrong twice, so here is how to re-derive it\n// ---------------------------------------------------------------------------\n//\n// Review round 1 found three copies of this block and this file said \"three\". Round 2\n// found five. Round 3 counted the grep and found the TYPED family is **ten**, across\n// eight files — `mounts.ts` alone has three separate request helpers, each with its own\n// copy, which round 2 read as one helper reached from three call sites.\n//\n// This PR folds the five that its own review rounds actually looked at:\n//\n// openExternal.ts · openRepository.ts · spacesMode.ts · secrets.ts · mounts.ts `request`\n//\n// The other five — `mounts.ts`'s `settingsRequest` and `localStoreRequest`, `editor.ts`,\n// `vcs.ts`, `dnd.ts` and `ipc.ts` (two sites) — were folded here too and then SPLIT BACK\n// OUT, because the gate caps at three rounds and they landed after the last one; nothing\n// had reviewed them. They go in their own PR. If you are reading this and that PR has\n// merged, this paragraph is the thing to delete.\n//\n// Not folded at all, deliberately: the UNTYPED family — `catalog.ts`, `feed.ts`,\n// `netFetch.ts`, `recents.ts`, `tasks.ts`, `theme.ts` (three sites) and `launch.ts`. They\n// are not alike: `launch.ts` folds an extra `!res.data?.launchId` into the same condition,\n// and the rest build their errors differently. Folding them is a behaviour change, not an\n// extraction.\n//\n// **Do not trust any list above; re-derive it.** `grep -n 'ok !== true' src/ | grep -v\n// '\\.test\\.'` is the whole population, and both miscounts came from reading files instead\n// of counting the grep. `check:clones` cannot help: minLines 6, minTokens 50, and no\n// identifier normalisation, so blocks differing only in type names read as distinct.\n//\n// ---------------------------------------------------------------------------\n// WHICH `ok` THIS READS, AND WHY IT MATTERS\n// ---------------------------------------------------------------------------\n//\n// It reads the DISPATCHER ENVELOPE's `ok` — the host's answer to \"did this call\n// succeed\", not a handler's own return value. site-main declares that envelope\n// (`src/editor/requestDispatcher.ts`):\n//\n// type SpaceResult =\n// | { ok: true; data: unknown }\n// | { ok: false; code: string; message: string };\n//\n// and the sandbox resolves it to the SDK unmodified (`src/protocol/iframe.ts`,\n// `resolve(msg.result)`). So a refusal reaches us as `{ok:false, code, message}` — which\n// is exactly what this function unwraps — and the host produces that frame by THROWING\n// `spaceError(code, message)`. The dispatcher's `.catch` turns the throw into the frame.\n//\n// **A handler that RETURNS `{ok:false, code}` instead of throwing does not produce a\n// refusal.** The dispatcher wraps a return value as `result: {ok: true, data: <return>}`,\n// so the envelope says the call succeeded and the refusal is buried one level down, where\n// nothing looks. Two shipped handlers do this today (site-main; audited round 2):\n//\n// `handleOpenRepository` returns `invalid`, `no-activation`\n// `handleOpenLink` returns `invalid`, `no-activation`, **`declined`**\n//\n// `declined` is the user pressing \"no\" on the host's confirmation dialog, and\n// `openExternal()` reports that to the app as a successful open. Driven against the built\n// SDK with each reply shape:\n//\n// thrown -> threw, code=no-activation\n// returned -> RESOLVED (the app believes the tab opened)\n//\n// That is a live defect in site-main's handlers, not here — the envelope is the contract\n// and this reads the contract. Filed as R3-778. It is written down here because this is\n// the file a host author will be pointed at when they ask what shape to reply with, and\n// the answer is: **throw `spaceError`; never return `{ok:false}`.**\n//\n// Deliberately NOT done: sniffing `res.data?.ok === false` as a second refusal shape. On a\n// SUCCESS, `data` is whatever the handler returned — so a handler whose legitimate payload\n// happens to carry `ok: false` would be turned into a refusal. It would bless the broken\n// shape and create a second contract where the spec names one.\n\n/** An error carrying a stable, host-supplied `code` the app can branch on. */\nexport interface CodedRefusalError<C extends string = string> extends Error {\n code: C;\n}\n\n/**\n * Throw a typed, coded error unless the host's reply envelope says the call succeeded.\n *\n * `fallbackMessage` is used when the host refused without a message, and `'unknown'` is\n * the code when it refused without one — a refusal is never reported as a success just\n * because it arrived under-specified.\n *\n * `code` and `message` must be STRINGS to be used. The five call sites this replaced\n * tested for PRESENCE (`'code' in res`, `res?.message ?? …`), so a host sending\n * `code: 42` surfaced `err.code === 42` on a field the type declares `string`, and\n * `message: 42` became the string `\"42\"`. Both now fall back. That is a deliberate\n * tightening, pinned by tests, not an accident of the rewrite.\n *\n * It is an ASSERTION function, not a `void` one, because the inline form it replaced\n * narrowed `res` as a side effect of its `if`/`throw`: `secrets.ts` and `mounts.ts` read\n * `res.data` on the next line and stopped compiling without it. A caller that only needs\n * the throw can ignore the narrowing; one that reads the payload gets it for free. (TS\n * requires the call target to be an explicitly-typed declared name — this is why it is a\n * `function` declaration and not an arrow const.)\n */\nexport function throwOnRefusal(res: unknown, fallbackMessage: string): asserts res is { ok: true; data?: unknown } {\n const r = res as { ok?: unknown; code?: unknown; message?: unknown } | null | undefined;\n if (r && r.ok === true) return;\n const err = new Error(typeof r?.message === 'string' ? r.message : fallbackMessage) as CodedRefusalError;\n err.code = typeof r?.code === 'string' ? r.code : 'unknown';\n throw err;\n}\n"],"mappings":";AAmGO,SAAS,eAAe,KAAc,iBAAsE;AACjH,QAAM,IAAI;AACV,MAAI,KAAK,EAAE,OAAO,KAAM;AACxB,QAAM,MAAM,IAAI,MAAM,OAAO,GAAG,YAAY,WAAW,EAAE,UAAU,eAAe;AAClF,MAAI,OAAO,OAAO,GAAG,SAAS,WAAW,EAAE,OAAO;AAClD,QAAM;AACR;","names":[]}
@@ -41,6 +41,7 @@ const SCHEMES = {
41
41
  [import_protocol.PROTOCOL_SECRETS]: schemeOf(import_protocol.PROTOCOL_SECRETS),
42
42
  [import_protocol.PROTOCOL_SETTINGS]: schemeOf(import_protocol.PROTOCOL_SETTINGS),
43
43
  [import_protocol.PROTOCOL_SPACES]: schemeOf(import_protocol.PROTOCOL_SPACES),
44
+ [import_protocol.PROTOCOL_SPACES_MODE]: schemeOf(import_protocol.PROTOCOL_SPACES_MODE),
44
45
  [import_protocol.PROTOCOL_TASK]: schemeOf(import_protocol.PROTOCOL_TASK),
45
46
  [import_protocol.PROTOCOL_THEME]: schemeOf(import_protocol.PROTOCOL_THEME),
46
47
  [import_protocol.PROTOCOL_VCS]: schemeOf(import_protocol.PROTOCOL_VCS)
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/protocolSchemes.ts"],"sourcesContent":["// The `protocol-<scheme>` SCHEMES, derived from the wire names.\n//\n// `protocolRequest(scheme, method, params)` takes the scheme — `'theme'` — while the\n// wire name the frame dispatches on is `'protocol-theme'`; the frame adds the prefix.\n// So the typed service wrappers cannot pass the published `PROTOCOL_*` constant\n// directly, and spelling the scheme inline would put a second, unguarded copy of the\n// name back in the tree — exactly what R3-274c removes.\n//\n// Instead the schemes are *derived* from the wire names, keyed BY the wire name:\n//\n// protocolRequest(SCHEMES[PROTOCOL_THEME], 'set', [{ theme }])\n//\n// Keying by the constant is what makes the derivation unfalsifiable — there is no\n// second place to name the family, so there is no pair to get wrong. `schemeOf`\n// returns a template-literal conditional, so each value has a literal type (`'theme'`),\n// which buys two more things:\n//\n// - a wire name that stops matching `protocol-*` stops compiling here, rather than\n// silently producing an empty scheme at runtime;\n// - `check-protocol-snapshot.mjs` resolves `SCHEMES[PROTOCOL_THEME]` through the type\n// checker exactly like a plain literal, so the call sites stay visible to the gate.\n//\n// One export, deliberately: `./*` is a public subpath, so every name added here is\n// public API forever (ways_of_working §6, additive-only).\n//\n// This module is NOT generated — the derivation is the content — so it lives outside\n// `src/generated/`.\nimport {\n PROTOCOL_ANALYTICS,\n PROTOCOL_CONTRIBUTE,\n PROTOCOL_DND,\n PROTOCOL_EDITOR,\n PROTOCOL_FEED,\n PROTOCOL_FETCH,\n PROTOCOL_IPC,\n PROTOCOL_LAUNCH,\n PROTOCOL_LLM,\n PROTOCOL_LOCALSTORE,\n PROTOCOL_OPENLINK,\n PROTOCOL_OPENREPO,\n PROTOCOL_RECENTS,\n PROTOCOL_SECRETS,\n PROTOCOL_SETTINGS,\n PROTOCOL_SPACES,\n PROTOCOL_TASK,\n PROTOCOL_THEME,\n PROTOCOL_VCS,\n} from './generated/protocol';\n\nconst PREFIX = 'protocol-';\n\n/** The scheme half of a `protocol-<scheme>` wire name. */\ntype SchemeOf<N extends string> = N extends `${typeof PREFIX}${infer S}` ? S : never;\n\n/**\n * `'protocol-theme'` → `'theme'`, as a literal type.\n *\n * The cast is the only place the derivation is asserted rather than computed; the\n * `N extends \\`protocol-${string}\\`` bound is what makes it sound — a wire name that is\n * not scheme-shaped is a compile error at the call, not a `never` at runtime.\n */\nconst schemeOf = <N extends `${typeof PREFIX}${string}`>(name: N): SchemeOf<N> =>\n name.slice(PREFIX.length) as SchemeOf<N>;\n\n/** Every `protocol-*` scheme the SDK speaks, keyed by its wire name. */\nexport const SCHEMES = {\n [PROTOCOL_ANALYTICS]: schemeOf(PROTOCOL_ANALYTICS),\n [PROTOCOL_CONTRIBUTE]: schemeOf(PROTOCOL_CONTRIBUTE),\n [PROTOCOL_DND]: schemeOf(PROTOCOL_DND),\n [PROTOCOL_EDITOR]: schemeOf(PROTOCOL_EDITOR),\n [PROTOCOL_FEED]: schemeOf(PROTOCOL_FEED),\n [PROTOCOL_FETCH]: schemeOf(PROTOCOL_FETCH),\n [PROTOCOL_IPC]: schemeOf(PROTOCOL_IPC),\n [PROTOCOL_LAUNCH]: schemeOf(PROTOCOL_LAUNCH),\n [PROTOCOL_LLM]: schemeOf(PROTOCOL_LLM),\n [PROTOCOL_LOCALSTORE]: schemeOf(PROTOCOL_LOCALSTORE),\n [PROTOCOL_OPENLINK]: schemeOf(PROTOCOL_OPENLINK),\n [PROTOCOL_OPENREPO]: schemeOf(PROTOCOL_OPENREPO),\n [PROTOCOL_RECENTS]: schemeOf(PROTOCOL_RECENTS),\n [PROTOCOL_SECRETS]: schemeOf(PROTOCOL_SECRETS),\n [PROTOCOL_SETTINGS]: schemeOf(PROTOCOL_SETTINGS),\n [PROTOCOL_SPACES]: schemeOf(PROTOCOL_SPACES),\n [PROTOCOL_TASK]: schemeOf(PROTOCOL_TASK),\n [PROTOCOL_THEME]: schemeOf(PROTOCOL_THEME),\n [PROTOCOL_VCS]: schemeOf(PROTOCOL_VCS),\n} as const;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA2BA,sBAoBO;AAEP,MAAM,SAAS;AAYf,MAAM,WAAW,CAAwC,SACvD,KAAK,MAAM,OAAO,MAAM;AAGnB,MAAM,UAAU;AAAA,EACrB,CAAC,kCAAkB,GAAG,SAAS,kCAAkB;AAAA,EACjD,CAAC,mCAAmB,GAAG,SAAS,mCAAmB;AAAA,EACnD,CAAC,4BAAY,GAAG,SAAS,4BAAY;AAAA,EACrC,CAAC,+BAAe,GAAG,SAAS,+BAAe;AAAA,EAC3C,CAAC,6BAAa,GAAG,SAAS,6BAAa;AAAA,EACvC,CAAC,8BAAc,GAAG,SAAS,8BAAc;AAAA,EACzC,CAAC,4BAAY,GAAG,SAAS,4BAAY;AAAA,EACrC,CAAC,+BAAe,GAAG,SAAS,+BAAe;AAAA,EAC3C,CAAC,4BAAY,GAAG,SAAS,4BAAY;AAAA,EACrC,CAAC,mCAAmB,GAAG,SAAS,mCAAmB;AAAA,EACnD,CAAC,iCAAiB,GAAG,SAAS,iCAAiB;AAAA,EAC/C,CAAC,iCAAiB,GAAG,SAAS,iCAAiB;AAAA,EAC/C,CAAC,gCAAgB,GAAG,SAAS,gCAAgB;AAAA,EAC7C,CAAC,gCAAgB,GAAG,SAAS,gCAAgB;AAAA,EAC7C,CAAC,iCAAiB,GAAG,SAAS,iCAAiB;AAAA,EAC/C,CAAC,+BAAe,GAAG,SAAS,+BAAe;AAAA,EAC3C,CAAC,6BAAa,GAAG,SAAS,6BAAa;AAAA,EACvC,CAAC,8BAAc,GAAG,SAAS,8BAAc;AAAA,EACzC,CAAC,4BAAY,GAAG,SAAS,4BAAY;AACvC;","names":[]}
1
+ {"version":3,"sources":["../src/protocolSchemes.ts"],"sourcesContent":["// The `protocol-<scheme>` SCHEMES, derived from the wire names.\n//\n// `protocolRequest(scheme, method, params)` takes the scheme — `'theme'` — while the\n// wire name the frame dispatches on is `'protocol-theme'`; the frame adds the prefix.\n// So the typed service wrappers cannot pass the published `PROTOCOL_*` constant\n// directly, and spelling the scheme inline would put a second, unguarded copy of the\n// name back in the tree — exactly what R3-274c removes.\n//\n// Instead the schemes are *derived* from the wire names, keyed BY the wire name:\n//\n// protocolRequest(SCHEMES[PROTOCOL_THEME], 'set', [{ theme }])\n//\n// Keying by the constant is what makes the derivation unfalsifiable — there is no\n// second place to name the family, so there is no pair to get wrong. `schemeOf`\n// returns a template-literal conditional, so each value has a literal type (`'theme'`),\n// which buys two more things:\n//\n// - a wire name that stops matching `protocol-*` stops compiling here, rather than\n// silently producing an empty scheme at runtime;\n// - `check-protocol-snapshot.mjs` resolves `SCHEMES[PROTOCOL_THEME]` through the type\n// checker exactly like a plain literal, so the call sites stay visible to the gate.\n//\n// One export, deliberately: `./*` is a public subpath, so every name added here is\n// public API forever (ways_of_working §6, additive-only).\n//\n// This module is NOT generated — the derivation is the content — so it lives outside\n// `src/generated/`.\nimport {\n PROTOCOL_ANALYTICS,\n PROTOCOL_CONTRIBUTE,\n PROTOCOL_DND,\n PROTOCOL_EDITOR,\n PROTOCOL_FEED,\n PROTOCOL_FETCH,\n PROTOCOL_IPC,\n PROTOCOL_LAUNCH,\n PROTOCOL_LLM,\n PROTOCOL_LOCALSTORE,\n PROTOCOL_OPENLINK,\n PROTOCOL_OPENREPO,\n PROTOCOL_RECENTS,\n PROTOCOL_SECRETS,\n PROTOCOL_SETTINGS,\n PROTOCOL_SPACES,\n PROTOCOL_SPACES_MODE,\n PROTOCOL_TASK,\n PROTOCOL_THEME,\n PROTOCOL_VCS,\n} from './generated/protocol';\n\nconst PREFIX = 'protocol-';\n\n/** The scheme half of a `protocol-<scheme>` wire name. */\ntype SchemeOf<N extends string> = N extends `${typeof PREFIX}${infer S}` ? S : never;\n\n/**\n * `'protocol-theme'` → `'theme'`, as a literal type.\n *\n * The cast is the only place the derivation is asserted rather than computed; the\n * `N extends \\`protocol-${string}\\`` bound is what makes it sound — a wire name that is\n * not scheme-shaped is a compile error at the call, not a `never` at runtime.\n */\nconst schemeOf = <N extends `${typeof PREFIX}${string}`>(name: N): SchemeOf<N> =>\n name.slice(PREFIX.length) as SchemeOf<N>;\n\n/** Every `protocol-*` scheme the SDK speaks, keyed by its wire name. */\nexport const SCHEMES = {\n [PROTOCOL_ANALYTICS]: schemeOf(PROTOCOL_ANALYTICS),\n [PROTOCOL_CONTRIBUTE]: schemeOf(PROTOCOL_CONTRIBUTE),\n [PROTOCOL_DND]: schemeOf(PROTOCOL_DND),\n [PROTOCOL_EDITOR]: schemeOf(PROTOCOL_EDITOR),\n [PROTOCOL_FEED]: schemeOf(PROTOCOL_FEED),\n [PROTOCOL_FETCH]: schemeOf(PROTOCOL_FETCH),\n [PROTOCOL_IPC]: schemeOf(PROTOCOL_IPC),\n [PROTOCOL_LAUNCH]: schemeOf(PROTOCOL_LAUNCH),\n [PROTOCOL_LLM]: schemeOf(PROTOCOL_LLM),\n [PROTOCOL_LOCALSTORE]: schemeOf(PROTOCOL_LOCALSTORE),\n [PROTOCOL_OPENLINK]: schemeOf(PROTOCOL_OPENLINK),\n [PROTOCOL_OPENREPO]: schemeOf(PROTOCOL_OPENREPO),\n [PROTOCOL_RECENTS]: schemeOf(PROTOCOL_RECENTS),\n [PROTOCOL_SECRETS]: schemeOf(PROTOCOL_SECRETS),\n [PROTOCOL_SETTINGS]: schemeOf(PROTOCOL_SETTINGS),\n [PROTOCOL_SPACES]: schemeOf(PROTOCOL_SPACES),\n [PROTOCOL_SPACES_MODE]: schemeOf(PROTOCOL_SPACES_MODE),\n [PROTOCOL_TASK]: schemeOf(PROTOCOL_TASK),\n [PROTOCOL_THEME]: schemeOf(PROTOCOL_THEME),\n [PROTOCOL_VCS]: schemeOf(PROTOCOL_VCS),\n} as const;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA2BA,sBAqBO;AAEP,MAAM,SAAS;AAYf,MAAM,WAAW,CAAwC,SACvD,KAAK,MAAM,OAAO,MAAM;AAGnB,MAAM,UAAU;AAAA,EACrB,CAAC,kCAAkB,GAAG,SAAS,kCAAkB;AAAA,EACjD,CAAC,mCAAmB,GAAG,SAAS,mCAAmB;AAAA,EACnD,CAAC,4BAAY,GAAG,SAAS,4BAAY;AAAA,EACrC,CAAC,+BAAe,GAAG,SAAS,+BAAe;AAAA,EAC3C,CAAC,6BAAa,GAAG,SAAS,6BAAa;AAAA,EACvC,CAAC,8BAAc,GAAG,SAAS,8BAAc;AAAA,EACzC,CAAC,4BAAY,GAAG,SAAS,4BAAY;AAAA,EACrC,CAAC,+BAAe,GAAG,SAAS,+BAAe;AAAA,EAC3C,CAAC,4BAAY,GAAG,SAAS,4BAAY;AAAA,EACrC,CAAC,mCAAmB,GAAG,SAAS,mCAAmB;AAAA,EACnD,CAAC,iCAAiB,GAAG,SAAS,iCAAiB;AAAA,EAC/C,CAAC,iCAAiB,GAAG,SAAS,iCAAiB;AAAA,EAC/C,CAAC,gCAAgB,GAAG,SAAS,gCAAgB;AAAA,EAC7C,CAAC,gCAAgB,GAAG,SAAS,gCAAgB;AAAA,EAC7C,CAAC,iCAAiB,GAAG,SAAS,iCAAiB;AAAA,EAC/C,CAAC,+BAAe,GAAG,SAAS,+BAAe;AAAA,EAC3C,CAAC,oCAAoB,GAAG,SAAS,oCAAoB;AAAA,EACrD,CAAC,6BAAa,GAAG,SAAS,6BAAa;AAAA,EACvC,CAAC,8BAAc,GAAG,SAAS,8BAAc;AAAA,EACzC,CAAC,4BAAY,GAAG,SAAS,4BAAY;AACvC;","names":[]}
@@ -16,6 +16,7 @@ declare const SCHEMES: {
16
16
  readonly "protocol-secrets": "secrets";
17
17
  readonly "protocol-settings": "settings";
18
18
  readonly "protocol-spaces": "spaces";
19
+ readonly "protocol-spaces-mode": "spaces-mode";
19
20
  readonly "protocol-task": "task";
20
21
  readonly "protocol-theme": "theme";
21
22
  readonly "protocol-vcs": "vcs";
@@ -16,6 +16,7 @@ declare const SCHEMES: {
16
16
  readonly "protocol-secrets": "secrets";
17
17
  readonly "protocol-settings": "settings";
18
18
  readonly "protocol-spaces": "spaces";
19
+ readonly "protocol-spaces-mode": "spaces-mode";
19
20
  readonly "protocol-task": "task";
20
21
  readonly "protocol-theme": "theme";
21
22
  readonly "protocol-vcs": "vcs";
@@ -16,6 +16,7 @@ import {
16
16
  PROTOCOL_SECRETS,
17
17
  PROTOCOL_SETTINGS,
18
18
  PROTOCOL_SPACES,
19
+ PROTOCOL_SPACES_MODE,
19
20
  PROTOCOL_TASK,
20
21
  PROTOCOL_THEME,
21
22
  PROTOCOL_VCS
@@ -39,6 +40,7 @@ const SCHEMES = {
39
40
  [PROTOCOL_SECRETS]: schemeOf(PROTOCOL_SECRETS),
40
41
  [PROTOCOL_SETTINGS]: schemeOf(PROTOCOL_SETTINGS),
41
42
  [PROTOCOL_SPACES]: schemeOf(PROTOCOL_SPACES),
43
+ [PROTOCOL_SPACES_MODE]: schemeOf(PROTOCOL_SPACES_MODE),
42
44
  [PROTOCOL_TASK]: schemeOf(PROTOCOL_TASK),
43
45
  [PROTOCOL_THEME]: schemeOf(PROTOCOL_THEME),
44
46
  [PROTOCOL_VCS]: schemeOf(PROTOCOL_VCS)
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/protocolSchemes.ts"],"sourcesContent":["// The `protocol-<scheme>` SCHEMES, derived from the wire names.\n//\n// `protocolRequest(scheme, method, params)` takes the scheme — `'theme'` — while the\n// wire name the frame dispatches on is `'protocol-theme'`; the frame adds the prefix.\n// So the typed service wrappers cannot pass the published `PROTOCOL_*` constant\n// directly, and spelling the scheme inline would put a second, unguarded copy of the\n// name back in the tree — exactly what R3-274c removes.\n//\n// Instead the schemes are *derived* from the wire names, keyed BY the wire name:\n//\n// protocolRequest(SCHEMES[PROTOCOL_THEME], 'set', [{ theme }])\n//\n// Keying by the constant is what makes the derivation unfalsifiable — there is no\n// second place to name the family, so there is no pair to get wrong. `schemeOf`\n// returns a template-literal conditional, so each value has a literal type (`'theme'`),\n// which buys two more things:\n//\n// - a wire name that stops matching `protocol-*` stops compiling here, rather than\n// silently producing an empty scheme at runtime;\n// - `check-protocol-snapshot.mjs` resolves `SCHEMES[PROTOCOL_THEME]` through the type\n// checker exactly like a plain literal, so the call sites stay visible to the gate.\n//\n// One export, deliberately: `./*` is a public subpath, so every name added here is\n// public API forever (ways_of_working §6, additive-only).\n//\n// This module is NOT generated — the derivation is the content — so it lives outside\n// `src/generated/`.\nimport {\n PROTOCOL_ANALYTICS,\n PROTOCOL_CONTRIBUTE,\n PROTOCOL_DND,\n PROTOCOL_EDITOR,\n PROTOCOL_FEED,\n PROTOCOL_FETCH,\n PROTOCOL_IPC,\n PROTOCOL_LAUNCH,\n PROTOCOL_LLM,\n PROTOCOL_LOCALSTORE,\n PROTOCOL_OPENLINK,\n PROTOCOL_OPENREPO,\n PROTOCOL_RECENTS,\n PROTOCOL_SECRETS,\n PROTOCOL_SETTINGS,\n PROTOCOL_SPACES,\n PROTOCOL_TASK,\n PROTOCOL_THEME,\n PROTOCOL_VCS,\n} from './generated/protocol';\n\nconst PREFIX = 'protocol-';\n\n/** The scheme half of a `protocol-<scheme>` wire name. */\ntype SchemeOf<N extends string> = N extends `${typeof PREFIX}${infer S}` ? S : never;\n\n/**\n * `'protocol-theme'` → `'theme'`, as a literal type.\n *\n * The cast is the only place the derivation is asserted rather than computed; the\n * `N extends \\`protocol-${string}\\`` bound is what makes it sound — a wire name that is\n * not scheme-shaped is a compile error at the call, not a `never` at runtime.\n */\nconst schemeOf = <N extends `${typeof PREFIX}${string}`>(name: N): SchemeOf<N> =>\n name.slice(PREFIX.length) as SchemeOf<N>;\n\n/** Every `protocol-*` scheme the SDK speaks, keyed by its wire name. */\nexport const SCHEMES = {\n [PROTOCOL_ANALYTICS]: schemeOf(PROTOCOL_ANALYTICS),\n [PROTOCOL_CONTRIBUTE]: schemeOf(PROTOCOL_CONTRIBUTE),\n [PROTOCOL_DND]: schemeOf(PROTOCOL_DND),\n [PROTOCOL_EDITOR]: schemeOf(PROTOCOL_EDITOR),\n [PROTOCOL_FEED]: schemeOf(PROTOCOL_FEED),\n [PROTOCOL_FETCH]: schemeOf(PROTOCOL_FETCH),\n [PROTOCOL_IPC]: schemeOf(PROTOCOL_IPC),\n [PROTOCOL_LAUNCH]: schemeOf(PROTOCOL_LAUNCH),\n [PROTOCOL_LLM]: schemeOf(PROTOCOL_LLM),\n [PROTOCOL_LOCALSTORE]: schemeOf(PROTOCOL_LOCALSTORE),\n [PROTOCOL_OPENLINK]: schemeOf(PROTOCOL_OPENLINK),\n [PROTOCOL_OPENREPO]: schemeOf(PROTOCOL_OPENREPO),\n [PROTOCOL_RECENTS]: schemeOf(PROTOCOL_RECENTS),\n [PROTOCOL_SECRETS]: schemeOf(PROTOCOL_SECRETS),\n [PROTOCOL_SETTINGS]: schemeOf(PROTOCOL_SETTINGS),\n [PROTOCOL_SPACES]: schemeOf(PROTOCOL_SPACES),\n [PROTOCOL_TASK]: schemeOf(PROTOCOL_TASK),\n [PROTOCOL_THEME]: schemeOf(PROTOCOL_THEME),\n [PROTOCOL_VCS]: schemeOf(PROTOCOL_VCS),\n} as const;\n"],"mappings":";AA2BA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,MAAM,SAAS;AAYf,MAAM,WAAW,CAAwC,SACvD,KAAK,MAAM,OAAO,MAAM;AAGnB,MAAM,UAAU;AAAA,EACrB,CAAC,kBAAkB,GAAG,SAAS,kBAAkB;AAAA,EACjD,CAAC,mBAAmB,GAAG,SAAS,mBAAmB;AAAA,EACnD,CAAC,YAAY,GAAG,SAAS,YAAY;AAAA,EACrC,CAAC,eAAe,GAAG,SAAS,eAAe;AAAA,EAC3C,CAAC,aAAa,GAAG,SAAS,aAAa;AAAA,EACvC,CAAC,cAAc,GAAG,SAAS,cAAc;AAAA,EACzC,CAAC,YAAY,GAAG,SAAS,YAAY;AAAA,EACrC,CAAC,eAAe,GAAG,SAAS,eAAe;AAAA,EAC3C,CAAC,YAAY,GAAG,SAAS,YAAY;AAAA,EACrC,CAAC,mBAAmB,GAAG,SAAS,mBAAmB;AAAA,EACnD,CAAC,iBAAiB,GAAG,SAAS,iBAAiB;AAAA,EAC/C,CAAC,iBAAiB,GAAG,SAAS,iBAAiB;AAAA,EAC/C,CAAC,gBAAgB,GAAG,SAAS,gBAAgB;AAAA,EAC7C,CAAC,gBAAgB,GAAG,SAAS,gBAAgB;AAAA,EAC7C,CAAC,iBAAiB,GAAG,SAAS,iBAAiB;AAAA,EAC/C,CAAC,eAAe,GAAG,SAAS,eAAe;AAAA,EAC3C,CAAC,aAAa,GAAG,SAAS,aAAa;AAAA,EACvC,CAAC,cAAc,GAAG,SAAS,cAAc;AAAA,EACzC,CAAC,YAAY,GAAG,SAAS,YAAY;AACvC;","names":[]}
1
+ {"version":3,"sources":["../src/protocolSchemes.ts"],"sourcesContent":["// The `protocol-<scheme>` SCHEMES, derived from the wire names.\n//\n// `protocolRequest(scheme, method, params)` takes the scheme — `'theme'` — while the\n// wire name the frame dispatches on is `'protocol-theme'`; the frame adds the prefix.\n// So the typed service wrappers cannot pass the published `PROTOCOL_*` constant\n// directly, and spelling the scheme inline would put a second, unguarded copy of the\n// name back in the tree — exactly what R3-274c removes.\n//\n// Instead the schemes are *derived* from the wire names, keyed BY the wire name:\n//\n// protocolRequest(SCHEMES[PROTOCOL_THEME], 'set', [{ theme }])\n//\n// Keying by the constant is what makes the derivation unfalsifiable — there is no\n// second place to name the family, so there is no pair to get wrong. `schemeOf`\n// returns a template-literal conditional, so each value has a literal type (`'theme'`),\n// which buys two more things:\n//\n// - a wire name that stops matching `protocol-*` stops compiling here, rather than\n// silently producing an empty scheme at runtime;\n// - `check-protocol-snapshot.mjs` resolves `SCHEMES[PROTOCOL_THEME]` through the type\n// checker exactly like a plain literal, so the call sites stay visible to the gate.\n//\n// One export, deliberately: `./*` is a public subpath, so every name added here is\n// public API forever (ways_of_working §6, additive-only).\n//\n// This module is NOT generated — the derivation is the content — so it lives outside\n// `src/generated/`.\nimport {\n PROTOCOL_ANALYTICS,\n PROTOCOL_CONTRIBUTE,\n PROTOCOL_DND,\n PROTOCOL_EDITOR,\n PROTOCOL_FEED,\n PROTOCOL_FETCH,\n PROTOCOL_IPC,\n PROTOCOL_LAUNCH,\n PROTOCOL_LLM,\n PROTOCOL_LOCALSTORE,\n PROTOCOL_OPENLINK,\n PROTOCOL_OPENREPO,\n PROTOCOL_RECENTS,\n PROTOCOL_SECRETS,\n PROTOCOL_SETTINGS,\n PROTOCOL_SPACES,\n PROTOCOL_SPACES_MODE,\n PROTOCOL_TASK,\n PROTOCOL_THEME,\n PROTOCOL_VCS,\n} from './generated/protocol';\n\nconst PREFIX = 'protocol-';\n\n/** The scheme half of a `protocol-<scheme>` wire name. */\ntype SchemeOf<N extends string> = N extends `${typeof PREFIX}${infer S}` ? S : never;\n\n/**\n * `'protocol-theme'` → `'theme'`, as a literal type.\n *\n * The cast is the only place the derivation is asserted rather than computed; the\n * `N extends \\`protocol-${string}\\`` bound is what makes it sound — a wire name that is\n * not scheme-shaped is a compile error at the call, not a `never` at runtime.\n */\nconst schemeOf = <N extends `${typeof PREFIX}${string}`>(name: N): SchemeOf<N> =>\n name.slice(PREFIX.length) as SchemeOf<N>;\n\n/** Every `protocol-*` scheme the SDK speaks, keyed by its wire name. */\nexport const SCHEMES = {\n [PROTOCOL_ANALYTICS]: schemeOf(PROTOCOL_ANALYTICS),\n [PROTOCOL_CONTRIBUTE]: schemeOf(PROTOCOL_CONTRIBUTE),\n [PROTOCOL_DND]: schemeOf(PROTOCOL_DND),\n [PROTOCOL_EDITOR]: schemeOf(PROTOCOL_EDITOR),\n [PROTOCOL_FEED]: schemeOf(PROTOCOL_FEED),\n [PROTOCOL_FETCH]: schemeOf(PROTOCOL_FETCH),\n [PROTOCOL_IPC]: schemeOf(PROTOCOL_IPC),\n [PROTOCOL_LAUNCH]: schemeOf(PROTOCOL_LAUNCH),\n [PROTOCOL_LLM]: schemeOf(PROTOCOL_LLM),\n [PROTOCOL_LOCALSTORE]: schemeOf(PROTOCOL_LOCALSTORE),\n [PROTOCOL_OPENLINK]: schemeOf(PROTOCOL_OPENLINK),\n [PROTOCOL_OPENREPO]: schemeOf(PROTOCOL_OPENREPO),\n [PROTOCOL_RECENTS]: schemeOf(PROTOCOL_RECENTS),\n [PROTOCOL_SECRETS]: schemeOf(PROTOCOL_SECRETS),\n [PROTOCOL_SETTINGS]: schemeOf(PROTOCOL_SETTINGS),\n [PROTOCOL_SPACES]: schemeOf(PROTOCOL_SPACES),\n [PROTOCOL_SPACES_MODE]: schemeOf(PROTOCOL_SPACES_MODE),\n [PROTOCOL_TASK]: schemeOf(PROTOCOL_TASK),\n [PROTOCOL_THEME]: schemeOf(PROTOCOL_THEME),\n [PROTOCOL_VCS]: schemeOf(PROTOCOL_VCS),\n} as const;\n"],"mappings":";AA2BA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,MAAM,SAAS;AAYf,MAAM,WAAW,CAAwC,SACvD,KAAK,MAAM,OAAO,MAAM;AAGnB,MAAM,UAAU;AAAA,EACrB,CAAC,kBAAkB,GAAG,SAAS,kBAAkB;AAAA,EACjD,CAAC,mBAAmB,GAAG,SAAS,mBAAmB;AAAA,EACnD,CAAC,YAAY,GAAG,SAAS,YAAY;AAAA,EACrC,CAAC,eAAe,GAAG,SAAS,eAAe;AAAA,EAC3C,CAAC,aAAa,GAAG,SAAS,aAAa;AAAA,EACvC,CAAC,cAAc,GAAG,SAAS,cAAc;AAAA,EACzC,CAAC,YAAY,GAAG,SAAS,YAAY;AAAA,EACrC,CAAC,eAAe,GAAG,SAAS,eAAe;AAAA,EAC3C,CAAC,YAAY,GAAG,SAAS,YAAY;AAAA,EACrC,CAAC,mBAAmB,GAAG,SAAS,mBAAmB;AAAA,EACnD,CAAC,iBAAiB,GAAG,SAAS,iBAAiB;AAAA,EAC/C,CAAC,iBAAiB,GAAG,SAAS,iBAAiB;AAAA,EAC/C,CAAC,gBAAgB,GAAG,SAAS,gBAAgB;AAAA,EAC7C,CAAC,gBAAgB,GAAG,SAAS,gBAAgB;AAAA,EAC7C,CAAC,iBAAiB,GAAG,SAAS,iBAAiB;AAAA,EAC/C,CAAC,eAAe,GAAG,SAAS,eAAe;AAAA,EAC3C,CAAC,oBAAoB,GAAG,SAAS,oBAAoB;AAAA,EACrD,CAAC,aAAa,GAAG,SAAS,aAAa;AAAA,EACvC,CAAC,cAAc,GAAG,SAAS,cAAc;AAAA,EACzC,CAAC,YAAY,GAAG,SAAS,YAAY;AACvC;","names":[]}
package/dist/secrets.cjs CHANGED
@@ -27,16 +27,13 @@ __export(secrets_exports, {
27
27
  });
28
28
  module.exports = __toCommonJS(secrets_exports);
29
29
  var import_sandboxUtils = require("./sandboxUtils");
30
+ var import_protocolRefusal = require("./protocolRefusal");
30
31
  var import_pushChannel = require("./pushChannel");
31
32
  var import_protocol = require("./generated/protocol");
32
33
  var import_protocolSchemes = require("./protocolSchemes");
33
34
  const request = async (method, query = {}) => {
34
35
  const res = await (0, import_sandboxUtils.protocolRequest)(import_protocolSchemes.SCHEMES[import_protocol.PROTOCOL_SECRETS], method, [query]);
35
- if (!res || res.ok !== true) {
36
- const err = new Error(res?.message ?? "secret request failed");
37
- err.code = res?.code ?? "unknown";
38
- throw err;
39
- }
36
+ (0, import_protocolRefusal.throwOnRefusal)(res, "secret request failed");
40
37
  return res.data;
41
38
  };
42
39
  const requestAddSecret = (hints = {}) => request("add", hints);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/secrets.ts"],"sourcesContent":["// The host-owned secret store — app-facing surface (SECRETS_SPEC §4/§5).\n//\n// An app can ASK the user to store a secret (`requestAddSecret`), be GRANTED the\n// right to USE a specific secret (`requestSecret`, the powerbox flow), LIST\n// secret METADATA (`getSecrets`/`useSecrets`, never values), and REVOKE one\n// (`revokeSecret`). The secret VALUE never crosses this boundary: it is read\n// host-side, once, at the `net:fetch` injection point (SECRETS_SPEC §6). These\n// functions move only hints, metadata, and grant handles.\n//\n// Resolves LLM_AND_AGENTS_SPEC D2 — the host-mediated BYOK key store. Inert until\n// the host implements `protocol-secrets` + the `secrets-metadata` channel\n// (SECRETS_SPEC §3/§6 host work, roadmap P1.E); the contract is shipped here so\n// apps (e.g. the in-browser coding agent, P3-73) can be written against it.\nimport { protocolRequest } from './sandboxUtils';\nimport { createPushChannel } from './pushChannel';\nimport { PROTOCOL_SECRETS, REQUEST_SECRETS_METADATA, SECRETS_METADATA } from './generated/protocol';\nimport { SCHEMES } from './protocolSchemes';\n\n/** The closed secret-type vocabulary (SECRETS_SPEC §2). `api-key` is always\n * origin-bound; `oauth-refresh` is reserved (no substitution in v1). */\nexport type SecretType = 'api-key' | 'bearer-token' | 'oauth-refresh';\n\n/**\n * The metadata-only projection of a stored secret (SECRETS_SPEC §2/§4) — exactly\n * what `secrets:list` and the powerbox return. **There is no `value` field by\n * design**: the plaintext is never part of any record an app receives.\n */\nexport interface SecretView {\n id: string;\n type: SecretType;\n family?: string;\n description: string;\n /** Required for `type:'api-key'` — the one https origin it may be sent to. */\n boundOrigin?: string;\n /** ISO-8601, or null if never used (drives the §8.15 90-day expiry). */\n lastUsedAt: string | null;\n}\n\n/** Hints for the host's \"add secret\" modal (SECRETS_SPEC §4 `secrets:add`). The\n * app supplies only hints; the user types the value into host chrome. */\nexport interface SecretHints {\n type?: SecretType;\n family?: string;\n /** Pre-fill the bound origin (e.g. `https://api.anthropic.com`). */\n suggestedOrigin?: string;\n description?: string;\n}\n\n/** What `requestSecret()` matches against in the powerbox picker (SECRETS_SPEC §5). */\nexport interface SecretQuery {\n type?: SecretType;\n family?: string;\n}\n\n/**\n * The result of a granted `requestSecret()` — a durable `(appKey, secretId)` use\n * grant plus the secret's metadata. **Never the value.** Hold onto nothing but\n * this; the host substitutes the value into matching `net:fetch` requests.\n */\nexport interface SecretGrant {\n /** Opaque handle for the minted `(appKey, secretId)` grant. */\n grantId: string;\n /** Metadata of the bound secret (no value). */\n secret: SecretView;\n}\n\n/** An error from a secret operation, carrying a machine-readable `code`. */\nexport interface SecretError extends Error {\n code: 'auth-required' | 'cancelled' | 'forbidden' | 'not-found' | 'invalid-params' | 'unknown';\n}\n\ntype SecretResult = { ok: true; data: unknown } | { ok: false; code: string; message: string };\n\n// Issue a `protocol-secrets` request, unwrapping the host's {ok,data} envelope\n// and throwing a typed SecretError on failure (mirrors mounts.ts `request`).\nconst request = async <T = unknown>(method: string, query: object = {}): Promise<T> => {\n const res = (await protocolRequest(SCHEMES[PROTOCOL_SECRETS], method, [query])) as SecretResult;\n if (!res || res.ok !== true) {\n const err = new Error(res?.message ?? 'secret request failed') as SecretError;\n err.code = (res?.code as SecretError['code']) ?? 'unknown';\n throw err;\n }\n return res.data as T;\n};\n\n/**\n * Ask the user to store a new secret (SECRETS_SPEC §4 `secrets:add`). Opens a\n * **host-drawn** modal (the value is typed into host chrome, never via the app);\n * resolves with the new secret's {@link SecretView} metadata, or rejects with a\n * {@link SecretError} (`cancelled` if the user dismisses the modal). Requires the\n * `secrets:add` capability.\n */\nexport const requestAddSecret = (hints: SecretHints = {}): Promise<SecretView> => request<SecretView>('add', hints);\n\n/**\n * Ask the user to bind one of their stored secrets to this app (SECRETS_SPEC §5,\n * the powerbox flow — modeled on `requestSpace()`). The host draws a picker of\n * **only the user's matching secrets**; the user picks, declines, or creates one.\n * On success the host records a durable `(appKey, secretId)` grant and resolves\n * with a {@link SecretGrant} (handle + metadata, **never the value**).\n *\n * **No existence oracle (T20/T27):** a decline, an ungranted secret, and a\n * nonexistent secret are indistinguishable — all reject with a {@link SecretError}\n * `cancelled`; the app never sees the list it chose from.\n */\nexport const requestSecret = (query: SecretQuery = {}): Promise<SecretGrant> => request<SecretGrant>('request', query);\n\n/**\n * Delete a stored secret and tombstone every dependent per-app use grant\n * (SECRETS_SPEC §4 `secrets:revoke`, §8.15 cascade). Requires `secrets:revoke`.\n */\nexport const revokeSecret = async (id: string): Promise<void> => {\n await request('revoke', { id });\n};\n\n// The metadata-only `secrets-metadata` channel (Recipe A): the host pushes the\n// current secret metadata on change and replays it on register-frame; gated by\n// `secrets:list`. NEVER carries a value (SECRETS_SPEC §4).\nconst channel = createPushChannel<SecretView[]>({\n pushType: SECRETS_METADATA,\n requestType: REQUEST_SECRETS_METADATA,\n initial: [],\n parse: (msg) => (Array.isArray(msg.secrets) ? (msg.secrets as SecretView[]) : undefined),\n});\n\n/** The metadata of the user's stored secrets (never values), `secrets:list`. Poll\n * for a one-off read; use {@link onSecretsChange}/{@link useSecrets} to react. */\nexport const getSecrets = (): SecretView[] => channel.get();\n\n/** Subscribe to secret-metadata changes (added/revoked). Invoked immediately with\n * the current list, then on every change. Returns an unsubscribe fn. */\nexport const onSecretsChange = (listener: (secrets: SecretView[]) => void): (() => void) => channel.onChange(listener);\n\n/** React hook returning the user's secret metadata (never values), re-rendering\n * on change. For the Settings app (SECRETS_SPEC §7). */\nexport const useSecrets = (): SecretView[] => channel.use();\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,0BAAgC;AAChC,yBAAkC;AAClC,sBAA6E;AAC7E,6BAAwB;AA2DxB,MAAM,UAAU,OAAoB,QAAgB,QAAgB,CAAC,MAAkB;AACrF,QAAM,MAAO,UAAM,qCAAgB,+BAAQ,gCAAgB,GAAG,QAAQ,CAAC,KAAK,CAAC;AAC7E,MAAI,CAAC,OAAO,IAAI,OAAO,MAAM;AAC3B,UAAM,MAAM,IAAI,MAAM,KAAK,WAAW,uBAAuB;AAC7D,QAAI,OAAQ,KAAK,QAAgC;AACjD,UAAM;AAAA,EACR;AACA,SAAO,IAAI;AACb;AASO,MAAM,mBAAmB,CAAC,QAAqB,CAAC,MAA2B,QAAoB,OAAO,KAAK;AAa3G,MAAM,gBAAgB,CAAC,QAAqB,CAAC,MAA4B,QAAqB,WAAW,KAAK;AAM9G,MAAM,eAAe,OAAO,OAA8B;AAC/D,QAAM,QAAQ,UAAU,EAAE,GAAG,CAAC;AAChC;AAKA,MAAM,cAAU,sCAAgC;AAAA,EAC9C,UAAU;AAAA,EACV,aAAa;AAAA,EACb,SAAS,CAAC;AAAA,EACV,OAAO,CAAC,QAAS,MAAM,QAAQ,IAAI,OAAO,IAAK,IAAI,UAA2B;AAChF,CAAC;AAIM,MAAM,aAAa,MAAoB,QAAQ,IAAI;AAInD,MAAM,kBAAkB,CAAC,aAA4D,QAAQ,SAAS,QAAQ;AAI9G,MAAM,aAAa,MAAoB,QAAQ,IAAI;","names":[]}
1
+ {"version":3,"sources":["../src/secrets.ts"],"sourcesContent":["// The host-owned secret store — app-facing surface (SECRETS_SPEC §4/§5).\n//\n// An app can ASK the user to store a secret (`requestAddSecret`), be GRANTED the\n// right to USE a specific secret (`requestSecret`, the powerbox flow), LIST\n// secret METADATA (`getSecrets`/`useSecrets`, never values), and REVOKE one\n// (`revokeSecret`). The secret VALUE never crosses this boundary: it is read\n// host-side, once, at the `net:fetch` injection point (SECRETS_SPEC §6). These\n// functions move only hints, metadata, and grant handles.\n//\n// Resolves LLM_AND_AGENTS_SPEC D2 — the host-mediated BYOK key store. Inert until\n// the host implements `protocol-secrets` + the `secrets-metadata` channel\n// (SECRETS_SPEC §3/§6 host work, roadmap P1.E); the contract is shipped here so\n// apps (e.g. the in-browser coding agent, P3-73) can be written against it.\nimport { protocolRequest } from './sandboxUtils';\nimport { throwOnRefusal } from './protocolRefusal';\nimport { createPushChannel } from './pushChannel';\nimport { PROTOCOL_SECRETS, REQUEST_SECRETS_METADATA, SECRETS_METADATA } from './generated/protocol';\nimport { SCHEMES } from './protocolSchemes';\n\n/** The closed secret-type vocabulary (SECRETS_SPEC §2). `api-key` is always\n * origin-bound; `oauth-refresh` is reserved (no substitution in v1). */\nexport type SecretType = 'api-key' | 'bearer-token' | 'oauth-refresh';\n\n/**\n * The metadata-only projection of a stored secret (SECRETS_SPEC §2/§4) — exactly\n * what `secrets:list` and the powerbox return. **There is no `value` field by\n * design**: the plaintext is never part of any record an app receives.\n */\nexport interface SecretView {\n id: string;\n type: SecretType;\n family?: string;\n description: string;\n /** Required for `type:'api-key'` — the one https origin it may be sent to. */\n boundOrigin?: string;\n /** ISO-8601, or null if never used (drives the §8.15 90-day expiry). */\n lastUsedAt: string | null;\n}\n\n/** Hints for the host's \"add secret\" modal (SECRETS_SPEC §4 `secrets:add`). The\n * app supplies only hints; the user types the value into host chrome. */\nexport interface SecretHints {\n type?: SecretType;\n family?: string;\n /** Pre-fill the bound origin (e.g. `https://api.anthropic.com`). */\n suggestedOrigin?: string;\n description?: string;\n}\n\n/** What `requestSecret()` matches against in the powerbox picker (SECRETS_SPEC §5). */\nexport interface SecretQuery {\n type?: SecretType;\n family?: string;\n}\n\n/**\n * The result of a granted `requestSecret()` — a durable `(appKey, secretId)` use\n * grant plus the secret's metadata. **Never the value.** Hold onto nothing but\n * this; the host substitutes the value into matching `net:fetch` requests.\n */\nexport interface SecretGrant {\n /** Opaque handle for the minted `(appKey, secretId)` grant. */\n grantId: string;\n /** Metadata of the bound secret (no value). */\n secret: SecretView;\n}\n\n/** An error from a secret operation, carrying a machine-readable `code`. */\nexport interface SecretError extends Error {\n code: 'auth-required' | 'cancelled' | 'forbidden' | 'not-found' | 'invalid-params' | 'unknown';\n}\n\ntype SecretResult = { ok: true; data: unknown } | { ok: false; code: string; message: string };\n\n// Issue a `protocol-secrets` request, unwrapping the host's {ok,data} envelope\n// and throwing a typed SecretError on failure (mirrors mounts.ts `request`).\nconst request = async <T = unknown>(method: string, query: object = {}): Promise<T> => {\n const res = (await protocolRequest(SCHEMES[PROTOCOL_SECRETS], method, [query])) as SecretResult;\n throwOnRefusal(res, 'secret request failed');\n return res.data as T;\n};\n\n/**\n * Ask the user to store a new secret (SECRETS_SPEC §4 `secrets:add`). Opens a\n * **host-drawn** modal (the value is typed into host chrome, never via the app);\n * resolves with the new secret's {@link SecretView} metadata, or rejects with a\n * {@link SecretError} (`cancelled` if the user dismisses the modal). Requires the\n * `secrets:add` capability.\n */\nexport const requestAddSecret = (hints: SecretHints = {}): Promise<SecretView> => request<SecretView>('add', hints);\n\n/**\n * Ask the user to bind one of their stored secrets to this app (SECRETS_SPEC §5,\n * the powerbox flow — modeled on `requestSpace()`). The host draws a picker of\n * **only the user's matching secrets**; the user picks, declines, or creates one.\n * On success the host records a durable `(appKey, secretId)` grant and resolves\n * with a {@link SecretGrant} (handle + metadata, **never the value**).\n *\n * **No existence oracle (T20/T27):** a decline, an ungranted secret, and a\n * nonexistent secret are indistinguishable — all reject with a {@link SecretError}\n * `cancelled`; the app never sees the list it chose from.\n */\nexport const requestSecret = (query: SecretQuery = {}): Promise<SecretGrant> => request<SecretGrant>('request', query);\n\n/**\n * Delete a stored secret and tombstone every dependent per-app use grant\n * (SECRETS_SPEC §4 `secrets:revoke`, §8.15 cascade). Requires `secrets:revoke`.\n */\nexport const revokeSecret = async (id: string): Promise<void> => {\n await request('revoke', { id });\n};\n\n// The metadata-only `secrets-metadata` channel (Recipe A): the host pushes the\n// current secret metadata on change and replays it on register-frame; gated by\n// `secrets:list`. NEVER carries a value (SECRETS_SPEC §4).\nconst channel = createPushChannel<SecretView[]>({\n pushType: SECRETS_METADATA,\n requestType: REQUEST_SECRETS_METADATA,\n initial: [],\n parse: (msg) => (Array.isArray(msg.secrets) ? (msg.secrets as SecretView[]) : undefined),\n});\n\n/** The metadata of the user's stored secrets (never values), `secrets:list`. Poll\n * for a one-off read; use {@link onSecretsChange}/{@link useSecrets} to react. */\nexport const getSecrets = (): SecretView[] => channel.get();\n\n/** Subscribe to secret-metadata changes (added/revoked). Invoked immediately with\n * the current list, then on every change. Returns an unsubscribe fn. */\nexport const onSecretsChange = (listener: (secrets: SecretView[]) => void): (() => void) => channel.onChange(listener);\n\n/** React hook returning the user's secret metadata (never values), re-rendering\n * on change. For the Settings app (SECRETS_SPEC §7). */\nexport const useSecrets = (): SecretView[] => channel.use();\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,0BAAgC;AAChC,6BAA+B;AAC/B,yBAAkC;AAClC,sBAA6E;AAC7E,6BAAwB;AA2DxB,MAAM,UAAU,OAAoB,QAAgB,QAAgB,CAAC,MAAkB;AACrF,QAAM,MAAO,UAAM,qCAAgB,+BAAQ,gCAAgB,GAAG,QAAQ,CAAC,KAAK,CAAC;AAC7E,6CAAe,KAAK,uBAAuB;AAC3C,SAAO,IAAI;AACb;AASO,MAAM,mBAAmB,CAAC,QAAqB,CAAC,MAA2B,QAAoB,OAAO,KAAK;AAa3G,MAAM,gBAAgB,CAAC,QAAqB,CAAC,MAA4B,QAAqB,WAAW,KAAK;AAM9G,MAAM,eAAe,OAAO,OAA8B;AAC/D,QAAM,QAAQ,UAAU,EAAE,GAAG,CAAC;AAChC;AAKA,MAAM,cAAU,sCAAgC;AAAA,EAC9C,UAAU;AAAA,EACV,aAAa;AAAA,EACb,SAAS,CAAC;AAAA,EACV,OAAO,CAAC,QAAS,MAAM,QAAQ,IAAI,OAAO,IAAK,IAAI,UAA2B;AAChF,CAAC;AAIM,MAAM,aAAa,MAAoB,QAAQ,IAAI;AAInD,MAAM,kBAAkB,CAAC,aAA4D,QAAQ,SAAS,QAAQ;AAI9G,MAAM,aAAa,MAAoB,QAAQ,IAAI;","names":[]}
package/dist/secrets.js CHANGED
@@ -1,15 +1,12 @@
1
1
  import "./chunk-VHAA22YE.js";
2
2
  import { protocolRequest } from "./sandboxUtils.js";
3
+ import { throwOnRefusal } from "./protocolRefusal.js";
3
4
  import { createPushChannel } from "./pushChannel.js";
4
5
  import { PROTOCOL_SECRETS, REQUEST_SECRETS_METADATA, SECRETS_METADATA } from "./generated/protocol.js";
5
6
  import { SCHEMES } from "./protocolSchemes.js";
6
7
  const request = async (method, query = {}) => {
7
8
  const res = await protocolRequest(SCHEMES[PROTOCOL_SECRETS], method, [query]);
8
- if (!res || res.ok !== true) {
9
- const err = new Error(res?.message ?? "secret request failed");
10
- err.code = res?.code ?? "unknown";
11
- throw err;
12
- }
9
+ throwOnRefusal(res, "secret request failed");
13
10
  return res.data;
14
11
  };
15
12
  const requestAddSecret = (hints = {}) => request("add", hints);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/secrets.ts"],"sourcesContent":["// The host-owned secret store — app-facing surface (SECRETS_SPEC §4/§5).\n//\n// An app can ASK the user to store a secret (`requestAddSecret`), be GRANTED the\n// right to USE a specific secret (`requestSecret`, the powerbox flow), LIST\n// secret METADATA (`getSecrets`/`useSecrets`, never values), and REVOKE one\n// (`revokeSecret`). The secret VALUE never crosses this boundary: it is read\n// host-side, once, at the `net:fetch` injection point (SECRETS_SPEC §6). These\n// functions move only hints, metadata, and grant handles.\n//\n// Resolves LLM_AND_AGENTS_SPEC D2 — the host-mediated BYOK key store. Inert until\n// the host implements `protocol-secrets` + the `secrets-metadata` channel\n// (SECRETS_SPEC §3/§6 host work, roadmap P1.E); the contract is shipped here so\n// apps (e.g. the in-browser coding agent, P3-73) can be written against it.\nimport { protocolRequest } from './sandboxUtils';\nimport { createPushChannel } from './pushChannel';\nimport { PROTOCOL_SECRETS, REQUEST_SECRETS_METADATA, SECRETS_METADATA } from './generated/protocol';\nimport { SCHEMES } from './protocolSchemes';\n\n/** The closed secret-type vocabulary (SECRETS_SPEC §2). `api-key` is always\n * origin-bound; `oauth-refresh` is reserved (no substitution in v1). */\nexport type SecretType = 'api-key' | 'bearer-token' | 'oauth-refresh';\n\n/**\n * The metadata-only projection of a stored secret (SECRETS_SPEC §2/§4) — exactly\n * what `secrets:list` and the powerbox return. **There is no `value` field by\n * design**: the plaintext is never part of any record an app receives.\n */\nexport interface SecretView {\n id: string;\n type: SecretType;\n family?: string;\n description: string;\n /** Required for `type:'api-key'` — the one https origin it may be sent to. */\n boundOrigin?: string;\n /** ISO-8601, or null if never used (drives the §8.15 90-day expiry). */\n lastUsedAt: string | null;\n}\n\n/** Hints for the host's \"add secret\" modal (SECRETS_SPEC §4 `secrets:add`). The\n * app supplies only hints; the user types the value into host chrome. */\nexport interface SecretHints {\n type?: SecretType;\n family?: string;\n /** Pre-fill the bound origin (e.g. `https://api.anthropic.com`). */\n suggestedOrigin?: string;\n description?: string;\n}\n\n/** What `requestSecret()` matches against in the powerbox picker (SECRETS_SPEC §5). */\nexport interface SecretQuery {\n type?: SecretType;\n family?: string;\n}\n\n/**\n * The result of a granted `requestSecret()` — a durable `(appKey, secretId)` use\n * grant plus the secret's metadata. **Never the value.** Hold onto nothing but\n * this; the host substitutes the value into matching `net:fetch` requests.\n */\nexport interface SecretGrant {\n /** Opaque handle for the minted `(appKey, secretId)` grant. */\n grantId: string;\n /** Metadata of the bound secret (no value). */\n secret: SecretView;\n}\n\n/** An error from a secret operation, carrying a machine-readable `code`. */\nexport interface SecretError extends Error {\n code: 'auth-required' | 'cancelled' | 'forbidden' | 'not-found' | 'invalid-params' | 'unknown';\n}\n\ntype SecretResult = { ok: true; data: unknown } | { ok: false; code: string; message: string };\n\n// Issue a `protocol-secrets` request, unwrapping the host's {ok,data} envelope\n// and throwing a typed SecretError on failure (mirrors mounts.ts `request`).\nconst request = async <T = unknown>(method: string, query: object = {}): Promise<T> => {\n const res = (await protocolRequest(SCHEMES[PROTOCOL_SECRETS], method, [query])) as SecretResult;\n if (!res || res.ok !== true) {\n const err = new Error(res?.message ?? 'secret request failed') as SecretError;\n err.code = (res?.code as SecretError['code']) ?? 'unknown';\n throw err;\n }\n return res.data as T;\n};\n\n/**\n * Ask the user to store a new secret (SECRETS_SPEC §4 `secrets:add`). Opens a\n * **host-drawn** modal (the value is typed into host chrome, never via the app);\n * resolves with the new secret's {@link SecretView} metadata, or rejects with a\n * {@link SecretError} (`cancelled` if the user dismisses the modal). Requires the\n * `secrets:add` capability.\n */\nexport const requestAddSecret = (hints: SecretHints = {}): Promise<SecretView> => request<SecretView>('add', hints);\n\n/**\n * Ask the user to bind one of their stored secrets to this app (SECRETS_SPEC §5,\n * the powerbox flow — modeled on `requestSpace()`). The host draws a picker of\n * **only the user's matching secrets**; the user picks, declines, or creates one.\n * On success the host records a durable `(appKey, secretId)` grant and resolves\n * with a {@link SecretGrant} (handle + metadata, **never the value**).\n *\n * **No existence oracle (T20/T27):** a decline, an ungranted secret, and a\n * nonexistent secret are indistinguishable — all reject with a {@link SecretError}\n * `cancelled`; the app never sees the list it chose from.\n */\nexport const requestSecret = (query: SecretQuery = {}): Promise<SecretGrant> => request<SecretGrant>('request', query);\n\n/**\n * Delete a stored secret and tombstone every dependent per-app use grant\n * (SECRETS_SPEC §4 `secrets:revoke`, §8.15 cascade). Requires `secrets:revoke`.\n */\nexport const revokeSecret = async (id: string): Promise<void> => {\n await request('revoke', { id });\n};\n\n// The metadata-only `secrets-metadata` channel (Recipe A): the host pushes the\n// current secret metadata on change and replays it on register-frame; gated by\n// `secrets:list`. NEVER carries a value (SECRETS_SPEC §4).\nconst channel = createPushChannel<SecretView[]>({\n pushType: SECRETS_METADATA,\n requestType: REQUEST_SECRETS_METADATA,\n initial: [],\n parse: (msg) => (Array.isArray(msg.secrets) ? (msg.secrets as SecretView[]) : undefined),\n});\n\n/** The metadata of the user's stored secrets (never values), `secrets:list`. Poll\n * for a one-off read; use {@link onSecretsChange}/{@link useSecrets} to react. */\nexport const getSecrets = (): SecretView[] => channel.get();\n\n/** Subscribe to secret-metadata changes (added/revoked). Invoked immediately with\n * the current list, then on every change. Returns an unsubscribe fn. */\nexport const onSecretsChange = (listener: (secrets: SecretView[]) => void): (() => void) => channel.onChange(listener);\n\n/** React hook returning the user's secret metadata (never values), re-rendering\n * on change. For the Settings app (SECRETS_SPEC §7). */\nexport const useSecrets = (): SecretView[] => channel.use();\n"],"mappings":";AAaA,SAAS,uBAAuB;AAChC,SAAS,yBAAyB;AAClC,SAAS,kBAAkB,0BAA0B,wBAAwB;AAC7E,SAAS,eAAe;AA2DxB,MAAM,UAAU,OAAoB,QAAgB,QAAgB,CAAC,MAAkB;AACrF,QAAM,MAAO,MAAM,gBAAgB,QAAQ,gBAAgB,GAAG,QAAQ,CAAC,KAAK,CAAC;AAC7E,MAAI,CAAC,OAAO,IAAI,OAAO,MAAM;AAC3B,UAAM,MAAM,IAAI,MAAM,KAAK,WAAW,uBAAuB;AAC7D,QAAI,OAAQ,KAAK,QAAgC;AACjD,UAAM;AAAA,EACR;AACA,SAAO,IAAI;AACb;AASO,MAAM,mBAAmB,CAAC,QAAqB,CAAC,MAA2B,QAAoB,OAAO,KAAK;AAa3G,MAAM,gBAAgB,CAAC,QAAqB,CAAC,MAA4B,QAAqB,WAAW,KAAK;AAM9G,MAAM,eAAe,OAAO,OAA8B;AAC/D,QAAM,QAAQ,UAAU,EAAE,GAAG,CAAC;AAChC;AAKA,MAAM,UAAU,kBAAgC;AAAA,EAC9C,UAAU;AAAA,EACV,aAAa;AAAA,EACb,SAAS,CAAC;AAAA,EACV,OAAO,CAAC,QAAS,MAAM,QAAQ,IAAI,OAAO,IAAK,IAAI,UAA2B;AAChF,CAAC;AAIM,MAAM,aAAa,MAAoB,QAAQ,IAAI;AAInD,MAAM,kBAAkB,CAAC,aAA4D,QAAQ,SAAS,QAAQ;AAI9G,MAAM,aAAa,MAAoB,QAAQ,IAAI;","names":[]}
1
+ {"version":3,"sources":["../src/secrets.ts"],"sourcesContent":["// The host-owned secret store — app-facing surface (SECRETS_SPEC §4/§5).\n//\n// An app can ASK the user to store a secret (`requestAddSecret`), be GRANTED the\n// right to USE a specific secret (`requestSecret`, the powerbox flow), LIST\n// secret METADATA (`getSecrets`/`useSecrets`, never values), and REVOKE one\n// (`revokeSecret`). The secret VALUE never crosses this boundary: it is read\n// host-side, once, at the `net:fetch` injection point (SECRETS_SPEC §6). These\n// functions move only hints, metadata, and grant handles.\n//\n// Resolves LLM_AND_AGENTS_SPEC D2 — the host-mediated BYOK key store. Inert until\n// the host implements `protocol-secrets` + the `secrets-metadata` channel\n// (SECRETS_SPEC §3/§6 host work, roadmap P1.E); the contract is shipped here so\n// apps (e.g. the in-browser coding agent, P3-73) can be written against it.\nimport { protocolRequest } from './sandboxUtils';\nimport { throwOnRefusal } from './protocolRefusal';\nimport { createPushChannel } from './pushChannel';\nimport { PROTOCOL_SECRETS, REQUEST_SECRETS_METADATA, SECRETS_METADATA } from './generated/protocol';\nimport { SCHEMES } from './protocolSchemes';\n\n/** The closed secret-type vocabulary (SECRETS_SPEC §2). `api-key` is always\n * origin-bound; `oauth-refresh` is reserved (no substitution in v1). */\nexport type SecretType = 'api-key' | 'bearer-token' | 'oauth-refresh';\n\n/**\n * The metadata-only projection of a stored secret (SECRETS_SPEC §2/§4) — exactly\n * what `secrets:list` and the powerbox return. **There is no `value` field by\n * design**: the plaintext is never part of any record an app receives.\n */\nexport interface SecretView {\n id: string;\n type: SecretType;\n family?: string;\n description: string;\n /** Required for `type:'api-key'` — the one https origin it may be sent to. */\n boundOrigin?: string;\n /** ISO-8601, or null if never used (drives the §8.15 90-day expiry). */\n lastUsedAt: string | null;\n}\n\n/** Hints for the host's \"add secret\" modal (SECRETS_SPEC §4 `secrets:add`). The\n * app supplies only hints; the user types the value into host chrome. */\nexport interface SecretHints {\n type?: SecretType;\n family?: string;\n /** Pre-fill the bound origin (e.g. `https://api.anthropic.com`). */\n suggestedOrigin?: string;\n description?: string;\n}\n\n/** What `requestSecret()` matches against in the powerbox picker (SECRETS_SPEC §5). */\nexport interface SecretQuery {\n type?: SecretType;\n family?: string;\n}\n\n/**\n * The result of a granted `requestSecret()` — a durable `(appKey, secretId)` use\n * grant plus the secret's metadata. **Never the value.** Hold onto nothing but\n * this; the host substitutes the value into matching `net:fetch` requests.\n */\nexport interface SecretGrant {\n /** Opaque handle for the minted `(appKey, secretId)` grant. */\n grantId: string;\n /** Metadata of the bound secret (no value). */\n secret: SecretView;\n}\n\n/** An error from a secret operation, carrying a machine-readable `code`. */\nexport interface SecretError extends Error {\n code: 'auth-required' | 'cancelled' | 'forbidden' | 'not-found' | 'invalid-params' | 'unknown';\n}\n\ntype SecretResult = { ok: true; data: unknown } | { ok: false; code: string; message: string };\n\n// Issue a `protocol-secrets` request, unwrapping the host's {ok,data} envelope\n// and throwing a typed SecretError on failure (mirrors mounts.ts `request`).\nconst request = async <T = unknown>(method: string, query: object = {}): Promise<T> => {\n const res = (await protocolRequest(SCHEMES[PROTOCOL_SECRETS], method, [query])) as SecretResult;\n throwOnRefusal(res, 'secret request failed');\n return res.data as T;\n};\n\n/**\n * Ask the user to store a new secret (SECRETS_SPEC §4 `secrets:add`). Opens a\n * **host-drawn** modal (the value is typed into host chrome, never via the app);\n * resolves with the new secret's {@link SecretView} metadata, or rejects with a\n * {@link SecretError} (`cancelled` if the user dismisses the modal). Requires the\n * `secrets:add` capability.\n */\nexport const requestAddSecret = (hints: SecretHints = {}): Promise<SecretView> => request<SecretView>('add', hints);\n\n/**\n * Ask the user to bind one of their stored secrets to this app (SECRETS_SPEC §5,\n * the powerbox flow — modeled on `requestSpace()`). The host draws a picker of\n * **only the user's matching secrets**; the user picks, declines, or creates one.\n * On success the host records a durable `(appKey, secretId)` grant and resolves\n * with a {@link SecretGrant} (handle + metadata, **never the value**).\n *\n * **No existence oracle (T20/T27):** a decline, an ungranted secret, and a\n * nonexistent secret are indistinguishable — all reject with a {@link SecretError}\n * `cancelled`; the app never sees the list it chose from.\n */\nexport const requestSecret = (query: SecretQuery = {}): Promise<SecretGrant> => request<SecretGrant>('request', query);\n\n/**\n * Delete a stored secret and tombstone every dependent per-app use grant\n * (SECRETS_SPEC §4 `secrets:revoke`, §8.15 cascade). Requires `secrets:revoke`.\n */\nexport const revokeSecret = async (id: string): Promise<void> => {\n await request('revoke', { id });\n};\n\n// The metadata-only `secrets-metadata` channel (Recipe A): the host pushes the\n// current secret metadata on change and replays it on register-frame; gated by\n// `secrets:list`. NEVER carries a value (SECRETS_SPEC §4).\nconst channel = createPushChannel<SecretView[]>({\n pushType: SECRETS_METADATA,\n requestType: REQUEST_SECRETS_METADATA,\n initial: [],\n parse: (msg) => (Array.isArray(msg.secrets) ? (msg.secrets as SecretView[]) : undefined),\n});\n\n/** The metadata of the user's stored secrets (never values), `secrets:list`. Poll\n * for a one-off read; use {@link onSecretsChange}/{@link useSecrets} to react. */\nexport const getSecrets = (): SecretView[] => channel.get();\n\n/** Subscribe to secret-metadata changes (added/revoked). Invoked immediately with\n * the current list, then on every change. Returns an unsubscribe fn. */\nexport const onSecretsChange = (listener: (secrets: SecretView[]) => void): (() => void) => channel.onChange(listener);\n\n/** React hook returning the user's secret metadata (never values), re-rendering\n * on change. For the Settings app (SECRETS_SPEC §7). */\nexport const useSecrets = (): SecretView[] => channel.use();\n"],"mappings":";AAaA,SAAS,uBAAuB;AAChC,SAAS,sBAAsB;AAC/B,SAAS,yBAAyB;AAClC,SAAS,kBAAkB,0BAA0B,wBAAwB;AAC7E,SAAS,eAAe;AA2DxB,MAAM,UAAU,OAAoB,QAAgB,QAAgB,CAAC,MAAkB;AACrF,QAAM,MAAO,MAAM,gBAAgB,QAAQ,gBAAgB,GAAG,QAAQ,CAAC,KAAK,CAAC;AAC7E,iBAAe,KAAK,uBAAuB;AAC3C,SAAO,IAAI;AACb;AASO,MAAM,mBAAmB,CAAC,QAAqB,CAAC,MAA2B,QAAoB,OAAO,KAAK;AAa3G,MAAM,gBAAgB,CAAC,QAAqB,CAAC,MAA4B,QAAqB,WAAW,KAAK;AAM9G,MAAM,eAAe,OAAO,OAA8B;AAC/D,QAAM,QAAQ,UAAU,EAAE,GAAG,CAAC;AAChC;AAKA,MAAM,UAAU,kBAAgC;AAAA,EAC9C,UAAU;AAAA,EACV,aAAa;AAAA,EACb,SAAS,CAAC;AAAA,EACV,OAAO,CAAC,QAAS,MAAM,QAAQ,IAAI,OAAO,IAAK,IAAI,UAA2B;AAChF,CAAC;AAIM,MAAM,aAAa,MAAoB,QAAQ,IAAI;AAInD,MAAM,kBAAkB,CAAC,aAA4D,QAAQ,SAAS,QAAQ;AAI9G,MAAM,aAAa,MAAoB,QAAQ,IAAI;","names":[]}
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var spacesMode_exports = {};
20
+ __export(spacesMode_exports, {
21
+ getSpacesMode: () => getSpacesMode,
22
+ navigateSpaces: () => navigateSpaces,
23
+ onSpacesModeChange: () => onSpacesModeChange,
24
+ useSpacesMode: () => useSpacesMode
25
+ });
26
+ module.exports = __toCommonJS(spacesMode_exports);
27
+ var import_sandboxUtils = require("./sandboxUtils");
28
+ var import_protocolRefusal = require("./protocolRefusal");
29
+ var import_pushChannel = require("./pushChannel");
30
+ var import_protocol = require("./generated/protocol");
31
+ var import_protocolSchemes = require("./protocolSchemes");
32
+ const ACTIVITIES = ["spaces", "inbox", "people", "settings"];
33
+ const ROLES = ["owner", "writer", "reader"];
34
+ const KINDS = ["personal", "shared"];
35
+ const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
36
+ const optionalString = (v) => v === void 0 || typeof v === "string";
37
+ const parseRoute = (v) => {
38
+ if (!isRecord(v)) return void 0;
39
+ if (typeof v.activity !== "string" || !ACTIVITIES.includes(v.activity)) return void 0;
40
+ if (!(v.spaceId === null || typeof v.spaceId === "string")) return void 0;
41
+ if (!optionalString(v.path) || !optionalString(v.roomId)) return void 0;
42
+ if (!optionalString(v.member) || !optionalString(v.section)) return void 0;
43
+ const route = {
44
+ spaceId: v.spaceId,
45
+ activity: v.activity
46
+ };
47
+ if (typeof v.path === "string") route.path = v.path;
48
+ if (typeof v.roomId === "string") route.roomId = v.roomId;
49
+ if (typeof v.member === "string") route.member = v.member;
50
+ if (typeof v.section === "string") route.section = v.section;
51
+ return route;
52
+ };
53
+ const parseSpace = (v) => {
54
+ if (v === null) return null;
55
+ if (!isRecord(v)) return void 0;
56
+ if (typeof v.id !== "string" || typeof v.name !== "string") return void 0;
57
+ if (typeof v.role !== "string" || !ROLES.includes(v.role)) return void 0;
58
+ if (typeof v.kind !== "string" || !KINDS.includes(v.kind)) return void 0;
59
+ if (!(v.root === null || typeof v.root === "string")) return void 0;
60
+ return {
61
+ id: v.id,
62
+ name: v.name,
63
+ role: v.role,
64
+ kind: v.kind,
65
+ root: v.root
66
+ };
67
+ };
68
+ const parseState = (state) => {
69
+ if (state === null) return null;
70
+ if (!isRecord(state)) return void 0;
71
+ const route = parseRoute(state.route);
72
+ if (!route) return void 0;
73
+ const space = parseSpace(state.space);
74
+ if (space === void 0) return void 0;
75
+ return { route, space };
76
+ };
77
+ const channel = (0, import_pushChannel.createPushChannel)({
78
+ pushType: import_protocol.SPACES_MODE,
79
+ requestType: import_protocol.REQUEST_SPACES_MODE,
80
+ initial: null,
81
+ // Written inline, reading `msg.state` here rather than inside the helper: the snapshot
82
+ // gate extracts a push channel's `reads` from THIS expression, and a bare function
83
+ // reference tells it nothing — it falls back to the parameter type and the wire shape
84
+ // reads `Record<string, unknown>` instead of `{reads:["state"]}`.
85
+ parse: (msg) => parseState(msg.state)
86
+ });
87
+ const getSpacesMode = () => channel.get();
88
+ const onSpacesModeChange = (listener) => channel.onChange(listener);
89
+ const useSpacesMode = () => channel.use();
90
+ async function navigateSpaces(target) {
91
+ const res = await (0, import_sandboxUtils.protocolRequest)(import_protocolSchemes.SCHEMES[import_protocol.PROTOCOL_SPACES_MODE], "navigate", [target]);
92
+ (0, import_protocolRefusal.throwOnRefusal)(res, "spaces navigation refused");
93
+ }
94
+ // Annotate the CommonJS export names for ESM import in node:
95
+ 0 && (module.exports = {
96
+ getSpacesMode,
97
+ navigateSpaces,
98
+ onSpacesModeChange,
99
+ useSpacesMode
100
+ });
101
+ //# sourceMappingURL=spacesMode.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/spacesMode.ts"],"sourcesContent":["// The spaces mode's route channel and its one navigation verb (R3-708).\n//\n// The spaces mode runs ONE app across six frames — three activity pairs — and they must\n// agree on which space, activity and bundle is selected. A reload or a pasted link has to\n// land every frame on the same state, so the selection is a route the HOST owns and\n// deep-links to (`SPACES_BRIEF` §3), not something the frames negotiate between\n// themselves.\n//\n// Two halves, and the asymmetry is the point:\n//\n// read `useSpacesMode()` — the host's parsed route, pushed down.\n// write `navigateSpaces(target)` — a request to MOVE, taking coordinates.\n//\n// The write half never takes a path string, now or later. An app that could spell the\n// destination could open anything (`BUNDLE_EMBEDDING_SPEC` §6.1a), so the SDK offers no\n// string overload and the host builds every URL from its own grammar\n// (`SPACES_BRIEF` §7, \"the host spells the URL\"). That is also why an app reads\n// `space.root` for its files rather than assuming a mount path.\nimport { protocolRequest } from './sandboxUtils';\nimport { throwOnRefusal } from './protocolRefusal';\nimport { createPushChannel } from './pushChannel';\nimport { SPACES_MODE, REQUEST_SPACES_MODE, PROTOCOL_SPACES_MODE } from './generated/protocol';\nimport { SCHEMES } from './protocolSchemes';\n\n/** The spaces mode's four top-level activities. */\nexport type SpacesActivity = 'spaces' | 'inbox' | 'people' | 'settings';\n\n/**\n * Where the user is inside the spaces mode, as the host parsed it.\n *\n * `spaceId` is `null` on a route that names no space, which is TWO routes, not one: the\n * launcher (`activity: 'spaces'`) and the **cross-space inbox** (`activity: 'inbox'` —\n * `/spaces/-/inbox`, every room across every space). Branch on the pair, not on `spaceId`\n * alone.\n *\n * The `-` in that URL is the host's reserved segment and never reaches here: it is not an\n * id, and an app must not send `spaceId: '-'` hoping to mean \"all spaces\" — say\n * `{ spaceId: null, activity: 'inbox' }`. The host spells the URL (`SPACES_BRIEF` §7); the\n * SDK never sees that grammar.\n *\n * The optional fields are the per-activity tail: `path` a bundle-relative file, `roomId` a\n * conversation, `member` the uid of `/spaces/<id>/people/<uid>`, `section` a settings pane.\n */\nexport interface SpacesRoute {\n spaceId: string | null;\n activity: SpacesActivity;\n path?: string;\n roomId?: string;\n member?: string;\n section?: string;\n}\n\n/**\n * The selected space, as the host resolved it for THIS frame.\n *\n * `root` is the path the host mounted the space at in this frame, at the reader's role —\n * or `null` in every frame the host did not mount it into. Read files under `root`; never\n * assume a mount path.\n *\n * `name` is untrusted display text supplied by whoever named the space. React escapes it\n * on render and the SDK does not sanitise it — treat it as content, not markup.\n *\n * `kind` (not `mode`) matches site-main's `SpaceKind`: one noun for the personal/shared\n * axis (R-IX-6).\n *\n * **None of this is a grant.** The object describes what the host chose to tell this\n * frame; it confers nothing. `role` is a label for deciding which affordances to *show* —\n * it is not permission to act, and an app that branches on `role === 'owner'` to skip\n * asking has only skipped its own UI, not the check. What IS enforced host-side is the\n * mount: `root` is mounted at the reader's role, so a reader's frame cannot write through\n * it (`site-main` `filesystem/liveRevocation.ts` derives the mount mode from the role, and\n * `editor/spaceHandler.ts` re-checks `role` on the owner-only paths).\n *\n * What is NOT enforced, and must not be read into the above: per-APP authority.\n * `UI_AS_APPS_SPEC` §8's audited gap is explicit that `mount` \"accepts an arbitrary\n * `spaceId` and enforces only user membership … every app currently inherits the user's\n * full authority\". So the host answers \"may the USER do this\", not \"may this app\", and a\n * frame holding this object is no more constrained than the reader is. Treat it as a\n * description of the reader's position, never as a sandbox around the app.\n *\n * A frame the host does not push to reads `null` — an absence of information, not a\n * denial, and equally not a reason to assume access.\n */\nexport interface SpacesModeSpace {\n id: string;\n name: string;\n role: 'owner' | 'writer' | 'reader';\n kind: 'personal' | 'shared';\n root: string | null;\n}\n\n/** The host's view of this frame: where the user is, and which space that resolves to. */\nexport interface SpacesModeState {\n route: SpacesRoute;\n space: SpacesModeSpace | null;\n}\n\n/**\n * Where to move to.\n *\n * Either a route inside the mode, or the one host destination outside it —\n * `{ destination: 'notifications' }`, which the inventory panel's line pointing at pending\n * invitations uses so the app never spells a mode path itself.\n */\nexport type SpacesTarget = SpacesRoute | { destination: 'notifications' };\n\n/** Why the host refused to navigate.\n *\n * - `invalid` — the target is not a route this host can build. This is also the code for\n * a space the reader has no membership-granted view of, **deliberately**: P7 forbids an\n * existence oracle, and `SPACES_BRIEF` §7 says a doclink into a space the reader is not\n * a member of \"renders the same not-found as a link to nothing\". A distinct code here\n * would be exactly the oracle — an app could enumerate spaceIds and read membership off\n * the difference. Non-member and never-existed are one answer.\n * - `forbidden` — this frame lacks the CAPABILITY to navigate at all. It is a statement\n * about the caller, never about the target, so it discloses nothing about what exists.\n * - `unsupported` — this host has no spaces mode wired.\n * - `unknown` — the host refused without naming a code. */\nexport type NavigateSpacesErrorCode = 'invalid' | 'forbidden' | 'unsupported' | 'unknown';\n\nexport interface NavigateSpacesError extends Error {\n code: NavigateSpacesErrorCode;\n}\n\nconst ACTIVITIES: readonly string[] = ['spaces', 'inbox', 'people', 'settings'];\nconst ROLES: readonly string[] = ['owner', 'writer', 'reader'];\nconst KINDS: readonly string[] = ['personal', 'shared'];\n\nconst isRecord = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);\n\n/** A present field must be a string; an absent one is fine. Anything else fails. */\nconst optionalString = (v: unknown): boolean => v === undefined || typeof v === 'string';\n\nconst parseRoute = (v: unknown): SpacesRoute | undefined => {\n if (!isRecord(v)) return undefined;\n if (typeof v.activity !== 'string' || !ACTIVITIES.includes(v.activity)) return undefined;\n if (!(v.spaceId === null || typeof v.spaceId === 'string')) return undefined;\n if (!optionalString(v.path) || !optionalString(v.roomId)) return undefined;\n if (!optionalString(v.member) || !optionalString(v.section)) return undefined;\n const route: SpacesRoute = {\n spaceId: v.spaceId as string | null,\n activity: v.activity as SpacesActivity,\n };\n // Copied field by field rather than spread: a host that adds a field tomorrow must not\n // have it silently appear on an object apps treat as this version's shape.\n if (typeof v.path === 'string') route.path = v.path;\n if (typeof v.roomId === 'string') route.roomId = v.roomId;\n if (typeof v.member === 'string') route.member = v.member;\n if (typeof v.section === 'string') route.section = v.section;\n return route;\n};\n\nconst parseSpace = (v: unknown): SpacesModeSpace | null | undefined => {\n if (v === null) return null;\n if (!isRecord(v)) return undefined;\n if (typeof v.id !== 'string' || typeof v.name !== 'string') return undefined;\n if (typeof v.role !== 'string' || !ROLES.includes(v.role)) return undefined;\n if (typeof v.kind !== 'string' || !KINDS.includes(v.kind)) return undefined;\n if (!(v.root === null || typeof v.root === 'string')) return undefined;\n return {\n id: v.id,\n name: v.name,\n role: v.role as SpacesModeSpace['role'],\n kind: v.kind as SpacesModeSpace['kind'],\n root: v.root as string | null,\n };\n};\n\n// Tolerant parse. `undefined` means \"ignore this message\", so a malformed push from a\n// newer or older host leaves the LAST GOOD value standing instead of flipping every frame\n// to a route nobody sent. Nothing in here throws: a throw in the listener would take down\n// the push loop for every channel sharing it.\nconst parseState = (state: unknown): SpacesModeState | null | undefined => {\n // A pushed `null` is a RETRACTION, not a malformed message, and the wire says so: the\n // channel's declared value is `SpacesModeState | null` (sandbox-protocol 0.11.0,\n // `snapshots/sdk.json`, `spaces-mode.value`). Folding it into the `isRecord` guard below\n // made it mean \"ignore\", which left the host with no way to say \"this frame has left the\n // mode\" — the last route would stand forever, and an app would keep rendering a space it\n // is no longer in. `null` here is distinct from `undefined`: it SETS the value.\n if (state === null) return null;\n if (!isRecord(state)) return undefined;\n const route = parseRoute(state.route);\n if (!route) return undefined;\n const space = parseSpace(state.space);\n if (space === undefined) return undefined;\n return { route, space };\n};\n\n// `initial: null` is the whole compatibility story, and it is deliberately NOT a synthetic\n// `{ activity: 'spaces' }`: an app must be able to tell \"the host has not told me anything\"\n// from \"the host says I am on the launcher\". A frame outside the mode, a standalone tab,\n// `vite dev`, an older host, or a frame lacking the read capability all stay `null`, and an\n// app falls back to its pre-mode UI there.\nconst channel = createPushChannel<SpacesModeState | null>({\n pushType: SPACES_MODE,\n requestType: REQUEST_SPACES_MODE,\n initial: null,\n // Written inline, reading `msg.state` here rather than inside the helper: the snapshot\n // gate extracts a push channel's `reads` from THIS expression, and a bare function\n // reference tells it nothing — it falls back to the parameter type and the wire shape\n // reads `Record<string, unknown>` instead of `{reads:[\"state\"]}`.\n parse: (msg) => parseState(msg.state),\n});\n\n/**\n * The host's spaces-mode state for this frame, or `null` when this app is not running in\n * the spaces mode — a standalone tab, `vite dev`, an older host, or a frame the host does\n * not push this to.\n *\n * `null` is a real answer, not a placeholder: fall back to your own UI rather than\n * assuming a route.\n */\nexport const getSpacesMode = (): SpacesModeState | null => channel.get();\n\n/**\n * Subscribe to spaces-mode changes. The listener is invoked immediately with the current\n * value, then on every change. Returns an unsubscribe function.\n */\nexport const onSpacesModeChange = (listener: (state: SpacesModeState | null) => void): (() => void) =>\n channel.onChange(listener);\n\n/**\n * React hook form of {@link getSpacesMode} — re-renders when the host's route changes.\n *\n * ```tsx\n * const mode = useSpacesMode();\n * if (!mode) return <MyStandaloneUI />; // not in the spaces mode\n * if (!mode.space) return <Launcher />; // no space selected\n * if (!mode.space.root) return <NotMountedHere />; // selected, but not mounted into THIS\n * return <Files root={mode.space.root} />; // never assume a mount path\n * ```\n *\n * The third guard is not defensive padding: `root` is `null` in every frame the host did\n * not mount the space into, which is every frame but the launcher's. Passing it through\n * unchecked is the mistake this example exists to prevent.\n */\nexport const useSpacesMode = (): SpacesModeState | null => channel.use();\n\n/** The host's reply ENVELOPE (site-main's `SpaceResult`). A refusal is a RESOLVED\n * `{ ok: false, code, message }` frame, not a transport-level rejection — see\n * `protocolRefusal.ts` for which `ok` this is and why a handler must THROW\n * `spaceError` rather than return `{ ok: false }`. R3-707's `navigate` handler must\n * throw. */\ntype NavigateReply = { ok: true; data?: unknown } | { ok: false; code?: string; message?: string };\n\n/**\n * Ask the host to move the spaces mode to `target`.\n *\n * Resolves once the host has navigated. Rejects with a typed {@link NavigateSpacesError}\n * carrying `code` when the host refuses.\n *\n * The target is always structured coordinates — there is no path-string form, because an\n * app that could spell the destination could open anything. To leave the mode for the one\n * host destination outside it, pass `{ destination: 'notifications' }`.\n *\n * ```ts\n * await navigateSpaces({ spaceId: 'abc', activity: 'spaces', path: 'notes/today.mdx' });\n * await navigateSpaces({ destination: 'notifications' });\n * ```\n */\nexport async function navigateSpaces(target: SpacesTarget): Promise<void> {\n const res = (await protocolRequest(SCHEMES[PROTOCOL_SPACES_MODE], 'navigate', [target])) as NavigateReply;\n throwOnRefusal(res, 'spaces navigation refused');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBA,0BAAgC;AAChC,6BAA+B;AAC/B,yBAAkC;AAClC,sBAAuE;AACvE,6BAAwB;AAsGxB,MAAM,aAAgC,CAAC,UAAU,SAAS,UAAU,UAAU;AAC9E,MAAM,QAA2B,CAAC,SAAS,UAAU,QAAQ;AAC7D,MAAM,QAA2B,CAAC,YAAY,QAAQ;AAEtD,MAAM,WAAW,CAAC,MAA6C,OAAO,MAAM,YAAY,MAAM,QAAQ,CAAC,MAAM,QAAQ,CAAC;AAGtH,MAAM,iBAAiB,CAAC,MAAwB,MAAM,UAAa,OAAO,MAAM;AAEhF,MAAM,aAAa,CAAC,MAAwC;AAC1D,MAAI,CAAC,SAAS,CAAC,EAAG,QAAO;AACzB,MAAI,OAAO,EAAE,aAAa,YAAY,CAAC,WAAW,SAAS,EAAE,QAAQ,EAAG,QAAO;AAC/E,MAAI,EAAE,EAAE,YAAY,QAAQ,OAAO,EAAE,YAAY,UAAW,QAAO;AACnE,MAAI,CAAC,eAAe,EAAE,IAAI,KAAK,CAAC,eAAe,EAAE,MAAM,EAAG,QAAO;AACjE,MAAI,CAAC,eAAe,EAAE,MAAM,KAAK,CAAC,eAAe,EAAE,OAAO,EAAG,QAAO;AACpE,QAAM,QAAqB;AAAA,IACzB,SAAS,EAAE;AAAA,IACX,UAAU,EAAE;AAAA,EACd;AAGA,MAAI,OAAO,EAAE,SAAS,SAAU,OAAM,OAAO,EAAE;AAC/C,MAAI,OAAO,EAAE,WAAW,SAAU,OAAM,SAAS,EAAE;AACnD,MAAI,OAAO,EAAE,WAAW,SAAU,OAAM,SAAS,EAAE;AACnD,MAAI,OAAO,EAAE,YAAY,SAAU,OAAM,UAAU,EAAE;AACrD,SAAO;AACT;AAEA,MAAM,aAAa,CAAC,MAAmD;AACrE,MAAI,MAAM,KAAM,QAAO;AACvB,MAAI,CAAC,SAAS,CAAC,EAAG,QAAO;AACzB,MAAI,OAAO,EAAE,OAAO,YAAY,OAAO,EAAE,SAAS,SAAU,QAAO;AACnE,MAAI,OAAO,EAAE,SAAS,YAAY,CAAC,MAAM,SAAS,EAAE,IAAI,EAAG,QAAO;AAClE,MAAI,OAAO,EAAE,SAAS,YAAY,CAAC,MAAM,SAAS,EAAE,IAAI,EAAG,QAAO;AAClE,MAAI,EAAE,EAAE,SAAS,QAAQ,OAAO,EAAE,SAAS,UAAW,QAAO;AAC7D,SAAO;AAAA,IACL,IAAI,EAAE;AAAA,IACN,MAAM,EAAE;AAAA,IACR,MAAM,EAAE;AAAA,IACR,MAAM,EAAE;AAAA,IACR,MAAM,EAAE;AAAA,EACV;AACF;AAMA,MAAM,aAAa,CAAC,UAAuD;AAOzE,MAAI,UAAU,KAAM,QAAO;AAC3B,MAAI,CAAC,SAAS,KAAK,EAAG,QAAO;AAC7B,QAAM,QAAQ,WAAW,MAAM,KAAK;AACpC,MAAI,CAAC,MAAO,QAAO;AACnB,QAAM,QAAQ,WAAW,MAAM,KAAK;AACpC,MAAI,UAAU,OAAW,QAAO;AAChC,SAAO,EAAE,OAAO,MAAM;AACxB;AAOA,MAAM,cAAU,sCAA0C;AAAA,EACxD,UAAU;AAAA,EACV,aAAa;AAAA,EACb,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA,EAKT,OAAO,CAAC,QAAQ,WAAW,IAAI,KAAK;AACtC,CAAC;AAUM,MAAM,gBAAgB,MAA8B,QAAQ,IAAI;AAMhE,MAAM,qBAAqB,CAAC,aACjC,QAAQ,SAAS,QAAQ;AAiBpB,MAAM,gBAAgB,MAA8B,QAAQ,IAAI;AAwBvE,eAAsB,eAAe,QAAqC;AACxE,QAAM,MAAO,UAAM,qCAAgB,+BAAQ,oCAAoB,GAAG,YAAY,CAAC,MAAM,CAAC;AACtF,6CAAe,KAAK,2BAA2B;AACjD;","names":[]}
@@ -0,0 +1,143 @@
1
+ /** The spaces mode's four top-level activities. */
2
+ type SpacesActivity = 'spaces' | 'inbox' | 'people' | 'settings';
3
+ /**
4
+ * Where the user is inside the spaces mode, as the host parsed it.
5
+ *
6
+ * `spaceId` is `null` on a route that names no space, which is TWO routes, not one: the
7
+ * launcher (`activity: 'spaces'`) and the **cross-space inbox** (`activity: 'inbox'` —
8
+ * `/spaces/-/inbox`, every room across every space). Branch on the pair, not on `spaceId`
9
+ * alone.
10
+ *
11
+ * The `-` in that URL is the host's reserved segment and never reaches here: it is not an
12
+ * id, and an app must not send `spaceId: '-'` hoping to mean "all spaces" — say
13
+ * `{ spaceId: null, activity: 'inbox' }`. The host spells the URL (`SPACES_BRIEF` §7); the
14
+ * SDK never sees that grammar.
15
+ *
16
+ * The optional fields are the per-activity tail: `path` a bundle-relative file, `roomId` a
17
+ * conversation, `member` the uid of `/spaces/<id>/people/<uid>`, `section` a settings pane.
18
+ */
19
+ interface SpacesRoute {
20
+ spaceId: string | null;
21
+ activity: SpacesActivity;
22
+ path?: string;
23
+ roomId?: string;
24
+ member?: string;
25
+ section?: string;
26
+ }
27
+ /**
28
+ * The selected space, as the host resolved it for THIS frame.
29
+ *
30
+ * `root` is the path the host mounted the space at in this frame, at the reader's role —
31
+ * or `null` in every frame the host did not mount it into. Read files under `root`; never
32
+ * assume a mount path.
33
+ *
34
+ * `name` is untrusted display text supplied by whoever named the space. React escapes it
35
+ * on render and the SDK does not sanitise it — treat it as content, not markup.
36
+ *
37
+ * `kind` (not `mode`) matches site-main's `SpaceKind`: one noun for the personal/shared
38
+ * axis (R-IX-6).
39
+ *
40
+ * **None of this is a grant.** The object describes what the host chose to tell this
41
+ * frame; it confers nothing. `role` is a label for deciding which affordances to *show* —
42
+ * it is not permission to act, and an app that branches on `role === 'owner'` to skip
43
+ * asking has only skipped its own UI, not the check. What IS enforced host-side is the
44
+ * mount: `root` is mounted at the reader's role, so a reader's frame cannot write through
45
+ * it (`site-main` `filesystem/liveRevocation.ts` derives the mount mode from the role, and
46
+ * `editor/spaceHandler.ts` re-checks `role` on the owner-only paths).
47
+ *
48
+ * What is NOT enforced, and must not be read into the above: per-APP authority.
49
+ * `UI_AS_APPS_SPEC` §8's audited gap is explicit that `mount` "accepts an arbitrary
50
+ * `spaceId` and enforces only user membership … every app currently inherits the user's
51
+ * full authority". So the host answers "may the USER do this", not "may this app", and a
52
+ * frame holding this object is no more constrained than the reader is. Treat it as a
53
+ * description of the reader's position, never as a sandbox around the app.
54
+ *
55
+ * A frame the host does not push to reads `null` — an absence of information, not a
56
+ * denial, and equally not a reason to assume access.
57
+ */
58
+ interface SpacesModeSpace {
59
+ id: string;
60
+ name: string;
61
+ role: 'owner' | 'writer' | 'reader';
62
+ kind: 'personal' | 'shared';
63
+ root: string | null;
64
+ }
65
+ /** The host's view of this frame: where the user is, and which space that resolves to. */
66
+ interface SpacesModeState {
67
+ route: SpacesRoute;
68
+ space: SpacesModeSpace | null;
69
+ }
70
+ /**
71
+ * Where to move to.
72
+ *
73
+ * Either a route inside the mode, or the one host destination outside it —
74
+ * `{ destination: 'notifications' }`, which the inventory panel's line pointing at pending
75
+ * invitations uses so the app never spells a mode path itself.
76
+ */
77
+ type SpacesTarget = SpacesRoute | {
78
+ destination: 'notifications';
79
+ };
80
+ /** Why the host refused to navigate.
81
+ *
82
+ * - `invalid` — the target is not a route this host can build. This is also the code for
83
+ * a space the reader has no membership-granted view of, **deliberately**: P7 forbids an
84
+ * existence oracle, and `SPACES_BRIEF` §7 says a doclink into a space the reader is not
85
+ * a member of "renders the same not-found as a link to nothing". A distinct code here
86
+ * would be exactly the oracle — an app could enumerate spaceIds and read membership off
87
+ * the difference. Non-member and never-existed are one answer.
88
+ * - `forbidden` — this frame lacks the CAPABILITY to navigate at all. It is a statement
89
+ * about the caller, never about the target, so it discloses nothing about what exists.
90
+ * - `unsupported` — this host has no spaces mode wired.
91
+ * - `unknown` — the host refused without naming a code. */
92
+ type NavigateSpacesErrorCode = 'invalid' | 'forbidden' | 'unsupported' | 'unknown';
93
+ interface NavigateSpacesError extends Error {
94
+ code: NavigateSpacesErrorCode;
95
+ }
96
+ /**
97
+ * The host's spaces-mode state for this frame, or `null` when this app is not running in
98
+ * the spaces mode — a standalone tab, `vite dev`, an older host, or a frame the host does
99
+ * not push this to.
100
+ *
101
+ * `null` is a real answer, not a placeholder: fall back to your own UI rather than
102
+ * assuming a route.
103
+ */
104
+ declare const getSpacesMode: () => SpacesModeState | null;
105
+ /**
106
+ * Subscribe to spaces-mode changes. The listener is invoked immediately with the current
107
+ * value, then on every change. Returns an unsubscribe function.
108
+ */
109
+ declare const onSpacesModeChange: (listener: (state: SpacesModeState | null) => void) => (() => void);
110
+ /**
111
+ * React hook form of {@link getSpacesMode} — re-renders when the host's route changes.
112
+ *
113
+ * ```tsx
114
+ * const mode = useSpacesMode();
115
+ * if (!mode) return <MyStandaloneUI />; // not in the spaces mode
116
+ * if (!mode.space) return <Launcher />; // no space selected
117
+ * if (!mode.space.root) return <NotMountedHere />; // selected, but not mounted into THIS
118
+ * return <Files root={mode.space.root} />; // never assume a mount path
119
+ * ```
120
+ *
121
+ * The third guard is not defensive padding: `root` is `null` in every frame the host did
122
+ * not mount the space into, which is every frame but the launcher's. Passing it through
123
+ * unchecked is the mistake this example exists to prevent.
124
+ */
125
+ declare const useSpacesMode: () => SpacesModeState | null;
126
+ /**
127
+ * Ask the host to move the spaces mode to `target`.
128
+ *
129
+ * Resolves once the host has navigated. Rejects with a typed {@link NavigateSpacesError}
130
+ * carrying `code` when the host refuses.
131
+ *
132
+ * The target is always structured coordinates — there is no path-string form, because an
133
+ * app that could spell the destination could open anything. To leave the mode for the one
134
+ * host destination outside it, pass `{ destination: 'notifications' }`.
135
+ *
136
+ * ```ts
137
+ * await navigateSpaces({ spaceId: 'abc', activity: 'spaces', path: 'notes/today.mdx' });
138
+ * await navigateSpaces({ destination: 'notifications' });
139
+ * ```
140
+ */
141
+ declare function navigateSpaces(target: SpacesTarget): Promise<void>;
142
+
143
+ export { type NavigateSpacesError, type NavigateSpacesErrorCode, type SpacesActivity, type SpacesModeSpace, type SpacesModeState, type SpacesRoute, type SpacesTarget, getSpacesMode, navigateSpaces, onSpacesModeChange, useSpacesMode };