@immediately-run/sdk 0.2.6 → 0.2.8

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.
@@ -0,0 +1,35 @@
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 hostRuntime_exports = {};
20
+ __export(hostRuntime_exports, {
21
+ getHostRuntime: () => getHostRuntime
22
+ });
23
+ module.exports = __toCommonJS(hostRuntime_exports);
24
+ function getHostRuntime() {
25
+ try {
26
+ return globalThis.__immediatelyRun__ ?? null;
27
+ } catch {
28
+ return null;
29
+ }
30
+ }
31
+ // Annotate the CommonJS export names for ESM import in node:
32
+ 0 && (module.exports = {
33
+ getHostRuntime
34
+ });
35
+ //# sourceMappingURL=hostRuntime.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hostRuntime.ts"],"sourcesContent":["// Runtime-discovery global (SDK_PACKAGING_SPEC §4) — a LEAF module that imports\n// nothing, so it can be read by both `sandboxUtils` (transport resolver) and\n// `runtime` (handshake) without forming an import cycle. `sandboxUtils → runtime`\n// + `runtime → sandboxUtils` was a cycle the sandbox bundler cannot evaluate\n// (infinite re-require → \"Maximum call stack size exceeded\"); routing the shared\n// `getHostRuntime` through this leaf breaks it.\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"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBO,SAAS,iBAA8C;AAC5D,MAAI;AACF,WAAQ,WAA6D,sBAAsB;AAAA,EAC7F,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -0,0 +1,19 @@
1
+ /** The sandbox runtime's pre-evaluation discovery global (§4). */
2
+ interface ImmediatelyRunGlobal {
3
+ /** Sandbox-runtime protocol version (semver). */
4
+ runtimeVersion?: string;
5
+ /** postMessage envelope/protocol version. */
6
+ protocolVersion?: string;
7
+ /** The host channel the SDK talks over (MessagePort | message bus). */
8
+ transport?: unknown;
9
+ /** Resolves when ports arrive, if they arrive async after register-frame. */
10
+ ready?: Promise<void>;
11
+ }
12
+ /**
13
+ * Read the sandbox runtime's discovery global (§4), or null when absent — in which
14
+ * case the SDK uses the current INJECTED path (`module.evaluation.*`). Lets the SDK
15
+ * detect a host too old/new and fail closed (§6) once the global ships.
16
+ */
17
+ declare function getHostRuntime(): ImmediatelyRunGlobal | null;
18
+
19
+ export { type ImmediatelyRunGlobal, getHostRuntime };
@@ -0,0 +1,19 @@
1
+ /** The sandbox runtime's pre-evaluation discovery global (§4). */
2
+ interface ImmediatelyRunGlobal {
3
+ /** Sandbox-runtime protocol version (semver). */
4
+ runtimeVersion?: string;
5
+ /** postMessage envelope/protocol version. */
6
+ protocolVersion?: string;
7
+ /** The host channel the SDK talks over (MessagePort | message bus). */
8
+ transport?: unknown;
9
+ /** Resolves when ports arrive, if they arrive async after register-frame. */
10
+ ready?: Promise<void>;
11
+ }
12
+ /**
13
+ * Read the sandbox runtime's discovery global (§4), or null when absent — in which
14
+ * case the SDK uses the current INJECTED path (`module.evaluation.*`). Lets the SDK
15
+ * detect a host too old/new and fail closed (§6) once the global ships.
16
+ */
17
+ declare function getHostRuntime(): ImmediatelyRunGlobal | null;
18
+
19
+ export { type ImmediatelyRunGlobal, getHostRuntime };
@@ -0,0 +1,11 @@
1
+ function getHostRuntime() {
2
+ try {
3
+ return globalThis.__immediatelyRun__ ?? null;
4
+ } catch {
5
+ return null;
6
+ }
7
+ }
8
+ export {
9
+ getHostRuntime
10
+ };
11
+ //# sourceMappingURL=hostRuntime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hostRuntime.ts"],"sourcesContent":["// Runtime-discovery global (SDK_PACKAGING_SPEC §4) — a LEAF module that imports\n// nothing, so it can be read by both `sandboxUtils` (transport resolver) and\n// `runtime` (handshake) without forming an import cycle. `sandboxUtils → runtime`\n// + `runtime → sandboxUtils` was a cycle the sandbox bundler cannot evaluate\n// (infinite re-require → \"Maximum call stack size exceeded\"); routing the shared\n// `getHostRuntime` through this leaf breaks it.\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"],"mappings":"AAwBO,SAAS,iBAA8C;AAC5D,MAAI;AACF,WAAQ,WAA6D,sBAAsB;AAAA,EAC7F,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
package/dist/index.d.cts CHANGED
@@ -13,9 +13,10 @@ 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
+ export { SDK_PROTOCOL_VERSION, SDK_VERSION, SdkHandshake, announceHandshake, sdkHandshake } from './runtime.cjs';
17
17
  export { StreamError, StreamFrame, StreamTransport, consumeStream, protocolStream } from './protocolStream.cjs';
18
18
  export { EvaluationContext, FileQueryResult, FilesMetadata, Metadata, MetadataQueryFunction, MetadataQueryResult, ModuleExports } from './sandboxTypes.cjs';
19
+ export { ImmediatelyRunGlobal, getHostRuntime } from './hostRuntime.cjs';
19
20
  import 'react';
20
21
  import './TinkerableContext.cjs';
21
22
  import './RoutingSpec.cjs';
package/dist/index.d.ts CHANGED
@@ -13,9 +13,10 @@ 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
+ export { SDK_PROTOCOL_VERSION, SDK_VERSION, SdkHandshake, announceHandshake, sdkHandshake } from './runtime.js';
17
17
  export { StreamError, StreamFrame, StreamTransport, consumeStream, protocolStream } from './protocolStream.js';
18
18
  export { EvaluationContext, FileQueryResult, FilesMetadata, Metadata, MetadataQueryFunction, MetadataQueryResult, ModuleExports } from './sandboxTypes.js';
19
+ export { ImmediatelyRunGlobal, getHostRuntime } from './hostRuntime.js';
19
20
  import 'react';
20
21
  import './TinkerableContext.js';
21
22
  import './RoutingSpec.js';
package/dist/runtime.cjs CHANGED
@@ -21,20 +21,14 @@ __export(runtime_exports, {
21
21
  SDK_PROTOCOL_VERSION: () => SDK_PROTOCOL_VERSION,
22
22
  SDK_VERSION: () => SDK_VERSION,
23
23
  announceHandshake: () => announceHandshake,
24
- getHostRuntime: () => getHostRuntime,
24
+ getHostRuntime: () => import_hostRuntime.getHostRuntime,
25
25
  sdkHandshake: () => sdkHandshake
26
26
  });
27
27
  module.exports = __toCommonJS(runtime_exports);
28
28
  var import_sandboxUtils = require("./sandboxUtils");
29
+ var import_hostRuntime = require("./hostRuntime");
29
30
  const SDK_PROTOCOL_VERSION = "1.0.0";
30
- const SDK_VERSION = "0.2.6";
31
- function getHostRuntime() {
32
- try {
33
- return globalThis.__immediatelyRun__ ?? null;
34
- } catch {
35
- return null;
36
- }
37
- }
31
+ const SDK_VERSION = "0.2.8";
38
32
  const sdkHandshake = () => ({
39
33
  sdkVersion: SDK_VERSION,
40
34
  protocolVersion: SDK_PROTOCOL_VERSION
@@ -1 +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.6';\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":[]}
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// `getHostRuntime` + `ImmediatelyRunGlobal` live in the leaf `hostRuntime` module\n// (imports nothing) and are re-exported here for a stable public API. This breaks\n// the sandboxUtils↔runtime import cycle: sandboxUtils reads `getHostRuntime` from\n// the leaf, while runtime still imports sandboxUtils for the handshake — one\n// direction only, no cycle.\nexport { getHostRuntime } from './hostRuntime';\nexport type { ImmediatelyRunGlobal } from './hostRuntime';\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.8';\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;AAOzC,yBAA+B;AAKxB,MAAM,uBAAuB;AAI7B,MAAM,cAAc;AAQpB,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":[]}
@@ -1,26 +1,11 @@
1
+ export { ImmediatelyRunGlobal, getHostRuntime } from './hostRuntime.cjs';
2
+
1
3
  /** The wire protocol (postMessage envelope / channels / methods) THIS SDK speaks.
2
4
  * Additive-only (§9); bump only for a backwards-compatible extension. */
3
5
  declare const SDK_PROTOCOL_VERSION = "1.0.0";
4
6
  /** This SDK's package version. Kept in step with package.json (a build step can
5
7
  * inject it later; a constant is fine while versions are still effectively fixed). */
6
- declare const SDK_VERSION = "0.2.6";
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;
8
+ declare const SDK_VERSION = "0.2.8";
24
9
  /** This SDK's handshake payload — the version + protocol the host records + checks
25
10
  * against `HOST_PROTOCOL_VERSION` (§6/T45). */
26
11
  interface SdkHandshake {
@@ -36,4 +21,4 @@ declare const sdkHandshake: () => SdkHandshake;
36
21
  */
37
22
  declare function announceHandshake(): () => void;
38
23
 
39
- export { type ImmediatelyRunGlobal, SDK_PROTOCOL_VERSION, SDK_VERSION, type SdkHandshake, announceHandshake, getHostRuntime, sdkHandshake };
24
+ export { SDK_PROTOCOL_VERSION, SDK_VERSION, type SdkHandshake, announceHandshake, sdkHandshake };
package/dist/runtime.d.ts CHANGED
@@ -1,26 +1,11 @@
1
+ export { ImmediatelyRunGlobal, getHostRuntime } from './hostRuntime.js';
2
+
1
3
  /** The wire protocol (postMessage envelope / channels / methods) THIS SDK speaks.
2
4
  * Additive-only (§9); bump only for a backwards-compatible extension. */
3
5
  declare const SDK_PROTOCOL_VERSION = "1.0.0";
4
6
  /** This SDK's package version. Kept in step with package.json (a build step can
5
7
  * inject it later; a constant is fine while versions are still effectively fixed). */
6
- declare const SDK_VERSION = "0.2.6";
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;
8
+ declare const SDK_VERSION = "0.2.8";
24
9
  /** This SDK's handshake payload — the version + protocol the host records + checks
25
10
  * against `HOST_PROTOCOL_VERSION` (§6/T45). */
26
11
  interface SdkHandshake {
@@ -36,4 +21,4 @@ declare const sdkHandshake: () => SdkHandshake;
36
21
  */
37
22
  declare function announceHandshake(): () => void;
38
23
 
39
- export { type ImmediatelyRunGlobal, SDK_PROTOCOL_VERSION, SDK_VERSION, type SdkHandshake, announceHandshake, getHostRuntime, sdkHandshake };
24
+ export { SDK_PROTOCOL_VERSION, SDK_VERSION, type SdkHandshake, announceHandshake, sdkHandshake };
package/dist/runtime.js CHANGED
@@ -1,13 +1,7 @@
1
1
  import { sendMessage, addListener } from "./sandboxUtils";
2
+ import { getHostRuntime } from "./hostRuntime";
2
3
  const SDK_PROTOCOL_VERSION = "1.0.0";
3
- const SDK_VERSION = "0.2.6";
4
- function getHostRuntime() {
5
- try {
6
- return globalThis.__immediatelyRun__ ?? null;
7
- } catch {
8
- return null;
9
- }
10
- }
4
+ const SDK_VERSION = "0.2.8";
11
5
  const sdkHandshake = () => ({
12
6
  sdkVersion: SDK_VERSION,
13
7
  protocolVersion: SDK_PROTOCOL_VERSION
@@ -1 +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.6';\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":[]}
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// `getHostRuntime` + `ImmediatelyRunGlobal` live in the leaf `hostRuntime` module\n// (imports nothing) and are re-exported here for a stable public API. This breaks\n// the sandboxUtils↔runtime import cycle: sandboxUtils reads `getHostRuntime` from\n// the leaf, while runtime still imports sandboxUtils for the handshake — one\n// direction only, no cycle.\nexport { getHostRuntime } from './hostRuntime';\nexport type { ImmediatelyRunGlobal } from './hostRuntime';\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.8';\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;AAOzC,SAAS,sBAAsB;AAKxB,MAAM,uBAAuB;AAI7B,MAAM,cAAc;AAQpB,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_hostRuntime = require("./hostRuntime");
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_hostRuntime.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 './hostRuntime';\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,yBAA+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,mCAAe,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 "./hostRuntime";
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 './hostRuntime';\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.6",
3
+ "version": "0.2.8",
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",