File size: 1,174 Bytes
4c76b0d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { resolveStateDir } from "../../config/paths.js";
import { createRuntimeConfig } from "./runtime-config.js";
import { createRuntimeSystem } from "./runtime-system.js";
import type { PluginRuntime } from "./types.js";

function unavailable(method: string): () => never {
  return () => {
    throw new Error(`${method} is only available through the plugin runtime proxy.`);
  };
}

/** Host-owned facades survive later path-loaded runtime materialization unchanged. */
export function createRuntimeBase(): Pick<PluginRuntime, "config" | "state" | "system"> {
  let system: PluginRuntime["system"] | undefined;
  return {
    config: createRuntimeConfig(),
    // Only the registry proxy grants storage, never the base runtime directly.
    state: {
      resolveStateDir,
      openBlobStore: unavailable("openBlobStore"),
      openKeyedStore: unavailable("openKeyedStore"),
      openSyncKeyedStore: unavailable("openSyncKeyedStore"),
      openChannelIngressQueue: unavailable("openChannelIngressQueue"),
      openChannelIngressDrain: unavailable("openChannelIngressDrain"),
    },
    get system() {
      return (system ??= createRuntimeSystem());
    },
  };
}