@illuma-ai/code-sandbox 1.1.0 → 1.2.1

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.
@@ -13,8 +13,9 @@
13
13
  *
14
14
  * @see bolt.diy: app/components/workbench/Workbench.client.tsx (reference)
15
15
  */
16
+ import React from "react";
16
17
  import "allotment/dist/style.css";
17
- import type { CodeSandboxProps } from "../types";
18
+ import type { CodeSandboxProps, CodeSandboxHandle } from "../types";
18
19
  /**
19
20
  * CodeSandbox — The main entrypoint component.
20
21
  *
@@ -25,4 +26,4 @@ import type { CodeSandboxProps } from "../types";
25
26
  * A compact toolbar row contains the view toggle and (in preview mode)
26
27
  * a URL bar with refresh button.
27
28
  */
28
- export declare function CodeSandbox(props: CodeSandboxProps): import("react/jsx-runtime").JSX.Element;
29
+ export declare const CodeSandbox: React.ForwardRefExoticComponent<CodeSandboxProps & React.RefAttributes<CodeSandboxHandle>>;
@@ -4,9 +4,9 @@
4
4
  * Manages the Nodepod runtime instance and exposes reactive state
5
5
  * for all UI components (progress, files, terminal output, preview URL).
6
6
  *
7
- * Supports two file sources:
8
- * 1. Direct files (via `files` prop or `template` prop)
9
- * 2. GitHub repo (via `github` prop) — with branch polling for hot-reload
7
+ * The sandbox is a pure renderer — it receives files via props (initial
8
+ * load) and via the imperative handle (updateFiles/updateFile for live
9
+ * updates). It does NOT interact with any storage backend directly.
10
10
  *
11
11
  * Error exposure: wires the runtime's structured error system and the
12
12
  * preview iframe's browser error capture into a unified `errors[]` array
@@ -14,24 +14,26 @@
14
14
  * so the AI agent can auto-fix.
15
15
  */
16
16
  import { NodepodRuntime } from "../services/runtime";
17
- import type { CodeSandboxProps, FileMap, RuntimeState, SandboxError } from "../types";
17
+ import type { CodeSandboxProps, FileChangeStatus, FileMap, RuntimeState, SandboxError } from "../types";
18
18
  /**
19
19
  * Hook that manages the full Nodepod runtime lifecycle.
20
20
  *
21
+ * The sandbox is a pure renderer — it receives files via props or the
22
+ * imperative handle. No polling, no storage backends.
23
+ *
21
24
  * @param props - CodeSandbox component props
22
- * @returns Reactive runtime state + control functions
25
+ * @returns Reactive runtime state + control functions + imperative methods
23
26
  *
24
27
  * @example
25
28
  * ```tsx
26
- * // Direct files
27
- * const { state } = useRuntime({ files: myFiles, entryCommand: 'node server.js' });
28
- *
29
- * // GitHub repo with auto-polling
30
- * const { state } = useRuntime({
31
- * github: { owner: 'illuma-ai', repo: 'fullstack-starter', branch: 'main' },
32
- * gitToken: 'ghp_xxx',
33
- * onSandboxError: (err) => agent.fix(err),
34
- * });
29
+ * // Direct files (fetched from any source by the host app)
30
+ * const runtime = useRuntime({ files: myFiles, entryCommand: 'node server.js' });
31
+ *
32
+ * // Later, push updated files from the host:
33
+ * await runtime.updateFiles(newFiles);
34
+ *
35
+ * // Or update a single file:
36
+ * await runtime.updateFile('server.js', newContent);
35
37
  * ```
36
38
  */
37
39
  export declare function useRuntime(props: CodeSandboxProps): {
@@ -43,6 +45,14 @@ export declare function useRuntime(props: CodeSandboxProps): {
43
45
  handleCloseFile: (path: string) => void;
44
46
  handleBrowserError: (error: SandboxError) => Promise<void>;
45
47
  restart: () => Promise<void>;
48
+ updateFiles: (newFiles: FileMap, options?: {
49
+ restartServer?: boolean;
50
+ }) => Promise<void>;
51
+ updateFile: (path: string, content: string) => Promise<void>;
52
+ getFiles: () => FileMap;
46
53
  getChangedFiles: () => FileMap;
54
+ getFileChanges: () => Record<string, FileChangeStatus>;
55
+ getErrors: () => SandboxError[];
56
+ getState: () => RuntimeState;
47
57
  runtime: import("react").MutableRefObject<NodepodRuntime | null>;
48
58
  };