@aprovan/patchwork-compiler 0.1.0

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,752 @@
1
+ import { z } from 'zod';
2
+ import { Plugin } from 'esbuild-wasm';
3
+
4
+ interface VirtualFile {
5
+ path: string;
6
+ content: string;
7
+ language?: string;
8
+ note?: string;
9
+ }
10
+ interface VirtualProject {
11
+ id: string;
12
+ entry: string;
13
+ files: Map<string, VirtualFile>;
14
+ }
15
+ interface StorageBackend {
16
+ get(path: string): Promise<string | null>;
17
+ put(path: string, content: string): Promise<void>;
18
+ delete(path: string): Promise<void>;
19
+ list(prefix?: string): Promise<string[]>;
20
+ exists(path: string): Promise<boolean>;
21
+ }
22
+
23
+ /**
24
+ * Core types for the Patchwork compiler
25
+ */
26
+ type Platform = 'browser' | 'cli';
27
+ interface Manifest$1 {
28
+ name: string;
29
+ version: string;
30
+ description?: string;
31
+ platform: Platform;
32
+ image: string;
33
+ inputs?: Record<string, InputSpec>;
34
+ services?: string[];
35
+ packages?: Record<string, string>;
36
+ }
37
+ interface InputSpec {
38
+ type: 'string' | 'number' | 'boolean' | 'object' | 'array';
39
+ default?: unknown;
40
+ required?: boolean;
41
+ description?: string;
42
+ }
43
+ interface CompileOptions {
44
+ }
45
+ interface CompiledWidget {
46
+ /** Compiled ESM code */
47
+ code: string;
48
+ /** Content hash for caching */
49
+ hash: string;
50
+ /** Original manifest */
51
+ manifest: Manifest$1;
52
+ /** Source map (if generated) */
53
+ sourceMap?: string;
54
+ }
55
+ type MountMode = 'embedded' | 'iframe';
56
+ interface MountOptions {
57
+ /** Target DOM element to mount into */
58
+ target: HTMLElement;
59
+ /** Mount mode: embedded (trusted) or iframe (sandboxed) */
60
+ mode: MountMode;
61
+ /** CSP sandbox attributes for iframe mode */
62
+ sandbox?: string[];
63
+ /** Initial props/inputs to pass to widget */
64
+ inputs?: Record<string, unknown>;
65
+ }
66
+ interface MountedWidget {
67
+ /** Unique mount ID */
68
+ id: string;
69
+ /** The compiled widget */
70
+ widget: CompiledWidget;
71
+ /** Mount mode used */
72
+ mode: MountMode;
73
+ /** Target element */
74
+ target: HTMLElement;
75
+ /** Iframe element (if mode is 'iframe') */
76
+ iframe?: HTMLIFrameElement;
77
+ /** Inputs used for the mount (if provided) */
78
+ inputs?: Record<string, unknown>;
79
+ /** Sandbox attributes used for iframe mode (if provided) */
80
+ sandbox?: string[];
81
+ /** Unmount function */
82
+ unmount: () => void;
83
+ }
84
+ interface ImageConfig$1 {
85
+ platform: Platform;
86
+ esbuild?: {
87
+ target?: string;
88
+ format?: 'esm' | 'cjs' | 'iife';
89
+ jsx?: 'automatic' | 'transform' | 'preserve';
90
+ jsxFactory?: string;
91
+ jsxFragment?: string;
92
+ };
93
+ framework?: {
94
+ /** Map of package names to window global names (e.g., { react: 'React' }) */
95
+ globals?: Record<string, string>;
96
+ /** CDN URLs to preload before widget execution */
97
+ preload?: string[];
98
+ /** Dependency version overrides for CDN packages (e.g., { react: '18' }) */
99
+ deps?: Record<string, string>;
100
+ };
101
+ /** Import path aliases (e.g., { '@/components/ui/*': '@packagedcn/react' }) */
102
+ aliases?: Record<string, string>;
103
+ }
104
+ /**
105
+ * Mount function signature provided by images to handle widget mounting.
106
+ * Takes the widget module exports and mounts it to the container.
107
+ *
108
+ * @param module - The widget module with its exports (default, mount, render, game, etc.)
109
+ * @param container - The DOM element to mount into
110
+ * @param inputs - Props/inputs to pass to the widget
111
+ * @returns A cleanup function to unmount, or void
112
+ */
113
+ type ImageMountFn = (module: Record<string, unknown>, container: HTMLElement, inputs: Record<string, unknown>) => void | (() => void) | Promise<void | (() => void)>;
114
+ interface LoadedImage {
115
+ /** Package name */
116
+ name: string;
117
+ /** Resolved version */
118
+ version: string;
119
+ /** Browser-importable module URL for this image (when loaded from CDN/local HTTP) */
120
+ moduleUrl?: string;
121
+ /** Package configuration */
122
+ config: ImageConfig$1;
123
+ /** Package dependencies */
124
+ dependencies: Record<string, string>;
125
+ /** Setup function (if available) */
126
+ setup?: (root: HTMLElement) => void | Promise<void>;
127
+ /** CSS content (if available) */
128
+ css?: string;
129
+ /**
130
+ * Mount function to handle widget mounting.
131
+ * Each image defines how it expects widgets to export their entry points.
132
+ * Falls back to default mounting behavior if not provided.
133
+ */
134
+ mount?: ImageMountFn;
135
+ }
136
+ interface CompilerOptions {
137
+ /** Image package to use (e.g., '@aprovan/patchwork-image-shadcnshadcn') */
138
+ image: string;
139
+ /** Backend proxy URL for service calls */
140
+ proxyUrl: string;
141
+ /** Base URL for CDN (default: 'https://esm.sh'). Used for loading image packages. */
142
+ cdnBaseUrl?: string;
143
+ /** Base URL for widget imports (default: same as cdnBaseUrl). Used for transforming imports in widget code. */
144
+ widgetCdnBaseUrl?: string;
145
+ }
146
+ interface Compiler {
147
+ /** Pre-load an image package */
148
+ preloadImage(spec: string): Promise<void>;
149
+ /** Check if an image is loaded */
150
+ isImageLoaded(spec: string): boolean;
151
+ /** Compile widget source to ESM */
152
+ compile(source: string | VirtualProject, manifest: Manifest$1, options?: CompileOptions): Promise<CompiledWidget>;
153
+ /** Mount a compiled widget to the DOM */
154
+ mount(widget: CompiledWidget, options: MountOptions): Promise<MountedWidget>;
155
+ /** Unmount a mounted widget */
156
+ unmount(mounted: MountedWidget): void;
157
+ /** Hot reload a mounted widget */
158
+ reload(mounted: MountedWidget, source: string | VirtualProject, manifest: Manifest$1): Promise<void>;
159
+ }
160
+ /**
161
+ * Service proxy interface - abstracts service calls to backend
162
+ *
163
+ * The compiler provides the interface; actual implementation (e.g., UTCP, MCP)
164
+ * is handled by the runtime/backend.
165
+ */
166
+ interface ServiceProxy {
167
+ call(namespace: string, procedure: string, args: unknown[]): Promise<unknown>;
168
+ }
169
+ /**
170
+ * Service call handler - function that handles calls for a specific namespace
171
+ */
172
+ type ServiceCallHandler = (procedure: string, args: unknown[]) => Promise<unknown>;
173
+ /**
174
+ * Global interface definition for code generation
175
+ *
176
+ * Describes available global namespaces and their methods that widgets can call.
177
+ * Used during compilation to generate proper TypeScript declarations.
178
+ */
179
+ interface GlobalInterfaceDefinition {
180
+ /** Namespace name (e.g., 'git', 'github') */
181
+ name: string;
182
+ /** Methods available on this namespace (supports nested paths like 'repos.list') */
183
+ methods: string[];
184
+ /** Optional TypeScript type definitions for methods */
185
+ types?: string;
186
+ }
187
+ type BridgeMessageType = 'service-call' | 'service-result' | 'error';
188
+ interface BridgeMessage {
189
+ type: BridgeMessageType;
190
+ id: string;
191
+ payload: unknown;
192
+ }
193
+ interface ServiceCallPayload {
194
+ namespace: string;
195
+ procedure: string;
196
+ args: unknown[];
197
+ }
198
+ interface ServiceResultPayload {
199
+ result?: unknown;
200
+ error?: string;
201
+ }
202
+
203
+ /**
204
+ * Create a compiler instance
205
+ */
206
+ declare function createCompiler(options: CompilerOptions): Promise<Compiler>;
207
+
208
+ /**
209
+ * Zod schemas for Patchwork compiler types
210
+ *
211
+ * These schemas validate:
212
+ * - ImageConfig from package.json patchwork field
213
+ * - Widget manifests
214
+ * - Input specifications
215
+ */
216
+
217
+ declare const PlatformSchema: z.ZodEnum<["browser", "cli"]>;
218
+ declare const EsbuildConfigSchema: z.ZodOptional<z.ZodObject<{
219
+ target: z.ZodOptional<z.ZodString>;
220
+ format: z.ZodOptional<z.ZodEnum<["esm", "cjs", "iife"]>>;
221
+ jsx: z.ZodOptional<z.ZodEnum<["automatic", "transform", "preserve"]>>;
222
+ jsxFactory: z.ZodOptional<z.ZodString>;
223
+ jsxFragment: z.ZodOptional<z.ZodString>;
224
+ }, "strict", z.ZodTypeAny, {
225
+ jsx?: "automatic" | "transform" | "preserve" | undefined;
226
+ target?: string | undefined;
227
+ format?: "esm" | "cjs" | "iife" | undefined;
228
+ jsxFactory?: string | undefined;
229
+ jsxFragment?: string | undefined;
230
+ }, {
231
+ jsx?: "automatic" | "transform" | "preserve" | undefined;
232
+ target?: string | undefined;
233
+ format?: "esm" | "cjs" | "iife" | undefined;
234
+ jsxFactory?: string | undefined;
235
+ jsxFragment?: string | undefined;
236
+ }>>;
237
+ declare const ImageConfigSchema: z.ZodObject<{
238
+ platform: z.ZodEnum<["browser", "cli"]>;
239
+ dependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
240
+ esbuild: z.ZodOptional<z.ZodObject<{
241
+ target: z.ZodOptional<z.ZodString>;
242
+ format: z.ZodOptional<z.ZodEnum<["esm", "cjs", "iife"]>>;
243
+ jsx: z.ZodOptional<z.ZodEnum<["automatic", "transform", "preserve"]>>;
244
+ jsxFactory: z.ZodOptional<z.ZodString>;
245
+ jsxFragment: z.ZodOptional<z.ZodString>;
246
+ }, "strict", z.ZodTypeAny, {
247
+ jsx?: "automatic" | "transform" | "preserve" | undefined;
248
+ target?: string | undefined;
249
+ format?: "esm" | "cjs" | "iife" | undefined;
250
+ jsxFactory?: string | undefined;
251
+ jsxFragment?: string | undefined;
252
+ }, {
253
+ jsx?: "automatic" | "transform" | "preserve" | undefined;
254
+ target?: string | undefined;
255
+ format?: "esm" | "cjs" | "iife" | undefined;
256
+ jsxFactory?: string | undefined;
257
+ jsxFragment?: string | undefined;
258
+ }>>;
259
+ framework: z.ZodOptional<z.ZodObject<{
260
+ globals: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
261
+ preload: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
262
+ deps: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
263
+ }, "strict", z.ZodTypeAny, {
264
+ globals?: Record<string, string> | undefined;
265
+ preload?: string[] | undefined;
266
+ deps?: Record<string, string> | undefined;
267
+ }, {
268
+ globals?: Record<string, string> | undefined;
269
+ preload?: string[] | undefined;
270
+ deps?: Record<string, string> | undefined;
271
+ }>>;
272
+ aliases: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
273
+ }, "strict", z.ZodTypeAny, {
274
+ platform: "browser" | "cli";
275
+ dependencies?: Record<string, string> | undefined;
276
+ esbuild?: {
277
+ jsx?: "automatic" | "transform" | "preserve" | undefined;
278
+ target?: string | undefined;
279
+ format?: "esm" | "cjs" | "iife" | undefined;
280
+ jsxFactory?: string | undefined;
281
+ jsxFragment?: string | undefined;
282
+ } | undefined;
283
+ framework?: {
284
+ globals?: Record<string, string> | undefined;
285
+ preload?: string[] | undefined;
286
+ deps?: Record<string, string> | undefined;
287
+ } | undefined;
288
+ aliases?: Record<string, string> | undefined;
289
+ }, {
290
+ platform: "browser" | "cli";
291
+ dependencies?: Record<string, string> | undefined;
292
+ esbuild?: {
293
+ jsx?: "automatic" | "transform" | "preserve" | undefined;
294
+ target?: string | undefined;
295
+ format?: "esm" | "cjs" | "iife" | undefined;
296
+ jsxFactory?: string | undefined;
297
+ jsxFragment?: string | undefined;
298
+ } | undefined;
299
+ framework?: {
300
+ globals?: Record<string, string> | undefined;
301
+ preload?: string[] | undefined;
302
+ deps?: Record<string, string> | undefined;
303
+ } | undefined;
304
+ aliases?: Record<string, string> | undefined;
305
+ }>;
306
+ type ImageConfig = z.infer<typeof ImageConfigSchema>;
307
+ declare const InputSpecSchema: z.ZodObject<{
308
+ type: z.ZodEnum<["string", "number", "boolean", "object", "array"]>;
309
+ default: z.ZodOptional<z.ZodUnknown>;
310
+ required: z.ZodOptional<z.ZodBoolean>;
311
+ description: z.ZodOptional<z.ZodString>;
312
+ }, "strip", z.ZodTypeAny, {
313
+ type: "string" | "number" | "boolean" | "object" | "array";
314
+ default?: unknown;
315
+ required?: boolean | undefined;
316
+ description?: string | undefined;
317
+ }, {
318
+ type: "string" | "number" | "boolean" | "object" | "array";
319
+ default?: unknown;
320
+ required?: boolean | undefined;
321
+ description?: string | undefined;
322
+ }>;
323
+ declare const ManifestSchema: z.ZodObject<{
324
+ name: z.ZodString;
325
+ version: z.ZodString;
326
+ description: z.ZodOptional<z.ZodString>;
327
+ platform: z.ZodEnum<["browser", "cli"]>;
328
+ image: z.ZodString;
329
+ inputs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
330
+ type: z.ZodEnum<["string", "number", "boolean", "object", "array"]>;
331
+ default: z.ZodOptional<z.ZodUnknown>;
332
+ required: z.ZodOptional<z.ZodBoolean>;
333
+ description: z.ZodOptional<z.ZodString>;
334
+ }, "strip", z.ZodTypeAny, {
335
+ type: "string" | "number" | "boolean" | "object" | "array";
336
+ default?: unknown;
337
+ required?: boolean | undefined;
338
+ description?: string | undefined;
339
+ }, {
340
+ type: "string" | "number" | "boolean" | "object" | "array";
341
+ default?: unknown;
342
+ required?: boolean | undefined;
343
+ description?: string | undefined;
344
+ }>>>;
345
+ services: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
346
+ packages: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
347
+ }, "strip", z.ZodTypeAny, {
348
+ platform: "browser" | "cli";
349
+ name: string;
350
+ version: string;
351
+ image: string;
352
+ description?: string | undefined;
353
+ inputs?: Record<string, {
354
+ type: "string" | "number" | "boolean" | "object" | "array";
355
+ default?: unknown;
356
+ required?: boolean | undefined;
357
+ description?: string | undefined;
358
+ }> | undefined;
359
+ services?: string[] | undefined;
360
+ packages?: Record<string, string> | undefined;
361
+ }, {
362
+ platform: "browser" | "cli";
363
+ name: string;
364
+ version: string;
365
+ image: string;
366
+ description?: string | undefined;
367
+ inputs?: Record<string, {
368
+ type: "string" | "number" | "boolean" | "object" | "array";
369
+ default?: unknown;
370
+ required?: boolean | undefined;
371
+ description?: string | undefined;
372
+ }> | undefined;
373
+ services?: string[] | undefined;
374
+ packages?: Record<string, string> | undefined;
375
+ }>;
376
+ type Manifest = z.infer<typeof ManifestSchema>;
377
+ declare const CompileOptionsSchema: z.ZodOptional<z.ZodObject<{
378
+ typescript: z.ZodOptional<z.ZodBoolean>;
379
+ }, "strict", z.ZodTypeAny, {
380
+ typescript?: boolean | undefined;
381
+ }, {
382
+ typescript?: boolean | undefined;
383
+ }>>;
384
+ declare const MountModeSchema: z.ZodEnum<["embedded", "iframe"]>;
385
+ declare const MountOptionsSchema: z.ZodObject<{
386
+ target: z.ZodType<HTMLElement, z.ZodTypeDef, HTMLElement>;
387
+ mode: z.ZodEnum<["embedded", "iframe"]>;
388
+ sandbox: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
389
+ inputs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
390
+ }, "strip", z.ZodTypeAny, {
391
+ target: HTMLElement;
392
+ mode: "embedded" | "iframe";
393
+ inputs?: Record<string, unknown> | undefined;
394
+ sandbox?: string[] | undefined;
395
+ }, {
396
+ target: HTMLElement;
397
+ mode: "embedded" | "iframe";
398
+ inputs?: Record<string, unknown> | undefined;
399
+ sandbox?: string[] | undefined;
400
+ }>;
401
+ /**
402
+ * Parse and validate ImageConfig from package.json patchwork field
403
+ *
404
+ * @param data - Raw data from package.json patchwork field
405
+ * @returns Validated ImageConfig
406
+ * @throws z.ZodError if validation fails
407
+ */
408
+ declare function parseImageConfig(data: unknown): ImageConfig;
409
+ /**
410
+ * Safely parse ImageConfig, returning null on failure
411
+ */
412
+ declare function safeParseImageConfig(data: unknown): ImageConfig | null;
413
+ /**
414
+ * Parse and validate widget manifest
415
+ */
416
+ declare function parseManifest(data: unknown): Manifest;
417
+ /**
418
+ * Safely parse manifest, returning null on failure
419
+ */
420
+ declare function safeParseManifest(data: unknown): Manifest | null;
421
+ declare const DEFAULT_IMAGE_CONFIG: ImageConfig;
422
+ declare const DEFAULT_CLI_IMAGE_CONFIG: ImageConfig;
423
+
424
+ /**
425
+ * Image loader - fetches and loads image packages from CDN or local
426
+ *
427
+ * Images must be installed as npm packages or available on CDN.
428
+ */
429
+
430
+ /**
431
+ * Set the CDN base URL for image loading
432
+ */
433
+ declare function setCdnBaseUrl(url: string): void;
434
+ /**
435
+ * Get the current CDN base URL
436
+ */
437
+ declare function getCdnBaseUrl(): string;
438
+ interface ImagePackageJson {
439
+ name: string;
440
+ version: string;
441
+ main?: string;
442
+ dependencies?: Record<string, string>;
443
+ patchwork?: unknown;
444
+ }
445
+ /**
446
+ * Parse image specifier into name and version
447
+ */
448
+ declare function parseImageSpec(spec: string): {
449
+ name: string;
450
+ version?: string;
451
+ };
452
+ /**
453
+ * Fetch package.json from CDN
454
+ */
455
+ declare function fetchPackageJson(packageName: string, version?: string): Promise<ImagePackageJson>;
456
+ /**
457
+ * Load an image package
458
+ *
459
+ * Priority:
460
+ * 1. Try to resolve locally (require.resolve for installed packages)
461
+ * 2. Fetch from CDN
462
+ *
463
+ * Images must be explicitly installed or available on CDN.
464
+ */
465
+ declare function loadImage(spec: string): Promise<LoadedImage>;
466
+
467
+ /**
468
+ * Image registry - manages loaded images
469
+ */
470
+
471
+ /**
472
+ * Registry of loaded images
473
+ */
474
+ declare class ImageRegistry {
475
+ private images;
476
+ private loading;
477
+ /**
478
+ * Get a loaded image by spec
479
+ */
480
+ get(spec: string): LoadedImage | undefined;
481
+ /**
482
+ * Check if an image is loaded
483
+ */
484
+ has(spec: string): boolean;
485
+ /**
486
+ * Load an image (or return cached)
487
+ */
488
+ load(spec: string): Promise<LoadedImage>;
489
+ /**
490
+ * Preload an image
491
+ */
492
+ preload(spec: string): Promise<void>;
493
+ /**
494
+ * Clear a specific image from cache
495
+ */
496
+ clear(spec: string): void;
497
+ /**
498
+ * Clear all cached images
499
+ */
500
+ clearAll(): void;
501
+ /**
502
+ * Get all loaded image names
503
+ */
504
+ getLoadedNames(): string[];
505
+ }
506
+ /**
507
+ * Get the global image registry
508
+ */
509
+ declare function getImageRegistry(): ImageRegistry;
510
+ /**
511
+ * Create a new isolated image registry
512
+ */
513
+ declare function createImageRegistry(): ImageRegistry;
514
+
515
+ /**
516
+ * CDN transform - converts bare imports to CDN URLs (esm.sh)
517
+ */
518
+
519
+ interface CdnTransformOptions {
520
+ /** Map of package names to versions */
521
+ packages?: Record<string, string>;
522
+ /** Additional external packages */
523
+ external?: string[];
524
+ /** Use bundled versions from esm.sh (adds ?bundle) */
525
+ bundle?: boolean;
526
+ /** Packages to inject from window globals instead of CDN */
527
+ globals?: Record<string, string>;
528
+ /** Dependency version overrides for CDN URLs (e.g., { react: '18' }) */
529
+ deps?: Record<string, string>;
530
+ /** Import path aliases (e.g., { '@/components/ui/*': '@packagedcn/react' }) */
531
+ aliases?: Record<string, string>;
532
+ }
533
+ /**
534
+ * Create an esbuild plugin that transforms bare imports to CDN URLs
535
+ * and injects globals for specified packages (like React)
536
+ */
537
+ declare function cdnTransformPlugin(options?: CdnTransformOptions): Plugin;
538
+ /**
539
+ * Generate import map for CDN dependencies
540
+ */
541
+ declare function generateImportMap(packages: Record<string, string>): Record<string, string>;
542
+
543
+ interface VFSPluginOptions {
544
+ aliases?: Record<string, string>;
545
+ }
546
+ declare function vfsPlugin(project: VirtualProject, options?: VFSPluginOptions): Plugin;
547
+
548
+ declare function createProjectFromFiles(files: VirtualFile[], id?: `${string}-${string}-${string}-${string}-${string}`): VirtualProject;
549
+ declare function resolveEntry(files: Map<string, VirtualFile>): string;
550
+ declare function detectMainFile(language?: string): string;
551
+ declare function createSingleFileProject(content: string, entry?: string, id?: string): VirtualProject;
552
+
553
+ declare class VFSStore {
554
+ private backend;
555
+ private root;
556
+ constructor(backend: StorageBackend, root?: string);
557
+ private key;
558
+ getFile(path: string): Promise<VirtualFile | null>;
559
+ putFile(file: VirtualFile): Promise<void>;
560
+ deleteFile(path: string): Promise<void>;
561
+ listFiles(prefix?: string): Promise<string[]>;
562
+ loadProject(id: string): Promise<VirtualProject | null>;
563
+ saveProject(project: VirtualProject): Promise<void>;
564
+ }
565
+
566
+ declare class IndexedDBBackend implements StorageBackend {
567
+ private prefix;
568
+ constructor(prefix?: string);
569
+ private key;
570
+ get(path: string): Promise<string | null>;
571
+ put(path: string, content: string): Promise<void>;
572
+ delete(path: string): Promise<void>;
573
+ list(prefix?: string): Promise<string[]>;
574
+ exists(path: string): Promise<boolean>;
575
+ }
576
+
577
+ interface LocalFSConfig {
578
+ baseUrl: string;
579
+ }
580
+ declare class LocalFSBackend implements StorageBackend {
581
+ private config;
582
+ constructor(config: LocalFSConfig);
583
+ get(path: string): Promise<string | null>;
584
+ put(path: string, content: string): Promise<void>;
585
+ delete(path: string): Promise<void>;
586
+ list(prefix?: string): Promise<string[]>;
587
+ exists(path: string): Promise<boolean>;
588
+ }
589
+
590
+ interface S3Config {
591
+ bucket: string;
592
+ region: string;
593
+ prefix?: string;
594
+ credentials?: {
595
+ accessKeyId: string;
596
+ secretAccessKey: string;
597
+ };
598
+ }
599
+ declare class S3Backend implements StorageBackend {
600
+ private config;
601
+ constructor(config: S3Config);
602
+ private get baseUrl();
603
+ private key;
604
+ get(path: string): Promise<string | null>;
605
+ put(path: string, content: string): Promise<void>;
606
+ delete(path: string): Promise<void>;
607
+ list(prefix?: string): Promise<string[]>;
608
+ exists(path: string): Promise<boolean>;
609
+ private parseListResponse;
610
+ }
611
+
612
+ /**
613
+ * Embedded mount mode - mounts widgets directly in the DOM
614
+ *
615
+ * For trusted widgets that need full window access.
616
+ */
617
+
618
+ /**
619
+ * Mount a widget in embedded mode (direct DOM injection)
620
+ */
621
+ declare function mountEmbedded(widget: CompiledWidget, options: MountOptions, image: LoadedImage | null, proxy: ServiceProxy): Promise<MountedWidget>;
622
+ /**
623
+ * Hot reload an embedded widget
624
+ */
625
+ declare function reloadEmbedded(mounted: MountedWidget, widget: CompiledWidget, image: LoadedImage | null, proxy: ServiceProxy): Promise<MountedWidget>;
626
+
627
+ /**
628
+ * Iframe mount mode - mounts widgets in sandboxed iframes
629
+ *
630
+ * For untrusted widgets that need isolation.
631
+ */
632
+
633
+ /**
634
+ * Development sandbox attributes - includes allow-same-origin
635
+ *
636
+ * allow-same-origin is required when:
637
+ * - Fetching modules from the parent origin (e.g., /_local-packages/ in dev)
638
+ * - Using import maps that reference parent-relative URLs
639
+ * - Accessing the parent's CDN proxy
640
+ *
641
+ * Note: This does NOT allow the iframe to access parent's DOM or cookies,
642
+ * but it does allow same-origin network requests.
643
+ *
644
+ * WARNING: Combining allow-scripts + allow-same-origin allows the iframe to
645
+ * escape its sandbox. Only use in development or when hosting on a separate subdomain.
646
+ */
647
+ declare const DEV_SANDBOX: string[];
648
+ /**
649
+ * Mount a widget in iframe mode (sandboxed)
650
+ */
651
+ declare function mountIframe(widget: CompiledWidget, options: MountOptions, image: LoadedImage | null, proxy: ServiceProxy): Promise<MountedWidget>;
652
+ /**
653
+ * Hot reload an iframe widget
654
+ */
655
+ declare function reloadIframe(mounted: MountedWidget, widget: CompiledWidget, image: LoadedImage | null, proxy: ServiceProxy): Promise<MountedWidget>;
656
+ /**
657
+ * Dispose the shared bridge (call on app shutdown)
658
+ */
659
+ declare function disposeIframeBridge(): void;
660
+
661
+ /**
662
+ * Service bridge - handles communication between widgets and service proxy
663
+ */
664
+
665
+ /**
666
+ * Create a service proxy that calls the backend via HTTP
667
+ */
668
+ declare function createHttpServiceProxy(proxyUrl: string): ServiceProxy;
669
+ /**
670
+ * Creates a proxy that enables fluent method chaining for dynamic field access.
671
+ *
672
+ * This allows arbitrary nested property access that resolves to a callable function,
673
+ * supporting patterns like `proxy.foo()`, `proxy.foo.bar()`, `proxy.bar.baz.qux()`.
674
+ *
675
+ * Used to create global namespace objects that proxy calls to a service backend.
676
+ */
677
+ declare function createFieldAccessProxy<T = unknown>(namespace: string, handler: (namespace: string, methodPath: string, ...args: T[]) => Promise<unknown>): Record<string, (...args: T[]) => Promise<unknown>>;
678
+ /**
679
+ * Create namespace globals that proxy calls to a service proxy
680
+ *
681
+ * Creates dynamic proxy objects for each namespace that support arbitrary
682
+ * nested method calls. This replaces the old static method registration.
683
+ *
684
+ * @param services - Array of service names (e.g., ['git', 'github'])
685
+ * @param proxy - The service proxy to forward calls to
686
+ * @returns Record of namespace names to proxy objects
687
+ *
688
+ * @example
689
+ * ```typescript
690
+ * const namespaces = generateNamespaceGlobals(['git', 'github'], proxy);
691
+ * // namespaces.git.status() calls proxy.call('git', 'status', [])
692
+ * // namespaces.github.repos.list_for_user({ username: 'x' })
693
+ * // calls proxy.call('github', 'repos.list_for_user', [{ username: 'x' }])
694
+ * ```
695
+ */
696
+ declare function generateNamespaceGlobals(services: string[], proxy: ServiceProxy): Record<string, unknown>;
697
+ /**
698
+ * Inject namespace globals into a window object
699
+ */
700
+ declare function injectNamespaceGlobals(target: Window | typeof globalThis, namespaces: Record<string, unknown>): void;
701
+ /**
702
+ * Remove namespace globals from a window object
703
+ */
704
+ declare function removeNamespaceGlobals(target: Window | typeof globalThis, namespaceNames: string[]): void;
705
+ /**
706
+ * Extract unique namespace names from services array
707
+ */
708
+ declare function extractNamespaces(services: string[]): string[];
709
+ /**
710
+ * Parent-side bridge for iframe communication
711
+ *
712
+ * Listens for postMessage events from iframes and proxies service calls.
713
+ */
714
+ declare class ParentBridge {
715
+ private proxy;
716
+ private pendingCalls;
717
+ private iframes;
718
+ private messageHandler;
719
+ constructor(proxy: ServiceProxy);
720
+ /**
721
+ * Register an iframe to receive messages from
722
+ */
723
+ registerIframe(iframe: HTMLIFrameElement): void;
724
+ /**
725
+ * Unregister an iframe
726
+ */
727
+ unregisterIframe(iframe: HTMLIFrameElement): void;
728
+ /**
729
+ * Handle incoming messages from iframes
730
+ */
731
+ private handleMessage;
732
+ /**
733
+ * Dispose the bridge
734
+ */
735
+ dispose(): void;
736
+ }
737
+ /**
738
+ * Child-side bridge for iframe communication
739
+ *
740
+ * Creates a service proxy that sends postMessage to parent.
741
+ */
742
+ declare function createIframeServiceProxy(): ServiceProxy;
743
+ /**
744
+ * Generate the bridge script to inject into iframes
745
+ *
746
+ * Creates a self-contained script that sets up:
747
+ * 1. Message handling for service results from parent
748
+ * 2. Dynamic proxy objects for each namespace that support arbitrary nested calls
749
+ */
750
+ declare function generateIframeBridgeScript(services: string[]): string;
751
+
752
+ export { type BridgeMessage, type BridgeMessageType, type CdnTransformOptions, type CompileOptions, CompileOptionsSchema, type CompiledWidget, type Compiler, type CompilerOptions, DEFAULT_CLI_IMAGE_CONFIG, DEFAULT_IMAGE_CONFIG, DEV_SANDBOX, EsbuildConfigSchema, type GlobalInterfaceDefinition, type ImageConfig$1 as ImageConfig, ImageConfigSchema, type ImageMountFn, ImageRegistry, IndexedDBBackend, type InputSpec, InputSpecSchema, type LoadedImage, LocalFSBackend, type LocalFSConfig, type Manifest$1 as Manifest, ManifestSchema, type MountMode, MountModeSchema, type MountOptions, MountOptionsSchema, type MountedWidget, ParentBridge, type Platform, PlatformSchema, S3Backend, type S3Config, type ServiceCallHandler, type ServiceCallPayload, type ServiceProxy, type ServiceResultPayload, type StorageBackend, type VFSPluginOptions, VFSStore, type VirtualFile, type VirtualProject, cdnTransformPlugin, createCompiler, createFieldAccessProxy, createHttpServiceProxy, createIframeServiceProxy, createImageRegistry, createProjectFromFiles, createSingleFileProject, detectMainFile, disposeIframeBridge, extractNamespaces, fetchPackageJson, generateIframeBridgeScript, generateImportMap, generateNamespaceGlobals, getCdnBaseUrl, getImageRegistry, injectNamespaceGlobals, loadImage, mountEmbedded, mountIframe, parseImageConfig, parseImageSpec, parseManifest, reloadEmbedded, reloadIframe, removeNamespaceGlobals, resolveEntry, safeParseImageConfig, safeParseManifest, setCdnBaseUrl, vfsPlugin };