tokensafe-ui 0.1.7 → 0.1.9
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/{chunk-UXZDGOF5.js → chunk-2YH7IQ3P.js} +1 -1
- package/dist/{chunk-GJWCBVCA.js → chunk-4PIOAQC3.js} +1 -1
- package/dist/{chunk-JQRAF2JG.js → chunk-GBP5S5VP.js} +59 -42
- package/dist/{chunk-W4DCPVD6.js → chunk-GVVBOP4E.js} +2 -2
- package/dist/{chunk-OE2N2PMS.js → chunk-LFFVZCNL.js} +3 -3
- package/dist/cli.js +4 -4
- package/dist/index.cjs +59 -42
- package/dist/index.d-BAn7lh_a.d.cts +71 -0
- package/dist/index.d-BAn7lh_a.d.ts +71 -0
- package/dist/index.d.cts +481 -5
- package/dist/index.d.ts +481 -5
- package/dist/index.js +1 -1
- package/dist/mcp.d.cts +91 -2
- package/dist/mcp.d.ts +91 -2
- package/dist/mcp.js +4 -4
- package/dist/observer.d.cts +186 -1
- package/dist/observer.d.ts +186 -1
- package/dist/observer.js +2 -2
- package/dist/oumv.d.cts +114 -1
- package/dist/oumv.d.ts +114 -1
- package/dist/oumv.js +4 -4
- package/dist/patcher.d.cts +68 -1
- package/dist/patcher.d.ts +68 -1
- package/dist/react.d.cts +280 -1
- package/dist/react.d.ts +280 -1
- package/dist/react.js +4 -4
- package/dist/testing.d.cts +2 -1
- package/dist/testing.d.ts +2 -1
- package/dist/testing.js +1 -1
- package/dist/vite.d.cts +24 -2
- package/dist/vite.d.ts +24 -2
- package/dist/vite.js +1 -1
- package/dist/vue.d.cts +180 -1
- package/dist/vue.d.ts +180 -1
- package/dist/vue.js +4 -4
- package/package.json +1 -1
|
@@ -837,8 +837,14 @@ var SVG_TAGS = /* @__PURE__ */ new Set([
|
|
|
837
837
|
]);
|
|
838
838
|
function h(type, props, ...children) {
|
|
839
839
|
const normalizedProps = props || {};
|
|
840
|
-
|
|
841
|
-
if (flatChildren.length
|
|
840
|
+
let flatChildren = children.flat().filter((c) => c !== null && c !== void 0);
|
|
841
|
+
if (flatChildren.length === 0 && normalizedProps.children) {
|
|
842
|
+
if (Array.isArray(normalizedProps.children)) {
|
|
843
|
+
flatChildren = normalizedProps.children.flat().filter((c) => c !== null && c !== void 0);
|
|
844
|
+
} else {
|
|
845
|
+
flatChildren = [normalizedProps.children];
|
|
846
|
+
}
|
|
847
|
+
} else if (flatChildren.length > 0 && !normalizedProps.children) {
|
|
842
848
|
normalizedProps.children = flatChildren.length === 1 ? flatChildren[0] : flatChildren;
|
|
843
849
|
}
|
|
844
850
|
return {
|
|
@@ -1050,7 +1056,6 @@ function convertReactNode(rn) {
|
|
|
1050
1056
|
if ("props" in rn && "type" in rn) {
|
|
1051
1057
|
const props = { ...rn.props || {} };
|
|
1052
1058
|
const rawChildren = props.children;
|
|
1053
|
-
delete props.children;
|
|
1054
1059
|
let children = [];
|
|
1055
1060
|
if (Array.isArray(rawChildren)) {
|
|
1056
1061
|
children = rawChildren.flat().filter((c) => c !== null && c !== void 0).map(convertReactNode);
|
|
@@ -1106,20 +1111,26 @@ function renderVNode(node, instance) {
|
|
|
1106
1111
|
}
|
|
1107
1112
|
return root;
|
|
1108
1113
|
}
|
|
1109
|
-
let
|
|
1114
|
+
let vnode = node;
|
|
1115
|
+
if ("props" in vnode && (!("children" in vnode) || !Array.isArray(vnode.children) || "$$typeof" in vnode)) {
|
|
1116
|
+
vnode = convertReactNode(vnode);
|
|
1117
|
+
}
|
|
1118
|
+
let targetType = vnode.type;
|
|
1110
1119
|
if (typeof targetType === "object" && targetType !== null) {
|
|
1111
1120
|
if (targetType.$$typeof && targetType.type) {
|
|
1112
1121
|
targetType = targetType.type;
|
|
1113
1122
|
}
|
|
1114
1123
|
if (typeof targetType.render === "function") {
|
|
1115
|
-
const rendered = targetType.render(
|
|
1124
|
+
const rendered = targetType.render(vnode.props, vnode.props?.ref || null);
|
|
1116
1125
|
return renderVNode(convertReactNode(rendered), instance);
|
|
1117
1126
|
}
|
|
1118
1127
|
}
|
|
1128
|
+
const rawChildren = vnode.children ?? vnode.props?.children;
|
|
1129
|
+
const childrenList = Array.isArray(rawChildren) ? rawChildren : rawChildren !== null && rawChildren !== void 0 ? [rawChildren] : [];
|
|
1119
1130
|
if (typeof targetType === "function") {
|
|
1120
1131
|
if (targetType === Fragment) {
|
|
1121
1132
|
const fragment = document.createDocumentFragment();
|
|
1122
|
-
for (const child of
|
|
1133
|
+
for (const child of childrenList) {
|
|
1123
1134
|
fragment.appendChild(renderVNode(child, instance));
|
|
1124
1135
|
}
|
|
1125
1136
|
return fragment;
|
|
@@ -1133,7 +1144,7 @@ function renderVNode(node, instance) {
|
|
|
1133
1144
|
let currentNodes = [];
|
|
1134
1145
|
let currentScope = null;
|
|
1135
1146
|
effect(() => {
|
|
1136
|
-
const whenVal = typeof
|
|
1147
|
+
const whenVal = typeof vnode.props.when === "function" ? vnode.props.when() : vnode.props.when;
|
|
1137
1148
|
if (currentScope) {
|
|
1138
1149
|
currentScope.dispose();
|
|
1139
1150
|
currentScope = null;
|
|
@@ -1145,7 +1156,7 @@ function renderVNode(node, instance) {
|
|
|
1145
1156
|
if (whenVal) {
|
|
1146
1157
|
const { result: rendered, scope: branchScope } = createScope(() => {
|
|
1147
1158
|
const branch = untrack(
|
|
1148
|
-
() => typeof
|
|
1159
|
+
() => typeof vnode.props.children === "function" ? vnode.props.children(whenVal) : vnode.props.children
|
|
1149
1160
|
);
|
|
1150
1161
|
return untrack(() => branch ? renderVNode(branch, instance) : null);
|
|
1151
1162
|
});
|
|
@@ -1155,9 +1166,9 @@ function renderVNode(node, instance) {
|
|
|
1155
1166
|
parent.insertBefore(rendered, endAnchor);
|
|
1156
1167
|
currentNodes.push(rendered);
|
|
1157
1168
|
}
|
|
1158
|
-
} else if (
|
|
1169
|
+
} else if (vnode.props.fallback) {
|
|
1159
1170
|
const { result: rendered, scope: branchScope } = createScope(() => {
|
|
1160
|
-
return untrack(() => renderVNode(
|
|
1171
|
+
return untrack(() => renderVNode(vnode.props.fallback, instance));
|
|
1161
1172
|
});
|
|
1162
1173
|
currentScope = branchScope;
|
|
1163
1174
|
if (rendered) {
|
|
@@ -1172,7 +1183,7 @@ function renderVNode(node, instance) {
|
|
|
1172
1183
|
});
|
|
1173
1184
|
return container;
|
|
1174
1185
|
}
|
|
1175
|
-
if (
|
|
1186
|
+
if (vnode.type === For) {
|
|
1176
1187
|
const container = document.createDocumentFragment();
|
|
1177
1188
|
const startAnchor = document.createComment("agent-dom:for-start");
|
|
1178
1189
|
const endAnchor = document.createComment("agent-dom:for-end");
|
|
@@ -1180,16 +1191,16 @@ function renderVNode(node, instance) {
|
|
|
1180
1191
|
container.appendChild(endAnchor);
|
|
1181
1192
|
let currentMap = /* @__PURE__ */ new Map();
|
|
1182
1193
|
effect(() => {
|
|
1183
|
-
const rawItems = typeof
|
|
1194
|
+
const rawItems = typeof vnode.props.each === "function" ? vnode.props.each() : vnode.props.each || [];
|
|
1184
1195
|
const items = Array.isArray(rawItems) ? rawItems : [];
|
|
1185
1196
|
const newMap = /* @__PURE__ */ new Map();
|
|
1186
1197
|
const parent = endAnchor.parentNode || container;
|
|
1187
1198
|
items.forEach((item, idx) => {
|
|
1188
1199
|
let itemKey;
|
|
1189
|
-
if (typeof
|
|
1190
|
-
itemKey =
|
|
1191
|
-
} else if (
|
|
1192
|
-
itemKey = item[
|
|
1200
|
+
if (typeof vnode.props.key === "function") {
|
|
1201
|
+
itemKey = vnode.props.key(item, idx);
|
|
1202
|
+
} else if (vnode.props.key && typeof item === "object") {
|
|
1203
|
+
itemKey = item[vnode.props.key];
|
|
1193
1204
|
} else {
|
|
1194
1205
|
itemKey = item?.id ?? item?.key ?? (typeof item === "string" ? item : idx);
|
|
1195
1206
|
}
|
|
@@ -1202,7 +1213,7 @@ function renderVNode(node, instance) {
|
|
|
1202
1213
|
} else {
|
|
1203
1214
|
const indexSignal = signal(idx);
|
|
1204
1215
|
const { result: rendered, scope: itemScope } = createScope(() => {
|
|
1205
|
-
const childVNode2 = untrack(() =>
|
|
1216
|
+
const childVNode2 = untrack(() => vnode.props.children(item, () => indexSignal.value));
|
|
1206
1217
|
return untrack(() => renderVNode(childVNode2, instance));
|
|
1207
1218
|
});
|
|
1208
1219
|
existing = { key: itemKey, node: rendered, indexSignal, scope: itemScope };
|
|
@@ -1227,7 +1238,7 @@ function renderVNode(node, instance) {
|
|
|
1227
1238
|
}
|
|
1228
1239
|
if (targetType === ErrorBoundary) {
|
|
1229
1240
|
try {
|
|
1230
|
-
return renderVNode(
|
|
1241
|
+
return renderVNode(vnode.props.children, instance);
|
|
1231
1242
|
} catch (err) {
|
|
1232
1243
|
if (instance?.runtimeLog) {
|
|
1233
1244
|
instance.runtimeLog.push({
|
|
@@ -1236,20 +1247,20 @@ function renderVNode(node, instance) {
|
|
|
1236
1247
|
error: `ErrorBoundary: ${err.message}`
|
|
1237
1248
|
});
|
|
1238
1249
|
}
|
|
1239
|
-
return renderVNode(
|
|
1250
|
+
return renderVNode(vnode.props.fallback(err), instance);
|
|
1240
1251
|
}
|
|
1241
1252
|
}
|
|
1242
|
-
let childVNode = targetType(
|
|
1253
|
+
let childVNode = targetType(vnode.props);
|
|
1243
1254
|
if (typeof childVNode === "function") {
|
|
1244
1255
|
childVNode = childVNode();
|
|
1245
1256
|
}
|
|
1246
1257
|
return renderVNode(childVNode, instance);
|
|
1247
1258
|
}
|
|
1248
|
-
const tagName = typeof
|
|
1259
|
+
const tagName = typeof vnode.type === "string" ? vnode.type : String(vnode.type);
|
|
1249
1260
|
const isSvg = SVG_TAGS.has(tagName.toLowerCase());
|
|
1250
1261
|
const el = isSvg ? document.createElementNS(SVG_NS, tagName) : document.createElement(tagName);
|
|
1251
1262
|
const cleanups = instance?._cleanups;
|
|
1252
|
-
for (const [key, value] of Object.entries(
|
|
1263
|
+
for (const [key, value] of Object.entries(vnode.props || {})) {
|
|
1253
1264
|
if (key === "children") continue;
|
|
1254
1265
|
if (key === "ref") {
|
|
1255
1266
|
if (typeof value === "function") {
|
|
@@ -1280,7 +1291,7 @@ function renderVNode(node, instance) {
|
|
|
1280
1291
|
if (key.startsWith("on") && typeof value === "function") {
|
|
1281
1292
|
const eventName = key.slice(2).toLowerCase();
|
|
1282
1293
|
el.addEventListener(eventName, value);
|
|
1283
|
-
if (value?._actionName && !
|
|
1294
|
+
if (value?._actionName && !vnode.props["data-agent-action"]) {
|
|
1284
1295
|
el.setAttribute("data-agent-action", value._actionName);
|
|
1285
1296
|
}
|
|
1286
1297
|
} else if (key === "class" || key === "className") {
|
|
@@ -1334,7 +1345,7 @@ function renderVNode(node, instance) {
|
|
|
1334
1345
|
el.setAttribute(key, value === true ? "" : String(value));
|
|
1335
1346
|
}
|
|
1336
1347
|
}
|
|
1337
|
-
for (const child of
|
|
1348
|
+
for (const child of childrenList) {
|
|
1338
1349
|
if (typeof child === "function") {
|
|
1339
1350
|
const parentAgentId = el.getAttribute("data-agent-id") || el.tagName.toLowerCase();
|
|
1340
1351
|
const startAnchor = document.createComment(`tokensafe:dyn-start`);
|
|
@@ -1432,44 +1443,50 @@ function vnodeToString(node) {
|
|
|
1432
1443
|
if (Array.isArray(node)) {
|
|
1433
1444
|
return node.map(vnodeToString).join("");
|
|
1434
1445
|
}
|
|
1435
|
-
let
|
|
1446
|
+
let vnode = node;
|
|
1447
|
+
if ("props" in vnode && (!("children" in vnode) || !Array.isArray(vnode.children) || "$$typeof" in vnode)) {
|
|
1448
|
+
vnode = convertReactNode(vnode);
|
|
1449
|
+
}
|
|
1450
|
+
let targetType = vnode.type;
|
|
1436
1451
|
if (typeof targetType === "object" && targetType !== null) {
|
|
1437
1452
|
if (targetType.$$typeof && targetType.type) {
|
|
1438
1453
|
targetType = targetType.type;
|
|
1439
1454
|
}
|
|
1440
1455
|
if (typeof targetType.render === "function") {
|
|
1441
|
-
const rendered = targetType.render(
|
|
1456
|
+
const rendered = targetType.render(vnode.props, vnode.props?.ref || null);
|
|
1442
1457
|
return vnodeToString(convertReactNode(rendered));
|
|
1443
1458
|
}
|
|
1444
1459
|
}
|
|
1460
|
+
const rawChildren = vnode.children ?? vnode.props?.children;
|
|
1461
|
+
const childrenList = Array.isArray(rawChildren) ? rawChildren : rawChildren !== null && rawChildren !== void 0 ? [rawChildren] : [];
|
|
1445
1462
|
if (typeof targetType === "function") {
|
|
1446
1463
|
if (targetType === Fragment) {
|
|
1447
|
-
return
|
|
1464
|
+
return childrenList.map(vnodeToString).join("");
|
|
1448
1465
|
}
|
|
1449
1466
|
if (targetType === Show) {
|
|
1450
|
-
const whenVal = typeof
|
|
1451
|
-
const branch = whenVal ? typeof
|
|
1467
|
+
const whenVal = typeof vnode.props.when === "function" ? vnode.props.when() : vnode.props.when;
|
|
1468
|
+
const branch = whenVal ? typeof vnode.props.children === "function" ? vnode.props.children(whenVal) : vnode.props.children : vnode.props.fallback;
|
|
1452
1469
|
return branch ? vnodeToString(branch) : "";
|
|
1453
1470
|
}
|
|
1454
1471
|
if (targetType === For) {
|
|
1455
|
-
const rawItems = typeof
|
|
1472
|
+
const rawItems = typeof vnode.props.each === "function" ? vnode.props.each() : vnode.props.each || [];
|
|
1456
1473
|
const items = Array.isArray(rawItems) ? rawItems : [];
|
|
1457
1474
|
return items.map((item, idx) => {
|
|
1458
|
-
const childNode =
|
|
1475
|
+
const childNode = vnode.props.children(item, () => idx);
|
|
1459
1476
|
return vnodeToString(childNode);
|
|
1460
1477
|
}).join("");
|
|
1461
1478
|
}
|
|
1462
1479
|
if (targetType === ErrorBoundary) {
|
|
1463
1480
|
try {
|
|
1464
|
-
return vnodeToString(
|
|
1481
|
+
return vnodeToString(vnode.props.children);
|
|
1465
1482
|
} catch (err) {
|
|
1466
|
-
return vnodeToString(
|
|
1483
|
+
return vnodeToString(vnode.props.fallback(err));
|
|
1467
1484
|
}
|
|
1468
1485
|
}
|
|
1469
|
-
return vnodeToString(targetType(
|
|
1486
|
+
return vnodeToString(targetType(vnode.props));
|
|
1470
1487
|
}
|
|
1471
1488
|
const attrs = [];
|
|
1472
|
-
for (let [key, value] of Object.entries(
|
|
1489
|
+
for (let [key, value] of Object.entries(vnode.props || {})) {
|
|
1473
1490
|
if (key === "children" || key.startsWith("on")) continue;
|
|
1474
1491
|
if (typeof value === "function") {
|
|
1475
1492
|
try {
|
|
@@ -1487,15 +1504,15 @@ function vnodeToString(node) {
|
|
|
1487
1504
|
}
|
|
1488
1505
|
}
|
|
1489
1506
|
const attrStr = attrs.length > 0 ? " " + attrs.join(" ") : "";
|
|
1490
|
-
if (
|
|
1491
|
-
return `<${
|
|
1507
|
+
if (vnode.props?.dangerouslySetInnerHTML?.__html) {
|
|
1508
|
+
return `<${vnode.type}${attrStr}>${vnode.props.dangerouslySetInnerHTML.__html}</${vnode.type}>`;
|
|
1492
1509
|
}
|
|
1493
|
-
if (
|
|
1494
|
-
const raw = typeof
|
|
1495
|
-
return `<${
|
|
1510
|
+
if (vnode.props?.innerHTML) {
|
|
1511
|
+
const raw = typeof vnode.props.innerHTML === "function" ? vnode.props.innerHTML() : vnode.props.innerHTML;
|
|
1512
|
+
return `<${vnode.type}${attrStr}>${raw}</${vnode.type}>`;
|
|
1496
1513
|
}
|
|
1497
|
-
const childrenStr =
|
|
1498
|
-
return `<${
|
|
1514
|
+
const childrenStr = childrenList.map(vnodeToString).join("");
|
|
1515
|
+
return `<${vnode.type}${attrStr}>${childrenStr}</${vnode.type}>`;
|
|
1499
1516
|
}
|
|
1500
1517
|
function escapeHtml(str) {
|
|
1501
1518
|
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildDependencyGraph,
|
|
3
3
|
observeDiff
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-4PIOAQC3.js";
|
|
5
5
|
import {
|
|
6
6
|
applyPatch
|
|
7
7
|
} from "./chunk-N7XIVYCL.js";
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
activeInstances,
|
|
10
10
|
testAction,
|
|
11
11
|
testEffect
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-GBP5S5VP.js";
|
|
13
13
|
|
|
14
14
|
// ../mcp/dist/index.js
|
|
15
15
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
atomicApplySourceEdit,
|
|
3
3
|
validateWorkspacePath
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-GVVBOP4E.js";
|
|
5
5
|
import {
|
|
6
6
|
buildDependencyGraph,
|
|
7
7
|
observe
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-4PIOAQC3.js";
|
|
9
9
|
import {
|
|
10
10
|
testAction
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-GBP5S5VP.js";
|
|
12
12
|
|
|
13
13
|
// ../oumv/dist/chunk-ONAJHNWR.js
|
|
14
14
|
import fs from "fs";
|
package/dist/cli.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
startMcpServer
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-2YH7IQ3P.js";
|
|
4
|
+
import "./chunk-GVVBOP4E.js";
|
|
5
|
+
import "./chunk-4PIOAQC3.js";
|
|
6
6
|
import "./chunk-N7XIVYCL.js";
|
|
7
|
-
import "./chunk-
|
|
7
|
+
import "./chunk-GBP5S5VP.js";
|
|
8
8
|
|
|
9
9
|
// src/cli.ts
|
|
10
10
|
function parseCliArgs(argv) {
|
package/dist/index.cjs
CHANGED
|
@@ -897,8 +897,14 @@ var SVG_TAGS = /* @__PURE__ */ new Set([
|
|
|
897
897
|
]);
|
|
898
898
|
function h(type, props, ...children) {
|
|
899
899
|
const normalizedProps = props || {};
|
|
900
|
-
|
|
901
|
-
if (flatChildren.length
|
|
900
|
+
let flatChildren = children.flat().filter((c) => c !== null && c !== void 0);
|
|
901
|
+
if (flatChildren.length === 0 && normalizedProps.children) {
|
|
902
|
+
if (Array.isArray(normalizedProps.children)) {
|
|
903
|
+
flatChildren = normalizedProps.children.flat().filter((c) => c !== null && c !== void 0);
|
|
904
|
+
} else {
|
|
905
|
+
flatChildren = [normalizedProps.children];
|
|
906
|
+
}
|
|
907
|
+
} else if (flatChildren.length > 0 && !normalizedProps.children) {
|
|
902
908
|
normalizedProps.children = flatChildren.length === 1 ? flatChildren[0] : flatChildren;
|
|
903
909
|
}
|
|
904
910
|
return {
|
|
@@ -1110,7 +1116,6 @@ function convertReactNode(rn) {
|
|
|
1110
1116
|
if ("props" in rn && "type" in rn) {
|
|
1111
1117
|
const props = { ...rn.props || {} };
|
|
1112
1118
|
const rawChildren = props.children;
|
|
1113
|
-
delete props.children;
|
|
1114
1119
|
let children = [];
|
|
1115
1120
|
if (Array.isArray(rawChildren)) {
|
|
1116
1121
|
children = rawChildren.flat().filter((c) => c !== null && c !== void 0).map(convertReactNode);
|
|
@@ -1166,20 +1171,26 @@ function renderVNode(node, instance) {
|
|
|
1166
1171
|
}
|
|
1167
1172
|
return root;
|
|
1168
1173
|
}
|
|
1169
|
-
let
|
|
1174
|
+
let vnode = node;
|
|
1175
|
+
if ("props" in vnode && (!("children" in vnode) || !Array.isArray(vnode.children) || "$$typeof" in vnode)) {
|
|
1176
|
+
vnode = convertReactNode(vnode);
|
|
1177
|
+
}
|
|
1178
|
+
let targetType = vnode.type;
|
|
1170
1179
|
if (typeof targetType === "object" && targetType !== null) {
|
|
1171
1180
|
if (targetType.$$typeof && targetType.type) {
|
|
1172
1181
|
targetType = targetType.type;
|
|
1173
1182
|
}
|
|
1174
1183
|
if (typeof targetType.render === "function") {
|
|
1175
|
-
const rendered = targetType.render(
|
|
1184
|
+
const rendered = targetType.render(vnode.props, vnode.props?.ref || null);
|
|
1176
1185
|
return renderVNode(convertReactNode(rendered), instance);
|
|
1177
1186
|
}
|
|
1178
1187
|
}
|
|
1188
|
+
const rawChildren = vnode.children ?? vnode.props?.children;
|
|
1189
|
+
const childrenList = Array.isArray(rawChildren) ? rawChildren : rawChildren !== null && rawChildren !== void 0 ? [rawChildren] : [];
|
|
1179
1190
|
if (typeof targetType === "function") {
|
|
1180
1191
|
if (targetType === Fragment) {
|
|
1181
1192
|
const fragment = document.createDocumentFragment();
|
|
1182
|
-
for (const child of
|
|
1193
|
+
for (const child of childrenList) {
|
|
1183
1194
|
fragment.appendChild(renderVNode(child, instance));
|
|
1184
1195
|
}
|
|
1185
1196
|
return fragment;
|
|
@@ -1193,7 +1204,7 @@ function renderVNode(node, instance) {
|
|
|
1193
1204
|
let currentNodes = [];
|
|
1194
1205
|
let currentScope = null;
|
|
1195
1206
|
effect(() => {
|
|
1196
|
-
const whenVal = typeof
|
|
1207
|
+
const whenVal = typeof vnode.props.when === "function" ? vnode.props.when() : vnode.props.when;
|
|
1197
1208
|
if (currentScope) {
|
|
1198
1209
|
currentScope.dispose();
|
|
1199
1210
|
currentScope = null;
|
|
@@ -1205,7 +1216,7 @@ function renderVNode(node, instance) {
|
|
|
1205
1216
|
if (whenVal) {
|
|
1206
1217
|
const { result: rendered, scope: branchScope } = createScope(() => {
|
|
1207
1218
|
const branch = untrack(
|
|
1208
|
-
() => typeof
|
|
1219
|
+
() => typeof vnode.props.children === "function" ? vnode.props.children(whenVal) : vnode.props.children
|
|
1209
1220
|
);
|
|
1210
1221
|
return untrack(() => branch ? renderVNode(branch, instance) : null);
|
|
1211
1222
|
});
|
|
@@ -1215,9 +1226,9 @@ function renderVNode(node, instance) {
|
|
|
1215
1226
|
parent.insertBefore(rendered, endAnchor);
|
|
1216
1227
|
currentNodes.push(rendered);
|
|
1217
1228
|
}
|
|
1218
|
-
} else if (
|
|
1229
|
+
} else if (vnode.props.fallback) {
|
|
1219
1230
|
const { result: rendered, scope: branchScope } = createScope(() => {
|
|
1220
|
-
return untrack(() => renderVNode(
|
|
1231
|
+
return untrack(() => renderVNode(vnode.props.fallback, instance));
|
|
1221
1232
|
});
|
|
1222
1233
|
currentScope = branchScope;
|
|
1223
1234
|
if (rendered) {
|
|
@@ -1232,7 +1243,7 @@ function renderVNode(node, instance) {
|
|
|
1232
1243
|
});
|
|
1233
1244
|
return container;
|
|
1234
1245
|
}
|
|
1235
|
-
if (
|
|
1246
|
+
if (vnode.type === For) {
|
|
1236
1247
|
const container = document.createDocumentFragment();
|
|
1237
1248
|
const startAnchor = document.createComment("agent-dom:for-start");
|
|
1238
1249
|
const endAnchor = document.createComment("agent-dom:for-end");
|
|
@@ -1240,16 +1251,16 @@ function renderVNode(node, instance) {
|
|
|
1240
1251
|
container.appendChild(endAnchor);
|
|
1241
1252
|
let currentMap = /* @__PURE__ */ new Map();
|
|
1242
1253
|
effect(() => {
|
|
1243
|
-
const rawItems = typeof
|
|
1254
|
+
const rawItems = typeof vnode.props.each === "function" ? vnode.props.each() : vnode.props.each || [];
|
|
1244
1255
|
const items = Array.isArray(rawItems) ? rawItems : [];
|
|
1245
1256
|
const newMap = /* @__PURE__ */ new Map();
|
|
1246
1257
|
const parent = endAnchor.parentNode || container;
|
|
1247
1258
|
items.forEach((item, idx) => {
|
|
1248
1259
|
let itemKey;
|
|
1249
|
-
if (typeof
|
|
1250
|
-
itemKey =
|
|
1251
|
-
} else if (
|
|
1252
|
-
itemKey = item[
|
|
1260
|
+
if (typeof vnode.props.key === "function") {
|
|
1261
|
+
itemKey = vnode.props.key(item, idx);
|
|
1262
|
+
} else if (vnode.props.key && typeof item === "object") {
|
|
1263
|
+
itemKey = item[vnode.props.key];
|
|
1253
1264
|
} else {
|
|
1254
1265
|
itemKey = item?.id ?? item?.key ?? (typeof item === "string" ? item : idx);
|
|
1255
1266
|
}
|
|
@@ -1262,7 +1273,7 @@ function renderVNode(node, instance) {
|
|
|
1262
1273
|
} else {
|
|
1263
1274
|
const indexSignal = signal(idx);
|
|
1264
1275
|
const { result: rendered, scope: itemScope } = createScope(() => {
|
|
1265
|
-
const childVNode2 = untrack(() =>
|
|
1276
|
+
const childVNode2 = untrack(() => vnode.props.children(item, () => indexSignal.value));
|
|
1266
1277
|
return untrack(() => renderVNode(childVNode2, instance));
|
|
1267
1278
|
});
|
|
1268
1279
|
existing = { key: itemKey, node: rendered, indexSignal, scope: itemScope };
|
|
@@ -1287,7 +1298,7 @@ function renderVNode(node, instance) {
|
|
|
1287
1298
|
}
|
|
1288
1299
|
if (targetType === ErrorBoundary) {
|
|
1289
1300
|
try {
|
|
1290
|
-
return renderVNode(
|
|
1301
|
+
return renderVNode(vnode.props.children, instance);
|
|
1291
1302
|
} catch (err) {
|
|
1292
1303
|
if (instance?.runtimeLog) {
|
|
1293
1304
|
instance.runtimeLog.push({
|
|
@@ -1296,20 +1307,20 @@ function renderVNode(node, instance) {
|
|
|
1296
1307
|
error: `ErrorBoundary: ${err.message}`
|
|
1297
1308
|
});
|
|
1298
1309
|
}
|
|
1299
|
-
return renderVNode(
|
|
1310
|
+
return renderVNode(vnode.props.fallback(err), instance);
|
|
1300
1311
|
}
|
|
1301
1312
|
}
|
|
1302
|
-
let childVNode = targetType(
|
|
1313
|
+
let childVNode = targetType(vnode.props);
|
|
1303
1314
|
if (typeof childVNode === "function") {
|
|
1304
1315
|
childVNode = childVNode();
|
|
1305
1316
|
}
|
|
1306
1317
|
return renderVNode(childVNode, instance);
|
|
1307
1318
|
}
|
|
1308
|
-
const tagName = typeof
|
|
1319
|
+
const tagName = typeof vnode.type === "string" ? vnode.type : String(vnode.type);
|
|
1309
1320
|
const isSvg = SVG_TAGS.has(tagName.toLowerCase());
|
|
1310
1321
|
const el = isSvg ? document.createElementNS(SVG_NS, tagName) : document.createElement(tagName);
|
|
1311
1322
|
const cleanups = instance?._cleanups;
|
|
1312
|
-
for (const [key, value] of Object.entries(
|
|
1323
|
+
for (const [key, value] of Object.entries(vnode.props || {})) {
|
|
1313
1324
|
if (key === "children") continue;
|
|
1314
1325
|
if (key === "ref") {
|
|
1315
1326
|
if (typeof value === "function") {
|
|
@@ -1340,7 +1351,7 @@ function renderVNode(node, instance) {
|
|
|
1340
1351
|
if (key.startsWith("on") && typeof value === "function") {
|
|
1341
1352
|
const eventName = key.slice(2).toLowerCase();
|
|
1342
1353
|
el.addEventListener(eventName, value);
|
|
1343
|
-
if (value?._actionName && !
|
|
1354
|
+
if (value?._actionName && !vnode.props["data-agent-action"]) {
|
|
1344
1355
|
el.setAttribute("data-agent-action", value._actionName);
|
|
1345
1356
|
}
|
|
1346
1357
|
} else if (key === "class" || key === "className") {
|
|
@@ -1394,7 +1405,7 @@ function renderVNode(node, instance) {
|
|
|
1394
1405
|
el.setAttribute(key, value === true ? "" : String(value));
|
|
1395
1406
|
}
|
|
1396
1407
|
}
|
|
1397
|
-
for (const child of
|
|
1408
|
+
for (const child of childrenList) {
|
|
1398
1409
|
if (typeof child === "function") {
|
|
1399
1410
|
const parentAgentId = el.getAttribute("data-agent-id") || el.tagName.toLowerCase();
|
|
1400
1411
|
const startAnchor = document.createComment(`tokensafe:dyn-start`);
|
|
@@ -1492,44 +1503,50 @@ function vnodeToString(node) {
|
|
|
1492
1503
|
if (Array.isArray(node)) {
|
|
1493
1504
|
return node.map(vnodeToString).join("");
|
|
1494
1505
|
}
|
|
1495
|
-
let
|
|
1506
|
+
let vnode = node;
|
|
1507
|
+
if ("props" in vnode && (!("children" in vnode) || !Array.isArray(vnode.children) || "$$typeof" in vnode)) {
|
|
1508
|
+
vnode = convertReactNode(vnode);
|
|
1509
|
+
}
|
|
1510
|
+
let targetType = vnode.type;
|
|
1496
1511
|
if (typeof targetType === "object" && targetType !== null) {
|
|
1497
1512
|
if (targetType.$$typeof && targetType.type) {
|
|
1498
1513
|
targetType = targetType.type;
|
|
1499
1514
|
}
|
|
1500
1515
|
if (typeof targetType.render === "function") {
|
|
1501
|
-
const rendered = targetType.render(
|
|
1516
|
+
const rendered = targetType.render(vnode.props, vnode.props?.ref || null);
|
|
1502
1517
|
return vnodeToString(convertReactNode(rendered));
|
|
1503
1518
|
}
|
|
1504
1519
|
}
|
|
1520
|
+
const rawChildren = vnode.children ?? vnode.props?.children;
|
|
1521
|
+
const childrenList = Array.isArray(rawChildren) ? rawChildren : rawChildren !== null && rawChildren !== void 0 ? [rawChildren] : [];
|
|
1505
1522
|
if (typeof targetType === "function") {
|
|
1506
1523
|
if (targetType === Fragment) {
|
|
1507
|
-
return
|
|
1524
|
+
return childrenList.map(vnodeToString).join("");
|
|
1508
1525
|
}
|
|
1509
1526
|
if (targetType === Show) {
|
|
1510
|
-
const whenVal = typeof
|
|
1511
|
-
const branch = whenVal ? typeof
|
|
1527
|
+
const whenVal = typeof vnode.props.when === "function" ? vnode.props.when() : vnode.props.when;
|
|
1528
|
+
const branch = whenVal ? typeof vnode.props.children === "function" ? vnode.props.children(whenVal) : vnode.props.children : vnode.props.fallback;
|
|
1512
1529
|
return branch ? vnodeToString(branch) : "";
|
|
1513
1530
|
}
|
|
1514
1531
|
if (targetType === For) {
|
|
1515
|
-
const rawItems = typeof
|
|
1532
|
+
const rawItems = typeof vnode.props.each === "function" ? vnode.props.each() : vnode.props.each || [];
|
|
1516
1533
|
const items = Array.isArray(rawItems) ? rawItems : [];
|
|
1517
1534
|
return items.map((item, idx) => {
|
|
1518
|
-
const childNode =
|
|
1535
|
+
const childNode = vnode.props.children(item, () => idx);
|
|
1519
1536
|
return vnodeToString(childNode);
|
|
1520
1537
|
}).join("");
|
|
1521
1538
|
}
|
|
1522
1539
|
if (targetType === ErrorBoundary) {
|
|
1523
1540
|
try {
|
|
1524
|
-
return vnodeToString(
|
|
1541
|
+
return vnodeToString(vnode.props.children);
|
|
1525
1542
|
} catch (err) {
|
|
1526
|
-
return vnodeToString(
|
|
1543
|
+
return vnodeToString(vnode.props.fallback(err));
|
|
1527
1544
|
}
|
|
1528
1545
|
}
|
|
1529
|
-
return vnodeToString(targetType(
|
|
1546
|
+
return vnodeToString(targetType(vnode.props));
|
|
1530
1547
|
}
|
|
1531
1548
|
const attrs = [];
|
|
1532
|
-
for (let [key, value] of Object.entries(
|
|
1549
|
+
for (let [key, value] of Object.entries(vnode.props || {})) {
|
|
1533
1550
|
if (key === "children" || key.startsWith("on")) continue;
|
|
1534
1551
|
if (typeof value === "function") {
|
|
1535
1552
|
try {
|
|
@@ -1547,15 +1564,15 @@ function vnodeToString(node) {
|
|
|
1547
1564
|
}
|
|
1548
1565
|
}
|
|
1549
1566
|
const attrStr = attrs.length > 0 ? " " + attrs.join(" ") : "";
|
|
1550
|
-
if (
|
|
1551
|
-
return `<${
|
|
1567
|
+
if (vnode.props?.dangerouslySetInnerHTML?.__html) {
|
|
1568
|
+
return `<${vnode.type}${attrStr}>${vnode.props.dangerouslySetInnerHTML.__html}</${vnode.type}>`;
|
|
1552
1569
|
}
|
|
1553
|
-
if (
|
|
1554
|
-
const raw = typeof
|
|
1555
|
-
return `<${
|
|
1570
|
+
if (vnode.props?.innerHTML) {
|
|
1571
|
+
const raw = typeof vnode.props.innerHTML === "function" ? vnode.props.innerHTML() : vnode.props.innerHTML;
|
|
1572
|
+
return `<${vnode.type}${attrStr}>${raw}</${vnode.type}>`;
|
|
1556
1573
|
}
|
|
1557
|
-
const childrenStr =
|
|
1558
|
-
return `<${
|
|
1574
|
+
const childrenStr = childrenList.map(vnodeToString).join("");
|
|
1575
|
+
return `<${vnode.type}${attrStr}>${childrenStr}</${vnode.type}>`;
|
|
1559
1576
|
}
|
|
1560
1577
|
function escapeHtml(str) {
|
|
1561
1578
|
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
type AgentChild = string | number | boolean | null | undefined | ((...args: any[]) => any) | AgentVNode;
|
|
2
|
+
interface AgentVNodeProps {
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
class?: string | (() => string);
|
|
5
|
+
className?: string | (() => string);
|
|
6
|
+
style?: string | Record<string, string>;
|
|
7
|
+
children?: any;
|
|
8
|
+
'data-agent-id'?: string;
|
|
9
|
+
onClick?: (e: any) => void;
|
|
10
|
+
onChange?: (e: any) => void;
|
|
11
|
+
onInput?: (e: any) => void;
|
|
12
|
+
onSubmit?: (e: any) => void;
|
|
13
|
+
}
|
|
14
|
+
interface AgentVNode {
|
|
15
|
+
type: string | ((props: any) => any);
|
|
16
|
+
props: AgentVNodeProps;
|
|
17
|
+
children: AgentChild[];
|
|
18
|
+
agentId?: string;
|
|
19
|
+
isControlFlow?: boolean;
|
|
20
|
+
}
|
|
21
|
+
declare global {
|
|
22
|
+
namespace JSX {
|
|
23
|
+
interface Element extends AgentVNode {
|
|
24
|
+
}
|
|
25
|
+
interface ElementClass {
|
|
26
|
+
render(): any;
|
|
27
|
+
}
|
|
28
|
+
interface IntrinsicElements {
|
|
29
|
+
[elemName: string]: any;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
interface StateDiff {
|
|
34
|
+
[key: string]: {
|
|
35
|
+
before: any;
|
|
36
|
+
after: any;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
interface SurfaceDiffItem {
|
|
40
|
+
op: 'attr' | 'text' | 'visibility';
|
|
41
|
+
target: string;
|
|
42
|
+
attr?: string;
|
|
43
|
+
before?: any;
|
|
44
|
+
after?: any;
|
|
45
|
+
}
|
|
46
|
+
interface VerificationTimings {
|
|
47
|
+
t_action_ms: number;
|
|
48
|
+
t_schema_ms: number;
|
|
49
|
+
t_propagation_ms: number;
|
|
50
|
+
t_dom_ms: number;
|
|
51
|
+
t_total_ms: number;
|
|
52
|
+
}
|
|
53
|
+
interface AssertionMismatch {
|
|
54
|
+
key: string;
|
|
55
|
+
expected: any;
|
|
56
|
+
received: any;
|
|
57
|
+
message: string;
|
|
58
|
+
}
|
|
59
|
+
interface TestActionResult {
|
|
60
|
+
status: 'passed' | 'failed';
|
|
61
|
+
componentId: string;
|
|
62
|
+
action: string;
|
|
63
|
+
diff: StateDiff;
|
|
64
|
+
surfaceDiff?: SurfaceDiffItem[];
|
|
65
|
+
timings: VerificationTimings;
|
|
66
|
+
durationMs: number;
|
|
67
|
+
assertionMismatch?: AssertionMismatch;
|
|
68
|
+
error?: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type { TestActionResult as T };
|