@studioindia/designx 1.1.0 → 1.2.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/assets/{AppPreviewPanel-dKEc87DX.js → AppPreviewPanel-Kzzw8_FK.js} +1 -1
- package/dist/assets/index-DB32CkYi.js +482 -0
- package/dist/assets/{index-BV7YFZ0k.js → index-YCdF8pEa.js} +1 -1
- package/dist/assets/{jszip.min-D8jHCuHH.js → jszip.min-BbKvkdq8.js} +1 -1
- package/dist/assets/{jszip.min-CMmTeOAB.js → jszip.min-DzuQM42A.js} +1 -1
- package/dist/index.html +1 -1
- package/package.json +1 -1
- package/server.cjs +127 -9
- package/dist/assets/index-BD0bOY-g.js +0 -482
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{g as Ss,d as Gt,e as Rs}from"./index-
|
|
1
|
+
import{g as Ss,d as Gt,e as Rs}from"./index-DB32CkYi.js";import{r as Ns}from"./jszip.min-BbKvkdq8.js";function Os(e,n){for(var i=0;i<n.length;i++){const t=n[i];if(typeof t!="string"&&!Array.isArray(t)){for(const r in t)if(r!=="default"&&!(r in e)){const a=Object.getOwnPropertyDescriptor(t,r);a&&Object.defineProperty(e,r,a.get?a:{enumerable:!0,get:()=>t[r]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}var Ge={},Rr="1.13.8",wa=typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global||Function("return this")()||{},Jt=Array.prototype,Nr=Object.prototype,Fa=typeof Symbol<"u"?Symbol.prototype:null,ks=Jt.push,ut=Jt.slice,tt=Nr.toString,Is=Nr.hasOwnProperty,zo=typeof ArrayBuffer<"u",Ls=typeof DataView<"u",qs=Array.isArray,Aa=Object.keys,Ca=Object.create,Wa=zo&&ArrayBuffer.isView,Ms=isNaN,Ps=isFinite,Go=!{toString:null}.propertyIsEnumerable("toString"),Ba=["valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"],Xs=Math.pow(2,53)-1;function Pe(e,n){return n=n==null?e.length-1:+n,function(){for(var i=Math.max(arguments.length-n,0),t=Array(i),r=0;r<i;r++)t[r]=arguments[r+n];switch(n){case 0:return e.call(this,t);case 1:return e.call(this,arguments[0],t);case 2:return e.call(this,arguments[0],arguments[1],t)}var a=Array(n+1);for(r=0;r<n;r++)a[r]=arguments[r];return a[n]=t,e.apply(this,a)}}function pn(e){var n=typeof e;return n==="function"||n==="object"&&!!e}function $o(e){return e===null}function Or(e){return e===void 0}function kr(e){return e===!0||e===!1||tt.call(e)==="[object Boolean]"}function Qo(e){return!!(e&&e.nodeType===1)}function Me(e){var n="[object "+e+"]";return function(i){return tt.call(i)===n}}const ei=Me("String"),Ir=Me("Number"),Yo=Me("Date"),Zo=Me("RegExp"),Ko=Me("Error"),Lr=Me("Symbol"),qr=Me("ArrayBuffer");var Jo=Me("Function"),js=wa.document&&wa.document.childNodes;typeof/./!="function"&&typeof Int8Array!="object"&&typeof js!="function"&&(Jo=function(e){return typeof e=="function"||!1});const qe=Jo,eu=Me("Object");var nu=Ls&&(!/\[native code\]/.test(String(DataView))||eu(new DataView(new ArrayBuffer(8)))),Mr=typeof Map<"u"&&eu(new Map),Vs=Me("DataView");function Hs(e){return e!=null&&qe(e.getInt8)&&qr(e.buffer)}const it=nu?Hs:Vs,mn=qs||Me("Array");function bn(e,n){return e!=null&&Is.call(e,n)}var Br=Me("Arguments");(function(){Br(arguments)||(Br=function(e){return bn(e,"callee")})})();const ni=Br;function tu(e){return!Lr(e)&&Ps(e)&&!isNaN(parseFloat(e))}function Pr(e){return Ir(e)&&Ms(e)}function Xr(e){return function(){return e}}function iu(e){return function(n){var i=e(n);return typeof i=="number"&&i>=0&&i<=Xs}}function ru(e){return function(n){return n==null?void 0:n[e]}}const $t=ru("byteLength"),zs=iu($t);var Gs=/\[object ((I|Ui)nt(8|16|32)|Float(32|64)|Uint8Clamped|Big(I|Ui)nt64)Array\]/;function $s(e){return Wa?Wa(e)&&!it(e):zs(e)&&Gs.test(tt.call(e))}const jr=zo?$s:Xr(!1),Le=ru("length");function Qs(e){for(var n={},i=e.length,t=0;t<i;++t)n[e[t]]=!0;return{contains:function(r){return n[r]===!0},push:function(r){return n[r]=!0,e.push(r)}}}function au(e,n){n=Qs(n);var i=Ba.length,t=e.constructor,r=qe(t)&&t.prototype||Nr,a="constructor";for(bn(e,a)&&!n.contains(a)&&n.push(a);i--;)a=Ba[i],a in e&&e[a]!==r[a]&&!n.contains(a)&&n.push(a)}function Se(e){if(!pn(e))return[];if(Aa)return Aa(e);var n=[];for(var i in e)bn(e,i)&&n.push(i);return Go&&au(e,n),n}function cu(e){if(e==null)return!0;var n=Le(e);return typeof n=="number"&&(mn(e)||ei(e)||ni(e))?n===0:Le(Se(e))===0}function Vr(e,n){var i=Se(n),t=i.length;if(e==null)return!t;for(var r=Object(e),a=0;a<t;a++){var c=i[a];if(n[c]!==r[c]||!(c in r))return!1}return!0}function Te(e){if(e instanceof Te)return e;if(!(this instanceof Te))return new Te(e);this._wrapped=e}Te.VERSION=Rr;Te.prototype.value=function(){return this._wrapped};Te.prototype.valueOf=Te.prototype.toJSON=Te.prototype.value;Te.prototype.toString=function(){return String(this._wrapped)};function Sa(e){return new Uint8Array(e.buffer||e,e.byteOffset||0,$t(e))}var Ra="[object DataView]";function ou(e,n){for(var i=[{a:e,b:n}],t=[],r=[];i.length;){var a=i.pop();if(a===!0){t.pop(),r.pop();continue}if(e=a.a,n=a.b,e===n){if(e!==0||1/e===1/n)continue;return!1}if(e==null||n==null)return!1;if(e!==e){if(n!==n)continue;return!1}var c=typeof e;if(c!=="function"&&c!=="object"&&typeof n!="object")return!1;e instanceof Te&&(e=e._wrapped),n instanceof Te&&(n=n._wrapped);var o=tt.call(e);if(o!==tt.call(n))return!1;if(nu&&o=="[object Object]"&&it(e)){if(!it(n))return!1;o=Ra}switch(o){case"[object RegExp]":case"[object String]":if(""+e==""+n)continue;return!1;case"[object Number]":i.push({a:+e,b:+n});continue;case"[object Date]":case"[object Boolean]":if(+e==+n)continue;return!1;case"[object Symbol]":if(Fa.valueOf.call(e)===Fa.valueOf.call(n))continue;return!1;case"[object ArrayBuffer]":case Ra:i.push({a:Sa(e),b:Sa(n)});continue}var u=o==="[object Array]";if(!u&&jr(e)){var s=$t(e);if(s!==$t(n))return!1;if(e.buffer===n.buffer&&e.byteOffset===n.byteOffset)continue;u=!0}if(!u){if(typeof e!="object"||typeof n!="object")return!1;var h=e.constructor,g=n.constructor;if(h!==g&&!(qe(h)&&h instanceof h&&qe(g)&&g instanceof g)&&"constructor"in e&&"constructor"in n)return!1}for(var f=t.length;f--;)if(t[f]===e){if(r[f]===n)break;return!1}if(!(f>=0))if(t.push(e),r.push(n),i.push(!0),u){if(f=e.length,f!==n.length)return!1;for(;f--;)i.push({a:e[f],b:n[f]})}else{var m=Se(e),D;if(f=m.length,Se(n).length!==f)return!1;for(;f--;){if(D=m[f],!bn(n,D))return!1;i.push({a:e[D],b:n[D]})}}}return!0}function Pn(e){if(!pn(e))return[];var n=[];for(var i in e)n.push(i);return Go&&au(e,n),n}function Hr(e){var n=Le(e);return function(i){if(i==null)return!1;var t=Pn(i);if(Le(t))return!1;for(var r=0;r<n;r++)if(!qe(i[e[r]]))return!1;return e!==du||!qe(i[zr])}}var zr="forEach",uu="has",Gr=["clear","delete"],su=["get",uu,"set"],Ys=Gr.concat(zr,su),du=Gr.concat(su),Zs=["add"].concat(Gr,zr,uu);const lu=Mr?Hr(Ys):Me("Map"),fu=Mr?Hr(du):Me("WeakMap"),hu=Mr?Hr(Zs):Me("Set"),gu=Me("WeakSet");function Cn(e){for(var n=Se(e),i=n.length,t=Array(i),r=0;r<i;r++)t[r]=e[n[r]];return t}function pu(e){for(var n=Se(e),i=n.length,t=Array(i),r=0;r<i;r++)t[r]=[n[r],e[n[r]]];return t}function $r(e){for(var n={},i=Se(e),t=0,r=i.length;t<r;t++)n[e[i[t]]]=i[t];return n}function rt(e){var n=[];for(var i in e)qe(e[i])&&n.push(i);return n.sort()}function Qr(e,n){return function(i){var t=arguments.length;if(n&&(i=Object(i)),t<2||i==null)return i;for(var r=1;r<t;r++)for(var a=arguments[r],c=e(a),o=c.length,u=0;u<o;u++){var s=c[u];(!n||i[s]===void 0)&&(i[s]=a[s])}return i}}const Yr=Qr(Pn),qn=Qr(Se),Zr=Qr(Pn,!0);function Ks(){return function(){}}function mu(e){if(!pn(e))return{};if(Ca)return Ca(e);var n=Ks();n.prototype=e;var i=new n;return n.prototype=null,i}function bu(e,n){var i=mu(e);return n&&qn(i,n),i}function Du(e){return pn(e)?mn(e)?e.slice():Yr({},e):e}function yu(e,n){return n(e),e}function Kr(e){return mn(e)?e:[e]}Te.toPath=Kr;function st(e){return Te.toPath(e)}function Jr(e,n){for(var i=n.length,t=0;t<i;t++){if(e==null)return;e=e[n[t]]}return i?e:void 0}function ea(e,n,i){var t=Jr(e,st(n));return Or(t)?i:t}function vu(e,n){n=st(n);for(var i=n.length,t=0;t<i;t++){var r=n[t];if(!bn(e,r))return!1;e=e[r]}return!!i}function ti(e){return e}function An(e){return e=qn({},e),function(n){return Vr(n,e)}}function ii(e){return e=st(e),function(n){return Jr(n,e)}}function dt(e,n,i){if(n===void 0)return e;switch(i??3){case 1:return function(t){return e.call(n,t)};case 3:return function(t,r,a){return e.call(n,t,r,a)};case 4:return function(t,r,a,c){return e.call(n,t,r,a,c)}}return function(){return e.apply(n,arguments)}}function xu(e,n,i){return e==null?ti:qe(e)?dt(e,n,i):pn(e)&&!mn(e)?An(e):ii(e)}function ri(e,n){return xu(e,n,1/0)}Te.iteratee=ri;function Xe(e,n,i){return Te.iteratee!==ri?Te.iteratee(e,n):xu(e,n,i)}function Uu(e,n,i){n=Xe(n,i);for(var t=Se(e),r=t.length,a={},c=0;c<r;c++){var o=t[c];a[o]=n(e[o],o,e)}return a}function na(){}function Tu(e){return e==null?na:function(n){return ea(e,n)}}function _u(e,n,i){var t=Array(Math.max(0,e));n=dt(n,i,1);for(var r=0;r<e;r++)t[r]=n(r);return t}function Qt(e,n){return n==null&&(n=e,e=0),e+Math.floor(Math.random()*(n-e+1))}const Mn=Date.now||function(){return new Date().getTime()};function Eu(e){var n=function(a){return e[a]},i="(?:"+Se(e).join("|")+")",t=RegExp(i),r=RegExp(i,"g");return function(a){return a=a==null?"":""+a,t.test(a)?a.replace(r,n):a}}const wu={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"},Fu=Eu(wu),Js=$r(wu),Au=Eu(Js),Cu=Te.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var wi=/(.)^/,ed={"'":"'","\\":"\\","\r":"r","\n":"n","\u2028":"u2028","\u2029":"u2029"},nd=/\\|'|\r|\n|\u2028|\u2029/g;function td(e){return"\\"+ed[e]}var id=/^\s*(\w|\$)+\s*$/;function Wu(e,n,i){!n&&i&&(n=i),n=Zr({},n,Te.templateSettings);var t=RegExp([(n.escape||wi).source,(n.interpolate||wi).source,(n.evaluate||wi).source].join("|")+"|$","g"),r=0,a="__p+='";e.replace(t,function(s,h,g,f,m){return a+=e.slice(r,m).replace(nd,td),r=m+s.length,h?a+=`'+
|
|
2
2
|
((__t=(`+h+`))==null?'':_.escape(__t))+
|
|
3
3
|
'`:g?a+=`'+
|
|
4
4
|
((__t=(`+g+`))==null?'':__t)+
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{d as bt}from"./index-
|
|
1
|
+
import{d as bt}from"./index-DB32CkYi.js";function vt(yt){throw new Error('Could not dynamically require "'+yt+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var kt={exports:{}};/*!
|
|
2
2
|
|
|
3
3
|
JSZip v3.10.1 - A JavaScript class for generating and reading zip files
|
|
4
4
|
<http://stuartk.com/jszip>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{e as p}from"./index-
|
|
1
|
+
import{e as p}from"./index-DB32CkYi.js";import{r as a}from"./jszip.min-BbKvkdq8.js";function f(t,n){for(var o=0;o<n.length;o++){const e=n[o];if(typeof e!="string"&&!Array.isArray(e)){for(const r in e)if(r!=="default"&&!(r in t)){const i=Object.getOwnPropertyDescriptor(e,r);i&&Object.defineProperty(t,r,i.get?i:{enumerable:!0,get:()=>e[r]})}}}return Object.freeze(Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}))}var s=a();const c=p(s),l=f({__proto__:null,default:c},[s]);export{l as j};
|
package/dist/index.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>DesignX</title>
|
|
7
|
-
<script type="module" crossorigin src="/assets/index-
|
|
7
|
+
<script type="module" crossorigin src="/assets/index-DB32CkYi.js"></script>
|
|
8
8
|
<link rel="stylesheet" crossorigin href="/assets/index-C0vXud8_.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
package/package.json
CHANGED
package/server.cjs
CHANGED
|
@@ -47596,7 +47596,7 @@ makeProjectDataRoutes("session", "session.json", {});
|
|
|
47596
47596
|
var uploadStorage = import_multer.default.diskStorage({
|
|
47597
47597
|
destination: (req, _file, cb) => {
|
|
47598
47598
|
const { slug } = req.params;
|
|
47599
|
-
const uploadDir = import_node_path.default.join(projectDir(slug), "
|
|
47599
|
+
const uploadDir = import_node_path.default.join(projectDir(slug), "knowledge-base");
|
|
47600
47600
|
import_node_fs.default.mkdirSync(uploadDir, { recursive: true });
|
|
47601
47601
|
cb(null, uploadDir);
|
|
47602
47602
|
},
|
|
@@ -47610,6 +47610,64 @@ var uploadMiddleware = (0, import_multer.default)({
|
|
|
47610
47610
|
limits: { fileSize: 50 * 1024 * 1024 }
|
|
47611
47611
|
// 50 MB per file
|
|
47612
47612
|
}).array("files", 20);
|
|
47613
|
+
var WORKSPACE_ROOT = import_node_path.default.resolve(__dirname, "..", "..");
|
|
47614
|
+
function pythonBin() {
|
|
47615
|
+
const venv = import_node_path.default.join(WORKSPACE_ROOT, ".venv", "bin", "python3");
|
|
47616
|
+
return import_node_fs.default.existsSync(venv) ? venv : "python3";
|
|
47617
|
+
}
|
|
47618
|
+
function triggerKbPipeline(slug) {
|
|
47619
|
+
const kbDir = import_node_path.default.join(projectDir(slug), "knowledge-base");
|
|
47620
|
+
const outDir = import_node_path.default.join(projectDir(slug), "knowledge-base-md");
|
|
47621
|
+
const py = pythonBin();
|
|
47622
|
+
const convert = (0, import_node_child_process.spawn)(
|
|
47623
|
+
py,
|
|
47624
|
+
["scripts/kb_artefacts_to_md.py", "--kb-dir", kbDir, "--out-dir", outDir],
|
|
47625
|
+
{ cwd: WORKSPACE_ROOT, stdio: "pipe" }
|
|
47626
|
+
);
|
|
47627
|
+
convert.on("close", (code) => {
|
|
47628
|
+
if (code !== 0) {
|
|
47629
|
+
console.warn(`[kb-pipeline] convert exited ${code} for ${slug}`);
|
|
47630
|
+
return;
|
|
47631
|
+
}
|
|
47632
|
+
const graph = (0, import_node_child_process.spawn)(
|
|
47633
|
+
py,
|
|
47634
|
+
[
|
|
47635
|
+
"-m",
|
|
47636
|
+
"enigma.optimization.knowledge_graph.cli",
|
|
47637
|
+
"restructure",
|
|
47638
|
+
"--project",
|
|
47639
|
+
slug,
|
|
47640
|
+
"--root-dir",
|
|
47641
|
+
DESIGNX_DATA_DIR
|
|
47642
|
+
],
|
|
47643
|
+
{ cwd: WORKSPACE_ROOT, stdio: "pipe" }
|
|
47644
|
+
);
|
|
47645
|
+
graph.on("close", (gc) => {
|
|
47646
|
+
if (gc !== 0) {
|
|
47647
|
+
console.warn(`[kb-pipeline] graph build exited ${gc} for ${slug}`);
|
|
47648
|
+
return;
|
|
47649
|
+
}
|
|
47650
|
+
console.log(`[kb-pipeline] graph ready for ${slug}`);
|
|
47651
|
+
const embed = (0, import_node_child_process.spawn)(
|
|
47652
|
+
py,
|
|
47653
|
+
[
|
|
47654
|
+
"-m",
|
|
47655
|
+
"enigma.optimization.knowledge_graph.cli",
|
|
47656
|
+
"embed",
|
|
47657
|
+
"--project",
|
|
47658
|
+
slug,
|
|
47659
|
+
"--root-dir",
|
|
47660
|
+
DESIGNX_DATA_DIR
|
|
47661
|
+
],
|
|
47662
|
+
{ cwd: WORKSPACE_ROOT, stdio: "pipe" }
|
|
47663
|
+
);
|
|
47664
|
+
embed.on("close", (ec) => {
|
|
47665
|
+
if (ec !== 0) console.warn(`[kb-pipeline] embed exited ${ec} for ${slug}`);
|
|
47666
|
+
else console.log(`[kb-pipeline] embeddings ready for ${slug}`);
|
|
47667
|
+
});
|
|
47668
|
+
});
|
|
47669
|
+
});
|
|
47670
|
+
}
|
|
47613
47671
|
app.post("/api/data/projects/:slug/uploads", (req, res) => {
|
|
47614
47672
|
const { slug } = req.params;
|
|
47615
47673
|
if (!safeSlug(slug)) {
|
|
@@ -47631,6 +47689,7 @@ app.post("/api/data/projects/:slug/uploads", (req, res) => {
|
|
|
47631
47689
|
mimetype: f.mimetype
|
|
47632
47690
|
}))
|
|
47633
47691
|
});
|
|
47692
|
+
if (files.length > 0) triggerKbPipeline(slug);
|
|
47634
47693
|
});
|
|
47635
47694
|
});
|
|
47636
47695
|
app.get("/api/data/projects/:slug/uploads", (req, res) => {
|
|
@@ -47640,7 +47699,7 @@ app.get("/api/data/projects/:slug/uploads", (req, res) => {
|
|
|
47640
47699
|
return;
|
|
47641
47700
|
}
|
|
47642
47701
|
try {
|
|
47643
|
-
const uploadDir = import_node_path.default.join(projectDir(slug), "
|
|
47702
|
+
const uploadDir = import_node_path.default.join(projectDir(slug), "knowledge-base");
|
|
47644
47703
|
if (!import_node_fs.default.existsSync(uploadDir)) {
|
|
47645
47704
|
res.json([]);
|
|
47646
47705
|
return;
|
|
@@ -47665,7 +47724,7 @@ app.delete("/api/data/projects/:slug/uploads/:filename", (req, res) => {
|
|
|
47665
47724
|
return;
|
|
47666
47725
|
}
|
|
47667
47726
|
try {
|
|
47668
|
-
const filePath = import_node_path.default.join(projectDir(slug), "
|
|
47727
|
+
const filePath = import_node_path.default.join(projectDir(slug), "knowledge-base", filename);
|
|
47669
47728
|
if (import_node_fs.default.existsSync(filePath)) import_node_fs.default.unlinkSync(filePath);
|
|
47670
47729
|
res.json({ ok: true });
|
|
47671
47730
|
} catch (err) {
|
|
@@ -47779,6 +47838,63 @@ app.put("/api/data/token-stats", (req, res) => {
|
|
|
47779
47838
|
res.status(500).json({ error: String(err) });
|
|
47780
47839
|
}
|
|
47781
47840
|
});
|
|
47841
|
+
app.get("/api/kb/:slug/retrieve", (req, res) => {
|
|
47842
|
+
const { slug } = req.params;
|
|
47843
|
+
if (!safeSlug(slug)) {
|
|
47844
|
+
res.status(400).json({ error: "Invalid slug" });
|
|
47845
|
+
return;
|
|
47846
|
+
}
|
|
47847
|
+
const rawQuery = typeof req.query.query === "string" ? req.query.query : "";
|
|
47848
|
+
const query = rawQuery.slice(0, 500);
|
|
47849
|
+
if (!query) {
|
|
47850
|
+
res.status(400).json({ error: "query param required" });
|
|
47851
|
+
return;
|
|
47852
|
+
}
|
|
47853
|
+
const maxTokens = String(parseInt(String(req.query.max_tokens ?? "3000"), 10) || 3e3);
|
|
47854
|
+
const strategy = /^[a-z]+$/.test(String(req.query.strategy ?? "")) ? String(req.query.strategy) : "balanced";
|
|
47855
|
+
const py = pythonBin();
|
|
47856
|
+
const child = (0, import_node_child_process.spawn)(
|
|
47857
|
+
py,
|
|
47858
|
+
[
|
|
47859
|
+
"-m",
|
|
47860
|
+
"enigma.optimization.knowledge_graph.cli",
|
|
47861
|
+
"context",
|
|
47862
|
+
"--project",
|
|
47863
|
+
slug,
|
|
47864
|
+
"--query",
|
|
47865
|
+
query,
|
|
47866
|
+
"--max-tokens",
|
|
47867
|
+
maxTokens,
|
|
47868
|
+
"--strategy",
|
|
47869
|
+
strategy,
|
|
47870
|
+
"--root-dir",
|
|
47871
|
+
DESIGNX_DATA_DIR
|
|
47872
|
+
],
|
|
47873
|
+
{ cwd: WORKSPACE_ROOT, stdio: "pipe" }
|
|
47874
|
+
);
|
|
47875
|
+
let stdout = "";
|
|
47876
|
+
child.stdout?.on("data", (chunk) => {
|
|
47877
|
+
stdout += chunk.toString();
|
|
47878
|
+
});
|
|
47879
|
+
const timeout = setTimeout(() => {
|
|
47880
|
+
child.kill();
|
|
47881
|
+
res.status(504).json({ error: "KB retrieval timed out" });
|
|
47882
|
+
}, 15e3);
|
|
47883
|
+
child.on("close", (code) => {
|
|
47884
|
+
clearTimeout(timeout);
|
|
47885
|
+
if (res.headersSent) return;
|
|
47886
|
+
try {
|
|
47887
|
+
const data = JSON.parse(stdout);
|
|
47888
|
+
if (data.error && !data.context) {
|
|
47889
|
+
res.status(500).json({ error: data.error });
|
|
47890
|
+
return;
|
|
47891
|
+
}
|
|
47892
|
+
res.json({ context: data.context ?? "", source: data.source ?? "fallback", tokens: data.tokens ?? 0 });
|
|
47893
|
+
} catch {
|
|
47894
|
+
res.status(500).json({ error: `KB retrieval failed (exit ${code})` });
|
|
47895
|
+
}
|
|
47896
|
+
});
|
|
47897
|
+
});
|
|
47782
47898
|
app.get("/api/kb/:slug/context", (req, res) => {
|
|
47783
47899
|
const { slug } = req.params;
|
|
47784
47900
|
if (!safeSlug(slug)) {
|
|
@@ -47786,12 +47902,14 @@ app.get("/api/kb/:slug/context", (req, res) => {
|
|
|
47786
47902
|
return;
|
|
47787
47903
|
}
|
|
47788
47904
|
try {
|
|
47789
|
-
const
|
|
47790
|
-
|
|
47905
|
+
const mdDir = import_node_path.default.join(projectDir(slug), "knowledge-base-md");
|
|
47906
|
+
const rawDir = import_node_path.default.join(projectDir(slug), "knowledge-base");
|
|
47907
|
+
const sourceDir = import_node_fs.default.existsSync(mdDir) ? mdDir : rawDir;
|
|
47908
|
+
if (!import_node_fs.default.existsSync(sourceDir)) {
|
|
47791
47909
|
res.json({ entries: [], totalChars: 0 });
|
|
47792
47910
|
return;
|
|
47793
47911
|
}
|
|
47794
|
-
const
|
|
47912
|
+
const PLAIN_TEXT_EXTS = /* @__PURE__ */ new Set([
|
|
47795
47913
|
".txt",
|
|
47796
47914
|
".md",
|
|
47797
47915
|
".mdx",
|
|
@@ -47825,12 +47943,12 @@ app.get("/api/kb/:slug/context", (req, res) => {
|
|
|
47825
47943
|
const TOTAL_CAP = 2e5;
|
|
47826
47944
|
let totalChars = 0;
|
|
47827
47945
|
const entries = [];
|
|
47828
|
-
for (const name of import_node_fs.default.readdirSync(
|
|
47946
|
+
for (const name of import_node_fs.default.readdirSync(sourceDir)) {
|
|
47829
47947
|
if (totalChars >= TOTAL_CAP) break;
|
|
47830
|
-
const filePath = import_node_path.default.join(
|
|
47948
|
+
const filePath = import_node_path.default.join(sourceDir, name);
|
|
47831
47949
|
if (import_node_fs.default.statSync(filePath).isDirectory()) continue;
|
|
47832
47950
|
const ext = import_node_path.default.extname(name).toLowerCase();
|
|
47833
|
-
if (ext && !
|
|
47951
|
+
if (sourceDir === rawDir && ext && !PLAIN_TEXT_EXTS.has(ext)) continue;
|
|
47834
47952
|
try {
|
|
47835
47953
|
const raw = import_node_fs.default.readFileSync(filePath, "utf8");
|
|
47836
47954
|
const limit = Math.min(PER_FILE_CAP, TOTAL_CAP - totalChars);
|