@renderify/core 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.
package/dist/core.d.ts ADDED
@@ -0,0 +1,335 @@
1
+ import { RuntimePlan, RuntimeExecutionResult } from '@renderify/ir';
2
+ import { RenderTarget, RuntimeManager, UIRenderer } from '@renderify/runtime';
3
+ export { DefaultUIRenderer, InteractiveRenderTarget, RenderTarget, RuntimeEventDispatchRequest, UIRenderer } from '@renderify/runtime';
4
+ import { RuntimeSecurityPolicy, SecurityCheckResult, SecurityChecker } from '@renderify/security';
5
+ export * from '@renderify/security';
6
+
7
+ interface ApiDefinition {
8
+ name: string;
9
+ endpoint: string;
10
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
11
+ headers?: Record<string, string>;
12
+ timeoutMs?: number;
13
+ }
14
+ interface ApiIntegration {
15
+ registerApi(api: ApiDefinition): void;
16
+ listApis(): ApiDefinition[];
17
+ callApi<TResponse = unknown>(name: string, params?: Record<string, unknown>): Promise<TResponse>;
18
+ }
19
+ declare class DefaultApiIntegration implements ApiIntegration {
20
+ private readonly apis;
21
+ registerApi(api: ApiDefinition): void;
22
+ listApis(): ApiDefinition[];
23
+ callApi<TResponse = unknown>(name: string, params?: Record<string, unknown>): Promise<TResponse>;
24
+ private buildUrl;
25
+ private createTimeout;
26
+ }
27
+
28
+ interface CodeGenerationInput {
29
+ prompt: string;
30
+ llmText: string;
31
+ context?: Record<string, unknown>;
32
+ }
33
+ interface IncrementalCodeGenerationInput {
34
+ prompt: string;
35
+ context?: Record<string, unknown>;
36
+ }
37
+ interface IncrementalCodeGenerationUpdate {
38
+ plan: RuntimePlan;
39
+ complete: boolean;
40
+ mode: "runtime-plan-json" | "runtime-node-json" | "runtime-source" | "runtime-text-fallback";
41
+ }
42
+ interface IncrementalCodeGenerationSession {
43
+ pushDelta(delta: string): Promise<IncrementalCodeGenerationUpdate | undefined>;
44
+ finalize(finalText?: string): Promise<RuntimePlan | undefined>;
45
+ }
46
+ interface CodeGenerator {
47
+ generatePlan(input: CodeGenerationInput): Promise<RuntimePlan>;
48
+ createIncrementalSession?(input: IncrementalCodeGenerationInput): IncrementalCodeGenerationSession;
49
+ validatePlan(plan: RuntimePlan): Promise<boolean>;
50
+ transformPlan(plan: RuntimePlan, transforms: Array<(plan: RuntimePlan) => RuntimePlan>): Promise<RuntimePlan>;
51
+ }
52
+ declare class DefaultCodeGenerator implements CodeGenerator {
53
+ createIncrementalSession(input: IncrementalCodeGenerationInput): IncrementalCodeGenerationSession;
54
+ generatePlan(input: CodeGenerationInput): Promise<RuntimePlan>;
55
+ validatePlan(plan: RuntimePlan): Promise<boolean>;
56
+ transformPlan(plan: RuntimePlan, transforms: Array<(plan: RuntimePlan) => RuntimePlan>): Promise<RuntimePlan>;
57
+ private createFallbackRoot;
58
+ private tryBuildIncrementalCandidate;
59
+ private createIncrementalPlanSignature;
60
+ private hashIncrementalSignatureValue;
61
+ private createPlanFromRoot;
62
+ private tryParseRuntimePlan;
63
+ private tryParseRuntimeNode;
64
+ private tryParseJsonPayload;
65
+ private isLikelyCompleteJsonPayload;
66
+ private hasClosedCodeFence;
67
+ private normalizePlanId;
68
+ private normalizePlanVersion;
69
+ private normalizeImports;
70
+ private normalizeModuleManifest;
71
+ private normalizeCapabilities;
72
+ private createModuleManifestFromImports;
73
+ private resolveImportToUrl;
74
+ private extractVersionFromSpecifier;
75
+ private normalizeMetadata;
76
+ private tryExtractRuntimeSource;
77
+ private createSourcePlan;
78
+ private parseImportsFromSource;
79
+ private isHttpUrl;
80
+ private isRecord;
81
+ private normalizeSourceModule;
82
+ private inferSourceRuntimeFromLanguage;
83
+ private resolveJspmSpecifier;
84
+ }
85
+
86
+ type SecurityProfileConfig = "strict" | "balanced" | "relaxed";
87
+ type LLMProviderConfig = string;
88
+ interface RenderifyConfigValues {
89
+ llmApiKey?: string;
90
+ llmProvider: LLMProviderConfig;
91
+ llmModel: string;
92
+ llmBaseUrl: string;
93
+ llmRequestTimeoutMs: number;
94
+ llmUseStructuredOutput: boolean;
95
+ jspmCdnUrl: string;
96
+ strictSecurity: boolean;
97
+ securityProfile: SecurityProfileConfig;
98
+ securityPolicy?: Partial<RuntimeSecurityPolicy>;
99
+ runtimeJspmOnlyStrictMode: boolean;
100
+ runtimeEnforceModuleManifest: boolean;
101
+ runtimeAllowIsolationFallback: boolean;
102
+ runtimeSupportedSpecVersions: string[];
103
+ runtimeEnableDependencyPreflight: boolean;
104
+ runtimeFailOnDependencyPreflightError: boolean;
105
+ runtimeRemoteFetchTimeoutMs: number;
106
+ runtimeRemoteFetchRetries: number;
107
+ runtimeRemoteFetchBackoffMs: number;
108
+ runtimeRemoteFallbackCdnBases: string[];
109
+ runtimeBrowserSourceSandboxMode: "none" | "worker" | "iframe";
110
+ runtimeBrowserSourceSandboxTimeoutMs: number;
111
+ runtimeBrowserSourceSandboxFailClosed: boolean;
112
+ [key: string]: unknown;
113
+ }
114
+ interface JspmOnlyStrictModeOptions {
115
+ allowedNetworkHosts?: string[];
116
+ }
117
+ declare function createJspmOnlyStrictModeConfig(options?: JspmOnlyStrictModeOptions): Partial<RenderifyConfigValues>;
118
+ interface RenderifyConfig {
119
+ load(overrides?: Partial<RenderifyConfigValues>): Promise<void>;
120
+ get<T = unknown>(key: string): T | undefined;
121
+ set(key: string, value: unknown): void;
122
+ snapshot(): Readonly<Record<string, unknown>>;
123
+ save(): Promise<void>;
124
+ }
125
+ declare class DefaultRenderifyConfig implements RenderifyConfig {
126
+ private config;
127
+ load(overrides?: Partial<RenderifyConfigValues>): Promise<void>;
128
+ get<T = unknown>(key: string): T | undefined;
129
+ set(key: string, value: unknown): void;
130
+ snapshot(): Readonly<Record<string, unknown>>;
131
+ save(): Promise<void>;
132
+ }
133
+
134
+ interface RenderifyContext {
135
+ user?: {
136
+ id: string;
137
+ name?: string;
138
+ role?: string;
139
+ };
140
+ app?: {
141
+ version: string;
142
+ environment?: "development" | "staging" | "production";
143
+ };
144
+ [key: string]: unknown;
145
+ }
146
+ interface ContextManager {
147
+ initialize(): Promise<void>;
148
+ getContext(): RenderifyContext;
149
+ updateContext(partialCtx: Partial<RenderifyContext>): void;
150
+ subscribe(listener: (ctx: RenderifyContext) => void): () => void;
151
+ }
152
+ declare class DefaultContextManager implements ContextManager {
153
+ private ctx;
154
+ private listeners;
155
+ initialize(): Promise<void>;
156
+ getContext(): RenderifyContext;
157
+ updateContext(partialCtx: Partial<RenderifyContext>): void;
158
+ subscribe(listener: (ctx: RenderifyContext) => void): () => void;
159
+ private notify;
160
+ }
161
+
162
+ type PluginHook = "beforeLLM" | "afterLLM" | "beforeCodeGen" | "afterCodeGen" | "beforePolicyCheck" | "afterPolicyCheck" | "beforeRuntime" | "afterRuntime" | "beforeRender" | "afterRender";
163
+ interface PluginContext {
164
+ traceId: string;
165
+ hookName: PluginHook;
166
+ }
167
+ type PluginHandler<Payload = unknown> = (payload: Payload, context: PluginContext) => Payload | Promise<Payload>;
168
+ interface RenderifyPlugin {
169
+ name: string;
170
+ hooks: Partial<Record<PluginHook, PluginHandler>>;
171
+ }
172
+ interface CustomizationEngine {
173
+ registerPlugin(plugin: RenderifyPlugin): void;
174
+ getPlugins(): RenderifyPlugin[];
175
+ runHook<Payload>(hookName: PluginHook, payload: Payload, context: PluginContext): Promise<Payload>;
176
+ }
177
+ declare class DefaultCustomizationEngine implements CustomizationEngine {
178
+ private plugins;
179
+ registerPlugin(plugin: RenderifyPlugin): void;
180
+ getPlugins(): RenderifyPlugin[];
181
+ runHook<Payload>(hookName: PluginHook, payload: Payload, context: PluginContext): Promise<Payload>;
182
+ }
183
+
184
+ interface LLMRequest {
185
+ prompt: string;
186
+ context?: Record<string, unknown>;
187
+ systemPrompt?: string;
188
+ signal?: AbortSignal;
189
+ }
190
+ interface LLMResponse {
191
+ text: string;
192
+ tokensUsed?: number;
193
+ model?: string;
194
+ raw?: unknown;
195
+ }
196
+ interface LLMResponseStreamChunk {
197
+ delta: string;
198
+ text: string;
199
+ done: boolean;
200
+ index: number;
201
+ tokensUsed?: number;
202
+ model?: string;
203
+ raw?: unknown;
204
+ }
205
+ interface LLMStructuredRequest extends LLMRequest {
206
+ format: "runtime-plan";
207
+ strict?: boolean;
208
+ }
209
+ interface LLMStructuredResponse<T = unknown> {
210
+ text: string;
211
+ value?: T;
212
+ valid: boolean;
213
+ errors?: string[];
214
+ tokensUsed?: number;
215
+ model?: string;
216
+ raw?: unknown;
217
+ }
218
+ interface LLMInterpreter {
219
+ configure(options: Record<string, unknown>): void;
220
+ generateResponse(req: LLMRequest): Promise<LLMResponse>;
221
+ generateResponseStream?(req: LLMRequest): AsyncIterable<LLMResponseStreamChunk>;
222
+ generateStructuredResponse?<T = unknown>(req: LLMStructuredRequest): Promise<LLMStructuredResponse<T>>;
223
+ setPromptTemplate(templateName: string, templateContent: string): void;
224
+ getPromptTemplate(templateName: string): string | undefined;
225
+ }
226
+
227
+ interface PerformanceMetric {
228
+ label: string;
229
+ startedAt: number;
230
+ endedAt: number;
231
+ durationMs: number;
232
+ }
233
+ interface PerformanceOptimizer {
234
+ startMeasurement(label: string): void;
235
+ endMeasurement(label: string): PerformanceMetric | undefined;
236
+ getMetrics(): PerformanceMetric[];
237
+ reset(): void;
238
+ }
239
+ declare class DefaultPerformanceOptimizer implements PerformanceOptimizer {
240
+ private readonly timers;
241
+ private readonly metrics;
242
+ startMeasurement(label: string): void;
243
+ endMeasurement(label: string): PerformanceMetric | undefined;
244
+ getMetrics(): PerformanceMetric[];
245
+ reset(): void;
246
+ }
247
+
248
+ interface RenderifyCoreDependencies {
249
+ config: RenderifyConfig;
250
+ context: ContextManager;
251
+ llm: LLMInterpreter;
252
+ codegen: CodeGenerator;
253
+ runtime: RuntimeManager;
254
+ security: SecurityChecker;
255
+ performance: PerformanceOptimizer;
256
+ ui: UIRenderer;
257
+ apiIntegration?: ApiIntegration;
258
+ customization?: CustomizationEngine;
259
+ }
260
+ interface RenderPromptOptions {
261
+ target?: RenderTarget;
262
+ traceId?: string;
263
+ signal?: AbortSignal;
264
+ }
265
+ interface RenderPlanOptions {
266
+ target?: RenderTarget;
267
+ traceId?: string;
268
+ prompt?: string;
269
+ signal?: AbortSignal;
270
+ }
271
+ interface RenderPlanResult {
272
+ traceId: string;
273
+ plan: RuntimePlan;
274
+ security: SecurityCheckResult;
275
+ execution: RuntimeExecutionResult;
276
+ html: string;
277
+ }
278
+ interface RenderPromptResult extends RenderPlanResult {
279
+ prompt: string;
280
+ llm: LLMResponse;
281
+ }
282
+ interface RenderPromptStreamOptions extends RenderPromptOptions {
283
+ previewEveryChunks?: number;
284
+ }
285
+ interface RenderPromptStreamChunk {
286
+ type: "llm-delta" | "preview" | "final" | "error";
287
+ traceId: string;
288
+ prompt: string;
289
+ llmText: string;
290
+ delta?: string;
291
+ html?: string;
292
+ diagnostics?: RuntimeExecutionResult["diagnostics"];
293
+ planId?: string;
294
+ final?: RenderPromptResult;
295
+ error?: {
296
+ message: string;
297
+ name?: string;
298
+ };
299
+ }
300
+ type EventCallback = (...args: unknown[]) => void;
301
+ declare class PolicyRejectionError extends Error {
302
+ readonly result: SecurityCheckResult;
303
+ constructor(result: SecurityCheckResult);
304
+ }
305
+ declare class RenderifyApp {
306
+ private readonly deps;
307
+ private readonly listeners;
308
+ private running;
309
+ constructor(deps: RenderifyCoreDependencies);
310
+ start(): Promise<void>;
311
+ stop(): Promise<void>;
312
+ renderPrompt(prompt: string, options?: RenderPromptOptions): Promise<RenderPromptResult>;
313
+ renderPromptStream(prompt: string, options?: RenderPromptStreamOptions): AsyncGenerator<RenderPromptStreamChunk, RenderPromptResult>;
314
+ renderPlan(plan: RuntimePlan, options?: RenderPlanOptions): Promise<RenderPlanResult>;
315
+ getConfig(): RenderifyConfig;
316
+ getContext(): ContextManager;
317
+ getLLM(): LLMInterpreter;
318
+ getCodeGenerator(): CodeGenerator;
319
+ getRuntimeManager(): RuntimeManager;
320
+ getSecurityChecker(): SecurityChecker;
321
+ on(eventName: string, callback: EventCallback): () => void;
322
+ emit(eventName: string, payload?: unknown): void;
323
+ private executePlanFlow;
324
+ private ensureRunning;
325
+ private runHook;
326
+ private toRecord;
327
+ private createTraceId;
328
+ private createMetricLabel;
329
+ private resolveUserId;
330
+ private buildStreamingPreview;
331
+ private throwIfAborted;
332
+ }
333
+ declare function createRenderifyApp(deps: RenderifyCoreDependencies): RenderifyApp;
334
+
335
+ export { type ApiDefinition, type ApiIntegration, type CodeGenerationInput, type CodeGenerator, type ContextManager, type CustomizationEngine, DefaultApiIntegration, DefaultCodeGenerator, DefaultContextManager, DefaultCustomizationEngine, DefaultPerformanceOptimizer, DefaultRenderifyConfig, type IncrementalCodeGenerationInput, type IncrementalCodeGenerationSession, type IncrementalCodeGenerationUpdate, type JspmOnlyStrictModeOptions, type LLMInterpreter, type LLMProviderConfig, type LLMRequest, type LLMResponse, type LLMResponseStreamChunk, type LLMStructuredRequest, type LLMStructuredResponse, type PerformanceMetric, type PerformanceOptimizer, type PluginContext, type PluginHandler, type PluginHook, PolicyRejectionError, type RenderPlanOptions, type RenderPlanResult, type RenderPromptOptions, type RenderPromptResult, type RenderPromptStreamChunk, type RenderPromptStreamOptions, RenderifyApp, type RenderifyConfig, type RenderifyConfigValues, type RenderifyContext, type RenderifyCoreDependencies, type RenderifyPlugin, type SecurityProfileConfig, createJspmOnlyStrictModeConfig, createRenderifyApp };