@immediately-run/sdk 0.84.1 → 0.85.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/catalog.cjs +2 -0
- package/dist/catalog.cjs.map +1 -1
- package/dist/catalog.js +2 -0
- package/dist/catalog.js.map +1 -1
- package/dist/contribute.cjs.map +1 -1
- package/dist/contribute.d.cts +39 -1
- package/dist/contribute.d.ts +39 -1
- package/dist/contribute.js.map +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/openBundle.cjs +44 -0
- package/dist/openBundle.cjs.map +1 -0
- package/dist/openBundle.d.cts +53 -0
- package/dist/openBundle.d.ts +53 -0
- package/dist/openBundle.js +20 -0
- package/dist/openBundle.js.map +1 -0
- package/dist/openRepository.cjs +4 -4
- package/dist/openRepository.cjs.map +1 -1
- package/dist/openRepository.d.cts +12 -2
- package/dist/openRepository.d.ts +12 -2
- package/dist/openRepository.js +4 -4
- package/dist/openRepository.js.map +1 -1
- package/dist/protocolRefusal.cjs.map +1 -1
- package/dist/protocolRefusal.d.cts +1 -1
- package/dist/protocolRefusal.d.ts +1 -1
- package/dist/protocolRefusal.js.map +1 -1
- package/dist/protocolSchemes.cjs +1 -0
- package/dist/protocolSchemes.cjs.map +1 -1
- package/dist/protocolSchemes.d.cts +1 -0
- package/dist/protocolSchemes.d.ts +1 -0
- package/dist/protocolSchemes.js +2 -0
- package/dist/protocolSchemes.js.map +1 -1
- package/dist/vcs.cjs +106 -1
- package/dist/vcs.cjs.map +1 -1
- package/dist/vcs.d.cts +104 -1
- package/dist/vcs.d.ts +104 -1
- package/dist/vcs.js +99 -1
- 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 +2 -2
package/dist/catalog.cjs
CHANGED
|
@@ -40,6 +40,8 @@ const invoke = async (name, params = {}) => {
|
|
|
40
40
|
if (!res || res.ok !== true) {
|
|
41
41
|
const err = new Error(res?.message ?? `${name} failed`);
|
|
42
42
|
err.code = res?.code ?? "unknown";
|
|
43
|
+
const wait = res?.retryAfter;
|
|
44
|
+
if (Number.isFinite(wait)) err.retryAfter = wait;
|
|
43
45
|
throw err;
|
|
44
46
|
}
|
|
45
47
|
return res.data;
|
package/dist/catalog.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/catalog.ts"],"sourcesContent":["// The method catalog (UI_AS_APPS_SPEC §5.5) — the app's own grant-filtered RPC\n// surface, and a generic way to call it. The host advertises exactly the methods\n// this app may invoke (MCP-tool-shaped); `invoke()` calls one by its catalog name.\n// Handing the catalog to an embedded agent as its tool list confines the agent to\n// the app's authority (agent sandboxing falls out of the capability model, §5.9).\nimport { protocolRequest, sendMessage, addListener } from './sandboxUtils';\nimport type { StreamFrame, StreamTransport } from './protocolStream';\nimport { consumeStream } from './protocolStream';\nimport { createPushChannel } from './pushChannel';\nimport { API_CATALOG, REQUEST_API_CATALOG } from './generated/protocol';\n\n/** One advertised method, as the host generated it from its gate table. */\nexport interface ApiMethod {\n /** Catalog name, `protocol-` stripped — e.g. `spaces:invite`, `contribute:run`. */\n name: string;\n /** The capability this method requires (already held — it's in your catalog). */\n capability: string;\n /** True when the method STREAMS (use {@link invokeStream}) vs. single-reply. */\n stream?: boolean;\n /**\n * JSON Schema for the method's single object argument, when the host declares one.\n * Self-describes the call so a catalog-as-tools bridge (an embedded agent) can\n * advertise the real param shape — e.g. that `authoring:typecheck` takes a nested\n * `{ files: [{ path, content }] }` array — instead of a permissive \"any object\".\n * Absent for methods the host advertises without a schema.\n */\n paramsSchema?: Record<string, unknown>;\n}\n\n// `scheme:method` → ['scheme', 'method'] (the wire protocol is `protocol-scheme`).\nconst split = (name: string): [string, string] => {\n const i = name.indexOf(':');\n if (i <= 0) throw new Error(`invalid catalog method name: ${name}`);\n return [name.slice(0, i), name.slice(i + 1)];\n};\n\n/**\n * Call a catalog method by name — `invoke('spaces:invite', { spaceId, login, role })`.\n * A thin generic over the host protocol: the host validates params and gates the\n * call (an un-granted method → `forbidden`, even if you name it directly). For a\n * STREAMING method (`ApiMethod.stream`), use {@link invokeStream}.\n */\nexport const invoke = async <T = unknown>(name: string, params: Record<string, unknown> = {}): Promise<T> => {\n const [scheme, method] = split(name);\n // The host replies with an `{ ok, data } | { ok:false, code }` envelope; unwrap\n // it and THROW on refusal (a `.code` like `forbidden` for an off-catalog call)\n // so callers — and any agent driving `invoke` — see the gate's verdict.\n const res = (await protocolRequest(scheme, method, [params])) as\n | { ok: true; data: unknown }\n | { ok: false; code?: string; message?: string }\n | undefined;\n if (!res || res.ok !== true) {\n const err = new Error(res?.message ?? `${name} failed`) as Error & { code?: string };\n err.code = res?.code ?? 'unknown';\n throw err;\n }\n return res.data as T;\n};\n\n// Stream transport over the resolver (SDK_PACKAGING_SPEC §4) — sendMessage /\n// addListener route through `transport()` (injected bundler messageBus or the §4\n// global), never `bundler.messageBus` directly.\nconst streamTransport: StreamTransport = {\n send: (msg) => sendMessage(msg.type, msg as unknown as Record<string, unknown>),\n subscribe: (type, handler) => addListener(type, (msg) => handler(msg as { msgId?: number; stream?: StreamFrame })),\n // Early-cancel: route a `{type, msgId, cancel:true}` frame back to the host so it\n // aborts the in-flight generation (and, for `llm:chat`, stops billing) — §3.3.\n cancel: (msg) => sendMessage(msg.type, msg as unknown as Record<string, unknown>),\n};\n\n/** Call a STREAMING catalog method by name, yielding its events. Pass `signal` to\n * abort mid-stream: the host stops generating and (for `llm:chat`) stops billing. */\nexport function invokeStream<T = unknown, R = unknown>(\n name: string,\n params: Record<string, unknown> = {},\n signal?: AbortSignal,\n): AsyncGenerator<T, R, void> {\n const [scheme, method] = split(name);\n return consumeStream<T, R>(streamTransport, `protocol-${scheme}`, method, [params], undefined, signal);\n}\n\n// The catalog list is read over the transport (§4): the host pushes `api-catalog`\n// and answers `request-api-catalog` with this app's grant-filtered methods (wire\n// format: site-main channelBridge.ts).\nconst channel = createPushChannel<ApiMethod[]>({\n pushType: API_CATALOG,\n requestType: REQUEST_API_CATALOG,\n initial: [],\n parse: (msg) => (Array.isArray(msg.methods) ? (msg.methods as ApiMethod[]) : undefined),\n});\n\n/** The methods this app may call (grant-filtered, §5.5). Poll for a one-off read;\n * use {@link onCatalogChange} / {@link useCatalog} to react. */\nexport const getCatalog = (): ApiMethod[] => channel.get();\n\n/** Subscribe to catalog changes (e.g. a grant added/revoked). Invoked immediately\n * with the current catalog, then on every change. Returns an unsubscribe fn. */\nexport const onCatalogChange = (listener: (catalog: ApiMethod[]) => void): (() => void) => channel.onChange(listener);\n\n/** React hook returning this app's method catalog, re-rendering on change. Hand\n * it to an embedded agent as its tool list to confine the agent to the app's\n * authority (§5.9). */\nexport const useCatalog = (): ApiMethod[] => channel.use();\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,0BAA0D;AAE1D,4BAA8B;AAC9B,yBAAkC;AAClC,sBAAiD;AAqBjD,MAAM,QAAQ,CAAC,SAAmC;AAChD,QAAM,IAAI,KAAK,QAAQ,GAAG;AAC1B,MAAI,KAAK,EAAG,OAAM,IAAI,MAAM,gCAAgC,IAAI,EAAE;AAClE,SAAO,CAAC,KAAK,MAAM,GAAG,CAAC,GAAG,KAAK,MAAM,IAAI,CAAC,CAAC;AAC7C;AAQO,MAAM,SAAS,OAAoB,MAAc,SAAkC,CAAC,MAAkB;AAC3G,QAAM,CAAC,QAAQ,MAAM,IAAI,MAAM,IAAI;AAInC,QAAM,MAAO,UAAM,qCAAgB,QAAQ,QAAQ,CAAC,MAAM,CAAC;AAI3D,MAAI,CAAC,OAAO,IAAI,OAAO,MAAM;AAC3B,UAAM,MAAM,IAAI,MAAM,KAAK,WAAW,GAAG,IAAI,SAAS;AACtD,QAAI,OAAO,KAAK,QAAQ;
|
|
1
|
+
{"version":3,"sources":["../src/catalog.ts"],"sourcesContent":["// The method catalog (UI_AS_APPS_SPEC §5.5) — the app's own grant-filtered RPC\n// surface, and a generic way to call it. The host advertises exactly the methods\n// this app may invoke (MCP-tool-shaped); `invoke()` calls one by its catalog name.\n// Handing the catalog to an embedded agent as its tool list confines the agent to\n// the app's authority (agent sandboxing falls out of the capability model, §5.9).\nimport { protocolRequest, sendMessage, addListener } from './sandboxUtils';\nimport type { StreamFrame, StreamTransport } from './protocolStream';\nimport { consumeStream } from './protocolStream';\nimport { createPushChannel } from './pushChannel';\nimport { API_CATALOG, REQUEST_API_CATALOG } from './generated/protocol';\n\n/** One advertised method, as the host generated it from its gate table. */\nexport interface ApiMethod {\n /** Catalog name, `protocol-` stripped — e.g. `spaces:invite`, `contribute:run`. */\n name: string;\n /** The capability this method requires (already held — it's in your catalog). */\n capability: string;\n /** True when the method STREAMS (use {@link invokeStream}) vs. single-reply. */\n stream?: boolean;\n /**\n * JSON Schema for the method's single object argument, when the host declares one.\n * Self-describes the call so a catalog-as-tools bridge (an embedded agent) can\n * advertise the real param shape — e.g. that `authoring:typecheck` takes a nested\n * `{ files: [{ path, content }] }` array — instead of a permissive \"any object\".\n * Absent for methods the host advertises without a schema.\n */\n paramsSchema?: Record<string, unknown>;\n}\n\n// `scheme:method` → ['scheme', 'method'] (the wire protocol is `protocol-scheme`).\nconst split = (name: string): [string, string] => {\n const i = name.indexOf(':');\n if (i <= 0) throw new Error(`invalid catalog method name: ${name}`);\n return [name.slice(0, i), name.slice(i + 1)];\n};\n\n/**\n * Call a catalog method by name — `invoke('spaces:invite', { spaceId, login, role })`.\n * A thin generic over the host protocol: the host validates params and gates the\n * call (an un-granted method → `forbidden`, even if you name it directly). For a\n * STREAMING method (`ApiMethod.stream`), use {@link invokeStream}.\n */\nexport const invoke = async <T = unknown>(name: string, params: Record<string, unknown> = {}): Promise<T> => {\n const [scheme, method] = split(name);\n // The host replies with an `{ ok, data } | { ok:false, code }` envelope; unwrap\n // it and THROW on refusal (a `.code` like `forbidden` for an off-catalog call)\n // so callers — and any agent driving `invoke` — see the gate's verdict.\n const res = (await protocolRequest(scheme, method, [params])) as\n | { ok: true; data: unknown }\n | { ok: false; code?: string; message?: string; retryAfter?: unknown }\n | undefined;\n if (!res || res.ok !== true) {\n const err = new Error(res?.message ?? `${name} failed`) as Error & { code?: string; retryAfter?: number };\n err.code = res?.code ?? 'unknown';\n // R3-954: a provider rate-limit refusal (`budget`) carries the wait in seconds.\n // Number.isFinite, not typeof: NaN and Infinity are numbers the structured-clone\n // transport carries intact — the same reason the sibling guards (vcs.ts) use it.\n const wait = res?.retryAfter;\n if (Number.isFinite(wait)) err.retryAfter = wait as number;\n throw err;\n }\n return res.data as T;\n};\n\n// Stream transport over the resolver (SDK_PACKAGING_SPEC §4) — sendMessage /\n// addListener route through `transport()` (injected bundler messageBus or the §4\n// global), never `bundler.messageBus` directly.\nconst streamTransport: StreamTransport = {\n send: (msg) => sendMessage(msg.type, msg as unknown as Record<string, unknown>),\n subscribe: (type, handler) => addListener(type, (msg) => handler(msg as { msgId?: number; stream?: StreamFrame })),\n // Early-cancel: route a `{type, msgId, cancel:true}` frame back to the host so it\n // aborts the in-flight generation (and, for `llm:chat`, stops billing) — §3.3.\n cancel: (msg) => sendMessage(msg.type, msg as unknown as Record<string, unknown>),\n};\n\n/** Call a STREAMING catalog method by name, yielding its events. Pass `signal` to\n * abort mid-stream: the host stops generating and (for `llm:chat`) stops billing. */\nexport function invokeStream<T = unknown, R = unknown>(\n name: string,\n params: Record<string, unknown> = {},\n signal?: AbortSignal,\n): AsyncGenerator<T, R, void> {\n const [scheme, method] = split(name);\n return consumeStream<T, R>(streamTransport, `protocol-${scheme}`, method, [params], undefined, signal);\n}\n\n// The catalog list is read over the transport (§4): the host pushes `api-catalog`\n// and answers `request-api-catalog` with this app's grant-filtered methods (wire\n// format: site-main channelBridge.ts).\nconst channel = createPushChannel<ApiMethod[]>({\n pushType: API_CATALOG,\n requestType: REQUEST_API_CATALOG,\n initial: [],\n parse: (msg) => (Array.isArray(msg.methods) ? (msg.methods as ApiMethod[]) : undefined),\n});\n\n/** The methods this app may call (grant-filtered, §5.5). Poll for a one-off read;\n * use {@link onCatalogChange} / {@link useCatalog} to react. */\nexport const getCatalog = (): ApiMethod[] => channel.get();\n\n/** Subscribe to catalog changes (e.g. a grant added/revoked). Invoked immediately\n * with the current catalog, then on every change. Returns an unsubscribe fn. */\nexport const onCatalogChange = (listener: (catalog: ApiMethod[]) => void): (() => void) => channel.onChange(listener);\n\n/** React hook returning this app's method catalog, re-rendering on change. Hand\n * it to an embedded agent as its tool list to confine the agent to the app's\n * authority (§5.9). */\nexport const useCatalog = (): ApiMethod[] => channel.use();\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,0BAA0D;AAE1D,4BAA8B;AAC9B,yBAAkC;AAClC,sBAAiD;AAqBjD,MAAM,QAAQ,CAAC,SAAmC;AAChD,QAAM,IAAI,KAAK,QAAQ,GAAG;AAC1B,MAAI,KAAK,EAAG,OAAM,IAAI,MAAM,gCAAgC,IAAI,EAAE;AAClE,SAAO,CAAC,KAAK,MAAM,GAAG,CAAC,GAAG,KAAK,MAAM,IAAI,CAAC,CAAC;AAC7C;AAQO,MAAM,SAAS,OAAoB,MAAc,SAAkC,CAAC,MAAkB;AAC3G,QAAM,CAAC,QAAQ,MAAM,IAAI,MAAM,IAAI;AAInC,QAAM,MAAO,UAAM,qCAAgB,QAAQ,QAAQ,CAAC,MAAM,CAAC;AAI3D,MAAI,CAAC,OAAO,IAAI,OAAO,MAAM;AAC3B,UAAM,MAAM,IAAI,MAAM,KAAK,WAAW,GAAG,IAAI,SAAS;AACtD,QAAI,OAAO,KAAK,QAAQ;AAIxB,UAAM,OAAO,KAAK;AAClB,QAAI,OAAO,SAAS,IAAI,EAAG,KAAI,aAAa;AAC5C,UAAM;AAAA,EACR;AACA,SAAO,IAAI;AACb;AAKA,MAAM,kBAAmC;AAAA,EACvC,MAAM,CAAC,YAAQ,iCAAY,IAAI,MAAM,GAAyC;AAAA,EAC9E,WAAW,CAAC,MAAM,gBAAY,iCAAY,MAAM,CAAC,QAAQ,QAAQ,GAA+C,CAAC;AAAA;AAAA;AAAA,EAGjH,QAAQ,CAAC,YAAQ,iCAAY,IAAI,MAAM,GAAyC;AAClF;AAIO,SAAS,aACd,MACA,SAAkC,CAAC,GACnC,QAC4B;AAC5B,QAAM,CAAC,QAAQ,MAAM,IAAI,MAAM,IAAI;AACnC,aAAO,qCAAoB,iBAAiB,YAAY,MAAM,IAAI,QAAQ,CAAC,MAAM,GAAG,QAAW,MAAM;AACvG;AAKA,MAAM,cAAU,sCAA+B;AAAA,EAC7C,UAAU;AAAA,EACV,aAAa;AAAA,EACb,SAAS,CAAC;AAAA,EACV,OAAO,CAAC,QAAS,MAAM,QAAQ,IAAI,OAAO,IAAK,IAAI,UAA0B;AAC/E,CAAC;AAIM,MAAM,aAAa,MAAmB,QAAQ,IAAI;AAIlD,MAAM,kBAAkB,CAAC,aAA2D,QAAQ,SAAS,QAAQ;AAK7G,MAAM,aAAa,MAAmB,QAAQ,IAAI;","names":[]}
|
package/dist/catalog.js
CHANGED
|
@@ -14,6 +14,8 @@ const invoke = async (name, params = {}) => {
|
|
|
14
14
|
if (!res || res.ok !== true) {
|
|
15
15
|
const err = new Error(res?.message ?? `${name} failed`);
|
|
16
16
|
err.code = res?.code ?? "unknown";
|
|
17
|
+
const wait = res?.retryAfter;
|
|
18
|
+
if (Number.isFinite(wait)) err.retryAfter = wait;
|
|
17
19
|
throw err;
|
|
18
20
|
}
|
|
19
21
|
return res.data;
|
package/dist/catalog.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/catalog.ts"],"sourcesContent":["// The method catalog (UI_AS_APPS_SPEC §5.5) — the app's own grant-filtered RPC\n// surface, and a generic way to call it. The host advertises exactly the methods\n// this app may invoke (MCP-tool-shaped); `invoke()` calls one by its catalog name.\n// Handing the catalog to an embedded agent as its tool list confines the agent to\n// the app's authority (agent sandboxing falls out of the capability model, §5.9).\nimport { protocolRequest, sendMessage, addListener } from './sandboxUtils';\nimport type { StreamFrame, StreamTransport } from './protocolStream';\nimport { consumeStream } from './protocolStream';\nimport { createPushChannel } from './pushChannel';\nimport { API_CATALOG, REQUEST_API_CATALOG } from './generated/protocol';\n\n/** One advertised method, as the host generated it from its gate table. */\nexport interface ApiMethod {\n /** Catalog name, `protocol-` stripped — e.g. `spaces:invite`, `contribute:run`. */\n name: string;\n /** The capability this method requires (already held — it's in your catalog). */\n capability: string;\n /** True when the method STREAMS (use {@link invokeStream}) vs. single-reply. */\n stream?: boolean;\n /**\n * JSON Schema for the method's single object argument, when the host declares one.\n * Self-describes the call so a catalog-as-tools bridge (an embedded agent) can\n * advertise the real param shape — e.g. that `authoring:typecheck` takes a nested\n * `{ files: [{ path, content }] }` array — instead of a permissive \"any object\".\n * Absent for methods the host advertises without a schema.\n */\n paramsSchema?: Record<string, unknown>;\n}\n\n// `scheme:method` → ['scheme', 'method'] (the wire protocol is `protocol-scheme`).\nconst split = (name: string): [string, string] => {\n const i = name.indexOf(':');\n if (i <= 0) throw new Error(`invalid catalog method name: ${name}`);\n return [name.slice(0, i), name.slice(i + 1)];\n};\n\n/**\n * Call a catalog method by name — `invoke('spaces:invite', { spaceId, login, role })`.\n * A thin generic over the host protocol: the host validates params and gates the\n * call (an un-granted method → `forbidden`, even if you name it directly). For a\n * STREAMING method (`ApiMethod.stream`), use {@link invokeStream}.\n */\nexport const invoke = async <T = unknown>(name: string, params: Record<string, unknown> = {}): Promise<T> => {\n const [scheme, method] = split(name);\n // The host replies with an `{ ok, data } | { ok:false, code }` envelope; unwrap\n // it and THROW on refusal (a `.code` like `forbidden` for an off-catalog call)\n // so callers — and any agent driving `invoke` — see the gate's verdict.\n const res = (await protocolRequest(scheme, method, [params])) as\n | { ok: true; data: unknown }\n | { ok: false; code?: string; message?: string }\n | undefined;\n if (!res || res.ok !== true) {\n const err = new Error(res?.message ?? `${name} failed`) as Error & { code?: string };\n err.code = res?.code ?? 'unknown';\n throw err;\n }\n return res.data as T;\n};\n\n// Stream transport over the resolver (SDK_PACKAGING_SPEC §4) — sendMessage /\n// addListener route through `transport()` (injected bundler messageBus or the §4\n// global), never `bundler.messageBus` directly.\nconst streamTransport: StreamTransport = {\n send: (msg) => sendMessage(msg.type, msg as unknown as Record<string, unknown>),\n subscribe: (type, handler) => addListener(type, (msg) => handler(msg as { msgId?: number; stream?: StreamFrame })),\n // Early-cancel: route a `{type, msgId, cancel:true}` frame back to the host so it\n // aborts the in-flight generation (and, for `llm:chat`, stops billing) — §3.3.\n cancel: (msg) => sendMessage(msg.type, msg as unknown as Record<string, unknown>),\n};\n\n/** Call a STREAMING catalog method by name, yielding its events. Pass `signal` to\n * abort mid-stream: the host stops generating and (for `llm:chat`) stops billing. */\nexport function invokeStream<T = unknown, R = unknown>(\n name: string,\n params: Record<string, unknown> = {},\n signal?: AbortSignal,\n): AsyncGenerator<T, R, void> {\n const [scheme, method] = split(name);\n return consumeStream<T, R>(streamTransport, `protocol-${scheme}`, method, [params], undefined, signal);\n}\n\n// The catalog list is read over the transport (§4): the host pushes `api-catalog`\n// and answers `request-api-catalog` with this app's grant-filtered methods (wire\n// format: site-main channelBridge.ts).\nconst channel = createPushChannel<ApiMethod[]>({\n pushType: API_CATALOG,\n requestType: REQUEST_API_CATALOG,\n initial: [],\n parse: (msg) => (Array.isArray(msg.methods) ? (msg.methods as ApiMethod[]) : undefined),\n});\n\n/** The methods this app may call (grant-filtered, §5.5). Poll for a one-off read;\n * use {@link onCatalogChange} / {@link useCatalog} to react. */\nexport const getCatalog = (): ApiMethod[] => channel.get();\n\n/** Subscribe to catalog changes (e.g. a grant added/revoked). Invoked immediately\n * with the current catalog, then on every change. Returns an unsubscribe fn. */\nexport const onCatalogChange = (listener: (catalog: ApiMethod[]) => void): (() => void) => channel.onChange(listener);\n\n/** React hook returning this app's method catalog, re-rendering on change. Hand\n * it to an embedded agent as its tool list to confine the agent to the app's\n * authority (§5.9). */\nexport const useCatalog = (): ApiMethod[] => channel.use();\n"],"mappings":";AAKA,SAAS,iBAAiB,aAAa,mBAAmB;AAE1D,SAAS,qBAAqB;AAC9B,SAAS,yBAAyB;AAClC,SAAS,aAAa,2BAA2B;AAqBjD,MAAM,QAAQ,CAAC,SAAmC;AAChD,QAAM,IAAI,KAAK,QAAQ,GAAG;AAC1B,MAAI,KAAK,EAAG,OAAM,IAAI,MAAM,gCAAgC,IAAI,EAAE;AAClE,SAAO,CAAC,KAAK,MAAM,GAAG,CAAC,GAAG,KAAK,MAAM,IAAI,CAAC,CAAC;AAC7C;AAQO,MAAM,SAAS,OAAoB,MAAc,SAAkC,CAAC,MAAkB;AAC3G,QAAM,CAAC,QAAQ,MAAM,IAAI,MAAM,IAAI;AAInC,QAAM,MAAO,MAAM,gBAAgB,QAAQ,QAAQ,CAAC,MAAM,CAAC;AAI3D,MAAI,CAAC,OAAO,IAAI,OAAO,MAAM;AAC3B,UAAM,MAAM,IAAI,MAAM,KAAK,WAAW,GAAG,IAAI,SAAS;AACtD,QAAI,OAAO,KAAK,QAAQ;
|
|
1
|
+
{"version":3,"sources":["../src/catalog.ts"],"sourcesContent":["// The method catalog (UI_AS_APPS_SPEC §5.5) — the app's own grant-filtered RPC\n// surface, and a generic way to call it. The host advertises exactly the methods\n// this app may invoke (MCP-tool-shaped); `invoke()` calls one by its catalog name.\n// Handing the catalog to an embedded agent as its tool list confines the agent to\n// the app's authority (agent sandboxing falls out of the capability model, §5.9).\nimport { protocolRequest, sendMessage, addListener } from './sandboxUtils';\nimport type { StreamFrame, StreamTransport } from './protocolStream';\nimport { consumeStream } from './protocolStream';\nimport { createPushChannel } from './pushChannel';\nimport { API_CATALOG, REQUEST_API_CATALOG } from './generated/protocol';\n\n/** One advertised method, as the host generated it from its gate table. */\nexport interface ApiMethod {\n /** Catalog name, `protocol-` stripped — e.g. `spaces:invite`, `contribute:run`. */\n name: string;\n /** The capability this method requires (already held — it's in your catalog). */\n capability: string;\n /** True when the method STREAMS (use {@link invokeStream}) vs. single-reply. */\n stream?: boolean;\n /**\n * JSON Schema for the method's single object argument, when the host declares one.\n * Self-describes the call so a catalog-as-tools bridge (an embedded agent) can\n * advertise the real param shape — e.g. that `authoring:typecheck` takes a nested\n * `{ files: [{ path, content }] }` array — instead of a permissive \"any object\".\n * Absent for methods the host advertises without a schema.\n */\n paramsSchema?: Record<string, unknown>;\n}\n\n// `scheme:method` → ['scheme', 'method'] (the wire protocol is `protocol-scheme`).\nconst split = (name: string): [string, string] => {\n const i = name.indexOf(':');\n if (i <= 0) throw new Error(`invalid catalog method name: ${name}`);\n return [name.slice(0, i), name.slice(i + 1)];\n};\n\n/**\n * Call a catalog method by name — `invoke('spaces:invite', { spaceId, login, role })`.\n * A thin generic over the host protocol: the host validates params and gates the\n * call (an un-granted method → `forbidden`, even if you name it directly). For a\n * STREAMING method (`ApiMethod.stream`), use {@link invokeStream}.\n */\nexport const invoke = async <T = unknown>(name: string, params: Record<string, unknown> = {}): Promise<T> => {\n const [scheme, method] = split(name);\n // The host replies with an `{ ok, data } | { ok:false, code }` envelope; unwrap\n // it and THROW on refusal (a `.code` like `forbidden` for an off-catalog call)\n // so callers — and any agent driving `invoke` — see the gate's verdict.\n const res = (await protocolRequest(scheme, method, [params])) as\n | { ok: true; data: unknown }\n | { ok: false; code?: string; message?: string; retryAfter?: unknown }\n | undefined;\n if (!res || res.ok !== true) {\n const err = new Error(res?.message ?? `${name} failed`) as Error & { code?: string; retryAfter?: number };\n err.code = res?.code ?? 'unknown';\n // R3-954: a provider rate-limit refusal (`budget`) carries the wait in seconds.\n // Number.isFinite, not typeof: NaN and Infinity are numbers the structured-clone\n // transport carries intact — the same reason the sibling guards (vcs.ts) use it.\n const wait = res?.retryAfter;\n if (Number.isFinite(wait)) err.retryAfter = wait as number;\n throw err;\n }\n return res.data as T;\n};\n\n// Stream transport over the resolver (SDK_PACKAGING_SPEC §4) — sendMessage /\n// addListener route through `transport()` (injected bundler messageBus or the §4\n// global), never `bundler.messageBus` directly.\nconst streamTransport: StreamTransport = {\n send: (msg) => sendMessage(msg.type, msg as unknown as Record<string, unknown>),\n subscribe: (type, handler) => addListener(type, (msg) => handler(msg as { msgId?: number; stream?: StreamFrame })),\n // Early-cancel: route a `{type, msgId, cancel:true}` frame back to the host so it\n // aborts the in-flight generation (and, for `llm:chat`, stops billing) — §3.3.\n cancel: (msg) => sendMessage(msg.type, msg as unknown as Record<string, unknown>),\n};\n\n/** Call a STREAMING catalog method by name, yielding its events. Pass `signal` to\n * abort mid-stream: the host stops generating and (for `llm:chat`) stops billing. */\nexport function invokeStream<T = unknown, R = unknown>(\n name: string,\n params: Record<string, unknown> = {},\n signal?: AbortSignal,\n): AsyncGenerator<T, R, void> {\n const [scheme, method] = split(name);\n return consumeStream<T, R>(streamTransport, `protocol-${scheme}`, method, [params], undefined, signal);\n}\n\n// The catalog list is read over the transport (§4): the host pushes `api-catalog`\n// and answers `request-api-catalog` with this app's grant-filtered methods (wire\n// format: site-main channelBridge.ts).\nconst channel = createPushChannel<ApiMethod[]>({\n pushType: API_CATALOG,\n requestType: REQUEST_API_CATALOG,\n initial: [],\n parse: (msg) => (Array.isArray(msg.methods) ? (msg.methods as ApiMethod[]) : undefined),\n});\n\n/** The methods this app may call (grant-filtered, §5.5). Poll for a one-off read;\n * use {@link onCatalogChange} / {@link useCatalog} to react. */\nexport const getCatalog = (): ApiMethod[] => channel.get();\n\n/** Subscribe to catalog changes (e.g. a grant added/revoked). Invoked immediately\n * with the current catalog, then on every change. Returns an unsubscribe fn. */\nexport const onCatalogChange = (listener: (catalog: ApiMethod[]) => void): (() => void) => channel.onChange(listener);\n\n/** React hook returning this app's method catalog, re-rendering on change. Hand\n * it to an embedded agent as its tool list to confine the agent to the app's\n * authority (§5.9). */\nexport const useCatalog = (): ApiMethod[] => channel.use();\n"],"mappings":";AAKA,SAAS,iBAAiB,aAAa,mBAAmB;AAE1D,SAAS,qBAAqB;AAC9B,SAAS,yBAAyB;AAClC,SAAS,aAAa,2BAA2B;AAqBjD,MAAM,QAAQ,CAAC,SAAmC;AAChD,QAAM,IAAI,KAAK,QAAQ,GAAG;AAC1B,MAAI,KAAK,EAAG,OAAM,IAAI,MAAM,gCAAgC,IAAI,EAAE;AAClE,SAAO,CAAC,KAAK,MAAM,GAAG,CAAC,GAAG,KAAK,MAAM,IAAI,CAAC,CAAC;AAC7C;AAQO,MAAM,SAAS,OAAoB,MAAc,SAAkC,CAAC,MAAkB;AAC3G,QAAM,CAAC,QAAQ,MAAM,IAAI,MAAM,IAAI;AAInC,QAAM,MAAO,MAAM,gBAAgB,QAAQ,QAAQ,CAAC,MAAM,CAAC;AAI3D,MAAI,CAAC,OAAO,IAAI,OAAO,MAAM;AAC3B,UAAM,MAAM,IAAI,MAAM,KAAK,WAAW,GAAG,IAAI,SAAS;AACtD,QAAI,OAAO,KAAK,QAAQ;AAIxB,UAAM,OAAO,KAAK;AAClB,QAAI,OAAO,SAAS,IAAI,EAAG,KAAI,aAAa;AAC5C,UAAM;AAAA,EACR;AACA,SAAO,IAAI;AACb;AAKA,MAAM,kBAAmC;AAAA,EACvC,MAAM,CAAC,QAAQ,YAAY,IAAI,MAAM,GAAyC;AAAA,EAC9E,WAAW,CAAC,MAAM,YAAY,YAAY,MAAM,CAAC,QAAQ,QAAQ,GAA+C,CAAC;AAAA;AAAA;AAAA,EAGjH,QAAQ,CAAC,QAAQ,YAAY,IAAI,MAAM,GAAyC;AAClF;AAIO,SAAS,aACd,MACA,SAAkC,CAAC,GACnC,QAC4B;AAC5B,QAAM,CAAC,QAAQ,MAAM,IAAI,MAAM,IAAI;AACnC,SAAO,cAAoB,iBAAiB,YAAY,MAAM,IAAI,QAAQ,CAAC,MAAM,GAAG,QAAW,MAAM;AACvG;AAKA,MAAM,UAAU,kBAA+B;AAAA,EAC7C,UAAU;AAAA,EACV,aAAa;AAAA,EACb,SAAS,CAAC;AAAA,EACV,OAAO,CAAC,QAAS,MAAM,QAAQ,IAAI,OAAO,IAAK,IAAI,UAA0B;AAC/E,CAAC;AAIM,MAAM,aAAa,MAAmB,QAAQ,IAAI;AAIlD,MAAM,kBAAkB,CAAC,aAA2D,QAAQ,SAAS,QAAQ;AAK7G,MAAM,aAAa,MAAmB,QAAQ,IAAI;","names":[]}
|
package/dist/contribute.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/contribute.ts"],"sourcesContent":["// Contribute — stream a save (PR or direct commit) from app code\n// (UI_AS_APPS_SPEC §5.1, CONTRIBUTE_SPEC). The host runs the *existing*\n// contribution orchestrator and streams its stages back; this is the typed\n// front door over `protocolStream`.\n//\n// The OAuth token never reaches here — it stays on the host. The app passes a\n// commit message + save mode and watches stages go by; the host owns the token,\n// the GitHub API calls, and the user-facing consent.\nimport { protocolStream } from './protocolStream';\nimport { PROTOCOL_CONTRIBUTE } from './generated/protocol';\n\n/** The save strategy. `direct` requires the first-party `contribute:direct`\n * capability and a scarier consent line — a `contribute:any` app asking for it\n * is REJECTED (`forbidden`), never silently downgraded to a PR (threat T11). */\nexport type ContributeMode = 'pr' | 'direct';\n\n/** A stage emitted as the contribution runs. Mirrors the host orchestrator's\n * event union; carries progress metadata only — never the token or file blobs. */\nexport type ContributionEvent =\n | { stage: 'auth-check' }\n | { stage: 'diff-compute' }\n | { stage: 'permission-check' }\n | { stage: 'install-required'; targetOwner: string; targetRepo: string; installUrl: string }\n | { stage: 'conflict-check' }\n | { stage: 'fork-prepare'; forkOwner: string; alreadyExists: boolean }\n | { stage: 'upload-blob'; path: string; index: number; total: number }\n | { stage: 'create-tree' }\n | { stage: 'create-commit' }\n | { stage: 'create-branch'; branchName: string }\n | { stage: 'create-pr' }\n | { stage: 'pr-updated'; prNumber: number; prUrl: string; commitSha: string }\n | { stage: 'commit-pushed'; ref: string; commitSha: string }\n | { stage: 'switch-branch'; provider: 'github'; pushOwner: string; repository: string; branchName: string }\n | { stage: 'done'; prUrl?: string; prNumber?: number; commitSha: string }\n | { stage: 'warning'; message: string; details?: unknown }\n | {
|
|
1
|
+
{"version":3,"sources":["../src/contribute.ts"],"sourcesContent":["// Contribute — stream a save (PR or direct commit) from app code\n// (UI_AS_APPS_SPEC §5.1, CONTRIBUTE_SPEC). The host runs the *existing*\n// contribution orchestrator and streams its stages back; this is the typed\n// front door over `protocolStream`.\n//\n// The OAuth token never reaches here — it stays on the host. The app passes a\n// commit message + save mode and watches stages go by; the host owns the token,\n// the GitHub API calls, and the user-facing consent.\nimport { protocolStream } from './protocolStream';\nimport { PROTOCOL_CONTRIBUTE } from './generated/protocol';\n\n/** The save strategy. `direct` requires the first-party `contribute:direct`\n * capability and a scarier consent line — a `contribute:any` app asking for it\n * is REJECTED (`forbidden`), never silently downgraded to a PR (threat T11). */\nexport type ContributeMode = 'pr' | 'direct';\n\n/** The recovery a recoverable save error offers (CONTRIBUTE_SPEC §12), so an app\n * renders the specified action instead of a generic \"try again\". Mirrors the\n * host orchestrator's `RecoveryAction`.\n * - `retry` — the failed step is idempotent; re-running the save is safe.\n * - `use-different-name` — a branch with that name exists and is not this\n * session's lineage; renaming (or, for a caller-supplied name, the §8.8 gated\n * force-update) is the only way on.\n * - `open-pr` — the branch was pushed but opening the PR failed; resume with the\n * event's `openPR` context (CT-6), never re-push.\n * - `switch-to-pr` — a direct commit was rejected as a non-fast-forward; offer a\n * new branch + PR instead (CT-3). */\nexport type RecoveryAction = 'retry' | 'use-different-name' | 'open-pr' | 'switch-to-pr';\n\n/** Identifiers for the `open-pr` resume: the branch already exists on the push\n * repo (the upstream or the user's fork) and only the PR is missing. `head` is\n * the PR head ref (`branch` or `forkOwner:branch`). Minted by the host; an app\n * passes it back unchanged in {@link ContributeOptions.resume}. */\nexport interface OpenPRResumeContext {\n pushOwner: string;\n repository: string;\n branchName: string;\n base: string;\n head: string;\n}\n\n/** A stage emitted as the contribution runs. Mirrors the host orchestrator's\n * event union; carries progress metadata only — never the token or file blobs. */\nexport type ContributionEvent =\n | { stage: 'auth-check' }\n | { stage: 'diff-compute' }\n | { stage: 'permission-check' }\n | { stage: 'install-required'; targetOwner: string; targetRepo: string; installUrl: string }\n | { stage: 'conflict-check' }\n | { stage: 'fork-prepare'; forkOwner: string; alreadyExists: boolean }\n | { stage: 'upload-blob'; path: string; index: number; total: number }\n | { stage: 'create-tree' }\n | { stage: 'create-commit' }\n | { stage: 'create-branch'; branchName: string }\n | { stage: 'create-pr' }\n | { stage: 'pr-updated'; prNumber: number; prUrl: string; commitSha: string }\n | { stage: 'commit-pushed'; ref: string; commitSha: string }\n | { stage: 'switch-branch'; provider: 'github'; pushOwner: string; repository: string; branchName: string }\n | { stage: 'done'; prUrl?: string; prNumber?: number; commitSha: string }\n | { stage: 'warning'; message: string; details?: unknown }\n | {\n stage: 'error';\n message: string;\n recoverable: boolean;\n /** The specific recovery to offer. Absent ⇒ the generic recoverable surface. */\n recovery?: RecoveryAction;\n /** Present only with `recovery === 'open-pr'`: the existing branch to open a PR for. */\n openPR?: OpenPRResumeContext;\n };\n\n/** The settled outcome (the stream's return value). */\nexport interface ContributionResult {\n prUrl?: string;\n prNumber?: number;\n commitSha: string;\n treeSha: string;\n branchName: string;\n mode: 'direct-commit' | 'new-branch-pr' | 'extend-existing';\n}\n\n/** Options for a contribution: the commit message, save {@link ContributeMode},\n * (PR mode) an optional branch name, and the transcript request hint. */\nexport interface ContributeOptions {\n /** The commit message / PR title. */\n commitMessage: string;\n /** `'pr'` (default) opens a PR; `'direct'` commits to the branch and needs\n * the first-party `contribute:direct` capability. */\n mode?: ContributeMode;\n /** Override the generated branch name (PR mode). */\n branchName?: string;\n /** CONTRIBUTE_TRANSCRIPT_SPEC §4 R-CT-5: the \"Commit session transcript\"\n * checkbox's sole effect — a boolean request HINT, never bytes/path/render\n * (R-CT-6). The host's disclosure review remains the consent (R-CT-7) and\n * the hint is spent per contribution (R-CT-8). */\n transcriptRequested?: boolean;\n /** CONTRIBUTE_SPEC §8.8: update a caller-supplied branch that already exists.\n * Offer it only after a `use-different-name` error on a name the user typed;\n * the host's lineage gate (CT-4) still decides whether the update is allowed. */\n forceUpdateBranch?: boolean;\n /** Resume instead of a fresh save. `open-pr` opens the PR for the branch a\n * failed attempt already pushed (CT-6), using the error event's `openPR`\n * context unchanged; the host refuses a context it did not mint for this app. */\n resume?: { kind: 'open-pr'; context: OpenPRResumeContext };\n}\n\n/**\n * Save the current working tree, streaming each stage.\n *\n * ```ts\n * for await (const ev of contribute({ commitMessage: 'Edit post' })) {\n * if (ev.stage === 'done') console.log(ev.prUrl);\n * }\n * ```\n *\n * Yields {@link ContributionEvent}s and returns a {@link ContributionResult}.\n * Throws a `StreamError` (`.code`) if the host rejects the request — notably\n * `forbidden` when a `contribute:any` app asks for `mode: 'direct'` (T11).\n */\nexport function contribute(opts: ContributeOptions): AsyncGenerator<ContributionEvent, ContributionResult, void> {\n return protocolStream<ContributionEvent, ContributionResult>(PROTOCOL_CONTRIBUTE, 'run', [opts]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,4BAA+B;AAC/B,sBAAoC;AA6G7B,SAAS,WAAW,MAAsF;AAC/G,aAAO,sCAAsD,qCAAqB,OAAO,CAAC,IAAI,CAAC;AACjG;","names":[]}
|
package/dist/contribute.d.cts
CHANGED
|
@@ -2,6 +2,29 @@
|
|
|
2
2
|
* capability and a scarier consent line — a `contribute:any` app asking for it
|
|
3
3
|
* is REJECTED (`forbidden`), never silently downgraded to a PR (threat T11). */
|
|
4
4
|
type ContributeMode = 'pr' | 'direct';
|
|
5
|
+
/** The recovery a recoverable save error offers (CONTRIBUTE_SPEC §12), so an app
|
|
6
|
+
* renders the specified action instead of a generic "try again". Mirrors the
|
|
7
|
+
* host orchestrator's `RecoveryAction`.
|
|
8
|
+
* - `retry` — the failed step is idempotent; re-running the save is safe.
|
|
9
|
+
* - `use-different-name` — a branch with that name exists and is not this
|
|
10
|
+
* session's lineage; renaming (or, for a caller-supplied name, the §8.8 gated
|
|
11
|
+
* force-update) is the only way on.
|
|
12
|
+
* - `open-pr` — the branch was pushed but opening the PR failed; resume with the
|
|
13
|
+
* event's `openPR` context (CT-6), never re-push.
|
|
14
|
+
* - `switch-to-pr` — a direct commit was rejected as a non-fast-forward; offer a
|
|
15
|
+
* new branch + PR instead (CT-3). */
|
|
16
|
+
type RecoveryAction = 'retry' | 'use-different-name' | 'open-pr' | 'switch-to-pr';
|
|
17
|
+
/** Identifiers for the `open-pr` resume: the branch already exists on the push
|
|
18
|
+
* repo (the upstream or the user's fork) and only the PR is missing. `head` is
|
|
19
|
+
* the PR head ref (`branch` or `forkOwner:branch`). Minted by the host; an app
|
|
20
|
+
* passes it back unchanged in {@link ContributeOptions.resume}. */
|
|
21
|
+
interface OpenPRResumeContext {
|
|
22
|
+
pushOwner: string;
|
|
23
|
+
repository: string;
|
|
24
|
+
branchName: string;
|
|
25
|
+
base: string;
|
|
26
|
+
head: string;
|
|
27
|
+
}
|
|
5
28
|
/** A stage emitted as the contribution runs. Mirrors the host orchestrator's
|
|
6
29
|
* event union; carries progress metadata only — never the token or file blobs. */
|
|
7
30
|
type ContributionEvent = {
|
|
@@ -63,6 +86,10 @@ type ContributionEvent = {
|
|
|
63
86
|
stage: 'error';
|
|
64
87
|
message: string;
|
|
65
88
|
recoverable: boolean;
|
|
89
|
+
/** The specific recovery to offer. Absent ⇒ the generic recoverable surface. */
|
|
90
|
+
recovery?: RecoveryAction;
|
|
91
|
+
/** Present only with `recovery === 'open-pr'`: the existing branch to open a PR for. */
|
|
92
|
+
openPR?: OpenPRResumeContext;
|
|
66
93
|
};
|
|
67
94
|
/** The settled outcome (the stream's return value). */
|
|
68
95
|
interface ContributionResult {
|
|
@@ -88,6 +115,17 @@ interface ContributeOptions {
|
|
|
88
115
|
* (R-CT-6). The host's disclosure review remains the consent (R-CT-7) and
|
|
89
116
|
* the hint is spent per contribution (R-CT-8). */
|
|
90
117
|
transcriptRequested?: boolean;
|
|
118
|
+
/** CONTRIBUTE_SPEC §8.8: update a caller-supplied branch that already exists.
|
|
119
|
+
* Offer it only after a `use-different-name` error on a name the user typed;
|
|
120
|
+
* the host's lineage gate (CT-4) still decides whether the update is allowed. */
|
|
121
|
+
forceUpdateBranch?: boolean;
|
|
122
|
+
/** Resume instead of a fresh save. `open-pr` opens the PR for the branch a
|
|
123
|
+
* failed attempt already pushed (CT-6), using the error event's `openPR`
|
|
124
|
+
* context unchanged; the host refuses a context it did not mint for this app. */
|
|
125
|
+
resume?: {
|
|
126
|
+
kind: 'open-pr';
|
|
127
|
+
context: OpenPRResumeContext;
|
|
128
|
+
};
|
|
91
129
|
}
|
|
92
130
|
/**
|
|
93
131
|
* Save the current working tree, streaming each stage.
|
|
@@ -104,4 +142,4 @@ interface ContributeOptions {
|
|
|
104
142
|
*/
|
|
105
143
|
declare function contribute(opts: ContributeOptions): AsyncGenerator<ContributionEvent, ContributionResult, void>;
|
|
106
144
|
|
|
107
|
-
export { type ContributeMode, type ContributeOptions, type ContributionEvent, type ContributionResult, contribute };
|
|
145
|
+
export { type ContributeMode, type ContributeOptions, type ContributionEvent, type ContributionResult, type OpenPRResumeContext, type RecoveryAction, contribute };
|
package/dist/contribute.d.ts
CHANGED
|
@@ -2,6 +2,29 @@
|
|
|
2
2
|
* capability and a scarier consent line — a `contribute:any` app asking for it
|
|
3
3
|
* is REJECTED (`forbidden`), never silently downgraded to a PR (threat T11). */
|
|
4
4
|
type ContributeMode = 'pr' | 'direct';
|
|
5
|
+
/** The recovery a recoverable save error offers (CONTRIBUTE_SPEC §12), so an app
|
|
6
|
+
* renders the specified action instead of a generic "try again". Mirrors the
|
|
7
|
+
* host orchestrator's `RecoveryAction`.
|
|
8
|
+
* - `retry` — the failed step is idempotent; re-running the save is safe.
|
|
9
|
+
* - `use-different-name` — a branch with that name exists and is not this
|
|
10
|
+
* session's lineage; renaming (or, for a caller-supplied name, the §8.8 gated
|
|
11
|
+
* force-update) is the only way on.
|
|
12
|
+
* - `open-pr` — the branch was pushed but opening the PR failed; resume with the
|
|
13
|
+
* event's `openPR` context (CT-6), never re-push.
|
|
14
|
+
* - `switch-to-pr` — a direct commit was rejected as a non-fast-forward; offer a
|
|
15
|
+
* new branch + PR instead (CT-3). */
|
|
16
|
+
type RecoveryAction = 'retry' | 'use-different-name' | 'open-pr' | 'switch-to-pr';
|
|
17
|
+
/** Identifiers for the `open-pr` resume: the branch already exists on the push
|
|
18
|
+
* repo (the upstream or the user's fork) and only the PR is missing. `head` is
|
|
19
|
+
* the PR head ref (`branch` or `forkOwner:branch`). Minted by the host; an app
|
|
20
|
+
* passes it back unchanged in {@link ContributeOptions.resume}. */
|
|
21
|
+
interface OpenPRResumeContext {
|
|
22
|
+
pushOwner: string;
|
|
23
|
+
repository: string;
|
|
24
|
+
branchName: string;
|
|
25
|
+
base: string;
|
|
26
|
+
head: string;
|
|
27
|
+
}
|
|
5
28
|
/** A stage emitted as the contribution runs. Mirrors the host orchestrator's
|
|
6
29
|
* event union; carries progress metadata only — never the token or file blobs. */
|
|
7
30
|
type ContributionEvent = {
|
|
@@ -63,6 +86,10 @@ type ContributionEvent = {
|
|
|
63
86
|
stage: 'error';
|
|
64
87
|
message: string;
|
|
65
88
|
recoverable: boolean;
|
|
89
|
+
/** The specific recovery to offer. Absent ⇒ the generic recoverable surface. */
|
|
90
|
+
recovery?: RecoveryAction;
|
|
91
|
+
/** Present only with `recovery === 'open-pr'`: the existing branch to open a PR for. */
|
|
92
|
+
openPR?: OpenPRResumeContext;
|
|
66
93
|
};
|
|
67
94
|
/** The settled outcome (the stream's return value). */
|
|
68
95
|
interface ContributionResult {
|
|
@@ -88,6 +115,17 @@ interface ContributeOptions {
|
|
|
88
115
|
* (R-CT-6). The host's disclosure review remains the consent (R-CT-7) and
|
|
89
116
|
* the hint is spent per contribution (R-CT-8). */
|
|
90
117
|
transcriptRequested?: boolean;
|
|
118
|
+
/** CONTRIBUTE_SPEC §8.8: update a caller-supplied branch that already exists.
|
|
119
|
+
* Offer it only after a `use-different-name` error on a name the user typed;
|
|
120
|
+
* the host's lineage gate (CT-4) still decides whether the update is allowed. */
|
|
121
|
+
forceUpdateBranch?: boolean;
|
|
122
|
+
/** Resume instead of a fresh save. `open-pr` opens the PR for the branch a
|
|
123
|
+
* failed attempt already pushed (CT-6), using the error event's `openPR`
|
|
124
|
+
* context unchanged; the host refuses a context it did not mint for this app. */
|
|
125
|
+
resume?: {
|
|
126
|
+
kind: 'open-pr';
|
|
127
|
+
context: OpenPRResumeContext;
|
|
128
|
+
};
|
|
91
129
|
}
|
|
92
130
|
/**
|
|
93
131
|
* Save the current working tree, streaming each stage.
|
|
@@ -104,4 +142,4 @@ interface ContributeOptions {
|
|
|
104
142
|
*/
|
|
105
143
|
declare function contribute(opts: ContributeOptions): AsyncGenerator<ContributionEvent, ContributionResult, void>;
|
|
106
144
|
|
|
107
|
-
export { type ContributeMode, type ContributeOptions, type ContributionEvent, type ContributionResult, contribute };
|
|
145
|
+
export { type ContributeMode, type ContributeOptions, type ContributionEvent, type ContributionResult, type OpenPRResumeContext, type RecoveryAction, contribute };
|
package/dist/contribute.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/contribute.ts"],"sourcesContent":["// Contribute — stream a save (PR or direct commit) from app code\n// (UI_AS_APPS_SPEC §5.1, CONTRIBUTE_SPEC). The host runs the *existing*\n// contribution orchestrator and streams its stages back; this is the typed\n// front door over `protocolStream`.\n//\n// The OAuth token never reaches here — it stays on the host. The app passes a\n// commit message + save mode and watches stages go by; the host owns the token,\n// the GitHub API calls, and the user-facing consent.\nimport { protocolStream } from './protocolStream';\nimport { PROTOCOL_CONTRIBUTE } from './generated/protocol';\n\n/** The save strategy. `direct` requires the first-party `contribute:direct`\n * capability and a scarier consent line — a `contribute:any` app asking for it\n * is REJECTED (`forbidden`), never silently downgraded to a PR (threat T11). */\nexport type ContributeMode = 'pr' | 'direct';\n\n/** A stage emitted as the contribution runs. Mirrors the host orchestrator's\n * event union; carries progress metadata only — never the token or file blobs. */\nexport type ContributionEvent =\n | { stage: 'auth-check' }\n | { stage: 'diff-compute' }\n | { stage: 'permission-check' }\n | { stage: 'install-required'; targetOwner: string; targetRepo: string; installUrl: string }\n | { stage: 'conflict-check' }\n | { stage: 'fork-prepare'; forkOwner: string; alreadyExists: boolean }\n | { stage: 'upload-blob'; path: string; index: number; total: number }\n | { stage: 'create-tree' }\n | { stage: 'create-commit' }\n | { stage: 'create-branch'; branchName: string }\n | { stage: 'create-pr' }\n | { stage: 'pr-updated'; prNumber: number; prUrl: string; commitSha: string }\n | { stage: 'commit-pushed'; ref: string; commitSha: string }\n | { stage: 'switch-branch'; provider: 'github'; pushOwner: string; repository: string; branchName: string }\n | { stage: 'done'; prUrl?: string; prNumber?: number; commitSha: string }\n | { stage: 'warning'; message: string; details?: unknown }\n | {
|
|
1
|
+
{"version":3,"sources":["../src/contribute.ts"],"sourcesContent":["// Contribute — stream a save (PR or direct commit) from app code\n// (UI_AS_APPS_SPEC §5.1, CONTRIBUTE_SPEC). The host runs the *existing*\n// contribution orchestrator and streams its stages back; this is the typed\n// front door over `protocolStream`.\n//\n// The OAuth token never reaches here — it stays on the host. The app passes a\n// commit message + save mode and watches stages go by; the host owns the token,\n// the GitHub API calls, and the user-facing consent.\nimport { protocolStream } from './protocolStream';\nimport { PROTOCOL_CONTRIBUTE } from './generated/protocol';\n\n/** The save strategy. `direct` requires the first-party `contribute:direct`\n * capability and a scarier consent line — a `contribute:any` app asking for it\n * is REJECTED (`forbidden`), never silently downgraded to a PR (threat T11). */\nexport type ContributeMode = 'pr' | 'direct';\n\n/** The recovery a recoverable save error offers (CONTRIBUTE_SPEC §12), so an app\n * renders the specified action instead of a generic \"try again\". Mirrors the\n * host orchestrator's `RecoveryAction`.\n * - `retry` — the failed step is idempotent; re-running the save is safe.\n * - `use-different-name` — a branch with that name exists and is not this\n * session's lineage; renaming (or, for a caller-supplied name, the §8.8 gated\n * force-update) is the only way on.\n * - `open-pr` — the branch was pushed but opening the PR failed; resume with the\n * event's `openPR` context (CT-6), never re-push.\n * - `switch-to-pr` — a direct commit was rejected as a non-fast-forward; offer a\n * new branch + PR instead (CT-3). */\nexport type RecoveryAction = 'retry' | 'use-different-name' | 'open-pr' | 'switch-to-pr';\n\n/** Identifiers for the `open-pr` resume: the branch already exists on the push\n * repo (the upstream or the user's fork) and only the PR is missing. `head` is\n * the PR head ref (`branch` or `forkOwner:branch`). Minted by the host; an app\n * passes it back unchanged in {@link ContributeOptions.resume}. */\nexport interface OpenPRResumeContext {\n pushOwner: string;\n repository: string;\n branchName: string;\n base: string;\n head: string;\n}\n\n/** A stage emitted as the contribution runs. Mirrors the host orchestrator's\n * event union; carries progress metadata only — never the token or file blobs. */\nexport type ContributionEvent =\n | { stage: 'auth-check' }\n | { stage: 'diff-compute' }\n | { stage: 'permission-check' }\n | { stage: 'install-required'; targetOwner: string; targetRepo: string; installUrl: string }\n | { stage: 'conflict-check' }\n | { stage: 'fork-prepare'; forkOwner: string; alreadyExists: boolean }\n | { stage: 'upload-blob'; path: string; index: number; total: number }\n | { stage: 'create-tree' }\n | { stage: 'create-commit' }\n | { stage: 'create-branch'; branchName: string }\n | { stage: 'create-pr' }\n | { stage: 'pr-updated'; prNumber: number; prUrl: string; commitSha: string }\n | { stage: 'commit-pushed'; ref: string; commitSha: string }\n | { stage: 'switch-branch'; provider: 'github'; pushOwner: string; repository: string; branchName: string }\n | { stage: 'done'; prUrl?: string; prNumber?: number; commitSha: string }\n | { stage: 'warning'; message: string; details?: unknown }\n | {\n stage: 'error';\n message: string;\n recoverable: boolean;\n /** The specific recovery to offer. Absent ⇒ the generic recoverable surface. */\n recovery?: RecoveryAction;\n /** Present only with `recovery === 'open-pr'`: the existing branch to open a PR for. */\n openPR?: OpenPRResumeContext;\n };\n\n/** The settled outcome (the stream's return value). */\nexport interface ContributionResult {\n prUrl?: string;\n prNumber?: number;\n commitSha: string;\n treeSha: string;\n branchName: string;\n mode: 'direct-commit' | 'new-branch-pr' | 'extend-existing';\n}\n\n/** Options for a contribution: the commit message, save {@link ContributeMode},\n * (PR mode) an optional branch name, and the transcript request hint. */\nexport interface ContributeOptions {\n /** The commit message / PR title. */\n commitMessage: string;\n /** `'pr'` (default) opens a PR; `'direct'` commits to the branch and needs\n * the first-party `contribute:direct` capability. */\n mode?: ContributeMode;\n /** Override the generated branch name (PR mode). */\n branchName?: string;\n /** CONTRIBUTE_TRANSCRIPT_SPEC §4 R-CT-5: the \"Commit session transcript\"\n * checkbox's sole effect — a boolean request HINT, never bytes/path/render\n * (R-CT-6). The host's disclosure review remains the consent (R-CT-7) and\n * the hint is spent per contribution (R-CT-8). */\n transcriptRequested?: boolean;\n /** CONTRIBUTE_SPEC §8.8: update a caller-supplied branch that already exists.\n * Offer it only after a `use-different-name` error on a name the user typed;\n * the host's lineage gate (CT-4) still decides whether the update is allowed. */\n forceUpdateBranch?: boolean;\n /** Resume instead of a fresh save. `open-pr` opens the PR for the branch a\n * failed attempt already pushed (CT-6), using the error event's `openPR`\n * context unchanged; the host refuses a context it did not mint for this app. */\n resume?: { kind: 'open-pr'; context: OpenPRResumeContext };\n}\n\n/**\n * Save the current working tree, streaming each stage.\n *\n * ```ts\n * for await (const ev of contribute({ commitMessage: 'Edit post' })) {\n * if (ev.stage === 'done') console.log(ev.prUrl);\n * }\n * ```\n *\n * Yields {@link ContributionEvent}s and returns a {@link ContributionResult}.\n * Throws a `StreamError` (`.code`) if the host rejects the request — notably\n * `forbidden` when a `contribute:any` app asks for `mode: 'direct'` (T11).\n */\nexport function contribute(opts: ContributeOptions): AsyncGenerator<ContributionEvent, ContributionResult, void> {\n return protocolStream<ContributionEvent, ContributionResult>(PROTOCOL_CONTRIBUTE, 'run', [opts]);\n}\n"],"mappings":";AAQA,SAAS,sBAAsB;AAC/B,SAAS,2BAA2B;AA6G7B,SAAS,WAAW,MAAsF;AAC/G,SAAO,eAAsD,qBAAqB,OAAO,CAAC,IAAI,CAAC;AACjG;","names":[]}
|
package/dist/index.cjs
CHANGED
|
@@ -62,6 +62,7 @@ __reExport(index_exports, require("./secrets"), module.exports);
|
|
|
62
62
|
__reExport(index_exports, require("./recents"), module.exports);
|
|
63
63
|
__reExport(index_exports, require("./openRepository"), module.exports);
|
|
64
64
|
__reExport(index_exports, require("./openExternal"), module.exports);
|
|
65
|
+
__reExport(index_exports, require("./openBundle"), module.exports);
|
|
65
66
|
__reExport(index_exports, require("./llm"), module.exports);
|
|
66
67
|
__reExport(index_exports, require("./diagnostics"), module.exports);
|
|
67
68
|
__reExport(index_exports, require("./vcs"), module.exports);
|
|
@@ -134,6 +135,7 @@ var import_ScrollRestoration = require("./components/ScrollRestoration");
|
|
|
134
135
|
...require("./recents"),
|
|
135
136
|
...require("./openRepository"),
|
|
136
137
|
...require("./openExternal"),
|
|
138
|
+
...require("./openBundle"),
|
|
137
139
|
...require("./llm"),
|
|
138
140
|
...require("./diagnostics"),
|
|
139
141
|
...require("./vcs"),
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './MDXProvider';\nexport * from './routing';\nexport * from './boot';\nexport * from './components/Include';\n// Only the component is public. `stripFrontmatter`/`appMountRelative` are module-level\n// exports so they can be unit-tested directly, NOT public API — the SDK's surface is\n// backwards-compatible forever, so an internal helper exported for a test's convenience is a\n// permanent commitment made for the wrong reason.\nexport { SafeInclude } from './components/SafeInclude';\nexport * from './sourceCache';\nexport * from './components/MDXComponents';\nexport * from './linkSpace';\nexport * from './bundle';\n// Deprecated `Corpus*` spellings of the above (R3-482); see `src/corpus.ts`.\nexport * from './corpus';\nexport * from './components/MountImage';\nexport * from './components/Routes';\nexport * from './hooks';\n// R3-276: the supported way for a viewer app to provide its own metadata store,\n// replacing a wholesale re-provision of `TinkerableContext` in app code.\nexport * from './metadataSource';\n// The deprecated injected-bundler adapters, re-exported so their deprecation notices\n// are visible in the published docs (R3-278; the window only narrows).\nexport { getInjectedMetadataEmitter, getInjectedMetadataSnapshot } from './injectedBundler';\nexport * from './auth';\nexport * from './theme';\nexport * from './editorContext';\nexport * from './editor';\nexport * from './formFactor';\nexport * from './chromeState';\nexport * from './workspace';\nexport * from './hostAttention';\nexport * from './region';\n// R3-708 — the spaces mode's route channel and its one navigation verb.\nexport * from './spacesMode';\nexport * from './mounts';\nexport * from './analytics';\nexport * from './contribute';\nexport * from './catalog';\nexport * from './ipc';\nexport * from './dnd';\nexport * from './netFetch';\nexport * from './feed';\nexport * from './secrets';\nexport * from './recents'; // R3-485: the gated recent-projects read (page.home)\nexport * from './openRepository'; // R3-476: host-mediated open-in-a-new-tab (route:read)\nexport * from './openExternal'; // R3-619: host-brokered outward-link open (link:open)\nexport * from './llm';\nexport * from './diagnostics';\nexport * from './vcs';\nexport * from './onFsChange';\nexport * from './fs';\nexport * from './debug';\nexport * from './tasks';\nexport * from './launch';\nexport * from './runtime';\nexport * from './irMarkers';\nexport * from './ready';\nexport * from './loading';\nexport * from './dialog';\nexport * from './status';\nexport * from './protocolStream';\nexport * from './protocolDeadline';\nexport * from './sandboxTypes';\nexport * from './safeContent';\n// R3-489 (GROVE_AGENT_SPEC): the embedded-agent seam every app shares — the tool-use\n// loop ported from agent-demo (`runAgent` over the host chat slot), the MDX metadata\n// query tool, the headings index collector, the deixis context block, and the fence\n// for corpus-derived bytes entering a loop.\nexport * from './agentLoop';\nexport * from './agentSteering';\nexport * from './agentPause';\nexport * from './agentChatClient';\nexport * from './metadataQueryTool';\nexport * from './collectHeadings';\nexport * from './agentContext';\nexport * from './fence';\nexport * from './platformLink';\n// R3-627: the per-history-entry scratch, and the scroll restoration built on it —\n// Back lands where the reader left, for however many entries deep they go.\nexport * from './entryState';\nexport * from './useEntryState';\nexport * from './scrollRestore';\nexport { ScrollRestoration, type ScrollRestorationProps } from './components/ScrollRestoration';\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAc,0BAAd;AACA,0BAAc,sBADd;AAEA,0BAAc,mBAFd;AAGA,0BAAc,iCAHd;AAQA,yBAA4B;AAC5B,0BAAc,0BATd;AAUA,0BAAc,uCAVd;AAWA,0BAAc,wBAXd;AAYA,0BAAc,qBAZd;AAcA,0BAAc,qBAdd;AAeA,0BAAc,oCAfd;AAgBA,0BAAc,gCAhBd;AAiBA,0BAAc,oBAjBd;AAoBA,0BAAc,6BApBd;AAuBA,6BAAwE;AACxE,0BAAc,mBAxBd;AAyBA,0BAAc,oBAzBd;AA0BA,0BAAc,4BA1Bd;AA2BA,0BAAc,qBA3Bd;AA4BA,0BAAc,yBA5Bd;AA6BA,0BAAc,0BA7Bd;AA8BA,0BAAc,wBA9Bd;AA+BA,0BAAc,4BA/Bd;AAgCA,0BAAc,qBAhCd;AAkCA,0BAAc,yBAlCd;AAmCA,0BAAc,qBAnCd;AAoCA,0BAAc,wBApCd;AAqCA,0BAAc,yBArCd;AAsCA,0BAAc,sBAtCd;AAuCA,0BAAc,kBAvCd;AAwCA,0BAAc,kBAxCd;AAyCA,0BAAc,uBAzCd;AA0CA,0BAAc,mBA1Cd;AA2CA,0BAAc,sBA3Cd;AA4CA,0BAAc,sBA5Cd;AA6CA,0BAAc,6BA7Cd;AA8CA,0BAAc,2BA9Cd;AA+CA,0BAAc,
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './MDXProvider';\nexport * from './routing';\nexport * from './boot';\nexport * from './components/Include';\n// Only the component is public. `stripFrontmatter`/`appMountRelative` are module-level\n// exports so they can be unit-tested directly, NOT public API — the SDK's surface is\n// backwards-compatible forever, so an internal helper exported for a test's convenience is a\n// permanent commitment made for the wrong reason.\nexport { SafeInclude } from './components/SafeInclude';\nexport * from './sourceCache';\nexport * from './components/MDXComponents';\nexport * from './linkSpace';\nexport * from './bundle';\n// Deprecated `Corpus*` spellings of the above (R3-482); see `src/corpus.ts`.\nexport * from './corpus';\nexport * from './components/MountImage';\nexport * from './components/Routes';\nexport * from './hooks';\n// R3-276: the supported way for a viewer app to provide its own metadata store,\n// replacing a wholesale re-provision of `TinkerableContext` in app code.\nexport * from './metadataSource';\n// The deprecated injected-bundler adapters, re-exported so their deprecation notices\n// are visible in the published docs (R3-278; the window only narrows).\nexport { getInjectedMetadataEmitter, getInjectedMetadataSnapshot } from './injectedBundler';\nexport * from './auth';\nexport * from './theme';\nexport * from './editorContext';\nexport * from './editor';\nexport * from './formFactor';\nexport * from './chromeState';\nexport * from './workspace';\nexport * from './hostAttention';\nexport * from './region';\n// R3-708 — the spaces mode's route channel and its one navigation verb.\nexport * from './spacesMode';\nexport * from './mounts';\nexport * from './analytics';\nexport * from './contribute';\nexport * from './catalog';\nexport * from './ipc';\nexport * from './dnd';\nexport * from './netFetch';\nexport * from './feed';\nexport * from './secrets';\nexport * from './recents'; // R3-485: the gated recent-projects read (page.home)\nexport * from './openRepository'; // R3-476: host-mediated open-in-a-new-tab (route:read)\nexport * from './openExternal'; // R3-619: host-brokered outward-link open (link:open)\nexport * from './openBundle'; // host-mediated open of a bundle in its own tab\nexport * from './llm';\nexport * from './diagnostics';\nexport * from './vcs';\nexport * from './onFsChange';\nexport * from './fs';\nexport * from './debug';\nexport * from './tasks';\nexport * from './launch';\nexport * from './runtime';\nexport * from './irMarkers';\nexport * from './ready';\nexport * from './loading';\nexport * from './dialog';\nexport * from './status';\nexport * from './protocolStream';\nexport * from './protocolDeadline';\nexport * from './sandboxTypes';\nexport * from './safeContent';\n// R3-489 (GROVE_AGENT_SPEC): the embedded-agent seam every app shares — the tool-use\n// loop ported from agent-demo (`runAgent` over the host chat slot), the MDX metadata\n// query tool, the headings index collector, the deixis context block, and the fence\n// for corpus-derived bytes entering a loop.\nexport * from './agentLoop';\nexport * from './agentSteering';\nexport * from './agentPause';\nexport * from './agentChatClient';\nexport * from './metadataQueryTool';\nexport * from './collectHeadings';\nexport * from './agentContext';\nexport * from './fence';\nexport * from './platformLink';\n// R3-627: the per-history-entry scratch, and the scroll restoration built on it —\n// Back lands where the reader left, for however many entries deep they go.\nexport * from './entryState';\nexport * from './useEntryState';\nexport * from './scrollRestore';\nexport { ScrollRestoration, type ScrollRestorationProps } from './components/ScrollRestoration';\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAc,0BAAd;AACA,0BAAc,sBADd;AAEA,0BAAc,mBAFd;AAGA,0BAAc,iCAHd;AAQA,yBAA4B;AAC5B,0BAAc,0BATd;AAUA,0BAAc,uCAVd;AAWA,0BAAc,wBAXd;AAYA,0BAAc,qBAZd;AAcA,0BAAc,qBAdd;AAeA,0BAAc,oCAfd;AAgBA,0BAAc,gCAhBd;AAiBA,0BAAc,oBAjBd;AAoBA,0BAAc,6BApBd;AAuBA,6BAAwE;AACxE,0BAAc,mBAxBd;AAyBA,0BAAc,oBAzBd;AA0BA,0BAAc,4BA1Bd;AA2BA,0BAAc,qBA3Bd;AA4BA,0BAAc,yBA5Bd;AA6BA,0BAAc,0BA7Bd;AA8BA,0BAAc,wBA9Bd;AA+BA,0BAAc,4BA/Bd;AAgCA,0BAAc,qBAhCd;AAkCA,0BAAc,yBAlCd;AAmCA,0BAAc,qBAnCd;AAoCA,0BAAc,wBApCd;AAqCA,0BAAc,yBArCd;AAsCA,0BAAc,sBAtCd;AAuCA,0BAAc,kBAvCd;AAwCA,0BAAc,kBAxCd;AAyCA,0BAAc,uBAzCd;AA0CA,0BAAc,mBA1Cd;AA2CA,0BAAc,sBA3Cd;AA4CA,0BAAc,sBA5Cd;AA6CA,0BAAc,6BA7Cd;AA8CA,0BAAc,2BA9Cd;AA+CA,0BAAc,yBA/Cd;AAgDA,0BAAc,kBAhDd;AAiDA,0BAAc,0BAjDd;AAkDA,0BAAc,kBAlDd;AAmDA,0BAAc,yBAnDd;AAoDA,0BAAc,iBApDd;AAqDA,0BAAc,oBArDd;AAsDA,0BAAc,oBAtDd;AAuDA,0BAAc,qBAvDd;AAwDA,0BAAc,sBAxDd;AAyDA,0BAAc,wBAzDd;AA0DA,0BAAc,oBA1Dd;AA2DA,0BAAc,sBA3Dd;AA4DA,0BAAc,qBA5Dd;AA6DA,0BAAc,qBA7Dd;AA8DA,0BAAc,6BA9Dd;AA+DA,0BAAc,+BA/Dd;AAgEA,0BAAc,2BAhEd;AAiEA,0BAAc,0BAjEd;AAsEA,0BAAc,wBAtEd;AAuEA,0BAAc,4BAvEd;AAwEA,0BAAc,yBAxEd;AAyEA,0BAAc,8BAzEd;AA0EA,0BAAc,gCA1Ed;AA2EA,0BAAc,8BA3Ed;AA4EA,0BAAc,2BA5Ed;AA6EA,0BAAc,oBA7Ed;AA8EA,0BAAc,2BA9Ed;AAiFA,0BAAc,yBAjFd;AAkFA,0BAAc,4BAlFd;AAmFA,0BAAc,4BAnFd;AAoFA,+BAA+D;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -24,7 +24,7 @@ export { getRegion, isRegionHidden, onRegionVisibilityChange, useRegion, useRegi
|
|
|
24
24
|
export { NavigateSpacesError, NavigateSpacesErrorCode, SpacesActivity, SpacesModeSpace, SpacesModeState, SpacesRoute, SpacesTarget, getSpacesMode, navigateSpaces, onSpacesModeChange, useSpacesMode } from './spacesMode.cjs';
|
|
25
25
|
export { MountQuery, MountRemoveReason, MountRule, PublishedSpaceKey, RemovedMount, SandboxMount, SandboxMountBundle, SessionMount, SpaceError, awaitMatchingMount, createSpace, findMount, getAppMountPath, getInvites, getMounts, getSessionMounts, importSettingsFromParent, listSettingsApps, listSpaceKeys, makeContentRef, mount, mountSpace, onInvitesChange, onMountsChange, onSessionMountsChange, openLocalStore, openSettings, openSettingsOf, publishSpaceKey, requestMount, requestSpace, resolveContentRef, resolveContentRefs, unmountSpace, useInvites, useMounts, useSessionMounts, waitForMount } from './mounts.cjs';
|
|
26
26
|
export { AnalyticsAck, AnalyticsPropValue, emitAnalyticsEvent, recordRoute, track, trackRoute } from './analytics.cjs';
|
|
27
|
-
export { ContributeMode, ContributeOptions, ContributionEvent, ContributionResult, contribute } from './contribute.cjs';
|
|
27
|
+
export { ContributeMode, ContributeOptions, ContributionEvent, ContributionResult, OpenPRResumeContext, RecoveryAction, contribute } from './contribute.cjs';
|
|
28
28
|
export { ApiMethod, getCatalog, invoke, invokeStream, onCatalogChange, useCatalog } from './catalog.cjs';
|
|
29
29
|
export { RegionMessage, onRegionMessage, postToRegion, revealRegion, useRegionMessage } from './ipc.cjs';
|
|
30
30
|
export { DraggableItem, DroppedItem, ItemDragError, cancelItemDrag, onItemDrop, startItemDrag, useDroppedItem } from './dnd.cjs';
|
|
@@ -32,11 +32,12 @@ export { HostFetchInit, HostFetchResponse, HostFetchStreamEvent, HostFetchStream
|
|
|
32
32
|
export { FeedFetchResponse, FeedParams, feedFetch } from './feed.cjs';
|
|
33
33
|
export { SecretError, SecretGrant, SecretHints, SecretQuery, SecretType, SecretView, getSecrets, onSecretsChange, requestAddSecret, requestSecret, revokeSecret, useSecrets } from './secrets.cjs';
|
|
34
34
|
export { RecentProject, clearRecentProjects, listRecentProjects } from './recents.cjs';
|
|
35
|
-
export { OpenRepositoryError, OpenRepositoryErrorCode, RepositoryCoordinates, openRepository } from './openRepository.cjs';
|
|
35
|
+
export { OpenRepositoryError, OpenRepositoryErrorCode, RepositoryCoordinates, RepositoryReveal, openRepository } from './openRepository.cjs';
|
|
36
36
|
export { OpenExternalError, OpenExternalErrorCode, openExternal } from './openExternal.cjs';
|
|
37
|
+
export { OPEN_BUNDLE_REPLY_TIMEOUT_MS, OpenBundleError, OpenBundleErrorCode, OpenBundleTarget, openBundle } from './openBundle.cjs';
|
|
37
38
|
export { ChatDelta, ChatExecutor, ChatFeatures, ChatMessage, ChatProviderChoice, ChatProviderInfo, ChatProviderState, ChatRequest, ChatResult, ChatRole, ChatStopReason, ChatTierModels, ContentPart, ToolDef, chat, deriveChatProviderState, describeChat, describeChatState, normalizeProviderInfo, onChatProviderChange, onChatProviderStateChange, useChatProvider, useChatProviderState } from './llm.cjs';
|
|
38
39
|
export { BuildError, ConsoleEntry, ConsoleLevel, Diagnostics, DiagnosticsProvenance, getDiagnostics, onDiagnosticsChange, useDiagnostics } from './diagnostics.cjs';
|
|
39
|
-
export { VcsActionError, VcsAgentSession, VcsBranch, VcsChange, VcsPR, VcsState, getVcsState, onVcsStateChange, refreshDiff, refreshPRs, resetWorkingTree, useVcsState } from './vcs.cjs';
|
|
40
|
+
export { BundleCommit, BundleHistoryError, REF_KINDS, VcsActionError, VcsAgentSession, VcsBranch, VcsChange, VcsDiffWarning, VcsPR, VcsState, VcsTarget, bundleCanWrite, bundleDiffPaths, bundleHead, bundleIsAncestor, bundleLog, bundleRead, getVcsState, onVcsStateChange, refreshDiff, refreshPRs, resetWorkingTree, useVcsState } from './vcs.cjs';
|
|
40
41
|
export { FsChange, MountChange, getFsChange, onFsChange, useFsChange } from './onFsChange.cjs';
|
|
41
42
|
export { DirEntry, FileStat, FsError, MountFs, SandboxFsPort, fsAvailable, mimeTypeFor, openAppFs, openFs, sandboxFs } from './fs.cjs';
|
|
42
43
|
export { DebugLevel, debug, isDebugEnabled, log, useDebugEnabled } from './debug.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export { getRegion, isRegionHidden, onRegionVisibilityChange, useRegion, useRegi
|
|
|
24
24
|
export { NavigateSpacesError, NavigateSpacesErrorCode, SpacesActivity, SpacesModeSpace, SpacesModeState, SpacesRoute, SpacesTarget, getSpacesMode, navigateSpaces, onSpacesModeChange, useSpacesMode } from './spacesMode.js';
|
|
25
25
|
export { MountQuery, MountRemoveReason, MountRule, PublishedSpaceKey, RemovedMount, SandboxMount, SandboxMountBundle, SessionMount, SpaceError, awaitMatchingMount, createSpace, findMount, getAppMountPath, getInvites, getMounts, getSessionMounts, importSettingsFromParent, listSettingsApps, listSpaceKeys, makeContentRef, mount, mountSpace, onInvitesChange, onMountsChange, onSessionMountsChange, openLocalStore, openSettings, openSettingsOf, publishSpaceKey, requestMount, requestSpace, resolveContentRef, resolveContentRefs, unmountSpace, useInvites, useMounts, useSessionMounts, waitForMount } from './mounts.js';
|
|
26
26
|
export { AnalyticsAck, AnalyticsPropValue, emitAnalyticsEvent, recordRoute, track, trackRoute } from './analytics.js';
|
|
27
|
-
export { ContributeMode, ContributeOptions, ContributionEvent, ContributionResult, contribute } from './contribute.js';
|
|
27
|
+
export { ContributeMode, ContributeOptions, ContributionEvent, ContributionResult, OpenPRResumeContext, RecoveryAction, contribute } from './contribute.js';
|
|
28
28
|
export { ApiMethod, getCatalog, invoke, invokeStream, onCatalogChange, useCatalog } from './catalog.js';
|
|
29
29
|
export { RegionMessage, onRegionMessage, postToRegion, revealRegion, useRegionMessage } from './ipc.js';
|
|
30
30
|
export { DraggableItem, DroppedItem, ItemDragError, cancelItemDrag, onItemDrop, startItemDrag, useDroppedItem } from './dnd.js';
|
|
@@ -32,11 +32,12 @@ export { HostFetchInit, HostFetchResponse, HostFetchStreamEvent, HostFetchStream
|
|
|
32
32
|
export { FeedFetchResponse, FeedParams, feedFetch } from './feed.js';
|
|
33
33
|
export { SecretError, SecretGrant, SecretHints, SecretQuery, SecretType, SecretView, getSecrets, onSecretsChange, requestAddSecret, requestSecret, revokeSecret, useSecrets } from './secrets.js';
|
|
34
34
|
export { RecentProject, clearRecentProjects, listRecentProjects } from './recents.js';
|
|
35
|
-
export { OpenRepositoryError, OpenRepositoryErrorCode, RepositoryCoordinates, openRepository } from './openRepository.js';
|
|
35
|
+
export { OpenRepositoryError, OpenRepositoryErrorCode, RepositoryCoordinates, RepositoryReveal, openRepository } from './openRepository.js';
|
|
36
36
|
export { OpenExternalError, OpenExternalErrorCode, openExternal } from './openExternal.js';
|
|
37
|
+
export { OPEN_BUNDLE_REPLY_TIMEOUT_MS, OpenBundleError, OpenBundleErrorCode, OpenBundleTarget, openBundle } from './openBundle.js';
|
|
37
38
|
export { ChatDelta, ChatExecutor, ChatFeatures, ChatMessage, ChatProviderChoice, ChatProviderInfo, ChatProviderState, ChatRequest, ChatResult, ChatRole, ChatStopReason, ChatTierModels, ContentPart, ToolDef, chat, deriveChatProviderState, describeChat, describeChatState, normalizeProviderInfo, onChatProviderChange, onChatProviderStateChange, useChatProvider, useChatProviderState } from './llm.js';
|
|
38
39
|
export { BuildError, ConsoleEntry, ConsoleLevel, Diagnostics, DiagnosticsProvenance, getDiagnostics, onDiagnosticsChange, useDiagnostics } from './diagnostics.js';
|
|
39
|
-
export { VcsActionError, VcsAgentSession, VcsBranch, VcsChange, VcsPR, VcsState, getVcsState, onVcsStateChange, refreshDiff, refreshPRs, resetWorkingTree, useVcsState } from './vcs.js';
|
|
40
|
+
export { BundleCommit, BundleHistoryError, REF_KINDS, VcsActionError, VcsAgentSession, VcsBranch, VcsChange, VcsDiffWarning, VcsPR, VcsState, VcsTarget, bundleCanWrite, bundleDiffPaths, bundleHead, bundleIsAncestor, bundleLog, bundleRead, getVcsState, onVcsStateChange, refreshDiff, refreshPRs, resetWorkingTree, useVcsState } from './vcs.js';
|
|
40
41
|
export { FsChange, MountChange, getFsChange, onFsChange, useFsChange } from './onFsChange.js';
|
|
41
42
|
export { DirEntry, FileStat, FsError, MountFs, SandboxFsPort, fsAvailable, mimeTypeFor, openAppFs, openFs, sandboxFs } from './fs.js';
|
|
42
43
|
export { DebugLevel, debug, isDebugEnabled, log, useDebugEnabled } from './debug.js';
|
package/dist/index.js
CHANGED
|
@@ -36,6 +36,7 @@ export * from "./secrets.js";
|
|
|
36
36
|
export * from "./recents.js";
|
|
37
37
|
export * from "./openRepository.js";
|
|
38
38
|
export * from "./openExternal.js";
|
|
39
|
+
export * from "./openBundle.js";
|
|
39
40
|
export * from "./llm.js";
|
|
40
41
|
export * from "./diagnostics.js";
|
|
41
42
|
export * from "./vcs.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './MDXProvider';\nexport * from './routing';\nexport * from './boot';\nexport * from './components/Include';\n// Only the component is public. `stripFrontmatter`/`appMountRelative` are module-level\n// exports so they can be unit-tested directly, NOT public API — the SDK's surface is\n// backwards-compatible forever, so an internal helper exported for a test's convenience is a\n// permanent commitment made for the wrong reason.\nexport { SafeInclude } from './components/SafeInclude';\nexport * from './sourceCache';\nexport * from './components/MDXComponents';\nexport * from './linkSpace';\nexport * from './bundle';\n// Deprecated `Corpus*` spellings of the above (R3-482); see `src/corpus.ts`.\nexport * from './corpus';\nexport * from './components/MountImage';\nexport * from './components/Routes';\nexport * from './hooks';\n// R3-276: the supported way for a viewer app to provide its own metadata store,\n// replacing a wholesale re-provision of `TinkerableContext` in app code.\nexport * from './metadataSource';\n// The deprecated injected-bundler adapters, re-exported so their deprecation notices\n// are visible in the published docs (R3-278; the window only narrows).\nexport { getInjectedMetadataEmitter, getInjectedMetadataSnapshot } from './injectedBundler';\nexport * from './auth';\nexport * from './theme';\nexport * from './editorContext';\nexport * from './editor';\nexport * from './formFactor';\nexport * from './chromeState';\nexport * from './workspace';\nexport * from './hostAttention';\nexport * from './region';\n// R3-708 — the spaces mode's route channel and its one navigation verb.\nexport * from './spacesMode';\nexport * from './mounts';\nexport * from './analytics';\nexport * from './contribute';\nexport * from './catalog';\nexport * from './ipc';\nexport * from './dnd';\nexport * from './netFetch';\nexport * from './feed';\nexport * from './secrets';\nexport * from './recents'; // R3-485: the gated recent-projects read (page.home)\nexport * from './openRepository'; // R3-476: host-mediated open-in-a-new-tab (route:read)\nexport * from './openExternal'; // R3-619: host-brokered outward-link open (link:open)\nexport * from './llm';\nexport * from './diagnostics';\nexport * from './vcs';\nexport * from './onFsChange';\nexport * from './fs';\nexport * from './debug';\nexport * from './tasks';\nexport * from './launch';\nexport * from './runtime';\nexport * from './irMarkers';\nexport * from './ready';\nexport * from './loading';\nexport * from './dialog';\nexport * from './status';\nexport * from './protocolStream';\nexport * from './protocolDeadline';\nexport * from './sandboxTypes';\nexport * from './safeContent';\n// R3-489 (GROVE_AGENT_SPEC): the embedded-agent seam every app shares — the tool-use\n// loop ported from agent-demo (`runAgent` over the host chat slot), the MDX metadata\n// query tool, the headings index collector, the deixis context block, and the fence\n// for corpus-derived bytes entering a loop.\nexport * from './agentLoop';\nexport * from './agentSteering';\nexport * from './agentPause';\nexport * from './agentChatClient';\nexport * from './metadataQueryTool';\nexport * from './collectHeadings';\nexport * from './agentContext';\nexport * from './fence';\nexport * from './platformLink';\n// R3-627: the per-history-entry scratch, and the scroll restoration built on it —\n// Back lands where the reader left, for however many entries deep they go.\nexport * from './entryState';\nexport * from './useEntryState';\nexport * from './scrollRestore';\nexport { ScrollRestoration, type ScrollRestorationProps } from './components/ScrollRestoration';\n"],"mappings":";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAKd,SAAS,mBAAmB;AAC5B,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AAGd,SAAS,4BAA4B,mCAAmC;AACxE,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAKd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAAS,yBAAsD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './MDXProvider';\nexport * from './routing';\nexport * from './boot';\nexport * from './components/Include';\n// Only the component is public. `stripFrontmatter`/`appMountRelative` are module-level\n// exports so they can be unit-tested directly, NOT public API — the SDK's surface is\n// backwards-compatible forever, so an internal helper exported for a test's convenience is a\n// permanent commitment made for the wrong reason.\nexport { SafeInclude } from './components/SafeInclude';\nexport * from './sourceCache';\nexport * from './components/MDXComponents';\nexport * from './linkSpace';\nexport * from './bundle';\n// Deprecated `Corpus*` spellings of the above (R3-482); see `src/corpus.ts`.\nexport * from './corpus';\nexport * from './components/MountImage';\nexport * from './components/Routes';\nexport * from './hooks';\n// R3-276: the supported way for a viewer app to provide its own metadata store,\n// replacing a wholesale re-provision of `TinkerableContext` in app code.\nexport * from './metadataSource';\n// The deprecated injected-bundler adapters, re-exported so their deprecation notices\n// are visible in the published docs (R3-278; the window only narrows).\nexport { getInjectedMetadataEmitter, getInjectedMetadataSnapshot } from './injectedBundler';\nexport * from './auth';\nexport * from './theme';\nexport * from './editorContext';\nexport * from './editor';\nexport * from './formFactor';\nexport * from './chromeState';\nexport * from './workspace';\nexport * from './hostAttention';\nexport * from './region';\n// R3-708 — the spaces mode's route channel and its one navigation verb.\nexport * from './spacesMode';\nexport * from './mounts';\nexport * from './analytics';\nexport * from './contribute';\nexport * from './catalog';\nexport * from './ipc';\nexport * from './dnd';\nexport * from './netFetch';\nexport * from './feed';\nexport * from './secrets';\nexport * from './recents'; // R3-485: the gated recent-projects read (page.home)\nexport * from './openRepository'; // R3-476: host-mediated open-in-a-new-tab (route:read)\nexport * from './openExternal'; // R3-619: host-brokered outward-link open (link:open)\nexport * from './openBundle'; // host-mediated open of a bundle in its own tab\nexport * from './llm';\nexport * from './diagnostics';\nexport * from './vcs';\nexport * from './onFsChange';\nexport * from './fs';\nexport * from './debug';\nexport * from './tasks';\nexport * from './launch';\nexport * from './runtime';\nexport * from './irMarkers';\nexport * from './ready';\nexport * from './loading';\nexport * from './dialog';\nexport * from './status';\nexport * from './protocolStream';\nexport * from './protocolDeadline';\nexport * from './sandboxTypes';\nexport * from './safeContent';\n// R3-489 (GROVE_AGENT_SPEC): the embedded-agent seam every app shares — the tool-use\n// loop ported from agent-demo (`runAgent` over the host chat slot), the MDX metadata\n// query tool, the headings index collector, the deixis context block, and the fence\n// for corpus-derived bytes entering a loop.\nexport * from './agentLoop';\nexport * from './agentSteering';\nexport * from './agentPause';\nexport * from './agentChatClient';\nexport * from './metadataQueryTool';\nexport * from './collectHeadings';\nexport * from './agentContext';\nexport * from './fence';\nexport * from './platformLink';\n// R3-627: the per-history-entry scratch, and the scroll restoration built on it —\n// Back lands where the reader left, for however many entries deep they go.\nexport * from './entryState';\nexport * from './useEntryState';\nexport * from './scrollRestore';\nexport { ScrollRestoration, type ScrollRestorationProps } from './components/ScrollRestoration';\n"],"mappings":";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAKd,SAAS,mBAAmB;AAC5B,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AAGd,SAAS,4BAA4B,mCAAmC;AACxE,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAKd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAAS,yBAAsD;","names":[]}
|
|
@@ -0,0 +1,44 @@
|
|
|
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 openBundle_exports = {};
|
|
20
|
+
__export(openBundle_exports, {
|
|
21
|
+
OPEN_BUNDLE_REPLY_TIMEOUT_MS: () => OPEN_BUNDLE_REPLY_TIMEOUT_MS,
|
|
22
|
+
openBundle: () => openBundle
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(openBundle_exports);
|
|
25
|
+
var import_sandboxUtils = require("./sandboxUtils");
|
|
26
|
+
var import_protocolRefusal = require("./protocolRefusal");
|
|
27
|
+
var import_protocol = require("./generated/protocol");
|
|
28
|
+
var import_protocolSchemes = require("./protocolSchemes");
|
|
29
|
+
const OPEN_BUNDLE_REPLY_TIMEOUT_MS = 2e3;
|
|
30
|
+
async function openBundle(target) {
|
|
31
|
+
const { $cap, mountId, relPath, mode } = target?.dir ?? {};
|
|
32
|
+
const params = { dir: { $cap, mountId, relPath, mode } };
|
|
33
|
+
if (target?.view !== void 0) params.view = target.view;
|
|
34
|
+
const res = await (0, import_sandboxUtils.protocolRequest)(import_protocolSchemes.SCHEMES[import_protocol.PROTOCOL_OPENBUNDLE], "open", [params], {
|
|
35
|
+
timeoutMs: OPEN_BUNDLE_REPLY_TIMEOUT_MS
|
|
36
|
+
});
|
|
37
|
+
(0, import_protocolRefusal.throwOnRefusal)(res, "bundle open refused");
|
|
38
|
+
}
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
OPEN_BUNDLE_REPLY_TIMEOUT_MS,
|
|
42
|
+
openBundle
|
|
43
|
+
});
|
|
44
|
+
//# sourceMappingURL=openBundle.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/openBundle.ts"],"sourcesContent":["// Host-mediated \"open this bundle in its own tab\" (BUNDLE_EMBEDDING_SPEC §4b.9).\n//\n// Opening a bundle is not a for-result task: the reader stays, the view wants the whole\n// screen, and the bundle's files are what they work on next. So a file manager's\n// \"Open as …\" asks the host for a new tab — an ordinary session of the opener over the\n// bundle — instead of the task overlay. The tab starts in present mode, except for a local\n// dev-server source, whose tab is its editing session.\n//\n// The app names the DIRECTORY it already holds, as the same capability it would hand a\n// task, and optionally a declared view by NAME. It cannot pass a URL, a route or an app:\n// the host maps the capability to a location it can address, builds the destination from\n// its own route grammar, and the opened tab re-reads the bundle's marker and resolves the\n// opener itself. The link grants nothing.\n//\n// Not every directory has an address. A folder in a space, or on a session mount, cannot\n// be named by a URL today; the host refuses those with `unaddressable`, and the caller\n// keeps its overlay open (`invokeTask`) as the fallback.\n//\n// A host that predates this call does not refuse it — it does not answer at all, because\n// it has never heard of the request. A host that knows the request answers on the turn it\n// arrives, so the wait is bounded tightly here and its expiry (`timeout`) is the third\n// reason to fall back.\n//\n// As with `openRepository`, the open needs the HOST document's live transient user\n// activation, which the host samples rather than believes.\nimport { protocolRequest } from './sandboxUtils';\nimport { throwOnRefusal } from './protocolRefusal';\nimport { PROTOCOL_OPENBUNDLE } from './generated/protocol';\nimport { SCHEMES } from './protocolSchemes';\nimport type { DirCap } from './tasks';\n\n/** What to open: a bundle directory the app holds, and optionally one of its declared views. */\nexport interface OpenBundleTarget {\n /** The bundle's directory, as the capability the app holds on it (`capDir(...)`). */\n dir: DirCap;\n /** A view the bundle's marker declares, by name. The host resolves which app shows it. */\n view?: string;\n}\n\n/** Why a bundle did not open in a tab.\n *\n * - `invalid-params` — `dir` is not a directory capability, or `view` is not a string.\n * - `invalid` — `view` is not a view name.\n * - `unaddressable` — the directory is real and the app holds it, but the host has no URL\n * for it (a space folder, a session mount). Fall back to the overlay open.\n * - `no-activation` — no live user gesture on the host document. Call this from a click\n * handler, with no `await` before it.\n * - `forbidden` — the app may not open tabs, or does not hold the directory it named.\n * - `unsupported` — this host knows the request but has no bundle-open surface wired.\n * Fall back to the overlay open.\n * - `timeout` — the host did not answer within {@link OPEN_BUNDLE_REPLY_TIMEOUT_MS}. That\n * is what a host that predates this call does. Fall back to the overlay open.\n * - `unknown` — the host refused without naming a code.\n *\n * The SDK throws a plain `Error` with `.code` assigned; `.code` is whatever string the\n * host sent, so treat an unlisted code as possible. */\nexport type OpenBundleErrorCode =\n | 'invalid-params'\n | 'invalid'\n | 'unaddressable'\n | 'no-activation'\n | 'forbidden'\n | 'unsupported'\n | 'timeout'\n | 'unknown';\n\n/**\n * How long `openBundle` waits for the host's answer, in ms. A host that knows the request\n * decides it synchronously — nothing is fetched and nobody is asked — so the answer is one\n * message round trip away. A host that does not know it never answers, and a click that\n * does nothing for the default thirty seconds before falling back would read as broken.\n */\nexport const OPEN_BUNDLE_REPLY_TIMEOUT_MS = 2000;\n\nexport interface OpenBundleError extends Error {\n code: OpenBundleErrorCode;\n}\n\n/** The wire params: the capability and the view name, and nothing else. */\ninterface OpenBundleParams {\n dir: DirCap;\n view?: string;\n}\n\n/** The host's reply: a refusal is a resolved `{ ok: false }`, not a transport rejection. */\ntype OpenBundleReply = { ok: true } | { ok: false; code?: string; message?: string };\n\n/**\n * Ask the host to open a bundle in a new browser tab.\n *\n * Resolves once the host has performed the open; it does not wait for — and cannot observe —\n * the opened tab loading. Rejects with an {@link OpenBundleError} carrying `code` otherwise.\n * On `unaddressable`, `unsupported` or `timeout`, open the bundle the way you did before\n * this call existed: the `invokeTask` you used (`open-declared` for an app-form marker or a\n * declared view, the marker's own contract for a task-form one).\n *\n * Call it directly from a user gesture: the host samples its own transient activation when\n * the request arrives, so anything that defers the call past the gesture is refused\n * `no-activation`.\n */\nexport async function openBundle(target: OpenBundleTarget): Promise<void> {\n // Whatever was passed as `dir` is narrowed to the capability's four fields and sent: a\n // value that is not a capability is the host's to refuse (`invalid-params`), with a code.\n const { $cap, mountId, relPath, mode } = (target?.dir ?? {}) as DirCap;\n const params: OpenBundleParams = { dir: { $cap, mountId, relPath, mode } };\n if (target?.view !== undefined) params.view = target.view;\n const res = (await protocolRequest(SCHEMES[PROTOCOL_OPENBUNDLE], 'open', [params], {\n timeoutMs: OPEN_BUNDLE_REPLY_TIMEOUT_MS,\n })) as OpenBundleReply;\n throwOnRefusal(res, 'bundle open refused');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyBA,0BAAgC;AAChC,6BAA+B;AAC/B,sBAAoC;AACpC,6BAAwB;AA4CjB,MAAM,+BAA+B;AA4B5C,eAAsB,WAAW,QAAyC;AAGxE,QAAM,EAAE,MAAM,SAAS,SAAS,KAAK,IAAK,QAAQ,OAAO,CAAC;AAC1D,QAAM,SAA2B,EAAE,KAAK,EAAE,MAAM,SAAS,SAAS,KAAK,EAAE;AACzE,MAAI,QAAQ,SAAS,OAAW,QAAO,OAAO,OAAO;AACrD,QAAM,MAAO,UAAM,qCAAgB,+BAAQ,mCAAmB,GAAG,QAAQ,CAAC,MAAM,GAAG;AAAA,IACjF,WAAW;AAAA,EACb,CAAC;AACD,6CAAe,KAAK,qBAAqB;AAC3C;","names":[]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { DirCap } from './tasks.cjs';
|
|
2
|
+
|
|
3
|
+
/** What to open: a bundle directory the app holds, and optionally one of its declared views. */
|
|
4
|
+
interface OpenBundleTarget {
|
|
5
|
+
/** The bundle's directory, as the capability the app holds on it (`capDir(...)`). */
|
|
6
|
+
dir: DirCap;
|
|
7
|
+
/** A view the bundle's marker declares, by name. The host resolves which app shows it. */
|
|
8
|
+
view?: string;
|
|
9
|
+
}
|
|
10
|
+
/** Why a bundle did not open in a tab.
|
|
11
|
+
*
|
|
12
|
+
* - `invalid-params` — `dir` is not a directory capability, or `view` is not a string.
|
|
13
|
+
* - `invalid` — `view` is not a view name.
|
|
14
|
+
* - `unaddressable` — the directory is real and the app holds it, but the host has no URL
|
|
15
|
+
* for it (a space folder, a session mount). Fall back to the overlay open.
|
|
16
|
+
* - `no-activation` — no live user gesture on the host document. Call this from a click
|
|
17
|
+
* handler, with no `await` before it.
|
|
18
|
+
* - `forbidden` — the app may not open tabs, or does not hold the directory it named.
|
|
19
|
+
* - `unsupported` — this host knows the request but has no bundle-open surface wired.
|
|
20
|
+
* Fall back to the overlay open.
|
|
21
|
+
* - `timeout` — the host did not answer within {@link OPEN_BUNDLE_REPLY_TIMEOUT_MS}. That
|
|
22
|
+
* is what a host that predates this call does. Fall back to the overlay open.
|
|
23
|
+
* - `unknown` — the host refused without naming a code.
|
|
24
|
+
*
|
|
25
|
+
* The SDK throws a plain `Error` with `.code` assigned; `.code` is whatever string the
|
|
26
|
+
* host sent, so treat an unlisted code as possible. */
|
|
27
|
+
type OpenBundleErrorCode = 'invalid-params' | 'invalid' | 'unaddressable' | 'no-activation' | 'forbidden' | 'unsupported' | 'timeout' | 'unknown';
|
|
28
|
+
/**
|
|
29
|
+
* How long `openBundle` waits for the host's answer, in ms. A host that knows the request
|
|
30
|
+
* decides it synchronously — nothing is fetched and nobody is asked — so the answer is one
|
|
31
|
+
* message round trip away. A host that does not know it never answers, and a click that
|
|
32
|
+
* does nothing for the default thirty seconds before falling back would read as broken.
|
|
33
|
+
*/
|
|
34
|
+
declare const OPEN_BUNDLE_REPLY_TIMEOUT_MS = 2000;
|
|
35
|
+
interface OpenBundleError extends Error {
|
|
36
|
+
code: OpenBundleErrorCode;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Ask the host to open a bundle in a new browser tab.
|
|
40
|
+
*
|
|
41
|
+
* Resolves once the host has performed the open; it does not wait for — and cannot observe —
|
|
42
|
+
* the opened tab loading. Rejects with an {@link OpenBundleError} carrying `code` otherwise.
|
|
43
|
+
* On `unaddressable`, `unsupported` or `timeout`, open the bundle the way you did before
|
|
44
|
+
* this call existed: the `invokeTask` you used (`open-declared` for an app-form marker or a
|
|
45
|
+
* declared view, the marker's own contract for a task-form one).
|
|
46
|
+
*
|
|
47
|
+
* Call it directly from a user gesture: the host samples its own transient activation when
|
|
48
|
+
* the request arrives, so anything that defers the call past the gesture is refused
|
|
49
|
+
* `no-activation`.
|
|
50
|
+
*/
|
|
51
|
+
declare function openBundle(target: OpenBundleTarget): Promise<void>;
|
|
52
|
+
|
|
53
|
+
export { OPEN_BUNDLE_REPLY_TIMEOUT_MS, type OpenBundleError, type OpenBundleErrorCode, type OpenBundleTarget, openBundle };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { DirCap } from './tasks.js';
|
|
2
|
+
|
|
3
|
+
/** What to open: a bundle directory the app holds, and optionally one of its declared views. */
|
|
4
|
+
interface OpenBundleTarget {
|
|
5
|
+
/** The bundle's directory, as the capability the app holds on it (`capDir(...)`). */
|
|
6
|
+
dir: DirCap;
|
|
7
|
+
/** A view the bundle's marker declares, by name. The host resolves which app shows it. */
|
|
8
|
+
view?: string;
|
|
9
|
+
}
|
|
10
|
+
/** Why a bundle did not open in a tab.
|
|
11
|
+
*
|
|
12
|
+
* - `invalid-params` — `dir` is not a directory capability, or `view` is not a string.
|
|
13
|
+
* - `invalid` — `view` is not a view name.
|
|
14
|
+
* - `unaddressable` — the directory is real and the app holds it, but the host has no URL
|
|
15
|
+
* for it (a space folder, a session mount). Fall back to the overlay open.
|
|
16
|
+
* - `no-activation` — no live user gesture on the host document. Call this from a click
|
|
17
|
+
* handler, with no `await` before it.
|
|
18
|
+
* - `forbidden` — the app may not open tabs, or does not hold the directory it named.
|
|
19
|
+
* - `unsupported` — this host knows the request but has no bundle-open surface wired.
|
|
20
|
+
* Fall back to the overlay open.
|
|
21
|
+
* - `timeout` — the host did not answer within {@link OPEN_BUNDLE_REPLY_TIMEOUT_MS}. That
|
|
22
|
+
* is what a host that predates this call does. Fall back to the overlay open.
|
|
23
|
+
* - `unknown` — the host refused without naming a code.
|
|
24
|
+
*
|
|
25
|
+
* The SDK throws a plain `Error` with `.code` assigned; `.code` is whatever string the
|
|
26
|
+
* host sent, so treat an unlisted code as possible. */
|
|
27
|
+
type OpenBundleErrorCode = 'invalid-params' | 'invalid' | 'unaddressable' | 'no-activation' | 'forbidden' | 'unsupported' | 'timeout' | 'unknown';
|
|
28
|
+
/**
|
|
29
|
+
* How long `openBundle` waits for the host's answer, in ms. A host that knows the request
|
|
30
|
+
* decides it synchronously — nothing is fetched and nobody is asked — so the answer is one
|
|
31
|
+
* message round trip away. A host that does not know it never answers, and a click that
|
|
32
|
+
* does nothing for the default thirty seconds before falling back would read as broken.
|
|
33
|
+
*/
|
|
34
|
+
declare const OPEN_BUNDLE_REPLY_TIMEOUT_MS = 2000;
|
|
35
|
+
interface OpenBundleError extends Error {
|
|
36
|
+
code: OpenBundleErrorCode;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Ask the host to open a bundle in a new browser tab.
|
|
40
|
+
*
|
|
41
|
+
* Resolves once the host has performed the open; it does not wait for — and cannot observe —
|
|
42
|
+
* the opened tab loading. Rejects with an {@link OpenBundleError} carrying `code` otherwise.
|
|
43
|
+
* On `unaddressable`, `unsupported` or `timeout`, open the bundle the way you did before
|
|
44
|
+
* this call existed: the `invokeTask` you used (`open-declared` for an app-form marker or a
|
|
45
|
+
* declared view, the marker's own contract for a task-form one).
|
|
46
|
+
*
|
|
47
|
+
* Call it directly from a user gesture: the host samples its own transient activation when
|
|
48
|
+
* the request arrives, so anything that defers the call past the gesture is refused
|
|
49
|
+
* `no-activation`.
|
|
50
|
+
*/
|
|
51
|
+
declare function openBundle(target: OpenBundleTarget): Promise<void>;
|
|
52
|
+
|
|
53
|
+
export { OPEN_BUNDLE_REPLY_TIMEOUT_MS, type OpenBundleError, type OpenBundleErrorCode, type OpenBundleTarget, openBundle };
|