@constela/runtime 0.19.5 → 0.19.6
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/index.d.ts +7 -0
- package/dist/index.js +58 -7
- package/package.json +12 -4
package/dist/index.d.ts
CHANGED
|
@@ -480,6 +480,13 @@ interface HMRHandlerOptions {
|
|
|
480
480
|
program: CompiledProgram;
|
|
481
481
|
/** Optional route context */
|
|
482
482
|
route?: RouteContext;
|
|
483
|
+
/**
|
|
484
|
+
* Skip initial app creation (for hydration scenarios where hydrateApp handles initial render).
|
|
485
|
+
* When true, the HMR handler will NOT render the app on creation. The first handleUpdate()
|
|
486
|
+
* call will clear the container (removing SSR content) before rendering.
|
|
487
|
+
* @default false
|
|
488
|
+
*/
|
|
489
|
+
skipInitialRender?: boolean;
|
|
483
490
|
}
|
|
484
491
|
/**
|
|
485
492
|
* HMR Handler interface
|
package/dist/index.js
CHANGED
|
@@ -1337,6 +1337,9 @@ async function executeStep(step, ctx) {
|
|
|
1337
1337
|
case "focus":
|
|
1338
1338
|
await executeFocusStep(step, ctx);
|
|
1339
1339
|
break;
|
|
1340
|
+
case "generate":
|
|
1341
|
+
await executeGenerateStep(step, ctx);
|
|
1342
|
+
break;
|
|
1340
1343
|
}
|
|
1341
1344
|
}
|
|
1342
1345
|
async function executeSetStep(target, value, ctx) {
|
|
@@ -1834,6 +1837,48 @@ async function executeFocusStep(step, ctx) {
|
|
|
1834
1837
|
}
|
|
1835
1838
|
}
|
|
1836
1839
|
}
|
|
1840
|
+
async function executeGenerateStep(step, ctx) {
|
|
1841
|
+
const { createDslGenerator } = await import("@constela/ai");
|
|
1842
|
+
const evalCtx = createEvalContext(ctx);
|
|
1843
|
+
const promptValue = evaluate(step.prompt, evalCtx);
|
|
1844
|
+
try {
|
|
1845
|
+
const generator = createDslGenerator({
|
|
1846
|
+
provider: step.provider
|
|
1847
|
+
});
|
|
1848
|
+
const result = await generator.generate({
|
|
1849
|
+
prompt: promptValue,
|
|
1850
|
+
output: step.output
|
|
1851
|
+
});
|
|
1852
|
+
ctx.locals[step.result] = result.dsl;
|
|
1853
|
+
if (!result.validated && result.errors && result.errors.length > 0) {
|
|
1854
|
+
ctx.locals["error"] = {
|
|
1855
|
+
message: `AI generated DSL validation failed: ${result.errors.join(", ")}`,
|
|
1856
|
+
name: "ValidationError"
|
|
1857
|
+
};
|
|
1858
|
+
if (step.onError) {
|
|
1859
|
+
for (const errorStep of step.onError) {
|
|
1860
|
+
await executeStep(errorStep, ctx);
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
return;
|
|
1864
|
+
}
|
|
1865
|
+
if (step.onSuccess) {
|
|
1866
|
+
for (const successStep of step.onSuccess) {
|
|
1867
|
+
await executeStep(successStep, ctx);
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
} catch (err) {
|
|
1871
|
+
ctx.locals["error"] = {
|
|
1872
|
+
message: err instanceof Error ? err.message : String(err),
|
|
1873
|
+
name: err instanceof Error ? err.name : "Error"
|
|
1874
|
+
};
|
|
1875
|
+
if (step.onError) {
|
|
1876
|
+
for (const errorStep of step.onError) {
|
|
1877
|
+
await executeStep(errorStep, ctx);
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1837
1882
|
|
|
1838
1883
|
// ../../node_modules/.pnpm/marked@17.0.1/node_modules/marked/lib/marked.esm.js
|
|
1839
1884
|
function L() {
|
|
@@ -15906,21 +15951,27 @@ function createHMRApp(program, container, route, existingStateStore) {
|
|
|
15906
15951
|
};
|
|
15907
15952
|
}
|
|
15908
15953
|
function createHMRHandler(options) {
|
|
15909
|
-
const { container, program, route } = options;
|
|
15954
|
+
const { container, program, route, skipInitialRender } = options;
|
|
15910
15955
|
let currentApp = null;
|
|
15911
15956
|
let destroyed = false;
|
|
15912
|
-
|
|
15957
|
+
if (!skipInitialRender) {
|
|
15958
|
+
currentApp = createHMRApp(program, container, route);
|
|
15959
|
+
}
|
|
15913
15960
|
return {
|
|
15914
15961
|
handleUpdate(newProgram) {
|
|
15915
15962
|
if (destroyed) {
|
|
15916
15963
|
return;
|
|
15917
15964
|
}
|
|
15918
|
-
|
|
15919
|
-
|
|
15920
|
-
|
|
15921
|
-
|
|
15922
|
-
currentApp =
|
|
15965
|
+
if (!currentApp) {
|
|
15966
|
+
while (container.firstChild) {
|
|
15967
|
+
container.removeChild(container.firstChild);
|
|
15968
|
+
}
|
|
15969
|
+
currentApp = createHMRApp(newProgram, container, route);
|
|
15970
|
+
return;
|
|
15923
15971
|
}
|
|
15972
|
+
const stateSnapshot = currentApp.stateStore.serialize();
|
|
15973
|
+
currentApp.destroy();
|
|
15974
|
+
currentApp = null;
|
|
15924
15975
|
const newStateStore = createStateStore(newProgram.state);
|
|
15925
15976
|
const newDefinitions = Object.entries(newProgram.state).map(
|
|
15926
15977
|
([name, def]) => ({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constela/runtime",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.6",
|
|
4
4
|
"description": "Runtime DOM renderer for Constela UI framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"dompurify": "^3.3.1",
|
|
19
19
|
"marked": "^17.0.1",
|
|
20
20
|
"shiki": "^3.20.0",
|
|
21
|
-
"@constela/compiler": "0.14.
|
|
22
|
-
"@constela/core": "0.16.
|
|
21
|
+
"@constela/compiler": "0.14.7",
|
|
22
|
+
"@constela/core": "0.16.2"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/dompurify": "^3.2.0",
|
|
@@ -29,7 +29,15 @@
|
|
|
29
29
|
"tsup": "^8.0.0",
|
|
30
30
|
"typescript": "^5.3.0",
|
|
31
31
|
"vitest": "^2.0.0",
|
|
32
|
-
"@constela/server": "12.0.
|
|
32
|
+
"@constela/server": "12.0.2"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@constela/ai": "1.0.2"
|
|
36
|
+
},
|
|
37
|
+
"peerDependenciesMeta": {
|
|
38
|
+
"@constela/ai": {
|
|
39
|
+
"optional": true
|
|
40
|
+
}
|
|
33
41
|
},
|
|
34
42
|
"engines": {
|
|
35
43
|
"node": ">=20.0.0"
|