@immediately-run/sdk 0.2.2 → 0.2.4
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 +83 -0
- package/dist/catalog.cjs.map +1 -0
- package/dist/catalog.d.cts +30 -0
- package/dist/catalog.d.ts +30 -0
- package/dist/catalog.js +55 -0
- package/dist/catalog.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/catalog.cjs
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
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 catalog_exports = {};
|
|
20
|
+
__export(catalog_exports, {
|
|
21
|
+
getCatalog: () => getCatalog,
|
|
22
|
+
invoke: () => invoke,
|
|
23
|
+
invokeStream: () => invokeStream,
|
|
24
|
+
onCatalogChange: () => onCatalogChange,
|
|
25
|
+
useCatalog: () => useCatalog
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(catalog_exports);
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
var import_sandboxUtils = require("./sandboxUtils");
|
|
30
|
+
var import_protocolStream = require("./protocolStream");
|
|
31
|
+
const split = (name) => {
|
|
32
|
+
const i = name.indexOf(":");
|
|
33
|
+
if (i <= 0) throw new Error(`invalid catalog method name: ${name}`);
|
|
34
|
+
return [name.slice(0, i), name.slice(i + 1)];
|
|
35
|
+
};
|
|
36
|
+
const invoke = async (name, params = {}) => {
|
|
37
|
+
const [scheme, method] = split(name);
|
|
38
|
+
const res = await (0, import_sandboxUtils.protocolRequest)(scheme, method, [params]);
|
|
39
|
+
if (!res || res.ok !== true) {
|
|
40
|
+
const err = new Error(res?.message ?? `${name} failed`);
|
|
41
|
+
err.code = res?.code ?? "unknown";
|
|
42
|
+
throw err;
|
|
43
|
+
}
|
|
44
|
+
return res.data;
|
|
45
|
+
};
|
|
46
|
+
const bundlerTransport = {
|
|
47
|
+
send: (msg) => (
|
|
48
|
+
// @ts-ignore - injected by the sandbox runtime
|
|
49
|
+
module.evaluation.module.bundler.messageBus.sendMessage(msg.type, msg)
|
|
50
|
+
),
|
|
51
|
+
subscribe: (type, handler) => {
|
|
52
|
+
const d = module.evaluation.module.bundler.messageBus.onMessage((m) => {
|
|
53
|
+
if (m && m.type === type) handler(m);
|
|
54
|
+
});
|
|
55
|
+
return () => d.dispose();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
function invokeStream(name, params = {}) {
|
|
59
|
+
const [scheme, method] = split(name);
|
|
60
|
+
return (0, import_protocolStream.consumeStream)(bundlerTransport, `protocol-${scheme}`, method, [params]);
|
|
61
|
+
}
|
|
62
|
+
const catalogService = () => {
|
|
63
|
+
return module.evaluation.module.bundler.catalog;
|
|
64
|
+
};
|
|
65
|
+
const getCatalog = () => catalogService().getCatalog();
|
|
66
|
+
const onCatalogChange = (listener) => {
|
|
67
|
+
const disposable = catalogService().onChange(listener);
|
|
68
|
+
return () => disposable.dispose();
|
|
69
|
+
};
|
|
70
|
+
const useCatalog = () => {
|
|
71
|
+
const [catalog, setCatalog] = (0, import_react.useState)(getCatalog);
|
|
72
|
+
(0, import_react.useEffect)(() => onCatalogChange(setCatalog), []);
|
|
73
|
+
return catalog;
|
|
74
|
+
};
|
|
75
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
76
|
+
0 && (module.exports = {
|
|
77
|
+
getCatalog,
|
|
78
|
+
invoke,
|
|
79
|
+
invokeStream,
|
|
80
|
+
onCatalogChange,
|
|
81
|
+
useCatalog
|
|
82
|
+
});
|
|
83
|
+
//# sourceMappingURL=catalog.cjs.map
|
|
@@ -0,0 +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 { useEffect, useState } from 'react';\nimport { protocolRequest } from './sandboxUtils';\nimport type { StreamFrame } from './protocolStream';\nimport { consumeStream } from './protocolStream';\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:share`, `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\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:share', { 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>(\n name: string,\n params: Record<string, unknown> = {},\n): 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\nconst bundlerTransport = {\n send: (msg: { type: string; method: string; params: unknown[]; msgId: number; stream: true }) =>\n // @ts-ignore - injected by the sandbox runtime\n module.evaluation.module.bundler.messageBus.sendMessage(msg.type, msg),\n subscribe: (type: string, handler: (msg: { msgId?: number; stream?: StreamFrame }) => void) => {\n // @ts-ignore - injected by the sandbox runtime\n const d = module.evaluation.module.bundler.messageBus.onMessage((m: { type?: string }) => {\n if (m && m.type === type) handler(m as { msgId?: number; stream?: StreamFrame });\n });\n return () => d.dispose();\n },\n};\n\n/** Call a STREAMING catalog method by name, yielding its events. */\nexport function invokeStream<T = unknown, R = unknown>(\n name: string,\n params: Record<string, unknown> = {},\n): AsyncGenerator<T, R, void> {\n const [scheme, method] = split(name);\n return consumeStream<T, R>(bundlerTransport, `protocol-${scheme}`, method, [params]);\n}\n\ninterface CatalogService {\n getCatalog(): ApiMethod[];\n onChange(listener: (catalog: ApiMethod[]) => void): { dispose(): void };\n}\n\n// `module.evaluation.module.bundler.catalog` — injected by the sandbox runtime.\nconst catalogService = (): CatalogService => {\n // @ts-ignore - injected by the sandbox runtime\n return module.evaluation.module.bundler.catalog;\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[] => catalogService().getCatalog();\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) => {\n const disposable = catalogService().onChange(listener);\n return () => disposable.dispose();\n};\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[] => {\n const [catalog, setCatalog] = useState<ApiMethod[]>(getCatalog);\n useEffect(() => onCatalogChange(setCatalog), []);\n return catalog;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,mBAAoC;AACpC,0BAAgC;AAEhC,4BAA8B;AAa9B,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,OACpB,MACA,SAAkC,CAAC,MACpB;AACf,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;AACxB,UAAM;AAAA,EACR;AACA,SAAO,IAAI;AACb;AAEA,MAAM,mBAAmB;AAAA,EACvB,MAAM,CAAC;AAAA;AAAA,IAEL,OAAO,WAAW,OAAO,QAAQ,WAAW,YAAY,IAAI,MAAM,GAAG;AAAA;AAAA,EACvE,WAAW,CAAC,MAAc,YAAqE;AAE7F,UAAM,IAAI,OAAO,WAAW,OAAO,QAAQ,WAAW,UAAU,CAAC,MAAyB;AACxF,UAAI,KAAK,EAAE,SAAS,KAAM,SAAQ,CAA6C;AAAA,IACjF,CAAC;AACD,WAAO,MAAM,EAAE,QAAQ;AAAA,EACzB;AACF;AAGO,SAAS,aACd,MACA,SAAkC,CAAC,GACP;AAC5B,QAAM,CAAC,QAAQ,MAAM,IAAI,MAAM,IAAI;AACnC,aAAO,qCAAoB,kBAAkB,YAAY,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC;AACrF;AAQA,MAAM,iBAAiB,MAAsB;AAE3C,SAAO,OAAO,WAAW,OAAO,QAAQ;AAC1C;AAIO,MAAM,aAAa,MAAmB,eAAe,EAAE,WAAW;AAIlE,MAAM,kBAAkB,CAAC,aAA2D;AACzF,QAAM,aAAa,eAAe,EAAE,SAAS,QAAQ;AACrD,SAAO,MAAM,WAAW,QAAQ;AAClC;AAKO,MAAM,aAAa,MAAmB;AAC3C,QAAM,CAAC,SAAS,UAAU,QAAI,uBAAsB,UAAU;AAC9D,8BAAU,MAAM,gBAAgB,UAAU,GAAG,CAAC,CAAC;AAC/C,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** One advertised method, as the host generated it from its gate table. */
|
|
2
|
+
interface ApiMethod {
|
|
3
|
+
/** Catalog name, `protocol-` stripped — e.g. `spaces:share`, `contribute:run`. */
|
|
4
|
+
name: string;
|
|
5
|
+
/** The capability this method requires (already held — it's in your catalog). */
|
|
6
|
+
capability: string;
|
|
7
|
+
/** True when the method STREAMS (use {@link invokeStream}) vs. single-reply. */
|
|
8
|
+
stream?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Call a catalog method by name — `invoke('spaces:share', { spaceId, login, role })`.
|
|
12
|
+
* A thin generic over the host protocol: the host validates params and gates the
|
|
13
|
+
* call (an un-granted method → `forbidden`, even if you name it directly). For a
|
|
14
|
+
* STREAMING method (`ApiMethod.stream`), use {@link invokeStream}.
|
|
15
|
+
*/
|
|
16
|
+
declare const invoke: <T = unknown>(name: string, params?: Record<string, unknown>) => Promise<T>;
|
|
17
|
+
/** Call a STREAMING catalog method by name, yielding its events. */
|
|
18
|
+
declare function invokeStream<T = unknown, R = unknown>(name: string, params?: Record<string, unknown>): AsyncGenerator<T, R, void>;
|
|
19
|
+
/** The methods this app may call (grant-filtered, §5.5). Poll for a one-off read;
|
|
20
|
+
* use {@link onCatalogChange} / {@link useCatalog} to react. */
|
|
21
|
+
declare const getCatalog: () => ApiMethod[];
|
|
22
|
+
/** Subscribe to catalog changes (e.g. a grant added/revoked). Invoked immediately
|
|
23
|
+
* with the current catalog, then on every change. Returns an unsubscribe fn. */
|
|
24
|
+
declare const onCatalogChange: (listener: (catalog: ApiMethod[]) => void) => (() => void);
|
|
25
|
+
/** React hook returning this app's method catalog, re-rendering on change. Hand
|
|
26
|
+
* it to an embedded agent as its tool list to confine the agent to the app's
|
|
27
|
+
* authority (§5.9). */
|
|
28
|
+
declare const useCatalog: () => ApiMethod[];
|
|
29
|
+
|
|
30
|
+
export { type ApiMethod, getCatalog, invoke, invokeStream, onCatalogChange, useCatalog };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** One advertised method, as the host generated it from its gate table. */
|
|
2
|
+
interface ApiMethod {
|
|
3
|
+
/** Catalog name, `protocol-` stripped — e.g. `spaces:share`, `contribute:run`. */
|
|
4
|
+
name: string;
|
|
5
|
+
/** The capability this method requires (already held — it's in your catalog). */
|
|
6
|
+
capability: string;
|
|
7
|
+
/** True when the method STREAMS (use {@link invokeStream}) vs. single-reply. */
|
|
8
|
+
stream?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Call a catalog method by name — `invoke('spaces:share', { spaceId, login, role })`.
|
|
12
|
+
* A thin generic over the host protocol: the host validates params and gates the
|
|
13
|
+
* call (an un-granted method → `forbidden`, even if you name it directly). For a
|
|
14
|
+
* STREAMING method (`ApiMethod.stream`), use {@link invokeStream}.
|
|
15
|
+
*/
|
|
16
|
+
declare const invoke: <T = unknown>(name: string, params?: Record<string, unknown>) => Promise<T>;
|
|
17
|
+
/** Call a STREAMING catalog method by name, yielding its events. */
|
|
18
|
+
declare function invokeStream<T = unknown, R = unknown>(name: string, params?: Record<string, unknown>): AsyncGenerator<T, R, void>;
|
|
19
|
+
/** The methods this app may call (grant-filtered, §5.5). Poll for a one-off read;
|
|
20
|
+
* use {@link onCatalogChange} / {@link useCatalog} to react. */
|
|
21
|
+
declare const getCatalog: () => ApiMethod[];
|
|
22
|
+
/** Subscribe to catalog changes (e.g. a grant added/revoked). Invoked immediately
|
|
23
|
+
* with the current catalog, then on every change. Returns an unsubscribe fn. */
|
|
24
|
+
declare const onCatalogChange: (listener: (catalog: ApiMethod[]) => void) => (() => void);
|
|
25
|
+
/** React hook returning this app's method catalog, re-rendering on change. Hand
|
|
26
|
+
* it to an embedded agent as its tool list to confine the agent to the app's
|
|
27
|
+
* authority (§5.9). */
|
|
28
|
+
declare const useCatalog: () => ApiMethod[];
|
|
29
|
+
|
|
30
|
+
export { type ApiMethod, getCatalog, invoke, invokeStream, onCatalogChange, useCatalog };
|
package/dist/catalog.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { protocolRequest } from "./sandboxUtils";
|
|
3
|
+
import { consumeStream } from "./protocolStream";
|
|
4
|
+
const split = (name) => {
|
|
5
|
+
const i = name.indexOf(":");
|
|
6
|
+
if (i <= 0) throw new Error(`invalid catalog method name: ${name}`);
|
|
7
|
+
return [name.slice(0, i), name.slice(i + 1)];
|
|
8
|
+
};
|
|
9
|
+
const invoke = async (name, params = {}) => {
|
|
10
|
+
const [scheme, method] = split(name);
|
|
11
|
+
const res = await protocolRequest(scheme, method, [params]);
|
|
12
|
+
if (!res || res.ok !== true) {
|
|
13
|
+
const err = new Error(res?.message ?? `${name} failed`);
|
|
14
|
+
err.code = res?.code ?? "unknown";
|
|
15
|
+
throw err;
|
|
16
|
+
}
|
|
17
|
+
return res.data;
|
|
18
|
+
};
|
|
19
|
+
const bundlerTransport = {
|
|
20
|
+
send: (msg) => (
|
|
21
|
+
// @ts-ignore - injected by the sandbox runtime
|
|
22
|
+
module.evaluation.module.bundler.messageBus.sendMessage(msg.type, msg)
|
|
23
|
+
),
|
|
24
|
+
subscribe: (type, handler) => {
|
|
25
|
+
const d = module.evaluation.module.bundler.messageBus.onMessage((m) => {
|
|
26
|
+
if (m && m.type === type) handler(m);
|
|
27
|
+
});
|
|
28
|
+
return () => d.dispose();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
function invokeStream(name, params = {}) {
|
|
32
|
+
const [scheme, method] = split(name);
|
|
33
|
+
return consumeStream(bundlerTransport, `protocol-${scheme}`, method, [params]);
|
|
34
|
+
}
|
|
35
|
+
const catalogService = () => {
|
|
36
|
+
return module.evaluation.module.bundler.catalog;
|
|
37
|
+
};
|
|
38
|
+
const getCatalog = () => catalogService().getCatalog();
|
|
39
|
+
const onCatalogChange = (listener) => {
|
|
40
|
+
const disposable = catalogService().onChange(listener);
|
|
41
|
+
return () => disposable.dispose();
|
|
42
|
+
};
|
|
43
|
+
const useCatalog = () => {
|
|
44
|
+
const [catalog, setCatalog] = useState(getCatalog);
|
|
45
|
+
useEffect(() => onCatalogChange(setCatalog), []);
|
|
46
|
+
return catalog;
|
|
47
|
+
};
|
|
48
|
+
export {
|
|
49
|
+
getCatalog,
|
|
50
|
+
invoke,
|
|
51
|
+
invokeStream,
|
|
52
|
+
onCatalogChange,
|
|
53
|
+
useCatalog
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=catalog.js.map
|
|
@@ -0,0 +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 { useEffect, useState } from 'react';\nimport { protocolRequest } from './sandboxUtils';\nimport type { StreamFrame } from './protocolStream';\nimport { consumeStream } from './protocolStream';\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:share`, `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\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:share', { 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>(\n name: string,\n params: Record<string, unknown> = {},\n): 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\nconst bundlerTransport = {\n send: (msg: { type: string; method: string; params: unknown[]; msgId: number; stream: true }) =>\n // @ts-ignore - injected by the sandbox runtime\n module.evaluation.module.bundler.messageBus.sendMessage(msg.type, msg),\n subscribe: (type: string, handler: (msg: { msgId?: number; stream?: StreamFrame }) => void) => {\n // @ts-ignore - injected by the sandbox runtime\n const d = module.evaluation.module.bundler.messageBus.onMessage((m: { type?: string }) => {\n if (m && m.type === type) handler(m as { msgId?: number; stream?: StreamFrame });\n });\n return () => d.dispose();\n },\n};\n\n/** Call a STREAMING catalog method by name, yielding its events. */\nexport function invokeStream<T = unknown, R = unknown>(\n name: string,\n params: Record<string, unknown> = {},\n): AsyncGenerator<T, R, void> {\n const [scheme, method] = split(name);\n return consumeStream<T, R>(bundlerTransport, `protocol-${scheme}`, method, [params]);\n}\n\ninterface CatalogService {\n getCatalog(): ApiMethod[];\n onChange(listener: (catalog: ApiMethod[]) => void): { dispose(): void };\n}\n\n// `module.evaluation.module.bundler.catalog` — injected by the sandbox runtime.\nconst catalogService = (): CatalogService => {\n // @ts-ignore - injected by the sandbox runtime\n return module.evaluation.module.bundler.catalog;\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[] => catalogService().getCatalog();\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) => {\n const disposable = catalogService().onChange(listener);\n return () => disposable.dispose();\n};\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[] => {\n const [catalog, setCatalog] = useState<ApiMethod[]>(getCatalog);\n useEffect(() => onCatalogChange(setCatalog), []);\n return catalog;\n};\n"],"mappings":"AAKA,SAAS,WAAW,gBAAgB;AACpC,SAAS,uBAAuB;AAEhC,SAAS,qBAAqB;AAa9B,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,OACpB,MACA,SAAkC,CAAC,MACpB;AACf,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;AACxB,UAAM;AAAA,EACR;AACA,SAAO,IAAI;AACb;AAEA,MAAM,mBAAmB;AAAA,EACvB,MAAM,CAAC;AAAA;AAAA,IAEL,OAAO,WAAW,OAAO,QAAQ,WAAW,YAAY,IAAI,MAAM,GAAG;AAAA;AAAA,EACvE,WAAW,CAAC,MAAc,YAAqE;AAE7F,UAAM,IAAI,OAAO,WAAW,OAAO,QAAQ,WAAW,UAAU,CAAC,MAAyB;AACxF,UAAI,KAAK,EAAE,SAAS,KAAM,SAAQ,CAA6C;AAAA,IACjF,CAAC;AACD,WAAO,MAAM,EAAE,QAAQ;AAAA,EACzB;AACF;AAGO,SAAS,aACd,MACA,SAAkC,CAAC,GACP;AAC5B,QAAM,CAAC,QAAQ,MAAM,IAAI,MAAM,IAAI;AACnC,SAAO,cAAoB,kBAAkB,YAAY,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC;AACrF;AAQA,MAAM,iBAAiB,MAAsB;AAE3C,SAAO,OAAO,WAAW,OAAO,QAAQ;AAC1C;AAIO,MAAM,aAAa,MAAmB,eAAe,EAAE,WAAW;AAIlE,MAAM,kBAAkB,CAAC,aAA2D;AACzF,QAAM,aAAa,eAAe,EAAE,SAAS,QAAQ;AACrD,SAAO,MAAM,WAAW,QAAQ;AAClC;AAKO,MAAM,aAAa,MAAmB;AAC3C,QAAM,CAAC,SAAS,UAAU,IAAI,SAAsB,UAAU;AAC9D,YAAU,MAAM,gBAAgB,UAAU,GAAG,CAAC,CAAC;AAC/C,SAAO;AACT;","names":[]}
|
package/dist/index.cjs
CHANGED
|
@@ -27,6 +27,7 @@ __reExport(index_exports, require("./editorContext"), module.exports);
|
|
|
27
27
|
__reExport(index_exports, require("./formFactor"), module.exports);
|
|
28
28
|
__reExport(index_exports, require("./mounts"), module.exports);
|
|
29
29
|
__reExport(index_exports, require("./contribute"), module.exports);
|
|
30
|
+
__reExport(index_exports, require("./catalog"), module.exports);
|
|
30
31
|
__reExport(index_exports, require("./protocolStream"), module.exports);
|
|
31
32
|
__reExport(index_exports, require("./sandboxTypes"), module.exports);
|
|
32
33
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -43,6 +44,7 @@ __reExport(index_exports, require("./sandboxTypes"), module.exports);
|
|
|
43
44
|
...require("./formFactor"),
|
|
44
45
|
...require("./mounts"),
|
|
45
46
|
...require("./contribute"),
|
|
47
|
+
...require("./catalog"),
|
|
46
48
|
...require("./protocolStream"),
|
|
47
49
|
...require("./sandboxTypes")
|
|
48
50
|
});
|
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';\nexport * from './components/MDXComponents';\nexport * from './hooks'\nexport * from './auth';\nexport * from './theme';\nexport * from './editorContext';\nexport * from './formFactor';\nexport * from './mounts';\nexport * from './contribute';\nexport * from './protocolStream';\nexport * from './sandboxTypes';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,0BAAd;AACA,0BAAc,sBADd;AAEA,0BAAc,mBAFd;AAGA,0BAAc,iCAHd;AAIA,0BAAc,uCAJd;AAKA,0BAAc,oBALd;AAMA,0BAAc,mBANd;AAOA,0BAAc,oBAPd;AAQA,0BAAc,4BARd;AASA,0BAAc,yBATd;AAUA,0BAAc,qBAVd;AAWA,0BAAc,yBAXd;AAYA,0BAAc,
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from \"./MDXProvider\";\nexport * from \"./routing\";\nexport * from \"./boot\";\nexport * from './components/Include';\nexport * from './components/MDXComponents';\nexport * from './hooks'\nexport * from './auth';\nexport * from './theme';\nexport * from './editorContext';\nexport * from './formFactor';\nexport * from './mounts';\nexport * from './contribute';\nexport * from './catalog';\nexport * from './protocolStream';\nexport * from './sandboxTypes';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,0BAAd;AACA,0BAAc,sBADd;AAEA,0BAAc,mBAFd;AAGA,0BAAc,iCAHd;AAIA,0BAAc,uCAJd;AAKA,0BAAc,oBALd;AAMA,0BAAc,mBANd;AAOA,0BAAc,oBAPd;AAQA,0BAAc,4BARd;AASA,0BAAc,yBATd;AAUA,0BAAc,qBAVd;AAWA,0BAAc,yBAXd;AAYA,0BAAc,sBAZd;AAaA,0BAAc,6BAbd;AAcA,0BAAc,2BAdd;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -10,6 +10,7 @@ export { EditorContext, getEditorContext, onEditorContextChange, useEditorContex
|
|
|
10
10
|
export { FormFactor, FormFactorClass, Orientation, getFormFactor, onFormFactorChange, useFormFactor } from './formFactor.cjs';
|
|
11
11
|
export { GrantRecord, Member, MountQuery, ResolvedUser, Role, SandboxMount, SpaceError, SpaceInfo, createSpace, findMount, getMounts, getSpaceMembers, listAllSpaces, listGrants, listSpaces, lookupUser, mount, mountSpace, onMountsChange, openAppSpace, requestMount, requestSpace, revokeGrant, setSpaceRole, shareSpace, unmountSpace, unshareSpace, useMounts, waitForMount } from './mounts.cjs';
|
|
12
12
|
export { ContributeMode, ContributeOptions, ContributionEvent, ContributionResult, contribute } from './contribute.cjs';
|
|
13
|
+
export { ApiMethod, getCatalog, invoke, invokeStream, onCatalogChange, useCatalog } from './catalog.cjs';
|
|
13
14
|
export { StreamError, StreamFrame, StreamTransport, consumeStream, protocolStream } from './protocolStream.cjs';
|
|
14
15
|
export { EvaluationContext, FileQueryResult, FilesMetadata, Metadata, MetadataQueryFunction, MetadataQueryResult, ModuleExports } from './sandboxTypes.cjs';
|
|
15
16
|
import 'react';
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { EditorContext, getEditorContext, onEditorContextChange, useEditorContex
|
|
|
10
10
|
export { FormFactor, FormFactorClass, Orientation, getFormFactor, onFormFactorChange, useFormFactor } from './formFactor.js';
|
|
11
11
|
export { GrantRecord, Member, MountQuery, ResolvedUser, Role, SandboxMount, SpaceError, SpaceInfo, createSpace, findMount, getMounts, getSpaceMembers, listAllSpaces, listGrants, listSpaces, lookupUser, mount, mountSpace, onMountsChange, openAppSpace, requestMount, requestSpace, revokeGrant, setSpaceRole, shareSpace, unmountSpace, unshareSpace, useMounts, waitForMount } from './mounts.js';
|
|
12
12
|
export { ContributeMode, ContributeOptions, ContributionEvent, ContributionResult, contribute } from './contribute.js';
|
|
13
|
+
export { ApiMethod, getCatalog, invoke, invokeStream, onCatalogChange, useCatalog } from './catalog.js';
|
|
13
14
|
export { StreamError, StreamFrame, StreamTransport, consumeStream, protocolStream } from './protocolStream.js';
|
|
14
15
|
export { EvaluationContext, FileQueryResult, FilesMetadata, Metadata, MetadataQueryFunction, MetadataQueryResult, ModuleExports } from './sandboxTypes.js';
|
|
15
16
|
import 'react';
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export * from "./editorContext";
|
|
|
10
10
|
export * from "./formFactor";
|
|
11
11
|
export * from "./mounts";
|
|
12
12
|
export * from "./contribute";
|
|
13
|
+
export * from "./catalog";
|
|
13
14
|
export * from "./protocolStream";
|
|
14
15
|
export * from "./sandboxTypes";
|
|
15
16
|
//# sourceMappingURL=index.js.map
|
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';\nexport * from './components/MDXComponents';\nexport * from './hooks'\nexport * from './auth';\nexport * from './theme';\nexport * from './editorContext';\nexport * from './formFactor';\nexport * from './mounts';\nexport * from './contribute';\nexport * from './protocolStream';\nexport * from './sandboxTypes';\n"],"mappings":"AAAA,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;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from \"./MDXProvider\";\nexport * from \"./routing\";\nexport * from \"./boot\";\nexport * from './components/Include';\nexport * from './components/MDXComponents';\nexport * from './hooks'\nexport * from './auth';\nexport * from './theme';\nexport * from './editorContext';\nexport * from './formFactor';\nexport * from './mounts';\nexport * from './contribute';\nexport * from './catalog';\nexport * from './protocolStream';\nexport * from './sandboxTypes';\n"],"mappings":"AAAA,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;","names":[]}
|
package/package.json
CHANGED