@immediately-run/sdk 0.2.5 → 0.2.7

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/index.cjs CHANGED
@@ -30,6 +30,7 @@ __reExport(index_exports, require("./contribute"), module.exports);
30
30
  __reExport(index_exports, require("./catalog"), module.exports);
31
31
  __reExport(index_exports, require("./ipc"), module.exports);
32
32
  __reExport(index_exports, require("./tasks"), module.exports);
33
+ __reExport(index_exports, require("./runtime"), module.exports);
33
34
  __reExport(index_exports, require("./protocolStream"), module.exports);
34
35
  __reExport(index_exports, require("./sandboxTypes"), module.exports);
35
36
  // Annotate the CommonJS export names for ESM import in node:
@@ -49,6 +50,7 @@ __reExport(index_exports, require("./sandboxTypes"), module.exports);
49
50
  ...require("./catalog"),
50
51
  ...require("./ipc"),
51
52
  ...require("./tasks"),
53
+ ...require("./runtime"),
52
54
  ...require("./protocolStream"),
53
55
  ...require("./sandboxTypes")
54
56
  });
@@ -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 './catalog';\nexport * from './ipc';\nexport * from './tasks';\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,kBAbd;AAcA,0BAAc,oBAdd;AAeA,0BAAc,6BAfd;AAgBA,0BAAc,2BAhBd;","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 './ipc';\nexport * from './tasks';\nexport * from './runtime';\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,kBAbd;AAcA,0BAAc,oBAdd;AAeA,0BAAc,sBAfd;AAgBA,0BAAc,6BAhBd;AAiBA,0BAAc,2BAjBd;","names":[]}
package/dist/index.d.cts CHANGED
@@ -13,6 +13,7 @@ export { ContributeMode, ContributeOptions, ContributionEvent, ContributionResul
13
13
  export { ApiMethod, getCatalog, invoke, invokeStream, onCatalogChange, useCatalog } from './catalog.cjs';
14
14
  export { RegionMessage, onRegionMessage, postToRegion, useRegionMessage } from './ipc.cjs';
15
15
  export { FileCap, TaskInput, cancelTask, capFile, completeTask, getTaskInput, invokeTask, useTaskInput } from './tasks.cjs';
16
+ export { ImmediatelyRunGlobal, SDK_PROTOCOL_VERSION, SDK_VERSION, SdkHandshake, announceHandshake, getHostRuntime, sdkHandshake } from './runtime.cjs';
16
17
  export { StreamError, StreamFrame, StreamTransport, consumeStream, protocolStream } from './protocolStream.cjs';
17
18
  export { EvaluationContext, FileQueryResult, FilesMetadata, Metadata, MetadataQueryFunction, MetadataQueryResult, ModuleExports } from './sandboxTypes.cjs';
18
19
  import 'react';
package/dist/index.d.ts CHANGED
@@ -13,6 +13,7 @@ export { ContributeMode, ContributeOptions, ContributionEvent, ContributionResul
13
13
  export { ApiMethod, getCatalog, invoke, invokeStream, onCatalogChange, useCatalog } from './catalog.js';
14
14
  export { RegionMessage, onRegionMessage, postToRegion, useRegionMessage } from './ipc.js';
15
15
  export { FileCap, TaskInput, cancelTask, capFile, completeTask, getTaskInput, invokeTask, useTaskInput } from './tasks.js';
16
+ export { ImmediatelyRunGlobal, SDK_PROTOCOL_VERSION, SDK_VERSION, SdkHandshake, announceHandshake, getHostRuntime, sdkHandshake } from './runtime.js';
16
17
  export { StreamError, StreamFrame, StreamTransport, consumeStream, protocolStream } from './protocolStream.js';
17
18
  export { EvaluationContext, FileQueryResult, FilesMetadata, Metadata, MetadataQueryFunction, MetadataQueryResult, ModuleExports } from './sandboxTypes.js';
18
19
  import 'react';
package/dist/index.js CHANGED
@@ -13,6 +13,7 @@ export * from "./contribute";
13
13
  export * from "./catalog";
14
14
  export * from "./ipc";
15
15
  export * from "./tasks";
16
+ export * from "./runtime";
16
17
  export * from "./protocolStream";
17
18
  export * from "./sandboxTypes";
18
19
  //# 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 './catalog';\nexport * from './ipc';\nexport * from './tasks';\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;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 './ipc';\nexport * from './tasks';\nexport * from './runtime';\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;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
@@ -0,0 +1,60 @@
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 runtime_exports = {};
20
+ __export(runtime_exports, {
21
+ SDK_PROTOCOL_VERSION: () => SDK_PROTOCOL_VERSION,
22
+ SDK_VERSION: () => SDK_VERSION,
23
+ announceHandshake: () => announceHandshake,
24
+ getHostRuntime: () => getHostRuntime,
25
+ sdkHandshake: () => sdkHandshake
26
+ });
27
+ module.exports = __toCommonJS(runtime_exports);
28
+ var import_sandboxUtils = require("./sandboxUtils");
29
+ const SDK_PROTOCOL_VERSION = "1.0.0";
30
+ const SDK_VERSION = "0.2.7";
31
+ function getHostRuntime() {
32
+ try {
33
+ return globalThis.__immediatelyRun__ ?? null;
34
+ } catch {
35
+ return null;
36
+ }
37
+ }
38
+ const sdkHandshake = () => ({
39
+ sdkVersion: SDK_VERSION,
40
+ protocolVersion: SDK_PROTOCOL_VERSION
41
+ });
42
+ function announceHandshake() {
43
+ const send = () => {
44
+ try {
45
+ (0, import_sandboxUtils.sendMessage)("sdk-handshake", sdkHandshake());
46
+ } catch {
47
+ }
48
+ };
49
+ send();
50
+ return (0, import_sandboxUtils.addListener)("request-handshake", send);
51
+ }
52
+ // Annotate the CommonJS export names for ESM import in node:
53
+ 0 && (module.exports = {
54
+ SDK_PROTOCOL_VERSION,
55
+ SDK_VERSION,
56
+ announceHandshake,
57
+ getHostRuntime,
58
+ sdkHandshake
59
+ });
60
+ //# sourceMappingURL=runtime.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/runtime.ts"],"sourcesContent":["// Runtime discovery + version handshake (SDK_PACKAGING_SPEC §4/§6).\n//\n// Today the SDK reaches the host through the INJECTED sandbox services\n// (`module.evaluation.module.bundler.*`, see sandboxUtils). The packaging migration\n// makes the SDK an app-pinnable npm dependency that finds the runtime through a\n// stable, versioned global the sandbox publishes BEFORE evaluating app code:\n//\n// globalThis.__immediatelyRun__ = { runtimeVersion, protocolVersion, transport }\n//\n// Phase 1 (behind a flag, injection still active): the SDK can READ that global\n// when present (else fall back to injection), and ANNOUNCE its own version +\n// protocol so the host can record + version-check it (§6/T45). The transport itself\n// is unchanged here — this only wires the discovery + handshake fields so the check\n// exists when app-pinned versions become real.\nimport { sendMessage, addListener } from './sandboxUtils';\n\n/** The wire protocol (postMessage envelope / channels / methods) THIS SDK speaks.\n * Additive-only (§9); bump only for a backwards-compatible extension. */\nexport const SDK_PROTOCOL_VERSION = '1.0.0';\n\n/** This SDK's package version. Kept in step with package.json (a build step can\n * inject it later; a constant is fine while versions are still effectively fixed). */\nexport const SDK_VERSION = '0.2.7';\n\n/** The sandbox runtime's pre-evaluation discovery global (§4). */\nexport interface ImmediatelyRunGlobal {\n /** Sandbox-runtime protocol version (semver). */\n runtimeVersion?: string;\n /** postMessage envelope/protocol version. */\n protocolVersion?: string;\n /** The host channel the SDK talks over (MessagePort | message bus). */\n transport?: unknown;\n /** Resolves when ports arrive, if they arrive async after register-frame. */\n ready?: Promise<void>;\n}\n\n/**\n * Read the sandbox runtime's discovery global (§4), or null when absent — in which\n * case the SDK uses the current INJECTED path (`module.evaluation.*`). Lets the SDK\n * detect a host too old/new and fail closed (§6) once the global ships.\n */\nexport function getHostRuntime(): ImmediatelyRunGlobal | null {\n try {\n return (globalThis as { __immediatelyRun__?: ImmediatelyRunGlobal }).__immediatelyRun__ ?? null;\n } catch {\n return null;\n }\n}\n\n/** This SDK's handshake payload — the version + protocol the host records + checks\n * against `HOST_PROTOCOL_VERSION` (§6/T45). */\nexport interface SdkHandshake {\n sdkVersion: string;\n protocolVersion: string;\n}\nexport const sdkHandshake = (): SdkHandshake => ({\n sdkVersion: SDK_VERSION,\n protocolVersion: SDK_PROTOCOL_VERSION,\n});\n\n/**\n * Announce this SDK's version to the host (§6). Sends `sdk-handshake` eagerly\n * (best-effort — the host may already be listening) AND replies to a host\n * `request-handshake` (the robust path, mirroring the other `request-*` pulls).\n * Idempotent; safe to call more than once. Returns an unsubscribe fn.\n */\nexport function announceHandshake(): () => void {\n const send = () => {\n try {\n sendMessage('sdk-handshake', sdkHandshake() as unknown as Record<string, unknown>);\n } catch {\n /* transport not ready yet — the request-handshake reply covers it */\n }\n };\n send();\n return addListener('request-handshake', send);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAcA,0BAAyC;AAIlC,MAAM,uBAAuB;AAI7B,MAAM,cAAc;AAmBpB,SAAS,iBAA8C;AAC5D,MAAI;AACF,WAAQ,WAA6D,sBAAsB;AAAA,EAC7F,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAQO,MAAM,eAAe,OAAqB;AAAA,EAC/C,YAAY;AAAA,EACZ,iBAAiB;AACnB;AAQO,SAAS,oBAAgC;AAC9C,QAAM,OAAO,MAAM;AACjB,QAAI;AACF,2CAAY,iBAAiB,aAAa,CAAuC;AAAA,IACnF,QAAQ;AAAA,IAER;AAAA,EACF;AACA,OAAK;AACL,aAAO,iCAAY,qBAAqB,IAAI;AAC9C;","names":[]}
@@ -0,0 +1,39 @@
1
+ /** The wire protocol (postMessage envelope / channels / methods) THIS SDK speaks.
2
+ * Additive-only (§9); bump only for a backwards-compatible extension. */
3
+ declare const SDK_PROTOCOL_VERSION = "1.0.0";
4
+ /** This SDK's package version. Kept in step with package.json (a build step can
5
+ * inject it later; a constant is fine while versions are still effectively fixed). */
6
+ declare const SDK_VERSION = "0.2.7";
7
+ /** The sandbox runtime's pre-evaluation discovery global (§4). */
8
+ interface ImmediatelyRunGlobal {
9
+ /** Sandbox-runtime protocol version (semver). */
10
+ runtimeVersion?: string;
11
+ /** postMessage envelope/protocol version. */
12
+ protocolVersion?: string;
13
+ /** The host channel the SDK talks over (MessagePort | message bus). */
14
+ transport?: unknown;
15
+ /** Resolves when ports arrive, if they arrive async after register-frame. */
16
+ ready?: Promise<void>;
17
+ }
18
+ /**
19
+ * Read the sandbox runtime's discovery global (§4), or null when absent — in which
20
+ * case the SDK uses the current INJECTED path (`module.evaluation.*`). Lets the SDK
21
+ * detect a host too old/new and fail closed (§6) once the global ships.
22
+ */
23
+ declare function getHostRuntime(): ImmediatelyRunGlobal | null;
24
+ /** This SDK's handshake payload — the version + protocol the host records + checks
25
+ * against `HOST_PROTOCOL_VERSION` (§6/T45). */
26
+ interface SdkHandshake {
27
+ sdkVersion: string;
28
+ protocolVersion: string;
29
+ }
30
+ declare const sdkHandshake: () => SdkHandshake;
31
+ /**
32
+ * Announce this SDK's version to the host (§6). Sends `sdk-handshake` eagerly
33
+ * (best-effort — the host may already be listening) AND replies to a host
34
+ * `request-handshake` (the robust path, mirroring the other `request-*` pulls).
35
+ * Idempotent; safe to call more than once. Returns an unsubscribe fn.
36
+ */
37
+ declare function announceHandshake(): () => void;
38
+
39
+ export { type ImmediatelyRunGlobal, SDK_PROTOCOL_VERSION, SDK_VERSION, type SdkHandshake, announceHandshake, getHostRuntime, sdkHandshake };
@@ -0,0 +1,39 @@
1
+ /** The wire protocol (postMessage envelope / channels / methods) THIS SDK speaks.
2
+ * Additive-only (§9); bump only for a backwards-compatible extension. */
3
+ declare const SDK_PROTOCOL_VERSION = "1.0.0";
4
+ /** This SDK's package version. Kept in step with package.json (a build step can
5
+ * inject it later; a constant is fine while versions are still effectively fixed). */
6
+ declare const SDK_VERSION = "0.2.7";
7
+ /** The sandbox runtime's pre-evaluation discovery global (§4). */
8
+ interface ImmediatelyRunGlobal {
9
+ /** Sandbox-runtime protocol version (semver). */
10
+ runtimeVersion?: string;
11
+ /** postMessage envelope/protocol version. */
12
+ protocolVersion?: string;
13
+ /** The host channel the SDK talks over (MessagePort | message bus). */
14
+ transport?: unknown;
15
+ /** Resolves when ports arrive, if they arrive async after register-frame. */
16
+ ready?: Promise<void>;
17
+ }
18
+ /**
19
+ * Read the sandbox runtime's discovery global (§4), or null when absent — in which
20
+ * case the SDK uses the current INJECTED path (`module.evaluation.*`). Lets the SDK
21
+ * detect a host too old/new and fail closed (§6) once the global ships.
22
+ */
23
+ declare function getHostRuntime(): ImmediatelyRunGlobal | null;
24
+ /** This SDK's handshake payload — the version + protocol the host records + checks
25
+ * against `HOST_PROTOCOL_VERSION` (§6/T45). */
26
+ interface SdkHandshake {
27
+ sdkVersion: string;
28
+ protocolVersion: string;
29
+ }
30
+ declare const sdkHandshake: () => SdkHandshake;
31
+ /**
32
+ * Announce this SDK's version to the host (§6). Sends `sdk-handshake` eagerly
33
+ * (best-effort — the host may already be listening) AND replies to a host
34
+ * `request-handshake` (the robust path, mirroring the other `request-*` pulls).
35
+ * Idempotent; safe to call more than once. Returns an unsubscribe fn.
36
+ */
37
+ declare function announceHandshake(): () => void;
38
+
39
+ export { type ImmediatelyRunGlobal, SDK_PROTOCOL_VERSION, SDK_VERSION, type SdkHandshake, announceHandshake, getHostRuntime, sdkHandshake };
@@ -0,0 +1,32 @@
1
+ import { sendMessage, addListener } from "./sandboxUtils";
2
+ const SDK_PROTOCOL_VERSION = "1.0.0";
3
+ const SDK_VERSION = "0.2.7";
4
+ function getHostRuntime() {
5
+ try {
6
+ return globalThis.__immediatelyRun__ ?? null;
7
+ } catch {
8
+ return null;
9
+ }
10
+ }
11
+ const sdkHandshake = () => ({
12
+ sdkVersion: SDK_VERSION,
13
+ protocolVersion: SDK_PROTOCOL_VERSION
14
+ });
15
+ function announceHandshake() {
16
+ const send = () => {
17
+ try {
18
+ sendMessage("sdk-handshake", sdkHandshake());
19
+ } catch {
20
+ }
21
+ };
22
+ send();
23
+ return addListener("request-handshake", send);
24
+ }
25
+ export {
26
+ SDK_PROTOCOL_VERSION,
27
+ SDK_VERSION,
28
+ announceHandshake,
29
+ getHostRuntime,
30
+ sdkHandshake
31
+ };
32
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/runtime.ts"],"sourcesContent":["// Runtime discovery + version handshake (SDK_PACKAGING_SPEC §4/§6).\n//\n// Today the SDK reaches the host through the INJECTED sandbox services\n// (`module.evaluation.module.bundler.*`, see sandboxUtils). The packaging migration\n// makes the SDK an app-pinnable npm dependency that finds the runtime through a\n// stable, versioned global the sandbox publishes BEFORE evaluating app code:\n//\n// globalThis.__immediatelyRun__ = { runtimeVersion, protocolVersion, transport }\n//\n// Phase 1 (behind a flag, injection still active): the SDK can READ that global\n// when present (else fall back to injection), and ANNOUNCE its own version +\n// protocol so the host can record + version-check it (§6/T45). The transport itself\n// is unchanged here — this only wires the discovery + handshake fields so the check\n// exists when app-pinned versions become real.\nimport { sendMessage, addListener } from './sandboxUtils';\n\n/** The wire protocol (postMessage envelope / channels / methods) THIS SDK speaks.\n * Additive-only (§9); bump only for a backwards-compatible extension. */\nexport const SDK_PROTOCOL_VERSION = '1.0.0';\n\n/** This SDK's package version. Kept in step with package.json (a build step can\n * inject it later; a constant is fine while versions are still effectively fixed). */\nexport const SDK_VERSION = '0.2.7';\n\n/** The sandbox runtime's pre-evaluation discovery global (§4). */\nexport interface ImmediatelyRunGlobal {\n /** Sandbox-runtime protocol version (semver). */\n runtimeVersion?: string;\n /** postMessage envelope/protocol version. */\n protocolVersion?: string;\n /** The host channel the SDK talks over (MessagePort | message bus). */\n transport?: unknown;\n /** Resolves when ports arrive, if they arrive async after register-frame. */\n ready?: Promise<void>;\n}\n\n/**\n * Read the sandbox runtime's discovery global (§4), or null when absent — in which\n * case the SDK uses the current INJECTED path (`module.evaluation.*`). Lets the SDK\n * detect a host too old/new and fail closed (§6) once the global ships.\n */\nexport function getHostRuntime(): ImmediatelyRunGlobal | null {\n try {\n return (globalThis as { __immediatelyRun__?: ImmediatelyRunGlobal }).__immediatelyRun__ ?? null;\n } catch {\n return null;\n }\n}\n\n/** This SDK's handshake payload — the version + protocol the host records + checks\n * against `HOST_PROTOCOL_VERSION` (§6/T45). */\nexport interface SdkHandshake {\n sdkVersion: string;\n protocolVersion: string;\n}\nexport const sdkHandshake = (): SdkHandshake => ({\n sdkVersion: SDK_VERSION,\n protocolVersion: SDK_PROTOCOL_VERSION,\n});\n\n/**\n * Announce this SDK's version to the host (§6). Sends `sdk-handshake` eagerly\n * (best-effort — the host may already be listening) AND replies to a host\n * `request-handshake` (the robust path, mirroring the other `request-*` pulls).\n * Idempotent; safe to call more than once. Returns an unsubscribe fn.\n */\nexport function announceHandshake(): () => void {\n const send = () => {\n try {\n sendMessage('sdk-handshake', sdkHandshake() as unknown as Record<string, unknown>);\n } catch {\n /* transport not ready yet — the request-handshake reply covers it */\n }\n };\n send();\n return addListener('request-handshake', send);\n}\n"],"mappings":"AAcA,SAAS,aAAa,mBAAmB;AAIlC,MAAM,uBAAuB;AAI7B,MAAM,cAAc;AAmBpB,SAAS,iBAA8C;AAC5D,MAAI;AACF,WAAQ,WAA6D,sBAAsB;AAAA,EAC7F,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAQO,MAAM,eAAe,OAAqB;AAAA,EAC/C,YAAY;AAAA,EACZ,iBAAiB;AACnB;AAQO,SAAS,oBAAgC;AAC9C,QAAM,OAAO,MAAM;AACjB,QAAI;AACF,kBAAY,iBAAiB,aAAa,CAAuC;AAAA,IACnF,QAAQ;AAAA,IAER;AAAA,EACF;AACA,OAAK;AACL,SAAO,YAAY,qBAAqB,IAAI;AAC9C;","names":[]}
@@ -23,14 +23,24 @@ __export(sandboxUtils_exports, {
23
23
  sendMessage: () => sendMessage
24
24
  });
25
25
  module.exports = __toCommonJS(sandboxUtils_exports);
26
+ var import_runtime = require("./runtime");
27
+ function transport() {
28
+ try {
29
+ const injected = module?.evaluation?.module?.bundler?.messageBus;
30
+ if (injected && typeof injected.sendMessage === "function") return injected;
31
+ } catch {
32
+ }
33
+ const t = (0, import_runtime.getHostRuntime)()?.transport;
34
+ if (t && typeof t.sendMessage === "function") return t;
35
+ throw new Error("immediately.run: no host transport (neither injected nor __immediatelyRun__)");
36
+ }
26
37
  const sendMessage = (type, data = {}) => {
27
- module.evaluation.module.bundler.messageBus.sendMessage(type, data);
28
- };
29
- const protocolRequest = (protocolName, method, params) => {
30
- return module.evaluation.module.bundler.messageBus.protocolRequest(protocolName, method, params);
38
+ transport().sendMessage(type, data);
31
39
  };
40
+ const protocolRequest = (protocolName, method, params) => transport().protocolRequest(protocolName, method, params);
32
41
  const addListener = (msgType, handler, event) => {
33
- const disposable = (event ?? module.evaluation.module.bundler.messageBus.onMessage)((msg) => {
42
+ const onMessage = event ?? transport().onMessage;
43
+ const disposable = onMessage((msg) => {
34
44
  if (msg.type === msgType) {
35
45
  handler(msg);
36
46
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/sandboxUtils.ts"],"sourcesContent":["export const sendMessage = (type: string, data: Record<string, any> = {}) => {\n // module.evaluation is defined in the sandbox environment\n // @ts-ignore\n module.evaluation.module.bundler.messageBus.sendMessage(type, data);\n}\n\nexport const protocolRequest = (protocolName: string, method: string, params: Array<any>): Promise<any> => {\n // example usage: const response = await protocolRequest('fs', 'readFile', [path]);\n // module.evaluation is defined in the sandbox environment\n // @ts-ignore\n return module.evaluation.module.bundler.messageBus.protocolRequest(protocolName, method, params);\n}\n\nexport const addListener = (msgType: string, handler: (msg:any)=>void, event?:any):(() => void) => {\n // @ts-ignore\n const disposable = (event ?? module.evaluation.module.bundler.messageBus.onMessage)((msg) => {\n if (msg.type === msgType) {\n handler(msg);\n }\n });\n return () => disposable.dispose();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,cAAc,CAAC,MAAc,OAA4B,CAAC,MAAM;AAG3E,SAAO,WAAW,OAAO,QAAQ,WAAW,YAAY,MAAM,IAAI;AACpE;AAEO,MAAM,kBAAkB,CAAC,cAAsB,QAAgB,WAAqC;AAIzG,SAAO,OAAO,WAAW,OAAO,QAAQ,WAAW,gBAAgB,cAAc,QAAQ,MAAM;AACjG;AAEO,MAAM,cAAc,CAAC,SAAiB,SAA0B,UAA4B;AAEjG,QAAM,cAAc,SAAS,OAAO,WAAW,OAAO,QAAQ,WAAW,WAAW,CAAC,QAAQ;AAC3F,QAAI,IAAI,SAAS,SAAS;AACxB,cAAQ,GAAG;AAAA,IACb;AAAA,EACF,CAAC;AACD,SAAO,MAAM,WAAW,QAAQ;AAClC;","names":[]}
1
+ {"version":3,"sources":["../src/sandboxUtils.ts"],"sourcesContent":["// Host transport access (SDK_PACKAGING_SPEC §4, expose-transport). All host comms\n// (sendMessage / protocolRequest / onMessage) go through ONE resolver so the SDK is\n// transport-agnostic: it works whether it was INJECTED into the bundler's evaluation\n// context (the current path — `module.evaluation.module.bundler.messageBus`) OR\n// fetched from npm as an ordinary dependency, in which case the sandbox runtime hands\n// it the transport via the §4 discovery global (`globalThis.__immediatelyRun__`).\n//\n// Dual-mode (§8): injection wins while it's active, so existing behaviour is\n// byte-for-byte preserved; the global is the fallback the npm-fetched SDK uses. When\n// injection is removed (phase 3), only the global path remains — `bundler.*` stops\n// being API, which is the whole point.\nimport { getHostRuntime } from './runtime';\n\ninterface HostTransport {\n sendMessage(type: string, data?: Record<string, any>): void;\n protocolRequest(protocolName: string, method: string, params: Array<any>): Promise<any>;\n onMessage(handler: (msg: any) => void): { dispose(): void };\n}\n\nfunction transport(): HostTransport {\n // Injected bundler messageBus first the current path, unchanged.\n try {\n // @ts-ignore - `module.evaluation` is injected by the sandbox runtime\n const injected = module?.evaluation?.module?.bundler?.messageBus;\n if (injected && typeof injected.sendMessage === 'function') return injected;\n } catch {\n /* no injection in this realm — fall through to the §4 global */\n }\n // §4 runtime-discovery transport (the npm-fetched SDK path).\n const t = getHostRuntime()?.transport as HostTransport | undefined;\n if (t && typeof t.sendMessage === 'function') return t;\n throw new Error('immediately.run: no host transport (neither injected nor __immediatelyRun__)');\n}\n\nexport const sendMessage = (type: string, data: Record<string, any> = {}) => {\n transport().sendMessage(type, data);\n};\n\nexport const protocolRequest = (\n protocolName: string,\n method: string,\n params: Array<any>,\n): Promise<any> => transport().protocolRequest(protocolName, method, params);\n\nexport const addListener = (\n msgType: string,\n handler: (msg: any) => void,\n event?: any,\n): (() => void) => {\n const onMessage = event ?? transport().onMessage;\n const disposable = onMessage((msg: any) => {\n if (msg.type === msgType) {\n handler(msg);\n }\n });\n return () => disposable.dispose();\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,qBAA+B;AAQ/B,SAAS,YAA2B;AAElC,MAAI;AAEF,UAAM,WAAW,QAAQ,YAAY,QAAQ,SAAS;AACtD,QAAI,YAAY,OAAO,SAAS,gBAAgB,WAAY,QAAO;AAAA,EACrE,QAAQ;AAAA,EAER;AAEA,QAAM,QAAI,+BAAe,GAAG;AAC5B,MAAI,KAAK,OAAO,EAAE,gBAAgB,WAAY,QAAO;AACrD,QAAM,IAAI,MAAM,8EAA8E;AAChG;AAEO,MAAM,cAAc,CAAC,MAAc,OAA4B,CAAC,MAAM;AAC3E,YAAU,EAAE,YAAY,MAAM,IAAI;AACpC;AAEO,MAAM,kBAAkB,CAC7B,cACA,QACA,WACiB,UAAU,EAAE,gBAAgB,cAAc,QAAQ,MAAM;AAEpE,MAAM,cAAc,CACzB,SACA,SACA,UACiB;AACjB,QAAM,YAAY,SAAS,UAAU,EAAE;AACvC,QAAM,aAAa,UAAU,CAAC,QAAa;AACzC,QAAI,IAAI,SAAS,SAAS;AACxB,cAAQ,GAAG;AAAA,IACb;AAAA,EACF,CAAC;AACD,SAAO,MAAM,WAAW,QAAQ;AAClC;","names":[]}
@@ -1,11 +1,21 @@
1
+ import { getHostRuntime } from "./runtime";
2
+ function transport() {
3
+ try {
4
+ const injected = module?.evaluation?.module?.bundler?.messageBus;
5
+ if (injected && typeof injected.sendMessage === "function") return injected;
6
+ } catch {
7
+ }
8
+ const t = getHostRuntime()?.transport;
9
+ if (t && typeof t.sendMessage === "function") return t;
10
+ throw new Error("immediately.run: no host transport (neither injected nor __immediatelyRun__)");
11
+ }
1
12
  const sendMessage = (type, data = {}) => {
2
- module.evaluation.module.bundler.messageBus.sendMessage(type, data);
3
- };
4
- const protocolRequest = (protocolName, method, params) => {
5
- return module.evaluation.module.bundler.messageBus.protocolRequest(protocolName, method, params);
13
+ transport().sendMessage(type, data);
6
14
  };
15
+ const protocolRequest = (protocolName, method, params) => transport().protocolRequest(protocolName, method, params);
7
16
  const addListener = (msgType, handler, event) => {
8
- const disposable = (event ?? module.evaluation.module.bundler.messageBus.onMessage)((msg) => {
17
+ const onMessage = event ?? transport().onMessage;
18
+ const disposable = onMessage((msg) => {
9
19
  if (msg.type === msgType) {
10
20
  handler(msg);
11
21
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/sandboxUtils.ts"],"sourcesContent":["export const sendMessage = (type: string, data: Record<string, any> = {}) => {\n // module.evaluation is defined in the sandbox environment\n // @ts-ignore\n module.evaluation.module.bundler.messageBus.sendMessage(type, data);\n}\n\nexport const protocolRequest = (protocolName: string, method: string, params: Array<any>): Promise<any> => {\n // example usage: const response = await protocolRequest('fs', 'readFile', [path]);\n // module.evaluation is defined in the sandbox environment\n // @ts-ignore\n return module.evaluation.module.bundler.messageBus.protocolRequest(protocolName, method, params);\n}\n\nexport const addListener = (msgType: string, handler: (msg:any)=>void, event?:any):(() => void) => {\n // @ts-ignore\n const disposable = (event ?? module.evaluation.module.bundler.messageBus.onMessage)((msg) => {\n if (msg.type === msgType) {\n handler(msg);\n }\n });\n return () => disposable.dispose();\n}\n"],"mappings":"AAAO,MAAM,cAAc,CAAC,MAAc,OAA4B,CAAC,MAAM;AAG3E,SAAO,WAAW,OAAO,QAAQ,WAAW,YAAY,MAAM,IAAI;AACpE;AAEO,MAAM,kBAAkB,CAAC,cAAsB,QAAgB,WAAqC;AAIzG,SAAO,OAAO,WAAW,OAAO,QAAQ,WAAW,gBAAgB,cAAc,QAAQ,MAAM;AACjG;AAEO,MAAM,cAAc,CAAC,SAAiB,SAA0B,UAA4B;AAEjG,QAAM,cAAc,SAAS,OAAO,WAAW,OAAO,QAAQ,WAAW,WAAW,CAAC,QAAQ;AAC3F,QAAI,IAAI,SAAS,SAAS;AACxB,cAAQ,GAAG;AAAA,IACb;AAAA,EACF,CAAC;AACD,SAAO,MAAM,WAAW,QAAQ;AAClC;","names":[]}
1
+ {"version":3,"sources":["../src/sandboxUtils.ts"],"sourcesContent":["// Host transport access (SDK_PACKAGING_SPEC §4, expose-transport). All host comms\n// (sendMessage / protocolRequest / onMessage) go through ONE resolver so the SDK is\n// transport-agnostic: it works whether it was INJECTED into the bundler's evaluation\n// context (the current path — `module.evaluation.module.bundler.messageBus`) OR\n// fetched from npm as an ordinary dependency, in which case the sandbox runtime hands\n// it the transport via the §4 discovery global (`globalThis.__immediatelyRun__`).\n//\n// Dual-mode (§8): injection wins while it's active, so existing behaviour is\n// byte-for-byte preserved; the global is the fallback the npm-fetched SDK uses. When\n// injection is removed (phase 3), only the global path remains — `bundler.*` stops\n// being API, which is the whole point.\nimport { getHostRuntime } from './runtime';\n\ninterface HostTransport {\n sendMessage(type: string, data?: Record<string, any>): void;\n protocolRequest(protocolName: string, method: string, params: Array<any>): Promise<any>;\n onMessage(handler: (msg: any) => void): { dispose(): void };\n}\n\nfunction transport(): HostTransport {\n // Injected bundler messageBus first the current path, unchanged.\n try {\n // @ts-ignore - `module.evaluation` is injected by the sandbox runtime\n const injected = module?.evaluation?.module?.bundler?.messageBus;\n if (injected && typeof injected.sendMessage === 'function') return injected;\n } catch {\n /* no injection in this realm — fall through to the §4 global */\n }\n // §4 runtime-discovery transport (the npm-fetched SDK path).\n const t = getHostRuntime()?.transport as HostTransport | undefined;\n if (t && typeof t.sendMessage === 'function') return t;\n throw new Error('immediately.run: no host transport (neither injected nor __immediatelyRun__)');\n}\n\nexport const sendMessage = (type: string, data: Record<string, any> = {}) => {\n transport().sendMessage(type, data);\n};\n\nexport const protocolRequest = (\n protocolName: string,\n method: string,\n params: Array<any>,\n): Promise<any> => transport().protocolRequest(protocolName, method, params);\n\nexport const addListener = (\n msgType: string,\n handler: (msg: any) => void,\n event?: any,\n): (() => void) => {\n const onMessage = event ?? transport().onMessage;\n const disposable = onMessage((msg: any) => {\n if (msg.type === msgType) {\n handler(msg);\n }\n });\n return () => disposable.dispose();\n};\n"],"mappings":"AAWA,SAAS,sBAAsB;AAQ/B,SAAS,YAA2B;AAElC,MAAI;AAEF,UAAM,WAAW,QAAQ,YAAY,QAAQ,SAAS;AACtD,QAAI,YAAY,OAAO,SAAS,gBAAgB,WAAY,QAAO;AAAA,EACrE,QAAQ;AAAA,EAER;AAEA,QAAM,IAAI,eAAe,GAAG;AAC5B,MAAI,KAAK,OAAO,EAAE,gBAAgB,WAAY,QAAO;AACrD,QAAM,IAAI,MAAM,8EAA8E;AAChG;AAEO,MAAM,cAAc,CAAC,MAAc,OAA4B,CAAC,MAAM;AAC3E,YAAU,EAAE,YAAY,MAAM,IAAI;AACpC;AAEO,MAAM,kBAAkB,CAC7B,cACA,QACA,WACiB,UAAU,EAAE,gBAAgB,cAAc,QAAQ,MAAM;AAEpE,MAAM,cAAc,CACzB,SACA,SACA,UACiB;AACjB,QAAM,YAAY,SAAS,UAAU,EAAE;AACvC,QAAM,aAAa,UAAU,CAAC,QAAa;AACzC,QAAI,IAAI,SAAS,SAAS;AACxB,cAAQ,GAAG;AAAA,IACb;AAAA,EACF,CAAC;AACD,SAAO,MAAM,WAAW,QAAQ;AAClC;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@immediately-run/sdk",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Runtime SDK for code executing inside an immediately.run sandbox.",
5
5
  "license": "MIT",
6
6
  "repository": "github:immediately-run/immediately-run-sdk",