@standardagents/builder 0.8.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.
package/dist/rou3.js ADDED
@@ -0,0 +1,157 @@
1
+ // ../../node_modules/.pnpm/rou3@0.7.9/node_modules/rou3/dist/index.mjs
2
+ var NullProtoObj = /* @__PURE__ */ (() => {
3
+ const e = function() {
4
+ };
5
+ return e.prototype = /* @__PURE__ */ Object.create(null), Object.freeze(e.prototype), e;
6
+ })();
7
+ function createRouter() {
8
+ return {
9
+ root: { key: "" },
10
+ static: new NullProtoObj()
11
+ };
12
+ }
13
+ function splitPath(path) {
14
+ const [_, ...s] = path.split("/");
15
+ return s[s.length - 1] === "" ? s.slice(0, -1) : s;
16
+ }
17
+ function getMatchParams(segments, paramsMap) {
18
+ const params = new NullProtoObj();
19
+ for (const [index, name] of paramsMap) {
20
+ const segment = index < 0 ? segments.slice(-1 * index).join("/") : segments[index];
21
+ if (typeof name === "string") params[name] = segment;
22
+ else {
23
+ const match = segment.match(name);
24
+ if (match) for (const key in match.groups) params[key] = match.groups[key];
25
+ }
26
+ }
27
+ return params;
28
+ }
29
+ function addRoute(ctx, method = "", path, data) {
30
+ method = method.toUpperCase();
31
+ if (path.charCodeAt(0) !== 47) path = `/${path}`;
32
+ const segments = splitPath(path);
33
+ let node = ctx.root;
34
+ let _unnamedParamIndex = 0;
35
+ const paramsMap = [];
36
+ const paramsRegexp = [];
37
+ for (let i = 0; i < segments.length; i++) {
38
+ const segment = segments[i];
39
+ if (segment.startsWith("**")) {
40
+ if (!node.wildcard) node.wildcard = { key: "**" };
41
+ node = node.wildcard;
42
+ paramsMap.push([
43
+ -i,
44
+ segment.split(":")[1] || "_",
45
+ segment.length === 2
46
+ ]);
47
+ break;
48
+ }
49
+ if (segment === "*" || segment.includes(":")) {
50
+ if (!node.param) node.param = { key: "*" };
51
+ node = node.param;
52
+ if (segment === "*") paramsMap.push([
53
+ i,
54
+ `_${_unnamedParamIndex++}`,
55
+ true
56
+ ]);
57
+ else if (segment.includes(":", 1)) {
58
+ const regexp = getParamRegexp(segment);
59
+ paramsRegexp[i] = regexp;
60
+ node.hasRegexParam = true;
61
+ paramsMap.push([
62
+ i,
63
+ regexp,
64
+ false
65
+ ]);
66
+ } else paramsMap.push([
67
+ i,
68
+ segment.slice(1),
69
+ false
70
+ ]);
71
+ continue;
72
+ }
73
+ const child = node.static?.[segment];
74
+ if (child) node = child;
75
+ else {
76
+ const staticNode = { key: segment };
77
+ if (!node.static) node.static = new NullProtoObj();
78
+ node.static[segment] = staticNode;
79
+ node = staticNode;
80
+ }
81
+ }
82
+ const hasParams = paramsMap.length > 0;
83
+ if (!node.methods) node.methods = new NullProtoObj();
84
+ node.methods[method] ??= [];
85
+ node.methods[method].push({
86
+ data: data || null,
87
+ paramsRegexp,
88
+ paramsMap: hasParams ? paramsMap : void 0
89
+ });
90
+ if (!hasParams) ctx.static[path] = node;
91
+ }
92
+ function getParamRegexp(segment) {
93
+ const regex = segment.replace(/:(\w+)/g, (_, id) => `(?<${id}>[^/]+)`).replace(/\./g, "\\.");
94
+ return /* @__PURE__ */ new RegExp(`^${regex}$`);
95
+ }
96
+ function findRoute(ctx, method = "", path, opts) {
97
+ if (path.charCodeAt(path.length - 1) === 47) path = path.slice(0, -1);
98
+ const staticNode = ctx.static[path];
99
+ if (staticNode && staticNode.methods) {
100
+ const staticMatch = staticNode.methods[method] || staticNode.methods[""];
101
+ if (staticMatch !== void 0) return staticMatch[0];
102
+ }
103
+ const segments = splitPath(path);
104
+ const match = _lookupTree(ctx, ctx.root, method, segments, 0)?.[0];
105
+ if (match === void 0) return;
106
+ if (opts?.params === false) return match;
107
+ return {
108
+ data: match.data,
109
+ params: match.paramsMap ? getMatchParams(segments, match.paramsMap) : void 0
110
+ };
111
+ }
112
+ function _lookupTree(ctx, node, method, segments, index) {
113
+ if (index === segments.length) {
114
+ if (node.methods) {
115
+ const match = node.methods[method] || node.methods[""];
116
+ if (match) return match;
117
+ }
118
+ if (node.param && node.param.methods) {
119
+ const match = node.param.methods[method] || node.param.methods[""];
120
+ if (match) {
121
+ const pMap = match[0].paramsMap;
122
+ if (pMap?.[pMap?.length - 1]?.[2]) return match;
123
+ }
124
+ }
125
+ if (node.wildcard && node.wildcard.methods) {
126
+ const match = node.wildcard.methods[method] || node.wildcard.methods[""];
127
+ if (match) {
128
+ const pMap = match[0].paramsMap;
129
+ if (pMap?.[pMap?.length - 1]?.[2]) return match;
130
+ }
131
+ }
132
+ return;
133
+ }
134
+ const segment = segments[index];
135
+ if (node.static) {
136
+ const staticChild = node.static[segment];
137
+ if (staticChild) {
138
+ const match = _lookupTree(ctx, staticChild, method, segments, index + 1);
139
+ if (match) return match;
140
+ }
141
+ }
142
+ if (node.param) {
143
+ const match = _lookupTree(ctx, node.param, method, segments, index + 1);
144
+ if (match) {
145
+ if (node.param.hasRegexParam) {
146
+ const exactMatch = match.find((m) => m.paramsRegexp[index]?.test(segment)) || match.find((m) => !m.paramsRegexp[index]);
147
+ return exactMatch ? [exactMatch] : void 0;
148
+ }
149
+ return match;
150
+ }
151
+ }
152
+ if (node.wildcard && node.wildcard.methods) return node.wildcard.methods[method] || node.wildcard.methods[""];
153
+ }
154
+
155
+ export { addRoute, createRouter, findRoute };
156
+ //# sourceMappingURL=rou3.js.map
157
+ //# sourceMappingURL=rou3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../node_modules/.pnpm/rou3@0.7.9/node_modules/rou3/dist/index.mjs"],"names":[],"mappings":";AAAA,IAAM,+BAAgC,CAAA,MAAM;AAC3C,EAAA,MAAM,IAAI,WAAW;AAAA,EAAC,CAAA;AACtB,EAAA,OAAO,CAAA,CAAE,SAAA,mBAAY,MAAA,CAAO,MAAA,CAAO,IAAI,GAAG,MAAA,CAAO,MAAA,CAAO,CAAA,CAAE,SAAS,CAAA,EAAG,CAAA;AACvE,CAAA,GAAG;AAKH,SAAS,YAAA,GAAe;AACvB,EAAA,OAAO;AAAA,IACN,I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K,CAAA;AAC9B,EAAA,IAAI,KAAK,MAAA,EAAQ;AAChB,IAAA,MAAM,WAAA,GAAc,IAAA,CAAK,MAAA,CAAO,OAAO,CAAA;AACvC,IAAA,IAAI,WAAA,EAAa;AAChB,MAAA,MAAM,QAAQ,WAAA,CAAY,GAAA,EAAK,aAAa,MAAA,EAAQ,QAAA,EAAU,QAAQ,CAAC,CAAA;AACvE,MAAA,IAAI,OAAO,OAAO,KAAA;AAAA,IACnB;AAAA,EACD;AACA,EAAA,IAAI,KAAK,KAAA,EAAO;AACf,IAAA,MAAM,KAAA,GAAQ,YAAY,GAAA,EAAK,IAAA,CAAK,OAAO,MAAA,EAAQ,QAAA,EAAU,QAAQ,CAAC,CAAA;AACtE,IAAA,IAAI,KAAA,EAAO;AACV,MAAA,IAAI,IAAA,CAAK,MAAM,aAAA,EAAe;AAC7B,QAAA,MAAM,UAAA,GAAa,MAAM,IAAA,CAAK,CAAC,MAAM,CAAA,CAAE,YAAA,CAAa,KAAK,CAAA,EAAG,IAAA,CAAK,OAAO,CAAC,CAAA,IAAK,MAAM,IAAA,CAAK,CAAC,MAAM,CAAC,CAAA,CAAE,YAAA,CAAa,KAAK,CAAC,CAAA;AACtH,QAAA,OAAO,UAAA,GAAa,CAAC,UAAU,CAAA,GAAI,MAAA;AAAA,MACpC;AACA,MAAA,OAAO,KAAA;AAAA,IACR;AAAA,EACD;AACA,EAAA,IAAI,IAAA,CAAK,QAAA,IAAY,IAAA,CAAK,QAAA,CAAS,SAAS,OAAO,IAAA,CAAK,QAAA,CAAS,OAAA,CAAQ,MAAM,CAAA,IAAK,IAAA,CAAK,QAAA,CAAS,QAAQ,EAAE,CAAA;AAC7G","file":"rou3.js","sourcesContent":["const NullProtoObj = /* @__PURE__ */ (() => {\n\tconst e = function() {};\n\treturn e.prototype = Object.create(null), Object.freeze(e.prototype), e;\n})();\n\n/**\n* Create a new router context.\n*/\nfunction createRouter() {\n\treturn {\n\t\troot: { key: \"\" },\n\t\tstatic: new NullProtoObj()\n\t};\n}\n\nfunction splitPath(path) {\n\tconst [_, ...s] = path.split(\"/\");\n\treturn s[s.length - 1] === \"\" ? s.slice(0, -1) : s;\n}\nfunction getMatchParams(segments, paramsMap) {\n\tconst params = new NullProtoObj();\n\tfor (const [index, name] of paramsMap) {\n\t\tconst segment = index < 0 ? segments.slice(-1 * index).join(\"/\") : segments[index];\n\t\tif (typeof name === \"string\") params[name] = segment;\n\t\telse {\n\t\t\tconst match = segment.match(name);\n\t\t\tif (match) for (const key in match.groups) params[key] = match.groups[key];\n\t\t}\n\t}\n\treturn params;\n}\n\n/**\n* Add a route to the router context.\n*/\nfunction addRoute(ctx, method = \"\", path, data) {\n\tmethod = method.toUpperCase();\n\tif (path.charCodeAt(0) !== 47) path = `/${path}`;\n\tconst segments = splitPath(path);\n\tlet node = ctx.root;\n\tlet _unnamedParamIndex = 0;\n\tconst paramsMap = [];\n\tconst paramsRegexp = [];\n\tfor (let i = 0; i < segments.length; i++) {\n\t\tconst segment = segments[i];\n\t\tif (segment.startsWith(\"**\")) {\n\t\t\tif (!node.wildcard) node.wildcard = { key: \"**\" };\n\t\t\tnode = node.wildcard;\n\t\t\tparamsMap.push([\n\t\t\t\t-i,\n\t\t\t\tsegment.split(\":\")[1] || \"_\",\n\t\t\t\tsegment.length === 2\n\t\t\t]);\n\t\t\tbreak;\n\t\t}\n\t\tif (segment === \"*\" || segment.includes(\":\")) {\n\t\t\tif (!node.param) node.param = { key: \"*\" };\n\t\t\tnode = node.param;\n\t\t\tif (segment === \"*\") paramsMap.push([\n\t\t\t\ti,\n\t\t\t\t`_${_unnamedParamIndex++}`,\n\t\t\t\ttrue\n\t\t\t]);\n\t\t\telse if (segment.includes(\":\", 1)) {\n\t\t\t\tconst regexp = getParamRegexp(segment);\n\t\t\t\tparamsRegexp[i] = regexp;\n\t\t\t\tnode.hasRegexParam = true;\n\t\t\t\tparamsMap.push([\n\t\t\t\t\ti,\n\t\t\t\t\tregexp,\n\t\t\t\t\tfalse\n\t\t\t\t]);\n\t\t\t} else paramsMap.push([\n\t\t\t\ti,\n\t\t\t\tsegment.slice(1),\n\t\t\t\tfalse\n\t\t\t]);\n\t\t\tcontinue;\n\t\t}\n\t\tconst child = node.static?.[segment];\n\t\tif (child) node = child;\n\t\telse {\n\t\t\tconst staticNode = { key: segment };\n\t\t\tif (!node.static) node.static = new NullProtoObj();\n\t\t\tnode.static[segment] = staticNode;\n\t\t\tnode = staticNode;\n\t\t}\n\t}\n\tconst hasParams = paramsMap.length > 0;\n\tif (!node.methods) node.methods = new NullProtoObj();\n\tnode.methods[method] ??= [];\n\tnode.methods[method].push({\n\t\tdata: data || null,\n\t\tparamsRegexp,\n\t\tparamsMap: hasParams ? paramsMap : void 0\n\t});\n\tif (!hasParams) ctx.static[path] = node;\n}\nfunction getParamRegexp(segment) {\n\tconst regex = segment.replace(/:(\\w+)/g, (_, id) => `(?<${id}>[^/]+)`).replace(/\\./g, \"\\\\.\");\n\treturn /* @__PURE__ */ new RegExp(`^${regex}$`);\n}\n\n/**\n* Find a route by path.\n*/\nfunction findRoute(ctx, method = \"\", path, opts) {\n\tif (path.charCodeAt(path.length - 1) === 47) path = path.slice(0, -1);\n\tconst staticNode = ctx.static[path];\n\tif (staticNode && staticNode.methods) {\n\t\tconst staticMatch = staticNode.methods[method] || staticNode.methods[\"\"];\n\t\tif (staticMatch !== void 0) return staticMatch[0];\n\t}\n\tconst segments = splitPath(path);\n\tconst match = _lookupTree(ctx, ctx.root, method, segments, 0)?.[0];\n\tif (match === void 0) return;\n\tif (opts?.params === false) return match;\n\treturn {\n\t\tdata: match.data,\n\t\tparams: match.paramsMap ? getMatchParams(segments, match.paramsMap) : void 0\n\t};\n}\nfunction _lookupTree(ctx, node, method, segments, index) {\n\tif (index === segments.length) {\n\t\tif (node.methods) {\n\t\t\tconst match = node.methods[method] || node.methods[\"\"];\n\t\t\tif (match) return match;\n\t\t}\n\t\tif (node.param && node.param.methods) {\n\t\t\tconst match = node.param.methods[method] || node.param.methods[\"\"];\n\t\t\tif (match) {\n\t\t\t\tconst pMap = match[0].paramsMap;\n\t\t\t\tif (pMap?.[pMap?.length - 1]?.[2]) return match;\n\t\t\t}\n\t\t}\n\t\tif (node.wildcard && node.wildcard.methods) {\n\t\t\tconst match = node.wildcard.methods[method] || node.wildcard.methods[\"\"];\n\t\t\tif (match) {\n\t\t\t\tconst pMap = match[0].paramsMap;\n\t\t\t\tif (pMap?.[pMap?.length - 1]?.[2]) return match;\n\t\t\t}\n\t\t}\n\t\treturn;\n\t}\n\tconst segment = segments[index];\n\tif (node.static) {\n\t\tconst staticChild = node.static[segment];\n\t\tif (staticChild) {\n\t\t\tconst match = _lookupTree(ctx, staticChild, method, segments, index + 1);\n\t\t\tif (match) return match;\n\t\t}\n\t}\n\tif (node.param) {\n\t\tconst match = _lookupTree(ctx, node.param, method, segments, index + 1);\n\t\tif (match) {\n\t\t\tif (node.param.hasRegexParam) {\n\t\t\t\tconst exactMatch = match.find((m) => m.paramsRegexp[index]?.test(segment)) || match.find((m) => !m.paramsRegexp[index]);\n\t\t\t\treturn exactMatch ? [exactMatch] : void 0;\n\t\t\t}\n\t\t\treturn match;\n\t\t}\n\t}\n\tif (node.wildcard && node.wildcard.methods) return node.wildcard.methods[method] || node.wildcard.methods[\"\"];\n}\n\n/**\n* Remove a route from the router context.\n*/\nfunction removeRoute(ctx, method, path) {\n\tconst segments = splitPath(path);\n\treturn _remove(ctx.root, method || \"\", segments, 0);\n}\nfunction _remove(node, method, segments, index) {\n\tif (index === segments.length) {\n\t\tif (node.methods && method in node.methods) {\n\t\t\tdelete node.methods[method];\n\t\t\tif (Object.keys(node.methods).length === 0) node.methods = void 0;\n\t\t}\n\t\treturn;\n\t}\n\tconst segment = segments[index];\n\tif (segment === \"*\") {\n\t\tif (node.param) {\n\t\t\t_remove(node.param, method, segments, index + 1);\n\t\t\tif (_isEmptyNode(node.param)) node.param = void 0;\n\t\t}\n\t\treturn;\n\t}\n\tif (segment.startsWith(\"**\")) {\n\t\tif (node.wildcard) {\n\t\t\t_remove(node.wildcard, method, segments, index + 1);\n\t\t\tif (_isEmptyNode(node.wildcard)) node.wildcard = void 0;\n\t\t}\n\t\treturn;\n\t}\n\tconst childNode = node.static?.[segment];\n\tif (childNode) {\n\t\t_remove(childNode, method, segments, index + 1);\n\t\tif (_isEmptyNode(childNode)) {\n\t\t\tdelete node.static[segment];\n\t\t\tif (Object.keys(node.static).length === 0) node.static = void 0;\n\t\t}\n\t}\n}\nfunction _isEmptyNode(node) {\n\treturn node.methods === void 0 && node.static === void 0 && node.param === void 0 && node.wildcard === void 0;\n}\n\n/**\n* Find all route patterns that match the given path.\n*/\nfunction findAllRoutes(ctx, method = \"\", path, opts) {\n\tif (path.charCodeAt(path.length - 1) === 47) path = path.slice(0, -1);\n\tconst segments = splitPath(path);\n\tconst matches = _findAll(ctx, ctx.root, method, segments, 0);\n\tif (opts?.params === false) return matches;\n\treturn matches.map((m) => {\n\t\treturn {\n\t\t\tdata: m.data,\n\t\t\tparams: m.paramsMap ? getMatchParams(segments, m.paramsMap) : void 0\n\t\t};\n\t});\n}\nfunction _findAll(ctx, node, method, segments, index, matches = []) {\n\tconst segment = segments[index];\n\tif (node.wildcard && node.wildcard.methods) {\n\t\tconst match = node.wildcard.methods[method] || node.wildcard.methods[\"\"];\n\t\tif (match) matches.push(...match);\n\t}\n\tif (node.param) {\n\t\t_findAll(ctx, node.param, method, segments, index + 1, matches);\n\t\tif (index === segments.length && node.param.methods) {\n\t\t\tconst match = node.param.methods[method] || node.param.methods[\"\"];\n\t\t\tif (match) {\n\t\t\t\tconst pMap = match[0].paramsMap;\n\t\t\t\tif (pMap?.[pMap?.length - 1]?.[2]) matches.push(...match);\n\t\t\t}\n\t\t}\n\t}\n\tconst staticChild = node.static?.[segment];\n\tif (staticChild) _findAll(ctx, staticChild, method, segments, index + 1, matches);\n\tif (index === segments.length && node.methods) {\n\t\tconst match = node.methods[method] || node.methods[\"\"];\n\t\tif (match) matches.push(...match);\n\t}\n\treturn matches;\n}\n\nfunction routeToRegExp(route = \"/\") {\n\tconst reSegments = [];\n\tlet idCtr = 0;\n\tfor (const segment of route.split(\"/\")) {\n\t\tif (!segment) continue;\n\t\tif (segment === \"*\") reSegments.push(`(?<_${idCtr++}>[^/]*)`);\n\t\telse if (segment.startsWith(\"**\")) reSegments.push(segment === \"**\" ? \"?(?<_>.*)\" : `?(?<${segment.slice(3)}>.+)`);\n\t\telse if (segment.includes(\":\")) reSegments.push(segment.replace(/:(\\w+)/g, (_, id) => `(?<${id}>[^/]+)`).replace(/\\./g, \"\\\\.\"));\n\t\telse reSegments.push(segment);\n\t}\n\treturn /* @__PURE__ */ new RegExp(`^/${reSegments.join(\"/\")}/?$`);\n}\n\nexport { NullProtoObj, addRoute, createRouter, findAllRoutes, findRoute, removeRoute, routeToRegExp };"]}
package/package.json ADDED
@@ -0,0 +1,97 @@
1
+ {
2
+ "name": "@standardagents/builder",
3
+ "version": "0.8.1",
4
+ "private": false,
5
+ "publishConfig": {
6
+ "access": "restricted",
7
+ "registry": "https://registry.npmjs.org/"
8
+ },
9
+ "type": "module",
10
+ "license": "UNLICENSED",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/standardagents/standardagents.git",
14
+ "directory": "packages/builder"
15
+ },
16
+ "main": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "workerd": "./dist/index.js",
22
+ "import": "./dist/plugin.js",
23
+ "default": "./dist/plugin.js"
24
+ },
25
+ "./runtime": {
26
+ "types": "./dist/index.d.ts",
27
+ "workerd": "./dist/index.js",
28
+ "import": "./dist/index.js",
29
+ "default": "./dist/index.js"
30
+ },
31
+ "./built-in-routes": {
32
+ "workerd": "./dist/built-in-routes.js",
33
+ "import": "./dist/built-in-routes.js",
34
+ "default": "./dist/built-in-routes.js"
35
+ },
36
+ "./mcp": {
37
+ "workerd": "./dist/mcp.js",
38
+ "import": "./dist/mcp.js",
39
+ "default": "./dist/mcp.js"
40
+ },
41
+ "./rou3": {
42
+ "workerd": "./dist/rou3.js",
43
+ "import": "./dist/rou3.js",
44
+ "default": "./dist/rou3.js"
45
+ },
46
+ "./client": {
47
+ "types": "./client.d.ts"
48
+ }
49
+ },
50
+ "files": [
51
+ "dist",
52
+ "client.d.ts",
53
+ "client"
54
+ ],
55
+ "scripts": {
56
+ "build": "pnpm build:ui && pnpm build:code",
57
+ "build:code": "tsup",
58
+ "build:ui": "vite build --config vite.config.ui.ts",
59
+ "dev": "tsup --watch",
60
+ "dev:ui": "vite ui --port 5177",
61
+ "typecheck": "tsc --noEmit"
62
+ },
63
+ "dependencies": {
64
+ "@formkit/drag-and-drop": "^0.5.3",
65
+ "@modelcontextprotocol/sdk": "^1.17.4",
66
+ "@vueuse/core": "^14.0.0",
67
+ "lucide-vue-next": "^0.546.0",
68
+ "monaco-editor": "^0.52.2",
69
+ "openai": "^6.5.0",
70
+ "rou3": "^0.7.3",
71
+ "vue": "^3.5.13",
72
+ "vue-router": "^4.5.0",
73
+ "zod": "^4.0.17",
74
+ "zodown": "^0.2.1"
75
+ },
76
+ "devDependencies": {
77
+ "@cloudflare/workers-types": "^4.0.0",
78
+ "@iconify-json/lucide": "^1.2.62",
79
+ "@tailwindcss/vite": "^4.1.12",
80
+ "@types/node": "^22.16.5",
81
+ "@vitejs/plugin-vue": "^6.0.1",
82
+ "@vue/tsconfig": "^0.7.0",
83
+ "esbuild-plugin-alias": "^0.2.1",
84
+ "tailwindcss": "^4.1.12",
85
+ "tsup": "^8.0.0",
86
+ "tsx": "^4.20.6",
87
+ "typescript": "~5.8.0",
88
+ "unplugin-icons": "^22.2.0",
89
+ "unplugin-vue": "^7.0.4",
90
+ "vite": "^7.0.6",
91
+ "vite-plugin-monaco-editor": "^1.1.0",
92
+ "vue-tsc": "^2.0.0"
93
+ },
94
+ "peerDependencies": {
95
+ "vite": "^7.0.0"
96
+ }
97
+ }